[WIP] Fix Windows SSH-key authentication failure issue#5
Draft
[WIP] Fix Windows SSH-key authentication failure issue#5
Conversation
…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>
Copilot stopped work on behalf of
GOODBOY008 due to an error
April 21, 2026 02:55
GOODBOY008
approved these changes
Apr 21, 2026
There was a problem hiding this comment.
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_keyusage withrussh_keys::load_secret_keyin SSH and SFTP clients (file-path based key loading). - Add
expand_tilde()/expand_tilde_with_home()to support Windows~\andUSERPROFILEfallback. - 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 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() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
decode_secret_key→load_secret_keyinssh/mod.rs(was passing file path as PEM content)decode_secret_key→load_secret_keyinsftp_client.rs(same bug)USERPROFILEenv var and~\path prefix viaexpand_tilde()helperexpand_tilde_with_home()for isolated unit testing (no env mutation)expand_tilde(Unix, Windows backslash, USERPROFILE fallback, absolute path, no home)