mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: connect to SFTP servers with no authentication (#3916)
Co-authored-by: yadokani389 <155296849+yadokani389@users.noreply.github.com>
This commit is contained in:
parent
88848932fc
commit
c4c533e3ef
1 changed files with 26 additions and 6 deletions
|
|
@ -93,8 +93,10 @@ impl Conn {
|
||||||
self.connect_by_key_and_cert(pref).await
|
self.connect_by_key_and_cert(pref).await
|
||||||
} else if !self.config.key_file.as_os_str().is_empty() {
|
} else if !self.config.key_file.as_os_str().is_empty() {
|
||||||
self.connect_by_key(pref).await
|
self.connect_by_key(pref).await
|
||||||
} else {
|
} else if !self.config.identity_agent.as_os_str().is_empty() {
|
||||||
self.connect_by_agent(pref).await
|
self.connect_by_agent(pref).await
|
||||||
|
} else {
|
||||||
|
self.connect_by_none(pref).await
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
let channel = session.channel_open_session().await?;
|
let channel = session.channel_open_session().await?;
|
||||||
|
|
@ -222,15 +224,13 @@ impl Conn {
|
||||||
russh::keys::agent::client::AgentClient::connect_named_pipe(identity_agent).await?;
|
russh::keys::agent::client::AgentClient::connect_named_pipe(identity_agent).await?;
|
||||||
|
|
||||||
let identities = agent.request_identities().await?;
|
let identities = agent.request_identities().await?;
|
||||||
if identities.is_empty() {
|
let identity_count = identities.len();
|
||||||
return Err(cfg_err!("No keys found in SSH agent"));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut session =
|
let mut session =
|
||||||
russh::client::connect(pref, (self.config.host.as_str(), self.config.port), self).await?;
|
russh::client::connect(pref, (self.config.host.as_str(), self.config.port), self).await?;
|
||||||
|
|
||||||
|
let hash_alg = session.best_supported_rsa_hash().await?.flatten();
|
||||||
for identity in identities {
|
for identity in identities {
|
||||||
let hash_alg = session.best_supported_rsa_hash().await?.flatten();
|
|
||||||
let result = match identity {
|
let result = match identity {
|
||||||
AgentIdentity::PublicKey { key, .. } => {
|
AgentIdentity::PublicKey { key, .. } => {
|
||||||
session.authenticate_publickey_with(&self.config.user, key, hash_alg, &mut agent).await
|
session.authenticate_publickey_with(&self.config.user, key, hash_alg, &mut agent).await
|
||||||
|
|
@ -248,6 +248,26 @@ impl Conn {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(cfg_err!("Identity agent authentication failed"))
|
if session.authenticate_none(&self.config.user).await?.success() {
|
||||||
|
Ok(session)
|
||||||
|
} else if identity_count == 0 {
|
||||||
|
Err(cfg_err!("No keys found in SSH agent"))
|
||||||
|
} else {
|
||||||
|
Err(cfg_err!("Identity agent authentication failed"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn connect_by_none(
|
||||||
|
self,
|
||||||
|
pref: Arc<russh::client::Config>,
|
||||||
|
) -> Result<russh::client::Handle<Self>, russh::Error> {
|
||||||
|
let mut session =
|
||||||
|
russh::client::connect(pref, (self.config.host.as_str(), self.config.port), self).await?;
|
||||||
|
|
||||||
|
if session.authenticate_none(&self.config.user).await?.success() {
|
||||||
|
Ok(session)
|
||||||
|
} else {
|
||||||
|
Err(cfg_err!("None authentication failed"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue