Skip to content

Emit dsig11:DEREncodedKeyValue for keys without a structured KeyValue form - #4

Merged
ffang merged 1 commit into
ffang:PQC-SIGNATUREfrom
Arpan0995:pqc-signature-keyvalue-fix
Aug 24, 2026
Merged

Emit dsig11:DEREncodedKeyValue for keys without a structured KeyValue form#4
ffang merged 1 commit into
ffang:PQC-SIGNATUREfrom
Arpan0995:pqc-signature-keyvalue-fix

Conversation

@Arpan0995

Copy link
Copy Markdown

As discussed on apache#651: this fixes the empty-KeyValue issue for ML-DSA StAX signing, taking the DEREncodedKeyValue route you preferred.

The problem. XMLSecurityUtils#createKeyValueTokenStructure dispatched on the public key algorithm with branches for RSA, DSA and EC only. For an ML-DSA key it fell through and emitted an empty <dsig:KeyValue/>, which is not schema-valid and which the StAX inbound processor rejects at schema validation (cvc-complex-type.2.4.b) before signature verification is ever reached.

The fix. For key types with no structured KeyValue form, emit a dsig11:DEREncodedKeyValue holding the DER SubjectPublicKeyInfo (PublicKey.getEncoded()). That is schema-valid inside dsig:KeyValue through the same ##other wildcard the existing dsig11:ECKeyValue branch relies on, and it mirrors the DOM-side DEREncodedKeyValue support this PR already extends for ML-DSA. A key whose encoding is unavailable is rejected with a clear XMLSecurityException rather than an empty element.

Test. Adds StaxMLDSAKeyValueTest, parameterized across ML-DSA-44/65/87, asserting the KeyValue is non-empty and carries a DEREncodedKeyValue, that its DER decodes back to the signer's public key, and that the recovered key verifies the signature. Verified with mvn test -P bouncycastle (3/3); without the profile it compiles and skips via the existing assumeTrue guard.

Scope. This corrects the malformed output so it is schema-valid and the embedded key is recoverable and usable. Full StAX-inbound round-trip additionally needs the inbound path to extract a public key from a DEREncodedKeyValue, which it does not do for any key type today; with this change the inbound path now gets past schema validation and fails later at key resolution ("No or unsupported key in KeyValue") rather than at the schema. Adding inbound DEREncodedKeyValue extraction is a larger, separate piece and is intentionally not in this change; I am happy to follow up with it if you would like.

… form

StAX signing with the KeyValue key identifier dispatched on the public
key algorithm with branches for RSA, DSA and EC only. For any other key
type (ML-DSA, EdDSA) it fell through and emitted an empty <dsig:KeyValue/>,
which the inbound processor then rejects at schema validation before
reaching signature verification.

Emit a dsig11:DEREncodedKeyValue holding the DER SubjectPublicKeyInfo for
those key types, which is schema-valid inside dsig:KeyValue via its ##other
wildcard and mirrors the DOM DEREncodedKeyValue support. Adds a
parameterized test across ML-DSA-44/65/87 asserting the KeyValue carries a
DEREncodedKeyValue that round-trips to the signer's public key and verifies
the signature.

Inbound extraction of a public key from DEREncodedKeyValue is not added
here; the StAX inbound path has no DEREncodedKeyValue support for any key
type yet.
@ffang
ffang merged commit 036194d into ffang:PQC-SIGNATURE Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants