1Mc@sdZddlmZmZmZmZddlZdefdYZej edZ dddYZ d dd YZ d d Z d ddYZdddYZejdZejdZejdZdS(sM2Crypto wrapper for OpenSSL EVP API. Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved. Portions Copyright (c) 2004-2007 Open Source Applications Foundation. Author: Heikki Toivonen i(tErrtutiltBIOtRSANtEVPErrorcBseZRS((t__name__t __module__(((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyR scCstj||||S(s Derive a key from password using PBKDF2 algorithm specified in RFC 2898. @param password: Derive the key from this password. @type password: str @param salt: Salt. @type salt: str @param iter: Number of iterations to perform. @type iter: int @param keylen: Length of key to produce. @type keylen: int @return: Key. @rtype: str (tm2tpkcs5_pbkdf2_hmac_sha1(tpasswordtsalttitertkeylen((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pytpbkdf2st MessageDigestcBsAeZdZejZdZdZdZdZ e Z RS(s Message Digest cCsett|d}|dkr0td|fn||_tj|_tj|j|jdS(Nsunknown algorithm(tgetattrRtNonet ValueErrortmdt md_ctx_newtctxt digest_init(tselftalgoR((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyt__init__(s   cCs)t|ddr%|j|jndS(NR(RRtm2_md_ctx_freeR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyt__del__0scCstj|j|S(s Add data to be digested. @return: -1 for Python error, 1 for success, 0 for OpenSSL failure. (Rt digest_updateR(Rtdata((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pytupdate4scCstj|jS(N(Rt digest_finalR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pytfinal<s( RRt__doc__Rt md_ctx_freeRRRRRtdigest(((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyR"s     tHMACcBsGeZejZddZdZdZdZdZ e Z RS(tsha1cCshtt|d}|dkr0td|fn||_tj|_tj|j||jdS(Nsunknown algorithm(RRRRRt hmac_ctx_newRt hmac_init(RtkeyRR((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRGs   cCs)t|ddr%|j|jndS(NR(RRtm2_hmac_ctx_freeR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyROscCstj|j||jdS(N(RR&RR(RR'((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pytresetSscCstj|j|dS(N(Rt hmac_updateR(RR((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRVscCstj|jS(N(Rt hmac_finalR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRYs( RRRt hmac_ctx_freeR(RRR)RRR"(((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyR#Cs      R$cCsFtt|d}|dkr0td|fntj|||S(Nsunknown algorithm(RRRRthmac(R'RRR((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyR-^s tCiphercBsPeZejZddddddZdZdZdZddZ RS( itmd5t12345678ic Cstt|d} | dkr0td|fn| |_|rtt|d} | dkrrtd|fntj|j| ||||}ntj|_tj|j|j||||j | ~dS(Nsunknown ciphersunknown message digest( RRRRtciphert bytes_to_keytcipher_ctx_newRt cipher_initt set_padding( RtalgR'tivtopt key_as_bytestdR titpaddingR1tkmd((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRis   ' cCs)t|ddr%|j|jndS(NR(RRtm2_cipher_ctx_freeR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRxscCstj|j|S(N(Rt cipher_updateR(RR((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyR|scCstj|jS(N(Rt cipher_finalR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRscCstj|j|S(N(Rtcipher_set_paddingR(RR<((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyR5s( RRRtcipher_ctx_freeR>RRRRR5(((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyR.es     tPKeycBseZdZejZejZddddZ dZ dZ dZ ddZ dZd Zd ZeZeZd Zd Zd ZddZdZdejdZdejdZdejdZdZdZdZRS(s Public Key iR$cCsJ|dk r!||_||_ntj|_d|_|j|dS(Ni(Rtpkeyt_pyfreeRtpkey_newt _set_context(RRDRER((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRs     cCsNt|ddr%|j|jnt|ddrJ|j|jndS(NREiR(Rt m2_pkey_freeRDRRR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRscCs|jS(N(RD(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyt_ptrscCsOtt|d}|dkr0td|fn||_tj|_dS(Nsunknown message digest(RRRRRRR(RRtmda((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRGs   cCs|j|dS(s Reset internal message digest context. @type md: string @param md: The message digest algorithm. N(RG(RR((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyt reset_contextscCstj|j|jdS(s9 Initialise signing operation with self. N(Rt sign_initRR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRLscCstj|j|dS(su Feed data to signing operation. @type data: string @param data: Data to be signed. N(Rt sign_updateR(RR((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRMscCstj|j|jS(s[ Return signature. @rtype: string @return: The signature. (Rt sign_finalRRD(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRNscCstj|j|jdS(sH Initialise signature verification operation with self. N(Rt verify_initRR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyROscCstj|j|S(s Feed data to verification operation. @type data: string @param data: Data to be verified. @return: -1 on Python error, 1 for success, 0 for OpenSSL error (Rt verify_updateR(RR((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRPscCstj|j||jS(s Return result of verification. @param sign: Signature to use for verification @rtype: int @return: Result of verification: 1 for success, 0 for failure, -1 on other error. (Rt verify_finalRRD(Rtsign((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRQs icCsO|r3tj|j|j}|rKd|_qKntj|j|j}|S(s Assign the RSA key pair to self. @type rsa: M2Crypto.RSA.RSA @param rsa: M2Crypto.RSA.RSA object to be assigned to self. @type capture: boolean @param capture: If true (default), this PKey object will own the RSA object, meaning that once the PKey object gets deleted it is no longer safe to use the RSA object. @rtype: int @return: Return 1 for success and 0 for failure. i(Rtpkey_assign_rsaRDtrsaREt pkey_set1_rsa(RRTtcapturetret((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyt assign_rsas cCsCtj|j}|dkr-tdntj|d}|S(sd Return the underlying RSA key if that is what the EVP instance is holding. s&PKey instance is not holding a RSA keyiN(Rt pkey_get1_rsaRDRRRtRSA_pub(Rtrsa_ptrRT((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pytget_rsas  t aes_128_cbccCs%tj|d}|j|||S(s, Save the key pair to a file in PEM format. @type file: string @param file: Name of file to save key to. @type cipher: string @param cipher: Symmetric cipher to protect the key. The default cipher is 'aes_128_cbc'. If cipher is None, then the key is saved in the clear. @type callback: Python callable @param callback: A Python callable object that is invoked to acquire a passphrase with which to protect the key. The default is util.passphrase_callback. twb(Rtopenfilet save_key_bio(RtfileR1tcallbacktbio((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pytsave_key scCs||dkr(tj|j|j|Stt|d}|dkrVtd|ntj|j|j||SdS(sN Save the key pair to the M2Crypto.BIO object 'bio' in PEM format. @type bio: M2Crypto.BIO @param bio: M2Crypto.BIO object to save key to. @type cipher: string @param cipher: Symmetric cipher to protect the key. The default cipher is 'aes_128_cbc'. If cipher is None, then the key is saved in the clear. @type callback: Python callable @param callback: A Python callable object that is invoked to acquire a passphrase with which to protect the key. The default is util.passphrase_callback. sno such cipher %sN(RRtpkey_write_pem_no_cipherRDRIRRtpkey_write_pem(RRcR1Rbtproto((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyR`s   cCs)tj}|j||||jS(s Return key in PEM format in a string. @type cipher: string @param cipher: Symmetric cipher to protect the key. The default cipher is 'aes_128_cbc'. If cipher is None, then the key is saved in the clear. @type callback: Python callable @param callback: A Python callable object that is invoked to acquire a passphrase with which to protect the key. The default is util.passphrase_callback. (Rt MemoryBufferR`tread_all(RR1RbRc((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pytas_pem7s cCs+tj|j}tj|}|jS(s6 Return key in DER format in a string (Rt pkey_as_derRDRRhRi(RtbufRc((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pytas_derIscCstj|jS(s6 Return the size of the key in bytes. (Rt pkey_sizeRD(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pytsizeQscCstj|jS(s3 Return the modulus in hex format. (Rtpkey_get_modulusRD(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyt get_modulusWsN( RRR Rt pkey_freeRHR!RRRRRIRGRKRLRMRNRRRORPRQRXR\Rtpassphrase_callbackRdR`RjRmRoRq(((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyRCs0            cCstj|d}|dkr6tjtjntj||}tj||dkrvt tjnt |dS(sj Load an M2Crypto.EVP.PKey from file. @type file: string @param file: Name of file containing the key in PEM format. @type callback: Python callable @param callback: A Python callable object that is invoked to acquire a passphrase with which to protect the key. @rtype: M2Crypto.EVP.PKey @return: M2Crypto.EVP.PKey object. triN( Rt bio_new_fileRRtBIOErrorRt get_errort pkey_read_pemtbio_freeRRC(RaRbRctcptr((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pytload_key^s   cCsFtj|j|}|dkr9ttjnt|dS(s Load an M2Crypto.EVP.PKey from an M2Crypto.BIO object. @type bio: M2Crypto.BIO @param bio: M2Crypto.BIO object containing the key in PEM format. @type callback: Python callable @param callback: A Python callable object that is invoked to acquire a passphrase with which to protect the key. @rtype: M2Crypto.EVP.PKey @return: M2Crypto.EVP.PKey object. iN(RRxRIRRRRwRC(RcRbRz((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyt load_key_bious cCstj|}t||S(sl Load an M2Crypto.EVP.PKey from a string. @type string: string @param string: String containing the key in PEM format. @type callback: Python callable @param callback: A Python callable object that is invoked to acquire a passphrase with which to protect the key. @rtype: M2Crypto.EVP.PKey @return: M2Crypto.EVP.PKey object. (RRhR|(tstringRbRc((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pytload_key_strings(((((R tM2CryptoRRRRRt ExceptionRtevp_initR RR#R-R.RCRsR{R|R~(((s2/usr/lib64/python2.7/site-packages/M2Crypto/EVP.pyts"   ! !