]> granicus.if.org Git - python/commitdiff
Issue #12000: When a SSL certificate has a subjectAltName without any
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 6 May 2011 13:19:49 +0000 (15:19 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 6 May 2011 13:19:49 +0000 (15:19 +0200)
dNSName entry, ssl.match_hostname() should use the subject's commonName.
Patch by Nicolas Bareil.

Lib/ssl.py
Lib/test/test_ssl.py
Misc/ACKS
Misc/NEWS

index 84aa6dc3bf7b8f028c6c0650c5be71eb6cde866b..e7c175f063a68ede5ba269ce4e190fba356f1925 100644 (file)
@@ -122,8 +122,9 @@ def match_hostname(cert, hostname):
             if _dnsname_to_pat(value).match(hostname):
                 return
             dnsnames.append(value)
-    if not san:
-        # The subject is only checked when subjectAltName is empty
+    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
index 164b6c262a5dceeabd0286c7d62eeecf4b4fb5e4..ba788e4c844488c48688cb161cb32922c036a04d 100644 (file)
@@ -277,6 +277,24 @@ class BasicSocketTests(unittest.TestCase):
                             (('organizationName', 'Google Inc'),))}
         fail(cert, 'mail.google.com')
 
+        # No DNS entry in subjectAltName but a commonName
+        cert = {'notAfter': 'Dec 18 23:59:59 2099 GMT',
+                'subject': ((('countryName', 'US'),),
+                            (('stateOrProvinceName', 'California'),),
+                            (('localityName', 'Mountain View'),),
+                            (('commonName', 'mail.google.com'),)),
+                'subjectAltName': (('othername', 'blabla'), )}
+        ok(cert, 'mail.google.com')
+
+        # No DNS entry subjectAltName and no commonName
+        cert = {'notAfter': 'Dec 18 23:59:59 2099 GMT',
+                'subject': ((('countryName', 'US'),),
+                            (('stateOrProvinceName', 'California'),),
+                            (('localityName', 'Mountain View'),),
+                            (('organizationName', 'Google Inc'),)),
+                'subjectAltName': (('othername', 'blabla'),)}
+        fail(cert, 'google.com')
+
         # Empty cert / no cert
         self.assertRaises(ValueError, ssl.match_hostname, None, 'example.com')
         self.assertRaises(ValueError, ssl.match_hostname, {}, 'example.com')
index 0443e9374c42a4191922770e7a455e3ed8ae261a..efbd30bae9b38c45f95064b8c8e5a6fa90b6fd67 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -49,6 +49,7 @@ Luigi Ballabio
 Jeff Balogh
 Matt Bandy
 Michael J. Barber
+Nicolas Bareil
 Chris Barker
 Nick Barnes
 Quentin Barnes
index 01274a11f85e76ba3a650445dc182805c5273843..827e8373cba3e87f2dad0cb3bb65128e8f126ec6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -83,6 +83,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #12000: When a SSL certificate has a subjectAltName without any
+  dNSName entry, ssl.match_hostname() should use the subject's commonName.
+  Patch by Nicolas Bareil.
+
 - Issue #11647: objects created using contextlib.contextmanager now support
   more than one call to the function when used as a decorator. Initial patch
   by Ysj Ray.