Skip to content

Add StAX inbound negative tests for ML-KEM decryption - #5

Merged
ffang merged 1 commit into
ffang:PQC-ENCRYPTIONfrom
Arpan0995:pqc-encryption-inbound-tests
Aug 24, 2026
Merged

Add StAX inbound negative tests for ML-KEM decryption#5
ffang merged 1 commit into
ffang:PQC-ENCRYPTIONfrom
Arpan0995:pqc-encryption-inbound-tests

Conversation

@Arpan0995

Copy link
Copy Markdown

As discussed on apache#652: this adds the StAX inbound negative coverage.

The existing ML-KEM StAX negative tests (testMLKEMStaxWrongRecipientPrivateKeyFailsCleanly, testMLKEMStaxTruncatedEncapsulationRejected) decrypt through the DOM XMLCipher helper, so the StAX inbound handler's Generic Hybrid Cipher branch (XMLEncryptedKeyInputHandler#getGenericHybridSecret) was only exercised on the happy path. This adds two parameterized tests across ML-KEM-512/768/1024 that drive the same two rejections through InboundXMLSec#processInMessage:

  • testMLKEMStaxInboundWrongRecipientKeyRejected
  • testMLKEMStaxInboundTruncatedEncapsulationRejected

Because ML-KEM implicit rejection and the handler's random-CEK timing mitigation defer the failure to the AES-256-GCM tag check, both surface to the caller as an XMLStreamException; the tests assert the inbound path rejects the message rather than yielding plaintext, so a future change that reintroduces a decrypting path here would fail the tests. (I confirmed the assertions are meaningful with a positive control: a valid document through the same serialize-then-processInMessage path decrypts and recovers the content.)

Verified with mvn test -Dtest=StaxMLKEMEncryptionTest -P bouncycastle (18 executions, 0 failures: the six new plus the existing twelve); without the profile it compiles and skips via the existing assumeTrue guard.

The existing ML-KEM StAX negative tests (wrong recipient key, truncated
encapsulation) decrypt through the DOM XMLCipher helper, so the StAX
inbound handler's Generic Hybrid Cipher failure path was only covered on
the happy path. Add two parameterized tests across ML-KEM-512/768/1024
that drive the same two rejections through InboundXMLSec#processInMessage.

Because ML-KEM implicit rejection and the inbound handler's random-CEK
timing mitigation defer the failure to the AES-256-GCM tag check, both
surface to the caller as an XMLStreamException; the tests assert the
inbound path rejects the message rather than yielding plaintext.
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