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

403 Commits

Author SHA1 Message Date
Viktor Szakats
2233bf95ed tests: retry '(-43): Failed getting banner' flaky failures
Example:
```
1: libssh2_session_handshake failed (-43): Failed getting banner
1: ---- sshd log ----
1: No matching private key for certificate: /etc/ssh/ssh_host_mldsa44-ed25519_key-cert.pub
1: debug1: Set /proc/self/oom_score_adj from 0 to -1000
1: debug2: fd 6 setting O_NONBLOCK
1: debug1: Bind to port 22 on 0.0.0.0.
1: Server listening on 0.0.0.0 port 22.
1: debug2: fd 7 setting O_NONBLOCK
1: debug1: Bind to port 22 on ::.
1: Server listening on :: port 22.
1: ------------------
1: Command: docker image pull ghcr.io/libssh2/ci_tests_openssh_server:8d1fde1834077fddb9f9
1: Command: docker image tag ghcr.io/libssh2/ci_tests_openssh_server:8d1fde1834077fddb9f9 libssh2/openssh_server
1: Command: docker run --rm -d -p 22 libssh2/openssh_server
1: Command: docker inspect --format "{{ (index (index .NetworkSettings.Ports \"22/tcp\") 0).HostIp }}" a1f1a209001852fa7e3aba87c0f1198661c4fe07c34ddcbf2e76e264ef64b7b8
1: Command: docker inspect --format "{{ (index (index .NetworkSettings.Ports \"22/tcp\") 0).HostPort }}" a1f1a209001852fa7e3aba87c0f1198661c4fe07c34ddcbf2e76e264ef64b7b8
1: Command: docker logs a1f1a209001852fa7e3aba87c0f1198661c4fe07c34ddcbf2e76e264ef64b7b8
1: Command: docker stop a1f1a209001852fa7e3aba87c0f1198661c4fe07c34ddcbf2e76e264ef64b7b8
 1/61 Test  #1: test_aa_warmup .......................................***Failed    6.08 sec
libssh2_session_handshake failed (-43): Failed getting banner
```
Ref: https://github.com/libssh2/libssh2/actions/runs/37613324059/job/112765610280?pr=2659#step:25:133

Ref: 5bfa574460 #2603

Closes #2662
2026-10-07 15:35:05 +02:00
syed abdul khaliq
7f28c290d3 wincng: validate Diffie-Hellman public value in ssh2_dh_secret()
ssh2_dh_secret() in the Windows CNG backend uses the server's
Diffie-Hellman public value f without the range check the other four
backends apply through ssh2_dh_validate(), so a malicious server can
send f of 0, 1 or p-1 and push the shared secret into a trivial subgroup
that openssl, libgcrypt, mbedtls and os400qc3 all reject with
LIBSSH2_ERROR_PROTO. This adds a WinCNG ssh2_dh_validate() that enforces
1 < f < p-1 and the same minimum-set-bits check on the big-endian value,
and calls it at the top of ssh2_dh_secret() like the other backends do.
The shared test_ssh2_dh_validate() in tests/test_simple.c was stubbed
out on WinCNG only because the function did not exist, so it now runs
against the real implementation too.

Reported-by: yaotushaozhu on github
Ref: GHSA-m9rg-h9jv-9gvh
Follow-up to fcf830788d #2239

Closes #2645
2026-10-04 21:17:02 +02:00
Viktor Szakats
4ab391ec9f tests: set PerSourcePenalties for sshd, bump debug level to 2
To silence a warning, in rare failure cases:
```
srclimit_penalise: ipv4: new 172.17.0.1/32 deferred penalty of 1.000
  seconds for penalty: connections without attempting authentication
```
Ref: https://github.com/libssh2/libssh2/actions/runs/37207427612/job/111451438515?pr=2649#step:25:537

Also:
- seize the opportunity and bump sshd debug level to 2.
  Level 1 is too low to see clearly in some cases.
  Ref: https://github.com/libssh2/libssh2/pull/2649
  Follow-up to 45aa5c5fa4 #2621

Refs:
https://man.openbsd.org/sshd_config#PerSourcePenalties
https://www.openssh.org/txt/release-9.8

Closes #2650
2026-10-04 20:07:33 +02:00
Viktor Szakats
c7541acd4b tests/cmake: suppress stderr in if expression
Silencing, seen with MSYS2 shell:
```
+ ln -s ../.. libssh2
ln: failed to create symbolic link 'libssh2': Too many levels of symbolic links
+ rm -rf libssh2
```
Ref: https://github.com/libssh2/libssh2/actions/runs/36978012817/job/110745989451#step:15:40

Closes #2642
2026-10-02 11:11:29 +02:00
Viktor Szakats
45aa5c5fa4 tests: dump container sshd log for test failures
To help debugging issues.

Also:
- bump sshd LogLevel to DEBUG1, for essential details.
- bump command output buffer in `run_command_varg()`
- drop redundant condition in `run_command_varg()`
- replace `BUFSIZ` with literal sizes in `run_command_varg()`.

After this patch it's showing this in the CI log for the libgcrypt
fallout that previously needed a long time to diagnose:
```
61: ---- sshd log ----
61: No matching private key for certificate: /etc/ssh/ssh_host_mldsa44-ed25519_key-cert.pub
61: Server listening on 0.0.0.0 port 22.
61: Server listening on :: port 22.
61: debug1: sshd-session version OpenSSH_10.5, OpenSSL 3.6.3 9 Jun 2026
61: Connection from 172.17.0.1 port 51878 on 172.17.0.2 port 22 rdomain ""
61: debug1: sshd-auth version OpenSSH_10.5, OpenSSL 3.6.3 9 Jun 2026 [preauth]
61: debug1: list_hostkey_types: rsa-sha2-512,rsa-sha2-256,ssh-rsa,rsa-sha2-512-cert-v01@openssh.com,
rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ecdsa-sha2-nistp256,
ecdsa-sha2-nistp256-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com [preauth]
61: debug1: Local version string SSH-2.0-OpenSSH_10.5p1 Debian-1 [preauth]
61: debug1: Remote protocol version 2.0, remote software version libssh2_1.11.2_DEV [preauth]
61: debug1: compat_banner: no match: libssh2_1.11.2_DEV [preauth]
61: debug1: SSH2_MSG_KEXINIT sent [preauth]
61: debug1: SSH2_MSG_KEXINIT received [preauth]
61: debug1: kex: algorithm: (no match) [preauth]
61: Unable to negotiate with 172.17.0.1 port 51878: no matching key exchange method found.
Their offer: diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,
diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,
diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1,ext-info-c,
kex-strict-c-v00@openssh.com [preauth]
[...]
61: ------------------
```

Follow-up to 1d0b86ac84 #2484
Follow-up to 8be5716437 #2174
Follow-up to 51f6259d18 #1720

Closes #2621
2026-09-13 21:20:56 +02:00
Viktor Szakats
418c2a2a67 openssh_fixture: merge Apple container commands with others
Use the full `image pull`, `image tag` commands for docker and podman,
to make them all use the same commands.

Ref:
https://docs.docker.com/reference/cli/docker/image/pull/
https://docs.docker.com/reference/cli/docker/image/tag/

Follow-up to 9bd1f16dc2 #2605

Closes #2622
2026-09-13 18:52:20 +02:00
Viktor Szakats
1061e299f2 openssh_fixture: drop progress from image pull with Apple container
Follow-up to 9bd1f16dc2 #2605

Closes #2620
2026-09-13 18:10:47 +02:00
Viktor Szakats
14fbba968b tidy-up: prefer host key in two words for human-readable text
Closes #2618
2026-09-13 16:12:32 +02:00
Viktor Szakats
967a24b3bb tidy-up: miscellaneous
- wincng: add version comments.
  Follow-up to 7a26697ede #397
