sun.security.validator.ValidatorException:PKIX路径构建失败:无法找到所请求目标的有效证书路径

时间:2015-02-19 16:10:56

标签: java php web-services ssl

我已从一台服务器迁移到新服务器。 我使用PHP Web服务为我的移动应用程序访问数据库中的数据。我已经安装了SSL证书,并且webservice在浏览器和iphone应用程序上运行正常(使用ASIHTTPRequest lib)。 但Android应用程序不会加载相同服务的数据。所以调试了,这是我得到的错误。

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:1868)
    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:1337)
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:154)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:998)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1294)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1321)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1305)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:523)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1087)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
    at com.turnkey.maths.Test.main(Test.java:60)
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:385)
    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:326)
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1319)
    ... 12 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:196)
    at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:268)
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)
    ... 18 more

这是我用来收集数据的方法

try 
{
    HttpURLConnection connection;
    OutputStreamWriter request = null;
    URL url = null;   
    String parameters = "query=SELECT * from table;";
    url = new URL("https://www.domain.com/weservice/index.php?");
    connection = (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestMethod("POST");    
    request = new OutputStreamWriter(connection.getOutputStream());
    request.write(parameters);
    request.flush();
    request.close();            
    String line = "";               
    InputStreamReader isr = new InputStreamReader(connection.getInputStream());
    BufferedReader reader = new BufferedReader(isr);
    StringBuilder sb = new StringBuilder();
    while ((line = reader.readLine()) != null)
    {
        sb.append(line + "\n");
    }
    String response = sb.toString();
    isr.close();
    reader.close();
    System.out.println(response);
} catch (Exception e) {
    e.printStackTrace();
}

没有 https 的网络服务链接。 我遵循this回答的指示,但这没有用。 知道Web服务或java密钥库有什么问题吗? 谢谢

1 个答案:

答案 0 :(得分:1)

几个月前,我有类似的问题。域的ssl证书未正确安装。基本上,服务器管理员为domain.com安装了证书,我使用了导致问题的链接https://www.domain.com/index.php。当我检查没有www它工作,所以我让我的服务器管理员重新安装www.domain.com的SSL证书,之后我能够访问安全链接上的数据。 我希望它有所帮助 干杯