
    _f                    :   d Z ddlmZ ddlZddl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 d	d
lmZ d	dlmZmZmZmZmZmZmZmZ  ej        e          5  ddlmZ ddlmZ ddd           n# 1 swxY w Y   dgZ ddZ!ddZ" ed          Z#d dZ$d dZ%dS )!zA
`pyOpenSSL <https://github.com/pyca/pyopenssl>`_-specific code.
    )annotationsN)Sequence)decode)	IA5String)ObjectIdentifier)GeneralNames   )CertificateError)DNS_IDCertificatePattern
DNSPatternIPAddress_IDIPAddressPattern
SRVPattern
URIPatternverify_service_identity)X509)
Connectionverify_hostname
connectionr   hostnamestrreturnNonec                    t          t          |                                           t          |          gg            dS )a;  
    Verify whether the certificate of *connection* is valid for *hostname*.

    Args:
        connection: A pyOpenSSL connection object.

        hostname: The hostname that *connection* should be connected to.

    Raises:
        service_identity.VerificationError:
            If *connection* does not provide a certificate that is valid for
            *hostname*.

        service_identity.CertificateError:
            If certificate provided by *connection* 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_patternsget_peer_certificater   )r   r   s     L/var/www/html/env/lib/python3.11/site-packages/service_identity/pyopenssl.pyr   r   '   sT    0 &++--
 
 x(()         
ip_addressc                    t          t          |                                           t          |          gg            dS )aX  
    Verify whether the certificate of *connection* is valid for *ip_address*.

    Args:
        connection: A pyOpenSSL connection object.

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

    Raises:
        service_identity.VerificationError:
            If *connection* does not provide a certificate that is valid for
            *ip_address*.

        service_identity.CertificateError:
            If the certificate chain of *connection* contains a certificate
            that contains invalid/unexpected data.

    .. 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$   s     r"   verify_ip_addressr&   H   sT    6 &++--
 
 %Z001     r#   z1.3.6.1.5.5.7.8.7certr   Sequence[CertificatePattern]c                   g }t          |                                           D ]5}|                     |          }|                                dk    rt	          |                                t                                \  }}|D ]}|                                }|dk    rL|                    t          j
        |                                                                                     i|dk    rL|                    t          j
        |                                                                                     |dk    rM|                    t          j
        |                                                                                     |dk    r|                                }|                    d          }	|	t           k    rt	          |                    d                    \  }
}t#          |
t$                    r;|                    t'          j
        |
                                                     t)          d	          ΐА7|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.
    s   subjectAltName)asn1SpecdNSName	iPAddressuniformResourceIdentifier	otherNamer   r	   zUnexpected certificate content.)rangeget_extension_countget_extensionget_short_namer   get_datar   getNameappendr   
from_bytesgetComponentasOctetsr   r   getComponentByPositionID_ON_DNS_SRV
isinstancer   r   r
   )r'   idsiextnames_nname_stringcompoidsrvs              r"   r    r    o   s3    %'C4++--.. " "  ###444cllnn|~~FFFHE1  iikk)++JJ"-ann.>.>.G.G.I.IJJ    !K//JJ(3NN,,5577    
 !$???JJ"-ann.>.>.G.G.I.IJJ    !K//>>++D55a88Cm++!'(C(CA(F(F!G!GQ%c955 JJz'<S\\^^'L'LMMMM"2 A# #  Jr#   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_idsrN      s6     M#Q   
 D!!!r#   )r   r   r   r   r   r   )r   r   r$   r   r   r   )r'   r   r   r(   )&__doc__
__future__r   
contextlibrK   typingr   pyasn1.codec.der.decoderr   pyasn1.type.charr   pyasn1.type.univr   pyasn1_modules.rfc2459r   
exceptionsr
   hazmatr   r   r   r   r   r   r   r   suppressImportErrorOpenSSL.cryptor   OpenSSL.SSLr   __all__r   r&   r:   r    rN    r#   r"   <module>r_      s    # " " " " "            + + + + + + & & & & & & - - - - - - / / / / / / ( ( ( ( ( (	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 Z%% ' '######&&&&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 
   B! ! ! !H ! !4552 2 2 2j" " " " " "s   A22A69A6