【问题标题】:Could not create SSL/TLS secure channel happens only in windows server 2012无法创建 SSL/TLS 安全通道仅在 Windows Server 2012 中发生
【发布时间】:2020-05-06 05:45:57
【问题描述】:

我的目标是检查文件大小,我在几台 windows server 2012 r2 机器上测试了这段代码下面的代码给出了错误,(在所有这些机器上):

无法创建 SSL/TLS 安全通道

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
string url = @"https://www.gov.il/BlobFolder/reports/fortimail/he/FORTIMAIL-CERT-IL-W-1068.pdf";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);            
using (HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse())
{
    var headers = myHttpWebResponse.Headers;
    string fileSize = "0";
    if (headers.AllKeys.Contains("Content-Length"))
        fileSize = headers.GetValues("Content-Length")[0];
    Console.WriteLine(fileSize);
}

相同的代码在 Windows Server 2016 和 Windows 10 上运行良好,但在 Windows Server 2012 上却不行。

当我从 chrome 输入此链接时,它甚至可以在服务器 2012 上运行,对于邮递员,它也可以在所有机器上运行(但在 windows 2012 中不能通过代码运行)。

错误发生在给定的链接上,但对于其他文件网址,如http://www.orimi.com/pdf-test.pdf,它可以正常工作。

我也尝试通过注册表启用 TLS:

有什么想法吗?

【问题讨论】:

标签: ssl tls1.2 windows-server-2012 windows-server-2012-r2


【解决方案1】:

尝试将配置更正为:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

这应该让它工作。该站点仅支持 TLS1.2,这是当前广泛支持的 TLS 版本。

Windows 2012 可能会执行 TLS 1.0 开箱即用。建议应用所有 Windows 更新并编辑系统设置以仅默认执行 TLS 1.2。您使用这些注册表项走上了正确的轨道,但还有更多。 Microsoft 文档没有对配置进行详细解释,也许能够找到解释调整的堆栈溢出。

Windows 2012 R2 于 2018 年终止支持,并将在 2023 年终止扩展支持(假设您每年为此支付额外费用)。您应该考虑升级。预计 Windows 2008 和 2012 上过时的加密技术会成为 TLS 连接问题的常见来源。

curl "https://www.gov.il/BlobFolder/reports/fortimail/he/FORTIMAIL-CERT-IL-W-1068.pdf" --tlsv1.2
... good

curl "https://www.gov.il/BlobFolder/reports/fortimail/he/FORTIMAIL-CERT-IL-W-1068.pdf" --tlsv1.1
curl: (35) schannel: next InitializeSecurityContext failed: SEC_E_ILLEGAL_MESSAGE (0x80090326)
This error usually occurs when a fatal SSL/TLS alert is received (e.g. handshake failed). More detail may be available in the Windows System event log.

curl "https://www.gov.il/BlobFolder/reports/fortimail/he/FORTIMAIL-CERT-IL-W-1068.pdf" --tlsv1.0
curl: (35) schannel: next InitializeSecurityContext failed: SEC_E_ILLEGAL_MESSAGE (0x80090326)
This error usually occurs when a fatal SSL/TLS alert is received (e.g. handshake failed). More detail may be available in the Windows System event log.

【讨论】:

  • 1.我尝试使用Tls12 配置,但没有成功。 2.我的windows更新了。 3."..registrey keys,但还有更多",在哪里?
  • 试试这个。在除TLS 1.2 之外的所有版本中,在ClientServer 子目录中设置Enabled=0DisabledByDefault=1。对于TLS 1.2,请改为设置Enabled=1DisabledByDefault=0。然后重启服务器。
猜你喜欢
  • 2020-05-15
  • 1970-01-01
  • 2021-03-23
  • 1970-01-01
  • 2016-11-18
  • 1970-01-01
  • 2020-09-29
  • 1970-01-01
  • 2021-12-13
相关资源
最近更新 更多