diff --git a/zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md b/zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md index 75b3796efa3..34af68f2fa5 100644 --- a/zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md +++ b/zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md @@ -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**) diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/common/SSLContextAndOptions.java b/zookeeper-server/src/main/java/org/apache/zookeeper/common/SSLContextAndOptions.java index 51cca1af31e..053d9d5a7e8 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/common/SSLContextAndOptions.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/common/SSLContextAndOptions.java @@ -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; @@ -210,7 +210,8 @@ 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(","); } @@ -218,7 +219,7 @@ private String[] getEnabledProtocols(final ZKConfig config, final SSLContext ssl private String[] getCipherSuites(final ZKConfig config) { String cipherSuitesInput = config.getProperty(x509Util.getSslCipherSuitesProperty()); if (cipherSuitesInput == null) { - return X509Util.getDefaultCipherSuites(); + return null; } else { return cipherSuitesInput.split(","); } diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/common/X509Util.java b/zookeeper-server/src/main/java/org/apache/zookeeper/common/X509Util.java index 2f8ec88a72a..de87babc60c 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/common/X509Util.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/common/X509Util.java @@ -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; @@ -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 { @@ -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 @@ -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 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; /** @@ -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; diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/common/X509UtilTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/common/X509UtilTest.java index a4ac4754373..e10c7148dc7 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/common/X509UtilTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/common/X509UtilTest.java @@ -23,6 +23,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import io.netty.buffer.UnpooledByteBufAllocator; +import io.netty.handler.ssl.IdentityCipherSuiteFilter; +import io.netty.handler.ssl.JdkSslContext; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -31,6 +34,7 @@ import java.nio.file.Path; import java.security.NoSuchAlgorithmException; import java.security.Security; +import java.util.Arrays; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -43,6 +47,7 @@ import javax.net.ssl.HandshakeCompletedEvent; import javax.net.ssl.HandshakeCompletedListener; import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLServerSocket; import javax.net.ssl.SSLSocket; @@ -83,6 +88,7 @@ public void cleanUp() { System.clearProperty(x509Util.getSslCrlEnabledProperty()); System.clearProperty(x509Util.getCipherSuitesProperty()); System.clearProperty(x509Util.getSslProtocolProperty()); + System.clearProperty(x509Util.getSslEnabledProtocolsProperty()); System.clearProperty(x509Util.getSslHandshakeDetectionTimeoutMillisProperty()); System.clearProperty("com.sun.net.ssl.checkRevocation"); System.clearProperty("com.sun.security.enableCRLDP"); @@ -102,6 +108,13 @@ public void testCreateSSLContextWithoutCustomProtocol( init(caKeyType, certKeyType, keyPassword, paramIndex); SSLContext sslContext = x509Util.getDefaultSSLContext(); assertEquals(X509Util.DEFAULT_PROTOCOL, sslContext.getProtocol()); + boolean supportsTls13 = Arrays.asList(SSLContext.getDefault().getSupportedSSLParameters().getProtocols()) + .contains(X509Util.TLS_1_3); + assertEquals(supportsTls13 ? X509Util.TLS_1_3 : X509Util.TLS_1_2, sslContext.getProtocol()); + try (SSLSocket socket = x509Util.createSSLSocket()) { + assertArrayEquals(sslContext.getDefaultSSLParameters().getProtocols(), socket.getEnabledProtocols()); + assertArrayEquals(sslContext.getDefaultSSLParameters().getCipherSuites(), socket.getEnabledCipherSuites()); + } } @ParameterizedTest @@ -115,6 +128,9 @@ public void testCreateSSLContextWithCustomProtocol( System.setProperty(x509Util.getSslProtocolProperty(), protocol); SSLContext sslContext = x509Util.getDefaultSSLContext(); assertEquals(protocol, sslContext.getProtocol()); + try (SSLSocket socket = x509Util.createSSLSocket()) { + assertArrayEquals(sslContext.getDefaultSSLParameters().getProtocols(), socket.getEnabledProtocols()); + } } @ParameterizedTest @@ -756,13 +772,15 @@ private static void forceClose(ServerSocket s) { } // This test makes sure that client-initiated TLS renegotiation does not - // succeed. We explicitly disable it at the top of X509Util.java. + // succeed with TLSv1.2. TLSv1.3 does not support renegotiation. @ParameterizedTest @MethodSource("data") + @Timeout(value = 30) public void testClientRenegotiationFails( X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex) throws Throwable { init(caKeyType, certKeyType, keyPassword, paramIndex); + System.setProperty(x509Util.getSslEnabledProtocolsProperty(), X509Util.TLS_1_2); assertThrows(SSLHandshakeException.class, () -> { int port = PortAssignment.unique(); ExecutorService workerPool = Executors.newCachedThreadPool(); @@ -805,7 +823,7 @@ public void handshakeCompleted(HandshakeCompletedEvent handshakeCompletedEvent) clientSocket.getOutputStream().write(1); // The exception is thrown on the server side, we need to unwrap it try { - serverSocket = acceptFuture.get(); + serverSocket = acceptFuture.get(10, TimeUnit.SECONDS); } catch (ExecutionException e) { throw e.getCause(); } @@ -824,68 +842,149 @@ public void handshakeCompleted(HandshakeCompletedEvent handshakeCompletedEvent) @ParameterizedTest @MethodSource("data") - public void testGetDefaultCipherSuitesJava8( - X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex) - throws Exception { - init(caKeyType, certKeyType, keyPassword, paramIndex); - String[] cipherSuites = X509Util.getDefaultCipherSuitesForJavaVersion("1.8"); - // Java 8 default should have the CBC suites first - assertTrue(cipherSuites[0].contains("CBC")); - } - - @ParameterizedTest - @MethodSource("data") - public void testGetDefaultCipherSuitesJava9( + public void testCreateSSLContextWithoutCipherSuites( X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex) throws Exception { init(caKeyType, certKeyType, keyPassword, paramIndex); - String[] cipherSuites = X509Util.getDefaultCipherSuitesForJavaVersion("9"); - // Java 9+ default should have the GCM suites first - assertTrue(cipherSuites[0].contains("GCM")); - } - - @ParameterizedTest - @MethodSource("data") - public void testGetDefaultCipherSuitesJava10( - X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex) - throws Exception { - init(caKeyType, certKeyType, keyPassword, paramIndex); - String[] cipherSuites = X509Util.getDefaultCipherSuitesForJavaVersion("10"); - // Java 9+ default should have the GCM suites first - assertTrue(cipherSuites[0].contains("GCM")); + try (X509Util clientUtil = new ClientX509Util(); X509Util quorumUtil = new QuorumX509Util()) { + for (X509Util util : new X509Util[]{clientUtil, quorumUtil}) { + for (boolean fips : new boolean[]{false, true}) { + ZKConfig config = new ZKConfig(); + config.setProperty(util.getFipsModeProperty(), Boolean.toString(fips)); + SSLContextAndOptions options = util.createSSLContextAndOptions(config); + SSLContext context = options.getSSLContext(); + String[] protocols = context.getDefaultSSLParameters().getProtocols(); + String[] ciphers = context.getDefaultSSLParameters().getCipherSuites(); + try (SSLSocket socket = options.createSSLSocket(); + SSLServerSocket serverSocket = options.createSSLServerSocket()) { + assertArrayEquals(protocols, socket.getEnabledProtocols()); + assertArrayEquals(protocols, serverSocket.getEnabledProtocols()); + assertArrayEquals(ciphers, socket.getEnabledCipherSuites()); + assertArrayEquals(ciphers, serverSocket.getEnabledCipherSuites()); + assertTrue(serverSocket.getNeedClientAuth()); + } + SSLEngine clientEngine = context.createSSLEngine("localhost", 443); + clientEngine.setUseClientMode(true); + assertArrayEquals(protocols, clientEngine.getEnabledProtocols()); + assertArrayEquals(ciphers, clientEngine.getEnabledCipherSuites()); + SSLEngine nettyEngine = options.createNettyJdkSslContext(context) + .newEngine(UnpooledByteBufAllocator.DEFAULT); + SSLEngine expectedEngine = new JdkSslContext( + context, false, null, IdentityCipherSuiteFilter.INSTANCE, null, + io.netty.handler.ssl.ClientAuth.REQUIRE, protocols, false) + .newEngine(UnpooledByteBufAllocator.DEFAULT); + assertArrayEquals(protocols, nettyEngine.getEnabledProtocols()); + assertArrayEquals(expectedEngine.getEnabledCipherSuites(), nettyEngine.getEnabledCipherSuites()); + if (Arrays.asList(protocols).contains(X509Util.TLS_1_3)) { + String[] tls13CipherSuites = { + "TLS_AES_128_GCM_SHA256", + "TLS_AES_256_GCM_SHA384", + "TLS_CHACHA20_POLY1305_SHA256", + "TLS_AES_128_CCM_SHA256", + "TLS_AES_128_CCM_8_SHA256" + }; + assertTrue(Arrays.stream(nettyEngine.getEnabledCipherSuites()) + .anyMatch(Arrays.asList(tls13CipherSuites)::contains), + "Netty must enable a TLSv1.3 cipher suite when TLSv1.3 is enabled"); + } + assertTrue(nettyEngine.getNeedClientAuth()); + assertEquals(fips && util instanceof QuorumX509Util ? "HTTPS" : null, + nettyEngine.getSSLParameters().getEndpointIdentificationAlgorithm()); + } + } + } } @ParameterizedTest @MethodSource("data") - public void testGetDefaultCipherSuitesJava11( + public void testExplicitProtocolsAndCipherSuites( X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex) throws Exception { init(caKeyType, certKeyType, keyPassword, paramIndex); - String[] cipherSuites = X509Util.getDefaultCipherSuitesForJavaVersion("11"); - // Java 9+ default should have the GCM suites first - assertTrue(cipherSuites[0].contains("GCM")); + String[] protocols = {X509Util.TLS_1_2}; + String[] ciphers = {"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"}; + try (X509Util clientUtil = new ClientX509Util(); X509Util quorumUtil = new QuorumX509Util()) { + for (X509Util util : new X509Util[]{clientUtil, quorumUtil}) { + ZKConfig config = new ZKConfig(); + config.setProperty(util.getSslEnabledProtocolsProperty(), String.join(",", protocols)); + config.setProperty(util.getSslCipherSuitesProperty(), String.join(",", ciphers)); + SSLContextAndOptions options = util.createSSLContextAndOptions(config); + try (SSLSocket socket = options.createSSLSocket(); + SSLServerSocket serverSocket = options.createSSLServerSocket()) { + assertArrayEquals(protocols, socket.getEnabledProtocols()); + assertArrayEquals(ciphers, socket.getEnabledCipherSuites()); + assertArrayEquals(protocols, serverSocket.getEnabledProtocols()); + assertArrayEquals(ciphers, serverSocket.getEnabledCipherSuites()); + } + SSLEngine engine = options.createNettyJdkSslContext(options.getSSLContext()) + .newEngine(UnpooledByteBufAllocator.DEFAULT); + assertArrayEquals(protocols, engine.getEnabledProtocols()); + assertArrayEquals(ciphers, engine.getEnabledCipherSuites()); + } + } } @ParameterizedTest @MethodSource("data") - public void testGetDefaultCipherSuitesUnknownVersion( + public void testInvalidProtocolsAndCipherSuites( X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex) throws Exception { init(caKeyType, certKeyType, keyPassword, paramIndex); - String[] cipherSuites = X509Util.getDefaultCipherSuitesForJavaVersion("notaversion"); - // If version can't be parsed, use the more conservative Java 8 default - assertTrue(cipherSuites[0].contains("CBC")); + for (String property : new String[]{x509Util.getSslEnabledProtocolsProperty(), x509Util.getSslCipherSuitesProperty()}) { + for (String value : new String[]{"", "not-supported"}) { + ZKConfig config = new ZKConfig(); + config.setProperty(property, value); + SSLContextAndOptions options = x509Util.createSSLContextAndOptions(config); + assertThrows(IllegalArgumentException.class, options::createSSLSocket); + assertThrows(IllegalArgumentException.class, options::createSSLServerSocket); + assertThrows(IllegalArgumentException.class, () -> + options.createNettyJdkSslContext(options.getSSLContext()).newEngine(UnpooledByteBufAllocator.DEFAULT)); + } + } } @ParameterizedTest @MethodSource("data") - public void testGetDefaultCipherSuitesNullVersion( + @Timeout(value = 30) + public void testDefaultProtocolNegotiation( X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex) throws Exception { init(caKeyType, certKeyType, keyPassword, paramIndex); - assertThrows(NullPointerException.class, () -> { - X509Util.getDefaultCipherSuitesForJavaVersion(null); - }); + for (boolean pinTls12 : new boolean[]{false, true}) { + ZKConfig serverConfig = new ZKConfig(); + if (pinTls12) { + serverConfig.setProperty(x509Util.getSslEnabledProtocolsProperty(), X509Util.TLS_1_2); + } + SSLContextAndOptions options = x509Util.createSSLContextAndOptions(serverConfig); + ExecutorService worker = Executors.newSingleThreadExecutor(); + try (SSLServerSocket listener = options.createSSLServerSocket(); + SSLSocket client = x509Util.createSSLSocket()) { + listener.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); + listener.setSoTimeout(5000); + Future serverSession = worker.submit(() -> { + try (SSLSocket server = (SSLSocket) listener.accept()) { + server.setSoTimeout(5000); + server.startHandshake(); + assertEquals(1, server.getInputStream().read()); + return new String[]{server.getSession().getProtocol(), server.getSession().getCipherSuite()}; + } + }); + client.setSoTimeout(5000); + client.connect(listener.getLocalSocketAddress(), 5000); + client.startHandshake(); + client.getOutputStream().write(1); + String protocol = client.getSession().getProtocol(); + String cipher = client.getSession().getCipherSuite(); + String expectedProtocol = pinTls12 ? X509Util.TLS_1_2 + : options.getSSLContext().getDefaultSSLParameters().getProtocols()[0]; + assertEquals(expectedProtocol, protocol); + assertTrue(Arrays.asList(client.getEnabledCipherSuites()).contains(cipher)); + assertArrayEquals(new String[]{protocol, cipher}, serverSession.get(10, TimeUnit.SECONDS)); + } finally { + worker.shutdownNow(); + assertTrue(worker.awaitTermination(5, TimeUnit.SECONDS)); + } + } } // Warning: this will reset the x509Util diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/QuorumSSLTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/QuorumSSLTest.java index 48799798e16..b61327902d7 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/QuorumSSLTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/QuorumSSLTest.java @@ -63,6 +63,7 @@ import org.apache.zookeeper.client.ZKClientConfig; import org.apache.zookeeper.common.QuorumX509Util; import org.apache.zookeeper.common.SecretUtilsTest; +import org.apache.zookeeper.common.X509Util; import org.apache.zookeeper.server.ServerCnxnFactory; import org.apache.zookeeper.test.ClientBase; import org.bouncycastle.asn1.ocsp.OCSPResponse; @@ -983,7 +984,7 @@ public void testCipherSuites(boolean fipsEnabled) throws Exception { @Timeout(value = 5, unit = TimeUnit.MINUTES) public void testProtocolVersion(boolean fipsEnabled) throws Exception { System.setProperty(quorumX509Util.getFipsModeProperty(), Boolean.toString(fipsEnabled)); - System.setProperty(quorumX509Util.getSslProtocolProperty(), "TLSv1.2"); + System.setProperty(quorumX509Util.getSslProtocolProperty(), X509Util.TLS_1_2); q1 = new MainThread(1, clientPortQp1, quorumConfiguration, SSL_QUORUM_ENABLED); q2 = new MainThread(2, clientPortQp2, quorumConfiguration, SSL_QUORUM_ENABLED); @@ -994,7 +995,7 @@ public void testProtocolVersion(boolean fipsEnabled) throws Exception { assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp1, CONNECTION_TIMEOUT)); assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp2, CONNECTION_TIMEOUT)); - System.setProperty(quorumX509Util.getSslProtocolProperty(), "TLSv1.1"); + System.setProperty(quorumX509Util.getSslProtocolProperty(), X509Util.TLS_1_1); // This server should fail to join the quorum as it is not using TLSv1.2 q3 = new MainThread(3, clientPortQp3, quorumConfiguration, SSL_QUORUM_ENABLED);