Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java URL连接javax.net.ssl.SSLHandShakeException_Java_Ssl_Urlconnection - Fatal编程技术网

Java URL连接javax.net.ssl.SSLHandShakeException

Java URL连接javax.net.ssl.SSLHandShakeException,java,ssl,urlconnection,Java,Ssl,Urlconnection,已解决-我通过将我的cacerts文件从windows计算机复制到pi来解决问题。 我正在编写一个应用程序,使用长轮询从Web服务器获取json字符串,该应用程序在我开发的windows机器上运行良好。然后我将源代码移动到一个raspberry pi并编译它,现在它抛出了这个异常: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: s

已解决-我通过将我的cacerts文件从windows计算机复制到pi来解决问题。

我正在编写一个应用程序,使用长轮询从Web服务器获取json字符串,该应用程序在我开发的windows机器上运行良好。然后我将源代码移动到一个raspberry pi并编译它,现在它抛出了这个异常:

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
            at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
            at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1917)
            at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:301)
            at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:295)
            at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1369)
            at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:156)
            at sun.security.ssl.Handshaker.processLoop(Handshaker.java:925)
            at sun.security.ssl.Handshaker.process_record(Handshaker.java:860)
            at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1043)
            at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1343)
            at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1371)
            at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355)
            at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
            at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
            at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1511)
            at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1439)
            at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
            at VideoBoard.main(VideoBoard.java:29)
    Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
            at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
            at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
            at sun.security.validator.Validator.validate(Validator.java:260)
            at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
            at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
            at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
            at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1351)
            ... 13 more
    Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
            at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:145)
            at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:131)
            at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
            at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)
            ... 19 more

我的网站由GoDaddy托管,他们还提供SSL证书。通过浏览器或java从我的桌面访问站点时没有问题,所有迹象表明SSL证书有效且受我的计算机信任。

您在Raspberry Pi上使用的操作系统在您在服务器上使用的操作系统的证书路径中没有可信证书。换句话说,Pi不知道应该相信您的服务器就是它所说的服务器


要解决此问题,您需要在Pi上安装GoDaddy的根证书。如果您使用的是Raspbian或其他Debian派生的操作系统,这是一篇关于如何做到这一点的好文章,也是GoDaddy的证书存储库

URLConnection connection=新URL(URL+“?”+查询).openConnection();setRequestProperty(“接受字符集”,字符集);InputStream响应=connection.getInputStream();我已经安装了3个证书,它们似乎最有意义,但仍然没有成功。您可以尝试打开浏览器,导航到您的站点,然后单击地址栏中的锁定图标,然后查看您的证书由哪个证书颁发机构验证吗?很抱歉,第一个链接有点不清楚;您是否将证书放在
/usr/local/share/ca certificates/
的新目录中,然后运行
sudo update ca certificates
?/usr/local/share/ca certicates/godaddy.org$ls gd-class2-root.crt gdig2.crt gdroot-g2.crtI也会尝试抓取gd_intermediate.crt。我通过从我的计算机上复制cacerts文件解决了这个问题windows计算机到pi。