
    qhW8                         S r / SQrSSKJr  SSKJr  SSKJrJr  SSK	r	SSK
r
\
R                  " \5      rSS/r/ S	Qr\	R                   " S
5      r " S S\5      rS r " S S\5      rSrS rS rS r\4S jrg)aQ  
This module contains the C{L{TrustRoot}} class, which helps handle
trust root checking.  This module is used by the
C{L{openid.server.server}} module, but it is also available to server
implementers who wish to use it for additional trust root checking.

It also implements relying party return_to URL verification, based on
the realm.
)	TrustRootRP_RETURN_TO_URL_TYPEextractReturnToURLsreturnToMatchesverifyReturnTo    )urinorm)services)urlparse
urlunparseNhttphttps(  acadaeaeroafagaialamanaoaqararpaasasiaatauawaxazbabbbdbebfbgbhbibizbjbmbnbobrbsbtbvbwbybzcacatcccdcfcgchcickclcmcncocomcoopcrcucvcxcyczdedjdkdmdodzecedueeegereseteufifjfkfmfofrgagbgdgegfggghgiglgmgngovgpgqgrgsgtgugwgyhkhmhnhrhthuidieilimininfointioiqirisitjejmjojobsjpkekgkhkikmknkpkrkwkykzlalblclilklrlsltlulvlymamcmdmemgmhmilmkmlmmmnmomobimpmqmrmsmtmumuseummvmwmxmymznanamencnenetnfngninlnonpnrnunzomorgpapepfpgphpkplpmpnprpropsptpwpyqarerorsrurwsasbscsdsesgshsisjskslsmsnsosrstsusvsysztctdteltftgthtjtktltmtntotptrtraveltttvtwtzuaugukusuyuzvavcvevgvivnvuwfwszxn--0zwm56dzxn--11b5bs3a9aj6gzxn--80akhbyknj4fzxn--9t4b11yi5azxn--deba0adzxn--g6w251dzxn--hgbk6aj7f53bbazxn--hlcj6aya9esc7azxn--jxalpdlpzxn--kgbechtvz
xn--zckzahyeytyuzazmzwz3(?:[-a-zA-Z0-9!$&'\(\)\*+,;=._~]|%[a-zA-Z0-9]{2})+$c                   $    \ rS rSrSrS rS rSrg)RealmVerificationRedirectedB   zGAttempting to verify this realm resulted in a redirect.

@since: 2.1.0
c                     Xl         X l        g Nrelying_party_urlrp_url_after_redirects)selfr!  r"  s      I/var/www/html/env/lib/python3.13/site-packages/openid/server/trustroot.py__init__$RealmVerificationRedirected.__init__H   s    !2&<#    c                 >    SU R                   < SU R                  < 3$ )NzAttempting to verify z resulted in redirect to r   r#  s    r$  __str__#RealmVerificationRedirected.__str__L   s     $($:$:$($?$?A 	Br'  r   N)__name__
__module____qualname____firstlineno____doc__r%  r*  __static_attributes__ r'  r$  r  r  B   s    
=Br'  r  c                     [         R                   " U 5      n [        U 5      u  pp4pVU(       d#  U(       d  SU;   a  UR                  SS5      u  p%Sn[	        SSX4XV45      nSU;   a2   UR                  S5      u  px[
        R                  " SU5      (       d  g OUnSnUR                  5       n[        R                  U5      (       d  g XX4$ ! [         a     g f = f! [         a     g f = f)N?   / :z\d+$)	r   
ValueErrorr
   splitr   r   matchlowerhost_segment_re)	urlprotonetlocpathparamsqueryfraghostports	            r$  	_parseURLrG  R   s    ooc" 08},E4"LLa0MFr2tU9:D
f}	c*JD xx&& ' ::<D  &&""9    		s#   C 'C 
CC
C('C(c                   ~    \ rS rSrSrS rS rS rS r\	" \5      rS r
\	" \
5      r
S r\	" \5      rS	 rS
 rS rSrg)r   t   a  
