Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect jdk.tls.client.protocols and jdk.tls.server.protocols #12797

Merged
merged 4 commits into from Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions handler/src/main/java/io/netty/handler/ssl/OpenSsl.java
Expand Up @@ -39,6 +39,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;
Expand All @@ -65,6 +66,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<String> CLIENT_DEFAULT_PROTOCOLS;
private static final Set<String> SERVER_DEFAULT_PROTOCOLS;
static final Set<String> SUPPORTED_PROTOCOLS_SET;
static final String[] EXTRA_SUPPORTED_TLS_1_3_CIPHERS;
static final String EXTRA_SUPPORTED_TLS_1_3_CIPHERS_STRING;
Expand Down Expand Up @@ -179,6 +182,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());
Expand Down Expand Up @@ -720,6 +725,33 @@ static boolean isTlsv13Supported() {
return TLSV13_SUPPORTED;
}

private static Set<String> protocols(String property) {
String protocolsString = SystemPropertyUtil.get(property, null);
if (protocolsString != null) {
Set<String> protocols = new HashSet<String>();
for (String proto : protocolsString.split(",")) {
String p = proto.trim();
protocols.add(p);
}
return protocols;
}
return null;
}

static String[] defaultProtocols(boolean isClient) {
final Collection<String> defaultProtocols = isClient ? CLIENT_DEFAULT_PROTOCOLS : SERVER_DEFAULT_PROTOCOLS;
if (defaultProtocols == null) {
return null;
}
List<String> protocols = new ArrayList<String>(defaultProtocols.size());
for (String proto : defaultProtocols) {
if (SUPPORTED_PROTOCOLS_SET.contains(proto)) {
protocols.add(proto);
}
}
return protocols.toArray(new String[0]);
}

static boolean isBoringSSL() {
return IS_BORINGSSL;
}
Expand Down
Expand Up @@ -259,7 +259,7 @@ public ApplicationProtocolConfig.SelectedListenerFailureBehavior selectedListene
leak = leakDetection ? leakDetector.track(this) : null;
this.mode = mode;
this.clientAuth = isServer() ? checkNotNull(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();
Expand Down