Commit Graph

6716 Commits

Author SHA1 Message Date
Rui Li
36116b814e auth: add option flag checks to public auth functions
Signed-off-by: Rui Li <ruili3422@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/792>
2026-04-09 14:40:56 +02:00
Manas Trivedi
08c7d67fac examples: replace atoi() with strtol() for safe number parsing
Replace all usages on atoi() in examples with strtol() and add validation
for the same.

Signed-off-by: Manas Trivedi <manas.trivedi.020@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-04-01 22:16:30 +02:00
ShreyasMahajann
51d715ec91 tests: extend ssh_options_getopt coverage for -q
Signed-off-by: Shreyas Mahajan <shreyasmahajan05@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-04-01 22:15:27 +02:00
ShreyasMahajann
152fc6633e options: add -q quiet flag to CLI getopt
Signed-off-by: Shreyas Mahajan <shreyasmahajan05@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-04-01 22:15:27 +02:00
ShreyasMahajann
b371214209 options: split out getopt cleanup
Signed-off-by: Shreyas Mahajan <shreyasmahajan05@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-04-01 22:15:26 +02:00
Jakub Jelen
e9c523e317 Use SSH_LOG_STRERROR where applicable
There were few leftovers of strerror() after the introduction of
ssh_strerror() some years back so this replaces the outstanding
cases with the portable and thread safe variant.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2026-04-01 14:40:47 +02:00
Jakub Jelen
13112fbdaa priv: Introduce SSH_LOG_STRERROR to avoid repetitive code
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2026-04-01 14:40:46 +02:00
Jakub Jelen
bacdcff7a0 sftpserver: Rename ssh_str_error to avoid confusion with ssh_strerror
Use the new name sftp_strerror() to better describe the reality.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2026-04-01 14:40:45 +02:00
Jakub Jelen
527d3b22a1 tests: Add missing newline at the end of file
This is breaking MacOS and FreeBSD builds.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2026-03-30 10:42:48 +02:00
Nuhiat-Arefin
93108dd026 config: add Match version support
Signed-off-by: Nuhiat-Arefin <nuhiatarefin@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-28 19:51:32 +01:00
Manas Trivedi
8dc59ae8ac sftp: set missing error codes in sftp_init failure paths
Ensure ssh and sftp error codes are consistently set across all
failure paths in sftp_init(). One branch previously returned
-1 leading to ambiguous error reporting.

Signed-off-by: Manas Trivedi <manas.trivedi.020@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-28 19:50:50 +01:00
Jakub Jelen
a00fbfb800 gcrypt: Remove unused bignum_free()
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2026-03-27 15:11:00 +01:00
Jakub Jelen
3360e6e1a3 dh-gex: Remove unused bignum context
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2026-03-27 15:10:58 +01:00
Jakub Jelen
d8ccda1d6f dh: Validate peer public key
The RFC 4253, Section 8 says that the

   Values of 'e' or 'f' that are not in the range [1, p-1] MUST NOT be
   sent or accepted by either side.  If this condition is violated, the
   key exchange fails.

Originally reported by Oren Yomtov

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2026-03-27 15:10:55 +01:00
Pavol Žáčik
44b186fa17 channels: Fail when receiving max packet size 0
Do this both for SSH2_MSG_CHANNEL_OPEN and for
SSH2_MSG_CHANNEL_OPEN_CONFIRMATION. Using the
max packet size 0 would lead to an infinite loop
in channel_write_common.

Originally reported by Rinku Das on on 23th February.
Independently reported by Yi Lin on 26th February and
Haruto Kimura on 22nd March.

We do not consider this as a security issue as connecting
to untrusted servers on the internet brings much worse
security consequences than hanging your clinet.

