403Webshell
Server IP : 192.158.238.246  /  Your IP : 3.145.177.28
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python37/lib/python3.7/site-packages/paste/auth/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python37/lib/python3.7/site-packages/paste/auth/__pycache__/cookie.cpython-37.pyc
B

���]�>�@sldZddlZddlZddlZddlZddlZyddlmZWnek
rXddl	ZYnXddl
mZdd�Ze
e�dde����Zee
ee����Zdd	d
dgZdd
�eD�Ze��efdd�Zdd�ZGdd�de�Zd�dd
�edd�D��Zdd�ZGdd�de�ZGdd�de�Z Gdd�de�Z!e!Z"d'd#d$�Z#dddgZ$d%e%k�rhddl&Z&e&j'e&j(d&�dS)(a
Cookie "Saved" Authentication

This authentication middleware saves the current REMOTE_USER,
REMOTE_SESSION, and any other environment variables specified in a
cookie so that it can be retrieved during the next request without
requiring re-authentication. This uses a session cookie on the client
side (so it goes away when the user closes their window) and does
server-side expiration.

Following is a very simple example where a form is presented asking for
a user name (no actual checking), and dummy session identifier (perhaps
corresponding to a database session id) is stored in the cookie.

::

  >>> from paste.httpserver import serve
  >>> from paste.fileapp import DataApp
  >>> from paste.httpexceptions import *
  >>> from paste.auth.cookie import AuthCookieHandler
  >>> from paste.wsgilib import parse_querystring
  >>> def testapp(environ, start_response):
  ...     user = dict(parse_querystring(environ)).get('user','')
  ...     if user:
  ...         environ['REMOTE_USER'] = user
  ...         environ['REMOTE_SESSION'] = 'a-session-id'
  ...     if environ.get('REMOTE_USER'):
  ...         page = '<html><body>Welcome %s (%s)</body></html>'
  ...         page %= (environ['REMOTE_USER'], environ['REMOTE_SESSION'])
  ...     else:
  ...         page = ('<html><body><form><input name="user" />'
  ...                 '<input type="submit" /></form></body></html>')
  ...     return DataApp(page, content_type="text/html")(
  ...                    environ, start_response)
  >>> serve(AuthCookieHandler(testapp))
  serving on...

�N)�sha1)�get_cookiescCst�dt�|��S)Nz
%Y%m%d%H%M)�time�strftime�gmtime)�value�r�B/opt/alt/python37/lib/python3.7/site-packages/paste/auth/cookie.py�	make_time5sr
�x)�\z\x5c)�"z\x22)�=z\x3d)�;z\x3bcCsg|]\}}||f�qSrr)�.0�k�vrrr	�
<listcomp>>srcCstdd�|t|��S)NcSs|�|d|d�S)Nr�)�replace)�a�brrr	�<lambda>A�zencode.<locals>.<lambda>)�reduce�str)�sZsublistrrr	�encode@srcCs
t|t�S)N)r�_decode)rrrr	rBrrc@seZdZdd�ZdS)�CookieTooLargecCst�d�||_||_dS)Nz*Signed cookie exceeds maximum size of 4096)�RuntimeError�__init__�content�cookie)�selfr"r#rrr	r!Es
zCookieTooLarge.__init__N)�__name__�
__module__�__qualname__r!rrrr	rDsr�cCsg|]}t|��qSr)�chr)rrrrr	rJs�cCsd�t�td��S)z returns a 64 byte secret r(�@)�join�random�sample�
_all_charsrrrr	�
new_secretKsr0c@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�AuthCookieSignera
    save/restore ``environ`` entries via digially signed cookie

    This class converts content into a timed and digitally signed
    cookie, as well as having the facility to reverse this procedure.
    If the cookie, after the content is encoded and signed exceeds the
    maximum length (4096), then CookieTooLarge exception is raised.

    The timeout of the cookie is handled on the server side for a few
    reasons.  First, if a 'Expires' directive is added to a cookie, then
    the cookie becomes persistent (lasting even after the browser window
    has closed). Second, the user's clock may be wrong (perhaps
    intentionally). The timeout is specified in minutes; and expiration
    date returned is rounded to one second.

    Constructor Arguments:

        ``secret``

            This is a secret key if you want to syncronize your keys so
            that the cookie will be good across a cluster of computers.
            It is recommended via the HMAC specification (RFC 2104) that
            the secret key be 64 bytes since this is the block size of
            the hashing.  If you do not provide a secret key, a random
            one is generated each time you create the handler; this
            should be sufficient for most cases.

        ``timeout``

            This is the time (in minutes) from which the cookie is set
            to expire.  Note that on each request a new (replacement)
            cookie is sent, hence this is effectively a session timeout
            parameter for your entire cluster.  If you do not provide a
            timeout, it is set at 30 minutes.

        ``maxlen``

            This is the maximum size of the *signed* cookie; hence the
            actual content signed will be somewhat less.  If the cookie
            goes over this size, a ``CookieTooLarge`` exception is
            raised so that unexpected handling of cookies on the client
            side are avoided.  By default this is set at 4k (4096 bytes),
            which is the standard cookie size limit.

    NcCs:|pd|_t|t�r td|��|p&d|_|p2t�|_dS)N�z5Timeout must be a number (minutes), not a string (%r)i)�timeout�
isinstance�
basestring�
ValueError�maxlenr0�secret)r$r8r3r7rrr	r!}s


zAuthCookieSigner.__init__cCsxt�t�|j|t���tt��d|j	�|�}|�
dd��
dd�}|�
dd��
dd�}t|�|jkrtt
||��|S)	z�
        Sign the content returning a valid cookie (that does not
        need to be escaped and quoted).  The expiration of this
        cookie is handled server-side in the auth() function.
        �<�/�_r�~�
r(�
)�base64�encodestring�hmac�newr8r�digestr
rr3r�lenr7r)r$r"r#rrr	�sign�s(
zAuthCookieSigner.signcCsxt�|�dd��dd��}|dt�}|tt�}|td�}|t�|j|t��	�krtt
|�t
tt����krt|SndS)z�
        Authenticate the cooke using the signature, verify that it
        has not expired; and return the cookie's content
        r;r:r<rN)
r?�decodestringr�_signature_size�_header_sizerArBr8rrC�intr
r)r$r#�decode�	signatureZexpiresr"rrr	�auth�szAuthCookieSigner.auth)NNN)r%r&r'�__doc__r!rErLrrrr	r1Os-
	r1c@s eZdZdZdd�Zdd�ZdS)�AuthCookieEnvironaH
    a list of environment keys to be saved via cookie

    An instance of this object, found at ``environ['paste.auth.cookie']``
    lists the `environ` keys that were restored from or will be added
    to the digially signed cookie.  This object can be accessed from an
    `environ` variable by using this module's name.
    cCst�||�||_dS)N)�listr!�handler)r$rP�scanlistrrr	r!�szAuthCookieEnviron.__init__cCs ||krdSt�|t|��dS)N)rO�appendr)r$rrrr	rR�szAuthCookieEnviron.appendN)r%r&r'rMr!rRrrrr	rN�srNc@s2eZdZdZdZdZeZeZ	d	dd�Z
dd�ZdS)
�AuthCookieHandlera�
    the actual handler that should be put in your middleware stack

    This middleware uses cookies to stash-away a previously authenticated
    user (and perhaps other variables) so that re-authentication is not
    needed.  This does not implement sessions; and therefore N servers
    can be syncronized to accept the same saved authentication if they
    all use the same cookie_name and secret.

    By default, this handler scans the `environ` for the REMOTE_USER
    and REMOTE_SESSION key; if found, it is stored. It can be
    configured to scan other `environ` keys as well -- but be careful
    not to exceed 2-3k (so that the encoded and signed cookie does not
    exceed 4k). You can ask it to handle other environment variables
    by doing:

       ``environ['paste.auth.cookie'].append('your.environ.variable')``


    Constructor Arguments:

        ``application``

            This is the wrapped application which will have access to
            the ``environ['REMOTE_USER']`` restored by this middleware.

        ``cookie_name``

            The name of the cookie used to store this content, by default
            it is ``PASTE_AUTH_COOKIE``.

        ``scanlist``

            This is the initial set of ``environ`` keys to
            save/restore to the signed cookie.  By default is consists
            only of ``REMOTE_USER`` and ``REMOTE_SESSION``; any tuple
            or list of environment keys will work.  However, be
            careful, as the total saved size is limited to around 3k.

        ``signer``

            This is the signer object used to create the actual cookie
            values, by default, it is ``AuthCookieSigner`` and is passed
            the remaining arguments to this function: ``secret``,
            ``timeout``, and ``maxlen``.

    At this time, each cookie is individually signed.  To store more
    than the 4k of data; it is possible to sub-class this object to
    provide different ``environ_name`` and ``cookie_name``
    zpaste.auth.cookie�PASTE_AUTH_COOKIENcCs8|s|�|||�}||_|pd|_||_|p0|j|_dS)N)�REMOTE_USER�REMOTE_SESSION)�signer_class�signerrQ�application�cookie_name)r$rYrZrQrXr8r3r7rrr	r!�s
zAuthCookieHandler.__init__c
s��j�krtd������j�}t��}|��j�r��j�|�jj	�}|r�x`|�
d�D]R}|�
d�\}}t|�}||kr�|�|�|�kr�qXt|��|<d|krXd�d<qXW|��j<d�kr�t
�d�d���fd	d
�	}	���|	�S)NzAuthCookie already installed!rrrUr#Z	AUTH_TYPEzpaste.httpexceptionsz�Since paste.httpexceptions is hooked in your processing chain before paste.auth.cookie, if an HTTPRedirection is raised, the cookies this module sets will not be included in your response.
cs����j�}|rt|�j�s t�g}xT|D]L}��|�}|dk	r*t|�tk	r\td||f��|�dt	|�t	|�f�q*W|r�d�
|�}�j�|�}d�j
|f}d�dkr�|d7}|�d	|f��|||�S)
z�
            Scan the environment for keys specified in the scanlist,
            pack up their values, signs the content and issues a cookie.
            NzUThe value of the environmental variable %r is not a str (only str is allowed; got %r)z%s=%srz%s=%s; Path=/;�httpszwsgi.url_schemez secure;z
Set-Cookie)�get�environ_namer4�
environ_class�AssertionError�typerr6rRrr,rXrErZ)�statusZresponse_headers�exc_inforQr"rrr#)�environr$�start_responserr	�
response_hooks&


z1AuthCookieHandler.__call__.<locals>.response_hook)N)r]r_r^rQrZhas_keyrZrXrLr�splitrJrR�warnings�warnrY)
r$rcrdrQZjarr"�pairrrrer)rcr$rdr	�__call__s,



zAuthCookieHandler.__call__)NNNNNN)r%r&r'rMr]rZr1rWrNr^r!rjrrrr	rS�s2
rSrT�rUrVr2�cCs�t|t�r|��}|dkr,|�d�r,|d}yt|�}Wn tk
rXtd|��YnXyt|�}Wn tk
r�td|��YnXt||||||d�S)a�
    This middleware uses cookies to stash-away a previously
    authenticated user (and perhaps other variables) so that
    re-authentication is not needed.  This does not implement
    sessions; and therefore N servers can be syncronized to accept the
    same saved authentication if they all use the same cookie_name and
    secret.

    By default, this handler scans the `environ` for the REMOTE_USER
    and REMOTE_SESSION key; if found, it is stored. It can be
    configured to scan other `environ` keys as well -- but be careful
    not to exceed 2-3k (so that the encoded and signed cookie does not
    exceed 4k). You can ask it to handle other environment variables
    by doing:

       ``environ['paste.auth.cookie'].append('your.environ.variable')``

    Configuration:

        ``cookie_name``

            The name of the cookie used to store this content, by
            default it is ``PASTE_AUTH_COOKIE``.

        ``scanlist``

            This is the initial set of ``environ`` keys to
            save/restore to the signed cookie.  By default is consists
            only of ``REMOTE_USER`` and ``REMOTE_SESSION``; any
            space-separated list of environment keys will work.
            However, be careful, as the total saved size is limited to
            around 3k.

        ``secret``

            The secret that will be used to sign the cookies.  If you
            don't provide one (and none is set globally) then a random
            secret will be created.  Each time the server is restarted
            a new secret will then be created and all cookies will
            become invalid!  This can be any string value.

        ``timeout``

            The time to keep the cookie, expressed in minutes.  This
            is handled server-side, so a new cookie with a new timeout
            is added to every response.

        ``maxlen``

            The maximum length of the cookie that is sent (default 4k,
            which is a typical browser maximum)
        
    Nr8z'Bad value for timeout (must be int): %rz&Bad value for maxlen (must be int): %r)rZrQr8r3r7)r4r5rfr\rIr6rS)ZappZglobal_confrZrQr8r3r7rrr	�make_auth_cookie7s">
rm�__main__)Zoptionflags)rTrkNr2rl))rMrAr?r-rrg�hashlibr�ImportErrorZshaZ
paste.requestrr
rDrBrCrGrH�_encoder�reverserrJr rr,�ranger/r0�objectr1rOrNrSZ
middlewarerm�__all__r%ZdoctestZtestmod�ELLIPSISrrrr	�<module>*s>(_u
H



Youez - 2016 - github.com/yon3zu
LinuXploit