agent: size the signature buffer from the identity - #1179
Conversation
There was a problem hiding this comment.
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 byWOLFSSH_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.
15954ae to
0b33201
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
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.
0b33201 to
77274f1
Compare
- 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
77274f1 to
ff029e7
Compare
Problem
PostSignRequest()insrc/agent.csigned into a fixedbyte sig[256].wc_RsaSSL_Sign()rejects an output buffer smaller than the modulus, so every RSA identity above 2048 bits — including the 3072-bitssh-keygen -t rsadefault — failed each sign request withWS_RSA_E. Deterministic, gated onWOLFSSH_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 intobyte 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.nSzfor RSA, the existingECDSA_ASN_SIG_SZfor ECDSA — allocates it fromagent->heap, and frees it on every path. A modulus longer thanRSA_MAX_SIZEreturnsWS_BUFFER_E.wolfSSH_AGENT_SignRequest()reads into a heap buffer ofWOLFSSH_AGENT_MAX_RSP_SZ(2048,#ifndef-overridable), freed after the last use ofagent->msg, which points into it.Both functions lose their large stack buffers.
SignHashRsa()andSignHashEcc()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():..._rsa_3072d, re-sign, expectWS_RSA_E..._ecc_p521WS_ECC_EThe 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
-Werrorpreflight: lint clean, all 6 configs clean.make check: 11 passed, 1 skipped, 0 failed.WS_RSA_E; clamping ECC to 136 givesWS_ECC_E; flipping one bit of the sign-request key blob trips the match proof.api.test: clean.