use bssh::diagnosticln as eprintln;
pub fn is_supported_query(query: &str) -> bool {
matches!(
query.to_ascii_lowercase().as_str(),
"cipher"
| "cipher-auth"
| "mac"
| "kex"
| "kexalgorithms"
| "key"
| "key-plain"
| "key-cert"
| "key-sig"
| "protocol-version"
| "help"
)
}
pub fn handle_query(query: &str) {
match query.to_ascii_lowercase().as_str() {
"cipher" => {
println!(
"{}",
bssh::ssh::tokio_client::supported_cipher_names().join("\n")
);
}
"cipher-auth" => {
println!("aes128-gcm@openssh.com\naes256-gcm@openssh.com");
println!("chacha20-poly1305@openssh.com");
}
"mac" => {
println!(
"{}",
bssh::ssh::tokio_client::supported_mac_names().join("\n")
);
}
"kex" | "kexalgorithms" => {
println!("curve25519-sha256\ncurve25519-sha256@libssh.org");
println!("ecdh-sha2-nistp256\necdh-sha2-nistp384\necdh-sha2-nistp521");
}
"key" | "key-plain" | "key-cert" | "key-sig" => {
println!("ssh-ed25519");
println!("ecdsa-sha2-nistp256\necdsa-sha2-nistp384\necdsa-sha2-nistp521");
println!("ssh-rsa");
}
"protocol-version" => {
println!("2");
}
"help" => {
println!("Available query options:");
println!(" cipher - Supported ciphers");
println!(" cipher-auth - Authenticated encryption ciphers");
println!(" mac - Supported MAC algorithms");
println!(" kex - Supported key exchange algorithms");
println!(" key - Supported key types");
println!(" protocol-version - SSH protocol version");
}
_ => {
eprintln!("Unknown query option: {query}");
eprintln!("Use 'bssh -Q help' to see available options");
std::process::exit(1);
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn openssh_kex_algorithms_keyword_is_a_case_insensitive_query_alias() {
for query in ["kex", "KexAlgorithms", "kexalgorithms"] {
assert!(is_supported_query(query));
}
}
}