Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/conch/ssh/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/conch/ssh/__pycache__/agent.cpython-37.pyc

B

:��]�%�@sdZddlmZmZddlZddlmZmZmZddl	m
Z
mZddlm
Z
ddlmZmZddlmZGd	d
�d
ej�ZGdd�dej�Zd
ZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"iZ#x:e$��%��&�D](\Z'Z(e'dd�dkr�e'dd�e#e(<q�WdS)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
�)�absolute_import�divisionN)�NS�getNS�getMP)�
ConchError�MissingKeyStoreError)�keys)�defer�protocol)�
itervaluesc@sbeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�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.
    cCsd|_g|_dS)N�)�buf�	deferreds)�self�r�J/opt/alt/python37/lib64/python3.7/site-packages/twisted/conch/ssh/agent.py�__init__szSSHAgentClient.__init__cCs�|j|7_x�t|j�dkr"dSt�d|jdd��d}t|j�d|krRdS|jdd|�|jd|d�}|_t|dd��}|j�d�}|tkr�|�t	d��q|t
kr�|�d�q|�|�qWdS)N�z!Lr�z
agent failurer)r�len�struct�unpack�ordr�pop�
AGENT_FAILUREZerrbackr�
AGENT_SUCCESS�callback)r�data�packLen�packet�reqType�drrr�dataReceived$s(zSSHAgentClient.dataReceivedcCs>t�dt|�d|�|}|j�|�t��}|j�|�|S)Nz!LBr)	r�packr�	transport�writer
ZDeferredr�append)rr"rr%r#rrr�sendRequest7s
zSSHAgentClient.sendRequestcCs|�td�}|�|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)r)�AGENTC_REQUEST_IDENTITIES�addCallback�_cbRequestIdentities)rr#rrr�requestIdentities?sz SSHAgentClient.requestIdentitiescCs�t|dd��tkr,tdt|dd����t�d|dd��d}g}|dd�}x6t|�D]*}t|�\}}t|�\}}|�||f�q^W|S)z}
        Unpack a collection of identities into a list of tuples comprised of
        public key blobs and comments.
        rrzunexpected response: %iz!L�N)r�AGENT_IDENTITIES_ANSWERrrr�rangerr()rr�numKeys�result�i�blob�commentrrrr,Jsz#SSHAgentClient._cbRequestIdentitiesrcCs|}|t|�7}|�t|�S)zK
        Add a private key blob to the agent's collection of keys.
        )rr)�AGENTC_ADD_IDENTITY)rr4r5�reqrrr�addIdentity[szSSHAgentClient.addIdentitycCs0t|�}|t|�7}|d7}|�t|��|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.
        s)rr)�AGENTC_SIGN_REQUESTr+�_cbSignData)rr4rr7rrr�signDatadszSSHAgentClient.signDatacCsDt|dd��tkr,tdt|dd����t|dd��d}|S)Nrrzunexpected data: %i)r�AGENT_SIGN_RESPONSErr)rr�	signaturerrrr:uszSSHAgentClient._cbSignDatacCst|�}|�t|�S)zp
        Remove the private key corresponding to the public key in blob from the
        running agent.
        )rr)�AGENTC_REMOVE_IDENTITY)rr4r7rrr�removeIdentity|szSSHAgentClient.removeIdentitycCs|�td�S)z9
        Remove all keys from the running agent.
        r)r)�AGENTC_REMOVE_ALL_IDENTITIES)rrrr�removeAllIdentities�sz"SSHAgentClient.removeAllIdentitiesN)r)�__name__�
__module__�__qualname__�__doc__rr$r)r-r,r8r;r:r?rArrrrr
s
		r
c@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�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.
    cCs
d|_dS)Nr)r)rrrrr�szSSHAgentServer.__init__cCs�|j|7_x�t|j�dkr"dSt�d|jdd��d}t|j�d|krRdS|jdd|�|jd|d�}|_t|dd��}t�|d�}|s�|�td�qt	|d|�}t	|j
dd�dkr�|�td�t��||dd��qWdS)Nrz!Lrrrz	agentc_%sr	)rrrrr�messages�get�sendResponser�getattr�factoryr)rrr r!r"ZreqName�frrrr$�s"(zSSHAgentServer.dataReceivedcCs*t�dt|�d|�|}|j�|�dS)Nz!LBr)rr%rr&r')rr"rr%rrrrI�szSSHAgentServer.sendResponsecCs~|dkst�t|jj�}g}|�t�d|��x8t|jj�D](\}}|�t|�	���|�t|��q<W|�
td�|��dS)zQ
        Return all of the identities that have been added to the server
        rz!LN)
�AssertionErrorrrKr	r(rr%rrr4rIr/�join)rrr1Zresp�keyr5rrr�agentc_REQUEST_IDENTITIES�sz(SSHAgentServer.agentc_REQUEST_IDENTITIEScCsbt|�\}}||jjkr$|�td�St|�\}}|dks<t�|�tt|jj|d�|���dS)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.
        rsrN)	rrKr	rIrrMr<r�sign)rrr4r;rrr�agentc_SIGN_REQUEST�sz"SSHAgentServer.agentc_SIGN_REQUESTcCs�t|�\}}|dkrd}n|dkr(d}nt�d|��t||�d}t|�\}}tjj|dd�}||f|jj|��<|�t	d	�d
S)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-dssr.zunknown blob type: %s���Zprivate_blob)�typerN)
rr	ZBadKeyErrorr�Key�
fromStringrKr4rIr)rrZkeyType�restZnmpr5�krrr�agentc_ADD_IDENTITY�sz"SSHAgentServer.agentc_ADD_IDENTITYcCs:t|�\}}tjj|dd�}|jj|��=|�td�dS)zR
        Remove a specific key from the agent's collection of identities.
        r4)rUrN)rr	rVrWrKr4rIr)rrr4�_rYrrr�agentc_REMOVE_IDENTITY�sz%SSHAgentServer.agentc_REMOVE_IDENTITYcCs$|dkst�i|j_|�td�dS)zL
        Remove all keys from the agent's collection of identities.
        rN)rMrKr	rIr)rrrrr�agentc_REMOVE_ALL_IDENTITIES�sz+SSHAgentServer.agentc_REMOVE_ALL_IDENTITIEScCs|�tt�dd��dS)z�
        v1 message for listing RSA1 keys; superseded by
        agentc_REQUEST_IDENTITIES, which handles different key types.
        z!LrN)rI�AGENT_RSA_IDENTITIES_ANSWERrr%)rrrrr�agentc_REQUEST_RSA_IDENTITIES�sz,SSHAgentServer.agentc_REQUEST_RSA_IDENTITIEScCs|�td�dS)z�
        v1 message for removing RSA1 keys; superseded by
        agentc_REMOVE_IDENTITY, which handles different key types.
        rN)rIr)rrrrr�agentc_REMOVE_RSA_IDENTITYsz)SSHAgentServer.agentc_REMOVE_RSA_IDENTITYcCs|�td�dS)z�
        v1 message for removing all RSA1 keys; superseded by
        agentc_REMOVE_ALL_IDENTITIES, which handles different key types.
        rN)rIr)rrrrr� agentc_REMOVE_ALL_RSA_IDENTITIES
sz/SSHAgentServer.agentc_REMOVE_ALL_RSA_IDENTITIESN)rBrCrDrErr$rIrPrRrZr\r]r_r`rarrrrrF�s
rFr�r.rS��	���
�����ZAGENTC_))rE�
__future__rrrZtwisted.conch.ssh.commonrrrZtwisted.conch.errorrrZtwisted.conch.sshr	Ztwisted.internetr
rZtwisted.python.compatrZProtocolr
rFZAGENTC_REQUEST_RSA_IDENTITIESr^rrZAGENTC_REMOVE_RSA_IDENTITYZ AGENTC_REMOVE_ALL_RSA_IDENTITIESr*r/r9r<r6r>r@rG�locals�copy�items�name�valuerrrr�<module>
s6u