mirror of
https://github.com/veeso/termscp.git
synced 2025-12-06 17:15:35 -08:00
126 new feature termscp doesnt use id rsa default ssh private key to authenticate to sftp scp endpoint (#144)
fixed issue 126 <https://github.com/veeso/termcp/issues/126>
This commit is contained in:
committed by
veeso
parent
efd2235ff3
commit
251b125cbb
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,6 +1,7 @@
|
||||
# Changelog
|
||||
|
||||
- [Changelog](#changelog)
|
||||
- [0.11.0](#0110)
|
||||
- [0.10.0](#0100)
|
||||
- [0.9.0](#090)
|
||||
- [0.8.2](#082)
|
||||
@@ -26,6 +27,19 @@
|
||||
|
||||
---
|
||||
|
||||
## 0.11.0
|
||||
|
||||
Released on ??
|
||||
|
||||
> 🦥 The lazy update
|
||||
|
||||
- **Bugfix**:
|
||||
- Fixed [Issue 126](https://github.com/veeso/termscp/issues/126)
|
||||
- Fixed [Issue 141](https://github.com/veeso/termscp/issues/141)
|
||||
- Dependencies:
|
||||
- Bump `remotefs-ssh` to `0.1.3`
|
||||
- Bump `ssh2-config` to `0.1.4`
|
||||
|
||||
## 0.10.0
|
||||
|
||||
Released on 15/10/2022
|
||||
|
||||
8
Cargo.lock
generated
8
Cargo.lock
generated
@@ -2070,9 +2070,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "remotefs-ssh"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "190106b53b839cf094172d2f1bc14e8d2846a69de06b239f11c2fc353080e9e0"
|
||||
checksum = "8bcccc51bbdd0d32e1d3ab7076edd03943a195a267809cbceba6ec40e9d54f93"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"lazy_static",
|
||||
@@ -2548,9 +2548,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ssh2-config"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23ab9de63060578308d874ed89c9e362884506cb7f7f9e350af4dd3679ac321a"
|
||||
checksum = "36ab5061c49144b158574b19c0e19d21ae97bed7f7bcf438dfe21fa27a46b633"
|
||||
dependencies = [
|
||||
"dirs",
|
||||
"thiserror",
|
||||
|
||||
@@ -54,7 +54,7 @@ rpassword = "^7.0"
|
||||
self_update = { version = "^0.32", default-features = false, features = [ "rustls", "archive-tar", "archive-zip", "compression-flate2", "compression-zip-deflate" ] }
|
||||
serde = { version = "^1", features = [ "derive" ] }
|
||||
simplelog = "^0.12"
|
||||
ssh2-config = "^0.1.3"
|
||||
ssh2-config = "^0.1.4"
|
||||
tempfile = "^3.2"
|
||||
thiserror = "^1"
|
||||
toml = "^0.5"
|
||||
@@ -77,12 +77,12 @@ with-keyring = [ "keyring" ]
|
||||
[target."cfg(target_family = \"windows\")"]
|
||||
[target."cfg(target_family = \"windows\")".dependencies]
|
||||
remotefs-ftp = { version = "^0.1.2", features = [ "native-tls" ] }
|
||||
remotefs-ssh = "^0.1.2"
|
||||
remotefs-ssh = "^0.1.3"
|
||||
|
||||
[target."cfg(target_family = \"unix\")"]
|
||||
[target."cfg(target_family = \"unix\")".dependencies]
|
||||
remotefs-ftp = { version = "^0.1.2", features = [ "vendored", "native-tls" ] }
|
||||
remotefs-ssh = { version = "^0.1.2", features = [ "ssh2-vendored" ] }
|
||||
remotefs-ssh = { version = "^0.1.3", features = [ "ssh2-vendored" ] }
|
||||
users = "0.11.0"
|
||||
|
||||
[profile.dev]
|
||||
|
||||
@@ -119,7 +119,7 @@ mod tests {
|
||||
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::HashMap;
|
||||
use std::io::{Seek, SeekFrom};
|
||||
use std::io::Seek;
|
||||
use std::path::PathBuf;
|
||||
use tuirealm::tui::style::Color;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ use ssh2_config::SshConfig;
|
||||
use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct SshKeyStorage {
|
||||
/// Association between {user}@{host} and RSA key path
|
||||
hosts: HashMap<String, PathBuf>,
|
||||
@@ -18,15 +19,6 @@ pub struct SshKeyStorage {
|
||||
}
|
||||
|
||||
impl SshKeyStorage {
|
||||
/// Create an empty ssh key storage; used in case `ConfigClient` is not available
|
||||
#[cfg(test)]
|
||||
pub fn empty() -> Self {
|
||||
SshKeyStorage {
|
||||
hosts: HashMap::new(),
|
||||
ssh_config: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Make mapkey from host and username
|
||||
fn make_mapkey(host: &str, username: &str) -> String {
|
||||
format!("{username}@{host}")
|
||||
@@ -61,16 +53,15 @@ impl SshKeyStorage {
|
||||
|
||||
/// Resolve host via ssh2 configuration
|
||||
fn resolve_host_in_ssh2_configuration(&self, host: &str) -> Option<PathBuf> {
|
||||
if let Some(config) = self.ssh_config.as_ref() {
|
||||
let params = config.query(host);
|
||||
params
|
||||
self.ssh_config.as_ref().and_then(|x| {
|
||||
let key = x
|
||||
.query(host)
|
||||
.identity_file
|
||||
.as_ref()
|
||||
.and_then(|x| x.get(0).cloned())
|
||||
} else {
|
||||
debug!("ssh2 config is not available; no key has been found");
|
||||
None
|
||||
}
|
||||
.and_then(|x| x.get(0).cloned());
|
||||
|
||||
key
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +76,9 @@ impl SshKeyStorageTrait for SshKeyStorage {
|
||||
username, host
|
||||
);
|
||||
// otherwise search in configuration
|
||||
self.resolve_host_in_ssh2_configuration(host)
|
||||
let key = self.resolve_host_in_ssh2_configuration(host)?;
|
||||
debug!("Found key in SSH config for {host}: {}", key.display());
|
||||
Some(key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,13 +179,13 @@ Host test
|
||||
|
||||
#[test]
|
||||
fn test_system_sshkey_storage_empty() {
|
||||
let storage: SshKeyStorage = SshKeyStorage::empty();
|
||||
let storage: SshKeyStorage = SshKeyStorage::default();
|
||||
assert_eq!(storage.hosts.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_system_sshkey_storage_add() {
|
||||
let mut storage: SshKeyStorage = SshKeyStorage::empty();
|
||||
let mut storage: SshKeyStorage = SshKeyStorage::default();
|
||||
storage.add_key("deskichup", "veeso", PathBuf::from("/tmp/omar"));
|
||||
assert_eq!(
|
||||
*storage.resolve("deskichup", "veeso").unwrap(),
|
||||
|
||||
Reference in New Issue
Block a user