Created
August 19, 2015 20:09
-
-
Save cfirmo33/7f6e1c372d5b2ea9c52a to your computer and use it in GitHub Desktop.
My SSL Socket Factory
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