R`i~pdZddlZddlZ ddlZdZGddeZd dZdZ dZ d Z y#e$rdZY$wxYw) zJThe match_hostname() function from Python 3.3.3, essential when using SSL.Nz3.5.0.1c eZdZy)CertificateErrorN)__name__ __module__ __qualname__/builddir/build/BUILDROOT/alt-python312-pip-23.3.1-3.el8.x86_64/opt/alt/python312/lib/python3.12/site-packages/pip/_vendor/urllib3/util/ssl_match_hostname.pyrrsr rcg}|sy|jd}|d}|dd}|jd}||kDrtdt|z|s!|j |j k(S|dk(r|j dn{|j d s|j d r%|j tj|n4|j tj|jd d |D]&}|j tj|(tjd d j|zdztj} | j|S)zhMatching according to RFC 6125, section 6.4.3 http://tools.ietf.org/html/rfc6125#section-6.4.3 F.rN*z,too many wildcards in certificate DNS name: z[^.]+zxn--z\*z[^.]*z\Az\.z\Z)splitcountrreprlowerappend startswithreescapereplacecompilejoin IGNORECASEmatch) dnhostname max_wildcardspatspartsleftmost remainder wildcardsfragpats r _dnsname_matchr&sE D  HHTNEQxHab Is#I=  :T"X E  xxzX^^--- 3 G   V $(;(;F(C BIIh'( BIIh'//w?@ BIIdO$ **UUZZ--5r}} EC 99X r cht|tr!tjdkrt |dd}|S)N)asciistrict)encodingerrors) isinstancestrsys version_infounicode)objs r _to_unicoder3Os,#s 0 04 7cGH= Jr cdtjt|j}||k(S)zExact matching of IP addresses. RFC 6125 explicitly doesn't define an algorithm for this (section 1.7.2 - "Out of Scope"). ) ipaddress ip_addressr3rstrip)ipnamehost_ipips r _ipaddress_matchr;Vs,   k&188: ;B =r c |s td tjt|}g}|j dd}|D]S\}}|dk(r"|t||ry|j|-|dk(s3|t||ry|j|U|sG|j ddD]2}|D]+\}}|dk(s t||ry|j|-4t|d kDr.td |d d jtt|t|d k(rtd |d |dtd#ttf$rd}Y2t $rtd}nYGwxYw)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_REQUIREDNsubjectAltNamerDNSz IP Addresssubject commonNamer z hostname z doesn't match either of z, z doesn't match rz=no appropriate commonName or subjectAltName fields were found) ValueErrorr5r6r3 UnicodeErrorAttributeErrorgetr&rr;lenrrmapr)certrr9dnsnamessankeyvaluesubs r match_hostnamerMbs  -  &&{8'<=H ((#R (C U %<>%#B OOE " L "'7w'G OOE " 88Ir*C! U,&%eX6OOE* "+ 8}q,4diiD(@S6T V   X! 8TU;WXX K  U * %    G  sE E5E54E5)r ) __doc__rr/r5 ImportError __version__rArr&r3r;rMrr r rQsWP    z 3l = gIs +55