Spade
Mini Shell
| Directory:~$ /proc/self/root/usr/lib/python2.7/site-packages/acme/ |
| [Home] [System Details] [Kill Me] |
�
���_c@shdZddlZddlZddlZddlmZddlZddlZddlZddl Z ddl
Z
ddlZddl
Z
ddlZddlmZddlmZddlmZddlZddlmZddlmZdd lmZdd
lmZddlmZddlmZdd
lmZddlm Z
ddlm!Z!ddl"m#Z#ej$e%�Z&e j'dddfkr�yej(j)j*j+j,�Wn-e-k
r�ddl.Z)e)j*j+j,�nXndZ/dZ0de1fd��YZ2de2fd��YZ3de2fd��YZ4de1fd��YZ5de1fd��YZ6dS(
sACME client
API.i����N(tparsedate_tz(tHTTPAdapter(tparse_header_links(tSourceAddressAdapter(thttp_client(tcrypto_util(terrors(tjws(tmessages(tDict(tList(tSet(tText(tVersionedLEACMEMixiniii i-sapplication/pkix-certt
ClientBasecBs�eZdZd�Zeddd��Zd�Zd�Zdd�Z d�Z
d�Zddd�Zd �Z
ed
��Zd�ZRS(
s�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(s�Initialize.
:param .messages.Directory directory: Directory Resource
:param .ClientNetwork net: Client network.
:param int acme_version: ACME protocol version. 1 or 2.
N(t directorytnettacme_version(tselfRRR((s//usr/lib/python2.7/site-packages/acme/client.pyt__init__8s cCs`d|jkr#|jdd}ntjdtjj|j��d|jjd|�d|�S(Nsterms-of-serviceturltbodyturitLocationtterms_of_service(tlinksRtRegistrationResourcetRegistrationt from_jsontjsontheaderstget(tclstresponseRR((s//usr/lib/python2.7/site-packages/acme/client.pyt_regr_from_responseCs cCs4|j|j|�}|j|d|jd|j�S(NRR(t_postRR"R(RtregrRR!((s//usr/lib/python2.7/site-packages/acme/client.pyt_send_recv_regrMscOsW|jd|j�t|jd�rD|jdt|jd��n|jj||�S(sBWrapper
around self.net.post that adds the acme_version.
RtnewNoncet
new_nonce_url(t
setdefaultRthasattrRtgetattrRtpost(Rtargstkwargs((s//usr/lib/python2.7/site-packages/acme/client.pyR#ZscCsU|dkr|jn|}tjt|��}|j|d|�}||j_|S(sKUpdate
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`
RN(tNoneRRtUpdateRegistrationtdictR%Rtaccount(RR$tupdateRtupdated_regr((s//usr/lib/python2.7/site-packages/acme/client.pytupdate_registrationcs
cCs|j|didd6�S(s�Deactivate registration.
:param messages.RegistrationResource regr: The Registration
Resource
to be deactivated.
:returns: The Registration resource that was deactivated.
:rtype: `.RegistrationResource`
R2tdeactivatedtstatus(R4(RR$((s//usr/lib/python2.7/site-packages/acme/client.pytdeactivate_registrationts
cCsCtjdd�}|j|j|�}|j||jj|j�S(sDeactivate
authorization.
:param messages.AuthorizationResource authzr: The Authorization
resource
to be deactivated.
:returns: The Authorization resource that was deactivated.
:rtype: `.AuthorizationResource`
R6R5(RtUpdateAuthorizationR#Rt_authzr_from_responseRt
identifier(RtauthzrRR!((s//usr/lib/python2.7/site-packages/acme/client.pytdeactivate_authorization�s cCsmtjdtjj|j��d|jjd|��}|dk ri|jj |krit
j|��n|S(NRRR(RtAuthorizationResourcet
AuthorizationRRRRR.RR:RtUnexpectedUpdate(RR!R:RR;((s//usr/lib/python2.7/site-packages/acme/client.pyR9�s cCs�|j|j|�}y|jdd}Wn
tk
rLtjd��nXtjd|dtjj |j
���}|j|jkr�tj|j��n|S(shAnswer 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:
tupRs"up" Link header missingt
authzr_uriR(R#RRtKeyErrorRtClientErrorRtChallengeResourcet
ChallengeBodyRRR?(RtchallbR!RAtchallr((s//usr/lib/python2.7/site-packages/acme/client.pytanswer_challenge�s
cCs�|jjdt|��}yt|�}Wn�tk
r�t|�}|dk r�yBtj|ddk rv|dnd�}tj|d
�|SWq�tt fk
r�q�Xn|}nXtjj
�tjd|�S(s�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`
sRetry-Afteri����iitsecondsN(RRtstrtintt
ValueErrorRR.tdatetimet timedeltat
OverflowErrortnow(R
R!tdefaulttretry_afterRItwhenttz_secs((s//usr/lib/python2.7/site-packages/acme/client.pyRR�s
)
cCsL|j|tjd|d|��}|jtjkrHtjd��ndS(s.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.
tcertificatetreasons0Successful revocation must return HTTP OK
statusN(R#Rt
Revocationtstatus_codeRtOKRRC(RtcerttrsnRR!((s//usr/lib/python2.7/site-packages/acme/client.pyt_revoke�s
N(t__name__t
__module__t__doc__RtclassmethodR.R"R%R#R4R7R<R9RHRRR\(((s//usr/lib/python2.7/site-packages/acme/client.pyR1s
tClientcBs�eZdZejedd�Zdd�Zd�Z d�Z
dd�Zdd�Zd�Z
d�Zd d
d�Zd�Zd
�Zd�Zd
d�Zd�ZRS(sACME 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`.
cCs�||_|dkr0t|d|d|�}nt|tj�rftjj|j |�j
��}ntt|�j
d|d|dd�dS(s�Initialize.
:param directory: Directory Resource (`.messages.Directory`) or
URI from which the resource will be downloaded.
talgt
verify_sslRRRiN(tkeyR.t
ClientNetworkt
isinstancetsixtstring_typesRt DirectoryRRRtsuperRaR(RRRdRbRcR((s//usr/lib/python2.7/site-packages/acme/client.pyR�s cCsD|dkrtj�n|}|j|j||�}|j|�S(s�Register.
:param .NewRegistration new_reg:
:returns: Registration Resource.
:rtype: `.RegistrationResource`
N(R.RtNewRegistrationR#RR"(Rtnew_regR!((s//usr/lib/python2.7/site-packages/acme/client.pytregister
s cCs|j|tj��S(s�Query
server about registration.
:param messages.RegistrationResource: Existing Registration
Resource.
(R%RR/(RR$((s//usr/lib/python2.7/site-packages/acme/client.pytquery_registrationscCs+|j|jd|jjd|j���S(sAgree
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`
Rt agreement(R4R2RR(RR$((s//usr/lib/python2.7/site-packages/acme/client.pytagree_to_tos'scCsz|dk rtjd�n|jjd�r@tjd��ntjd|�}|j |j
j|�}|j||�S(sGRequest 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
s2request_challenges with new_authzr_uri deprecated.t*sbRequesting
an authorization for a wildcard name is forbidden by this version of the
ACME protocol.R:N(
R.tloggertdebugtvaluet
startswithRtWildcardUnsupportedErrorRtNewAuthorizationR#Rt new_authzR9(RR:tnew_authzr_uriRxR!((s//usr/lib/python2.7/site-packages/acme/client.pytrequest_challenges6scCs%|jtjdtjd|�|�S(s"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
ttypRt(RzRt
IdentifiertIDENTIFIER_FQDN(RtdomainRy((s//usr/lib/python2.7/site-packages/acme/client.pytrequest_domain_challengesPscCs�tjd�tjd|�}t}|j|jj|d|di|d6�}|jj di�j d�}y|j
d}Wn tk
r�tj
d ��nXtjd
|d|d|d
tjtjjtjj|j���S(sRequest issuance.
:param csr: CSR
:type csr: `OpenSSL.crypto.X509Req` wrapped in `.ComparableX509`
:param authzrs: `list` of `.AuthorizationResource`
:returns: Issued certificate
:rtype: `.messages.CertificateResource`
sRequesting
issuance...tcsrtcontent_typeRtAcceptR@RRs"Location" Header
missingRtauthzrstcert_chain_uriR(RrRsRtCertificateRequesttDER_CONTENT_TYPER#Rtnew_certRRRRBRRCtCertificateResourcetjosetComparableX509tOpenSSLtcryptotload_certificatet
FILETYPE_ASN1tcontent(RR�R�treqR�R!R�R((s//usr/lib/python2.7/site-packages/acme/client.pytrequest_issuanceds"
cCs=|jj|j�}|j||jj|j�}||fS(sPoll
Authorization Resource for status.
:param authzr: Authorization Resource
:type authzr: `.AuthorizationResource`
:returns: Updated Authorization Resource and HTTP response.
:rtype: (`.AuthorizationResource`, `requests.Response`)
(RRRR9RR:(RR;R!tupdated_authzr((s//usr/lib/python2.7/site-packages/acme/client.pytpoll�sii
cs�tjt�}t�}gt|�D]$\}}tjj�||f^q%} tj| �d�|D��x| rttj | �\}
}}tjj�}|
|kr�|
|j
}tjd|�t
j|�n|j�|�\}
}|
�|<||cd7<|
jjtjtjfkro|||kratj| |j|d|�||f�qq|j|�qoqoW|s�td�tj��D��r�tj|���nt�fd�|D��}|j||�|fS(s�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
cSsi|]}||�qS(((t.0R;((s//usr/lib/python2.7/site-packages/acme/client.pys
<dictcomp>�s sSleeping for %d
secondsiRQcss$|]}|jjtjkVqdS(N(RR6RtSTATUS_INVALID(R�R;((s//usr/lib/python2.7/site-packages/acme/client.pys <genexpr>�sc3s|]}�|VqdS(N((R�R;(tupdated(s//usr/lib/python2.7/site-packages/acme/client.pys <genexpr>�s(tcollectionstdefaultdictRKtsett enumerateRMRPtheapqtheapifytheappopRIRrRsttimetsleepR�RR6RtSTATUS_VALIDR�theappushRRtaddtanyRgt
itervaluesRt PollErrorttupleR�(RR�R�tmintimetmax_attemptstattemptst exhaustedtindexR;twaitingRSRPRIR�R!tupdated_authzrs((R�s//usr/lib/python2.7/site-packages/acme/client.pytpoll_and_request_issuance�s6 4
cCsVt}|jj|di|d6d|�}|tjtjjtjj|j ��fS(s�Returns
certificate from URI.
:param str uri: URI of certificate
:returns: tuple of the form
(response, :class:`josepy.util.ComparableX509`)
:rtype: tuple
RR�R�(
R�RRR�R�R�R�R�R�R�(RRR�R!((s//usr/lib/python2.7/site-packages/acme/client.pyt _get_cert�s
cCst|j|j�\}}d|jkr9tjd��n|jd|jkrdtj|j��n|jd|�S(s�Check
for new cert.
:param certr: Certificate Resource
:type certr: `.CertificateResource`
:returns: Updated Certificate Resource.
:rtype: `.CertificateResource`
RsLocation header
missingR(R�RRRRCR?ttextR2(RtcertrR!RZ((s//usr/lib/python2.7/site-packages/acme/client.pyt
check_cert�scCs
|j|�S(s�Refresh certificate.
:param certr: Certificate Resource
:type certr: `.CertificateResource`
:returns: Updated Certificate Resource.
:rtype: `.CertificateResource`
(R�(RR�((s//usr/lib/python2.7/site-packages/acme/client.pytrefreshs
cCs�g}|j}xb|dk rst|�|krs|j|�\}}|jjdi�jd�}|j|�qW|dk r�tjdj |���n|S(s�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`
R@Rs'Recursion limit reached. Didn't get {0}N(
R�R.tlenR�RRtappendRtErrortformat(RR�t
max_lengthtchainRR!RZ((s//usr/lib/python2.7/site-packages/acme/client.pytfetch_chains !cCs|j|||jtj�S(sRevoke
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\RRRW(RRZR[((s//usr/lib/python2.7/site-packages/acme/client.pytrevoke3sN(R]R^R_R�tRS256tTrueR.RRmRnRpRzRR�R�R�R�R�R�R�R�(((s//usr/lib/python2.7/site-packages/acme/client.pyRa�s
% J tClientV2cBs�eZdZd�Zd�Zd�Zdd�Zd�Zd�Z d�Z
dd�Zd �Ze
d
�Zd�Zd�Zd
�Zd�ZRS(suACME client for a v2 API.
:ivar messages.Directory directory:
:ivar .ClientNetwork net: Client network.
cCs)tt|�jd|d|dd�dS(s�Initialize.
:param .messages.Directory directory: Directory Resource
:param .ClientNetwork net: Client network.
RRRiN(RjR�R(RRR((s//usr/lib/python2.7/site-packages/acme/client.pyRHscCst|j|jd|�}|jdkrUd|jkrUtj|jjd���n|j|�}||j_ |S(s�Register.
:param .NewRegistration new_account:
:raises .ConflictError: in case the account already exists
:returns: Registration Resource.
:rtype: `.RegistrationResource`
t
newAccounti�R(
R#RRXRRt
ConflictErrorRR"RR1(Rtnew_accountR!R$((s//usr/lib/python2.7/site-packages/acme/client.pyR�Qs
cCsR||j_|j|jd�}|j|d|jd|j�|j_|jjS(s�Query
server about registration.
:param messages.RegistrationResource: Existing Registration
Resource.
RRN(RR1R#RR.R"R(RR$R!((s//usr/lib/python2.7/site-packages/acme/client.pyRnds
cCs(|j|�}tt|�j||�S(sKUpdate 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`
(t_get_v2_accountRjR�R4(RR$R2tnew_regr((s//usr/lib/python2.7/site-packages/acme/client.pyR4sscCsid|j_|jjdt�}|j|jd|�}|jd}|jd|�}||j_|S(Ntonly_return_existingR�RR( R.RR1RR2R�R#RR(RR$tonly_existing_regR!tupdated_uriR�((s//usr/lib/python2.7/site-packages/acme/client.pyR��s
c Cstjjtjj|�}tj|�}g}x0|D](}|jtjdtj d|��q7Wtj
d|�}|j|jd|�}tj
j|j��}g} x6|jD]+}
| j|j|j|
�d|
��q�Wtjd|d|jjd�d| d |�S(
s�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{RttidentifierstnewOrderRRRtauthorizationstcsr_pem(R�R�tload_certificate_requesttFILETYPE_PEMRt
_pyopenssl_cert_or_req_all_namesR�RR|R}tNewOrderR#RtOrderRRR�R9t_post_as_gett
OrderResourceRR(RR�R�tdnsNamesR�tnametorderR!RR�R((s//usr/lib/python2.7/site-packages/acme/client.pyt new_order�s"
) cCs:|j|j�}|j||jj|j�}||fS(sPoll
Authorization Resource for status.
:param authzr: Authorization Resource
:type authzr: `.AuthorizationResource`
:returns: Updated Authorization Resource and HTTP response.
:rtype: (`.AuthorizationResource`, `requests.Response`)
(R�RR9RR:(RR;R!R�((s//usr/lib/python2.7/site-packages/acme/client.pyR��scCsP|dkr.tjj�tjdd�}n|j||�}|j||�S(sdPoll
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
RIiZN(R.RMRPRNtpoll_authorizationstfinalize_order(Rtorderrtdeadline((s//usr/lib/python2.7/site-packages/acme/client.pytpoll_and_finalize�s
"cCsDg}x�|jjD]s}xjtjj�|kr�|j|j|�d|�}|jjtjkru|j |�Pnt
jd�qWqWt|�t|jj�kr�t
j��ng}x\|D]T}|jjtjkr�x6|jjD]%}|jdk r�|j |�q�q�Wq�q�W|r4t
j|��n|jd|�S(sPoll
Order Resource for
status.RiR�N(RR�RMRPR9R�R6RtSTATUS_PENDINGR�R�R�R�RtTimeoutErrorR�t
challengesterrorR.tValidationErrorR2(RR�R�t responsesRR;tfailedtchall((s//usr/lib/python2.7/site-packages/acme/client.pyR��s&
cCshtjjtjj|j�}tjdtj|��}|j |j
j|�xtjj
�|krWtjd�|j|j�}tjj|j��}|jdk r�tj|j��n|jdk rR|j|j�}|jd|d|j�}|rP|j|d�} g| D]}
|j|
�j^q}|jd|�}n|SqRWtj��dS(s{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
R�iRt
fullchain_pemt alternatetalternative_fullchains_pemN(R�R�R�R�R�RR�R�R�R#RtfinalizeRMRPR�R�R�RR�RRR�R.Rt
IssuanceErrorRUR2R�t
_get_linksR�(RR�R�tfetch_alternative_chainsR�twrapped_csrR!Rtcertificate_responsetalt_chains_urlsRt
alt_chains((s//usr/lib/python2.7/site-packages/acme/client.pyR��s&
%cCs|j|||jd�S(sRevoke
certificate.
:param .ComparableX509 cert: `OpenSSL.crypto.X509` wrapped in
`.ComparableX509`
:param int rsn: Reason code for certificate revocation.
:raises .ClientError: If revocation is unsuccessful.
t
revokeCert(R\R(RRZR[((s//usr/lib/python2.7/site-packages/acme/client.pyR�scCst|jd�o|jjjS(sGChecks
if ACME server requires External Account Binding
authentication.tmeta(R)RR�texternal_account_required(R((s//usr/lib/python2.7/site-packages/acme/client.pyR�scOs&|d
d|d}|j||�S(s
Send GET request using the POST-as-GET protocol.
:param args:
:param kwargs:
:return:
iN(N(R.R#(RR,R-tnew_args((s//usr/lib/python2.7/site-packages/acme/client.pyR�scCsid|jkrgSt|jd�}g|D]8}d|kr-d|kr-|d|kr-|d^q-S(s�
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.
tLinktrelR(RR(RR!t
relation_typeRtl((s//usr/lib/python2.7/site-packages/acme/client.pyR�s
N(R]R^R_RR�RnR.R4R�R�R�R�R�tFalseR�R�R�R�R�(((s//usr/lib/python2.7/site-packages/acme/client.pyR�As
tBackwardsCompatibleClientV2cBs\eZdZd�Zd�Zd d�Zd�Zed�Z d�Z
d�Zd�ZRS(
s�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
cCsytjj|j|�j��}|j|�|_|jdkr`t|d|d|�|_nt |d|�|_dS(NiRdR(
RRiRRRt_acme_version_from_directoryRRatclientR�(RRRdtserverR((s//usr/lib/python2.7/site-packages/acme/client.pyR>s
!cCst|j|�S(N(R*R�(RR�((s//usr/lib/python2.7/site-packages/acme/client.pyt__getattr__Fscs��fd�}|jdkr`|jj|�}|jdk r\||j�|jj|�S|Sd|jjjkr�||jjjj�|jdt �}n|jj
|�SdS(s�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�|�ndS(N(R.(ttos(tcheck_tos_cb(s//usr/lib/python2.7/site-packages/acme/client.pyt_assess_tosPsiRtterms_of_service_agreedN(RR�RmRR.RpRR�R2R�R�(RR$R�R�((R�s//usr/lib/python2.7/site-packages/acme/client.pytnew_account_and_tosIs
cCs�|jdkrtjjtjj|�}tj|�}g}x'|D]}|j|jj |��qFWt
jd|d|�S|jj|�S(s�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
iR�R�(
RR�R�R�R�RR�R�R�RRR�R�(RR�R�R�R�R~((s//usr/lib/python2.7/site-packages/acme/client.pyR�_s
cCs/|jdkr|j}|jjtjtjjtjj |��|j
�}d}xTtjj
�|kr�y|jj|�}PWqWtjk
r�tjd�qWXqWW|dkr�tjd��ntjjtjj |jj�j�}tj|�j�}|jd||�S|jj|||�S(s{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
isoFailed to fetch chain. You should not deploy the generated
certificate, please rerun the command for a new
one.R�N(RR�R�R�R�R�R�R�R�R�R�R.RMRPR�RR�R�R�R�tdump_certificateRtwrappedtdecodeRtdump_pyopenssl_chainR2R�(RR�R�R�R�R�R�RZ((s//usr/lib/python2.7/site-packages/acme/client.pyR�xs* cCs|jj||�S(sRevoke
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�R�(RRZR[((s//usr/lib/python2.7/site-packages/acme/client.pyR��scCst|d�rdSdS(NR&ii(R)(RR((s//usr/lib/python2.7/site-packages/acme/client.pyR��scCs
|jdkrtS|jj�S(s�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.i(RR�R�R�(R((s//usr/lib/python2.7/site-packages/acme/client.pyR��sN(
R]R^R_RR�R.RR�R�R�R�R�R�(((s//usr/lib/python2.7/site-packages/acme/client.pyR�+s '
RecBs�eZdZdZdZdZdZdej e
dedd�Zd�Z
d�Zedd ��Zd
�Zd�Zed�Zd
�Zd�Zd�Zedd�ZRS(svWrapper around
requests that signs POSTs for authentication.
Also adds user agent, and handles Content-Type.
sapplication/jsonsapplication/jose+jsonsapplication/problem+jsonsReplay-Noncesacme-pythonc Cs�||_||_||_||_t�|_||_tj�|_ ||_
t�}|dk rut
|�}n|j jd|�|j jd|�dS(Nshttp://shttps://(RdR1RbRcR�t_noncest
user_agenttrequeststSessiontsessiont_default_timeoutRR.Rtmount( RRdR1RbRcRttimeouttsource_addresstadapter((s//usr/lib/python2.7/site-packages/acme/client.pyR�s cCs)y|jj�Wntk
r$nXdS(N(R tcloset Exception(R((s//usr/lib/python2.7/site-packages/acme/client.pyt__del__�s
cCs�t|t�r||_n|r9|jdd�j�nd}tjd|�i|jd6|d6}|dkr�||d<|jdk r�|jd|d <q�n|j
|d
<tjj
||�jdd�S(s 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`
tindentitsJWS payload:
%sRbtnonceRRtkidRdN(RfR
tle_acme_versiont
json_dumpstencodeRrRsRbR1R.RdRtJWStsign(RtobjRRRtjobjR-((s//usr/lib/python2.7/site-packages/acme/client.pyt_wrap_in_jws�s$
cCs�|jjd�}|r4|jd�dj�}ny|j�}Wntk
r]d }nX|jdkr�tj |jjd���n|j
s|d k r ||jkr�tj
d|�nytjj|��Wqtjk
r}tj||f��qXqtj|��nd|d k rI||jkrItj
d|�n||jkr|d krtjdj|���n|S(
s�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.
sContent-Typet;ii�Rs/Ignoring wrong Content-Type (%r) for
JSON Errors<Ignoring wrong Content-Type (%r) for JSON decodable
responses%Unexpected response Content-Type:
{0}N(RRtsplittstripRRLR.RXRR�toktJSON_ERROR_CONTENT_TYPERrRsRR�RR�tDeserializationErrorRCtJSON_CONTENT_TYPER�(R
R!R�tresponse_ctRR�((s//usr/lib/python2.7/site-packages/acme/client.pyt_check_responses8
cOs�|dkr&tjd||d�ntjd||�|j|d<|jdi�|djd|j�|jd|j�y|jj||||�}Wn|tj j
k
r}d }tj|t
|��}|dkr��n|j�\} }
}}td
j| |
|���nX|jjd�tkrKtj|j�}
n|jjd�}
tjd
|jdjd�|jj�D��|
�|S(s�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`
tPOSTsSending POST request to %s:
%stdatasSending %s request to %s.tverifyRs
User-AgentRsT.*host='(\S*)'.*Max retries exceeded with url\:
(\/\w*).*(\[Errno \d+\])([A-Za-z ]*)sRequesting
{0}{1}:{2}sContent-Typesutf-8s!Received response:
HTTP %d
%s
%ss
css'|]\}}dj||�VqdS(s{0}:
{1}N(R�(R�tktv((s//usr/lib/python2.7/site-packages/acme/client.pys <genexpr>~sN(RrRsRcR(RR
R trequestRt
exceptionstRequestExceptiontretmatchRJR.tgroupsRLR�RRR�tbase64t b64encodeR�RRXtjointitems(RtmethodRR,R-R!tet err_regextmthosttpatht_err_noterr_msgt
debug_content((s//usr/lib/python2.7/site-packages/acme/client.pyt
_send_requestCs4
cOs|jd||�S(sSend
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.
tHEAD(R?(RR,R-((s//usr/lib/python2.7/site-packages/acme/client.pythead�scKs"|j|jd||�d|�S(s$Send
GET request and check
response.tGETR�(R&R?(RRR�R-((s//usr/lib/python2.7/site-packages/acme/client.pyR�scCs�|j|jkr�|j|j}ytjjdj|�}Wn(tjk
ri}tj ||��nXt
jd|�|jj
|�ntj|��dS(NRsStoring nonce:
%s(tREPLAY_NONCE_HEADERRRtHeadert_fieldsRR�R#RtBadNonceRrRsRR�tMissingNonce(RR!Rt
decoded_nonceR�((s//usr/lib/python2.7/site-packages/acme/client.pyt
_add_nonce�scCso|jsbtjd�|dkr4|j|�}n|j|j|�dd�}|j|�n|jj�S(NsRequesting
fresh
nonceR�(RRrRsR.RAR&RItpop(RRR'R!((s//usr/lib/python2.7/site-packages/acme/client.pyt
_get_nonce�s
cOscy|j||�SWnHtjk
r^}|jdkrXtjd|�|j||�S�nXdS(s�POST object wrapped
in `.JWS` and check response.
If the server responded with a badNonce error, the request will
be retried once.
tbadNonces Retrying request after error:
%sN(t
_post_onceRR�tcodeRrRs(RR,R-R�((s//usr/lib/python2.7/site-packages/acme/client.pyR+�sic Ks�|jdd�}|j||j||�||�}|jdi|d6�|jd|d||�}|j|d|�}|j|�|S(NR'RsContent-TypeR'R(R�(RJR.RRKR(R?R&RI( RRRR�RR-R'R(R!((s//usr/lib/python2.7/site-packages/acme/client.pyRM�s$
N(R]R^R_R$tJOSE_CONTENT_TYPER"RCR.R�R�R�tDEFAULT_NETWORK_TIMEOUTRRRR`R&R?RARRIRKR+RM(((s//usr/lib/python2.7/site-packages/acme/client.pyRe�s( : @
(7R_R2R�RMtemail.utilsRR�tloggingR/tsysR�tjosepyR�R�Rtrequests.adaptersRtrequests.utilsRt!requests_toolbelt.adapters.sourceRRgt six.movesRtacmeRRRRtacme.magic_typingR R
RRtacme.mixinsR
t getLoggerR]Rrtversion_infotpackagesturllib3tcontribt pyopenssltinject_into_urllib3tAttributeErrorturllib3.contrib.pyopensslRPR�tobjectRRaR�R�Re(((s//usr/lib/python2.7/site-packages/acme/client.pyt<module>sR
��X��