From 340749cbb73b42a0bcbcd46960b4ceb5e0e68fc0 Mon Sep 17 00:00:00 2001 From: Lukas Puehringer Date: Fri, 10 Feb 2023 11:30:25 +0100 Subject: [PATCH] Remove obsolete `ssl_match_hostname` module Originally added in: theupdateframework/python-tuf@d03dd0f Moved to sslib in: eee8434b1902bca1c2a29b7c4bf1ddce2ee4bf08 Obsolete since: theupdateframework/python-tuf@b9bc8602c2bdc31f09b241f3612f7fda6d601ea9 Signed-off-by: Lukas Puehringer --- .../_vendor/ssl_match_hostname.py | 70 ------------------- 1 file changed, 70 deletions(-) delete mode 100644 securesystemslib/_vendor/ssl_match_hostname.py diff --git a/securesystemslib/_vendor/ssl_match_hostname.py b/securesystemslib/_vendor/ssl_match_hostname.py deleted file mode 100644 index 1a2602e5..00000000 --- a/securesystemslib/_vendor/ssl_match_hostname.py +++ /dev/null @@ -1,70 +0,0 @@ -""" -We copy some functions from the Python 3.3.0 ssl module. - -http://hg.python.org/releasing/3.3.0/file/1465cbbc8f64/Lib/ssl.py -""" - - -import re - - -class CertificateError(ValueError): - pass - - -def _dnsname_to_pat(dn): - pats = [] - for frag in dn.split(r'.'): - if frag == '*': - # When '*' is a fragment by itself, it matches a non-empty dotless - # fragment. - pats.append('[^.]+') - else: - # Otherwise, '*' matches any dotless fragment. - frag = re.escape(frag) - pats.append(frag.replace(r'\*', '[^.]*')) - return re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE) - - -def match_hostname(cert, hostname): - """Verify that *cert* (in decoded format as returned by - SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 rules - are mostly followed, but IP addresses are not accepted for *hostname*. - - CertificateError is raised on failure. On success, the function - returns nothing. - """ - if not cert: - raise ValueError("empty or no certificate") - dnsnames = [] - san = cert.get('subjectAltName', ()) - for key, value in san: - if key == 'DNS': - if _dnsname_to_pat(value).match(hostname): - 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_to_pat(value).match(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") - - -