1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.ssl;
17
18 import io.netty.util.internal.PlatformDependent;
19
20 import javax.net.ssl.SSLEngine;
21 import java.lang.reflect.InvocationTargetException;
22 import java.lang.reflect.Method;
23
24
25
26
27 final class Conscrypt {
28
29
30 private static final Method IS_CONSCRYPT_SSLENGINE;
31
32 static {
33 Method isConscryptSSLEngine = null;
34
35 if ((PlatformDependent.javaVersion() >= 8 &&
36
37
38 PlatformDependent.javaVersion() < 15) || PlatformDependent.isAndroid()) {
39 try {
40 Class<?> providerClass = Class.forName("org.conscrypt.OpenSSLProvider", true,
41 PlatformDependent.getClassLoader(ConscryptAlpnSslEngine.class));
42 providerClass.newInstance();
43
44 Class<?> conscryptClass = Class.forName("org.conscrypt.Conscrypt", true,
45 PlatformDependent.getClassLoader(ConscryptAlpnSslEngine.class));
46 isConscryptSSLEngine = conscryptClass.getMethod("isConscrypt", SSLEngine.class);
47 } catch (Throwable ignore) {
48
49 }
50 }
51 IS_CONSCRYPT_SSLENGINE = isConscryptSSLEngine;
52 }
53
54
55
56
57 static boolean isAvailable() {
58 return IS_CONSCRYPT_SSLENGINE != null;
59 }
60
61
62
63
64 static boolean isEngineSupported(SSLEngine engine) {
65 try {
66 return IS_CONSCRYPT_SSLENGINE != null && (Boolean) IS_CONSCRYPT_SSLENGINE.invoke(null, engine);
67 } catch (IllegalAccessException ignore) {
68 return false;
69 } catch (InvocationTargetException ex) {
70 throw new RuntimeException(ex);
71 }
72 }
73
74 private Conscrypt() { }
75 }