ok

Mini Shell

Direktori : /lib/python3.6/site-packages/acme/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/acme/__pycache__/challenges.cpython-36.pyc

3

گa�T�@s$dZddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddlm
Z
ddlmZddlmZddlm
Z
dd	lmZdd
lmZddlZddlmZddlmZddlZdd
lmZddlmZddlmZddlmZddlmZeje�Z Gdd�dej!�Z"Gdd�deeej!�Z#Gdd�de"�Z$Gdd�de"�Z%Gdd�de#�Z&Gdd�de%ej'd�Z(e#j)Gdd �d e&��Z*e"j)Gd!d"�d"e(��Z+e#j)Gd#d$�d$e&��Z,e"j)Gd%d&�d&e(��Z-e#j)Gd'd(�d(e&��Z.e"j)Gd)d*�d*e(��Z/e"j)Gd+d,�d,e%��Z0e#j)Gd-d.�d.e#��Z1dS)/z&ACME Identifier Validation Challenges.�N)�cast)�Any)�Dict)�Mapping)�Optional)�Tuple)�Type)�hashes)�crypto)�SSL)�crypto_util)�errors)�fields)�
ResourceMixin)�	TypeMixincsJeZdZUdZiZeeedfee	ee
fdd��fdd��Z�ZS)�	ChallengezACME challenge.)�jobj�returncsDyt�j|�Stjk
r>}ztj|�tj|�Sd}~XnXdS)N)�super�	from_json�joseZUnrecognizedTypeError�logger�debug�UnrecognizedChallenge)�clsr�error)�	__class__�� /usr/lib/python3.6/challenges.pyr$s

zChallenge.from_json)
�__name__�
__module__�__qualname__�__doc__�TYPESr�strr�classmethodrrr�
__classcell__rr)rrrs
rc@s4eZdZUdZiZeeedfdZe	j
e�ZdS)�ChallengeResponsezACME challenge response.Z	challengeN)rr r!r"r#rr$rZ
resource_typerZResourceZresourcerrrrr'-s
r'csbeZdZdZeeefdd��fdd�Zeeefd�dd�Z	e
eeefdd�d	d
��Z�ZS)ralUnrecognized challenge.

    ACME specification defines a generic framework for challenges and
    defines some standard challenges that are implemented in this
    module. However, other implementations (including peers) might
    define additional challenge types, which should be ignored if
    unrecognized.

    :ivar jobj: Original JSON decoded object.

    N)rrcst�j�tj|d|�dS)Nr)r�__init__�object�__setattr__)�selfr)rrrr(Bs
zUnrecognizedChallenge.__init__)rcCs|jS)N)r)r+rrr�to_partial_jsonFsz%UnrecognizedChallenge.to_partial_jsoncCs||�S)Nr)rrrrrrIszUnrecognizedChallenge.from_json)
rr r!r"rr$rr(rr,r%rr&rr)rrr5s
rc@sLeZdZUdZdZejdejej	ej
edd�d�Zee
ed�d	d
��ZdS)
�_TokenChallengez3Challenge with token.

    :ivar bytes token:

    ���tokenT)�sizeZminimum)�encoder�decoder)rcCsd|jkod|jkS)z�Is `token` good?

        .. todo:: acme-spec wants "It MUST NOT contain any non-ASCII
           characters", but it should also warrant that it doesn't
           contain ".." or "/"...

        s..�/)r0)r+rrr�
good_token]sz_TokenChallenge.good_tokenNg0@)rr r!r"Z
TOKEN_SIZEr�FieldZencode_b64jose�	functools�partialZdecode_b64joser0�bytes�property�boolr5rrrrr-Ns

r-csReZdZdZejd�ZejZ	dej
ed�dd�Ze
eefd��fdd	�Z�ZS)
�!KeyAuthorizationChallengeResponsez_Response to Challenges based on Key Authorization.

    :param unicode key_authorization:

    �keyAuthorization�KeyAuthorizationChallenge)�chall�account_public_keyrcCs�|jjd�}t|�dkr*tjd|j�dS|d|jd�krXtjd|d|jd��dStj|j|j	d��j
�}|d	|kr�tjd
|d|�dSdS)a%Verify the key authorization.

        :param KeyAuthorization chall: Challenge that corresponds to
            this response.
        :param JWK account_public_key:

        :return: ``True`` iff verification of the key authorization was
            successful.
        :rtype: bool

        �.�z)Key authorization (%r) is not well formedFrr0z8Mismatching token in key authorization: %r instead of %r)�
hash_function�z=Mismatching thumbprint in key authorization: %r instead of %rT)�key_authorization�split�lenrr�encoder�	b64encode�
thumbprint�thumbprint_hash_function�decode)r+r?r@�partsrJrrr�verifyus z(KeyAuthorizationChallengeResponse.verify)rcst�j�}|jdd�|S)Nr=)rr,�pop)r+r)rrrr,�s
z1KeyAuthorizationChallengeResponse.to_partial_json)rr r!r"rr6rEr	ZSHA256rK�JWKr;rNrr$rr,r&rr)rrr<ls

 r<c@s�eZdZUdZeZeeZee	e	j
Z
ejed�dd�Z
eje	d�dd�Zejejeed�dd	��Zejeeee	efd
�dd�Zd
S)r>z�Challenge based on Key Authorization.

    :param response_cls: Subclass of `KeyAuthorizationChallengeResponse`
        that will be used to generate ``response``.
    :param str typ: type of the challenge
    )�account_keyrcCs&|jd�dtj|j|jd��j�S)z^Generate Key Authorization.

        :param JWK account_key:
        :rtype unicode:

        r0rA)rC)rHrrIrJrKrL)r+rQrrrrE�sz+KeyAuthorizationChallenge.key_authorizationcCs|j|j|�d�S)z�Generate response to the challenge.

        :param JWK account_key:

        :returns: Response (initialized `response_cls`) to the challenge.
        :rtype: KeyAuthorizationChallengeResponse

        )rE)�response_clsrE)r+rQrrr�response�s	z"KeyAuthorizationChallenge.response)rQ�kwargsrcKs
t��dS)a�Generate validation for the challenge.

        Subclasses must implement this method, but they are likely to
        return completely different data structures, depending on what's
        necessary to complete the challenge. Interpretation of that
        return value must be known to the caller.

        :param JWK account_key:
        :returns: Challenge-specific validation.

        N)�NotImplementedError)r+rQrTrrr�
validation�s
z$KeyAuthorizationChallenge.validation)rQ�argsrTrcOs|j|�|j|f|�|�fS)z�Generate response and validation.

        Convenience function that return results of `response` and
        `validation`.

        :param JWK account_key:
        :rtype: tuple

        )rSrV)r+rQrWrTrrr�response_and_validation�sz1KeyAuthorizationChallenge.response_and_validationN)rr r!r"�NotImplemented�typr$rRrr<rKrrPrErS�abc�abstractmethodrrVrrXrrrrr>�s
