Created
July 29, 2014 13:15
-
-
Save pmauduit/f2901a87a3ea86f23360 to your computer and use it in GitHub Desktop.
Get rid of SSL checks in Java
This file contains hidden or 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
// don't really care of SSL issues ... | |
public static void disableCertificates() { | |
TrustManager[] trustAllCerts = new TrustManager[]{ | |
new X509TrustManager() { | |
@Override | |
public java.security.cert.X509Certificate[] getAcceptedIssuers() { | |
return null; | |
} | |
@Override | |
public void checkClientTrusted( | |
java.security.cert.X509Certificate[] certs, String authType) { | |
} | |
@Override | |
public void checkServerTrusted( | |
java.security.cert.X509Certificate[] certs, String authType) { | |
} | |
} | |
}; | |
// Install the all-trusting trust manager | |
try { | |
SSLContext sc = SSLContext.getInstance("SSL"); | |
sc.init(null, trustAllCerts, new java.security.SecureRandom()); | |
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); | |
} catch (Exception e) { | |
} | |
} | |
static { disableCertificates(); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment