ó |~úVc@€ssdZddlmZmZddlZddlZddlmZddlZddl Zddl Ze ej j jƒƒZ d„Zdefd„ƒYZdefd „ƒYZd efd „ƒYZd efd „ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZeƒZeƒZeƒZeƒZeƒZeƒZdS(sWCommandline scripts. These scripts are called by the executables defined in setup.py. iÿÿÿÿ(twith_statementtprint_functionN(t OptionParsercC€s"tddddƒ}|jddddd ƒ|jd d dddd ƒ|jd ddddddƒ|jtjdƒ\}}t|ƒdkr°|jƒtdƒ‚nyt|dƒ}WnBt k r|jƒt d|ddtj ƒtdƒ‚nXt d|dtj ƒt j |ƒ\}}|jr˜t d|jdtj ƒ|jd|jƒ}t|jdƒ}|j|ƒWdQXn|jd|jƒ}|jrût d|jdtj ƒt|jdƒ}|j|ƒWdQXn#t ddtj ƒtjj|ƒdS(sKey generator.tusagesusage: %prog [options] keysizet descriptions.Generates a new RSA keypair of "keysize" bits.s--puboutttypetstringthelpsžOutput filename for the public key. The public key is not saved if this option is not present. You can use pyrsa-priv2pub to create the public key file later.s-os--outs`Output filename for the private key. The key is written to stdout if this option is not present.s--forms7key format of the private and public keys - default PEMtchoicestPEMtDERtdefaultiisNot a valid number: %stfilesGenerating %i-bit keysWriting public key to %stformattwbNsWriting private key to %ssWriting private key to stdout(R R (Rt add_optiont parse_argstsystargvtlent print_helpt SystemExittintt ValueErrortprinttstderrtrsatnewkeystpuboutt save_pkcs1tformtopentwritetouttstdout(tparsertclitcli_argstkeysizetpub_keytpriv_keytdatatoutfile((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pytkeygen#sB         tCryptoOperationcB€s§eZdZejZdZdZdZ dZ dZ dZ dZ dZdZeZejZd „Zejdd „ƒZd „Zd „Zd „Zd„Zd„ZRS(s9CLI callable that operates with input, output, and a key.tpublics'usage: %%prog [options] %(keyname)s_keytdecryptt decryptedt decryptingsEName of the file to %(operation)s. Reads from stdin if not specified.sjName of the file to write the %(operation_past)s file to. Written to stdout if this option is not present.icC€sF|j|jj|_|j|jj|_|j|jj|_dS(N(Rt __class__t__dict__t input_helpt output_help(tself((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyt__init__nscC€sdS(s€Performs the program's operation. Implement in a subclass. :returns: the data to write to the output. N((R5tindatatkeyR%((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pytperform_operationstcC€s‘|jƒ\}}|j|d|jƒ}|j|jƒ}t|jjƒdtj ƒ|j |||ƒ}|j r|j ||j ƒndS(sRuns the program.iR N(t parse_clitread_keytkeyformt read_infiletinputRtoperation_progressivettitleRRR9t has_outputt write_outfiletoutput(R5R$R%R8R7toutdata((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyt__call__|s cC€sßtd|jd|jƒ}|jddddd|jƒ|jre|jdd ddd|jƒn|jd dd |jd ddd ƒ|jt j dƒ\}}t |ƒ|j krÕ|j ƒtdƒ‚n||fS(sFParse the CLI options :returns: (cli_opts, cli_args) RRs-is--inputRRRs-os--outputs --keyforms&Key format of the %s key - default PEMRR R R i(R R (RRRRR3RBR4tkeynameRRRRtexpected_cli_argsRR(R5R#R$R%((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR;‹s "    cC€sWtd|j|fdtjƒt|dƒ}|jƒ}WdQX|jj||ƒS(sReads a public or private key.sReading %s key from %sR trbN(RRGRRRtreadt key_classt load_pkcs1(R5tfilenameR=tkeyfiletkeydata((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR<¤s cC€sb|rBtd|dtjƒt|dƒ}|jƒSWdQXntddtjƒtjjƒS(sRead the input filesReading input from %sR RINsReading input from stdin(RRRRRJtstdin(R5tinnametinfile((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR>­s cC€sl|rEtd|dtjƒt|dƒ}|j|ƒWdQXn#tddtjƒtjj|ƒdS(sWrite the output filesWriting output to %sR RNsWriting output to stdout(RRRRR R"(R5REtoutnameR*((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyRC¸s N(t__name__t __module__t__doc__tabctABCMetat __metaclass__RGRtNoneRt operationtoperation_pastR@R3R4RHtTrueRBRt PublicKeyRKR6tabstractmethodR9RFR;R<R>RC(((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR,Zs*      tEncryptOperationcB€s8eZdZdZdZdZdZdZdd„Z RS(sEncrypts a file.R-sEncrypts a file. The file must be shorter than the key length in order to be encrypted. For larger files, use the pyrsa-encrypt-bigfile command.tencryptt encryptedt encryptingcC€stj||ƒS(sEncrypts files.(RRa(R5R7R'R%((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR9ÏsN( RTRURVRGRR[R\R@RZR9(((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR`ÄstDecryptOperationcB€sAeZdZdZdZdZdZdZej Z dd„Z RS(sDecrypts a file.tprivates Decrypts a file. The original file must be shorter than the key length in order to have been encrypted. For larger files, use the pyrsa-decrypt-bigfile command.R.R/R0cC€stj||ƒS(sDecrypts files.(RR.(R5R7R(R%((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR9ásN( RTRURVRGRR[R\R@Rt PrivateKeyRKRZR9(((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyRdÕs t SignOperationcB€s]eZdZdZdZddjeƒZdZdZ dZ e j Z dZd Zd „ZRS( s Signs a file.Res/usage: %%prog [options] private_key hash_methodsCSigns a file, outputs the signature. Choose the hash method from %ss, tsignt signaturetSigningis\Name of the file to write the signature to. Written to stdout if this option is not present.cC€sE|d}|tkr2tddjtƒƒ‚ntj|||ƒS(s Signs files.is%Invalid hash method, choose one of %ss, (t HASH_METHODSRtjoinRRh(R5R7R(R%t hash_method((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR9÷s   (RTRURVRGRRlRkRR[R\R@RRfRKRHR4R9(((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyRgçs tVerifyOperationcB€sPeZdZdZdZdZdZdZdZe j Z dZ e Zd„ZRS( sVerify a signature.R-s1usage: %%prog [options] public_key signature_filessVerifies a signature, exits with status 0 upon success, prints an error message and exits with status 1 upon error.tverifytverifiedt VerifyingicC€s|d}t|dƒ}|jƒ}WdQXytj|||ƒWn tjk rgtdƒ‚nXtddtjƒdS(sVerifies files.iRINsVerification failed.sVerification OKR ( RRJRRotVerificationErrorRRRR(R5R7R'R%tsignature_filetsigfileRi((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR9s (RTRURVRGRRR[R\R@RR^RKRHtFalseRBR9(((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyRns tBigfileOperationcB€s;eZdZd„Zd„Zd„Zd„Zd„ZRS(s>CryptoOperation that doesn't read the entire file into memory.cC€stj|ƒg|_dS(N(R,R6t file_objects(R5((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR6#s cC€s"x|jD]}|jƒq WdS(sCloses any open file handles.N(Rwtclose(R5tfobj((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyt__del__(scC€s…|jƒ\}}|j|d|jƒ}|j|jƒ}|j|jƒ}t|jj ƒdt j ƒ|j ||||ƒdS(sRuns the program.iR N( R;R<R=t get_infileR?t get_outfileRDRR@RARRR9(R5R$R%R8RRR*((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyRF.s cC€s_|r?td|dtjƒt|dƒ}|jj|ƒntddtjƒtj}|S(sReturns the input file objectsReading input from %sR RIsReading input from stdin(RRRRRwtappendRP(R5RQRy((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR{=s cC€s_|r?td|dtjƒt|dƒ}|jj|ƒntddtjƒtj}|S(sReturns the output file objectsWill write output to %sR RsWill write output to stdout(RRRRRwR}R"(R5RSRy((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR|Js (RTRURVR6RzRFR{R|(((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyRv s     tEncryptBigfileOperationcB€s8eZdZdZdZdZdZdZdd„Z RS(s#Encrypts a file to VARBLOCK format.R-s’Encrypts a file to an encrypted VARBLOCK file. The file can be larger than the key length, but the output file is only compatible with Python-RSA.RaRbRccC€stjj|||ƒS(sEncrypts files to VARBLOCK.(Rtbigfiletencrypt_bigfile(R5RRR*R'R%((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR9csN( RTRURVRGRR[R\R@RZR9(((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR~XstDecryptBigfileOperationcB€sAeZdZdZdZdZdZdZej Z dd„Z RS(s#Decrypts a file in VARBLOCK format.ResQDecrypts an encrypted VARBLOCK file that was encrypted with pyrsa-encrypt-bigfileR.R/R0cC€stjj|||ƒS(sDecrypts a VARBLOCK file.(RRtdecrypt_bigfile(R5RRR*R(R%((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyR9tsN( RTRURVRGRR[R\R@RRfRKRZR9(((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyRis (RVt __future__RRRWRtoptparseRRt rsa.bigfilet rsa.pkcs1tsortedtpkcs1RktkeysR+tobjectR,R`RdRgRnRvR~RRaR.RhRoR€R‚(((s2/opt/awscli/lib/python2.7/site-packages/rsa/cli.pyts.      7j8