1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.netty.handler.ssl.util;
18
19 import io.netty.util.internal.EmptyArrays;
20 import io.netty.util.internal.logging.InternalLogger;
21 import io.netty.util.internal.logging.InternalLoggerFactory;
22
23 import javax.net.ssl.ManagerFactoryParameters;
24 import javax.net.ssl.TrustManager;
25 import javax.net.ssl.TrustManagerFactory;
26 import javax.net.ssl.X509TrustManager;
27 import java.security.KeyStore;
28 import java.security.cert.X509Certificate;
29
30
31
32
33
34
35
36
37
38 public final class InsecureTrustManagerFactory extends SimpleTrustManagerFactory {
39
40 private static final InternalLogger logger = InternalLoggerFactory.getInstance(InsecureTrustManagerFactory.class);
41
42 public static final TrustManagerFactory INSTANCE = new InsecureTrustManagerFactory();
43
44 private static final TrustManager tm = new X509TrustManager() {
45 @Override
46 public void checkClientTrusted(X509Certificate[] chain, String s) {
47 if (logger.isDebugEnabled()) {
48 logger.debug("Accepting a client certificate: " + chain[0].getSubjectDN());
49 }
50 }
51
52 @Override
53 public void checkServerTrusted(X509Certificate[] chain, String s) {
54 if (logger.isDebugEnabled()) {
55 logger.debug("Accepting a server certificate: " + chain[0].getSubjectDN());
56 }
57 }
58
59 @Override
60 public X509Certificate[] getAcceptedIssuers() {
61 return EmptyArrays.EMPTY_X509_CERTIFICATES;
62 }
63 };
64
65 private InsecureTrustManagerFactory() { }
66
67 @Override
68 protected void engineInit(KeyStore keyStore) throws Exception { }
69
70 @Override
71 protected void engineInit(ManagerFactoryParameters managerFactoryParameters) throws Exception { }
72
73 @Override
74 protected TrustManager[] engineGetTrustManagers() {
75 return new TrustManager[] { tm };
76 }
77 }