This commit is contained in:
2024-10-21 09:39:26 -07:00
committed by Adam Wick
parent a813b65535
commit b30823a502
4 changed files with 41 additions and 28 deletions

View File

@@ -9,6 +9,7 @@ use error_stack::{report, Report, ResultExt};
use std::fmt::Display; use std::fmt::Display;
use std::str::FromStr; use std::str::FromStr;
use thiserror::Error; use thiserror::Error;
use tracing::Instrument;
pub async fn hush(base_config: ClientConfiguration) -> error_stack::Result<(), OperationalError> { pub async fn hush(base_config: ClientConfiguration) -> error_stack::Result<(), OperationalError> {
match base_config.command() { match base_config.command() {
@@ -99,34 +100,43 @@ async fn connect(
.connect(resolver, 22) .connect(resolver, 22)
.await .await
.change_context(OperationalError::Connection)?; .change_context(OperationalError::Connection)?;
let stream_span = tracing::debug_span!(
"client connection",
server = %stream.peer_addr().map(|x| x.to_string()).unwrap_or_else(|_| "<unknown>".to_string()),
client = %stream.local_addr().map(|x| x.to_string()).unwrap_or_else(|_| "<unknown>".to_string()),
);
let _preamble = ssh::Preamble::read(&mut stream) let their_preamble = ssh::Preamble::read(&mut stream)
.instrument(stream_span.clone())
.await .await
.change_context(OperationalError::Connection)?; .change_context(OperationalError::Connection)?;
// if !commentary.is_empty() { let our_preamble = ssh::Preamble::default()
// tracing::debug!(?commentary, "Server sent commentary."); .write(&mut stream)
// } .instrument(stream_span)
// if !pre_message.is_empty() { .await
// for line in pre_message.lines() { .change_context(OperationalError::Connection)?;
// tracing::debug!(?line, "Server sent prefix line.");
// } if !their_preamble.preamble.is_empty() {
// } for line in their_preamble.preamble.lines() {
// tracing::info!("server: {}", line);
// let my_info = format!( }
// "SSH-2.0-{}_{}\r\n", }
// env!("CARGO_PKG_NAME"),
// env!("CARGO_PKG_VERSION") tracing::info!(
// ); software = ?their_preamble.software_name,
// connection version = ?their_preamble.software_version,
// .write_all(my_info.as_bytes()) commentary = ?their_preamble.commentary,
// .await "received server preamble"
// .map_err(OperationalError::WriteBanner)?; );
//
// assert_eq!(4096, read_buffer.len()); let mut stream = ssh::SshChannel::new(stream);
// read_buffer.fill(0); let their_initial = stream
// .read()
// let mut stream = SshChannel::new(connection); .await
.attach_printable_lazy(stream_error_info)
.change_context(OperationalError::KeyExchange)?
.ok_or_else();
// let mut rng = rand::thread_rng(); // let mut rng = rand::thread_rng();
// //
// let packet = stream // let packet = stream

View File

@@ -7,6 +7,8 @@ pub enum OperationalError {
ConfigurationError, ConfigurationError,
#[error("Failed to connect to target address")] #[error("Failed to connect to target address")]
Connection, Connection,
#[error("Failure during key exchange / agreement protocol")]
KeyExchange,
#[error("Failed to complete initial read: {0}")] #[error("Failed to complete initial read: {0}")]
InitialRead(std::io::Error), InitialRead(std::io::Error),
#[error("SSH banner was not formatted in UTF-8: {0}")] #[error("SSH banner was not formatted in UTF-8: {0}")]

View File

@@ -3,6 +3,7 @@ mod message_ids;
mod packets; mod packets;
mod preamble; mod preamble;
pub use channel::SshChannel;
pub use message_ids::SshMessageID; pub use message_ids::SshMessageID;
pub use packets::SshKeyExchangeProcessingError; pub use packets::SshKeyExchangeProcessingError;
pub use preamble::Preamble; pub use preamble::Preamble;

View File

@@ -6,10 +6,10 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct Preamble { pub struct Preamble {
preamble: String, pub preamble: String,
software_name: String, pub software_name: String,
software_version: String, pub software_version: String,
commentary: String, pub commentary: String,
} }
impl Arbitrary for Preamble { impl Arbitrary for Preamble {