
    Wwg-              
           d dl Z d dlZd dlmZmZ d dlmZ ddlmZ ddl	m
Z
 ddlmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZmZ ddlmZmZ g dZ	 ddej:                  dee   de
dee   fdZ G d d      Zy)    N)IterableOptional)x509   )	type_name)ValidationContext)InvalidCertificateErrorPathBuildingErrorValidationError)ValidationPath)PKIXValidationParams)CancelableAsyncIterator)async_validate_pathvalidate_tls_hostnamevalidate_usage)__version____version_info__)r   r   CertificateValidatorr   r   find_valid_pathcertificatepathsvalidation_contextpkix_validation_paramsc                 B  K   g }	 |2 3 d {   }	 t        |||       d {    |c |j                          d {    S 7 67 "7 	# t        $ r}|j                  |       Y d }~`d }~ww xY w6 n?# t        $ r3 | j
                  dv r#t        d| j                  j                   d       w xY w	 |j                          d {  7   n# |j                          d {  7   w xY wt        |      dk(  r|d   d }|D ]  }dt        |      vs|} |r||d   w)N>   yesmaybez1The X.509 certificate provided is self-signed - ""r   r   	signature)r   cancelr   appendr
   self_signedr	   subjecthuman_friendlylenstr)	r   r   r   r   
exceptionscandidate_pathenon_signature_exception	exceptions	            U/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko_certvalidator/__init__.pyr   r      sZ     J$) 	% 	%.%)&8N   &% lln!	% 	 # %!!!$$% %*  ""&66)''667q:  	 %*  llnelln
:!m" 0	c)n,&/#0 %%
Q-s   DA2 A0AA0A2 A	AA	A2 DADA0A	D		A-A(#A2 (A--A2 1C 2<B..C 2DCDC' C#!C''*DDc            
           e Zd ZdZ	 	 	 ddej
                  deeej
                        dee   dee	   fdZ
ed        Zdefd	Z	 dd
Z	 ddZd Zd Zy)r   Nend_entity_certintermediate_certsr   pkix_paramsc                     |
t               }|$|j                  }|D ]  }|j                  |        || _        || _        || _        y)a
  
        :param end_entity_cert:
            An asn1crypto.x509.Certificate object X.509 end-entity
            certificate to validate

        :param intermediate_certs:
            None or a list of asn1crypto.x509.Certificate
            Used in constructing certificate paths for validation.

        :param validation_context:
            A pyhanko_certvalidator.context.ValidationContext() object that
            controls generic validation options and tracks revocation data.

            The same validation context will also be used in the validation
            of relevant certificates found in OCSP responses and/or CRLs.

        :param pkix_params:
            A pyhanko_certvalidator.context.PKIXValidationParams() object that
            controls advanced PKIX validation parameters used to validate
            the end-entity certificate. These can be used to constrain
            policy processing and names.

            Ancillary validation of CRLs and OCSP responses ignore these
            settings.
        N)r   certificate_registryregister_context_certificate_params)selfr-   r.   r   r/   r1   intermediate_certs          r+   __init__zCertificateValidator.__init__F   s_    B %!2!4)#5#J#J %7 A!$--.?@A ,>.=7B    c                     | j                   S N)r4   )r6   s    r+   r   z CertificateValidator.certificates   s       r9   returnc                   K   | j                   | j                   S | j                  }| j                  j                  j	                  |      }t        ||| j                  | j                         d{   x| _         }|S 7 w)a  
        Builds possible certificate paths and validates them until a valid one
        is found, or all fail.

        :raises:
            pyhanko_certvalidator.errors.PathBuildingError - when an error occurs building the path
            pyhanko_certvalidator.errors.PathValidationError - when an error occurs validating the path
            pyhanko_certvalidator.errors.RevokedError - when the certificate or another certificate in its path has been revoked
        N)r   r   )_pathr4   r3   path_builderasync_build_paths_lazyr   r5   )r6   r   r   r'   s       r+   r   z(CertificateValidator.async_validate_pathw   sz      ::!::''**AA+N,;#}}#'<<	-
 '
 	

