1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-29 13:01:14 +03:00

3061 Commits

Author SHA1 Message Date
30203f167b docs: improve man page for libssh2_channel_request_auth_agent
Mention that the callback is needed for full functionality.

This is inspired/copied from the existing X11 man pages.

Closes #1503
2025-07-22 14:13:01 +02:00
30befffe04 kex: fix DH-GEX-sha256 bignum initialization
In `kex_method_diffie_hellman_group_exchange_sha256_key_exchange`,
`p` and `g` are later initialized with `_libssh2_bn_from_bin`, so they
should be initially created using `_libssh2_bn_init_from_bin` rather
than `_libssh2_bn_init`, as is done in
`kex_method_diffie_hellman_group_exchange_sha1_key_exchange`.

Fixing memory leaks when using the libgcrypt backend.

Follow-up to 09c5e59933
Ref: https://web.archive.org/web/trac.libssh2.org/ticket/168

Closes #1599
2025-07-21 21:26:32 +02:00
cea8783ed8 Fix small leak in base64_encode() with empty data #1627 (#1630)
Fix small memory leak when trying to encode base64 data with no data.

Credit:
Liu Xing Yu
2025-07-21 11:48:25 -07:00
aa4c7b5b96 Handle malformed comments in known_hosts parsing #1628 (#1629)
Notes:
Handle malformed comment in known_hosts parsing to avoid buffer overflow.

