Current File : //usr/lib/python2.7/site-packages/paramiko/kex_gex.pyc
�
=OXc@s	dZddlZddlmZmZddlmZddlmZddl	m
Z
ddlmZm
Z
mZddlmZed	d
�\ZZZZZged	d
�D]Zee�^q�\ZZZZZdefd��YZd
efd��YZdS(s�
Variant on `KexGroup1 <paramiko.kex_group1.KexGroup1>` where the prime "p" and
generator "g" are provided by the server.  A bit more work is required on the
client side, and a **lot** more on the server side.
i����N(tsha1tsha256(tutil(tDEBUG(tMessage(tbyte_chrtbyte_ordt	byte_mask(tSSHExceptionii#tKexGexcBszeZdZdZdZdZeZd�Ze	d�Z
d�Zd�Zd�Z
d	�Zd
�Zd�Zd�ZRS(
s"diffie-hellman-group-exchange-sha1ii icCsL||_d|_d|_d|_d|_d|_d|_t|_	dS(N(
t	transporttNonetptqtgtxtetftFalset	old_style(tselfR
((s4/usr/lib/python2.7/site-packages/paramiko/kex_gex.pyt__init__1s							cCs�|jjr#|jjtt�dSt�}|r[|jt�|j|j	�t
|_n=|jt�|j|j
�|j|j	�|j|j�|jj|�|jjt�dS(N(R
tserver_modet_expect_packett_MSG_KEXDH_GEX_REQUESTt_MSG_KEXDH_GEX_REQUEST_OLDRtadd_bytetc_MSG_KEXDH_GEX_REQUEST_OLDtadd_inttpreferred_bitstTrueRtc_MSG_KEXDH_GEX_REQUESTtmin_bitstmax_bitst
_send_messaget_MSG_KEXDH_GEX_GROUP(Rt_test_old_styletm((s4/usr/lib/python2.7/site-packages/paramiko/kex_gex.pyt	start_kex;s	

cCs�|tkr|j|�S|tkr2|j|�S|tkrK|j|�S|tkrd|j|�S|tkr}|j	|�St
d|j|��dS(Ns(KexGex %s asked to handle packet type %d(Rt_parse_kexdh_gex_requestR#t_parse_kexdh_gex_groupt_MSG_KEXDH_GEX_INITt_parse_kexdh_gex_initt_MSG_KEXDH_GEX_REPLYt_parse_kexdh_gex_replyRt_parse_kexdh_gex_request_oldRtname(RtptypeR%((s4/usr/lib/python2.7/site-packages/paramiko/kex_gex.pyt
parse_nextPs




cCs�|jdd}tj|d�}t|d�}t|�}d}x"|d@si|dK}|dL}qHWxbtr�tj|�}t|d|�|d}tj	|d�}|dkrm||krmPqmqmW||_
dS(Niiii�i�(RRtdeflate_longRtlenRtosturandomRtinflate_longR(RR
tqnormtqhbytet
byte_counttqmasktx_bytesR((s4/usr/lib/python2.7/site-packages/paramiko/kex_gex.pyt_generate_x_s

	cCsd|j�}|j�}|j�}||jkr?|j}n||jkrZ|j}n||kro|}n||kr�|}n||_||_||_|jj�}|dkr�td��n|jjt	d|||f�|j
|||�\|_|_t
�}|jt�|j|j�|j|j�|jj|�|jjt�dS(Ns-Can't do server-side gex with no modulus packsPicking p (%d <= %d <= %d bits)(tget_intR!R RR
t_get_modulus_packRRt_logRtget_modulusRRRRtc_MSG_KEXDH_GEX_GROUPt	add_mpintR"RR)(RR%tminbitst
preferredbitstmaxbitstpack((s4/usr/lib/python2.7/site-packages/paramiko/kex_gex.pyR'qs2					 !	
cCs%|j�|_|j|jkr0|j|_n|j|jkrQ|j|_n|jj�}|dkr{td��n|jjt	d|jf�|j
|j|j|j�\|_|_t
�}|jt�|j|j�|j|j�|jj|�|jjt�t|_dS(Ns-Can't do server-side gex with no modulus packsPicking p (~ %d bits)(R<RR!R R
R=RRR>RR?RRRRR@RAR"RR)RR(RR%RE((s4/usr/lib/python2.7/site-packages/paramiko/kex_gex.pyR-�s"*	
cCs�|j�|_|j�|_tj|j�}|dksH|dkr[td|��n|jjtd|�|j	�t
|j|j|j�|_t
�}|jt�|j|j�|jj|�|jjt�dS(Nii s<Server-generated gex p (don't ask) is out of range (%d bits)sGot server p (%d bits)(t	get_mpintRRRt
bit_lengthRR
R>RR;tpowRRRRtc_MSG_KEXDH_GEX_INITRAR"RR+(RR%tbitlen((s4/usr/lib/python2.7/site-packages/paramiko/kex_gex.pyR(�s
	
cCs|j�|_|jdks4|j|jdkrCtd��n|j�t|j|j|j�|_t|j|j|j�}|j	j
�j�}t�}|j
|j	j|j	j|j	j|j	j|�|js�|j|j�n|j|j�|js|j|j�n|j|j�|j|j�|j|j�|j|j�|j|�|j|j��j�}|j	j||�|j	j
�j|�}t�}|jt�|j|�|j|j�|j|�|j	j|�|j	j �dS(NisClient kex "e" is out of range(!RFRRRR;RHRRRR
tget_server_keytasbytesRtaddtremote_versiont
local_versiontremote_kex_inittlocal_kex_initRRR RR!RAt	hash_algotdigestt_set_K_Ht
sign_ssh_dataRtc_MSG_KEXDH_GEX_REPLYt
add_stringR"t_activate_outbound(RR%tKtkeythmtHtsig((s4/usr/lib/python2.7/site-packages/paramiko/kex_gex.pyR*�s>%
			
	


cCs�|j�}|j�|_|j�}|jdksL|j|jdkr[td��nt|j|j|j�}t�}|j|j	j
|j	j|j	j|j	j
|�|js�|j|j�n|j|j�|js�|j|j�n|j|j�|j|j�|j|j�|j|j�|j|�|j	j||j|j��j��|j	j||�|j	j�dS(NisServer kex "f" is out of range(t
get_stringRFRRRRHRRRMR
RORNRQRPRRR RR!RARRRTRRRLRSt_verify_keyRX(RR%thost_keyR]RYR[((s4/usr/lib/python2.7/site-packages/paramiko/kex_gex.pyR,�s.%			
((t__name__t
__module__R.R R!RRRRRRR&R0R;R'R-R(R*R,(((s4/usr/lib/python2.7/site-packages/paramiko/kex_gex.pyR	)s	
			!			$tKexGexSHA256cBseZdZeZRS(s$diffie-hellman-group-exchange-sha256(RaRbR.RRR(((s4/usr/lib/python2.7/site-packages/paramiko/kex_gex.pyRc�s( t__doc__R3thashlibRRtparamikoRtparamiko.commonRtparamiko.messageRtparamiko.py3compatRRRtparamiko.ssh_exceptionRtrangeRR#R)R+RtcRR@RIRVRtobjectR	Rc(((s4/usr/lib/python2.7/site-packages/paramiko/kex_gex.pyt<module>s7