Skip to content

Commit dbd32d8

Browse files
jiafu1115chia7712
authored andcommitted
MINOR: Skip testDsaKeyPair when DSA algorithm is not supported (#20967)
Background: #20961 (comment) ``` Gradle Test Run :clients:test > Gradle Test Executor 7 > SslTransportLayerTest > testDsaKeyPair(Args) > "testDsaKeyPair(Args).args=tlsProtocol=TLSv1.2, useInlinePem=true" FAILED org.opentest4j.AssertionFailedError: Channel 0 was not ready after 30 seconds ==> expected: <true> but was: <false> at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151) at app//org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132) at app//org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63) at app//org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36) at app//org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:214) at app//org.apache.kafka.common.network.NetworkTestUtils.waitForChannelReady(NetworkTestUtils.java:107) at app//org.apache.kafka.common.network.NetworkTestUtils.checkClientConnection(NetworkTestUtils.java:70) at app//org.apache.kafka.common.network.SslTransportLayerTest.verifySslConfigs(SslTransportLayerTest.java:1326) at app//org.apache.kafka.common.network.SslTransportLayerTest.testDsaKeyPair(SslTransportLayerTest.java:483) ``` Reviewers: Gaurav Narula <[email protected]>, Chia-Ping Tsai <[email protected]>
1 parent 5a7aa4d commit dbd32d8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

clients/src/test/java/org/apache/kafka/common/network/SslTransportLayerTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import java.nio.channels.SocketChannel;
5656
import java.nio.charset.StandardCharsets;
5757
import java.util.ArrayList;
58+
import java.util.Arrays;
5859
import java.util.Collection;
5960
import java.util.Collections;
6061
import java.util.HashMap;
@@ -78,6 +79,7 @@
7879
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
7980
import static org.junit.jupiter.api.Assertions.assertThrows;
8081
import static org.junit.jupiter.api.Assertions.assertTrue;
82+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
8183
import static org.mockito.ArgumentMatchers.any;
8284
import static org.mockito.Mockito.doReturn;
8385
import static org.mockito.Mockito.doThrow;
@@ -475,6 +477,8 @@ public void testClientAuthenticationRequestedNotProvided(Args args) throws Excep
475477
@ArgumentsSource(SslTransportLayerArgumentsForTLS2Provider.class)
476478
public void testDsaKeyPair(Args args) throws Exception {
477479
// DSA algorithms are not supported for TLSv1.3.
480+
// Skip test if DSA is not supported by the JVM
481+
assumeTrue(isDsaSupported(), "DSA algorithm is not supported by this JVM");
478482
args.serverCertStores = certBuilder(true, "server", args.useInlinePem).keyAlgorithm("DSA").build();
479483
args.clientCertStores = certBuilder(false, "client", args.useInlinePem).keyAlgorithm("DSA").build();
480484
args.sslServerConfigs = args.getTrustingConfig(args.serverCertStores, args.clientCertStores);
@@ -1346,6 +1350,39 @@ private static CertStores.Builder certBuilder(boolean isServer, String cn, boole
13461350
.usePem(useInlinePem);
13471351
}
13481352

1353+
/**
1354+
* Check if DSA algorithm is supported by the JVM and if there are compatible cipher suites
1355+
* available for TLSv1.2. This is important because even if DSA KeyPairGenerator is available,
1356+
* the SSL handshake may fail if no DSA-compatible cipher suites are available.
1357+
* @return true if DSA KeyPairGenerator is available and DSA-compatible cipher suites exist, false otherwise
1358+
*/
1359+
private static boolean isDsaSupported() {
1360+
// First check if DSA KeyPairGenerator is available
1361+
try {
1362+
java.security.KeyPairGenerator.getInstance("DSA");
1363+
} catch (java.security.NoSuchAlgorithmException e) {
1364+
return false;
1365+
}
1366+
1367+
// Check if there are DSA-compatible cipher suites available for TLSv1.2
1368+
// DSA algorithms are not supported for TLSv1.3, so we only check TLSv1.2
1369+
try {
1370+
SSLContext context = SSLContext.getInstance("TLSv1.2");
1371+
context.init(null, null, null);
1372+
SSLParameters params = context.getDefaultSSLParameters();
1373+
String[] cipherSuites = params.getCipherSuites();
1374+
1375+
// Check if any cipher suite supports DSA
1376+
// In TLS standards and JVM implementations, DSA signature cipher suites use "_DSS_" naming
1377+
// Common patterns: TLS_DHE_DSS_*, TLS_DH_DSS_*, SSL_DHE_DSS_*, SSL_DH_DSS_*
1378+
return Arrays.stream(cipherSuites)
1379+
.anyMatch(suite -> suite.contains("_DSS_"));
1380+
} catch (Exception e) {
1381+
// If we can't check cipher suites, assume DSA is not fully supported
1382+
return false;
1383+
}
1384+
}
1385+
13491386
@FunctionalInterface
13501387
private interface FailureAction {
13511388
FailureAction NO_OP = () -> { };

0 commit comments

Comments
 (0)