Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/clients/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<version>7.2.1</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import org.apache.ignite.configuration.ConnectorConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import redis.clients.jedis.ClientSetInfoConfig;
import redis.clients.jedis.DefaultJedisClientConfig;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

Expand Down Expand Up @@ -59,7 +62,13 @@ public class RedisCommonAbstractTest extends GridCommonAbstractTest {
jedisPoolCfg.setTestWhileIdle(true);
jedisPoolCfg.setTimeBetweenEvictionRunsMillis(30000);

pool = new JedisPool(jedisPoolCfg, HOST, PORT, 10000);
DefaultJedisClientConfig clientCfg = DefaultJedisClientConfig.builder()
.connectionTimeoutMillis(10000)
.socketTimeoutMillis(10000)
.clientSetInfoConfig(ClientSetInfoConfig.DISABLED)
.build();

pool = new JedisPool(jedisPoolCfg, new HostAndPort(HOST, PORT), clientCfg);
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.params.SetParams;

/**
* Tests for String commands of Redis protocol.
Expand Down Expand Up @@ -188,14 +189,14 @@ public void testSet() throws Exception {
Assert.assertEquals("b0", jcache().get("setKey2"));

// test options.
jedis.set("setKey1", "2", "nx");
jedis.set("setKey3", "3", "nx", "px", EXPIRE_MS);
jedis.set("setKey1", "2", SetParams.setParams().nx());
jedis.set("setKey3", "3", SetParams.setParams().nx().px(EXPIRE_MS));

Assert.assertEquals("1", jcache().get("setKey1"));
Assert.assertEquals("3", jcache().get("setKey3"));

jedis.set("setKey1", "2", "xx", "ex", EXPIRE_SEC);
jedis.set("setKey4", "4", "xx");
jedis.set("setKey1", "2", SetParams.setParams().xx().ex(EXPIRE_SEC));
jedis.set("setKey4", "4", SetParams.setParams().xx());

Assert.assertEquals("2", jcache().get("setKey1"));
Assert.assertNull(jcache().get("setKey4"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.Callable;
import javax.cache.configuration.Factory;
import javax.net.ssl.SSLContext;
Expand All @@ -33,6 +36,7 @@
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.ssl.SslContextFactory;
import org.apache.ignite.testframework.GridTestUtils;
import org.junit.Assume;
import org.junit.Test;

/**
Expand All @@ -51,6 +55,8 @@ public class JdbcThinConnectionSSLTest extends JdbcThinAbstractSelfTest {
/** Trust key store path. */
private static final String TRUST_KEY_STORE_PATH = U.getIgniteHome() +
"/modules/clients/src/test/keystore/trust-one.jks";
/** Unsupported cipher. */
private static final String UNSUPPORTED_CIPHER = "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA";

/** SSL context factory. */
private static Factory<SSLContext> sslCtxFactory;
Expand Down Expand Up @@ -96,6 +102,62 @@ public class JdbcThinConnectionSSLTest extends JdbcThinAbstractSelfTest {
return cfg;
}

/**
* @return One of default cipher suites for the current JDK.
* @throws NoSuchAlgorithmException If failed.
*/
private static String defaultCipher() throws NoSuchAlgorithmException {
String[] dflt = SSLContext.getDefault().getSocketFactory().getDefaultCipherSuites();

assertTrue("No default cipher suites available", dflt.length > 0);

return dflt[0];
}

/**
* @param exclude Cipher to exclude.
* @return Another default cipher suite for the current JDK.
* @throws NoSuchAlgorithmException If failed.
*/
private static String anotherDefaultCipher(String exclude) throws NoSuchAlgorithmException {
String[] dflt = SSLContext.getDefault().getSocketFactory().getDefaultCipherSuites();

for (String cipher : dflt) {
if (!cipher.equals(exclude))
return cipher;
}

fail("No alternative default cipher suite found");

return null;
}

/**
* @return Supported RSA cipher suite that is not enabled by default, or null if none found.
* @throws NoSuchAlgorithmException If failed.
*/
private static String supportedButNonDfltCipherOrNull() throws NoSuchAlgorithmException {
SSLSocketFactory factory = SSLContext.getDefault().getSocketFactory();

Set<String> supported = new LinkedHashSet<>(Arrays.asList(factory.getSupportedCipherSuites()));
Set<String> dflt = new LinkedHashSet<>(Arrays.asList(factory.getDefaultCipherSuites()));

for (String cipher : supported) {
if (dflt.contains(cipher))
continue;

if (!cipher.contains("_RSA_"))
continue;

if (cipher.contains("_anon_") || cipher.contains("_NULL_") || cipher.contains("_ECDSA_"))
continue;

return cipher;
}

return null;
}

/**
* @throws Exception If failed.
*/
Expand Down Expand Up @@ -232,10 +294,13 @@ public void testCustomCiphersOnClient() throws Exception {
setSslCtxFactoryToCli = true;
sslCtxFactory = getTestSslContextFactory();

String cipher1 = defaultCipher();
String cipher2 = anotherDefaultCipher(cipher1);

startGrids(1);

try {
// Default ciphers
// Default ciphers.
try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
"&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
"&sslClientCertificateKeyStorePassword=123456" +
Expand All @@ -244,9 +309,9 @@ public void testCustomCiphersOnClient() throws Exception {
checkConnection(conn);
}

// Explicit cipher (one of defaults).
// Explicit cipher.
try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
"&sslCipherSuites=TLS_RSA_WITH_AES_256_CBC_SHA256" +
"&sslCipherSuites=" + cipher1 +
"&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
"&sslClientCertificateKeyStorePassword=123456" +
"&sslTrustCertificateKeyStoreUrl=" + TRUST_KEY_STORE_PATH +
Expand All @@ -256,7 +321,7 @@ public void testCustomCiphersOnClient() throws Exception {

// Explicit ciphers.
try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
"&sslCipherSuites=TLS_RSA_WITH_NULL_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA256" +
"&sslCipherSuites=" + cipher2 + "," + cipher1 +
"&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
"&sslClientCertificateKeyStorePassword=123456" +
"&sslTrustCertificateKeyStoreUrl=" + TRUST_KEY_STORE_PATH +
Expand All @@ -275,7 +340,11 @@ public void testCustomCiphersOnClient() throws Exception {
@Test
public void testCustomCiphersOnServer() throws Exception {
setSslCtxFactoryToCli = true;
supportedCiphers = new String[] {"TLS_RSA_WITH_AES_256_CBC_SHA256" /* Enabled by default */};

String cipher1 = defaultCipher();
String cipher2 = anotherDefaultCipher(cipher1);

supportedCiphers = new String[] {cipher1};
sslCtxFactory = getTestSslContextFactory();

startGrids(1);
Expand All @@ -292,27 +361,28 @@ public void testCustomCiphersOnServer() throws Exception {

// Explicit cipher.
try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
"&sslCipherSuites=TLS_RSA_WITH_AES_256_CBC_SHA256" +
"&sslCipherSuites=" + cipher1 +
"&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
"&sslClientCertificateKeyStorePassword=123456" +
"&sslTrustCertificateKeyStoreUrl=" + TRUST_KEY_STORE_PATH +
"&sslTrustCertificateKeyStorePassword=123456")) {
checkConnection(conn);
}

// Disabled by default cipher.
GridTestUtils.assertThrows(log, () -> {
return DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
"&sslCipherSuites=TLS_RSA_WITH_NULL_SHA256" +
// Explicit cipher not supported by server.
GridTestUtils.assertThrows(log, () ->
DriverManager.getConnection(
"jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
"&sslCipherSuites=" + cipher2 +
"&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
"&sslClientCertificateKeyStorePassword=123456" +
"&sslTrustCertificateKeyStoreUrl=" + TRUST_KEY_STORE_PATH +
"&sslTrustCertificateKeyStorePassword=123456");
}, SQLException.class, "Failed to SSL connect to server");
"&sslTrustCertificateKeyStorePassword=123456"
), SQLException.class, "Failed to SSL connect to server");

// Explicit ciphers.
try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
"&sslCipherSuites=TLS_RSA_WITH_NULL_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA256" +
"&sslCipherSuites=" + cipher2 + "," + cipher1 +
"&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
"&sslClientCertificateKeyStorePassword=123456" +
"&sslTrustCertificateKeyStoreUrl=" + TRUST_KEY_STORE_PATH +
Expand All @@ -333,15 +403,20 @@ public void testCustomCiphersOnServer() throws Exception {
*/
@Test
public void testDisabledCustomCipher() throws Exception {
String nonDfltCipher = supportedButNonDfltCipherOrNull();

Assume.assumeNotNull(nonDfltCipher);

setSslCtxFactoryToCli = true;
supportedCiphers = new String[] {"TLS_RSA_WITH_NULL_SHA256" /* Disabled by default */};
supportedCiphers = new String[] {nonDfltCipher};
sslCtxFactory = getTestSslContextFactory();

startGrids(1);

try {
// Explicit supported ciphers.
// Explicit supported cipher.
try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
"&sslCipherSuites=TLS_RSA_WITH_NULL_SHA256" +
"&sslCipherSuites=" + nonDfltCipher +
"&sslTrustAll=true" +
"&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
"&sslClientCertificateKeyStorePassword=123456" +
Expand All @@ -351,13 +426,13 @@ public void testDisabledCustomCipher() throws Exception {
}

// Default ciphers.
GridTestUtils.assertThrows(log, () -> {
return DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
GridTestUtils.assertThrows(log, () -> DriverManager.getConnection(
"jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
"&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
"&sslClientCertificateKeyStorePassword=123456" +
"&sslTrustCertificateKeyStoreUrl=" + TRUST_KEY_STORE_PATH +
"&sslTrustCertificateKeyStorePassword=123456");
}, SQLException.class, "Failed to SSL connect to server");
"&sslTrustCertificateKeyStorePassword=123456"
), SQLException.class, "Failed to SSL connect to server");
}
finally {
stopAllGrids();
Expand All @@ -372,28 +447,31 @@ public void testDisabledCustomCipher() throws Exception {
*/
@Test
public void testUnsupportedCustomCipher() throws Exception {
String nonDfltCipher = supportedButNonDfltCipherOrNull();

Assume.assumeNotNull(nonDfltCipher);

setSslCtxFactoryToCli = true;
supportedCiphers = new String[] {
"TLS_RSA_WITH_NULL_SHA256" /* Disabled by default */,
"TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" /* With disabled protocol*/};
supportedCiphers = new String[] {nonDfltCipher, UNSUPPORTED_CIPHER};
sslCtxFactory = getTestSslContextFactory();

startGrids(1);

try {
// Enabled ciphers with unsupported algorithm can't be negotiated.
GridTestUtils.assertThrows(log, () -> {
return DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
"&sslCipherSuites=TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" +
// Unsupported cipher can't be negotiated.
GridTestUtils.assertThrows(log, () -> DriverManager.getConnection(
"jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
"&sslCipherSuites=" + UNSUPPORTED_CIPHER +
"&sslTrustAll=true" +
"&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
"&sslClientCertificateKeyStorePassword=123456" +
"&sslTrustCertificateKeyStoreUrl=" + TRUST_KEY_STORE_PATH +
"&sslTrustCertificateKeyStorePassword=123456");
}, SQLException.class, "Failed to SSL connect to server");
"&sslTrustCertificateKeyStorePassword=123456"
), SQLException.class, "Failed to SSL connect to server");

// Supported cipher.
try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
"&sslCipherSuites=TLS_RSA_WITH_NULL_SHA256" +
"&sslCipherSuites=" + nonDfltCipher +
"&sslTrustAll=true" +
"&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
"&sslClientCertificateKeyStorePassword=123456" +
Expand All @@ -403,14 +481,13 @@ public void testUnsupportedCustomCipher() throws Exception {
}

// Default ciphers.
GridTestUtils.assertThrows(log, () -> {
return DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
GridTestUtils.assertThrows(log, () -> DriverManager.getConnection(
"jdbc:ignite:thin://127.0.0.1/?sslMode=require" +
"&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH +
"&sslClientCertificateKeyStorePassword=123456" +
"&sslTrustCertificateKeyStoreUrl=" + TRUST_KEY_STORE_PATH +
"&sslTrustCertificateKeyStorePassword=123456");
}, SQLException.class, "Failed to SSL connect to server");

"&sslTrustCertificateKeyStorePassword=123456"
), SQLException.class, "Failed to SSL connect to server");
}
finally {
stopAllGrids();
Expand Down