Skip to content

Throw BadPaddingException on RSA decrypt failures#216

Merged
rlm2002 merged 1 commit into
wolfSSL:masterfrom
cconlon:rsaPkcs1BadPadding
May 14, 2026
Merged

Throw BadPaddingException on RSA decrypt failures#216
rlm2002 merged 1 commit into
wolfSSL:masterfrom
cconlon:rsaPkcs1BadPadding

Conversation

@cconlon

@cconlon cconlon commented May 12, 2026

Copy link
Copy Markdown
Member

This PR fixes RSA decrypt exception handling in WolfCryptCipher to match expected JCE Cipher behavior:

  • Throw javax.crypto.BadPaddingException on RSA/ECB/PKCS1Padding and RSA/ECB/OAEP* decrypt failures, instead of propagating a WolfCryptException.
  • Throw IllegalBlockSizeException when RSA decrypt input length does not match the modulus size.

Includes JUnit tests to prevent regression.

@cconlon cconlon self-assigned this May 12, 2026
Copilot AI review requested due to automatic review settings May 12, 2026 21:00
@cconlon cconlon changed the title Throw BadPaddingException on RSA/ECB/PKCS1Padding decrypt failure Throw BadPaddingException on RSA decrypt failures May 12, 2026

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR aligns WolfCryptCipher RSA decrypt error handling with JCE Cipher expectations by mapping native RSA decrypt failures to JCE exceptions and adding regression tests for wrong-key decrypt paths.

Changes:

  • Map RSA OAEP and PKCS#1 decrypt failures to BadPaddingException instead of propagating WolfCryptException.
  • Add RSA decrypt input-length checks intended to throw IllegalBlockSizeException when ciphertext length doesn’t match the modulus size.
  • Add JUnit regression tests covering wrong-key decrypt scenarios and tighten existing “too big data” expectations.

Reviewed changes

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

File Description
src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java Adds RSA ciphertext length checks and remaps native decrypt errors to BadPaddingException.
src/test/java/com/wolfssl/provider/jce/test/WolfCryptCipherTest.java Adds regression tests and test vectors for wrong-key RSA decrypt; updates expectations for oversize input.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java Outdated
Comment thread src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java Outdated
Comment thread src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java
Comment thread src/test/java/com/wolfssl/provider/jce/test/WolfCryptCipherTest.java Outdated
@cconlon cconlon force-pushed the rsaPkcs1BadPadding branch from caa979a to 0da3d08 Compare May 12, 2026 22:10

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-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.

Fenrir Automated Review — PR #216

Scan targets checked: wolfcrypt-jni-bugs, wolfcrypt-jni-src

No new issues found in the changed files. ✅

@cconlon cconlon assigned rlm2002 and unassigned cconlon May 13, 2026
@rlm2002 rlm2002 merged commit 56fee0b into wolfSSL:master May 14, 2026
80 checks passed
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.

4 participants