1 20 21 package org.apache.directory.ldapstudio.browser.core.internal.model; 22 23 24 import java.io.IOException ; 25 import java.net.InetAddress ; 26 import java.net.Socket ; 27 import java.net.UnknownHostException ; 28 import java.security.SecureRandom ; 29 import java.security.cert.CertificateException ; 30 import java.security.cert.X509Certificate ; 31 32 import javax.net.SocketFactory; 33 import javax.net.ssl.SSLContext; 34 import javax.net.ssl.SSLSocketFactory; 35 import javax.net.ssl.TrustManager; 36 import javax.net.ssl.X509TrustManager; 37 38 39 public class DummySSLSocketFactory extends SSLSocketFactory 40 { 41 42 private static SocketFactory instance; 43 44 45 public static SocketFactory getDefault() 46 { 47 if ( instance == null ) 48 { 49 instance = new DummySSLSocketFactory(); 50 } 51 return instance; 52 } 53 54 private SSLSocketFactory delegate; 55 56 57 public DummySSLSocketFactory() 58 { 59 60 try 61 { 62 TrustManager tm = new X509TrustManager() 63 { 64 public X509Certificate [] getAcceptedIssuers() 65 { 66 return new X509Certificate [0]; 67 } 68 69 70 public void checkClientTrusted( X509Certificate [] arg0, String arg1 ) throws CertificateException 71 { 72 } 73 74 75 public void checkServerTrusted( X509Certificate [] arg0, String arg1 ) throws CertificateException 76 { 77 } 78 }; 79 TrustManager[] tma = 80 { tm }; 81 SSLContext sc = SSLContext.getInstance( "TLS" ); sc.init( null, tma, new SecureRandom () ); 83 delegate = sc.getSocketFactory(); 84 85 } 86 catch ( Exception e ) 87 { 88 e.printStackTrace(); 89 } 90 91 } 92 93 94 public String [] getDefaultCipherSuites() 95 { 96 return delegate.getDefaultCipherSuites(); 97 } 98 99 100 public String [] getSupportedCipherSuites() 101 { 102 return delegate.getSupportedCipherSuites(); 103 } 104 105 106 public Socket createSocket( Socket arg0, String arg1, int arg2, boolean arg3 ) throws IOException 107 { 108 try 109 { 110 return delegate.createSocket( arg0, arg1, arg2, arg3 ); 111 } 112 catch ( IOException e ) 113 { 114 e.printStackTrace(); 115 throw e; 116 } 117 } 118 119 120 public Socket createSocket( String arg0, int arg1 ) throws IOException , UnknownHostException 121 { 122 try 123 { 124 return delegate.createSocket( arg0, arg1 ); 125 } 126 catch ( IOException e ) 127 { 128 e.printStackTrace(); 129 throw e; 130 } 131 } 132 133 134 public Socket createSocket( InetAddress arg0, int arg1 ) throws IOException 135 { 136 try 137 { 138 return delegate.createSocket( arg0, arg1 ); 139 } 140 catch ( IOException e ) 141 { 142 e.printStackTrace(); 143 throw e; 144 } 145 } 146 147 148 public Socket createSocket( String arg0, int arg1, InetAddress arg2, int arg3 ) throws IOException , 149 UnknownHostException 150 { 151 try 152 { 153 return delegate.createSocket( arg0, arg1, arg2, arg3 ); 154 } 155 catch ( IOException e ) 156 { 157 e.printStackTrace(); 158 throw e; 159 } 160 } 161 162 163 public Socket createSocket( InetAddress arg0, int arg1, InetAddress arg2, int arg3 ) throws IOException 164 { 165 try 166 { 167 return delegate.createSocket( arg0, arg1, arg2, arg3 ); 168 } 169 catch ( IOException e ) 170 { 171 e.printStackTrace(); 172 throw e; 173 } 174 } 175 176 } 177 | Popular Tags |