o
    >h                     @  s   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dZ dddZ!edZ"d ddZ#d 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                 C     t t| t|gg d 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    r$   }/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/service_identity/cryptography.pyr   (   s
   

ip_addressc                 C  r   )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&   r$   r$   r%   verify_certificate_ip_addressL   s
   !
r'   z1.3.6.1.5.5.7.8.7certSequence[CertificatePattern]c                 C  s   g }z	| j tj}W n
 ty   Y |S w |dd |jtD  |dd |jt	D  |dd |jt
D  |jtD ]$}|jtkrjt|j\}}t|trd|t|  qFd}t|qF|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                 S     g | ]
}t |d qS zutf-8)r   
from_bytesencode).0namer$   r$   r%   
<listcomp>       z$extract_patterns.<locals>.<listcomp>c                 S  r*   r+   )r   r,   r-   )r.   urir$   r$   r%   r0      r1   c                 S  s   g | ]}t |qS r$   )r   )r.   ipr$   r$   r%   r0      s    zUnexpected certificate content.)
extensionsget_extension_for_oidr   SUBJECT_ALTERNATIVE_NAMEr   extendvalueget_values_for_typer   r
   r   r	   type_idID_ON_DNS_SRVr   
isinstancer   appendr   r,   asOctetsr   )r(   idsextothersrv_msgr$   r$   r%   r#   w   sF   



r#   c                 C  s   t jtd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(   r$   r$   r%   extract_ids   s   rL   )r   r   r   r   r   r   )r   r   r&   r   r   r   )r(   r   r   r)   )%__doc__
__future__r   rI   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#   rL   r$   r$   r$   r%   <module>   s     $	(

$(
5