^ '
s   A0B2B 3Bc                     t        j                  dt               t        j                  | j                  |||            S )a  
        Validates the certificate path and that the certificate is valid for
        the key usage and extended key usage purposes specified.

        .. deprecated:: 0.17.0
            Use :meth:`async_validate_usage` instead.

        :param key_usage:
            A set of unicode strings of the required key usage purposes. Valid
            values include:

             - "digital_signature"
             - "non_repudiation"
             - "key_encipherment"
             - "data_encipherment"
             - "key_agreement"
             - "key_cert_sign"
             - "crl_sign"
             - "encipher_only"
             - "decipher_only"

        :param extended_key_usage:
            A set of unicode strings of the required extended key usage
            purposes. These must be either dotted number OIDs, or one of the
            following extended key usage purposes:

             - "server_auth"
             - "client_auth"
             - "code_signing"
             - "email_protection"
             - "ipsec_end_system"
             - "ipsec_tunnel"
             - "ipsec_user"
             - "time_stamping"
             - "ocsp_signing"
             - "wireless_access_points"

            An example of a dotted number OID:

             - "1.3.6.1.5.5.7.3.1"

        :param extended_optional:
            A bool - if the extended_key_usage extension may be ommited and still
            considered valid

        :raises:
            pyhanko_certvalidator.errors.PathValidationError - when an error occurs validating the path
            pyhanko_certvalidator.errors.RevokedError - when the certificate or another certificate in its path has been revoked
            pyhanko_certvalidator.errors.InvalidCertificateError - when the certificate is not valid for the usages specified

        :return:
            A pyhanko_certvalidator.path.ValidationPath object of the validated
            certificate validation path
        zB'validate_usage' is deprecated, use 'async_validate_usage' instead)warningswarnDeprecationWarningasynciorunasync_validate_usage)r6   	key_usageextended_key_usageextended_optionals       r+   r   z#CertificateValidator.validate_usage   sC    t 	-	
 {{%%-/@
 	
r9   c                    K   | j                          d{   }t        | j                  | j                  |||       |S 7 )w)aN  
        Validates the certificate path and that the certificate is valid for
        the key usage and extended key usage purposes specified.

        :param key_usage:
            A set of unicode strings of the required key usage purposes. Valid
            values include:

             - "digital_signature"
             - "non_repudiation"
             - "key_encipherment"
             - "data_encipherment"
             - "key_agreement"
             - "key_cert_sign"
             - "crl_sign"
             - "encipher_only"
             - "decipher_only"

        :param extended_key_usage:
            A set of unicode strings of the required extended key usage
            purposes. These must be either dotted number OIDs, or one of the
            following extended key usage purposes:

             - "server_auth"
             - "client_auth"
             - "code_signing"
             - "email_protection"
             - "ipsec_end_system"
             - "ipsec_tunnel"
             - "ipsec_user"
             - "time_stamping"
             - "ocsp_signing"
             - "wireless_access_points"

            An example of a dotted number OID:

             - "1.3.6.1.5.5.7.3.1"

        :param extended_optional:
            A bool - if the extended_key_usage extension may be ommited and still
            considered valid

        :raises:
            pyhanko_certvalidator.errors.PathValidationError - when an error occurs validating the path
            pyhanko_certvalidator.errors.RevokedError - when the certificate or another certificate in its path has been revoked
            pyhanko_certvalidator.errors.InvalidCertificateError - when the certificate is not valid for the usages specified

        :return:
            A pyhanko_certvalidator.path.ValidationPath object of the validated
            certificate validation path
        N)r   r   r3   r4   )r6   rH   rI   rJ   validated_paths        r+   rG   z)CertificateValidator.async_validate_usage   sH     n  $7799MM	
  :s   AA *Ac                 ~    t        j                  dt               t        j                  | j                  |            S )ah  
        Validates the certificate path, that the certificate is valid for
        the hostname provided and that the certificate is valid for the purpose
        of a TLS connection.

        .. deprecated:: 0.17.0
            Use :meth:`async_validate_tls` instead.

        :param hostname:
            A unicode string of the TLS server hostname

        :raises:
            pyhanko_certvalidator.errors.PathValidationError - when an error occurs validating the path
            pyhanko_certvalidator.errors.RevokedError - when the certificate or another certificate in its path has been revoked
            pyhanko_certvalidator.errors.InvalidCertificateError - when the certificate is not valid for TLS or the hostname

        :return:
            A pyhanko_certvalidator.path.ValidationPath object of the validated
            certificate validation path
        z>'validate_tls' is deprecated, use 'async_validate_tls' instead)rB   rC   rD   rE   rF   async_validate_tlsr6   hostnames     r+   validate_tlsz!CertificateValidator.validate_tls  s2    , 	L	

 {{4228<==r9   c                    K   | j                          d{    t        | j                  | j                  |       | j                  S 7 1w)a  
        Validates the certificate path, that the certificate is valid for
        the hostname provided and that the certificate is valid for the purpose
        of a TLS connection.

        :param hostname:
            A unicode string of the TLS server hostname

        :raises:
            pyhanko_certvalidator.errors.PathValidationError - when an error occurs validating the path
            pyhanko_certvalidator.errors.RevokedError - when the certificate or another certificate in its path has been revoked
            pyhanko_certvalidator.errors.InvalidCertificateError - when the certificate is not valid for TLS or the hostname

        :return:
            A pyhanko_certvalidator.path.ValidationPath object of the validated
            certificate validation path
        N)r   r   r3   r4   r>   rO   s     r+   rN   z'CertificateValidator.async_validate_tls4  s?     & &&(((dmmT->->Izz 	)s   A
A2A
)NNN)NF)__name__
__module____qualname__r>   r   Certificater   r   r   r   r8   propertyr   r   r   r   rG   rQ   rN    r9   r+   r   r   B   s    E
 DH:>6:+C))+C %Xd.>.>%?@+C %%67	+C
 23+CZ ! !> 4 EJD
N EJ?B>:r9   r   r;   ) rE   rB   typingr   r   
asn1cryptor   _typesr   contextr   errorsr	   r
   r   pathr   policy_declr   utilr   validater   r   r   versionr   r   __all__rV   r   r   rX   r9   r+   <module>rd      s      %   & O O   - ) P P 2 >B	%!!%">2% *% %%9:	%PG Gr9   