我正在尝试在 Apache 服务器上使用通过 StartSSL.com 获得的 SSL 证书。与浏览器的连接很好,但是当我尝试使用 Java 应用程序时,我得到了这个异常:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
我不明白可能是什么问题,因为在浏览器中,我得到了带有绿色标签的 SSL。
最佳答案
问题是您的 Java 不信任该证书。您必须将它导入您的 java 的 truststore
。
# Copy the certificate into the directory Java_home\Jre\Lib\Security
# Change your directory to Java_home\Jre\Lib\Security>
# Import the certificate to a trust store.
# Here's the import command:
keytool -import -alias ca -file somecert.cer -keystore cacerts -storepass changeit [Return]
Trust this certificate: [Yes]
changeit 是默认的信任库密码。
对于导入到信任库中的每个证书,您都必须提供一个新别名。
导入方法引用自Here
关于带有 SSL 证书错误的 Java HTTPS 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30199806/