带有 SSL 证书错误的 Java HTTPS 连接

标签 java ssl

我正在尝试在 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/

相关文章:

java - ArrayIndexOutOfBoundsException - 解析 csv 文件时

java - 配置Web应用程序的上下文路径

security - TLS 证书是否需要一个通用的 SAN

Tomcat HTTPS 启用自签名证书失败

c# - 仅使用公钥验证签名 (C#)

php - SSL:使用 PHP(没有 phpseclib)将私钥与证书匹配

ruby - 如何以安全 SSL 模式 HTTPS 启动 WEBrick Ruby 服务器

java - 如何读取 Java Spring MVC 应用程序中的属性(或任何其他文本)文件?

java - 同一 ArrayList 内的碰撞检测

java - OS X 的 Java 执行路径中的空格