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/CyberCP/lib/python3.10/site-packages/asyncssh/__pycache__/agent.cpython-310.pyc
o

�h�Z�@s�dZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZmZm
Z
ddlmZmZddlmZddlmZmZdd	lmZmZmZmZmZdd
lmZmZmZddlm Z m!Z!erdddl"m#Z#Gd
d�de�Z$Gdd�de�Z%ej&dkr�ddl'm(Z(nddl)m(Z(Gdd�de�Z*e
e+e*fZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7d Z8d!Z9d"Z:d#Z;d$Z<d%Z=dZ>d&Z?d'Z@d&ZAd(ZBGd)d*�d*e�ZCGd+d,�d,�ZDGd-d.�d.�ZEed4d0e,d1d,fd2d3��ZFdS)5�SSH agent client�N)�
TracebackType)�
TYPE_CHECKING�List�Optional�Sequence�Tuple�Type�Union)�Protocol�Self�)�SSHForwardListener)�async_context_manager�maybe_wait_closed)�Byte�String�UInt32�PacketDecodeError�	SSHPacket)�KeyPairListArg�SSHCertificate�
SSHKeyPair)�load_default_keypairs�
load_keypairs)�TemporaryDirectoryc@s"eZdZdZdedefdd�ZdS)�AgentReaderz&Protocol for reading from an SSH agent�n�returnc���dS)z'Read exactly n bytes from the SSH agentN�)�selfrr r �A/usr/local/CyberCP/lib/python3.10/site-packages/asyncssh/agent.py�readexactly+�zAgentReader.readexactlyN)�__name__�
__module__�__qualname__�__doc__�int�bytesr#r r r r"r(src@s6eZdZdZdeddfdd�Zddd�Zdd	d
�ZdS)�AgentWriterz$Protocol for writing to an SSH agent�datarNcC�dS)zWrite bytes to the SSH agentNr �r!r,r r r"�write2�zAgentWriter.writecCr-)z!Close connection to the SSH agentNr �r!r r r"�close5r0zAgentWriter.closec�r)z1Wait for the connection to the SSH agent to closeNr r1r r r"�wait_closed8r$zAgentWriter.wait_closed�rN)r%r&r'r(r*r/r2r3r r r r"r+/s

r+�win32)�
open_agentc@s&eZdZdZdeeeffdd�ZdS)�_SupportsOpenAgentConnectionz+A class that supports open_agent_connectionrc�r)z8Open a forwarded ssh-agent connection back to the clientNr r1r r r"�open_agent_connectionEr$z2_SupportsOpenAgentConnection.open_agent_connectionN)r%r&r'r(rrr+r8r r r r"r7Bsr7��
������������������cs�eZdZdZdZdddededef�fdd�Zed	efd
d��Z	ed	efdd
��Z
ded	df�fdd�Zded	df�fdd�Z
ded	efdd�Zddd�Z�ZS)�SSHAgentKeyPairz,Surrogate for a key managed by the SSH agent�agent�SSHAgentClient�	algorithm�public_data�commentc	s�|�d�}|r|�d�r|dd�d}n	|dd�}n|}|dkr*tjdkr*d}n|f}|r3|f}n|}t��||||||�||_||_d|_dS)	Ns-cert-v01@openssh.com�sk-i��s@openssh.com�ssh-rsar5)�rsa-sha2-256�rsa-sha2-512rTr)	�endswith�
startswith�sys�platform�super�__init__�_agent�_is_cert�_flags)	r!rNrPrQrR�is_cert�
sig_algorithm�sig_algorithms�host_key_algorithms��	__class__r r"r\ps&

��
zSSHAgentKeyPair.__init__rcC�|jS)z/ Return if this key pair has an associated cert)r^r1r r r"�has_cert�szSSHAgentKeyPair.has_certcCr-)z; Return if this key pair has an associated X.509 cert chainFr r1r r r"�has_x509_chain�szSSHAgentKeyPair.has_x509_chain�certNcst��|�d|_dS)z$Set certificate to use with this keyTN)r[�set_certificater^)r!rirdr r"rj�s
zSSHAgentKeyPair.set_certificateracsDt��|�|dvr|jtO_dS|dkr |jtO_dSdS)z4Set the signature algorithm to use when signing data)rUsx509v3-rsa2048-sha256rVN)r[�set_sig_algorithmr_�SSH_AGENT_RSA_SHA2_256�SSH_AGENT_RSA_SHA2_512)r!rardr r"rk�s�z!SSHAgentKeyPair.set_sig_algorithmr,c�s�|j�|j||j�IdHS)z9Asynchronously sign a block of data with this private keyN)r]�sign�key_public_datar_r.r r r"�
sign_async�s�zSSHAgentKeyPair.sign_asyncc�s�|j�|g�IdHdS)z#Remove this key pair from the agentN)r]�remove_keysr1r r r"�remove�s�zSSHAgentKeyPair.remover4)r%r&r'r(�	_key_typer*r\�property�boolrgrhrrjrkrprr�
__classcell__r r rdr"rMks 
�� 
rMc@s�eZdZdZdefdd�Zdefdd�Zdee	e
d	ee
d
eedefdd�Z
d=dd�Zedeededefdd��Zd=dd�Zdededeeeffdd�Zd>deeedeefdd�Z	d?deded edefd!d"�Z	#	
	
	$d@d%ed&eedeededd
