How do I initialize a TrustManagerFactory with multiple sources of trust?

后端 未结 6 1390
伪装坚强ぢ
伪装坚强ぢ 2020-12-25 15:42

My application has a personal keystore containing trusted self-signed certificates for use in the local network - say mykeystore.jks. I wish to be able to conne

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-25 16:01

    The answer here is how I came to understand how to do this. If you just want to accept the system CA certs plus a custom keystore of certs I simplified it into a single class with some convenience methods. Full code available here:

    https://gist.github.com/HughJeffner/6eac419b18c6001aeadb

    KeyStore keystore; // Get your own keystore here
    SSLContext sslContext = SSLContext.getInstance("TLS");
    TrustManager[] tm = CompositeX509TrustManager.getTrustManagers(keystore);
    sslContext.init(null, tm, null);
    

提交回复
热议问题