Created
May 5, 2012 06:14
-
-
Save yayitswei/2600263 to your computer and use it in GitHub Desktop.
ignore ssl
This file contains 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 class MySSLSocketFactory extends SSLSocketFactory { | |
SSLContext sslContext = SSLContext.getInstance("TLS"); | |
public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { | |
super(truststore); | |
TrustManager tm = new X509TrustManager() { | |
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { | |
} | |
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { | |
} | |
public X509Certificate[] getAcceptedIssuers() { | |
return null; | |
} | |
}; | |
sslContext.init(null, new TrustManager[] { tm }, null); | |
} | |
@Override | |
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException { | |
return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose); | |
} | |
@Override | |
public Socket createSocket() throws IOException { | |
return sslContext.getSocketFactory().createSocket(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
source: http://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https