Commit Graph

242 Commits (8d97ee9250d4b83fefa0479a99516da45e31ad45)

Author SHA1 Message Date
Yosuke Shimizu a2a78da28a Bind userauth username to the first request 2026-07-14 11:21:54 -07:00
John Safranek f8c43e17ae Test DoChannelWindowAdjust overflow guard
- Add test_DoChannelWindowAdjust_overflow via new
  wolfSSH_TestDoChannelWindowAdjust wrapper.
- Seed non-zero peer window, feed bytesToAdd = UINT32_MAX,
  assert WS_OVERFLOW_E with window unchanged.
- Feed a fitting value, assert window advances.
- Covers the guard so flipping or deleting it now fails.

Issue: F-2874
2026-07-13 14:26:41 -07:00
Yosuke Shimizu fed66b9450 Add server-side IsMessageAllowed pre-auth gate regression tests 2026-07-08 22:51:31 -07:00
John Safranek 75c5adbb74 Centralize AES cipher lifecycle
- Add CipherSetKey()/CipherClear() to init, key, and free the Aes
  contexts; init lazily and track isInit/cipherType.
- Free only inited contexts, fixing wc_AesFree on uninitialized ones.
- DoNewKeys now fails an unknown peer cipher with WS_INVALID_ALGO_ID
  instead of WS_SUCCESS, matching SendNewKeys.
- Add regression coverage for isInit/cipherType and a never-keyed free.
2026-07-08 18:15:20 -07:00
John Safranek 9e02350aaa Reject password-change auth requests
- 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: #1047 (6)
2026-07-08 18:00:23 -07:00
John Safranek df635a3e16 Reject packets with too-little padding
- 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: #1047 (5)
2026-07-08 18:00:23 -07:00
John Safranek dcee1ffa87 Simplify redundant KEX method flags
- remove redundant useCurve25519MlKem HandshakeInfo flag
- merge the duplicate Curve25519 keygen branch in SendKexDhInit
- order the client KeyAgree dispatch to match the combined flags
- rename the surviving flags for clarity: useEcc->useEcdh and
  useEccMlKem->useMlKem
- make the flag set orthogonal: each ML-KEM hybrid now sets its
  classical-component flag (useEcdh or useCurve25519) alongside useMlKem,
  so the four bits independently describe every KEX family
- apply the same flag handling to the server SendKexDhReply path
2026-07-08 18:00:23 -07:00
John Safranek 71d8529306 Validate peer KEX public keys
- 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, #1047 (1)
2026-07-08 18:00:23 -07:00
John Safranek 75144cfa05 Bound KEXINIT language name-list skips
- DoKexInit skipped both language name-lists with an unchecked
  begin += skipSz; a forged length could wrap begin into earlier
  payload bytes and still return success.
- Use bounds-checked GetSkip for both language fields.
- Add regression test; checked skip now rejects with WS_BUFFER_E.

Issue: F-5576
2026-07-08 17:48:28 -07:00
John Safranek 36198800a3 Strip trailing comma from peer name lists
- GetNameListRaw folded a trailing comma into the last name,
  so NameToId returned ID_UNKNOWN and negotiation failed.
- Trim one trailing comma up front, matching AlgoListSz.
- Add regression test for a KEX list with a trailing comma.

Issue: F-2478
2026-07-08 17:48:28 -07:00
Yosuke Shimizu 90692e6995 Validate peer DH public value before key agreement 2026-07-06 17:10:02 -05:00
Eric Blankenhorn 28701904c1 Harden DoOpenSshKey parsing 2026-07-06 16:55:54 -05:00
Emma Stensland c56dc1027f added ml-dsa plain key and cert algorithms 2026-07-06 16:51:21 -05:00
Yosuke Shimizu 422f69de8b Bound KEXINIT name-list parsing to prevent pre-auth CPU DoS 2026-06-26 14:38:08 -07:00
Yosuke Shimizu 8ec9aa737c wolfssh/client: reject unsanitized fields before known_hosts write 2026-06-26 14:30:31 -07:00
Yosuke Shimizu 336a759af5 Bind SCP file timestamps to open descriptor 2026-06-26 13:42:52 -07:00
Yosuke Shimizu cd3ccd6f49 Bound SFTP NAME response size on the client 2026-06-26 12:10:32 -07:00
John Safranek 616eb681e7 Gate forwarded-tcpip opens like direct-tcpip
- forwarded-tcpip was never gated; fell through to default-accept channelOpenCb.
- Require fwdCb for both forwarding channel types, failing closed without it.
- Reject server-side forwarded-tcpip opens before any policy hook runs.
- Add regress coverage for both rejections.

Issue: F-6275
2026-06-25 13:27:00 -07:00
Yosuke Shimizu 673b2d25e7 Report allocated port in tcpip-forward reply
- Reply to a port-0 (dynamic) tcpip-forward with the bound port.
- Add WS_FWD_PORT_CHECK (1024) as the status/port boundary in WS_FwdCbError.
- Callback returns a WS_FwdCbError status below it, the port at or above it.
- DoGlobalRequestFwd reports the port and rejects a port-0 setup with none.
- Map a callback rejection to WS_RESOURCE_E so a no-reply request keeps the link.
- Update the echoserver reference callbacks (examples and Espressif) to
  recover the OS-chosen port with getsockname() and return it under the new
  convention.
- Add regress coverage for the allocated-port and rejection paths.

Issue: F-5573

Co-authored-by: John Safranek <john@wolfssl.com>
2026-06-25 13:27:00 -07:00
Yosuke Shimizu 916af608f6 wolfscp: fix ExtractFileName for separator-less paths 2026-06-25 11:15:01 -07:00
Yosuke Shimizu c8a347de85 Reject symlinks in default SCP send callback 2026-06-23 14:37:57 -07:00
John Safranek c9f877df95 Test SFTP forged handles and namespace isolation
- Reject forged/raw-fd handles in Write/Read/FSetSTAT/FSTAT/Close
- Isolate file vs directory handle-ID namespaces
- Cover positive and forged FSTAT
2026-06-22 20:11:36 -07:00
JacobBarthelmeh dc4df8dfdf keep a list of file handles open per session
- Track open SFTP file handles per session in a fileList, returning
  opaque session-scoped handle IDs instead of raw file descriptors.
- Resolve and validate client-supplied handle IDs via FindFileHandle.
- Free the handle list and close handles on error paths, including the
  Windows code paths.
- Drop the old raw-fd SFTP_ValidateFileHandle/STOREHANDLE handle table
  and its tests, superseded by the per-session ID lookup.
2026-06-22 20:11:36 -07:00
Paul Adelsbach 1dc30ed97e Set keyAllocated=1 when initializing any key 2026-06-22 10:40:56 -07:00
Yosuke Shimizu 0256f4c8fb Reject SCP receive through pre-existing symlinks 2026-06-18 14:15:36 -07:00
Yosuke Shimizu 00e85522aa Mask special bits from peer-supplied SCP receive mode 2026-06-18 14:05:01 -07:00
Yosuke Shimizu f2b4f43c20 Sanitize control bytes in formatted log messages 2026-06-18 13:52:00 -07:00
Yosuke Shimizu 253c157066 wolfsshd: implement PubkeyAuthentication config directive 2026-06-18 13:08:14 -07:00
Yosuke Shimizu 2425f7c594 Bound OSC index before reads in wolfSSH_DoOSC 2026-06-18 11:00:42 -07:00
Yosuke Shimizu 4cf61a1368 Bound server-side inbound SFTP request size in wolfSSH_SFTP_read 2026-06-18 10:02:10 -07:00
Yosuke Shimizu 1efd64743c wolfssh/scp: complete rekey that starts mid-transfer 2026-06-16 15:56:50 -07:00
Yosuke Shimizu cb9bb7a2a7 Fix SFTP client states dropping unsent bytes after partial channel send 2026-06-16 11:21:19 -07:00
John Safranek 92e1bdcb18 Add DoUserAuthRequestRsaCert sig-parse test
Run the DoUserAuthRequestRsa vectors through the X.509 path to pin
that a raw signature with a high leading bit is accepted via the
RFC 6187 branch. keys/ has no RSA certificate, so the test embeds a
self-signed cert made from keys/hansel-key-rsa.pem (valid until
May 2048).
2026-06-15 21:34:16 -07:00
John Safranek 31d13697a6 Bind ECDSA host key curve to negotiated algo
- Validate blob algorithm name against handshake pubKeyId
- Derive curve from negotiated algo, not the key blob
- Check curve name instead of skipping it
- Add a ParseECCPubKey test checking the key blob algorithm and
  curve names are validated against the negotiated host key
  algorithm.

