Skip to content

Instantly share code, notes, and snippets.

@jforge
Created February 12, 2016 14:32
Show Gist options
  • Select an option

  • Save jforge/5b915f313e96663add19 to your computer and use it in GitHub Desktop.

Select an option

Save jforge/5b915f313e96663add19 to your computer and use it in GitHub Desktop.
private static TrustManager[] dummyTrustManager = new TrustManager[] { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
} };
private static HostnameVerifier dummyHostnameVerifier = ((hostname, session) -> true);
private static SSLContext dummySSLContext = null;
static {
try {
dummySSLContext = SSLContext.getInstance("SSL");
dummySSLContext.init(null, dummyTrustManager, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(dummySSLContext.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(dummyHostnameVerifier);
LOG.trace("Installed all-accepting trust-manager");
} catch (NoSuchAlgorithmException | KeyManagementException e) {
LOG.error("Could not create SSLContext: " + e.getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment