
    #a"                         d Z ddlmZmZ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mZmZmZmZmZmZmZ dd
lmZ dgZd Zd Z ed          Zd ZdS )zA
`pyOpenSSL <https://github.com/pyca/pyopenssl>`_-specific code.
    )absolute_importdivisionprint_functionN)decode)	IA5String)ObjectIdentifier)GeneralNames   )DNS_IDCertificateError
DNSPatternIPAddress_IDIPAddressPattern
SRVPattern
URIPatternverify_service_identity)SubjectAltNameWarningverify_hostnamec                     t          t          |                                           t          |          gg            dS )a?  
    Verify whether the certificate of *connection* is valid for *hostname*.

    :param OpenSSL.SSL.Connection connection: A pyOpenSSL connection object.
    :param unicode 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*.
    :raises service_identity.CertificateError: If the certificate chain of
        *connection* contains a certificate that contains invalid/unexpected
        data.

    :returns: ``None``
    cert_patternsobligatory_idsoptional_idsN)r   extract_idsget_peer_certificater   )
connectionhostnames     :lib/python3.11/site-packages/service_identity/pyopenssl.pyr   r       sM      !*"A"A"C"CDDx(()         c                     t          t          |                                           t          |          gg            dS )a  
    Verify whether the certificate of *connection* is valid for *ip_address*.

    :param OpenSSL.SSL.Connection connection: A pyOpenSSL connection object.
    :param unicode 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*.
    :raises service_identity.CertificateError: If the certificate chain of
        *connection* contains a certificate that contains invalid/unexpected
        data.

    :returns: ``None``

    .. versionadded:: 18.1.0
    r   N)r   r   r   r   )r   
ip_addresss     r   verify_ip_addressr"   7   sM    $ !*"A"A"C"CDD$Z001     r   z1.3.6.1.5.5.7.8.7c                    g }t           j                            |                                           D ]&}|                     |          }|                                dk    rt          |                                t                                \  }}|D ]}|	                                }|dk    rG|
                    t          |                                                                                     d|dk    rL|
                    t          j        |                                                                                     |dk    rH|
                    t!          |                                                                                     |dk    r|                                }|                    d          }	|	t$          k    rt          |                    d                    \  }
}t'          |
t(                    r6|
                    t+          |
                                                     t-          d	          (|sd
 |                                                                 D             }t3          t5          |          d          }d |D             }t7          j        d|                    d          dt:          d           |S )a  
    Extract all valid IDs from a certificate for service verification.

    If *cert* doesn't contain any identifiers, the ``CN``s are used as DNS-IDs
    as fallback.

    :param OpenSSL.SSL.X509 cert: The certificate to be dissected.

    :return: List of IDs.
    s   subjectAltName)asn1SpecdNSName	iPAddressuniformResourceIdentifier	otherNamer   r
   zUnexpected certificate content.c                 6    g | ]}|d          dk    |d         S )r   s   CNr
    .0cs     r   
<listcomp>zextract_ids.<locals>.<listcomp>   s,     
 
 
1AaDr   s   <not given>c                 ,    g | ]}t          |          S r*   )r   r+   s     r   r.   zextract_ids.<locals>.<listcomp>   s    111z!}}111r   zCertificate with CN 'zutf-8z' has no `subjectAltName`, falling back to check for a `commonName` for now.  This feature is being removed by major browsers and deprecated by RFC 2818.  service_identity will remove the support for it in mid-2018.   )
stacklevel)sixmovesrangeget_extension_countget_extensionget_short_namer   get_datar	   getNameappendr   getComponentasOctetsr   
from_bytesr   getComponentByPositionID_ON_DNS_SRV
isinstancer   r   r   get_subjectget_componentsnextiterwarningswarnr   )certidsiextnames_nname_stringcompoidsrv
componentscns                r   r   r   S   s    CY__T557788    ###444cllnn|~~FFFHE1  iikk)++JJz!..*:*:*C*C*E*EFFGGGG K//JJ(3NN,,5577    
 !$???JJz!..*:*:*C*C*E*EFFGGGG K//>>++D55a88Cm++!'(C(CA(F(F!G!GQ%c955 JJz#,,..'A'ABBBB"2 A# #   


 
**,,;;==
 
 

 $z""N3311j111
 yy!!!!	$
 "	
 	
 	
 	
 Jr   )__doc__
__future__r   r   r   rE   r2   pyasn1.codec.der.decoderr   pyasn1.type.charr   pyasn1.type.univr   pyasn1_modules.rfc2459r	   _commonr   r   r   r   r   r   r   r   
exceptionsr   __all__r   r"   r?   r   r*   r   r   <module>r]      sV    A @ @ @ @ @ @ @ @ @  



 + + + + + + & & & & & & - - - - - - / / / / / /	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 . - - - - - 
  .  2 ! !455? ? ? ? ?r   