Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the OpenSSL backend’s OpenSSH private-key loading by consolidating the per-algorithm ossl_*_openssh_priv_new() helpers into a single shared ossl_key_from_openssh_file() implementation, reducing duplicated parsing logic across RSA/DSA/ECDSA/ED25519 key loaders.
Changes:
- Introduces
ossl_key_from_openssh_file()and routes RSA/DSA/ECDSA private-key-from-file fallbacks through it. - Simplifies
ssh2_ed25519_new_priv()control flow to use the shared file loader and a common cleanup section. - Removes the now-redundant per-algorithm
ossl_*_openssh_priv_new()helpers.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/openssl.c:3456
ossl_key_from_openssh_file()applieswant_methodfiltering for most key types, but the ECDSA security-key branch ([email protected]) ignoreswant_method. That can allow a caller that expectsssh-ecdsato successfully parse ask-ecdsa-*private key (algorithm mismatch).
if(!strcmp("[email protected]", (const char *)buf))
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
src/openssl.c:1981
ossl_key_from_openssh()expects avoid **output parameter. Passing(void **)ctxpasses a NULL/invalid address, so the parsed ED25519 key context is not returned (and can lead to returning success with*ed_ctx == NULL). Pass&ctxso the callee can store the allocated key into the localctxthat is later published incleanup:.
if(filename)
rc = ossl_key_from_openssh(session, (void **)ctx, "ssh-ed25519",
NULL, NULL, NULL,
filename, NULL, 0, passphrase);
else {
src/openssl.c:2015
- On the OpenSSH-blob fallback path, the key is currently parsed into
ed_ctx, butcleanup:then overwrites*ed_ctxwith the localctx(still NULL here), discarding the successfully parsed key and leaking it. Parse into localctx(like the PEM path) socleanup:publishes the correct value.
rc = ossl_key_from_openssh(session, (void **)ed_ctx, "ssh-ed25519",
NULL, NULL, NULL,
NULL, blob, blob_len, passphrase);
}
cleanup:
if(ed_ctx)
*ed_ctx = ctx;
else
ssh2_ed25519_free(ctx);
src/openssl.c:2901
ssh2_ecdsa_new_priv()now falls back toossl_key_from_openssh(..., want_method="ssh-ecdsa", ...), butossl_key_from_openssh()accepts[email protected]without checkingwant_method. That means an OpenSSH ECDSA-SK key can be returned here as a plainssh2_ecdsa_ctx(without the SK application/key_handle needed for signing), causing a later signing failure after this function reports success.ossl_key_from_openssh()should gate the SK-ECDSA branch the same way it gates other key types (only whenwant_methodis NULL or matches the SK method).
if(!*ec_ctx)
rc = ossl_key_from_openssh(session, (void **)ec_ctx, "ssh-ecdsa",
NULL, NULL, NULL,
filename, blob, blob_len, passphrase);
ossl_*_openssh_priv_new() functionsossl_*_openssh_priv_new() functions with ossl_key_from_openssh()
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/openssl.c:2007
- In the blob path,
ossl_key_from_openssh()is called with(void **)ed_ctx, but the followingcleanup:block always overwrites the caller output with localctx(which is still NULL on this path). This discards a successfully parsed OpenSSH key and can leak the allocated key context.
rc = ossl_key_from_openssh(session, (void **)ed_ctx, "ssh-ed25519",
NULL, NULL, NULL,
NULL, blob, blob_len, passphrase);
Merging
ossl_*_openssh_priv_new()functions and syncing the result upwith
ossl_key_from_openssh()ends up with an almost identical function(with the newly merged ones supporting filenames, not blobs). Therefore
replace these calls with the latter, and drop the redundant code.
This also syncs up recognized keys loaded from filenames with those
loaded from memory buffers.
Also:
ssh2_ed25519_new_priv()with sibling functions, also mergingits file/blob codepaths. It means the filename codepath now uses
OpenSSL's built-in loader first, and resorts to libssh2's own loader
if OpenSSL's failed.
Follow-up to b560cb4 crypto: de-duplicate/merge most file/blob codepaths #2379
Follow-up to 3bb068e #2394