Skip to content

Commit

Permalink
Change ssl parameter to UseEncryption
Browse files Browse the repository at this point in the history
  • Loading branch information
jcralmeida committed Apr 19, 2022
1 parent 7924e7b commit e6d01af
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static ArrowFlightSqlClientHandler createNewClientHandler(
.withTrustStorePassword(config.getTrustStorePassword())
.withSystemTrustStore(config.useSystemTrustStore())
.withBufferAllocator(allocator)
.withTlsEncryption(config.useTls())
.withEncryption(config.useEncryption())
.withDisableCertificateVerification(config.getDisableCertificateVerification())
.withToken(config.getToken())
.withCallOptions(config.toCallOption())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public static final class Builder {
private String trustStorePath;
private String trustStorePassword;
private String token;
private boolean useTls;
private boolean useEncryption;
private boolean disableCertificateVerification;
private boolean useSystemTrustStore;
private BufferAllocator allocator;
Expand Down Expand Up @@ -419,11 +419,11 @@ public Builder withTrustStorePassword(final String trustStorePassword) {
/**
* Sets whether to use TLS encryption in this handler.
*
* @param useTls whether to use TLS encryption.
* @param useEncryption whether to use TLS encryption.
* @return this instance.
*/
public Builder withTlsEncryption(final boolean useTls) {
this.useTls = useTls;
public Builder withEncryption(final boolean useEncryption) {
this.useEncryption = useEncryption;
return this;
}

Expand Down Expand Up @@ -533,15 +533,15 @@ public ArrowFlightSqlClientHandler build() throws SQLException {
withMiddlewareFactories(new ClientCookieMiddleware.Factory());
middlewareFactories.forEach(clientBuilder::intercept);
Location location;
if (useTls) {
if (useEncryption) {
location = Location.forGrpcTls(host, port);
clientBuilder.useTls();
} else {
location = Location.forGrpcInsecure(host, port);
}
clientBuilder.location(location);

if (useTls) {
if (useEncryption) {
if (disableCertificateVerification) {
clientBuilder.verifyServer(false);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public boolean useSystemTrustStore() {
*
* @return whether to use TLS encryption.
*/
public boolean useTls() {
return ArrowFlightConnectionProperty.SSL.getBoolean(properties);
public boolean useEncryption() {
return ArrowFlightConnectionProperty.USE_ENCRYPTION.getBoolean(properties);
}

public boolean getDisableCertificateVerification() {
Expand Down Expand Up @@ -149,7 +149,7 @@ public enum ArrowFlightConnectionProperty implements ConnectionProperty {
PORT("port", null, Type.NUMBER, true),
USER("user", null, Type.STRING, false),
PASSWORD("password", null, Type.STRING, false),
SSL("ssl", true, Type.BOOLEAN, false),
USE_ENCRYPTION("useEncryption", true, Type.BOOLEAN, false),
CERTIFICATE_VERIFICATION("disableCertificateVerification", false, Type.BOOLEAN, false),
TRUST_STORE("trustStore", null, Type.STRING, false),
TRUST_STORE_PASSWORD("trustStorePassword", null, Type.STRING, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void testShouldConnectWhenProvidedWithValidUrl() throws Exception {
driver.connect("jdbc:arrow-flight://" +
dataSource.getConfig().getHost() + ":" +
dataSource.getConfig().getPort() + "?" +
"ssl=false",
"useEncryption=false",
dataSource.getProperties(dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()))) {
assert connection.isValid(300);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void testShouldBeAbleToEstablishAConnectionSuccessfully() throws Exceptio
properties.putAll(ImmutableMap.of(
ArrowFlightConnectionProperty.HOST.camelName(), "localhost",
ArrowFlightConnectionProperty.PORT.camelName(), 32010,
ArrowFlightConnectionProperty.SSL.camelName(), false));
ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), false));

try (Connection connection = factory.newConnection(driver, constructor.newInstance(),
"jdbc:arrow-flight://localhost:32010", properties)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testUnencryptedConnectionShouldOpenSuccessfullyWhenProvidedValidCred
userTest);
properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(),
passTest);
properties.put("ssl", false);
properties.put("useEncryption", false);

try (Connection connection = DriverManager.getConnection(
"jdbc:arrow-flight://" + FLIGHT_SERVER_TEST_RULE.getHost() + ":" +
Expand Down Expand Up @@ -154,7 +154,7 @@ public void testUnencryptedConnectionProvidingInvalidPort()
userTest);
properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(),
passTest);
properties.put(ArrowFlightConnectionProperty.SSL.camelName(),
properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(),
false);
final String invalidUrl = "jdbc:arrow-flight://" + FLIGHT_SERVER_TEST_RULE.getHost() +
":" + 65537;
Expand Down Expand Up @@ -192,7 +192,7 @@ public void testUnencryptedConnectionShouldOpenSuccessfullyWithoutAuthentication
properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost");
properties.put(ArrowFlightConnectionProperty.PORT.camelName(),
FLIGHT_SERVER_TEST_RULE.getPort());
properties.put(ArrowFlightConnectionProperty.SSL.camelName(),
properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(),
false);
try (Connection connection = DriverManager
.getConnection("jdbc:arrow-flight://localhost:32010", properties)) {
Expand All @@ -217,7 +217,7 @@ public void testUnencryptedConnectionShouldThrowExceptionWhenProvidedWithInvalid
"invalidUser");
properties.put(ArrowFlightConnectionProperty.PORT.camelName(),
FLIGHT_SERVER_TEST_RULE.getPort());
properties.put(ArrowFlightConnectionProperty.SSL.camelName(),
properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(),
false);
properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(),
"invalidPassword");
Expand All @@ -241,7 +241,7 @@ public void testTLSConnectionPropertyFalseCorrectCastUrlWithDriverManager() thro

Connection connection = DriverManager.getConnection(
String.format(
"jdbc:arrow-flight://localhost:%s?user=%s&password=%s&ssl=false",
"jdbc:arrow-flight://localhost:%s?user=%s&password=%s&useEncryption=false",
FLIGHT_SERVER_TEST_RULE.getPort(),
userTest,
passTest));
Expand All @@ -267,7 +267,7 @@ public void testTLSConnectionPropertyFalseCorrectCastUrlAndPropertiesUsingSetPro
userTest);
properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(),
passTest);
properties.setProperty(ArrowFlightConnectionProperty.SSL.camelName(), "false");
properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "false");

Connection connection = DriverManager.getConnection(
String.format(
Expand Down Expand Up @@ -295,7 +295,7 @@ public void testTLSConnectionPropertyFalseCorrectCastUrlAndPropertiesUsingPutWit
userTest);
properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(),
passTest);
properties.put(ArrowFlightConnectionProperty.SSL.camelName(), false);
properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), false);

Connection connection = DriverManager.getConnection(
String.format(
Expand All @@ -320,7 +320,7 @@ public void testTLSConnectionPropertyFalseIntegerCorrectCastUrlWithDriverManager

Connection connection = DriverManager.getConnection(
String.format(
"jdbc:arrow-flight://localhost:%s?user=%s&password=%s&ssl=0",
"jdbc:arrow-flight://localhost:%s?user=%s&password=%s&useEncryption=0",
FLIGHT_SERVER_TEST_RULE.getPort(),
userTest,
passTest));
Expand All @@ -346,7 +346,7 @@ public void testTLSConnectionPropertyFalseIntegerCorrectCastUrlAndPropertiesUsin
userTest);
properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(),
passTest);
properties.setProperty(ArrowFlightConnectionProperty.SSL.camelName(), "0");
properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "0");

Connection connection = DriverManager.getConnection(
String.format(
Expand Down Expand Up @@ -375,7 +375,7 @@ public void testTLSConnectionPropertyFalseIntegerCorrectCastUrlAndPropertiesUsin
userTest);
properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(),
passTest);
properties.put(ArrowFlightConnectionProperty.SSL.camelName(), 0);
properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), 0);

Connection connection = DriverManager.getConnection(
String.format(
Expand All @@ -400,7 +400,7 @@ public void testThreadPoolSizeConnectionPropertyCorrectCastUrlWithDriverManager(

Connection connection = DriverManager.getConnection(
String.format(
"jdbc:arrow-flight://localhost:%s?user=%s&password=%s&threadPoolSize=1&ssl=%s",
"jdbc:arrow-flight://localhost:%s?user=%s&password=%s&threadPoolSize=1&useEncryption=%s",
FLIGHT_SERVER_TEST_RULE.getPort(),
userTest,
passTest,
Expand Down Expand Up @@ -428,7 +428,7 @@ public void testThreadPoolSizeConnectionPropertyCorrectCastUrlAndPropertiesUsing
properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(),
passTest);
properties.setProperty(ArrowFlightConnectionProperty.THREAD_POOL_SIZE.camelName(), "1");
properties.put("ssl", false);
properties.put("useEncryption", false);

Connection connection = DriverManager.getConnection(
String.format(
Expand Down Expand Up @@ -458,7 +458,7 @@ public void testThreadPoolSizeConnectionPropertyCorrectCastUrlAndPropertiesUsing
properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(),
passTest);
properties.put(ArrowFlightConnectionProperty.THREAD_POOL_SIZE.camelName(), 1);
properties.put("ssl", false);
properties.put("useEncryption", false);

Connection connection = DriverManager.getConnection(
String.format(
Expand All @@ -483,7 +483,7 @@ public void testPasswordConnectionPropertyIntegerCorrectCastUrlWithDriverManager

Connection connection = DriverManager.getConnection(
String.format(
"jdbc:arrow-flight://localhost:%s?user=%s&password=%s&ssl=%s",
"jdbc:arrow-flight://localhost:%s?user=%s&password=%s&useEncryption=%s",
FLIGHT_SERVER_TEST_RULE.getPort(),
userTest,
passTest,
Expand All @@ -510,7 +510,7 @@ public void testPasswordConnectionPropertyIntegerCorrectCastUrlAndPropertiesUsin
userTest);
properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(),
passTest);
properties.put("ssl", false);
properties.put("useEncryption", false);

Connection connection = DriverManager.getConnection(
String.format(
Expand Down Expand Up @@ -539,7 +539,7 @@ public void testPasswordConnectionPropertyIntegerCorrectCastUrlAndPropertiesUsin
userTest);
properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(),
passTest);
properties.put("ssl", false);
properties.put("useEncryption", false);

Connection connection = DriverManager.getConnection(
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class ConnectionTlsTest {
.host("localhost")
.randomPort()
.authentication(authentication)
.useTls(certKey.cert, certKey.key)
.useEncryption(certKey.cert, certKey.key)
.producer(PRODUCER)
.build();
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public void testGetEncryptedClientAuthenticatedWithDisableCertVerification() thr
.withPassword(credentials.getPassword())
.withDisableCertificateVerification(true)
.withBufferAllocator(allocator)
.withTlsEncryption(true)
.withEncryption(true)
.build()) {
assertNotNull(client);
}
Expand All @@ -127,7 +127,7 @@ public void testGetEncryptedClientAuthenticated() throws Exception {
.withTrustStorePath(trustStorePath)
.withTrustStorePassword(trustStorePass)
.withBufferAllocator(allocator)
.withTlsEncryption(true)
.withEncryption(true)
.build()) {
assertNotNull(client);
}
Expand All @@ -149,7 +149,7 @@ public void testGetEncryptedClientWithNoCertificateOnKeyStore() throws Exception
.withTrustStorePath(noCertificateKeyStorePath)
.withTrustStorePassword(noCertificateKeyStorePassword)
.withBufferAllocator(allocator)
.withTlsEncryption(true)
.withEncryption(true)
.build()) {
Assert.fail();
}
Expand All @@ -168,7 +168,7 @@ public void testGetNonAuthenticatedEncryptedClientNoAuth() throws Exception {
.withTrustStorePath(trustStorePath)
.withTrustStorePassword(trustStorePass)
.withBufferAllocator(allocator)
.withTlsEncryption(true)
.withEncryption(true)
.build()) {
assertNotNull(client);
}
Expand All @@ -190,7 +190,7 @@ public void testGetEncryptedClientWithKeyStoreBadPasswordAndNoAuth() throws Exce
.withTrustStorePath(trustStorePath)
.withTrustStorePassword(keyStoreBadPassword)
.withBufferAllocator(allocator)
.withTlsEncryption(true)
.withEncryption(true)
.build()) {
Assert.fail();
}
Expand Down Expand Up @@ -242,7 +242,7 @@ public void testGetAuthenticatedEncryptedConnectionWithKeyStoreBadPassword() thr
userTest);
properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(),
passTest);
properties.put(ArrowFlightConnectionProperty.SSL.camelName(), true);
properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true);
properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath);
properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), "badpassword");

Expand All @@ -264,7 +264,7 @@ public void testGetNonAuthenticatedEncryptedConnection() throws Exception {

properties.put(ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost());
properties.put(ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort());
properties.put(ArrowFlightConnectionProperty.SSL.camelName(), true);
properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true);
properties.put(ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), false);
properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath);
properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass);
Expand All @@ -288,7 +288,8 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlWithDriverManager() throw

