HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberPanel/lib64/python3.10/site-packages/paramiko/__pycache__/agent.cpython-310.pyc
o

�h>�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZddlm
Z
mZddlmZmZddlmZddlmZmZdd	lmZmZed
�ZdZed�Zd
ZdZdZeed�Z e!e �"��D]\Z#Z$e$e e#�d�<qoGdd�d�Z%Gdd�dej&�Z'Gdd�de'�Z(Gdd�de'�Z)dd�Z*Gdd�d�Z+Gdd�de%�Z,Gd d!�d!�Z-Gd"d#�d#e%�Z.Gd$d%�d%e�Z/dS)&z
SSH Agent interface
�N)�DEBUG)�select)�io_sleep�byte_chr)�SSHException�AuthenticationException)�Message)�PKey�UnknownKeyType)�asbytes�
get_logger���
���)zrsa-sha2-256zrsa-sha2-512z-cert-v01@openssh.comc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�AgentSSHcCsd|_d|_dS�N�)�_conn�_keys��selfrr�D/usr/local/CyberPanel/lib/python3.10/site-packages/paramiko/agent.py�__init__>s
zAgentSSH.__init__cC�|jS)a�
        Return the list of keys available through the SSH agent, if any.  If
        no SSH agent was running (or it couldn't be contacted), an empty list
        will be returned.

        This method performs no IO, just returns the list of keys retrieved
        when the connection was made.

        :return:
            a tuple of `.AgentKey` objects representing keys available on the
            SSH agent
        )rrrrr�get_keysBs
zAgentSSH.get_keyscCsd||_|�t�\}}|tkrtd��g}t|���D]}|�t||�	�|�
�d��qt|�|_dS)Nz!could not get keys from ssh-agent)�agent�blob�comment)
r�
_send_message�cSSH2_AGENTC_REQUEST_IDENTITIES�SSH2_AGENT_IDENTITIES_ANSWERr�range�get_int�append�AgentKey�
get_binary�get_text�tupler)r�conn�ptype�result�keys�irrr�_connectQs��zAgentSSH._connectcCs$|jdur
|j��d|_d|_dSr)r�closerrrrr�_closeas


zAgentSSH._closecCsXt|�}|j�t�dt|��|�|�d�}t|�t�d|�d��}t	|�
��|fS)Nz>Irr)rr�send�struct�pack�len�	_read_allr�unpack�ord�get_byte)r�msg�datarrrr!gs

zAgentSSH._send_messagecCsl|j�|�}t|�|kr4t|�dkrtd��|j�|t|��}t|�dkr*td��||7}t|�|ks|S)Nr�lost ssh-agent)r�recvr6r)r�wantedr-�extrarrrr7ns�zAgentSSH._read_allN)	�__name__�
__module__�__qualname__rrr0r2r!r7rrrrr=src@�0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�AgentProxyThreadz@
    Class in charge of communication between two channels.
    cCs"tjj||jd�||_d|_dS)N)�targetF)�	threading�Threadr�run�_agent�_exit�rrrrrrs
zAgentProxyThread.__init__cCshz/|��\}}||_||_|j��t|jt�s)|jjdus%t|jjd�s)t	d��|�
�WdS�)N�filenozUnable to connect to SSH agent)�get_connection�_AgentProxyThread__inr�_AgentProxyThread__addrrJ�connect�
isinstance�intr�hasattrr�_communicate)r�r�addrrrrrI�s
�zAgentProxyThread.runcCs�ddl}|�|j|j�}|�|j|j|tjB�|jswt|jj	|jgggd�}|dD]A}|jj	|krM|jj	�
d�}t|�dkrG|j�|�q+|�
�n |j|krl|j�
d�}t|�dkrf|jj	�|�q+|�
�nq+t�t�|jrdSdS)Nrg�?i)�fcntlrO�F_GETFL�F_SETFL�os�
O_NONBLOCKrKrrJrr>r6r3r2�time�sleepr)rrX�oldflags�events�fdr<rrrrU�s*
�
�zAgentProxyThread._communicatecCs d|_|j��|jj��dS)NT)rKrOr1rJrrrrrr2�s
zAgentProxyThread._closeN)rArBrC�__doc__rrIrUr2rrrrrEzsrEc@� eZdZdZdd�Zdd�ZdS)�AgentLocalProxyz�
    Class to be used when wanting to ask a local SSH Agent being
    asked from a remote fake agent (so use a unix socket for ex.)
    cCst�||�dS�N)rErrLrrrr�szAgentLocalProxy.__init__cCsJt�tjtj�}z|�|j���|�d�|��\}}||fWS�)zX
        Return a pair of socket object and string address.

        May block!
        �)�socket�AF_UNIX�SOCK_STREAM�bindrJ�
_get_filename�listen�accept)rr+rVrWrrrrN�s

zAgentLocalProxy.get_connectionN�rArBrCrbrrNrrrrrd�srdc@rc)�AgentRemoteProxyzA
    Class to be used when wanting to ask a remote SSH Agent
    cCst�||�||_dSre)rEr�_AgentRemoteProxy__chan)rr�chanrrrr�s
zAgentRemoteProxy.__init__cCs
|jdfSre)rprrrrrN�s
zAgentRemoteProxy.get_connectionNrnrrrrro�srocCs�dtjvr$tjdkr$t�tjtj�}z|�tjd�|WSYdStjdkrGddlm	}m
}d}|��r=|��}|S|��rE|�
�}|SdS)zj
    Returns some SSH agent object, or None if none were found/supported.

    .. versionadded:: 2.10
    �
SSH_AUTH_SOCK�win32Nrf)�win_pageant�win_openssh)r[�environ�sys�platformrgrhrirQ�rtru�can_talk_to_agent�PageantConnection�OpenSSHAgentConnection)r+rtrurrr�get_agent_connection�s"
�r}c@rD)�AgentClientProxya�
    Class proxying request as a client:

    #. client ask for a request_forward_agent()
    #. server creates a proxy and a fake SSH Agent
    #. server ask for establishing a connection when needed,
       calling the forward_agent_handler at client side.
    #. the forward_agent_handler launch a thread for connecting
       the remote fake agent and the local agent
    #. Communication occurs ...
    cCs&d|_||_t||�|_|j��dSre)r�_AgentClientProxy__chanRro�thread�start�r�
chanRemoterrrrszAgentClientProxy.__init__cC�|��dSre�r1rrrr�__del__
�zAgentClientProxy.__del__cCst�}|sdS||_dS)zJ
        Method automatically called by ``AgentProxyThread.run``.
        N)r}r�rr+rrrrQ
s
zAgentClientProxy.connectcCs:t|d�rd|j_|j�d�|jdur|j��dSdS)zh
        Close the current connection and terminate the agent
        Should be called manually
        r�T��N)rTr�rK�joinrr1rrrrr1s

�zAgentClientProxy.closeN)rArBrCrbrr�rQr1rrrrr~�s	r~c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�AgentServerProxya�
    Allows an SSH server to access a forwarded agent.

    This also creates a unix domain socket on the system to allow external
    programs to also access the agent. For this reason, you probably only want
    to create one of these.

    :meth:`connect` must be called before it is usable. This will also load the
    list of keys the agent contains. You must also call :meth:`close` in
    order to clean up the unix socket and the thread that maintains it.
    (:class:`contextlib.closing` might be helpful to you.)

    :param .Transport t: Transport used for SSH Agent communication forwarding

    :raises: `.SSHException` -- mostly if we lost the agent
    cCsPt�|�||_t�d�|_t�|jtj	�|jd|_
t|�|_|j�
�dS)N�sshproxyz
/sshproxy.ssh)rr�_AgentServerProxy__t�tempfile�mkdtemp�_dirr[�chmod�stat�S_IRWXU�_filerdr�r�)r�trrrr4s

zAgentServerProxy.__init__cCr�rer�rrrrr�=r�zAgentServerProxy.__del__cCs2|j��}|dur
td��|�d�|�|�dS)Nr=z
auth-agent)r��open_forward_agent_channelr�set_namer0)r�	conn_sockrrrrQ@s


zAgentServerProxy.connectcCs8t�|j�t�|j�d|j_|j�d�|��dS)zk
        Terminate the agent, clean the files, close connections
        Should be called manually
        Tr�N)	r[�remover��rmdirr�r�rKr�r2rrrrr1Gs
zAgentServerProxy.closecCsd|��iS)z�
        Helper for the environment under unix

        :return:
            a dict containing the ``SSH_AUTH_SOCK`` environment variables
        rr)rkrrrr�get_envRszAgentServerProxy.get_envcCrre)r�rrrrrk[�zAgentServerProxy._get_filenameN)
rArBrCrbrr�rQr1r�rkrrrrr�"s		r�c@rD)�AgentRequestHandlera�
    Primary/default implementation of SSH agent forwarding functionality.

    Simply instantiate this class, handing it a live command-executing session
    object, and it will handle forwarding any local SSH agent processes it
    finds.

    For example::

        # Connect
        client = SSHClient()
        client.connect(host, port, username)
        # Obtain session
        session = client.get_transport().open_session()
        # Forward local agent
        AgentRequestHandler(session)
        # Commands executed after this point will see the forwarded agent on
        # the remote end.
        session.exec_command("git clone https://my.git.repository/")
    cCs"d|_||_|�|j�g|_dSre)r�_AgentRequestHandler__chanC�request_forward_agent�_forward_agent_handler�"_AgentRequestHandler__clientProxys)r�
chanClientrrrrus
zAgentRequestHandler.__init__cCs|j�t|��dSre)r�r&r~r�rrrr�{sz*AgentRequestHandler._forward_agent_handlercCr�rer�rrrrr�~r�zAgentRequestHandler.__del__cCs|jD]}|��qdSre)r�r1)r�prrrr1�s

�zAgentRequestHandler.closeN)rArBrCrbrr�r�r1rrrrr�_sr�c@rc)�Agenta�
    Client interface for using private keys from an SSH agent running on the
    local machine.  If an SSH agent is running, this class can be used to
    connect to it and retrieve `.PKey` objects which can be used when
    attempting to authenticate to remote SSH servers.

    Upon initialization, a session with the local machine's SSH agent is
    opened, if one is running. If no agent is running, initialization will
    succeed, but `get_keys` will return an empty tuple.

    :raises: `.SSHException` --
        if an SSH agent is found, but speaks an incompatible protocol

    .. versionchanged:: 2.10
        Added support for native openssh agent on windows (extending previous
        putty pageant support)
    cCs&t�|�t�}|sdS|�|�dSre)rrr}r0r�rrrr�s

zAgent.__init__cCs|��dS)z1
        Close the SSH agent connection.
        N)r2rrrrr1�szAgent.closeN)rArBrCrbrr1rrrrr��sr�cs`eZdZdZddd�Zdd�Zdd�Zd	d
�Z�fdd�Zd
d�Z	e
dd��Zddd�Z�Z
S)r'a�
    Private key held in a local SSH agent.  This type of key can be used for
    authenticating to a remote server (signing).  Most other key operations
    work as expected.

    .. versionchanged:: 3.2
        Added the ``comment`` kwarg and attribute.

    .. versionchanged:: 3.2
        Added the ``.inner_key`` attribute holding a reference to the 'real'
        key instance this key is a proxy for, if one was obtainable, else None.
    ryc	Csz||_||_||_t|�}|��|_tt�|_d|_	zt
j|j|d�|_	WdSty<d}|�
t|�|j��YdSw)N)�key_type�	key_bytesz5Unable to derive inner_key for agent key of type {!r})rrr rr)�namer�__file__�_logger�	inner_keyr	�from_type_stringr
�logr�format)rrrr r;�errrrrr�s

��zAgentKey.__init__cOs|jj|i|��Sre)r�r�)r�args�kwargsrrrr��szAgentKey.logcCs|jr|j��S|jSre)r�rrrrrrr�szAgentKey.asbytescCrre)r�rrrr�get_name�r�zAgentKey.get_namecs|jdur
|j��St���Sre)r��get_bits�superr��	__class__rrr��s


zAgentKey.get_bitscCs|jdur	t|��t|j|�S)zO
        Proxy any un-implemented methods/properties to the inner_key.
        N)r��AttributeError�getattr)rr�rrr�__getattr__�s
zAgentKey.__getattr__cCs |��|jg}|jr|jjS|Sre)r�rr��_fields)r�fallbackrrrr��szAgentKey._fieldsNcCsbt�}|�t�|�|���|�|�|�t�|d��|j�	|�\}}|t
kr-td��|��S)Nrzkey cannot be used for signing)
r�add_byte�cSSH2_AGENTC_SIGN_REQUEST�
add_stringr�add_int�ALGORITHM_FLAG_MAP�getrr!�SSH2_AGENT_SIGN_RESPONSErr()rr<�	algorithmr;r,r-rrr�
sign_ssh_data�s

zAgentKey.sign_ssh_data)ryre)rArBrCrbrr�rr�r�r��propertyr�r��
__classcell__rrr�rr'�s


r')0rbr[rgr4rwrGr]r�r��loggingrr�paramiko.commonrr�paramiko.ssh_exceptionrr�paramiko.messager�
paramiko.pkeyr	r
�
paramiko.utilrrr"r#r�r��SSH_AGENT_RSA_SHA2_256�SSH_AGENT_RSA_SHA2_512r��list�items�key�valuerrHrErdror}r~r�r�r�r'rrrr�<module>sJ�=;
+='"