Skip to content

Commit

Permalink
Merge pull request #78 from HsuJv/patch_77
Browse files Browse the repository at this point in the history
Do not panic at non-ssh server connections
  • Loading branch information
HsuJv authored Oct 13, 2023
2 parents 8735a04 + 00e2ebe commit 8eeec25
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/config/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;
use tracing::*;

use crate::{
constant::{self, CLIENT_VERSION},
constant::{self, CLIENT_VERSION, SSH_MAGIC},
error::{SshError, SshResult},
model::Timeout,
};
Expand Down Expand Up @@ -33,7 +33,6 @@ where
match stream.read(&mut buf) {
Ok(i) => {
// MY TO DO: To Skip the other lines
assert_eq!(&buf[0..4], constant::SSH_MAGIC);
buf.truncate(i);
return Ok(buf);
}
Expand All @@ -59,6 +58,10 @@ impl SshVersion {
S: Read,
{
let buf = read_version(stream, timeout)?;
if &buf[0..4] != SSH_MAGIC {
error!("SSH version magic doesn't match");
error!("Probably not an ssh server");
}
let from_utf8 = String::from_utf8(buf)?;
let version_str = from_utf8.trim();
info!("server version: [{}]", version_str);
Expand Down

0 comments on commit 8eeec25

Please sign in to comment.