Loading install +19 −9 Original line number Diff line number Diff line Loading @@ -26,12 +26,28 @@ import logging import sys from paramiko import MissingHostKeyPolicy, SSHException from paramiko import AutoAddPolicy, MissingHostKeyPolicy, SSHException, WarningPolicy from invoke import Argument, Collection from fabric import Connection from fabric_tpa import host, install from fabric_tpa.ui import VerboseProgram, hash_digest_hex from fabric_tpa.ui import VerboseProgram, hash_digest_hex, no_yes # suggestd in upstream paramiko: https://github.com/paramiko/paramiko/pull/2503 class PromptAddPolicy(MissingHostKeyPolicy): """ Policy for automatically adding the hostname and new host key to the local `.HostKeys` object, and saving it. This is used by `.SSHClient`. """ def missing_host_key(self, client, hostname, key): WarningPolicy.missing_host_key(self, client, hostname, key) if not no_yes("Are you sure you want to continue connecting?"): raise SSHException( "Server {!r} not found in known_hosts".format(hostname) ) AutoAddPolicy.missing_host_key(self, client, hostname, key) class MatchingHostKeyPolicy(MissingHostKeyPolicy): Loading @@ -52,13 +68,7 @@ class MatchingHostKeyPolicy(MissingHostKeyPolicy): if hash in self.fingerprints_md5_colons: logging.info('accepting fingerprint %s for host %s', hash, hostname) else: raise SSHException( "Server {!r} key {} not in trusted fingerprints: {!r}".format( hostname, hash, self.fingerprints_md5_colons ) ) PromptAddPolicy.missing_host_key(self, client, hostname, key) # this custom program (and, in fact, this entire script) is required Loading Loading
install +19 −9 Original line number Diff line number Diff line Loading @@ -26,12 +26,28 @@ import logging import sys from paramiko import MissingHostKeyPolicy, SSHException from paramiko import AutoAddPolicy, MissingHostKeyPolicy, SSHException, WarningPolicy from invoke import Argument, Collection from fabric import Connection from fabric_tpa import host, install from fabric_tpa.ui import VerboseProgram, hash_digest_hex from fabric_tpa.ui import VerboseProgram, hash_digest_hex, no_yes # suggestd in upstream paramiko: https://github.com/paramiko/paramiko/pull/2503 class PromptAddPolicy(MissingHostKeyPolicy): """ Policy for automatically adding the hostname and new host key to the local `.HostKeys` object, and saving it. This is used by `.SSHClient`. """ def missing_host_key(self, client, hostname, key): WarningPolicy.missing_host_key(self, client, hostname, key) if not no_yes("Are you sure you want to continue connecting?"): raise SSHException( "Server {!r} not found in known_hosts".format(hostname) ) AutoAddPolicy.missing_host_key(self, client, hostname, key) class MatchingHostKeyPolicy(MissingHostKeyPolicy): Loading @@ -52,13 +68,7 @@ class MatchingHostKeyPolicy(MissingHostKeyPolicy): if hash in self.fingerprints_md5_colons: logging.info('accepting fingerprint %s for host %s', hash, hostname) else: raise SSHException( "Server {!r} key {} not in trusted fingerprints: {!r}".format( hostname, hash, self.fingerprints_md5_colons ) ) PromptAddPolicy.missing_host_key(self, client, hostname, key) # this custom program (and, in fact, this entire script) is required Loading