Commit Graph

3344 Commits (57dfc44c93bfe00b4e64bf6a4e3051dfefd4d4da)

Author SHA1 Message Date
John Safranek 57dfc44c93 sftp: send the caller's attributes with MKDIR
wolfSSH_SFTP_MKDIR() encodes atr with SFTP_SetAttributes(), as the
other attribute-carrying requests do. A NULL atr requests permissions
0777, the request every MKDIR used to send.

- sftpclient: pass NULL instead of an uninitialized atr
- api: a 0700 request makes a 0700 directory on the echoserver

Issue: F-14634
2026-11-13 11:32:45 -06:00
John Safranek 8fd8f3fd15 Make wolfSSH_GetText output the same everywhere
wolfSSH_GetText() builds the text locally and copies it into str, so
str is always terminated and the return is the full text length,
whichever function WSNPRINTF maps to. A return of strSz or more means
truncation; an unknown id or unnegotiated KEX gives "" and 0.

- echoservers: test truncation with ret >= strSz
- api: empty, exact, truncated, and DH texts

Issue: F-17102
2026-11-13 11:32:45 -06:00
John Safranek 52014ac166 Ignore a NULL session in terminal resize setters
wolfSSH_SetTerminalResizeCb() and wolfSSH_SetTerminalResizeCtx() do
nothing for a NULL session, like the other session setters.

- api: NULL and valid session through both setters

Issue: F-17101
2026-11-13 11:32:45 -06:00
John Safranek d6ff22e140 Fill a caller buffer for ASN.1 public keys
DoAsn1Key() encodes a public key into the caller's *out when one is
supplied, as the private-key path already does, and returns WS_BUFFER_E
when *outSz is too small. It allocates only when *out is NULL.

- GetPubKeyOut() picks the buffer for every public-key encoder
- api: RSA, ECC, Ed25519 and ML-DSA-44 reads into a caller buffer, and
  one byte short

Issue: F-11652
2026-11-13 11:32:45 -06:00
John Safranek b256895f04 Send the caller's payload in wolfSSH_SendIgnore
wolfSSH_SendIgnore() carries buf in the SSH_MSG_IGNORE it sends. A
NULL buf with a zero bufSz still sends 128 zero bytes, and a NULL buf
with a nonzero size is WS_BAD_ARGUMENT. So is a payload whose packet,
with worst-case padding and MAC, would pass the peer's MAX_PACKET_SZ
check; this also keeps the PreparePacket() size sums from wrapping.

- internal: MAX_IGNORE_DATA_SZ bounds the payload like the peer check
- regress: check the payload and the NULL default on the wire
- regress: 0xFFFFFFFB and one over the bound fail cleanly
- regress: the largest payload reaches a peer, plain and keyed, with
  the byte highwater off so a low DEFAULT_HIGHWATER_MARK cannot rekey

Issue: F-7512
2026-11-13 11:32:45 -06:00
John Safranek 63cf1ff4e9 internal: wipe packets DoPacket refuses
DoReceive() wipes a packet that DoPacket() refuses before dispatch: a
message id the state does not allow, such as a USERAUTH_REQUEST after
auth, padding under the minimum, or a length that overflows. Only a
pending auth keeps its packet, since the next call dispatches it again.

- tests: a post-auth password request and a short-padding packet are
  wiped; a pending password request is kept until it completes

Issue: F-17105
2026-11-12 16:55:41 -06:00
John Safranek 87012b9a73 wolfsshd: hold failed userauth to a minimum time
DefaultUserAuth() holds a failed attempt to a per-user minimum, modeled
on OpenSSH sshd: 5 ms plus up to 4.29 ms from a keyed hash of the
username, doubled while the time already spent exceeds it, and skipped
past 5 s. It sleeps and rechecks until the minimum has passed. The
library itself stays non-blocking.

- wolfSSHD_AuthInit() draws the per-daemon key before any fork
- the hash is SHA-256, else SHA-512 or SHA-384; with none, the floor
- Windows times the wait with QueryPerformanceCounter
- tests for the delay range, the doubling, an early-waking sleep, and
  a failing request

Issue: F-11938
2026-11-12 16:31:35 -06:00
John Safranek 9858b19269 internal: pad client userauth secrets to 64 bytes
The client pads a password USERAUTH_REQUEST and a keyboard-interactive
INFO_RESPONSE up to a multiple of 64 bytes, as OpenSSH does, so the
packet length no longer tracks the secret's length to the cipher block.

- BundlePacketPad() adds whole blocks of padding up to a bucket
- a packet held during our rekey keeps its bucket in keyingHold and is
  padded to it on release
- regress test checks 1 to 64 byte secrets over the none cipher,
  AES-CTR with HMAC, and AES-GCM, sent directly and after a hold

Issue: F-13390
2026-11-12 16:31:35 -06:00
John Safranek 7414925b98 internal: refuse secret auth over the none cipher
With WOLFSSH_ALLOW_NONE_CIPHER, a server whose NEWKEYS installed the
none cipher in either direction answers password and
keyboard-interactive requests, and an INFO_RESPONSE after a rekey to
none, with USERAUTH_FAILURE before the userauth callback sees a secret,
and leaves both methods out of the method list.

- DoNewKeys() and SendNewKeys() record a none cipher per direction
- a refused request or response clears authId, so a later INFO_RESPONSE
  is rejected
- unit tests drive both methods with each direction cleartext, and a
  rekey to none with a prompt outstanding

Issue: F-10578
2026-11-12 16:31:35 -06:00
John Safranek a4a6514cb3 wolfsshd: match CheckPasswordPAM to the callback
CheckPasswordPAM takes the WOLFSSHD_AUTH argument that
CallbackCheckPassword requires, so a --with-pam build compiles again.
It is still a stub and returns WSSHD_AUTH_FAILURE for every password.

Issue: F-11676
2026-11-11 22:55:03 -06:00
John Safranek 4582fcadd5 wolfsshd: free usrW in SetupUserTokenWin
SetupUserTokenWin frees its WCHAR copy of the user name in the common
cleanup with authInfo and the LSA handle, so a public key probe no
longer leaks it on Windows.

Issue: F-8854
2026-11-11 22:55:03 -06:00
John Safranek 00e6f3718c Correct comments that disagree with the code
Comment-only change: each comment now describes what its code does.
No code tokens change.

- kex: server f is our output, not the peer key; the ML-KEM-768 f is
  the ciphertext; the client hybrid also covers P-256 and P-384
- scp: base path and fd referents, NEW_REQUEST state, unchanged index,
  oversize rejection, and where the symlink checks are not atomic
- error.h: WS_DH_SIZE_E and WS_DISCONNECT meanings, GetErrorString()
- api: stream_read WS_EXTDATA, channel-open built-in refusals, write
  ctx, SFTP write offset, agent reply status, userauth returns
- misc: off_t guess, wSelect, handle cap, sftpclient, wolfsshd notes

Issue: F-9422, F-10564, F-11637, F-11638, F-11639, F-11640, F-12555,
       F-12556, F-13915, F-14207, F-14399, F-15514, F-15515, F-15516,
       F-16055, F-16056, F-16057, F-16757, F-16758, F-16759, F-16760,
       F-16761, F-16762, F-16763, F-17054, F-17055, F-17868, F-17869
2026-11-11 22:36:36 -06:00
John Safranek dfd7da5eb7 Read secret files through unbuffered streams
ReadFileIntoBuffer and the wolfsshd host-key and /etc/shadow readers
turn off stdio buffering right after open, so those secrets are read
straight into wolfSSH's own buffers instead of being staged in a libc
FILE buffer that fclose frees without wiping. Public-key lists stay
buffered.

- port.h: add WFSETNOBUF, setvbuf(_IONBF) for stdio ports, a no-op
  elsewhere
- wolfsshd: add wolfSSHD_OpenSecretFile, the unbuffered secure open
- test_configuration: the secret open reads no further than asked,
  the secure open reads ahead

Issue: F-14689, F-14690
2026-11-11 22:19:00 -06:00
John Safranek e1216a11dd internal: enforce accepted-key list in userauth
DoUserAuthRequestPublicKey() refuses a public key algorithm whose name
is not on algoListKeyAccepted, the list the server advertises in
server-sig-algs (RFC 8308 section 3.1). A NULL list leaves only the
compiled-in check.

- Match by name: the three OpenSSH RSA certificate names share one ID
- Bind an rsa-sha2-*-cert signature to its name's hash; the legacy
  ssh-rsa-cert-v01 takes any RSA hash, as OpenSSH's sshd does
- Advertise ssh-rsa-cert-v01 only where an ssh-rsa signature is accepted
- Pick the client's RSA certificate name from the certificate names in
  server-sig-algs
- Add TestUserAuthPkHonorsAcceptedList and two OpenSSH RSA certificate
  tests to the regress tests

Issue: F-16810
2026-11-11 21:57:43 -06:00
John Safranek e9deb96762 Anchor the key type checks in ReadKey_file
wolfSSH_ReadKey_file() now classifies a key file by comparing only its
first bytes against each SSH key type name and the OpenSSH and PEM
begin markers, rather than searching the whole file, which may be a
private key.

- match "ssh-mldsa" so composite ML-DSA public keys, such as
  ssh-mldsa44-es256@wolfssl.com, load as SSH format
- add test_wolfSSH_ReadKey_file_mldsaPub to api.c

Issue: F-14633, F-14666
2026-11-11 16:47:00 -06:00
John Safranek e2454ca67d tests: retry the drain peer's read on a timeout
The forked peer in RunDrainMidRekey() sets a 100 ms SO_RCVTIMEO and
retries its read. macOS can miss waking a read() that blocks just as
the other end half closes, leaving the peer asleep past the drain's
10 s deadline and failing DrainFailedRekey or DrainDisconnectMidRekey.
A missed wakeup now costs one timeout.
2026-11-11 14:12:41 -06:00
John Safranek d8d2140121 ssh: stop reading behind a large output backlog
wolfSSH_worker() and wolfSSH_stream_read() now flush before reading
once more than WOLFSSH_MAX_OUTPUT_BACKLOG bytes are queued, and return
WS_WANT_WRITE without reading if the flush leaves it over. A peer that
never reads can no longer grow outputBuffer one reply per packet.

- WOLFSSH_MAX_OUTPUT_BACKLOG defaults to two MAX_PACKET_SZ, overridable
- A smaller backlog still reads first, keeping the PR 856 order
- regress: unknown-id and GLOBAL_REQUEST floods with blocked sends stop
  at the cap and drain once the peer reads

Issue: F-16808
2026-11-11 12:35:23 -06:00
John Safranek 823a9edda8 client: load the built-in public key by default
Without -i the client loads the built-in private key, so load its public
half too and publickey auth with the default keys works. A -j file or a
TPM key still supplies its own public key.

Issue: F-13905
2026-11-10 23:46:28 -06:00
John Safranek fe9d68fafc client: bound and wipe the TPM key blob load
readKeyBlob() checks each part of the key file against its destination
before reading it, and every failure now returns an error with the file
closed. wolfSSH_TPM_InitKey() refuses a key auth that does not fit the
blob, frees what it loaded when it fails, and wipes the key material.
The tpm-ssh job feeds the client a bad key blob for each check.

- reject a public size over pubAreaBuffer, a private part over key->priv
- return BUFFER_E on a short read; parse errors go through exit
- refuse a -K value longer than the auth buffer
- unload the EK, session and key blob when the key load fails
- wipe the key blob and session on return, the TPM key on cleanup

Issue: F-8855, F-10558, F-10604, F-10601, F-10602, F-10603, F-17098
2026-11-10 23:46:28 -06:00
John Safranek b5e37bef91 ossh: keep decoder errors and the caller's heap
GetOpenSshKeyEd25519 now returns its parse errors as they are and
reports a wolfCrypt failure as WS_ED25519_E instead of WS_ECC_E. The
OpenSSH key decoders take the WS_KeySignature heap and initialize the
key with it, where they used NULL or the zeroed key's own heap field.

- tests: check the Ed25519 decoder errors and the heap of a decoded
  key

Issue: F-11653, F-11656
2026-11-10 14:58:50 -06:00
John Safranek 18dd82dd68 ossh: reject a misaligned OpenSSH private section
GetOpenSshKey checked the padding only when the private section was a
whole number of blocks, so a misaligned section, or one ending in junk,
loaded. It now rejects a section that is not a multiple of MIN_BLOCK_SZ,
as OpenSSH does, and compares every pad byte before deciding.

