readthefuckingmanual.net

[SOLVED] sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Error added: 2014-08-30T10:40:46Z

0 people waiting for the answer...

1 answers found.

Answer 2535 (100.0% helpful)

This is an INSECURE answer. It will make the error go away, but you will be liable to MITM attacks, because you aren't verifying the certificates.


    TrustManager[] trustAllCerts = new TrustManager[]{
      new X509TrustManager() {
        @Override
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
          return new X509Certificate[0];
        }

        @Override
        public void checkClientTrusted(java.security.cert.X509Certificate[] certs,
                                       String authType) {
        }

        @Override
        public void checkServerTrusted(java.security.cert.X509Certificate[] certs,
                                       String authType) {
        }
      }
    };

    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new java.security.SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
Permalink

Add an answer/solution

If you know the answer, please add your own solution below.
If you don't know, but find out later, please come back and share your answer - there will be other people struggling with this too.


Please enter 61948 here

If you want to be notified via email when this is solved, enter your email address here: