summaryrefslogtreecommitdiffstats
path: root/Lib/ssl.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-06-25 10:54:11 (GMT)
committerGitHub <noreply@github.com>2022-06-25 10:54:11 (GMT)
commit944c7d8a8561d4b637af5c128df1d8d7570ccb46 (patch)
tree900315b515aadaf9297178d6ddc23aa14a03670f /Lib/ssl.py
parentb52849905218582d067a875712af8c2bcc8789c4 (diff)
downloadcpython-944c7d8a8561d4b637af5c128df1d8d7570ccb46.zip
cpython-944c7d8a8561d4b637af5c128df1d8d7570ccb46.tar.gz
cpython-944c7d8a8561d4b637af5c128df1d8d7570ccb46.tar.bz2
gh-94199: Remove ssl.match_hostname() function (#94224)
Diffstat (limited to 'Lib/ssl.py')
-rw-r--r--Lib/ssl.py62
1 files changed, 0 insertions, 62 deletions
diff --git a/Lib/ssl.py b/Lib/ssl.py
index 7c99041..02359a1 100644
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -373,68 +373,6 @@ def _ipaddress_match(cert_ipaddress, host_ip):
return ip == host_ip
-def match_hostname(cert, hostname):
- """Verify that *cert* (in decoded format as returned by
- SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125
- rules are followed.
-
- The function matches IP addresses rather than dNSNames if hostname is a
- valid ipaddress string. IPv4 addresses are supported on all platforms.
- IPv6 addresses are supported on platforms with IPv6 support (AF_INET6
- and inet_pton).
-
- CertificateError is raised on failure. On success, the function
- returns nothing.
- """
- warnings.warn(
- "ssl.match_hostname() is deprecated",
- category=DeprecationWarning,
- stacklevel=2
- )
- if not cert:
- raise ValueError("empty or no certificate, match_hostname needs a "
- "SSL socket or SSL context with either "
- "CERT_OPTIONAL or CERT_REQUIRED")
- try:
- host_ip = _inet_paton(hostname)
- except ValueError:
- # Not an IP address (common case)
- host_ip = None
- dnsnames = []
- san = cert.get('subjectAltName', ())
- for key, value in san:
- if key == 'DNS':
- if host_ip is None and _dnsname_match(value, hostname):
- return
- dnsnames.append(value)
- elif key == 'IP Address':
- if host_ip is not None and _ipaddress_match(value, host_ip):
- return
- dnsnames.append(value)
- if not dnsnames:
- # The subject is only checked when there is no dNSName entry
- # in subjectAltName
- for sub in cert.get('subject', ()):
- for key, value in sub:
- # XXX according to RFC 2818, the most specific Common Name
- # must be used.
- if key == 'commonName':
- if _dnsname_match(value, hostname):
- return
- dnsnames.append(value)
- if len(dnsnames) > 1:
- raise CertificateError("hostname %r "
- "doesn't match either of %s"
- % (hostname, ', '.join(map(repr, dnsnames))))
- elif len(dnsnames) == 1:
- raise CertificateError("hostname %r "
- "doesn't match %r"
- % (hostname, dnsnames[0]))
- else:
- raise CertificateError("no appropriate commonName or "
- "subjectAltName fields were found")
-
-
DefaultVerifyPaths = namedtuple("DefaultVerifyPaths",
"cafile capath openssl_cafile_env openssl_cafile openssl_capath_env "
"openssl_capath")