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.Method;
22
23
24
25
26 final class Conscrypt {
27
28
29 private static final Class<?> CONSCRYPT_CLASS = getConscryptClass();
30
31
32
33
34 static boolean isAvailable() {
35 return CONSCRYPT_CLASS != null && PlatformDependent.javaVersion() >= 8;
36 }
37
38 static boolean isEngineSupported(SSLEngine engine) {
39 return isAvailable() && isConscryptEngine(engine, CONSCRYPT_CLASS);
40 }
41
42 private static Class<?> getConscryptClass() {
43 try {
44 Class<?> conscryptClass = Class.forName("org.conscrypt.Conscrypt", true,
45 ConscryptAlpnSslEngine.class.getClassLoader());
46
47 getIsConscryptMethod(conscryptClass);
48 return conscryptClass;
49 } catch (Throwable ignore) {
50
51 return null;
52 }
53 }
54
55 private static boolean isConscryptEngine(SSLEngine engine, Class<?> conscryptClass) {
56 try {
57 Method method = getIsConscryptMethod(conscryptClass);
58 return (Boolean) method.invoke(null, engine);
59 } catch (Throwable ignore) {
60 return false;
61 }
62 }
63
64 private static Method getIsConscryptMethod(Class<?> conscryptClass) throws NoSuchMethodException {
65 return conscryptClass.getMethod("isConscrypt", SSLEngine.class);
66 }
67
68 private Conscrypt() { }
69 }