Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md
Original file line number Diff line number Diff line change
Expand Up @@ -1781,20 +1781,39 @@ is an intentional access-policy change and should be qualified before rollout.
* *ssl.protocol* and *ssl.quorum.protocol* :
(Java system properties: **zookeeper.ssl.protocol** and **zookeeper.ssl.quorum.protocol**)
**New in 3.5.5:**
Specifies to protocol to be used in client and quorum TLS negotiation.
Default: TLSv1.2
Selects the SSLContext protocol for client and quorum TLS.
Default: TLSv1.3 if supported by the runtime, otherwise TLSv1.2.
Java 8 TLSv1.3 support depends on the vendor and update level; the default
is determined from runtime capabilities, not the Java major version.
Selecting a context does not restrict negotiation to a single protocol;
use `ssl.enabledProtocols` or `ssl.quorum.enabledProtocols` to do that.

The public `X509Util.DEFAULT_PROTOCOL` field is now computed at runtime.
Existing binaries compiled against the former constant may retain an
inlined TLSv1.2 value until recompiled. Upgrading the server does not
upgrade application client JARs; evaluate and upgrade clients separately.

* *ssl.enabledProtocols* and *ssl.quorum.enabledProtocols* :
(Java system properties: **zookeeper.ssl.enabledProtocols** and **zookeeper.ssl.quorum.enabledProtocols**)
**New in 3.5.5:**
Specifies the enabled protocols in client and quorum TLS negotiation.
Default: value of `protocol` property
Default: the selected SSLContext's JDK default enabled protocols.
For example, a TLSv1.3 context may enable both TLSv1.3 and TLSv1.2, subject
to the runtime's security policy. An explicit comma-separated list overrides
this default.

* *ssl.ciphersuites* and *ssl.quorum.ciphersuites* :
(Java system properties: **zookeeper.ssl.ciphersuites** and **zookeeper.ssl.quorum.ciphersuites**)
**New in 3.5.5:**
Specifies the enabled cipher suites to be used in client and quorum TLS negotiation.
Default: Enabled cipher suites depend on the Java runtime version being used.
Default: the TLS implementation's default cipher suites, including TLSv1.3
suites where available. JDK sockets use JDK defaults; Netty server engines
use Netty defaults. ZooKeeper no longer imposes a hardcoded cipher list
or Java-version-based ordering.

Explicit protocol and cipher lists continue to apply to quorum sockets and
Netty server engines. The Netty client currently uses its SSLContext's JDK
defaults and does not apply `ssl.enabledProtocols` or `ssl.ciphersuites`.

