
    _f                        d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
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 d	dlmZmZmZmZmZmZmZmZ dgZddZ ddZ! ed          Z"ddZ#ddZ$dS )zL
`cryptography.x509 <https://github.com/pyca/cryptography>`_-specific code.
    )annotationsN)Sequence)CertificateDNSNameExtensionOID	IPAddressObjectIdentifier	OtherNameUniformResourceIdentifier)ExtensionNotFound)decode)	IA5String   )CertificateError)DNS_IDCertificatePattern
DNSPatternIPAddress_IDIPAddressPattern
SRVPattern
URIPatternverify_service_identityverify_certificate_hostnamecertificater   hostnamestrreturnNonec                `    t          t          |           t          |          gg            dS )a  
    Verify whether *certificate* is valid for *hostname*.

    .. note::
        Nothing is verified about the *authority* of the certificate;
        the caller must verify that the certificate chains to an appropriate
        trust root themselves.

    Args:
        certificate: A *cryptography* X509 certificate object.

        hostname: The hostname that *certificate* should be valid for.

    Raises:
        service_identity.VerificationError:
            If *certificate* is not valid for *hostname*.

        service_identity.CertificateError:
            If *certificate* contains invalid / unexpected data. This includes
            the case where the certificate contains no `subjectAltName`\ s.

    .. versionchanged:: 24.1.0
        :exc:`~service_identity.CertificateError` is raised if the certificate
        contains no ``subjectAltName``\ s instead of
        :exc:`~service_identity.VerificationError`.
    cert_patternsobligatory_idsoptional_idsN)r   extract_patternsr   )r   r   s     O/var/www/html/env/lib/python3.11/site-packages/service_identity/cryptography.pyr   r   (   sA    : &{33x(()         
ip_addressc                `    t          t          |           t          |          gg            dS )a  
    Verify whether *certificate* is valid for *ip_address*.

    .. note::
        Nothing is verified about the *authority* of the certificate;
        the caller must verify that the certificate chains to an appropriate
        trust root themselves.

    Args:
        certificate: A *cryptography* X509 certificate object.

        ip_address:
            The IP address that *connection* should be valid for.  Can be an
            IPv4 or IPv6 address.

    Raises:
        service_identity.VerificationError:
            If *certificate* is not valid for *ip_address*.

        service_identity.CertificateError:
            If *certificate* contains invalid / unexpected data. This includes
            the case where the certificate contains no ``subjectAltName``\ s.

    .. versionadded:: 18.1.0

    .. versionchanged:: 24.1.0
        :exc:`~service_identity.CertificateError` is raised if the certificate
        contains no ``subjectAltName``\ s instead of
        :exc:`~service_identity.VerificationError`.
    r    N)r   r$   r   )r   r'   s     r%   verify_certificate_ip_addressr)   L   sB    B &{33$Z001     r&   z1.3.6.1.5.5.7.8.7certSequence[CertificatePattern]c                ,   g }	 | j                             t          j                  }|                    d |j                            t                    D                        |                    d |j                            t                    D                        |                    d |j                            t                    D                        |j                            t                    D ]}|j        t          k    rut          |j                  \  }}t          |t                    r:|                    t#          j        |                                                     xt)          d          n# t*          $ r Y nw xY w|S )a
  
    Extract all valid ID patterns from a certificate for service verification.

    Args:
        cert: The certificate to be dissected.

    Returns:
        List of IDs.

    .. versionchanged:: 23.1.0
       ``commonName`` is not used as a fallback anymore.
    c                \    g | ])}t          j        |                    d                     *S zutf-8)r   
from_bytesencode).0names     r%   
<listcomp>z$extract_patterns.<locals>.<listcomp>   s?        %dkk'&:&:;;  r&   c                \    g | ])}t          j        |                    d                     *S r.   )r   r/   r0   )r1   uris     r%   r3   z$extract_patterns.<locals>.<listcomp>   s?        %cjj&9&9::  r&   c                ,    g | ]}t          |          S  )r   )r1   ips     r%   r3   z$extract_patterns.<locals>.<listcomp>   s0        !$$  r&   zUnexpected certificate content.)
extensionsget_extension_for_oidr   SUBJECT_ALTERNATIVE_NAMEextendvalueget_values_for_typer   r   r   r
   type_idID_ON_DNS_SRVr   
isinstancer   appendr   r/   asOctetsr   r   )r*   idsextothersrv_s         r%   r$   r$   w   s    %'C!No331
 
 	

 I99'BB  	
 	
 	
 	

 988-   	
 	
 	
 	

 )77	BB  	
 	
 	
 Y229== 	N 	NE}--,,Qc9-- NJJz4S\\^^DDEEEE*+LMMM .	N/    > Js   $F 
FFc                X    t          j        t          dd           t          |           S )zm
    Deprecated and never public API.  Use :func:`extract_patterns` instead.

    .. deprecated:: 23.1.0
    z?`extract_ids()` is deprecated, please use `extract_patterns()`.   )categorymessage
stacklevel)warningswarnDeprecationWarningr$   )r*   s    r%   extract_idsrQ      s6     M#Q   
 D!!!r&   )r   r   r   r   r   r   )r   r   r'   r   r   r   )r*   r   r   r+   )%__doc__
__future__r   rN   typingr   cryptography.x509r   r   r   r   r	   r
   r   cryptography.x509.extensionsr   pyasn1.codec.der.decoderr   pyasn1.type.charr   
exceptionsr   hazmatr   r   r   r   r   r   r   r   __all__r   r)   r@   r$   rQ   r7   r&   r%   <module>r\      s    # " " " " "                         ; : : : : : + + + + + + & & & & & & ( ( ( ( ( (	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 )
)! ! ! !H% % % %P ! !4551 1 1 1h" " " " " "r&   