%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/paramiko/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/paramiko/__pycache__/agent.cpython-312.pyc

�

�ec�3���dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m	Z	ddl
mZmZddl
mZddlmZmZddlmZddlmZdd	lmZed
�ZdZed�Zd
ZdZdZeed�ZGd�de�Z Gd�dejB�Z"Gd�de"�Z#Gd�de"�Z$d�Z%Gd�de�Z&Gd�de �Z'Gd�de�Z(Gd �d!e �Z)Gd"�d#e�Z*y)$z
SSH Agent interface
�N)�select)�asbytes�io_sleep)�byte_chr)�SSHException�AuthenticationException)�Message)�PKey)�retry_on_signal���
���)zrsa-sha2-256zrsa-sha2-512c�0�eZdZd�Zd�Zd�Zd�Zd�Zd�Zy)�AgentSSHc� �d|_d|_y�N�)�_conn�_keys��selfs �0/usr/lib/python3/dist-packages/paramiko/agent.py�__init__zAgentSSH.__init__;s����
���
�c��|jS)a4
        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.

        :return:
            a tuple of `.AgentKey` objects representing keys available on the
            SSH agent
        )rrs r�get_keyszAgentSSH.get_keys?s���z�z�rc�<�||_|jt�\}}|tk7rt	d��g}t|j
��D];}|jt||j���|j��=t|�|_y)Nz!could not get keys from ssh-agent)
r�
_send_message�cSSH2_AGENTC_REQUEST_IDENTITIES�SSH2_AGENT_IDENTITIES_ANSWERr�range�get_int�append�AgentKey�
get_binary�
get_string�tupler)r�conn�ptype�result�keys�is      r�_connectzAgentSSH._connectKs�����
��*�*�+J�K�
��v��0�0��B�C�C����v�~�~�'�(�	 �A��K�K���v�'8�'8�':�;�<�����	 ��4�[��
rc�l�|j�|jj�d|_d|_yr)r�closerrs r�_closezAgentSSH._closeVs*���:�:�!��J�J������
���
rc�H�t|�}|jjtjdt|��|z�|j
d�}t|j
tjd|�d��}t|j��|fS)Nz>Irr)rr�send�struct�pack�len�	_read_allr	�unpack�ord�get_byte)r�msg�datas   rr!zAgentSSH._send_message\sv���c�l���
�
������D�#�c�(�3�c�9�:��~�~�a� ���d�n�n�V�]�]�4��%>�q�%A�B�C���3�<�<�>�"�C�'�'rc�2�|jj|�}t|�|krmt|�dk(rtd��|jj|t|�z
�}t|�dk(rtd��||z
}t|�|kr�m|S)Nr�lost ssh-agent)r�recvr8r)r�wantedr-�extras    rr9zAgentSSH._read_allcs���������(���&�k�F�"��6�{�a��"�#3�4�4��J�J�O�O�F�S��[�$8�9�E��5�z�Q��"�#3�4�4��e�O�F�
�&�k�F�"��
rN)	�__name__�
__module__�__qualname__rrr0r3r!r9rrrrr:s ���
�	!��(�	rrc�(�eZdZdZd�Zd�Zd�Zd�Zy)�AgentProxyThreadz@
    Class in charge of communication between two channels.
    c�v�tjj||j��||_d|_y)N)�targetF)�	threading�Threadr�run�_agent�_exit�r�agents  rrzAgentProxyThread.__init__ts-�����!�!�$�t�x�x�!�8������
rc�^�	|j�\}}||_||_|jj	�t|jt�sA|jj� t|jjd�std��|j�y#�xYw)N�filenozUnable to connect to SSH agent)�get_connection�_AgentProxyThread__inr�_AgentProxyThread__addrrN�connect�
isinstance�intr�hasattrr�_communicate)r�r�addrs   rrMzAgentProxyThread.runys���	��+�+�-�I�Q���D�J��D�K��K�K���!��d�k�k�3�/����!�!�)��t�{�{�0�0�(�;�-�.N�O�O������	��s�B&B)�)B,c�v�ddl}|j|j|j�}|j|j|j|tj
z�|j�sJt|jj|jgggd�}|dD]�}|jj|k(ra|jjjd�}t|�dk7r|jj|��k|j�nr|j|k(s��|jjd�}t|�dk7r&|jjj|���|j�ntjt �|js��Iyy)Nrg�?i)�fcntlrU�F_GETFL�F_SETFL�os�
O_NONBLOCKrOrrNrrAr8r5r3�time�sleepr)rr_�oldflags�events�fdr>s      rr[zAgentProxyThread._communicate�s2����;�;�t�z�z�5�=�=�9��
���D�J�J��
�
�x�"�-�-�/G�H��*�*��T�[�[�.�.��
�
�;�R��S�I�F��Q�i�
���;�;�$�$��*��;�;�,�,�1�1�#�6�D��4�y�A�~��
�
����-����
���Z�Z�2�%��:�:�?�?�3�/�D��4�y�A�~����)�)�.�.�t�4����
��
�
�J�J�x� �#�*�*rc��d|_|jj�|jjj�y)NT)rOrUr2rNrrs rr3zAgentProxyThread._close�s/����
��
�
�����������!rN)rDrErF�__doc__rrMr[r3rrrrHrHos����
�&!�0"rrHc��eZdZdZd�Zd�Zy)�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.)
    c�0�tj||�y�N)rHrrPs  rrzAgentLocalProxy.__init__�s���!�!�$��.rc��tjtjtj�}	|j|jj��|j
d�|j�\}}||fS#�xYw)zX
        Return a pair of socket object and string address.

        May block!
        �)�socket�AF_UNIX�SOCK_STREAM�bindrN�
_get_filename�listen�accept)rr+r\r]s    rrTzAgentLocalProxy.get_connection�si���}�}�V�^�^�V�-?�-?�@��	��I�I�d�k�k�/�/�1�2��K�K��N����
�I�Q���d�7�N��	��s�AB�BN�rDrErFrjrrTrrrrlrl�s���
/�
rrlc��eZdZdZd�Zd�Zy)�AgentRemoteProxyzA
    Class to be used when wanting to ask a remote SSH Agent
    c�>�tj||�||_yrn)rHr�_AgentRemoteProxy__chan)rrQ�chans   rrzAgentRemoteProxy.__init__�s���!�!�$��.���rc��|jdfSrn)r|rs rrTzAgentRemoteProxy.get_connection�s���{�{�D� � rNrxrrrrzrz�s����!rrzc���dtjvrVtjdk7rCt	jtj
tj��	t�fd���Stjdk(rNddlm	}m
}d�|j�r|j���S|j�r|j���Sy#YyxYw)zj
    Returns some SSH agent object, or None if none were found/supported.

    .. versionadded:: 2.10
    �
SSH_AUTH_SOCK�win32c�H���jtjd�S)Nr�)rWrb�environ)r+s�r�<lambda>z&get_agent_connection.<locals>.<lambda>�s���D�L�L����O�1L�$M�rNrp)�win_pageant�win_openssh)rbr��sys�platformrqrrrsr�r�r��can_talk_to_agent�PageantConnection�OpenSSHAgentConnection)r�r�r+s  @r�get_agent_connectionr��s����	�2�:�:�%�C�L�L�G�,C��}�}�V�^�^�V�-?�-?�@��	��M�N��K�

����	 �.����(�(�*��0�0�2�D����
*�
*�
,��5�5�7�D���	��	��s�C�Cc�(�eZdZdZd�Zd�Zd�Zd�Zy)�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 ...
    c�v�d|_||_t||�|_|jj	�yrn)r�_AgentClientProxy__chanRrz�thread�start�r�
chanRemotes  rrzAgentClientProxy.__init__�s.����
�!���&�t�Z�8��������rc�$�|j�yrn�r2rs r�__del__zAgentClientProxy.__del__�����
�
�rc�,�t�}|sy||_y)zJ
        Method automatically called by ``AgentProxyThread.run``.
        N)r�r�rr+s  rrWzAgentClientProxy.connects��$�%������
rc���t|d�r,d|j_|jjd�|j�|jj�yy)zh
        Close the current connection and terminate the agent
        Should be called manually
        r�T��N)rZr�rO�joinrr2rs rr2zAgentClientProxy.closesK��
�4��"� $�D�K�K���K�K���T�"��:�:�!��J�J����"rN)rDrErFrjrr�rWr2rrrr�r��s��
����	rr�c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�AgentServerProxyz�
    :param .Transport t: Transport used for SSH Agent communication forwarding

    :raises: `.SSHException` -- mostly if we lost the agent
    c�H�tj|�||_tjd�|_t
