-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
GH-39014: [Java] Add default truststore along with KeychainStore when on Mac system #39235
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,16 @@ static KeyStore getKeyStoreInstance(String instance) | |
return keyStore; | ||
} | ||
|
||
@VisibleForTesting | ||
static KeyStore getDefaultKeyStoreInstance(String password) | ||
throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException { | ||
try (InputStream fileInputStream = getKeystoreInputStream()) { | ||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); | ||
keyStore.load(fileInputStream, password == null ? null : password.toCharArray()); | ||
return keyStore; | ||
} | ||
} | ||
|
||
static String getOperatingSystem() { | ||
return System.getProperty("os.name"); | ||
} | ||
|
@@ -156,16 +166,9 @@ public static InputStream getCertificateInputStreamFromSystem(String password) t | |
keyStoreList.add(getKeyStoreInstance("Windows-MY")); | ||
} else if (isMac()) { | ||
keyStoreList.add(getKeyStoreInstance("KeychainStore")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it not necessary to delete this method now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I considered it, but I don't see the harm in keeping it, especially if users are now importing certificates into their user keychain as a workaround. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, thanks for letting me know. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a big deal to keep it for now imho. |
||
keyStoreList.add(getDefaultKeyStoreInstance(password)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the order matter? Should the system key store come first? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears order does not matter, given that pemWriter writes data for all keystores added to the keystore list. I also did a manual test that required the default keystore and it passed successfully. |
||
} else { | ||
try (InputStream fileInputStream = getKeystoreInputStream()) { | ||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); | ||
if (password == null) { | ||
keyStore.load(fileInputStream, null); | ||
} else { | ||
keyStore.load(fileInputStream, password.toCharArray()); | ||
} | ||
keyStoreList.add(keyStore); | ||
} | ||
keyStoreList.add(getDefaultKeyStoreInstance(password)); | ||
} | ||
|
||
return getCertificatesInputStream(keyStoreList); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it need to load all cacerts files? Is there a way to restrict files needed to be loaded based on security concerns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate on the security concerns from loading all the cacerts files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the current user workaround, there is no more question for my side #39235 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me. Maybe it would be better to name this method
geetDefaultTrustStore()
but that's not a big deal.