diff --git a/bin/cluelessh-faked/src/readline.rs b/bin/cluelessh-faked/src/readline.rs index 574aa44..3d48438 100644 --- a/bin/cluelessh-faked/src/readline.rs +++ b/bin/cluelessh-faked/src/readline.rs @@ -43,7 +43,7 @@ impl InteractiveShell { 127 => { // Backspace, space, backspace. // We literally erase it. - if self.line_buf.len() > 0 { + if !self.line_buf.is_empty() { self.write(&[8, 32, 8]); self.line_buf.truncate(self.line_buf.len() - 1); } diff --git a/bin/cluelesshd/src/auth.rs b/bin/cluelesshd/src/auth.rs index 50c732f..f7d8162 100644 --- a/bin/cluelesshd/src/auth.rs +++ b/bin/cluelesshd/src/auth.rs @@ -39,11 +39,11 @@ impl UserPublicKey { let file = tokio::fs::read_to_string(sshd_dir) .await - .map_err(|err| AuthError::NoAuthorizedKeys(err))?; + .map_err(AuthError::NoAuthorizedKeys)?; let authorized_keys = AuthorizedKeys::parse(&file)?; - if let Some(key) = authorized_keys.contains(&provided_key) { + if let Some(key) = authorized_keys.contains(provided_key) { Ok(Self(key.clone())) } else { Err(AuthError::UnauthorizedPublicKey) diff --git a/bin/cluelesshd/src/main.rs b/bin/cluelesshd/src/main.rs index 61b6761..cd05106 100644 --- a/bin/cluelesshd/src/main.rs +++ b/bin/cluelesshd/src/main.rs @@ -192,7 +192,7 @@ async fn handle_connection( } }, }, - result = futures::future::try_join_all(&mut channel_tasks), if channel_tasks.len() > 0 => { + result = futures::future::try_join_all(&mut channel_tasks), if !channel_tasks.is_empty() => { match result { Ok(_) => channel_tasks.clear(), Err(err) => return Err((err as eyre::Report).wrap_err("channel task failed")), @@ -259,20 +259,17 @@ async fn handle_session_channel(user: String, channel: Channel) -> Result<()> { } } exit = state.process_exit_recv.recv() => { - match exit { - Some(exit) => { - let exit = exit?; - state.channel.send(ChannelOperationKind::Eof).await?; - // TODO: also handle exit-signal - state.channel - .send(ChannelOperationKind::Request(ChannelRequest::ExitStatus { - status: exit.code().unwrap_or(0) as u32, - })) - .await?; - state.channel.send(ChannelOperationKind::Close).await?; - return Ok(()); - } - None => {} + if let Some(exit) = exit { + let exit = exit?; + state.channel.send(ChannelOperationKind::Eof).await?; + // TODO: also handle exit-signal + state.channel + .send(ChannelOperationKind::Request(ChannelRequest::ExitStatus { + status: exit.code().unwrap_or(0) as u32, + })) + .await?; + state.channel.send(ChannelOperationKind::Close).await?; + return Ok(()); } } read = read => { @@ -346,12 +343,11 @@ impl SessionState { }; } ChannelUpdateKind::OpenFailed { .. } => todo!(), - ChannelUpdateKind::Data { data } => match &mut self.writer { - Some(pty) => { - pty.write_all(&data).await?; + ChannelUpdateKind::Data { data } => { + if let Some(writer) = &mut self.writer { + writer.write_all(&data).await?; } - None => {} - }, + } ChannelUpdateKind::Open(_) | ChannelUpdateKind::Closed | ChannelUpdateKind::ExtendedData { .. } diff --git a/lib/cluelessh-keys/src/private.rs b/lib/cluelessh-keys/src/private.rs index 5df7614..0384a41 100644 --- a/lib/cluelessh-keys/src/private.rs +++ b/lib/cluelessh-keys/src/private.rs @@ -33,6 +33,7 @@ impl Debug for PlaintextPrivateKey { } #[derive(Clone)] +#[allow(clippy::large_enum_variant)] pub enum PrivateKey { Ed25519 { public_key: ed25519_dalek::VerifyingKey, diff --git a/lib/cluelessh-tokio/src/server.rs b/lib/cluelessh-tokio/src/server.rs index 553b308..77affb7 100644 --- a/lib/cluelessh-tokio/src/server.rs +++ b/lib/cluelessh-tokio/src/server.rs @@ -24,8 +24,7 @@ use crate::{Channel, ChannelState, PendingChannel}; pub struct ServerListener { listener: TcpListener, auth_verify: ServerAuthVerify, - transport_config: cluelessh_transport::server::ServerConfig - // TODO ratelimits etc + transport_config: cluelessh_transport::server::ServerConfig, // TODO ratelimits etc } pub struct ServerConnection { @@ -80,7 +79,11 @@ impl From for Error { } impl ServerListener { - pub fn new(listener: TcpListener, auth_verify: ServerAuthVerify, transport_config: cluelessh_transport::server::ServerConfig) -> Self { + pub fn new( + listener: TcpListener, + auth_verify: ServerAuthVerify, + transport_config: cluelessh_transport::server::ServerConfig, + ) -> Self { Self { listener, auth_verify, @@ -101,7 +104,12 @@ impl ServerListener { } impl ServerConnection { - pub fn new(stream: S, peer_addr: SocketAddr, auth_verify: ServerAuthVerify, transport_config: cluelessh_transport::server::ServerConfig) -> Self { + pub fn new( + stream: S, + peer_addr: SocketAddr, + auth_verify: ServerAuthVerify, + transport_config: cluelessh_transport::server::ServerConfig, + ) -> Self { let (operations_send, operations_recv) = tokio::sync::mpsc::channel(15); let (channel_ops_send, channel_ops_recv) = tokio::sync::mpsc::channel(15); diff --git a/lib/cluelessh-transport/src/crypto.rs b/lib/cluelessh-transport/src/crypto.rs index 53887cb..dd4c68a 100644 --- a/lib/cluelessh-transport/src/crypto.rs +++ b/lib/cluelessh-transport/src/crypto.rs @@ -110,7 +110,7 @@ impl AlgorithmName for EncryptionAlgorithm { pub struct EncodedSshSignature(pub Vec); pub struct HostKeySigningAlgorithm { - private_key: PrivateKey, + private_key: Box, } impl AlgorithmName for HostKeySigningAlgorithm { @@ -121,7 +121,9 @@ impl AlgorithmName for HostKeySigningAlgorithm { impl HostKeySigningAlgorithm { pub fn new(private_key: PrivateKey) -> Self { - Self { private_key } + Self { + private_key: Box::new(private_key), + } } pub fn sign(&self, data: &[u8]) -> Signature { self.private_key.sign(data) diff --git a/lib/cluelessh-transport/src/server.rs b/lib/cluelessh-transport/src/server.rs index 7f040bc..1c27096 100644 --- a/lib/cluelessh-transport/src/server.rs +++ b/lib/cluelessh-transport/src/server.rs @@ -145,8 +145,9 @@ impl ServerConnection { let kex_algorithm = sup_algs.key_exchange.find(kex.kex_algorithms.0)?; debug!(name = %kex_algorithm.name(), "Using KEX algorithm"); - let server_host_key_algorithm = - sup_algs.hostkey_sign.find(kex.server_host_key_algorithms.0)?; + let server_host_key_algorithm = sup_algs + .hostkey_sign + .find(kex.server_host_key_algorithms.0)?; debug!(name = %server_host_key_algorithm.name(), "Using host key algorithm"); // TODO: Implement aes128-ctr