Skip to content

Commit

Permalink
delete ssh-ed25519 加密
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 20, 2022
1 parent d0ec38a commit 68f0d28
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/algorithm/mod.rs
Expand Up @@ -36,7 +36,7 @@ impl Kex {
}

pub enum PubKey {
SshEd25519,
// SshEd25519,
#[cfg(feature = "dangerous-rsa-sha1")]
SshRsa,
RsaSha2_256,
Expand All @@ -45,7 +45,7 @@ pub enum PubKey {
impl PubKey {
pub(crate) fn as_str(&self) -> &'static str {
match self {
PubKey::SshEd25519 => constant::pubkey::SSH_ED25519,
// PubKey::SshEd25519 => constant::pubkey::SSH_ED25519,
#[cfg(feature = "dangerous-rsa-sha1")]
PubKey::SshRsa => constant::pubkey::SSH_RSA,
PubKey::RsaSha2_256 => constant::pubkey::RSA_SHA2_256,
Expand Down
4 changes: 2 additions & 2 deletions src/algorithm/public_key/mod.rs
Expand Up @@ -7,7 +7,7 @@ mod rsa;
use self::rsa::RsaSha1;
use self::rsa::RsaSha256;
use crate::constant::algorithms as constant;
use ed25519::Ed25519;
// use ed25519::Ed25519;

/// # 公钥算法
/// 主要用于对服务端签名的验证
Expand All @@ -21,7 +21,7 @@ pub(crate) trait PublicKey: Send + Sync {

pub(crate) fn from(s: &str) -> Box<dyn PublicKey> {
match s {
constant::pubkey::SSH_ED25519 => Box::new(Ed25519::new()),
// constant::pubkey::SSH_ED25519 => Box::new(Ed25519::new()),
#[cfg(feature = "dangerous-rsa-sha1")]
constant::pubkey::SSH_RSA => Box::new(RsaSha1::new()),
constant::pubkey::RSA_SHA2_256 => Box::new(RsaSha256::new()),
Expand Down
12 changes: 10 additions & 2 deletions src/client/client_auth.rs
Expand Up @@ -8,7 +8,6 @@ use crate::{
};

use super::Client;

impl Client {
pub fn do_auth<S>(&mut self, stream: &mut S, digest: &mut Digest) -> SshResult<()>
where
Expand All @@ -24,14 +23,20 @@ impl Client {
loop {
let mut data = Data::unpack(SecPacket::from_stream(stream, self)?)?;
let message_code = data.get_u8();
// println!("[26]message_code >>>>>>>>>:{:#?}",message_code);
match message_code {
ssh_msg_code::SSH_MSG_SERVICE_ACCEPT => {
// log::info!("{:#?}",self.config);
// println!("[30] message_code >>>>>>>>>:{:#?}",tried_public_key);
if self.config.auth.key_pair.is_none() {
tried_public_key = true;
// if no private key specified
// just try password auth
// println!("[35] password>>>>>>>>>:{:#?}",tried_public_key);

self.password_authentication(stream)?
} else {
// println!("[39] public>>>>>>>>>:{:#?}",tried_public_key);
// if private key was provided
// use public key auth first, then fallback to password auth
self.public_key_authentication(stream)?
Expand All @@ -48,7 +53,7 @@ impl Client {
self.password_authentication(stream)?
} else {
log::error!("user auth failure. (password)");
return Err(SshError::from("user auth failure."));
return Err(SshError::from("user auth failure.xxxx"));
}
}
ssh_msg_code::SSH_MSG_USERAUTH_PK_OK => {
Expand Down Expand Up @@ -92,6 +97,8 @@ impl Client {
let data = {
let pubkey_alg = &self.negotiated.public_key.0[0];
log::info!("public key authentication. algorithm: {:?}", pubkey_alg);
log::info!("username: {:?}", self.config.auth.username);

let mut data = Data::new();
data.put_u8(ssh_msg_code::SSH_MSG_USERAUTH_REQUEST)
.put_str(self.config.auth.username.as_str())
Expand All @@ -108,6 +115,7 @@ impl Client {
.unwrap()
.get_blob(pubkey_alg),
);
log::info!("data: {:?}", data);
data
};
data.pack(self).write_stream(stream)
Expand Down
2 changes: 1 addition & 1 deletion src/config/algorithm.rs
Expand Up @@ -188,7 +188,7 @@ pub struct PublicKey(pub Vec<String>);
impl PublicKey {
pub fn client_default() -> Self {
PublicKey(vec![
constant::pubkey::SSH_ED25519.to_string(),
// constant::pubkey::SSH_ED25519.to_string(),
constant::pubkey::RSA_SHA2_256.to_string(),
])
}
Expand Down
2 changes: 1 addition & 1 deletion src/constant.rs
Expand Up @@ -154,7 +154,7 @@ pub mod algorithms {

/// pubkey hash algorithm
pub(crate) mod pubkey {
pub const SSH_ED25519: &str = "ssh-ed25519";
// pub const SSH_ED25519: &str = "ssh-ed25519";
#[cfg(feature = "dangerous-rsa-sha1")]
pub const SSH_RSA: &str = "ssh-rsa";
pub const RSA_SHA2_256: &str = "rsa-sha2-256";
Expand Down

0 comments on commit 68f0d28

Please sign in to comment.