8000 Support Post-Quantum Cryptography (ML-DSA) OIDC token signing and key… by arnabnandy7 · Pull Request #50358 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Support Post-Quantum Cryptography (ML-DSA) OIDC token signing and key… - #50358

Open
arnabnandy7 wants to merge 2 commits into
keycloak:mainfrom
arnabnandy7:feature/post-quantum-keys
Open

arnabnandy7 wants to merge 2 commits into
keycloak:mainfrom
arnabnandy7:feature/post-quantum-keys

Conversation

@arnabnandy7
Copy link
Copy Markdown
Contributor

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

  • Core Algorithm Mappings: Integrated ML-DSA-44, ML-DSA-65, and ML-DSA-87 constants and mapped them to KeyType.AKP in JavaAlgorithm.java.
  • JWK & Thumbprint: Configured JWKSUtils to support AKP JWK thumbprints (using alg and pub claims) and updated JWKSServerUtils to format AKP keys into JWK representations.
  • Signer/Verifier SPI Providers: Implemented new SignatureProvider and ClientSignatureVerifierProvider factories for ML-DSA and registered them via ServiceLoader.
  • Admin Console Key Generation: Created a new generated ML-DSA key provider GeneratedMlDsaKeyProvider and 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:

mvn test -pl crypto/default,services -am "-Dtest=DefaultCryptoAKPJWKTest,DefaultCryptoJWKSUtilsTest,CryptoUtilsTest"

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

Copilot AI balanced review requested due to automatic review settings June 25, 2026 22:06
@arnabnandy7
arnabnandy7 requested a review from a team as a code owner June 25, 2026 22:06
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.

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.AKP wiring (signing/verifying + JWKS thumbprints).
  • Introduced ML-DSA SignatureProvider and ClientSignatureVerifierProvider implementations 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.

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.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings June 25, 2026 22:48
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.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings June 26, 2026 09:24
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.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings June 26, 2026 09:35
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.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

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.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings July 10, 2026 18:14
@arnabnandy7
arnabnandy7 force-pushed the feature/post-quantum-keys branch from 75fb3bf to 66bc1cd Compare July 10, 2026 18:16
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.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings July 10, 2026 18:18
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.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings July 10, 2026 18:25
Copilot AI review requested due to automatic review settings August 21, 2026 08:22
@arnabnandy7
arnabnandy7 force-pushed the feature/post-quantum-keys branch from a55b302 to ed0d9b2 Compare August 21, 2026 08:22
@arnabnandy7
arnabnandy7 force-pushed the feature/post-quantum-keys branch from afc29ec to a9132e0 Compare August 21, 2026 08:24
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.

Pull request overview

Copilot reviewed 53 out of 53 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 21, 2026 08:26
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.

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.

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If 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

Keycloak CI - Clustering IT

org.awaitility.core.ConditionTimeoutException: Assertion condition defined as a Lambda expression in org.keycloak.testsuite.cluster.JGroupsCertificateRotationClusterTest expected: <2> but was: <1> within 1 minutes.
	at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:167)
	at org.awaitility.core.AssertionCondition.await(AssertionCondition.java:119)
	at org.awaitility.core.AssertionCondition.await(AssertionCondition.java:31)
	at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:1160)
...

Report flaky test

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 review overview

🟡 Changes recommended

Existing exact-list integration tests will fail when the newly registered ML-DSA providers are available.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (2)

Copilot AI balanced review requested due to automatic review settings September 30, 2026 08:37
@arnabnandy7
arnabnandy7 force-pushed the feature/post-quantum-keys branch from 8d7bafc to 6878ee0 Compare September 30, 2026 08:37
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 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)

@nithusha21 nithusha21 left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

  1. TokenVerifier's publicKey(...) path takes the key's alg from the token header. In the MLDSA branch, key.setAlgorithm(jws.getHeader().getRawAlgorithm()), so in this path nothing checks that the key's parameter set matches alg (RFC 8725 §3.1). Safety then depends on the JCA provider throwing when, say, an ML-DSA-44 key is given to Signature.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 or NamedParameterSpec) and compare it with the header.
  2. ClientMLDSASignatureVerifierContext.validateKey with no key alg. The mismatch case Copilot flagged is now rejected, which is great. But when the client key has no alg, it still adopts the header's. RFC 9964 §3 makes alg REQUIRED 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.
  3. getJavaAlgorithmForHash → "SHAKE256". JCA's SHAKE256 digest produces 64 bytes (checked on JDK 25), which matches the OpenID Connect Token Hash Algorithm Implementer's Guide's SHAKE256/64 for ML-DSA, so at_hash interop works. A test pinning the length would help, since it relies on a provider default. (Separate and pre-existing: Ed448 also maps to SHAKE256, 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.)
  4. The AKP thumbprint members (alg, pub, with kty) in JWKSUtils match 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>
@arnabnandy7
arnabnandy7 force-pushed the feature/post-quantum-keys branch from 6878ee0 to f63da61 Compare December 5, 2026 13:49
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.

🟡 Changes recommended

ML-DSA tests fail because the feature is disabled during initialization, and native JDK ML-DSA public keys are misclassified as OCT, causing the client verifier to reject them.

2 open issues

Review effort: Balanced

Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
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.

🔵 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

@arnabnandy7
Copy link
Copy Markdown
Contributor Author

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.

Thanks for the detailed review, @nithusha21! I’ve rebased the PR and pushed the fixes in 992b4e4.

TokenVerifier.publicKey(...) now derives the ML-DSA parameter set from the encoded public key and checks it against the JWT header before verification. AKP client JWKs missing alg are rejected during parsing, and the client verifier also rejects keys without it. I added an end-to-end assertion that the decoded at_hash is 32 bytes.

If your offer still stands, I’d appreciate a run against your RFC 9964 conformance corpus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Post-Quantum Keys choice for signing/encryption

5 participants

0