%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__/hostkeys.cpython-312.pyc

�

�ec�3���ddlZddlZddlZejdddk\rddlmZnddlmZddlmZddl	m
Z
ddlmZm
Z
mZmZddlmZdd	lmZdd
lmZmZddlmZddlmZdd
lmZGd�de�ZGd�de�ZGd�d�Z y)�N�)�r)�MutableMapping)�sha1)�HMAC)�b�u�encodebytes�decodebytes)�DSSKey)�RSAKey)�
get_logger�constant_time_bytes_eq)�ECDSAKey)�
Ed25519Key)�SSHExceptionc�~�eZdZdZdd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zd�Zd�Zedd��Zy)�HostKeysaZ
    Representation of an OpenSSH-style "known hosts" file.  Host keys can be
    read from one or more files, and then individual hosts can be looked up to
    verify server keys during SSH negotiation.

    A `.HostKeys` object can be treated like a dict; any dict lookup is
    equivalent to calling `lookup`.

    .. versionadded:: 1.5.3
    Nc�:�g|_|�|j|�yy)z�
        Create a new HostKeys object, optionally loading keys from an OpenSSH
        style host-key file.

        :param str filename: filename to load host keys from, or ``None``
        N)�_entries�load)�self�filenames  �3/usr/lib/python3/dist-packages/paramiko/hostkeys.py�__init__zHostKeys.__init__5s"����
����I�I�h�� �c���|jD]7}||jvs�|jj�|k(s�0||_y|jj	t|g|��y)a.
        Add a host key entry to the table.  Any existing entry for a
        ``(hostname, keytype)`` pair will be replaced.

        :param str hostname: the hostname (or IP) to add
        :param str keytype: key type (``"ssh-rsa"`` or ``"ssh-dss"``)
        :param .PKey key: the key to add
        N)r�	hostnames�key�get_name�append�HostKeyEntry)r�hostname�keytyper�es     r�addzHostKeys.addAs\�����	�A��A�K�K�'�a�e�e�n�n�.>�'�.I�����	�	
�
�
���\�8�*�c�:�;rc��t|d�5}t|d�D]�\}}|j�}t|�dk(s|ddk(r�-	tj||�}|��G|j}|D]:}|j||j�s� |jj|��<t|j�s��|jj|���	ddd�y#t$rY��wxYw#1swYyxYw)a]
        Read a file of known SSH host keys, in the format used by OpenSSH.
        This type of file unfortunately doesn't exist on Windows, but on
        posix, it will usually be stored in
        ``os.path.expanduser("~/.ssh/known_hosts")``.

        If this method is called multiple times, the host keys are merged,
        not cleared.  So multiple calls to `load` will just call `add`,
        replacing any existing entries and adding new ones.

        :param str filename: name of the file to read host keys from

        :raises: ``IOError`` -- if there was an error reading the file
        �r�r�#N)
�open�	enumerate�strip�lenr"�	from_linerr�checkr�removerr!)rr�f�lineno�liner%�
_hostnames�hs        rrz
HostKeys.loadPs����(�C�
 �	0�A� )�!�Q��
0�����z�z�|����I��N��Q��3����$�.�.�t�V�<�A��=�!"���J�'�2���:�:�a����/��K�K�.�.�q�1�2��1�;�;�'��
�
�,�,�Q�/�
0�	0�	0��$�����	0�	0�sA�:C8�C)�C8�!-C8�2C8�C8�)	C5�2C8�4C5�5C8�8Dc��t|d�5}|jD]&}|j�}|s�|j|��(	ddd�y#1swYyxYw)a�
        Save host keys into a file, in the format used by OpenSSH.  The order
        of keys in the file will be preserved when possible (if these keys were
        loaded from a file originally).  The single exception is that combined
        lines will be split into individual key lines, which is arguably a bug.

        :param str filename: name of the file to write

        :raises: ``IOError`` -- if there was an error writing the file

        .. versionadded:: 1.6.1
        �wN)r+r�to_line�write)rrr2r%r4s     r�savez
HostKeys.savepsQ���(�C�
 �	"�A��]�]�
"���y�y�{����G�G�D�M�
"�	"�	"�	"�s�"A
�A
�
Ac����G�fd�dt�}g}|jD]&}|j�|�s�|j|��(t	|�dk(ry|�||�S)a�
        Find a hostkey entry for a given hostname or IP.  If no entry is found,
        ``None`` is returned.  Otherwise a dictionary of keytype to key is
        returned.  The keytype will be either ``"ssh-rsa"`` or ``"ssh-dss"``.

        :param str hostname: the hostname (or IP) to lookup
        :return: dict of `str` -> `.PKey` keys associated with this host
            (or ``None``)
        c�<��eZdZd�Zd�Zd�Zd�Zd�Z�fd�Zd�Z	y)	� HostKeys.lookup.<locals>.SubDictc�.�||_||_||_y�N)�	_hostnamer�	_hostkeys)rr#�entries�hostkeyss    rrz)HostKeys.lookup.<locals>.SubDict.__init__�s��!)��� '��
