CasperSecurity

Current Path : /lib/python3/dist-packages/launchpadlib/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/launchpadlib/__pycache__/credentials.cpython-310.pyc

o

�ΔaZy�@s�ddlmZ	eZgd�ZzddlmZWney$ddlmZYnwddl	Z	ddl
Z
ddlZddlmZddl
Z
ddlmZddlZzddlmZWney\ddlmZYnwzddlmZWneytddlmZYnwddlZdd	lmZmZdd
lmZeeur�eZneZddl m!Z!ddl"m#Z$m%Z%m&Z&m'Z'dd
l(m)Z)dZ*dZ+dZ,dZ-dZ.e/e0e1fZ2dd�Z3dd�Z4Gdd�de&�Z5Gdd�de$�Z#Gdd�de$�Z6Gdd�de7�Z8Gdd �d e8�Z9Gd!d"�d"e8�Z:Gd#d$�d$e8�Z;Gd%d&�d&e7�Z<Gd'd(�d(e<�Z=Gd)d*�d*e=�Z>Gd+d,�d,e?�Z@Gd-d.�d.e@�ZAGd/d0�d0e@�ZBGd1d2�d2eB�ZCGd3d4�d4eB�ZDGd5d6�d6eD�ZEGd7d8�d8e@�ZFGd9d:�d:e@�ZGGd;d<�d<e@�ZHGd=d>�d>e@�ZIdS)?�)�print_function)�AccessToken�AnonymousAccessToken� AuthorizeRequestTokenWithBrowser�CredentialStore�RequestTokenAuthorizationEngine�Consumer�Credentials)�StringION)�select)�stdin)�	urlencode)�urljoin)�	b64decode�	b64encode)�parse_qs)�	HTTPError)rr�OAuthAuthorizer�SystemWideConsumer)�urisz+request-tokenz
+access-tokenz+authorize-token�i�cCsttj�dd��S)z�Whether the user has disabled SSL certificate connection.

    Some testing servers have broken certificates.  Rather than raising an
    error, we allow an environment variable,
    ``LP_DISABLE_SSL_CERTIFICATE_VALIDATION`` to disable the check.
    �%LP_DISABLE_SSL_CERTIFICATE_VALIDATIONF)�bool�os�environ�get�rr�:/usr/lib/python3/dist-packages/launchpadlib/credentials.py�$_ssl_certificate_validation_disabledVs
rcCsDt�}tj|d�j|d|t|�d�\}}|jdkrt||��||fS)z�POST to ``url`` with ``headers`` and a body of urlencoded ``params``.

    Wraps it up to make sure we avoid the SSL certificate validation if our
    environment tells us to.  Also, raises an error on non-200 statuses.
    )�"disable_ssl_certificate_validation�POST)�method�headers�body��)r�httplib2�Http�requestr
�statusr)�urlr"�params�
cert_disabled�response�contentrrr�
_http_postcs�
�

r.c@sXeZdZdZdZdZdZdZdZdd�Z	e
d	d
��Zdej
efdd�Zej
fd
d�ZdS)r	z�Standard credentials storage and usage class.

    :ivar consumer: The consumer (application)
    :type consumer: `Consumer`
    :ivar access_token: Access information on behalf of the user
    :type access_token: `AccessToken`
    N�uri�dictz<BR>�
cCs0t�}|�|�|��}t|t�r|�d�}|S)zeTurn this object into a string.

        This should probably be moved into OAuthAuthorizer.
        �utf-8)r
�save�getvalue�
isinstance�unicode_type�encode)�self�sio�
serializedrrr�	serialize�s


zCredentials.serializecCs,|�}t|t�s
|�d�}|�t|��|S)z}Create a `Credentials` object from a serialized string.

        This should probably be moved into OAuthAuthorizer.
        r2)r5r6�decode�loadr
)�cls�value�credentialsrrr�from_string�s