Signed-off-by: Pavol Žáčik <pzacik@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-27 09:26:17 +01:00
Robert Pana
66285b3ce4 [examples/ssh_client.c] Implemented -E log_file flag to redirect logs
Signed-off-by: Robert Pana <robertpana2015@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-25 11:26:44 +01:00
Robert Pana
c81c6d897f [examples/ssh_client.c] Reformatted ssh_client.c to match coding style
Signed-off-by: Robert Pana <robertpana2015@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-25 11:26:44 +01:00
Haythem666
28947fb58b doc: add missing doxygen documentation for SFTP handles
Add @brief documentation for:
- sftp_handle struct and sftp_handle_remove function

Contributes to #342

Signed-off-by: Haythem666 <haythem.farhat@epfl.ch>
2026-03-25 11:19:31 +01:00
Mingyuan Li
6fc95e8d43 examples: Enable libssh_scp and scp_download on Windows
Both examples only depend on getopt, which is now provided by the
bundled fallback. Include the getopt wrapper header and move them
out of the UNIX-only build guard.

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Mingyuan Li
715d79647d tests: Add dedicated unit tests for getopt abstraction
Add torture_getopt.c with 11 test cases covering basic option parsing,
arguments, optional arguments, unknown options, missing arguments,
BADARG colon behavior, double-dash termination, combined options,
optind advancement, reset behavior, and no-options edge case.
Registered in the unit test CMakeLists.txt.

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Mingyuan Li
90169c598e tests: Enable getopt tests on all platforms
Remove _MSC_VER guards from torture_options_getopt and
torture_options_getopt_o_option so they run unconditionally,
now that a bundled getopt fallback is available.

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Mingyuan Li
950f796aca options: Enable ssh_options_getopt on all platforms
Include the new platform-independent getopt wrapper header and remove
the #ifdef _MSC_VER guard that disabled ssh_options_getopt() on MSVC.
The function is now compiled unconditionally on all platforms.

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Mingyuan Li
31a882016e options: Add platform-independent getopt wrapper header
Add include/libssh/getopt.h that transparently includes the system
<getopt.h> when available, or declares the bundled fallback interface
otherwise.

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Mingyuan Li
d2f7994140 options: Add bundled getopt implementation from FreeBSD
Add a portable getopt() fallback for platforms that lack it (e.g. MSVC).
Based on FreeBSD lib/libc/stdlib/getopt.c (BSD-3-Clause), adapted by
replacing FreeBSD internal headers and _getprogname() with standard C
equivalents. Only compiled when HAVE_GETOPT is not defined.

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Mingyuan Li
9a2f23ee30 cmake: Add detection for getopt and getopt.h
Add CMake checks for the getopt function and getopt.h header to
prepare for a bundled getopt fallback on platforms that lack it
(e.g. MSVC).

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Jakub Jelen
729a44e121 ci: Skip macos jobs on forks
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2026-03-24 10:58:22 +01:00
Jakub Jelen
051ac812db examples: Add warning about example code
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2026-03-24 10:58:11 +01:00
Haythem666
01772c4f79 pki: add ssh_key_type_and_hash_from_signature_name()
Merge ssh_key_type_from_signature_name() and ssh_key_hash_from_name()
into a single function ssh_key_type_and_hash_from_signature_name() to:

- Avoid double string comparisons on the same algorithm name
- Return SSH_ERROR on unknown/NULL input instead of silently returning SSH_DIGEST_AUTO
- Use strlen() before strcmp() to short-circuit string comparisons.

Handle GSSAPI "null" hostkey case in wrapper.c.
Add unit tests for the new function.

Fixes: https://gitlab.com/libssh/libssh-mirror/-/issues/355
Signed-off-by: Haythem666 <haythem.farhat@epfl.ch>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 10:50:39 +01:00
Manas Trivedi
9f7c596ca5 tests: add coverage for NULL session in ssh_channel_is_open
Signed-off-by: Manas Trivedi <manas.trivedi.020@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 10:15:06 +01:00
Manas Trivedi
34bbb48561 channels: add NULL session check in ssh_channel_is_open
Prevent potential NULL pointer dereference when accessing
channel->session->alive.

