1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.example.securechat;
17
18 import java.security.InvalidAlgorithmParameterException;
19 import java.security.KeyStore;
20 import java.security.KeyStoreException;
21 import java.security.cert.CertificateException;
22 import java.security.cert.X509Certificate;
23
24 import javax.net.ssl.ManagerFactoryParameters;
25 import javax.net.ssl.TrustManager;
26 import javax.net.ssl.TrustManagerFactorySpi;
27 import javax.net.ssl.X509TrustManager;
28
29
30
31
32
33
34
35
36
37
38 public class SecureChatTrustManagerFactory extends TrustManagerFactorySpi {
39
40 private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() {
41 public X509Certificate[] getAcceptedIssuers() {
42 return new X509Certificate[0];
43 }
44
45 public void checkClientTrusted(
46 X509Certificate[] chain, String authType) throws CertificateException {
47
48
49
50
51 System.err.println(
52 "UNKNOWN CLIENT CERTIFICATE: " + chain[0].getSubjectDN());
53 }
54
55 public void checkServerTrusted(
56 X509Certificate[] chain, String authType) throws CertificateException {
57
58
59 System.err.println(
60 "UNKNOWN SERVER CERTIFICATE: " + chain[0].getSubjectDN());
61 }
62 };
63
64 public static TrustManager[] getTrustManagers() {
65 return new TrustManager[] { DUMMY_TRUST_MANAGER };
66 }
67
68 @Override
69 protected TrustManager[] engineGetTrustManagers() {
70 return getTrustManagers();
71 }
72
73 @Override
74 protected void engineInit(KeyStore keystore) throws KeyStoreException {
75
76 }
77
78 @Override
79 protected void engineInit(ManagerFactoryParameters managerFactoryParameters)
80 throws InvalidAlgorithmParameterException {
81
82 }
83 }