zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
U
 ý°d´ã@s dZddlmZddlZddlZddlZddlmZmZejrJddl    m
Z
dZ Gdd    „d    e ƒZ dd
d d d dœdd„Zd dddœdd„Zddd dddœdd„ZdS)zHThe match_hostname() function from Python 3.5, essential when using SSL.é)Ú annotationsN)Ú IPv4AddressÚ IPv6Addressé)Ú_TYPE_PEER_CERT_RET_DICTz3.5.0.1c@s eZdZdS)ÚCertificateErrorN)Ú__name__Ú
__module__Ú __qualname__©r r úVd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\urllib3/util/ssl_match_hostname.pyrsrz
typing.AnyÚstrÚintztyping.Match[str] | None | bool)ÚdnÚhostnameÚ max_wildcardsÚreturnc
Csög}|s dS| d¡}|d}|dd…}| d¡}||krLtdt|ƒƒ‚|sdt| ¡| ¡kƒS|dkrx| d¡n>| d    ¡sŒ| d    ¡rž| t     |¡¡n| t     |¡ 
d
d ¡¡|D]}| t     |¡¡qºt  d d   |¡dtj ¡}    |     |¡S)zhMatching according to RFC 6125, section 6.4.3
 
    http://tools.ietf.org/html/rfc6125#section-6.4.3
    FÚ.rrNÚ*z,too many wildcards in certificate DNS name: z[^.]+zxn--z\*z[^.]*z\Az\.z\Z)ÚsplitÚcountrÚreprÚboolÚlowerÚappendÚ
startswithÚreÚescapeÚreplaceÚcompileÚjoinÚ
IGNORECASEÚmatch)
rrrZpatsÚpartsZleftmostÚ    remainderÚ    wildcardsÚfragÚpatr r r Ú_dnsname_matchs,
 
 
ÿ r(zIPv4Address | IPv6Addressr)ÚipnameÚhost_iprcCst | ¡¡}t|j|jkƒ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_matchPs r0Fz_TYPE_PEER_CERT_RET_DICT | NoneÚNone)ÚcertrÚhostname_checks_common_namerc    Cs†|s tdƒ‚z0d|kr0t |d| d¡…¡}n
t |¡}Wntk
rTd}YnXg}| dd¡}|D]^\}}|dkrž|dkr’t||ƒr’dS| |¡qj|dkrj|dk    r¾t||ƒr¾dS| |¡qj|r&|dkr&|s&| dd¡D]8}|D].\}}|d    krôt||ƒrdS| |¡qôqìt|ƒd
krRt    d |d  
t t |ƒ¡fƒ‚n0t|ƒd
krzt    d |›d|d›ƒ‚nt    dƒ‚dS)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Ú
commonNamerz&hostname %r doesn't match either of %sz, z    hostname z doesn't match rz/no appropriate subjectAltName fields were found) Ú
ValueErrorr+r,ÚrfindÚgetr(rr0Úlenrr Úmapr)    r2rr3r*ÚdnsnamesÚsanÚkeyÚvalueÚsubr r r Úmatch_hostname_sJ ÿ
      ÿÿrC)r)F)Ú__doc__Ú
__future__rr+rÚtypingrrÚ TYPE_CHECKINGÚssl_rÚ __version__r9rr(r0rCr r r r Ú<module>s  ÿ8ý