Skip to content

Commit

Permalink
Add authentication_banner method to server::Handler (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicEric authored Dec 16, 2024
1 parent 85c45cb commit 030468a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions russh/src/server/encrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl Session {
debug!("request: {:?}", request);
if request == "ssh-userauth" {
let auth_request = server_accept_service(
self.common.config.as_ref().auth_banner,
handler.authentication_banner().await?,
self.common.config.as_ref().methods,
&mut enc.write,
)?;
Expand Down Expand Up @@ -242,7 +242,7 @@ impl Session {
}

fn server_accept_service(
banner: Option<&str>,
banner: Option<String>,
methods: MethodSet,
buffer: &mut CryptoVec,
) -> Result<AuthRequest, crate::Error> {
Expand Down
11 changes: 7 additions & 4 deletions russh/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ pub struct Config {
pub server_id: SshId,
/// Authentication methods proposed to the client.
pub methods: auth::MethodSet,
/// The authentication banner, usually a warning message shown to the client.
pub auth_banner: Option<&'static str>,
/// Authentication rejections must happen in constant time for
/// security reasons. Russh does not handle this by default.
pub auth_rejection_time: std::time::Duration,
Expand Down Expand Up @@ -104,7 +102,6 @@ impl Default for Config {
env!("CARGO_PKG_VERSION")
)),
methods: auth::MethodSet::all(),
auth_banner: None,
auth_rejection_time: std::time::Duration::from_secs(1),
auth_rejection_time_initial: None,
keys: Vec::new(),
Expand All @@ -128,7 +125,6 @@ impl Debug for Config {
f.debug_struct("Config")
.field("server_id", &self.server_id)
.field("methods", &self.methods)
.field("auth_banner", &self.auth_banner)
.field("auth_rejection_time", &self.auth_rejection_time)
.field(
"auth_rejection_time_initial",
Expand Down Expand Up @@ -289,6 +285,13 @@ pub trait Handler: Sized {
Ok(())
}

/// Called when authentication starts but before it is successful.
/// Return value is an authentication banner, usually a warning message shown to the client.
#[allow(unused_variables)]
async fn authentication_banner(&mut self) -> Result<Option<String>, Self::Error> {
Ok(None)
}

/// Called when the client closes a channel.
#[allow(unused_variables)]
async fn channel_close(
Expand Down

0 comments on commit 030468a

Please sign in to comment.