.NET Core - HTTPClient - Ubuntu 20.04上的dh密钥太小了。

问题描述 投票:0回答:1

我想问一下,是否有办法绕过Ubuntu的安全检查,使我能够在我的.NET Core Client应用程序中用一个小的密钥来获取一个网站?我得到的是 error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small 异常。

问题是在Ubuntu 20.04中,openSSL的安全级别设置为 2 和(目前,希望有人能对这个问题给出答案 我的问题 在 Ask Ubuntu 上)我不知道如何将其设置为一个较低的值。

同样的错误发生在使用 curl 除非 --ciphers 'DEFAULT:!DH' 提供了参数,所以我认为问题的根源在于操作系统本身。

我无法控制网站的服务器,所以改变其安全设置是不可能的。

到目前为止,我从C#方面尝试了什么。

serviceCollection.AddHttpClient<IInterface, IImplementation>()
                             .ConfigureHttpMessageHandlerBuilder(messageHandlerBuilder =>
                             {
                                 messageHandlerBuilder.PrimaryHandler = new HttpClientHandler
                                 {
                                     ServerCertificateCustomValidationCallback = (m, c, ch, e) => true
                                 };
                             });

using var httpClient = new HttpClient();
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

var websiteContent = await httpClient.GetStreamAsync(url);

在这种情况下,安全问题不大,所以我在这里使用任何肮脏的黑客都可以。

任何帮助都将是非常感激的。

c# ubuntu .net-core openssl dotnet-httpclient
1个回答
5
投票

谢谢 在Ask Ubuntu上收到的回答 我通过以下方法解决了这个问题

  • 复制 openssl.cnf 档案
  • 增加 openssl_conf = default_conf 在复制文件的顶部
  • 在最后添加。
    [ default_conf ]

    ssl_conf = ssl_sect

    [ssl_sect]

    system_default = ssl_default_sect

    [ssl_default_sect]
    MinProtocol = TLSv1.2
    CipherString = DEFAULT:@SECLEVEL=1

  • 在最后添加: OPENSSL_CONF 环境变量设置为更改后的配置文件的路径。
© www.soinside.com 2019 - 2024. All rights reserved.