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