Https未能创建 SSL/TLS 安全通道。Could not create SSL/TLS secure channel解决方案

描述:请求被中止: 未能创建 SSL/TLS 安全通道。Could not create SSL/TLS secure channel。 产生平台:Windows Server 2012,Windows 7 Service Pack 1(SP1)和Windows Server 2008 R2 SP1

转载自:
https://www.xftsoft.com/news/jiaocheng/Could-not-create-SSL-TLS-secure-channel.html

解决办法一:

在HttpWebRequest前设置代码

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;

解决办法二

上面的方法没有效果,则为系统层面的问题了,对照你现在使用的系统更新系统补丁

更新以将TLS 1.1和TLS 1.2启用为Windows中WinHTTP中的默认安全协议,此更新提供对Windows Server 2012,Windows 7 Service Pack 1(SP1)和Windows Server 2008 R2 SP1中的传输层安全性(TLS)1.1和TLS 1.2的支持, 参考官方文档 /link?id=554500000064525498db08d90a346844

更新补丁KB3140245:/link?id=5545000000645254993d08d90a346844

在SChannel组件级别的Windows 7上启用TLS 1.1和1.2 (采用以下任意一种更新)
方法一:使用微软更新安装包更新 MicrosoftEasyFix51044.msi

方法二:手动更新注册表

复制下面注册表代码导入到注册表。新建txt,将后缀txt改为reg(注册表项),导入(导入之前做备份)

WIN7 64

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet
Settings\WinHttp] “DefaultSecureProtocols”=dword:00000a00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet
Settings\WinHttp] “DefaultSecureProtocols”=dword:00000a00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet
Settings] “SecureProtocols”=dword:00000a80

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet
Settings] “SecureProtocols”=dword:00000a80

Windows Server

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet
Settings\WinHttp] “DefaultSecureProtocols”=dword:00000800

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet
Settings\WinHttp] “DefaultSecureProtocols”=dword:00000800

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS
1.1\Client] “DisabledByDefault”=dword:00000000 “Enabled”=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS
1.1\Server] “DisabledByDefault”=dword:00000000 “Enabled”=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS
1.2\Client] “DisabledByDefault”=dword:00000000 “Enabled”=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS
1.2\Server] “DisabledByDefault”=dword:00000000 “Enabled”=dword:00000001

验证系统是否支持TLS1.2、TLS1.3
PowerShell打开:

[Net.ServicePointManager]::SecurityProtocol
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3 -bor [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12

第一行代码检查支持TLS版本 第二行代码修改TLS支持

解决办法三

前面两种办法都不行,只能使用终极办法):升级系统到windows 10。

其他参考内容一

https://www.xftsoft.com/link?id=554500000064525499ca08d90a346844

存在解决方案,但是它们取决于框架版本:

.NET 4.6及更高版本。您无需执行任何其他工作即可支持TLS 1.2,默认情况下支持该功能。

.NET 4.5 支持TLS 1.2,但它不是默认协议。您需要选择使用它。以下代码将TLS 1.2设置为默认值,请确保在连接到安全资源之前执行它:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

.NET 4.0 不支持TLS 1.2,但是如果系统上安装了.NET 4.5(或更高版本),那么即使您的应用程序框架不支持TLS 1.2,您仍然可以选择使用TLS 1.2。唯一的问题是.NET 4.0中的SecurityProtocolType没有TLS1.2的条目,因此我们必须使用此枚举值的数字表示形式:
ServicePointManager.SecurityProtocol =(SecurityProtocolType)3072;

.NET 3.5或更低版本。不支持TLS 1.2(*),并且没有解决方法。将您的应用程序升级到该框架的最新版本。

PS对于场景3,还有一个注册表黑客,默认情况下会强制4.5使用TLS 1.2,而无需以编程方式强制执行。
PPS正如Microsoft的Christian Pop在下面提到的那样,.NET 3.5有一个可用的最新补丁程序,它启用了TLS1.2支持。
请参阅:

  • KB3154518 – Reliability Rollup HR-1605 – NDP 2.0 SP2 – Win7 SP1/Win 2008 R2 SP1
  • KB3154519 – Reliability Rollup HR-1605 – NDP 2.0 SP2 – Win8 RTM/Win 2012 RTM
  • KB3154520 – Reliability Rollup HR-1605 – NDP 2.0 SP2 – Win8.1RTM/Win 2012 R2 RTM
  • KB3156421 -1605 HotFix Rollup through Windows Update for Windows 10.

其他参考内容二

可能网站提供的证书密钥长度为512位,按目前的行业标准应包含不小于2048位的公钥。 微软在2016年9月的安全更新响应这一问题,如果公钥长度小于2048字节(例如RSA 512),Windows可以取消HTTPS连接

安装的更新有

2012 R2 and Windows 8

  • KB3185331
  • KB3188743
  • KB3174644

2008 R2 and Windows 7

  • KB3185278
  • KB3185330
  • KB3192391
  • KB3175024
  • KB3172605

猜你喜欢

转载自blog.csdn.net/carcarrot/article/details/119252958