This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-java.git
The following commit(s) were added to refs/heads/main by this push:
new 4fcf67eca GH-1499: [JDBC] Prefer an explicit trustStore over the
system trust store (#1496)
4fcf67eca is described below
commit 4fcf67eca862cafbbd6531cf18c9892bdab40979
Author: Abdul Rawoof Khan <[email protected]>
AuthorDate: Wed Nov 18 15:18:30 2026 +0530
GH-1499: [JDBC] Prefer an explicit trustStore over the system trust store
(#1496)
## What's Changed
`ArrowFlightSqlClientHandler.Builder.build()` picks the TLS trust source
in the order `tlsRootCerts`, `useSystemTrustStore`, `trustStore`.
`useSystemTrustStore` defaults to true, so a connection configured with
`trustStore` and `trustStorePassword` but without
`useSystemTrustStore=false` never reads that trust store. The server is
validated against the system store instead, which is opened with the
trust store's password. When that password matches the JDK `cacerts`
(`changeit`), or on Windows and macOS where the system keychains need
none, any certificate chaining to a system CA is accepted even though
the user limited trust to their own CA, and the handshake then sends the
credentials to that server. Otherwise the connection fails with
"Keystore was tampered with, or password was incorrect", which is why
every existing test sets `useSystemTrustStore=false` next to
`trustStore`.
An explicit `trustStore` now takes precedence over the system store, the
same way `tlsRootCerts` already does, and the docs say
`useSystemTrustStore` is ignored when either is set. Configurations that
already set `useSystemTrustStore=false` are unaffected. The new test in
`ConnectionTlsTest` connects with `trustStore` and the default
`useSystemTrustStore` and fails without this change.
`testGetAuthenticatedEncryptedConnectionWithKeyStoreBadPassword` still
passes, now failing on the configured trust store rather than on
`cacerts`.
Closes #1499.
---
docs/source/flight_sql_jdbc_driver.rst | 3 ++-
.../jdbc/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 a999de08b..5e5a55981 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 d82521240..74da46380 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 final class ArrowFlightSqlClientHandler
implements AutoCloseable {
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 ddea9b24a..47e8404ef 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 class ConnectionTlsTest {
}
}
+ /**
+ * 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.