Skip to content

agent: size the signature buffer from the identity - #1179

Merged
ejohnstown merged 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_10541
Aug 20, 2026
Merged

agent: size the signature buffer from the identity#1179
ejohnstown merged 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_10541

Conversation

@yosuke-wolfssl

Copy link
Copy Markdown
Contributor

Problem

PostSignRequest() in src/agent.c signed into a fixed byte sig[256]. wc_RsaSSL_Sign() rejects an output buffer smaller than the modulus, so every RSA identity above 2048 bits — including the 3072-bit ssh-keygen -t rsa default — failed each sign request with WS_RSA_E. Deterministic, gated on WOLFSSH_AGENT, and untested. Not a memory-safety defect; the agent simply cannot sign with a mainstream key size.

Adjacent to it, wolfSSH_AGENT_SignRequest() read agent replies into byte rxBuf[512], which cannot hold an RSA-4096 sign response (521 bytes).

Fix (src/agent.c)

  • PostSignRequest() sizes the signature buffer from the identity — id->key.rsa.nSz for RSA, the existing ECDSA_ASN_SIG_SZ for ECDSA — allocates it from agent->heap, and frees it on every path. A modulus longer than RSA_MAX_SIZE returns WS_BUFFER_E.
  • wolfSSH_AGENT_SignRequest() reads into a heap buffer of WOLFSSH_AGENT_MAX_RSP_SZ (2048, #ifndef-overridable), freed after the last use of agent->msg, which points into it.

Both functions lose their large stack buffers. SignHashRsa() and SignHashEcc() are unmodified, so their pre-existing stack usage is untouched.

Closes f-10541.

Tests (tests/api.c)

Two tests drive real keys through the fake-agent reply path the existing agent tests already use, with key components as hex constants decoded by ConvertHexToBin():

Test Key Proof of signing
..._rsa_3072 RSA-3072 clear the stored d, re-sign, expect WS_RSA_E
..._ecc_p521 NIST P-521 corrupt the stored point, re-sign, expect WS_ECC_E

The trailing step matters because a successful sign and a key-blob miss both surface as WS_AGENT_NO_KEY_E; without it a drifted key blob would pass vacuously.

Verification

  • gcc-13 -Werror preflight: lint clean, all 6 configs clean.
  • make check: 11 passed, 1 skipped, 0 failed.
  • Negative controls: clamping the RSA buffer to 256 gives WS_RSA_E; clamping ECC to 136 gives WS_ECC_E; flipping one bit of the sign-request key blob trips the match proof.
  • ASan + UBSan on api.test: clean.

@yosuke-wolfssl yosuke-wolfssl self-assigned this Aug 19, 2026
Copilot AI lite review requested due to automatic review settings August 19, 2026 00:02

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

This PR fixes wolfSSH agent signing failures with larger RSA identities by sizing signature/reply buffers dynamically (or via a larger configurable cap) and adds regression tests for RSA-3072 and ECDSA P-521 agent signing paths.

Changes:

  • Allocate the RSA/ECDSA signature buffer in PostSignRequest() based on identity size instead of a fixed 256-byte stack buffer.
  • Increase agent reply read capacity in wolfSSH_AGENT_SignRequest() by reading into a heap buffer sized by WOLFSSH_AGENT_MAX_RSP_SZ.
  • Add API tests that drive RSA-3072 and ECDSA P-521 identities through the fake-agent path to validate the fix and prevent vacuous “no key” passes.

Reviewed changes

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

File Description
src/agent.c Sizes signature buffer from identity and increases agent reply read buffer via heap allocation.
tests/api.c Adds regression tests for RSA-3072 and ECDSA P-521 agent sign requests and expands test IO buffers.

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

Comment thread src/agent.c
Comment thread src/agent.c
Comment thread src/agent.c
Comment thread tests/api.c Outdated
Comment thread tests/api.c Outdated
Comment thread tests/api.c Outdated
Comment thread tests/api.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 #1179

Scan targets checked: wolfssh-bugs, wolfssh-src

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

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread src/agent.c
Comment thread src/agent.c
Comment thread tests/api.c Outdated
- PostSignRequest() allocates the signature buffer from agent->heap,
  sized from the identity's modulus mpint for RSA and from
  ECDSA_ASN_SIG_SZ for ECDSA, and frees it before returning. A modulus
  longer than RSA_MAX_SIZE, or a key type that sets no size, returns
  WS_BUFFER_E.
- wolfSSH_AGENT_SignRequest() reads the agent's reply into a heap
  buffer of WOLFSSH_AGENT_MAX_RSP_SZ, a new overridable define in
  agent.c, freed after the last use of agent->msg.
- tests/api.c carries a 3072-bit RSA key and a P-521 key as hex string
  components, and build_string() and build_mpint() helpers that write
  the message fields. AgentTestCtx.response sizes from
  AGENT_TEST_BUF_SZ.
- test_wolfSSH_agent_signrequest_rsa_3072() and
  test_wolfSSH_agent_signrequest_ecc_p521() add their identity through
  the agent callbacks and sign with it, then clear the stored private
  exponent or point and sign again.
  test_wolfSSH_agent_signrequest_rsa_too_large() adds an identity whose
  modulus exceeds RSA_MAX_SIZE and expects WS_BUFFER_E.
- The comment on test_wolfSSH_agent_signrequest_oversize_rsa_key()
  describes the identity that test uses.

Issue: F-10541
@ejohnstown
ejohnstown merged commit 091399c into wolfSSL:master Aug 20, 2026
163 checks passed
@yosuke-wolfssl
yosuke-wolfssl deleted the fix/f_10541 branch August 20, 2026 04:35
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.

5 participants