Commit Graph

2644 Commits (673b2d25e72ca24fe465d1c644a634e650cdd4f4)

Author SHA1 Message Date
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
Yosuke Shimizu ef56aca663 wolfsshd: fix uninitialized fileNames[] deref in HandleInclude 2026-06-18 13:46:05 -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 7393aaea9b wolfsshd: reject Match blocks using unimplemented selectors 2026-06-16 15:38:16 -07:00
aidan garske 633f627422 Use shared wolfTPM2_SetKeyBlobFromBuffer parser and guard TPM signing args 2026-06-16 13:59:52 -07:00
aidan garske a2c28c9c3c Add TPM 2.0 resident server host keys for ECDSA and RSA 2026-06-16 13:59:52 -07:00
Yosuke Shimizu eef8281609 wolfsshd: bind certificate auth to user, fail closed without FPKI 2026-06-16 11:50:34 -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 d43dfd5b83 Coverity: Uninitialized scalar variable
1. Remove the check on authType, it is covered already.
2. Add Keyboard Setup to the existing check on authType.
3. Add a branch for User Auth None so it reaches its handler
   in the map loop rather than the new error case.
4. Add else case for an error.

Fixes CID: 637345
2026-06-16 10:20:06 -07:00
John Safranek 36e276529f Fix sshd test flakiness and orphan daemon
- term size test: poll tmux output with retries instead of fixed sleeps,
  re-sending the size query each pass in case the shell was not yet ready
- term close test: scope netstat checks to the test port so unrelated
  host CLOSE_WAIT/TIME_WAIT sockets don't fail the test
- run_all_sshd_tests.sh: validate --match before starting wolfSSHd
- renewcerts.sh: build the per-user cert from a throwaway config copy so
  the tracked renewcerts.cnf is never modified in place
2026-06-15 22:05:50 -07:00
John Safranek 69f7799929 Check Include path truncation in sshd config
HandleInclude built the wildcard include path with WSNPRINTF without
checking the result, silently truncating over-long paths (flagged by
GCC 12 as -Werror=format-truncation). Merge the duplicate WSNPRINTF
calls and return WS_INVALID_PATH_E when the path does not fit.
2026-06-15 21:48:30 -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 db62bed546 Free ECC key on ParseECCPubKey error paths
Set keyAllocated right after wc_ecc_init_ex so FreePubKey frees the
initialized key on the early error exits, not only after a
successful import.
2026-06-15 21:34:16 -07:00
John Safranek 85fc81bd41 Scope ECC pubkey blob fields into own variables
- Parse each field of the key blob in ParseECCPubKey with its own
  scoped variables instead of reusing q/qSz for the algorithm name,
  curve name, and public key point.
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 df6e81c6c7 Skip OCSP when cert has no responder URL
OCSP_NEED_URL meant the cert has no AIA OCSP URL and no
default responder is set, so OCSP cannot run. Treat it as
not-revoked instead of failing the whole verification.

This softens revocation from hard-fail to soft-fail for that case
only. The AIA URL is part of the signed certificate and is not
attacker-strippable, so a malicious peer cannot use this to bypass
an otherwise-enforced OCSP check.
2026-06-15 15:48:03 -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 e2bfa19673
Merge pull request #1002 from ejohnstown/tidy-tidy
tidy clang-tidy
2026-06-10 07:26:32 -07:00
John Safranek 1d86a8ed27 Bound sshd Include directive recursion
Cleanup clang-tidy misc-no-recursion finding.

- wolfSSHD_ConfigLoad: track depth on WOLFSSHD_CONFIG
  and reject loads past WOLFSSHD_MAX_INCLUDE_DEPTH (16).
- HandleInclude, HandleConfigOption, ParseConfigLine,
  wolfSSHD_ConfigLoad: annotate the call cycle with
  NOLINTNEXTLINE pointing at the bound.
- Add a recursive configuration test.
2026-06-09 17:18:39 -07:00
John Safranek bb25181766 Tighten SCP timestamp bounds check
Cleanup clang-tidy bugprone-inc-dec-in-conditions finding.

- ParseTimestamp: move ++idx out of the || conditions
  and tighten the bound from > bufSz to >= bufSz.
2026-06-09 17:18:39 -07:00
John Safranek 067187babe Use reentrant time conversion in SFTP
Cleanup clang-tidy concurrency-mt-unsafe finding. Note, this
originally used gmtime which provided UTC based time values. Now,
the wolfSFTP server will provide localtimes for file timestamps.
The exception is Zephyr, which only provides UTC times.

- SFTP_CreateLongName: switch from XGMTIME (gmtime) to
  WLOCALTIME, which expands to localtime_r/localtime_s
  per platform.
- Note in the Zephyr WLOCALTIME macro that gmtime_r is used
  because Zephyr's minimal libc does not provide localtime_r.
- Moved the posix attributes breakdown into a helper function.
- Changed some of the X-prefixed macros to the W-prefixed versions.
- Changed the SFTP longname creation to add a "?" in place of the
  number of links. (OpenSSH does the same.)
2026-06-09 17:18:39 -07:00
John Safranek 304955ff94 Move unsafe call out of signal handler
Cleanup clang-tidy bugprone-signal-handler findings.
- wolfsshd: drop fprintf from interruptCatch; the main accept
  loop logs "Closing down wolfSSHD" after seeing quit set.
- sftpclient: annotate wolfSSH_SFTP_Interrupt call in
  sig_handler with NOLINT, since the function is only a single
  byte store and is safe to call from a signal handler.
2026-06-09 17:03:02 -07:00
John Safranek 534500d66b Remove redundant preprocessor guard
Cleanup clang-tidy readability-redundant-preprocessor finding.
2026-06-09 17:03:02 -07:00
John Safranek 863a52be63 Add parameter names to function declarations
Clean up clang-tidy readability-named-parameter findings
across wolfSSH headers and sources.
2026-06-09 17:03:02 -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 6af538ded0 Fix 2026-06-09 11:05:54 -07:00
Yosuke Shimizu 3f981d1e8d wolfsshd: fix peer-controlled over-read in Windows pseudo-console resize 2026-06-09 11:05:54 -07:00
Yosuke Shimizu d49b15f51a SFTP path confinement and status-reply refactor 2026-06-09 10:46:17 -07:00
Yosuke Shimizu 12d39dd970 examples/client: guard rxBuf indexing against negative stream_read error 2026-06-09 09:34:14 -07:00
Yosuke Shimizu 2d0ef5aee4 wolfsshd: honor Match-block auth restrictions in DoCheckUser and RequestAuthentication 2026-06-08 14:54:28 -07:00