我使用HttpClient与我的WebAPI服务进行通信。对于SSL认证,我成立了HttpClient的使用WebRequestHandler客户端证书 -WebRequestHandler中的ClientCertificates
private static WebRequestHandler CreateWebRequestHandler(List<X509Certificate2> clientCertificates)
{
WebRequestHandler handler = new WebRequestHandler();
if (clientCertificates != null && clientCertificates.Any())
{
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
clientCertificates.ForEach(cert => handler.ClientCertificates.Add(cert));
}
return handler;
}
在服务,我有一个自定义DelegatingHandler使用指纹验证客户端证书 -
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
X509Certificate2 certificate = request.GetClientCertificate();
// Code to validate certificate's Thumbprint with white listed thumbprints
}
从HttpRequest的,我只能获得一个客户端证书。
我的问题:为什么WebRequestHandler允许设置一个ClientCertificates集合?它是否将所有客户端证书提供给服务器?如果是,那么我如何获得DelegatingHandler中的客户端证书列表?