
    WwgxM                     r   d Z ddlZddlZddlmZ ddlmZmZ ddlmZm	Z	m
Z
 ddlmZmZ ddlmZ g d	Z eg d
      Z	  ed      Z	  ed       G d d             Zej*                   G d dej,                               Z ed       G d d             Z eej2                  ej2                        Z	  eej6                  ej6                        Z	  eej:                  ej:                         eej<                  ej<                        edZ	 ej*                   G d dej,                               Z  ed       G d d             Z!dee"   dee"   dee"   fdZ# ed       G d d              Z$ ed       G d! d"             Z% G d# d$ejL                        Z' G d% d&e'      Z( G d' d(e'      Z)y))z
.. versionadded:: 0.20.0
    N)	dataclass)datetime	timedelta)	FrozenSetIterableOptional)algoskeys   )PKIXSubtrees)RevocationCheckingRuleRevocationCheckingPolicyFreshnessReqTypeCertRevTrustPolicyPKIXValidationParamsAlgorithmUsageConstraintAlgorithmUsagePolicyDisallowWeakAlgorithmsPolicyAcceptAllAlgorithmsNonRevokedStatusAssertionDEFAULT_WEAK_HASH_ALGOSREQUIRE_REVINFONO_REVOCATION)md2md5sha1   )minutesT)frozenc                   (    e Zd ZU dZeed<   	 eed<   y)r   zG
    Assert that a certificate was not revoked at some given date.
    cert_sha256atN)__name__
__module____qualname____doc__bytes__annotations__r        X/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko_certvalidator/policy_decl.pyr   r   -   s       	Lr*   r   c                       e Zd ZdZdZ	 dZ	 dZ	 dZ	 dZ	 dZ		 dZ
	 ed	efd
       Zed	efd       Zed	efd       Zed	efd       Zed	efd       Zed	efd       Zy)r   zg
    Rules determining in what circumstances revocation data has to be checked,
    and what kind.
    clrcheck	ocspcheck	bothcheckeitherchecknocheckifdeclaredcheckifdeclaredsoftcheckreturnc                 d    | t         j                  t         j                  t         j                  fvS N)r   CHECK_IF_DECLAREDCHECK_IF_DECLARED_SOFTNO_CHECKselfs    r+   strictzRevocationCheckingRule.strict{   s1     "44"99"++
 
 	
r*   c                 F    | t         j                  t         j                  fv S r6   )r   r8   r9   r:   s    r+   tolerantzRevocationCheckingRule.tolerant   s&    "99"++
 
 	
r*   c                 F    | t         j                  t         j                  fv S r6   )r   CRL_REQUIREDCRL_AND_OCSP_REQUIREDr:   s    r+   crl_mandatoryz$RevocationCheckingRule.crl_mandatory   s&    "//"88
 
 	
r*   c                 F    | t         j                  t         j                  fvS r6   )r   r9   OCSP_REQUIREDr:   s    r+   crl_relevantz#RevocationCheckingRule.crl_relevant   s&    "++"00
 
 	
r*   c                 F    | t         j                  t         j                  fv S r6   )r   rD   rA   r:   s    r+   ocsp_mandatoryz%RevocationCheckingRule.ocsp_mandatory   s&    "00"88
 
 	
r*   c                 F    | t         j                  t         j                  fvS r6   )r   r9   r@   r:   s    r+   ocsp_relevantz$RevocationCheckingRule.ocsp_relevant   s&    "++"//
 
 	
r*   N)r#   r$   r%   r&   r@   rD   rA   CRL_OR_OCSP_REQUIREDr9   r7   r8   propertyboolr<   r>   rB   rE   rG   rI   r)   r*   r+   r   r   >   s    L  M ( ) H *
 3 
 
 
 
$ 
 
 
t 
 
 
d 
 
 
 
 
 
t 
 
r*   r   c                   V    e Zd ZU dZeed<   	 eed<   	 edefd       Ze	de
fd       Zy)	r   zu
    Class describing a revocation checking policy
    based on the types defined in the ETSI TS 119 172 series.
    ee_certificate_ruleintermediate_ca_cert_rulepolicyc                 N    	 t         |   S # t        $ r t        d| d      w xY w)N'z ' is not a valid revocation mode)LEGACY_POLICY_MAPKeyError