r>)�	metaclassc@s*eZdZdZdZdeejed�dd�Z	dS)�
DNS01ResponsezACME dns-01 challenge response.zdns-01�DNS01)r?�domainr@rcCs|j||�}|stjd�|S)a�Simple verify.

        This method no longer checks DNS records and is a simple wrapper
        around `KeyAuthorizationChallengeResponse.verify`.

        :param challenges.DNS01 chall: Corresponding challenge.
        :param unicode domain: Domain name being verified.
        :param JWK account_public_key: Public key for the key pair
            being authorized.

        :return: ``True`` iff verification of the key authorization was
            successful.
        :rtype: bool

        z4Verification of key authorization in response failed)rNrr)r+r?r`r@Zverifiedrrr�
simple_verify�s
zDNS01Response.simple_verifyN)
rr r!r"rZr$rrPr;rarrrrr^�sr^c@sBeZdZdZeZejZdZej	e
ed�dd�Zeed�dd�Z
d	S)
r_zACME dns-01 challenge.z_acme-challenge)rQ�
unused_kwargsrcKs$tjtj|j|�jd��j��j�S)zWGenerate validation.

        :param JWK account_key:
        :rtype: unicode

        zutf-8)rrI�hashlib�sha256rErH�digestrL)r+rQrbrrrrVszDNS01.validation)�namercCsdj|j|�S)zkDomain name for TXT validation record.

        :param unicode name: Domain name being validated.

        z{0}.{1})�format�LABEL)r+rfrrr�validation_domain_name
szDNS01.validation_domain_nameN)rr r!r"r^rRrZrhrrPrr$rVrirrrrr_�s
r_c@s:eZdZdZdZdZdZd
deej	e
eed�dd	�Z
dS)�HTTP01Responsez ACME http-01 challenge response.zhttp-01�Pz

	 N�HTTP01)r?r`r@�portrc	Cs�|j||�stjd�dS|dk	rF||jkrFtjd|�|dj|�7}|j|�}tjd|j|�ytj	|dd�}Wn2tj
jk
r�}ztjd||�dSd}~XnXd	|_
tjd
||j|j�|jj|j�}|j|kr�tjd|j|�dSdS)
a�Simple verify.

        :param challenges.SimpleHTTP chall: Corresponding challenge.
        :param unicode domain: Domain name being verified.
        :param JWK account_public_key: Public key for the key pair
            being authorized.
        :param int port: Port used in the validation.

        :returns: ``True`` iff validation with the files currently served by the
            HTTP server is successful.
        :rtype: bool

        z4Verification of key authorization in response failedFNz4Using non-standard port for http-01 verification: %sz:{0}zVerifying %s at %s...)rNzUnable to reach %s: %s�asciizReceived %s: %s. Headers: %szEKey authorization from response (%r) doesn't match HTTP response (%r)T)rNrr�PORTZwarningrg�urirZ�requests�get�
exceptionsZRequestExceptionr�encoding�textZheaders�rstrip�WHITESPACE_CUTSETrE)	r+r?r`r@rmrpZ
http_responserZchallenge_responserrrra#s0

	
zHTTP01Response.simple_verify)N)rr r!r"rZrorwr$rrPr�intr;rarrrrrjs
rjc@sTeZdZdZeZejZdZee	d�dd��Z
e	e	d�dd�Zej
ee	d	�d
d�ZdS)
rlzACME http-01 challenge.z.well-known/acme-challenge)rcCsd|jd|jd�S)zTPath (starting with '/') for provisioned resource.

        :rtype: string

        �/r0)�
URI_ROOT_PATHrH)r+rrr�pathdszHTTP01.path)r`rcCsd||jS)z�Create an URI to the provisioned resource.

        Forms an URI to the HTTPS server provisioned resource
        (containing :attr:`~SimpleHTTP.token`).

        :param unicode domain: Domain name being verified.
        :rtype: string

        zhttp://)r{)r+r`rrrrpms
z
HTTP01.uri)rQrbrcKs
|j|�S)zWGenerate validation.

        :param JWK account_key:
        :rtype: unicode

        )rE)r+rQrbrrrrVyszHTTP01.validationN)rr r!r"rjrRrZrzr:r$r{rprrPrrVrrrrrl[srlc	@s�eZdZdZdZdZdZdZee	d�dd��Z
deee
jeee
je
jfd�dd
�Zdeeeeee
jd�dd�Zee
jed�dd�Zddeejee
jeeeeed�dd�Zd	S)�TLSALPN01Responsez$ACME tls-alpn-01 challenge response.ztls-alpn-01i�s1.3.6.1.5.5.7.1.30.1z
acme-tls/1)rcCstj|jjd��j�S)z*Hash value stored in challenge certificatezutf-8)rcrdrErHre)r+rrr�h�szTLSALPN01Response.hN�)r`�key�bitsrcCs\|dkrtj�}|jtj|�dtj|jd�}tj|jd|d�}t	j
||gd|gd�|fS)a�Generate tls-alpn-01 certificate.

        :param unicode domain: Domain verified by the challenge.
        :param OpenSSL.crypto.PKey key: Optional private key used in
            certificate generation. If not provided (``None``), then
            fresh key will be generated.
        :param int bits: Number of bits for newly generated key.

        :rtype: `tuple` of `OpenSSL.crypto.X509` and `OpenSSL.crypto.PKey`

        NsDER:�hexT)Zcritical�value)Z	force_san�
extensions)r
�PKeyZgenerate_keyZTYPE_RSA�codecsrHr}Z
X509Extension�ID_PE_ACME_IDENTIFIER_V1rZgen_ss_cert)r+r`rr�Z	der_valueZacme_extensionrrr�gen_cert�s

zTLSALPN01Response.gen_cert)r`�hostrmrcCsL|dkr tj|�}tjd||�|dkr.|j}tj|j�||j�|jgd�S)z�Probe tls-alpn-01 challenge certificate.

        :param unicode domain: domain being validated, required.
        :param string host: IP address used to probe the certificate.
        :param int port: Port used to probe the certificate.

        Nz%s resolved to %s)r�rmrfZalpn_protocols)	�socketZ
gethostbynamerrrorZ	probe_snirH�ACME_TLS_1_PROTOCOL)r+r`r�rmrrr�
probe_cert�s	
zTLSALPN01Response.probe_cert)r`�certrcCs�tj|�}tjd|jd�|�t|�dks>|dj�|j�krBdSx<t|j��D],}|j	|�}|j
�dkrP|j�}||jkSqPWdS)aVerify tls-alpn-01 challenge certificate.

        :param unicode domain: Domain name being validated.
        :param OpensSSL.crypto.X509 cert: Challenge certificate.

        :returns: Whether the certificate was successfully verified.
        :rtype: bool

        zCertificate %s. SANs: %srdrDrFsUNDEF)
rZ _pyopenssl_cert_or_req_all_namesrrrerG�lower�rangeZget_extension_countZ
get_extensionZget_short_name�get_datar})r+r`r��names�iZext�datarrr�verify_cert�s
 
zTLSALPN01Response.verify_cert�	TLSALPN01)r?r`r@r�r�rmrcCsx|j||�stjd�dS|dkrly|j|||d�}Wn4tjk
rj}ztjt|�dd�dSd}~XnX|j||�S)a�Simple verify.

        Verify ``validation`` using ``account_public_key``, optionally
        probe tls-alpn-01 certificate and check using `verify_cert`.

        :param .challenges.TLSALPN01 chall: Corresponding challenge.
        :param str domain: Domain name being validated.
        :param JWK account_public_key:
        :param OpenSSL.crypto.X509 cert: Optional certificate. If not
            provided (``None``) certificate will be retrieved using
            `probe_cert`.
        :param string host: IP address used to probe the certificate.
        :param int port: Port used to probe the certificate.


        :returns: ``True`` if and only if client's control of the domain has been verified.
        :rtype: bool

        z4Verification of key authorization in response failedFN)r`r�rmT)�exc_info)rNrrr�r
�Errorr$r�)r+r?r`r@r�r�rmrrrrra�s
zTLSALPN01Response.simple_verify)Nr~)NN)NNN)rr r!r"rZror�r�r:r9r}r$rr
r�rxr�X509r�r�r;r�rrPrarrrrr|�s r|c@sLeZdZdZeZejZeje	e
ejej
fd�dd�Zeed�dd��ZdS)	r�zACME tls-alpn-01 challenge.)rQrTrcKs |j|�j|jd�|jd�d�S)a�Generate validation.

        :param JWK account_key:
        :param unicode domain: Domain verified by the challenge.
        :param OpenSSL.crypto.PKey cert_key: Optional private key used
            in certificate generation. If not provided (``None``), then
            fresh key will be generated.

        :rtype: `tuple` of `OpenSSL.crypto.X509` and `OpenSSL.crypto.PKey`

        Zcert_keyr`)rr`)rSr�rr)r+rQrTrrrrV
s
zTLSALPN01.validation)rcCsttjd�ottjd�S)ai
        Check if TLS-ALPN-01 challenge is supported on this machine.
        This implies that a recent version of OpenSSL is installed (>= 1.0.2),
        or a recent cryptography version shipped with the OpenSSL library is installed.

        :returns: ``True`` if TLS-ALPN-01 is supported on this machine, ``False`` otherwise.
        :rtype: bool

        Zset_alpn_protosZset_alpn_select_callback)�hasattrrZ
ConnectionZContextrrrr�is_supportedszTLSALPN01.is_supportedN)rr r!r"r|rRrZrrPrrr
r�r�rV�staticmethodr;r�rrrrr�s r�c@sreZdZdZdZdZejfejej	e
ejd�dd�Zejeje
d�dd	�Zeje
d
d�dd
�Zeed�dd�ZdS)�DNSzACME "dns" challenge.�dnsz_acme-challenge)rQ�algrTrcKs(tjjf|jdd�jd�||d�|��S)z�Generate validation.

        :param .JWK account_key: Private account key.
        :param .JWA alg:

        :returns: This challenge wrapped in `.JWS`
        :rtype: .JWS

        T)Z	sort_keyszutf-8)�payloadrr�)r�JWSZsignZ
json_dumpsrH)r+rQr�rTrrr�gen_validation1szDNS.gen_validation)rVr@rcCsZ|j|d�sdSy||j|jjd��kStjk
rT}ztjd|�dSd}~XnXdS)zwCheck validation.

        :param JWS validation:
        :param JWK account_public_key:
        :rtype: bool

        )rFzutf-8z&Checking validation for DNS failed: %sN)rNZ
json_loadsr�rLrZDeserializationErrorrr)r+rVr@rrrr�check_validation@szDNS.check_validation�DNSResponse)rQrTrcKst|j|f|�d�S)z�Generate response.

        :param .JWK account_key: Private account key.
        :param .JWA alg:

        :rtype: DNSResponse

        )rV)r�r�)r+rQrTrrr�gen_responseQs	zDNS.gen_response)rfrcCsdj|j|�S)zkDomain name for TXT validation record.

        :param unicode name: Domain name being validated.

        z{0}.{1})rgrh)r+rfrrrri]szDNS.validation_domain_nameN)rr r!r"rZrhrZRS256rPZJWASignaturerr�r�r;r�r�r$rirrrrr�)sr�c@s:eZdZdZdZejdejjd�Z	dej
ed�dd�Zd	S)
r�z@ACME "dns" challenge response.

    :param JWS validation:

    r�rV)r3r�)r?r@rcCs|jttj|j�|�S)z~Check validation.

        :param challenges.DNS chall:
        :param JWK account_public_key:

        :rtype: bool

        )r�rrr�rV)r+r?r@rrrr�qs	zDNSResponse.check_validationN)
rr r!r"rZrr6r�rrVrPr;r�rrrrr�fsr�)2r"r[r�r7rcZloggingr�ZtypingrrrrrrrZcryptography.hazmat.primitivesr	ZjosepyrZOpenSSLr
rrqZacmerr
rZacme.mixinsrrZ	getLoggerrrZTypedJSONObjectWithFieldsrr'rr-r<�ABCMetar>�registerr^r_rjrlr|r�r�r�rrrr�<module>s^
/AG'$<

Zerion Mini Shell 1.0