Created
August 30, 2018 06:51
-
-
Save lokeshh/88e1b9cca001a5e189cc68fcb17573e5 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
public static void trustSelfSignedSSL() { | |
// TODO: Do not use self signed certificate | |
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { | |
public boolean verify(String hostname, SSLSession sslSession) { | |
return true; | |
} | |
}); | |
try { | |
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; | |
} | |
}; | |
SSLContext ctx = SSLContext.getInstance("TLS"); | |
ctx.init(null, new TrustManager[] { tm }, null); | |
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); | |
} catch (Exception ex) { | |
ex.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment