Skip to content

Commit 21c28bb

Browse files
jiafu1115chia7712
authored andcommitted
MINOR: Skip testDsaKeyPair when DSA algorithm is not supported (apache#20967)
Background: apache#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 ebd46cc commit 21c28bb

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;
@@ -476,6 +478,8 @@ public void testClientAuthenticationRequestedNotProvided(Args args) throws Excep
476478
@ArgumentsSource(SslTransportLayerArgumentsForTLS2Provider.class)
477479
public void testDsaKeyPair(Args args) throws Exception {
478480
// DSA algorithms are not supported for TLSv1.3.
481+
// Skip test if DSA is not supported by the JVM
482+
assumeTrue(isDsaSupported(), "DSA algorithm is not supported by this JVM");
479483
args.serverCertStores = certBuilder(true, "server", args.useInlinePem).keyAlgorithm("DSA").build();
480484
args.clientCertStores = certBuilder(false, "client", args.useInlinePem).keyAlgorithm("DSA").build();
481485
args.sslServerConfigs = args.getTrustingConfig(args.serverCertStores, args.clientCertStores);
@@ -1345,6 +1349,39 @@ private static CertStores.Builder certBuilder(boolean isServer, String cn, boole
13451349
.usePem(useInlinePem);
13461350
}
13471351

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

0 commit comments

Comments
 (0)