o
    'èhÕ  ã                   @  sˆ   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	„ d	eƒZ	d!d"dd„Zd#dd„Z	d$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                   @  s   e Zd ZdS )ÚCertificateErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú[/var/www/html/olx_land/venv/lib/python3.10/site-packages/urllib3/util/ssl_match_hostname.pyr      s    r   Údnú
typing.AnyÚhostnameÚstrÚmax_wildcardsÚintÚreturnútyping.Match[str] | None | boolc           
      C  sö   g }| sdS |   d¡}|d }|dd… }| d¡}||kr&tdt| ƒ ƒ‚|s2t|  ¡ | ¡ kƒS |dkr<| d¡ n| d	¡sF| d	¡rO| t 	|¡¡ n| t 	|¡ 
d
d¡¡ |D ]
}| t 	|¡¡ q]t dd |¡ d 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Úpatr   r   r   Ú_dnsname_match   s,   


ÿ
r,   ÚipnameÚhost_ipúIPv4Address | IPv6Addressr   c                 C  s   t  |  ¡ ¡}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)r-   r.   Úipr   r   r   Ú_ipaddress_matchP   s   r5   FÚcertú_TYPE_PEER_CERT_RET_DICT | NoneÚhostname_checks_common_nameÚNonec           	      C  sp  | st dƒ‚zd|v rt |d| d¡… ¡}nt |¡}W n t y)   d}Y nw g }|  dd¡}|D ]/\}}|dkrN|du rHt||ƒrH dS | |¡ q4|dkrc|dur^t||ƒr^ dS | |¡ q4|rŽ|du rŽ|sŽ|  dd¡D ]}|D ]\}}|d	krŒt||ƒr‡  dS | |¡ qvqrt|ƒd
kr¢t	d|d 
tt|ƒ¡f ƒ‚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 %r doesn't match either of %sz, z	hostname z doesn't match r   z/no appropriate subjectAltName fields were found)Ú
ValueErrorr0   r1   ÚrfindÚgetr,   r   r5   Úlenr   r"   Úmapr   )	r6   r   r8   r.   ÚdnsnamesÚsanÚkeyÚvalueÚsubr   r   r   Úmatch_hostname_   sT   ÿ
€þ
€

€üÿÿrI   )r   )r   r   r   r   r   r   r   r   )r-   r   r.   r/   r   r   )F)r6   r7   r   r   r8   r   r   r9   )Ú__doc__Ú
__future__r   r0   r   Útypingr   r   ÚTYPE_CHECKINGÚssl_r   Ú__version__r?   r   r,   r5   rI   r   r   r   r   Ú<module>   s    ÿ
8ý