diff --git a/Cargo.lock b/Cargo.lock index f1925ec..5308d44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -326,6 +326,7 @@ version = "0.1.0" dependencies = [ "eyre", "hex-literal", + "rand", "ssh-protocol", "tokio", "tracing", @@ -937,7 +938,6 @@ dependencies = [ "hex-literal", "p256", "poly1305", - "rand", "rand_core", "sha2", "subtle", diff --git a/Cargo.toml b/Cargo.toml index c2c805c..19a02f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" [dependencies] eyre = "0.6.12" hex-literal = "0.4.1" +rand = "0.8.5" ssh-protocol = { path = "./ssh-protocol" } tokio = { version = "1.39.2", features = ["full"] } diff --git a/src/main.rs b/src/main.rs index 32a92cc..938fc0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::{collections::HashMap, net::SocketAddr}; use eyre::{Context, Result}; +use rand::RngCore; use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, net::{TcpListener, TcpStream}, @@ -9,11 +10,18 @@ use tracing::{debug, error, info, info_span, Instrument}; use ssh_protocol::{ connection::{ChannelOpen, ChannelOperationKind, ChannelRequest}, - transport::{self, ThreadRngRand}, + transport::{self}, ChannelUpdateKind, ServerConnection, SshStatus, }; use tracing_subscriber::EnvFilter; +struct ThreadRngRand; +impl ssh_protocol::transport::SshRng for ThreadRngRand { + fn fill_bytes(&mut self, dest: &mut [u8]) { + rand::thread_rng().fill_bytes(dest); + } +} + #[tokio::main] async fn main() -> eyre::Result<()> { let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); @@ -190,11 +198,9 @@ async fn handle_connection( total_sent_data.extend_from_slice(&data); } else { info!(channel = %update.number, "Reached stdin limit"); - state.do_operation( - update.number.construct_op(ChannelOperationKind::Data( - b"Thanks Hayley!\n".to_vec(), - )), - ); + state.do_operation(update.number.construct_op(ChannelOperationKind::Data( + b"Thanks Hayley!\n".to_vec(), + ))); state.do_operation(update.number.construct_op(ChannelOperationKind::Close)); } diff --git a/ssh-transport/Cargo.toml b/ssh-transport/Cargo.toml index 49bc96b..c214362 100644 --- a/ssh-transport/Cargo.toml +++ b/ssh-transport/Cargo.toml @@ -9,11 +9,10 @@ aes-gcm = "0.10.3" chacha20 = "0.9.1" crypto-bigint = "0.5.5" ctr = "0.9.2" -ed25519-dalek = { version = "2.1.1" } +ed25519-dalek = "2.1.1" eyre = "0.6.12" p256 = { version = "0.13.2", features = ["ecdh", "ecdsa"] } poly1305 = "0.8.0" -rand = "0.8.5" rand_core = "0.6.4" sha2 = "0.10.8" subtle = "2.6.1" diff --git a/ssh-transport/src/lib.rs b/ssh-transport/src/lib.rs index a01ea04..9d1a4c3 100644 --- a/ssh-transport/src/lib.rs +++ b/ssh-transport/src/lib.rs @@ -9,7 +9,6 @@ use std::{collections::VecDeque, mem::take}; use crypto::{AlgorithmName, AlgorithmNegotiation, EncryptionAlgorithm, HostKeySigningAlgorithm}; use packet::{KeyExchangeEcDhInitPacket, KeyExchangeInitPacket, Packet, PacketTransport}; use parse::{NameList, Parser, Writer}; -use rand::RngCore; use sha2::Digest; use tracing::{debug, info, trace}; @@ -79,8 +78,8 @@ pub trait SshRng { fn fill_bytes(&mut self, dest: &mut [u8]); } struct SshRngRandAdapter<'a>(&'a mut dyn SshRng); -impl rand::CryptoRng for SshRngRandAdapter<'_> {} -impl rand::RngCore for SshRngRandAdapter<'_> { +impl rand_core::CryptoRng for SshRngRandAdapter<'_> {} +impl rand_core::RngCore for SshRngRandAdapter<'_> { fn next_u32(&mut self) -> u32 { self.next_u64() as u32 } @@ -93,19 +92,12 @@ impl rand::RngCore for SshRngRandAdapter<'_> { self.0.fill_bytes(dest); } - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> std::result::Result<(), rand::Error> { + fn try_fill_bytes(&mut self, dest: &mut [u8]) -> std::result::Result<(), rand_core::Error> { self.fill_bytes(dest); Ok(()) } } -pub struct ThreadRngRand; -impl SshRng for ThreadRngRand { - fn fill_bytes(&mut self, dest: &mut [u8]) { - rand::thread_rng().fill_bytes(dest); - } -} - impl ServerConnection { pub fn new(rng: impl SshRng + Send + Sync + 'static) -> Self { Self {