+; d Z ddlmZ ddlZddlZddlZddlmZmZ ej rddl m Z dZ G d d e Z dddZd dZ d!d"dZdS )#zHThe match_hostname() function from Python 3.5, essential when using SSL. )annotationsN)IPv4AddressIPv6Address )_TYPE_PEER_CERT_RET_DICTz3.5.0.1c e Zd ZdS )CertificateErrorN)__name__ __module____qualname__ q/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/urllib3/util/ssl_match_hostname.pyr r s Dr r dn typing.Anyhostnamestr max_wildcardsintreturntyping.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)splitcountr reprboollowerappend startswithreescapereplacecompilejoin IGNORECASEmatch) r r r patspartsleftmost remainder wildcardsfragpats r _dnsname_matchr0 s D u HHTNNEQxHabb Is##I= :T"XXE 4BHHJJ(.."2"22333 3 G V $ $ A(;(;F(C(C A BIh''(((( BIh''//w??@@@ % %BIdOO$$$$ *UUZZ---5r} E EC99Xr ipnamehost_ipIPv4Address | 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_addressrstripr packed)r1 r2 ips r _ipaddress_matchr: P s3 fmmoo . .B W^+,,,r Fcert_TYPE_PEER_CERT_RET_DICT | Nonehostname_checks_common_nameNonec | 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%NsubjectAltNamer DNSz IP Addresssubject commonNamer z hostname z doesn't match either of z, z doesn't match r z/no appropriate subjectAltName fields were found) ValueErrorr5 r6 rfindgetr0 r r: lenr r&