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
Changes from 2 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
Expand Up @@ -50,9 +50,11 @@
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
Expand Down Expand Up @@ -119,6 +121,10 @@ public abstract class ReferenceCountedOpenSslContext extends SslContext implemen
static final boolean CLIENT_ENABLE_SESSION_CACHE =
SystemPropertyUtil.getBoolean("io.netty.handler.ssl.openssl.sessionCacheClient", false);

private static final String[] CLIENT_DEFAULT_PROTOCOLS;

private static final String[] SERVER_DEFAULT_PROTOCOLS;

/**
* The OpenSSL SSL_CTX object.
*
Expand Down Expand Up @@ -201,10 +207,32 @@ public ApplicationProtocolConfig.SelectedListenerFailureBehavior selectedListene
// ignore
}
DH_KEY_LENGTH = dhLen;

CLIENT_DEFAULT_PROTOCOLS = protocols("jdk.tls.client.protocols");
SERVER_DEFAULT_PROTOCOLS = protocols("jdk.tls.server.protocols");
}

private static 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();
if (OpenSsl.SUPPORTED_PROTOCOLS_SET.contains(p)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should log this when the protocol is defined in the jdk.tls.server.protocols but not supported by OpenSSL.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JDK is not logging as well... So I think we should also not do it.

protocols.add(p);
}
}
return protocols.toArray(new String[0]);
}
return null;
}

final boolean tlsFalseStart;

private static String[] defaultProtocols(boolean isClient) {
return isClient ? CLIENT_DEFAULT_PROTOCOLS : SERVER_DEFAULT_PROTOCOLS;
}

ReferenceCountedOpenSslContext(Iterable<String> ciphers, CipherSuiteFilter cipherFilter,
OpenSslApplicationProtocolNegotiator apn, int mode, Certificate[] keyCertChain,
ClientAuth clientAuth, String[] protocols, boolean startTls, boolean enableOcsp,
Expand Down Expand Up @@ -259,7 +287,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 ? defaultProtocols(mode == SSL.SSL_MODE_CLIENT) : protocols;
this.enableOcsp = enableOcsp;

this.keyCertChain = keyCertChain == null ? null : keyCertChain.clone();
Expand Down