Skip to content

Commit 59bae17

Browse files
committed
fixed #112 - parse and handle hostkeys-00@openssh.com requests
1 parent 11ed001 commit 59bae17

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

russh/src/client/encrypted.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::cell::RefCell;
1616

1717
use russh_cryptovec::CryptoVec;
1818
use russh_keys::encoding::{Encoding, Reader};
19+
use russh_keys::key::parse_public_key;
1920
use tokio::sync::mpsc::unbounded_channel;
2021

2122
use crate::client::{Handler, Msg, Reply, Session};
@@ -520,6 +521,34 @@ impl Session {
520521
} else {
521522
warn!("Received keepalive without reply request!");
522523
}
524+
} else if req == b"hostkeys-00@openssh.com" {
525+
let mut keys = vec![];
526+
loop {
527+
match r.read_string() {
528+
Ok(key) => {
529+
let key2 = key.clone();
530+
#[cfg(not(feature = "openssl"))]
531+
let key = parse_public_key(key).map_err(crate::Error::from);
532+
#[cfg(feature = "openssl")]
533+
let key =
534+
parse_public_key(key, None).map_err(crate::Error::from);
535+
match key {
536+
Ok(key) => keys.push(key),
537+
Err(err) => {
538+
debug!(
539+
"failed to parse announced host key {:?}: {:?}",
540+
key2, err
541+
)
542+
}
543+
}
544+
}
545+
Err(russh_keys::Error::IndexOutOfBounds) => break,
546+
x => {
547+
x.map_err(crate::Error::from)?;
548+
}
549+
}
550+
}
551+
return client.openssh_ext_host_keys_announced(keys, self).await;
523552
} else {
524553
warn!(
525554
"Unhandled global request: {:?} {:?}",

russh/src/client/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ use russh_cryptovec::CryptoVec;
9292
use russh_keys::encoding::Reader;
9393
#[cfg(feature = "openssl")]
9494
use russh_keys::key::SignatureHash;
95-
use russh_keys::key::{self, parse_public_key};
95+
use russh_keys::key::{self, parse_public_key, PublicKey};
9696
use tokio;
9797
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
9898
use tokio::net::{TcpStream, ToSocketAddrs};
@@ -1473,4 +1473,15 @@ pub trait Handler: Sized + Send {
14731473
fn adjust_window(&mut self, channel: ChannelId, window: u32) -> u32 {
14741474
window
14751475
}
1476+
1477+
/// Called when the server signals success.
1478+
#[allow(unused_variables)]
1479+
async fn openssh_ext_host_keys_announced(
1480+
self,
1481+
keys: Vec<PublicKey>,
1482+
session: Session,
1483+
) -> Result<(Self, Session), Self::Error> {
1484+
debug!("openssh_ext_hostkeys_announced: {:?}", keys);
1485+
Ok((self, session))
1486+
}
14761487
}

0 commit comments

Comments
 (0)