관리-도구
편집 파일: ssl_match_hostname.cpython-311.pyc
� �܋f� � � � d Z ddlmZ ddlZddlZddlZddlmZmZ ej rddl m Z dZ G d� d e� � Z ddd�Zd d�Z d!d"d�ZdS )#zHThe match_hostname() function from Python 3.5, essential when using SSL.� )�annotationsN)�IPv4Address�IPv6Address� )�_TYPE_PEER_CERT_RET_DICTz3.5.0.1c � � e Zd ZdS )�CertificateErrorN)�__name__� __module__�__qualname__� � �V/opt/cloudlinux/venv/lib64/python3.11/site-packages/urllib3/util/ssl_match_hostname.pyr r s � � � � � ��Dr r �dn� typing.Any�hostname�str� max_wildcards�int�return�typing.Match[str] | None | boolc � � g }| sdS | � d� � }|d }|dd� }|� d� � }||k rt dt | � � z � � �|s7t | � � � |� � � k � � S |dk r|� d� � n�|� d � � s|� d � � r(|� t j |� � � � n;|� t j |� � � d d� � � � |D ])}|� t j |� � � � �*t j dd � |� � z dz t j � � } | � |� � S )zhMatching according to RFC 6125, section 6.4.3 http://tools.ietf.org/html/rfc6125#section-6.4.3 F�.r r N�*z,too many wildcards in certificate DNS name: z[^.]+zxn--z\*z[^.]*z\Az\.z\Z)�split�countr �repr�bool�lower�append� startswith�re�escape�replace�compile�join� IGNORECASE�match) r r r �pats�parts�leftmost� remainder� wildcards�frag�pats r �_dnsname_matchr0 s� � � �D� � ��u� �H�H�T�N�N�E��Q�x�H��a�b�b� �I����s�#�#�I��=� � � �:�T�"�X�X�E� � � � � 4��B�H�H�J�J�(�.�.�"2�"2�2�3�3�3� �3��� ���G����� � � �V� $� $� A��(;�(;�F�(C�(C� A� ���B�I�h�'�'�(�(�(�(� ���B�I�h�'�'�/�/��w�?�?�@�@�@� � %� %�����B�I�d�O�O�$�$�$�$� �*�U�U�Z�Z��-�-�-��5�r�}� E� E�C��9�9�X���r �ipname�host_ip�IPv4Address | IPv6Addressr c � � t j | � � � � � }t |j |j k � � S )a� Exact matching of IP addresses. RFC 9110 section 4.3.5: "A reference identity of IP-ID contains the decoded bytes of the IP address. An IP version 4 address is 4 octets, and an IP version 6 address is 16 octets. [...] A reference identity of type IP-ID matches if the address is identical to an iPAddress value of the subjectAltName extension of the certificate." )� ipaddress� ip_address�rstripr �packed)r1 r2 �ips r �_ipaddress_matchr: P s3 � � � �f�m�m�o�o� .� .�B��� �W�^�+�,�,�,r F�cert�_TYPE_PEER_CERT_RET_DICT | None�hostname_checks_common_name�Nonec � � | st d� � � d|v r0t j |d|� d� � � � � }nt j |� � }n# t $ r d}Y nw xY wg }| � dd� � }|D ]f\ }}|dk r+|�t ||� � r dS |� |� � �6|dk r*|�t ||� � r dS |� |� � �g|rT|�R|sP| � dd� � D ]9}|D ]4\ }}|d k r)t ||� � r dS |� |� � �5�:t |� � d k r;t d|�dd � t t |� � � � ��� � �t |� � d k rt d|�d|d ��� � �t d� � �)a) Verify that *cert* (in decoded format as returned by SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125 rules are followed, but IP addresses are not accepted for *hostname*. CertificateError is raised on failure. On success, the function returns nothing. ztempty or no certificate, match_hostname needs a SSL socket or SSL context with either CERT_OPTIONAL or CERT_REQUIRED�%N�subjectAltNamer �DNSz IP Address�subject� commonNamer z hostname z doesn't match either of z, z doesn't match r z/no appropriate subjectAltName fields were found) � ValueErrorr5 r6 �rfind�getr0 r r: �lenr r&