Repository navigation
Support Post-Quantum Cryptography (ML-DSA) OIDC token signing and key… - #50358
arnabnandy7 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for post-quantum ML-DSA (FIPS 204) signature algorithms in Keycloak for OIDC/JWS by introducing AKP key handling, new signature/verifier SPI providers, and an admin key-provider for generated ML-DSA realm keys.
Changes:
- Added ML-DSA-44/65/87 algorithm → JCA mapping and associated
KeyType.AKPwiring (signing/verifying + JWKS thumbprints). - Introduced ML-DSA
SignatureProviderandClientSignatureVerifierProviderimplementations and registered them via ServiceLoader. - Added an admin-console key provider to generate/rotate ML-DSA keys and updated tests to ensure provider discovery.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| services/src/test/java/org/keycloak/crypto/CryptoUtilsTest.java | Extends provider-discovery test coverage to ML-DSA algorithms. |
| services/src/main/resources/META-INF/services/org.keycloak.keys.KeyProviderFactory | Registers the generated ML-DSA key provider factory. |
| services/src/main/resources/META-INF/services/org.keycloak.crypto.SignatureProviderFactory | Registers ML-DSA signature provider factories. |
| services/src/main/resources/META-INF/services/org.keycloak.crypto.ClientSignatureVerifierProviderFactory | Registers ML-DSA client signature verifier factories. |
| services/src/main/java/org/keycloak/protocol/oidc/utils/JWKSServerUtils.java | Emits AKP keys into JWKS responses. |
| services/src/main/java/org/keycloak/keys/GeneratedMlDsaKeyProviderFactory.java | Adds generated ML-DSA key provider factory + fallback key generation logic. |
| services/src/main/java/org/keycloak/keys/GeneratedMlDsaKeyProvider.java | Loads persisted/generated ML-DSA keys into KeyWrapper. |
| services/src/main/java/org/keycloak/keys/AbstractMlDsaKeyProviderFactory.java | Defines shared ML-DSA key provider factory config/validation building blocks. |
| services/src/main/java/org/keycloak/keys/AbstractMlDsaKeyProvider.java | Implements common ML-DSA KeyProvider behavior and KeyWrapper creation. |
| services/src/main/java/org/keycloak/crypto/MLDSASignatureProvider.java | Implements server-side ML-DSA signing/verifying via the Signature SPI. |
| services/src/main/java/org/keycloak/crypto/MLDSAClientSignatureVerifierProvider.java | Implements client assertion verification entry-point for ML-DSA. |
| services/src/main/java/org/keycloak/crypto/MLDSA44SignatureProviderFactory.java | Factory for ML-DSA-44 SignatureProvider. |
| services/src/main/java/org/keycloak/crypto/MLDSA65SignatureProviderFactory.java | Factory for ML-DSA-65 SignatureProvider. |
| services/src/main/java/org/keycloak/crypto/MLDSA87SignatureProviderFactory.java | Factory for ML-DSA-87 SignatureProvider. |
| services/src/main/java/org/keycloak/crypto/MLDSA44ClientSignatureVerifierProviderFactory.java | Factory for ML-DSA-44 ClientSignatureVerifierProvider. |
| services/src/main/java/org/keycloak/crypto/MLDSA65ClientSignatureVerifierProviderFactory.java | Factory for ML-DSA-65 ClientSignatureVerifierProvider. |
| services/src/main/java/org/keycloak/crypto/MLDSA87ClientSignatureVerifierProviderFactory.java | Factory for ML-DSA-87 ClientSignatureVerifierProvider. |
| services/src/main/java/org/keycloak/crypto/ClientMLDSASignatureVerifierContext.java | Adds ML-DSA-specific client signature verification context. |
| core/src/main/java/org/keycloak/util/KeyWrapperUtil.java | Enables generic asymmetric signer/verifier contexts for AKP keys. |
| core/src/main/java/org/keycloak/util/JWKSUtils.java | Adds AKP thumbprint member handling (including alg). |
| core/src/main/java/org/keycloak/crypto/JavaAlgorithm.java | Adds ML-DSA algorithm and hash mappings; maps ML-DSA to KeyType.AKP. |
56e7462 to
7017ed6
Compare
75fb3bf to
66bc1cd
Compare
a55b302 to
ed0d9b2
Compare
afc29ec to
a9132e0
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 53 out of 53 changed files in this pull request and generated no new comments.
Suppressed comments (1)
services/src/main/java/org/keycloak/keys/GeneratedMlDsaKeyProviderFactory.java:151
- A missing or malformed persisted public key lets the Base64 decoder's runtime exception escape the component-validation path, producing either a generic “invalid provider type” response or a server error instead of an ML-DSA key validation error. Wrap decoding in
ComponentValidationException, as the generated EdDSA provider does.
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.cluster.JGroupsCertificateRotationClusterTest#testCoordinatorHasScheduleTask |
a9132e0 to
8d7bafc
Compare
8d7bafc to
6878ee0
Compare
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The security-sensitive cryptographic changes span multiple token-verification paths and require final human interoperability and provider review.
Review effort: Balanced
Findings: None
Resolved since last review (1)
There was a problem hiding this comment.
Thanks for keeping this going. A few things from reading the verification path at 6878ee0. It needs a rebase first: merge state is dirty, and CI likely needs a rerun for the flaky-test label.
TokenVerifier'spublicKey(...)path takes the key's alg from the token header. In theMLDSAbranch,key.setAlgorithm(jws.getHeader().getRawAlgorithm()), so in this path nothing checks that the key's parameter set matchesalg(RFC 8725 §3.1). Safety then depends on the JCA provider throwing when, say, an ML-DSA-44 key is given toSignature.getInstance("ML-DSA-65"). I checked that the JDK 25 provider does reject this (InvalidKeyException), but please confirm BC and BC-FIPS behave the same. Better still, derive the alg from the key (SPKI OID orNamedParameterSpec) and compare it with the header.ClientMLDSASignatureVerifierContext.validateKeywith no keyalg. The mismatch case Copilot flagged is now rejected, which is great. But when the client key has noalg, it still adopts the header's. RFC 9964 §3 makesalgREQUIRED on AKP keys, so a client JWK without it is malformed and should be rejected at import, not filled in from the attacker-controlled header.getJavaAlgorithmForHash→"SHAKE256". JCA'sSHAKE256digest produces 64 bytes (checked on JDK 25), which matches the OpenID Connect Token Hash Algorithm Implementer's Guide's SHAKE256/64 for ML-DSA, soat_hashinterop works. A test pinning the length would help, since it relies on a provider default. (Separate and pre-existing: Ed448 also maps toSHAKE256, i.e. 64 bytes, while the guide's Table 1 lists Ed448 as SHAKE256 with 114-byte output. The guide is draft 00, so that's probably worth its own issue asking which Keycloak intends to follow.)- The AKP thumbprint members (
alg,pub, withkty) inJWKSUtilsmatch RFC 9964. 👍
I also have an RFC 9964 conformance corpus at https://github.com/CipherraAI/jose-pq-interop. If it's useful once the branch is rebased, I'm happy to run Keycloak's verifier through it.
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
6878ee0 to
f63da61
Compare
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed to evaluate ML-DSA compatibility gaps affecting advertised mDoc algorithms and certificate-based proof and key attestation validation.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
Thanks for the detailed review, @nithusha21! I’ve rebased the PR and pushed the fixes in 992b4e4.
If your offer still stands, I’d appreciate a run against your RFC 9964 conformance corpus. |