This class represents an OpenID trust root.  The C{L{parse}}
classmethod accepts a trust root string, producing a
C{L{TrustRoot}} object.  The method OpenID server implementers
would be most likely to use is the C{L{isSane}} method, which
checks the trust root for given patterns that indicate that the
trust root is too broad or points to a local network resource.

@sort: parse, isSane
c                 L    Xl         X l        X0l        X@l        XPl        X`l        g r  unparsedr?  wildcardrE  rF  rA  )r#  rL  r?  rM  rE  rF  rA  s          r$  r%  TrustRoot.__init__   s      
 			r'  c                    U R                   S:X  a  gU R                   R                  S5      nU R                  (       a  US   S:X  d   U5       eUS	 U(       a  US   (       d  US	 U(       d  gSU;   a  gUS   nU[        ;  a  g[	        U5      S:X  a  gU R                  (       a/  [	        U5      S	:X  a   [	        US
   5      S::  a  [	        U5      S	:  $ g)a  
This method checks the to see if a trust root represents a
reasonable (sane) set of URLs.  'http://*.com/', for example
is not a reasonable pattern, as it cannot meaningfully specify
the site claiming it.  This function attempts to find many
related examples, but it can only work via heuristics.
Negative responses from this method should be treated as
advisory, used only to alert the user to examine the trust
root carefully.


@return: Whether the trust root is sane

@rtype: C{bool}
	localhostT.r   r7  Fr5        )rE  r:  rM  _top_level_domainslen)r#  
host_partstlds      r$  isSaneTrustRoot.isSane   s    " 99#YY__S)
==a=B&2
2&1 jn2 n((z?a==3x1}Z^!4!9 :** r'  c                    [        U5      nUc  gUu  p4pVX0R                  :w  a  gXPR                  :w  a  gSU;   a  gU R                  (       d  X@R                  :w  a  gO4UR                  U R                  5      (       d  SU-   U R                  :w  a  gX`R                  :w  ad  [        U R                  5      nU R                  SU nUSU n	X:w  a  gSU R                  ;   a  Sn
OSn
U R                  S   U
;   =(       d    Xg   U
;   $ g	)
z
Validates a URL against this trust root.


@param url: The URL to check

@type url: C{str}


@return: Whether the given URL is within this trust root.

@rtype: C{bool}
NF*rQ  r4  &z?/rR  T)rG  r?  rF  rM  rE  endswithrA  rW  )r#  r>  	url_partsr?  rE  rF  rA  path_lentrust_prefix
url_prefixalloweds              r$  validateURLTrustRoot.validateURL   s     cN	"+TJJ99$;}}yy  !==++#*1J99499~H99Yh/LixJ )
 diiIIbMW,I'0IJr'  c                 $   [        U5      nUc  gUu  p4pVU[        ;  a  gUR                  S5      S:w  a  gUR                  SS5      S:w  a  gUR                  S5      (       a!  [	        U5      S:  a
  US   S:w  a  gUSS nSnOSnU " XXtXV5      nU$ )	aH  
This method creates a C{L{TrustRoot}} instance from the given
input, if possible.


@param trust_root: This is the trust root to parse into a
C{L{TrustRoot}} object.

@type trust_root: C{str}


@return: A C{L{TrustRoot}} instance if trust_root parses as a
trust root, C{None} otherwise.

@rtype: C{NoneType} or C{L{TrustRoot}}
N#rR  r]  r5  rQ  TF)rG  
_protocolsfind
startswithrW  )	cls
trust_rootr`  r?  rE  rF  rA  wilcardr   s	            r$  parseTrustRoot.parse   s    " j)	"+T 
" 99S>R 99S!"??3 4y1}aC8DGG G4>	r'  c                 L    U R                  U5      nUc  gUR                  5       $ )z(str -> bool

is this a sane trust root?
F)ro  rZ  )rl  trust_root_stringrm  s      r$  checkSanityTrustRoot.checkSanity-  s+    
 YY01
$$&&r'  c                 \    U R                  U5      nUSL=(       a    UR                  U5      $ )zhquick func for validating a url against a trust root.  See the
TrustRoot class if you need more control.N)ro  re  )rl  rm  r>  r   s       r$  checkURLTrustRoot.checkURL:  s*     YYz"~5".."55r'  c                     U R                   (       a`  U R                  R                  S5      (       d   U R                  5       eSU R                  -   nU R                  < SU< U R                  < 3$ U R
                  $ )a"  Return a discovery URL for this realm.

This function does not check to make sure that the realm is
valid. Its behaviour on invalid inputs is undefined.

@rtype: str

@returns: The URL upon which relying party discovery should be run
    in order to verify the return_to URL

@since: 2.1.0
rQ  wwwz://)rM  rE  rk  r?  rA  rL  )r#  
www_domains     r$  buildDiscoveryURLTrustRoot.buildDiscoveryURLB  s\     ==99'',,7dii7,*J"&**j$))DD== r'  c                     SU R                   < SU R                  < SU R                  < SU R                  < SU R                  < SU R
                  < S3$ )Nz
TrustRoot(z, )rK  r)  s    r$  __repr__TrustRoot.__repr__W  s2    MM4::t}}diiII 	r'  c                     [        U 5      $ r  )reprr)  s    r$  r*  TrustRoot.__str__\  s    Dzr'  )rE  rA  rF  r?  rL  rM  N)r,  r-  r.  r/  r0  r%  rZ  re  ro  classmethodrs  rv  r{  r  r*  r1  r2  r'  r$  r   r   t   s[    	4l7r2h E	' k*K6 8$H!*
r'  r   z*http://specs.openid.net/auth/2.0/return_toc                 R    U R                  [        /5      (       a  U R                  $ g)a  If the endpoint is a relying party OpenID return_to endpoint,
return the endpoint URL. Otherwise, return None.

This function is intended to be used as a filter for the Yadis
filtering interface.

@see: C{L{openid.yadis.services}}
@see: C{L{openid.yadis.filters}}

@param endpoint: An XRDS BasicServiceEndpoint, as returned by
    performing Yadis dicovery.

@returns: The endpoint URL or None if the endpoint is not a
    relying party endpoint.
@rtype: str or NoneType
N)
matchTypesr   uri)endpoints    r$  _extractReturnURLr  g  s&    " 1233||r'  c                     U  HH  n[         R                  U5      nUc  M  UR                  (       a  M0  UR                  U5      (       d  MH    g   g)zVIs the return_to URL under one of the supplied allowed
return_to URLs?

@since: 2.1.0
TF)r   ro  rM  re  )allowed_return_to_urls	return_toallowed_return_toreturn_realms       r$  r   r   ~  sO     4 !'89( !))) ((33 4$ r'  c                 b    [         R                  " U [        5      u  pX:w  a  [        U U5      eU$ )zTGiven a relying party discovery URL return a list of return_to URLs.

@since: 2.1.0
)r	   getServiceEndpointsr  r  )r!  r"  return_to_urlss      r$  getAllowedReturnURLsr    sC    
 08/K/K,0., 2)*;*@B 	B r'  c                 2   [         R                  U 5      nUc  g U" UR                  5       5      n[        XA5      (       a  g[        R                  SU< SU < SU< 35        g! [         a(  n[        R                  [        U5      5         SnAgSnAff = f)a  Verify that a return_to URL is valid for the given realm.

This function builds a discovery URL, performs Yadis discovery on
it, makes sure that the URL does not redirect, parses out the
return_to URLs, and finally checks to see if the current return_to
URL matches the return_to.

@raises DiscoveryFailure: When Yadis discovery fails
@returns: True if the return_to URL is valid for the realm

@since: 2.1.0
NFTzFailed to validate return_to z for realm z, was not in )	r   ro  r{  r  logger	exceptionstrr   error)	realm_strr  _vrfyrealmallowable_urlserrs         r$  r   r     s     OOI&E}u6689
 ~11!*I~G 	H ' S"s   A$ $
B.BB)r0  __all__openidr   openid.yadisr	   urllib.parser
   r   r   logging	getLoggerr,  r  ri  rV  compiler=  	Exceptionr  rG  objectr   r   r  r   r  r   r2  r'  r$  <module>r     s     ! - 	 			8	$ g
 > **:<B) B #Di i` E .8" 0D r'  