Harden KEX and userauth packet handling#1049
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens wolfSSH’s transport and authentication handling by adding stricter validation of peer-provided key-exchange inputs and enforcing additional RFC-required parsing/validation rules, addressing parts of issue #1047 / finding F-5690.
Changes:
- Add DH/ECDH peer public-key validation (including hybrid ML-KEM paths) before deriving shared secrets; simplify Curve25519+ML-KEM flag handling.
- Enforce RFC 4253 minimum padding length on received packets and add a negative unit test.
- Reject password-change userauth requests (per RFC 4252 §8) without invoking the userauth callback, while still consuming the full message; add a negative unit test.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/internal.c |
Adds DH/ECDH peer key validation, enforces minimum padding on receive, rejects password-change auth, and simplifies Curve25519+ML-KEM flag routing. |
wolfssh/internal.h |
Removes redundant handshake flag and exposes additional WOLFSSH_TEST_INTERNAL wrappers for new negative KEX tests. |
tests/unit.c |
Adds unit tests for short padding rejection, password-change userauth rejection, and DH/ECDH invalid peer public-key handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1049
Scan targets checked: wolfssh-bugs, wolfssh-src
No new issues found in the changed files. ✅
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1049
Scan targets checked: wolfssh-bugs, wolfssh-src
No new issues found in the changed files. ✅
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1049
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. Findings are non-blocking.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1049
Scan targets checked: wolfssh-bugs, wolfssh-src
No new issues found in the changed files. ✅
- DH: add wc_DhCheckPubKey on client and server before wc_DhAgree; rejects degenerate/small-order values per NIST SP 800-56A (2 <= y <= p-2), stricter than RFC 4253 section 8's [1, p-1] - ECDH and ECC+ML-KEM hybrid: validate the peer point through a shared EccCheckPeerKey helper (import + wc_ecc_check_key) on client and server, so the plain and hybrid paths cannot diverge - add wolfSSH_TestKeyAgreeEcdh_server/client and wolfSSH_TestSetDhKexKey test hooks - add negative unit tests rejecting bad DH and off-curve ECDH peer keys on client and server; the hybrid paths share the same helper and are exercised by kex.test Issues: F-5690, wolfSSL#1047 (1)
- remove redundant useCurve25519MlKem HandshakeInfo flag - identify the Curve25519+ML-KEM hybrid as useCurve25519 && useEccMlKem - merge the duplicate Curve25519 keygen branch in SendKexDhInit - order the client KeyAgree dispatch to match the combined flags
- enforce RFC 4253 section 6 minimum of 4 padding bytes on receive - return WS_BUFFER_E when padding_length is below MIN_PAD_LENGTH - add negative unit test driving DoReceive with a short-padded packet Issue: wolfSSL#1047 (5)
- fail userauth when the request sets the password-change flag - do not invoke the userauth callback with the current password - parse the new-password field so the message is fully consumed - add negative unit test asserting USERAUTH_FAILURE and no callback Per RFC 4252 section 8, an expired password MUST NOT be used to authenticate; password changes remain unsupported. Issue: wolfSSL#1047 (6)
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1049
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. Findings are non-blocking.
Addresses parts of issue #1047 and finding F-5690.