diff options
| author | robot-piglet <[email protected]> | 2025-06-22 18:50:56 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2025-06-22 19:04:42 +0300 |
| commit | c7cbc6d480c5488ff6e921c709680fd2c1340a10 (patch) | |
| tree | 10843f44b67c0fb5717ad555556064095f701d8c /contrib/python/Twisted/py3/twisted/conch/client/default.py | |
| parent | 26d391cdb94d2ce5efc8d0cc5cea7607dc363c0b (diff) | |
Intermediate changes
commit_hash:28750b74281710ec1ab5bdc2403c8ab24bdd164b
Diffstat (limited to 'contrib/python/Twisted/py3/twisted/conch/client/default.py')
| -rw-r--r-- | contrib/python/Twisted/py3/twisted/conch/client/default.py | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/contrib/python/Twisted/py3/twisted/conch/client/default.py b/contrib/python/Twisted/py3/twisted/conch/client/default.py index daf4cf33719..7038f8c0107 100644 --- a/contrib/python/Twisted/py3/twisted/conch/client/default.py +++ b/contrib/python/Twisted/py3/twisted/conch/client/default.py @@ -17,12 +17,15 @@ import io import os import sys from base64 import decodebytes +from typing import TYPE_CHECKING from twisted.conch.client import agent from twisted.conch.client.knownhosts import ConsoleUI, KnownHostsFile from twisted.conch.error import ConchError from twisted.conch.ssh import common, keys, userauth +from twisted.conch.ssh.transport import SSHClientTransport from twisted.internet import defer, protocol, reactor +from twisted.internet.defer import Deferred from twisted.python.compat import nativeString from twisted.python.filepath import FilePath @@ -36,7 +39,9 @@ _open = open _input = input -def verifyHostKey(transport, host, pubKey, fingerprint): +def verifyHostKey( + transport: SSHClientTransport, host: bytes, pubKey: bytes, fingerprint: str +) -> Deferred[bool]: """ Verify a host's key. @@ -56,26 +61,29 @@ def verifyHostKey(transport, host, pubKey, fingerprint): equivalent that could be used. @param host: Due to a bug in L{SSHClientTransport.verifyHostKey}, this is - always the dotted-quad IP address of the host being connected to. - @type host: L{str} + always the dotted-quad IP address of the host being connected to. @param transport: the client transport which is attempting to connect to - the given host. - @type transport: L{SSHClientTransport} + the given host. @param fingerprint: the fingerprint of the given public key, in - xx:xx:xx:... format. This is ignored in favor of getting the fingerprint - from the key itself. - @type fingerprint: L{str} + xx:xx:xx:... format. This is ignored in favor of getting the + fingerprint from the key itself. @param pubKey: The public key of the server being connected to. - @type pubKey: L{str} - @return: a L{Deferred} which fires with C{1} if the key was successfully - verified, or fails if the key could not be successfully verified. Failure - types may include L{HostKeyChanged}, L{UserRejectedKey}, L{IOError} or - L{KeyboardInterrupt}. + @return: a L{Deferred} which fires with C{True} if the key was successfully + verified, or fails if the key could not be successfully verified. + Failure types may include L{HostKeyChanged}, L{UserRejectedKey}, + L{IOError} or L{KeyboardInterrupt}. """ + if TYPE_CHECKING: + # this is just a structured assumption that we are making about the + # transport's factory; behind a TYPE_CHECKING flag because we use some + # test fakes and don't want to nail down the type that much. + from twisted.conch.client.direct import SSHClientFactory + + assert isinstance(transport.factory, SSHClientFactory) actualHost = transport.factory.options["host"] actualKey = keys.Key.fromString(pubKey) kh = KnownHostsFile.fromPath( |
