1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.gridsystems.innergrid.api;
18
19 import java.security.KeyManagementException;
20 import java.security.NoSuchAlgorithmException;
21 import java.security.cert.CertificateException;
22 import java.security.cert.X509Certificate;
23
24 import javax.net.ssl.SSLContext;
25 import javax.net.ssl.SSLSocketFactory;
26 import javax.net.ssl.TrustManager;
27 import javax.net.ssl.X509TrustManager;
28
29 import com.gridsystems.innergrid.kernel.KernelException;
30
31
32
33
34
35
36
37
38 public class AcceptAllCertificates implements SSLConnectionInfo {
39
40
41
42
43 public AcceptAllCertificates() {
44 }
45
46
47
48
49 public SSLSocketFactory getSSLSocketFactory() throws KernelException {
50 TrustManager trustman = new AcceptAllTrustManager();
51
52 try {
53 SSLContext ctx = SSLContext.getInstance("SSL");
54
55 ctx.init(null, new TrustManager[] { trustman }, null);
56
57 return (SSLSocketFactory) ctx.getSocketFactory();
58 } catch (KeyManagementException e) {
59
60 throw new CKernelException(e, "CLT031");
61 } catch (NoSuchAlgorithmException e) {
62
63 throw new CKernelException(e, "CLT031");
64 }
65 }
66
67
68
69
70 private static class AcceptAllTrustManager implements X509TrustManager {
71
72
73
74 public AcceptAllTrustManager() { }
75
76
77
78
79 public X509Certificate[] getAcceptedIssuers() {
80 return new X509Certificate[0];
81 }
82
83
84
85
86 public void checkClientTrusted(X509Certificate[] chain, String authType)
87 throws CertificateException {
88 }
89
90
91
92
93 public void checkServerTrusted(X509Certificate[] chain, String authType)
94 throws CertificateException {
95 }
96 }
97
98 }