zCredentials.from_stringc	Cs�|jdus	Jd��|jdusJd��t�|�}t|jjddd�}|t}d|i}||jkr1d|d	<t|||�\}}t	|t
�rC|�d
�}||jkr]t�
|�}|durU||d<t�|�|_|St�|�|_d|t|jjf}|durz||j_|d
|7}|S)a�Request an OAuth token to Launchpad.

        Also store the token in self._request_token.

        This method must not be called on an object with no consumer
        specified or if an access token has already been obtained.

        :param context: The context of this token, that is, its scope of
            validity within Launchpad.
        :param web_root: The URL of the website on which the token
            should be requested.
        :token_format: How the token should be
            presented. URI_TOKEN_FORMAT means just return the URL to
            the page that authorizes the token.  DICT_TOKEN_FORMAT
            means return a dictionary describing the token
            and the site's authentication policy.

        :return: If token_format is URI_TOKEN_FORMAT, the URL for the
            user to authorize the `AccessToken` provided by
            Launchpad. If token_format is DICT_TOKEN_FORMAT, a dict of
            information about the new access token.
        NzConsumer not specified.zAccess token already obtained.�	PLAINTEXT�&)�oauth_consumer_key�oauth_signature_method�oauth_signature�Refererzapplication/json�Acceptr2�
lp.contextz%s%s?oauth_token=%sz&lp.context=%s)�consumer�access_tokenr�lookup_web_rootr0�key�request_token_page�DICT_TOKEN_FORMATr.r5�bytesr<�json�loadsr�from_params�_request_tokenrA�authorize_token_page�context)	r8rV�web_root�token_formatr*r)r"r,r-rrr�get_request_token�s>
�




�zCredentials.get_request_tokencCsl|jdus	Jd��t�|�}t|jjd|jjd|jjd�}|t}d|i}t|||�\}}t	�
|�|_dS)adExchange the previously obtained request token for an access token.

        This method must not be called unless get_request_token() has been
        called and completed successfully.

        The access token will be stored as self.access_token.

        :param web_root: The base URL of the website that granted the
            request token.
        Nz5get_request_token() doesn't seem to have been called.rBz&%s)rDrE�oauth_tokenrFrG)rTrrLr0rJrM�secret�access_token_pager.rrArK)r8rWr*r)r"r,r-rrr�'exchange_request_token_for_access_token�s�

�z3Credentials.exchange_request_token_for_access_token)�__name__�
__module__�__qualname__�__doc__rT�URI_TOKEN_FORMATrO�ITEM_SEPARATOR�NEWLINEr;�classmethodrAr�STAGING_WEB_ROOTrYr]rrrrr	rs 


�>�r	c@s(eZdZdZedd��Zedd��ZdS)rzAn OAuth access token.cCs&|d}|d}|�d�}||||�S)z:Create and return a new `AccessToken` from the given dict.rZ�oauth_token_secretrI)r)r>r*rMr[rVrrrrS�s
zAccessToken.from_paramscCs�t|t�s
|�d�}t|dd�}|d}t|�dksJd��|d}|d}t|�dks0Jd	��|d}|�d
�}|durKt|�dksGJd��|d}||||�S)
z<Create and return a new `AccessToken` from the given string.r2F)�keep_blank_valuesrZrz/Query string must have exactly one oauth_token.rrgz*Query string must have exactly one secret.rINz*Query string must have exactly one context)r5r6r<r�lenr)r>�query_stringr*rMr[rVrrrrA�s 


�zAccessToken.from_stringN)r^r_r`rarerSrArrrrr�s
rcs eZdZdZ�fdd�Z�ZS)rzoAn OAuth access token that doesn't authenticate anybody.

    This token can be used for anonymous access.
    cstt|��dd�dS)N�)�superr�__init__�r8��	__class__rrrmszAnonymousAccessToken.__init__)r^r_r`rarm�
__classcell__rrrorrsrc@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)rz�Store OAuth credentials locally.

    This is a generic superclass. To implement a specific way of
    storing credentials locally you'll need to subclass this class,
    and implement `do_save` and `do_load`.
    NcCs
||_dS)aConstructor.

        :param credential_save_failed: A callback to be invoked if the
            save to local storage fails. You should never invoke this
            callback yourself! Instead, you should raise an exception
            from do_save().
        N)�credential_save_failed�r8rrrrrrm&s
zCredentialStore.__init__c
Cs^z	|�||�W|Sty�ty.}z|jdur|�|��WYd}~|Sd}~ww)z�Save the credentials and invoke the callback on failure.

        Do not override this method when subclassing. Override
        do_save() instead.
        N)�do_save�EXPLOSIVE_ERRORS�	Exceptionrr)r8r@�unique_consumer_id�errrr30s�
��zCredentialStore.savecC�t��)z�Store newly-authorized credentials locally for later use.

        :param credentials: A Credentials object to save.
        :param unique_consumer_id: A string uniquely identifying an
            OAuth consumer on a Launchpad instance.
        ��NotImplementedError)r8r@rwrrrrt@szCredentialStore.do_savecCs
|�|�S)a0Retrieve credentials from a local store.

        This method is the inverse of `save`.

        There's no special behavior in this method--it just calls
        `do_load`. There _is_ special behavior in `save`, and this
        way, developers can remember to implement `do_save` and
        `do_load`, not `do_save` and `load`.

        :param unique_key: A string uniquely identifying an OAuth consumer
            on a Launchpad instance.

        :return: A `Credentials` object if one is found in the local
            store, and None otherise.
        )�do_load�r8�
unique_keyrrrr=Is
zCredentialStore.loadcCry)a@Retrieve credentials from a local store.

        This method is the inverse of `do_save`.

        :param unique_key: A string uniquely identifying an OAuth consumer
            on a Launchpad instance.

        :return: A `Credentials` object if one is found in the local
            store, and None otherise.
        rzr}rrrr|[szCredentialStore.do_load�N)	r^r_r`rarmr3rtr=r|rrrrrs

	rcsBeZdZdZdZd
�fdd�	Zedd��Zd	d
�Zdd�Z	�Z
S)�KeyringCredentialStorez�Store credentials in the GNOME keyring or KDE wallet.

    This is a good solution for desktop applications and interactive
    scripts. It doesn't work for non-interactive scripts, or for
    integrating third-party websites into Launchpad.
    s<B64>NFcs,tt|��|�d|_|rt|�|_dSdSr)rlr�rm�	_fallback�MemoryCredentialStore)r8rr�fallbackrorrrmss
�zKeyringCredentialStore.__init__cCsLdt�vr	ddladt�vr$z	ddlmaWdSty#taYdSwdS)aGEnsure the keyring module is imported (postponing side effects).

        The keyring module initializes the environment-dependent backend at
        import time (nasty).  We want to avoid that initialization because it
        may do things like prompt the user to unlock their password store
        (e.g., KWallet).
        �keyringrN�NoKeyringError)r�)�globalsr��keyring.errorsr��ImportError�RuntimeErrorrrrr�_ensure_keyring_importedys
	

��z/KeyringCredentialStore._ensure_keyring_importedc
Cs�|��|��}|jt|�}z
t�d||�d��WdStyF}zttkr/dt	|�vr/�|j
r:|j
�||�n�WYd}~dSd}~ww)z2Store newly-authorized credentials in the keyring.�launchpadlibr2�$No recommended backend was availableN)r�r;�	B64MARKERrr��set_passwordr<r�r��strr�r3)r8r@r~r:rxrrrrt�s"
����zKeyringCredentialStore.do_savec
Cs�|��zt�d|�}Wn'ty3}zttkrdt|�vr�|jr.|j�|�WYd}~S�d}~ww|durst|t	�rB|�
d�}|�|j�r`z
t
|t|j�d��}Wn
ty_YdSwzt�|�}|WStyrYdSwdS)z&Retrieve credentials from the keyring.r�r�N�utf8)r�r��get_passwordr�r�r�r�r=r5r6r7�
startswithr�rri�	TypeErrorr	rArv)r8r~�credential_stringrxr@rrrr|�s@���

��
�zKeyringCredentialStore.do_load)NF)r^r_r`rar�rm�staticmethodr�rtr|rqrrrorr�is
r�c�2eZdZdZd	�fdd�	Zdd�Zdd�Z�ZS)
�UnencryptedFileCredentialStorez�Store credentials unencrypted in a file on disk.

    This is a good solution for scripts that need to run without any
    user interaction.
    Ncstt|��|�||_dSr)rlr�rm�filename)r8r�rrrorrrm�s
�
z'UnencryptedFileCredentialStore.__init__cCs|�|j�dS)zSave the credentials to disk.N)�save_to_pathr��r8r@r~rrrrt�sz&UnencryptedFileCredentialStore.do_savecCs4tj�|j�rt�|j�tjdkst�|j�SdS)zLoad the credentials from disk.rN)r�path�existsr��stat�ST_SIZEr	�load_from_pathr}rrrr|�s
�z&UnencryptedFileCredentialStore.do_loadr�r^r_r`rarmrtr|rqrrrorr��s
r�cr�)
r�z�CredentialStore that stores keys only in memory.

    This can be used to provide a CredentialStore instance without
    actually saving any key to persistent storage.
    Ncstt|��|�i|_dSr)rlr�rm�_credentialsrsrorrrm�s
zMemoryCredentialStore.__init__cCs||j|<dS)z!Store the credentials in our dictN)r�r�rrrrt�szMemoryCredentialStore.do_savecCs|j�|�S)z&Retrieve the credentials from our dict)r�rr}rrrr|�szMemoryCredentialStore.do_loadrr�rrrorr��s
r�c@sPeZdZdZdZ			ddd�Zedd��Zdd	�Zd
d�Z	dd
�Z
dd�ZdS)ra/The superclass of all request token authorizers.

    This base class does not implement request token authorization,
    since that varies depending on how you want the end-user to
    authorize a request token. You'll need to subclass this class and
    implement `make_end_user_authorize_token`.
    �UNAUTHORIZEDNcCs�t�|�|_t�|�|_|dur|durtd��|dur(|dur(td||f��|dur4dg}t|�}nt|�}|}||_||_	|pCg|_
dS)aDBase class initialization.

        :param service_root: The root of the Launchpad instance being
            used.

        :param application_name: The name of the application that
            wants to use launchpadlib. This is used in conjunction
            with a desktop-wide integration.

            If you specify this argument, your values for
            consumer_name and allow_access_levels are ignored.

        :param consumer_name: The OAuth consumer name, for an
            application that wants its own point of integration into
            Launchpad. In almost all cases, you want to specify
            application_name instead and do a desktop-wide
            integration. The exception is when you're integrating a
            third-party website into Launchpad.

        :param allow_access_levels: A list of the Launchpad access
            levels to present to the user. ('READ_PUBLIC' and so on.)
            Your value for this argument will be ignored during a
            desktop-wide integration.
        :type allow_access_levels: A list of strings.
        Nz:You must provide either application_name or consumer_name.zZYou must provide only one of application_name and consumer_name. (You provided %r and %r.)�DESKTOP_INTEGRATION)r�lookup_service_root�service_root�web_root_for_service_rootrW�
ValueErrorrrrJ�application_name�allow_access_levels)r8r�r��
consumer_namer�rJrrrrm	s( ���
z(RequestTokenAuthorizationEngine.__init__cCs|jjd|jS)z7Return a string identifying this consumer on this host.�@)rJrMr�rnrrrrwIsz2RequestTokenAuthorizationEngine.unique_consumer_idcCs>dt|f}d}t|j�dkr|||�|j�7}t|j|�S)z�Return the authorization URL for a request token.

        This is the URL the end-user must visit to authorize the
        token. How exactly does this happen? That depends on the
        subclass implementation.
        z%s?oauth_token=%sz&allow_permission=r)rUrir��joinrrW)r8�
request_token�page�allow_permissionrrr�authorization_urlNs�z1RequestTokenAuthorizationEngine.authorization_urlcCs6|�|�}|�||�|jdurdS|�||j�|S)adAuthorize a token and associate it with the given credentials.

        If the credential store runs into a problem storing the
        credential locally, the `credential_save_failed` callback will
        be invoked. The callback will not be invoked if there's a
        problem authorizing the credentials.

        :param credentials: A `Credentials` object. If the end-user
            authorizes these credentials, this object will have its
            .access_token property set.

        :param credential_store: A `CredentialStore` object. If the
            end-user authorizes the credentials, they will be
            persisted locally using this object.

        :return: If the credentials are successfully authorized, the
            return value is the `Credentials` object originally passed
            in. Otherwise the return value is None.
        N)rY�make_end_user_authorize_tokenrKr3rw)r8r@�credential_store�request_token_stringrrr�__call__]s

z(RequestTokenAuthorizationEngine.__call__cCs|j|jtjd�}|dS)z\Get a new request token from the server.

        :param return: The request token.
        )rWrXrZ)rYrWr	rO)r8r@�authorization_jsonrrrrY{s�z1RequestTokenAuthorizationEngine.get_request_tokencCry)a5Authorize the given request token using the given credentials.

        Your subclass must implement this method: it has no default
        implementation.

        Because an access token may expire or be revoked in the middle
        of a session, this method may be called at arbitrary points in
        a launchpadlib session, or even multiple times during a single
        session (with a different request token each time).

        In most cases, however, this method will be called at the
        beginning of a launchpadlib session, or not at all.
        rz)r8r@r�rrrr��sz=RequestTokenAuthorizationEngine.make_end_user_authorize_token�NNN)r^r_r`ra�UNAUTHORIZED_ACCESS_LEVELrm�propertyrwr�r�rYr�rrrrr�s
�@

rc@s@eZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�AuthorizeRequestTokenWithURLz�Authorize using a URL.

    This authorizer simply shows the URL for the user to open for
    authorization, and waits until the server responds.
    z�Please open this authorization page:
 (%s)
in your browser. Use your browser to authorize
this program to access Launchpad on your behalf.z.Press Enter after authorizing in your browser.cCst|�dS)z�Display a message.

        By default, prints the message to standard output. The message
        does not require any user interaction--it's solely
        informative.
        N)�print)r8�messagerrr�output�sz#AuthorizeRequestTokenWithURL.outputcCs|�|j|�dS)�Notify the end-user of the URL.N)r��WAITING_FOR_USER)r8r�rrr�!notify_end_user_authorization_url�sz>AuthorizeRequestTokenWithURL.notify_end_user_authorization_urlc
Cspz|�|j�Wn*ty2}z|jjdkrt|j��|jjdkr)td�t|�t|j��d}~ww|j	duS)z Check if the end-user authorizedi�i�z#Unexpected response from Launchpad:N)
r]rWrr,r(�EndUserDeclinedAuthorizationr-r��EndUserNoAuthorizationrK)r8r@rxrrr�check_end_user_authorization�s

��
z9AuthorizeRequestTokenWithURL.check_end_user_authorizationcCs"|�|j�t��|�|�dS)�"Wait for the end-user to authorizeN)r��WAITING_FOR_LAUNCHPADr�readliner�)r8r@rrr�wait_for_end_user_authorization�sz<AuthorizeRequestTokenWithURL.wait_for_end_user_authorizationcCs"|�|�}|�|�|�|�dS)z2Have the end-user authorize the token using a URL.N)r�r�r�)r8r@r�r�rrrr��s

z:AuthorizeRequestTokenWithURL.make_end_user_authorize_tokenN)r^r_r`rar�r�r�r�r�r�r�rrrrr��s�	r�csPeZdZdZdZdZdZdZdZ			d�fdd	�	Z	�fd
d�Z
dd
�Z�ZS)raSAuthorize using a URL that pops-up automatically in a browser.

    This authorizer simply opens up the end-user's web browser to a
    Launchpad URL and lets the end-user authorize the request token
    themselves.

    This is the same as its superclass, except this class also
    performs the browser automatic opening of the URL.
    z�The authorization page:
 (%s)
