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

17 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
Viktor Szakats
41d5efc913 tests: regenerate id_rsa_signed.pub to match intent, fix sshd_config to accept it
Explicitly use `-t ssh-rsa` (signature algorithm) to generate
`id_rsa_signed.pub` to match the purpose of the patch it came with. Also
to differenciate this key (and test) from the subsequently merged
`id_rsa_sha2_512_signed-cert.pub`, which used the exact same keys (`-t
rsa-sha2-512`, the default) before this patch, and made these tests
duplicates.

Also:
- update `sshd_config` to actually allow using an obsolete/insecure
  certificate signature `ssh-rsa`, by adding it to `CASignatureAlgorithms`.
- delete recently added entry from `HostKeyAlgorithms`, it was not
  necessary.
  Follow-up to 5b494b04b1 #2478

Testing obsolete/insecure algs is not time best spent in CI and for
maintainers, so maybe in a next step it'd useful to disable the RSA
SHA1-based ones by default.

Ref: https://superuser.com/questions/1556852/how-to-check-if-your-ssh-keys-are-in-the-ssh-rsa2-format
Ref: 7392dc95dc #2479
Follow-up to 4b21e49d9d #710

Closes #2474
2026-08-02 15:24:21 +02:00
Viktor Szakats
7392dc95dc tests: rename a test and keys to match the actual format
The committed key was in reality `rsa-sha2-512`, not `rsa-sha2-256`, as
the filenames suggested.

Also set the type explicitly to `rsa-sha2-512`, to avoid relying on
ssh-keygen's default (`rsa-sha2-512`).

```shell
$ grep -E -o ' .+ ' id_rsa_sha2_512_signed-cert.pub | base64 -d | strings | grep -i rsa
```

Bug: #2474
Follow-up to 3a6ab70dcf #1314

Closes #2479
2026-08-02 12:20:23 +02:00
Viktor Szakats
e77f5da49d tests: sync up pubkey comments with generator (tidy-up)
Also:
- switch to `id_` prefix in comments to match filenames.
- use empty comment to add variation.
- spacecheck: allow trailing spaces for `.pub` files, this is how
  `ssh-keygen -C ''` generates them.

Closes #2472
2026-08-01 16:08:54 +02:00
Viktor Szakats
a824e9d8a9 tests: move test keys into keys subdirectory
Also:
- replace the prefix `key_` with `id_` to match defaults and make them
  easier to identify.
- rename `gen_keys.sh` to `keys-generate.sh`.
- include `keys-generate.sh` in tarball.

Closes #2471
2026-08-01 15:24:36 +02:00