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. |
||
|---|---|---|
| .. | ||
| wolfssh.X | ||
| README.md | ||
| include.am | ||
| user_settings.h | ||
| wolfssh.c | ||
README.md
wolfSSH MPLABX
This is example project to create a wolfSSH library and example code for adding a wolfSSH echoserver to a MPLABX project.
Tested on a ATSAMV71Q21B with MPLABX version 6.20.
Building wolfSSH library
The library project is located at ide/mplabx/wolfssh.X
- First open wolfssh.X with MPLABX IDE then click on "CM" content manager and import the ide/mplabx/wolfssh.X/mcc-manifest-generated-success.yml file.
- Click apply.
- Next click "MCC" and "generate".
- To build from the command line, do the following after the XC32 toolchain has been installed.
cd ide/mplabx/wolfssh.X
make
- To build using the IDE open the project ide/mplabx/wolfssh.X and click build.
This will produce a wolfssh.X.a library in the directory ide/mplabx/wolfssh.X/dist/default/production/wolfssh.X.a
The application and wolfSSL must be built with the same user_settings.h as the wolfSSH library was built with! Differences in macro's defined for configuration will cause undefined behavior and potential crashes.
Building an example app
- Adjust the "Preprocessor macros" to include WOLFSSL_USER_SETTINGS and add an include path to ide/mplabx/user_settings.h.
- Remove the generated app.c from Source File
- Link to the wolfssh.X.a library. Properties->Libraries->Add Library/Object File...
- Right click on the project and add existing item. Select ide/mplabx/wolfssh.c
- Increase the heap size to 200,000 by right clicking on the project, selecting "Properties"->"x32-ld"
Notes:
For the current project this was tested with the heap and stack set to 200,000 each. This was not trimed to see the minumum possible heap and stack usage yet. The TX buffer size used was set to 1024. The example was developed with wolfssh version 1.4.20.
After building and flashing the board a wolfSSH echoserver will be open on port
22 which can be connected to by using the example client bundled with wolfSSH.
./examples/client/client -u jill -P upthehill -h 192.168.1.120 -p 22