U
    ςdl                     @   s   d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	m
Z
 ddl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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byte_chr	byte_mask)Message)SSHException       c                 C   s   g | ]}t |qS  )r   ).0cr   r   P/var/www/html/myproject/myenv/lib/python3.8/site-packages/paramiko/kex_group1.py
<listcomp>"   s     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 yZ3V58noPe?a-tBLy3W[<p6m5P&aF!33*w& ARM;L}.c|&A@h\&&#-Dvd    zdiffie-hellman-group1-sha1c                 C   s   || _ d| _d| _d| _d S )Nr   )	transportxef)selfr   r   r   r   __init__1   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_kex7   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   ptyper'   msgr   r   r   
parse_nextF   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   P   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 )Nr0   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*   a   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 || | |  }| j|| | j || jj}t	 }|t || || j || | j| | j  d S )Nr0   zClient kex "e" is out of range)r5   r   r    r	   r   r   r   Zget_server_keyr>   r   r6   r8   r7   r:   r9   r;   r$   r   r=   r?   r<   Zsign_ssh_dataZhost_key_typer"   c_MSG_KEXDH_REPLYr%   r@   )r   r'   rB   keyrC   HrA   r   r   r   r)   z   s:    



 


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__r1   hashlibr   Zparamikor   Zparamiko.commonr   r   r   r   Zparamiko.messager   Zparamiko.ssh_exceptionr	   ranger!   r&   r#   rD   r3   r4   r   r   r   r   r   <module>   s   