- tests: parse crafted Ed25519 keys with good, missing, junk and bad
  padding

Issue: F-12551, F-13925
2026-11-10 14:58:50 -06:00
John Safranek 2cc0d7d3f7 internal: keep rekey windows to transport only
RFC 4253 section 7.1 allows only transport messages from a party's
KEXINIT until its NEWKEYS. BundlePacket() holds anything else framed
in our window and SendNewKeys() sends it behind our NEWKEYS, and
IsMessageAllowed() refuses it from a peer in its window.
wolfSSH_OutputPending() does not count held output.

- Held: replies to requests in flight before our KEXINIT, and agent
  and forwarding channel opens, which still report success
- A hold past DEFAULT_KEYING_HOLD_SZ, or a failed release, sends
  DISCONNECT and ends the session
- wolfSSH_shutdown() runs the rekey until its held teardown goes out;
  HalfCloseAndDrain() runs it to the end unless the session is over
- The release reserves the output queue once, not once per packet
- regress, unit: cover both gates, delivery, the hold cap, a failed
  release, a channel open, the release allocations, and a shutdown and
  a drain mid-rekey

Issue: #1381
2026-11-10 14:34:09 -06:00
John Safranek bfc2a73550 zephyr: opt the tests in to weak entropy
wolfSSL now fails the Zephyr build with an #error unless the board has
a chosen entropy device or WOLFSSL_ACCEPT_WEAK_ENTROPY is defined.
qemu_x86 has no entropy device, so define the macro in both test
wolfSSL settings files to keep the sys_rand_get() seed.
2026-11-10 10:53:23 -07:00
John Safranek ef7fbf5913 internal: refuse an unsolicited INFO_RESPONSE
The server takes a keyboard-interactive INFO_RESPONSE only while an
INFO_REQUEST is outstanding, and refuses any other as fatal, as it
does one outside keyboard-interactive auth. A response kept for
redispatch on WS_AUTH_PENDING keeps the exchange outstanding.

- DoUserAuthInfoResponse() requires kbSetupPending and clears it only
  once the response is consumed, not on WS_AUTH_PENDING
- SendUserAuthKeyboardRequest() arms it once the request is delivered,
  even if the highwater callback then fails; a blocked setup re-arms it
- unit: unsolicited responses after no request, a declined setup, and
  failed or partial rounds; would-block retries; a highwater failure
- regress: the INFO_RESPONSE harness marks the exchange outstanding

Issue: F-17085
2026-11-10 10:31:31 -06:00
John Safranek 505df91780 Free only the KEX keys that were initialized
SendKexDhReply and the ECDH and Curve25519 KeyAgree functions now
track which keys were initialized and free only those. A host-key
format with no loaded key, or a failed small-stack allocation, no
longer hands never-initialized storage to the wolfCrypt free.

- sigKeyBlockFull gains keyInit, set by SendKexGetSigningKey
- per-key Inited flags in the client and server KeyAgree functions
- regress: no matching host key frees nothing (WOLF_CRYPTO_CB_FREE)
- unit: server KeyAgree survives an allocation failure (small stack)

Issue: F-11675, F-11939
2026-11-08 22:12:25 -06:00
John Safranek fc5d2631f9 ssh, internal: send one KEXINIT per key exchange
RFC 4253 7.1 allows one KEXINIT from each side per key exchange.
wolfSSH_TriggerKeyExchange() is now a no-op returning WS_SUCCESS while
any keying is in progress, and SendKexInit() skips once this side's
KEXINIT is out, so the stored copy feeding the exchange hash stays put.

- covers the highwater callback, whose byte and message marks can both
  fire in one rekey
- covers the window after SendNewKeys() clears the self-keying flag
  while the peer's NEWKEYS is still due
- regress: second trigger, nested highwater and NEWKEYS-window tests

