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

GH-39014: [Java] Add default truststore along with KeychainStore when on Mac system #39235

Merged
merged 3 commits into from
Dec 22, 2023

Conversation

ravjotbrar
Copy link
Contributor

@ravjotbrar ravjotbrar commented Dec 14, 2023

Rationale for this change

As described in #39014, when using the system TrustStore on Mac, the certificates returned do not include Root CAs trusted by the system. This change adds the default KeyStore instance along with the KeyChainStore to include trusted Root CAs. The reason we add the default KeyStore instance is because there is no easy way to get the certificates from the System Roots keychain.

What changes are included in this PR?

I've updated ClientAuthenticationUtils to get the default KeyStore instance when the operating system is macOS and have updated the tests to include this change.

Are these changes tested?

See changes made in ClientAuthenticationUtilsTest.java.

Are there any user-facing changes?

No

@ravjotbrar ravjotbrar requested a review from lidavidm as a code owner December 14, 2023 19:48
Copy link

⚠️ GitHub issue #39014 has been automatically assigned in GitHub to PR creator.

@@ -156,16 +166,9 @@ public static InputStream getCertificateInputStreamFromSystem(String password) t
keyStoreList.add(getKeyStoreInstance("Windows-MY"));
} else if (isMac()) {
keyStoreList.add(getKeyStoreInstance("KeychainStore"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not necessary to delete this method now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks for letting me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal to keep it for now imho.

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Dec 14, 2023
throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
try (InputStream fileInputStream = getKeystoreInputStream()) {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(fileInputStream, password == null ? null : password.toCharArray());
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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)

Copy link
Member

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.

@jbonofre
Copy link
Member

Thanks for the PR. I'm doing a pass as well 😄

throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
try (InputStream fileInputStream = getKeystoreInputStream()) {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(fileInputStream, password == null ? null : password.toCharArray());
Copy link
Member

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.

@@ -156,16 +166,9 @@ public static InputStream getCertificateInputStreamFromSystem(String password) t
keyStoreList.add(getKeyStoreInstance("Windows-MY"));
} else if (isMac()) {
keyStoreList.add(getKeyStoreInstance("KeychainStore"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal to keep it for now imho.

@@ -156,16 +166,9 @@ public static InputStream getCertificateInputStreamFromSystem(String password) t
keyStoreList.add(getKeyStoreInstance("Windows-MY"));
} else if (isMac()) {
keyStoreList.add(getKeyStoreInstance("KeychainStore"));
keyStoreList.add(getDefaultKeyStoreInstance(password));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the order matter? Should the system key store come first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@github-actions github-actions bot added awaiting merge Awaiting merge awaiting committer review Awaiting committer review awaiting review Awaiting review and removed awaiting committer review Awaiting committer review awaiting merge Awaiting merge awaiting review Awaiting review labels Dec 21, 2023
@lidavidm lidavidm merged commit cd5a1bd into apache:main Dec 22, 2023
25 of 26 checks passed
@lidavidm lidavidm removed the awaiting committer review Awaiting committer review label Dec 22, 2023
Copy link

After merging your PR, Conbench analyzed the 5 benchmarking runs that have been run so far on merge-commit cd5a1bd.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

clayburn pushed a commit to clayburn/arrow that referenced this pull request Jan 23, 2024
…e when on Mac system (apache#39235)

### Rationale for this change
As described in apache#39014, when using the system TrustStore on Mac, the certificates returned do not include Root CAs trusted by the system. This change adds the default KeyStore instance along with the KeyChainStore to include trusted Root CAs. The reason we add the default KeyStore instance is because there is no easy way to get the certificates from the System Roots keychain. 

### What changes are included in this PR?

I've updated ClientAuthenticationUtils to get the default KeyStore instance when the operating system is macOS and have updated the tests to include this change. 

### Are these changes tested?

See changes made in ClientAuthenticationUtilsTest.java.

### Are there any user-facing changes?

No

* Closes: apache#39014

Authored-by: Ravjot Brar <ravjot.brar@dremio.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
dgreiss pushed a commit to dgreiss/arrow that referenced this pull request Feb 19, 2024
…e when on Mac system (apache#39235)

### Rationale for this change
As described in apache#39014, when using the system TrustStore on Mac, the certificates returned do not include Root CAs trusted by the system. This change adds the default KeyStore instance along with the KeyChainStore to include trusted Root CAs. The reason we add the default KeyStore instance is because there is no easy way to get the certificates from the System Roots keychain. 

### What changes are included in this PR?

I've updated ClientAuthenticationUtils to get the default KeyStore instance when the operating system is macOS and have updated the tests to include this change. 

### Are these changes tested?

See changes made in ClientAuthenticationUtilsTest.java.

### Are there any user-facing changes?

No

* Closes: apache#39014

Authored-by: Ravjot Brar <ravjot.brar@dremio.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Java][FlightSQL] useSystemTrustStore on MacOS returns user's keychain instead of System Roots keychain
4 participants