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/CyberPanel/lib64/python3.10/site-packages/paramiko/__pycache__/kex_gss.cpython-310.pyc
o

�h�_�@s�dZddlZddlmZddlmZmZmZmZm	Z	m
Z
ddlmZddl
mZddlmZedd	�\ZZZZZed
d�\ZZdd
�edd	�D�\ZZZZZdd
�ed
d�D�\ZZGdd�d�Z Gdd�de �Z!Gdd�d�Z"Gdd�d�Z#dS)a�
This module provides GSS-API / SSPI Key Exchange as defined in :rfc:`4462`.

.. note:: Credential delegation is not supported in server mode.

.. note::
    `RFC 4462 Section 2.2
    <https://tools.ietf.org/html/rfc4462.html#section-2.2>`_ says we are not
    required to implement GSS-API error messages. Thus, in many methods within
    this module, if an error occurs an exception will be thrown and the
    connection will be terminated.

.. seealso:: :doc:`/api/ssh_gss`

.. versionadded:: 1.15
�N)�sha1)�DEBUG�max_byte�	zero_byte�byte_chr�	byte_mask�byte_ord)�util)�Message)�SSHException��#�(�*cC�g|]}t|��qS��r��.0�crr�F/usr/local/CyberPanel/lib/python3.10/site-packages/paramiko/kex_gss.py�
<listcomp>FsrcCrrrrrrrrGs�c@s|eZdZdZdZdZed�edZe	dZ
dZdd	�Zd
d�Z
dd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�KexGSSGroup1z�
    GSS-API / SSPI Authenticated Diffie-Hellman Key Exchange as defined in `RFC
    4462 Section 2 <https://tools.ietf.org/html/rfc4462.html#section-2>`_
    lE����8�{3If?�E y�Z�3�V�58n�oP�e�?a-�
�tBL�
�y3W[�<�p�6m5��P��&a�F!�33*�w& �AR�M;L}.�c|&A�@�h\�&&#-D�v�d��������z(gss-group1-sha1-toWM5Slw5Ew8Mqkay+al2g==cCs,||_|jj|_d|_d|_d|_d|_dS)Nr)�	transport�kexgss_ctxt�kexgss�gss_host�x�e�f��selfrrrr�__init__Ys

zKexGSSGroup1.__init__cCs�|��|jjrt|j|j|j�|_|j�t	�dSt|j|j|j�|_
|jj|_t�}|�
t�|�|jj|jd��|�|j
�|j�|�|j�tttt�dS)zU
        Start the GSS-API / SSPI Authenticated Diffie-Hellman Key Exchange.
        N��target)�_generate_xr�server_mode�pow�Gr!�Pr#�_expect_packet�MSG_KEXGSS_INITr"r r
�add_byte�c_MSG_KEXGSS_INIT�
add_stringr�ssh_init_sec_context�	add_mpint�
_send_message�MSG_KEXGSS_HOSTKEY�MSG_KEXGSS_CONTINUE�MSG_KEXGSS_COMPLETE�MSG_KEXGSS_ERROR�r%�mrrr�	start_kexas$

�zKexGSSGroup1.start_kexcCs�|jjr
|tkr
|�|�S|jjs|tkr|�|�S|jjr'|tkr'|�|�S|jjs4|tkr4|�	|�S|t
kr=|�|�Sd}t|�
|���)��
        Parse the next packet.

        :param ptype: The (string) type of the incoming packet
        :param `.Message` m: The packet content
        z.GSS KexGroup1 asked to handle packet type {:d})rr*r/�_parse_kexgss_initr6�_parse_kexgss_hostkeyr7�_parse_kexgss_continuer8�_parse_kexgss_completer9�_parse_kexgss_errorr�format�r%�ptyper;�msgrrr�
parse_next{s




zKexGSSGroup1.parse_nextcCsV	t�d�}t|dd�|dd�}|dd�}||j|jfvr"nqt�|�|_dS)ap
        generate an "x" (1 < x < q), where q is (p-1)/2.
        p is a 128-byte (1024-bit) number, where the first 64 bits are 1.
        therefore q can be approximated as a 2^1023.  we drop the subset of
        potential x where the first 63 bits are 1, because some of those will
        be larger than q (but this is a tiny tiny subset of potential x).
        ��rrNr)�os�urandomr�b7fffffffffffffff�b0000000000000000r	�inflate_longr!)r%�x_bytes�firstrrrr)�s
�zKexGSSGroup1._generate_xcC�8|��}||j_|��}|j�||�|j�tt�dS)z�
        Parse the SSH2_MSG_KEXGSS_HOSTKEY message (client mode).

        :param `.Message` m: The content of the SSH2_MSG_KEXGSS_HOSTKEY message
        N��
get_stringr�host_key�_verify_keyr.r7r8�r%r;rT�sigrrrr?��
z"KexGSSGroup1._parse_kexgss_hostkeycC�^|jjs,|��}t�}|�t�|�|jj|j	|d��|j�
|�|j�tt
t�dS	dS)z�
        Parse the SSH2_MSG_KEXGSS_CONTINUE message.

        :param `.Message` m: The content of the SSH2_MSG_KEXGSS_CONTINUE
            message
        �r(�
recv_tokenN�rr*rSr
r0�c_MSG_KEXGSS_CONTINUEr2rr3r �send_messager.r7r8r9�r%r;�	srv_tokenrrrr@�s
���z#KexGSSGroup1._parse_kexgss_continuecCs:|jjdurt�|j_|��|_|jdks|j|jdkr!td��|��}|��}d}|r1|��}t	|j|j
|j�}t�}|�|jj
|jj|jj|jj�|�|jj���|�|j�|�|j�|�|�tt|����}|j�||�|dur�|jj|j|d�|j�||�n|j�||�d|j_|j��dS)z�
        Parse the SSH2_MSG_KEXGSS_COMPLETE message (client mode).

        :param `.Message` m: The content of the
            SSH2_MSG_KEXGSS_COMPLETE message
        NrH�Server kex "f" is out of rangerZT)rrT�NullHostKey�	get_mpintr#r-rrS�get_booleanr+r!r
�add�
local_version�remote_version�local_kex_init�remote_kex_initr2�__str__r4r"r�str�digest�_set_K_Hrr3r �
ssh_check_mic�gss_kex_used�_activate_outbound�r%r;�	mic_token�boolr`�K�hm�HrrrrA�s@

�
�z#KexGSSGroup1._parse_kexgss_completec	Cs�|��}|��|_|jdks|j|jdkrtd��t|j|j|j�}t�|j_	|jj	�
�}t�}|�|jj
|jj|jj|jj�|�|�|�|j�|�|j�|�|�t|�����}|j�||�|j�|j|�}t�}|jjr�|jj|jjdd�}|�t�|�|j�|�|�|dur�|� d�|�|�n|� d�|j�!|�d|j_"|j�#�dS|�t$�|�|�|j�!|�|j�%t&t't(�dS)z�
        Parse the SSH2_MSG_KEXGSS_INIT message (server mode).

        :param `.Message` m: The content of the SSH2_MSG_KEXGSS_INIT message
        rH�Client kex "e" is out of rangeT��gss_kexNF))rSrcr"r-rr+r!rbrrTrjr
rergrfrirhr2r4r#r�asbytesrlrmr�ssh_accept_sec_contextr �_gss_srv_ctxt_status�ssh_get_mic�
session_idr0�c_MSG_KEXGSS_COMPLETE�add_booleanr5rorpr]r.r7r8r9�	r%r;�client_tokenrt�keyrurvr`rrrrrr>�sX

�

��





�zKexGSSGroup1._parse_kexgss_initcC�2|��}|��}|��}|��td�|||���)a�
        Parse the SSH2_MSG_KEXGSS_ERROR message (client mode).
        The server may send a GSS-API error message. if it does, we display
        the error by throwing an exception (client mode).

        :param `.Message` m: The content of the SSH2_MSG_KEXGSS_ERROR message
        :raise SSHException: Contains GSS-API major and minor status as well as
                             the error message and the language tag of the
                             message
        �CGSS-API Error:
Major Status: {}
Minor Status: {}
Error Message: {}
��get_intrSrrC�r%r;�
maj_status�
min_status�err_msgrrrrB*���z KexGSSGroup1._parse_kexgss_errorN)�__name__�
__module__�__qualname__�__doc__r-r,rrrLrrM�NAMEr&r<rGr)r?r@rAr>rBrrrrrLs 
-8rc@seZdZdZdZdZdZdS)�
KexGSSGroup14z�
    GSS-API / SSPI Authenticated Diffie-Hellman Group14 Key Exchange as defined
    in `RFC 4462 Section 2
    <https://tools.ietf.org/html/rfc4462.html#section-2>`_
    l������&�U�G9
