Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved moderate issues remain in provider selection and regression coverage.
1 open finding
What changed in this PR
Fixes generated PKCS12 truststore compatibility by selecting the JDK implementation and adding regression coverage.
Changes:
- Override PKCS12 truststore creation in
DefaultCryptoProvider. - Add provider-selection regression coverage.
| File | Summary |
|---|---|
services/src/test/java/org/keycloak/truststore/TruststoreBuilderTest.java |
Verifies PKCS12 provider selection; round-trip coverage is still needed. |
crypto/default/src/main/java/org/keycloak/crypto/def/DefaultCryptoProvider.java |
Selects the PKCS12 implementation; explicit JDK provider selection is still needed. |
🧠 Review effort: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…match Closes keycloak#53729 Signed-off-by: Peter Zaoral <pzaoral@redhat.com>
My understanding is that it's the combination of #51405 with #50110. The essential problem seems to be ensuring every path that loads the truststore uses a provider that is compatible. #50110 (comment) indicated: "To sum it up - PKCS12 is absolutely fine; the problem is the mix of OpenJDK 21 defaults and how Keycloak configures it." So if my understanding is correct there, with JDK 21 the created PKCS12 truststore is not usable by the BC provider.
I think that will work for paths that specify the JDK provider or use CryptoIntegration - but could still fail if the logic is directly picking up the BC provider. An alternative narrow fix (that would preserve the intent of #50110) would be to change the file truststore provider to use CryptoIntegration - as then the truststore would be loaded by BC as well. Or should we consider going further to ensure:
@slaskawi WDYT? |
This is my understanding too. Here's the order of events as I understand it: @Pepo48’s approach explicitly selects SUN for PKCS12 truststores in DefaultCryptoProvider. This should address the reported RC2 failure because SUN honors certProtectionAlgorithm=NONE.
@shawkins I think that's just a typo and you probably mean that BC created PKCS12 cannot be read by JDK (because of As a side note - I did a small experiment and BC seems to be able to read a PKCS12 created by JDK.
I would lean into this approach as well. So essentially we'd have: This essentially would mean refactoring the // inside FileTruststoreProviderFactory.init()
try {
truststore = loadTrustStore(storepath, pass, resolvedFormat);
} catch (Exception failure) {
...
}
// new method(s) in FileTruststoreProviderFactory
KeyStore loadTrustStore(path, password, resolvedFormat) {
KeyStore store = CryptoIntegration.getProvider()
.getTrustStore(resolvedFormat); // replaces ambient provider selection
try (InputStream input = /* existing filesystem/classpath resolution */) {
store.load(
input,
password == null ? null : password.toCharArray()
);
}
return store;
} |
I mean it both ways. #53729 is because the JDK provider cannot read the BC FIPS created PKCS12, while #50110 was due to the JDK created truststore not being usable by BC FIPS.
Does that apply to BC FIPS as well? If so, how does that relate to #50110? |
Understood and agreed! I misread your previous comment.
I think the root cause is that #50110 introduced a misalignment between I can definitely put this on my plate and should be able to get a PR up either tomorrow or on Monday. If we're short on time, I'm OK with merging this PR as a "stop-the-bleeding" approach. I can revert it and introduce |
|
@slaskawi I'm fine with it. We can either merge it and proceed with the follow-up as you suggest or you can takeover and reuse this PR directly - whatever you prefer. Thank you! |
|
Thanks @Pepo48 ! Let's sync on Monday and see how far I will get. What's the cut-off date for 26.8.2? This probably should aim to squeeze it in. |
I'm not talking about what 50110 introduced - I mean what it was trying to address. Under what circumstance was a truststore created by the JDK provider not usable in BC FIPS mode? |
The #50110 aimed to solve the problematic combination of the JDK-generated System TrustStore (which it automatically created) with the Strict FIPS runtime. A shorter version of my long comment from here would be:
The #50110 changes the Trust Store type in Strict FIPS mode from OpenJDK PKCS12 to BCFKS. BCFKS guarantees that you won't be able to use anything non-FIPS compliant. |
|
Thanks @slaskawi I just wanted to make sure the scope of the statement Locally on main with JDK 25 in a non-fips environment I see:
@slaskawi I don't think I've ever really fully reproduced the exception scenario with #50110 - I still must be missing something. Perhaps it's a JDK version issue, requires running in a fips enabled environment, or changes to java.security? |
|
@shawkins We might want to wait for the issue author to tell us how he reproduced it presiesly but I suspect it's a FIPS-configured OS (with Red Hat OpenJDK) with a non-FIPS Keycloak. I described this in detail here. If that's the case, the solution is like you descibed earlier - "ensuring every path that loads the truststore uses a provider that is compatible". I took this approach and implemented a potential fix: #54017 I will mark it for review once I tidy up the testsuite (which should happen today or over the weekend). |
|
With @shawkins we discussed offline that we should really try and reproduce it the original issue (#53729). The fix proposed in #54017 is correcting the behaviour with selecting the crypto providers, however technically it might not be needed if #53729 is not really a real issue. Perhaps I'm missing something? |
Thanks for chiming in @vmuzikar! I agree - we might want to wait for the end user comment on this. At the same time, I discovered that this happens on FIPS-enabled systems with a non-FIPS Keyclaok containers running on them. I posted the minimal reproducer (that can be evaluated on a non-FIPS system) here. If you guys have access to a properly configured Red Hat RHEL system with OpenShift installed on it - you can quickly check if running non-FIPS Keycloak causes the same failure. Unfortunately, I have no such system to test on (that's why I came up with that reproducer). |
|
I think we can close this now as these changes are no longer needed nor address what #53729 is trying to do. |

…match
Closes #53729
This was introduced in #51405, which fixed the truststore init ordering so that
FileTruststoreProviderFactoryactually reads the generatedkeycloak-truststore.p12. Before that fix, the read never happened against the generated file, so the bug was hidden.The fix overrides
getTrustStore()inDefaultCryptoProviderto return a JDK KeyStore for PKCS12 truststores (they only hold certs, no private keys, so BC is not needed). The JDK implementation honours theNONEproperty and stores certs unencrypted.