ÿØÿàJFIFÿþ ÿÛC       ÿÛC ÿÀÿÄÿÄ"#QrÿÄÿÄ&1!A"2qQaáÿÚ ?Øy,æ/3JæÝ¹È߲؋5êXw²±ÉyˆR”¾I0ó2—PI¾IÌÚiMö¯–þrìN&"KgX:Šíµ•nTJnLK„…@!‰-ý ùúmë;ºgµŒ&ó±hw’¯Õ@”Ü— 9ñ-ë.²1<yà‚¹ïQÐU„ہ?.’¦èûbß±©Ö«Âw*VŒ) `$‰bØÔŸ’ëXÖ-ËTÜíGÚ3ð«g Ÿ§¯—Jx„–’U/ÂÅv_s(Hÿ@TñJÑãõçn­‚!ÈgfbÓc­:él[ðQe 9ÀPLbÃãCµm[5¿ç'ªjglå‡Ûí_§Úõl-;"PkÞÞÁQâ¼_Ñ^¢SŸx?"¸¦ùY騐ÒOÈ q’`~~ÚtËU¹CڒêV  I1Áß_ÿÙ ]c@sdZddlZddlZddlZddlZddlZyddlmZWnek ruddl ZnXddl m Z dZ e ejddejZee e ejZd%d&d'd(gZgeD]\ZZeef^qZejedZdZdefdYZdjgeddD]Zee^qNZdZ de!fdYZ"de#fdYZ$de!fdYZ%e%Z&dd)dd d!d"Z(dddgZ)d#e*krddl+Z+e+j,d$e+j-ndS(*s 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 = 'Welcome %s (%s)' ... page %= (environ['REMOTE_USER'], environ['REMOTE_SESSION']) ... else: ... page = ('
' ... '
') ... return DataApp(page, content_type="text/html")( ... environ, start_response) >>> serve(AuthCookieHandler(testapp)) serving on... iN(tsha1(t get_cookiescCstjdtj|S(Ns %Y%m%d%H%M(ttimetstrftimetgmtime(tvalue((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pyt make_time5stxs\s\x5ct"s\x22t=s\x3dt;s\x3bcCstd|t|S(NcSs|j|d|dS(Nii(treplace(tatb((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pytAt(treducetstr(tstsublist((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pytencode@scCs t|tS(N(Rt_decode(R((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pyRBRtCookieTooLargecBseZdZRS(cCs#tjd||_||_dS(Ns*Signed cookie exceeds maximum size of 4096(t RuntimeErrort__init__tcontenttcookie(tselfRR((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pyREs  (t__name__t __module__R(((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pyRDsRiicCsdjtjtdS(s returns a 64 byte secret Ri@(tjointrandomtsamplet _all_chars(((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pyt new_secretKstAuthCookieSignercBs2eZdZddddZdZdZRS(s 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. cCsV|p d|_t|tr1td|n|p:d|_|pLt|_dS(Nis5Timeout must be a number (minutes), not a string (%r)i(ttimeoutt isinstancet basestringt ValueErrortmaxlenR"tsecret(RR)R$R(((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pyR}s cCstjtj|j|tjttjd|j |}|j ddj dd}|j ddj dd}t ||j krt ||n|S( s 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. i<t/t_R t~s Rs (tbase64t encodestringthmactnewR)RtdigestRRR$R tlenR(R(RRR((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pytsigns6 cCstj|jddjdd}|t }|tt!}|t}|tj|j|tj krt |t t t j kr|SndS(s Authenticate the cooke using the signature, verify that it has not expired; and return the cookie's content R+R*R,R N( R-t decodestringR t_signature_sizet _header_sizeR/R0R)RR1tintRR(RRtdecodet signaturetexpiresR((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pytauths!   $$N(RRt__doc__tNoneRR3R;(((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pyR#Os- tAuthCookieEnvironcBs eZdZdZdZRS(sH 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. cCstj||||_dS(N(tlistRthandler(RR@tscanlist((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pyRscCs*||krdStj|t|dS(N(R?tappendR(RR((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pyRBs (RRR<RRB(((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pyR>s tAuthCookieHandlercBsJeZdZdZdZeZeZdddddddZ dZ RS(s 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`` spaste.auth.cookietPASTE_AUTH_COOKIEcCsU|s|j|||}n||_|p0d|_||_|pK|j|_dS(Nt REMOTE_USERtREMOTE_SESSION(RERF(t signer_classtsignerRAt applicationt cookie_name(RRIRJRARHR)R$R(((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pyRs   c s\jkrtdnjj}t}|jjr jj|jj }|r x|j dD]~}|j d\}}t |}||kr|j |n|krqnt ||ROR=RR`(((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pyRCs2RDRERFiic Cst|tr|j}n|dkrF|jdrF|d}nyt|}Wn!tk rytd|nXyt|}Wn!tk rtd|nXt|d|d|d|d|d|S( s 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) R)s'Bad value for timeout (must be int): %rs&Bad value for maxlen (must be int): %rRJRAR$R(N(R%R&R[R=RMR7R'RC(tappt global_confRJRAR)R$R(((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pytmake_auth_cookie7s">   t__main__t optionflags(s\s\x5c(Rs\x22(R s\x3d(R s\x3b(RERF(.R<R/R-RRR\thashlibRt ImportErrortshat paste.requestRRR2R0R1R5R6t_encodeRURVRtreverseRR8RRRtrangeRtchrR!R"tobjectR#R?R>RCt middlewareR=Rct__all__RtdoctestttestmodtELLIPSIS(((sB/opt/alt/python27/lib/python2.7/site-packages/paste/auth/cookie.pyt*s><  ! %   1 _u H