Thi*_*ard 7 c# ssl https webclient .net-core
我在连接西部数据网站时遇到如下异常:
\n\n22:02:34,803 | HttpGrabber | DEBUG | Grabbing: GET https://shop.westerndigital.com/de-de/products/internal-drives/wd-red-sata-2-5-ssd#WDS200T1R0A\n22:02:34,858 | HttpGrabber | DEBUG | System.Net.Http.SocketsHttpHandler.Http2Support: True\n22:02:34,865 | HttpGrabber | DEBUG | System.Net.Http.UseSocketsHttpHandler: True\n22:02:35,067 | HttpGrabber | ERROR | System.AggregateException: One or more errors occurred. (The SSL connection could not be established, see inner exception.)\n ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.\n ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.\n ---> System.ComponentModel.Win32Exception (0x80090326): Le message re\xc3\xa7u \xc3\xa9tait inattendu ou format\xc3\xa9 de fa\xc3\xa7on incorrecte.\n --- End of inner exception stack trace ---\nRun Code Online (Sandbox Code Playgroud)\n我认为 C# 代码是正确的,因为我有 3/4 单元测试通过:
\n [TestCase("https://allianz-fonds.webfg.net/sheet/fund/FR0013192572/730?date_entree=2018-04-04")]\n [TestCase("https://www.galaxus.de/de/s1/product/zotac-zbox-magnus-en72070v-intel-core-i7-9750h-0gb-pc-13590721")]\n [TestCase("https://www.hystou.com/Gaming-Mini-PC-F7-with-Nvidia-GeForce-GTX-1650-p177717.html")]\n [TestCase("https://shop.westerndigital.com/de-de/products/internal-drives/wd-red-sata-2-5-ssd#WDS200T1R0A")]\n\nRun Code Online (Sandbox Code Playgroud)\n\nssllabs完成的 SSL 诊断给出了 Western digital 网站处理的支持的密码套件列表:\n
Firefox 成功连接到网站,并且 Wireshark 发现 Firefox 的列表中有 1 个密码:\n
然而,我的 dotnet 核心应用程序在 ssl 握手中存在致命错误,因为它没有与 WD 通用的单个密码:
\n\n我花了很多时间才明白错误来自这里......如果它真的来自这里。
\n因此,这个分析提出了两个问题:
\n是否可以在我的 dot net core 3.1 应用程序中添加一个用 C# 编写的密码套件,以便与该网站兼容?\n我在互联网上看到了讨论,规定也许美国公司 Microsoft 不允许导出强加密算法...如果这是真的,那么 Firefox(美国也是)使用与西部数据(美国也是)相同的套件怎么样?
\n是否有可能在 C# 中使用另一个库(我考虑开放 SSl),但另一个库确实提供了所有 https 层(即建议相当于 httpClient)/跨平台以避免失去 dotnetcore 的跨平台功能... 。
\nDmi*_*hin 19
我遇到了同样的问题,我的自动测试(dotnetcore3.1)在 WS 2012 R2 计算机上运行,我必须调用仅接受两个密码套件的第三方 API:TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (0xc02f) TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (0xc030)。
C# HttpClient 依赖于主机系统中的密码套件,而 Chrome、Firefox 和 Curl 则拥有自己的安全和加密系统。WS 2012 R2 没有这两个密码,我不知道如何将它们添加到计算机上,也没有使用这些密码的 Windows 更新。
我选择使用一个非常酷的 NuGet 数据包CurlThin作为解决方案。使用它我们可以为请求设置我们自己的密码套件,因此我们不需要对服务器端执行任何操作。
我安装了两个数据包:CurlThin本身和CurlThin.Native。
向 HTTPS 端点发送带有标头的 GET 请求的结果代码如下所示:
using CurlThin;
using CurlThin.Enums;
using CurlThin.Helpers;
using CurlThin.Native;
using CurlThin.SafeHandles;
using System.Text;
private static string GetToken()
{
//This string is for extracting libcurl and ssl libs to the bin directory.
CurlResources.Init();
var global = CurlNative.Init();
var easy = CurlNative.Easy.Init();
string content;
try
{
var dataCopier = new DataCallbackCopier();
CurlNative.Easy.SetOpt(easy, CURLoption.URL, "https://someendpoints.net/thatendpoint?fake=true");
CurlNative.Easy.SetOpt(easy, CURLoption.WRITEFUNCTION, dataCopier.DataHandler);
//This string is needed when you call a https endpoint.
CurlNative.Easy.SetOpt(easy, CURLoption.CAINFO, CurlResources.CaBundlePath);
var headers = CurlNative.Slist.Append(SafeSlistHandle.Null, "Authorization: Bearer blablabla");
CurlNative.Easy.SetOpt(easy, CURLoption.HTTPHEADER, headers.DangerousGetHandle());
//Your set of ciphers, full list is here https://curl.se/docs/ssl-ciphers.html
CurlNative.Easy.SetOpt(easy, CURLoption.SSL_CIPHER_LIST, "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256");
CurlNative.Easy.Perform(easy);
content = Encoding.UTF8.GetString(dataCopier.Stream.ToArray());
}
finally
{
easy.Dispose();
if (global == CURLcode.OK)
CurlNative.Cleanup();
}
return content;
}
Run Code Online (Sandbox Code Playgroud)
.NET Core 使用本机 TLS 堆栈(即 SChannel)支持的密码。支持哪些密码取决于 Windows 版本。您的操作系统支持哪些密码(在 Windows 7 中的 TLS 密码套件中有记录)。如您所见,您的操作系统不支持服务器提供的所有密码。
对于 Firefox 或 Chrome 浏览器,情况有所不同。它们带有自己的堆栈,因此不受操作系统提供的功能的限制。这就是他们工作的原因。
| 归档时间: |
|
| 查看次数: |
13671 次 |
| 最近记录: |