a `]@sBdZddlZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddl m Z zdd l mZWneydd lmZYn0d Zd Zd d ddddddddddddddddddd d!d"d#d$d%d&Zed'd(eDZeed)d(eDd*d+ZejGd,d-d-ejejZGd.d/d/ejeZGd0d1d1eZed2Zed3Z ed4Z!ed5Z"ed6Z#ed7Z$ed8Z%ed9Z&Gd:d;d;eZ'e'd<Z(Gd=d>d>ejZ)Gd?d@d@ejZ*GdAdBdBejZ+GdCdDdDe+Z,GdEdFdFejZ-GdGdHdHe.Z/GdIdJdJe-Z0e*j1GdKdLdLe e0Z2GdMdNdNe e0Z3GdOdPdPe,Z4GdQdRdRe-Z5GdSdTdTe+Z6GdUdVdVe-Z7e*j1GdWdXdXe e7Z8GdYdZdZe e7Z9Gd[d\d\e,Z:e*j1Gd]d^d^e ejZ;Gd_d`d`e,ZGdedfdfe,Z?e*j1Gdgdhdhe>Z@dS)izACME protocol messages.N challenges)errors)fields)jws)util) ResourceMixin)Hashablezurn:acme:error:zurn:ietf:params:acme:error:z4The request specified an account that does not existzOThe request specified a certificate to be revoked that has already been revokedz2The CSR is unacceptable (e.g., due to a short key)z1The client sent an unacceptable anti-replay noncez>The JWS was signed by a public key the server does not supportz;The revocation reason provided is not allowed by the serverz@The JWS was signed with an algorithm the server does not supportz\Certification Authority Authorization (CAA) records forbid the CA from issuing a certificatezBSpecific error conditions are indicated in the "subproblems" arrayz?The server could not connect to the client to verify the domainzAThere was a problem with a DNS query during identifier validationz4The server could not validate a DNSSEC signed domainz;Response received didn't match the challenge's requirementsz1The provided email for a registration was invalidz$The provided contact URI was invalidz!The request message was malformedz9The server will not issue certificates for the identifierzLThe request attempted to finalize an order that is not ready to be finalizedz,There were too many requests of a given typez(The server experienced an internal errorz=The server experienced a TLS error during domain verificationz)The client lacks sufficient authorizationz@A contact URL for an account used an unsupported protocol schemez*The server could not resolve a domain namez'An identifier is of an unsupported typez,The server requires external account binding)ZaccountDoesNotExistZalreadyRevokedZbadCSRZbadNonceZ badPublicKeyZbadRevocationReasonZbadSignatureAlgorithmZcaaZcompoundZ connectiondnsZdnssecZincorrectResponseZ invalidEmailZinvalidContactZ malformedZrejectedIdentifierZ orderNotReadyZ rateLimitedZserverInternalZtlsZ unauthorizedZunsupportedContactZ unknownHostZunsupportedIdentifierexternalAccountRequiredccs|]\}}t||fVqdSN) ERROR_PREFIX.0nameZdescr//usr/lib/python3/dist-packages/acme/messages.py 9srccs|]\}}t||fVqdSr )OLD_ERROR_PREFIXrrrrr<scCs,t|tr(|jdur(t|jvp&t|jvSdS)z#Check if argument is an ACME error.NF) isinstanceErrortypr r)errrrr is_acme_error@src@sheZdZdZejddddZejdddZejdddZe d d Z e d d Z e d dZ ddZdS)rzACME error. https://tools.ietf.org/html/draft-ietf-appsawg-http-problem-00 :ivar unicode typ: :ivar unicode title: :ivar unicode detail: typeTz about:blank omitemptydefaulttitlerdetailcKs.|tvrtd|t|}|fd|i|S)zCreate an Error instance with an ACME Error code. :unicode code: An ACME error code, like 'dnssec'. :kwargs: kwargs to pass to Error. z4The supplied code: %s is not a known ACME error coder) ERROR_CODES ValueErrorr )clscodekwargsrrrr with_codeVs zError.with_codecCs t|jS)zHardcoded error description based on its type. :returns: Description if standard ACME error or ``None``. :rtype: unicode )ERROR_TYPE_DESCRIPTIONSgetrselfrrr descriptiondszError.descriptioncCs$t|jdd}|tvr |SdS)zACME error code. Basically self.typ without the ERROR_PREFIX. :returns: error code if standard ACME code or ``None``. :rtype: unicode :N)strrsplitr!)r*r$rrrr$ns z Error.codecCs(ddd|j|j|j|jfDS)Ns :: css"|]}|dur|ddVqdS)Nasciibackslashreplace)encode)rpartrrrr~sz Error.__str__..)joinrr+r rdecoder)rrr__str__}s z Error.__str__N)__name__ __module__ __qualname____doc__joseFieldrrr classmethodr&propertyr+r$r6rrrrrGs    rcs\eZdZdZdZeZfddZddZe ddZ d d Z d d Z d dZ ddZZS) _ConstantzACME constant.rcs"tt|||j|<||_dSr )superr?__init__POSSIBLE_NAMESrr*r __class__rrrBs z_Constant.__init__cCs|jSr r@r)rrrto_partial_jsonsz_Constant.to_partial_jsoncCs&||jvrtd|j|j|S)Nz{0} not recognized)rCr;ZDeserializationErrorformatr7r#jobjrrr from_jsons   z_Constant.from_jsoncCsd|jj|jS)Nz{0}({1}))rHrFr7rr)rrr__repr__sz_Constant.__repr__cCst|t|o|j|jkSr )rrrr*otherrrr__eq__sz_Constant.__eq__cCst|j|jfSr )hashrFrr)rrr__hash__sz_Constant.__hash__cCs ||k Sr rrMrrr__ne__sz_Constant.__ne__)r7r8r9r: __slots__NotImplementedrCrBrGr=rKrLrOrQrR __classcell__rrrErr?s  r?c@seZdZdZiZdS)StatuszACME "status" field.Nr7r8r9r:rCrrrrrVsrVunknownpendingZ processingZvalidZinvalidZrevokedZreadyZ deactivatedc@seZdZdZiZdS)IdentifierTypezACME identifier type.NrWrrrrrZsrZr c@s*eZdZdZejdejdZedZ dS) IdentifierzNACME identifier. :ivar IdentifierType typ: :ivar unicode value: rdecodervalueN) r7r8r9r:r;r<rZrKrr^rrrrr[sr[c@sjeZdZdZiZGdddejZeddZ eddZ dd Z d d Z d d Z ddZeddZdS) Directoryz Directory.cseZdZdZejdddZejdddZejdddZejdddZ ejdddZ fd d Z e d d Z fd dZddZZS)zDirectory.MetazDirectory Meta.zterms-of-serviceTrZtermsOfServicewebsiteZ caaIdentitiesr c s2fdd|D}ttjjfi|dS)Ncsi|]\}}||qSr_internal_namerkvr)rr z+Directory.Meta.__init__..)itemsrAr_MetarBr*r%rEr)rrBszDirectory.Meta.__init__cCs |jp |jS)zURL for the CA TOS)_terms_of_service_terms_of_service_v2r)rrrterms_of_serviceszDirectory.Meta.terms_of_servicec#s4ttj|D]}|dkr(|ddn|VqdS)Nrk)rAr_ri__iter__rDrErrroszDirectory.Meta.__iter__cCs|dkrd|S|S)Nrm_rrDrrrrbszDirectory.Meta._internal_name)r7r8r9r:r;r<rkrlr`Zcaa_identitiesZexternal_account_requiredrBr>rmrorbrUrrrErris   ricCs t|d|S)N resource_type)getattr)r#keyrrr _canon_keyszDirectory._canon_keycCs"|j}||jvsJ||j|<|S)zRegister resource.)rq_REGISTERED_TYPES)r#Zresource_body_clsrqrrrregisters zDirectory.registercCst||j}||_dSr )rZmap_keysrt_jobj)r*rJZ canon_jobjrrrrBszDirectory.__init__c CsHz||ddWStyB}ztt|WYd}~n d}~00dS)Nrp-)replaceKeyErrorAttributeErrorr.)r*rerrorrrr __getattr__szDirectory.__getattr__cCs@z|j||WSty:td||dYn0dS)NzDirectory field "z " not found)rwrtrzrDrrr __getitem__s zDirectory.__getitem__cCs|jSr )rwr)rrrrGszDirectory.to_partial_jsoncCs |j|di|d<||S)Nmeta)rirKpoprIrrrrKszDirectory.from_jsonN)r7r8r9r:rur;JSONObjectWithFieldsrir=rtrvrBr}r~rGrKrrrrr_s  r_c@seZdZdZedZdS)ResourcezOACME Resource. :ivar acme.messages.ResourceBody body: Resource body. bodyN)r7r8r9r:r;r<rrrrrr src@seZdZdZedZdS)ResourceWithURIzQACME Resource with URI. :ivar unicode ~.uri: Location of the resource. uriN)r7r8r9r:r;r<rrrrrrsrc@seZdZdZdS) ResourceBodyzACME Resource Body.N)r7r8r9r:rrrrrsrc@seZdZdZeddZdS)ExternalAccountBindingzACME External Account Bindingc CsRt|}tj|}|d}tj |tj j |dtj j d||}|S)zLCreate External Account Binding Resource from contact details, kid and hmac.Z newAccount)rsN)jsondumpsrGr2r;Zb64Z b64decoderZJWSZsignZjwkZJWKOctZjwaZHS256) r#Zaccount_public_keyZkidZhmac_keyZ directoryZkey_jsonZdecoded_hmac_keyurlZeabrrr from_data#s z ExternalAccountBinding.from_dataN)r7r8r9r:r=rrrrrr srcseZdZdZejddejjdZejddddZ ejddd Z ejd dd Z ejd dd Z ejd dd Z ejd dd ZdZdZed!ddZfddZddZddZfddZfddZeddZedd ZZS)" RegistrationzRegistration Resource Body. :ivar josepy.jwk.JWK key: Public key. :ivar tuple contact: Contact information following ACME spec, `tuple` of `unicode`. :ivar unicode agreement: rsTrr]contactrr agreementrstatusZtermsOfServiceAgreedZonlyReturnExistingZexternalAccountBindingztel:zmailto:Nc sd|v}t|dd}|dur0|j||durV|fdd|dD|s^|rjt||d<|rv||d<fi|S)a Create registration resource from contact details. The `contact` keyword being passed to a Registration object is meaningful, so this function represents empty iterables in its kwargs by passing on an empty `tuple`. rrNcsg|]}j|qSr) email_prefix)rZmailr#rr ]rgz*Registration.from_data..,external_account_binding)listrappend phone_prefixextendr/tuple)r#ZphoneZemailrr%Zcontact_providedZdetailsrrrrKs  zRegistration.from_datac s0d|vrt|ddtt|jfi|dS)z;Note if the user provides a value for the `contact` member.r _add_contactTN)object __setattr__rArrBrjrErrrBiszRegistration.__init__cstfdd|jDS)Nc3s(|] }|r|tdVqdSr ) startswithlen)rr prefixrrrqs z/Registration._filter_contact..)rr)r*rrrr_filter_contactps zRegistration._filter_contactcCst|ddr|d|d<|S)a The `contact` member of Registration objects should not be required when de-serializing (as it would be if the Fields' `omitempty` flag were `False`), but it should be included in serializations if it was provided. :param jobj: Dictionary containing this Registrations' data :type jobj: dict :returns: Dictionary containing Registrations data to transmit to the server :rtype: dict rFr)rrr2r*rJrrr_add_contact_if_appropriateus z(Registration._add_contact_if_appropriatecstt|}||S)z2Modify josepy.JSONDeserializable.to_partial_json())rArrGrrrErrrGszRegistration.to_partial_jsoncstt|}||S)z;Modify josepy.JSONObjectWithFields.fields_to_partial_json())rArfields_to_partial_jsonrrrErrrsz#Registration.fields_to_partial_jsoncCs ||jS)z*All phones found in the ``contact`` field.)rrr)rrrphonesszRegistration.phonescCs ||jS)z*All emails found in the ``contact`` field.)rrr)rrremailsszRegistration.emails)NNN)r7r8r9r:r;r<ZJWKrKrsrrrZterms_of_service_agreedZonly_return_existingrrrr=rrBrrrGrr>rrrUrrrErr2s*      rc@seZdZdZdZeeZdS)NewRegistrationzNew registration.znew-regNr7r8r9r:rqrrresourcerrrrrsrc@seZdZdZdZeeZdS)UpdateRegistrationzUpdate registration.ZregNrrrrrrsrc@s<eZdZdZejdejdZejdddZ ejdddZ dS) RegistrationResourcezRegistration Resource. :ivar acme.messages.Registration body: :ivar unicode new_authzr_uri: Deprecated. Do not use. :ivar unicode terms_of_service: URL for the CA TOS. rr\new_authzr_uriTrrmN) r7r8r9r:r;r<rrKrrrmrrrrrsrcseZdZdZdZejddddZejddddZejde j de d Z e jd dd Zejd ej ddd Zfd dZfddZfddZefddZeddZddZfddZddZZS) ChallengeBodya>Challenge Resource Body. .. todo:: Confusingly, this has a similar name to `.challenges.Challenge`, as well as `.achallenges.AnnotatedChallenge`. Please use names such as ``challb`` to distinguish instances of this class from ``achall``. :ivar acme.challenges.Challenge: Wrapped challenge. Conveniently, all challenge fields are proxied, i.e. you can call ``challb.x`` to get ``challb.chall.x`` contents. :ivar acme.messages.Status status: :ivar datetime.datetime validated: :ivar messages.Error error: )challrTNrrr)r]rr validatedrr|c s0fdd|D}ttjfi|dS)Ncsi|]\}}||qSrrarcr)rrrfrgz*ChallengeBody.__init__..)rhrArrBrjrEr)rrBszChallengeBody.__init__cstt|||Sr )rArr2rbrDrErrr2szChallengeBody.encodecs"tt|}||j|Sr )rArrGupdaterrrErrrGszChallengeBody.to_partial_jsoncs$tt||}tj||d<|S)Nr)rArfields_from_jsonrZ ChallengerK)r#rJZ jobj_fieldsrErrrszChallengeBody.fields_from_jsoncCs |jp |jS)zThe URL of this challenge.)_url_urir)rrrrszChallengeBody.uricCs t|j|Sr )rrrrDrrrr}szChallengeBody.__getattr__c#s2tt|D]}|dkr&|ddn|VqdS)Nrrn)rArrorDrErrroszChallengeBody.__iter__cCs|dkrd|S|S)NrrprrDrrrrbszChallengeBody._internal_name)r7r8r9r:rSr;r<rrrVrKSTATUS_PENDINGrr RFC3339Fieldrrr|rBr2rGr=rr>rr}rorbrUrrrErrs*       rc@s6eZdZdZejdejdZedZ e ddZ dS)ChallengeResourcezChallenge Resource. :ivar acme.messages.ChallengeBody body: :ivar unicode authzr_uri: URI found in the 'up' ``Link`` header. rr\ authzr_uricCs|jjS)zThe URL of the challenge body.)rrr)rrrrszChallengeResource.uriN) r7r8r9r:r;r<rrKrrr>rrrrrrs  rc@seZdZdZejdejddZejdddZ ejdddZ ejdde jd Z e jd ddZejd ddZe jd d Z eddZdS) Authorizationa^Authorization Resource Body. :ivar acme.messages.Identifier identifier: :ivar list challenges: `list` of `.ChallengeBody` :ivar tuple combinations: Challenge combinations (`tuple` of `tuple` of `int`, as opposed to `list` of `list` from the spec). :ivar acme.messages.Status status: :ivar datetime.datetime expires: identifierTr]rrr combinationsrrexpireswildcardcCstdd|DS)Ncss|]}t|VqdSr )rrK)rrrrrr rgz+Authorization.challenges..rr^rrrrszAuthorization.challengescstfddjDS)z0Combinations with challenges instead of indices.c3s$|]}tfdd|DVqdS)c3s|]}j|VqdSr r)ridxr)rrr%rgz@Authorization.resolved_combinations...Nr)rZcombor)rrr%sz6Authorization.resolved_combinations..)rrr)rr)rresolved_combinations"s z#Authorization.resolved_combinationsN)r7r8r9r:r;r<r[rKrrrrVrrrrrr]r>rrrrrrs  rc@seZdZdZdZeeZdS)NewAuthorizationzNew authorization.z new-authzNrrrrrr)src@seZdZdZdZeeZdS)UpdateAuthorizationzUpdate authorization.ZauthzNrrrrrr0src@s.eZdZdZejdejdZejdddZ dS)AuthorizationResourcezAuthorization Resource. :ivar acme.messages.Authorization body: :ivar unicode new_cert_uri: Deprecated. Do not use. rr\ new_cert_uriTrN) r7r8r9r:r;r<rrKrrrrrrr6src@s2eZdZdZdZeeZej dej ej dZ dS)CertificateRequestzACME new-cert request. :ivar josepy.util.ComparableX509 csr: `OpenSSL.crypto.X509Req` wrapped in `.ComparableX509` znew-certcsrr]encoderN) r7r8r9r:rqrrrr;r<Z decode_csrZ encode_csrrrrrrrAs rc@s$eZdZdZedZedZdS)CertificateResourceaCertificate Resource. :ivar josepy.util.ComparableX509 body: `OpenSSL.crypto.X509` wrapped in `.ComparableX509` :ivar unicode cert_chain_uri: URI found in the 'up' ``Link`` header :ivar tuple authzrs: `tuple` of `AuthorizationResource`. cert_chain_uriauthzrsN)r7r8r9r:r;r<rrrrrrrNs rc@s<eZdZdZdZeeZej dej ej dZ e dZ dS) Revocationz|Revocation message. :ivar .ComparableX509 certificate: `OpenSSL.crypto.X509` wrapped in `.ComparableX509` z revoke-cert certificaterreasonN)r7r8r9r:rqrrrr;r<Z decode_certZ encode_certrrrrrrr[s  rc@seZdZdZejdddZejdejddZ ejdddZ ejdddZ ejd ddZ e jd ddZejd dejd Zejd dZdS)Ordera_Order Resource Body. :ivar identifiers: List of identifiers for the certificate. :vartype identifiers: `list` of `.Identifier` :ivar acme.messages.Status status: :ivar authorizations: URLs of authorizations. :vartype authorizations: `list` of `str` :ivar str certificate: URL to download certificate as a fullchain PEM. :ivar str finalize: URL to POST to to request issuance once all authorizations have "valid" status. :ivar datetime.datetime expires: When the order expires. :ivar ~.Error error: Any error that occurred during finalization, if applicable. identifiersTrrrauthorizationsrfinalizerr|rcCstdd|DS)Ncss|]}t|VqdSr )r[rK)rrrrrrrgz$Order.identifiers..rrrrrrszOrder.identifiersN)r7r8r9r:r;r<rrVrKrrrrrrrrr|r]rrrrrjs  rc@sTeZdZdZejdejdZejdddZ edZ ejdddZ ejd ddZ d S) OrderResourceaOrder Resource. :ivar acme.messages.Order body: :ivar str csr_pem: The CSR this Order will be finalized with. :ivar authorizations: Fully-fetched AuthorizationResource objects. :vartype authorizations: `list` of `acme.messages.AuthorizationResource` :ivar str fullchain_pem: The fetched contents of the certificate URL produced once the order was finalized, if it's present. :ivar alternative_fullchains_pem: The fetched contents of alternative certificate chain URLs produced once the order was finalized, if present and requested during finalization. :vartype alternative_fullchains_pem: `list` of `str` rr\csr_pemTrr fullchain_pemalternative_fullchains_pemN) r7r8r9r:r;r<rrKrrrrrrrrrrs   rc@seZdZdZdZdS)NewOrderz New order.z new-orderN)r7r8r9r:rqrrrrrsr)Ar:rZjosepyr;ZsixZacmerrrrrZ acme.mixinsrcollections.abcr ImportError collectionsrr r!dictrhr'rrZpython_2_unicode_compatiblerrZJSONDeSerializabler?rVZSTATUS_UNKNOWNrZSTATUS_PROCESSINGZ STATUS_VALIDZSTATUS_INVALIDZSTATUS_REVOKEDZ STATUS_READYZSTATUS_DEACTIVATEDrZZIDENTIFIER_FQDNr[r_rrrrrrrvrrrrrrrrrrrrrrrrrrrs       !  <! G  i B"