Issue: F-16775
2026-11-08 17:47:44 -06:00
John Safranek 77283a6f41 Verify RSA host key signatures by encoding
DoKexDhReply() now checks an RSA host key signature over H the same way
userauth does: it hashes H, encodes the DigestInfo, and compares whole
blocks with wolfSSH_RsaVerify() per RFC 8332 Section 5.3, in place of
wc_SignatureVerify(). This also restores ssh-rsa host keys on wolfSSL
5.9.2 and later, which refuse SHA-1 in wc_SignatureVerify().

- tests: ssh-rsa host key handshake, valid and corrupted signature
- tests: host key signature with a trailing byte is rejected

Issue: F-17075
2026-11-08 16:42:27 -06:00
John Safranek 880ace69ad Refuse RSA signatures longer than the key
wolfSSH_RsaVerify() now returns WS_RSA_E when the signature is longer
than the modulus, so trailing bytes after a valid signature no longer
verify. A shorter signature is still left-padded with zeros.

- tests: unit test with one byte appended to a valid signature
2026-11-08 16:42:27 -06:00
John Safranek 788a0c3279 Reject UINT32_MAX before size + 1 allocations
DoSshPubKey() and wolfSSH_SetUsernameRaw() allocate a word32 size plus
one for a null terminator. Both now return WS_BAD_ARGUMENT for a size
of UINT32_MAX, where that sum wraps to a zero-byte allocation.

- api.c: SetUsernameRaw and ReadKey_buffer reject UINT32_MAX

Issue: F-15662, F-15663
2026-11-08 14:47:53 -06:00
John Safranek fa1696714d io: map ECONNABORTED on send to a closed socket
wsEmbedSend() returns WS_CBIO_ERR_CONN_CLOSE for SOCKET_ECONNABORTED,
matching wsEmbedRecv(), so an aborted connection during a send sets
isClosed instead of being reported as a general error.

- unit: a send failing with ECONNABORTED closes the session

Issue: F-13903
2026-11-08 14:04:58 -06:00
John Safranek d50e1fabd5 Treat a 0 from the recv callback as a hang-up
GetInputData() now fails with WS_SOCKET_ERROR_E and marks the session
closed when the recv callback returns 0, as GetInputLine() already
does. A custom callback reporting an orderly shutdown no longer spins
DoReceive() forever.

- tests: DoReceive with a callback that always returns 0

Issue: F-14397
2026-11-08 14:04:58 -06:00
John Safranek 8e4bfc188a Wipe the client channel name before freeing it
The client keeps its exec command line, which can carry credentials,
in ssh->channelName. FreeChannelName() wipes and frees it, mirroring
FreeChannelCommand() on the server side.

- use it in SshResourceFree() and at the three wolfSSH_SetChannelType()
  release sites
- unit test reads back each freed name through a retaining allocator

Issue: F-14691
2026-11-08 13:40:28 -06:00
John Safranek c4fba59b19 Wipe the env request value in DoChannelRequest
The env branch decodes the peer's variable value into a stack buffer
that can carry a token. Zero it before it leaves scope, on success and
on a parse error alike.

Issue: F-8849
2026-11-08 13:40:28 -06:00
John Safranek c0a36ce31f internal: keep userauth verifier error codes
The public-key userauth verifiers now return the error from the step
that failed, and map only the wolfCrypt key decode itself to
WS_CRYPTO_FAILED. The X.509 ECDSA verifier checks the signature's
algorithm name like its siblings.

- EccCert and Ed25519: argument, allocation, parse and type errors
  keep their own codes
- Rsa and RsaCert: a hash with no OID, or a failed encode, is
  WS_CRYPTO_FAILED before the verify
- EccCert: accept the declared x509v3 name or RFC 6187's ecdsa-sha2
  name for the same curve; anything else is WS_INVALID_ALGO_ID
- unit: cover each case; add wolfSSH_TestDoUserAuthRequestEccCert

Issue: F-11654, F-12544, F-15665
2026-11-07 09:40:21 -06:00
John Safranek d043c69477 wolfsshd: refuse Match Group on Windows
Windows wolfsshd does not look up a user's groups, so a Match Group
block could never apply and its restrictions were skipped. The config
load now rejects a Group selector there, as it does other unsupported
Match selectors.

- WOLFSSHD_NO_MATCH_GROUP gates the rejection, set for _WIN32
- add sshd_match_group_win_test.ps1 to the Windows check workflow

