summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-03-07 08:44:04 +0100
committerGitHub <noreply@github.com>2024-03-07 08:44:04 +0100
commitf639e515676b8ac6a176fd04d72134ccc44e1c14 (patch)
treeac2705fb20deb63a4f6ce378c1ad4c5ea35fad76
parent171ceda96321f7b7e24a1267f844025a6d8563ea (diff)
parent85c9450f1f6d4782f26fb30e2f41c94ed5cadcd3 (diff)
downloadvyos-1x-f639e515676b8ac6a176fd04d72134ccc44e1c14.tar.gz
vyos-1x-f639e515676b8ac6a176fd04d72134ccc44e1c14.zip
Merge pull request #3102 from vyos/mergify/bp/sagitta/pr-3100
remote: T6104: fix logic of failure case in MissingHostKeyPolicy (backport #3100)
-rw-r--r--python/vyos/remote.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/python/vyos/remote.py b/python/vyos/remote.py
index 830770d11..ee97ee4ad 100644
--- a/python/vyos/remote.py
+++ b/python/vyos/remote.py
@@ -43,6 +43,7 @@ from vyos.utils.io import print_error
from vyos.utils.misc import begin
from vyos.utils.process import cmd, rc_cmd
from vyos.version import get_version
+from vyos.base import Warning
CHUNK_SIZE = 8192
@@ -54,13 +55,16 @@ class InteractivePolicy(MissingHostKeyPolicy):
def missing_host_key(self, client, hostname, key):
print_error(f"Host '{hostname}' not found in known hosts.")
print_error('Fingerprint: ' + key.get_fingerprint().hex())
- if is_interactive() and ask_yes_no('Do you wish to continue?'):
- if client._host_keys_filename\
- and ask_yes_no('Do you wish to permanently add this host/key pair to known hosts?'):
- client._host_keys.add(hostname, key.get_name(), key)
- client.save_host_keys(client._host_keys_filename)
- else:
+ if not sys.stdin.isatty():
+ return
+ if not ask_yes_no('Do you wish to continue?'):
raise SSHException(f"Cannot connect to unknown host '{hostname}'.")
+ if client._host_keys_filename is None:
+ Warning('no \'known_hosts\' file; create to store keys permanently')
+ return
+ if ask_yes_no('Do you wish to permanently add this host/key pair to known_hosts file?'):
+ client._host_keys.add(hostname, key.get_name(), key)
+ client.save_host_keys(client._host_keys_filename)
class SourceAdapter(HTTPAdapter):
"""