
    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$y)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_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     ?/usr/lib/python3/dist-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&   L   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'        |t(              r3|j+                  t-        j                  |j/                                      rt1        d       |S c c}w c c}w c c}w # t2        $ 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.)
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   
isinstancer   appendr   asOctetsr   r   )	certidsextnameuriipothersrv_s	            r"   r   r   w   s    %'C!Noo3311
 	

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

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

 ))77	B !$	
 YY229= 	NE}}-,Qc9-JJz44S\\^DE*+LMM	N J7%  < J?s#   )G +G7+GG	G)(G)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   )r5   s    r"   extract_idsrF      s&     MM#Q
 D!!r#   )r    r   r!   strreturnNone)r    r   r%   rG   rH   rI   )r5   r   rH   zSequence[CertificatePattern])%__doc__
__future__r   rC   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&   r1   r   rF    r#   r"   <module>rU      s    #     ; + & (	 	 	 )
)!!(+!	!H%%*-%	%P !!451h"r#   