Created
March 29, 2021 10:00
-
-
Save mhewedy/9cb0f3ab14c607abdd8a3e7c455be19e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static { | |
disableSslVerification(); | |
} | |
private static void disableSslVerification() { | |
try | |
{ | |
// Create a trust manager that does not validate certificate chains | |
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[] {new javax.net.ssl.X509TrustManager() { | |
public java.security.cert.X509Certificate[] getAcceptedIssuers() { | |
return null; | |
} | |
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { | |
} | |
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { | |
} | |
} | |
}; | |
// Install the all-trusting trust manager | |
javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL"); | |
sc.init(null, trustAllCerts, new java.security.SecureRandom()); | |
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); | |
// Create all-trusting host name verifier | |
javax.net.ssl.HostnameVerifier allHostsValid = new javax.net.ssl.HostnameVerifier() { | |
public boolean verify(String hostname, javax.net.ssl.SSLSession session) { | |
return true; | |
} | |
}; | |
// Install the all-trusting host verifier | |
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); | |
} catch (java.security.NoSuchAlgorithmException e) { | |
e.printStackTrace(); | |
} catch (java.security.KeyManagementException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment