Java HttpsURLConnection SSLHandshakeException

发布于 2024-11-19 09:55:33 字数 526 浏览 3 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只涨不跌 2024-11-26 09:55:33

您可以通过工具 keytool(来自 JDK)将 StartCom 的根证书导入到 Java 密钥存储(JKS)中,然后将密钥存储设置为“受信任的存储”。

请参阅以下位置的“导出和导入证书”部分:

http://java.sun.com/ developer/technicalArticles/Security/secureinternet2/

该文章中提到的命令:

将证书导入到 trustcerts.jks:

keytool -import -keystore trustedcerts.jks -alias qusay -file server.crt

使用自定义 tuststore 启动 Java:

java -Djavax.net.ssl.trustStore=trustedcerts.jks com.example.MyClass

或者您可以设置运行时的信任库:

System.setProperty("javax.net.ssl.trustStore","./trustedcerts.jks");

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:

keytool -import -keystore trustedcerts.jks -alias qusay -file server.crt

Start Java using custom tuststore:

java -Djavax.net.ssl.trustStore=trustedcerts.jks com.example.MyClass

Alternatively you can set the truststore at runtime:

System.setProperty("javax.net.ssl.trustStore","./trustedcerts.jks");
策马西风 2024-11-26 09:55:33

另请参阅此问题:在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文