1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-10-24 03:48:58 +03:00
Commit Graph

3979 Commits

Author SHA1 Message Date
Viktor Szakats
ca8864db09 GHA: switch a Linux job (with tests) to arm64
Follow-up to 667f7cac77
Follow-up to 7d9d0f8db5 #2606

Closes #2607
2026-09-12 22:50:21 +02:00
Viktor Szakats
667f7cac77 GHA/openssh_server: try with qemu-user
Ref: https://packages.ubuntu.com/resolute/qemu-user

Follow-up to 7d9d0f8db5 #2606
2026-09-12 19:51:28 +02:00
Viktor Szakats
7d9d0f8db5 openssh_server: build container for arm64 also, fix Dockerfile for trixie
To enable testing on arm64 Linux and possibly also on macOS, and
possibly possibly on arm64 Windows.

Also:
- switch to debian:testing to trigger a container rebuild.
- Dockerfile: install `adduser` explicitly. Required for debian:forky.
- Dockerfile: stop installing suggested/recommended packages.

Ref: https://github.com/docker/build-push-action

Closes #2606
2026-09-12 19:24:57 +02:00
Viktor Szakats
b937ded9f0 tests: replace DSA with RSA key for fail test
To use a key type that is:
- supported by all backends.
- can be generated with the most recent `ssh-keygen` version.
- here to stay for the foreseeable future.
  (DSA is scheduled for removal from the libssh2 codebase.)

Cherry-picked from #2598

Closes #2604
2026-09-12 01:36:44 +02:00
Viktor Szakats
5bfa574460 tests: drop WinCNG retry workarounds
Should no longer be necessary after fixing the root cause.
(Though we do not run these tests in CI at the moment.)

Ref: #804
Follow-up to f216bbe3aa #2583
Follow-up to bc120a343b #1023

Closes #2603
2026-09-12 00:47:41 +02:00
Viktor Szakats
917f38bfe3 GHA: use cache-mode
Limit cache access to the minimum required.

Refs:
https://github.blog/changelog/2026-09-10-control-github-actions-cache-access-with-cache-mode/
https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#cache-mode
https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching#bypassing-the-default-untrusted-trigger-cache-restriction

Closes #2601
2026-09-12 00:27:39 +02:00
Viktor Szakats
1a1e62c548 GHA: drop redundant shellcheck expression filter
GHA expressions are no longer used and no longer allowed in GHA scripts.

Follow-up to d7cf63bb05 #1609

Closes #2602
2026-09-11 23:36:20 +02:00
Viktor Szakats
3f26c15b2f wincng: fix builds with RSA and DSA disabled
Fixing:
```
x86_64-w64-mingw32-ld: src/CMakeFiles/libssh2_shared.dir/Unity/unity_0_c.c.obj: in function `userauth_hostbased_fromfile':
src/userauth.c:923:(.text+0x34c29): undefined reference to `ssh2_pub_privkey'
x86_64-w64-mingw32-ld: src/CMakeFiles/libssh2_shared.dir/Unity/unity_0_c.c.obj: in function `userauth_publickey':
src/userauth.c:1745:(.text+0x37171): undefined reference to `ssh2_pub_privkey'
collect2: error: ld returned 1 exit status
```

Note: This fixes the build, but leaves `ssh2_pub_privkey()` a no-op, because it's not implemented for ECDSA.

Closes #2600
2026-09-11 20:36:00 +02:00
Viktor Szakats
65a9333204 docs: update list of key types where necessary
Closes #2599
2026-09-11 18:46:57 +02:00
Viktor Szakats
bb8e0957b8 GHA: test WinCNG SCP/SFTP via curl runtests
The WinCNG backend has been missing runtime tests for a while. To
restore some level of testing, this PR make use of curl's regression
test suite (`runtests`) to run SCP/SFTP-specific tests with the
master/PR libssh2 revision at hand. Some tests need to be disabled when
using the built-in Windows OpenSSH server.

The current CI jobs reproduce the long-running WinCNG flaky failure
reported in #804 reliability.

Note, if these CI jobs make libssh2 CI a pain to use, they will be
removed. This has a reasonably fair chance to happen, based on the
experience with curl CI with Windows.

Also:
- test both ECDH and non-ECDH builds.
- test build on x64 and ARM64.
- test with both Windows built-in OpenSSH port and MSYS2's sshd.
- enable debug logging in libssh2 while running the tests.
- for extra stress, run each of the 56-57 tests 6 times.
  This may be lowered in a future commit to avoid flakiness and reduce
  CI load and job times.

