/** * Set the default X509 Trust Manager to an instance of a dummy class that trust all certificates, * even the self-signed ones. * * @param protocol e.g. TLS, TLSv1.2 */ public static void trustAllHttpsCertificates( String protocol ) { // Create a trust manager that does not validate certificate chains if (instance.trustManagers == null) { synchronized (instance) { if (instance.trustManagers == null) { // if several threads had waited for entering the synchronized block instance.trustManagers = new TrustManager[]{ new DefaultTrustManager() }; // Install the all-trusting trust manager: try { trustAllSSlContext = SSLContext.getInstance(protocol); trustAllSSlContext.init(null, instance.trustManagers, null); } catch (GeneralSecurityException gse) { throw new IllegalStateException(gse.getMessage()); } HttpsURLConnection.setDefaultSSLSocketFactory(trustAllSSlContext.getSocketFactory()); } } } }
TrustManager[] trustManagers = new TrustManager[]{ new SslUtils.DefaultTrustManager() }; tmf.init(ksKeys);