- wincng: fix two version support comments.
- tests/keys-generate.sh: add comment, newlines.
- mbedtls: casing in comment.
- wording: use `null-terminator` more.
- typos: `ssh-dss`.
- knownhost: drop obsolete comment.
- include/libssh2.h: clarify comments.
- include/libssh2.h: drop empty lines.
- libssh2_knownhost_writeline.md: fix grammar.
- GHA: reorder Cygwin settings, improve package search URL.
- fixup newlines.

Closes #2617
2026-09-13 16:12:32 +02:00
Viktor Szakats
f1572b2888 GHA/openssh_server: drop docker login Action, limit scope
In favor of direct execution or `docker login` and `docker logout`.

Also to limit the logged-in time to the steps the require it, and to
avoid passing a secret via the command-line.

Closes #2616
2026-09-13 14:50:26 +02:00
Viktor Szakats
781b6ca8a5 sshd_config: drop accidental ML-DSA change [ci skip]
Follow-up to 5c50ea8a5d #2615
2026-09-13 14:28:02 +02:00
Viktor Szakats
5c50ea8a5d tests: add ML-DSA host keys (not used or supported by libssh2)
Requires OpenSSH 10.3. As of 10.5, to enable in sshd, this patch needs
to be applied:

```diff
--- a/tests/openssh_server/sshd_config
+++ b/tests/openssh_server/sshd_config
@@ -3,9 +3,9 @@
 # SPDX-License-Identifier: BSD-3-Clause

 CASignatureAlgorithms +ssh-rsa
-HostKeyAlgorithms +ssh-rsa,ssh-rsa-cert-v01@openssh.com
+HostKeyAlgorithms +ssh-rsa,ssh-rsa-cert-v01@openssh.com,ssh-mldsa44-ed25519@openssh.com,ssh-mldsa44-ed25519-cert-v01@openssh.com
 # modern name in OpenSSH 8.5+: PubkeyAcceptedAlgorithms
-PubkeyAcceptedKeyTypes +ssh-rsa,ssh-rsa-cert-v01@openssh.com
+PubkeyAcceptedKeyTypes +ssh-rsa,ssh-rsa-cert-v01@openssh.com,ssh-mldsa44-ed25519@openssh.com,ssh-mldsa44-ed25519-cert-v01@openssh.com
 MACs +hmac-sha1,hmac-sha1-96,hmac-sha2-256,hmac-sha2-512,hmac-md5,hmac-md5-96,umac-64@openssh.com,umac-128@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-md5-etm@openssh.com,hmac-md5-96-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com
 Ciphers +3des-cbc,aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
 # for libgcrypt, WinCNG
```
2026-09-13 13:44:17 +02:00
Viktor Szakats
e3f1853298 Dockerfile: copy ssh_host_*.pub keys to avoid sshd warnings
To overwrite default ones with the ones matching the copied private
keys.

Fixing in sshd log:
```
Public key for /etc/ssh/ssh_host_rsa_key does not match private key
Public key for /etc/ssh/ssh_host_ecdsa_key does not match private key
Public key for /etc/ssh/ssh_host_ed25519_key does not match private key
```

Closes #2614
2026-09-13 13:09:52 +02:00
Viktor Szakats
7bf89e2bb8 Dockerfile: drop repeating source filenames in the destination
Closes #2613
2026-09-13 12:40:48 +02:00
Viktor Szakats
7498e661b4 test_sshd.test: add RSA and ECDSA HostCertificate options
Follow-up to c704efcc7d #2539

Closes #2612
2026-09-13 12:40:48 +02:00
Viktor Szakats
86dca4efea openssh_fixture: drop docker-machine ip logic
Also drop using the `DOCKER_MACHINE_NAME` env which is part of the logic
deleted.

The `docker-machine` command and package no longer exists upstream. It's
missing from distros, its last commit was on 2019-09-02, repo archived
on 2025-07-18.

Refs:
https://github.com/docker-archive-public/docker.machine
https://github.com/docker/roadmap/issues/245
https://docs.docker.com/retired/

Follow-up to 2ded2f95c5 #2609
Follow-up to cf80f2f4b5 #100

