Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.net.Socket;
  3. import java.net.UnknownHostException;
  4. import java.security.KeyManagementException;
  5. import java.security.KeyStore;
  6. import java.security.KeyStoreException;
  7. import java.security.NoSuchAlgorithmException;
  8. import java.security.UnrecoverableKeyException;
  9. import java.security.cert.CertificateException;
  10. import java.security.cert.X509Certificate;
  11.  
  12. import javax.net.ssl.SSLContext;
  13. import javax.net.ssl.TrustManager;
  14. import javax.net.ssl.X509TrustManager;
  15.  
  16. import org.apache.http.conn.ssl.SSLSocketFactory;
  17. public class MySSLSocketFactory extends SSLSocketFactory {
  18. SSLContext sslContext = SSLContext.getInstance("TLS");
  19.  
  20. public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
  21. super(truststore);
  22.  
  23. TrustManager tm = new X509TrustManager() {
  24. public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
  25. }
  26.  
  27. public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
  28. }
  29.  
  30. public X509Certificate[] getAcceptedIssuers() {
  31. return null;
  32. }
  33. };
  34.  
  35. sslContext.init(null, new TrustManager[] { tm }, null);
  36. }
  37.  
  38. @Override
  39. public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
  40. return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
  41. }
  42.  
  43. @Override
  44. public Socket createSocket() throws IOException {
  45. return sslContext.getSocketFactory().createSocket();
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement