在Java客户机中接受服务器的自签名SSL证书这看起来是个标准问题,但我哪里也找不到明确的方向。我有Java代码试图连接到一个可能是自签名(或过期)证书的服务器。代码报告以下错误:[HttpMethodDirector] I/O exception (javax.net.ssl.SSLHandshakeException) caught
when processing request: sun.security.validator.ValidatorException: PKIX path
building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target据我所知,我不得不用钥匙工具告诉java允许这种连接是可以的。所有修复此问题的说明都假定我完全精通keyTool,如为服务器生成私钥并将其导入密钥存储库有人可以贴详细说明吗?我正在运行Unix,所以bash脚本最好。不确定它是否重要,但是在JBoss中执行的代码。
3 回答
九州编程
TA贡献1785条经验 获得超4个赞
SSLContext sslContext = SSLContexts.custom() .loadTrustMaterial(new TrustSelfSignedStrategy()) .build();SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext);Registry<ConnectionSocketFactory> reg = RegistryBuilder.<ConnectionSocketFactory>create() .register("https", socketFactory) .build();HttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(reg); CloseableHttpClient httpClient = HttpClients.custom() .setConnectionManager(cm) .build();HttpGet httpGet = new HttpGet(url);CloseableHttpResponse sslResponse = httpClient.execute(httpGet);
TrustSelfSignedStrategy
添加回答
举报
0/150
提交
取消