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 javax.net.ssl.ManagerFactoryParameters;
19 import javax.net.ssl.TrustManager;
20 import javax.net.ssl.TrustManagerFactorySpi;
21 import javax.net.ssl.X509TrustManager;
22 import java.security.InvalidAlgorithmParameterException;
23 import java.security.KeyStore;
24 import java.security.KeyStoreException;
25 import java.security.cert.X509Certificate;
26
27
28
29
30
31 public class SecureChatTrustManagerFactory extends TrustManagerFactorySpi {
32
33 private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() {
34 public X509Certificate[] getAcceptedIssuers() {
35 return new X509Certificate[0];
36 }
37
38 public void checkClientTrusted(X509Certificate[] chain, String authType) {
39
40
41
42
43 System.err.println(
44 "UNKNOWN CLIENT CERTIFICATE: " + chain[0].getSubjectDN());
45 }
46
47 public void checkServerTrusted(X509Certificate[] chain, String authType) {
48
49
50 System.err.println(
51 "UNKNOWN SERVER CERTIFICATE: " + chain[0].getSubjectDN());
52 }
53 };
54
55 public static TrustManager[] getTrustManagers() {
56 return new TrustManager[] { DUMMY_TRUST_MANAGER };
57 }
58
59 @Override
60 protected TrustManager[] engineGetTrustManagers() {
61 return getTrustManagers();
62 }
63
64 @Override
65 protected void engineInit(KeyStore keystore) throws KeyStoreException {
66
67 }
68
69 @Override
70 protected void engineInit(ManagerFactoryParameters managerFactoryParameters)
71 throws InvalidAlgorithmParameterException {
72
73 }
74 }