From 6d2c6376286ef1ebd254d34c6163399c85550def Mon Sep 17 00:00:00 2001 From: Damian Peckett Date: Wed, 2 Dec 2026 22:46:47 +0100 Subject: [PATCH] kex: add P-256 host key negotiation support --- src/kex.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/kex.rs b/src/kex.rs index 86235814..f90325bf 100644 --- a/src/kex.rs +++ b/src/kex.rs @@ -57,6 +57,8 @@ const marker_only_kexs: &[&str] = &[ const fixed_options_hostsig: &[&str] = &[ SSH_NAME_ED25519, + #[cfg(feature = "ecdsa256")] + SSH_NAME_ECDSA256, #[cfg(feature = "rsa")] SSH_NAME_RSA_SHA256, ]; @@ -1280,11 +1282,23 @@ mod tests { #[test] fn test_each_kex() { for name in fixed_options_kex { - test_kex_allow(name) + test_kex_allow(name, SSH_NAME_ED25519, crate::KeyType::Ed25519); } } - fn test_kex_allow(chosen_kex: &'static str) { + #[cfg(feature = "ecdsa256")] + #[test] + fn test_p256_hostkey() { + for name in fixed_options_kex { + test_kex_allow(name, SSH_NAME_ECDSA256, crate::KeyType::ECDSA256); + } + } + + fn test_kex_allow( + chosen_kex: &'static str, + chosen_hostsig: &'static str, + key_type: crate::KeyType, + ) { // #![allow(unused)] init_test_log(); let mut cli_conf = kex::AlgoConfig::new(true); @@ -1293,6 +1307,8 @@ mod tests { // Use the tested kex algorithm cli_conf.kexs = LocalNames::new(); cli_conf.kexs.0.push(chosen_kex).unwrap(); + cli_conf.hostsig = LocalNames::new(); + cli_conf.hostsig.0.push(chosen_hostsig).unwrap(); // needs to be hardcoded because that's what we send. let mut s = Vec::from(crate::ident::OUR_VERSION); @@ -1300,8 +1316,7 @@ mod tests { let mut version = RemoteVersion::new(true); version.consume(s.as_slice()).unwrap(); - let keys = - [crate::SignKey::generate(crate::KeyType::Ed25519, None).unwrap()]; + let keys = [crate::SignKey::generate(key_type, None).unwrap()]; let keys: Vec<&SignKey> = keys.iter().collect(); let mut ts = TrafCatcher::new();