Skip to content

crypto: de-dupe *_supported_key_sign_algs() into userauth.c - #2249

Closed
vszakats wants to merge 5 commits into
libssh2:masterfrom
vszakats:signalgsdedupe
Closed

vszakats wants to merge 5 commits into
libssh2:masterfrom
vszakats:signalgsdedupe

Conversation

@vszakats

@vszakats vszakats commented Jul 8, 2026 •

Copy link
Copy Markdown
Member

They were shared between all crypto backends, except openssl, which
supports an extra key method. Retain this exception by using the
LIBSSH2_OPENSSL guards. This is a workaround, but I deem it fine, due
to already existing evidence for per-crypto-backend logic in non-crypto
code, and the codebase already making this exception in tests.

A better option would be introducing a crypto-feature macro flag, maybe
in a future commit. Perhaps also worth a check whether the exception is
necessary.

Ref: 3a6ab70 #1314
Follow-up to 82ffc1b #2248


  • it may also happen the exception is unnecessary. To be tested in another PR.

vszakats added 2 commits July 8, 2026 11:53
They were shared between all crypto backends, except openssl, which
supports an extra key method. Retain this exception by using the
`LIBSSH2_OPENSSL` guards. This is a workaround, but I deem it fine, due
to already existing evidence for per-crypto-backend logic in non-crypto
code, and the codebase already making this exception in tests.

A better option would be introducing a crypto-feature macro flag, maybe
in a future commit.

Ref: 3a6ab70 libssh2#1314

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR centralizes the “supported key signing algorithm upgrades” helper (RFC 8332) by removing duplicated ssh2_supported_key_sign_algs() implementations from individual crypto backend files and moving the logic into src/userauth.c, while keeping the OpenSSL/WolfSSL RSA cert exception via LIBSSH2_OPENSSL / LIBSSH2_WOLFSSL guards.

Changes:

  • Removed per-backend ssh2_supported_key_sign_algs() implementations from multiple crypto backend source files.
  • Added a userauth_supported_key_sign_algs() helper in src/userauth.c and updated the call site in userauth_key_sign_algs() to use it.
  • Preserved the OpenSSL/WolfSSL-specific handling of [email protected] via compile-time guards.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/userauth.c Adds centralized helper for supported key-signing algorithm upgrades and updates call site.
src/wincng.c Removes duplicated backend-local supported-algorithms helper.
src/os400qc3.c Removes duplicated backend-local supported-algorithms helper.
src/openssl.c Removes duplicated backend-local supported-algorithms helper (previously included cert exception).
src/mbedtls.c Removes duplicated backend-local supported-algorithms helper.
src/libgcrypt.c Removes duplicated backend-local supported-algorithms helper.
Comments suppressed due to low confidence (1)

src/userauth.c:1333

  • The Doxygen @related tag still references ssh2_supported_key_sign_algs(), but this file now calls userauth_supported_key_sign_algs() and (after this PR) there is no definition of ssh2_supported_key_sign_algs in the codebase. Update the tag to avoid stale cross-references in generated docs.
 * @abstract Upgrades the algorithm used for public key signing RFC 8332
 * @discussion Based on the incoming key_method value, this function
 * Upgrades the key method input based on user preferences,
 * server support algos and crypto backend support
 * @related ssh2_supported_key_sign_algs()
 * @param key_method current key method, usually the default key sig method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/userauth.c Resolved
Comment thread src/userauth.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/userauth.c Resolved
@vszakats vszakats closed this in 1410efa Jul 8, 2026
@vszakats
vszakats deleted the signalgsdedupe branch July 8, 2026 10:24
vszakats added a commit that referenced this pull request Aug 2, 2026
…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: #1314 (comment)
Ref: #2252 (initial fix attempt)
Follow-up to 1410efa #2249
Follow-up to 3a6ab70 #1314

Closes #2483
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants