简体   繁体   English

HTTP Web 请求 TLS 1.3 C# .NET 核心 3.1 异常“客户端和服务器无法通信,因为它们不具备通用算法。”

[英]HTTP Web Request TLS 1.3 with C# .NET Core 3.1 exception "The client and server cannot communicate, because they do not possess a common algorithm."

When attempting a web request to a site which requires TLS 1.3 https://shop.claytonengineering.com/ .尝试向需要 TLS 1.3 https://shop.claytonengineering.com/的站点发出 web 请求时。 I'm receiving the following exception on "request.GetResponse();".我在“request.GetResponse();”上收到以下异常。

Exception: The SSL connection could not be established, see inner exception.异常:无法建立SSL连接,见内部异常。 Inner Exception: The client and server cannot communicate, because they do not possess a common algorithm.内部异常:客户端和服务器无法通信,因为它们不具备通用算法。

From Google Chrome Developer tools Security tab - "The connection to this site is encrypted and authenticated using TLS 1.3, X25519, and AES_128_GCM."来自 Google Chrome 开发者工具的安全选项卡 - “使用 TLS 1.3、X25519 和 AES_128_GCM 对与此站点的连接进行加密和身份验证。”

Any ideas on how to get this request to work?关于如何让这个请求起作用的任何想法?

HttpWebResponse response = null;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://shop.claytonengineering.com/");

request.KeepAlive = true;
request.Headers.Add("Upgrade-Insecure-Requests", @"1");
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36";
request.Headers.Add("Sec-Fetch-Mode", @"navigate");
request.Headers.Add("Sec-Fetch-User", @"?1");
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
request.Headers.Add("Sec-Fetch-Site", @"same-origin");

request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.9");

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;

response = (HttpWebResponse)request.GetResponse();

string html = null;

using (StreamReader stream = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
    html = stream.ReadToEnd();
}

There are at least two parts to a successful TLS connection:成功的 TLS 连接至少有两个部分:

  1. Protocol version协议版本
  2. Ciphersuite match密码套件匹配

In both cases both the client and server must match up to use the same protocol and cipher.在这两种情况下,客户端和服务器都必须匹配才能使用相同的协议和密码。 You already understand that there are multiple TLS versions (1.0, 1.1, 1.2, 1.3) but there are also multiple ciphers that are used to encrypt/decrypt information.您已经了解有多个 TLS 版本(1.0、1.1、1.2、1.3),但也有多个密码用于加密/解密信息。

After the 3-way handshake, the client sends its accepted versions in the "Client Hello" and a list of accepted ciphers to the server.在 3 次握手之后,客户端在“Client Hello”中将其接受的版本和接受的密码列表发送给服务器。 The server finds a match and sends that information back to the client ("Server Hello"), then communication begins.服务器找到匹配项并将该信息发送回客户端(“Server Hello”),然后开始通信。

In this case, although you're both using TLS 1.3, you aren't matching up with a cipher.在这种情况下,尽管你们都在使用 TLS 1.3,但您并没有匹配到密码。 The server has a list of ciphers that can be found by using the test found at ssllabs.com.服务器有一个密码列表,可以使用 ssllabs.com 中的测试找到。

The list of ciphers accepted by the server you listed above is in the image below.您上面列出的服务器接受的密码列表如下图所示。 You can enable one of the above on your client and then the connection should succeed.您可以在客户端上启用上述其中一项,然后连接应该成功。 I assume you're using Windows, so please see this:我假设你使用的是 Windows,所以请看这个:

https://www.howtogeek.com/221080/how-to-update-your-windows-server-cipher-suite-for-better-security/#:~:text=On%20the%20left%20hand%20side%2C%20expand%20Computer%20Configuration%2C,%E2%80%9CEnabled%E2%80%9D%20button%20to%20edit%20your%20server%E2%80%99s%20Cipher%20Suites . https://www.howtogeek.com/221080/how-to-update-your-windows-server-cipher-suite-for-better-security/#:~:text=On%20the%20left%20hand%20side% 2C%20expand%20Computer%20Configuration%2C,%E2%80%9CEnabled%E2%80%9D%20button%20to%20edit%20your%20server%E2%80%99s%20Cipher%20Suites

在此处输入图像描述

I had this very same issue and found out that while.Net framework 4.8 and.Net5.0 and 6.0 all have implementations of the TLS1.3 stack, none of them seem to use them when you do not tell Windows to do so.我遇到了同样的问题,发现虽然 .Net framework 4.8 和 .Net5.0 和 6.0 都有 TLS1.3 堆栈的实现,但当您不告诉 Windows 这样做时,它们似乎都没有使用它们。

In my case I had to add the following registry key:在我的例子中,我必须添加以下注册表项:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001

For some reason these are not there by default.出于某种原因,这些默认情况下不存在。

暂无
暂无

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

相关问题 客户端和服务器无法通信,因为它们没有共同的算法 - ASP.NET C# IIS TLS 1.0 / 1.1 / 1.2 - Win32 - The client and server cannot communicate, because they do not possess a common algorithm - ASP.NET C# IIS TLS 1.0 / 1.1 / 1.2 - Win32Exception C# 客户端和服务器无法通信,因为它们没有通用的算法 - C# The client and server cannot communicate, because they do not possess a common algorithm 客户端和服务器无法通信,因为它们没有通用的算法C#SslStream - The client and server cannot communicate, because they do not possess a common algorithm, C# SslStream TLS 1. 2 客户端和服务器无法通信,因为它们没有通用算法 - TLS 1. 2 The client and server cannot communicate, because they do not possess a common algorithm SoapHttpClientProtocol和TLS 1.2 - 客户端和服务器无法通信,因为它们没有通用的算法 - SoapHttpClientProtocol and TLS 1.2 - The client and server cannot communicate, because they do not possess a common algorithm 无法创建SSL / TLS安全通道。客户端和服务器无法通信,因为它们没有通用算法 - Could not create SSL/TLS secure channel. The client and server cannot communicate, because they do not possess a common algorithm 客户端和服务器无法通信,因为它们没有通用的 WCF 算法 - The client and server cannot communicate, because they do not possess a common algorithm WCF 客户端和服务器无法通信,因为它们在Windows Server 2008 Web上不具有通用算法 - The client and server cannot communicate, because they do not possess a common algorithm on Windows Server 2008 Web ASP.NET 4.5客户端和服务器无法通信,因为它们不具有通用算法 - ASP.NET 4.5 The client and server cannot communicate, because they do not possess a common algorithm SSLStream.AuthenticateAsServer “客户端和服务器无法通信,因为它们没有通用算法” - SSLStream.AuthenticateAsServer “The client and server cannot communicate, because they do not possess a common algorithm”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM