HOME


Mini Shell 1.0
DIR: /usr/lib/python3/dist-packages/twisted/conch/ssh/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/twisted/conch/ssh/__pycache__/agent.cpython-312.pyc
�

Ϫ�f,%��T�dZddlZddlmZmZddlmZddlmZm	Z	m
Z
ddlmZm
Z
Gd�de
j�ZGd	�d
e
j�ZdZdZd
ZdZdZdZdZdZdZdZdZdZdZiZe�jA�jC�D]\Z"Z#e"dddk(s�e"ddee#<�y)z�
Implements the SSH v2 key agent protocol.  This protocol is documented in the
SSH source code, in the file
U{PROTOCOL.agent<http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.agent>}.

Maintainer: Paul Swartz
�N)�
ConchError�MissingKeyStoreError)�keys)�NS�getMP�getNS)�defer�protocolc�N�eZdZdZd�Zd�Zd�Zd�Zd�Zd
d�Z	d�Z
d	�Zd
�Zd�Z
y)�SSHAgentClientz�
    The client side of the SSH agent protocol.  This is equivalent to
    ssh-add(1) and can be used with either ssh-agent(1) or the SSHAgentServer
    protocol, also in this package.
    c� �d|_g|_y�N�)�buf�	deferreds��selfs �9/usr/lib/python3/dist-packages/twisted/conch/ssh/agent.py�__init__zSSHAgentClient.__init__s�������rc�,�|xj|z
c_	t|j�dkrytjd|jdd�d}t|j�d|zkry|jdd|z|jd|zdc}|_t	|dd�}|j
j
d�}|tk(r|jtd��n,|tk(r|jd�n|j|���)N���!Lrz
agent failurer)r�len�struct�unpack�ordr�pop�
AGENT_FAILURE�errbackr�
AGENT_SUCCESS�callback)r�data�packLen�packet�reqType�ds      r�dataReceivedzSSHAgentClient.dataReceived s������D�����4�8�8�}��!���m�m�D�$�(�(�2�A�,�7��:�G��4�8�8�}�q�7�{�*��#�x�x��A��K�8�$�(�(�1�w�;�=�:Q��F�D�H��&��1�+�&�G����"�"�1�%�A��-�'��	�	�*�_�5�6��M�)��
�
�3���
�
�6�"�rc���tjdt|�dz|�|z}|jj	|�tj�}|jj|�|S�Nz!LBr)	r�packr�	transport�writer	�Deferredr�append)rr&r#r+r's     r�sendRequestzSSHAgentClient.sendRequest2sV���{�{�5�#�d�)�a�-��9�D�@�������T�"��N�N��������a� ��rc�h�|jtd�}|j|j�|S)z�
        @return: A L{Deferred} which will fire with a list of all keys found in
            the SSH agent. The list of keys is comprised of (public key blob,
            comment) tuples.
        r)r0�AGENTC_REQUEST_IDENTITIES�addCallback�_cbRequestIdentities)rr's  r�requestIdentitiesz SSHAgentClient.requestIdentities9s.��
���6��<��	�
�
�d�/�/�0��rc�(�t|dd�tk7rtdt|dd�z��tjd|dd�d}g}|dd}t|�D]1}t
|�\}}t
|�\}}|j||f��3|S)z}
        Unpack a collection of identities into a list of tuples comprised of
        public key blobs and comments.
        rrzunexpected response: %ir�N)r�AGENT_IDENTITIES_ANSWERrrr�rangerr/)rr#�numKeys�result�i�blob�comments       rr4z#SSHAgentClient._cbRequestIdentitiesCs���
�t�A�a�y�>�4�4��6��T�!�A�Y��G�H�H��-�-��d�1�Q�i�0��3�����A�B�x���w��	+�A��t��J�D�$�!�$�K�M�G�T��M�M�4��/�*�	+��
rc�N�|}|t|�z
}|jt|�S)zK
        Add a private key blob to the agent's collection of keys.
        )rr0�AGENTC_ADD_IDENTITY)rr=r>�reqs    r�addIdentityzSSHAgentClient.addIdentitySs+�����r�'�{������ 3�S�9�9rc��t|�}|t|�z
}|dz
}|jt|�j|j�S)a�
        Request that the agent sign the given C{data} with the private key
        which corresponds to the public key given by C{blob}.  The private
        key should have been added to the agent already.

        @type blob: L{bytes}
        @type data: L{bytes}
        @return: A L{Deferred} which fires with a signature for given data
            created with the given key.
        �)rr0�AGENTC_SIGN_REQUESTr3�_cbSignData)rr=r#rAs    r�signDatazSSHAgentClient.signData[sJ����h���r�$�x����"�"����� 3�S�9�E�E�d�FV�FV�W�Wrc��t|dd�tk7rtdt|dd�z��t|dd�d}|S)Nrrzunexpected data: %i)r�AGENT_SIGN_RESPONSErr)rr#�	signatures   rrFzSSHAgentClient._cbSignDataksJ���t�A�a�y�>�0�0��2�S��a���^�C�D�D��$�q�r�(�O�A�&�	��rc�D�t|�}|jt|�S)zp
        Remove the private key corresponding to the public key in blob from the
        running agent.
        )rr0�AGENTC_REMOVE_IDENTITY)rr=rAs   r�removeIdentityzSSHAgentClient.removeIdentityqs!��
��h����� 6��<�<rc�.�|jtd�S)z9
        Remove all keys from the running agent.
        r)r0�AGENTC_REMOVE_ALL_IDENTITIESrs r�removeAllIdentitiesz"SSHAgentClient.removeAllIdentitiesys����� <�c�B�BrN)r)�__name__�
__module__�__qualname__�__doc__rr(r0r5r4rBrGrFrMrP�rrrrs;����#�$��� :�X� �=�Crrc�R�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�SSHAgentServerz�
    The server side of the SSH agent protocol.  This is equivalent to
    ssh-agent(1) and can be used with either ssh-add(1) or the SSHAgentClient
    protocol, also in this package.
    c��d|_yr)rrs rrzSSHAgentServer.__init__�s	����rc�X�|xj|z
c_	t|j�dkrytjd|jdd�d}t|j�d|zkry|jdd|z|jd|zdc}|_t	|dd�}t
j
|d�}|s|jtd�nQt|d|z�}t|jdd�� |jtd�t��||dd���)Nrrrrrz	agentc_%sr)rrrrr�messages�get�sendResponser�getattr�factoryr)rr#r$r%r&�reqName�fs       rr(zSSHAgentServer.dataReceived�s
�����D�����4�8�8�}��!���m�m�D�$�(�(�2�A�,�7��:�G��4�8�8�}�q�7�{�*��#�x�x��A��K�8�$�(�(�1�w�;�=�:Q��F�D�H��&��1�+�&�G��l�l�7�D�1�G���!�!�-��5��D�+��"7�8���4�<�<���6�>��%�%�m�S�9�.�0�0��&���*�
�!rc��tjdt|�dz|�|z}|jj	|�yr*)rr+rr,r-)rr&r#r+s    rr\zSSHAgentServer.sendResponse�s3���{�{�5�#�d�)�a�-��9�D�@�������T�"rc���|dk(sJ�t|jj�}g}|jt	j
d|��|jjj
�D]G\}}|jt|j���|jt|���I|jtdj|��y)zQ
        Return all of the identities that have been added to the server
        rrN)rr^rr/rr+�valuesrr=r\r8�join)rr#r:�resp�keyr>s      r�agentc_REQUEST_IDENTITIESz(SSHAgentServer.agentc_REQUEST_IDENTITIES�s����s�{��{��d�l�l�'�'�(�������F�K�K��g�.�/� �L�L�-�-�4�4�6�	%�L�C���K�K��3�8�8�:��'��K�K��7��$�	%�	
���1�3�8�8�D�>�Brc�6�t|�\}}||jjvr|jtd�St|�\}}|dk(sJ�|jt
t
|jj|dj|���y)z�
        Data is a structure with a reference to an already added key object and
        some data that the clients wants signed with that key.  If the key
        object wasn't loaded, return AGENT_FAILURE, else return the signature.
        rrDrN)rr^rr\rrIr�sign)rr#r=rGs    r�agentc_SIGN_REQUESTz"SSHAgentServer.agentc_SIGN_REQUEST�s����4�[�
