简体   繁体   English

无法从 .NET C# 创建 SSL/TLS 安全通道

[英]Could not create SSL/TLS secure channel from .NET C#

I'm trying to call an API on my server windows 2008 R2, but I keep getting this error: Could not create SSL/TLS secure channel我正在尝试在我的服务器 windows 2008 R2 上调用 API,但我不断收到此错误:无法创建 SSL/TLS 安全通道

I'm launching the app as a Windows service, with the LocalSystem account.我使用 LocalSystem 帐户将应用程序作为 Windows 服务启动。

I tried many things from some Question from Stack Overflow to get it started but none of these works:我从 Stack Overflow 的一些问题中尝试了很多东西来开始它,但这些都不起作用:

  • With AppContext Switch使用 AppContext 开关

  • Without AppContext Switch没有 AppContext 开关

  • With only SSL Protocol 1.2 on Security protocol只有 SSL 安全协议上的协议 1.2

  • Without SecurityProcotol changed没有更改 SecurityProcotol

  • With ExpectContinue = 100 ExpectContinue = 100

     //Config const string DontEnableSystemDefaultTlsVersions = @"Switch.System.Net.DontEnableSystemDefaultTlsVersions"; const string DontEnableSchUseStrongCryptoName = @"Switch.System.Net.DontEnableSchUseStrongCrypto"; const string DisableUsingServicePointManagerSecurityProtocols = @"Switch.System.ServiceModel.DisableUsingServicePointManagerSecurityProtocols"; const string DontEnableSystemDefaultTlsVersionsServiceModel = @"Switch.System.ServiceModel.DontEnableSystemDefaultTlsVersions"; AppContext.SetSwitch(DontEnableSchUseStrongCryptoName, false); AppContext.SetSwitch(DontEnableSystemDefaultTlsVersions, true); AppContext.SetSwitch(DisableUsingServicePointManagerSecurityProtocols, false); AppContext.SetSwitch(DontEnableSystemDefaultTlsVersionsServiceModel, true); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; //API config and Call HttpWebRequest request = (HttpWebRequest)WebRequest.Create(message.Url); request.Credentials = CredentialCache.DefaultCredentials; request.Method = message.Method; System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); Byte[] byteArray = encoding.GetBytes(message.Content); request.ContentLength = byteArray.Length; request.ContentType = message.ContentType; request.UserAgent = message.UserAgent; request.Accept = message.Accept; using (Stream dataStream = request.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); }

The API need TLS 1.2+ to be called. API 需要 TLS 1.2+ 才能被调用。

I have tested Inte.net Explorer to see if we can call TLS 1.2, and it seems that it can call, I used this https://browserleaks.com/ssl : BrowserLeak我已经测试了 Inte.net Explorer 看我们是否可以调用 TLS 1.2,它似乎可以调用,我使用了这个https://browserleaks.com/ssl : BrowserLeak

I tried to call the API from Postman online (with Chrome) and the Postman app on the server, both are calling the API without an issue.我试图从 Postman 在线(使用 Chrome)和服务器上的 Postman 应用程序调用 API,两者都在毫无问题地调用 API。 Same with SoapUI, it works.与 SoapUI 一样,它可以工作。

It works on my computer (Windows 10), it doesn't work on the server, with the same C# Code.它适用于我的计算机(Windows 10),但不适用于服务器,具有相同的 C# 代码。

I tried to change the framework, 4.0, 4.5, 4.6, 4.8, doesn't seem to change something.我试过换框架,4.0、4.5、4.6、4.8,好像没什么变化。

I have the SSL Handshake, but it doesn't help very much, it said that there was a Handshake failure (02 28):我有 SSL 握手,但没有太大帮助,它说握手失败 (02 28):

    System.Net.Sockets Verbose: 0 : [51080] Exiting Socket#40535505::Send()     -> Int32#174
    ProcessId=46588
    ThreadId=6
    DateTime=2021-11-24T09:05:57.5541547Z
System.Net.Sockets Verbose: 0 : [51080] Entering Socket#40535505::Receive()
    ProcessId=46588
    ThreadId=6
    DateTime=2021-11-24T09:05:57.5541547Z
System.Net.Sockets Verbose: 0 : [51080] Data from Socket#40535505::Receive
    ProcessId=46588
    ThreadId=6
    DateTime=2021-11-24T09:05:57.6151608Z
System.Net.Sockets Verbose: 0 : [51080] 00000000 : 15 03 03 00 02                                  : .....
    ProcessId=46588
    ThreadId=6
    DateTime=2021-11-24T09:05:57.6151608Z
