如何通过 HTTP 客户端传递客户端证书?

问题描述:

我想在服务 A 和 B 之间使用相互 SSL 身份验证.我目前正在使用 Java 实现从服务 A 传递客户端证书.我正在使用 Apache DefaultHttpClient 来执行我的请求.我能够从内部凭证管理器检索服务 A 的客户端证书,并将其保存为字节数组.

I want to use mutual SSL authentication between service A and B. I'm currently implementing passing the client certificate from service A in Java. I'm using Apache DefaultHttpClient to execute my requests. I was able to retrieve the client certificate for my service A from an internal credential manager and I keep it as an array of bytes.

DefaultHttpClient client = new DefaultHttpClient();
byte [] certificate = localCertManager.retrieveCert();

我在这方面的经验很少,非常感谢您的帮助!

I have very little experience in this area and I'd appreciate your help!

我想也许它应该以某种方式通过 HTTP 客户端或标头中的参数传递.

I thought maybe it should be somehow passed through arguments in the HTTP client or maybe in the headers.

如何通过 HTTP 客户端传递客户端证书?

How do I pass the client certificate with HTTP client?

您需要将您的密钥库告诉 SSLSocketFactory(org.apache.http,而不是 javax),并配置您的 DefaultHTTPClient 以将其用于 https 连接.

You need to tell an SSLSocketFactory (org.apache.http, not javax) about your keystore, and configure your DefaultHTTPClient to use it for https connections.

>

示例如下:http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientCustomSSL.java