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: sport3497 (1034)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib64/python3.10/site-packages/asyncssh/__pycache__/known_hosts.cpython-310.pyc
o

�h�6�
@sdZddlZddlmZddlZddlmZmZmZm	Z	ddlm
Z
mZmZm
Z
z
ddlmZdZWney=d	ZYnwdd
lmZmZmZddlmZddlmZdd
lmZmZmZddlmZmZddlmZddlm Z m!Z!edZ"ee	e#e	ee	ee	dfZ$e
eZ%e
eZ&e
dZ'ee%e%e%e&e&e'e'fZ(ee#e#e	e)ge
e#fZ*ee#e
e#dfZ+ede#e,e*de(e
e+fZ-de
e#de
dfdd�Z.Gdd�d�Z/Gdd�d�Z0Gdd�d�Z1de#de1fdd�Z2d ee#e
e#fde1fd!d"�Z3d#e-d$e#d%e#d&e	e)de(f
d'd(�Z4dS))z Parser for SSH known_hosts files�N)�sha1)�Callable�Dict�List�Optional)�Sequence�Tuple�Union�cast�)�X509NamePatternTF)�	IPAddress�
ip_address�	read_file)�HostPatternList)�KeyImportError)�SSHKey�SSHCertificate�SSHX509Certificate)�import_public_key�import_certificate)�import_certificate_subject)�load_public_keys�load_certificates)�
_PlainHost�_HashedHostr�
SSHKnownHosts�names�returncCstsgSttt|��S)z*Load a list of X.509 subject name patterns)�_x509_available�list�mapr)r�r"�G/usr/local/CyberCP/lib/python3.10/site-packages/asyncssh/known_hosts.py�_load_subject_namesAsr$c@s<eZdZdZdefdd�Zdededeedefd	d
�Z	dS)rz(A plain host entry in a known_hosts file�patterncCst|�|_dS�N)r�_pattern)�selfr%r"r"r#�__init__Msz_PlainHost.__init__�host�addr�iprcCs|j�|||�S)z?Return whether a host or address matches this host pattern list)r'�matches)r(r*r+r,r"r"r#r-Psz_PlainHost.matchesN)
�__name__�
__module__�__qualname__�__doc__�strr)rr
�boolr-r"r"r"r#rJs"rc@sReZdZdZdZdefdd�Zdedefdd	�Zd
edede	e
defd
d�ZdS)rz)A hashed host entry in a known_hosts file�1r%c	Csxz|dd��d�\}}}t�|�|_t�|�|_Wnttjfy,td|���d�w||jkr:td|���d�dS)Nr�|z Invalid known hosts hash entry: zInvalid known hosts hash type: )�split�binascii�
a2b_base64�_salt�	_hosthash�
ValueError�Error�_HMAC_SHA1_MAGIC)r(r%�magic�salt�hosthashr"r"r#r)[s$���
���z_HashedHost.__init__�valuercCs"t�|j|��t���}||jkS)z-Return whether this host hash matches a value)�hmac�newr9�encoder�digestr:)r(rAr@r"r"r#�_matchis
z_HashedHost._matchr*r+�_ipcCs|�|�p	|�|�S)z7Return whether a host or address matches this host hash�rF)r(r*r+rGr"r"r#r-osz_HashedHost.matchesN)r.r/r0r1r=r2r)r3rFrr
r-r"r"r"r#rVs"rc	@s�eZdZdZddeefdd�Zdeddfdd�Zd	ed
eddfdd�Z	d	ed
eddfd
d�Z
	ddededeedefdd�Z
dededeedefdd�ZdS)rzAn SSH known hosts listN�known_hostscCs"i|_g|_|r|�|�dSdSr&)�_exact_entries�_pattern_entries�load)r(rIr"r"r#r)xs
�zSSHKnownHosts.__init__rc
sd|��D]�}|��}|r|�d�rqz|�d�r&|dd��dd�\}�}n
d}|�dd�\�}Wnty@td|���d�w|dvrMtd|���d�d}d}d}zt|�}Wn4ty�zt|�}Wn$ty�tsrYYqzt	|�}Wnty�YYYqwt
|�}YnwYnw||tt|�|f}	t
�fd	d
�dD��r�|��|	�q|��|	�qdS)z&Load known hosts data into this object�#�@rN�zInvalid known hosts entry: )N�cert-authority�revokedzInvalid known hosts marker: c3s�|]}|�vVqdSr&r")�.0�c�r%r"r#�	<genexpr>�s�z%SSHKnownHosts.load.<locals>.<genexpr>z*?|/!)�
splitlines�strip�
startswithr6r;rrrrrrr
r�any�_add_pattern�
_add_exact)
r(rI�line�marker�data�key�cert�subject�subject_text�entryr"rTr#rLs`
�����������zSSHKnownHosts.loadr%rccCs8|�d�D]}||jvrg|j|<|j|�|�qdS)zAdd an exact match entry�,N)r6rJ�append�r(r%rc�host_patr"r"r#r[�s


�zSSHKnownHosts._add_exactcCs0|�d�r
t|�}nt|�}|j�||f�dS)zAdd a pattern match entryr5N)rXrrrKrerfr"r"r#rZ�s

zSSHKnownHosts._add_patternr*r+�portcsp�rt���nzt���Wntyd�Ynw|r3�r%d��d|��nd��r1d��d|��nd�g}||j��g�7}||j��g�7}|���fdd�|jD�7}g}g}g}g}g}	g}
g}|D]I\}}
}}|
r�|dkrw|�|
�qe|dkr�|�|
�qe|�|
�qe|r�|dkr�|	�|�qe|�|�qe|dus�J�|dkr�|�|�qe|
�|�qe|||||	|
|fS)	z9Find host keys matching specified host, address, and portN�[z]:�c3s&�|]\}}|�����r|VqdSr&)r-)rRrc�match�r+r*r,r"r#rU�s�
�z'SSHKnownHosts._match.<locals>.<genexpr>rQrP)rr;rJ�getrKre)r(r*r+rhr-�	host_keys�ca_keys�revoked_keys�
x509_certs�
revoked_certs�
x509_subjects�revoked_subjectsr]r_r`rar"rlr#rF�sN
�
�zSSHKnownHosts._matchcCs\|�|||�\}}}}}}	}
|r%|s%|s%|s%|	s%|�||�\}}}}}}	}
||||||	|
fS)atMatch a host, IP address, and port against known_hosts patterns

           If the port is not the default port and no match is found
           for it, the lookup is attempted again without a port number.

           :param host:
               The hostname of the target host
           :param addr:
               The IP address of the target host
           :param port:
               The port number on the target host, or `None` for the default
           :type host: `str`
           :type addr: `str`
           :type port: `int`


           :returns: A tuple of matching host keys, CA keys, and revoked keys

        rH)r(r*r+rhrnrorprqrrrsrtr"r"r#rk�s�
�
�zSSHKnownHosts.matchr&)r.r/r0r1rr2r)rL�
_HostEntryr[rZ�int�_KnownHostsResultrFrkr"r"r"r#rus"4	��
�
6��r^cCst|�S)aImport SSH known hosts

       This function imports known host patterns and keys in
       OpenSSH known hosts format.

       :param data:
           The known hosts data to import
       :type data: `str`

       :returns: An :class:`SSHKnownHosts` object

    )r)r^r"r"r#�import_known_hostssrx�filelistcCs4t�}t|t�r|g}|D]
}|�t|d��q
|S)aqRead SSH known hosts from a file or list of files

       This function reads known host patterns and keys in
       OpenSSH known hosts format from a file or list of files.

       :param filelist:
           The file or list of files to read the known hosts from
       :type filelist: `str` or `list` of `str`

       :returns: An :class:`SSHKnownHosts` object

    �r)r�
isinstancer2rLr)ryrI�filenamer"r"r#�read_known_hosts.s
r}rIr*r+rhcCst|t�s|rt|t�rt|dt�rt|�}nt|t�r#t|���}t|t�r0|�|||�}nAt	|�r:||||�}t
tt|�}tt
t|dd���tt
t|dd���tt
t|dd���}t|�dkrl|d7}t
t|�}t|d�t|d�D]
}|js�td�d�q}|S)	a�Match a host, IP address, and port against a known_hosts list

       This function looks up a host, IP address, and port in a list of
       host patterns in OpenSSH `known_hosts` format and returns the
       host keys, CA keys, and revoked keys which match.

       The `known_hosts` argument can be any of the following:

           * a string containing the filename to load host patterns from
           * a byte string containing host pattern data to load
           * an already loaded :class:`SSHKnownHosts` object containing
             host patterns to match against
           * an alternate matching function which accepts a host, address,
             and port and returns lists of trusted host keys, trusted CA
             keys, and revoked keys to load
           * lists of trusted host keys, trusted CA keys, and revoked keys
             to load without doing any matching

       If the port is not the default port and no match is found
       for it, the lookup is attempted again without a port number.

       :param known_hosts:
           The host patterns to match against
       :param host:
           The hostname of the target host
       :param addr:
           The IP address of the target host
       :param port:
           The port number on the target host, or `None` for the default
       :type host: `str`
       :type addr: `str`
       :type port: `int`

       :returns: A tuple of matching host keys, CA keys, and revoked keys

    rN���)r"r"r"r"�z/OpenSSH certificates not allowed in known hosts)r{r2r r}�bytesrx�decoderrk�callabler
r�tupler!rrr$�lenrw�is_x509r;)rIr*r+rh�resultr`r"r"r#�match_known_hostsGs<
'���


��
��r�)5r1r7�hashlibrrB�typingrrrrrrr	r
�cryptorr�ImportError�miscr
rrr%r�
public_keyrrrrrrrrr�_HostPatternr2ru�_KnownHostsKeys�_KnownHostsCerts�_KnownHostsNamesrwrv�_KnownHostsCallable�_KnownHostsListArgr��
KnownHostsArgr$rrrrxr}r�r"r"r"r#�<module>sb����	)
���