| Server IP : 23.254.227.96 / Your IP : 216.73.216.21 Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64 User : viralblo ( 1001) PHP Version : 8.1.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /lib/python3.6/site-packages/oauthlib/oauth1/rfc5849/__pycache__/ |
Upload File : |
3
,�[�v � @ s@ d Z ddlmZmZ ddlZddlmZmZ G dd� de�Z dS )z�
oauthlib.oauth1.rfc5849
~~~~~~~~~~~~~~
This module is an implementation of various logic needed
for signing and checking OAuth 1.0 RFC 5849 requests.
� )�absolute_import�unicode_literalsN� )�SIGNATURE_METHODS�utilsc @ s� e Zd ZdZdd� Zedd� �Zedd� �Zedd � �Zed
d� �Z edd
� �Z
edd� �Zedd� �Zedd� �Z
edd� �Zedd� �Zdd� Zdd� Zdd� Zdd� Zd d!� Zd"d#� Zd$d%� Zed&d'� �Zed(d)� �Zed*d+� �Zd,d-� Zd.d/� Zd0d1� Zd2d3� Zd4d5� Zd6d7� Zd8d9� Z d:d;� Z!d<d=� Z"d>d?� Z#d@dA� Z$dWdCdD�Z%dEdF� Z&dGdH� Z'dXdIdJ�Z(dKdL� Z)dMdN� Z*dOdP� Z+dQdR� Z,dSdT� Z-dUdV� Z.dBS )Y�RequestValidatora� A validator/datastore interaction base class for OAuth 1 providers.
OAuth providers should inherit from RequestValidator and implement the
methods and properties outlined below. Further details are provided in the
documentation for each method and property.
Methods used to check the format of input parameters. Common tests include
length, character set, membership, range or pattern. These tests are
referred to as `whitelisting or blacklisting`_. Whitelisting is better
but blacklisting can be usefull to spot malicious activity.
The following have methods a default implementation:
- check_client_key
- check_request_token
- check_access_token
- check_nonce
- check_verifier
- check_realms
The methods above default to whitelist input parameters, checking that they
are alphanumerical and between a minimum and maximum length. Rather than
overloading the methods a few properties can be used to configure these
methods.
* @safe_characters -> (character set)
* @client_key_length -> (min, max)
* @request_token_length -> (min, max)
* @access_token_length -> (min, max)
* @nonce_length -> (min, max)
* @verifier_length -> (min, max)
* @realms -> [list, of, realms]
Methods used to validate/invalidate input parameters. These checks usually
hit either persistent or temporary storage such as databases or the
filesystem. See each methods documentation for detailed usage.
The following methods must be implemented:
- validate_client_key
- validate_request_token
- validate_access_token
- validate_timestamp_and_nonce
- validate_redirect_uri
- validate_requested_realms
- validate_realms
- validate_verifier
- invalidate_request_token
Methods used to retrieve sensitive information from storage.
The following methods must be implemented:
- get_client_secret
- get_request_token_secret
- get_access_token_secret
- get_rsa_key
- get_realms
- get_default_realms
- get_redirect_uri
Methods used to save credentials.
The following methods must be implemented:
- save_request_token
- save_verifier
- save_access_token
Methods used to verify input parameters. This methods are used during
authorizing request token by user (AuthorizationEndpoint), to check if
parameters are valid. During token authorization request is not signed,
thus 'validation' methods can not be used. The following methods must be
implemented:
- verify_realms
- verify_request_token
To prevent timing attacks it is necessary to not exit early even if the
client key or resource owner key is invalid. Instead dummy values should
be used during the remaining verification process. It is very important
that the dummy client and token are valid input parameters to the methods
get_client_secret, get_rsa_key and get_(access/request)_token_secret and
that the running time of those methods when given a dummy value remain
equivalent to the running time when given a valid client/resource owner.
The following properties must be implemented:
* @dummy_client
* @dummy_request_token
* @dummy_access_token
Example implementations have been provided, note that the database used is
a simple dictionary and serves only an illustrative purpose. Use whichever
database suits your project and how to access it is entirely up to you.
The methods are introduced in an order which should make understanding
their use more straightforward and as such it could be worth reading what
follows in chronological order.
.. _`whitelisting or blacklisting`: https://www.schneier.com/blog/archives/2011/01/whitelisting_vs.html
c C s d S )N� )�selfr r �'/usr/lib/python3.6/request_validator.py�__init__s s zRequestValidator.__init__c C s t S )N)r )r r r r
�allowed_signature_methodsv s z*RequestValidator.allowed_signature_methodsc C s
t tj�S )N)�setr ZUNICODE_ASCII_CHARACTER_SET)r r r r
�safe_charactersz s z RequestValidator.safe_charactersc C s dS )N� � )r r r )r r r r
�client_key_length~ s z"RequestValidator.client_key_lengthc C s dS )Nr r )r r r )r r r r
�request_token_length� s z%RequestValidator.request_token_lengthc C s dS )Nr r )r r r )r r r r
�access_token_length� s z$RequestValidator.access_token_lengthc C s dS )NiX r )r r r r
�timestamp_lifetime� s z#RequestValidator.timestamp_lifetimec C s dS )Nr r )r r r )r r r r
�nonce_length� s zRequestValidator.nonce_lengthc C s dS )Nr r )r r r )r r r r
�verifier_length� s z RequestValidator.verifier_lengthc C s g S )Nr )r r r r
�realms� s zRequestValidator.realmsc C s dS )NTr )r r r r
�enforce_ssl� s zRequestValidator.enforce_sslc C s4 | j \}}t|�| jko2|t|� ko.|kS S )zCheck that the client key only contains safe characters
and is no shorter than lower and no longer than upper.
)r r
r �len)r �
client_key�lower�upperr r r
�check_client_key� s
z!RequestValidator.check_client_keyc C s4 | j \}}t|�| jko2|t|� ko.|kS S )z�Checks that the request token contains only safe characters
and is no shorter than lower and no longer than upper.
)r r
r r )r �
request_tokenr r r r r
�check_request_token� s
z$RequestValidator.check_request_tokenc C s4 | j \}}t|�| jko2|t|� ko.|kS S )z{Checks that the token contains only safe characters
and is no shorter than lower and no longer than upper.
)r r
r r )r r r r r r r
�check_access_token� s
z#RequestValidator.check_access_tokenc C s4 | j \}}t|�| jko2|t|� ko.|kS S )z�Checks that the nonce only contains only safe characters
and is no shorter than lower and no longer than upper.
)r r
r r )r �noncer r r r r
�check_nonce� s
zRequestValidator.check_noncec C s4 | j \}}t|�| jko2|t|� ko.|kS S )z~Checks that the verifier contains only safe characters
and is no shorter than lower and no longer than upper.
)r r
r r )r �verifierr r r r r
�check_verifier� s
zRequestValidator.check_verifierc s t � fdd�|D ��S )z4Check that the realm is one of a set allowed realms.c 3 s | ]}|� j kV qd S )N)r )�.0�r)r r r
� <genexpr>� s z0RequestValidator.check_realms.<locals>.<genexpr>)�all)r r r )r r
�check_realms� s zRequestValidator.check_realmsc C s dj t| �|�}t|�S )z�
Returns a NotImplementedError for a function that should be implemented.
:param fn: name of the function
z)Missing function implementation in {}: {})�format�type�NotImplementedError)r �fn�mr r r
�_subclass_must_implement� s z)RequestValidator._subclass_must_implementc C s | j d��dS )aT Dummy client used when an invalid client key is supplied.
:returns: The dummy client key string.
The dummy client should be associated with either a client secret,
a rsa key or both depending on which signature methods are supported.
Providers should make sure that
get_client_secret(dummy_client)
get_rsa_key(dummy_client)
return a valid secret or key for the dummy client.
This method is used by
* AccessTokenEndpoint
* RequestTokenEndpoint
* ResourceEndpoint
* SignatureOnlyEndpoint
�dummy_clientN)r/ )r r r r
r0 � s zRequestValidator.dummy_clientc C s | j d��dS )am Dummy request token used when an invalid token was supplied.
:returns: The dummy request token string.
The dummy request token should be associated with a request token
secret such that get_request_token_secret(.., dummy_request_token)
returns a valid secret.
This method is used by
* AccessTokenEndpoint
�dummy_request_tokenN)r/ )r r r r
r1 � s z$RequestValidator.dummy_request_tokenc C s | j d��dS )ae Dummy access token used when an invalid token was supplied.
:returns: The dummy access token string.
The dummy access token should be associated with an access token
secret such that get_access_token_secret(.., dummy_access_token)
returns a valid secret.
This method is used by
* ResourceEndpoint
�dummy_access_tokenN)r/ )r r r r
r2 � s z#RequestValidator.dummy_access_tokenc C s | j d��dS )a� Retrieves the client secret associated with the client key.
:param client_key: The client/consumer key.
:param request: An oauthlib.common.Request object.
:returns: The client secret as a string.
This method must allow the use of a dummy client_key value.
Fetching the secret using the dummy key must take the same amount of
time as fetching a secret for a valid client::
# Unlikely to be near constant time as it uses two database
# lookups for a valid client, and only one for an invalid.
from your_datastore import ClientSecret
if ClientSecret.has(client_key):
return ClientSecret.get(client_key)
else:
return 'dummy'
# Aim to mimic number of latency inducing operations no matter
# whether the client is valid or not.
from your_datastore import ClientSecret
return ClientSecret.get(client_key, 'dummy')
Note that the returned key must be in plaintext.
This method is used by
* AccessTokenEndpoint
* RequestTokenEndpoint
* ResourceEndpoint
* SignatureOnlyEndpoint
�get_client_secretN)r/ )r r �requestr r r
r3
s !z"RequestValidator.get_client_secretc C s | j d��dS )a� Retrieves the shared secret associated with the request token.
:param client_key: The client/consumer key.
:param token: The request token string.
:param request: An oauthlib.common.Request object.
:returns: The token secret as a string.
This method must allow the use of a dummy values and the running time
must be roughly equivalent to that of the running time of valid values::
# Unlikely to be near constant time as it uses two database
# lookups for a valid client, and only one for an invalid.
from your_datastore import RequestTokenSecret
if RequestTokenSecret.has(client_key):
return RequestTokenSecret.get((client_key, request_token))
else:
return 'dummy'
# Aim to mimic number of latency inducing operations no matter
# whether the client is valid or not.
from your_datastore import RequestTokenSecret
return ClientSecret.get((client_key, request_token), 'dummy')
Note that the returned key must be in plaintext.
This method is used by
* AccessTokenEndpoint
�get_request_token_secretN)r/ )r r �tokenr4 r r r
r5 - s z)RequestValidator.get_request_token_secretc C s | j d��dS )a� Retrieves the shared secret associated with the access token.
:param client_key: The client/consumer key.
:param token: The access token string.
:param request: An oauthlib.common.Request object.
:returns: The token secret as a string.
This method must allow the use of a dummy values and the running time
must be roughly equivalent to that of the running time of valid values::
# Unlikely to be near constant time as it uses two database
# lookups for a valid client, and only one for an invalid.
from your_datastore import AccessTokenSecret
if AccessTokenSecret.has(client_key):
return AccessTokenSecret.get((client_key, request_token))
else:
return 'dummy'
# Aim to mimic number of latency inducing operations no matter
# whether the client is valid or not.
from your_datastore import AccessTokenSecret
return ClientSecret.get((client_key, request_token), 'dummy')
Note that the returned key must be in plaintext.
This method is used by
* ResourceEndpoint
�get_access_token_secretN)r/ )r r r6 r4 r r r
r7 M s z(RequestValidator.get_access_token_secretc C s | j d��dS )a� Get the default realms for a client.
:param client_key: The client/consumer key.
:param request: An oauthlib.common.Request object.
:returns: The list of default realms associated with the client.
The list of default realms will be set during client registration and
is outside the scope of OAuthLib.
This method is used by
* RequestTokenEndpoint
�get_default_realmsN)r/ )r r r4 r r r
r8 m s z#RequestValidator.get_default_realmsc C s | j d��dS )aG Get realms associated with a request token.
:param token: The request token string.
:param request: An oauthlib.common.Request object.
:returns: The list of realms associated with the request token.
This method is used by
* AuthorizationEndpoint
* AccessTokenEndpoint
�
get_realmsN)r/ )r r6 r4 r r r
r9 } s zRequestValidator.get_realmsc C s | j d��dS )a Get the redirect URI associated with a request token.
:param token: The request token string.
:param request: An oauthlib.common.Request object.
:returns: The redirect URI associated with the request token.
It may be desirable to return a custom URI if the redirect is set to "oob".
In this case, the user will be redirected to the returned URI and at that
endpoint the verifier can be displayed.
This method is used by
* AuthorizationEndpoint
�get_redirect_uriN)r/ )r r6 r4 r r r
r: � s z!RequestValidator.get_redirect_uric C s | j d��dS )a� Retrieves a previously stored client provided RSA key.
:param client_key: The client/consumer key.
:param request: An oauthlib.common.Request object.
:returns: The rsa public key as a string.
This method must allow the use of a dummy client_key value. Fetching
the rsa key using the dummy key must take the same amount of time
as fetching a key for a valid client. The dummy key must also be of
the same bit length as client keys.
Note that the key must be returned in plaintext.
This method is used by
* AccessTokenEndpoint
* RequestTokenEndpoint
* ResourceEndpoint
* SignatureOnlyEndpoint
�get_rsa_keyN)r/ )r r r4 r r r
r; � s zRequestValidator.get_rsa_keyc C s | j d��dS )a- Invalidates a used request token.
:param client_key: The client/consumer key.
:param request_token: The request token string.
:param request: An oauthlib.common.Request object.
:returns: None
Per `Section 2.3`__ of the spec:
"The server MUST (...) ensure that the temporary
credentials have not expired or been used before."
.. _`Section 2.3`: https://tools.ietf.org/html/rfc5849#section-2.3
This method should ensure that provided token won't validate anymore.
It can be simply removing RequestToken from storage or setting
specific flag that makes it invalid (note that such flag should be
also validated during request token validation).
This method is used by
* AccessTokenEndpoint
�invalidate_request_tokenN)r/ )r r r r4 r r r
r<