Trust Anchor not found for Android SSL Connection

后端 未结 17 826
囚心锁ツ
囚心锁ツ 2020-11-22 05:06

I am trying to connect to an IIS6 box running a godaddy 256bit SSL cert, and I am getting the error :

java.security.cert.CertPathValidatorException: Trust an         


        
17条回答
  •  长情又很酷
    2020-11-22 05:28

    I know that you don't need to trust all certificates but in my case I had problems with some debugging environments where we had self-signed certificates and I needed a dirty solution.

    All I had to do was to change the initialization of the sslContext

    mySSLContext.init(null, trustAllCerts, null); 
    

    where trustAllCerts was created like this:

    private final TrustManager[] trustAllCerts= new TrustManager[] { new X509TrustManager() {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return new java.security.cert.X509Certificate[]{};
        }
    
        public void checkClientTrusted(X509Certificate[] chain,
                                       String authType) throws CertificateException {
        }
    
        public void checkServerTrusted(X509Certificate[] chain,
                                       String authType) throws CertificateException {
        }
    } };
    

    Hope that this will come in handy.

提交回复
热议问题