o
    ßý°j2  ã                   @   sn   d Z ddlZddlmZmZmZ zddlmZmZ W dS  e	y6   G dd„ de
ƒZdd	d
„Zdd„ ZY dS w )Ú
é    Né   )ÚlogÚlog_enabledÚNETWORK)Úmatch_hostnameÚCertificateErrorc                   @   s   e Zd ZdS )r   N)Ú__name__Ú
__module__Ú__qualname__© r   r   ú‹/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/ldap3/utils/tls_backport.pyr      s    r   é   c           
      C   s  t tƒrttd| |ƒ g }| sdS |  d¡}|d }|dd… }| d¡}||kr1tdt| ƒ ƒ‚|s;|  ¡ | ¡ kS |dkrE| d	¡ n| 	d
¡sO| 	d
¡rX| t
 |¡¡ n| t
 |¡ dd¡¡ |D ]
}| t
 |¡¡ qft
 dd |¡ d t
j¡}	|	 |¡S )z§Backported 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   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Úpatr   r   r   Ú_dnsname_match#   s0   


ÿ
r(   c                 C   sä   | st dƒ‚g }|  dd¡}|D ]\}}|dkr%t||ƒr  dS | |¡ q|sJ|  dd¡D ]}|D ]\}}|dkrHt||ƒrC  dS | |¡ q2q.t|ƒdkr^td	|d
 tt|ƒ¡f ƒ‚t|ƒdkrntd||d f ƒ‚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 %r doesn't match either of %sz, zhostname %r doesn't match %rr   z=no appropriate commonName or subjectAltName fields were found)	Ú
ValueErrorÚgetr(   r   Úlenr   r   Úmapr   )Úcertr   ÚdnsnamesÚsanÚkeyÚvalueÚsubr   r   r   r   Z   s8   

€

€úþ
þr   )r   )Ú__doc__r   Ú	utils.logr   r   r   Úbackports.ssl_match_hostnamer   r   ÚImportErrorr-   r(   r   r   r   r   Ú<module>   s    
7Ä