Commit Graph

118 Commits (c71202ffdb92202cc53bd520ee45f438d2edded4)

Author SHA1 Message Date
John Safranek 7325678553 echoserver: keep the EOF reply owed across a rekey
wolfSSH_ChannelIdRead() has no rekey guard, so a drained channel still
reports zero mid-rekey and the drain loop calls the reply in. That send
returns WS_REKEYING before it prepares a packet, so nothing is queued.

- take the send's status instead of discarding it
- latch eofAnswered and ChildRunning on every status but WS_REKEYING, so
  the reply is retried on a later pass; the KEX traffic wakes it
- a short send is left latching: it bundled the EOF and set eofTxd, so a
  retry queues nothing and the loop would stall in an untimed select
  waiting on a peer that has already half-closed
- same change in the Espressif copy
2026-08-31 11:53:29 -05:00
John Safranek fc3b0a86bd Take the worker's status before the EOF drain
The drain runs between wolfSSH_worker() and the get_error() that classifies
its result, and its reads and sends latch their own status: WS_WINDOW_FULL
and WS_WANT_WRITE from a send, WS_REKEYING from a read. The ladder then read
the drain's status as the worker's, matched no arm, and ended the session
with the backlog unsent and no EOF.

- Read the error once, right after the worker returns
2026-08-31 11:53:29 -05:00
John Safranek ad08a10ba6 Hold the EOF drain's unsent tail across passes
A chunk read out of the channel is gone from it, so breaking the drain on
a non-positive send dropped whatever the send had not taken, and the echo
back to a half-closing peer came up short.

- Keep the chunk and its offset across worker passes, and read the next
  chunk only once the last one is out
- Give the drain its own buffer; the read path below it reuses
  channelBuffer in the same pass
- Answer the EOF off a drained flag, since a held tail means a zero read
  count no longer marks an emptied channel
2026-08-31 11:53:29 -05:00
John Safranek ff59c723ec Handle the EOF status in apps and examples
Every in-tree caller of wolfSSH_worker() now recognises a peer half-close.
wolfsshd's shell loop and both echoservers need it: all three ladders end in
"else if (rc != WS_WANT_READ) break", and wolfsshd's reaches
kill(childPid, SIGKILL), so without it a client half-close kills the command
it just finished feeding.

- wolfsshd closes the child's stdin off the channel's own EOF state instead of
  off a worker return of zero, which no longer happens on a half-close.
- The echoservers answer the half-close off wolfSSH_ChannelGetEof() rather
  than the WS_EOF status: the flush inside wolfSSH_worker() can supersede that
  status, and it is raised once. They hand back the backlog first, finish a
  short send, and only send the EOF once the channel is empty. Answering is
  not conditional on the shell build, where an echo session is the default.
- The SFTP loops peek before leaving, so a half-close with requests still
  buffered is served rather than dropped, and they report an ordinary session
  end as success.
- The clients -- examples/client, scpclient, sftpclient, apps/wolfssh -- treat
  it as the graceful case instead of an error. apps/wolfssh counts it as a
  finished flush as well, since one worker pass can drain the queue and
  consume the peer's EOF together.
- portfwd relays it to the local socket with shutdown(SHUT_WR) so a local
  reader waiting on end-of-input returns, once the backlog has genuinely been
  handed over: a read cut short by a rekey leaves the half-close for a later
  pass.
- The Windows half of wolfsshd does not answer with an EOF of its own. That
  latches eofTxd and the child's remaining output would be refused, which is
  the defect this series removes from the library.
- The mplabx port drains before tearing down, the way its SFTP read path
  already did; its worker arm was unreachable for a half-close until now.
2026-08-31 11:53:29 -05:00
John Safranek d70f8e64d3 Hoist the shared unit test doubles
The receive mock and the packet builders sit ahead of every endpoint region
rather than inside the server half. A staged-packet IORecv and a plaintext
packet builder have nothing to do with which endpoint is built, and the tests
that follow reach for them from both halves.

- Marked WS_MAYBE_UNUSED, since either half can be the only user of any one.
- WantWriteIoSend() joins DiscardIoSend() among the send mocks.
- A relocation only: no test body changes, and the moved text is unchanged
  bar the annotation. Read it with --color-moved.
2026-08-31 11:53:29 -05:00
John Safranek 26ccac3cdd examples, tests: terminate the ES_ERROR messages with a newline
ES_ERROR() passes its arguments straight to fprintf(stderr, ...), so a
message with no trailing newline runs into whatever the shell or the
test harness prints next.

- 7 sites in the echoserver, 6 in tests/auth.c, 8 in the Espressif copy
  of the echoserver, which carries the same macro and takes this kind of
  cross-cutting fix (e91ff50d, ab8058d7)
- the two wrapped format strings already ended with a newline
2026-08-28 18:22:34 -05:00
Yosuke Shimizu e91ff50def Fix a one byte heap overflow in LoadTpmSshKey 2026-08-13 11:59:57 -07:00
Ruby Martin ab8058d7cd check return value of WFTELL() 2026-08-10 10:19:45 -07:00
Ruby Martin 97bbe42263 Add WFSEEK return value checks where previously discarded 2026-08-10 10:19:45 -07:00
Yosuke Shimizu 029d412e1f Add OpenSSH certificate user authentication 2026-07-27 23:30:20 -07:00
Emma Stensland 1f674b0ec7 SSHD/Echoserver: Fix memory leaks and public-key lookup 2026-07-17 20:01:44 -05: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
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
John Safranek e8793bb268 UTF-8 -> 7-bit ASCII cleanup
1. replace section symbol with 'sec'
2. replace right arrow with '->'
3. replace m-dash with '--'
4. replace less-than-equatal-to with '<='
2026-05-18 14:35:58 -07:00
John Safranek b610dd75c4 sftp Client Windows Version
The project file for the wolfSFTP example client is specifying a
too-specific Windows target platform version. It is the only project
file specifying the version to four places. Removed it and using the
default Windows version for the version of the build tools.
2026-04-27 13:42:06 -07:00
John Safranek 8951bd9209 Release v1.4.22
1. Update copyright date to 2026.
2025-12-29 16:53:33 -08:00
John Safranek f1b5b78a98
Merge pull request #847 from miyazakh/sftpclient_RX72N
sftp client example for Renesas RX72N
2025-12-18 09:44:09 -08:00
Eric Blankenhorn 4c7ca0e9eb
Merge pull request #851 from lealem47/vs_fips
Add FIPS configurations to Visual Studio project
2025-12-15 16:35:53 -06:00
Lealem Amedie 1adcdebc1e Documentation feedback 2025-12-15 14:59:32 -07:00
Lealem Amedie 7ed7cd6a7f Add some documentation for the FIPS configs 2025-12-12 10:25:39 -07:00
Hideki Miyazaki 63ed4eb072 Addressed code review comments
- enable TSIP
 - clean up user_settings.h
2025-12-10 04:51:19 +09:00
Hideki Miyazaki 344bba5e51 Addressed review comments
- renamed wolfstp_util.c to wolfsftp_util.c
 - removed unnecessary if condition
2025-12-10 04:51:19 +09:00
Hideki Miyazaki 23cc902466 update README 2025-12-10 04:51:19 +09:00
Hideki Miyazaki 9c9d1b0ee1 sftp client example for Renesas RX72N 2025-12-10 04:51:19 +09:00
Lealem Amedie dc9321b714 Add FIPS configurations to Visual Studio project 2025-12-05 16:45:11 -07:00
hanshenrik 44dc148dbd replace sys/errno.h with errno.h
Historically, some systems have used <sys/errno.h> in place of <errno.h>, but the C standard,
 all the way back to C89/Ansi C, specifies that the correct name is `errno.h` -
and most modern compilers create a sys/errno.h compatibility shim sys/errno.h -
but musl-gcc does not have this compatibility shim,
 reasoning that sys/errno.h is non-standard, and fails to compile:
```
$ CC=musl-gcc ./configure --enable-static --disable-shared --enable-scp --enable-sftp --enable-shell --with-wolfssl=wolfssl/install-musl
(...)
$ make
make -j17  all-am
make[1]: Entering directory '/home/hans/projects/wolfssh'
  CC       examples/client/common.o
  CC       examples/client/client.o
  CC       src/libwolfssh_la-ssh.lo
  CC       src/libwolfssh_la-internal.lo
  CC       src/libwolfssh_la-log.lo
  CC       src/libwolfssh_la-port.lo
  CC       src/libwolfssh_la-io.lo
  CC       src/libwolfssh_la-wolfscp.lo
  CC       src/libwolfssh_la-wolfsftp.lo
  CC       examples/echoserver/echoserver.o
  CC       src/libwolfssh_la-wolfterm.lo
  CC       examples/sftpclient/sftpclient.o
  CC       examples/scpclient/scpclient.o
In file included from examples/echoserver/echoserver.c:91:
/usr/include/x86_64-linux-musl/sys/errno.h:1:2: error: #warning redirecting incorrect #include <sys/errno.h> to <errno.h> [-Werror=cpp]
    1 | #warning redirecting incorrect #include <sys/errno.h> to <errno.h>
      |  ^~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:1452: examples/echoserver/echoserver.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/home/hans/projects/wolfssh'
make: *** [Makefile:1020: all] Error 2
```

so, unless we need to support pre-C89 (35+ year old C) compilers,
we can just replace sys/errno.h with errno.h.
2025-11-22 17:40:20 +01:00
gojimmypi dccc62bafd
Rename wolfssh test certs 2025-09-03 11:10:53 -07:00
JacobBarthelmeh 333cf30d60 fix for make dist 2025-08-21 11:07:50 -06:00
JacobBarthelmeh abc4e27e3c refactor internal handle list and set filesystem override priority 2025-06-13 16:32:06 -06:00
gojimmypi 89013e73cf
Update Espressif README with getting started info. 2025-06-12 11:36:35 -07:00
gojimmypi b9658bc801
Update Espressif Examples 2025-06-11 15:37:14 -07:00
David Garske d3bd96f210
Merge pull request #790 from JacobBarthelmeh/pic32
microchip example and filesystem port
2025-04-04 10:04:16 -07:00
JacobBarthelmeh ae5fa76f74 update include.am for correct mplabx files 2025-04-04 10:15:30 -06:00
JacobBarthelmeh 79d32d0f80 create library build exmaple 2025-04-02 17:17:40 -06:00
JacobBarthelmeh 5fb496b9aa add chmod support, update readme and example app 2025-03-19 14:32:18 +07:00
JacobBarthelmeh 4f9e6b5732 remove some trailing white space and initialize get current drive buffer 2025-03-18 15:13:48 +07:00
JacobBarthelmeh 7067b200b8 clear stat struct before use and treat mount as directory 2025-03-18 13:01:04 +07:00
JacobBarthelmeh 604d1e8422 ls command working 2025-03-14 09:33:42 +07:00
Andrew Hutchings a37591f3f5 Remove FATFS and link to it instead 2025-03-06 10:33:40 +00:00
Jacob Barthelmeh 41cef3309f fix numbering in README steps 2025-02-28 16:17:54 -07:00
Jacob Barthelmeh 48fa1e019e add example code for MPLABX use 2025-02-28 16:17:51 -07:00
Andrew Hutchings 648bee2314 Add copyright header to fatfs_example.c 2025-02-28 07:21:44 +00:00
Devin AI 86a6544c52 Fix C-style comments in fatfs_example.c
Co-Authored-By: andrew@wolfssl.com <andrew@wolfssl.com>
2025-02-27 20:11:14 +00:00
Devin AI d8e94e55f3 Fix C-style comments in diskio.c
Co-Authored-By: andrew@wolfssl.com <andrew@wolfssl.com>
2025-02-27 19:56:02 +00:00
Devin AI da01ceac13 Add GitHub Action to test FATFS support for wolfsftp client
This adds a GitHub Action workflow to test the FATFS support for the wolfsftp client.
The workflow:
- Installs dependencies
- Clones and builds wolfSSL with appropriate flags
- Compiles the FATFS library
- Configures and builds wolfSSH with FATFS support
- Creates a test file
- Sets up an SSH server
- Uses the wolfsftp client to transfer a test file
- Verifies the file in the FATFS image

Co-Authored-By: andrew@wolfssl.com <andrew@wolfssl.com>

Co-Authored-By: andrew@wolfssl.com <andrew@wolfssl.com>
2025-02-27 15:40:06 +00:00
Andrew Hutchings 08759f1943 Add FATFS Linux example
This allows a file on the Linux filesystem to be used as a FATFS file.

It also fixes a bug in `port.h` when opening file on a FATFS filesystem.
2025-02-27 12:18:05 +00:00
Andrew Hutchings d108c69c5d Add cppcheck test to GitHub actions
Found and fixed:

* Fix typos in Renesas demo
* Fix uninitialized variable reads
* Fix redundant condition
* Fix argument checks
* Fix some null ptr dereferences
* Fix ambiguous statement
2025-02-05 19:49:01 +00:00
gojimmypi fa23bf58df
Adjust Espressif wolfssl_echoserver example timehelper 2024-07-22 20:57:03 -07:00
gojimmypi 45a857b960 Update Espressif examples for Managed Component publish 2024-05-22 16:10:44 -07:00
Lealem Amedie a87fe3fce5 Updates to STM32Cube Pack 2024-05-02 16:33:43 -06:00