8000 fix: use configured crypto provider to read generated truststores by slaskawi · Pull Request #54017 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

fix: use configured crypto provider to read generated truststores - #54017

Merged
vmuzikar merged 5 commits into
keycloak:mainfrom
slaskawi:fix/truststore-crypto-provider
Oct 26, 2026
Merged

vmuzikar merged 5 commits into
keycloak:mainfrom
slaskawi:fix/truststore-crypto-provider

Conversation

@slaskawi
@slaskawi slaskawi commented Oct 15, 2026 •
Copy link
Copy Markdown
Contributor

Summary

Publish and honor javax.net.ssl.trustStoreProvider when loading system truststores. Preserve explicit SPI and HTTPS truststore loading.

Related Ticket

Closes #53729

Reproducer

On Kubernetes, NSS_FIPS=1 simulates host-FIPS detection in the Red Hat JVM. The first pod fails reading the generated PKCS12 truststore with Cannot find any provider supporting PBEWithSHA1AndRC2_40; the PR image starts successfully and serves OpenID discovery (HTTP 200). No Java agents or extra providers are needed.

kubectl run keycloak-before --restart=Never --image=quay.io/keycloak/keycloak:26.8.0 --env=NSS_FIPS=1 -- start --http-enabled=true --hostname=http://localhost:8080 --db=dev-file
kubectl run keycloak-after --restart=Never --image=quay.io/sebastian_laskawiec/keycloak:54017 --env=NSS_FIPS=1 -- start --http-enabled=true --hostname=http://localhost:8080 --db=dev-file
kubectl logs -f keycloak-before
kubectl logs -f keycloak-after

Prior Work

#53900

AI usage information

AI agents assisted implementation and review.

Closes keycloak#53729

Signed-off-by: Sebastian Łaskawiec <sebastian.laskawiec@defenseunicorns.com>
Signed-off-by: Sebastian Łaskawiec <sebastian.laskawiec@defenseunicorns.com>
@slaskawi
slaskawi marked this pull request as ready for review October 16, 2026 09:09
@slaskawi
slaskawi requested a review from a team as a code owner October 16, 2026 09:09
Copilot AI balanced review requested due to automatic review settings October 16, 2026 09:09
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@slaskawi
Copy link
Copy Markdown
Contributor Author

@Pepo48 @shawkins This one is ready for review. The testsuite should pass but if it doesn't - I'll address the failures over the weekend.

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

Provider selection remains scoped to system truststores, regression coverage includes default and FIPS providers, and no blocking issues remain.

No open issues 🎉

Review effort: Balanced

shawkins
shawkins previously approved these changes Oct 21, 2026
@shawkins shawkins left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @slaskawi LGTM.

@shawkins
shawkins requested review from Pepo48 and vmuzikar October 21, 2026 15:55
@vmuzikar vmuzikar left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@slaskawi Thank you for the PR!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should consider adding an explicit test for what this PR is actually trying to fix: same provider is used for writing and reading. I believe we're missing that at the moment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The current tests explicitly check the system property as well as the provider used to read the generated store:

In services/src/test/java/org/keycloak/truststore/FileTruststoreProviderFactoryTest.java, generatedTruststoreIsReadWithItsWriterProvider():

  1. Reads the expected certificates from the PEM fixture.
  2. Calls TruststoreBuilder.setSystemTruststore(...) to generate and save the truststore. That production method publishes the writer's truststore.getProvider().getName() as javax.net.ssl.trustStoreProvider.
  3. Initializes FileTruststoreProviderFactory without an explicit truststore configuration, so it loads the generated store using the system properties.
  4. Explicitly asserts System.getProperty(TruststoreBuilder.SYSTEM_TRUSTSTORE_PROVIDER_KEY) equals "BC" and the loaded store's getProvider().getName() also equals "BC".
  5. Checks the loaded type is PKCS12, the certificate count matches the fixture, and every expected certificate is present.

In crypto/fips1402/src/test/java/org/keycloak/crypto/fips/test/FIPS1402KeystoreTypesTest.java, generatedTruststoreIsReadWithItsWriterProvider() exercises the same generation-and-readback path, explicitly asserts both the property and reader provider equal "BCFIPS", and checks the preferred generated store type and retained certificates.

Separately, testSetSystemTruststoreUsesPkcs12ByDefault() and testSetSystemTruststoreUsesPreferredBcfksType() in services/src/test/java/org/keycloak/truststore/TruststoreBuilderTest.java already assert the generated path, type, and password properties. Those two tests do not currently assert the provider property; adding that assertion would be straightforward, but the explicit provider-property checks are already in the readback tests above.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@slaskawi Thanks for the reply. Yes, we're checking the indirect effects the truststore logic. It could still happen that e.g. FileTruststoreProviderFactory ignores javax.net.ssl.trustStoreProvider, and we might not notice that from the test, or that the builder uses a different provider that what is then stored in javax.net.ssl.trustStoreProvider. But that's a very marginal risk. Hence approving, thanks!

Signed-off-by: Sebastian Łaskawiec <sebastian.laskawiec@defenseunicorns.com>
Copilot AI balanced review requested due to automatic review settings October 26, 2026 07:44
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@vmuzikar vmuzikar left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@vmuzikar
vmuzikar merged commit 895e804 into keycloak:main Oct 26, 2026
98 of 169 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants

0