�!)��rc3�>K�|j�D]}|���y�wr@��keys�r�ks  r�__iter__z)HostKeys.lookup.<locals>.SubDict.__iter__�s ���������A��G����c�4�t|j��Sr@�r.rG�rs r�__len__z(HostKeys.lookup.<locals>.SubDict.__len__�s���4�9�9�;�'�'rc��t|j�D]<}|jj�|k(s�!|jj	|�yt|��r@)�listrrr r1�KeyError�rrr%s   r�__delitem__z,HostKeys.lookup.<locals>.SubDict.__delitem__�sN���d�m�m�,�(�A��u�u�~�~�'�3�.��
�
�,�,�Q�/��(�
#�3�-�'rc��|jD]-}|jj�|k(s�!|jcSt|��r@)rrr rRrSs   r�__getitem__z,HostKeys.lookup.<locals>.SubDict.__getitem__�s=�����%�A��u�u�~�~�'�3�.� �u�u��%��s�m�#rc�(��|jD]5}|j��|jj�|k(s�.||_yt�g|�}|jj	|�|j
jj	|�yr@)rrr r"r!rB)rr�valr%r#s    �r�__setitem__z,HostKeys.lookup.<locals>.SubDict.__setitem__�sy������6�A��u�u�}� ��u�u�~�~�'�3�.� #����
6�%�h�Z��5�A��M�M�(�(��+��N�N�+�+�2�2�1�5rc��|jD�cgc](}|j�|jj���*c}Scc}wr@)rrr )rr%s  rrGz%HostKeys.lookup.<locals>.SubDict.keys�s=��"�]�]����u�u�(��E�E�N�N�$����s�-?N)
�__name__�
__module__�__qualname__rrJrOrTrVrYrG)r#s�r�SubDictr>�s&���
*�

�
(�
(�
$�
6�
rr^rN)rr�_hostname_matchesr!r.)rr#r^rCr%s `   r�lookupzHostKeys.lookup�sf���.	�n�.	�`�����	"�A��%�%�h��2����q�!�	"��w�<�1����x��$�/�/rc��|jD]I}||k(sA|jd�s�|jd�r�,t|j||�|�s�Iyy)zl
        Tests whether ``hostname`` string matches given SubDict ``entry``.

        :returns bool:
        �|1|TF)r�
startswithr�	hash_host)rr#�entryr6s    rr_zHostKeys._hostname_matches�sU�����	�A��X�
��<�<��&� �+�+�E�2�*�4�>�>�(�A�+F��J��	�rc��|j|�}|�y|j|j�d�}|�y|j�|j�k(S)a=
        Return True if the given key is associated with the given hostname
        in this dictionary.

        :param str hostname: hostname (or IP) of the SSH server
        :param .PKey key: the key to check
        :return:
            ``True`` if the key is associated with the hostname; else ``False``
        NF)r`�getr �asbytes)rr#rrI�host_keys     rr0zHostKeys.check�sS��
�K�K��!���9���5�5������.��������!�S�[�[�]�2�2rc��g|_y)z;
        Remove all host keys from the dictionary.
        N)rrNs r�clearzHostKeys.clear�s����
rc#�>K�|j�D]}|���y�wr@rFrHs  rrJzHostKeys.__iter__�s ��������	�A��G�	�rKc�4�t|j��Sr@rMrNs rrOzHostKeys.__len__�s���4�9�9�;��rc�B�|j|�}|�t|��|Sr@)r`rR)rr�rets   rrVzHostKeys.__getitem__�s$���k�k�#����;��3�-���
rc��d}t|j�D]\}}|j||�s�|}n|�t|��|jj	|�yr@)r,rr_rR�pop)rr�index�ires     rrTzHostKeys.__delitem__�s^����!�$�-�-�0�	�H�A�u��%�%�c�5�1����	��=��3�-���
�
���%� rc��t|�dk(r'|jjt|gd��y|j	�D]z}d}|jD];}||j
vs�|jj�|k(s�0|||_d}�=|r�R|jjt|g||���|y)NrFT)r.rr!r"rGrrr )rr#re�key_type�foundr%s      rrYzHostKeys.__setitem__s����u�:��?��M�M� � ��x�j�$�!?�@���
�
��	P�H��E��]�]�
!������+������1A�X�1M�!�(�O�A�E� �E�	
!�
��
�
�$�$�\�8�*�e�H�o�%N�O�	Prc�z�g}|jD])}|jD]}||vs�|j|���+|Sr@)rrr!)rror%r6s    rrGz
HostKeys.keyssF�������	"�A��[�[�
"���C�<��J�J�q�M�
"�	"��
rc�t�g}|j�D]"}|j|j|���$|Sr@)rGr!r`)rrorIs   r�valueszHostKeys.valuess5��������	'�A��J�J�t�{�{�1�~�&�	'��
rc���|�(tjt�j�}n9|j	d�r|jd�d}t
t|��}t|�t�jk(sJ�t|t|�t�j�}djtt|��tt|���}|jdd�S)aM
        Return a "hashed" form of the hostname, as used by OpenSSH when storing
        hashed hostnames in the known_hosts file.

        :param str hostname: the hostname to hash
        :param str salt: optional salt to use when hashing
            (must be 20 bytes long)
        :return: the hashed hostname as a `str`
        rb�|rz|1|{}|{}�
