【问题标题】:Could not create SSL/TLS secure channel only on Windows Server 2012无法仅在 Windows Server 2012 上创建 SSL/TLS 安全通道
【发布时间】:2020-05-15 11:23:44
【问题描述】:

我有一个特殊的问题,即 c# 应用程序可以在我测试过的所有其他机器和其他客户端机器上运行。但没有在他的 ISP 托管的我的客户端 Windows Server 2012 上建立连接。根据我的客户,这个应用程序已经在这台机器上运行了大约 2 天,并使用 .Net4.5.2。不幸的是,我不知道最近几天发生了什么变化。

我在这台机器上测试过的内容:

  • 使用 Chrome 的 url 有效
  • 使用 Edge 的 url 工作
  • 使用 curl 访问 URL 有效
  • 使用 IE11 的 url 工作
  • 使用我们的应用不起作用
  • 使用快速测试应用不起作用

无论我在服务器或应用程序中更改什么设置,这都是一样的。

我的应用出错:

AuthResponse is null: False 
AuthResponse ErrorException: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
   at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
   at System.Net.HttpWebRequest.GetRequestStream()
   at RestSharp.Http.WriteRequestBody(HttpWebRequest webRequest)
   at RestSharp.Http.PostPutInternal(String method)
   at RestSharp.Http.AsPost(String httpMethod)
   at RestSharp.RestClient.DoExecuteAsPost(IHttp http, String method)
   at RestSharp.RestClient.Execute(IRestRequest request, String httpMethod, Func`3 getResponse)
AuthResponse ErrorMessage: The request was aborted: Could not create SSL/TLS secure channel.

来自 IE11 的错误:

Turn on TLS 1.0, TLS 1.1, and TLS 1.2 in Advanced settings and try connecting to  again. If this error persists, it is possible that this site uses an unsupported protocol or cipher suite such as RC4 (link for the details), which is not considered secure. Please contact your site administrator.

来自事件查看器的错误:

A fatal alert was received from the remote endpoint. The TLS protocol defined fatal alert code is 40.
A fatal alert was generated and sent to the remote endpoint. This may result in termination of the connection. The TLS protocol defined fatal error code is 40. The Windows SChannel error state is 1205.
A fatal error occurred while creating an SSL client credential. The internal error state is 10013.

事件查看器中有很多这样的错误,我只是复制了其中三个以防它们实际上相关。

我尝试过的:

我使用IISCrypto 更改和配置各种设置和测试。所有结果都相同。我已经修改了我的应用程序,并通过搜索所有相同的结果发现了很多更改。我在下面所做的一些代码更改:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.Expect100Continue = true;
System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

这不是我尝试的所有更改。我也尝试了各种不同的变体,例如只有 tls1.2。我也使用我的小测试应用程序连接到其他 https 网站,如 google 和我的其他休息服务,这台机器上没有报告错误。

我们的身份验证服务器使用 Lets Encrypts 证书并使用 OAth,并且仅接受 tls2.1。我已经找到了另一个我们使用的 REST Api,它也使用 Lets Encrypt 并且正在工作。我不知道是否需要更新证书存储(如果可能的话),或者是否缺少我的设置。老实说,我在这里不知所措。

如果有帮助,请测试应用源:

static async Task test(string url)
{
    // Call asynchronous network methods in a try/catch block to handle exceptions.
    try
    {
        HttpClient httpClient = new HttpClient();
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

        var result = await httpClient.GetAsync(url);
        MessageBox.Show(result.StatusCode.ToString());
    }
    catch (HttpRequestException e)
    {
        MessageBox.Show(e.ToString());
    }
}

【问题讨论】:

  • 错误 40 是握手失败,错误状态 1205 标识了密码套件交换失败的原因(在握手中,端点和客户端找不到通用的可用/接受的密码)。端点可能已经确定客户端只能理解 SHA1,而预期 SHA256。 SHA 可能已被安全更新或某人禁用。 IIS Crypto 应该给你信息。您可以尝试安装 .Net Framework 4.8(引入 TLS1.3)。
  • @TJ Snyman 你是如何解决这个问题的?我们有同样的问题。

标签: c# certificate tls1.2


【解决方案1】:

我们今天遇到了同样的问题。 昨天在我们的网络服务器上删除了一些不安全的密码套件。 虽然容易受到攻击,但添加这些密码套件可以解决问题。 https://docs.microsoft.com/en-us/windows-server/security/tls/manage-tls

以下是密码套件列表: https://support.microsoft.com/en-us/help/2929781/update-adds-new-tls-cipher-suites-and-changes-cipher-suite-priorities

列出支持的密码套件: https://docs.microsoft.com/nl-nl/windows/win32/secauthn/prioritizing-schannel-cipher-suites?redirectedfrom=MSDN#listing-supported-cipher-suites

【讨论】:

  • 荷兰语页面解释如何更改密码套件的顺序:sslcertificaten.nl/support/IIS_FAQ/IIS_-_Instellen_TLSv1.2
  • 这个页面也很有用阅读:nartac.com/Products/IISCrypto
  • 谢谢克里斯,链接解决了我的问题。同时,我告诉客户迁移到更新版本的 windows 服务器作为更永久的“修复”。
  • 更新 2919355 已安装在我们的机器上,但我们仍然遇到 TJ Snyman 解释的相同错误,我们的环境和用法与他的完全相同。
【解决方案2】:

我也有同样的问题,搜索了一段时间后,有一个视图你需要做的事情:

  1. 首先需要检查您需要访问/查询的 url,该 Url 使用什么类型的“连接加密”?简单的方法是通过 Mozila 或 chrome 打开 url,然后检查“Connection Encrypted” this example for my case

  2. 然后尝试在此处搜索可用于 Windows Server 2012 的可用 TLS 芯片:https://docs.microsoft.com/en-us/windows/win32/secauthn/tls-cipher-suites-in-windows-8-1,从第一步中找到“连接加密”,对于此步骤 2,如果找不到它“密码套件字符串”,因此这意味着您的服务器不支持通过 C# 代码调用该 url。

您的代码中的事件已经添加: ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 因为 Windows Server 2012 不支持“连接加密”

希望能帮到你。

【讨论】:

    【解决方案3】:

    您可能已经解决了这个问题,但我刚刚遇到了同样的问题,即由于“无法创建 SSL/TLS 安全通道”的相同错误,外部 api 调用失败。

    我花了两天时间修复它,首先使用https://www.ssllabs.com/ssltest/检查端点支持的 TLS 版本和密码

    之后,我使用 IIS Crypto 相应地启用了正确的密码,按照 SSLLabs 提供的顺序重新排列密码并解决了问题。

    【讨论】:

      【解决方案4】:

      也许这会对某人有所帮助。

      我刚刚在使用 Windows Server 2019 Datacenter 时遇到了这个问题。

      我用来保护服务器上的自托管服务的 X.509 证书陈旧而脆弱,RSA 1024,MD5 哈希。

      事件查看器无法追踪原因。

      凭直觉,我用更新的 X.509、RSA 4096、SHA256 替换了旧的 X.509,错误就消失了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-03-23
        • 2016-11-18
        • 1970-01-01
        • 2020-09-29
        • 1970-01-01
        • 1970-01-01
        • 2021-12-13
        相关资源
        最近更新 更多