1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.util;
21
22
23 import java.io.IOException;
24 import java.net.InetAddress;
25 import java.net.Socket;
26 import java.security.SecureRandom;
27 import java.security.cert.CertificateException;
28 import java.security.cert.X509Certificate;
29
30 import javax.net.SocketFactory;
31 import javax.net.ssl.SSLContext;
32 import javax.net.ssl.SSLSocketFactory;
33 import javax.net.ssl.TrustManager;
34 import javax.net.ssl.X509TrustManager;
35
36
37
38
39
40
41
42 public class DummySSLSocketFactory extends SSLSocketFactory
43 {
44
45
46 private static SocketFactory instance;
47
48
49
50
51
52
53
54
55
56
57 public static SocketFactory getDefault()
58 {
59 if ( instance == null )
60 {
61 instance = new DummySSLSocketFactory();
62 }
63 return instance;
64 }
65
66
67 private SSLSocketFactory delegate;
68
69
70
71
72
73 public DummySSLSocketFactory()
74 {
75 try
76 {
77 TrustManager tm = new X509TrustManager()
78 {
79 public X509Certificate[] getAcceptedIssuers()
80 {
81 return new X509Certificate[0];
82 }
83
84
85 public void checkClientTrusted( X509Certificate[] arg0, String arg1 ) throws CertificateException
86 {
87 }
88
89
90 public void checkServerTrusted( X509Certificate[] arg0, String arg1 ) throws CertificateException
91 {
92 }
93 };
94 TrustManager[] tma =
95 { tm };
96 SSLContext sc = SSLContext.getInstance( "TLS" );
97 sc.init( null, tma, new SecureRandom() );
98 delegate = sc.getSocketFactory();
99 }
100 catch ( Exception e )
101 {
102 e.printStackTrace();
103 }
104 }
105
106
107
108
109
110 public String[] getDefaultCipherSuites()
111 {
112 return delegate.getDefaultCipherSuites();
113 }
114
115
116
117
118
119 public String[] getSupportedCipherSuites()
120 {
121 return delegate.getSupportedCipherSuites();
122 }
123
124
125
126
127
128 public Socket createSocket( Socket arg0, String arg1, int arg2, boolean arg3 ) throws IOException
129 {
130 try
131 {
132 return delegate.createSocket( arg0, arg1, arg2, arg3 );
133 }
134 catch ( IOException e )
135 {
136 e.printStackTrace();
137 throw e;
138 }
139 }
140
141
142
143
144
145 public Socket createSocket( String arg0, int arg1 ) throws IOException
146 {
147 try
148 {
149 return delegate.createSocket( arg0, arg1 );
150 }
151 catch ( IOException e )
152 {
153 e.printStackTrace();
154 throw e;
155 }
156 }
157
158
159
160
161
162 public Socket createSocket( InetAddress arg0, int arg1 ) throws IOException
163 {
164 try
165 {
166 return delegate.createSocket( arg0, arg1 );
167 }
168 catch ( IOException e )
169 {
170 e.printStackTrace();
171 throw e;
172 }
173 }
174
175
176
177
178
179 public Socket createSocket( String arg0, int arg1, InetAddress arg2, int arg3 ) throws IOException
180 {
181 try
182 {
183 return delegate.createSocket( arg0, arg1, arg2, arg3 );
184 }
185 catch ( IOException e )
186 {
187 e.printStackTrace();
188 throw e;
189 }
190 }
191
192
193
194
195
196 public Socket createSocket( InetAddress arg0, int arg1, InetAddress arg2, int arg3 ) throws IOException
197 {
198 try
199 {
200 return delegate.createSocket( arg0, arg1, arg2, arg3 );
201 }
202 catch ( IOException e )
203 {
204 e.printStackTrace();
205 throw e;
206 }
207 }
208 }