final Connection connection = DriverManager.getConnection(
String.format(
"jdbc:arrow-flight://localhost:%s?user=%s&password=%s&ssl=true&useSystemTrustStore=false&%s=%s&%s=%s",
"jdbc:arrow-flight://localhost:%s?user=%s&password=%s" +
"&useEncryption=true&useSystemTrustStore=false&%s=%s&%s=%s",
FLIGHT_SERVER_TEST_RULE.getPort(),
userTest,
passTest,
Expand Down Expand Up @@ -318,7 +319,7 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetProp
properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest);
properties.setProperty(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath);
properties.setProperty(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass);
properties.setProperty(ArrowFlightConnectionProperty.SSL.camelName(), "true");
properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "true");
properties.setProperty(ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), "false");

final Connection connection = DriverManager.getConnection(
Expand Down Expand Up @@ -346,7 +347,7 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingPutWith

properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest);
properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest);
properties.put(ArrowFlightConnectionProperty.SSL.camelName(), true);
properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true);
properties.put(ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), false);
properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath);
properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass);
Expand Down Expand Up @@ -374,7 +375,7 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlWithDriverManager(

final Connection connection = DriverManager.getConnection(
String.format(
"jdbc:arrow-flight://localhost:%s?user=%s&password=%s&ssl=1&useSystemTrustStore=0&%s=%s&%s=%s",
"jdbc:arrow-flight://localhost:%s?user=%s&password=%s&useEncryption=1&useSystemTrustStore=0&%s=%s&%s=%s",
FLIGHT_SERVER_TEST_RULE.getPort(),
userTest,
passTest,
Expand Down Expand Up @@ -404,7 +405,7 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing
properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest);
properties.setProperty(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath);
properties.setProperty(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass);
properties.setProperty(ArrowFlightConnectionProperty.SSL.camelName(), "1");
properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "1");
properties.setProperty(ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), "0");

final Connection connection = DriverManager.getConnection(
Expand All @@ -430,7 +431,7 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing

properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest);
properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest);
properties.put(ArrowFlightConnectionProperty.SSL.camelName(), 1);
properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), 1);
properties.put(ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), 0);
properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath);
properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass);
Expand Down
Loading

0 comments on commit e6d01af

Please sign in to comment.