* *ssl.context.supplier.class* and *ssl.quorum.context.supplier.class* :
(Java system properties: **zookeeper.ssl.context.supplier.class** and **zookeeper.ssl.quorum.context.supplier.class**)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class SSLContextAndOptions {
this.enabledProtocols = getEnabledProtocols(requireNonNull(config), sslContext);
String[] ciphers = getCipherSuites(config);
this.cipherSuites = ciphers;
this.cipherSuitesAsList = Collections.unmodifiableList(Arrays.asList(ciphers));
this.cipherSuitesAsList = ciphers == null ? null : Collections.unmodifiableList(Arrays.asList(ciphers));
this.clientAuth = getClientAuth(config);
this.handshakeDetectionTimeoutMillis = getHandshakeDetectionTimeoutMillis(config);
this.config = config;
Expand Down Expand Up @@ -210,15 +210,16 @@ private void configureSslParameters(SSLParameters sslParameters, boolean isClien
private String[] getEnabledProtocols(final ZKConfig config, final SSLContext sslContext) {
String enabledProtocolsInput = config.getProperty(x509Util.getSslEnabledProtocolsProperty());
if (enabledProtocolsInput == null) {
return new String[]{sslContext.getProtocol()};
// Selecting a context does not pin a single enabled protocol.
return sslContext.getDefaultSSLParameters().getProtocols();
}
return enabledProtocolsInput.split(",");
}

private String[] getCipherSuites(final ZKConfig config) {
String cipherSuitesInput = config.getProperty(x509Util.getSslCipherSuitesProperty());
if (cipherSuitesInput == null) {
return X509Util.getDefaultCipherSuites();
return null;
} else {
return cipherSuitesInput.split(",");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import java.security.Security;
import java.security.cert.PKIXBuilderParameters;
import java.security.cert.X509CertSelector;
import java.util.Objects;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import javax.net.ssl.CertPathTrustManagerParameters;
Expand All @@ -57,11 +59,6 @@

/**
* Utility code for X509 handling
*
* Default cipher suites:
*
* Performance testing done by Facebook engineers shows that on Intel x86_64 machines, Java9 performs better with
* GCM and Java8 performs better with CBC, so these seem like reasonable defaults.
*/
public abstract class X509Util implements Closeable, AutoCloseable {

Expand All @@ -70,6 +67,9 @@ public abstract class X509Util implements Closeable, AutoCloseable {
private static final String REJECT_CLIENT_RENEGOTIATION_PROPERTY = "jdk.tls.rejectClientInitiatedRenegotiation";
private static final String FIPS_MODE_PROPERTY = "zookeeper.fips-mode";
private static final boolean FIPS_MODE_DEFAULT = false;
public static final String TLS_1_1 = "TLSv1.1";
public static final String TLS_1_2 = "TLSv1.2";
public static final String TLS_1_3 = "TLSv1.3";

static {
// Client-initiated renegotiation in TLS is unsafe and
Expand All @@ -83,28 +83,27 @@ public abstract class X509Util implements Closeable, AutoCloseable {
}
}

public static final String DEFAULT_PROTOCOL = "TLSv1.2";
private static String[] getGCMCiphers() {
return new String[]{"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"};
}

private static String[] getCBCCiphers() {
return new String[]{"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"};
}
/**
* Runtime-selected default. Binaries compiled against the former constant may
* retain the inlined TLSv1.2 value until recompiled.
*/
public static final String DEFAULT_PROTOCOL = defaultTlsProtocol();

private static String[] concatArrays(String[] left, String[] right) {
String[] result = new String[left.length + right.length];
System.arraycopy(left, 0, result, 0, left.length);
System.arraycopy(right, 0, result, left.length, right.length);
return result;
private static String defaultTlsProtocol() {
String defaultProtocol = TLS_1_2;
List<String> supported = Collections.emptyList();
try {
supported = Arrays.asList(SSLContext.getDefault().getSupportedSSLParameters().getProtocols());
if (supported.contains(TLS_1_3)) {
defaultProtocol = TLS_1_3;
}
} catch (NoSuchAlgorithmException e) {
// If the default context is unavailable, retain the TLSv1.2 fallback.
}
LOG.info("Default TLS protocol is {}, supported TLS protocols are {}", defaultProtocol, supported);
return defaultProtocol;
}

// On Java 8, prefer CBC ciphers since AES-NI support is lacking and GCM is slower than CBC.
private static final String[] DEFAULT_CIPHERS_JAVA8 = concatArrays(getCBCCiphers(), getGCMCiphers());
// On Java 9 and later, prefer GCM ciphers due to improved AES-NI support.
// Note that this performance assumption might not hold true for architectures other than x86_64.
private static final String[] DEFAULT_CIPHERS_JAVA9 = concatArrays(getGCMCiphers(), getCBCCiphers());

public static final int DEFAULT_HANDSHAKE_DETECTION_TIMEOUT_MILLIS = 5000;

/**
Expand Down Expand Up @@ -606,26 +605,6 @@ public SSLServerSocket createSSLServerSocket(int port) throws X509Exception, IOE
return getDefaultSSLContextAndOptions().createSSLServerSocket(port);
}

static String[] getDefaultCipherSuites() {
return getDefaultCipherSuitesForJavaVersion(System.getProperty("java.specification.version"));
}

static String[] getDefaultCipherSuitesForJavaVersion(String javaVersion) {
Objects.requireNonNull(javaVersion);
if (javaVersion.matches("\\d+")) {
// Must be Java 9 or later
LOG.debug("Using Java9+ optimized cipher suites for Java version {}", javaVersion);
return DEFAULT_CIPHERS_JAVA9;
} else if (javaVersion.startsWith("1.")) {
// Must be Java 1.8 or earlier
LOG.debug("Using Java8 optimized cipher suites for Java version {}", javaVersion);
return DEFAULT_CIPHERS_JAVA8;
} else {
LOG.debug("Could not parse java version {}, using Java8 optimized cipher suites", javaVersion);
return DEFAULT_CIPHERS_JAVA8;
}
}

private FileChangeWatcher newFileChangeWatcher(String fileLocation) throws IOException {
if (fileLocation == null || fileLocation.isEmpty()) {
return null;
Expand Down
Loading