U ä€C^–mã@söddlZddlZddlZddlZddlZddlZddlmZmZddl m Z m Z ddl m Z ddl mZddl mZddlmZmZGdd „d eƒZGd d „d eƒZd d „Zddd„ZGdd„deƒZdd„Zddd„Zdd„Zddd„Zdd„ZdS) éN)ÚsixÚ OrderedDict)Úcreate_request_objectÚprepare_request_dict)ÚUnknownSignatureVersionError)ÚUnknownClientMethodError)Ú UnsupportedSignatureVersionError)Ú fix_s3_hostÚdatetime2timestampc@speZdZdZdd„Zedd„ƒZedd„ƒZedd „ƒZdd d „Z ddd„Z dd„Z ddd„Z e Z ddd„Zd S)Ú RequestSignera0 An object to sign requests before they go out over the wire using one of the authentication mechanisms defined in ``auth.py``. This class fires two events scoped to a service and operation name: * choose-signer: Allows overriding the auth signer name. * before-sign: Allows mutating the request before signing. Together these events allow for customization of the request signing pipeline, including overrides, request path manipulation, and disabling signing per operation. :type service_id: botocore.model.ServiceId :param service_id: The service id for the service, e.g. ``S3`` :type region_name: string :param region_name: Name of the service region, e.g. ``us-east-1`` :type signing_name: string :param signing_name: Service signing name. This is usually the same as the service name, but can differ. E.g. ``emr`` vs. ``elasticmapreduce``. :type signature_version: string :param signature_version: Signature name like ``v4``. :type credentials: :py:class:`~botocore.credentials.Credentials` :param credentials: User credentials with which to sign requests. :type event_emitter: :py:class:`~botocore.hooks.BaseEventHooks` :param event_emitter: Extension mechanism to fire events. cCs.||_||_||_||_||_t |¡|_dS©N)Ú _region_nameÚ _signing_nameÚ_signature_versionÚ _credentialsÚ _service_idÚweakrefÚproxyÚ_event_emitter)ÚselfZ service_idÚ region_nameÚ signing_nameÚsignature_versionÚ credentialsZ event_emitter©rú6/tmp/pip-install-6_kvzl1k/botocore/botocore/signers.pyÚ__init__>s zRequestSigner.__init__cCs|jSr )r ©rrrrrIszRequestSigner.region_namecCs|jSr )rrrrrrMszRequestSigner.signature_versioncCs|jSr )rrrrrrQszRequestSigner.signing_nameNcKs | ||¡Sr )Úsign)rÚoperation_nameÚrequestÚkwargsrrrÚhandlerUszRequestSigner.handlerÚstandardc Cs|}|dkr|j}|dkr |j}| |||j¡}|jjd |j ¡|¡|||j|||d�|t j k�r|||dœ} |dk r‚|| d<|s¬|j  di¡  d¡r¬|jdd| d<z|j f| Ž} Wn:t k rö} z|d krât|d �‚n| ‚W5d} ~ XYnX|  |¡dS) a<Sign a request before it goes out over the wire. :type operation_name: string :param operation_name: The name of the current operation, e.g. ``ListBuckets``. :type request: AWSRequest :param request: The request object to be sent over the wire. :type region_name: str :param region_name: The region to sign the request for. :type signing_type: str :param signing_type: The type of signing to perform. This can be one of three possible values: * 'standard' - This should be used for most requests. * 'presign-url' - This should be used when pre-signing a request. * 'presign-post' - This should be used when pre-signing an S3 post. :type expires_in: int :param expires_in: The number of seconds the presigned url is valid for. This parameter is only valid for signing type 'presign-url'. :type signing_name: str :param signing_name: The name to use for the service when signing. Nzbefore-sign.{0}.{1})r rrrÚrequest_signerr)rrrÚexpiresZsigningÚregionrr#©r)r rÚ_choose_signerÚcontextrÚemitÚformatrÚ hyphenizeÚbotocoreÚUNSIGNEDÚgetÚget_auth_instancerrZadd_auth) rrr rÚ signing_typeÚ expires_inrZexplicit_region_namerr!ÚauthÚerrrr\sZÿÿú ý ÿÿÿzRequestSigner.signc Cs�dddœ}| |d¡}|j}|tjk r8| |¡s8||7}|jjd |j  ¡|¡|j |j ||d�\}}|dk rŒ|}|tjk rŒ| |¡sŒ||7}|S)ai Allow setting the signature version via the choose-signer event. A value of `botocore.UNSIGNED` means no signing will be performed. :param operation_name: The operation to sign. :param signing_type: The type of signing that the signer is to be used for. :return: The signature version to sign with. z -presign-postz-query)ú presign-postú presign-urlÚzchoose-signer.{0}.{1})rrrr)N) r/rr-r.ÚendswithrZemit_until_responser+rr,rr ) rrr1r)Zsigning_type_suffix_mapÚsuffixrr"Úresponserrrr(¢s4 þ  ÿÿü  ÿzRequestSigner._choose_signercKs†|dkr|j}tjj |¡}|dkr.t|d�‚d}|jdk rF|j ¡}||d<|jrx|j dkrhtj   ¡‚||d<||d<|f|Ž}|S)a© Get an auth instance which can be used to sign a request using the given signature version. :type signing_name: string :param signing_name: Service signing name. This is usually the same as the service name, but can differ. E.g. ``emr`` vs. ``elasticmapreduce``. :type region_name: string :param region_name: Name of the service region, e.g. ``us-east-1`` :type signature_version: string :param signature_version: Signature name like ``v4``. :rtype: :py:class:`~botocore.auth.BaseSigner` :return: Auth instance to sign a request. Nr'rrZ service_name) rr-r3ZAUTH_TYPE_MAPSr/rrZget_frozen_credentialsZREQUIRES_REGIONr Ú exceptionsZ NoRegionError)rrrrr!ÚclsZfrozen_credentialsr3rrrr0Çs$ÿ     zRequestSigner.get_auth_instanceécCs*t|ƒ}| |||d||¡| ¡|jS)aÍGenerates a presigned url :type request_dict: dict :param request_dict: The prepared request dictionary returned by ``botocore.awsrequest.prepare_request_dict()`` :type operation_name: str :param operation_name: The operation being signed. :type expires_in: int :param expires_in: The number of seconds the presigned url is valid for. By default it expires in an hour (3600 seconds) :type region_name: string :param region_name: The region name to sign the presigned url. :type signing_name: str :param signing_name: The name to use for the service when signing. :returns: The presigned url r6)rrÚprepareÚurl)rÚ request_dictrr2rrr rrrÚgenerate_presigned_urlõs ÿz$RequestSigner.generate_presigned_url)NN)Nr#NN)N)r=NN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rÚpropertyrrrr"rr(r0Zget_authrArrrrr s,!     ÿ F&ÿ ,þr c@s<eZdZdZdd„Zd dd„Zdd„Zdd d „Zd d „ZdS)ÚCloudFrontSigneraàA signer to create a signed CloudFront URL. First you create a cloudfront signer based on a normalized RSA signer:: import rsa def rsa_signer(message): private_key = open('private_key.pem', 'r').read() return rsa.sign( message, rsa.PrivateKey.load_pkcs1(private_key.encode('utf8')), 'SHA-1') # CloudFront requires SHA-1 hash cf_signer = CloudFrontSigner(key_id, rsa_signer) To sign with a canned policy:: signed_url = cf_signer.generate_signed_url( url, date_less_than=datetime(2015, 12, 1)) To sign with a custom policy:: signed_url = cf_signer.generate_signed_url(url, policy=my_policy) cCs||_||_dS)a–Create a CloudFrontSigner. :type key_id: str :param key_id: The CloudFront Key Pair ID :type rsa_signer: callable :param rsa_signer: An RSA signer. Its only input parameter will be the message to be signed, and its output will be the signed content as a binary string. The hash algorithm needed by CloudFront is SHA-1. N)Úkey_idÚ rsa_signer)rrHrIrrrr-s zCloudFrontSigner.__init__NcCsÂ|dk r|dk s |dkr,|dkr,d}t|ƒ‚|dk r@| ||¡}t|tjƒrV| d¡}|dk rrdtt|ƒƒg}nd| |¡  d¡g}|  |¡}|  d| |¡  d¡d|j g¡|  ||¡S)a¤Creates a signed CloudFront URL based on given parameters. :type url: str :param url: The URL of the protected object :type date_less_than: datetime :param date_less_than: The URL will expire after that date and time :type policy: str :param policy: The custom policy, possibly built by self.build_policy() :rtype: str :return: The signed URL. Nz=Need to provide either date_less_than or policy, but not bothÚutf8z Expires=%sz Policy=%sz Signature=%szKey-Pair-Id=%s)Ú ValueErrorÚ build_policyÚ isinstancerÚ text_typeÚencodeÚintr Ú_url_b64encodeÚdecoderIÚextendrHÚ _build_url)rr?Údate_less_thanÚpolicyr4ÚparamsÚ signaturerrrrA<s(ÿÿ    þz'CloudFrontSigner.generate_presigned_urlcCs"d|kr dnd}||d |¡S)Nú?ú&)Újoin)rÚbase_urlZ extra_paramsÚ separatorrrrrT_szCloudFrontSigner._build_urlc Cs„tt|ƒƒ}tdd|iiƒ}|r s4   z~ 3Lÿ ?ÿ s