Created
June 22, 2017 11:49
-
-
Save aigor/cc14e1880ac59b428b8e500d92ffa5d6 to your computer and use it in GitHub Desktop.
SSL without certificate check
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
| private SSLContext noCheckSslContext() throws GeneralSecurityException { | |
| // Create a trust manager that does not validate certificate chains | |
| TrustManager[] trustAllCerts = new TrustManager[] { | |
| new X509TrustManager() { | |
| public X509Certificate[] getAcceptedIssuers() { | |
| return new X509Certificate[0]; | |
| } | |
| public void checkClientTrusted( | |
| X509Certificate[] certs, String authType) { | |
| } | |
| public void checkServerTrusted( | |
| X509Certificate[] certs, String authType) { | |
| } | |
| } | |
| }; | |
| // Install the all-trusting trust manager | |
| SSLContext allowAllCertificates; | |
| allowAllCertificates = SSLContext.getInstance("SSL"); | |
| allowAllCertificates.init(null, trustAllCerts, new java.security.SecureRandom()); | |
| HttpsURLConnection.setDefaultSSLSocketFactory(allowAllCertificates.getSocketFactory()); | |
| return allowAllCertificates; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment