/** * Initialize the SSL Context, factory and verifier. * * @throws NoSuchAlgorithmException * @throws KeyManagementException * @throws IOException * @throws CertificateException * @throws FileNotFoundException * @throws InvalidAlgorithmParameterException */ private synchronized void init() throws NoSuchAlgorithmException, KeyManagementException, FileNotFoundException, CertificateException, IOException, InvalidAlgorithmParameterException { if (factory == null) { TrustManager[] trustManagers = new TrustManager[0]; trustManagers = new TrustManager[] { new LocalTrustManager(verify, createCertificates(certificatesPath)) }; SSLContext context = SSLContext.getInstance("TLS"); context.init(null, trustManagers, new SecureRandom()); factory = context.getSocketFactory(); verifier = new HostnameVerifier() { @Override public boolean verify(String string, SSLSession session) { return verify; } }; } }
/** * Initialize the SSL Context, factory and verifier. * * @throws NoSuchAlgorithmException * @throws KeyManagementException * @throws IOException * @throws CertificateException * @throws FileNotFoundException * @throws InvalidAlgorithmParameterException */ private synchronized void init() throws NoSuchAlgorithmException, KeyManagementException, FileNotFoundException, CertificateException, IOException, InvalidAlgorithmParameterException { if (factory == null) { TrustManager[] trustManagers = new TrustManager[0]; trustManagers = new TrustManager[] { new LocalTrustManager(verify, createCertificates(certificatesPath)) }; SSLContext context = SSLContext.getInstance("TLS"); context.init(null, trustManagers, new SecureRandom()); factory = context.getSocketFactory(); verifier = new HostnameVerifier() { @Override public boolean verify(String string, SSLSession session) { return verify; } }; } }