diff --git a/handler/src/main/java/io/netty5/handler/ssl/OpenSsl.java b/handler/src/main/java/io/netty5/handler/ssl/OpenSsl.java index 45a7417941b..45bd521e785 100644 --- a/handler/src/main/java/io/netty5/handler/ssl/OpenSsl.java +++ b/handler/src/main/java/io/netty5/handler/ssl/OpenSsl.java @@ -33,6 +33,7 @@ import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashSet; @@ -64,6 +65,8 @@ public final class OpenSsl { private static final boolean SUPPORTS_OCSP; private static final boolean TLSV13_SUPPORTED; private static final boolean IS_BORINGSSL; + private static final Set CLIENT_DEFAULT_PROTOCOLS; + private static final Set SERVER_DEFAULT_PROTOCOLS; static final Set SUPPORTED_PROTOCOLS_SET; static final String[] EXTRA_SUPPORTED_TLS_1_3_CIPHERS; static final String EXTRA_SUPPORTED_TLS_1_3_CIPHERS_STRING; @@ -178,6 +181,8 @@ public final class OpenSsl { } UNAVAILABILITY_CAUSE = cause; + CLIENT_DEFAULT_PROTOCOLS = protocols("jdk.tls.client.protocols"); + SERVER_DEFAULT_PROTOCOLS = protocols("jdk.tls.server.protocols"); if (cause == null) { logger.debug("netty-tcnative using native library: {}", SSL.versionString()); @@ -678,6 +683,33 @@ static boolean isTlsv13Supported() { return TLSV13_SUPPORTED; } + private static Set protocols(String property) { + String protocolsString = SystemPropertyUtil.get(property, null); + if (protocolsString != null) { + Set protocols = new HashSet<>(); + for (String proto : protocolsString.split(",")) { + String p = proto.trim(); + protocols.add(p); + } + return protocols; + } + return null; + } + + static String[] defaultProtocols(boolean isClient) { + final Collection defaultProtocols = isClient ? CLIENT_DEFAULT_PROTOCOLS : SERVER_DEFAULT_PROTOCOLS; + if (defaultProtocols == null) { + return null; + } + List protocols = new ArrayList<>(defaultProtocols.size()); + for (String proto : defaultProtocols) { + if (SUPPORTED_PROTOCOLS_SET.contains(proto)) { + protocols.add(proto); + } + } + return protocols.toArray(EmptyArrays.EMPTY_STRINGS); + } + static boolean isBoringSSL() { return IS_BORINGSSL; } diff --git a/handler/src/main/java/io/netty5/handler/ssl/ReferenceCountedOpenSslContext.java b/handler/src/main/java/io/netty5/handler/ssl/ReferenceCountedOpenSslContext.java index b5d844378fb..2fdd6f08387 100644 --- a/handler/src/main/java/io/netty5/handler/ssl/ReferenceCountedOpenSslContext.java +++ b/handler/src/main/java/io/netty5/handler/ssl/ReferenceCountedOpenSslContext.java @@ -260,7 +260,7 @@ public ApplicationProtocolConfig.SelectedListenerFailureBehavior selectedListene leak = leakDetection ? leakDetector.track(this) : null; this.mode = mode; this.clientAuth = isServer() ? requireNonNull(clientAuth, "clientAuth") : ClientAuth.NONE; - this.protocols = protocols; + this.protocols = protocols == null ? OpenSsl.defaultProtocols(mode == SSL.SSL_MODE_CLIENT) : protocols; this.enableOcsp = enableOcsp; this.keyCertChain = keyCertChain == null ? null : keyCertChain.clone();