tcb0]Q\-�:�$�90.`U�_�b;YS7x]Ek�`:xds�!,w<G�8�qbdR_��h��d�d��Y6K�pRT{�U�j�K�#�Gt|�L���4�S�8� �FYpw,(.>�=�H�G2C�d�c_�.K?&j�_�c�}�z[\V�_1M.D�^�/1v5I	�j�V&|�
�/�mV�lR�<6#�{n4�(EY91�T�:�g8	H	�Ap�cb4B�B�j~H�����rz)gss-group14-sha1-toWM5Slw5Ew8Mqkay+al2g==N)r�r�r�r�r-r,r�rrrrr�Ds
r�c@sxeZdZdZdZdZdZdZdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�	KexGSSGexz�
    GSS-API / SSPI Authenticated Diffie-Hellman Group Exchange as defined in
    `RFC 4462 Section 2 <https://tools.ietf.org/html/rfc4462.html#section-2>`_
    z%gss-gex-sha1-toWM5Slw5Ew8Mqkay+al2g==�� icCsD||_|jj|_d|_d|_d|_d|_d|_d|_d|_	d|_
dS)NF)rrrr �p�q�gr!r"r#�	old_styler$rrrr&[s

zKexGSSGex.__init__cCsr|jjr|j�t�dS|jj|_t�}|�t�|�|j	�|�|j
�|�|j�|j�|�|j�t
�dS)zV
        Start the GSS-API / SSPI Authenticated Diffie-Hellman Group Exchange
        N)rr*r.�MSG_KEXGSS_GROUPREQr r
r0�c_MSG_KEXGSS_GROUPREQ�add_int�min_bits�preferred_bits�max_bitsr5�MSG_KEXGSS_GROUPr:rrrr<gs

zKexGSSGex.start_kexcCs�|tkr	|�|�S|tkr|�|�S|tkr|�|�S|tkr$|�|�S|tkr-|�	|�S|t
kr6|�|�S|tkr?|�
|�Sd}t|�|���)r=z'KexGex asked to handle packet type {:d})r��_parse_kexgss_groupreqr��_parse_kexgss_groupr/�_parse_kexgss_gex_initr6r?r7r@r8rAr9rBrrCrDrrrrGzs 






zKexGSSGex.parse_nextcCs�|jdd}t�|d�}t|d�}t|�}d}|d@s)|dK}|dL}|d@r	t�|�}t|d|�|dd�}t�|d�}|dkrK||krKnq*||_	dS)NrHrr�rI)
r�r	�deflate_longr�lenrJrKrrNr!)r%r��qnorm�qhbyte�
byte_count�qmaskrOr!rrrr)�s"�
�
zKexGSSGex._generate_xcCs�|��}|��}|��}||jkr|j}||jkr|j}||kr"|}||kr(|}||_||_||_|j��}|dur>td��|j�td�	|||��|�
|||�\|_|_t
�}|�t�|�|j�|�|j�|j�|�|j�t�dS)z�
        Parse the SSH2_MSG_KEXGSS_GROUPREQ message (server mode).

        :param `.Message` m: The content of the
            SSH2_MSG_KEXGSS_GROUPREQ message
        Nz-Can't do server-side gex with no modulus packzPicking p ({} <= {} <= {} bits))r�r�r�r�r�_get_modulus_packr�_logrrC�get_modulusr�r�r
r0�c_MSG_KEXGSS_GROUPr4r5r.r/)r%r;�minbits�
preferredbits�maxbits�packrrrr��s<


��
z KexGSSGex._parse_kexgss_groupreqcCs�|��|_|��|_t�|j�}|dks|dkrtd�|���|j�t	d�|��|�
�t|j|j|j�|_
t�}|�t�|�|jj|jd��|�|j
�|j�|�|j�tttt�dS)z�
        Parse the SSH2_MSG_KEXGSS_GROUP message (client mode).

        :param `Message` m: The content of the SSH2_MSG_KEXGSS_GROUP message
        r�r�z<Server-generated gex p (don't ask) is out of range ({} bits)zGot server p ({} bits)r'N)rcr�r�r	�
