1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.security.util; |
18 |
|
|
19 |
|
import java.io.IOException; |
20 |
|
import java.net.InetAddress; |
21 |
|
import java.net.Socket; |
22 |
|
import java.net.UnknownHostException; |
23 |
|
import java.security.KeyManagementException; |
24 |
|
import java.security.NoSuchAlgorithmException; |
25 |
|
import java.security.SecureRandom; |
26 |
|
import java.security.cert.CertificateException; |
27 |
|
import java.security.cert.X509Certificate; |
28 |
|
import javax.net.ssl.X509TrustManager; |
29 |
|
import javax.net.SocketFactory; |
30 |
|
import javax.net.ssl.SSLContext; |
31 |
|
import javax.net.ssl.SSLSocketFactory; |
32 |
|
import javax.net.ssl.TrustManager; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
public class GullibleSSLSocketFactory extends SSLSocketFactory { |
44 |
|
|
45 |
|
class GullibleTrustManager implements X509TrustManager |
46 |
|
{ |
47 |
|
GullibleTrustManager() { } |
48 |
|
public void checkClientTrusted(final X509Certificate[] chain, class="keyword">final String authType) throws CertificateException { |
49 |
|
} |
50 |
|
|
51 |
|
public void checkServerTrusted(final X509Certificate[] chain, class="keyword">final String authType) throws CertificateException { |
52 |
|
} |
53 |
|
|
54 |
|
public X509Certificate[] getAcceptedIssuers() { |
55 |
|
return new X509Certificate[0]; |
56 |
|
} |
57 |
|
} |
58 |
|
|
59 |
|
private SSLSocketFactory factory; |
60 |
0 |
protected GullibleSSLSocketFactory() { |
61 |
|
try { |
62 |
0 |
SSLContext context = SSLContext.getInstance("TLS"); |
63 |
0 |
context.init(null, new TrustManager[] {class="keyword">new GullibleTrustManager()}, |
64 |
|
new SecureRandom()); |
65 |
0 |
factory = context.getSocketFactory(); |
66 |
0 |
} catch (NoSuchAlgorithmException e) { |
67 |
0 |
e.printStackTrace(); |
68 |
0 |
} catch (KeyManagementException e) { |
69 |
0 |
e.printStackTrace(); |
70 |
0 |
} |
71 |
0 |
} |
72 |
|
public static SocketFactory getDefault() { |
73 |
0 |
return new GullibleSSLSocketFactory(); |
74 |
|
} |
75 |
|
public String[] getDefaultCipherSuites() { |
76 |
0 |
return factory.getDefaultCipherSuites(); |
77 |
|
} |
78 |
|
public String[] getSupportedCipherSuites() { |
79 |
0 |
return factory.getSupportedCipherSuites(); |
80 |
|
} |
81 |
|
public Socket createSocket(final Socket s, class="keyword">final String host, class="keyword">final int port, class="keyword">final boolean autoClose) throws IOException { |
82 |
0 |
return factory.createSocket(s, host, port, autoClose); |
83 |
|
} |
84 |
|
public Socket createSocket(final String host, class="keyword">final int port) throws IOException, UnknownHostException { |
85 |
0 |
return factory.createSocket(host, port); |
86 |
|
} |
87 |
|
public Socket createSocket(final String host, class="keyword">final int port, class="keyword">final InetAddress localAddress, class="keyword">final int localPort) throws IOException, UnknownHostException { |
88 |
0 |
return factory.createSocket(host, port, localAddress, localPort); |
89 |
|
} |
90 |
|
public Socket createSocket(final InetAddress host, class="keyword">final int port) throws IOException { |
91 |
0 |
return factory.createSocket(host, port); |
92 |
|
} |
93 |
|
public Socket createSocket(final InetAddress address, class="keyword">final int port, class="keyword">final InetAddress localAddress, class="keyword">final int localPort) throws IOException { |
94 |
0 |
return factory.createSocket(address, port, localAddress, localPort); |
95 |
|
} |
96 |
|
} |