aboutsummaryrefslogtreecommitdiff
path: root/src/remote.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/remote.rs')
-rw-r--r--src/remote.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/remote.rs b/src/remote.rs
index ba935ec4..4ab4d531 100644
--- a/src/remote.rs
+++ b/src/remote.rs
@@ -19,6 +19,16 @@ pub(crate) fn run_remote_client_bridge() -> std::io::Result<()> {
))
}
+pub(crate) fn print_saved_ssh_error_hint(err: &std::io::Error, target: &str) {
+ if is_remote_host_key_error(err) {
+ eprintln!(
+ "hint: saved machines use strict host-key checking; add the host key to the configured known_hosts file, then retry."
+ );
+ } else {
+ print_remote_error_hint(err, target);
+ }
+}
+
pub(crate) fn print_remote_error_hint(err: &std::io::Error, target: &str) {
if is_remote_auth_error(err) {
eprintln!(
@@ -31,6 +41,12 @@ pub(crate) fn print_remote_error_hint(err: &std::io::Error, target: &str) {
}
}
+fn is_remote_host_key_error(err: &std::io::Error) -> bool {
+ let message = err.to_string().to_ascii_lowercase();
+ message.contains("host key verification failed")
+ || message.contains("remote host identification has changed")
+}
+
fn is_remote_auth_error(err: &std::io::Error) -> bool {
let message = err.to_string();
message.contains("Permission denied")
@@ -64,6 +80,19 @@ mod tests {
use super::*;
#[test]
+ fn remote_host_key_error_matches_ssh_diagnostics() {
+ for message in [
+ "Host key verification failed.",
+ "REMOTE HOST IDENTIFICATION HAS CHANGED!",
+ ] {
+ assert!(is_remote_host_key_error(&std::io::Error::other(message)));
+ }
+ assert!(!is_remote_host_key_error(&std::io::Error::other(
+ "server closed connection"
+ )));
+ }
+
+ #[test]
fn remote_auth_error_matches_ssh_auth_denied() {
let err = std::io::Error::other(
"remote platform detection failed: user@host: Permission denied (publickey).",