Repository navigation
fix: use configured crypto provider to read generated truststores - #54017
Conversation
Closes keycloak#53729 Signed-off-by: Sebastian Łaskawiec <sebastian.laskawiec@defenseunicorns.com>
0dbdd78 to
895add0
Compare
Signed-off-by: Sebastian Łaskawiec <sebastian.laskawiec@defenseunicorns.com>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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():
- Reads the expected certificates from the PEM fixture.
- Calls
TruststoreBuilder.setSystemTruststore(...)to generate and save the truststore. That production method publishes the writer'struststore.getProvider().getName()asjavax.net.ssl.trustStoreProvider. - Initializes
FileTruststoreProviderFactorywithout an explicit truststore configuration, so it loads the generated store using the system properties. - Explicitly asserts
System.getProperty(TruststoreBuilder.SYSTEM_TRUSTSTORE_PROVIDER_KEY)equals"BC"and the loaded store'sgetProvider().getName()also equals"BC". - 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.
There was a problem hiding this comment.
@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>
Summary
Publish and honor
javax.net.ssl.trustStoreProviderwhen loading system truststores. Preserve explicit SPI and HTTPS truststore loading.Related Ticket
Closes #53729
Reproducer
On Kubernetes,
NSS_FIPS=1simulates host-FIPS detection in the Red Hat JVM. The first pod fails reading the generated PKCS12 truststore withCannot 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.Prior Work
#53900
AI usage information
AI agents assisted implementation and review.