
    hB                         d dl Z d dlZ	 d dlmZ ej
                  d    dk  reZnd Zd dlm	Z	 d
dZ
d Zd	 Zy# e$ r d ZY 3w xY w)    N)
ip_addressc                      y N )addresss    ]/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/pymongo/ssl_match_hostname.py<lambda>r	      s           c                     | S r   r   )values    r   r	   r	      s    U r
   )CertificateErrorc                    g }| sy| j                  d      }|d   }|dd }|j                  d      }||kD  rt        dt        |       z         |s!| j	                         |j	                         k(  S |dk(  r|j                  d       n{|j                  d	      s|j                  d	      r%|j                  t        j                  |             n4|j                  t        j                  |      j                  d
d             |D ]&  }|j                  t        j                  |             ( t        j                  ddj                  |      z   dz   t        j                        }	|	j                  |      S )zhMatching according to RFC 6125, section 6.4.3

    http://tools.ietf.org/html/rfc6125#section-6.4.3
    F.r      N*z,too many wildcards in certificate DNS name: z[^.]+zxn--z\*z[^.]*z\Az\.z\Z)splitcountr   reprlowerappend
startswithreescapereplacecompilejoin
IGNORECASEmatch)
dnhostnamemax_wildcardspatspartsleftmost	remainder	wildcardsfragpats
             r   _dnsname_matchr*      sJ   
 DHHTNEQxHab	Is#I= 
 :T"XEG 	G xxzX^^---
 3 	G			V	$(;(;F(C
 	BIIh'( 	BIIh'//w?@  %BIIdO$% **UUZZ--5r}}
EC99Xr
   c                 P    t        t        |       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").
    )r   _unicoderstrip)ipnamehost_ipips      r   _ipaddress_matchr1   H   s&     
HV$++-	.B=r
   c                    | st        d      	 t        t        |            }g }| j	                  dd      }|D ]S  \  }}|dk(  r"|t        ||      r y|j                  |       -|dk(  s3|t        ||      r y|j                  |       U |sG| j	                  dd      D ]2  }|D ]+  \  }}|dk(  st        ||      r  y|j                  |       - 4 t        |      d	kD  r.t        d
|ddj                  t        t        |                  t        |      d	k(  rt        d
|d|d         t        d      # t         t        f$ r d}Y 2w xY w)zVerify that *cert* (in decoded format as returned by
    SSLSocket.getpeercert()) matches the *hostname*.  RFC 2818 and RFC 6125
    rules are followed.

    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_REQUIREDNsubjectAltNamer   DNSz
IP Addresssubject
commonNamer   z	hostname z doesn't match either of z, z doesn't match r   z=no appropriate commonName or subjectAltName fields were found)
ValueErrorr   r,   UnicodeErrorgetr*   r   r1   lenr   r   mapr   )certr!   r/   dnsnamessankeyr   subs           r   match_hostnamerA   S   s     : ; 	;Xh/0 H
((#R
(C #
U%<>%#BOOE"L "'7w'GOOE"#  88Ir* 	+C! +
U ,&%eX6OOE*+	+ 8}q3tX#67 9 : 	: 
X!	! & ' 	'   / 0 	0E % s   E EE)r   )r   sys	ipaddressr   ImportErrorversion_infounicoder,   pymongo.errorsr   r*   r1   rA   r   r
   r   <module>rH      s^    
 
&$
 AH"H +0f10S  &%J&s   9 AA