ó ñ1Mc@s"dZddlZddlZddlZddlZddlZdefd„ƒYZejeƒej Z ej Z ej Z ej Z ddd„ƒYZ de fd„ƒYZd „Zejd „Zed „Zejd „Zejd „Zejd„Zd„Zd„Zd„ZdS(scM2Crypto wrapper for OpenSSL RSA API. Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved.iÿÿÿÿNtRSAErrorcBseZRS((t__name__t __module__(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pyRstRSAcBs eZdZejZdd„Zd„Zd„Zd„Z d„Z d„Z d„Z d „Z d „Zd ejd „Zd ejd „ZeZd ejd„Zd„Zd„Zd„Zd„Zd„Zddd„Zddd„Zdd„Zdd„ZRS(s RSA Key Pair. icCs1tj|ƒstdƒ‚||_||_dS(Ns'rsa' type error(tm2trsa_type_checktAssertionErrortrsat_pyfree(tselfRR((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pyt__init__s cCs)t|ddƒr%|j|jƒndS(NRi(tgetattrt m2_rsa_freeR(R ((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pyt__del__scCstj|jƒd>S(Ni(Rtrsa_sizeR(R ((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pyt__len__"scCsB|dkrtj|jƒS|dkr8tj|jƒSt‚dS(Ntetn(Rt rsa_get_eRt rsa_get_ntAttributeError(R tname((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pyt __getattr__%s   cCs:|jƒstdƒ‚tj|jƒtj|jƒfS(Nskey is not initialised(t check_keyRRRRR(R ((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pytpub-scCs.|jƒstdƒ‚tj|j||ƒS(Nskey is not initialised(RRRtrsa_public_encryptR(R tdatatpadding((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pytpublic_encrypt1scCs.|jƒstdƒ‚tj|j||ƒS(Nskey is not initialised(RRRtrsa_public_decryptR(R RR((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pytpublic_decrypt5scCs.|jƒstdƒ‚tj|j||ƒS(Nskey is not initialised(RRRtrsa_private_encryptR(R RR((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pytprivate_encrypt9scCs.|jƒstdƒ‚tj|j||ƒS(Nskey is not initialised(RRRtrsa_private_decryptR(R RR((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pytprivate_decrypt=st aes_128_cbccCs‚|dkr(tj|j|jƒ|ƒStt|dƒ}|dkrVtd|‚n |ƒ}tj|j|jƒ||ƒSdS(sR Save the key pair to an M2Crypto.BIO.BIO object in PEM format. @type bio: M2Crypto.BIO.BIO @param bio: M2Crypto.BIO.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. snot such cipher %sN(tNoneRtrsa_write_key_no_cipherRt_ptrR Rt rsa_write_key(R tbiotciphertcallbacktciph((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pyt save_key_bioAs   cCs%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(tBIOtopenfileR,(R tfileR)R*R(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pytsave_key\scCs)tjƒ}|j|||ƒ|jƒS(sB Returns the key(pair) as a string in PEM format. (R.t MemoryBufferR,tread(R R)R*R(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pytas_pemrs cCstj|j|jƒƒS(s± Save the key pair to an M2Crypto.BIO.BIO object in DER format. @type bio: M2Crypto.BIO.BIO @param bio: M2Crypto.BIO.BIO object to save key to. (Rtrsa_write_key_derRR&(R R(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pytsave_key_der_biozscCstj|dƒ}|j|ƒS(s‚ Save the key pair to a file in DER format. @type file: str @param file: Filename to save key to R-(R.R/R6(R R0R(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pyt save_key_derƒscCstj|j|jƒƒS(s³ Save the public key to an M2Crypto.BIO.BIO object in PEM format. @type bio: M2Crypto.BIO.BIO @param bio: M2Crypto.BIO.BIO object to save key to. (Rtrsa_write_pub_keyRR&(R R(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pytsave_pub_key_bioscCs+tj|dƒ}tj|j|jƒƒS(sŒ Save the public key to a file in PEM format. @type file: string @param file: Name of file to save key to. R-(R.R/RR8RR&(R R0R(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pyt save_pub_key–scCstj|jƒS(N(Rt rsa_check_keyR(R ((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pyR stsha1icCsbtt|dƒ}|dkr1tdtƒ‚ntj|j||ƒ|ƒ}|j|tjƒS(sµ Signs a digest with the private key using RSASSA-PSS @requires: OpenSSL 0.9.7h or later. @type digest: str @param digest: A digest created by using the digest method @type salt_length: int @param salt_length: The length of the salt to use @type algo: str @param algo: The hash algorithm to use @return: a string which is the signature snot such hash algorithm %sN( R RR$t ValueErrort hash_algotrsa_padding_add_pkcs1_pssRR t no_padding(R tdigesttalgot salt_lengththasht signature((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pytsign_rsassa_pss£s  cCsett|dƒ}|dkr1tdtƒ‚n|j|tjƒ}tj|j|||ƒ|ƒS(s Verifies the signature RSASSA-PSS @requires: OpenSSL 0.9.7h or later. @type data: str @param data: Data that has been signed @type signature: str @param signature: The signature signed with RSASSA-PSS @type salt_length: int @param salt_length: The length of the salt that was used @type algo: str @param algo: The hash algorithm to use @return: 1 or 0, depending on whether the signature was verified or not. snot such hash algorithm %sN( R RR$R=R>RR@trsa_verify_pkcs1_pssR(R RRERBRCRDtplain_signature((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pytverify_rsassa_pss¼s  cCsJttd|dƒ}|dkr4td|f‚ntj|j||ƒS(st Signs a digest with the private key @type digest: str @param digest: A digest created by using the digest method @type algo: str @param algo: The method that created the digest. Legal values are 'sha1','sha224', 'sha256', 'ripemd160', and 'md5'. @return: a string which is the signature tNID_sunknown algorithmN(R RR$R=trsa_signR(R RARBt digest_type((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pytsignÙs cCsMttd|dƒ}|dkr4td|f‚ntj|j|||ƒS(s  Verifies the signature with the public key @type data: str @param data: Data that has been signed @type signature: str @param signature: The signature signed with the private key @type algo: str @param algo: The method use to create digest from the data before it was signed. Legal values are 'sha1','sha224', 'sha256', 'ripemd160', and 'md5'. @return: True or False, depending on whether the signature was verified. RJsunknown algorithmN(R RR$R=t rsa_verifyR(R RRERBRL((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pytverifyís (RRt__doc__Rtrsa_freeR R R RRRRRR R"tutiltpassphrase_callbackR,R1tsave_pemR4R6R7R9R:RRFRIRMRO(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/RSA.pyRs0            tRSA_pubcBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(s0 Object interface to an RSA public key. cCs)|dkrtd‚n ||j|s& 0     ô'