我正在对 .NET 4.8 中的 https 端点进行 REST 调用。端点还需要客户端证书 (pfx) 并支持 Tls 1.1 和 Tls 1.2。
在应用程序启动时,我设置一次:
try
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls |
SecurityProtocolType.Ssl3;
}
catch( Exception ex )
{
log.Warn( "TLS 1.3 as security protocol type is not usable on this machine. Using TLS 1.2 instead.", ex );
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls |
SecurityProtocolType.Ssl3;
}
我们有很多不同的外部 API 调用,但失败的端点的基本代码是:
HttpClientHandler handler = new HttpClientHandler();
handler.ClientCertificates.Add( new X509Certificate2( path, password ) );
HttpClient client = new HttpClient( handler );
// Set url and basic authentication...
client.GetAsync(resource);
证书有效并存储在 certmgr 中的正确位置。
该请求在我的本地开发机器(Win10)上有效。
它在 Windows Server 2019 上抛出“无法创建 ssl/tls 安全通道”异常。
我尝试设置 handler.SslProtocols = SslProtocols.Tls11 resp。 tls12 但错误保持不变。
Win Server 2019 上应该默认启用 Tls 1.2。如何检查它是否已启用?
这里有人有其他想法吗?
谢谢!
有完全相同的问题,你找到解决方案了吗?