Issue: F-15559
2026-11-06 17:22:52 -06:00
John Safranek 5427e97a87 wolfsshd: honor ChrootDirectory none
"ChrootDirectory none" now means no chroot, as in OpenSSH, instead of
a relative chdir() target. The keyword still counts as set, so a Match
block using it exempts a user from a global ChrootDirectory.

- match "none" case-insensitively, as OpenSSH does
- add sshd_chroot_none_test.sh: global and Match cases against an
  empty global chroot

Issue: F-16811
2026-11-06 17:22:52 -06:00
John Safranek 1a34042a5c wolfsshd: honor AuthorizedKeysFile none
"AuthorizedKeysFile none" now turns off the authorized keys file, as
in OpenSSH, instead of naming ~/none, a file the user controls. The
value stays "none" through Match composition, and SearchForPubKey
refuses it before resolving any path.

- match "none" case-insensitively, as OpenSSH does
- OpenSSH certificates still check against TrustedUserCAKeys
- X.509 certificates do not fall back to CA-only under "none"
- a "none" node passes the wolfSSH_TrustedSystemCAKeys startup gates
- add sshd_authkeys_none_test.sh: key in ~/none, X.509 CA-only and
  system CA gate cases, each set globally and in a Match block

Issue: F-15558
2026-11-06 17:22:52 -06:00
John Safranek 33e4c2c3ce wolfsshd: hash passwords with crypt_r() if found
CheckPasswordHashUnix() hashes into a heap struct crypt_data when
configure finds crypt_r(), and wipes the whole struct on return, so
neither the result nor crypt's working state is left behind. Builds
without it, such as macOS, keep crypt() and its result wipe.

- configure probes crypt_r() through <crypt.h> as HAVE_CRYPT_R

Issue: F-8842
2026-11-06 11:35:15 -06:00
John Safranek 4f4bce302f wolfsshd: wipe host key copies left behind
The shell child frees its session and the server context before it
drops to the user, so the host private key and the session keys are
wiped from its image ahead of the exec. It keeps copies of the user
name and command it still needs. A short read of a key file wipes
the buffer before freeing it.

Issue: F-8841, F-14227
2026-11-06 11:35:15 -06:00
John Safranek 7c0e77f4de wolfsshd: wipe Windows shell command lines
The wide-character copies of the peer's command are zeroed before
they are freed, in SHELL_Subsystem() and in SetupConsole(). A
CreateProcessW() failure in SetupConsole() now runs its cleanup
before returning WS_FATAL_ERROR.

Issue: F-8851, F-10596
2026-11-06 11:35:15 -06:00
John Safranek da34cd0dd6 wolfsshd: keep account entries off libc storage
Account lookups go through wolfSSHD_GetPwnam(), which fills a
caller-owned store with getpwnam_r() and wipes it on release. Shadow
entries are read the same way with getspnam_r() where libc has it.
The crypt() result is wiped on every path.

- auth.c and the session lookup in HandleConnection use the store
- configure probes the five-argument getspnam_r() as HAVE_GETSPNAM_R
- ScanShadowFile() wipes the line the loop exit reads
- the getpwnam/getspnam test hooks default to NULL, the real lookup
- test_GetPwnam checks the store, the wipe, and the errno contract

Issue: F-11683, F-11684, F-13439, F-8842, F-12646
2026-11-06 11:35:15 -06:00
John Safranek ba55eef265 wolfsshd: start SCP sessions in the user's home
SCP_Subsystem() changes to pw_dir after dropping privileges, as the
shell and SFTP do, so a relative remote path resolves from home rather
than from the daemon's working directory, inside a chroot too. When
home is unreachable, SCP and the shell start from "/", as OpenSSH does.
Both log that only outside a chroot.

- sshd_scp_home_test.sh uploads to "." and finds the file in home

Issue: F-15502
2026-11-06 11:35:15 -06:00
John Safranek 0c826bb4c6 wolfsshd: fix shell child exit and setup failures
A shell child killed by a signal now reports 128 plus the signal as
its exit status. A failure after the fork kills and reaps the child
and closes the parent's descriptors to it, and the resize context is
cleared before the terminal it points at is closed.

- SHELL_AbortChild() serves the post-fork setup failures, which now
  run before the parent drops privileges so it can still kill the child
