From a69d064143b88ae53440b7992ea4135b97f4db33 Mon Sep 17 00:00:00 2001 From: abdul rawoof Date: Tue, 17 Nov 2026 12:43:17 +0530 Subject: [PATCH] MINOR: [JDBC] Prefer an explicit trustStore over the system trust store useSystemTrustStore defaults to true and was checked before trustStore, so a configured trustStore was ignored unless useSystemTrustStore=false was also set, and the server was validated against the system trust store instead. Check trustStore first, as tlsRootCerts already is. --- docs/source/flight_sql_jdbc_driver.rst | 3 +- .../client/ArrowFlightSqlClientHandler.java | 8 +++--- .../arrow/driver/jdbc/ConnectionTlsTest.java | 28 +++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/docs/source/flight_sql_jdbc_driver.rst b/docs/source/flight_sql_jdbc_driver.rst index a999de08bb..5e5a559811 100644 --- a/docs/source/flight_sql_jdbc_driver.rst +++ b/docs/source/flight_sql_jdbc_driver.rst @@ -155,7 +155,8 @@ case-sensitive. The supported parameters are: * - useSystemTrustStore - true - - When TLS is enabled, whether to use the system certificate store + - When TLS is enabled, whether to use the system certificate store. + Ignored when ``trustStore`` or ``tlsRootCerts`` is set. * - retainCookies - true diff --git a/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java b/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java index d82521240e..74da46380f 100644 --- a/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java +++ b/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java @@ -1154,14 +1154,14 @@ public ArrowFlightSqlClientHandler build() throws SQLException { if (tlsRootCertificatesPath != null) { clientBuilder.trustedCertificates( ClientAuthenticationUtils.getTlsRootCertificatesStream(tlsRootCertificatesPath)); - } else if (useSystemTrustStore) { - clientBuilder.trustedCertificates( - ClientAuthenticationUtils.getCertificateInputStreamFromSystem( - trustStorePassword)); } else if (trustStorePath != null) { clientBuilder.trustedCertificates( ClientAuthenticationUtils.getCertificateStream( trustStorePath, trustStorePassword)); + } else if (useSystemTrustStore) { + clientBuilder.trustedCertificates( + ClientAuthenticationUtils.getCertificateInputStreamFromSystem( + trustStorePassword)); } } diff --git a/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsTest.java b/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsTest.java index ddea9b24af..47e8404ef7 100644 --- a/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsTest.java +++ b/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsTest.java @@ -294,6 +294,34 @@ public void testGetNonAuthenticatedEncryptedConnection() throws Exception { } } + /** + * Check that a configured trust store is used even when useSystemTrustStore is left at its + * default value, rather than being silently replaced by the system trust store. + * + * @throws Exception on error. + */ + @Test + public void testGetEncryptedConnectionWithTrustStoreAndDefaultSystemTrustStore() + throws Exception { + final Properties properties = new Properties(); + + properties.put( + ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_EXTENSION.getHost()); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_EXTENSION.getPort()); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); + properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true); + properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); + properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); + + final ArrowFlightJdbcDataSource dataSource = + ArrowFlightJdbcDataSource.createNewDataSource(properties); + try (final Connection connection = dataSource.getConnection()) { + assertTrue(connection.isValid(300)); + } + } + /** * Check if an encrypted connection can be established successfully when connecting through the * DriverManager using just a connection url.