首頁軟件教程“請求被中止: 未能創建 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
教程資訊 用戶手冊 網站專題