Https 与HttpClient的相互身份验证
我将提出我的问题: 我的web应用程序通过https向服务器提交表单,该服务器需要客户端证书来设置通信。它工作正常,当我提交表单时,https服务器要求我提供证书,我选择我的证书,服务器响应我。但是现在,我想用HttpClient从一个servlet发布到https服务器,因为我想管理来自https服务器的响应,这里我遇到了一些问题 我使用HttpClient发送帖子的代码是:Https 与HttpClient的相互身份验证,https,apache-httpclient-4.x,Https,Apache Httpclient 4.x,我将提出我的问题: 我的web应用程序通过https向服务器提交表单,该服务器需要客户端证书来设置通信。它工作正常,当我提交表单时,https服务器要求我提供证书,我选择我的证书,服务器响应我。但是现在,我想用HttpClient从一个servlet发布到https服务器,因为我想管理来自https服务器的响应,这里我遇到了一些问题 我使用HttpClient发送帖子的代码是: DefaultHttpClient client = new DefaultHttpClient(); // in
DefaultHttpClient client = new DefaultHttpClient();
// in the truststore i have the https server certificates for establish connection
// from my client to https server
FileInputStream instream = new FileInputStream(new File(TRUESTORE_PATH));
KeyStore truststore = KeyStore.getInstance(KeyStore.getDefaultType());
truststore.load(instream, KEY_TRUESTORE_PASS.toCharArray());
// in the keystore i have the client certificate but without private key because,
// in theory, i shouldn't know it
FileInputStream otherinstream = new FileInputStream(new File(KEYSTORE_PATH));
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(otherinstream,KEY_STORE_PASS.toCharArray());
SSLSocketFactory socketFactory = new SocketFactory(keystore,KEY_STORE_PASS,truststore);
Scheme sch = new Scheme("https", 443, socketFactory);
client.getConnectionManager().getSchemeRegistry().register(sch);
HttpGet httpget = new HttpGet("https://remote_server_with_client_authentication");
HttpResponse response = client.execute(httpget);
当我执行此代码时,例如在单元测试中,我收到了来自https服务器的响应,但它告诉我,未授权。我怀疑我无法通过https服务器进行身份验证,因为密钥库具有客户端证书,但没有私钥,因此我未获得授权
那么,是否有某种方法可以使用用户选择的客户端证书与https服务器建立通信
谢谢 要使其正常工作,您需要具有要呈现给服务器的证书的私钥。