�)�os�urandomr�digest_sizerc�splitrrr.r�digest�formatr	r
�replace)r#�salt�hmac�hostkeys    rrdzHostKeys.hash_host#s����<��:�:�d�f�0�0�1�D����u�%��z�z�#��q�)���q��w�'�D��4�y�D�F�.�.�.�.�.��D�!�H�+�t�,�3�3�5���#�#�A�k�$�&7�$8�!�K��<M�:N�O�����t�R�(�(rr@)r[r\r]�__doc__rr&rr;r`r_r0rkrJrOrVrTrYrGry�staticmethodrd�rrrr)sj��	�
 �
<�0�@"�&A0�F� 3�$�� ��!�
P����)��)rrc��eZdZd�Zy)�InvalidHostKeyc�2�||_||_||f|_yr@)r4�exc�args)rr4r�s   rrzInvalidHostKey.__init__;s����	�����3�K��	rN)r[r\r]rr�rrr�r�:s�� rr�c�6�eZdZdZdd�Zedd��Zd�Zd�Zy)	r"zJ
    Representation of a line in an OpenSSH-style "known hosts" file.
    Nc�>�|duxr|du|_||_||_yr@)�validrr)rrrs   rrzHostKeyEntry.__init__Fs%���t�+�B�#�T�/��
�"�����rc��td�}|jd�}t|�dkr$d}|j|j	||��y|dd}|\}}}|jd�}	t|�}|dk(rt
t|���}n�|d	k(rtt|���}ni|tj�vrtt|�d
��}n<|dk(rtt|���}n!|jd
j	|��y|||�S#tj$r}	t||	��d}	~	wwxYw)a�
        Parses the given line of text to find the names for the host,
        the type of key, and the key data. The line is expected to be in the
        format used by the OpenSSH known_hosts file.

        Lines are expected to not have leading or trailing whitespace.
        We don't bother to check for comments or empty lines.  All of
        that should be taken care of before sending the line to us.

        :param str line: a line from an OpenSSH known_hosts file
        zparamiko.hostkeys� rz8Not enough fields found in known_hosts in line {} ({!r})N�,zssh-rsa)�datazssh-dssF)r��validate_pointzssh-ed25519zUnable to handle key of type {})rr�r.�infor�rr
rrr� supported_key_format_identifiersr�binascii�Errorr�)
�clsr4r3�log�fields�msg�namesr$rr%s
          rr/zHostKeyEntry.from_lineKs,���,�-�����C����v�;��?�L�C��H�H�S�Z�Z���-�.�������$���w�����C� ��	*��C�&�C��)�#��+�c�"2�3���I�%��+�c�"2�3���H�E�E�G�G��K��$4�U�K���M�)� �k�#�&6�7�����:�A�A�'�J�K��
�5�#�����~�~�	*� ��q�)�)��	*�s�,B)D�E�2D>�>Ec���|jr\djdj|j�|jj�|jj
��Sy)z�
        Returns a string in OpenSSH known_hosts file format, or None if
        the object is not in a valid state.  A trailing newline is
        included.
        z	{} {} {}
r�N)r�r��joinrrr �
get_base64rNs rr9zHostKeyEntry.to_lineysS���:�:��&�&�������(����!�!�#����#�#�%��
�
rc�N�dj|j|j�S)Nz<HostKeyEntry {!r}: {!r}>)r�rrrNs r�__repr__zHostKeyEntry.__repr__�s��*�1�1�$�.�.�$�(�(�K�Kr)NNr@)	r[r\r]r�r�classmethodr/r9r�r�rrr"r"As,����
�+��+�Z�Lrr")!r�r~�sys�version_info�collections.abcr�collections�hashlibrr�r�paramiko.py3compatrr	r
r�paramiko.dsskeyr�paramiko.rsakeyr
�
paramiko.utilrr�paramiko.ecdsakeyr�paramiko.ed25519keyr�paramiko.ssh_exceptionrr�	Exceptionr�r"r�rr�<module>r�sr��(�	�
����B�Q��6�!�.�*���=�=�"�"�<�&�*�/�N)�~�N)�b �Y� �GL�GLr

Zerion Mini Shell 1.0