Skip to content

Commit

Permalink
added Handler::auth_publickey_offered
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Sep 27, 2023
1 parent fe3717f commit df34137
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
23 changes: 19 additions & 4 deletions russh/src/server/encrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl Encrypted {
} else if auth_user.is_empty() {
auth_user.clear();
auth_user.push_str(user);
let (h, auth) = handler.auth_publickey(user, &pubkey).await?;
let (h, auth) = handler.auth_publickey_offered(user, &pubkey).await?;
handler = h;
auth == Auth::Accept
} else {
Expand All @@ -425,8 +425,23 @@ impl Encrypted {
pubkey.verify_client_auth(&buf, sig)
}) {
debug!("signature verified");
server_auth_request_success(&mut self.write);
self.state = EncryptedState::InitCompression;
let (h, auth) = handler.auth_publickey(user, &pubkey).await?;
handler = h;

if auth == Auth::Accept {
server_auth_request_success(&mut self.write);
self.state = EncryptedState::InitCompression;
} else {
if let Auth::Reject {
proceed_with_methods: Some(proceed_with_methods),
} = auth
{
auth_request.methods = proceed_with_methods;
}
auth_request.partial_success = false;
auth_user.clear();
reject_auth_request(until, &mut self.write, auth_request).await;
}
} else {
debug!("signature wrong");
reject_auth_request(until, &mut self.write, auth_request).await;
Expand All @@ -438,7 +453,7 @@ impl Encrypted {
} else {
auth_user.clear();
auth_user.push_str(user);
let (h, auth) = handler.auth_publickey(user, &pubkey).await?;
let (h, auth) = handler.auth_publickey_offered(user, &pubkey).await?;
handler = h;
match auth {
Auth::Accept => {
Expand Down
18 changes: 18 additions & 0 deletions russh/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,24 @@ pub trait Handler: Sized {
/// `config.auth_rejection_time`, except if this method takes more
/// time than that.
#[allow(unused_variables)]
async fn auth_publickey_offered(
self,
user: &str,
public_key: &key::PublicKey,
) -> Result<(Self, Auth), Self::Error> {
Ok((
self,
Auth::Accept,
))
}

/// Check authentication using the "publickey" method. This method
/// is called after the signature has been verified and key
/// ownership has been confirmed.
/// Russh guarantees that rejection happens in constant time
/// `config.auth_rejection_time`, except if this method takes more
/// time than that.
#[allow(unused_variables)]
async fn auth_publickey(
self,
user: &str,
Expand Down

0 comments on commit df34137

Please sign in to comment.