Closes #2611
2026-09-13 12:08:11 +02:00
Viktor Szakats
2ded2f95c5 tidy-up: prefer term 'container' over 'docker'
To reflect the support for multiple container engines, and to make
terminology more consistent and implementation-agnostic.

Also:
- add FIXME for `docker-machine ip` command that has been dropped
  upstream.

Follow-up to 9bd1f16dc2 #2605

Closes #2609
2026-09-13 11:54:32 +02:00
Viktor Szakats
9bd1f16dc2 tests: add support for podman, Apple container
- add `FIXTURE_CONTAINER_CMD` to the container command. Supported:
  `podman`, `container`, `docker` (default).
- deprecate `OPENSSH_NO_DOCKER` env. Replaced by setting
  `FIXTURE_CONTAINER_CMD` to an empty string.
- GHA: replace Docker with `podman` in a some Linux jobs.
- openssh_fixture: fixup `inspect` commands to be compatible with both
  docker and podman.
- openssh_fixture: add `inspect` fallback for podman, which does not
  support `HostIp` before 6.1.0.
  Ref: https://github.com/podman-container-tools/podman/issues/29164
- openssh_fixture: add Apple container alternatives for `pull` and
  `tag`.
- openssh_fixture: fix `run` command to suppress progress output when
  using Apple container.
- openssh_fixture: if `OPENSSH_SERVER_PORT` is set, omit querying
  the port number via the container tool.

`podman` seems to be a tiny bit slower than Docker in CI.

Requirements for Apple container:
- Apple container 0.8.0+ (2026-01-02). Tested with 1.4.1.
- `jq` installed in PATH.
- setting the sshd port manually on the host via `OPENSSH_SERVER_PORT`
  (`container` cannot automatically assign one).
- physical macOS machine.

Example to run conainerized tests on macOS:
```sh
brew install container jq
container system start --disable-kernel-install
container system kernel set --recommended
export FIXTURE_CONTAINER_CMD=container
export OPENSSH_SERVER_PORT=<free-port-number>
export OPENSSH_SERVER_IMAGE; OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:tests/openssh_server)
ctest -VV
```

Also tried:
- using Apple container in CI. Does not work because nested
  virtualization is not supported in GHA runners.
- installing WSL on Windows. Failed with cryptic error upon
  `wsl --install --distribution Debian`.

Closes #2605
2026-09-13 10:34:14 +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
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
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
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
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
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
1c9ff81452 test_auth_keyboard_info_request: delete unused free_count variable
To fix unused variable warning with clang-tidy 23.1.0.

Follow-up to 83853f8aea #663

Closes #2554
2026-08-28 14:18:01 +02:00
Viktor Szakats
532ba6dcb7 tidy-up: miscellaneous
- cipher-chachapoly: replace magic number, drop {}.
- cipher-chachapoly: simplify.
- tests/cmake/test: constify.

Closes #2526
2026-08-14 02:07:18 +02:00
Viktor Szakats
3f718eaa90 tidy-up: comment and formatting fixes
Closes #2525
2026-08-14 01:58:59 +02:00
Huang Rui
4dbbcf9261 channel: add public API libssh2_channel_has_exit_status()
`libssh2_channel_get_exit_status()` returns 0 both for a real exit
status of 0 and for a channel that never received an `exit-status`
request. A server that force-closes a session, like OpenSSH under
`ChannelTimeout`, makes a still-running command look like a clean exit
0. Reproduction with the stock `example/ssh2_exec` is in #2515.

This adds `libssh2_channel_has_exit_status()`, returning 1 once the
request arrived, the name you suggested.

The new field sits in `_LIBSSH2_CHANNEL` in `libssh2_priv.h` and callers
only ever hold a pointer, so no ABI change.
`libssh2_channel_get_exit_signal()` already lets a caller see whether
that request arrived by leaving the pointer NULL, exit-status was the
odd one out.

Man page and a `test_exit_status` covering both states are included.

Follow-up to 77bd3c1215
Fixes #2515
Closes #2516
2026-08-14 01:31:20 +02:00
hunterinvariants
75b472cf0e session: free keyboard-interactive state in session_free()
Free keyboard-interactive authentication state when a session is
destroyed.