Signed-off-by: Manas Trivedi <manas.trivedi.020@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 10:15:05 +01:00
Jakub Jelen
f060583d6f tests: Generate coverage for fuzzing tests
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-19 22:16:17 +01:00
Bulitha Kawushika De Zoysa
a05b2b76be tests: initialize sftp test pointers to NULL
Signed-off-by: Bulitha Kawushika De Zoysa <bulithakaushika99@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-19 17:06:05 +01:00
Bulitha Kawushika De Zoysa
c9f34ac55f sftp: Add support for the users-groups-by-id@openssh.com OpenSSH extension on the server side.
Signed-off-by: Bulitha Kawushika De Zoysa <bulithakaushika99@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-19 17:06:04 +01:00
Ahmed hossam
bc24bba176 docs: Add documentation for test_server functions
Signed-off-by: Ahmed hossam <ahmed.hossambahig@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-19 17:03:42 +01:00
Colin Baumgarten
3154a4ab8d sftpserver: Fix client messages being ignored if sent at a high rate
When using OpenSSH scp to read files larger than a few hundred
kilobytes, downloads stall and never finish. A workaround is to
pass -Xnrequests=1 to scp, which will cause scp to only do a
single concurrent SFTP read request at a time.

The cause for the problem is that if SFTP client messages are
received at a high rate, sftp_channel_default_data_callback() will
potentially be called with multiple messages in the incoming data
buffer, but only the first message will be extracted and handled.

So add a loop to extract as many SFTP client messages as available
from the incoming data buffer.

Signed-off-by: Colin Baumgarten <colin.baumgarten@hubersuhner.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-17 12:01:15 +01:00
Sudharshan Hegde
9478de8082 doc: add missing Doxygen comments and fix documentation style
- Add missing @brief, @param, and @return docs across src/ and include/
- Fix blank lines between doc comments and function definitions
- Move function docs from headers to corresponding .c files
- Use named constants (SSH_OK, SSH_ERROR, SSH_TIMEOUT_INFINITE) in docs
- Fix parameter ordering in error.c, buffer.c, log.c docs
- Place #ifdef-guarded docs inside their respective #ifdef blocks

Signed-off-by: Sudharshan Hegde <sudharshanhegde68@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-17 11:46:11 +01:00
Shreyas Mahajan
e927820082 Make headers self-contained and include-order independent
Signed-off-by: Shreyas Mahajan <shreyasmahajan05@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 19:07:16 +01:00
ShreyasMahajann
67950c620d misc: Reformat struct ssh_list members to use 4-space indentation
Signed-off-by: Shreyas Mahajan <shreyasmahajan05@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 19:07:16 +01:00
Jakub Jelen
31ea4d1213 tests: Negative tests for ssh_pki_ctx_options_set
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 19:04:57 +01:00
Jakub Jelen
29c503ed7c tests: Remove needless reset to NULL
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 19:04:57 +01:00
Jakub Jelen
b1a28f7987 tests: Use the new ssh_pki_generate_key() where possible
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 19:04:57 +01:00
Jakub Jelen
616d165f14 pki_context: Document 0 is valid for bit size (default)
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 19:04:57 +01:00
Jakub Jelen
b9ecb9283e pki_context: Allow using minimal RSA key size in new API
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 19:04:57 +01:00
Jakub Jelen
c38edb59f2 examples: Avoid using deprecated ssh_pki_generate
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 19:04:57 +01:00
Jakub Jelen
def7a679f8 examples: Use separate variable for exit code
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 19:04:57 +01:00
Jakub Jelen
6f671919ad examples: Use separate variable for fd
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 19:04:57 +01:00
Jakub Jelen
45b1d85fb0 fuzz: Add debugging hints to readme
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 18:44:55 +01:00
Jakub Jelen
e7f4cc9580 knownhosts: Avoid possible memory leak on failed malloc
Thanks oss-fuzz

https://issues.oss-fuzz.com/issues/489362256

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 18:44:55 +01:00
Jakub Jelen
5479b276b2 Use ARRAY_SIZE systematically
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 18:25:22 +01:00
Jakub Jelen
5d7fbcf22a Fix line endings in sftp_attr_fuzzer
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 18:25:22 +01:00