Skip to content

Commit 96ff690

Browse files
authored
ZOOKEEPER-5054: Netty client should allow every supported TLS ciphers…
Reviewers: anmolnar Author: meszibalu Closes #2469 from meszibalu/zookeeper-5054
1 parent 389f0cd commit 96ff690

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

‎zookeeper-server/src/test/java/org/apache/zookeeper/common/X509UtilTest.java‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import java.security.NoSuchAlgorithmException;
3838
import java.util.Arrays;
3939
import java.util.List;
40+
import java.util.Set;
41+
import java.util.TreeSet;
4042
import java.util.concurrent.Callable;
4143
import java.util.concurrent.CountDownLatch;
4244
import java.util.concurrent.ExecutionException;
@@ -823,27 +825,33 @@ public void testCreateSSLContext_hostnameVerificationNoCustomTrustStore(X509KeyT
823825

824826
@ParameterizedTest
825827
@MethodSource("data")
826-
public void testCreateSSLContext_ChaCha20Cipher(X509KeyType caKeyType,
828+
public void testCreateSSLContext_AllClientCiphers(X509KeyType caKeyType,
827829
X509KeyType certKeyType, String keyPassword, Integer paramIndex) throws Exception {
828830
init(caKeyType, certKeyType, keyPassword, paramIndex);
829831

830-
// TLS_CHACHA20_POLY1305_SHA256 cipher is a mandatory cipher suite on TLSv1.3,
831-
// so a client with default configuration must support it.
832+
// Netty has an own list of supported ciphers, which is a subset of
833+
// JVM's available cipher suites. A client ssl engine must support every
834+
// cipher which is supported by the JVM.
832835

833-
ZKConfig zkConfig = new ZKConfig();
834-
zkConfig.setProperty(x509Util.getSslEnabledProtocolsProperty(), "TLSv1.3");
836+
SSLContext defaultContext = SSLContext.getInstance("TLSv1.3");
837+
defaultContext.init(null, null, null);
838+
839+
String[] defaultCipherArray = defaultContext.getSupportedSSLParameters().getCipherSuites();
840+
Set<String> defaultCipherSet = new TreeSet<>(Arrays.asList(defaultCipherArray));
835841

836842
try (ClientX509Util clientX509Util = new ClientX509Util()) {
837-
SslContext context = clientX509Util.createNettySslContextForClient(zkConfig);
843+
ZKConfig config = new ZKConfig();
844+
config.setProperty(x509Util.getSslEnabledProtocolsProperty(), "TLSv1.3");
845+
846+
SslContext clientContext = clientX509Util.createNettySslContextForClient(config);
838847

839848
UnpooledByteBufAllocator byteBufAllocator = new UnpooledByteBufAllocator(false);
840-
SSLEngine engine = context.newEngine(byteBufAllocator);
849+
SSLEngine engine = clientContext.newEngine(byteBufAllocator);
841850

842-
String[] enabledProtocols = engine.getEnabledProtocols();
843-
assertArrayEquals(new String[] { "TLSv1.3" }, enabledProtocols);
851+
String[] clientCipherArray = engine.getEnabledCipherSuites();
852+
Set<String> clientCipherSet = new TreeSet<>(Arrays.asList(clientCipherArray));
844853

845-
List<String> enabledCipherSuites = Arrays.asList(engine.getEnabledCipherSuites());
846-
assertTrue(enabledCipherSuites.contains("TLS_CHACHA20_POLY1305_SHA256"));
854+
assertEquals(defaultCipherSet, clientCipherSet);
847855
}
848856
}
849857

0 commit comments

Comments
 (0)