Caveats:
- as seen in curl CI, runtests may result in hangs due to broken pipes
  and error 2304 for undiscovered reasons.
  Discussion: https://github.com/curl/curl/discussions/14854
- MSBuild has an undisablable "smart" feature that sometimes marks a
  successful run a failure.
  Refs:
  a477789c43
  https://github.com/curl/curl/pull/18301
- these tests are different in scope than libssh2's own.
- tests sometime fail flaky with:
  ```
  Failure Event: -43 - Failed getting banner
  ```
  Ref: https://github.com/libssh2/libssh2/actions/runs/34134974899/job/101783681252?pr=2590
- running on modern runner machines, the Win10-introduced DH algo is
  always enabled.

Ref: https://github.com/libssh2/libssh2/discussions/2049
Ref: #2583

Closes #2590
2026-09-08 20:42:06 +02:00
lv2dev
f216bbe3aa wincng: normalize fixed-width DH values before mpint encoding
- normalize fixed-width WinCNG bignums before SSH `mpint` serialization
- apply the normalization to DH public values and DH/ECDH shared secrets
- zero the removed tail bytes and add common bignum conversion tests

WinCNG returns DH public values and raw DH/ECDH shared secrets in
fixed-width buffers. The WinCNG bignum retained that buffer width as its
numeric length. When a value started with `0x00`, libssh2 included the
redundant byte in the exchange hash even though RFC 4251 requires a
canonical `mpint` representation.

The peer hashes the normalized integer, so the exchange hashes differ
and a valid server host-key signature is rejected. This appeared
intermittently as `LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE` because it
depends on the generated value.

The helper introduced here moves significant bytes to the start of the
existing allocation, explicitly clears the removed tail, and updates
only the logical length. It does not add an allocation or a new failure
path.

Reported-by: Dan Fandrich
Fixes #804
Ref: #2590 (tests)

Closes #2583
2026-09-08 20:19:44 +02:00
Viktor Szakats
a951e06640 test_simple: make test_ssh2_dh_validate() portable
Omit direct backend-specific API use. Drop one test using negative
input, that's impossible with the internal crypto API. Using
backend-specific code in tests is highly undesired. It's also
discouraged to special-case any, in this case WinCNG had to be because
it does not implement the DH validation function.

Also:
- mbedtls: fix an internal API type difference with a cast.
- unfold a line.

Follow-up to fcf830788d #2239

Closes #2595
2026-09-07 16:44:32 +02:00
Viktor Szakats
f0ac38ab93 libgcrypt: fix ssh2_bn_set_word() return value
It was returning a non-NULL address on success, which translated to
permanent failure as mapped to this internal crypto API. Fix to match it
with the rest of crypto backends and the expectation of callers.

Reported by Copilot
Bug: https://github.com/libssh2/libssh2/pull/2595#discussion_r3950301182
Follow-up to 95c824d5d9 #1354
Follow-up to c9d40afa14

Closes #2596
2026-09-07 16:26:02 +02:00
Viktor Szakats
13e1042b99 crypto: make ssh2_bn_from_bin() init the bignum, drop ssh2_bn_init_from_bin()
To better hide backend-specific differences and t bring the init
sub-steps (1. allocation, 2. conversion) close to each other.

Also:
- HACKING_CRYPTO.md: fix docs for `ssh2_bn_from_bin()` and
  `ssh2_bn_set_word()`.

Ref: https://github.com/libssh2/libssh2/pull/2583#discussion_r3948922721

Closes #2594
2026-09-07 15:23:10 +02:00
Viktor Szakats
c3c1743a1f kex: adjust type to drop casts for ssh2_bn_bits() value
Closes #2593
2026-09-07 10:40:52 +02:00
Viktor Szakats
b766778c22 openssl: make ssh2_bn_bytes()/ssh2_bn_bits() return size_t
To match other crypto backends.

Closes #2592
2026-09-07 10:40:52 +02:00
Viktor Szakats
8e181e7a8e src: constify arguments where feasible
Closes #2589
2026-09-04 16:56:17 +02:00
Viktor Szakats
da8d048dda clang-tidy: enable readability-redundant-casting, fix/silence findings
Also:
- openssl: drop redundant local variable in non-OpenSSL3 branch.
- x11: drop redundant cast.
- silence false positives.

Follow-up to 0b915eab67 #2586