��d��t�|�|�(�(�(��$�$�]�C�8�8��t����$��*�*�*�*������D�L�L�$5�$5�d�$;�A�$>�$C�$C�H�$M�!N�	
rc�j�t|�\}}|dk(rd}n |dk(rd}ntjd|z��t||�d}t|�\}}tjj|d��}||f|jj|j�<|jtd	�y
)z�
        Adds a private key to the agent's collection of identities.  On
        subsequent interactions, the private key can be accessed using only the
        corresponding public key.
        sssh-rsa�sssh-dssr7zunknown blob type: %s����private_blob��typerN)
rr�BadKeyErrorr�Key�
fromStringr^r=r\r!)rr#�keyType�rest�nmpr>�ks       r�agentc_ADD_IDENTITYz"SSHAgentServer.agentc_ADD_IDENTITY�s����d��
����j� ��C�
�
�
"��C��"�"�#:�W�#D�E�E��T�3���
���d��
����H�H����>��:��'(�'�l������!�&�&�(�#����-��-rc���t|�\}}tjj|d��}|jj|j�=|j
td�y)zR
        Remove a specific key from the agent's collection of identities.
        r=rorN)rrrrrsr^r=r\r!)rr#r=�_rws     r�agentc_REMOVE_IDENTITYz%SSHAgentServer.agentc_REMOVE_IDENTITY�sR����+���a��H�H����6��2���L�L���a�f�f�h�'����-��-rc�`�|dk(sJ�i|j_|jtd�y)zL
        Remove all keys from the agent's collection of identities.
        rN)r^rr\r!�rr#s  r�agentc_REMOVE_ALL_IDENTITIESz+SSHAgentServer.agentc_REMOVE_ALL_IDENTITIES�s,���s�{��{���������-��-rc�X�|jttjdd��y)z�
        v1 message for listing RSA1 keys; superseded by
        agentc_REQUEST_IDENTITIES, which handles different key types.
        rrN)r\�AGENT_RSA_IDENTITIES_ANSWERrr+r}s  r�agentc_REQUEST_RSA_IDENTITIESz,SSHAgentServer.agentc_REQUEST_RSA_IDENTITIES�s ��
	
���5�v�{�{�4��7K�Lrc�0�|jtd�y)z�
        v1 message for removing RSA1 keys; superseded by
        agentc_REMOVE_IDENTITY, which handles different key types.
        rN�r\r!r}s  r�agentc_REMOVE_RSA_IDENTITYz)SSHAgentServer.agentc_REMOVE_RSA_IDENTITY����
	
���-��-rc�0�|jtd�y)z�
        v1 message for removing all RSA1 keys; superseded by
        agentc_REMOVE_ALL_IDENTITIES, which handles different key types.
        rNr�r}s  r� agentc_REMOVE_ALL_RSA_IDENTITIESz/SSHAgentServer.agentc_REMOVE_ALL_RSA_IDENTITIES�r�rN)rQrRrSrTrr(r\rgrjrxr{r~r�r�r�rUrrrWrW�s@�����(#�C�

�.�2.�.�M�.�.rrWr�r7rl��	���
������AGENTC_)$rTr�twisted.conch.errorrr�twisted.conch.sshr�twisted.conch.ssh.commonrrr�twisted.internetr	r
�ProtocolrrW�AGENTC_REQUEST_RSA_IDENTITIESr�rr!�AGENTC_REMOVE_RSA_IDENTITY� AGENTC_REMOVE_ALL_RSA_IDENTITIESr2r8rErIr@rLrOrZ�locals�copy�items�name�valuerUrr�<module>r�s�����@�"�5�5�,�hC�X�&�&�hC�V@.�X�&�&�@.�F!"�����
��
���#$� �������������!��
���8�=�=�?�(�(�*�#�K�D�%��B�Q�x�9���q�r�(����#r