Skip to content

Instantly share code, notes, and snippets.

@toandv
Created November 21, 2017 03:06
Show Gist options
  • Save toandv/254e483e13f1c1f377ad4c0b0f0c1d3a to your computer and use it in GitHub Desktop.
Save toandv/254e483e13f1c1f377ad4c0b0f0c1d3a to your computer and use it in GitHub Desktop.
public static void trustSelfSignedSSL() {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLContext.setDefault(ctx);
HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true);
} catch (Exception ex) {
LOG.error(ex.getMessage(), ex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment