Commit Graph

2678 Commits (8d97ee9250d4b83fefa0479a99516da45e31ad45)

Author SHA1 Message Date
John Safranek 8d97ee9250 Port Zephyr test sample to 3.4.0 and 4.4.0
Zephyr 3.5 moved the RAM disk driver from Kconfig to devicetree and 4.1
replaced CONFIG_NET_SOCKETS_POSIX_NAMES with CONFIG_POSIX_API. Port the
sample to the new APIs while keeping it buildable on older Zephyr.

- add ramdisk.overlay (zephyr,ram-disk node) for the FS scenarios;
  drop CONFIG_DISK_RAM_VOLUME_SIZE
- switch to CONFIG_POSIX_API; include the POSIX time/select/socket/netdb
  headers in test.h and port.h, gated on ZEPHYR_VERSION_CODE >= 4.1.0 so
  older Zephyr keeps the BSD names from <zephyr/net/socket.h>
- select RAM disk (overlay >= 3.5, else CONFIG_DISK_RAM_VOLUME_SIZE) and
  POSIX (CONFIG_POSIX_API >= 4.1, else the legacy symbols) in
  CMakeLists.txt, with ramdisk_legacy.conf / posix_legacy.conf fallbacks
- tests, nofs and kbi scenarios pass on qemu_x86 with Zephyr 3.4.0
  (SDK 0.16.1) and 4.4.0 (SDK 1.0.0)
2026-07-14 13:58:43 -07:00
John Safranek ac762368ac Fix keyboard-interactive without TERM
Keyboard-interactive was unusable in builds with
WOLFSSH_KEYBOARD_INTERACTIVE but no WOLFSSH_TERM, in two ways.

- ClientFreeBuffers declared 'entry' under TERM && KBI but used it
  under KBI alone, so KBI-without-TERM failed to compile; widen the
  declaration guard to match the use
- ClientUserAuth's keyboard-interactive branch is guarded on
  TERM && KBI, so without TERM a keyboard-interactive request fell
  past every branch and returned the initial WOLFSSH_USERAUTH_SUCCESS
  with no responses populated. There is no terminal to prompt on, so
  answer WOLFSSH_USERAUTH_FAILURE instead of claiming success.
2026-07-14 13:58:43 -07:00
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
Anthony Hu 974f4fd39a C89 compliance; remove comma 2026-07-09 11:13:51 -05:00
Yosuke Shimizu 331b2c4c97 examples/client: add cert-name length bounds check in ParseRFC6187 2026-07-08 23:36:25 -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 37edd24d4e Fix SCP base-path check using wrong length
- Bound the buffer by scpBasePath length (sz), not the unrelated cmdSz.
2026-07-08 18:00:23 -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
aidan garske b8e2fd3703 Address review: TPM publickey auth fallback, reject truncated CA, guard negative CI test, silence maybe-uninitialized 2026-07-07 14:28:56 -07:00
aidan garske d818d032ba Address review: clear crypto callback on error, gate SHA-1 to RSA, cryptocb docs, fix comment 2026-07-07 14:28:56 -07:00
aidan garske 8dfdb63168 examples: line-buffer stdout so tests reliably capture server output 2026-07-07 14:28:56 -07:00
aidan garske 5f715daf02 Add TPM X.509 host certificate docs and CI coverage 2026-07-07 14:28:56 -07:00
aidan garske 36a7cc95f9 examples: add TPM-backed X.509 host certificate server and client 2026-07-07 14:28:56 -07:00
aidan garske 9f581eccf3 wolfSSH: enable password/keyboard auth in TPM builds and prefer client TPM key 2026-07-07 14:28:56 -07:00
Yosuke Shimizu 62639efd35 Enforce LoginGraceTime in wolfsshd on Windows and make the grace flag per-connection 2026-07-07 12:43:08 -05:00
Yosuke Shimizu 09cbe92daa Fix ssh->fs reference in Nucleus/Harmony SFTP_GetAttributes helpers 2026-07-06 18:36:41 -05:00
Kareem 9011f558db Fix incorrect argument being passed to wc_InitDecodedCert. Should be the heap rather than the CM.
Reported-by: Asif Nadaf <postasif@protonmail.com>
2026-07-06 18:32:25 -05: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 323ec15bb0 wolfsshd: add StrictModes and secure loading of trust anchors 2026-06-26 14:13:02 -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
Yosuke Shimizu 6bdddc6053 wolfsshd: mark AuthorizedKeysFile as explicitly set in public setter 2026-06-25 13:35:27 -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 4483254e8c Zeroize SFTP file payload buffers before freeing 2026-06-25 10:28:47 -07:00
Yosuke Shimizu 281e4bc19f Treat combined Match User/Group blocks as a conjunction in wolfsshd 2026-06-23 14:57:09 -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
John Safranek 72b8e888d8 Share one ID counter for SFTP handles
- Merge fileIdCount and dirIdCount into a single handleIdCount.
- File and directory handle IDs now share one namespace.
- A close or other handle op cannot match the wrong resource type.
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 52f6db9fe7 Fix memory leak when freeing keys 2026-06-22 10:40:56 -07:00
Paul Adelsbach 1dc30ed97e Set keyAllocated=1 when initializing any key 2026-06-22 10:40:56 -07:00
aidan garske e52b038de9 Add timeout to TPM SSH workflow to prevent multi-hour hangs 2026-06-22 08:51:37 -07:00
Yosuke Shimizu 8ac056793f Update the skip guard for Mac environment 2026-06-18 14:42:52 -07:00
Yosuke Shimizu 1d2b95f979 wolfsshd: fix Match User/Group directive misparse 2026-06-18 14:24:09 -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