Skip to content

Reject wrong-length RSA signatures in Signature.verify() - #297

Merged
rlm2002 merged 1 commit into
wolfSSL:masterfrom
cconlon:rsaVerifySigLength
Oct 21, 2026
Merged

rlm2002 merged 1 commit into
wolfSSL:masterfrom
cconlon:rsaVerifySigLength

Conversation

@cconlon

@cconlon cconlon commented Oct 13, 2026

Copy link
Copy Markdown
Member

This PR makes WolfCryptSignature.engineVerify() throw SignatureException when an RSA or RSA-PSS signature is not exactly the modulus length, as RFC 8017 sections 8.1.2 and 8.2.2 require. Before, the result depended on the native wolfSSL version. Older versions accepted a signature with an extra leading zero byte, while wolfCrypt FIPS v7 rejects it. The new check gives the same result on every native version and matches SunRsaSign.

Changes

  • Check the RSA signature length against Rsa.getEncryptSize() in engineVerify(), after the digest is finalized so the hash state still resets.
  • Add testRsaVerifyRejectsWrongLengthSignature, which checks that signatures one byte longer or shorter are rejected for both SHA256withRSA and RSASSA-PSS, and that a valid signature still verifies afterward.

@cconlon cconlon self-assigned this Oct 13, 2026
@cconlon
cconlon requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot October 13, 2026 22:51
@cconlon cconlon changed the title JCE: reject wrong-length RSA signatures in Signature.verify( Reject wrong-length RSA signatures in Signature.verify( Oct 13, 2026
@cconlon cconlon changed the title Reject wrong-length RSA signatures in Signature.verify( Reject wrong-length RSA signatures in Signature.verify() Oct 13, 2026

@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 #297

Scan targets checked: wolfcrypt-jni-src, wolfcrypt-jni-bugs
Coverage: 1 of 2 in-scope changed file(s) opened by the reviewer; not opened: src/test/java/com/wolfssl/provider/jce/test/WolfCryptSignatureTest.java

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

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.

🟢 Approval recommended

The implementation meets the stated requirement and includes appropriate regression coverage.

0 open findings

What changed in this PR

Enforces consistent RSA signature-length validation in the wolfJCE signature provider.

Changes:

  • Rejects RSA and RSA-PSS signatures that differ from the modulus length.
  • Tests longer, shorter, and valid signatures while confirming state recovery.
File Description
WolfCryptSignature.java Adds RSA signature-length validation.
WolfCryptSignatureTest.java Tests invalid lengths and subsequent valid verification.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@cconlon cconlon assigned rlm2002 and unassigned cconlon Oct 13, 2026
@rlm2002
rlm2002 merged commit acfa606 into wolfSSL:master Oct 21, 2026
189 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