bit_lengthrrCrr�rr)r+r!r"r
r0r1r2rr3r r4r5r.r6r7r8r9)r%r;�bitlenrrrr��s0

�
�
�zKexGSSGex._parse_kexgss_groupc	Cs�|��}|��|_|jdks|j|jdkrtd��|��t|j|j|j�|_	t|j|j|j�}t
�|j_|jj�
�}t�}|�|jj|jj|jj|jj|�|�|j�|�|j�|�|j�|�|j�|�|j�|�|j�|�|j	�|�|�t|�����}|j�||�|j�|j|�}t�}|jj r�|jj!|jj"dd�}|�#t$�|�|j	�|�%|�|dur�|�&d�|�%|�n|�&d�|j�'|�d|j_(|j�)�dS|�#t*�|�%|�|j�'|�|j�+t,t-t.�dS)z�
        Parse the SSH2_MSG_KEXGSS_INIT message (server mode).

        :param `Message` m: The content of the SSH2_MSG_KEXGSS_INIT message
        rHrwTrxNF)/rSrcr"r�rr)r+r�r!r#rbrrTrjr
rergrfrirhr�r�r�r�r4rrzrlrmrr{r r|r}r~r0rr2r�r5rorpr]r.r7r8r9r�rrrr��sf

�
��





�z KexGSSGex._parse_kexgss_gex_initcCrQ)z�
        Parse the SSH2_MSG_KEXGSS_HOSTKEY message (client mode).

        :param `Message` m: The content of the SSH2_MSG_KEXGSS_HOSTKEY message
        NrRrVrrrr?1rXzKexGSSGex._parse_kexgss_hostkeycCrY)z�
        Parse the SSH2_MSG_KEXGSS_CONTINUE message.

        :param `Message` m: The content of the SSH2_MSG_KEXGSS_CONTINUE message
        rZNr\r_rrrr@>s
���z KexGSSGex._parse_kexgss_continuecCsz|jjdurt�|j_|��|_|��}|��}d}|r |��}|jdks-|j|jdkr1td��t	|j|j
|j�}t�}|�|jj
|jj|jj|jj|jj���|js[|�|j�|�|j�|jsj|�|j�|�|j�|�|j�|�|j�|�|j�|�|�t|�����}|j�||�|dur�|jj|j |d�|j�!||�n|j�!||�d|j_"|j�#�dS)z�
        Parse the SSH2_MSG_KEXGSS_COMPLETE message (client mode).

        :param `Message` m: The content of the SSH2_MSG_KEXGSS_COMPLETE message
        NrHrarZT)$rrTrbrcr#rSrdr�rr+r!r
rerfrgrhrirjr�r�r�r�r�r4r�r"rrzrlrmrr3r rnrorprqrrrrATsN


�
�z KexGSSGex._parse_kexgss_completecCr�)a�
        Parse the SSH2_MSG_KEXGSS_ERROR message (client mode).
        The server may send a GSS-API error message. if it does, we display
        the error by throwing an exception (client mode).

        :param `Message` m:  The content of the SSH2_MSG_KEXGSS_ERROR message
        :raise SSHException: Contains GSS-API major and minor status as well as
                             the error message and the language tag of the
                             message
        r�r�r�rrrrB�r�zKexGSSGex._parse_kexgss_errorN)r�r�r�r�r�r�r�r�r&r<rGr)r�r�r�r?r@rArBrrrrr�Ps",!>
2r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	rbz�
    This class represents the Null Host Key for GSS-API Key Exchange as defined
    in `RFC 4462 Section 5
    <https://tools.ietf.org/html/rfc4462.html#section-5>`_
    cCs
d|_dS)N��r��r%rrrr&�s
zNullHostKey.__init__cC�|jS�Nr�r�rrrrj��zNullHostKey.__str__cCr�r�r�r�rrr�get_name�r�zNullHostKey.get_nameN)r�r�r�r�r&rjr�rrrrrb�s
rb)$r�rJ�hashlibr�paramiko.commonrrrrrr�paramikor	�paramiko.messager
�paramiko.ssh_exceptionr�ranger/r7r8r6r9r�r�r1r]r�c_MSG_KEXGSS_HOSTKEY�c_MSG_KEXGSS_ERRORr�r�rr�r�rbrrrr�<module>s@ 	��
�yR