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

�h6.�@s dZddlmZmZmZmZmZddlmZmZm	Z	m
Z
zddlmZm
Z
dZWney3dZYnwddlmZmZdd	lmZmZdd
lmZmZddlmZmZddlmZmZdd
lmZeeefZ Gdd�d�Z!Gdd�d�Z"dede"fdd�Z#de	eeefde"fdd�Z$dS)z$Parser for SSH authorized_keys files�)�Dict�List�Mapping�Optional�Sequence)�Set�Tuple�Union�cast�)�X509Name�X509NamePatternTF)�
ip_address�	read_file)�HostPatternList�WildcardPatternList)�KeyImportError�SSHKey)�SSHX509Certificate�SSHX509CertificateChain)�import_public_key�import_certificate)�import_certificate_subjectc@seZdZdZdefdd�Zdeddfdd�Zd	ed
eddfdd�Zd	ed
eddfd
d�Zd	ed
eddfdd�Z	d	ed
eddfdd�Z
d	ed
eddfdd�Zd	ed
eddfdd�Zeee	e
eed�Z
d#dd�Zdedefdd�Z	d$dededeeeded def
d!d"�ZdS)%�_SSHAuthorizedKeyEntryz'An entry in an SSH authorized_keys list�linecCsNd|_d|_i|_z|�|�WdStyYnw|�|�}|�|�dS�N)�key�cert�options�_import_key_or_certr�_parse_options��selfr�r#�H/usr/local/CyberPanel/lib/python3.10/site-packages/asyncssh/auth_keys.py�__init__.s
�
z_SSHAuthorizedKeyEntry.__init__�returnNcCs�zt|�|_WdStyYnwzttt|��|_d|jvr,|jj|jj	kr,t
d��WdSty7Ynwd|jvr[zd|_d|_|�dt|��WdStyZYtd��wtd��)z'Import key or certificate in this entryN�cert-authorityz?X.509 cert-authority entries must contain a root CA certificate�subjectz)Unrecognized key, certificate, or subject)
rrrr
rrrrr(�issuer�
ValueError�_add_subjectrr!r#r#r$r<s4
�
�
�z*_SSHAuthorizedKeyEntry._import_key_or_cert�option�valuecCs||j|<dS)z!Set an option with a string valueN)r)r"r,r-r#r#r$�_set_string\sz"_SSHAuthorizedKeyEntry._set_stringcCsN|�d�s	d|vr
td��|�dd�\}}|ttttf|j�|i��|<dS)z!Add an environment key/value pair�=z,Invalid environment entry in authorized_keysrN)�
startswithr*�splitr
r�strr�
setdefault)r"r,r-�namer#r#r$�_add_environmentas$z'_SSHAuthorizedKeyEntry._add_environmentcC�*ttt|j�|g��}|�t|��dS)zAdd a from host patternN)r
rrrr3�append)r"r,r-�
from_patternsr#r#r$�	_add_fromj��z _SSHAuthorizedKeyEntry._add_fromcCs�z$|�dd�\}}|�d�r|�d�r|dd�}|dkrdnt|�}Wnty3td|���d�wttttt	tf|j
�|t���}|�
||f�dS)	zAdd a permitopen host/port pair�:r�[�]����*NzIllegal permitopen value: )�rsplitr0�endswith�intr*r
rrr2rrr3�set�add)r"r,r-�host�port_str�port�permitted_opensr#r#r$�_add_permitopenqs��z&_SSHAuthorizedKeyEntry._add_permitopencCr6)z&Add a principals wildcard pattern listN)r
rrrr3r7)r"r,r-�principal_patternsr#r#r$�_add_principals�r:z&_SSHAuthorizedKeyEntry._add_principalscCs2trttt|j�|g��}|�t|��dSdS)zAdd an X.509 subject patternN)�_x509_availabler
rr
rr3r7)r"r,r-�subject_patternsr#r#r$r+�s��z#_SSHAuthorizedKeyEntry._add_subject)�command�environment�from�
permitopen�
principalsr(cCs�|j�d�r
td��d|jvr;|j�dd�\}}|j�|�}|r(||||�dSttt|j	�
|g��}|�|�dSd|j	|j<dS)zAdd an option valuer/z&Missing option name in authorized_keysrTN)�_optionr0r*r1�	_handlers�getr
rr2rr3r7)r"r,r-�handler�valuesr#r#r$�_add_option�s
z"_SSHAuthorizedKeyEntry._add_optioncCs�d|_d}d}d}t|�D]B\}}|r|j|7_d}q
|dkr$d}q
|dkr,|}q
|r6|j|7_q
|dvr<n|dkrH|��d|_q
|j|7_q
|��|rZtd	��|r`td
��||d���S)zParse options in this entry�rF�\T�"z 	�,z#Unbalanced quote in authorized_keysz'Unbalanced backslash in authorized_keysN)rS�	enumeraterXr*�strip)r"r�idx�quoted�escaped�chr#r#r$r �s4z%_SSHAuthorizedKeyEntry._parse_options�client_host�client_addr�cert_principals�cert_subjectrcs�ttt|j�d��}|r t���t���fdd�|D��s dSttt|j�d��}�dur@|dur@t�fdd�|D��s@dSttd|j�d	��}�dur`|dur`t�fd
d�|D��s`dSdS)z9Match "from", "principals" and "subject" options in entryrPc3s�|]
}|�����VqdSr��matches��.0�pattern)rdrc�	client_ipr#r$�	<genexpr>�s��z7_SSHAuthorizedKeyEntry.match_options.<locals>.<genexpr>FrRNc3s&�|]�t�fdd��D��VqdS)c3s�|]}��|�VqdSrrg)rj�	principal�rkr#r$rm����zA_SSHAuthorizedKeyEntry.match_options.<locals>.<genexpr>.<genexpr>N)�any)rj)reror$rm�s���r
r(c3s�|]}|���VqdSrrgri)rfr#r$rm�rpT)r
rrrrUr�allr)r"rcrdrerfr8rJrMr#)rerfrdrcrlr$�
match_options�s0�
��
��z$_SSHAuthorizedKeyEntry.match_options)r&Nr)�__name__�
__module__�__qualname__�__doc__r2r%rr.r5r9rIrKr+rTrXr rr�boolrsr#r#r#r$r+s6 		�
	&�
���rc@s�eZdZdZddeefdd�Zdeddfdd�Z			dd
ededed
ee	ede
deeeeffdd�Z
dedededeeeeeffdd�ZdS)�SSHAuthorizedKeyszAn SSH authorized keys listN�authorized_keyscCs(g|_g|_g|_|r|�|�dSdSr)�
_user_entries�_ca_entries�
_x509_entries�load)r"rzr#r#r$r%�s�zSSHAuthorizedKeys.__init__r&c	Cs�|��D]:}|��}|r|�d�rqzt|�}Wn	ty!Yqw|jr8d|jvr1|j�|�q|j	�|�q|j
�|�q|j	sL|jsN|j
sPtd��dSdSdS)z*Load authorized keys data into this object�#r'zNo valid entries foundN)�
splitlinesr^r0rrrrr|r7r{r}r*)r"rzr�entryr#r#r$r~�s&�
��zSSHAuthorizedKeys.loadFrrcrdre�cacCs<|r|jn|jD]}|j|kr|�|||�r|jSqdS)z=Return whether a public key or CA is valid for authenticationN)r|r{rrsr)r"rrcrdrer�r�r#r#r$�validates
��
�zSSHAuthorizedKeys.validatercCsb|jD]+}|jrd|jvr|j|jjks|j|jjkrq|�|||j|j�r.|j|jfSqdS)z?Return whether an X.509 certificate is valid for authenticationr')NN)r}rrrr(rs�user_principals)r"rrcrdr�r#r#r$�
validate_x509#s
��zSSHAuthorizedKeys.validate_x509r)NF)rtrurvrwrr2r%r~rrrxr�objectr�rr�
_EntryOptionsrr�r#r#r#r$ry�s(�
��
�

���ry�datar&cCst|�S)aImport SSH authorized keys

       This function imports public keys and associated options in
       OpenSSH authorized keys format.

       :param data:
           The key data to import.
       :type data: `str`

       :returns: An :class:`SSHAuthorizedKeys` object

    )ry)r�r#r#r$�import_authorized_keys4sr��filelistcCs:t�}t|t�r|g}n|}|D]
}|�t|d��q|S)a~Read SSH authorized keys from a file or list of files

       This function reads public keys and associated options in
       OpenSSH authorized_keys format from a file or list of files.

       :param filelist:
           The file or list of files to read the keys from.
       :type filenlist: `str` or `list` of `str`

       :returns: An :class:`SSHAuthorizedKeys` object

    �r)ry�
isinstancer2r~r)r�rz�files�filenamer#r#r$�read_authorized_keysEs
r�N)%rw�typingrrrrrrrr	r
�cryptorr
rL�ImportError�miscrrrkrr�
public_keyrrrrrrrr2r�r�rryr�r�r#r#r#r$�<module>s.�HB