System.Net.Sockets Verbose: 0 : [51080] Exiting Socket#40535505::Receive()  -> Int32#5
    ProcessId=46588
    ThreadId=6
    DateTime=2021-11-24T09:05:57.6151608Z
System.Net.Sockets Verbose: 0 : [51080] Entering Socket#40535505::Receive()
    ProcessId=46588
    ThreadId=6
    DateTime=2021-11-24T09:05:57.6161609Z
System.Net.Sockets Verbose: 0 : [51080] Data from Socket#40535505::Receive
    ProcessId=46588
    ThreadId=6
    DateTime=2021-11-24T09:05:57.6161609Z
System.Net.Sockets Verbose: 0 : [51080] 00000005 : 02 28                                           : .(
    ProcessId=46588
    ThreadId=6
    DateTime=2021-11-24T09:05:57.6161609Z

The Cipher suite seems to be good, I have the first 3 Cipher suite that are required by the API on the beginning of the suite.密码套件似乎不错,我在套件开头有 API 所需的前 3 个密码套件。

The API need the ISRG Root X1 Certificate, which is in the Trusted Root Certification Authorities store. API 需要 ISRG 根 X1 证书,该证书位于受信任的根证书颁发机构存储中。

I used the tool from windows to modify the registry https://support.microsoft.com/en-us/topic/update-to-enable-tls-1-1-and-tls-1-2-as-default-secure-protocols-in-winhttp-in-windows-c4bd73d2-31d7-761e-0178-11268bb10392 Which enabled the TLS 1.2, it wasn't activated in browserleaks before I launch the tool.我使用 windows 的工具修改注册表https://support.microsoft.com/en-us/topic/update-to-enable-tls-1-1-and-tls-1-2-as-default- secure-protocols-in-winhttp-in-windows-c4bd73d2-31d7-761e-0178-11268bb10392启用了 TLS 1.2,在我启动该工具之前它没有在 browserleaks 中激活。

Also SSL 2.0 and SSL3.0 are disabled and TLS1.0, TLS1.1 and TLS1.2 are activated: Secure channel registry此外 SSL 2.0 和 SSL3.0 被禁用,TLS1.0、TLS1.1 和 TLS1.2 被激活:安全通道注册表

I can't seem to find a solution to get it worked.我似乎找不到解决方案来让它工作。 How can I try to find a clue to the issue?我怎样才能找到问题的线索?

We found the issue, the cipher suite required for the API isn't compatible with the windows server 2008 R2, we verified the cipher suite with我们发现了问题,API 所需的密码套件与 windows 服务器 2008 R2 不兼容,我们验证了密码套件

https://www.ssllabs.com/ssltest/ with the url of the api https://www.ssllabs.com/ssltest/与 api 的 url

then compared it with the cipher suites on the server located here:然后将其与位于此处的服务器上的密码套件进行比较:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers

and none of them were matching.他们都不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# 无法创建 ssl/tls 安全通道 (Restsharp) - C# could not create ssl/tls secure channel (Restsharp) HTTP C#客户端:无法创建SSL / TLS安全通道 - HTTP C# client: Could not create SSL/TLS secure channel C# HttpClient:无法创建 SSL/TLS 安全通道 - C# HttpClient: Could not create SSL/TLS secure channel .Net无法创建SSL / TLS安全通道 - .Net could not create SSL/TLS secure channel 无法从Soap C#SoapHttpClientProtocol创建SSL / TLS安全通道 - Could not create SSL/TLS secure channel from soap c# SoapHttpClientProtocol C# 无法在 Windows 7/Windows Server 上使用 TLS1.2 创建 ssl/tls 安全通道 - C# Could not create ssl/tls secure channel on Windows 7/Windows Server, using TLS1.2 该请求已中止:无法创建SSL / TLS安全通道.Net 4.5.2 - The request was aborted: Could not create SSL/TLS secure channel .Net 4.5.2 ASP.NET,HttpWebRequest和“无法创建SSL / TLS安全通道” - ASP.NET, HttpWebRequest and “Could not create SSL/TLS secure channel” .NET请求已中止:无法创建SSL / TLS安全通道 - .NET The request was aborted: Could not create SSL/TLS secure channel 具有X509Certificate2的C#HttpClient-WebException:请求已中止:无法创建SSL / TLS安全通道 - C# HttpClient with X509Certificate2 - WebException: The request was aborted: Could not create SSL/TLS secure channel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM