Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not panic at non-ssh server connections #78

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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