【问题标题】:Client Certificate Authentication failed in WebRequest\HttpClient C#WebRequest\HttpClient C# 中的客户端证书身份验证失败
【发布时间】:2021-02-21 03:39:09
【问题描述】:

我们的客户在通过客户端证书身份验证进行身份验证时遇到了失败。

使用 IISCrypto 完成了他们的 Tls1.2 配置。 SSL 协议和 TLS1.1 被标记为禁用。

他们使用 IISCrypto 完成了他们的 Cipher Suite 配置。

我检查了密码套件\.net 框架版本\操作系统版本\TLS 重新协商\服务器证书设置\API 网关设置\Windows 服务。 但我无法得到任何结果。

然后我尝试编写一些故障排除程序来测试通信和握手顺序。 我什么都没有。

Curl.exeopenssl 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\WebRequestSslStream 之间的客户端证书选择处理程序似乎不同。

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。 这是一个错误。

【问题讨论】:

    标签: c# ssl tls1.2 client-certificates


    【解决方案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。 这是一个错误。

    【讨论】:

      猜你喜欢
      • 2014-03-31
      • 1970-01-01
      • 2019-06-27
      • 2011-04-09
      • 2013-10-07
      • 2014-05-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-23
      相关资源
      最近更新 更多