httpclient尝试使用证书进行https调用时,已将pem证书导入密钥库,并将根ca证书导入信任库。
但唯一可行的方法是使用openssl和代码实现创建p12:
private CloseableHttpClient getHttpClient() throws Exception{
KeyStore clientStore = KeyStore.getInstance("PKCS12");
clientStore.load(new FileInputStream("C:\\Users\\myUSer\\client.p12"), "passValue".toCharArray());
SSLContext sslContext = SSLContexts.custom()
.loadKeyMaterial(clientStore, certificateProperties.getCertPassword().toCharArray())
.loadTrustMaterial(null, (x509CertChain, authType) -> true)
.build();
HttpClientBuilder httpBuilder = HttpClients.custom()
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.setSSLContext(sslContext);
RequestConfig requestConfig = RequestConfig.custom()
.setRedirectsEnabled(false)
.build();
return httpBuilder.setDefaultRequestConfig(requestConfig).build();
}
想摆脱路径的证书和通行证,只使用全局密钥库,但我不清楚如何使用全局密钥库没有通行证,并告诉httpclient使用所需的证书从密钥库。
检查时密钥库文件存在:
system.getproperty(“javax.net.ssl.truststore”)
暂无答案!
目前还没有任何答案,快来回答吧!