1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.miloss.fgsms.bueller;
23
24 import javax.net.ssl.TrustManager;
25 import javax.net.ssl.X509TrustManager;
26 import java.security.cert.X509Certificate;
27
28 import javax.net.ssl.X509TrustManager;
29 import java.security.cert.CertificateException;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33
34
35
36 class AuthSSLX509TrustManager implements TrustManager {
37
38 private X509TrustManager defaultTrustManager = null;
39
40
41 private static final Log LOG = LogFactory.getLog(AuthSSLX509TrustManager.class);
42
43
44
45
46 public AuthSSLX509TrustManager(final X509TrustManager defaultTrustManager) {
47 super();
48 if (defaultTrustManager == null) {
49 throw new IllegalArgumentException("Trust manager may not be null");
50 }
51 this.defaultTrustManager = defaultTrustManager;
52 }
53
54
55
56
57 public void checkClientTrusted(X509Certificate[] certificates,String authType) throws CertificateException {
58 if (LOG.isInfoEnabled() && certificates != null) {
59 for (int c = 0; c < certificates.length; c++) {
60 X509Certificate cert = certificates[c];
61 LOG.info(" Client certificate " + (c + 1) + ":");
62 LOG.info(" Subject DN: " + cert.getSubjectDN());
63 LOG.info(" Signature Algorithm: " + cert.getSigAlgName());
64 LOG.info(" Valid from: " + cert.getNotBefore() );
65 LOG.info(" Valid until: " + cert.getNotAfter());
66 LOG.info(" Issuer: " + cert.getIssuerDN());
67 }
68 }
69 defaultTrustManager.checkClientTrusted(certificates,authType);
70 }
71
72
73
74
75 public void checkServerTrusted(X509Certificate[] certificates,String authType) throws CertificateException {
76 if (LOG.isInfoEnabled() && certificates != null) {
77 for (int c = 0; c < certificates.length; c++) {
78 X509Certificate cert = certificates[c];
79 LOG.info(" Server certificate " + (c + 1) + ":");
80 LOG.info(" Subject DN: " + cert.getSubjectDN());
81 LOG.info(" Signature Algorithm: " + cert.getSigAlgName());
82 LOG.info(" Valid from: " + cert.getNotBefore() );
83 LOG.info(" Valid until: " + cert.getNotAfter());
84 LOG.info(" Issuer: " + cert.getIssuerDN());
85 }
86 }
87 defaultTrustManager.checkServerTrusted(certificates,authType);
88 }
89
90
91
92
93 public X509Certificate[] getAcceptedIssuers() {
94 return this.defaultTrustManager.getAcceptedIssuers();
95 }
96
97 }