
    kj                        d Z ddlmZ ddl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 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"y)zL
`cryptography.x509 <https://github.com/pyca/cryptography>`_-specific code.
    )annotationsN)Sequence)asn1)CertificateDNSNameExtensionOID	IPAddressObjectIdentifier	OtherNameUniformResourceIdentifier)ExtensionNotFound   )CertificateError)DNS_IDCertificatePattern
DNSPatternIPAddress_IDIPAddressPattern
SRVPattern
URIPatternverify_service_identityverify_certificate_hostnamec                F    t        t        |       t        |      gg        y)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   )certificatehostnames     f/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/service_identity/cryptography.pyr   r   '   s"    : &{3x()    c                F    t        t        |       t        |      gg        y)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   
ip_addresss     r!   verify_certificate_ip_addressr%   K   s#    B &{3$Z01r"   z1.3.6.1.5.5.7.8.7c           
     ,   g }	 | j                   j                  t        j                        }|j	                  |j
                  j                  t              D cg c]&  }t        j                  |j                  d            ( c}       |j	                  |j
                  j                  t              D cg c]&  }t        j                  |j                  d            ( c}       |j	                  |j
                  j                  t              D cg c]  }t        |       c}       |j
                  j                  t              D ]  }|j                   t"        k(  s	 t%        j&                  t$        j(                  |j
                        }|j/                  t1        j                  |j3                         j                  d                    |S c c}w c c}w c c}w # t*        $ r}d}	t-        |	      |d}~ww xY w# t4        $ r Y |S w xY w)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.
    zutf-8zUnexpected certificate content.Nascii)
extensionsget_extension_for_oidr   SUBJECT_ALTERNATIVE_NAMEextendvalueget_values_for_typer   r   
from_bytesencoder   r   r	   r   r   type_idID_ON_DNS_SRVr   
decode_der	IA5String
ValueErrorr   appendr   as_strr   )
certidsextnameuriipothersrvemsgs
             r!   r   r   v   s    %'C#Poo3311
 	

  II99'B %%dkk'&:;	
 	

 9988- %%cjj&9:	
 	

 ))77	B !$	
 YY229= 	PE}}-7//$..%++FC
 

:001D1DW1MNO	P J; " 7;C*3/Q677  @ JCs;   )H +G7+GG"%.G''	H0G>>H	HHc                P    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   )r7   s    r!   extract_idsrI      s&     MM#Q
 D!!r"   )r   r   r    strreturnNone)r   r   r$   rJ   rK   rL   )r7   r   rK   zSequence[CertificatePattern])#__doc__
__future__r   rF   typingr   cryptography.hazmatr   cryptography.x509r   r   r   r	   r
   r   r   cryptography.x509.extensionsr   
exceptionsr   hazmatr   r   r   r   r   r   r   r   __all__r   r%   r1   r   rI    r"   r!   <module>rW      s    #   $   ; (	 	 	 )
)!!(+!	!H%%*-%	%P !!453l"r"   