Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens libssh2’s RSA hostkey handling by disabling SHA1-based RSA hostkey methods (ssh-rsa, [email protected]) by default, while adding/adjusting build guards across multiple crypto backends to prevent fallout when SHA1 (and/or RSA) is disabled.
Changes:
- Disable SHA1-based RSA hostkey methods by default, with a new opt-in build define (
LIBSSH2_RSA_SHA1_ENABLE) and updated release notes/CI coverage. - Make
hostkey_method_ssh_rsa_init()accept all relevant RSA key header types in common code paths. - Add missing RSA/SHA1 and RSA/SHA2 compile guards across several crypto backends (mbedTLS, OS/400 QC3, Windows CNG) and tidy
#endifcomments.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/wincng.c | Add LIBSSH2_RSA_SHA1 / LIBSSH2_RSA_SHA2 guards around RSA sign entrypoints in the Windows CNG backend. |
| src/os400qc3.h | Add missing RSA / SHA1 / SHA2 guards for OS/400 QC3 RSA macros and declarations. |
| src/os400qc3.c | Add missing RSA guard(s) and SHA1/SHA2 guards for OS/400 QC3 RSA verify functions. |
| src/mbedtls.c | Wrap RSA-related functions with LIBSSH2_RSA guards in the mbedTLS backend. |
| src/hostkey.c | Simplify RSA hostkey init header-type acceptance to handle all RSA variants in common code. |
| src/crypto.h | Clarify #endif comments for RSA/DSA blocks. |
| src/crypto_config.h | Switch to opt-in LIBSSH2_RSA_SHA1_ENABLE to keep SHA1 RSA hostkey methods disabled by default. |
| RELEASE-NOTES | Document the default disablement and the opt-in flag for SHA1-based RSA hostkey methods. |
| .github/workflows/ci.yml | Ensure legacy-options CI runs explicitly opt back into RSA-SHA1 (and place DSA enable flag appropriately). |
Suppressed comments (3)
src/mbedtls.c:585
mbed_gen_publickey_from_rsa()is now inside#if LIBSSH2_RSA, but it is still called unconditionally frommbed_pub_priv_key()(e.g., line 612). When building withLIBSSH2_NO_RSAthis will result in an undefined reference at link time. Either keepmbed_gen_publickey_from_rsa()available in non-RSA builds (stub that returns NULL / sets an error) or extend the#if LIBSSH2_RSAguard to cover the callers as well.
size_t *pubkeydata_len,
mbedtls_pk_context *pkey)
{
src/os400qc3.c:2403
- These RSA verify helpers are guarded by
LIBSSH2_RSA_SHA2/LIBSSH2_RSA_SHA1only. Because the backend headers define those as 1 by default, aLIBSSH2_NO_RSAbuild can still compile this RSA code even though RSA is disabled, potentially causing dead code and missing-prototype warnings. Consider also gating these blocks withLIBSSH2_RSA(and ideally the surrounding RSA-only helpers, includingssh2_rsa_new_priv()/ssh2_os400qc3_rsa_signv()).
#if LIBSSH2_RSA_SHA2
int ssh2_rsa_sha2_verify(ssh2_rsa_ctx *rsa, size_t hash_len,
const unsigned char *sig, size_t sig_len,
const unsigned char *m, size_t m_len)
{
src/os400qc3.c:2438
- Same as the SHA2 block above: this SHA1 verify wrapper should also be gated with
LIBSSH2_RSAso RSA-disabled builds don't compile RSA-only code just becauseLIBSSH2_RSA_SHA1defaults to 1 in the backend header.
int ssh2_rsa_sha1_verify(ssh2_rsa_ctx *rsa,
const unsigned char *sig, size_t sig_len,
const unsigned char *m, size_t m_len)
{
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #if LIBSSH2_RSA | ||
| if(mbedtls_pk_get_type(pkey) != MBEDTLS_PK_RSA) | ||
| #endif | ||
| { | ||
| mbedtls_pk_free(pkey); | ||
| return ssh2_err(session, LIBSSH2_ERROR_FILE, "Key type not supported"); | ||
| } |
There was a problem hiding this comment.
Not like this, but sure. No-RSA builds are very low priority, the LIBSSH2_RSA and LIBSSH2_RSA_SHA2 guards are rather informational, than something we put focus on.
There was a problem hiding this comment.
The ownership issue is real, fixing in separate PR after merging this.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
RELEASE-NOTES:8
- This item is labeled as “hostkey methods”, but
LIBSSH2_RSA_SHA1is also used for RSA/SHA1 signatures in publickey auth (e.g.userauth_supported_key_sign_algs()conditionally includes,ssh-rsa). Consider broadening the wording so it’s clear this option affects RSA/SHA1 signature methods beyond hostkey negotiation.
- SHA1-based hostkey methods: `ssh-rsa`, `[email protected]`
You can enable them with `-DLIBSSH2_RSA_SHA1_ENABLE`.
| { | ||
| mbedtls_pk_free(pkey); | ||
| return ssh2_err(session, LIBSSH2_ERROR_FILE, "Key type not supported"); | ||
| } |
There was a problem hiding this comment.
Sure, sure. In another PR.
"`mbed_pub_priv_key()` frees `pkey` on the unsupported-key path, but the caller (`ssh2_pub_privkey()`) unconditionally calls `mbedtls_pk_free(&pkey)` after this helper returns. That makes this a double-free on the error path (memory corruption). The helper should not free `pkey`; leave ownership/cleanup to the caller." Reported by Copilot Bug: #2501 (comment) Bug: #2501 (comment) Follow-up to 186f1a2 #132 Closes #2502
They are
ssh-rsaand[email protected], and insecure dueto their reliance on SHA1 hashes.
Also:
hostkey_method_ssh_rsa_init().mbed_pub_priv_key().#endifcomments.-DLIBSSH2_DSA_ENABLEto its place.Follow-up to b7ab0fa disable DSA by default #1435
LIBSSH2_RSA, replacingLIBSSH2_RSA_SHA1to keep test coverage. Keep using the latter fortesting SHA1-based signatures in
test_auth_pubkey_ok_rsa_signed.Follow-up to 3e14d67 #2444
Follow-up to 99f9353 #2443
https://github.com/libssh2/libssh2/pull/2501/files?w=1