Credit:
Liu Xing Yu
2025-07-21 11:46:58 -07:00
992dafbc7f scp: fix NULL dereference in path arg of send/recv (#1625)
Notes:
* Error handling if path for scp is NULL

Reported-by:
Liu Xing Yu

Credit:
Ryan Kelley
2025-07-21 10:02:42 -07:00
f46422223f libgcrypt: add support for RSA SHA-256/SHA-512
Closes #1600
2025-07-21 02:01:02 +02:00
ad8e924583 cmake: fixup Libs.private lib order
- Reworking the `Libs.private` collector logic for INTERFACE targets,
  broke the original lib order. Fix it by going back a single loop
  to retain order.
  Follow-up to df0563a857 #1535

- Implement the above with one change: move implicit CMake libs
  to the end of the list (was: the beginning).
  I expect these to be libs that any custom libs may depend on,
  like system libs, C runtime, compiler runtime lib.
  Follow-up to c87f129630 #1466

Closes #1623
2025-07-14 01:34:40 +02:00
e1da7b2cb8 cmake: de-duplicate LIBSSH2_PC_LIBS_PRIVATE more carefully
`LIBSSH2_PC_LIBS_PRIVATE` ends up in `Libs.private` in `libssh2.pc`.

The order and duplication may be significant for linkers that rely on
strict lib order and unable to resolve symbols without it. Such linker
is binutils `ld`. De-duplication can break it.

As of now there is no purposeful duplication in libs in libssh2, thus
the de-duplication most likely did not affect actual builds.

It was originally introduced to avoid a repeat `-lz` (with
a zlib-enabled OpenSSL or wolfSSL build.) To keep this feature, this
patch makes sure to only delete duplicates that are next to each other.

Follow-up to 6464301820 #1131

Closes #1621
2025-07-14 01:34:40 +02:00
4e08dac73d cmake: tidy up add_feature_info() formatting
Closes #1622
2025-07-13 21:24:10 +02:00
dfe7aca9b0 ci/GHA: allow more time for 'CM integration' job
Sometime 5 minutes wasn't enough for the Windows platform.

Ref: https://github.com/libssh2/libssh2/actions/runs/16251541971/job/45881908411?pr=1622
Ref: https://github.com/libssh2/libssh2/actions/runs/15478243283/job/43578759660?pr=1600
2025-07-13 19:25:17 +02:00
300da4e2ff cmake: pre-fill more, simplify control flow
Closes #1620
2025-07-13 14:34:17 +02:00
22784a56e2 cmake: drop redundant -lws2_32 meant for libssh2.pc
The `libssh2.pc` generator logic automatically adds `-lws2_32` while
parsing `LIBSSH2_LIBS`, which contains this lib already. Then discard
the duplicate.

This patch introduces a change in the position of `ws2_32` within
the lib list advertised via `libssh2.pc` for static builds.

This order might in cases by significant, but:

- libssh2 no longer links against `libssl`, which was the library
  also referencing `ws2_32` and breaking picky binutils `ld` linker
  when not passed in strict dependency order.
  Ref: c84745e34e #1128

- since switching to INTERFACE targets, cmake messes up the lib order
  anyway, adding `OpenSSL:Crypto` last, instead of `ws2_32`. This did
  not seem to cause an issue so far.
  Ref: df0563a857 #1535

For these reasons it seems unlikely this position change could break
Windows OpenSSL static gcc/ld builds relying on `libssh2.pc` for their
lib list. It least no more than it was before this patch.

Turns out these theories don't stand in practice and the order is broken
possibly by introducing INTERFACE targets, with or without this patch.
`libcrypto` (tested with LibreSSL) is in fact depending on `ws2_32`, and
the `bcrypt` dependency is also causing breakage with picky binutils ld.
I may try addressing it in a separate PR.

Ref: 33b6d5f89d #827
Ref: 31fb8860db #811

Closes #1619
2025-07-13 14:34:17 +02:00
e62a72b22f ci/GHA: move CI checks to Linux, other CI tweaks
Also:
- merge CI check and shellcheck jobs into a single one.
  To share the same shellcheck version and less overhead.
- use `set -eu` in more scripts.
- make sure CI scripts run from any cwd.
  To make it easy to run them on local machine.
- minor tidy-ups.

Closes #1618
2025-07-13 11:21:39 +02:00
98cd10d1c1 INSTALL_CMAKE: fixes build result directories
In the CMake installation instructions, the resulting static library,
examples and tests are actually found in `bld`, not in `bin`.

Closes #1617
2025-07-13 11:21:39 +02:00
723b701715 build: tidy up comments on Makefile.inc variables
Closes #1615
2025-07-02 12:02:09 +02:00
339ea0f61f GHA: fix new zizmor warnings
Also:
- fix old yamllint warnings.
- make quoting more consistent.
- drop stray step name: "checkout".
- merge REUSE workflow into main CI one.

Closes #1614
2025-07-02 11:03:41 +02:00
694b9d964b cmake: add linter, fix issues
Ref: https://cmake-format.readthedocs.io/en/latest/cmake-lint.html
Ref: https://github.com/cheshirekow/cmake_format

Closes #1610
2025-06-11 07:09:10 +02:00
d7cf63bb05 GHA: fix zizmor and shellcheck warnings, verify in CI
Closes #1609
2025-06-09 16:40:26 +02:00
d8ae40bad0 Fixes when server/client uses encryption method with integrated MAC and the other doesn't (#1582)
Notes:
Connection fails when server/client uses one encryption method with integrated MAC and one without.

Credit:
Christian Ghisler
2025-05-21 13:38:11 -07:00
9136cc763b agent: fix byte amount copied for method in libssh2_agent_sign
It looks like the incorrect length is used to copy the public key method
into the session in `libssh2_agent_sign()` and while the public key type
at the start of a identity blob is often identical to the public key
method it might not always be such as when method is `rsa-sha2-256` for
`ssh-rsa` keys.

Closes #1603
2025-05-17 23:46:45 +02:00
201c368aa1 ci/GHA: avoid touching GITHUB_ENV
To make configuration simpler, easier to understand and possibly more
secure.

Closes #1598
2025-05-08 23:50:28 +02:00
f522f10c2f cmake: test integration with old cmake (v3.11.4 2018-03-28)
It was an exercise to run old cmake versions in CI and in the test suite.

It also revealed that 3.7.2 2017-01-13 is too old to consume libssh2 via
`find_package()` due to:
```
CMake Error at bld-libssh2/_pkg/lib/cmake/libssh2/libssh2-config.cmake:35 (add_library):
  add_library cannot create ALIAS target "libssh2::libssh2" because target
  "libssh2::libssh2_shared" is IMPORTED.
Call Stack (most recent call first):
  CMakeLists.txt:27 (find_package)
```
The mitigation for this issue requires 3.11.

Also:
- rename a few existing envs to use the `TEST_` prefix.
- make the `find_package` test provider stage verbose.

Closes #1591
2025-05-08 15:05:07 +02:00
72982d1589 build: sync up picky warnings with curl, fix fallouts
- cmake: sync `-ftree-vrp` behavior with autotools.
- build: enable `-Wjump-misses-init` for GCC 4.5+.
  Credits-to: Marcel Raad
- packet: fix `-Wjump-misses-init` warnings.
  ```
  src/packet.c: In function ‘_libssh2_packet_add’:
  src/packet.c:671:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:920:31: note: ‘want_reply’ declared here
  src/packet.c:671:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:919:26: note: ‘len’ declared here
  src/packet.c:669:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:1121:31: note: ‘want_reply’ declared here
  src/packet.c:669:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:1120:26: note: ‘len’ declared here
  src/packet.c:669:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:1119:26: note: ‘channel’ declared here
  ```
- build: enable gcc-12/13+, clang-10+ picky warnings
- acinclude.m4: sync formatting/comments with curl.
- autotools: fix `-Wtrampolines` picky warning for gcc 4.x versions.
  Follow-up to 854cfa8292 #1524
- cmake: enable `-Wall` for MSVC when `PICKY_COMPILER=ON`.
- MSVC: fix `-Wall` warnings.
  Seen on VS2015. Not seen on VS2022. Unknown for other versions.
  ```
  tests\test_simple.c(60): warning C4777: 'fprintf' : format string '%d' requires an argument of type 'int', but variadic argument 1 has type 'std::size_t'
  tests\test_simple.c(60): warning C4777: 'fprintf' : format string '%.*s' requires an argument of type 'int', but variadic argument 2 has type 'std::size_t'
  ```
- mbedtls: stop silencing warnings in 3rd-party header.
  Follow-up to a3aa6b4ca8 #1525
- cmake: stop deleting `-W<n>` from `CMAKE_C_FLAGS` (MSVC)
  1. `CMAKE_C_FLAGS` may apply to other projects, and deleting/altering it
     may be unexpected.
  2. We pass `-W4`/`-Wall` internally now, which do override custom
     `-W<n>` options as tested with VS2008 and newer VS generators.

Closes #1588
2025-05-07 23:24:41 +02:00
62ad6a84ce cmake: honor individual picky option overrides found in CMAKE_C_FLAGS
Also to sync up with similar `./configure` feature via
`CURL_ADD_COMPILER_WARNINGS()`.

Example: `-DCMAKE_C_FLAGS=-Wno-xor-used-as-pow`

It may be useful as a workaround if a specific build combination hits
a picky warning within libssh2's source code. If such happens, we do
appreciate a report to fix it in libssh2 itself.

Closes #1590
2025-05-07 23:22:16 +02:00
f89406b50c Dockerfile: switch to Debian stable
To avoid failing tests in job
'linux (clang, i386, Libgcrypt, autotools, ON, --disable-static)'.
Same job with x86_64 or OpenSSL did pass without issues.

Example:
https://github.com/libssh2/libssh2/actions/runs/14703383105/job/41758988183?pr=1588
```
libssh2_session_handshake failed (-5): Unable to exchange encryption keys
```

Bug: https://github.com/libssh2/libssh2/pull/1591#issuecomment-2844417405
Fix-suggested-by: Jacob Barthelmeh
Fixes #1594
Closes #1595
2025-05-07 01:04:57 +02:00
4e78006c2b cmake: fix copy-paste typo in integration tests for old cmake
Follow-up to 77df767784 #1589

Closes #1592
2025-04-28 15:04:28 +02:00
77df767784 cmake: extend integration tests
- ci/GHA: add cmake integration tests for Windows.
- ci/GHA: test `add_subdirectory` with Libgcrypt.
- make them run faster with prefill, unity, Ninja, omitting curl tool.
- add support for any build configuration.
- add old-cmake support with auto-detection.
- auto-detect Ninja.
- run consumer test apps to see if they work.
  Also show the cryptography backend.
- add support for Windows.
- make it more verbose.
- re-add `ExternalProject` cmake consumer test. It's broken.
- tidy up terminology.

Cherry-picked from #1581

Closes #1589
2025-04-27 13:46:30 +02:00
ac80041852 cmake: IMPORTED target improvements and fixes
- fix `add_subdirectory` builds for old CMake versions.
- libssh2-config.cmake: fix to set CMP0099 for CMake 3.17+ only.
- libssh2-config.cmake: generalize code to support any number of deps.
  (mainly to sync with curl.)
- libssh2-config.cmake: bind dependencies to the static libssh2 only.

Follow-up to a0d8529b08 #1571
Follow-up to df0563a857 #1535

Closes #1581
2025-04-27 13:46:30 +02:00
a8dd5090d6 cmake: avoid 'target is imported but not globally visible' when consuming libcurl with old cmake
Fixes:
```
CMake Error at bld-libssh2/_pkg/lib/cmake/libssh2/libssh2-config.cmake:35 (add_library):
  add_library cannot create ALIAS target "libssh2::libssh2" because target
  "libssh2::libssh2_shared" is imported but not globally visible.
Call Stack (most recent call first):
  CMakeLists.txt:27 (find_package)

CMake Error at bld-libssh2/_pkg/lib/cmake/libssh2/libssh2-config.cmake:40 (add_library):
  add_library cannot create ALIAS target "Libssh2::libssh2" because target
  "libssh2::libssh2_shared" is imported but not globally visible.
Call Stack (most recent call first):
  CMakeLists.txt:27 (find_package)
```

tests/cmake reproducer (requires #1581):
```shell
export CMAKE_CONSUMER=/path/to/CMake-3.12.0/bin/cmake
./test.sh find_package
```

I don't understand what this error says, why it happens in certain CMake
versions, and why a workaround is necessary for what seems like
a standard export/consume configuration. This patch is based on internet
suggestions and other projects ending up with this workaround.

Ref: https://github.com/curl/curl/pull/16973
Ref: https://github.com/curl/curl/pull/17140
Cherry-picked from #1581
Closes #1587
2025-04-25 16:44:55 +02:00
117b02b442 cmake: fix libssh2-config.cmake for cmake <3.15
Replace `list(PREPEND ...)` for compatibility with CMake < 3.15.

Ref: https://cmake.org/cmake/help/latest/command/list.html#prepend

Follow-up to 82b09f9b3a #1322
Cherry-picked from #1581
Closes #1586
2025-04-25 16:44:55 +02:00
3ae5ae3248 cmake: whitespace in Find modules [ci skip]
Cherry-picked from #1581
2025-04-25 15:04:58 +02:00
09c948c93c ci/GHA: use more Ninja
It's installed now on all GHA runners by default.

Also drop explicit installs.

Closes #1585
2025-04-25 14:59:59 +02:00
01b8d3565e ci/GHA: skip updating man-db for faster installs (Ubuntu)
To save 5+ seconds per CI job.

Also drop `/etc/apt/sources.list.d/microsoft-prod.list`.

Closes #1584
2025-04-25 14:37:00 +02:00
6af8a7ca7f cmake: use CMAKE_COMPILE_WARNING_AS_ERROR if available
It's available in CMake >= 3.24.

Ref: https://cmake.org/cmake/help/latest/variable/CMAKE_COMPILE_WARNING_AS_ERROR.html

Closes #1583
2025-04-25 14:37:00 +02:00
7b4f821e7a cmake: fix declspec for MSVC consuming static libssh2
Ref, same fix in curl (2018-08-15):
ab66a80488
https://github.com/curl/curl/issues/2817
https://github.com/curl/curl/pull/2823

Reported-by: geral-victor on github
Fixes #1578
Closes #1579
2025-04-22 08:56:11 +02:00
8a871d0b40 cmake: tidy-up ENABLE_WERROR logic
Tidy up the way we handle options not to be passed to feature checks,
and make sure to show them in the configure log.

Also:
- drop redundant and obsolete compiler check.
- drop redundant parenthesis.

Closes #1576
2025-04-15 16:18:44 +02:00
a8e4456b05 cmake: avoid passing options via CMAKE_*_FLAGS
- replace `CMAKE_C_FLAGS*` and `CMAKE_CXX_FLAGS` with `COMPILE_OPTIONS`.
- replace `CMAKE_SHARED_LINKER_FLAGS_DEBUG` with
  `LINK_OPTIONS`/`LINK_FLAGS`.
- make it explicit to pass these C flags to feature checks.
- enable `-pedantic-errors` picky option for GCC with CMake <3.23.
- drop redundant condition when stripping existing MSVC `/Wn` options.

CMake passes `CMAKE_C_FLAGS` to targets, feature checks and raw
`try_compile()` calls. With `COMPILE_OPTIONS`, this is limited to
targets, and we must explicitly pass them to feature checks. This
makes the build logic clearer, and offers more control. It also
reduces log noise by omitting these options from linker commands,
and from `CMAKE_C_FLAGS` dumps in feature checks.

Closes #1575
2025-04-15 01:47:31 +02:00
a0d8529b08 cmake: fix target interfaces for old CMake versions
- drop `VERSION` target property for cmake <3.19 compatibility
  ```
  CMake Error at CMake/Find*.cmake:90 (set_target_properties):
    INTERFACE_LIBRARY targets may only have whitelisted properties.
    The property "VERSION" is not allowed.
  ```
- move custom target property to the `INTERFACE_` namespace
  for cmake <3.19 compatibility. (To avoid same error as above)
- fix forwarding multiple `CFLAGS`, when detected via `pkg-config`.
- restore support for `-framework` and raw libs when processing
  the internal lib list for generating `libssh2.pc`. For good measure,
  at the moment libssh2 doesn't depend on a Framework.
- limit `libssh2_dumptargetprops()` to cmake 3.19+. It doesn't work with
  older versions.

Issues found while applying this change to curl. They did not surface in
libssh2 CI.

Follow-up to df0563a857 #1535

Closes #1571
2025-04-14 02:13:37 +02:00
71179930e1 cmake: use VERSION_GREATER_EQUAL
Available since 3.7, which is the minimum required for libssh2:
https://cmake.org/cmake/help/latest/command/if.html#version-greater-equal

Closes #1573
2025-04-10 08:59:47 +02:00
ea56904aef tests: improve SSHD default value (fixup)
Fix typo in the commit improving `SSHD` default.

Regression from fb12d87e0e #1563

Reported-by: Paul Howarth
Bug: https://github.com/libssh2/libssh2/pull/1563#issuecomment-2753676646

Closes #1568
2025-03-26 11:48:03 +01:00
1323e17ba9 ci/GHA: move Cygwin to drive D: for install speed
Save 30-90s per job in the Cygwin install step.

Closes #1567
2025-03-24 15:26:03 +01:00
fb7ea5d7e1 ci/GHA: add clang-tidy jobs for Linux and Windows
With their supported crypto backends.

Cherry-picked from #1561

Closes #1566
2025-03-24 15:05:31 +01:00
a1a28ac943 clang-tidy: fix and/or silence issues found, and more
- kex: drop unused assigment.
- knownhost: error when salt is NULL.
- mbedtls: avoid unnecessary inline assigments, that were ignored for
  the second block and replaceable with a `ret = 0` initialization for
  the first one.
- mbedtls: fix ignoring an API failure and ending up calling
  `mbedtls_rsa_check_privkey()` unconditionally.
- misc: initialize datalen on error in `_libssh2_base64_decode()`.
- openssl: drop unused assigments.
- openssl: fix unused static function.
- packet: avoid NULL deref.
- packet: avoid NULL in `memcpy` src.
- publickey: optimize struct layout to avoid padding.
- sftp: replace ignored `rc` error assigment with `_libssh2_error()` call.
- transport: fix potential NULL ptr dereferences.
- transport: silence uninitialized value warnings.
- userauth: drop unused assigment.
- userauth: possible use of unitialized pointer.
- userauth: replace `rewind()` with `fseek()`.
  `rewind()` returns an error condition in `errno`. `errno` is
  problematic and reduces portability. Use `fseek()` to avoid it.
- userauth: replace potential NULL deref by returning error from
  `sign_frommemory()`. Possible false positive. `rc` should be set
  upstream if the callback is NULL.
- userauth: replace potential NULL deref by returning error from
  `sign_fromfile()`. clang-tidy did not warn about this one, but
  let's match `sign_frommemory()` anyway.
- wincng: fix potentially unused macros.
- wincng: make sure bignum is not NULL before use.

tests:
- openssh_fixture: drop unused assignment.
- session_fixture: exit if `username` not set, to avoid `strlen(NULL)`.
- session_fixture: replace `rewind()` with `fseek()`.
  `rewind()` returns an error condition in `errno`. `errno` is
  problematic and reduces portability. Use `fseek()` to avoid it.
- test_read: exit if `username` not set, to avoid `strlen(NULL)`.

examples:
- scp_write_nonblock: fix file handle leak.
- sftp_write_nonblock: file handle leak on error.
- sftp_write_sliding: file handle leak on error.
- ssh2_agent_forwarding: fix unused error codes.

Details in the subcommits under the PR.

Thanks-to: Michael Buckley
Thanks-to: Will Cosgrove

Closes #1561
2025-03-24 14:37:08 +01:00
15752e5f0b ci/GHA: sync linux-mingw workflow with curl
To prepare for the addition of a clang-tidy job for Windows.

Cherry-picked from #1561
2025-03-24 14:06:28 +01:00
64fafc78b0 transport: fix formatting
Cherry-picked from #1561
2025-03-24 14:06:28 +01:00
6635880497 cmake: add clang-tidy support via LIBSSH2_CLANG_TIDY=ON
Cherry-picked from #1561
2025-03-24 14:06:24 +01:00
e0681cdba9 build: drop crypto.c umbrella source
Instead build all crypto backend sources always, and exclude inactive
ones with guards.

To play better with code checkers and compilers that are blind to
included C sources, e.g. clang with certain compiler warnings and
clang-tidy.

We continue to include `blowfish.c`.

Follow-up to 4f0f4bff5a #941
Cherry-picked from #1561
2025-03-24 14:04:07 +01:00
ddc4cf34da agent: merge agent_win.c into the main source
To play better with code checkers and compilers that are blind to
included C sources, e.g. clang with certain compiler warnings and
clang-tidy.

Follow-up to 4f0f4bff5a #941
Cherry-picked from #1561
2025-03-24 14:03:56 +01:00
cf15fdd29f tests: use setfacl if available
Closes #1565
2025-03-24 10:07:27 +01:00
902fc9574d cmake: replace deprecated CMAKE_COMPILER_IS_GNUCC
Closes #1564
2025-03-23 21:13:26 +01:00