使用无权访问私钥的客户端证书通过 HttpClient 进行 HTTPS 调用

Make HTTPS call through HttpClient with client certificate that does not have access to private key

是否可以在 HTTPs 请求中发送没有(访问)私钥的客户端证书(例如,通过使用 HttpClient)?

可以达到目标 API 并且客户端证书可以通过以下使用带有私钥的客户端证书的 HTTPS 请求实现获得。

var handler = new HttpClientHandler();
handler.ClientCertificates.Add(new X509Certificate2(@"clientcertificate.pfx", "password"));
var client = new HttpClient(handler);
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "https://url");
var result = await client.SendAsync(httpRequestMessage);

客户端证书在目标 API 端被读取为 var clientCertificate = await Request.HttpContext.Connection.GetClientCertificateAsync();

但是,当在 HTTPS 请求期间使用没有(访问)私钥的证书时,目标 API 不会获得客户端证书(它是 nullRequest.HttpContext.Connection.ClientCertificate 属性).

handler.ClientCertificates.Add(new X509Certificate2(@"clientcertificate.crt"));

Is it possible to send client certificate without (access to) private key in HTTPs request (e.g. by using HttpClient)?

当然可以,您可以将其作为内容发送;但是您不能将它 用作 没有私钥的客户端证书。这就像通过声明用户名登录系统一样。

技术原因是,无论何时在 TLS 中发送证书,都必须发送一个必需的签名以证明私钥由发送者持有。如果签名未通过验证,则收件人将终止会话。