Trust Anchor not found for Android SSL Connection

后端 未结 17 1081
囚心锁ツ
囚心锁ツ 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:16

    You can trust particular certificate at runtime.
    Just download it from server, put in assets and load like this using ssl-utils-android:

    OkHttpClient client = new OkHttpClient();
    SSLContext sslContext = SslUtils.getSslContextForCertificateFile(context, "BPClass2RootCA-sha2.cer");
    client.setSslSocketFactory(sslContext.getSocketFactory());
    

    In the example above I used OkHttpClient but SSLContext can be used with any client in Java.

    If you have any questions feel free to ask. I'm the author of this small library.

提交回复
热议问题