Description
This PR implements support for Post-Quantum Cryptography (PQC) signature algorithms (ML-DSA-44, ML-DSA-65, ML-DSA-87) in Keycloak. It extends Keycloak's core JWK, JWS, and SPI providers to support OIDC token signing and verification using these FIPS 204 standardized algorithms.
Key Changes
ML-DSA-44,ML-DSA-65, andML-DSA-87constants and mapped them toKeyType.AKPinJavaAlgorithm.java.JWKSUtilsto support AKP JWK thumbprints (usingalgandpubclaims) and updatedJWKSServerUtilsto format AKP keys into JWK representations.SignatureProviderandClientSignatureVerifierProviderfactories for ML-DSA and registered them via ServiceLoader.GeneratedMlDsaKeyProviderand factory so that administrators can generate and rotate ML-DSA keys directly from the Realm Keys management page.Testing & Verification
All modifications have been thoroughly validated with existing and updated test cases:
DefaultCryptoAKPJWKTest: Passed (verified AKP JWK decoding/encoding).DefaultCryptoJWKSUtilsTest: Passed (verified thumbprint calculations for AKP).CryptoUtilsTest: Passed (verified ML-DSA signature providers retrieval).Test execution command:
AI Agent Disclosure
In accordance with Keycloak's generative AI usage guidelines (Section 11.4 of CONTRIBUTING.md), this PR was generated and verified using Antigravity, an autonomous AI coding assistant. The agent analyzed the codebase, proposed the implementation plan, created the new provider classes, and executed tests to verify correctness.
Closes #50355