
    >OOf2                     p    d Z ddlZddlmZmZmZ 	 ddlmZmZ y# e	$ r  G d de
      Zd
dZd	 ZY yw xY w)
    N   )loglog_enabledNETWORK)match_hostnameCertificateErrorc                       e Zd Zy)r	   N)__name__
__module____qualname__     Y/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/ldap3/utils/tls_backport.pyr	   r	      s    r   r	   c                 2   t        t              rt        t        d| |       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 )zBackported from Python 3.4.3 standard library

        Matching according to RFC 6125, section 6.4.3

        http://tools.ietf.org/html/rfc6125#section-6.4.3
        zmatching dn %s with hostname %sF.r      N*z,too many wildcards in certificate DNS name: z[^.]+zxn--z\*z[^.]*z\Az\.z\Z)r   r   r   splitcountr	   reprlowerappend
startswithreescapereplacecompilejoin
IGNORECASEmatch)
dnhostnamemax_wildcardspatspiecesleftmost	remainder	wildcardsfragpats
             r   _dnsname_matchr,   #   sa    w:BI$!912J	NN3'	}$
 #>bIK K 88:!111
 s? KK   (H,?,?,G
 KK		(+, KK		(+33E7CD  	)DKK		$(	) jjD!11E92==Iyy""r   c                    | st        d      g }| j                  dd      }|D ]*  \  }}|dk(  st        ||      r y|j                  |       , |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      )au  Backported from Python 3.4.3 standard library.

        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subjectAltNamer   DNSN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)	
ValueErrorgetr,   r   lenr	   r   mapr   )certr#   dnsnamessankeyvaluesubs          r   r   r   Z   s3     > ? ? hh', 	'JCe|!%2&		'
  xx	2. /"% /JC l*)%:" .// x=1"&.		#dH:M0N$P Q Q ]a"&.$= > > # $F G Gr   )r   )__doc__r   	utils.logr   r   r   backports.ssl_match_hostnamer   r	   ImportErrorr2   r,   r   r   r   <module>r@      sN   0 
 1 1iGMM gG: 4#n+GygGs    55