首页软件教程“请求被中止: 未能创建 SSL/TLS 安全通道”的原因及解决办法
“请求被中止: 未能创建 SSL/TLS 安全通道”的原因及解决办法

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

[插曲] 小飞兔下载 是一款整站下载工具,输入网址一键下载,操作简单易用,多线程任务

解决办法一:代码层面

在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的支持, 参考官方文档 https://support.microsoft.com/en-us/help/3140245/update-to-enable-tls-1-1-and-tls-1-2-as-default-secure-protocols-in-wi

更新补丁KB3140245

在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和windows server 2019 (支持到TLS1.2);
  • 升级系统到windows 11和windows server 2022 (支持到TLS1.3)。

备注:具体到每个windows版本对应支持的TSL版本,请参考本文中的补充资料部分内容。


其他参考内容

其他参考内容一

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

.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

其他参考内容三

SecurityProtocolType.Tls1.0=0xC0; 
SecurityProtocolType.Tls1.1=0x300; 
SecurityProtocolType.Tls1.2=0xC00;
.net 4.0/4.5默认值:SecurityProtocolType.Tls | SecurityProtocolType.Ssl3
.net 4.6/4.7默认值:SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12

https://support.microsoft.com/en-us/help/3069494/cannot-connect-to-a-server-by-using-the-servicepointmanager-or-sslstre

SCH_USE_STRONG_CRYPTO 此标志将在.NET Framework 4.6中自动使用 https://support.microsoft.com/en-us/help/3154518/support-for-tls-system-default-versions-included-in-the-net-framework 在Win7Sp1和.Net 3.5.1中,支持TLS1.2

ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3; //关闭ssl3
ServicePointManager.SecurityProtocol |= (SecurityProtocolType)0x300 | (SecurityProtocolType)0xc00; //增加1.1和1.2支持

TLS1.2的结论是这样的:

  • 安装.Net3.5.1需要打个补丁,然后增加TLS1.2枚举
  • 安装.Net 4.0需要修改注册表,然后增加TLS1.2枚举
  • 安装.Net4.5之后,还需要增加TLS1.2枚举
  • 安装.Net4.6.1之后,默认支持TLS1.2

.net4下的注册表修改

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001

补充资料

本文由小飞兔下载收集整理,内容来源于互联网,转载请注明出处,谢谢。

软件应用:前端模板下载;开发设计;SEO优化;离线浏览网页。备注:本软件不是黑客程序,不能下载后台数据!
免责声明:服务用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯本网站及相关权利人的合法权利,通过使用本站工具随之而来的风险与本软件无关。
Copyright © 2019-2024 小飞兔软件 All Rights Reserved 粤ICP备19111427号-2
教程资讯 用户手册 网站专题