a
   ‚s’fWŒ<ã                   @   s²   d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
 ddlmZmZmZ ddlmZ ed	d
ƒ\ZZdd„ ed	d
ƒD ƒ\ZZedƒed  Zed ZG dd„ deƒZdS )z
Standard SSH key exchange ("kex" if you wanna sound cool).  Diffie-Hellman of
1024 bit key halves, using a known "p" prime and "g" generator.
é    N)Úsha1)Úutil)Úmax_byteÚ	zero_byte)ÚMessage)Úbyte_chrÚlongÚ	byte_mask)ÚSSHExceptioné   é    c                 C   s   g | ]}t |ƒ‘qS © )r   )Ú.0Úcr   r   ú7/usr/lib/python3.9/site-packages/paramiko/kex_group1.pyÚ
<listcomp>#   ó    r   é   é   é   c                   @   sL   e Zd ZdZdZdZeZdd„ Zdd„ Z	dd	„ Z
d
d„ Zdd„ Zdd„ ZdS )Ú	KexGroup1lE   ÿÿÿÿ8Ê{3If?ñE yéZô3¢Vý58nÛoP·eõ?a-ûÓtBLèûy3W[<‘p¨6m5ÂÝPøß&aÌF!Í33*¾w& ãAR‘M;L}. c|&A“@”h\Š&&#-D¨v‡dÿÿÿÿ é   zdiffie-hellman-group1-sha1c                 C   s(   || _ tdƒ| _tdƒ| _tdƒ| _d S )Nr   )Ú	transportr   ÚxÚeÚf)Úselfr   r   r   r   Ú__init__2   s    

zKexGroup1.__init__c                 C   s€   |   ¡  | jjr4t| j| j| jƒ| _| j t	¡ d S t| j| j| jƒ| _
tƒ }| t¡ | | j
¡ | j |¡ | j t¡ d S )N)Ú_generate_xr   Úserver_modeÚpowÚGr   ÚPr   Z_expect_packetÚ_MSG_KEXDH_INITr   r   Úadd_byteÚc_MSG_KEXDH_INITÚ	add_mpintÚ_send_messageÚ_MSG_KEXDH_REPLY)r   Úmr   r   r   Ú	start_kex8   s    
zKexGroup1.start_kexc                 C   sJ   | j jr|tkr|  |¡S | j js4|tkr4|  |¡S d}t| |¡ƒ‚d S )Nz*KexGroup1 asked to handle packet type {:d})r   r   r#   Ú_parse_kexdh_initr(   Ú_parse_kexdh_replyr
   Úformat)r   Zptyper)   Úmsgr   r   r   Ú
parse_nextG   s    

zKexGroup1.parse_nextc                 C   sX   t  d¡}t|d dƒ|dd …  }|d d… tkr |d d… tkr qHq t |¡| _d S )Né€   r   r   é   r   )ÚosÚurandomr	   Úb7fffffffffffffffÚb0000000000000000r   Zinflate_longr   )r   Zx_bytesr   r   r   r   Q   s    
ÿþzKexGroup1._generate_xc                 C   sØ   |  ¡ }| ¡ | _| jdk s,| j| jd kr4tdƒ‚| ¡ }t| j| j| jƒ}tƒ }| 	| j
j| j
j| j
j| j
j¡ | |¡ | | j¡ | | j¡ | |¡ | j
 ||  | ¡ ¡ ¡ ¡ | j
 ||¡ | j
 ¡  d S )Nr1   zServer kex "f" is out of range)Z
get_stringÚ	get_mpintr   r"   r
   Z
get_binaryr    r   r   Úaddr   Úlocal_versionÚremote_versionÚlocal_kex_initÚremote_kex_initÚ
add_stringr&   r   Ú_set_K_HÚ	hash_algoÚasbytesÚdigestZ_verify_keyÚ_activate_outbound)r   r)   Zhost_keyÚsigÚKÚhmr   r   r   r,   b   s(    
ü

zKexGroup1._parse_kexdh_replyc                 C   s  |  ¡ | _| jdk s$| j| jd kr,tdƒ‚t| j| j| jƒ}| j ¡  ¡ }t	ƒ }| 
| jj| jj| jj| jj¡ | |¡ | | j¡ | | j¡ | |¡ t| ¡ ƒ ¡ }| j ||¡ | j ¡  |¡}t	ƒ }| t¡ | |¡ | | j¡ | |¡ | j |¡ | j ¡  d S )Nr1   zClient kex "e" is out of range)r6   r   r"   r
   r    r   r   Zget_server_keyr?   r   r7   r9   r8   r;   r:   r<   r&   r   r   r@   r=   Zsign_ssh_datar$   Úc_MSG_KEXDH_REPLYr'   rA   )r   r)   rC   ÚkeyrD   ÚHrB   r   r   r   r+   {   s4    
ü




zKexGroup1._parse_kexdh_initN)Ú__name__Ú
__module__Ú__qualname__r"   r!   Únamer   r>   r   r*   r/   r   r,   r+   r   r   r   r   r   )   s   
r   )Ú__doc__r2   Zhashlibr   Zparamikor   Zparamiko.commonr   r   Zparamiko.messager   Zparamiko.py3compatr   r   r	   Zparamiko.ssh_exceptionr
   Úranger#   r(   r%   rE   r4   r5   Úobjectr   r   r   r   r   Ú<module>   s   