
    h                        S r SSKJr  SSKrSSKrSSKrSSKJrJr  \R                  (       a  SSK	J
r
  Sr " S S	\5      r S       SS
 jjrSS jr S       SS jjrg)zHThe match_hostname() function from Python 3.5, essential when using SSL.    )annotationsN)IPv4AddressIPv6Address   )_TYPE_PEER_CERT_RET_DICTz3.5.0.1c                      \ rS rSrSrg)CertificateError    N)__name__
__module____qualname____firstlineno____static_attributes__r       Q/var/www/html/env/lib/python3.13/site-packages/urllib3/util/ssl_match_hostname.pyr	   r	      s    r   r	   c                8   / nU (       d  gU R                  S5      nUS   nUSS nUR                  S5      nXr:  a  [        S[        U 5      -   5      eU(       d*  [	        U R                  5       UR                  5       :H  5      $ US:X  a  UR                  S5        OUR                  S	5      (       d  UR                  S	5      (       a&  UR                  [        R                  " U5      5        O5UR                  [        R                  " U5      R                  S
S5      5        U H(  nUR                  [        R                  " U5      5        M*     [        R                  " SSR                  U5      -   S-   [        R                  5      n	U	R                  U5      $ )z`Matching 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[^.]+zxn--z\*z[^.]*z\Az\.z\Z)splitcountr	   reprboollowerappend
startswithreescapereplacecompilejoin
IGNORECASEmatch)
dnhostnamemax_wildcardspatspartsleftmost	remainder	wildcardsfragpats
             r   _dnsname_matchr.      sN    D HHTNEQxHab	Is#I 
 :T"XE
 	

 BHHJ(.."2233
 3 	G			V	$	$(;(;F(C(C
 	BIIh'( 	BIIh'//w?@ BIIdO$  **UUZZ--5r}}
EC99Xr   c                    [         R                  " U R                  5       5      n[        UR                  UR                  :H  5      $ )am  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)ipnamehost_ipips      r   _ipaddress_matchr7   P   s2     
		fmmo	.B		W^^+,,r   c                p   U (       d  [        S5      e SU;   a)  [        R                  " USUR                  S5       5      nO[        R                  " U5      n / nU R	                  SS5      nU Ha  u  pgUS:X  a(  Uc  [        Xq5      (       a    gUR                  U5        M3  US:X  d  M;  Ub  [        Xs5      (       a    gUR                  U5        Mc     U(       aZ  UcW  U(       dP  U R	                  SS5       H:  nU H1  u  pgUS	:X  d  M  [        Xq5      (       a      gUR                  U5        M3     M<     [        U5      S
:  a0  [        SU< SSR                  [        [        U5      5      < 35      e[        U5      S
:X  a  [        SU< SUS   < 35      e[        S5      e! [          a    Sn GNZf = f)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)
ValueErrorr0   r1   rfindgetr.   r   r7   lenr	   r!   mapr   )	certr%   hostname_checks_common_namer5   dnsnamessankeyvaluesubs	            r   match_hostnamerJ   _   s    -
 	

 (?**84IhnnS6I+JKG**84G
 H'+xx0@"'EC 
%<>%#B#BOOE"L "'7'G'GOOE"  #wx88Ir*C!
,&%e66OOE*	 " + 8}q,4diiD(@S6TV
 	
 
X!	8,ohqk_UVVPQQG  s   .F% F% %F54F5)r   )r$   z
typing.Anyr%   strr&   intreturnztyping.Match[str] | None | bool)r4   rK   r5   zIPv4Address | IPv6AddressrM   r   )F)rC   z_TYPE_PEER_CERT_RET_DICT | Noner%   rK   rD   r   rM   None)__doc__
__future__r   r0   r   typingr   r   TYPE_CHECKINGssl_r   __version__r>   r	   r.   r7   rJ   r   r   r   <module>rU      s    N #  	  .	.	z 	
 9:55!5255$5p-$ ).@R
)@R@R "&@R 
	@Rr   