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

Add Windows and MacOS native certificate support #3124

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

minfrin
Copy link

@minfrin minfrin commented Feb 16, 2024

Add three new SSLSocketFactory implementations to support native keystores on Windows and Mac.

org.postgresql.ssl.MSCAPILocalMachineSSLFactory
org.postgresql.ssl.MSCAPISSLFactory
org.postgresql.ssl.KeychainSSLFactory

Add the sslsubject parameter to limit the chosen certificate where more than one certificate might match for a given connection.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Does ./gradlew styleCheck pass ?
  3. Have you added your new test classes to an existing test suite in alphabetical order?

Changes to Existing Features:

  • Does this break existing behaviour? If so please explain.
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?

Add three new SSLSocketFactory implementations to support native
keystores on Windows and Mac.

org.postgresql.ssl.MSCAPILocalMachineSSLFactory
org.postgresql.ssl.MSCAPISSLFactory
org.postgresql.ssl.KeychainSSLFactory

Add the sslsubject parameter to limit the chosen certificate where
more than one certificate might match for a given connection.
@minfrin
Copy link
Author

minfrin commented Feb 22, 2024

Would it be possible to approve the workflows outstanding on this PR?

@davecramer
Copy link
Member

Would it be possible to approve the workflows outstanding on this PR?

Yes, sorry. I should have realized they weren't running


try {

keyManagerFactory.init(keyStore, keyPassphrase);
Copy link
Author

Choose a reason for hiding this comment

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

I'm getting a test failure, more specifically a compilation failure that I don't understand.

[Task :postgresql:compileJava] [argument] incompatible argument for parameter arg1 of KeyManagerFactory.init.
      keyManagerFactory.init(keyStore, keyPassphrase);
                                       ^
  found   : @initialized @nonnull char @FBCBottom @nullable []

keyPassphrase is a char[], the extra annotations seem sane.

Can you confirm for me if possible what specifically is wrong with this line so I can fix it?

Copy link
Author

Choose a reason for hiding this comment

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

These warnings might be relevant:

> Task :postgresql:compileJava
warning: /home/runner/work/pgjdbc/pgjdbc/config/checkerframework/Assert.astub:(line 1,col 1): Package not found: org.junit
warning: /home/runner/work/pgjdbc/pgjdbc/config/checkerframework/Assert.astub:(line 6,col 1): Type not found: org.junit.Assert

Copy link
Author

Choose a reason for hiding this comment

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

Quick ping on this comment - I don't understand how it compiles everywhere else but not in this specific case. Is someone familiar with CheckerFramework able to confirm?

https://github.com/pgjdbc/pgjdbc/actions/runs/8323877965/job/23147420376?pr=3124

keyManagerFactory.init(keyStore, keyPassphrase);

} catch (NoSuchAlgorithmException ex) {
throw new PSQLException(GT.tr("Could not find a java cryptographic algorithm: {0}.",

Choose a reason for hiding this comment

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

Java

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.


} catch (NoSuchAlgorithmException ex) {
throw new PSQLException(GT.tr("Could not find a java cryptographic algorithm: {0}.",
ex.getMessage()), PSQLState.CONNECTION_FAILURE, ex);

Choose a reason for hiding this comment

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

Isn't ex.getMessage() redudant since the target message will be recursively built?

Copy link
Author

Choose a reason for hiding this comment

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

Java is fixed.

The ex.getMessage() is there on purpose so that the whole error message is on one single line.

The target audience for this patch are data scientists who aren't Java developers, nor are they experts in SSL. They see the message "Could not find a java cryptographic algorithm", they don't understand it (fair: "which crypto algorithm?"), and I have to pick it all apart for them, first helping them give me the whole exception (I'll get a screenshot of the top few lines, then I'll explain how to cut and paste), then finding the needle in the haystack of "caused by", then googling for them.

With the whole message on one line, they have one line to google themselves, on the top line, and lots and lots of make work is avoided.

trustStoreType), PSQLState.CONNECTION_FAILURE, ex);
} catch (NoSuchAlgorithmException ex) {
throw new PSQLException(GT.tr("Could not find a java cryptographic algorithm: {0}.",
ex.getMessage()), PSQLState.CONNECTION_FAILURE, ex);

Choose a reason for hiding this comment

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

Same here

Copy link
Author

Choose a reason for hiding this comment

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

Java is fixed.

throw new PSQLException(GT.tr("SSL truststore {0} could not be loaded.",
trustStoreType), PSQLState.CONNECTION_FAILURE, ex);
} catch (NoSuchAlgorithmException ex) {
throw new PSQLException(GT.tr("Could not find a java cryptographic algorithm: {0}.",

Choose a reason for hiding this comment

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

same here

Copy link
Author

Choose a reason for hiding this comment

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

Java is fixed.


} catch (NoSuchAlgorithmException ex) {
throw new PSQLException(GT.tr("Could not find a java cryptographic algorithm: {0}.",
ex.getMessage()), PSQLState.CONNECTION_FAILURE, ex);

Choose a reason for hiding this comment

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

Both same here

Copy link
Author

Choose a reason for hiding this comment

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

Java is fixed.


} catch (NoSuchAlgorithmException ex) {
throw new PSQLException(GT.tr("Could not find a java cryptographic algorithm: {0}.",
ex.getMessage()), PSQLState.CONNECTION_FAILURE, ex);

Choose a reason for hiding this comment

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

Same both here

Copy link
Author

Choose a reason for hiding this comment

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

Java is fixed.


} catch (IllegalArgumentException ex) {
throw new PSQLException(GT.tr("Could not parse sslsubject {0}: {1}.",
sslsubject, ex.getMessage()), PSQLState.CONNECTION_FAILURE, ex);

Choose a reason for hiding this comment

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

Same here

Copy link
Author

Choose a reason for hiding this comment

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

This is intended.

@minfrin
Copy link
Author

minfrin commented Mar 25, 2024

Another gentle bump - is it possible to trigger workflows?

@davecramer
Copy link
Member

sorry about that

@sehrope
Copy link
Member

sehrope commented Mar 27, 2024

@minfrin You can enable actions to run on your pgjdbc fork as well. This is particularly useful if you want to try running something in CI without opening a PR in this repo. The GitHub Actions should work with no issues on your fork. The Windows / AppVeyor stuff is a bit finicky but in theory should work if you set up an account there as well.

(Note that I'm not suggesting opening this PR and running the CI on pgjdbc/pgjdbc was a bad idea ... I'm just suggesting an alternative for the future if you're trying out something else)

@davecramer
Copy link
Member

@minfrin I took the liberty of fixing the checker errors

@minfrin
Copy link
Author

minfrin commented Apr 24, 2024

@minfrin I took the liberty of fixing the checker errors

Much appreciated, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants