
     hJ                     P   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	 ddl
mZmZ ddlmZ g d	Z eg d
          Z	 ej         G d dej                              Z ed           G d d                      Z eej        ej                  Z	  eej        ej                  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j#                  Z$ G d! d"e$          Z% G d# d$e$          Z&dS )%z
.. versionadded:: 0.20.0
    N)	dataclass)datetime	timedelta)	FrozenSetOptional)algoskeys   )PKIXSubtrees)RevocationCheckingRuleRevocationCheckingPolicyFreshnessReqTypeCertRevTrustPolicyPKIXValidationParamsAlgorithmUsageConstraintAlgorithmUsagePolicyDisallowWeakAlgorithmsPolicyAcceptAllAlgorithmsDEFAULT_WEAK_HASH_ALGOSREQUIRE_REVINFONO_REVOCATION)md2md5sha1c                       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dS )r   zg
    Rules determining in what circumstances revocation data has to be checked,
    and what kind.
    clrcheck	ocspcheck	bothcheckeitherchecknocheckifdeclaredcheckifdeclaredsoftcheckreturnc                 L    | t           j        t           j        t           j        fvS N)r   CHECK_IF_DECLAREDCHECK_IF_DECLARED_SOFTNO_CHECKselfs    ]/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/pyhanko_certvalidator/policy_decl.pystrictzRevocationCheckingRule.stricta   s(     "4"9"+
 
 	
    c                 6    | t           j        t           j        fv S r%   )r   r'   r(   r)   s    r+   tolerantzRevocationCheckingRule.tolerantj   s     "9"+
 
 	
r-   c                 6    | t           j        t           j        fv S r%   )r   CRL_REQUIREDCRL_AND_OCSP_REQUIREDr)   s    r+   crl_mandatoryz$RevocationCheckingRule.crl_mandatoryq   s     "/"8
 
 	
r-   c                 6    | t           j        t           j        fvS r%   )r   r(   OCSP_REQUIREDr)   s    r+   crl_relevantz#RevocationCheckingRule.crl_relevantx   s     "+"0
 
 	
r-   c                 6    | t           j        t           j        fv S r%   )r   r5   r2   r)   s    r+   ocsp_mandatoryz%RevocationCheckingRule.ocsp_mandatory   s     "0"8
 
 	
r-   c                 6    | t           j        t           j        fvS r%   )r   r(   r1   r)   s    r+   ocsp_relevantz$RevocationCheckingRule.ocsp_relevant   s     "+"/
 
 	
r-   N)__name__
__module____qualname____doc__r1   r5   r2   CRL_OR_OCSP_REQUIREDr(   r&   r'   propertyboolr,   r/   r3   r6   r8   r:    r-   r+   r   r   $   s`         L  M ( ) H *
 3 
 
 
 
 X
 
$ 
 
 
 X
 
t 
 
 
 X
 
d 
 
 
 X
 
 
 
 
 X
 
t 
 
 
 X
 
 
r-   r   T)frozenc                   d    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dS )	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                 `    	 t           |         S # t          $ r t          d| d          w xY w)N'z ' is not a valid revocation mode)LEGACY_POLICY_MAPKeyError
ValueError)clsrG   s     r+   from_legacyz$RevocationCheckingPolicy.from_legacy   sL    	K$V,, 	K 	K 	KIIIIJJJ	Ks    -r#   c                 4    | j         j        o| j         j         S r%   )rE   r/   r)   s    r+   	essentialz"RevocationCheckingPolicy.essential   s%     $- 2(1
 	
r-   N)r;   r<   r=   r>   r   __annotations__classmethodstrrN   r@   rA   rP   rB   r-   r+   r   r      s          
 0///  6555 K K K K [K 
4 
 
 
 X
 
 
r-   r   )rE   rF   )z	soft-failz	hard-failrequirec                   p    e Zd ZdZ ej                    Z	  ej                    Z	  ej                    ZdS )r   z%
    Freshness requirement type.
    N)	r;   r<   r=   r>   enumautoDEFAULTMAX_DIFF_REVOCATION_VALIDATIONTIME_AFTER_SIGNATURErB   r-   r+   r   r      sW          dikkG &/TY[[" %49;; 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<   dS )	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   rQ   r]   r   r   r   rX   r^   r_   r`   rA   rB   r-   r+   r   r      s          
 !9888 &*Ix	"))) ,<+C(CCC
 >B%x	':AAA
 !&%%% r-   r   a_polsb_polsr#   c                 T    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)ra   rb   a_anyb_anys       r+   intersect_policy_setsrh     s[     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dS )r   rd   user_initial_policy_setFinitial_policy_mapping_inhibitinitial_explicit_policyinitial_any_policy_inhibitNinitial_permitted_subtreesinitial_excluded_subtreesotherr#   c                     d| j         v r|j         }n d|j         v r| j         }n|j         | j         z  }| j        o|j        }| j        o|j        }| j        o|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.
        rd   )rj   rm   rl   rk   )rj   rm   rl   rk   r   )r*   rp   init_policy_setrm   rl   rk   s         r+   mergezPKIXValidationParams.merge  s     4777#;OOU:::":OO -0LL 
 +P0P 	# (JU-J 	  / 54 	' $$3'A$;+I	
 
 
 	