Issue: #1012
2026-06-15 21:34:16 -07:00
John Safranek 848ba54b55 Reject negative mpints in GetMpint
- GetMpint now rejects values with the sign bit set as
  non-canonical (RFC 4251 Section 5) and is rewritten in
  terms of GetStringRef.
- Parse RSA signature blobs with GetStringRef; they are
  strings of raw signature bytes (RFC 4253 Section 6.6),
  not mpints, and often have the high bit set.
- Add unit test covering GetMpint parsing and rejection.
- Add a DoUserAuthRequestRsa test pinning the string parse of
  the signature blob with a fixed signature whose leading byte
  has the high bit set; an mpint parse would reject it as
  negative.

Issue: #1013
2026-06-15 21:34:16 -07:00
John Safranek e2b7ad5d21 Reject non-CA peer intermediate certs
- Add CertManIntermediateIsCA: require isCA and, for non-self-signed
  intermediates that carry a KeyUsage extension, the keyCertSign bit
  before promoting a cert.
- Only promote a verified intermediate into the trust store when it is
  actually a CA; otherwise fail with WS_CERT_NO_SIGNER_E.
- Prevents a peer-supplied end-entity cert at an intermediate position
  from being trusted to issue certs for arbitrary SSH principals.
- Gate keyCertSign on ALLOW_INVALID_CERTSIGN and on the KeyUsage
  extension being present, matching wolfSSL's AddCA loader.
- Add regression tests: non-CA intermediate is not promoted, and a
  valid CA intermediate (with and without KeyUsage) still is.

Issue: F-5851
2026-06-15 15:48:03 -07:00
David Garske ba09b582ba
Merge pull request #1007 from ejohnstown/hex2octal
Convert file permission hex constants to octal
2026-06-09 14:22:34 -07:00
Yosuke Shimizu a760b9a1d2 apps/wolfssh: fix ssh://hostname destination without explicit port 2026-06-09 11:11:37 -07:00
Yosuke Shimizu d49b15f51a SFTP path confinement and status-reply refactor 2026-06-09 10:46:17 -07:00
John Safranek 3abdc22355 Convert file permission hex constants to octal
- Replace hex literals (0x1ED, 0x124, 0x4000, etc.) with octal
  equivalents (0755, 0444, 040000) in SCP/SFTP attribute handling
2026-06-08 10:39:48 -07:00
Yosuke Shimizu ca803ec2cc Add a safe mask for peer-supplied mode and extend wolfSSH_SFTP_Open 2026-06-08 10:01:24 -07:00
Yosuke Shimizu 0f11691a07 Harden a file handle validation into SFTP Recv functions 2026-06-08 09:27:01 -07:00
Yosuke Shimizu 5a19e449c6 Add upper limit of max window size and packet size, Add unit tests 2026-06-08 08:53:53 -07:00
Yosuke Shimizu aa04eca815 Fix SFTP rekey transparency in buffer_read and buffer_send 2026-06-04 14:36:20 -07:00
Yosuke Shimizu 4ae8eee109 Add tests for DoUserAuthRequestRsa and DoUserAuthRequestRsaCert 2026-05-27 14:44:10 -07:00
Yosuke Shimizu b9dfa042bf Add scpDirDepth as depth guard and Add unit tests 2026-05-27 14:06:18 -07:00
Yosuke Shimizu 3b867e7313 Add unit tests and regress tests 2026-05-27 11:13:54 -07:00
John Safranek fd29780c8e DoProtoId: case-sensitive SSH- prefix match
- Per RFC 4253 4.2 use WSTRNCMP instead of WSTRNCASECMP for
  prefix and full-ID comparisons.
- Update client tests; add server test vectors expecting
  rejection of lowercase/mixed case.

Issue: F-2865
2026-05-21 11:42:43 -07:00
John Safranek be4aa445d5 DoNewKeys: reject NEWKEYS with non-empty payload
- Reject SSH_MSG_NEWKEYS when len != 0 per RFC 4253 7.3.
- Update wolfSSH_TestDoNewKeys to take buf/len/idx instead
  of assuming NULL/0, and add a non-zero len test case.

Issue: F-2079
2026-05-21 11:42:43 -07:00
John Safranek 63a63cf0fb CERTMAN_VerifyCerts_buffer: reject certsCount=0
- Without the guard, inner loops short-circuit and WS_SUCCESS
  is returned without any verification.
- Add test case covering the new and existing bad-arg paths.

Issue: F-409
2026-05-21 11:42:43 -07:00