should be opening in your browser. Use your browser to authorize
this program to access Launchpad on your behalf.z/Press Enter to continue or wait (%d) seconds...�)zwww-browser�links�links2�lynx�elinkszelinks-lite�netrik�w3mz5Waiting to hear from Launchpad about your decision...Ncstt|��||d|�dS)aoConstructor.

        :param service_root: See `RequestTokenAuthorizationEngine`.
        :param application_name: See `RequestTokenAuthorizationEngine`.
        :param consumer_name: The value of this argument is
            ignored. If we have the capability to open the end-user's
            web browser, we must be running on the end-user's computer,
            so we should do a full desktop integration.
        :param credential_save_failed: See `RequestTokenAuthorizationEngine`.
        :param allow_access_levels: The value of this argument is
            ignored, for the same reason as consumer_name.
        N)rlrrm)r8r�r�r�rrr�rorrrm�s
�z)AuthorizeRequestTokenWithBrowser.__init__cs�tt|��|�zt��}t|dd�}||jv}Wntjy'd}d}Ynw|rE|�|j	|j
�ttggg|j
�\}}}|rEt�
�|durPt�|�dSdS)r��basenameNF)rlrr��
webbrowserr�getattr�TERMINAL_BROWSERS�Errorr��TIMEOUT_MESSAGE�TIMEOUTrrr��open)r8r��browser_obj�browser�console_browser�rlist�_rorrr�
s(���zBAuthorizeRequestTokenWithBrowser.notify_end_user_authorization_urlcCs~|�|j�t��}|jdur=t�t�z
|�|�rWdSWn	ty'Ynwt��|tkr6t	dt��|jdusdSdS)r�NzTimed out after %d seconds.)
r�r��timerK�sleep�access_token_poll_timer�r��access_token_poll_timeout�TokenAuthorizationTimedOut)r8r@�
start_timerrrr�&s 


����z@AuthorizeRequestTokenWithBrowser.wait_for_end_user_authorizationr�)
r^r_r`rar�r�r�r�r�rmr�r�rqrrrorr�s���rc@�eZdZdS)�TokenAuthorizationExceptionN�r^r_r`rrrrr�7�r�c@r�)�RequestTokenAlreadyAuthorizedNr�rrrrr�;r�r�c@�eZdZdZdS)�EndUserAuthorizationFailedz?Superclass exception for all failures of end-user authorizationN�r^r_r`rarrrrr�?�r�c@r�)r�zEnd-user declined authorizationNr�rrrrr�Er�r�c@r�)r�z*End-user did not perform any authorizationNr�rrrrr�Kr�r�c@r�)r�z<End-user did not perform any authorization in timeout periodNr�rrrrr�Qr�r�c@r�)�ClientErrorNr�rrrrr�Wr�r�c@r�)�ServerErrorNr�rrrrr�[r�r�c@r�)�NoLaunchpadAccountNr�rrrrr�_r�r�c@r�)�TooManyAuthenticationFailuresNr�rrrrr�cr�r�)J�
__future__r�type�
__metaclass__�__all__�	cStringIOr
r��ior%rQrrr��sysrr��urllib.parser
�urllibr�urlparser��base64rr�six.moves.urllib.parserrPr��unicoder6�lazr.restfulclient.errorsr�"lazr.restfulclient.authorize.oauthr�_AccessTokenrrrr�rrNr\rUr�r��MemoryError�KeyboardInterrupt�
SystemExitrurr.r	r�objectrr�r�r�rr�rrvr�r�r�r�r�r�r�r�r�r�rrrr�<module>s�
���

 
Kf;f
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY