【发布时间】:2018-11-08 22:36:35
【问题描述】:
我想通过 Java 中的 HTTPS 连接调用一些 Web 服务。证书颁发机构给了我一个 PKCS12 文件,但我得到了一个
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
由于
javax.net.ssl.SSLHandshakeException
这是我正在执行的代码:
System.setProperty("javax.net.ssl.keyStoreType", "JKS");
System.setProperty("javax.net.ssl.keyStore", "path/toto2.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "pwd");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
System.setProperty("javax.net.ssl.trustStore", "path/toto2.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "pwd");
System.setProperty("proxySet","true") ;
System.setProperty("https.proxyHost", "XXX") ;
System.setProperty("https.proxyPort", "XXX") ;
我首先尝试提供 PKCS12 文件,然后是 JKS,但我遇到了同样的错误。
我尝试了另一种解决方案,使用 curl。所以我从 PKCS12 中提取了证书,请求成功。
以下是我用来从 P12 中提取不同文件的命令:
openssl pkcs12 -in file.p12 -nocerts -nodes -out clientcert.key
openssl pkcs12 -in file.p12 -clcerts -nokeys -out clientcert.cer
openssl pkcs12 -in file.p12 -cacerts -nokeys -chain -out cacerts.cer
我在 Java 中使用这些文件的方式有问题吗?
【问题讨论】: