Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load default Java truststore for --use-system-truststore #19365

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 18 additions & 9 deletions client/trino-client/src/main/java/io/trino/client/OkHttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,29 @@ private static KeyStore loadTrustStore(File trustStorePath, Optional<String> tru
private static KeyStore loadSystemKeyStore(Optional<String> keyStoreType)
throws IOException, GeneralSecurityException
{
return loadSystemStore(keyStoreType, KEYSTORE_MACOS, KEYSTORE_WINDOWS_MY);
Optional<String> systemStoreType = getSystemStoreType(keyStoreType, KEYSTORE_WINDOWS_MY);
KeyStore store = KeyStore.getInstance(systemStoreType.orElseGet(KeyStore::getDefaultType));
store.load(null, null);
return store;
}

private static KeyStore loadSystemTrustStore(Optional<String> trustStoreType)
throws IOException, GeneralSecurityException
{
return loadSystemStore(trustStoreType, KEYSTORE_MACOS, KEYSTORE_WINDOWS_ROOT);
Optional<String> systemStoreType = getSystemStoreType(trustStoreType, KEYSTORE_WINDOWS_ROOT);
if (systemStoreType.isPresent()) {
KeyStore store = KeyStore.getInstance(systemStoreType.get());
store.load(null, null);
return store;
}
else {
// return null if trustStoreType isn't specified and osName is unknown
// trustManagerFactory.init(null) will try to load the default Java trustStore
return null;
}
}

private static KeyStore loadSystemStore(Optional<String> storeType, String mac, String windows)
throws IOException, GeneralSecurityException
private static Optional<String> getSystemStoreType(Optional<String> storeType, String windows)
{
String osName = Optional.ofNullable(StandardSystemProperty.OS_NAME.value()).orElse("");
Optional<String> systemStoreType = storeType;
Expand All @@ -353,13 +365,10 @@ private static KeyStore loadSystemStore(Optional<String> storeType, String mac,
systemStoreType = Optional.of(windows);
}
else if (osName.contains("Mac")) {
systemStoreType = Optional.of(mac);
systemStoreType = Optional.of(KEYSTORE_MACOS);
}
}

KeyStore store = KeyStore.getInstance(systemStoreType.orElseGet(KeyStore::getDefaultType));
store.load(null, null);
return store;
return systemStoreType;
}

public static void setupKerberos(
Expand Down
Loading