mirror of
https://github.com/Noratrieb/cluelessh.git
synced 2026-01-16 09:25:04 +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 = [
|
dependencies = [
|
||||||
"eyre",
|
"eyre",
|
||||||
"hex-literal",
|
"hex-literal",
|
||||||
|
"rand",
|
||||||
"ssh-protocol",
|
"ssh-protocol",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
|
@ -937,7 +938,6 @@ dependencies = [
|
||||||
"hex-literal",
|
"hex-literal",
|
||||||
"p256",
|
"p256",
|
||||||
"poly1305",
|
"poly1305",
|
||||||
"rand",
|
|
||||||
"rand_core",
|
"rand_core",
|
||||||
"sha2",
|
"sha2",
|
||||||
"subtle",
|
"subtle",
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eyre = "0.6.12"
|
eyre = "0.6.12"
|
||||||
hex-literal = "0.4.1"
|
hex-literal = "0.4.1"
|
||||||
|
rand = "0.8.5"
|
||||||
ssh-protocol = { path = "./ssh-protocol" }
|
ssh-protocol = { path = "./ssh-protocol" }
|
||||||
|
|
||||||
tokio = { version = "1.39.2", features = ["full"] }
|
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 std::{collections::HashMap, net::SocketAddr};
|
||||||
|
|
||||||
use eyre::{Context, Result};
|
use eyre::{Context, Result};
|
||||||
|
use rand::RngCore;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncReadExt, AsyncWriteExt},
|
io::{AsyncReadExt, AsyncWriteExt},
|
||||||
net::{TcpListener, TcpStream},
|
net::{TcpListener, TcpStream},
|
||||||
|
|
@ -9,11 +10,18 @@ use tracing::{debug, error, info, info_span, Instrument};
|
||||||
|
|
||||||
use ssh_protocol::{
|
use ssh_protocol::{
|
||||||
connection::{ChannelOpen, ChannelOperationKind, ChannelRequest},
|
connection::{ChannelOpen, ChannelOperationKind, ChannelRequest},
|
||||||
transport::{self, ThreadRngRand},
|
transport::{self},
|
||||||
ChannelUpdateKind, ServerConnection, SshStatus,
|
ChannelUpdateKind, ServerConnection, SshStatus,
|
||||||
};
|
};
|
||||||
use tracing_subscriber::EnvFilter;
|
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]
|
#[tokio::main]
|
||||||
async fn main() -> eyre::Result<()> {
|
async fn main() -> eyre::Result<()> {
|
||||||
let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
|
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);
|
total_sent_data.extend_from_slice(&data);
|
||||||
} else {
|
} else {
|
||||||
info!(channel = %update.number, "Reached stdin limit");
|
info!(channel = %update.number, "Reached stdin limit");
|
||||||
state.do_operation(
|
state.do_operation(update.number.construct_op(ChannelOperationKind::Data(
|
||||||
update.number.construct_op(ChannelOperationKind::Data(
|
b"Thanks Hayley!\n".to_vec(),
|
||||||
b"Thanks Hayley!\n".to_vec(),
|
)));
|
||||||
)),
|
|
||||||
);
|
|
||||||
state.do_operation(update.number.construct_op(ChannelOperationKind::Close));
|
state.do_operation(update.number.construct_op(ChannelOperationKind::Close));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,10 @@ aes-gcm = "0.10.3"
|
||||||
chacha20 = "0.9.1"
|
chacha20 = "0.9.1"
|
||||||
crypto-bigint = "0.5.5"
|
crypto-bigint = "0.5.5"
|
||||||
ctr = "0.9.2"
|
ctr = "0.9.2"
|
||||||
ed25519-dalek = { version = "2.1.1" }
|
ed25519-dalek = "2.1.1"
|
||||||
eyre = "0.6.12"
|
eyre = "0.6.12"
|
||||||
p256 = { version = "0.13.2", features = ["ecdh", "ecdsa"] }
|
p256 = { version = "0.13.2", features = ["ecdh", "ecdsa"] }
|
||||||
poly1305 = "0.8.0"
|
poly1305 = "0.8.0"
|
||||||
rand = "0.8.5"
|
|
||||||
rand_core = "0.6.4"
|
rand_core = "0.6.4"
|
||||||
sha2 = "0.10.8"
|
sha2 = "0.10.8"
|
||||||
subtle = "2.6.1"
|
subtle = "2.6.1"
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ use std::{collections::VecDeque, mem::take};
|
||||||
use crypto::{AlgorithmName, AlgorithmNegotiation, EncryptionAlgorithm, HostKeySigningAlgorithm};
|
use crypto::{AlgorithmName, AlgorithmNegotiation, EncryptionAlgorithm, HostKeySigningAlgorithm};
|
||||||
use packet::{KeyExchangeEcDhInitPacket, KeyExchangeInitPacket, Packet, PacketTransport};
|
use packet::{KeyExchangeEcDhInitPacket, KeyExchangeInitPacket, Packet, PacketTransport};
|
||||||
use parse::{NameList, Parser, Writer};
|
use parse::{NameList, Parser, Writer};
|
||||||
use rand::RngCore;
|
|
||||||
use sha2::Digest;
|
use sha2::Digest;
|
||||||
use tracing::{debug, info, trace};
|
use tracing::{debug, info, trace};
|
||||||
|
|
||||||
|
|
@ -79,8 +78,8 @@ pub trait SshRng {
|
||||||
fn fill_bytes(&mut self, dest: &mut [u8]);
|
fn fill_bytes(&mut self, dest: &mut [u8]);
|
||||||
}
|
}
|
||||||
struct SshRngRandAdapter<'a>(&'a mut dyn SshRng);
|
struct SshRngRandAdapter<'a>(&'a mut dyn SshRng);
|
||||||
impl rand::CryptoRng for SshRngRandAdapter<'_> {}
|
impl rand_core::CryptoRng for SshRngRandAdapter<'_> {}
|
||||||
impl rand::RngCore for SshRngRandAdapter<'_> {
|
impl rand_core::RngCore for SshRngRandAdapter<'_> {
|
||||||
fn next_u32(&mut self) -> u32 {
|
fn next_u32(&mut self) -> u32 {
|
||||||
self.next_u64() as u32
|
self.next_u64() as u32
|
||||||
}
|
}
|
||||||
|
|
@ -93,19 +92,12 @@ impl rand::RngCore for SshRngRandAdapter<'_> {
|
||||||
self.0.fill_bytes(dest);
|
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);
|
self.fill_bytes(dest);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ThreadRngRand;
|
|
||||||
impl SshRng for ThreadRngRand {
|
|
||||||
fn fill_bytes(&mut self, dest: &mut [u8]) {
|
|
||||||
rand::thread_rng().fill_bytes(dest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ServerConnection {
|
impl ServerConnection {
|
||||||
pub fn new(rng: impl SshRng + Send + Sync + 'static) -> Self {
|
pub fn new(rng: impl SshRng + Send + Sync + 'static) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue