Created
March 24, 2015 14:34
-
-
Save jbruchanov/20bafe030a512e1dc332 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
HttpURLConnection hc = (HttpURLConnection) connection; | |
HttpsURLConnection huc = (HttpsURLConnection) hc; | |
huc.setHostnameVerifier(mHostnameVerifier); | |
huc.setSSLSocketFactory(initSSLSocketFactory(new FakeTrustManager())); | |
private SSLSocketFactory initSSLSocketFactory(manager) | |
throws KeyManagementException, NoSuchAlgorithmException { | |
// Install the all-trusting trust manager | |
final SSLContext sslContext = SSLContext.getInstance("SSL"); | |
sslContext.init(null, new TrustManager[]{manager}, | |
new java.security.SecureRandom()); | |
// Create an ssl socket factory with our all-trusting manager | |
return sslContext.getSocketFactory(); | |
} | |
public class FakeTrustManager implements X509TrustManager { | |
@Override | |
public void checkClientTrusted(X509Certificate[] chain, String authType) | |
throws CertificateException { | |
} | |
@Override | |
public void checkServerTrusted(X509Certificate[] chain, String authType) | |
throws CertificateException { | |
} | |
@Override | |
public X509Certificate[] getAcceptedIssuers() { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment