a `l@sdZddlZddlZddlZddlmZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddlZddlmZddlmZddlmZddlZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlm Z ddlm!Z!ddl"m#Z#e$e%Z&e j'dkr`zej(j)j*j+,Wn(e-y^ddl.Z)e)j*j+,Yn0dZ/dZ0Gddde1Z2Gddde2Z3Gddde2Z4Gddde1Z5Gddde1Z6dS)zACME client API.N) parsedate_tz) HTTPAdapter)parse_header_links)SourceAddressAdapter) http_client) crypto_util)errors)jws)messages)Dict)List)Set)Text)VersionedLEACMEMixin) -zapplication/pkix-certc@sveZdZdZddZedddZddZd d Zdd d Z d dZ ddZ dddZ ddZ eddZddZdS) ClientBasezACME client base object. :ivar messages.Directory directory: :ivar .ClientNetwork net: Client network. :ivar int acme_version: ACME protocol version. 1 or 2. cCs||_||_||_dS)zInitialize. :param .messages.Directory directory: Directory Resource :param .ClientNetwork net: Client network. :param int acme_version: ACME protocol version. 1 or 2. N directorynet acme_version)selfrrrr-/usr/lib/python3/dist-packages/acme/client.py__init__8szClientBase.__init__NcCs>d|jvr|jdd}tjtj||jd||dS)Nzterms-of-serviceurlLocation)bodyuriterms_of_service)linksr ZRegistrationResourceZ Registration from_jsonjsonheadersget)clsresponser r!rrr_regr_from_responseCs  zClientBase._regr_from_responsecCs"||j|}|j||j|jdS)Nr r!)_postr r)r!)rregrrr(rrr_send_recv_regrMs zClientBase._send_recv_regrcOs@|d|jt|jdr.|dt|jd|jj|i|S)zBWrapper around self.net.post that adds the acme_version. rnewNonce new_nonce_url) setdefaultrhasattrrgetattrrpostrargskwargsrrrr+Zs zClientBase._postcCs@|dur|jn|}tjfit|}|j||d}||j_|S)KUpdate registration. :param messages.RegistrationResource regr: Registration Resource. :param messages.Registration update: Updated body of the resource. If not provided, body will be taken from `regr`. :returns: Updated Registration Resource. :rtype: `.RegistrationResource` Nr)rr UpdateRegistrationdictr-raccount)rr,updaterZ updated_regrrrrupdate_registrationcs zClientBase.update_registrationcCs|j|ddidS)zDeactivate registration. :param messages.RegistrationResource regr: The Registration Resource to be deactivated. :returns: The Registration resource that was deactivated. :rtype: `.RegistrationResource` status deactivated)r<)r=rr,rrrdeactivate_registrationts z"ClientBase.deactivate_registrationcCs.tjdd}||j|}|||jj|jS)aDeactivate authorization. :param messages.AuthorizationResource authzr: The Authorization resource to be deactivated. :returns: The Authorization resource that was deactivated. :rtype: `.AuthorizationResource` r?)r>)r ZUpdateAuthorizationr+r _authzr_from_responser identifier)rauthzrrr(rrrdeactivate_authorizations  z#ClientBase.deactivate_authorizationcCsFtjtj||jd|d}|durB|jj|krBt ||S)Nr)rr ) r ZAuthorizationResourceZ Authorizationr#r$r%r&rrCrUnexpectedUpdate)rr(rCr rDrrrrBs  z ClientBase._authzr_from_responsecCst||j|}z|jdd}Wnty<tdYn0tj|tj | d}|j|jkrpt |j|S)ahAnswer challenge. :param challb: Challenge Resource body. :type challb: `.ChallengeBody` :param response: Corresponding Challenge response :type response: `.challenges.ChallengeResponse` :returns: Challenge Resource with updated body. :rtype: `.ChallengeResource` :raises .UnexpectedUpdate: uprz"up" Link header missing) authzr_urir) r+r r"KeyErrorr ClientErrorr ZChallengeResourceZ ChallengeBodyr#r$rF)rZchallbr(rHZchallrrrranswer_challenges   zClientBase.answer_challengec Cs|jdt|}z t|}Wnxtyt|}|durz:t|ddurV|dnd}tj|dd|WYSttfyYn0|}Yn0tj tj|dS)aCompute next `poll` time based on response ``Retry-After`` header. Handles integers and various datestring formats per https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.37 :param requests.Response response: Response from `poll`. :param int default: Default value (in seconds), used when ``Retry-After`` header is not present or invalid. :returns: Time point when next `poll` should be performed. :rtype: `datetime.datetime` z Retry-AfterNrrseconds) r%r&strint ValueErrorrdatetime timedelta OverflowErrornow)r'r(default retry_afterrNwhenZtz_secsrrrrWs   zClientBase.retry_aftercCs0||tj||d}|jtjkr,tddS)a.Revoke certificate. :param .ComparableX509 cert: `OpenSSL.crypto.X509` wrapped in `.ComparableX509` :param int rsn: Reason code for certificate revocation. :param str url: ACME URL to post to :raises .ClientError: If revocation is unsuccessful. ) certificatereasonz0Successful revocation must return HTTP OK statusN)r+r Revocation status_coderZOKrrJ)rcertrsnrr(rrr_revokes  zClientBase._revoke)NN)N)NN)__name__ __module__ __qualname____doc__r classmethodr)r-r+r=rArErBrKrWr_rrrrr1s       rcseZdZdZejddffdd Zd"ddZdd Zd d Z d#d d Z d$ddZ ddZ ddZ d%ddZddZddZddZd&ddZd d!ZZS)'ClientaACME client for a v1 API. .. todo:: Clean up raised error types hierarchy, document, and handle (wrap) instances of `.DeserializationError` raised in `from_json()`. :ivar messages.Directory directory: :ivar key: `josepy.JWK` (private) :ivar alg: `josepy.JWASignature` :ivar bool verify_ssl: Verify SSL certificates? :ivar .ClientNetwork net: Client network. Useful for testing. If not supplied, it will be initialized using `key`, `alg` and `verify_ssl`. TNcsX||_|durt|||d}t|tjr>tj|| }t t |j ||dddS)zInitialize. :param directory: Directory Resource (`.messages.Directory`) or URI from which the resource will be downloaded. N)alg verify_sslr) key ClientNetwork isinstancesixZ string_typesr Directoryr#r&r$superrer)rrrirfrgr __class__rrrs   zClient.__init__cCs@|durtn|}||j||}|jtjks6J||S)zRegister. :param .NewRegistration new_reg: :returns: Registration Resource. :rtype: `.RegistrationResource` N)r ZNewRegistrationr+rr\rCREATEDr))rZnew_regr(rrrregister s zClient.registercCs||tS)Query server about registration. :param messages.RegistrationResource: Existing Registration Resource. )r-r r9r@rrrquery_registrationszClient.query_registrationcCs||j|jj|jddS)aAgree to the terms-of-service. Agree to the terms-of-service in a Registration Resource. :param regr: Registration Resource. :type regr: `.RegistrationResource` :returns: Updated Registration Resource. :rtype: `.RegistrationResource` )Z agreementr8)r=r<rr!r@rrr agree_to_tos's zClient.agree_to_toscCs`|durtd|jdr(tdtj|d}||j j |}|j t j ksTJ|||S)aGRequest challenges. :param .messages.Identifier identifier: Identifier to be challenged. :param str new_authzr_uri: Deprecated. Do not use. :returns: Authorization Resource. :rtype: `.AuthorizationResource` :raises errors.WildcardUnsupportedError: if a wildcard is requested Nz2request_challenges with new_authzr_uri deprecated.*zbRequesting an authorization for a wildcard name is forbidden by this version of the ACME protocol.)rC)loggerdebugvalue startswithrZWildcardUnsupportedErrorr ZNewAuthorizationr+r new_authzr\rrqrB)rrCnew_authzr_urir{r(rrrrequest_challenges6s    zClient.request_challengescCs|tjtj|d|S)a"Request challenges for domain names. This is simply a convenience function that wraps around `request_challenges`, but works with domain names instead of generic identifiers. See ``request_challenges`` for more documentation. :param str domain: Domain name to be challenged. :param str new_authzr_uri: Deprecated. Do not use. :returns: Authorization Resource. :rtype: `.AuthorizationResource` :raises errors.WildcardUnsupportedError: if a wildcard is requested typry)r}r IdentifierIDENTIFIER_FQDN)rdomainr|rrrrequest_domain_challengesPs z Client.request_domain_challengesc Cs|s Jdtdtj|d}t}|j|jj||d|id}|j di d}z|j d}Wnt y~t d Yn0tj|||ttjtjj|jd S) aRequest issuance. :param csr: CSR :type csr: `OpenSSL.crypto.X509Req` wrapped in `.ComparableX509` :param authzrs: `list` of `.AuthorizationResource` :returns: Issued certificate :rtype: `.messages.CertificateResource` zAuthorizations list is emptyzRequesting issuance...csrAccept) content_typer%rGrrz"Location" Header missing)r authzrscert_chain_urir)rwrxr CertificateRequestDER_CONTENT_TYPEr+rZnew_certr"r&r%rIrrJZCertificateResourcejoseComparableX509OpenSSLcryptoload_certificate FILETYPE_ASN1content)rrrZreqrr(rr rrrrequest_issuanceds*      zClient.request_issuancecCs*|j|j}|||jj|j}||fSaPoll Authorization Resource for status. :param authzr: Authorization Resource :type authzr: `.AuthorizationResource` :returns: Updated Authorization Resource and HTTP response. :rtype: (`.AuthorizationResource`, `requests.Response`) )rr&r rBrrCrrDr(updated_authzrrrrpolls  z Client.poll csT|dks Jtt}t}ddt|D}t|dd|D|rt|\}} } tj } || kr|| j } t d| t | || \} }| | <|| d7<| jjtjtjfvrF|| |krt||j||d| | fqF|| qF|s"td d tDr.t|tfd d |D}||||fS) aPoll and request issuance. This function polls all provided Authorization Resource URIs until all challenges are valid, respecting ``Retry-After`` HTTP headers, and then calls `request_issuance`. :param .ComparableX509 csr: CSR (`OpenSSL.crypto.X509Req` wrapped in `.ComparableX509`) :param authzrs: `list` of `.AuthorizationResource` :param int mintime: Minimum time before next attempt, used if ``Retry-After`` is not present in the response. :param int max_attempts: Maximum number of attempts (per authorization) before `PollError` with non-empty ``waiting`` is raised. :returns: ``(cert, updated_authzrs)`` `tuple` where ``cert`` is the issued certificate (`.messages.CertificateResource`), and ``updated_authzrs`` is a `tuple` consisting of updated Authorization Resources (`.AuthorizationResource`) as present in the responses from server, and in the same order as the input ``authzrs``. :rtype: `tuple` :raises PollError: in case of timeout or if some authorization was marked by the CA as invalid rcSs g|]\}}tj||fqSr)rRrU).0indexrDrrr sz4Client.poll_and_request_issuance..cSsi|] }||qSrrrrDrrr z4Client.poll_and_request_issuance..zSleeping for %d secondsrh)rVcss|]}|jjtjkVqdSN)rr>r STATUS_INVALIDrrrr sz3Client.poll_and_request_issuance..c3s|]}|VqdSrrrupdatedrrrr) collections defaultdictrPset enumerateheapqheapifyheappoprRrUrNrwrxtimesleeprrr>r STATUS_VALIDrheappushrWaddanyrlZ itervaluesrZ PollErrortupler)rrrZmintimeZ max_attemptsZattemptsZ exhaustedZwaitingrXrrDrUrNrr(Zupdated_authzrsrrrpoll_and_request_issuancesD            z Client.poll_and_request_issuancecCs8t}|jj|d|i|d}|ttjtjj|j fS)zReturns certificate from URI. :param str uri: URI of certificate :returns: tuple of the form (response, :class:`josepy.util.ComparableX509`) :rtype: tuple r)r%r) rrr&rrrrrrr)rr rr(rrr _get_certs   zClient._get_certcCsL||j\}}d|jvr$td|jd|jkr@t|j|j|dS)zCheck for new cert. :param certr: Certificate Resource :type certr: `.CertificateResource` :returns: Updated Certificate Resource. :rtype: `.CertificateResource` rzLocation header missingr8)rr r%rrJrFtextr<)rcertrr(r]rrr check_certs    zClient.check_certcCs ||S)zRefresh certificate. :param certr: Certificate Resource :type certr: `.CertificateResource` :returns: Updated Certificate Resource. :rtype: `.CertificateResource` )r)rrrrrrefreshs zClient.refreshcCshg}|j}|durLt||krL||\}}|jdid}||q |durdtd||S)aFetch chain for certificate. :param .CertificateResource certr: Certificate Resource :param int max_length: Maximum allowed length of the chain. Note that each element in the certificate requires new ``HTTP GET`` request, and the length of the chain is controlled by the ACME CA. :raises errors.Error: if recursion exceeds `max_length` :returns: Certificate chain for the Certificate Resource. It is a list ordered so that the first element is a signer of the certificate from Certificate Resource. Will be empty if ``cert_chain_uri`` is ``None``. :rtype: `list` of `OpenSSL.crypto.X509` wrapped in `.ComparableX509` NrGrz'Recursion limit reached. Didn't get {0}) rlenrr"r&appendrErrorformat)rrZ max_lengthchainr r(r]rrr fetch_chains zClient.fetch_chaincCs||||jtjSRevoke certificate. :param .ComparableX509 cert: `OpenSSL.crypto.X509` wrapped in `.ComparableX509` :param int rsn: Reason code for certificate revocation. :raises .ClientError: If revocation is unsuccessful. )r_rr r[rr]r^rrrrevoke3s z Client.revoke)N)N)N)rr)r)r`rarbrcrRS256rrrrtrur}rrrrrrrrr __classcell__rrrorres$    % K recseZdZdZfddZddZddZd fd d Zd d Zd dZ ddZ d!ddZ ddZ d"ddZ ddZddZddZddZZS)#ClientV2zuACME client for a v2 API. :ivar messages.Directory directory: :ivar .ClientNetwork net: Client network. cstt|j||dddS)zInitialize. :param .messages.Directory directory: Directory Resource :param .ClientNetwork net: Client network. rrN)rnrr)rrrrorrrHs zClientV2.__init__cCsN||jd|}|jdkr8d|jvr8t|jd||}||j_ |S)zRegister. :param .NewRegistration new_account: :raises .ConflictError: in case the account already exists :returns: Registration Resource. :rtype: `.RegistrationResource` newAccountr) r+rr\r%r ConflictErrorr&r)rr;)r new_accountr(r,rrrrQs  zClientV2.new_accountcCs6||j_||jd}|j||j|jd|j_|jjS)rsNr*)rr;r+r r)r!)rr,r(rrrrtds   zClientV2.query_registrationNcs||}tt|||S)r7)_get_v2_accountrnrr=)rr,r<new_regrrorrr=ss zClientV2.update_registrationcCsJd|j_|jjdd}||jd|}|jd}|j|d}||j_|S)NT)Zonly_return_existingrrr )rr;rr<r+rr%)rr,Zonly_existing_regr(Z updated_urirrrrrs  zClientV2._get_v2_accountc Cstjtjj|}t|}g}|D]}|tjtj |dq$tj |d}| |j d|}tj |}g} |jD]} | |j|| | dqxtj||jd| |dS)zRequest a new Order object from the server. :param str csr_pem: A CSR in PEM format. :returns: The newly created order. :rtype: OrderResource r~) identifiersZnewOrderrr)rr authorizationscsr_pem)rrload_certificate_request FILETYPE_PEMr _pyopenssl_cert_or_req_all_namesrr rrZNewOrderr+rOrderr#r$rrB _post_as_get OrderResourcer%r&) rrrdnsNamesrnameorderr(rrrrrr new_orders&      zClientV2.new_ordercCs(||j}|||jj|j}||fSr)rr rBrrCrrrrrs  z ClientV2.pollcCs6|durtjtjdd}|||}|||S)adPoll authorizations and finalize the order. If no deadline is provided, this method will timeout after 90 seconds. :param messages.OrderResource orderr: order to finalize :param datetime.datetime deadline: when to stop polling and timeout :returns: finalized order :rtype: messages.OrderResource NZrM)rRrUrSpoll_authorizationsfinalize_order)rorderrdeadlinerrrpoll_and_finalizes  zClientV2.poll_and_finalizecCsg}|jjD]L}tj|kr |j|||d}|jjtjkrL| |q t dqq t |t |jjkrvt g}|D]4}|jjtjkr~|jjD]}|jdur| |qq~|rt ||j|dS)zPoll Order Resource for status.rrhN)r)rrrRrUrBrr>r ZSTATUS_PENDINGrrrrr TimeoutErrorrZ challengeserrorZValidationErrorr<)rrrZ responsesrrDZfailedZchallrrrrs&     zClientV2.poll_authorizationsFc stjtjj|j}tjt|d} |j j |t j |krtd|j}tj|}|jdurt|j|jdur6|j}|j||jd}|rԈ|d} fdd| D} |j| d}|Sq6tdS) {Finalize an order and obtain a certificate. :param messages.OrderResource orderr: order to finalize :param datetime.datetime deadline: when to stop polling and timeout :param bool fetch_alternative_chains: whether to also fetch alternative certificate chains :returns: finalized order :rtype: messages.OrderResource rrhN)r fullchain_pemZ alternatecsg|]}|jqSr)rr)rrrrrrrz+ClientV2.finalize_order..)Zalternative_fullchains_pem)rrrrrr rrrr+rfinalizerRrUrrrr rr#r$rrZ IssuanceErrorrYr<r _get_linksr) rrrfetch_alternative_chainsrZ wrapped_csrr(rZcertificate_responseZalt_chains_urlsZ alt_chainsrrrrs(          zClientV2.finalize_ordercCs||||jdS)rZ revokeCert)r_rrrrrrs zClientV2.revokecCst|jdo|jjjS)zGChecks if ACME server requires External Account Binding authentication.meta)r1rrexternal_account_requiredrrrrrsz"ClientV2.external_account_requiredcOs,|ddd|dd}|j|i|S)z Send GET request using the POST-as-GET protocol. :param args: :param kwargs: :return: Nrhr)r+)rr5r6new_argsrrrrszClientV2._post_as_getcs.d|jvrgSt|jd}fdd|DS)z Retrieves all Link URIs of relation_type from the response. :param requests.Response response: The requests HTTP response. :param str relation_type: The relation type to filter by. ZLinkcs0g|](}d|vrd|vr|dkr|dqS)Zrelrr)rl relation_typerrr'sz'ClientV2._get_links..)r%r)rr(rr"rrrrs zClientV2._get_links)N)N)F)r`rarbrcrrrtr=rrrrrrrrrrrrrrorrAs      rc@sTeZdZdZddZddZdddZd d Zdd d ZddZ ddZ ddZ dS)BackwardsCompatibleClientV2aACME client wrapper that tends towards V2-style calls, but supports V1 servers. .. note:: While this class handles the majority of the differences between versions of the ACME protocol, if you need to support an ACME server based on version 3 or older of the IETF ACME draft that uses combinations in authorizations (or lack thereof) to signal that the client needs to complete something other than any single challenge in the authorization to make it valid, the user of this class needs to understand and handle these differences themselves. This does not apply to either of Let's Encrypt's endpoints where successfully completing any challenge in an authorization will make it valid. :ivar int acme_version: 1 or 2, corresponding to the Let's Encrypt endpoint :ivar .ClientBase client: either Client or ClientV2 cCsPtj||}|||_|jdkr>t|||d|_nt ||d|_dS)Nrh)rir)r) r rmr#r&r$_acme_version_from_directoryrreclientr)rrriZserverrrrrr>s   z$BackwardsCompatibleClientV2.__init__cCs t|j|Sr)r2r)rrrrr __getattr__Fsz'BackwardsCompatibleClientV2.__getattr__Ncsfdd}|jdkrF|j|}|jdurB||j|j|S|Sd|jjjvrp||jjjj|jdd}|j|SdS)zCombined register and agree_tos for V1, new_account for V2 :param .NewRegistration regr: :param callable check_tos_cb: callback that raises an error if the check does not work csdur|dSrr)Ztos check_tos_cbrr _assess_tosPszDBackwardsCompatibleClientV2.new_account_and_tos.._assess_tosrhNr!T)Zterms_of_service_agreed) rrrrr!rurrr<r)rr,rrrrrnew_account_and_tosIs       z/BackwardsCompatibleClientV2.new_account_and_toscCs`|jdkrTtjtjj|}t|}g}|D]}||j |q.t j ||dS|j |S)aRequest a new Order object from the server. If using ACMEv1, returns a dummy OrderResource with only the authorizations field filled in. :param str csr_pem: A CSR in PEM format. :returns: The newly created order. :rtype: OrderResource :raises errors.WildcardUnsupportedError: if a wildcard domain is requested but unsupported by the ACME version rh)rr) rrrrrrrrrrr rr)rrrrrrrrrr_s  z%BackwardsCompatibleClientV2.new_orderFcCs|jdkr|j}|jttjtjj ||j }d}t j |kr|z|j |}Wq|Wq8tjyxtdYq80q8|durtdtjtjj |jj}t|}|j||dS|j|||S)rrhNzoFailed to fetch chain. You should not deploy the generated certificate, please rerun the command for a new one.)r)rrrrrrrrrrrrRrUrrrrrrZdump_certificaterwrappeddecoderZdump_pyopenssl_chainr<r)rrrrrrrr]rrrrxs2   z*BackwardsCompatibleClientV2.finalize_ordercCs|j||Sr)rrrrrrrs z"BackwardsCompatibleClientV2.revokecCst|drdSdS)Nr.rrh)r1)rrrrrrs z8BackwardsCompatibleClientV2._acme_version_from_directorycCs|jdkrdS|jS)zChecks if the server requires an external account for ACMEv2 servers. Always return False for ACMEv1 servers, as it doesn't use External Account Binding.rhF)rrrrrrrrs z5BackwardsCompatibleClientV2.external_account_required)N)F) r`rarbrcrrrrrrrrrrrrr+s  ' rc@seZdZdZdZdZdZdZdej dde dfd d Z d d Z d dZ ed ddZddZddZefddZddZddZddZedfddZdS)!rjzvWrapper around requests that signs POSTs for authentication. Also adds user agent, and handles Content-Type. zapplication/jsonzapplication/jose+jsonzapplication/problem+jsonz Replay-NonceNTz acme-pythonc Csl||_||_||_||_t|_||_t|_ ||_ t }|durLt |}|j d||j d|dS)Nzhttp://zhttps://)rir;rfrgr_nonces user_agentrequestsZSessionsession_default_timeoutrrZmount) rrir;rfrgrtimeoutZsource_addressZadapterrrrrs zClientNetwork.__init__cCs&z|jWnty Yn0dSr)rclose Exceptionrrrr__del__s zClientNetwork.__del__cCst|tr||_|r$|jddnd}td||j|d}|dkrh||d<|jdurh|jd|d <|j |d <t j j |fi|jddS) a Wrap `JSONDeSerializable` object in JWS. .. todo:: Implement ``acmePath``. :param josepy.JSONDeSerializable obj: :param str url: The URL to which this object will be POSTed :param bytes nonce: :rtype: `josepy.JWS` r)indentrzJWS payload: %s)rfnoncerNr Zkidri) rkrZle_acme_versionZ json_dumpsencoderwrxrfr;rir ZJWSZsign)robjrrrjobjr6rrr _wrap_in_jwss    zClientNetwork._wrap_in_jwsc Cs"|jd}|r"|dd}z |}WntyDd}Yn0|jdkrbt|jd|j s|dur||j krt d|zt j|Wqtjy}zt||fWYd}~qd}~00n t|nD|dur||jkrt d|||jkr|durtd ||S) aCheck response content and its type. .. note:: Checking is not strict: wrong server response ``Content-Type`` HTTP header is ignored if response is an expected JSON object (c.f. Boulder #56). :param str content_type: Expected Content-Type response header. If JSON is expected and not present in server response, this function will raise an error. Otherwise, wrong Content-Type is ignored, but logged. :raises .messages.Error: If server response body carries HTTP Problem (draft-ietf-appsawg-http-problem-00). :raises .ClientError: In case of other networking errors. Content-Type;rNirz/Ignoring wrong Content-Type (%r) for JSON Errorz      & zClientNetwork._check_responsec OsB|dkrtd||dntd|||j|d<|di|dd|j|d|jz |jj||g|Ri|}Wnhtj j y}zLd }t |t |}|d ur|\} } } } td | | | WYd }~n d }~00|jd tkr t|j} n |jd } td|jddd|jD| |S)aSend HTTP request. Makes sure that `verify_ssl` is respected. Logs request and response (with headers). For allowed parameters please see `requests.request`. :param str method: method for the new `requests.Request` object :param str url: URL for the new `requests.Request` object :raises requests.exceptions.RequestException: in case of any problems :returns: HTTP Response :rtype: `requests.Response` POSTzSending POST request to %s: %sdatazSending %s request to %s.Zverifyr%z User-AgentrzT.*host='(\S*)'.*Max retries exceeded with url\: (\/\w*).*(\[Errno \d+\])([A-Za-z ]*)NzRequesting {0}{1}:{2}rzutf-8z!Received response: HTTP %d %s %s css|]\}}d||VqdS)z{0}: {1}N)r)rkvrrrr~sz.ClientNetwork._send_request..)rwrxrgr0rrrZrequestr exceptionsZRequestExceptionrematchrOgroupsrQrr%r&rbase64Z b64encoderrr\joinitems)rmethodrr5r6r(eZ err_regexmZhostpathZ_err_noerr_msgZ debug_contentrrr _send_requestCs:   (  zClientNetwork._send_requestcOs|jdg|Ri|S)aSend HEAD request without checking the response. Note, that `_check_response` is not called, as it is expected that status code other than successfully 2xx will be returned, or messages2.Error will be raised by the server. ZHEAD)r!r4rrrheadszClientNetwork.headcKs|j|jd|fi||dS)z$Send GET request and check response.ZGETr)rr!)rrrr6rrrr&szClientNetwork.getc Cs|j|jvr||j|j}ztjjd|}Wn2tjy`}zt ||WYd}~n d}~00t d||j |n t|dS)NrzStoring nonce: %s)REPLAY_NONCE_HEADERr%r ZHeader_fieldsrrr rZBadNoncerwrxrrZ MissingNonce)rr(rZ decoded_noncerrrr _add_nonces  " zClientNetwork._add_noncecCsL|jsBtd|dur$||}n|j||dd}|||jS)NzRequesting fresh noncer#)rrwrxr"rr&pop)rrr/r(rrr _get_nonces   zClientNetwork._get_noncec Osrz|j|i|WStjyl}z@|jdkrVtd||j|i|WYd}~SWYd}~n d}~00dS)zPOST object wrapped in `.JWS` and check response. If the server responded with a badNonce error, the request will be retried once. ZbadNoncez Retrying request after error: %sN) _post_oncer rcoderwrx)rr5r6rrrrr3s  zClientNetwork.postrhc Ksh|dd}|||||||}|dd|i|jd|fd|i|}|j||d}|||S)Nr/r%rrrr#)r'rr(r0r!rr&) rrrrrr6r/rr(rrrr)s  zClientNetwork._post_once)N)r`rarbrcrZJOSE_CONTENT_TYPEr r$rrDEFAULT_NETWORK_TIMEOUTrrrrdrr!r"r&r&r(r3r)rrrrrjs,  :@   rj)7rcrrrRZ email.utilsrrZloggingrsysrZjosepyrrrZrequests.adaptersrZrequests.utilsrZ!requests_toolbelt.adapters.sourcerrlZ six.movesrZacmerrr r Zacme.magic_typingr r r rZ acme.mixinsrZ getLoggerr`rw version_infoZpackagesZurllib3ZcontribZ pyopensslZinject_into_urllib3AttributeErrorZurllib3.contrib.pyopensslr+robjectrrerrrjrrrrsZ                :Yk