Add StAX inbound negative tests for ML-KEM decryption - #5
Merged
ffang merged 1 commit intoAug 24, 2026
Merged
Conversation
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.
ffang
approved these changes
Aug 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As discussed on apache#652: this adds the StAX inbound negative coverage.
The existing ML-KEM StAX negative tests (
testMLKEMStaxWrongRecipientPrivateKeyFailsCleanly,testMLKEMStaxTruncatedEncapsulationRejected) decrypt through the DOMXMLCipherhelper, 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 throughInboundXMLSec#processInMessage:testMLKEMStaxInboundWrongRecipientKeyRejectedtestMLKEMStaxInboundTruncatedEncapsulationRejectedBecause 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-processInMessagepath 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 existingassumeTrueguard.