File: //proc/1233/cwd/lib/python3/dist-packages/service_identity/__pycache__/pyopenssl.cpython-310.pyc
o
��\" � @ s� d Z ddlmZmZmZ ddlZddlZddlmZ ddl m
Z
ddlmZ ddl
mZ dd lmZmZmZmZmZmZmZmZ dd
lmZ dgZdd� Zd
d� Zed�Zdd� ZdS )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 C � t t| �� �t|�gg d� dS )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�hostname� r �</usr/lib/python3/dist-packages/service_identity/pyopenssl.pyr s
�c C r )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_addressr r r �verify_ip_address7 s
�r z1.3.6.1.5.5.7.8.7c
C sp g }t j�| �� �D ]�}| �|�}|�� dkr�t|�� t� d�\}}|D ]g}|� � }|dkr:|�
t|�� �
� �� q$|dkrK|�
t�|�� �
� �� q$|dkr[|�
t|�� �
� �� q$|dkr�|�� }|�d�} | tkr�t|�d��\}
}t|
t�r�|�
t|
�
� �� q$td �� q$ q$q
|s�d
d� | �� �� D �}tt|�d�}d
d� |D �}tjd|�d�f tdd� |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 zUnexpected certificate content.c S s g | ]}|d dkr|d �qS )r s CNr r ��.0�cr r r �
<listcomp>� s zextract_ids.<locals>.<listcomp>s <not given>c S s g | ]}t |��qS r )r r&