Skip to content

Instantly share code, notes, and snippets.

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