From 2923f335309812f0aad58ac9ebfdacdaf9579d3a Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Thu, 1 Feb 2018 16:48:09 -0800 Subject: [PATCH] Adapt to API changes in Conscrypt 1.0.0.RC11 Motivation: In google/conscrypt#313 the Conscrypt.Engines class was removed in favor of methods directly on Conscrypt and overloading. The Conscrypt-using code in Netty used reflection to access the old API, that doesn't exist anymore. And thus recent versions of Conscrypt fail to enable things like ALPN with Netty. Modifications: Instead of calling Conscrypt.Engines.isConscrypt, call Conscrypt.isConscrypt. Result: Conscrypt detected properly at runtime. --- .../java/io/netty/handler/ssl/Conscrypt.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/handler/src/main/java/io/netty/handler/ssl/Conscrypt.java b/handler/src/main/java/io/netty/handler/ssl/Conscrypt.java index d50333ea54..a75fa3ba23 100644 --- a/handler/src/main/java/io/netty/handler/ssl/Conscrypt.java +++ b/handler/src/main/java/io/netty/handler/ssl/Conscrypt.java @@ -26,44 +26,43 @@ import java.lang.reflect.Method; final class Conscrypt { // This class exists to avoid loading other conscrypt related classes using features only available in JDK8+, // because we need to maintain JDK6+ runtime compatibility. - private static final Class ENGINES_CLASS = getEnginesClass(); + private static final Class CONSCRYPT_CLASS = getConscryptClass(); /** * Indicates whether or not conscrypt is available on the current system. */ static boolean isAvailable() { - return ENGINES_CLASS != null && PlatformDependent.javaVersion() >= 8; + return CONSCRYPT_CLASS != null && PlatformDependent.javaVersion() >= 8; } static boolean isEngineSupported(SSLEngine engine) { - return isAvailable() && isConscryptEngine(engine, ENGINES_CLASS); + return isAvailable() && isConscryptEngine(engine, CONSCRYPT_CLASS); } - private static Class getEnginesClass() { + private static Class getConscryptClass() { try { - // Always use bootstrap class loader. - Class engineClass = Class.forName("org.conscrypt.Conscrypt$Engines", true, + Class conscryptClass = Class.forName("org.conscrypt.Conscrypt", true, ConscryptAlpnSslEngine.class.getClassLoader()); // Ensure that it also has the isConscrypt method. - getIsConscryptMethod(engineClass); - return engineClass; + getIsConscryptMethod(conscryptClass); + return conscryptClass; } catch (Throwable ignore) { // Conscrypt was not loaded. return null; } } - private static boolean isConscryptEngine(SSLEngine engine, Class enginesClass) { + private static boolean isConscryptEngine(SSLEngine engine, Class conscryptClass) { try { - Method method = getIsConscryptMethod(enginesClass); + Method method = getIsConscryptMethod(conscryptClass); return (Boolean) method.invoke(null, engine); } catch (Throwable ignore) { return false; } } - private static Method getIsConscryptMethod(Class enginesClass) throws NoSuchMethodException { - return enginesClass.getMethod("isConscrypt", SSLEngine.class); + private static Method getIsConscryptMethod(Class conscryptClass) throws NoSuchMethodException { + return conscryptClass.getMethod("isConscrypt", SSLEngine.class); } private Conscrypt() { }