
    f}@                         d Z g dZddlmZ ddlZddlZdZdZdZdZ	d	Z
 ej                  d
      ZdZdZ G d de      Z G d de      Zee_         G d de      Zee_        y)zAn implementation of the OpenID Provider Authentication Policy
Extension 1.0, Draft 5

@see: http://openid.net/developers/specs/

@since: 2.1.0
)RequestResponsens_uriAUTH_PHISHING_RESISTANTAUTH_MULTI_FACTORAUTH_MULTI_FACTOR_PHYSICALLEVELS_NISTLEVELS_JISA    )	ExtensionNz+http://specs.openid.net/extensions/pape/1.0zEhttp://schemas.openid.net/pape/policies/2007/06/multi-factor-physicalz<http://schemas.openid.net/pape/policies/2007/06/multi-factorzBhttp://schemas.openid.net/pape/policies/2007/06/phishing-resistantz4http://schemas.openid.net/pape/policies/2007/06/nonez$^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$zDhttp://csrc.nist.gov/publications/nistpubs/800-63/SP800-63V1_0_2.pdfz*http://www.jisa.or.jp/spec/auth_level.htmlc                   0    e Zd ZeedZd ZddZd Zd Z	y)PAPEExtension)nistjisac                 B    | j                   j                         | _        y N)_default_auth_level_aliasescopyauth_level_aliasesselfs    X/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/openid/extensions/draft/pape5.py__init__zPAPEExtension.__init__/   s    "&"B"B"G"G"I    Nc                     |	 | j                  |      }n0| j                  j	                  |      }|||k7  rt        d|||      || j                  |<   y# t        $ r | j                         }Y +w xY w)a&  Add an auth level URI alias to this request.

        @param auth_level_uri: The auth level URI to send in the
            request.

        @param alias: The namespace alias to use for this auth level
            in this message. May be None if the alias is not
            important.
        Nz-Attempting to redefine alias %r from %r to %r)	_getAliasKeyError_generateAliasr   getr   auth_level_urialiasexisting_uris       r   _addAuthLevelAliasz PAPEExtension._addAuthLevelAlias2   s     =.~6  2266u=L'LN,JN$lND D *8&  .++-.s   A A21A2c                 h    t        d      D ]  }d|fz  }|| j                  vs|c S  t        d      )z!Return an unused auth level aliasi  zcust%dz,Could not find an unused alias (tried 1000!))ranger   RuntimeError)r   ir!   s      r   r   zPAPEExtension._generateAliasI   sB    t 	Au$ED333	
 IJJr   c                 n    | j                   j                         D ]  \  }}||k(  s|c S  t        |      )zmReturn the alias for the specified auth level URI.

        @raises KeyError: if no alias is defined
        )r   itemsr   r   s       r   r   zPAPEExtension._getAliasR   sA    
 &*%<%<%B%B%D 	!UL-	 ~&&r   r   )
__name__
__module____qualname__r   r	   r   r   r#   r   r    r   r   r   r   )   s&    #
J8.K	'r   r   c                   l     e Zd ZdZdZ	 	 	 d fd	Zd Zd ZddZd Z	d Z
 ee
      Z
dd	Zd
 Z xZS )r   aD  A Provider Authentication Policy request, sent from a relying
    party to a provider

    @ivar preferred_auth_policies: The authentication policies that
        the relying party prefers
    @type preferred_auth_policies: [str]

    @ivar max_auth_age: The maximum time, in seconds, that the relying
        party wants to allow to have elapsed before the user must
        re-authenticate
    @type max_auth_age: int or NoneType

    @ivar preferred_auth_level_types: Ordered list of authentication
        level namespace URIs

    @type preferred_auth_level_types: [str]
    papec                     t         t        |           |g }|| _        || _        g | _        ||D ]  }| j                  |        y y r   )superr   r   preferred_auth_policiesmax_auth_agepreferred_auth_level_typesaddAuthLevel)r   r2   r3   r4   
auth_level	__class__s        r   r   zRequest.__init__s   s^     	gt%'"*&(#'>$(*,'%18 .
!!*-. 2r   c                 h    t        | j                  xs | j                  d uxs | j                        S r   )boolr2   r3   r4   r   s    r   __bool__zRequest.__bool__   s8    D00 4%%T14335 	5r   c                 X    || j                   vr| j                   j                  |       yy)a  Add an acceptable authentication policy URI to this request

        This method is intended to be used by the relying party to add
        acceptable authentication types to the request.

        @param policy_uri: The identifier for the preferred type of
            authentication.
        @see: http://openid.net/specs/openid-provider-authentication-policy-extension-1_0-05.html#auth_policies
        N)r2   appendr   
policy_uris     r   addPolicyURIzRequest.addPolicyURI   s+     T999((//
; :r   c                 |    | j                  ||       || j                  vr| j                  j                  |       y y r   )r#   r4   r<   )r   r    r!   s      r   r5   zRequest.addAuthLevel   s:    6!@!@@++22>B Ar   c                 B   ddj                  | j                        i}| j                  t        | j                        |d<   | j                  rQg }| j                  D ],  }| j                  |      }||d|<   |j                  |       . dj                  |      |d<   |S )/@see: C{L{Extension.getExtensionArgs}}
        r2    r3   auth_level.ns.r4   )joinr2   r3   strr4   r   r<   )r   ns_argspreferred_typesr    r!   s        r   getExtensionArgszRequest.getExtensionArgs   s     &sxx0L0L'M
 (&)$*;*;&<GN#** O"&"A"A .~6:He67&&u-.
 58HH_4MG01r   c                      |        }|j                   j                  |j                        }|j                   j                         }|i k(  ry|j	                  ||       |S )zaInstantiate a Request object from the arguments in a
        C{checkid_*} OpenID message
        N)messagegetArgsr   	isOpenID1parseExtensionArgs)clsrequestr   args
is_openid1s        r   fromOpenIDRequestzRequest.fromOpenIDRequest   sT     u&&t{{3__..0
2:j1r   c                    g | _         |j                  d      }|r]t        |t              rt	        |d      }|j                  d      D ],  }|| j                   vs| j                   j                  |       . |j                  d      }d| _        |r	 t        |      | _        |j                  d      }|rW|j                         j                         }|D ]3  }	d|	}
	 ||
   }||st        d	|	d
      | j                  ||	       5 yy# t        $ r |r Y yw xY w# t        $ r# |r| j                  j                  |	      }nd}Y gw xY w)a-  Set the state of this request to be that expressed in these
        PAPE arguments

        @param args: The PAPE arguments without a namespace

        @param strict: Whether to raise an exception if the input is
            out of spec or otherwise malformed. If strict is false,
            malformed input will be ignored.

        @param is_openid1: Whether the input should be treated as part
            of an OpenID1 request

        @rtype: None

        @raises ValueError: When the max_auth_age is not parseable as
            an integer
        r2   zutf-8)encodingrC   r3   Nr4   rD   zpreferred auth level z is not defined in this message)r2   r   
isinstancebytesrF   splitr<   r3   int
ValueErrorstripr   r   r5   )r   rQ   rR   strictpolicies_strurimax_auth_age_strr4   aliasesr!   keys              r   rN   zRequest.parseExtensionArgs   st   ( (*$xx 9:,."<'B#))#. =d:::0077<=
  88N3 $'(8$9! &*XX.J%K"%0668>>@G  2,14#s)C ;(FK*O P P %%c512 &      #!">>BB5I"	#s$   D D DD )EEc                 T    t        t        | j                  j                  |            S )a  Given a list of authentication policy URIs that a provider
        supports, this method returns the subsequence of those types
        that are preferred by the relying party.

        @param supported_types: A sequence of authentication policy
            type URIs that are supported by a provider

        @returns: The sub-sequence of the supported types that are
            preferred by the relying party. This list will be ordered
            in the order that the types appear in the supported_types
            sequence, and may be empty if the provider does not prefer
            any of the supported authentication types.

        @returntype: [str]
        )listfilterr2   __contains__)r   supported_typess     r   preferredTypeszRequest.preferredTypes   s)      4//<<oNP 	Pr   NNNr   F)r*   r+   r,   __doc__ns_aliasr   r:   r?   r5   rI   rS   classmethodrN   rg   __classcell__r7   s   @r   r   r   ^   sS    $ H *.",0. 5