This covers the authentication name, prompt and response arrays, and
their individual strings. Avoid calling memcpy() with null pointers for
zero-length test input.

Tested with the complete CMake/OpenSSL test suite and the targeted
ASan/UBSan test.

Also:
- test_auth_keyboard_info_request: tidy up to prevent zero-size
  allocation and memcpy.

Closes #2517
2026-08-14 01:24:44 +02:00
hunterinvariants
fb2b6d576e test_hostkey: free decoded expected hostkey
Release the expected hostkey buffer allocated by ssh2_base64_decode() on
success and mismatch paths.

Tested with the complete CMake/OpenSSL test suite and the targeted
ASan/UBSan test.

Follow-up to cf80f2f4b5

Closes #2518
2026-08-14 01:14:50 +02:00
Viktor Szakats
6036e57720 tests: add tests for signed hostkey: ssh-ed25519-cert-v01@openssh.com
- add host CA keys.
- add ed25519 signed hostkey for tests.
- make hostkey tests recognize it and skip hash checks.
- make existing tests select hostkey algos.
- add `ssh-ed25519-cert-v01@openssh.com` to the list of tested algos.
  (exclude for unsupported backends.)

Ref: #2434
Inspired-by: #2435
Credits-to: Pier Carlo Cadoppi
Follow-up to 65a276e8fe #2064

Closes #2513
2026-08-10 17:00:04 +02:00
Viktor Szakats
19aa4338f7 tests: rename CA keys to reflect they are user keys
Closes #2512
2026-08-06 10:53:16 +02:00
Viktor Szakats
c8543ef39f tests: upload host pubkeys to repo
Also: regen ed25519 key to have an empty comment like its siblings.

To be used for generating host certificate keys.

Ref: 65a276e8fe #2064
Ref: #2435

Closes #2511
2026-08-06 02:05:49 +02:00
Viktor Szakats
72693e4e36 tests: rename keys/tests to contain the key format
To make navigating, identifying, key files and tests easier.

Also:
- example/ssh2: sync key filenames with rest of examples.

Closes #2510
2026-08-06 01:06:21 +02:00
Viktor Szakats
84cffeaf11 session_fixture: fix to skip AES-CBC/CTR tests if not supported or disabled
Closes #2507
2026-08-04 03:15:31 +02:00
Viktor Szakats
0b749a969f tests: add chacha20-poly1305@openssh.com to test_read_algos.txt
To enable testing via the `test_read` test.

Follow-up to 492bc543bb #1426

Closes #2506
2026-08-04 03:15:31 +02:00
Viktor Szakats
4b5303ab6d tests: add PKCS8-formatted plain and encrypted keys and tests
They are supported via the backends, except OS/400 which has its own
parser, leaving libgcrypt and WinCNG (untested) without support. With
mbedTLS PKCS8 encryption (aes-128-cbc) requires 3.6.0+.

Add RSA, ECDSA and ED25519 keys.

What I find interesting in PKCS8 private keys, is the easy way to
inspect the ASN.1 content (`openssl asn1parse -dump -in <fn>`). I could
not find similar tooling for PEM and OpenSSH files.

Also:
- tests/openssh_server/authorized_keys: sync up comments with private
  keys and the generator script.

Ref: https://github.com/Mbed-TLS/mbedtls/releases/tag/v3.6.0

Closes #2500
2026-08-04 00:42:31 +02:00
Viktor Szakats
079eeb852b src: disable SHA1-based hostkey methods and signatures by default, fix fallouts
They are `ssh-rsa` and `ssh-rsa-cert-v01@openssh.com`, and insecure due
to their reliance on SHA1 hashes.

Also:
- hostkey: fix to accept all RSA hostkey methods in common
  `hostkey_method_ssh_rsa_init()`.
