Repository navigation
Decrypt messages whose content key is wrapped with RSAES-OAEP - #635
Merged
Merged
Conversation
BCCryptoHelper.decrypt unwrapped the content key with BouncyCastle's lightweight BcRSAKeyTransEnvelopedRecipient, whose BcRSAAsymmetricKeyUnwrapper always uses PKCS#1 v1.5 and ignores the key-encryption algorithm named in the envelope. A key wrapped with RSAES-OAEP (1.2.840.113549.1.1.7) therefore failed with "unable to recover secret key: block incorrect", and the partner got a decryption-failed MDN. Microsoft BizTalk wraps with OAEP, so no message from a BizTalk partner could be received. JceKeyTransEnvelopedRecipient reads the algorithm from the recipient info and handles PKCS#1 v1.5 and OAEP alike. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
uhurusurfa
approved these changes
Oct 25, 2026
uhurusurfa
left a comment
Contributor
There was a problem hiding this comment.
🚀 Thanks for the fix.
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.
Problem
An inbound message whose content key is wrapped with RSAES-OAEP (
1.2.840.113549.1.1.7) can't be decrypted. It fails with:The partner then gets a
processed/error:decryption-failedMDN. We hit this with a trading partner running Microsoft BizTalk, which wraps with OAEP. A packet capture confirmed the envelope was addressed to the correct certificate. Every message from that partner failed, while messages wrapped with PKCS#1 v1.5 decrypted fine.Cause
BCCryptoHelper.decryptunwraps with BouncyCastle's lightweightBcRSAKeyTransEnvelopedRecipient. Its unwrapper,BcRSAAsymmetricKeyUnwrapper.createAsymmetricUnwrapper, always returnsnew PKCS1Encoding(new RSABlindedEngine())and ignores the key-encryption algorithm named in the recipient info. So an OAEP-wrapped key is decoded as PKCS#1 v1.5 and fails the padding check.Fix
Use
JceKeyTransEnvelopedRecipient((PrivateKey) receiverKey).setProvider("BC"). It reads the algorithm and its parameters from the envelope, so PKCS#1 v1.5 and OAEP both work. This matches the existingKeyAgreebranch next to it, which already uses the JCE recipient. Sending is unchanged.Tests
The new
KeyTransportDecryptionTestencrypts a part to a generated key in three ways (PKCS#1 v1.5, OAEP with default SHA-1 parameters, OAEP with SHA-256) and asserts thatBCCryptoHelper.decryptrecovers the payload.master, both OAEP cases fail withblock incorrect../mvnw -pl Server -am test: 249 tests run, 0 failures (1 skipped, as before).We are running this change on 4.8.3 on our own AS2 host, where it now decrypts every message from that BizTalk partner.
🤖 Generated with Claude Code