f
d'd(�Z	
	
	$dAd)ed*eedeededd
f
d+d,�Zd%eedd
fd-d.�Z	
d>d)ed*eedd
fd/d0�Z d=d1d2�Z!d&edd
fd3d4�Z"d&edd
fd5d6�Z#deefd7d8�Z$d=d9d:�Z%d=d;d<�Z&d
S)BrOr�
agent_pathcCs ||_d|_d|_t��|_dS�N)�_agent_path�_reader�_writer�asyncio�Lock�_lock)r!rwr r r"r\�szSSHAgentClient.__init__rc�s�|S)z;Allow SSHAgentClient to be used as an async context managerr r1r r r"�
__aenter__�s�zSSHAgentClient.__aenter__�exc_type�	exc_value�	tracebackc�s�|��IdHdS)z?Wait for connection close when used as an async context managerNF)�_cleanup)r!r�r�r�r r r"�	__aexit__�s�zSSHAgentClient.__aexit__Nc�s�|��|��IdHdS)zClean up this SSH agent clientN)r2r3r1r r r"r��s�zSSHAgentClient._cleanup�lifetime�confirmcCs0d}|r|tt�t|�7}|r|tt�7}|S)zEncode key constraints�)r�SSH_AGENT_CONSTRAIN_LIFETIMEr�SSH_AGENT_CONSTRAIN_CONFIRM)r�r��resultr r r"�encode_constraints�sz!SSHAgentClient.encode_constraintsc�sF�t|jt�rt|j�IdH\|_|_dS|j��IdH\|_|_dS)zConnect to the SSH agentN)�
isinstancery�strr6rzr{r8r1r r r"�connect�s
��zSSHAgentClient.connect�msgtype�argsc
�s�|j4IdH�xzY|js|��IdH|j}|j}|dus J�|dus&J�t|�d�|�}|�tt|��|�t	�
|�d�IdHd�}t|�|�IdH�}|�
�}||fWWd�IdHStttfy}	z|��IdHtt|	��d�d}	~	ww1IdHs�wYdS)zSend an SSH agent requestNr�rL�big)r~r{r�rzr�joinr/r�lenr)�
from_bytesr#r�get_byte�OSError�EOFErrorrr��
ValueErrorr�)
r!r�r��reader�writer�payload�resplen�resp�resptype�excr r r"�
_make_request�s,�����zSSHAgentClient._make_request�
identitiesc�s��|�t�IdH\}}|tkrCg}|��}t|�D]#}|��}|��}|r*||vr*qt|�}	|	��}
|�t||
||��q|�	�|St
d|����)a�Request the available client keys

           This method is a coroutine which returns a list of client keys
           available in the ssh-agent.

           :param identities: (optional)
               A list of allowed byte string identities to return. If empty,
               all identities on the SSH agent will be returned.

           :returns: A list of :class:`SSHKeyPair` objects

        N�Unknown SSH agent response: )r��SSH_AGENTC_REQUEST_IDENTITIES�SSH_AGENT_IDENTITIES_ANSWER�
