�
Ϫ�f�. � �� � d Z ddlZddlZddlZddlZddlZddlmZ ddlm Z ddl
mZmZ ddl
mZ ddlmZmZmZ ddlmZmZmZ dd lmZ dd
lmZ dZeZeZd� Z d
� Z!d� Z" G d� dejF � Z#y)aN
Various classes and functions for implementing user-interaction in the
command-line conch client.
You probably shouldn't use anything in this module directly, since it assumes
you are sitting at an interactive terminal. For example, to programmatically
interact with a known_hosts database, use L{twisted.conch.client.knownhosts}.
� N)�decodebytes)�agent)� ConsoleUI�KnownHostsFile)�
ConchError)�common�keys�userauth)�defer�protocol�reactor)�nativeString)�FilePathz~/.ssh/known_hostsc �f � | j j d }t j j |� }t j t | j j d xs# t j j t � � � }t d� � }|j ||||� S )a%
Verify a host's key.
This function is a gross vestige of some bad factoring in the client
internals. The actual implementation, and a better signature of this logic
is in L{KnownHostsFile.verifyHostKey}. This function is not deprecated yet
because the callers have not yet been rehabilitated, but they should
eventually be changed to call that method instead.
However, this function does perform two functions not implemented by
L{KnownHostsFile.verifyHostKey}. It determines the path to the user's
known_hosts file based on the options (which should really be the options
object's job), and it provides an opener to L{ConsoleUI} which opens
'/dev/tty' so that the user will be prompted on the tty of the process even
if the input and output of the process has been redirected. This latter
part is, somewhat obviously, not portable, but I don't know of a portable
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}
@param transport: the client transport which is attempting to connect to
the given host.
@type transport: L{SSHClientTransport}
@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}
@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}.
�host�known-hostsc � � t ddd�� S )N�/dev/ttyzr+br )� buffering)�_open� � �>/usr/lib/python3/dist-packages/twisted/conch/client/default.py�<lambda>zverifyHostKey.<locals>.<lambda>V s � �5��U�a�@� r )�factory�optionsr �Key�
fromStringr �fromPathr �os�path�
expanduser�_KNOWN_HOSTSr �
verifyHostKey)� transportr �pubKey�fingerprint�
actualHost� actualKey�kh�uis r r$ r$ ' |