<C
, $$56=2~Pr   r   c                   z     e Zd ZdZdZd fd	ZddZd Zd Z e	ed      Z
d	 Zd
 ZddZ ee      Zd Z xZS )r   zA Provider Authentication Policy response, sent from a provider
    to a relying party

    @ivar auth_policies: List of authentication policies conformed to
        by this OpenID assertion, represented as policy URIs
    r/   c                     t         t        |           |r|| _        ng | _        || _        i | _        |i }|j                         D ]  \  }}| j                  ||        y r   )r1   r   r   auth_policies	auth_timeauth_levelsr)   setAuthLevel)r   rq   rr   rs   r^   levelr7   s         r   r   zResponse.__init__   si    h&(!.D!#D"K%++- 	*JCc5)	*r   c                 F    | j                  ||       || j                  |<   y)a  Set the value for the given auth level type.

        @param level: string representation of an authentication level
            valid for level_uri

        @param alias: An optional namespace alias for the given auth
            level URI. May be omitted if the alias is not
            significant. The library will use a reasonable default for
            widely-used auth level types.
        N)r#   rs   )r   	level_uriru   r!   s       r   rt   zResponse.setAuthLevel0  s$     		51&+#r   c                      | j                   |   S )a  Return the auth level for the specified auth level
        identifier

        @returns: A string that should map to the auth levels defined
            for the auth level type

        @raises KeyError: If the auth level type is not present in
            this message
        )rs   )r   rw   s     r   getAuthLevelzResponse.getAuthLevel>  s     	**r   c                 ^    	 t        | j                  t                    S # t        $ r Y y w xY wr   )rY   ry   r   r   r   s    r   _getNISTAuthLevelzResponse._getNISTAuthLevelJ  s/    	t((566 		s     	,,z7Backward-compatibility accessor for the NIST auth level)docc                     |t         k(  rt        d      || j                  vr| j                  j                  |       yy)a  Add a authentication policy to this response

        This method is intended to be used by the provider to add a
        policy that the provider conformed to when authenticating the user.

        @param policy_uri: The identifier for the preferred type of
            authentication.
        @see: http://openid.net/specs/openid-provider-authentication-policy-extension-1_0-01.html#auth_policies
        z4To send no policies, do not set any on the response.N)	AUTH_NONEr&   rq   r<   r=   s     r   r?   zResponse.addPolicyURIT  sG     "FH H T///%%j1 0r   c                      |        }|j                  |j                        }|j                         }||j                  ||       |S y)a9  Create a C{L{Response}} object from a successful OpenID
        library response
        (C{L{openid.consumer.consumer.SuccessResponse}}) response
        message

        @param success_response: A SuccessResponse from consumer.complete()
        @type success_response: C{L{openid.consumer.consumer.SuccessResponse}}

        @rtype: Response or None
        @returns: A provider authentication policy response from the
            data that was supplied with the C{id_res} response or None
            if the provider sent no signed PAPE response arguments.
        N)getSignedNSr   rM   rN   )rO   success_responser   rQ   rR   s        r   fromSuccessResponsezResponse.fromSuccessResponsee  sO     u  ++DKK8%//1
 ##D*5Kr   c                    |j                  d      }|r|j                  d      }n|rt        d      g }t        |      dkD  r|rt        |v rt        d|      d|v r&d}|rt        |      t        j                  |d	       |D cg c]  }|dt        fvs| }}|| _        |j                         D ]]  \  }}	|j                  d
      s|dd }
|
j                  d      r/	 |d|
   }||s=t        d|
      | j                  ||	|
       _ |j                  d      }|r+t        j                  |      r|| _        y|rt        d      yyc c}w # t        $ r# |r| j                  j                  |
      }nd}Y w xY w)a  Parse the provider authentication policy arguments into the
        internal state of this object

        @param args: unqualified provider authentication policy
            arguments

        @param strict: Whether to raise an exception when bad data is
            encountered

        @returns: None. The data is parsed into the internal fields of
            this object.
        rq   rC   zMissing auth_policies   z;Got some auth policies, as well as the special "none" URI: nonez0"none" used as a policy URI (see PAPE draft < 5)   )
stacklevelauth_level.   Nzns.rD   zUndefined auth level alias: rr   #auth_time must be in RFC3339 format)r   rX   rZ   lenr~   warningswarnrq   r)   
startswithr   r   rt   TIME_VALIDATORmatchrr   )r   rQ   rR   r\   r]   rq   msgura   valr!   r^   rr   s                r   rN   zResponse.parseExtensionArgs  s    xx0(..s3M455M"v)}2L1>B C C ]"DC o%ca0 %
&)1D(DA
 
 +**, 	7JS#~~m,BC ##E*#U=>C ;(*/*3 4 4 %%c36+	7. HH[)	##I.!* !FGG  =
    #!">>BB5I"	#s   	EE&E)FFc                    t        | j                        dk(  r	dt        i}nddj                  | j                        i}| j                  j                         D ]/  \  }}| j                  |      }||d|<   t        |      |d|<   1 | j                  9t        j                  | j                        st        d      | j                  |d<   |S )rB   r
   rq   rC   rD   r   r   rr   )r   rq   r~   rE   rs   r)   r   rF   rr   r   r   rZ   )r   rG   
level_typeru   r!   s        r   rI   zResponse.getExtensionArgs  s     t!!"a'G
  $*<*<!=G "&!1!1!7!7!9 	>JNN:.E6@G%2336u:Gu/0	>
 >>%!''7 !FGG#'>>GK r   rh   r   ri   )r*   r+   r,   rj   rk   r   rt   ry   r{   propertynist_auth_levelr?   r   rN   rl   rI   rm   rn   s   @r   r   r     s[     H* ,
+ EGO2"8BHH &&9:r   r   )rj   __all__openid.extensionr   r   rer   r   r   r   r~   compiler   r   r	   r   r   r   r-   r   r   <module>r      s   	 '  		6 L  C  I  ; 
 CDT:2'I 2'jrPm rPj H} HV r   