%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/conch/client/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/conch/client/__pycache__/default.cpython-312.pyc

�

Ϫ�f�.����dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZddl
mZddlmZmZmZddlmZmZmZdd	lmZdd
lmZdZeZeZd�Z d
�Z!d�Z"Gd�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�|jjd}tjj	|�}tjt|jjdxs#tjjt���}td��}|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��tddd��S)N�/dev/ttyzr+br)�	buffering)�_open���>/usr/lib/python3/dist-packages/twisted/conch/client/default.py�<lambda>zverifyHostKey.<locals>.<lambda>Vs��5��U�a�@�r)�factory�optionsr	�Key�
fromStringr�fromPathr�os�path�
expanduser�_KNOWN_HOSTSr�
verifyHostKey)�	transportr�pubKey�fingerprint�
actualHost�	actualKey�kh�uis        rr$r$'s���P�"�"�*�*�6�2�J����#�#�F�+�I�	�	 �	 �����%�%�m�4�X����8J�8J�<�8X�	
�
�B�

�@�	A�B�
���B�
�D�)�<�<rc��tj|�d}d}|dsytjj	tjjd��s=t
d�tjtjjd��|dxst}	ttjj|�d�}|5|j�D]a}|j�}t|�dkr�"|dd\}	}
}||	jd	�vr�?|
|k7r�E	t|�}||k(r
ddd�y
d}�c	ddd�|S#t$rYywxYw#t$rY��wxYw#1swY|SxYw)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�getNSr r!�existsr"�print�mkdirr#�open�OSError�	readlines�split�lenr�
BaseException)
rr&r�keyType�retVal�kh_file�known_hosts�liner9�hosts�hostKeyType�
encodedKey�
decodedKeys
             r�isInKnownHostsrEZsn���l�l�6�"�1�%�G�
�F��=�!�"�'�'�.�.����9K�9K�I�9V�*W�
�,�-�
������#�#�H�-�.��m�$�4��G���2�7�7�-�-�g�6��=��
���)�)�+�	�D��J�J�L�E��5�z�A�~��-2�2�A�Y�*�E�;�
��5�;�;�t�,�,���g�%��
�(��4�
��V�#����"��!	��$�M��)�����!�
��
���$�M�sI�')E�AE0�)E!�4E0�E0�	E�E�!	E-�*E0�,E-�-E0�0E:c�@�tjt|dxs#tjjt���}g}|j�D]>}|j|�s�|j|vs�$|j|j��@|xsdS)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)rrrr r!r"r#�iterentries�matchesHostr<�append)rr�
knownHosts�keyTypes�entrys     r�getHostKeyAlgorithmsrM�s��� �(�(����'�K�2�7�7�+=�+=�l�+K�L��J��H��'�'�)�/�����T�"��}�}�H�,�����
�
�.�/���t�rc��eZdZd�Zd�Zd�Zd�Zd�Zd�Zdd�Z	d	�Z
d
�Zd�Zd�Z
ed
��Zeej"d���Zy)�SSHUserAuthClientc��tjj||g|���d|_||_g|_|js
ddg|_yy)Nz
~/.ssh/id_rsaz
~/.ssh/id_dsa)r
rO�__init__�keyAgentr�	usedFiles�	identitys)�self�userr�argss    rrQzSSHUserAuthClient.__init__�sM���"�"�+�+�D�$�>��>���
�������� � �!0�/� B�G��!rc���dtjvr�|jds�|jj	dtjd��tjttj�}|jtjd�}|j|j�|j|j�ytj j#|�y)N�
SSH_AUTH_SOCK�noagentzusing SSH agent {authSock!r})�authSock)r �environr�_log�debugr�
ClientCreatorr
r�SSHAgentClient�connectUNIX�addCallback�	_setAgent�
addErrback�_ebSetAgentr
rO�serviceStarted)rU�cc�ds   rrfz SSHUserAuthClient.serviceStarted�s����b�j�j�(����i�1H��I�I�O�O�.����O�9T�
�
��'�'���1E�1E�F�B����r�z�z�/�:�;�A�
�M�M�$�.�.�)�
�L�L��)�)�*��&�&�5�5�d�;rc�t�|jr,|jjj�d|_yy�N)rRr%�loseConnection)rUs r�serviceStoppedz SSHUserAuthClient.serviceStopped�s+���=�=��M�M�#�#�2�2�4� �D�M�rc�~�||_|jj�}|j|j�|Srj)rR�
getPublicKeys�addBothre)rU�arhs   rrczSSHUserAuthClient._setAgent�s2����
��M�M�'�'�)��	�	�	�$�"�"�#��rc�B�tjj|�yrj)r
rOrf)rU�fs  rrezSSHUserAuthClient._ebSetAgent�s���"�"�1�1�$�7rc���|j�5	tj|�}|cddd�S#ttf$rt	�td��wxYw#1swYyxYw)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�KeyboardInterruptr7r4r�rU�prompt�ps   r�_getPasswordzSSHUserAuthClient._getPassword�sf���
%�
%�
'�	+�
+��O�O�F�+���	+�	+��&�w�/�
+��� ��*�*�
+��		+�	+�s�A�3�%A�A�A$Nc��|rt|�}nQdjt|j�|jjj	�j
�}	|j
|�jtj��}tj|�S#t$rtj�cYSwxYw)Nz{}@{}'s password: )r�formatrVr%�getPeerrr{�encode�sys�getdefaultencodingr�succeedr�failrxs   r�getPasswordzSSHUserAuthClient.getPassword�s����!�&�)�F�)�0�0��T�Y�Y�'����(�(�0�0�2�7�7��F�	 �
�!�!�&�)�0�0��1G�1G�1I�J�A��=�=��#�#���	 ��:�:�<��	 �s�!AB(�(C�Cc��|jr|jj�}|�|S|jjD�cgc]}||jvs�|��}}|j
j
d|jj|��|sy|d}|jj|�tjj|�}|dz
}tjj|�s|j�S	tjj|�Scc}w#tj$r|j�cYSwxYw)z�
        Get a public key from the key agent if possible, otherwise look in
        the next configured identity file for one.
        Nz+public key identities: {identities}
{files})�
identities�filesrz.pub)rR�getPublicKeyrrTrSr]r^rIr r!r"r3r	r�fromFile�BadKeyError)rU�key�xr��files     rr�zSSHUserAuthClient.getPublicKey�s��
�=�=��-�-�,�,�.�C����
� �L�L�2�2�N�q�a�t�~�~�6M��N��N��	�	���:��|�|�-�-��	�	
�
���Q�x�������d�#��w�w�!�!�$�'�������w�w�~�~�d�#��$�$�&�&�	'��8�8�$�$�T�*�*��O�� ���	'��$�$�&�&�	'�s�D%�D%�D*�*#E�Ec��|js*|jj|j�|�Stj
j|||�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}
        )rSrR�signData�blobr
rO)rU�	publicKeyr�s   rr�zSSHUserAuthClient.signData�sD���~�~��=�=�)�)�)�.�.�*:�H�E�E��-�-�6�6�t�Y��Q�Qrc��tjj|jd�}tjj	|�sy	tjtjj|��S#tj$r�td�D]�}d|jdz}	|j|�jtj��}tjtjj||���ccYS#tj t"f$rYnwxYwtj$t#d��ccYS�t&$r!t)�t+j,�YywxYw)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)r r!r"rSr3rr�r	rr��EncryptedKeyError�ranger{rr��getfilesystemencodingr�rr�rwr4r
�stop)rUr��iryrzs     r�
getPrivateKeyzSSHUserAuthClient.getPrivateKeys*���w�w�!�!�$�.�.��"4�5���w�w�~�~�d�#��	��=�=����!2�!2�4�!8�9�9���%�%�		��1�X�
>��:�T�^�^�B�=O�O����)�)�&�1�8�8��9R�9R�9T�U�A� �=�=����):�):�4�A�):�)N�O�O���(�(�*�5������z�z�*�^�"<�=�=�
>�
� �	��G��L�L�N�	�s=�1B�3F
�4A%D�F
�D:�7F
�9D:�:#F
�(F
�	F
c��g}|j�5|rt|jd��|rt|jd��|D]W\}}|jd�}|r|jt	|���4|jtj
|���Y	ddd�t
j|�S#1swY�xYw)Nzutf-8)rur4�decoderI�_inputrvrr�)rU�name�instruction�prompts�	responsesry�echos       r�getGenericAnswersz#SSHUserAuthClient.getGenericAnswers s����	�
�
%�
%�
'�
	>���d�k�k�'�*�+���k�(�(��1�2� '�
>�������w�/����$�$�V�F�^�4��$�$�W�_�_�V�%<�=�
>�
	>��}�}�Y�'�'�
	>�
	>�s�BC�Cc��tjtdd��}tjtdd��}||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�
TextIOWrapperr6)�cls�stdin�stdouts   r�_openTtyzSSHUserAuthClient._openTty/s<��� � ��j�$�!7�8���!�!�$�z�4�"8�9���f�}�rc#�K�tjtj}}|j�\t_t_	d��tjj	�tjj	�||ct_t_y#tjj	�tjj	�||ct_t_wxYw�w)zv
        Contextmanager that replaces stdout and stdin with /dev/tty
        and resets them when it is done.
        N)r�r�r�r��close)r��oldout�oldins   rruz%SSHUserAuthClient._replaceStdoutStdin=s������
�
�C�I�I��� #������	�3�:�	2���J�J�����I�I�O�O��$*�E�!�C�J��	��
�J�J�����I�I�O�O��$*�E�!�C�J��	�s �AC9�	B!�
AC9�!AC6�6C9rj)�__name__�
__module__�__qualname__rQrfrlrcrer{r�r�r�r�r��classmethodr��
contextlib�contextmanagerrurrrrOrO�sq��C�
<�!�
�8�+�" �$'�8R��2
(���������2���2rrO)$�__doc__r�rvr�r r��base64r�twisted.conch.clientr�twisted.conch.client.knownhostsrr�twisted.conch.errorr�twisted.conch.sshrr	r
�twisted.internetrrr
�twisted.python.compatr�twisted.python.filepathrr#r6r�inputr�r$rErMrOrrr�<module>r�sq��
���	�	�
��&�E�*�4�4�5�5�.�,�$��	
��	��0=�f$�N�.s2��2�2�s2r

Zerion Mini Shell 1.0