Closes #2588
2026-09-04 15:29:18 +02:00
Viktor Szakats
260fe5b694 RELEASE-NOTES: sync [ci skip] 2026-09-04 14:35:14 +02:00
Viktor Szakats
0b915eab67 clang-tidy: fix readability-redundant-casting findings
Do not enforce due to false positives.

Ref: https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-casting.html

Closes #2586
2026-09-04 14:23:06 +02:00
Viktor Szakats
c4ae6510ef clang-tidy: enable readability-redundant-nested-if, fix findings
Ref: https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-nested-if.html

Closes #2585
2026-09-04 14:23:06 +02:00
Viktor Szakats
404e32a445 clang-tidy: enable readability-misleading-indentation
Ref: https://clang.llvm.org/extra/clang-tidy/checks/readability/misleading-indentation.html

Closes #2584
2026-09-04 13:53:26 +02:00
Viktor Szakats
b5c37a910d channel, packet: validate packet size received from server
To avoid continuing with a zero value and entering a busy-loop.

Reported-by: Nora-Qiu
Fixes GHSA-4q73-hh48-fmr8

Closes #2582
2026-09-04 09:06:20 +02:00
Viktor Szakats
9438f90ae0 sftp: fix handling unexpected EOF in sftp_packet_read()
If the server failed to serve the promised amount of data,
`sftp_packet_read()` could be stuck in a loop, prior to this patch.

Report-and-patch-by: RELAUNCH DEPT.
Fixes GHSA-2q3j-q544-xxp7

Closes #2581
2026-09-03 23:22:30 +02:00
Viktor Szakats
d0a0210bd4 agent: fix potential infinite loop while receiving data from SSH agent
If the local SSH agent terminates while we are receiving data from it.

Refs:
https://learn.microsoft.com/windows/win32/api/fileapi/nf-fileapi-readfile#pipes
https://linux.die.net/man/2/recv
https://www.man7.org/linux/man-pages/man2/recv.2.html

Reported-by: afldl on github

Closes #2414
2026-09-03 23:15:07 +02:00
Viktor Szakats
14b9d8771c publickey: cap number of public keys in libssh2_publickey_list_fetch()
tn the abitrary value of 32768. To avoid overflowing the counter and
letting it wrap around, and to avoid exhausting memory if the list is
large or keeps coming from the server.

Closes #2580
2026-09-03 19:44:50 +02:00
RELAUNCH DEPT.
b4e6761de0 publickey: preserve list state across EAGAIN in libssh2_publickey_list_fetch()
`libssh2_publickey_list_fetch()` preserves its packet-receive state when
a non-blocking channel returns `LIBSSH2_ERROR_EAGAIN`, but the
accumulated list, key count and capacity were local to a single
invocation.

Keep those aggregate values in the opaque publickey handle while a list
fetch is in progress. Restore them on retry, transfer ownership to the
caller on success, and release them on an error or subsystem shutdown.

Fixes GHSA-qwvp-xm4w-32m7

Closes #2578
2026-09-03 18:17:26 +02:00
RELAUNCH DEPT.
ad16eb112f publickey: initialize the list terminator
The allocation reserves `max_keys + 1` entries, while the initialization
after growth currently covers only `max_keys - keys` entries. Include
the additional reserved entry in that initialization so the list
terminator is initialized at exact capacity boundaries.

Follow-up to c2f1a3a21b #2380
Ref: https://github.com/libssh2/libssh2/pull/2380#pullrequestreview-4746725158

Closes #2579
2026-09-03 16:42:51 +02:00
Viktor Szakats
dc656fd807 include: restore parentheses for macro arguments, for compatibility
To avoid the chance of breaking compatibility. Make an exception for
values also passed to `strlen()` because these were already not
supporting callers passing `x, y`-style macro expressions to these
macros, as arguments.

Also note that SFTP handle args already did not support this due to the
lack of parentheses in `libssh2_sftp_close()`, `libssh2_sftp_closedir()`
macros.

Follow-up to b6f307dca9 #1898

Closes #2577
2026-09-03 16:42:51 +02:00
Viktor Szakats
1545df0993 libssh2.h: macro value formatting
To keep value and its corresponding `strlen(value)` pair in one line,
where they fit.

Closes #2576
2026-09-03 15:02:26 +02:00
Viktor Szakats
e09f811180 wincng: rename local private key parsing functions to share a suffix
Closes #2575
2026-09-03 14:44:15 +02:00
Viktor Szakats
ceb158014b tests: add script to dump test keys in more parsable formats
In some cases this is binary, in others it's textual.

To better see what's in the keys, to debug them, and debug code dealing
with them. It's a manual script, not run automatically by this repo.

Closes #2574
2026-09-03 10:51:07 +02:00
Viktor Szakats
4884fc6102 scp: handle ssh2_snprintf() failure in scp_send()
It could happen with base paths too large to fit into the 256-byte
response buffer.

Reported-by: QcN3ep
Fixes GHSA-v6rf-jr7x-9hhp
Reported-by: Nora-Qiu
Fixes GHSA-p2v4-ghw2-mvq3

Closes #2573
2026-09-03 00:22:09 +02:00
Viktor Szakats
3a8baf3b81 RELEASE-NOTES: sync [ci skip] 2026-09-02 07:48:10 +02:00
hunterinvariants
dd47304a16 knownhost: match equivalent IPv6 literals
Plain known-host entries are currently compared as text, so equivalent
expanded and compressed IPv6 literals do not match.

This change keeps the existing exact-string fast path and compares two
valid plain IPv6 literals by their 128-bit address. It also supports
bracketed IPv6 host-and-port entries while requiring the port suffix to
match exactly.

No DNS lookup is performed. Hostname matching and the CUSTOM and hashed
known-host paths remain unchanged.

Reported-by: Krisscut on github
Fixes #1398

Closes #2568
2026-09-02 07:26:55 +02:00
Pier Carlo Cadoppi
c704efcc7d hostkey: implement ECDSA/RSA certificate hostkey verification
Implement server hostkey verification for the six ECDSA/RSA OpenSSH
certificate hostkey variants:

- `ecdsa-sha2-nistp256-cert-v01@openssh.com`
- `ecdsa-sha2-nistp384-cert-v01@openssh.com`
- `ecdsa-sha2-nistp521-cert-v01@openssh.com`
- `ssh-rsa-cert-v01@openssh.com`
- `rsa-sha2-256-cert-v01@openssh.com`
- `rsa-sha2-512-cert-v01@openssh.com`

This fixes #2434, where these algorithms were advertised and accepted as
preferences but had `NULL` hostkey `init`/`sig_verify` callbacks. A
certificate-only hostkey offer therefore caused
`LIBSSH2_ERROR_KEX_FAILURE (-5)`.

## Implementation

- ECDSA certificate parsing uses one shared init path for all three
  curves. It validates the certificate type, nonce, inner curve name, and
  EC point before constructing the verification context.
- RSA certificate parsing uses one shared init path for all three RSA
  signature variants.
- Per-algorithm RSA `sig_verify` callbacks remain distinct.
- Per `PROTOCOL.certkeys`, the RSA/SHA-2 certificate blob itself carries
  the type string `ssh-rsa-cert-v01@openssh.com`; the negotiated SHA-2
  algorithm is represented by KEXINIT and the exchange signature.
- Certificate CA trust validation remains out of scope, consistent with
  existing plain-hostkey handling.

## Tests

- Host CA fixtures (`keys/ca_host_ecdsa`, `keys/ca_host_rsa`) and
  CA-signed host certificates for the ECDSA P-256 and RSA host keys in the
  Docker OpenSSH fixture.
- The certificate algorithms are exercised through `test_read_algos.txt`
  and `FIXTURE_TEST_HOSTKEY`: `ecdsa-sha2-nistp256-cert-v01@openssh.com`,
  `rsa-sha2-256-cert-v01@openssh.com`,
  `rsa-sha2-512-cert-v01@openssh.com`, `ssh-rsa-cert-v01@openssh.com`,
  plus the pre-existing `ssh-ed25519-cert-v01@openssh.com`.
- The ECDSA P-384/P-521 certificate variants share the same codepath and
  are covered by it; only P-256 is tested directly to keep the fixture
  matrix lean (per maintainer review feedback).
- Disabled-backend skip entries in `tests/session_fixture.c` for the new
  certificate algorithms.
- Preserved the existing ed25519 certificate test path.

Fixes #2434
Follow-up to 6036e57720 #2513
Follow-up to 65a276e8fe #2064

Closes #2539
2026-09-02 07:26:55 +02:00
Viktor Szakats
c5434649ce GHA/codeql: build C++ (fuzzer) code
Closes #2572
2026-09-01 23:52:17 +02:00
Viktor Szakats
d7e461a081 GHA: restore building examples in CodeQL jobs
Follow-up to 6bf392f627 #2276

