IgnoreHostsTrustManager extends X509ExtendedTrustManager { static IgnoreHostsTrustManager of(Set<String> insecureHosts) { X509ExtendedTrustManager delegate = null; try { final TrustManagerFactory trustManagerFactory = TrustManagerFactory .getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init((KeyStore) null); final TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); for (TrustManager tm : trustManagers) { if (tm instanceof X509ExtendedTrustManager) { delegate = (X509ExtendedTrustManager) tm; break; } } } catch (GeneralSecurityException ignored) { } requireNonNull(delegate, "cannot resolve default trust manager"); return new IgnoreHostsTrustManager(delegate, ImmutableSet.copyOf(insecureHosts)); } IgnoreHostsTrustManager(X509ExtendedTrustManager delegate, Set<String> insecureHosts); @Override void checkServerTrusted(X509Certificate[] x509Certificates, String authType, Socket socket); @Override void checkServerTrusted(X509Certificate[] x509Certificates, String authType, SSLEngine sslEngine); @Override void checkServerTrusted(X509Certificate[] x509Certificates, String authType); @Override void checkClientTrusted(X509Certificate[] x509Certificates, String authType, Socket socket); @Override void checkClientTrusted(X509Certificate[] x509Certificates, String authType, SSLEngine sslEngine); @Override void checkClientTrusted(X509Certificate[] x509Certificates, String authType); @Override X509Certificate[] getAcceptedIssuers();  }
@Test void testCreate() { assertThat(IgnoreHostsTrustManager.of(ImmutableSet.of("localhost"))).isNotNull(); }