r-   )rp   r   r#   r   )r;   r<   r=   re   rj   rQ   rk   rA   rl   rm   rn   r   r   ro   rs   rB   r-   r+   r   r   8  s         )2L>)B)BYBBB
 ,1"D000 %*T)))" (-,,, :> 6=== 9=x5<<<$
 $
 $
 $
 $
 $
r-   r   c                   ^    e Zd ZU dZeed<   	 dZee         ed<   	 dZ	ee
         ed<   	 d ZdS )r   zh
    Expression of a constraint on the usage of an algorithm (possibly with
    parameter choices).
    allowedNnot_allowed_afterfailure_reasonc                     | j         S r%   ru   r)   s    r+   __bool__z!AlgorithmUsageConstraint.__bool__  s
    |r-   )r;   r<   r=   r>   rA   rQ   rv   r   r   rw   rS   rz   rB   r-   r+   r   r     sw          
 MMM -1x)00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dS )	r   zR
    Abstract interface defining a usage policy for cryptographic algorithms.
    algomomentr#   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   rB   r-   r+   r   r     s         ")"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dS )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                 >    || _         || _        || _        || _        d S r%   )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}   r#   c                 D    t          |d         j        | j        v          S )N	algorithm)r   nativer   r   s      r+   r   z5DisallowWeakAlgorithmsPolicy.digest_algorithm_allowed  s)     ($D,@@
 
 	
r-   r   c           	         |j         }|| j        v}|                    d          }|dk    }|rT|R|s|rN|j        }d }	|r|| j        k     r| j        }	n|r|| j        k     r| j        }	|	t          dd| d| d|	           S 	 |j        }
n# t          $ r d }
Y nw xY w|r\|
Z| 	                    t          j        d|j        i          |          }|s)t          dd	| d
|d         j         d|j                  S t          |          S )NrsadsaFz	Key size z for algorithm z- is considered too small; policy mandates >= )ru   rw   r   zDigest algorithm z< is not allowed, which disqualifies the signature mechanism z	 as well.)ru   rw   rv   ry   )signature_algor   
startswithbit_sizer   r   r   	hash_algorL   r   r   r   r   rv   )r*   r|   r}   r   	algo_namealgo_allowedis_rsais_dsakey_szfailed_thresholdr   digest_alloweds               r+   r   z8DisallowWeakAlgorithmsPolicy.signature_algorithm_allowed!  s    '	 (AA%%e,,e# 	J22&2(F# ?&4#>>>#'#>   ?FT%@@@#'#> +/!AF A A9 A A.>A A   	II 	 	 	III	 	I1!::%{DN&CDDf N " 	/!?N ? ?,3? ? ? '5&F    (====s   B BBN)r;   r<   r=   r>   r   re   r   r   r   r   r   r   r   r   r	   r   r   rB   r-   r+   r   r     s         4 0&Y[[##= = = =
)
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dS )r   r|   r}   r#   c                 "    t          d          S NTry   r   r   s      r+   r   z,AcceptAllAlgorithms.digest_algorithm_allowedQ  s     (5555r-   r   c                 "    t          d          S r   r   r   s       r+   r   z/AcceptAllAlgorithms.signature_algorithm_allowedV  s     (5555r-   N)r;   r<   r=   r   r   r   r   r   r   r   r	   r   r   rB   r-   r+   r   r   P  s        6)63;H3E6	!6 6 6 6
6)6 "6 T/0	6
 
"6 6 6 6 6 6r-   r   )'r>   abcrV   dataclassesr   r   r   typingr   r   
asn1cryptor   r	   
name_treesr   __all__re   r   uniqueEnumr   r   r?   r   r(   r   r'   r&   rJ   r   r   rS   rh   r   r   ABCr   r   r   rB   r-   r+   <module>r      s    


  ! ! ! ! ! ! ( ( ( ( ( ( ( ( & & & & & & & & " " " " " " " " $ $ $ $ $ $    $)$:$:$:;; 
 f
 f
 f
 f
 f
TY f
 f
 f
R $
 
 
 
 
 
 
 
> +*//  )(.74=   *)55  *)00  
 
      ty   6 $* * * * * * * *ZcN$-cNs^   8 $k
 k
 k
 k
 k
 k
 k
 k
\ $       4/" /" /" /" /"37 /" /" /"dY> Y> Y> Y> Y>#7 Y> Y> Y>x6 6 6 6 6. 6 6 6 6 6r-   