Skip to content

fix: compare RSA blocks instead of parsing - #1203

Open
ejohnstown wants to merge 1 commit into
wolfSSL:masterfrom
ejohnstown:sf24
Open

fix: compare RSA blocks instead of parsing#1203
ejohnstown wants to merge 1 commit into
wolfSSL:masterfrom
ejohnstown:sf24

Conversation

@ejohnstown

@ejohnstown ejohnstown commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

RFC 8332 section 3 advises against verifying RSASSA-PKCS1-v1_5 by applying the key and parsing the output. wolfSSH_RsaVerify() builds the expected EMSA-PKCS1-v1_5 block, applies the key with a raw public operation, and compares whole modulus-sized blocks.

  • verify through wc_RsaFunction() and a constant-time block compare
  • reject a key too small for the digest and minimum padding
  • reject a wc_RsaEncryptSize() error rather than casting it
  • carve the three working blocks from one allocation
  • add test_RsaVerify_BadPadding() for pad and block-type errors

The test passes against the old code too; wolfSSL's unpadding is already strict, so it guards the property rather than a live defect.

Issue: F-10574

Copilot AI lite review requested due to automatic review settings August 27, 2026 19:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates wolfSSH_RsaVerify() to follow RFC 8332 §3 guidance by verifying RSASSA-PKCS1-v1_5 signatures via a raw public RSA operation and constant-time comparison of full modulus-sized EMSA-PKCS1-v1_5 blocks, rather than parsing the decrypted output. It also adds a unit test that exercises malformed padding cases to ensure the implementation rejects non–well-formed encodings.

Changes:

  • Reworked wolfSSH_RsaVerify() to build an expected EMSA-PKCS1-v1_5 block, recover the signature block via wc_RsaFunction(), and compare full blocks in constant time.
  • Added key-size validation and refactored temporary buffers into a single heap allocation.
  • Added test_RsaVerify_BadPadding() to validate rejection of malformed padding and incorrect block type.

Reviewed changes

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

File Description
tests/unit.c Adds a padding-focused RSA verify unit test and wires it into the unit test runner.
src/internal.c Implements block-based RSA PKCS#1 v1.5 verification using raw public operation + constant-time full-block compare.

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

Comment thread src/internal.c
Comment thread tests/unit.c

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

Scan targets checked: wolfssh-bugs, wolfssh-src

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Comment thread tests/unit.c
Comment thread tests/unit.c
RFC 8332 section 3 advises against verifying RSASSA-PKCS1-v1_5 by
applying the key and parsing the output. wolfSSH_RsaVerify() builds the
expected EMSA-PKCS1-v1_5 block, applies the key with a raw public
operation, and compares whole modulus-sized blocks.

- verify through wc_RsaFunction() and a constant-time block compare
- reject a signature not less than the modulus, which the raw operation
  would otherwise reduce into a second encoding of the same signature
- reject a key too small for the digest, and a wc_RsaEncryptSize() error
- carve the four working blocks from one allocation
- add test_RsaVerify_BadPadding() and test_RsaVerify_SigRange()

Offload builds leave the modulus empty, so the range check is skipped
there. That check walks the bytes itself rather than calling memcmp(),
which some libcs compare as signed char, ordering the modulus's high
byte backwards. The padding cases pass against the old code as well;
the range case does not.

Issue: F-10574

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

Scan targets checked: wolfssh-bugs, wolfssh-src

Fenrir result: Approved ✅

No new issues found in the changed files.

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

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed their stale review August 28, 2026 18:54

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

@ejohnstown
ejohnstown requested a review from philljj August 28, 2026 22:30
@philljj philljj self-assigned this Aug 28, 2026
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