mirror of
https://github.com/Noratrieb/cluelessh.git
synced 2026-01-14 16:35:06 +01:00
remove rand from ssh-transport
This commit is contained in:
parent
8d795e73b2
commit
c8842ef22a
5 changed files with 18 additions and 20 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"] }
|
||||
|
|
|
|||
18
src/main.rs
18
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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue