Repository navigation
Reject wrong-length RSA signatures in Signature.verify() - #297
Conversation
…gnature.engineVerify()
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
🟢 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.
This PR makes
WolfCryptSignature.engineVerify()throwSignatureExceptionwhen 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
Rsa.getEncryptSize()inengineVerify(), after the digest is finalized so the hash state still resets.testRsaVerifyRejectsWrongLengthSignature, which checks that signatures one byte longer or shorter are rejected for bothSHA256withRSAandRSASSA-PSS, and that a valid signature still verifies afterward.