Skip to content

Commit

Permalink
Support ssh clients without RFC 8308 extenstion negotation mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkj authored and Eugeny committed Apr 7, 2023
1 parent a7292a2 commit 87245b5
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion russh/src/server/session.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::collections::HashMap;
use std::sync::Arc;

use russh_keys::encoding::Encoding;
use russh_keys::encoding::{Encoding, Reader};
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
use tokio::sync::mpsc::{unbounded_channel, Receiver, Sender, UnboundedReceiver, UnboundedSender};
use log::debug;

use super::*;
use crate::channels::{Channel, ChannelMsg};
use crate::kex::EXTENSION_SUPPORT_AS_CLIENT;
use crate::msg;

/// A connected server session. This type is unique to a client.
Expand Down Expand Up @@ -874,6 +875,24 @@ impl Session {

pub(crate) fn maybe_send_ext_info(&mut self) {
if let Some(ref mut enc) = self.common.encrypted {
// If client sent a ext-info-c message in the kex list, it supports RFC 8308 extension negotiation.
let mut key_extension_client = false;
if let Some(e) = &enc.exchange {
let mut r = e.client_kex_init.as_ref().reader(17);
if let Ok(kex_string) = r.read_string() {
use super::negotiation::Select;
key_extension_client = super::negotiation::Server::select(
&[EXTENSION_SUPPORT_AS_CLIENT],
kex_string,
).is_some();
}
}

if !key_extension_client {
debug!("RFC 8308 Extension Negotiation not supported by client");
return;
}

push_packet!(enc.write, {
enc.write.push(msg::EXT_INFO);
enc.write.push_u32_be(1);
Expand Down

0 comments on commit 87245b5

Please sign in to comment.