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-actionCloses#2606
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 #2598Closes#2604
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#1023Closes#2603
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
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:
a477789c43https://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: #2583Closes#2590
- 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
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#2239Closes#2595
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_r3948922721Closes#2594
Also:
- openssl: drop redundant local variable in non-OpenSSL3 branch.
- x11: drop redundant cast.
- silence false positives.
Follow-up to 0b915eab67#2586Closes#2588
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
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
`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
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-4746725158Closes#2579
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#1898Closes#2577
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
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
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#1398Closes#2568
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#2064Closes#2539
- 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
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
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 d385230e15Closes#2560