HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/acme/__pycache__/client.cpython-38.pyc
U

[^��@s�dZddlZddlZddlZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddl
Z
ddlZddlmZddlmZddlZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZe� e!�Z"e	j#dk�rJzej$j%j&j'�(�Wn*e)k
�rHddl*Z%e%j&j'�(�YnXdZ+dZ,Gdd�de-�Z.Gdd�de.�Z/Gdd�de.�Z0Gdd�de-�Z1Gdd�de-�Z2dS)zACME client API.�N)�parsedate_tz)�HTTPAdapter)�SourceAddressAdapter)�http_client)�crypto_util)�errors)�jws)�messages)�Dict)�List)�Set)�Text)���	�-zapplication/pkix-certc@sveZdZdZdd�Zeddd��Zdd�Zd	d
�Zddd�Z	d
d�Z
dd�Zddd�Zdd�Z
edd��Zdd�ZdS)�
ClientBasez�ACME client base object.

    :ivar messages.Directory directory:
    :ivar .ClientNetwork net: Client network.
    :ivar int acme_version: ACME protocol version. 1 or 2.
    cCs||_||_||_dS)z�Initialize.

        :param .messages.Directory directory: Directory Resource
        :param .ClientNetwork net: Client network.
        :param int acme_version: ACME protocol version. 1 or 2.
        N��	directory�net�acme_version)�selfrrr�r�-/usr/lib/python3/dist-packages/acme/client.py�__init__6szClientBase.__init__NcCs>d|jkr|jdd}tjtj�|���|j�d|�|d�S)Nzterms-of-service�url�Location)�body�uri�terms_of_service)�linksr	ZRegistrationResourceZRegistration�	from_json�json�headers�get)�cls�responserrrrr�_regr_from_responseAs
�zClientBase._regr_from_responsecCs"|�|j|�}|j||j|jd�S)N�rr)�_postrr'r)r�regrrr&rrr�_send_recv_regrKs�zClientBase._send_recv_regrcOs<|�d|j�t|jd�r.|�dt|jd��|jj||�S)zBWrapper around self.net.post that adds the acme_version.

        r�newNonce�
new_nonce_url)�
setdefaultr�hasattrr�getattrr�post�r�args�kwargsrrrr)XszClientBase._postcCs<|dkr|jn|}tjft|��}|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`

        N�r)rr	�UpdateRegistration�dictr+r�account)rr*�updaterZupdated_regrrrr�update_registrationas
zClientBase.update_registrationcCs|j|ddid�S)z�Deactivate 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*rrr�deactivate_registrationrs
z"ClientBase.deactivate_registrationcCs.tjdd�}|�|j|�}|�||jj|j�S)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)r�authzrrr&rrr�deactivate_authorization~s�z#ClientBase.deactivate_authorizationcCsFtjtj�|���|j�d|�d�}|dk	rB|jj|krBt	�
|��|S)Nr)rr)r	ZAuthorizationResourceZ
Authorizationr!r"r#r$rrAr�UnexpectedUpdate)rr&rArrBrrrr@�s�
z ClientBase._authzr_from_responsecCsv|�|j|�}z|jdd}Wntk
r>t�d��YnXtj|tj�	|�
��d�}|j|jkrrt�|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)rr �KeyErrorr�ClientErrorr	ZChallengeResourceZ
ChallengeBodyr!r"rD)rZchallbr&rFZchallrrrr�answer_challenge�s�zClientBase.answer_challengecCs�|j�dt|��}zt|�}Wnxtk
r�t|�}|dk	r�z6t�|drT|dnd�}tj|dd��|WYSttfk
r�YnX|}YnXtj�	�tj|d�S)a�Compute 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`

        zRetry-AfterN���rr��seconds)
r#r$�str�int�
ValueErrorr�datetime�	timedelta�
OverflowError�now)r%r&�default�retry_afterrL�whenZtz_secsrrrrU�s
zClientBase.retry_aftercCs0|�|tj||d��}|jtjkr,t�d��dS)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.

        )�certificate�reasonz0Successful revocation must return HTTP OK statusN)r)r	�
Revocation�status_coderZOKrrH)r�cert�rsnrr&rrr�_revoke�s
���zClientBase._revoke)NN)N)NN)�__name__�
__module__�__qualname__�__doc__r�classmethodr'r+r)r;r?rCr@rIrUr]rrrrr/s	
	


rcs�eZdZdZejddf�fdd�	Zd"dd�Zdd	�Zd
d�Z	d#dd
�Z
d$dd�Zdd�Zdd�Z
d%dd�Zdd�Zdd�Zdd�Zd&dd�Zd d!�Z�ZS)'�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||_|dkrt|||d�}t|tj�r>tj�|�|��	��}t
t|�j||dd�dS)z�Initialize.

        :param directory: Directory Resource (`.messages.Directory`) or
            URI from which the resource will be downloaded.

        N)�alg�
verify_ssl�r)
�key�
ClientNetwork�
isinstance�sixZstring_typesr	�	Directoryr!r$r"�superrcr)rrrgrdrer��	__class__rrr�s��zClient.__init__cCs@|dkrt��n|}|�|j||�}|jtjks6t�|�|�S)z�Register.

        :param .NewRegistration new_reg:

        :returns: Registration Resource.
        :rtype: `.RegistrationResource`

        N)	r	ZNewRegistrationr)rrZr�CREATED�AssertionErrorr')rZnew_regr&rrr�registers	zClient.registercCs|�|t���S)��Query server about registration.

        :param messages.RegistrationResource: Existing Registration
            Resource.

        )r+r	r7r>rrr�query_registrationszClient.query_registrationcCs|�|j|jj|jd�d��S)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	agreementr6)r;r:rrr>rrr�agree_to_tos%s�zClient.agree_to_toscCs`|dk	rt�d�|j�d�r(t�d��tj|d�}|�|j	j
|�}|jtj
ksTt�|�||�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.)rA)�logger�debug�value�
startswithrZWildcardUnsupportedErrorr	ZNewAuthorizationr)r�	new_authzrZrrorpr@)rrA�new_authzr_urirzr&rrr�request_challenges4s
�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

        ��typrx)r|r	�
Identifier�IDENTIFIER_FQDN)r�domainr{rrr�request_domain_challengesNs��z Client.request_domain_challengesc
Cs�|std��t�d�tj|d�}t}|j|jj||d|id�}|j	�
di��
d�}z|jd}Wntk
r�t
�d	��YnXtj|||t�tj�tjj|j��d
�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...��csr�Accept)�content_typer#rErrz"Location" Header missing)r�authzrs�cert_chain_urir)rprvrwr	�CertificateRequest�DER_CONTENT_TYPEr)rZnew_certr r$r#rGrrHZCertificateResource�jose�ComparableX509�OpenSSL�crypto�load_certificate�
FILETYPE_ASN1�content)rr�r�Zreqr�r&r�rrrr�request_issuancebs0
�
��zClient.request_issuancecCs*|j�|j�}|�||jj|j�}||fS�aPoll Authorization Resource for status.

        :param authzr: Authorization Resource
        :type authzr: `.AuthorizationResource`

        :returns: Updated Authorization Resource and HTTP response.

        :rtype: (`.AuthorizationResource`, `requests.Response`)

        )rr$rr@rrA�rrBr&�updated_authzrrrr�poll�s�zClient.poll��
csX|dkst�t�t�}t�}dd�t|�D�}t�|�tdd�|D���|�rt�	|�\}}	}
t
j
��}||kr�||j}t
�d|�t�|�|��|
�\}
}|
�|
<||
d7<|
jjtjtjfkrJ||
|kr�t�||j||d�|	|
f�qJ|�|
�qJ|�s&td	d�t���D���r2t�|���t�fd
d�|D��}|� ||�|fS)a�Poll 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��||f�qSr)rPrS)�.0�indexrBrrr�
<listcomp>�s�z4Client.poll_and_request_issuance.<locals>.<listcomp>css|]}||fVqdS�Nr�r�rBrrr�	<genexpr>�sz3Client.poll_and_request_issuance.<locals>.<genexpr>zSleeping for %d secondsrf)rTcss|]}|jjtjkVqdSr�)rr<r	�STATUS_INVALIDr�rrrr��s�c3s|]}�|VqdSr�rr���updatedrrr��s)!rp�collections�defaultdictrN�set�	enumerate�heapq�heapifyr8�heappoprPrSrLrvrw�time�sleepr�rr<r	�STATUS_VALIDr��heappushrU�add�anyrjZ
itervaluesrZ	PollError�tupler�)rr�r�ZmintimeZmax_attemptsZattemptsZ	exhaustedZwaitingrVr�rBrSrLr�r&Zupdated_authzrsrr�r�poll_and_request_issuance�sJ
�



�
���
z Client.poll_and_request_issuancecCs8t}|jj|d|i|d�}|t�tj�tjj|j	��fS)z�Returns certificate from URI.

        :param str uri: URI of certificate

        :returns: tuple of the form
            (response, :class:`josepy.util.ComparableX509`)
        :rtype: tuple

        r�)r#r�)
r�rr$r�r�r�r�r�r�r�)rrr�r&rrr�	_get_cert�s
��zClient._get_certcCsL|�|j�\}}d|jkr$t�d��|jd|jkr@t�|j��|j|d�S)z�Check for new cert.

        :param certr: Certificate Resource
        :type certr: `.CertificateResource`

        :returns: Updated Certificate Resource.
        :rtype: `.CertificateResource`

        rzLocation header missingr6)r�rr#rrHrD�textr:)r�certrr&r[rrr�
check_cert�s

zClient.check_certcCs
|�|�S)z�Refresh certificate.

        :param certr: Certificate Resource
        :type certr: `.CertificateResource`

        :returns: Updated Certificate Resource.
        :rtype: `.CertificateResource`

        )r�)rr�rrr�refreshs
zClient.refreshcCshg}|j}|dk	rLt|�|krL|�|�\}}|j�di��d�}|�|�q
|dk	rdt�d�|���|S)a�Fetch 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`

        NrErz'Recursion limit reached. Didn't get {0})	r��lenr�r r$�appendr�Error�format)rr�Z
max_length�chainrr&r[rrr�fetch_chains�zClient.fetch_chaincCs|�|||jtj�S��Revoke 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	rY�rr[r\rrr�revoke1sz
Client.revoke)N)N)N)r�r�)r�)r^r_r`rar��RS256rrqrsrtr|r�r�r�r�r�r�r�r�r��
__classcell__rrrmrrc�s&�
	

%�
K
rccs�eZdZdZ�fdd�Zdd�Zdd�Zd�fd	d
�	Zdd�Zd
d�Z	dd�Z
ddd�Zdd�Zdd�Z
dd�Zdd�Zdd�Z�ZS)�ClientV2zuACME client for a v2 API.

    :ivar messages.Directory directory:
    :ivar .ClientNetwork net: Client network.
    cstt|�j||dd�dS)z�Initialize.

        :param .messages.Directory directory: Directory Resource
        :param .ClientNetwork net: Client network.
        rrN)rlr�r)rrrrmrrrFs�zClientV2.__init__cCsN|�|jd|�}|jdkr8d|jkr8t�|j�d���|�|�}||j_	|S)z�Register.

        :param .NewRegistration new_account:

        :raises .ConflictError: in case the account already exists

        :returns: Registration Resource.
        :rtype: `.RegistrationResource`
        �
newAccount��r)
r)rrZr#r�
ConflictErrorr$r'rr9)r�new_accountr&r*rrrr�Os

zClientV2.new_accountcCs6||j_|�|jd�}|j||j|jd�|j_|jjS)rrNr()rr9r)rr'r)rr*r&rrrrsbs
�
zClientV2.query_registrationNcs|�|�}tt|��||�S)r5)�_get_v2_accountrlr�r;)rr*r:�new_regrrmrrr;qs
zClientV2.update_registrationcCsJd|j_|jjdd�}|�|jd|�}|jd}|j|d�}||j_|S)NT)Zonly_return_existingr�r�r)rr9rr:r)rr#)rr*Zonly_existing_regr&Zupdated_urir�rrrr��s
zClientV2._get_v2_accountcCs�tj�tjj|�}t�|�}g}|D]}|�tjtj	|d��q$tj
|d�}|�|jd|�}tj
�|���}g}	|jD]}
|	�|j|�|
�|
d��qxtj||j�d�|	|d�S)z�Request a new Order object from the server.

        :param str csr_pem: A CSR in PEM format.

        :returns: The newly created order.
        :rtype: OrderResource
        r})�identifiersZnewOrderr�r)rr�authorizations�csr_pem)r�r��load_certificate_request�FILETYPE_PEMr� _pyopenssl_cert_or_req_all_namesr�r	rr�ZNewOrderr)r�Orderr!r"r�r@�_post_as_get�
OrderResourcer#r$)rr�r��dnsNamesr��name�orderr&rr�rrrr�	new_order�s&
�


�zClientV2.new_ordercCs(|�|j�}|�||jj|j�}||fSr�)r�rr@rrAr�rrrr��s�z
ClientV2.pollcCs6|dkrtj��tjdd�}|�||�}|�||�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

        N�ZrK)rPrSrQ�poll_authorizations�finalize_order)r�orderr�deadlinerrr�poll_and_finalize�s
zClientV2.poll_and_finalizecCs�g}|jjD]L}tj��|kr|j|�|�|d�}|jjtjkrL|�	|�qt
�d�qqt|�t|jj�krvt
���g}|D]4}|jjtjkr~|jjD]}|jdk	r�|�	|�q�q~|r�t
�|��|j|d�S)zPoll Order Resource for status.r�rfN)r�)rr�rPrSr@r�r<r	ZSTATUS_PENDINGr�r�r�r�r�TimeoutErrorr�Z
challenges�errorZValidationErrorr:)rr�r�Z	responsesrrBZfailedZchallrrrr��s&


zClientV2.poll_authorizationscCs�tj�tjj|j�}tjt�|�d�}|�	|j
j|�tj�
�|kr�t�d�|�|j�}tj�|���}|jdk	r�t�|j��|jdk	r6|�|j�j}|j||d�Sq6t���dS)�Finalize an order and obtain a certificate.

        :param messages.OrderResource orderr: order to finalize
        :param datetime.datetime deadline: when to stop polling and timeout

        :returns: finalized order
        :rtype: messages.OrderResource

        r�rfN)r�
fullchain_pem)r�r�r�r�r�r	r�r�r�r)r�finalizerPrSr�r�r�rr�r!r"r�rZ
IssuanceErrorrWr�r:r�)rr�r�r�Zwrapped_csrr&rZcertificate_responserrrr��s 
�


zClientV2.finalize_ordercCs|�|||jd�S)r�Z
revokeCert)r]rr�rrrr��szClientV2.revokecCst|jd�o|jjjS)zGChecks if ACME server requires External Account Binding authentication.�meta)r/rr��external_account_required�rrrrr�sz"ClientV2.external_account_requiredcOs(|dd�d|dd�}|j||�S)z
        Send GET request using the POST-as-GET protocol.
        :param args:
        :param kwargs:
        :return:
        Nrfr�)r))rr3r4Znew_argsrrrr�	szClientV2._post_as_get)N)N)r^r_r`rarr�rsr;r�r�r�r�r�r�r�r�r�r�rrrmrr�?s		

r�c@sReZdZdZdd�Zdd�Zddd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�BackwardsCompatibleClientV2a�ACME 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)Nrf)rgr)r)
r	rkr!r$r"�_acme_version_from_directoryrrc�clientr�)rrrgZserverrrrrr's

z$BackwardsCompatibleClientV2.__init__cCst|j|�Sr�)r0r�)rr�rrr�__getattr__/sz'BackwardsCompatibleClientV2.__getattr__Ncs��fdd�}|jdkrF|j�|�}|jdk	rB||j�|j�|�S|Sd|jjjkrp||jjjj�|jdd�}|j�|�SdS)z�Combined 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
        cs�dk	r�|�dSr�r)Ztos��check_tos_cbrr�_assess_tos9szDBackwardsCompatibleClientV2.new_account_and_tos.<locals>._assess_tosrfNrT)Zterms_of_service_agreed)	rr�rqrrtrr�r:r�)rr*r�r�rr�r�new_account_and_tos2s


z/BackwardsCompatibleClientV2.new_account_and_toscCs`|jdkrTtj�tjj|�}t�|�}g}|D]}|�|j�	|��q.t
j||d�S|j�|�S)a�Request 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

        rf)r�r�)
rr�r�r�r�rr�r�r�r�r	r�r�)rr�r�r�r�r�rrrr�Hs

z%BackwardsCompatibleClientV2.new_ordercCs�|jdkr�|j}|j�t�tj�tjj	|��|j
�}d}tj��|kr~z|j�
|�}Wq~Wq8tjk
rzt�d�Yq8Xq8|dkr�t�d��tj�tjj	|jj���}t�|���}|j||d�S|j�||�S)r�rfNzoFailed to fetch chain. You should not deploy the generated certificate, please rerun the command for a new one.)r�)rr�r�r�r�r�r�r�r�r�r�rPrSr�rr�r�r�r�Zdump_certificater�wrapped�decoderZdump_pyopenssl_chainr:r�)rr�r�r�r�r�r[rrrr�as4

����z*BackwardsCompatibleClientV2.finalize_ordercCs|j�||�Sr�)r�r�r�rrrr��sz"BackwardsCompatibleClientV2.revokecCst|d�rdSdS)Nr,rrf)r/)rrrrrr��s
z8BackwardsCompatibleClientV2._acme_version_from_directorycCs|jdkrdS|j��S)z�Checks if the server requires an external account for ACMEv2 servers.

        Always return False for ACMEv1 servers, as it doesn't use External Account Binding.rfF)rr�r�r�rrrr��s
z5BackwardsCompatibleClientV2.external_account_required)N)r^r_r`rarr�r�r�r�r�r�r�rrrrr�s
%
r�c@s�eZdZdZdZdZdZdZdej	dde
dfd	d
�Zdd�Zd
d�Z
ed dd��Zdd�Zdd�Zefdd�Zdd�Zdd�Zdd�Zedfdd�ZdS)!rhzvWrapper around requests that signs POSTs for authentication.

    Also adds user agent, and handles Content-Type.
    zapplication/jsonzapplication/jose+jsonzapplication/problem+jsonzReplay-NonceNTzacme-pythonc	Csl||_||_||_||_t�|_||_t��|_	||_
t�}|dk	rLt|�}|j	�
d|�|j	�
d|�dS)Nzhttp://zhttps://)rgr9rdrer��_nonces�
user_agent�requestsZSession�session�_default_timeoutrrZmount)	rrgr9rdrer��timeoutZsource_addressZadapterrrrr�s
zClientNetwork.__init__cCs(z|j��Wntk
r"YnXdSr�)r��close�	Exceptionr�rrr�__del__�szClientNetwork.__del__cCsz|r|jdd���nd}t�d|�|j|d�}|dkrX||d<|jdk	rX|jd|d	<|j|d
<tjj	|f|�jdd�S)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)�indent�zJWS payload:
%s)rd�noncerNrZkidrg)
Z
json_dumps�encodervrwrdr9rgrZJWSZsign)r�objr�rr�jobjr4rrr�_wrap_in_jws�s�

zClientNetwork._wrap_in_jwsc
Cs|j�d�}z|��}Wntk
r0d}YnX|jdkrNt�|j�d���|js�|dk	r�||jkrrt	�
d|�ztj�
|��Wq�tjk
r�}zt�||f��W5d}~XYq�Xn
t�|��nD|dk	r�||jkr�t	�
d|�||jk�r|dk�rt�d�|���|S)a�Check 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-TypeNi�rz/Ignoring wrong Content-Type (%r) for JSON Errorz<Ignoring wrong Content-Type (%r) for JSON decodable responsez%Unexpected response Content-Type: {0})r#r$r"rOrZrr��ok�JSON_ERROR_CONTENT_TYPErvrwr	r�r!r��DeserializationErrorrH�JSON_CONTENT_TYPEr�)r%r&r�Zresponse_ctr�r�rrr�_check_response�s:


�"��zClientNetwork._check_responsec
Os:|dkrt�d||d�nt�d||�|j|d<|�di�|d�d|j�|�d|j�z|jj||f|�|�}Wnftj	j
k
r�}zDd	}t�|t
|��}|d
kr��|��\}	}
}}td�|	|
|���W5d
}~XYnX|j�d�tk�rt�|j�}
n|j�d
�}
t�d|jd�dd�|j��D��|
�|S)a�Send 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:
%s�datazSending %s request to %s.Zverifyr#z
User-Agentr�zT.*host='(\S*)'.*Max retries exceeded with url\: (\/\w*).*(\[Errno \d+\])([A-Za-z ]*)NzRequesting {0}{1}:{2}r�zutf-8z!Received response:
HTTP %d
%s

%s�
cSsg|]\}}d�||��qS)z{0}: {1})r�)r��k�vrrrr�`s�z/ClientNetwork._send_request.<locals>.<listcomp>)rvrwrer.r�r�r�Zrequestr��
exceptionsZRequestException�re�matchrM�groupsrOr�r#r$r��base64Z	b64encoder�r�rZ�join�items)r�methodrr3r4r&�eZ	err_regex�mZhost�pathZ_err_no�err_msgZ
debug_contentrrr�
_send_request%s<�
$
��zClientNetwork._send_requestcOs|jd|�|�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.

        �HEAD)r)rr2rrr�headeszClientNetwork.headcKs|j|jd|f|�|d�S)z$Send GET request and check response.ZGET�r�)rr)rrr�r4rrrr$os�zClientNetwork.getc
Cs�|j|jkrz|j|j}ztjjd�|�}Wn0tjk
r^}zt�	||��W5d}~XYnXt
�d|�|j�
|�n
t�|��dS)Nr�zStoring nonce: %s)�REPLAY_NONCE_HEADERr#rZHeader�_fieldsr�r�rrZBadNoncervrwr�r�ZMissingNonce)rr&r�Z
decoded_noncer�rrr�
_add_noncetszClientNetwork._add_noncecCsL|jsBt�d�|dkr$|�|�}n|j|�|�dd�}|�|�|j��S)NzRequesting fresh noncer)r�rvrwrrr�pop)rrr-r&rrr�
_get_nonce�s

zClientNetwork._get_noncec
Osdz|j||�WStjk
r^}z0|jdkrLt�d|�|j||�WY�S�W5d}~XYnXdS)z�POST 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	r��codervrw)rr3r4r�rrrr1�s
zClientNetwork.postrfc	Ksh|�dd�}|�||�||�||�}|�dd|i�|jd|fd|i|��}|j||d�}|�|�|S)Nr-r#r�rrr)rr�rr.rrr)	rrr�r�rr4r-rr&rrrr�s
zClientNetwork._post_once)N)r^r_r`rarZJOSE_CONTENT_TYPErrr�r��DEFAULT_NETWORK_TIMEOUTrr�r�rbrrrr$rrr1rrrrrrh�s.�
7@
�rh)3rarr�rPZemail.utilsrr�Zloggingr�sysr�Zjosepyr�r�r�Zrequests.adaptersrZ!requests_toolbelt.adapters.sourcerrjZ	six.movesrZacmerrrr	Zacme.magic_typingr
rrr
Z	getLoggerr^rv�version_infoZpackagesZurllib3ZcontribZ	pyopensslZinject_into_urllib3�AttributeErrorZurllib3.contrib.pyopensslr!r��objectrrcr�r�rhrrrr�<module>sV
:YV