我们的客户在通过客户端证书身份验证进行身份验证时遇到了失败。
使用 IISCrypto 完成了他们的 Tls1.2 配置。 SSL 协议(protocol)和 TLS1.1 被标记为禁用。
并且他们使用 IISCrypto 完成了他们的 Cipher Suite 配置。
我检查了 Cipher Suite\.net Framework 版本\操作系统版本\TLS 重新协商\服务器证书设置\API 网关设置\Windows 服务。
但我无法得到任何结果。
然后我尝试编写一些故障排除程序来测试通信和握手顺序。
我什么都没有。Curl.exe
和 openssl s_client
使用客户端证书发送消息时可以,但在 C# 中总是失败,我的代码如下:
X509Certificate2 cert = new X509Certificate2(@"C:\Communicate.pfx", "xxxxx");
HttpClient client = null;
System.Net.Http.WebRequestHandler _internalHandler = new System.Net.Http.WebRequestHandler();
_internalHandler.UseProxy = false;
_internalHandler.ClientCertificates.Add(cert);
_internalHandler.ServerCertificateValidationCallback = ((obj, x509, chain, policyError) =>
{
return true;
});
client = new HttpClient(_internalHandler);
client.BaseAddress = new Uri(string.Format("https://{0}:{1}/", args[0], int.Parse(args[1])));
=================================更新================= =====我试图写一个 TCP 请求者来测试。它成功了。
HttpClient\WebRequest
之间的客户端证书选择处理程序似乎不同和 SslStream
.X509Certificate2 cert = new X509Certificate2(@"C:\Communicate.pfx", "xxxxxxxx");
X509Certificate2Collection col = new X509Certificate2Collection();
col.Add(cert);
TcpClient client = new TcpClient(args[0], int.Parse(args[1]));
Stream stream = client.GetStream();
SslStream ssl = new SslStream(stream, false, new RemoteCertificateValidationCallback((a, b, c, d) =>
{
return true;
}),
new LocalCertificateSelectionCallback((sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers)=>
{
return cert;
}));
ssl.AuthenticateAsClient("1.1.1.1", col, System.Security.Authentication.SslProtocols.Tls12, false);
string x = "GET /api/TimebasedProxy/ HTTP/1.1\r\n";
x += "Host:1.1.1.1\r\n";
x += "Content-Type: application/json\r\n";
x += "Connection: Close\r\n\r\n";
byte[] xs = Encoding.UTF8.GetBytes(x);
ssl.Write(xs, 0, xs.Length);
================更新==============我得到了原因:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\SendTrustedIssuerList
在服务器端设置为 1。(https://docs.microsoft.com/en-us/windows-server/security/tls/tls-registry-settings#sendtrustedissuerlist)
但是客户在 Windows Server 2012R2 下运行他们的服务器,他设置了
SendTrustedIssuerList
到 1?===========================更新=============
IISCrypto 做到了。
你对 IISCrypto 做了什么,IISCrypto 总是设置
SendTrustedIssuerList
为 1。这是一个错误。
最佳答案
我得到了原因:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\SendTrustedIssuerList
在服务器端设置为 1。
(https://docs.microsoft.com/en-us/windows-server/security/tls/tls-registry-settings#sendtrustedissuerlist)
但是客户在 Windows Server 2012R2 下运行他们的服务器,他设置了 SendTrustedIssuerList
到 1?
IISCrypto 做到了。
你对 IISCrypto 做了什么,IISCrypto 总是设置 SendTrustedIssuerList
为 1。
这是一个错误。
关于c# - WebRequest\HttpClient C# 中的客户端证书身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64747910/