Skip to content

[WIP] Fix Windows SSH-key authentication failure issue#5

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-ssh-key-authentication-issue
Draft

[WIP] Fix Windows SSH-key authentication failure issue#5
Copilot wants to merge 2 commits intomainfrom
copilot/fix-ssh-key-authentication-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 21, 2026

  • Fix decode_secret_keyload_secret_key in ssh/mod.rs (was passing file path as PEM content)
  • Fix decode_secret_keyload_secret_key in sftp_client.rs (same bug)
  • Fix Windows tilde expansion: support USERPROFILE env var and ~\ path prefix via expand_tilde() helper
  • Extract expand_tilde_with_home() for isolated unit testing (no env mutation)
  • Add unit tests: expand_tilde (Unix, Windows backslash, USERPROFILE fallback, absolute path, no home)
  • Add unit tests: key-loading error paths (missing file → "not found", invalid PEM → "Failed to load SSH key")

…ix Windows tilde expansion

Agent-Logs-Url: https://github.com/GOODBOY008/r-shell/sessions/43009ee7-28d3-4906-aa8c-054fbe0f1f24

Co-authored-by: GOODBOY008 <13617900+GOODBOY008@users.noreply.github.com>
@GOODBOY008 GOODBOY008 marked this pull request as ready for review April 21, 2026 04:55
Copilot AI review requested due to automatic review settings April 21, 2026 04:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR fixes Windows SSH public-key authentication by correctly loading keys from file paths and improving ~ expansion behavior across platforms, backed by new unit tests.

Changes:

  • Replace decode_secret_key usage with russh_keys::load_secret_key in SSH and SFTP clients (file-path based key loading).
  • Add expand_tilde() / expand_tilde_with_home() to support Windows ~\ and USERPROFILE fallback.
  • Add unit tests for tilde expansion and key-loading error paths.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src-tauri/src/ssh/tests.rs Adds unit tests for tilde expansion and SSH key-loading error messages.
src-tauri/src/ssh/mod.rs Introduces expand_tilde helpers and switches to russh_keys::load_secret_key.
src-tauri/src/sftp_client.rs Switches key loading to russh_keys::load_secret_key and reuses expand_tilde.

Comment on lines +77 to +94
fn test_load_key_missing_file_returns_error() {
// Attempting to connect with a non-existent key file should return a
// clear "file not found" error, not a "could not read key" error that
// would arise if the path were mistakenly passed as PEM content.
let config = SshConfig {
host: "127.0.0.1".to_string(),
port: 22,
username: "user".to_string(),
auth_method: AuthMethod::PublicKey {
key_path: "/nonexistent/path/to/key".to_string(),
passphrase: None,
},
};
let rt = tokio::runtime::Runtime::new().unwrap();
let err = rt.block_on(async {
let mut client = SshClient::new();
client.connect(&config).await.unwrap_err()
});
Comment on lines +108 to +110
let mut _tmp = tempfile::NamedTempFile::new().expect("create temp file");
write!(_tmp, "this is not a valid pem key").expect("write temp file");
let path = _tmp.path().to_str().unwrap().to_string();
Comment thread src-tauri/src/ssh/mod.rs
Comment on lines +91 to +100
pub(crate) fn expand_tilde_with_home(path: &str, home: Option<&str>) -> String {
if path.starts_with("~/") || path.starts_with("~\\") {
if let Some(h) = home {
if !h.is_empty() {
return path.replacen('~', h, 1);
}
}
}
path.to_string()
}
@GOODBOY008 GOODBOY008 marked this pull request as draft April 23, 2026 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows SSH-key authentication fails: "Could not read key" (but works with native ssh)

3 participants