get_uint32�range�
get_stringr�appendrM�	check_endr�)r!r�r�r�r��num_keys�_�key_blobrR�packetrPr r r"�get_keyss&��
�zSSHAgentClient.get_keysrr�r,�flagsc�sb�|�tt|�t|�t|��IdH\}}|tkr"|��}|��|S|tkr*td��td|����)z+Sign a block of data with the requested keyNz!Unable to sign with requested keyr�)	r��SSH_AGENTC_SIGN_REQUESTrr�SSH_AGENT_SIGN_RESPONSEr�r��SSH_AGENT_FAILUREr�)r!r�r,r�r�r��sigr r r"rn/s��zSSHAgentClient.signr F�keylist�
passphrasec�s��|rt||�}d}nt|�}d}|�||�}tj�d�pd}tt�td�t|�}	|D]E}
|}|
j	�
d�r;||	7}|r?tnt}|
�
�}
|�||
��t|
pOd�|�IdH\}}|tkra|��q-|tkrl|sktd	��q-td
|����dS)a4Add keys to the agent

           This method adds a list of local private keys and optional
           matching certificates to the agent.

           :param keylist: (optional)
               The list of keys to add. If not specified, an attempt will
               be made to load keys from the files
               :file:`.ssh/id_ed25519_sk`, :file:`.ssh/id_ecdsa_sk`,
               :file:`.ssh/id_ed448`, :file:`.ssh/id_ed25519`,
               :file:`.ssh/id_ecdsa`, :file:`.ssh/id_rsa` and
               :file:`.ssh/id_dsa` in the user's home directory with
               optional matching certificates loaded from the files
               :file:`.ssh/id_ed25519_sk-cert.pub`,
               :file:`.ssh/id_ecdsa_sk-cert.pub`,
               :file:`.ssh/id_ed448-cert.pub`,
               :file:`.ssh/id_ed25519-cert.pub`,
               :file:`.ssh/id_ecdsa-cert.pub`, :file:`.ssh/id_rsa-cert.pub`,
               and :file:`.ssh/id_dsa-cert.pub`. Failures when adding keys
               are ignored in this case, as the agent may not recognize
               some of these key types.
           :param passphrase: (optional)
               The passphrase to use to decrypt the keys.
           :param lifetime: (optional)
               The time in seconds after which the keys should be
               automatically deleted, or `None` to store these keys
               indefinitely (the default).
           :param confirm: (optional)
               Whether or not to require confirmation for each private
               key operation which uses these keys, defaulting to `False`.
           :type keylist: *see* :ref:`SpecifyingPrivateKeys`
           :type passphrase: `str`
           :type lifetime: `int` or `None`
           :type confirm: `bool`

           :raises: :exc:`ValueError` if the keys cannot be added

        FT�SSH_SK_PROVIDER�internalzsk-provider@openssh.comrSr�NzUnable to add keyr�)rrr��os�environ�getr�SSH_AGENT_CONSTRAIN_EXTENSIONrrPrX�SSH_AGENTC_ADD_ID_CONSTRAINED�SSH_AGENTC_ADD_IDENTITY�get_comment_bytesr��get_agent_private_key�SSH_AGENT_SUCCESSr�r�r�)r!r�r�r�r��keypairs�ignore_failures�base_constraints�provider�sk_constraints�keypair�constraintsr�rRr�r�r r r"�add_keys@sD�+
�����
��zSSHAgentClient.add_keysr��pinc	�sr�|�||�}|rtnt}|�|t|�t|pd�|�IdH\}}|tkr*|��dS|tkr2td��td|����)aMStore keys associated with a smart card in the agent

           :param provider:
               The name of the smart card provider
           :param pin: (optional)
               The PIN to use to unlock the smart card
           :param lifetime: (optional)
               The time in seconds after which the keys should be
               automatically deleted, or `None` to store these keys
               indefinitely (the default).
           :param confirm: (optional)
               Whether or not to require confirmation for each private
               key operation which uses these keys, defaulting to `False`.
           :type provider: `str`
           :type pin: `str` or `None`
           :type lifetime: `int` or `None`
           :type confirm: `bool`

           :raises: :exc:`ValueError` if the keys cannot be added

        �NzUnable to add keysr�)	r��(SSH_AGENTC_ADD_SMARTCARD_KEY_CONSTRAINED�SSH_AGENTC_ADD_SMARTCARD_KEYr�rr�r�r�r�)	r!r�r�r�r�r�r�r�r�r r r"�add_smartcard_keys�s���
�z!SSHAgentClient.add_smartcard_keysc�sZ�|D]'}|�tt|j��IdH\}}|tkr|��q|tkr$td��td|����dS)z�Remove a key stored in the agent

           :param keylist:
               The list of keys to remove.
           :type keylist: `list` of :class:`SSHKeyPair`

           :raises: :exc:`ValueError` if any keys are not found

        Nz
Key not foundr�)r��SSH_AGENTC_REMOVE_IDENTITYrrQr�r�r�r�)r!r�r�r�r�r r r"rq�s���
�zSSHAgentClient.remove_keysc�sX�|�tt|�t|pd��IdH\}}|tkr|��dS|tkr%td��td|����)awRemove keys associated with a smart card stored in the agent

           :param provider:
               The name of the smart card provider
           :param pin: (optional)
               The PIN to use to unlock the smart card
           :type provider: `str`
           :type pin: `str` or `None`

           :raises: :exc:`ValueError` if the keys are not found

        r�NzKeys not foundr�)r��SSH_AGENTC_REMOVE_SMARTCARD_KEYrr�r�r�r�)r!r�r�r�r�r r r"�remove_smartcard_keys�s���z$SSHAgentClient.remove_smartcard_keysc�sH�|�t�IdH\}}|tkr|��dS|tkrtd��td|����)zqRemove all keys stored in the agent

           :raises: :exc:`ValueError` if the keys can't be removed

        NzUnable to remove all keysr�)r�� SSH_AGENTC_REMOVE_ALL_IDENTITIESr�r�r�r�)r!r�r�r r r"�
remove_all�s��zSSHAgentClient.remove_allc��N�|�tt|��IdH\}}|tkr|��dS|tkr td��td|����)a�Lock the agent using the specified passphrase

           .. note:: The lock and unlock actions don't appear to be
                     supported on the Windows 10 OpenSSH agent.

           :param passphrase:
               The passphrase required to later unlock the agent
           :type passphrase: `str`

           :raises: :exc:`ValueError` if the agent can't be locked

        NzUnable to lock SSH agentr�)r��SSH_AGENTC_LOCKrr�r�r�r��r!r�r�r�r r r"�lock����zSSHAgentClient.lockc�r�)aUnlock the agent using the specified passphrase

           .. note:: The lock and unlock actions don't appear to be
                     supported on the Windows 10 OpenSSH agent.

           :param passphrase:
               The passphrase to use to unlock the agent
           :type passphrase: `str`

           :raises: :exc:`ValueError` if the agent can't be unlocked

        NzUnable to unlock SSH agentr�)r��SSH_AGENTC_UNLOCKrr�r�r�r�r�r r r"�unlockr�zSSHAgentClient.unlockc�s��|�ttd��IdH\}}|tkr7g}|r5|��}z|�d�}Wnty-td�d�w|�|�|s|S|t	kr=gStd|����)z�Return a list of extensions supported by the agent

           :returns: A list of strings of supported extension names

        �queryNzutf-8zInvalid extension type namer�)
r��SSH_AGENTC_EXTENSIONrr�r��decode�UnicodeDecodeErrorr�r�r�)r!r�r�r��exttype�exttype_strr r r"�query_extensions-s&��
�
�
zSSHAgentClient.query_extensionscCs|jr
|j��dSdS)z�Close the SSH agent connection

           This method closes the connection to the ssh-agent. Any
           attempts to use this :class:`SSHAgentClient` or the key
           pairs it previously returned will result in an error.

        N)r{r2r1r r r"r2Js	�zSSHAgentClient.closec�s,�|jrt|j�IdHd|_d|_dSdS)z�Wait for this agent connection to close

           This method is a coroutine which can be called to block until
           the connection to the agent has finished closing.

        N)r{rrzr1r r r"r3Vs�
�zSSHAgentClient.wait_closedr4rx)r)r NNF)NNF)'r%r&r'r(�
_AgentPathr\rrrr	�
BaseExceptionrrur�r��staticmethodr)r*r�r�rrr�rrr�rnrr�r�r�rqr�r�r�r�r�r2r3r r r r"rO�s���
�


	

�
�)��
�����
�S����
�)��
�

rOc@s>eZdZdZdddedefdd�Zdefd	d
�Zddd
�ZdS)�SSHAgentListenerz*Listener used to forward agent connections�tempdirzTemporaryDirectory[str]�path�
unix_listenercCs||_||_||_dSrx)�_tempdir�_path�_unix_listener)r!r�r�r�r r r"r\hs
zSSHAgentListener.__init__rcCrf)z!Return the path being listened on)r�r1r r r"�get_pathnszSSHAgentListener.get_pathNcCs|j��|j��dS)zClose the agent listenerN)r�r2r��cleanupr1r r r"r2ss
zSSHAgentListener.closer4)	r%r&r'r(r�rr\r�r2r r r r"r�es

�r�r�rwrc�s.�|s
tj�dd�}t|�}|��IdH|S)a�Make a connection to the SSH agent

       This function attempts to connect to an ssh-agent process
       listening on a UNIX domain socket at `agent_path`. If not
       provided, it will attempt to get the path from the `SSH_AUTH_SOCK`
       environment variable.

       If the connection is successful, an :class:`SSHAgentClient` object
       is returned that has methods on it you can use to query the
       ssh-agent. If no path is specified and the environment variable
       is not set or the connection to the agent fails, an error is
       raised.

       :param agent_path: (optional)
           The path to use to contact the ssh-agent process, or the
           :class:`SSHServerConnection` to forward the agent request
           over.
       :type agent_path: `str` or :class:`SSHServerConnection`

       :returns: An :class:`SSHAgentClient`

       :raises: :exc:`OSError` or :exc:`ChannelOpenError` if the
                connection to the agent can't be opened

    �
SSH_AUTH_SOCKr�N)r�r�r�rOr�)rwrNr r r"�
connect_agentzs�r�)r�)Gr(r|r�rY�typesr�typingrrrrrr	r
�typing_extensionsrr�listenerr�miscrrr�rrrrr�
public_keyrrrrr�tempfilerrr+rZ�agent_win32r6�
agent_unixr7r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��SSH_AGENT_EXTENSION_FAILUREr�r�r�rlrmrMrOr�r�r r r r"�<module>sf$

M0