HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/conch/ssh/__pycache__/agent.cpython-38.pyc
U


W[�%�@sdZddlmZmZddlZddlmZmZmZddl	m
Z
mZddlm
Z
ddlmZmZddlmZGd	d
�d
ej�ZGdd�dej�Zd
ZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"iZ#e$��%��&�D](\Z'Z(e'dd�dkr�e'dd�e#e(<q�dS)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�9/usr/lib/python3/dist-packages/twisted/conch/ssh/agent.py�__init__szSSHAgentClient.__init__cCs�|j|7_t|j�dkr dSt�d|jdd��d}t|j�d|krPdS|jdd|�|jd|d�}|_t|dd��}|j�d�}|tkr�|�t	d��q|t
kr�|�d�q|�|�qdS)N��!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%r"r)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�}t|�D]*}t|�\}}t|�\}}|�||f�q\|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�commentrrrr0Jsz#SSHAgentClient._cbRequestIdentitiesrcCs|}|t|�7}|�t|�S)zK
        Add a private key blob to the agent's collection of keys.
        )rr-�AGENTC_ADD_IDENTITY)rr8r9�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.
        �)rr-�AGENTC_SIGN_REQUESTr/�_cbSignData)rr8r"r;rrr�signDatadszSSHAgentClient.signDatacCsDt|dd��tkr,tdt|dd����t|dd��d}|S)Nrrzunexpected data: %i)r�AGENT_SIGN_RESPONSErr)rr"Z	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)rr8r;rrr�removeIdentity|szSSHAgentClient.removeIdentitycCs|�td�S)z9
        Remove all keys from the running agent.
        r)r-�AGENTC_REMOVE_ALL_IDENTITIESrrrr�removeAllIdentities�sz"SSHAgentClient.removeAllIdentitiesN)r)�__name__�
__module__�__qualname__�__doc__rr'r-r1r0r<r@r?rCrErrrrr
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|_dSr)rrrrrr�szSSHAgentServer.__init__cCs�|j|7_t|j�dkr dSt�d|jdd��d}t|j�d|krPdS|jdd|�|jd|d�}|_t|dd��}t�|d�}|s�|�td�qt	|d|�}t	|j
dd�dkr�|�td�t��||dd��qdS)Nrrrrrz	agentc_%sr	)rrrrr�messages�get�sendResponser�getattr�factoryr)rr"r#r$r%ZreqName�frrrr'�s (zSSHAgentServer.dataReceivedcCs*t�dt|�d|�|}|j�|�dSr()rr)rr*r+)rr%r"r)rrrrM�szSSHAgentServer.sendResponsecCsz|dkst�t|jj�}g}|�t�d|��t|jj�D](\}}|�t|�	���|�t|��q:|�
td�|��dS)zQ
        Return all of the identities that have been added to the server
        rrN)
�AssertionErrorrrOr	r,rr)rrr8rMr3�join)rr"r5Zresp�keyr9rrr�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.
        rr=rN)	rrOr	rMrrQrArZsign)rr"r8r@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-dssr2zunknown blob type: %s���Zprivate_blob��typerN)
rr	ZBadKeyErrorr�Key�
fromStringrOr8rMr )rr"ZkeyType�restZnmpr9�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.
        r8rXrN)rr	rZr[rOr8rMr )rr"r8�_r]rrr�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)rQrOr	rMr �rr"rrr�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.
        rrN)rM�AGENT_RSA_IDENTITIES_ANSWERrr)rarrr�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�rMr rarrr�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.
        rNrerarrr� agentc_REMOVE_ALL_RSA_IDENTITIES
sz/SSHAgentServer.agentc_REMOVE_ALL_RSA_IDENTITIESN)rFrGrHrIrr'rMrTrUr^r`rbrdrfrgrrrrrJ�s
rJr�r2rV��	���
�����ZAGENTC_))rIZ
__future__rrrZtwisted.conch.ssh.commonrrrZtwisted.conch.errorrrZtwisted.conch.sshr	Ztwisted.internetr
rZtwisted.python.compatrZProtocolr
rJZAGENTC_REQUEST_RSA_IDENTITIESrcrr ZAGENTC_REMOVE_RSA_IDENTITYZ AGENTC_REMOVE_ALL_RSA_IDENTITIESr.r3r>rAr:rBrDrK�locals�copy�items�name�valuerrrr�<module>s6u