Skip to content

Commit cb5d3ba

Browse files
committed
fixed #418 - client - incorrect kex signature verification for RSA-SHA2
1 parent 52216ef commit cb5d3ba

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

russh/src/client/mod.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use std::collections::{HashMap, VecDeque};
3939
use std::convert::TryInto;
4040
use std::num::Wrapping;
4141
use std::pin::Pin;
42+
use std::str::FromStr;
4243
use std::sync::Arc;
4344

4445
use async_trait::async_trait;
@@ -49,7 +50,7 @@ use log::{debug, error, info, trace};
4950
use russh_keys::key::PrivateKeyWithHashAlg;
5051
use russh_keys::map_err;
5152
use ssh_encoding::{Decode, Encode, Reader};
52-
use ssh_key::{Certificate, PrivateKey, PublicKey};
53+
use ssh_key::{Algorithm, Certificate, PrivateKey, PublicKey};
5354
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, ReadHalf, WriteHalf};
5455
use tokio::pin;
5556
use tokio::sync::mpsc::{
@@ -1326,21 +1327,24 @@ impl KexDhDone {
13261327
.compute_exchange_hash(&pubkey_vec, &self.exchange, &mut buffer)?;
13271328

13281329
debug!("exchange hash: {:?}", hash);
1329-
let signature = {
1330+
let (sig_type, signature) = {
13301331
let mut r = &signature[..];
13311332
let sig_type = map_err!(String::decode(&mut r))?;
13321333
debug!("sig_type: {:?}", sig_type);
1333-
map_err!(Bytes::decode(&mut r))?
1334+
(
1335+
map_err!(Algorithm::from_str(&sig_type).map_err(ssh_encoding::Error::from))?,
1336+
map_err!(Bytes::decode(&mut r))?,
1337+
)
13341338
};
13351339

13361340
debug!("signature: {:?}", signature);
1337-
let signature = sig_workaround::Sig::new(pubkey.algorithm(), signature.to_vec())
1338-
.map_err(|e| {
1341+
let signature =
1342+
sig_workaround::Sig::new(sig_type, signature.to_vec()).map_err(|e| {
13391343
debug!("signature ctor failed: {e:?}");
13401344
crate::Error::WrongServerSig
13411345
})?;
1342-
if sig_workaround::verify(&pubkey, hash.as_ref(), &signature).is_err() {
1343-
debug!("wrong server sig");
1346+
if let Err(e) = sig_workaround::verify(&pubkey, hash.as_ref(), &signature) {
1347+
debug!("wrong server sig: {e:?}");
13441348
return Err(crate::Error::WrongServerSig.into());
13451349
}
13461350
hash

0 commit comments

Comments
 (0)