From b0acf035020f4faf1d2179a9cfc1f39a09e75908 Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Sun, 25 Aug 2024 15:13:46 +0200 Subject: [PATCH] cleanup --- Cargo.toml | 7 +++++++ bin/cluelessh-agentctl/Cargo.toml | 5 ++++- bin/cluelessh-dos/Cargo.toml | 5 ++++- bin/cluelessh-dos/src/main.rs | 2 +- bin/cluelessh-faked/Cargo.toml | 2 +- bin/cluelessh-key/Cargo.toml | 5 ++++- bin/cluelessh-key/src/main.rs | 2 +- bin/cluelessh/Cargo.toml | 5 ++++- bin/cluelessh/src/main.rs | 5 ++--- bin/cluelesshd/Cargo.toml | 3 +++ lib/cluelessh-agent-client/Cargo.toml | 5 ++++- lib/cluelessh-agent-client/src/lib.rs | 8 ++++---- lib/cluelessh-connection/Cargo.toml | 3 +++ lib/cluelessh-keys/Cargo.toml | 3 +++ lib/cluelessh-keys/src/lib.rs | 12 ++++++------ lib/cluelessh-protocol/Cargo.toml | 2 ++ lib/cluelessh-tokio/Cargo.toml | 5 ++++- lib/cluelessh-tokio/src/client.rs | 2 +- lib/cluelessh-transport/Cargo.toml | 3 +++ lib/cluelessh-transport/src/crypto.rs | 4 ++-- lib/cluelessh-transport/src/parse.rs | 2 +- lib/cluelessh-transport/src/server.rs | 20 ++++++++++++++++++++ 22 files changed, 84 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7ea01c4..b23309f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,5 +5,12 @@ members = [ ] resolver = "2" +[workspace.lints.clippy] +type_complexity = "allow" +too_many_arguments = "allow" +new_without_default = "allow" +useless_format = "allow" + [workspace.dependencies] tracing = "0.1.40" +eyre = "0.6.12" \ No newline at end of file diff --git a/bin/cluelessh-agentctl/Cargo.toml b/bin/cluelessh-agentctl/Cargo.toml index c165ab9..30e8025 100644 --- a/bin/cluelessh-agentctl/Cargo.toml +++ b/bin/cluelessh-agentctl/Cargo.toml @@ -8,10 +8,13 @@ cluelessh-agent-client = { path = "../../lib/cluelessh-agent-client" } cluelessh-transport = { path = "../../lib/cluelessh-transport" } clap = { version = "4.5.16", features = ["derive"] } -eyre = "0.6.12" +eyre.workspace = true tokio = { version = "1.39.3", features = ["full"] } tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } rpassword = "7.3.1" sha2 = "0.10.8" hex = "0.4.3" pem = "3.0.4" + +[lints] +workspace = true diff --git a/bin/cluelessh-dos/Cargo.toml b/bin/cluelessh-dos/Cargo.toml index fc69f2b..9d9543a 100644 --- a/bin/cluelessh-dos/Cargo.toml +++ b/bin/cluelessh-dos/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" cluelessh-protocol = { path = "../../lib/cluelessh-protocol" } cluelessh-transport = { path = "../../lib/cluelessh-transport" } clap = { version = "4.5.15", features = ["derive"] } -eyre = "0.6.12" +eyre.workspace = true rand = "0.8.5" tokio = { version = "1.39.2", features = ["full"] } tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] } @@ -15,3 +15,6 @@ tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] } tracing.workspace = true rpassword = "7.3.1" futures = "0.3.30" + +[lints] +workspace = true diff --git a/bin/cluelessh-dos/src/main.rs b/bin/cluelessh-dos/src/main.rs index c19eab3..1c25b7f 100644 --- a/bin/cluelessh-dos/src/main.rs +++ b/bin/cluelessh-dos/src/main.rs @@ -110,7 +110,7 @@ async fn execute_attempt_inner(mut conn: TcpStream) -> eyre::Result<()> { .wrap_err("writing response")?; } - if let Some(_) = state.auth() { + if state.auth().is_some() { unreachable!(); } diff --git a/bin/cluelessh-faked/Cargo.toml b/bin/cluelessh-faked/Cargo.toml index 5d5bf96..dfc4979 100644 --- a/bin/cluelessh-faked/Cargo.toml +++ b/bin/cluelessh-faked/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -eyre = "0.6.12" +eyre.workspace = true hex-literal = "0.4.1" rand = "0.8.5" cluelessh-protocol = { path = "../../lib/cluelessh-protocol" } diff --git a/bin/cluelessh-key/Cargo.toml b/bin/cluelessh-key/Cargo.toml index 83c8496..3ca3f76 100644 --- a/bin/cluelessh-key/Cargo.toml +++ b/bin/cluelessh-key/Cargo.toml @@ -5,10 +5,13 @@ edition = "2021" [dependencies] clap = { version = "4.5.16", features = ["derive"] } -eyre = "0.6.12" +eyre.workspace = true tracing.workspace = true cluelessh-keys = { path = "../../lib/cluelessh-keys" } base64 = "0.22.1" rpassword = "7.3.1" pem = "3.0.4" + +[lints] +workspace = true diff --git a/bin/cluelessh-key/src/main.rs b/bin/cluelessh-key/src/main.rs index 4a86265..86c2d6b 100644 --- a/bin/cluelessh-key/src/main.rs +++ b/bin/cluelessh-key/src/main.rs @@ -113,7 +113,7 @@ fn info(id_file: &Path, decrypt: bool, show_private: bool) -> eyre::Result<()> { } let file = - std::fs::read(&id_file).wrap_err_with(|| format!("reading file {}", id_file.display()))?; + std::fs::read(id_file).wrap_err_with(|| format!("reading file {}", id_file.display()))?; let keys = cluelessh_keys::EncryptedPrivateKeys::parse(&file)?; diff --git a/bin/cluelessh/Cargo.toml b/bin/cluelessh/Cargo.toml index 131ca8a..b22f0e0 100644 --- a/bin/cluelessh/Cargo.toml +++ b/bin/cluelessh/Cargo.toml @@ -10,7 +10,7 @@ cluelessh-agent-client = { path = "../../lib/cluelessh-agent-client" } cluelessh-tokio = { path = "../../lib/cluelessh-tokio" } clap = { version = "4.5.15", features = ["derive"] } -eyre = "0.6.12" +eyre.workspace = true rand = "0.8.5" tokio = { version = "1.39.2", features = ["full"] } tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] } @@ -18,3 +18,6 @@ tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] } tracing.workspace = true rpassword = "7.3.1" users = "0.11.0" + +[lints] +workspace = true diff --git a/bin/cluelessh/src/main.rs b/bin/cluelessh/src/main.rs index f88e9c9..fec2e7d 100644 --- a/bin/cluelessh/src/main.rs +++ b/bin/cluelessh/src/main.rs @@ -59,11 +59,10 @@ async fn main() -> eyre::Result<()> { let destination = args.destination.clone(); Box::pin(async { let result = tokio::task::spawn_blocking(move || { - let password = rpassword::prompt_password(format!( + rpassword::prompt_password(format!( "{}@{}'s password: ", username, destination - )); - password + )) }) .await?; result.wrap_err("failed to prompt password") diff --git a/bin/cluelesshd/Cargo.toml b/bin/cluelesshd/Cargo.toml index 6c15fba..9b3f4ad 100644 --- a/bin/cluelesshd/Cargo.toml +++ b/bin/cluelesshd/Cargo.toml @@ -7,3 +7,6 @@ edition = "2021" cluelessh-protocol = { path = "../../lib/cluelessh-protocol" } cluelessh-tokio = { path = "../../lib/cluelessh-tokio" } cluelessh-transport = { path = "../../lib/cluelessh-transport" } + +[lints] +workspace = true diff --git a/lib/cluelessh-agent-client/Cargo.toml b/lib/cluelessh-agent-client/Cargo.toml index 85a0d05..8f9bc1f 100644 --- a/lib/cluelessh-agent-client/Cargo.toml +++ b/lib/cluelessh-agent-client/Cargo.toml @@ -4,7 +4,10 @@ version = "0.1.0" edition = "2021" [dependencies] -eyre = "0.6.12" +eyre.workspace = true cluelessh-transport = { path = "../cluelessh-transport" } tokio = { version = "1.39.3", features = ["net"] } tracing.workspace = true + +[lints] +workspace = true diff --git a/lib/cluelessh-agent-client/src/lib.rs b/lib/cluelessh-agent-client/src/lib.rs index cb4eb30..6be4574 100644 --- a/lib/cluelessh-agent-client/src/lib.rs +++ b/lib/cluelessh-agent-client/src/lib.rs @@ -45,7 +45,7 @@ impl Request { } => { p.u8(numbers::SSH_AGENTC_ADD_IDENTITY); p.string(key_type.as_bytes()); - p.raw(&key_contents); + p.raw(key_contents); p.string(key_comment.as_bytes()); } Self::RemoveAllIdentities => p.u8(numbers::SSH_AGENTC_REMOVE_ALL_IDENTITIES), @@ -56,8 +56,8 @@ impl Request { flags, } => { p.u8(numbers::SSH_AGENTC_SIGN_REQUEST); - p.string(&key_blob); - p.string(&data); + p.string(key_blob); + p.string(data); p.u32(*flags); } Self::Lock { passphrase } => { @@ -186,7 +186,7 @@ impl AgentConnection { mut bytes: &'a [u8], ) -> impl Iterator> + 'a { std::iter::from_fn(move || -> Option> { - if bytes.len() == 0 { + if bytes.is_empty() { return None; } match self.packets.recv_plaintext_bytes(bytes) { diff --git a/lib/cluelessh-connection/Cargo.toml b/lib/cluelessh-connection/Cargo.toml index dd65e27..784c820 100644 --- a/lib/cluelessh-connection/Cargo.toml +++ b/lib/cluelessh-connection/Cargo.toml @@ -9,3 +9,6 @@ tracing.workspace = true [dev-dependencies] tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } + +[lints] +workspace = true diff --git a/lib/cluelessh-keys/Cargo.toml b/lib/cluelessh-keys/Cargo.toml index 74f51fa..927576c 100644 --- a/lib/cluelessh-keys/Cargo.toml +++ b/lib/cluelessh-keys/Cargo.toml @@ -11,3 +11,6 @@ ed25519-dalek = { version = "2.1.1", features = ["rand_core"] } pem = "3.0.4" rand = "0.8.5" cluelessh-transport = { path = "../cluelessh-transport" } + +[lints] +workspace = true diff --git a/lib/cluelessh-keys/src/lib.rs b/lib/cluelessh-keys/src/lib.rs index b1b165a..f4ccb48 100644 --- a/lib/cluelessh-keys/src/lib.rs +++ b/lib/cluelessh-keys/src/lib.rs @@ -92,12 +92,12 @@ impl EncryptedPrivateKeys { p.array(*MAGIC); p.string(self.cipher.name().as_bytes()); p.string(self.kdf.name().as_bytes()); - p.string(&self.kdf.options()); + p.string(self.kdf.options()); p.u32(self.public_keys.len() as u32); for pubkey in &self.public_keys { - p.string(&pubkey.to_wire_encoding()); + p.string(pubkey.to_wire_encoding()); } p.string(&self.encrypted_private_keys); @@ -124,7 +124,7 @@ impl EncryptedPrivateKeys { let mut output = vec![0; key_size + iv_size]; self.kdf.derive(passphrase, &mut output)?; let (key, iv) = output.split_at(key_size); - self.cipher.crypt_in_place(&mut data, &key, &iv); + self.cipher.crypt_in_place(&mut data, key, iv); } Ok(data) } @@ -254,12 +254,12 @@ impl PlaintextPrivateKey { } => { // enc.string(b"ssh-ed25519"); - enc.string(&public_key); + enc.string(public_key); let combined = private_key.len() + public_key.len(); enc.u32(combined as u32); enc.raw(&private_key); enc.raw(&public_key); - enc.string(&self.comment.as_bytes()); + enc.string(self.comment.as_bytes()); } } @@ -282,7 +282,7 @@ impl PlaintextPrivateKey { let (key, iv) = output.split_at(key_size); params .cipher - .crypt_in_place(&mut encrypted_private_keys, &key, &iv); + .crypt_in_place(&mut encrypted_private_keys, key, iv); } } diff --git a/lib/cluelessh-protocol/Cargo.toml b/lib/cluelessh-protocol/Cargo.toml index 4b5f34b..ffd1240 100644 --- a/lib/cluelessh-protocol/Cargo.toml +++ b/lib/cluelessh-protocol/Cargo.toml @@ -9,3 +9,5 @@ cluelessh-connection = { path = "../cluelessh-connection" } cluelessh-transport = { path = "../cluelessh-transport" } tracing.workspace = true +[lints] +workspace = true diff --git a/lib/cluelessh-tokio/Cargo.toml b/lib/cluelessh-tokio/Cargo.toml index 7483db0..b5a9f3c 100644 --- a/lib/cluelessh-tokio/Cargo.toml +++ b/lib/cluelessh-tokio/Cargo.toml @@ -4,10 +4,13 @@ version = "0.1.0" edition = "2021" [dependencies] -eyre = "0.6.12" +eyre.workspace = true cluelessh-transport = { path = "../cluelessh-transport" } cluelessh-connection = { path = "../cluelessh-connection" } cluelessh-protocol = { path = "../cluelessh-protocol" } tokio = { version = "1.39.3", features = ["net"] } tracing.workspace = true futures = "0.3.30" + +[lints] +workspace = true diff --git a/lib/cluelessh-tokio/src/client.rs b/lib/cluelessh-tokio/src/client.rs index 22d30ba..47848fb 100644 --- a/lib/cluelessh-tokio/src/client.rs +++ b/lib/cluelessh-tokio/src/client.rs @@ -3,7 +3,7 @@ use std::{collections::HashMap, pin::Pin, sync::Arc}; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use cluelessh_protocol::{ChannelUpdateKind, SshStatus}; -use eyre::{bail, ContextCompat, OptionExt, Result, WrapErr}; +use eyre::{bail, ContextCompat, Result, WrapErr}; use futures::future::BoxFuture; use tokio::io::{AsyncRead, AsyncWrite}; use tracing::{debug, info, warn}; diff --git a/lib/cluelessh-transport/Cargo.toml b/lib/cluelessh-transport/Cargo.toml index cbf89fa..738714d 100644 --- a/lib/cluelessh-transport/Cargo.toml +++ b/lib/cluelessh-transport/Cargo.toml @@ -22,3 +22,6 @@ base64 = "0.22.1" [dev-dependencies] hex-literal = "0.4.1" + +[lints] +workspace = true diff --git a/lib/cluelessh-transport/src/crypto.rs b/lib/cluelessh-transport/src/crypto.rs index 0884199..56d1032 100644 --- a/lib/cluelessh-transport/src/crypto.rs +++ b/lib/cluelessh-transport/src/crypto.rs @@ -152,7 +152,7 @@ pub fn hostkey_ed25519(hostkey_private: Vec) -> HostKeySigningAlgorithm { // let mut data = Writer::new(); data.string(b"ssh-ed25519"); - data.string(&signature.to_bytes()); + data.string(signature.to_bytes()); EncodedSshSignature(data.finish()) }, verify: |public_key, message, signature| { @@ -216,7 +216,7 @@ pub fn hostkey_ecdsa_sha2_p256(hostkey_private: Vec) -> HostKeySigningAlgori let mut signature_blob = Writer::new(); signature_blob.mpint(p256::U256::from(r.as_ref())); signature_blob.mpint(p256::U256::from(s.as_ref())); - data.string(&signature_blob.finish()); + data.string(signature_blob.finish()); EncodedSshSignature(data.finish()) }, verify: |_public_key, _message, _signature| todo!("ecdsa p256 verification"), diff --git a/lib/cluelessh-transport/src/parse.rs b/lib/cluelessh-transport/src/parse.rs index 6bb2fba..3077f78 100644 --- a/lib/cluelessh-transport/src/parse.rs +++ b/lib/cluelessh-transport/src/parse.rs @@ -29,7 +29,7 @@ impl<'a> Parser<'a> { } pub fn remaining(&self) -> &[u8] { - &self.0 + self.0 } pub fn has_data(&self) -> bool { diff --git a/lib/cluelessh-transport/src/server.rs b/lib/cluelessh-transport/src/server.rs index 7f8d817..67cea19 100644 --- a/lib/cluelessh-transport/src/server.rs +++ b/lib/cluelessh-transport/src/server.rs @@ -99,6 +99,26 @@ impl ServerConnection { return Err(SshStatus::Disconnect); } + Some(numbers::SSH_MSG_IGNORE) => { + // + let mut p = Parser::new(&packet.payload[1..]); + let _ = p.string()?; + continue; + } + Some(numbers::SSH_MSG_DEBUG) => { + // + let mut p = Parser::new(&packet.payload[1..]); + let always_display = p.bool()?; + let msg = p.utf8_string()?; + let _language_tag = p.utf8_string()?; + + if always_display { + info!(%msg, "Received debug message (SSH_MSG_DEBUG)"); + } else { + debug!(%msg, "Received debug message (SSH_MSG_DEBUG)") + } + continue; + } _ => {} }