Created
February 12, 2016 14:32
-
-
Save jforge/5b915f313e96663add19 to your computer and use it in GitHub Desktop.
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 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