Skip to content

Fix "No common key algorithm" connection failure for RSA-keyed SSH servers#3

Merged
GOODBOY008 merged 3 commits intomainfrom
copilot/fix-connection-failure-key-algorithm
Mar 31, 2026
Merged

Fix "No common key algorithm" connection failure for RSA-keyed SSH servers#3
GOODBOY008 merged 3 commits intomainfrom
copilot/fix-connection-failure-key-algorithm

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

russh gates RSA host key algorithm support behind an openssl Cargo feature that was not enabled. Servers advertising only RSA host keys (ssh-rsa, rsa-sha2-256, rsa-sha2-512) caused an immediate NoCommonKeyAlgo negotiation failure.

Changes

  • Cargo.toml: Enable both openssl and vendored-openssl features on russh and russh-keys to compile in RSA support. The openssl feature is needed for #[cfg(feature = "openssl")] guards in russh's source code, while vendored-openssl compiles OpenSSL from source via the openssl-src crate, eliminating the need for a system-installed OpenSSL library (which is unavailable on Windows CI).
  • ssh/mod.rs: Define a shared pub static PREFERRED_HOST_KEY_ALGOS covering all supported algorithms in preference order, and pass it via a custom client::Config instead of Config::default().
  • sftp_client.rs: Apply the same client::Config override using the shared constant for consistency.
pub static PREFERRED_HOST_KEY_ALGOS: &[russh_keys::key::Name] = &[
    russh_keys::key::ED25519,
    russh_keys::key::ECDSA_SHA2_NISTP256,
    russh_keys::key::ECDSA_SHA2_NISTP521,
    russh_keys::key::RSA_SHA2_256,  // requires openssl feature
    russh_keys::key::RSA_SHA2_512,  // requires openssl feature
    russh_keys::key::SSH_RSA,       // legacy sha1-rsa for older servers
];

Legacy ssh-rsa (SHA-1) is included at the end of the preference list to remain compatible with older servers that don't advertise the newer rsa-sha2-* variants.

Original prompt

Connection Failed
Failed to connect to 23.94.68.53:22: No common key algorithm

…algorithm error

Enable the `openssl` feature on russh/russh-keys so that RSA key algorithms
(rsa-sha2-256, rsa-sha2-512, ssh-rsa) are compiled in.  Customise the
client::Config preferred host-key list to include all three RSA variants in
addition to the modern Ed25519/ECDSA ones, making r-shell compatible with
older SSH servers that only advertise an RSA host key.

Agent-Logs-Url: https://github.com/GOODBOY008/r-shell/sessions/eeff48ae-3142-4a4b-90c4-9a817c3cfb6a

Co-authored-by: GOODBOY008 <13617900+GOODBOY008@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix connection failure due to no common key algorithm Fix "No common key algorithm" connection failure for RSA-keyed SSH servers Mar 31, 2026
Copilot AI requested a review from GOODBOY008 March 31, 2026 13:56
@GOODBOY008
Copy link
Copy Markdown
Owner

@copilot this pr fix error :Connection Failed Failed to connect to 23.94.68.53:22: No common key algorithm , but current ci failed with:``` Updating crates.io index
Compiling pkg-config v0.3.32
Compiling vcpkg v0.2.15
Compiling foreign-types-shared v0.1.1
Compiling openssl v0.10.75
Compiling foreign-types v0.3.2
Compiling openssl-macros v0.1.1
Compiling r-shell v1.3.0 (D:\a\r-shell\r-shell\src-tauri)
Compiling openssl-sys v0.9.111
warning: openssl-sys@0.9.111: Could not find directory of OpenSSL installation, and this -sys crate cannot proceed without this knowledge. If OpenSSL is installed and this crate had trouble finding it, you can set the `OPENSSL_DIR` environment variable for the compilation process. See stderr section below for further information.
error: failed to run custom build command for `openssl-sys v0.9.111`

Caused by:
process didn't exit successfully: D:\a\r-shell\r-shell\src-tauri\target\debug\build\openssl-sys-129ca7eb00c9b20d\build-script-main (exit code: 101)
--- stdout
cargo:rustc-check-cfg=cfg(osslconf, values("OPENSSL_NO_OCB", "OPENSSL_NO_SM4", "OPENSSL_NO_SEED", "OPENSSL_NO_CHACHA", "OPENSSL_NO_CAST", "OPENSSL_NO_IDEA", "OPENSSL_NO_CAMELLIA", "OPENSSL_NO_RC4", "OPENSSL_NO_BF", "OPENSSL_NO_PSK", "OPENSSL_NO_DEPRECATED_3_0", "OPENSSL_NO_SCRYPT", "OPENSSL_NO_SM3", "OPENSSL_NO_RMD160", "OPENSSL_NO_EC2M", "OPENSSL_NO_OCSP", "OPENSSL_NO_CMS", "OPENSSL_NO_COMP", "OPENSSL_NO_SOCK", "OPENSSL_NO_STDIO", "OPENSSL_NO_EC", "OPENSSL_NO_SSL3_METHOD", "OPENSSL_NO_KRB5", "OPENSSL_NO_TLSEXT", "OPENSSL_NO_SRP", "OPENSSL_NO_SRTP", "OPENSSL_NO_RFC3779", "OPENSSL_NO_SHA", "OPENSSL_NO_NEXTPROTONEG", "OPENSSL_NO_ENGINE", "OPENSSL_NO_BUF_FREELISTS", "OPENSSL_NO_RC2"))
cargo:rustc-check-cfg=cfg(openssl)
cargo:rustc-check-cfg=cfg(libressl)
cargo:rustc-check-cfg=cfg(boringssl)
cargo:rustc-check-cfg=cfg(awslc)
cargo:rustc-check-cfg=cfg(libressl250)
cargo:rustc-check-cfg=cfg(libressl251)
cargo:rustc-check-cfg=cfg(libressl252)
cargo:rustc-check-cfg=cfg(libressl261)
cargo:rustc-check-cfg=cfg(libressl270)
cargo:rustc-check-cfg=cfg(libressl271)
cargo:rustc-check-cfg=cfg(libressl273)
cargo:rustc-check-cfg=cfg(libressl280)
cargo:rustc-check-cfg=cfg(libressl281)
cargo:rustc-check-cfg=cfg(libressl291)
cargo:rustc-check-cfg=cfg(libressl310)
cargo:rustc-check-cfg=cfg(libressl321)
cargo:rustc-check-cfg=cfg(libressl332)
cargo:rustc-check-cfg=cfg(libressl340)
cargo:rustc-check-cfg=cfg(libressl350)
cargo:rustc-check-cfg=cfg(libressl360)
cargo:rustc-check-cfg=cfg(libressl361)
cargo:rustc-check-cfg=cfg(libressl370)
cargo:rustc-check-cfg=cfg(libressl380)
cargo:rustc-check-cfg=cfg(libressl381)
cargo:rustc-check-cfg=cfg(libressl382)
cargo:rustc-check-cfg=cfg(libressl390)
cargo:rustc-check-cfg=cfg(libressl400)
cargo:rustc-check-cfg=cfg(libressl410)
cargo:rustc-check-cfg=cfg(libressl420)
cargo:rustc-check-cfg=cfg(ossl101)
cargo:rustc-check-cfg=cfg(ossl102)
cargo:rustc-check-cfg=cfg(ossl102f)
cargo:rustc-check-cfg=cfg(ossl102h)
cargo:rustc-check-cfg=cfg(ossl110)
cargo:rustc-check-cfg=cfg(ossl110f)
cargo:rustc-check-cfg=cfg(ossl110g)
cargo:rustc-check-cfg=cfg(ossl110h)
cargo:rustc-check-cfg=cfg(ossl111)
cargo:rustc-check-cfg=cfg(ossl111b)
cargo:rustc-check-cfg=cfg(ossl111c)
cargo:rustc-check-cfg=cfg(ossl111d)
cargo:rustc-check-cfg=cfg(ossl300)
cargo:rustc-check-cfg=cfg(ossl310)
cargo:rustc-check-cfg=cfg(ossl320)
cargo:rustc-check-cfg=cfg(ossl330)
cargo:rustc-check-cfg=cfg(ossl340)
cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR
X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR unset
cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
OPENSSL_LIB_DIR unset
cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR
X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR unset
cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
OPENSSL_INCLUDE_DIR unset
cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR
X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR unset
cargo:rerun-if-env-changed=OPENSSL_DIR
OPENSSL_DIR unset
note: vcpkg did not find openssl: Could not find Vcpkg tree: No vcpkg installation found. Set the VCPKG_ROOT environment variable or run 'vcpkg integrate install'
cargo:warning=Could not find directory of OpenSSL installation, and this -sys crate cannot proceed without this knowledge. If OpenSSL is installed and this crate had trouble finding it, you can set the OPENSSL_DIR environment variable for the compilation process. See stderr section below for further information.

--- stderr

Could not find directory of OpenSSL installation, and this -sys crate cannot
proceed without this knowledge. If OpenSSL is installed and this crate had
trouble finding it, you can set the OPENSSL_DIR environment variable for the
compilation process.

Make sure you also have the development packages of openssl installed.
For example, libssl-dev on Ubuntu or openssl-devel on Fedora.

If you're in a situation where you think the directory should be found
automatically, please open a bug at https://github.com/rust-openssl/rust-openssl
and include information about your system as well as this message.

$HOST = x86_64-pc-windows-msvc
$TARGET = x86_64-pc-windows-msvc
openssl-sys = 0.9.111

It looks like you're compiling for MSVC but we couldn't detect an OpenSSL
installation. If there isn't one installed then you can try the rust-openssl
README for more information about how to download precompiled binaries of
OpenSSL:

https://github.com/rust-openssl/rust-openssl#windows

warning: build failed, waiting for other jobs to finish...
Error: Process completed with exit code 1.```

