HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //snap/certbot/4965/lib/python3.12/site-packages/acme/__pycache__/challenges.cpython-312.pyc
�

N�h�=���dZddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZdd	lm
Z
ddlZddlZej"e�Ze
d
d��ZGd
�dej*�ZGd�dej*�ZGd�de�ZGd�de�ZGd�de�ZGd�deej6��Zej:Gd�de��Zej:Gd�de��Zej:Gd�de��Z ej:Gd�d e��Z!ej:Gd!�d"e��Z"ej:Gd#�d$e��Z#y)%z&ACME Identifier Validation Challenges.�N)�Any)�cast)�Mapping)�Optional)�TypeVar)�Union)�hashes�GenericChallenge�	Challenge)�boundc	�t��eZdZUdZiZeeedfed<e	dee
deeefde
e
dff�fd��Z�xZS)rzACME challenge.�TYPES�cls�jobj�return�UnrecognizedChallengec����	ttt�|�
|��S#tj
$r4}tj|�tj|�cYd}~Sd}~wwxYw�N)	rr
�super�	from_json�jose�UnrecognizedTypeError�logger�debugr)rr�error�	__class__s   ��/build/snapcraft-certbot-c9561b03ef7f16aa90eb6754ca5f17a1/parts/certbot/install/lib/python3.12/site-packages/acme/challenges.pyrzChallenge.from_jsonsS���	9��(�%�'�*;�D�*A�B�B���)�)�	9��L�L���(�2�2�4�8�8��	9�s� �A'�)A"�A'�"A')�__name__�
__module__�__qualname__�__doc__r�dict�str�type�__annotations__�classmethodr
rrrr�
__classcell__�rs@rrrsc����*,�E�4��T�+�&�&�'�,��9�t�,�-�9���S��)�9�.3�4D�F]�4]�.^�9��9�c�R��eZdZUdZiZeeedfed<deee	ff�fd�Z
�xZS)�ChallengeResponsezACME challenge response.rrc�\��t�|��}|j|jd�|Sr)r�to_partial_json�pop�type_field_name��selfrrs  �rr-z!ChallengeResponse.to_partial_json*s+����w�&�(������%�%�t�,��r))rrr r!rr"r#r$r%rr-r'r(s@rr+r+%s9���"�24�E�4��T�-�.�.�/�4���c�3�h���r)r+c���eZdZUdZeeefed<deeefddf�fd�Z	deeeffd�Z
edeeefddfd��Z�xZ
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.

    rrNc�P��t�|��tj|d|�y)Nr)r�__init__�object�__setattr__r0s  �rr4zUnrecognizedChallenge.__init__@s ���
�������4���.r)c��|jSr)r�r1s rr-z%UnrecognizedChallenge.to_partial_jsonDs���y�y�r)c��||�Sr�)rrs  rrzUnrecognizedChallenge.from_jsonGs���4�y�r))rrr r!r"r#rr%rr4r-r&rr'r(s@rrr2st���
��s�C�x�.��/�W�S�#�X�.�/�4�/���c�3�h�����W�S�#�X�.��3J���r)rc	��eZdZUdZdZ	ejdejejejed����Zee
d<edefd��Zy	)
�_TokenChallengez3Challenge with token.

    :ivar bytes token:

    ��tokenT)�size�minimum)�encoder�decoderrc�>�d|jvxrd|jvS)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..�/)r>r8s r�
good_tokenz_TokenChallenge.good_token[s!���D�J�J�&�A�4�t�z�z�+A�Ar)N)rrr r!�
TOKEN_SIZEr�field�encode_b64jose�	functools�partial�decode_b64joser>�bytesr%�property�boolrEr:r)rr<r<Lss���
�J�5��4�:�:���,�,�6G�i�6G�6G����j�$�7@�A�E�5�A�
�B�D�B��Br)r<c���eZdZUdZej
d�Zeed<e	jZdddejde
fd�Zdeeeff�fd	�Z�xZS)
�!KeyAuthorizationChallengeResponsez[Response to Challenges based on Key Authorization.

    :param str key_authorization:

    �keyAuthorization�key_authorization�chall�KeyAuthorizationChallenge�account_public_keyrc���|jjd�}t|�dk7r!tj	d|j�y|d|jd�k7r*tj	d|d|jd��yt
j|j|j���j�}|d	|k7rtj	d
|d|�yy)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 formedFrr>z8Mismatching token in key authorization: %r instead of %r��
hash_function�z=Mismatching thumbprint in key authorization: %r instead of %rT)rR�split�lenrr�encoder�	b64encode�
thumbprint�thumbprint_hash_function�decode)r1rSrU�partsr`s     r�verifyz(KeyAuthorizationChallengeResponse.verifyss����&�&�,�,�S�1���u�:��?��L�L�D��/�/�
1����8�u�|�|�G�,�,��L�L�,�-2�1�X�u�|�|�G�7L�
N���^�^�$6�$A�$A��7�7�%B�%9�:�:@�&�(�	���8�z�!��L�L�,�-2�1�X�z�
C��r)c�H��t�|��}|jdd�|S)NrQ)rr-r.r0s  �rr-z1KeyAuthorizationChallengeResponse.to_partial_json�s$����w�&�(�����#�T�*��r))rrr r!rrGrRr#r%r	�SHA256ra�JWKrNrdr"rr-r'r(s@rrPrPjse����
(�T�Z�Z�(:�;��s�;�%�}�}���7��T�X�X��Z^��@��c�3�h���r)rPc
��eZdZUdZeZeed<eZe	e
ed<e
jZdejdefd�Zdejde
fd�Zej"dejdedefd	��Zdejd
ededee
effd�Zy)
rTz�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
    �typ�response_cls�account_keyrc��|jd�dztj|j|j���j�zS)zZGenerate Key Authorization.

        :param JWK account_key:
        :rtype str:

        r>rWrY)r^rr_r`rarb�r1rks  rrRz+KeyAuthorizationChallenge.key_authorization�sO���{�{�7�#�c�)�D�N�N��"�"�"�;�;�
#�
=�->�>D�f�h�G�	Gr)c�D�|j|j|���S)z�Generate response to the challenge.

        :param JWK account_key:

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

        �rR)rjrRrms  r�responsez"KeyAuthorizationChallenge.response�s,��� � �"�4�4�[�A�!�C�	Cr)�kwargsc��t��)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.

        )�NotImplementedError�r1rkrqs   r�
validationz$KeyAuthorizationChallenge.validation�s
��"�#�#r)�argsc�P�|j|�|j|g|��i|��fS)z�Generate response and validation.

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

        :param JWK account_key:
        :rtype: tuple

        )rpru)r1rkrvrqs    r�response_and_validationz1KeyAuthorizationChallenge.response_and_validation�s2���
�
�k�*������=�d�=�f�=�?�	?r)N)rrr r!�NotImplementedrir#r%rjr$rPrarrgrRrp�abc�abstractmethodrru�tuplerxr:r)rrTrT�s�����C���<J�L�$�8�9�J�)�B�B��	G�T�X�X�	G�#�	G�
C�D�H�H�
C�1R�
C�	���$�d�h�h�$�#�$�#�$��$�?�4�8�8�?�C�?�SV�?�%*�+L�c�+Q�%R�?r)rT)�	metaclassc�@�eZdZdZdZdddedejdefd�Z	y	)
�
DNS01ResponsezACME dns-01 challenge response.zdns-01rS�DNS01�domainrUrc�X�|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 str 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

        �4Verification of key authorization in response failed)rdrr)r1rSr�rU�verifieds     r�
simple_verifyzDNS01Response.simple_verify�s*�� �;�;�u�&8�9����L�L�O�P��r)N)
rrr r!rir#rrgrNr�r:r)rrr�s0��)�
�C��7��C��T�X�X��Z^�r)rc�j�eZdZdZeZejZdZ	dejde
defd�Zdedefd�Z
y	)
r�zACME dns-01 challenge.�_acme-challengerk�
unused_kwargsrc���tjtj|j	|�jd��j
��j�S)�SGenerate validation.

        :param JWK account_key:
        :rtype: str

        �utf-8)rr_�hashlib�sha256rRr^�digestrb�r1rkr�s   rruzDNS01.validationsG���~�~�g�n�n�T�-C�-C��.�����*�*0�&�(�4�4:�F�H�	=r)�namec�$�|j�d|��S)z{Domain name for TXT validation record.

        :param str name: Domain name being validated.
        :rtype: str

        rW)�LABEL�r1r�s  r�validation_domain_namezDNS01.validation_domain_names���*�*��Q�t�f�%�%r)N)rrr r!rrjrir�rrgrr#rur�r:r)rr�r��sN�� � �L�
�
�
�C��E�C�=�d�h�h�=��=��=�&�3�&�3�&r)r�c
�^�eZdZdZdZdZ	dZ		dddded	ejd
e
ededefd
�Z
y)�HTTP01Responsez ACME http-01 challenge response.zhttp-01�Pz

	 NrS�HTTP01r�rU�port�timeoutrc���|j||�stjd�y|�9||jk7r*tj	d|�|dj|�z
}|j
|�}tjd|j|�	tj|d|��}d	|_
tjd
||j|j�|jj!|j"�}	|j$|	k7r"tjd|j$|	�yy#tjj$r!}tjd||�Yd}~yd}~wwxYw)
a�Simple verify.

        :param challenges.SimpleHTTP chall: Corresponding challenge.
        :param str 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.
        :param int timeout: Timeout in seconds.

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

        r�FNz4Using non-standard port for http-01 verification: %sz:{0}zVerifying %s at %s...)rdr�zUnable to reach %s: %s�asciizReceived %s: %s. Headers: %szEKey authorization from response (%r) doesn't match HTTP response (%r)T)rdrr�PORT�warning�format�uriri�requests�get�
exceptions�RequestExceptionr�encoding�text�headers�rstrip�WHITESPACE_CUTSETrR)
r1rSr�rUr�r�r��
http_responser�challenge_responses
          rr�zHTTP01Response.simple_verify%sG�� �{�{�5�"4�5��L�L�O�P��
����	�	� 1��N�N�F��
N��f�m�m�D�)�)�F��i�i�������,�e�i�i��=�	�$�L�L��U�G�L�M�")�
�����3�]�"�'�'��)>�)>�	@�+�/�/�6�6�t�7M�7M�N���!�!�%7�7��L�L�.�/3�/E�/E�+�
-����-�"�"�3�3�	��L�L�1�3��>���	�s�D9�9E7�E2�2E7)N�)rrr r!rir�r�r#rrgr�intrNr�r:r)rr�r�s`��*�
�C�
�D��"��O�BD�6�8�6�S�6�d�h�h�6�$�S�M�6�;>�6�HL�6r)r�c��eZdZdZeZejZdZ	ede	fd��Z
de	de	fd�Zdejdede	fd	�Zy
)r�zACME http-01 challenge.z.well-known/acme-challengerc�J�d|jzdz|jd�zS)zQPath (starting with '/') for provisioned resource.

        :rtype: str

        �/r>)�
URI_ROOT_PATHr^r8s r�pathzHTTP01.pathgs(���T�'�'�'�#�-����G�0D�D�Dr)r�c�&�d|z|jzS)z�Create an URI to the provisioned resource.

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

        :param str domain: Domain name being verified.
        :rtype: str

        zhttp://)r�)r1r�s  rr�z
HTTP01.urips���6�!�D�I�I�-�-r)rkr�c�$�|j|�S)r�ror�s   rruzHTTP01.validation|s���%�%�k�2�2r)N)rrr r!r�rjrir�rMr#r�r�rrgrrur:r)rr�r�^sj��!�!�L�
�
�
�C�0�M�<�
�E�c�E��E�
.�#�
.�#�
.�3�d�h�h�3��3��3r)r�c	��eZdZdZdZdZ	ejfdejdejde
dejfd�Zd	ejd
ejde
fd�Zdejde
ddfd
�Zdedefd�Zy)�DNSzACME "dns" challenge.�dnsr�rk�algrqrc��tjjd|jd��j	d�||d�|��S)z�Generate validation.

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

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

        T)�	sort_keysr�)�payload�keyr�r:)r�JWS�sign�
json_dumpsr^)r1rkr�rqs    r�gen_validationzDNS.gen_validation�sD���x�x�}�}�0��O�O�d�O�3�:�:�7�C���0�(.�0�	0r)rurUc���|j|��sy	||j|jjd��k(S#tj
$r }tjd|�Yd}~yd}~wwxYw)zwCheck validation.

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

        )r�Fr�z&Checking validation for DNS failed: %sN)rd�
json_loadsr�rbr�DeserializationErrorrr)r1rurUrs    r�check_validationzDNS.check_validation�sr��� � �%7� �8��	��4�?�?��"�"�)�)�'�2�4�4�
4���(�(�	��L�L�A�5�I���	�s�,A�A5�A0�0A5�DNSResponsec�<�t|j|fi|����S)z�Generate response.

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

        :rtype: DNSResponse

        )ru)r�r�rts   r�gen_responsezDNS.gen_response�s"���&9�d�&9�&9�+�&P��&P�Q�Qr)r�c�:�dj|j|�S)zgDomain name for TXT validation record.

        :param str name: Domain name being validated.

        z{0}.{1})r�r�r�s  rr�zDNS.validation_domain_name�s������
�
�D�1�1r)N)rrr r!rir�r�RS256rg�JWASignaturerr�r�rNr�r�r#r�r:r)rr�r��s����
�C��E�C�MQ�Z�Z�
0�$�(�(�
0��9J�9J�
0�!$�
0�)-���
0��4�8�8������VZ��"	R����	R�C�	R�M�	R�2�3�2�3�2r)r�c��eZdZUdZdZejdejj��Z	eje
d<dddejdefd	�Z
y
)r�z@ACME "dns" challenge response.

    :param JWS validation:

    r�ru)rBrSr�rUrc�:�|j|j|�S)z~Check validation.

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

        :rtype: bool

        )r�ru)r1rSrUs   rr�zDNSResponse.check_validation�s���%�%�d�o�o�7I�J�Jr)N)rrr r!rirrGr�rrur%rgrNr�r:r)rr�r��sU���
�C�%�4�:�:�l�D�H�H�<N�<N�O�J����O�	K�e�	K����	K�d�	Kr)r�)$r!rzrIr��logging�typingrrrrrr�cryptography.hazmat.primitivesr	�josepyrr��	getLoggerrrr
�TypedJSONObjectWithFieldsrr+rr<rP�ABCMetarT�registerrr�r�r�r�r�r:r)r�<module>r�s���,�
����������1���	��	�	�8�	$���-�[�A��9��.�.�9�
��6�6�
��I��4B�i�B�<,�(9�,�d>?��3�;�;�>?�B����5����4���&�%�&��&�8���E�6�E��E�P���$3�
&�$3��$3�N���82�/�82��82�v���K�#�K��Kr)