Repository navigation
Conversation
userauth_publickey()userauth_publickey()
There was a problem hiding this comment.
Pull request overview
This PR refactors public-key user authentication by merging the previously separate “from file” and “from memory/blob” helper paths into a single internal helper (userauth_publickey()), aligning with the broader effort in #2354 to reduce duplicated key-loading logic and backend divergence.
Changes:
- Consolidates
userauth_publickey_fromfile()anduserauth_publickey_frommemory()into a unifieduserauth_publickey()helper that supports file or blob inputs. - Simplifies error propagation in hostbased auth setup by using a single post-branch
rccheck with a consistent comment. - Updates internal comments to reflect the new consolidated helper name and behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
vszakats
added a commit
that referenced
this pull request
Jul 21, 2026
Replace separate codepath for loading private keys from filenames vs. memory buffers (blobs), with unified functions that handle both. Either filename or blob pointer + size must be passed to these functions. To reduce code duplication and small/large differences and bugs between these codepaths. Also to improve readability and ease maintenance. Also fix: - mbedtls: do not pass redundant null-terminator to `mbed_parse_openssh_key()` on in ECDSA blob codepath. (benign) - libgcrypt: add support for RSA/DSA blobs. - openssl: error handling code now applies to from-file codepath. Reported-and-alternate-patch-by: Martin Nowak Fixes #1652 - openssl: add file support for `ssh2_sk_pubkey()`. (not exposed via public API at this time.) - openssl: fix to call `OSSL_INIT_IF_NEEDED()` from `ssh2_pub_privkey()`. (for wolfSSL-debug enabled builds.) - openssl: fix error code returned by `ssh2_sk_pubkey()`. (to be consistent with rest of code.) - openssl: fix potential NULL deref in `ssh2_ed25519_new_priv()` blob codepaths. - openssl: fix potential dangling pointer in RSA, DSA, ECDSA codepaths (both file and blob) if BIO init failed. - os400qc3: fix uninitialized structs in `os400_pub_privkey_*()`. - os400qc3: drop unused local variable. Notes: - os400: use wrappers without actually merging the code. They are very different and difficult to read, also not possible to build test. - openssl: ed25519 loader code has outlier code where the file/blob code is different (both rather short.) - openssl: there is a file/blob function pair left to merge. - pem: there remain two pairs of file/blob internal APIs. Follow-up to 6a95116 #2362 Follow-up to fe9442b #2359 Follow-up to 5b94157 #2354 Closes #2379
1 task done
vszakats
added a commit
that referenced
this pull request
Jul 22, 2026
To further merge file/blob codepaths/behavior, and to reduce branching at callers. Also: - pem: add internal API `ssh2_file_to_blob()` to load a (PEM) file into memory. Use it internally. Make sure to null-terminate the returned blob, primarily for mbedTLS. - mbedtls, os400qc3: use `ssh2_file_to_blob()`. - pem: fix to return `LIBSSH2_ERROR_ALGO_UNSUPPORTED` in `ssh2_pem_parse()` in no-MD5 builds (was: -1). - os400qc3: fix to scrub data before free in `try_pem_load()`. Note: - os400qc3: `try_pem_load()` has unique behavior of allowing multiple instances of private keys within a single file, but only when loading from a file. I could not positively confirm this to be valid/standard private file format, nor find a comment or commit message explaining the behavior. I've added (untested) support for this using the blob codepath, because the `FILE *` method is now gone from `pem.c`. It also seems one contributing factor why the file (vs blob) tracks are much different in this backend. After this patch, both could use `ssh2_pem_parse()` and possibly unify `os400_pub_privkey_file/blob()` and `os400_rsa_new_priv_from_file/blob()`. Follow-up to b560cb4 #2379 Follow-up to 6a95116 #2362 Follow-up to fe9442b #2359 Follow-up to 5b94157 #2354 Closes #2388
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to 5b94157 #2354