From 7696484f0b4341e72abb22d34600f94863889912 Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Mon, 12 Aug 2024 22:16:35 +0200 Subject: [PATCH] improvements and fixes --- src/main.rs | 2 ++ ssh-connection/src/lib.rs | 2 +- ssh-protocol/src/lib.rs | 1 - ssh-transport/src/lib.rs | 28 +++++++++++++++++++++++++--- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8f47202..7aebd4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,6 +87,7 @@ async fn handle_connection( .await .wrap_err("reading from connection")?; if read == 0 { + info!("Did not read any bytes from TCP stream, EOF"); return Ok(()); } @@ -100,6 +101,7 @@ async fn handle_connection( return Err(err); } SshStatus::Disconnect => { + info!("Received disconnect from client"); return Ok(()); } } diff --git a/ssh-connection/src/lib.rs b/ssh-connection/src/lib.rs index 4326eb4..094b9fc 100644 --- a/ssh-connection/src/lib.rs +++ b/ssh-connection/src/lib.rs @@ -157,8 +157,8 @@ impl ServerChannelsState { self.packets_to_send .push_back(Packet::new_msg_channel_open_confirmation( - our_number.0, sender_channel, + our_number.0, initial_window_size, max_packet_size, )); diff --git a/ssh-protocol/src/lib.rs b/ssh-protocol/src/lib.rs index f7f119c..4635ae8 100644 --- a/ssh-protocol/src/lib.rs +++ b/ssh-protocol/src/lib.rs @@ -135,7 +135,6 @@ pub mod auth { info!(%password, "Got password"); // Don't worry queen, your password is correct! self.queue_packet(Packet::new_msg_userauth_success()); - self.is_authenticated = true; } "publickey" => { diff --git a/ssh-transport/src/lib.rs b/ssh-transport/src/lib.rs index 2b3d73c..88d7234 100644 --- a/ssh-transport/src/lib.rs +++ b/ssh-transport/src/lib.rs @@ -5,8 +5,8 @@ pub mod parse; use core::str; use std::{collections::VecDeque, mem::take}; -use ed25519_dalek::ed25519::signature::Signer; use crypto::{AlgorithmName, AlgorithmNegotiation, EncryptionAlgorithm}; +use ed25519_dalek::ed25519::signature::Signer; use packet::{ DhKeyExchangeInitReplyPacket, KeyExchangeEcDhInitPacket, KeyExchangeInitPacket, Packet, PacketTransport, SshPublicKey, SshSignature, @@ -153,7 +153,26 @@ impl ServerConnection { let description = disconnect.utf8_string()?; let _language_tag = disconnect.utf8_string()?; - info!(%reason, %description, "Client disconnecting"); + let reason_string = match reason { + 1 => "SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT", + 2 => "SSH_DISCONNECT_PROTOCOL_ERROR", + 3 => "SSH_DISCONNECT_KEY_EXCHANGE_FAILED", + 4 => "SSH_DISCONNECT_RESERVED", + 5 => "SSH_DISCONNECT_MAC_ERROR", + 6 => "SSH_DISCONNECT_COMPRESSION_ERROR", + 7 => "SSH_DISCONNECT_SERVICE_NOT_AVAILABLE", + 8 => "SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED", + 9 => "SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE", + 10 => "SSH_DISCONNECT_CONNECTION_LOST", + 11 => "SSH_DISCONNECT_BY_APPLICATION", + 12 => "SSH_DISCONNECT_TOO_MANY_CONNECTIONS", + 13 => "SSH_DISCONNECT_AUTH_CANCELLED_BY_USER", + 14 => "SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE", + 15 => "SSH_DISCONNECT_ILLEGAL_USER_NAME", + _ => "", + }; + + info!(%reason, %reason_string, %description, "Client disconnecting"); return Ok(()); } @@ -179,7 +198,10 @@ impl ServerConnection { }; let kex_algorithms = AlgorithmNegotiation { - supported: vec![crypto::KEX_CURVE_25519_SHA256, crypto::KEX_ECDH_SHA2_NISTP256], + supported: vec![ + crypto::KEX_CURVE_25519_SHA256, + crypto::KEX_ECDH_SHA2_NISTP256, + ], }; let kex_algorithm = kex_algorithms.find(kex.kex_algorithms.0)?;