java - 使用没有密码的全局密钥库 - java HttpClient
问题描述
尝试使用 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")
解决方案
推荐阅读
- swift - 使用自定义路径无法在 Swift 包管理器中解析清单文件
- keras - 我们可以摆脱 Tensorflow 2.0 中的 set_session 吗?
- javascript - CraftCMS Gatsby 项目抛出错误“GraphQL 错误预期类型 [String],找到 {eq: $slug}。”
- laravel - 在一行中显示父母和孩子
- react-native-popup-menu - 如何在弹出菜单中添加偏移量?
- elasticsearch - Elasticsearch 中的无痛脚本通过条件检查来操纵分数
- javascript - 将 HTML 解析为组成标签
- c# - 发布目标中缺少 VS 2019 天蓝色功能
- ruby - 未初始化的常量 Van (NameError)
- vuejs2 - 在Vue中设置包装对象的子组件的道具