%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python27/lib/python2.7/site-packages/paste/auth/
Upload File :
Create Path :
Current File : //opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pyc

�
|��Wc@sdZddlmZddlTyddlmZWn!ek
rWddlmZnXddlZddlZddl	m
Zd�Zd�Z
d	�Zd
efd��YZdefd
��YZeZddgZd�ZdekrddlZejdej�ndS(s
Digest HTTP/1.1 Authentication

This module implements ``Digest`` authentication as described by
RFC 2617 [1]_ .

Basically, you just put this module before your application, and it
takes care of requesting and handling authentication requests.  This
module has been tested with several common browsers "out-in-the-wild".

>>> from paste.wsgilib import dump_environ
>>> from paste.httpserver import serve
>>> # from paste.auth.digest import digest_password, AuthDigestHandler
>>> realm = 'Test Realm'
>>> def authfunc(environ, realm, username):
...     return digest_password(realm, username, username)
>>> serve(AuthDigestHandler(dump_environ, realm, authfunc))
serving on...

This code has not been audited by a security expert, please use with
caution (or better yet, report security holes). At this time, this
implementation does not provide for further challenges, nor does it
support Authentication-Info header.  It also uses md5, and an option
to use sha would be a good thing.

.. [1] http://www.faqs.org/rfcs/rfc2617.html
i����(tHTTPUnauthorized(t*(tmd5N(tquoteccs�d}x�|jd�D]x}y/|jd�dkrJd||f}wnWn/tk
r||dkrs|}qq}t�nX|j�V|}qW|j�Vt�dS(s> split a digest auth string into individual key=value strings t,t"is%s,%sN(tNonetsplittcounttAttributeErrort
StopIterationtstrip(tauth_stringtprevtitem((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pyt_split_auth_string)s



ccs~xwt|�D]i}|jdd�\}}|jd�rkt|�dkrk|jd�rk|dd!}n||fVq
WdS(s2 split a digest auth string into key, value pairs t=iRi����N(RRt
startswithtlentendswith(RRtktv((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pyt_auth_to_kv_pairs=s
0cCstd|||f�j�S(s; construct the appropriate hashcode needed for HTTP digest s%s:%s:%s(Rt	hexdigest(trealmtusernametpassword((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pytdigest_passwordEstAuthDigestAuthenticatorcBs;eZdZd�Zdd�Zd�Zd�ZeZRS(s9 implementation of RFC 2617 - HTTP Digest Authentication cCsi|_||_||_dS(N(tnoncetauthfuncR(tselfRR((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pyt__init__Ks		tcCs�tdtj�tj�f�j�}tdtj�tj�f�j�}d|j|<i|jd6dd6|d6|d6}|r�d|d<nd	jg|j�D]\}}d
||f^q��}dd|fg}t	d
|�S(s! builds the authentication error s%s:%sRtauthtqopRtopaquettruetstales, s%s="%s"sWWW-Authenticates	Digest %stheadersN(
RttimetrandomRRRRtjointitemsR(RR&RR$tpartsRRthead((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pytbuild_authenticationPs%%

8c

Cs|s|j�Std||f�j�}
|	rQd|||||	|
f}nd|||
f}|t|�j�kr�||jkr�|j|=n|j�S|jj|d�}||kr�||jkr�|j|=n|jdt�S||j|<|S(s; computes the authentication, raises error if unsuccessful s%s:%ss%s:%s:%s:%s:%s:%ss%s:%s:%st00000000R&(R.RRRtgettTrue(
Rtha1RtresponsetmethodtpathRtnctcnonceR#tha2tchktpnc((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pytcompute_s"




cCs�t|�}tt|��tt|��}t|�}|sJ|j�S|jdd�\}}d|j�kr~|j�Stt	|��}y�|d}|d}	|d}
|d}|d}|	jd	d�d
|ks�t
�||jks�t
�|jdd�}
|jd
d�}|jdd�}|
r_d|
ksJt
�|
rV|s_t
�nWn|j�SX|j
|||�}|j|||||	|
|||
�	S(s� This function takes a WSGI environment and authenticates
            the request returning authenticated user or error.
        t itdigestRturiRRR3t?iR#R!R7R6R/R"(tREQUEST_METHODt	url_quotetSCRIPT_NAMEt	PATH_INFOt
AUTHORIZATIONR.RtlowertdictRtAssertionErrorRR0RR;(RtenvironR4tfullpatht
authorizationtauthmethR"tamapRtauthpathRRR3R#R7R6R2((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pytauthenticateus8"






"(t__name__t
__module__t__doc__R R.R;RNt__call__(((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pyRIs			!tAuthDigestHandlercBs eZdZd�Zd�ZRS(s
    middleware for HTTP Digest authentication (RFC 2617)

    This component follows the procedure below:

        0. If the REMOTE_USER environment variable is already populated;
           then this middleware is a no-op, and the request is passed
           along to the application.

        1. If the HTTP_AUTHORIZATION header was not provided or specifies
           an algorithem other than ``digest``, then a HTTPUnauthorized
           response is generated with the challenge.

        2. If the response is malformed or or if the user's credientials
           do not pass muster, another HTTPUnauthorized is raised.

        3. If all goes well, and the user's credintials pass; then
           REMOTE_USER environment variable is filled in and the
           AUTH_TYPE is listed as 'digest'.

    Parameters:

        ``application``

            The application object is called only upon successful
            authentication, and can assume ``environ['REMOTE_USER']``
            is set.  If the ``REMOTE_USER`` is already set, this
            middleware is simply pass-through.

        ``realm``

            This is a identifier for the authority that is requesting
            authorization.  It is shown to the user and should be unique
            within the domain it is being used.

        ``authfunc``

            This is a callback function which performs the actual
            authentication; the signature of this callback is:

              authfunc(environ, realm, username) -> hashcode

            This module provides a 'digest_password' helper function
            which can help construct the hashcode; it is recommended
            that the hashcode is stored in a database, not the user's
            actual password (since you only need the hashcode).
    cCst||�|_||_dS(N(RRNtapplication(RRTRR((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pyR �scCsvt|�}|sf|j|�}t|t�rStj|d�tj||�qf|j||�Sn|j||�S(NR=(tREMOTE_USERRNt
isinstancetstrt	AUTH_TYPEtupdatetwsgi_applicationRT(RRHtstart_responseRtresult((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pyRR�s(RORPRQR RR(((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pyRS�s/	RcKsVddlm}ddl}||�}t||j�sFtd��t|||�S(s�
    Grant access via digest authentication

    Config looks like this::

      [filter:grant]
      use = egg:Paste#auth_digest
      realm=myrealm
      authfunc=somepackage.somemodule:somefunction

    i����(teval_importNs#authfunc must resolve to a function(tpaste.util.import_stringR]ttypesRVtFunctionTypeRGRS(tapptglobal_confRRtkwR]R_((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pytmake_digest�s
t__main__toptionflags(RQtpaste.httpexceptionsRtpaste.httpheadersthashlibRtImportErrorR(R)turllibRRARRRtobjectRRSt
middlewaret__all__RdROtdoctestttestmodtELLIPSIS(((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/digest.pyt<module>s&

			O?	

Zerion Mini Shell 1.0