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

View File

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

View File

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

View File

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