public static SSLSocketFactory createSocketFactory ( Collection < KeyStore > extraStores ) throws KeyStoreException , KeyManagementException { final Collection < X509TrustManager > managers = new ArrayList <> ( ) ; for ( KeyStore ks : extraStores ) { addX509Managers ( managers , ks ) ; } /* Add default manager. */ addX509Managers ( managers , null ) ; final TrustManager tm = new CompositeTrustManager ( managers ) ; try { final SSLContext ctx = SSLContext . getInstance ( "SSL" ) ; ctx . init ( null , new TrustManager [ ] { tm } , null ) ; return new SSLSocketFactory ( ctx ) ; } catch ( NoSuchAlgorithmException e ) { throw new Error ( "No SSL protocols supported :(" , e ) ; } }
Creates a new SSL socket factory which supports both system - installed keys and all additional keys in the provided keystores .