ValueError)clsrP   s     r+   from_legacyz$RevocationCheckingPolicy.from_legacy   s9    	K$V,, 	Kq(HIJJ	Ks    $r4   c                 `    | j                   j                  xr | j                   j                   S r6   )rN   r>   r:   s    r+   	essentialz"RevocationCheckingPolicy.essential   s1     $$-- 2((11
 	
r*   N)r#   r$   r%   r&   r   r(   classmethodstrrW   rK   rL   rY   r)   r*   r+   r   r      sZ    
 0/  65 K K K 
4 
 
r*   r   )rN   rO   )z	soft-failz	hard-failrequirec                   z    e Zd ZdZ ej
                         Z	  ej
                         Z	  ej
                         Zy)r   z%
    Freshness requirement type.
    N)	r#   r$   r%   r&   enumautoDEFAULTMAX_DIFF_REVOCATION_VALIDATIONTIME_AFTER_SIGNATUREr)   r*   r+   r   r      sE     diikG &/TYY[" %499;r*   r   c                   |    e Zd ZU dZeed<   	 dZee   ed<   	 e	j                  Ze	ed<   	 dZee   ed<   	 dZeed<   y)	r   zz
    Class describing conditions for trusting revocation info.
    Based on CertificateRevTrust in ETSI TS 119 172-3.
    revocation_checking_policyN	freshnessfreshness_req_type!expected_post_expiry_revinfo_timeFretroactive_revinfo)r#   r$   r%   r&   r   r(   re   r   r   r   r`   rf   rg   rh   rL   r)   r*   r+   r   r     sm    
 !98 &*Ix	") ,<+C+C(C
 >B%x	':A
 !&%r*   r   a_polsb_polsr4   c                 L    d| v }d|v }|r|rt        dg      S |r|S |r|S || z  S )z
    Intersect two sets of policies, taking into account the special
    'any_policy'.

    :param a_pols:
        A set of policies.
    :param b_pols:
        Another set of policies.
    :return:
        The intersection of both.
    
any_policy)	frozenset)ri   rj   a_anyb_anys       r+   intersect_policy_setsrp   8  sD     F"EF"E,((		r*   c                       e Zd ZU  edg      Zeed<   	 dZeed<   	 dZeed<   	 dZ	eed<   	 dZ
ee   ed<   	 dZee   ed	<   	 dd
Zy)r   rl   user_initial_policy_setFinitial_policy_mapping_inhibitinitial_explicit_policyinitial_any_policy_inhibitNinitial_permitted_subtreesinitial_excluded_subtreesc                 Z   d| j                   v r|j                   }n4d|j                   v r| j                   }n|j                   | j                   z  }| j                  xr |j                  }| j                  xr |j                  }| j                  xr |j                  }t	        ||||      S )aa  
        Combine the conditions of these PKIX validation params with another
        set of parameters, producing the most lenient set of parameters that
        is stricter than both inputs.

        :param other:
            Another set of PKIX validation parameters.
        :return:
            A combined set of PKIX validation parameters.
        rl   )rr   ru   rt   rs   )rr   ru   rt   rs   r   )r;   otherinit_policy_setru   rt   rs   s         r+   mergezPKIXValidationParams.merge  s     4777#;;OU:::"::O --0L0LL 
 ++P0P0P 	# ((JU-J-J 	  // 544 	' $$3'A$;+I	
 	
r*   )ry   r   r4   r   )r#   r$   r%   rm   rr   r(   rs   rL   rt   ru   rv   r   r   rw   r{   r)   r*   r+   r   r   T  s    )2L>)BYB
 ,1"D0 %*T)" (-, :> 6= 9=x5<$
r*   r   c                   P    e Zd ZU dZeed<   	 dZee   ed<   	 dZ	ee
   ed<   	 d Zy)r   zh
    Expression of a constraint on the usage of an algorithm (possibly with
    parameter choices).
    allowedNnot_allowed_afterfailure_reasonc                     | j                   S r6   r}   r:   s    r+   __bool__z!AlgorithmUsageConstraint.__bool__  s    ||r*   )r#   r$   r%   r&   rL   r(   r~   r   r   r   r[   r   r)   r*   r+   r   r     sD    
 M -1x)0
 %)NHSM(r*   r   c                       e Zd ZdZdej
                  dee   defdZ	dej                  dee   deej                     defdZy)	r   zR
    Abstract interface defining a usage policy for cryptographic algorithms.
    algomomentr4   c                     t         )a  
        Determine if the indicated digest algorithm can be used at the point
        in time indicated.

        :param algo:
            A digest algorithm description in ASN.1 form.
        :param moment:
            The point in time at which the algorithm should be usable.
            If ``None``, then the returned judgment applies at all times.
        :return:
            A :class:`.AlgorithmUsageConstraint` expressing the judgment.
        NotImplementedErrorr;   r   r   s      r+   digest_algorithm_allowedz-AlgorithmUsagePolicy.digest_algorithm_allowed  s
     "!r*   
public_keyc                     t         )a'  
        Determine if the indicated signature algorithm (including the associated
        digest function and any parameters, if applicable) can be used at the
        point in time indicated.

        :param algo:
            A signature mechanism description in ASN.1 form.
        :param moment:
            The point in time at which the algorithm should be usable.
            If ``None``, then the returned judgment applies at all times.
        :param public_key:
            The public key associated with the operation, if available.

            .. note::
                This parameter can be used to enforce key size limits or
                to filter out keys with known structural weaknesses.
        :return:
            A :class:`.AlgorithmUsageConstraint` expressing the judgment.
        r   r;   r   r   r   s       r+   signature_algorithm_allowedz0AlgorithmUsagePolicy.signature_algorithm_allowed  s
    2 "!r*   N)r#   r$   r%   r&   r	   DigestAlgorithmr   r   r   r   SignedDigestAlgorithmr
   PublicKeyInfor   r)   r*   r+   r   r     sp    "))"3;H3E"	!"""))" "" T//0	"
 
""r*   r   c                       e Zd ZdZe e       ddfdZdej                  de	e
   defdZdej                  de	e
   d	e	ej                     defd
Zy)r   a  
    Primitive usage policy that forbids a list of user-specified
    "weak" algorithms and allows everything else.
    It also ignores the time parameter completely.

    .. note::
        This denial-based strategy is supplied to provide a backwards-compatible
        default.
        In many scenarios, an explicit allow-based strategy is more appropriate.
        Users with specific security requirements are encouraged to implement
        :class:`.AlgorithmUsagePolicy` themselves.

    :param weak_hash_algos:
        The list of digest algorithms considered weak.
        Defaults to :const:`.DEFAULT_WEAK_HASH_ALGOS`.
    :param weak_signature_algos:
        The list of digest algorithms considered weak.
        Defaults to the empty set.
    :param rsa_key_size_threshold:
        The key length threshold for RSA keys, in bits.
    :param dsa_key_size_threshold:
        The key length threshold for DSA keys, in bits.
    i   ix  c                 <    || _         || _        || _        || _        y r6   )weak_hash_algosweak_signature_algosrsa_key_size_thresholddsa_key_size_threshold)r;   r   r   r   r   s        r+   __init__z%DisallowWeakAlgorithmsPolicy.__init__)  s$      /$8!&<#&<#r*   r   r   r4   c                 J    t        |d   j                  | j                  v      S )N	algorithm)r   nativer   r   s      r+   r   z5DisallowWeakAlgorithmsPolicy.digest_algorithm_allowed6  s*     ($$D,@,@@
 	
r*   r   c           	      N   |j                   }|| j                  v}|j                  d      }|dk(  }|rg|e|s|ra|j                  }d }	|r|| j                  k  r| j                  }	n|r|| j
                  k  r| j
                  }	|	t        dd| d| d|	       S 	 |j                  }
|ra|
_| j                  t        j                  d|j                  i      |      }|s,t        dd	| d
|d   j                   d|j                        S t        |      S # t        $ r d }
Y |w xY w)NrsadsaFz	Key size z for algorithm z- is considered too small; policy mandates >= )r}   r   r   zDigest algorithm z< is not allowed, which disqualifies the signature mechanism z	 as well.)r}   r   r~   r   )signature_algor   
startswithbit_sizer   r   r   	hash_algorU   r   r	   r   r   r~   )r;   r   r   r   	algo_namealgo_allowedis_rsais_dsakey_szfailed_thresholdr   digest_alloweds               r+   r   z8DisallowWeakAlgorithmsPolicy.signature_algorithm_allowed=  sm    ''	 (A(AA%%e,e#J2&((F#&4#>#>>#'#>#> FT%@%@@#'#>#> +/!#F8?9+ F..>-?A 	I I1!::%%{DNN&CDfN "/!+N+; <F,334I? '5&F&F  (==!  	I	s   D D$#D$N)r#   r$   r%   r&   r   rm   r   r	   r   r   r   r   r   r   r
   r   r   r)   r*   r+   r   r     s    4 0&[##=
))
3;H3E
	!
,>)),> ",> T//0	,>
 
",>r*   r   c                       e Zd Zdej                  dee   defdZdej                  dee   dee
j                     defdZy)r   r   r   r4   c                     t        d      S NTr   r   r   s      r+   r   z,AcceptAllAlgorithms.digest_algorithm_allowedm  s     (55r*   r   c                     t        d      S r   r   r   s       r+   r   z/AcceptAllAlgorithms.signature_algorithm_allowedr  s     (55r*   N)r#   r$   r%   r	   r   r   r   r   r   r   r
   r   r   r)   r*   r+   r   r   l  sk    6))63;H3E6	!6
6))6 "6 T//0	6
 
"6r*   r   )*r&   abcr^   dataclassesr   r   r   typingr   r   r   
asn1cryptor	   r
   
name_treesr   __all__rm   r   #FRESHNESS_FALLBACK_VALIDITY_DEFAULTr   uniqueEnumr   r   rJ   r   r9   r   r8   r7   rS   r   r   r[   rp   r   r   ABCr   r   r   r)   r*   r+   <module>r      s     ! ( 0 0 " $" $$:;  '0&; # $    f
TYY f
 f
R $
 
 
> +//// ).774== *5555 *0000 
  tyy  6 $, , ,^cN$-cNs^8 $k
 k
 k
\ $  4/"377 /"dY>#7 Y>x6. 6r*   