
    g                        d Z ddlmZ ddlZddlZddlZddlmZmZ ej        rddl	m
Z
 dZ G d d	e          Z	 dddZd dZ	 d!d"dZdS )#zHThe match_hostname() function from Python 3.5, essential when using SSL.    )annotationsN)IPv4AddressIPv6Address   )_TYPE_PEER_CERT_RET_DICTz3.5.0.1c                      e Zd ZdS )CertificateErrorN)__name__
__module____qualname__     [/var/www/html/4nations/venv/lib/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 }| sdS |                      d          }|d         }|dd         }|                    d          }||k    rt          dt          |           z             |s7t	          |                                 |                                k              S |dk    r|                    d           n|                    d	          s|                    d	          r(|                    t          j	        |                     n;|                    t          j	        |          
                    d
d                     |D ])}|                    t          j	        |                     *t          j        dd                    |          z   dz   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[^.]+zxn--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 HHTNNEQxHabb	Is##I=  
 :T"XXE
 
 	

  4BHHJJ(.."2"22333
 3 	G			V	$	$ A(;(;F(C(C A
 	BIh''(((( 	BIh''//w??@@@  % %BIdOO$$$$
*UUZZ---5r}
E
EC99X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     
	fmmoo	.	.B	W^+,,,r   Fcert_TYPE_PEER_CERT_RET_DICT | Nonehostname_checks_common_nameNonec                   | st          d          	 d|v r0t          j        |d|                    d                             }nt          j        |          }n# t           $ r d}Y nw xY wg }|                     dd          }|D ]f\  }}|dk    r+|t          ||          r dS |                    |           6|dk    r*|t          ||          r dS |                    |           g|rT|R|sP|                     dd          D ]9}|D ]4\  }}|d	k    r)t          ||          r  dS |                    |           5:t          |          d
k    r;t          d|dd
                    t          t          |                              t          |          d
k    rt          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&   mapr   )	r;   r   r=   r2   dnsnamessankeyvaluesubs	            r   match_hostnamerO   _   sI     
-
 
 	

 (??*84IhnnS6I6I4I+JKKGG*844G    H'+xx0@"'E'EC  # #
U%<<>%#B#BOOE""""L  "'7w'G'G"OOE""" # +wx88Ir** 	+ 	+C! + +
U,&&%eX66 OOE***	+ 8}}q,4HHdiiD(@S@S6T6T6TV
 
 	
 
X!		U8UUhqkUUVVVPQQQs   AA A+*A+)r   )r   r   r   r   r   r   r   r   )r1   r   r2   r3   r   r   )F)r;   r<   r   r   r=   r   r   r>   )__doc__
__future__r   r5   r"   typingr   r   TYPE_CHECKINGssl_r   __version__rE   r	   r0   r:   rO   r   r   r   <module>rV      s
   N N # " " " " "     				  . . . . . . . .	 /......	 	 	 	 	z 	 	 	
 9:5 5 5 5 5p- - - -$ ).@R @R @R @R @R @R @Rr   