Closes #2571
2026-09-01 23:40:15 +02:00
dependabot[bot]
1f35fe4335 GHA: bump GitHub Actions
- update `docker/login-action` from 4.5.1 to 4.6.0
- update `github/codeql-action/analyze` from 4.37.3 to 4.37.8
- update `github/codeql-action/init` from 4.37.3 to 4.37.8

Closes #2570
2026-09-01 20:06:41 +02:00
dependabot[bot]
995b230ad4 Dockerfile: bump debian from trixie-20260713-slim to trixie-20260824-slim
Closes #2569
2026-09-01 20:06:41 +02:00
Viktor Szakats
99f17f4fe8 GHA: bump cross-build-actions to 1.5.0
Also adjust BSD job descriptions to sort them in one group.

Ref: https://github.com/cross-platform-actions/action/releases/tag/v1.5.0

Closes #2567
2026-08-31 11:22:08 +02:00
Viktor Szakats
c7557852f1 RELEASE-NOTES: sync [ci skip] 2026-08-29 02:58:51 +02:00
Viktor Szakats
eabe683e4e openssl: bail out early on bignum OOM in ssh2_rsa_new(), ssh2_dsa_new() with OpenSSL 3+
Also: delete stray unused `session` suppression.

Reported by Copilot
Bug: https://github.com/libssh2/libssh2/pull/2564#discussion_r3884840663
Bug: https://github.com/libssh2/libssh2/pull/2564#discussion_r3884840697
Follow-up to b0ab005fe7 #1207

Closes #2566
2026-08-29 02:48:39 +02:00
Viktor Szakats
8aeee0009d openssl: replace OpenSSL allocator with the SSH2 one in ssh2_rsa_new(), ssh2_dsa_new()
Follow-up to 5ef9591d2c #2559
Follow-up to d5149ca35d #2548
Follow-up to b0ab005fe7 #1207

Closes #2564
2026-08-29 02:26:53 +02:00
Viktor Szakats
2042863db5 crypto: fix LIBSSH2_NO_RSA to explicitly disable both RSA SHA1/SHA2
To simplify RSA feature guards and fix pre-existing ones in tests, e.g.
in `test_auth_pubkey_ok_rsa_pem_sha2_512_signed.c`.

Bug: https://github.com/libssh2/libssh2/pull/2539/files#discussion_r3880534427
Bug: https://github.com/libssh2/libssh2/pull/2539/files#discussion_r3880534393

Closes #2565
2026-08-29 02:19:12 +02:00
Viktor Szakats
b15d84b33d mbedtls: use ssh2_zero_free() where applicable
Follow-up to a2ac6bd4e8 #2544

Closes #2563
2026-08-29 02:19:12 +02:00
Viktor Szakats
a794df666a mbedtls: merge local function mbed_parse_eckey() into its sole caller
Follow-up to b560cb4c7b #2379
Follow-up to 5528f3da02 #385

Closes #2562
2026-08-29 01:42:01 +02:00
Viktor Szakats
e655d94a08 wincng: constify static function arguments, where missing
Closes #2561
2026-08-28 22:22:29 +02:00
Viktor Szakats
5ef9591d2c crypto: propagate session to key alloc/free functions, switch to SSH2 allocator
To shift allocation from raw or backend-specific allocators to libssh2's
own. To respect custom allocators set via `libssh2_session_init_ex()`,
and to reduce the chance for mismatched alloc/free calls.

- pass `session` to `ssh2_rsa_new()` and `ssh2_dsa_new()` and all the
  `ssh2_*_free()` deallocators.
- mbedtls: replace mbedTLS alloc/free with libssh2 alloc/free.
- wincng: replace malloc/free with libssh2 alloc/free.
- wincng: use libssh2 allocator in `wcng_asn_decode()` to sycn up with
  the above change and avoid using mixed allocators in key contexts.
- wincng: use libssh2 allocator in `wcng_asn_decode_bns()`,
  `wcng_publickey_from_point()`, `wcng_privatekey_from_point()`.

Closes #2559
2026-08-28 22:13:11 +02:00
Viktor Szakats
48eb7c9ff2 wincng: fix allow/free mismatch with wcng_load_priv() return buffers
This function calls `ssh2_pem_parse()`, which allocates the returned
buffer using `SSH2_ALLOC()`. The backend used `wcng_zero_free()` to
free them, which uses `free()`.

Fix by replacing these with `ssh2_zero_free()`.

Follow-up to d385230e15

Closes #2560
2026-08-28 21:19:03 +02:00