@@ -55,9 +55,6 @@ public class JdbcThinConnectionSSLTest extends JdbcThinAbstractSelfTest {
5555 /** Enabled cipher. */
5656 private static final String ENABLED_CIPHER = "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" ;
5757
58- /** Disabled-by-default cipher. */
59- private static final String DISABLED_BY_DEFAULT_CIPHER = "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256" ;
60-
6158 /** Unsupported cipher. */
6259 private static final String UNSUPPORTED_CIPHER = "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" ;
6360
@@ -73,12 +70,16 @@ public class JdbcThinConnectionSSLTest extends JdbcThinAbstractSelfTest {
7370 /** Supported ciphers. */
7471 private static String [] supportedCiphers ;
7572
73+ /** Supported cipher that is not enabled by default on the current JDK. */
74+ private static String disabledByDefaultCipher ;
75+
7676 /** {@inheritDoc} */
7777 @ Override protected void beforeTest () throws Exception {
7878 setSslCtxFactoryToCli = false ;
7979 setSslCtxFactoryToIgnite = false ;
8080 supportedCiphers = null ;
8181 sslCtxFactory = null ;
82+ disabledByDefaultCipher = null ;
8283 }
8384
8485 /** {@inheritDoc} */
@@ -105,6 +106,42 @@ public class JdbcThinConnectionSSLTest extends JdbcThinAbstractSelfTest {
105106 return cfg ;
106107 }
107108
109+ /**
110+ * @return Supported RSA cipher suite that is not enabled by default on the current JDK.
111+ * @throws NoSuchAlgorithmException If failed.
112+ */
113+ private static String disabledByDefaultCipher () throws NoSuchAlgorithmException {
114+ if (disabledByDefaultCipher != null )
115+ return disabledByDefaultCipher ;
116+
117+ SSLContext ctx = SSLContext .getDefault ();
118+
119+ SSLSocketFactory factory = ctx .getSocketFactory ();
120+
121+ java .util .Set <String > supported = new java .util .HashSet <>();
122+ java .util .Collections .addAll (supported , factory .getSupportedCipherSuites ());
123+
124+ java .util .Set <String > enabled = new java .util .HashSet <>();
125+ java .util .Collections .addAll (enabled , factory .getDefaultCipherSuites ());
126+
127+ for (String cipher : supported ) {
128+ if (enabled .contains (cipher ))
129+ continue ;
130+
131+ if (!cipher .contains ("_RSA_" ))
132+ continue ;
133+
134+ if (cipher .contains ("_anon_" ) || cipher .contains ("_NULL_" ) || cipher .contains ("_ECDSA_" ))
135+ continue ;
136+
137+ disabledByDefaultCipher = cipher ;
138+
139+ return cipher ;
140+ }
141+
142+ throw new IllegalStateException ("No supported non-default RSA cipher suite found for the current JDK" );
143+ }
144+
108145 /**
109146 * @throws Exception If failed.
110147 */
@@ -265,7 +302,7 @@ public void testCustomCiphersOnClient() throws Exception {
265302
266303 // Explicit ciphers.
267304 try (Connection conn = DriverManager .getConnection ("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
268- "&sslCipherSuites=" + DISABLED_BY_DEFAULT_CIPHER + "," + ENABLED_CIPHER +
305+ "&sslCipherSuites=" + disabledByDefaultCipher () + "," + ENABLED_CIPHER +
269306 "&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
270307 "&sslClientCertificateKeyStorePassword=123456" +
271308 "&sslTrustCertificateKeyStoreUrl=" + TRUST_KEY_STORE_PATH +
@@ -284,7 +321,7 @@ public void testCustomCiphersOnClient() throws Exception {
284321 @ Test
285322 public void testCustomCiphersOnServer () throws Exception {
286323 setSslCtxFactoryToCli = true ;
287- supportedCiphers = new String [] {ENABLED_CIPHER /* Enabled by default */ };
324+ supportedCiphers = new String [] {ENABLED_CIPHER };
288325 sslCtxFactory = getTestSslContextFactory ();
289326
290327 startGrids (1 );
@@ -312,7 +349,7 @@ public void testCustomCiphersOnServer() throws Exception {
312349 // Disabled by default cipher.
313350 GridTestUtils .assertThrows (log , () -> {
314351 return DriverManager .getConnection ("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
315- "&sslCipherSuites=" + DISABLED_BY_DEFAULT_CIPHER +
352+ "&sslCipherSuites=" + disabledByDefaultCipher () +
316353 "&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
317354 "&sslClientCertificateKeyStorePassword=123456" +
318355 "&sslTrustCertificateKeyStoreUrl=" + TRUST_KEY_STORE_PATH +
@@ -321,7 +358,7 @@ public void testCustomCiphersOnServer() throws Exception {
321358
322359 // Explicit ciphers.
323360 try (Connection conn = DriverManager .getConnection ("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
324- "&sslCipherSuites=" + DISABLED_BY_DEFAULT_CIPHER + "," + ENABLED_CIPHER +
361+ "&sslCipherSuites=" + disabledByDefaultCipher () + "," + ENABLED_CIPHER +
325362 "&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
326363 "&sslClientCertificateKeyStorePassword=123456" +
327364 "&sslTrustCertificateKeyStoreUrl=" + TRUST_KEY_STORE_PATH +
@@ -340,15 +377,15 @@ public void testCustomCiphersOnServer() throws Exception {
340377 @ Test
341378 public void testDisabledCustomCipher () throws Exception {
342379 setSslCtxFactoryToCli = true ;
343- supportedCiphers = new String [] {DISABLED_BY_DEFAULT_CIPHER /* Disabled by default */ };
380+ supportedCiphers = new String [] {disabledByDefaultCipher () };
344381 sslCtxFactory = getTestSslContextFactory ();
345382
346383 startGrids (1 );
347384
348385 try {
349386 // Explicit supported ciphers.
350387 try (Connection conn = DriverManager .getConnection ("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
351- "&sslCipherSuites=" + DISABLED_BY_DEFAULT_CIPHER +
388+ "&sslCipherSuites=" + disabledByDefaultCipher () +
352389 "&sslTrustAll=true" +
353390 "&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
354391 "&sslClientCertificateKeyStorePassword=123456" +
@@ -378,8 +415,8 @@ public void testDisabledCustomCipher() throws Exception {
378415 public void testUnsupportedCustomCipher () throws Exception {
379416 setSslCtxFactoryToCli = true ;
380417 supportedCiphers = new String [] {
381- DISABLED_BY_DEFAULT_CIPHER /* Disabled by default */ ,
382- UNSUPPORTED_CIPHER /* With disabled protocol/algorithm */
418+ disabledByDefaultCipher () ,
419+ UNSUPPORTED_CIPHER
383420 };
384421 sslCtxFactory = getTestSslContextFactory ();
385422
@@ -399,7 +436,7 @@ public void testUnsupportedCustomCipher() throws Exception {
399436
400437 // Supported cipher.
401438 try (Connection conn = DriverManager .getConnection ("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
402- "&sslCipherSuites=" + DISABLED_BY_DEFAULT_CIPHER +
439+ "&sslCipherSuites=" + disabledByDefaultCipher () +
403440 "&sslTrustAll=true" +
404441 "&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
405442 "&sslClientCertificateKeyStorePassword=123456" +
@@ -416,7 +453,6 @@ public void testUnsupportedCustomCipher() throws Exception {
416453 "&sslTrustCertificateKeyStoreUrl=" + TRUST_KEY_STORE_PATH +
417454 "&sslTrustCertificateKeyStorePassword=123456" );
418455 }, SQLException .class , "Failed to SSL connect to server" );
419-
420456 }
421457 finally {
422458 stopAllGrids ();
0 commit comments