- mbedtls: add missing RSA SHA1/SHA2 guards.
- mbedtls: cleanup on error in `mbed_pub_priv_key()`.
- os400qc3: add missing RSA SHA1/SHA2 guards. (untested)
- wincng: add missing RSA SHA1/SHA2 guards.
- crypto.h: add missing `#endif` comments.
- GHA: move stray `-DLIBSSH2_DSA_ENABLE` to its place.
  Follow-up to b7ab0faa70 #1435
- tests: fix to guard RSA tests with `LIBSSH2_RSA`, replacing
  `LIBSSH2_RSA_SHA1` to keep test coverage. Keep using the latter for
  testing SHA1-based signatures in `test_auth_pubkey_ok_rsa_signed`.

Follow-up to 3e14d67d26 #2444
Follow-up to 99f935358d #2443

Closes #2501
2026-08-03 16:44:03 +02:00
Viktor Szakats
f3a5b6a038 tests: add ECDSA PEM format plain and encrypted keys and tests
To improve coverage. This is the 'EC PRIVATE KEY` format, not tested
before. The encrypted flavor probably should not be used nowadays due to
its dependence on MD5, and thus also only tested in one job. Also use
this opportunity to introduce ECDSA 521 into the mix.

Also:
- test_auth_pubkey_ok_rsa_encrypted: require `LIBSSH2_AES_CBC`.

Closes #2499
2026-08-03 12:24:57 +02:00
Viktor Szakats
f5821e600d tests: move trusted CA private keys off the test server
They are unused on the server and meant to stay on the issuer machine.
Only the trusted public CA keys are needed on the server.

Reported by Copilot
Bug: https://github.com/libssh2/libssh2/pull/2496#discussion_r3702522974

Closes #2497
2026-08-03 11:32:06 +02:00
Viktor Szakats
d7a253f5f3 tests: add signed ed25519 key and test
Closes #2496
2026-08-03 10:54:14 +02:00
Viktor Szakats
e0595be5de keys-generate.sh: group signed keys, drop newlines [ci skip] 2026-08-03 05:26:20 +02:00
Viktor Szakats
7abbac4e7f src: add support for chacha20-poly130-encrypted OpenSSH key files
Also:
- switch encrypted ECDSA test key to use chacha20-poly1305@openssh.com.
- pem: add debug message on decryption error.

Follow-up to fd07ca411f #2486
Follow-up to 492bc543bb #1426

Closes #2488
2026-08-03 05:23:50 +02:00
Viktor Szakats
fd07ca411f tests: add test for encrypted ECDSA key
Make it 256-bit to add variation.

Choose aes256-ctr for encryption to keep it compatible with mbedTLS,
which lacks AES-GCM support. (The other alternative, chacha-poly, has
decryption broken for keys.)

Closes #2486
2026-08-02 23:46:14 +02:00
Viktor Szakats
2a38092caf tests: add support to disable hex debug dumps
via new env `FIXTURE_TRACE_NO_DEBUGDUMP`.

Also:
- CI: set `FIXTURE_TRACE_NO_DEBUGDUMP` to make detailed logs (much)
  shorter and more readable for the common debug use-case.

- GHA: enable debug trace for clang-tidy OpenSSL jobs and simplify
  configuration.

Cherry-picked from #2485

Closes #2487
2026-08-02 22:19:50 +02:00
Viktor Szakats
88dd2f0fb6 userauth: enable ssh-rsa-cert-v01@openssh.com for all backends in userauth_supported_key_sign_algs(), fix tests
The PR implementing this did not add anything OpenSSL-specific, yet it
gated the feature OpenSSL only. Turns out the reason for this is that
the test RSA keys are in OpenSSH format, which is only supported by
OpenSSL (and wolfSSL) in libssh2.

Fix by converting the two test keys to PEM format, making them
compatible with all backends. (RSA OpenSSH key format is already tested
separately.)

Also: this also fixes outdated comment fields present in these keys.

Bug: https://github.com/libssh2/libssh2/pull/1314#discussion_r3542830756
Ref: #2252 (initial fix attempt)
Follow-up to 1410efad7a #2249
Follow-up to 3a6ab70dcf #1314

Closes #2483
2026-08-02 18:46:37 +02:00