Commit Graph

2593 Commits (3abdc2235575a0822e67b92fddc8e5a562f60e76)

Author SHA1 Message Date
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
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
John Safranek 0b37d43239 Add x509 interop CI workflow
- Build PKIX-SSH and run wolfSSHd against the PKIX-SSH ssh/sftp
  clients using x509 user certs.
- Posts an issue if the test fails.
2026-05-28 08:48:13 -07:00
John Safranek 2ca89137a8 wolfsshd: gate debug logging behind -d flag
- Enable wolfSSH/wolfSSL debug logging only when -d is passed
- Disable both logging facilities during cleanup
2026-05-28 08:48:13 -07:00
Yosuke Shimizu 4ae8eee109 Add tests for DoUserAuthRequestRsa and DoUserAuthRequestRsaCert 2026-05-27 14:44:10 -07:00
Yosuke Shimizu b9dfa042bf Add scpDirDepth as depth guard and Add unit tests 2026-05-27 14:06:18 -07:00
Yosuke Shimizu 3b867e7313 Add unit tests and regress tests 2026-05-27 11:13:54 -07:00
John Safranek fd29780c8e DoProtoId: case-sensitive SSH- prefix match
- Per RFC 4253 4.2 use WSTRNCMP instead of WSTRNCASECMP for
  prefix and full-ID comparisons.
- Update client tests; add server test vectors expecting
  rejection of lowercase/mixed case.

Issue: F-2865
2026-05-21 11:42:43 -07:00
John Safranek be4aa445d5 DoNewKeys: reject NEWKEYS with non-empty payload
- Reject SSH_MSG_NEWKEYS when len != 0 per RFC 4253 7.3.
- Update wolfSSH_TestDoNewKeys to take buf/len/idx instead
  of assuming NULL/0, and add a non-zero len test case.

Issue: F-2079
2026-05-21 11:42:43 -07:00
John Safranek 63a63cf0fb CERTMAN_VerifyCerts_buffer: reject certsCount=0
- Without the guard, inner loops short-circuit and WS_SUCCESS
  is returned without any verification.
- Add test case covering the new and existing bad-arg paths.

Issue: F-409
2026-05-21 11:42:43 -07:00
John Safranek 80c3a0e61a wolfSSH_DoControlSeq: tighten escBuf bounds
- Guard escBuf[i] read when getArgs consumes all input without a command.
- Cap WMEMCPY against WOLFSSL_MAX_ESCBUF; escBufSz can exceed 16.
- Update escBufSz on WS_WANT_READ resume so CSI leftovers survive
  multi-fill reads.

Issue: F-250
2026-05-21 11:42:43 -07:00
John Safranek 1aac6d2f5a ClientFreeBuffers: zero secrets before free
- Zero private key and password buffers in both apps/wolfssh
  and examples client.
- Also zero keyboard-interactive response buffers in the
  example client.

Issue: F-249
2026-05-21 11:42:43 -07:00
John Safranek bcbb8e1ad7 DoKexInit: enforce zero KEXINIT reserved field
- Per RFC 4253 7.1 the reserved field is uint32 0, not a length
  prefix; reject non-zero values with WS_PARSE_E.
- Add regression test.

Issue: F-869
2026-05-21 11:42:43 -07:00
John Safranek 2dc337d34a ClientPublicKeyCheck: drop dead otherMatch guard
- otherMatch is set to 1 immediately above; guard always true.

Issue: F-3205
2026-05-21 11:42:43 -07:00
John Safranek b45aed9639 DoKexInit: set ret on host-key algo mismatch
- Replace mid-function return so end-of-function cleanup runs.

Issue: F-3204
2026-05-21 11:42:43 -07:00
John Safranek 541f0ac42a wolfsshd: unit test for CheckAuthKeysLine
- Expose CheckAuthKeysLine under WOLFSSHD_UNIT_TEST so tests can link it.
- Add test_CheckAuthKeysLine covering match, different key, and same-length
  key differing only in the last byte.
- Route the test Log() to stderr instead of an unused local buffer.

Issue: F-4107
2026-05-20 13:03:03 -07:00
John Safranek 5f4032f831 wolfssh: config user handling fix
1. Fix where an already allocated config->user is leaked.
2. Copy the argv user name into a heap buffer.

Issue: F-4102
2026-05-20 13:03:03 -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
Yosuke Shimizu 67496a385d Fix minor issues and Add unit tests 2026-05-18 14:02:52 -07:00
Paul Adelsbach c3640630b0 Allow empty passwords in sshd when PermitEmptyPasswords is set 2026-05-18 13:55:40 -07:00
Yosuke Shimizu 9d9fa2699d Refactor resource cleanup in windows path 2026-05-18 13:35:07 -07:00
John Safranek b583c0a225 Update wolfSSL version in ML-KEM and Thread tests
1. Update WOLFSSL_REF to v5.9.1-stable in the ML-KEM and single-thread
   tests (interop-mlkem.yml, singlethread-check.yml).
2. Drop kyber.yml; its coverage is a strict subset of interop-mlkem.yml.
   Fold its push and workflow_dispatch triggers into interop-mlkem.yml so
   ML-KEM still runs on master/release pushes and via manual dispatch.
3. Drop liboqs from the ML-KEM test. It isn't in configure.ac any more.
2026-05-18 11:04:51 -07:00
John Safranek 162dd7fbc6 Test ForceZero of secrets in free and DH KEX
- Add retain-on-free and size-tracking capture allocators to inspect
  freed buffers post-free.
- Verify SshResourceFree zeroes ssh->k, ssh->keys, and ssh->peerKeys
  before wolfSSH_free releases the struct.
- Verify KeyAgreeDh_client wipes ssh->handshake->x even when wc_DhAgree
  fails (ForceZero is unconditional).
- Verify KeyAgreeDh_server zeroes the MAX_KEX_KEY_SZ y_ptr allocation
  under WOLFSSH_SMALL_STACK via 0xCC poisoning.
- Expose KeyAgreeDh_client / KeyAgreeDh_server via wolfSSH_Test* hooks
  under WOLFSSH_TEST_INTERNAL.

Issues: F-2488, F-2492, F-2493, F-2875
2026-05-14 14:42:20 -07:00
Yosuke Shimizu fb1aa6daba Fix minor issues and Add test vectors 2026-05-14 09:36:43 -07:00
John Safranek 4b948e68cf sftp: NULL fName after free in all readdir variants
- Apply the prior FATFS fix across Nucleus, MQX, Windows,
  Zephyr, Harmony, and user-filesystem readdir paths.
- Prevents double-free crash when SFTPNAME_free runs on a
  name struct after readdir returns an error.
2026-05-13 16:25:46 -07:00
Jan Goldacker 0169eb4544 Fix SFTP_GetAttributes with fatfs for root 2026-05-13 15:32:25 -07:00
Jan Goldacker 0838634aab set fName to NULL after free
otherwise wolfSSH_SFTPNAME_free would crash afterwards
2026-05-13 15:31:30 -07:00
Jan Goldacker c68829901d stop on end-of-dir 2026-05-13 15:31:30 -07:00
John Safranek c2f40e0743 Convert FatFS date/time to Unix timestamp in SFTP
- Add SetAttrTime() helper to decode fdate/ftime into a Unix
  timestamp via mktime() and assigns it to atr->atime/mtime.
- Use it from both SFTP_GetAttributes() (was using raw fdate) and
  SFTP_GetAttributes_Handle() (was using raw ftime, losing the date).
2026-05-13 14:03:00 -07:00
Yosuke Shimizu 7d4fa32ce5 Fix minor issues and add unit test for IdentifyAsn1Key 2026-05-13 09:12:20 -07:00
John Safranek bd75cb4069 Pin expectMsgId after KEXDH_GEX_GROUP
- Set expectMsgId to MSGID_KEXDH_GEX_INIT so the server rejects
  any other KEX message at this stage (RFC 4419 sec 3).
- Reject NULL ssh->handshake in the entry check now that the
  success path dereferences it.

Issue: F-3668
2026-05-12 21:39:33 -07:00
John Safranek 822c09d0eb Fix integer overflow in ParseRFC6187 name length
- Reject name lengths that would overflow m when added
  to sizeof(word32), preventing OOB reads on later checks.

Issue: F-1277
2026-05-12 21:39:33 -07:00
John Safranek 11e407f7db Zero lastBlock buffers in GenerateKey
- Add ForceZero on lastBlock in both remainder paths
- Prevents leftover key-derivation material on the stack

Issue: F-2494
2026-05-12 21:39:33 -07:00
John Safranek 8854fd70a9 Zero key buffers on load failure
- ForceZero newKey before WFREE in DoPemKey/DoOpenSshKey,
  covering both locally-allocated and caller-supplied buffers.
- ForceZero PEM file buffer after read in wolfSSH_ReadKey_file
- Track newKeySz for caller-supplied buffer path

Issue: F-2885, F-3211, F-3212
2026-05-12 21:39:33 -07:00
Yosuke Shimizu 7d7d04dc70 Fix minor issues and Add unit test for wrong padded OpenSSH key 2026-05-12 13:14:56 -07:00
John Safranek 6e6995980e Fix integer underflow in SFTP RecvRead bound check
- Replace `strSz > maxSz - WOLFSSH_SFTP_HEADER - idx`
  with `strSz > WOLFSSH_MAX_SFTP_RW` to prevent unsigned
  wraparound and downstream WMALLOC size overflow.
- Apply to both POSIX and Windows variants.

Issue: F-3682
2026-05-11 22:28:44 -07:00
John Safranek 8231703875 Fix Ed25519 user-auth verify and add unit test
- Map ed25519 verify_msg_final errors to WS_CRYPTO_FAILED
  and status==0 to WS_ED25519_E (no longer overwritten)
- Expose DoUserAuthRequestEd25519 via test shim
- Add unit test covering valid and tampered signatures

Issue: F-3445
2026-05-11 22:28:44 -07:00