Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ClientCertificate是服务器';s SSL证书_C#_Authentication_Ssl - Fatal编程技术网

C# ClientCertificate是服务器';s SSL证书

C# ClientCertificate是服务器';s SSL证书,c#,authentication,ssl,C#,Authentication,Ssl,我正在使用RestSharp向本地IIS发送客户端证书以进行测试。客户端发送证书A: var client = new RestClient(myHost) { ClientCertificates = new X509Certificate2Collection(store.Certificates.Find(X509FindType.FindByThumbprint, myClientThumbprint, true)) }; var request = new RestReque

我正在使用RestSharp向本地IIS发送客户端证书以进行测试。客户端发送证书A:

var client = new RestClient(myHost)
{
    ClientCertificates = new X509Certificate2Collection(store.Certificates.Find(X509FindType.FindByThumbprint, myClientThumbprint, true))
};

var request = new RestRequest(myResource, Method.GET);
var response = client.Execute(request);
在我的服务器上,有一个
DelegatingHandler
连接到我的管道中,在这里成功调用:

protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
    X509Certificate2 certificate = request.GetClientCertificate();
    // ...
}
我也试过了

这两个证书都是由一个受信任的CA创建的,但为了以防万一,我使用它对一个公共/私有证书进行了自签名,以用于我的客户端证书

在任何情况下,假定的“客户机证书”都会被检索为null或服务器的SSL证书。我的客户机肯定会找到证书A。当我使用Fiddler解密HTTPS通信时,我看到一个隧道,标识服务器使用证书B,但没有表示正在传递证书a。(这并不是说它不是——只是我无法证实它是。)

我是否遗漏了一些明显的东西,例如我的证书的性质是单独的还是一起的?或者IIS是否需要一些额外的配置来允许客户端证书传递

编辑: 尝试隔离组件时,我删除了测试客户端上的RestSharp代码,并将其替换为:

var req = (HttpWebRequest)WebRequest.Create(myHost + "/" + myResource);
req.ClientCertificates.Add(myClientCertificate);
req.Method = "GET";

var resp = req.GetResponse();
在Fiddler中,我看到以下HTTP隧道:

HTTP/1.1 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:53:50.370
Connection: close

Encrypted HTTPS traffic flows through this CONNECT tunnel. HTTPS Decryption is enabled in Fiddler, so decrypted sessions running in this tunnel will be shown in the Web Sessions list.

Secure Protocol: Tls
Cipher: Aes256 256bits
Hash Algorithm: Sha1 160bits
Key Exchange: ECDHE_RSA (0xae06) 256bits

== Client Certificate ==========
[Subject]
  CN=(server's SSL certificate)

[Issuer]
  CN=...

(and so on)
  ...


== Server Certificate ==========
(same as the above 'client' certificate)

同样,我已经在VS中确认,我的请求有我的客户端证书要发送到服务器。

当您生成测试证书时,是否设置了正确的密钥用法?@LexLi:即使他设置了,一些SSL证书也会将客户端身份验证和服务器身份验证结合起来。是否有一种方法可以通过筛选其DN/颁发者DN上的可用证书来选择客户端证书…@Iansus应该很少见,因为加载证书的代码使用指纹。在现实世界中,客户端证书永远不能用于服务器目的。如果发生这种情况,那将是灾难性的。@LexLi:我创建的客户端证书只提供“向远程计算机证明您的身份”,而我最初使用的客户端证书(由另一个CA签名)提供“确保远程计算机的身份”。您明白了吗?当您生成测试证书时,你设置了正确的密钥用法吗?@LexLi:即使他设置了,一些SSL认证也会结合客户端身份验证和服务器身份验证。是否有一种方法可以通过筛选其DN/颁发者DN上的可用证书来选择客户端证书…@Iansus应该很少见,因为加载证书的代码使用指纹。在现实世界中,客户端证书永远不能用于服务器目的。如果发生这种情况,那将是灾难性的。@LexLi:我创建的客户端证书只提供“向远程计算机证明您的身份”,而我最初使用的客户端证书(由另一个CA签名)提供“确保远程计算机的身份”。你明白了吗?
HTTP/1.1 200 Connection Established
FiddlerGateway: Direct
StartTime: 09:53:50.370
Connection: close

Encrypted HTTPS traffic flows through this CONNECT tunnel. HTTPS Decryption is enabled in Fiddler, so decrypted sessions running in this tunnel will be shown in the Web Sessions list.

Secure Protocol: Tls
Cipher: Aes256 256bits
Hash Algorithm: Sha1 160bits
Key Exchange: ECDHE_RSA (0xae06) 256bits

== Client Certificate ==========
[Subject]
  CN=(server's SSL certificate)

[Issuer]
  CN=...

(and so on)
  ...


== Server Certificate ==========
(same as the above 'client' certificate)