
    )Jf}@                         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_        dS )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                   2    e Zd ZeedZd ZddZd Zd Z	dS )PAPEExtension)nistjisac                 B    | j                                         | _        d S N)_default_auth_level_aliasescopyauth_level_aliasesselfs    `/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/openid/extensions/draft/pape5.py__init__zPAPEExtension.__init__/   s    "&"B"G"G"I"I    Nc                     |;	 |                      |          }nX# t          $ r |                                 }Y n8w xY w| j                            |          }|||k    rt          d|||          || j        |<   dS )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6 . . .++--.  266u==L'LN,J,JN$lND D D *8&&&s    ;;c                 j    t          d          D ]}d|fz  }|| j        vr|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   sP    t 	 	Au$ED333 4 IJJJr   c                 r    | j                                         D ]\  }}||k    r|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   sP    
 &*%<%B%B%D%D 	 	!UL-- . ~&&&r   r   )
__name__
__module____qualname__r   r	   r   r   r#   r   r    r   r   r   r   )   sn        # #
J J J8 8 8 8.K K K	' 	' 	' 	' 	'r   r   c                   r     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]
    papeNc                     t          t          |                                            |g }|| _        || _        g | _        ||D ]}|                     |           d S d S 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 . .
!!*---- 21. .r   c                 J    t          | j        p| j        d up| j                  S r   )boolr2   r3   r4   r   s    r   __bool__zRequest.__bool__   s4    D0 4%T1435 5 	5r   c                 P    || j         vr| j                             |           dS dS )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   s7     T999(//
;;;;; :9r   c                 |    |                      ||           || j        vr| j                            |           d S d S r   )r#   r4   r<   )r   r    r!   s      r   r5   zRequest.addAuthLevel   sL    666!@@@+22>BBBBB A@r   c                 4   dd                     | j                  i}| j        t          | j                  |d<   | j        rVg }| j        D ]4}|                     |          }||d|<   |                    |           5d                     |          |d<   |S )/@see: C{L{Extension.getExtensionArgs}}
        r2    Nr3   auth_level.ns.r4   )joinr2   r3   strr4   r   r<   )r   ns_argspreferred_typesr    r!   s        r   getExtensionArgszRequest.getExtensionArgs   s     &sxx0L'M'M
 (&)$*;&<&<GN#* 	N O"&"A . .~66:Hee67&&u----47HH_4M4MG01r   c                      |             }|j                             |j                  }|j                                         }|i k    rdS |                    ||           |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   sb     suu&&t{33_..00
2::4j111r   Fc                    g | _         |                    d          }|rat          |t                    rt	          |d          }|                    d          D ]%}|| j         vr| j                             |           &|                    d          }d| _        |r)	 t          |          | _        n# t          $ r |r Y nw xY w|                    d          }|r|
                                                                }|D ]p}	d|	}
	 ||
         }n/# t          $ r" |r| j                            |	          }nd}Y nw xY w||rt          d	|	d
          X|                     ||	           odS dS )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   s   ( (*$xx 9:: 	=,.. C"<'BBB#))#.. = =d:::077<<<  88N33  	$'(8$9$9!!     
 &*XX.J%K%K"% 	206688>>@@G  2 2,1E4#s)CC # # #! #">BB5II"	# ; P(jFKee*O P P PP %%c51111%	2 	22 2s$   B4 4CCD)EEc                 P    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NP P 	Pr   NNNr   F)r*   r+   r,   __doc__ns_aliasr   r:   r?   r5   rI   rS   classmethodrN   rg   __classcell__r7   s   @r   r   r   ^   s         $ H *.",0. . . . . . 5 5 5
< < <C C C C
  ,   $$566=2 =2 =2 =2~P P P P P P Pr   r   c                        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/   Nc                     t          t          |                                            |r|| _        ng | _        || _        i | _        |i }|                                D ]\  }}|                     ||           d S r   )r1   r   r   auth_policies	auth_timeauth_levelsr)   setAuthLevel)r   rq   rr   rs   r^   levelr7   s         r   r   zResponse.__init__   s    h&&((( 	$!.D!#D"K%++-- 	* 	*JCc5))))	* 	*r   c                 F    |                      ||           || j        |<   dS )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1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    	 t          |                     t                              S # t          $ r Y d S w xY wr   )rY   ry   r   r   r   s    r   _getNISTAuthLevelzResponse._getNISTAuthLevelJ  sE    	t((55666 	 	 	44	s   &) 
77z7Backward-compatibility accessor for the NIST auth level)docc                     |t           k    rt          d          || j        vr| j                            |           dS dS )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  s\     ""FH H H T///%%j11111 0/r   c                      |             }|                     |j                  }|                                }||                    ||           |S dS )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  s_     suu  ++DK88%//11
 ##D*555K4r   Fc                 r   |                     d          }|r|                    d          }n|rt          d          g }t          |          dk    r|rt          |v rt          d|          d|v r)d}|rt          |          t          j        |d	           d
 |D             }|| _        |                                D ]\  }}|	                    d          r|dd         }	|		                    d          r:	 |d|	         }
n/# t          $ r" |r| j                             |	          }
nd}
Y nw xY w|
|rt          d|	          |                     |
||	           |                     d          }|r4t                              |          r	|| _        dS |rt          d          dS dS )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)   )
stacklevelc                 (    g | ]}|d t           fv|S )r   )r~   ).0us     r   
<listcomp>z/Response.parseExtensionArgs.<locals>.<listcomp>  s.     
 
 
&)1D(D(DA(D(D(Dr   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   msgra   valr!   r^   rr   s               r   rN   zResponse.parseExtensionArgs  s_    xx00 	(..s33MM 	4555M""v")}2L2L*1>B C C C ]""DC 1 oo%ca0000
 
$
 
 
 +**,, 	7 	7JS#~~m,, 7BCC ##E** #$UU=>CC # # #! #">BB5II"	# ; 4(j*/%*3 4 4 44 %%c3666HH[))	 	H##I.. H!* H !FGGG		H 	HH Hs    D)D87D8c                    t          | j                  dk    r
dt          i}ndd                    | j                  i}| j                                        D ]7\  }}|                     |          }||d|<   t          |          |d|<   8| j        8t          
                    | j                  st          d          | j        |d<   |S )	rB   r
   rq   rC   rD   r   Nr   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''GG
  $*<!=!=G "&!1!7!7!9!9 	> 	>JNN:..E6@GG%%2336u::GGuu/00>%!''77 H !FG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* * * * * * , , , ,
+ 
+ 
+   hEG G GO2 2 2"  8BH BH BH B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      sC   	 	 	 ' & & & & &  					6 L  C  I  ; 
 CDDT:2' 2' 2' 2' 2'I 2' 2' 2'jrP rP rP rP rPm rP rP rPj H H H H H} H H HV r   