The `openssl` feature requires a system-installed OpenSSL library, which
is not available on the Windows CI runner. Switching to `vendored-openssl`
compiles OpenSSL from source via the openssl-src crate, removing the
system dependency. Both `openssl` (for #[cfg(feature="openssl")] guards)
and `vendored-openssl` (for cross-platform builds) are needed on russh.

Agent-Logs-Url: https://github.com/GOODBOY008/r-shell/sessions/f595a194-989f-4da2-9f8f-b3ec5f2a6d15

Co-authored-by: GOODBOY008 <13617900+GOODBOY008@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot this pr fix error :Connection Failed Failed to connect to 23.94.68.53:22: No common key algorithm , but current ci failed with:``` Updating crates.io index
Com...

Fixed in 7ce6f18. The openssl feature requires a system-installed OpenSSL library, which isn't available on the Windows CI runner. Switched to vendored-openssl which compiles OpenSSL from source via the openssl-src crate, removing the system dependency. Both openssl (needed for #[cfg(feature = "openssl")] guards in russh) and vendored-openssl (for cross-platform builds) are now enabled.

@GOODBOY008 GOODBOY008 marked this pull request as ready for review March 31, 2026 15:32
Copilot AI review requested due to automatic review settings March 31, 2026 15:32
@GOODBOY008 GOODBOY008 merged commit 2c43fbe into main Mar 31, 2026
5 checks passed
@GOODBOY008 GOODBOY008 deleted the copilot/fix-connection-failure-key-algorithm branch March 31, 2026 15:33
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes SSH connection negotiation failures against RSA-only servers by enabling RSA host key algorithm support in russh and explicitly advertising a preferred host key algorithm list during connection setup.

Changes:

  • Enable OpenSSL-backed RSA support for russh (and vendored OpenSSL builds) via Cargo features.
  • Introduce a shared preferred host key algorithm list and apply it to SSH connections.
  • Apply the same SSH client config override to the standalone SFTP client for consistency.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.

File Description
src-tauri/Cargo.toml Enables openssl + vendored-openssl features for russh (and vendored OpenSSL for russh-keys) to support RSA host key algorithms.
src-tauri/Cargo.lock Locks new OpenSSL/vendored build dependencies resulting from enabling the features.
src-tauri/src/ssh/mod.rs Adds PREFERRED_HOST_KEY_ALGOS and wires it into client::Config for SSH connection negotiation.
src-tauri/src/sftp_client.rs Uses the shared preferred host key algorithm list for SFTP’s SSH transport config.

Comment on lines +29 to +30
russh = { version = "0.43", features = ["openssl", "vendored-openssl"] }
russh-keys = { version = "0.43", features = ["vendored-openssl"] }
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

PR description says both openssl and vendored-openssl features are enabled on russh-keys, but Cargo.toml only enables vendored-openssl. Please either add the openssl feature here for consistency/clarity, or update the PR description/docs to reflect that vendored-openssl is sufficient.

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +16
/// reachable. The `openssl` feature on `russh` / `russh-keys` must be enabled
/// for the RSA entries to have any effect.
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

The comment says the openssl feature must be enabled on both russh and russh-keys, but the dependency config currently only enables openssl on russh. Consider clarifying this comment (or the dependency features) so it’s unambiguous which crate features are actually required for RSA host key algorithms to be available.

Suggested change
/// reachable. The `openssl` feature on `russh` / `russh-keys` must be enabled
/// for the RSA entries to have any effect.
/// reachable. Support for these RSA algorithms depends on enabling the
/// appropriate RSA-related features for the `russh` / `russh-keys` crates
/// (for example, the `openssl` feature where applicable).

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +23
/// least preferred. RSA variants (including the legacy `ssh-rsa` / SHA-1) are
/// included so that older servers that only offer RSA host keys are still
/// reachable. The `openssl` feature on `russh` / `russh-keys` must be enabled
/// for the RSA entries to have any effect.
pub static PREFERRED_HOST_KEY_ALGOS: &[russh_keys::key::Name] = &[
russh_keys::key::ED25519,
russh_keys::key::ECDSA_SHA2_NISTP256,
russh_keys::key::ECDSA_SHA2_NISTP521,
russh_keys::key::RSA_SHA2_256,
russh_keys::key::RSA_SHA2_512,
russh_keys::key::SSH_RSA,
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

Including russh_keys::key::SSH_RSA enables legacy SHA-1 ssh-rsa host keys, which is considered insecure and is disabled by default in many SSH stacks. If compatibility is required, consider making ssh-rsa opt-in via a user setting (or only enabling it when explicitly requested) and/or surfacing a clear warning when negotiating it.

Suggested change
/// least preferred. RSA variants (including the legacy `ssh-rsa` / SHA-1) are
/// included so that older servers that only offer RSA host keys are still
/// reachable. The `openssl` feature on `russh` / `russh-keys` must be enabled
/// for the RSA entries to have any effect.
pub static PREFERRED_HOST_KEY_ALGOS: &[russh_keys::key::Name] = &[
russh_keys::key::ED25519,
russh_keys::key::ECDSA_SHA2_NISTP256,
russh_keys::key::ECDSA_SHA2_NISTP521,
russh_keys::key::RSA_SHA2_256,
russh_keys::key::RSA_SHA2_512,
russh_keys::key::SSH_RSA,
/// least preferred. Only modern, non–SHA-1 algorithms are enabled by default.
/// The `openssl` feature on `russh` / `russh-keys` must be enabled for the RSA
/// entries to have any effect.
pub static PREFERRED_HOST_KEY_ALGOS: &[russh_keys::key::Name] = &[
russh_keys::key::ED25519,
russh_keys::key::ECDSA_SHA2_NISTP256,
russh_keys::key::ECDSA_SHA2_NISTP521,
russh_keys::key::RSA_SHA2_256,
russh_keys::key::RSA_SHA2_512,

Copilot uses AI. Check for mistakes.
Comment on lines 83 to +90
pub async fn connect(&mut self, config: &SshConfig) -> Result<()> {
let ssh_config = client::Config::default();
let ssh_config = client::Config {
preferred: russh::Preferred {
key: PREFERRED_HOST_KEY_ALGOS,
..russh::Preferred::DEFAULT
},
..client::Config::default()
};
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

This change introduces a custom host key algorithm preference list that affects connection negotiation. There are existing tests in this module; consider adding a small unit test that asserts the preferred host key algorithm list and/or that the client config uses it, so regressions don’t silently reintroduce NoCommonKeyAlgo failures.

Copilot uses AI. Check for mistakes.
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.

3 participants