j|j
tj�|j
dz|_
t|�|_|jj�y)N�sshproxyz
/sshproxy.ssh)rr�_AgentServerProxy__t�tempfile�mkdtemp�_dirrb�chmod�stat�S_IRWXU�_filerlr�r�)r�ts  rrzAgentServerProxy.__init__sk�����$������$�$�Z�0��	�
������D�L�L�)��Y�Y��0��
�%�d�+��������rc�$�|j�yrnr�rs rr�zAgentServerProxy.__del__'r�rc��|jj�}|�td��|jd�|j	|�y)Nr@z
auth-agent)r��open_forward_agent_channelr�set_namer0)r�	conn_socks  rrWzAgentServerProxy.connect*s@���H�H�7�7�9�	����/�0�0����<�(��
�
�i� rc��tj|j�tj|j�d|j
_|j
jd�|j�y)zk
        Terminate the agent, clean the files, close connections
        Should be called manually
        Tr�N)	rb�remover��rmdirr�r�rOr�r3rs rr2zAgentServerProxy.close1sK��
	�	�	�$�*�*��
������� ���������������
rc�&�d|j�iS)z�
        Helper for the environnement under unix

        :return:
            a dict containing the ``SSH_AUTH_SOCK`` environnement variables
        r�)rurs r�get_envzAgentServerProxy.get_env<s�� ��!3�!3�!5�6�6rc��|jSrn)r�rs rruzAgentServerProxy._get_filenameEs���z�z�rN)
rDrErFrjrr�rWr2r�rurrrr�r�s%�����!�	�7�rr�c�(�eZdZdZd�Zd�Zd�Zd�Zy)�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/")
    c�d�d|_||_|j|j�g|_yrn)r�_AgentRequestHandler__chanC�request_forward_agent�_forward_agent_handler�"_AgentRequestHandler__clientProxys)r�
chanClients  rrzAgentRequestHandler.__init___s,����
�!����(�(��)D�)D�E� ��rc�L�|jjt|��yrn)r�r&r�r�s  rr�z*AgentRequestHandler._forward_agent_handleres�����"�"�#3�J�#?�@rc�$�|j�yrnr�rs rr�zAgentRequestHandler.__del__hr�rc�F�|jD]}|j��yrn)r�r2)r�ps  rr2zAgentRequestHandler.closeks ���$�$�	�A�
�G�G�I�	rN)rDrErFrjrr�r�r2rrrr�r�Is���*!�A��rr�c��eZdZdZd�Zd�Zy)�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)
    c�j�tj|�t�}|sy|j|�yrn)rrr�r0r�s  rrzAgent.__init__�s*�����$��#�%�����
�
�d�rc�$�|j�y)z1
        Close the SSH agent connection.
        N)r3rs rr2zAgent.close�s
��	
���
rN)rDrErFrjrr2rrrr�r�ps���$�rr�c�@�eZdZdZd�Zd�Zd�Zd�Zed��Z	d	d�Z
y)
r'z�
    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.
    c�j�||_||_d|_t|�j	�|_yrn)rQ�blob�public_blobr	�get_text�name)rrQr�s   rrzAgentKey.__init__�s,����
���	�����D�M�*�*�,��	rc��|jSrn)r�rs rrzAgentKey.asbytes�����y�y�rc�"�|j�Srn)rrs r�__str__zAgentKey.__str__�s���|�|�~�rc��|jSrn)r�rs r�get_namezAgentKey.get_name�r�rc��t�rn)�NotImplementedErrorrs r�_fieldszAgentKey._fields�s��!�!rNc�f�t�}|jt�|j|j�|j|�|jtj|d��|jj|�\}}|tk7rtd��|j�S)Nrzkey cannot be used for signing)
r	�add_byte�cSSH2_AGENTC_SIGN_REQUEST�
add_stringr��add_int�ALGORITHM_FLAG_MAP�getrQr!�SSH2_AGENT_SIGN_RESPONSErr()rr>�	algorithmr=r,r-s      r�
sign_ssh_datazAgentKey.sign_ssh_data�s����i�����.�/����t�y�y�!����t�����&�*�*�9�a�8�9��
�
�0�0��5�
��v��,�,��?�@�@�� � �"�"rrn)rDrErFrjrrr�r��propertyr�r�rrrr'r'�s4���-�����"��"�	#rr')+rjrbrqr6r�rKrdr�r�r�paramiko.commonrr�paramiko.py3compatr�paramiko.ssh_exceptionrr�paramiko.messager	�
paramiko.pkeyr
�
paramiko.utilrr"r#r�r��SSH_AGENT_RSA_SHA2_256�SSH_AGENT_RSA_SHA2_512r��objectrrLrHrlrzr�r�r�r�r�r'rrr�<module>r�s���&�
�
�
�
������-�'�H�$��)�"*�2�,��!��$�R�L��������+�*���2�v�2�j8"�y�'�'�8"�v�&��2
!�'�
!��8(�v�(�V/�x�/�d$�&�$�N�H��D##�t�##r

Zerion Mini Shell 1.0