Commit Graph

2384 Commits (9cb60cdadf0e423498d47504e3d35bc5e93b187d)

Author SHA1 Message Date
John Safranek 9cb60cdadf DoUserAuthRequestPassword Missing Bounds Check
Replace the original message parsing functions with the GetStringRef()
function, which does better bounds checking.

Affected function: DoUserAuthRequestPassword.
Issue: F-411
2026-03-16 14:20:23 -07:00
John Safranek a8ad9f0197 DoIgnore Missing Payload Bounds Validation
The DoIgnore() function was not bounds checking the ignore message.
Changed it to use the GetSkip() function which does bounds checking and
skips the current blob. Updated GetSkip() to allow 0 length blobs to
skip.

Affected function: DoIgnore.
Issue: F-410
2026-03-16 14:20:23 -07:00
John Safranek 801ac0701d Non-constant-time password hash comparison
In wolfSSHd, the comparisons of the password hash and public keys were
using memcmp(). Changed to use ConstantCompare().

Affected functions: CheckPasswordHashUnix, CheckPublicKeyUnix.
Issue: F-53
2026-03-16 14:20:18 -07:00
John Safranek 010380666e
Merge pull request #887 from tjko/mlkem_fix
Fix compiling when WOLFSSH_NO_NISTP256_MLKEM768_SHA256 is defined.
2026-03-09 10:30:05 -07:00
John Safranek a6b6db8d2a KEX Fix
1. When disabling mlkem768nistp256-sha256, there's a crash when doing a
   mlkem768x25519-sha256 KEX. It tries to do a DH key exchange instead
   of x25519 with ML-KEM. Modified the check.
2. Fixed a guard where the build was treating not having
   mlkem768nistp256-sha256 like a FIPS build disallowing using ML-KEM
   when generating sesssion keys. It shouldn't make that check.
3. Added a test case to the KEM test.
2026-03-09 10:29:13 -07:00
John Safranek ddd93343d0 No Server Guard Update
1. Adds --disable-server and --disable-client configure flags. Allows for
   compile-time exclusion of server or client code.
2. Add check to internal.h for both NO_WOLFSSH_SERVER and
   NO_WOLFSSH_CLIENT being set and errors.
3. In ports.h, add check for not-NO_WOLFSSH_CLIENT so SFTP/SCP
   filesystrem types are also available in client-only builds.
4. Update the NO_WOLFSSH_SERVER and NO_WOLFSSH_DIR guards around
   wolfsftp.c. Update wolfSSH_SFTP_free() to skip directory cleanup
   when server code is disabled.

ZD #21261
2026-03-09 10:29:00 -07:00
John Safranek b048f18d8c
Merge pull request #885 from padelsbach/padelsbach/finding-401-402-403
Fix multibyte passwords, file mode and attrib reporting
2026-03-09 10:27:56 -07:00
JacobBarthelmeh 1e1140aa5a
Merge pull request #883 from ejohnstown/static-fixes
Static analysis fixes
2026-03-06 10:09:29 -07:00
John Safranek be69a46db0
Merge pull request #882 from JacobBarthelmeh/sftp
More robust SFTP send/read handling
2026-03-06 07:35:58 -08:00
Timo Kokkonen 697ee6c79a Remove guard checks. 2026-03-05 16:39:41 -08:00
JacobBarthelmeh 045012c163 adjust when the windows-sftp github actions test is triggered 2026-03-05 13:27:08 -07:00
John Safranek e923235cb9 Uninitialized `mode` Variable in FatFS `ff_open`
Removed the variable. The flags passed to ff_open() are appropriate for
ff_open(). Just check that read or write is set.

Affected function: ff_open.
Issue: F-213
2026-03-05 10:45:51 -08:00
John Safranek 3cfec8b3d2 Missing ForceZero on plaintext password copy
When a copy of the user's password is freed, it wasn't getting force
zeroed. It might still exist in the heap after getting freed.  Added
a call to `ForceZero()`.

Affected function: CheckPasswordUnix.
Issue: F-56
2026-03-05 10:45:37 -08:00
John Safranek 86636797ee Missing break between switch cases
Addded a break to the 'J' case of a switch statement that handles
terminal display clearing for Windows. It was flowing into case 'K'
without an explicit fallthrough tag.

Affected function: wolfSSH_DoControlSeq.
Issue: F-49
2026-03-05 10:45:16 -08:00
John Safranek f424d7a7fb Unchecked `wc_InitRsaKey` Return Value
Check the return value of `wc_InitRsaKey()`. It will initialize the
structure provided the pointer is non-null. Since the key is on the
stack, the later call to `wc_FreeRsaKey()` will succeed as well.
Modified the check for the encoded signature size inside the block where
it is set; that check also updates the return value.

Affected function: SignHashRsa.
Issue: F-212
2026-03-05 10:45:01 -08:00
John Safranek b0e424e05d Missing `wc_ecc_init()` Before ECC Key Import
1. Call `wc_ecc_init()` on an ECC key before importing it.
2. Incidental: `PostLock()` and `PostUnlock()` needed their agent pointers
   tagged as unused.

Affected functions: SignHashEcc. PostLock and PostUnlock.
Issue: F-211
2026-03-05 10:44:49 -08:00
John Safranek 2da09427cd Operator Precedence Bug
Added parens around an assignment to a variable before it is compared to
an expected value.

Affected function: SetupUserTokenWin.
Issue: F-210
2026-03-05 10:43:56 -08:00
David Garske 9efdb7e820
Merge pull request #884 from aidangarske/add-ci-workflows
Add more CI workflows for wolfSSH
2026-03-04 17:07:48 -08:00
Paul Adelsbach 0458d83137 Fix multibyte passwords, file mode and attrib reporting 2026-03-04 15:29:36 -08:00
aidan garske 09144d0c7a Add more wolfSSH CI workflows 2026-03-03 21:22:39 -08:00
JacobBarthelmeh 567efa5a04
Merge pull request #874 from ejohnstown/rxd-fix
RxD Fix
2026-03-03 14:48:44 -07:00
JacobBarthelmeh 30ea988943 add Windows wolfsshd <-> wolfsftp test with large transfers 2026-02-27 16:23:27 -07:00
JacobBarthelmeh 83a3990d0d add aditional large SFTP transfer test when the SFTP read/write buffer is increased in size 2026-02-27 16:22:55 -07:00
JacobBarthelmeh 0539f004d3 use NoticeError throughout wolfsftp.c and account for rekey with more sftp client commands 2026-02-27 16:21:46 -07:00
John Safranek 2c6c0c7754 RxD Fix
1. When wolfSSH_worker() receives channel data, it should set the
   channelId for the data. It was not happening. Change the check for
   WS_SUCCESS to also check for WS_CHAN_RXD.
2026-02-26 15:06:17 -08:00
John Safranek 08ce58ce7c Forwarding Test
1. Add a test script and expect script for testing forwarding.
2. Update portfwd to have a ready file option.
3. Fix echoserver error string, needed NL.
2026-02-26 15:02:19 -08:00
John Safranek 5cd81c9f1f Agent Update
1. Fix a couple unused variable warnings.
2. In wolfSSH_AGENT_DefaultActions(), fix comparison to the result of
   snprintf() treating normal result as an error. Reset the return code
   for the error state of the socket() command. Better cleanup of agent
   startup failures.
2026-02-26 14:37:07 -08:00
JacobBarthelmeh a2e6556a1a
Merge pull request #881 from ejohnstown/static-fixes
Static analysis fixes
2026-02-25 17:05:13 -07:00
John Safranek 961810b993 Fix wrong bitwise operator for testing attribute
Was using OR to check if a bit was set in the read-only file attribute.
This was always succeeding. Needed to change to an AND to see if it is
set.

Affected function: GetFileStats.
2026-02-24 16:43:18 -08:00
John Safranek d6e1b04316 Check correct pointer for null
After creating a new SSH context, the pointer returned wasn't checked;
the pointer to the pointer was checked. Changed to the correct pointer.

Affected function: SetupCTX.
2026-02-24 16:43:18 -08:00
John Safranek 13ffca4828 Fix null dereference after failed channel lookup
When looking up the channel object for the current channel ID, if the
lookup failed, we still checked if the channel had an EOF with a null
pointer. That function, does check for NULL and error, but it is better
to error out sooner.

Affected function: ReceiveScpMessage.
2026-02-24 16:43:18 -08:00
John Safranek 05ec832939 Check bounds on addition with value from peer
Bounds check the bytes to add from the peer against the window size.

Affected function: DoChannelWindowAdjust.
2026-02-24 16:43:13 -08:00
John Safranek c802a7faf4 Fix null check for duplicated string
When making a copy of a string, check the destination pointer of the
copy rather than the original.

Affected function: CheckPasswordUnix.
2026-02-24 16:15:11 -08:00
David Garske 0a0341fea9
Merge pull request #880 from LinuxJedi/static-fixes
Static analysis fixes
2026-02-23 08:08:22 -08:00
Andrew Hutchings 82b9f1138d Fix NULL pointer dereference in wolfSSH_SetTpmDev/SetTpmKey
Move the NULL validation checks inside the existing NULL guards for
ssh and ssh->ctx. Previously, the check accessed ssh->ctx outside
the guard, causing a NULL dereference when ssh or ssh->ctx was NULL.
Also fix wolfSSH_SetTpmKey to check tpmKey instead of tpmDev.
2026-02-23 10:23:26 +00:00
Andrew Hutchings 99319bf773 Fix wrong variable checked in DoCheckUser auth callback
In DoCheckUser, after calling auth->checkUserCb(usr) into rc, the
failure check on line 1063 compared ret instead of rc against
WSSHD_AUTH_FAILURE. Since ret is WOLFSSH_USERAUTH_SUCCESS at that
point, the condition was always false, causing callback failures to
fall through to the generic error branch with WOLFSSH_USERAUTH_FAILURE
instead of returning WOLFSSH_USERAUTH_INVALID_USER.
2026-02-23 10:21:35 +00:00
Andrew Hutchings eab0488966 Fix octal validation loop index in GetScpFileMode
The upper-bound check in the octal-to-integer conversion loop used
modeOctet[0] instead of modeOctet[i], so only the first character
was validated against '7'. Characters at positions 1-3 could have
values above '7' without triggering an error.
2026-02-23 10:19:25 +00:00
Andrew Hutchings 6547f04a77 Fix digest comparison in FindKeyId to use id->id field
WMEMCMP was comparing the computed SHA-256 digest against the
WOLFSSH_AGENT_ID struct pointer instead of the id field within
the struct, causing key lookups by digest to never match.
2026-02-23 10:14:21 +00:00
Andrew Hutchings 0728d9cac0 Fix two bugs in PostRemoveId agent identity removal
Fix inverted WMEMCMP check that removed non-matching entries and kept
matching ones. WMEMCMP returns 0 on match, so the condition was backwards.

Fix head-of-list removal setting idList to NULL instead of cur->next,
which dropped all remaining entries after the removed one
2026-02-23 10:12:01 +00:00
Andrew Hutchings 4cb8d1ee99 Fix buffer over-read in wolfSSH_DoModes terminal mode parsing
The while loop condition only checked that the opcode byte was in bounds
(idx < modesSz) but not the 4-byte argument read by ato32(). When
modesSz had a remainder of 1 mod 5 and the trailing byte was a valid
opcode (1-159) rather than TTY_OP_END, ato32() would read 4 bytes past
the buffer. Change the loop guard to require a full TERMINAL_MODE_SZ
bytes remaining before entering the loop body.
2026-02-23 09:56:01 +00:00
Andrew Hutchings 46cd6a7d6e Fix logical operator in public key type validation checks
Change && to || in 5 instances where public key type matching used
AND instead of OR, causing WMEMCMP to be skipped when type sizes
matched. Two key types with the same size but different content
would incorrectly pass validation.

Affected functions: DoUserAuthRequestRsaCert, DoUserAuthRequestEcc,
and DoUserAuthRequestEccCert.
2026-02-23 09:28:08 +00:00
JacobBarthelmeh 4b46454af2
Merge pull request #877 from LinuxJedi/contention-testing
Add contention testing
2026-02-16 14:02:43 -07:00
Andrew Hutchings 33203c3aca Add contention testing
Simulate netowrk latency using netem and use it to test the non-blocking
mode of SFTP. This helps find issues which would affect running an SFTP
server on a microcontroller. It helped find the bug fixed in #876.
2026-02-16 06:42:32 +00:00
JacobBarthelmeh e60aafe955
Merge pull request #876 from LinuxJedi/sftp-hang
Fix SFTP server hang on WS_WANT_WRITE with non-blocking sockets
2026-02-12 15:23:42 -07:00
JacobBarthelmeh 61d1094f9d
Merge pull request #878 from ejohnstown/fatfs-update
Update FatFS Test
2026-02-12 15:18:24 -07:00
John Safranek 804aef5b00 Update FatFS Test
1. Update caching the download of the FatFS source archive to the
   pattern other tests are using to cache items. It was downloading
   the FatFS source archive every time, despite it being in the cache.
2. Update building wolfSSL to follow the pattern of the other tests.
2026-02-12 13:14:41 -08:00
Andrew Hutchings 67c7b9cce9 Address items in the review 2026-02-12 06:40:29 +00:00
Andrew Hutchings aa1b1676cb Fix SFTP server hang on WS_WANT_WRITE with non-blocking sockets
When wolfSSH_SFTP_buffer_send() called wolfSSH_stream_send(), the data
would be consumed into the SSH output buffer even if the underlying
socket returned EWOULDBLOCK/EAGAIN. SendChannelData() returns the
positive dataSz on WS_WANT_WRITE, causing the SFTP layer to advance
its buffer index as if the data was sent. The SSH output buffer still
had pending data that was never flushed, leading to an indefinite hang.

Fix: At the start of wolfSSH_SFTP_buffer_send(), check if there's
pending data in ssh->outputBuffer from a previous WS_WANT_WRITE. If
so, attempt to flush it first and return WS_WANT_WRITE if the flush
fails. This ensures the caller retries until all pending data is sent.

Also expose WS_SFTP_BUFFER and wolfSSH_SFTP_buffer_send() as
WOLFSSH_LOCAL for unit testing, and add regression test that verifies
the fix catches the bug.

Fixes ZD 21157
2026-02-05 12:06:46 +00:00
JacobBarthelmeh d32dd2bf97
Merge pull request #873 from ejohnstown/misc-updates
Misc Updates
2026-01-28 11:01:03 -07:00
John Safranek ea45034204 Global Request functions
1. Readjust the whitespace in the Global Request functions.
2. Remove redundant logging statements.
2026-01-27 11:00:09 -08:00