URL连接给出证书路径错误

时间:2014-05-20 13:15:27

标签: java ssl httpurlconnection

Wile我正在尝试连接https正在提供证书错误

  

javax.net.ssl.SSLHandshakeException:   sun.security.validator.ValidatorException:PKIX路径构建失败:   sun.security.provider.certpath.SunCertPathBuilderException:无法   找到所请求目标的有效证书路径   sun.security.ssl.Alerts.getSSLException(Alerts.java:192)at   sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1886)at at   sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276)at   sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270)at   sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341)     在   sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)     在sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)at at   sun.security.ssl.Handshaker.process_record(Handshaker.java:804)at   sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016)at at   sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)     在   sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)     在   sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)     在   sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:515)     在   sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.setProxiedClient(AbstractDelegateHttpsURLConnection.java:142)     在   sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.setProxiedClient(AbstractDelegateHttpsURLConnection.java:118)     在   sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:629)     在   sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1320)     在   java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)     在   sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)     在com.poc.TestServlet.doPost(TestServlet.java:75)at   javax.servlet.http.HttpServlet.service(HttpServlet.java:641)at at   javax.servlet.http.HttpServlet.service(HttpServlet.java:722)at at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)     在   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)     在   org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:188)     在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:302)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)     在java.lang.Thread.run(Thread.java:722)引起:   sun.security.validator.ValidatorException:PKIX路径构建失败:   sun.security.provider.certpath.SunCertPathBuilderException:无法   找到所请求目标的有效证书路径   sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:385)     在   sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)     在sun.security.validator.Validator.validate(Validator.java:260)at   sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326)     在   sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231)     在   sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126)     在   sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1323)     ... 33更多引起:   sun.security.provider.certpath.SunCertPathBuilderException:无法   找到所请求目标的有效证书路径   sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:196)     在java.security.cert.CertPathBuilder.build(CertPathBuilder.java:268)     在   sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)     ... 39更多

连接很简单https连接

1 个答案:

答案 0 :(得分:0)

您必须将HTTPS证书放入JVM。要从HTTPS获取证书,请通过浏览器,然后单击"锁定"地址栏上的徽标。您应该能够导出证书。

Linux解决方案: 在$JAVA_HOME/jre/lib/security中,使用以下命令:

sudo keytool -import -alias keyName -file /[pathForYourKey]/keyName.cert -keystore cacerts

" cacerts"的默认密码是changeit