ó =OXc@sâdZddlmZddlmZddlmZmZddlm Z ddl m Z m Z ddl mZddlmZdd lmZdd lmZdd lmZmZdd lmZd efd„ƒYZdS(s DSS keys. iÿÿÿÿ(tInvalidSignature(tdefault_backend(thashest serialization(tdsa(tdecode_dss_signaturetencode_dss_signature(tutil(t zero_byte(t SSHException(tMessage(tBERt BERException(tPKeytDSSKeycBs¹eZdZddddddd„Zd„Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z dd „Z dd „Zed dd „ƒZd„Zd„Zd„ZRS(sX Representation of a DSS key which can be used to sign an verify SSH2 data. cCsRd|_d|_d|_d|_d|_|dk rM|j||ƒdS|dk rm|j||ƒdS|dkr”|dk r”t|ƒ}n|dk rÁ|\|_|_|_|_nx|dkrÜt dƒ‚n|j ƒdkrýt dƒ‚n|j ƒ|_|j ƒ|_|j ƒ|_|j ƒ|_t j |jƒ|_dS(NsKey object may not be emptysssh-dsss Invalid key(tNonetptqtgtytxt_from_private_keyt_from_private_key_fileR R tget_textt get_mpintRt bit_lengthtsize(tselftmsgtdatatfilenametpasswordtvalstfile_obj((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pyt__init__-s0        ! cCs`tƒ}|jdƒ|j|jƒ|j|jƒ|j|jƒ|j|jƒ|jƒS(Nsssh-dss(R t add_stringt add_mpintRRRRtasbytes(Rtm((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pyR%Hs  cCs |jƒS(N(R%(R((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pyt__str__QscCsxt|jƒƒ}|dt|jƒ}|dt|jƒ}|dt|jƒ}|dt|jƒ}t|ƒS(Ni%(thashtget_nameRRRR(Rth((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pyt__hash__Ts cCsdS(Nsssh-dss((R((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pyR)]scCs|jS(N(R(R((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pytget_bits`scCs |jdk S(N(RR(R((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pytcan_signcsc CsCtjd|jdtjd|jdtjd|jd|jd|jƒƒƒj dt ƒƒ}|j t j ƒƒ}|j|ƒt|jƒƒ\}}tƒ}|jd ƒtj|d ƒ}tj|d ƒ}t|ƒd krtd t|ƒ|}nt|ƒd kr.td t|ƒ|}n|j||ƒ|S( NRtpublic_numbersRtparameter_numbersRRRtbackendsssh-dssii(RtDSAPrivateNumbersRtDSAPublicNumbersRtDSAParameterNumbersRRRt private_keyRtsignerRtSHA1tupdateRtfinalizeR R#Rt deflate_longtlenR( RRtkeyR5trtsR&trstrtsstr((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pyt sign_ssh_datafs,           c Cs%t|jƒƒdkr'|jƒ}n(|jƒ}|dkrCdS|jƒ}tj|d dƒ}tj|ddƒ}t||ƒ}tjd|j dtj d|j d |j d |j ƒƒjd tƒƒ}|j|tjƒƒ} | j|ƒy| jƒWntk rtSXtSdS( Ni(sssh-dssiiiRR/RRRR0(R:R%Rt get_binaryRt inflate_longRRR2RR3RRRt public_keyRtverifierRR6R7tverifyRtFalsetTrue( RRRtsigtkindtsigRtsigSt signatureR;RD((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pytverify_ssh_sig‚s.           cCsƒtjd|jdtjd|jdtjd|jd|jd|jƒƒƒj dt ƒƒ}|j ||t j jd |ƒdS( NRR.RR/RRRR0R(RR1RR2RR3RRRR4Rt_write_private_key_fileRt PrivateFormattTraditionalOpenSSL(RRRR;((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pytwrite_private_key_file£s         cCsƒtjd|jdtjd|jdtjd|jd|jd|jƒƒƒj dt ƒƒ}|j ||t j jd |ƒdS( NRR.RR/RRRR0R(RR1RR2RR3RRRR4Rt_write_private_keyRRORP(RR!RR;((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pytwrite_private_key·s         icCsjtj|dtƒƒjƒ}td|jjj|jjj|jjj |jj fƒ}|j |_ |S(s- Generate a new private DSS key. This factory function can be used to generate a new host key or authentication key. :param int bits: number of bits the generated key should be. :param function progress_func: Unused :return: new `.DSSKey` private key R0R ( Rtgenerate_private_keyRtprivate_numbersRR.R/RRRRR(tbitst progress_functnumbersR;((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pytgenerateËs     cCs&|jd||ƒ}|j|ƒdS(NtDSA(t_read_private_key_filet _decode_key(RRRR((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pyRãscCs&|jd||ƒ}|j|ƒdS(NRZ(t_read_private_keyR\(RR!RR((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pyRçscCsßyt|ƒjƒ}Wn)tk rA}tdt|ƒƒ‚nXt|ƒtk svt|ƒdksv|ddkr…tdƒ‚n|d|_|d|_ |d|_ |d|_ |d |_ t j|jƒ|_dS( NsUnable to parse key file: iis3not a valid DSA private key file (bad ber encoding)iiiii(R tdecodeR R tstrttypetlistR:RRRRRRRR(RRtkeylistte((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pyR\ës4     N(t__name__t __module__t__doc__RR"R%R'R+R)R,R-R@RMRQRSt staticmethodRYRRR\(((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pyR's"      !    N(Rftcryptography.exceptionsRtcryptography.hazmat.backendsRtcryptography.hazmat.primitivesRRt)cryptography.hazmat.primitives.asymmetricRt/cryptography.hazmat.primitives.asymmetric.utilsRRtparamikoRtparamiko.commonRtparamiko.ssh_exceptionR tparamiko.messageR t paramiko.berR R t paramiko.pkeyR R(((s3/usr/lib/python2.7/site-packages/paramiko/dsskey.pyts