o
    vh-                  
   @   s   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dZG dd dZdS )    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           	         s  g }z[z:|2 z43 d H W }zt |||I d H  |W   W W | I d H  S  ty; } z|| W Y d }~qd }~ww 6 W n tyU   | jdv rTtd| jj d w W | I d H  n| I d H  w t	|dkrq|d d }|D ]
}dt
|vr|}qu|r||d )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	exception r)   \/var/www/html/hyperkenya/venv/lib/python3.10/site-packages/pyhanko_certvalidator/__init__.pyr      sH   

 r   c                
   @   s   e Zd ZdZ			ddejdeeej  dee dee	 fddZ
edd	 Zd
efddZ	dddZ	dddZdd Zdd ZdS )r   Nend_entity_certintermediate_certsr   pkix_paramsc                 C   sF   |du rt  }|dur|j}|D ]}|| q|| _|| _|| _dS )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-   r.   intermediate_certr)   r)   r*   __init__F   s   !
zCertificateValidator.__init__c                 C   s   | j S N)r1   )r3   r)   r)   r*   r   s   s   z CertificateValidator.certificatereturnc                    sJ   | j dur	| j S | j}| jj|}t||| j| jdI dH  | _ }|S )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   )_pathr1   r0   path_builderasync_build_paths_lazyr   r2   )r3   r   r   r%   r)   r)   r*   r   w   s   
z(CertificateValidator.async_validate_pathFc                 C   s    t dt t| |||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)r3   	key_usageextended_key_usageextended_optionalr)   r)   r*   r      s   :z#CertificateValidator.validate_usagec                    s(   |   I dH }t| j| j||| |S )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   r0   r1   )r3   rA   rB   rC   validated_pathr)   r)   r*   r@      s   7z)CertificateValidator.async_validate_usagec                 C   s   t dt t| |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)r;   r<   r=   r>   r?   async_validate_tlsr3   hostnamer)   r)   r*   validate_tls  s
   z!CertificateValidator.validate_tlsc                    s&   |   I dH  t| j| j| | jS )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   r0   r1   r8   rF   r)   r)   r*   rE   4  s   z'CertificateValidator.async_validate_tls)NNN)NF)__name__
__module____qualname__r8   r   Certificater   r   r   r   r5   propertyr   r   r   r   r@   rH   rE   r)   r)   r)   r*   r   B   s.    
-

G
Ar   r6   ) r>   r;   typingr   r   
asn1cryptor   _typesr   contextr   errorsr   r	   r
   pathr   policy_declr   utilr   validater   r   r   versionr   r   __all__rL   r   r   r)   r)   r)   r*   <module>   s0    
(