Commit Graph

2678 Commits (8d97ee9250d4b83fefa0479a99516da45e31ad45)

Author SHA1 Message Date
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
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
Daniel Pouzzner 4ebb6be336
Merge pull request #998 from ejohnstown/sf7
Static Analysis Fixes
2026-06-08 11:28:01 -05: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 d234a2721d Add unit tests for wolfSSHD_AuthReducePermissionsUser 2026-06-04 13:20:29 -07:00
John Safranek fd334579c5 wolfsshd: fix data loss in Windows shell relay
- buffer unsent bytes on backpressure/partial send and resend
- hold loop open until buffered data flushes after child exit
2026-06-03 07:40:27 -07:00
John Safranek 9d62a4483a wolfsshd: set stdoutEmpty on PTY EOF
Lets the relay loop reach its shutdown condition after SIGCHLD
instead of relying on a -1/EIO break.
2026-06-03 07:40:27 -07:00
John Safranek c851de1708 wolfsshd: harden windowFull retry
- Guard the retry against a negative cnt_w so a non-sentinel
  send error cannot become a negative memmove offset.
- Clear windowFullExt at the stdout and childFd save sites so
  stream ownership is set unconditionally.
2026-06-03 07:40:27 -07:00
John Safranek 27439881fd wolfsshd: save shellBuffer on WS_WANT_WRITE
ChannelIdSend / extended_data_send returning WS_WANT_WRITE set
wantWrite but didn't save cnt_r, so the next read overwrote the
held bytes. Store cnt_r in windowFull at all three read sites
(stderr, stdout, pty childFd); flag windowFullExt for stderr so
the retry routes through extended_data_send.
2026-06-03 07:40:27 -07:00
John Safranek 339c39bb57 wolfsshd: track stream for windowFull retry
Stderr and stdout shared shellBuffer/windowFull, so a stderr hold
retried on stdout, and a stderr partial send let the stdout read
clobber the remainder. Tag the held bytes with windowFullExt;
retry via extended_data_send and skip the stdout read when set.
2026-06-03 07:40:27 -07:00
John Safranek 094c686142 wolfsshd: retry select() on EINTR in relay loop
SIGCHLD from the exec child interrupts select(), returning -1 and
breaking the loop. Any windowFull data awaiting a peer window adjust
was then abandoned, causing intermittent 32 KB truncations on large
exec transfers. Continue on EINTR.
2026-06-03 07:40:27 -07:00
John Safranek caec20f1f8 SFTP: retry short writes, fail if stuck
1. Loop WPWRITE until the full chunk is written, advancing the
   split 64-bit offset with carry. Bail out on error or a zero
   return and report WOLFSSH_FTP_FAILURE so clients see the
   truncation instead of a silent success.
2. Update the backup WPWRITE() implemented with fwrite() to
   parallel the behavior of the backup WPREAD(). Changed to write
   sz number of 1 byte objects.

Issue: F-3880
2026-06-02 16:53:35 -07:00
John Safranek a35d1e3543 SendKexInit: advertise ext-info-s
Per RFC 8308 Section 2.1.

1. The server will now advertize that it accepts an ext-info message.
2. The client and server will send the ext-info message if requested and
   and allowed. The per-side send functions are guarded based on
   configuration. The wolfSSH client currently doesn't have anything to
   say in an ext-info message.

Issue: F-3448
2026-06-02 16:47:07 -07:00
Yosuke Shimizu 13db37b1b4 Fix retry loop in doAutopilot 2026-06-02 09:48:11 -07:00