- -r with no command now fails at the argument check in main()
- sshd_exit_signal_test.sh checks a plain exit and a SIGKILL

Issue: F-13327, F-14203, F-15571, F-14204
2026-11-06 11:35:15 -06:00
John Safranek b40b26b2b2 internal: fail DoModes when the tty is unreadable
wolfSSH_DoModes() now returns -1 without touching the terminal when
tcgetattr() fails, instead of applying an uninitialized termios. A
failed tcsetattr() is reported the same way, and wolfsshd logs it.

- api.c: DoModes fails on a pipe and sets ECHO on a pty

Issue: F-10546
2026-11-06 11:35:15 -06:00
John Safranek fed79308c5 wolfsshd: stop splitting long config lines
ConfigLoad() reads lines of up to 1023 bytes and drains the rest of a
longer one, so its tail is never parsed as a line of its own.

- skip an over-long comment whole and fail the load on an over-long
  directive, also one pushed out by leading whitespace
- ignore whitespace past the end of the buffer
- drop the one-byte peek past a full buffer, which the drain replaces;
  it failed every over-long comment
- add a long-line load test

Issue: F-14395
2026-11-05 12:42:15 -06:00
John Safranek 6753f21a28 wolfsshd: accept comma lists in Match User/Group
Match User and Match Group now take a comma separated list of exact
names and apply when any entry equals the user or one of the user's
groups.

- reject '*', '?', '!' and empty entries in a Match name list
- add parser cases and a Match list lookup test

Issue: F-11661
2026-11-05 12:42:15 -06:00
John Safranek 3105f72777 wolfsshd: fix Include wildcard matching
HandleInclude() now checks the first character of the pattern for a
'*', so a pattern with no directory part, such as "Include *.conf",
is expanded rather than opened as a literal file. The '*' may match
an empty sequence, but the fixed prefix and postfix may not overlap.

- skip names with a leading '.' unless the pattern starts with '.',
  as glob(3) does
- add tests for foo*, *foo, f*o, a*a and the overlapping ab*ba
- add a leading-wildcard pattern that matches nothing

Issue: F-10550, F-14632
2026-11-05 12:42:15 -06:00
John Safranek 727efd690f wolfsshd: reject trailing text in numeric options
GetConfigInt() now requires the whole value to be decimal digits, so
"Port 22abc" fails to load instead of reading 22. LoginGraceTime takes
the sshd_config(5) time format, number and unit groups summed as
seconds, so "1h30m" is 5400 and "2junk" is rejected.

- accept the s, m, h, d and w units in either case, zero-padded
  groups, and a bare trailing number as seconds, as OpenSSH does
- reject values above 0x7FFFFFFF, per group and in the sum
- write the bad Include fixture as "LoginGraceTime bad", since a
  zero-padded time is now valid
- add Port, Protocol and LoginGraceTime cases to the parser test

Issue: F-10549, F-17100
2026-11-05 12:42:15 -06:00
John Safranek db33d8f462 certman: reject a profile leaf with no signer
wc_ParseCert() with NO_VERIFY does not look up the signer of a
self-issued leaf, so CheckProfile() treats a NULL cert->ca as a
profile mismatch instead of dereferencing it.

- test a self-issued leaf that reaches the issuer-DN match

Issue: F-8862
2026-11-05 12:26:48 -06:00
John Safranek 7371233e86 certman: keep peer intermediates as chain CAs
VerifyCerts_buffer() loaded every verified cert above the leaf as a
trusted root. It now loads an intermediate only when the cert below
needs it as issuer, and on wolfSSL 5.8.4 or later keeps it as a
WOLFSSL_CHAIN_CA, as TLS does, tagging it once the cert below verifies
or fails only on its signature, since the typed load retags matches.

- every cert above the leaf must still pass the CA check
- use the typed load only without NO_SKID, mapping failures to WS_ codes
  and logging a failed retag as an error
- document the kept intermediates and the strict chain order
- test that roots stay roots and a CA loads only for a cert it signs
- test that a failed allocation never retags a trusted root and that a
  bad-signature leaf leaves its CA a chain CA

Issue: F-10586
2026-11-05 12:26:48 -06:00