/usr/lib/python3/dist-packages/twisted/conch/client/__pycache__
Edit: /usr/lib/python3/dist-packages/twisted/conch/client/__pycache__/default.cpython-310.pyc (11156B)
o
b. @ s d Z ddlZddlZddlZddlZddlZddlmZ ddlm Z ddl
mZmZ ddl
mZ ddlmZmZmZ ddlmZmZmZ dd lmZ dd
lmZ dZeZeZdd
Z dd Z!dd Z"G dd dej#Z#dS )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) ConsoleUIKnownHostsFile)
ConchError)commonkeysuserauth)deferprotocolreactor)nativeString)FilePathz~/.ssh/known_hostsc C sV | j jd }tj|}tt| j jd ptj
t}tdd }|
||||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}.
hostknown-hostsc S s t ddddS )N/dev/ttyzr+br ) buffering)_open r r >/usr/lib/python3/dist-packages/twisted/conch/client/default.py
V s zverifyHostKey..)factoryoptionsr Key
fromStringr fromPathr ospath
expanduser_KNOWN_HOSTSr
verifyHostKey) transportr pubKeyfingerprint
actualHost actualKeykhuir r r r ' s (r c
C s8 t |d }d}|d s$tjtjds$td ttjd |d p)t}zt tj|d}W n
t
y? Y dS w |P | D ]B}| }t
|dk rTqG|dd \} }
}| | d vreqG|
|krjqGzt|}W n tyy Y qGw ||kr W d d
S d}qGW d |S 1 sw Y |S )z
Checks to see if host is in the known_hosts file for the user.
@return: 0 if it isn't, 1 if it is and is the same, 2 if it's changed.
@rtype: L{int}
r r z~/.ssh/zCreating ~/.ssh directory...z~/.sshrb N , )r getNSr r existsr printmkdirr openOSError readlinessplitlenr
BaseException)
r r" r keyTyperetValkh_fileknown_hostsliner4 hostshostKeyType
encodedKey
decodedKeyr r r isInKnownHostsZ sF
r@ c C sX t t|d ptjt}g }| D ]}|| r'|j |vr'|
|j q|p+dS )a
Look in known_hosts for a key corresponding to C{host}.
This can be used to change the order of supported key types
in the KEXINIT packet.
@type host: L{str}
@param host: the host to check in known_hosts
@type options: L{twisted.conch.client.options.ConchOptions}
@param options: options passed to client
@return: L{list} of L{str} representing key types or L{None}.
r N)r r r r r r r iterentriesmatchesHostr7 append)r r
knownHostskeyTypesentryr r r getHostKeyAlgorithms s
rG c @ s e Zd Zdd Zdd Zdd Zdd Zd d
Zdd ZdddZ dd Z
dd Zdd Zdd Z
edd Zeejdd Zd
S )SSHUserAuthClientc G s@ t jj| |g|R d | _|| _g | _|jsddg|_d S d S )Nz
~/.ssh/id_rsaz
~/.ssh/id_dsa)r rH __init__keyAgentr usedFiles identitys)selfuserr argsr r r rI s zSSHUserAuthClient.__init__c C st dt jv r2| jd s2| jjdt jd d tttj }|
t jd }|| j |
| j d S tj| d S )N
SSH_AUTH_SOCKnoagentzusing SSH agent {authSock!r})authSock)r environr _logdebugr
ClientCreatorr r SSHAgentClientconnectUNIXaddCallback _setAgent
addErrback_ebSetAgentr rH serviceStarted)rM ccdr r r r] s
z SSHUserAuthClient.serviceStartedc C s | j r| j j d | _ d S d S N)rJ r! loseConnectionrM r r r serviceStopped s
z SSHUserAuthClient.serviceStoppedc C s || _ | j }|| j |S r` )rJ
getPublicKeysaddBothr\ )rM ar_ r r r rZ s
zSSHUserAuthClient._setAgentc C s t j| d S r` )r rH r] )rM fr r r r\ s zSSHUserAuthClient._ebSetAgentc
C s^ | ! zt|}|W W d S ttfy$ t tdw 1 s(w Y dS )z
Prompt for a password using L{getpass.getpass}.
@param prompt: Written on tty to ask for the input.
@type prompt: L{str}
@return: The input.
@rtype: L{str}
NPEBKAC)_replaceStdoutStdingetpassKeyboardInterruptr2 r/ r rM promptpr r r _getPassword s
zSSHUserAuthClient._getPasswordNc C sf |rt |}ndt | j| jj j}z| |t }t
|W S ty2 t
Y S w )Nz{}@{}'s password: )r
formatrN r! getPeerr ro encodesysgetdefaultencodingr
succeedr failrl r r r getPassword s
zSSHUserAuthClient.getPasswordc s j r j }|dur|S fdd jjD } jjd jj|d |s(dS |d } j| tj
|}|d7 }tj |sF S ztj
|W S tjy[ Y S w )z
Get a public key from the key agent if possible, otherwise look in
the next configured identity file for one.
Nc s g | ] }| j vr|qS r )rK ).0xrb r r