Java HttpsURLConnection SSLHandshakeException
我尝试使用 HttpsURLConnection
与网站建立 HTTPS 连接,然后执行 PUT 请求。当我尝试从 HttpsURLConnection.getOutputStream()
创建 OutputStreamWriter
时,会引发以下异常:
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
该页面刚刚获得其证书(由 StartCom 颁发) - 我需要吗手动执行某些操作以使 Java 识别证书现在是否存在?我可以毫无困难地连接到同一网站的其他页面,但它们有不同的证书。
I am attempting to make a HTTPS connection to a website using HttpsURLConnection
, and then perform a PUT request. When I try to create the OutputStreamWriter
from HttpsURLConnection.getOutputStream()
, the following exception is thrown:
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
The page has just gotten its certificate (issued by StartCom) - do I need to manually do something to make Java recognise the certificate is present now? I can connect to other pages of the same website with no difficulty, but they have a different certificate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过工具 keytool(来自 JDK)将 StartCom 的根证书导入到 Java 密钥存储(JKS)中,然后将密钥存储设置为“受信任的存储”。
请参阅以下位置的“导出和导入证书”部分:
http://java.sun.com/ developer/technicalArticles/Security/secureinternet2/
该文章中提到的命令:
将证书导入到 trustcerts.jks:
使用自定义 tuststore 启动 Java:
或者您可以设置运行时的信任库:
You can import the root certificate of StartCom yia the tool keytool (from JDK) into a Java Key Store (JKS) and then set the key store as "trusted store".
See section "Exporting and Importing Certificates" on:
http://java.sun.com/developer/technicalArticles/Security/secureinternet2/
Commands mentioned in that article:
Import certifificate to trustedcerts.jks:
Start Java using custom tuststore:
Alternatively you can set the truststore at runtime:
另请参阅此问题:在 Windows JRE 中导入 StartCom CA 证书
它链接到一个脚本,用于将 StartCom 证书导入到受信任的 JDK 中店铺。
Please also see this question: Import StartCom CA certificates in Windows JRE
It links to a script for importing StartCom certificates into your JDK trusted store.