diff tests/test-url.py @ 29452:26a5d605b868 stable 3.8.4

sslutil: synchronize hostname matching logic with CPython sslutil contains its own hostname matching logic. CPython has code for the same intent. However, it is only available to Python 2.7.9+ (or distributions that have backported 2.7.9's ssl module improvements). This patch effectively imports CPython's hostname matching code from its ssl.py into sslutil.py. The hostname matching code itself is pretty similar. However, the DNS name matching code is much more robust and spec conformant. As the test changes show, this changes some behavior around wildcard handling and IDNA matching. The new behavior allows wildcards in the middle of words (e.g. 'f*.com' matches 'foo.com') This is spec compliant according to RFC 6125 Section 6.5.3 item 3. There is one test where the matcher is more strict. Before, '*.a.com' matched '.a.com'. Now it doesn't match. Strictly speaking this is a security vulnerability.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 26 Jun 2016 19:34:48 -0700
parents 676f4d0e3a7b
children 0dcd03637d36
line wrap: on
line diff
--- a/tests/test-url.py	Sun Jun 26 19:16:54 2016 -0700
+++ b/tests/test-url.py	Sun Jun 26 19:34:48 2016 -0700
@@ -51,8 +51,7 @@
 # Avoid some pitfalls
 check(_verifycert(cert('*.foo'), 'foo'),
       'certificate is for *.foo')
-check(_verifycert(cert('*o'), 'foo'),
-      'certificate is for *o')
+check(_verifycert(cert('*o'), 'foo'), None)
 
 check(_verifycert({'subject': ()},
                   'example.com'),
@@ -82,13 +81,12 @@
       'certificate is for *.a.com')
 check(_verifycert(cert('*.a.com'), 'Xa.com'),
       'certificate is for *.a.com')
-check(_verifycert(cert('*.a.com'), '.a.com'), None)
+check(_verifycert(cert('*.a.com'), '.a.com'),
+      'certificate is for *.a.com')
 
 # only match one left-most wildcard
-check(_verifycert(cert('f*.com'), 'foo.com'),
-      'certificate is for f*.com')
-check(_verifycert(cert('f*.com'), 'f.com'),
-      'certificate is for f*.com')
+check(_verifycert(cert('f*.com'), 'foo.com'), None)
+check(_verifycert(cert('f*.com'), 'f.com'), None)
 check(_verifycert(cert('f*.com'), 'bar.com'),
       'certificate is for f*.com')
 check(_verifycert(cert('f*.com'), 'foo.a.com'),
@@ -136,10 +134,10 @@
 idna = u'www*.pythön.org'.encode('idna').decode('ascii')
 check(_verifycert(cert(idna),
                   u'www.pythön.org'.encode('idna').decode('ascii')),
-      'certificate is for www*.xn--pythn-mua.org')
+      None)
 check(_verifycert(cert(idna),
                   u'www1.pythön.org'.encode('idna').decode('ascii')),
-      'certificate is for www*.xn--pythn-mua.org')
+      None)
 check(_verifycert(cert(idna),
                   u'ftp.pythön.org'.encode('idna').decode('ascii')),
       'certificate is for www*.xn--pythn-mua.org')
@@ -229,11 +227,12 @@
 # avoid denials of service by refusing more than one
 # wildcard per fragment.
 check(_verifycert({'subject': (((u'commonName', u'a*b.com'),),)},
-                  'axxb.com'), 'certificate is for a*b.com')
+                  'axxb.com'), None)
 check(_verifycert({'subject': (((u'commonName', u'a*b.co*'),),)},
                   'axxb.com'), 'certificate is for a*b.co*')
 check(_verifycert({'subject': (((u'commonName', u'a*b*.com'),),)},
-                  'axxbxxc.com'), 'certificate is for a*b*.com')
+                  'axxbxxc.com'),
+      'too many wildcards in certificate DNS name: a*b*.com')
 
 def test_url():
     """