Blame SOURCES/00188-CVE-2013-4238-hostname-check-bypass-in-SSL-module.patch

6e8c2f
diff -r 9ddc63c039ba Lib/test/nullbytecert.pem
6e8c2f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
6e8c2f
+++ b/Lib/test/nullbytecert.pem	Sun Aug 11 18:13:17 2013 +0200
6e8c2f
@@ -0,0 +1,90 @@
6e8c2f
+Certificate:
6e8c2f
+    Data:
6e8c2f
+        Version: 3 (0x2)
6e8c2f
+        Serial Number: 0 (0x0)
6e8c2f
+    Signature Algorithm: sha1WithRSAEncryption
6e8c2f
+        Issuer: C=US, ST=Oregon, L=Beaverton, O=Python Software Foundation, OU=Python Core Development, CN=null.python.org\x00example.org/emailAddress=python-dev@python.org
6e8c2f
+        Validity
6e8c2f
+            Not Before: Aug  7 13:11:52 2013 GMT
6e8c2f
+            Not After : Aug  7 13:12:52 2013 GMT
6e8c2f
+        Subject: C=US, ST=Oregon, L=Beaverton, O=Python Software Foundation, OU=Python Core Development, CN=null.python.org\x00example.org/emailAddress=python-dev@python.org
6e8c2f
+        Subject Public Key Info:
6e8c2f
+            Public Key Algorithm: rsaEncryption
6e8c2f
+                Public-Key: (2048 bit)
6e8c2f
+                Modulus:
6e8c2f
+                    00:b5:ea:ed:c9:fb:46:7d:6f:3b:76:80:dd:3a:f3:
6e8c2f
+                    03:94:0b:a7:a6:db:ec:1d:df:ff:23:74:08:9d:97:
6e8c2f
+                    16:3f:a3:a4:7b:3e:1b:0e:96:59:25:03:a7:26:e2:
6e8c2f
+                    88:a9:cf:79:cd:f7:04:56:b0:ab:79:32:6e:59:c1:
6e8c2f
+                    32:30:54:eb:58:a8:cb:91:f0:42:a5:64:27:cb:d4:
6e8c2f
+                    56:31:88:52:ad:cf:bd:7f:f0:06:64:1f:cc:27:b8:
6e8c2f
+                    a3:8b:8c:f3:d8:29:1f:25:0b:f5:46:06:1b:ca:02:
6e8c2f
+                    45:ad:7b:76:0a:9c:bf:bb:b9:ae:0d:16:ab:60:75:
6e8c2f
+                    ae:06:3e:9c:7c:31:dc:92:2f:29:1a:e0:4b:0c:91:
6e8c2f
+                    90:6c:e9:37:c5:90:d7:2a:d7:97:15:a3:80:8f:5d:
6e8c2f
+                    7b:49:8f:54:30:d4:97:2c:1c:5b:37:b5:ab:69:30:
6e8c2f
+                    68:43:d3:33:78:4b:02:60:f5:3c:44:80:a1:8f:e7:
6e8c2f
+                    f0:0f:d1:5e:87:9e:46:cf:62:fc:f9:bf:0c:65:12:
6e8c2f
+                    f1:93:c8:35:79:3f:c8:ec:ec:47:f5:ef:be:44:d5:
6e8c2f
+                    ae:82:1e:2d:9a:9f:98:5a:67:65:e1:74:70:7c:cb:
6e8c2f
+                    d3:c2:ce:0e:45:49:27:dc:e3:2d:d4:fb:48:0e:2f:
6e8c2f
+                    9e:77:b8:14:46:c0:c4:36:ca:02:ae:6a:91:8c:da:
6e8c2f
+                    2f:85
6e8c2f
+                Exponent: 65537 (0x10001)
6e8c2f
+        X509v3 extensions:
6e8c2f
+            X509v3 Basic Constraints: critical
6e8c2f
+                CA:FALSE
6e8c2f
+            X509v3 Subject Key Identifier:
6e8c2f
+                88:5A:55:C0:52:FF:61:CD:52:A3:35:0F:EA:5A:9C:24:38:22:F7:5C
6e8c2f
+            X509v3 Key Usage:
6e8c2f
+                Digital Signature, Non Repudiation, Key Encipherment
6e8c2f
+            X509v3 Subject Alternative Name:
6e8c2f
+                *************************************************************
6e8c2f
+                WARNING: The values for DNS, email and URI are WRONG. OpenSSL
6e8c2f
+                         doesn't print the text after a NULL byte.
6e8c2f
+                *************************************************************
6e8c2f
+                DNS:altnull.python.org, email:null@python.org, URI:http://null.python.org, IP Address:192.0.2.1, IP Address:2001:DB8:0:0:0:0:0:1
6e8c2f
+    Signature Algorithm: sha1WithRSAEncryption
6e8c2f
+         ac:4f:45:ef:7d:49:a8:21:70:8e:88:59:3e:d4:36:42:70:f5:
6e8c2f
+         a3:bd:8b:d7:a8:d0:58:f6:31:4a:b1:a4:a6:dd:6f:d9:e8:44:
6e8c2f
+         3c:b6:0a:71:d6:7f:b1:08:61:9d:60:ce:75:cf:77:0c:d2:37:
6e8c2f
+         86:02:8d:5e:5d:f9:0f:71:b4:16:a8:c1:3d:23:1c:f1:11:b3:
6e8c2f
+         56:6e:ca:d0:8d:34:94:e6:87:2a:99:f2:ae:ae:cc:c2:e8:86:
6e8c2f
+         de:08:a8:7f:c5:05:fa:6f:81:a7:82:e6:d0:53:9d:34:f4:ac:
6e8c2f
+         3e:40:fe:89:57:7a:29:a4:91:7e:0b:c6:51:31:e5:10:2f:a4:
6e8c2f
+         60:76:cd:95:51:1a:be:8b:a1:b0:fd:ad:52:bd:d7:1b:87:60:
6e8c2f
+         d2:31:c7:17:c4:18:4f:2d:08:25:a3:a7:4f:b7:92:ca:e2:f5:
6e8c2f
+         25:f1:54:75:81:9d:b3:3d:61:a2:f7:da:ed:e1:c6:6f:2c:60:
6e8c2f
+         1f:d8:6f:c5:92:05:ab:c9:09:62:49:a9:14:ad:55:11:cc:d6:
6e8c2f
+         4a:19:94:99:97:37:1d:81:5f:8b:cf:a3:a8:96:44:51:08:3d:
6e8c2f
+         0b:05:65:12:eb:b6:70:80:88:48:72:4f:c6:c2:da:cf:cd:8e:
6e8c2f
+         5b:ba:97:2f:60:b4:96:56:49:5e:3a:43:76:63:04:be:2a:f6:
6e8c2f
+         c1:ca:a9:94
6e8c2f
+-----BEGIN CERTIFICATE-----
6e8c2f
+MIIE2DCCA8CgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBxTELMAkGA1UEBhMCVVMx
6e8c2f
+DzANBgNVBAgMBk9yZWdvbjESMBAGA1UEBwwJQmVhdmVydG9uMSMwIQYDVQQKDBpQ
6e8c2f
+eXRob24gU29mdHdhcmUgRm91bmRhdGlvbjEgMB4GA1UECwwXUHl0aG9uIENvcmUg
6e8c2f
+RGV2ZWxvcG1lbnQxJDAiBgNVBAMMG251bGwucHl0aG9uLm9yZwBleGFtcGxlLm9y
6e8c2f
+ZzEkMCI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FtcGxlLm9yZ4YpaHR0cDovL251
6e8c2f
+bGwucHl0aG9uLm9yZwBodHRwOi8vZXhhbXBsZS5vcmeHBMAAAgGHECABDbgAAAAA
6e8c2f
+AAAAAAAAAAEwDQYJKoZIhvcNAQEFBQADggEBAKxPRe99SaghcI6IWT7UNkJw9aO9
6e8c2f
+i9eo0Fj2MUqxpKbdb9noRDy2CnHWf7EIYZ1gznXPdwzSN4YCjV5d+Q9xtBaowT0j
6e8c2f
+HPERs1ZuytCNNJTmhyqZ8q6uzMLoht4IqH/FBfpvgaeC5tBTnTT0rD5A/olXeimk
6e8c2f
+kX4LxlEx5RAvpGB2zZVRGr6LobD9rVK91xuHYNIxxxfEGE8tCCWjp0+3ksri9SXx
6e8c2f
+VHWBnbM9YaL32u3hxm8sYB/Yb8WSBavJCWJJqRStVRHM1koZlJmXNx2BX4vPo6iW
6e8c2f
+RFEIPQsFZRLrtnCAiEhyT8bC2s/Njlu6ly9gtJZWSV46Q3ZjBL4q9sHKqZQ=
6e8c2f
+-----END CERTIFICATE-----
6e8c2f
diff -r 9ddc63c039ba Lib/test/test_ssl.py
6e8c2f
--- a/Lib/test/test_ssl.py	Sun Aug 11 13:04:50 2013 +0300
6e8c2f
+++ b/Lib/test/test_ssl.py	Sun Aug 11 18:13:17 2013 +0200
6e8c2f
@@ -25,6 +25,7 @@
6e8c2f
 HOST = test_support.HOST
6e8c2f
 CERTFILE = None
6e8c2f
 SVN_PYTHON_ORG_ROOT_CERT = None
6e8c2f
+NULLBYTECERT = None
6e8c2f
 
6e8c2f
 def handle_error(prefix):
6e8c2f
     exc_format = ' '.join(traceback.format_exception(*sys.exc_info()))
6e8c2f
@@ -123,6 +124,27 @@
6e8c2f
                           ('DNS', 'projects.forum.nokia.com'))
6e8c2f
                         )
6e8c2f
 
6e8c2f
+    def test_parse_cert_CVE_2013_4073(self):
6e8c2f
+        p = ssl._ssl._test_decode_cert(NULLBYTECERT)
6e8c2f
+        if test_support.verbose:
6e8c2f
+            sys.stdout.write("\n" + pprint.pformat(p) + "\n")
6e8c2f
+        subject = ((('countryName', 'US'),),
6e8c2f
+                   (('stateOrProvinceName', 'Oregon'),),
6e8c2f
+                   (('localityName', 'Beaverton'),),
6e8c2f
+                   (('organizationName', 'Python Software Foundation'),),
6e8c2f
+                   (('organizationalUnitName', 'Python Core Development'),),
6e8c2f
+                   (('commonName', 'null.python.org\x00example.org'),),
6e8c2f
+                   (('emailAddress', 'python-dev@python.org'),))
6e8c2f
+        self.assertEqual(p['subject'], subject)
6e8c2f
+        self.assertEqual(p['issuer'], subject)
6e8c2f
+        self.assertEqual(p['subjectAltName'],
6e8c2f
+                         (('DNS', 'altnull.python.org\x00example.com'),
6e8c2f
+                         ('email', 'null@python.org\x00user@example.org'),
6e8c2f
+                         ('URI', 'http://null.python.org\x00http://example.org'),
6e8c2f
+                         ('IP Address', '192.0.2.1'),
6e8c2f
+                         ('IP Address', '2001:DB8:0:0:0:0:0:1\n'))
6e8c2f
+                        )
6e8c2f
+
6e8c2f
     def test_DER_to_PEM(self):
6e8c2f
         with open(SVN_PYTHON_ORG_ROOT_CERT, 'r') as f:
6e8c2f
             pem = f.read()
6e8c2f
@@ -1360,7 +1382,7 @@
6e8c2f
 
6e8c2f
 
6e8c2f
 def test_main(verbose=False):
6e8c2f
-    global CERTFILE, SVN_PYTHON_ORG_ROOT_CERT, NOKIACERT
6e8c2f
+    global CERTFILE, SVN_PYTHON_ORG_ROOT_CERT, NOKIACERT, NULLBYTECERT
6e8c2f
     CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir,
6e8c2f
                             "keycert.pem")
6e8c2f
     SVN_PYTHON_ORG_ROOT_CERT = os.path.join(
6e8c2f
@@ -1368,10 +1390,13 @@
6e8c2f
         "https_svn_python_org_root.pem")
6e8c2f
     NOKIACERT = os.path.join(os.path.dirname(__file__) or os.curdir,
6e8c2f
                              "nokia.pem")
6e8c2f
+    NULLBYTECERT = os.path.join(os.path.dirname(__file__) or os.curdir,
6e8c2f
+                                "nullbytecert.pem")
6e8c2f
 
6e8c2f
     if (not os.path.exists(CERTFILE) or
6e8c2f
         not os.path.exists(SVN_PYTHON_ORG_ROOT_CERT) or
6e8c2f
-        not os.path.exists(NOKIACERT)):
6e8c2f
+        not os.path.exists(NOKIACERT) or
6e8c2f
+        not os.path.exists(NULLBYTECERT)):
6e8c2f
         raise test_support.TestFailed("Can't read certificate files!")
6e8c2f
 
6e8c2f
     tests = [BasicTests, BasicSocketTests]
6e8c2f
diff -r 9ddc63c039ba Modules/_ssl.c
6e8c2f
--- a/Modules/_ssl.c	Sun Aug 11 13:04:50 2013 +0300
6e8c2f
+++ b/Modules/_ssl.c	Sun Aug 11 18:13:17 2013 +0200
6e8c2f
@@ -741,8 +741,13 @@
6e8c2f
 
6e8c2f
             /* get a rendering of each name in the set of names */
6e8c2f
 
6e8c2f
+            int gntype;
6e8c2f
+            ASN1_STRING *as = NULL;
6e8c2f
+
6e8c2f
             name = sk_GENERAL_NAME_value(names, j);
6e8c2f
-            if (name->type == GEN_DIRNAME) {
6e8c2f
+            gntype = name-> type;
6e8c2f
+            switch (gntype) {
6e8c2f
+            case GEN_DIRNAME:
6e8c2f
 
6e8c2f
                 /* we special-case DirName as a tuple of tuples of attributes */
6e8c2f
 
6e8c2f
@@ -764,11 +769,61 @@
6e8c2f
                     goto fail;
6e8c2f
                 }
6e8c2f
                 PyTuple_SET_ITEM(t, 1, v);
6e8c2f
+                break;
6e8c2f
 
6e8c2f
-            } else {
6e8c2f
+            case GEN_EMAIL:
6e8c2f
+            case GEN_DNS:
6e8c2f
+            case GEN_URI:
6e8c2f
+                /* GENERAL_NAME_print() doesn't handle NUL bytes in ASN1_string
6e8c2f
+                   correctly. */
6e8c2f
+                t = PyTuple_New(2);
6e8c2f
+                if (t == NULL)
6e8c2f
+                    goto fail;
6e8c2f
+                switch (gntype) {
6e8c2f
+                case GEN_EMAIL:
6e8c2f
+                    v = PyUnicode_FromString("email");
6e8c2f
+                    as = name->d.rfc822Name;
6e8c2f
+                    break;
6e8c2f
+                case GEN_DNS:
6e8c2f
+                    v = PyUnicode_FromString("DNS");
6e8c2f
+                    as = name->d.dNSName;
6e8c2f
+                    break;
6e8c2f
+                case GEN_URI:
6e8c2f
+                    v = PyUnicode_FromString("URI");
6e8c2f
+                    as = name->d.uniformResourceIdentifier;
6e8c2f
+                    break;
6e8c2f
+                }
6e8c2f
+                if (v == NULL) {
6e8c2f
+                    Py_DECREF(t);
6e8c2f
+                    goto fail;
6e8c2f
+                }
6e8c2f
+                PyTuple_SET_ITEM(t, 0, v);
6e8c2f
+                v = PyString_FromStringAndSize((char *)ASN1_STRING_data(as),
6e8c2f
+                                               ASN1_STRING_length(as));
6e8c2f
+                if (v == NULL) {
6e8c2f
+                    Py_DECREF(t);
6e8c2f
+                    goto fail;
6e8c2f
+                }
6e8c2f
+                PyTuple_SET_ITEM(t, 1, v);
6e8c2f
+                break;
6e8c2f
 
6e8c2f
+            default:
6e8c2f
                 /* for everything else, we use the OpenSSL print form */
6e8c2f
-
6e8c2f
+                switch (gntype) {
6e8c2f
+                    /* check for new general name type */
6e8c2f
+                    case GEN_OTHERNAME:
6e8c2f
+                    case GEN_X400:
6e8c2f
+                    case GEN_EDIPARTY:
6e8c2f
+                    case GEN_IPADD:
6e8c2f
+                    case GEN_RID:
6e8c2f
+                        break;
6e8c2f
+                    default:
6e8c2f
+                        if (PyErr_Warn(PyExc_RuntimeWarning,
6e8c2f
+				       "Unknown general name type") == -1) {
6e8c2f
+                            goto fail;
6e8c2f
+                        }
6e8c2f
+                        break;
6e8c2f
+                }
6e8c2f
                 (void) BIO_reset(biobuf);
6e8c2f
                 GENERAL_NAME_print(biobuf, name);
6e8c2f
                 len = BIO_gets(biobuf, buf, sizeof(buf)-1);
6e8c2f
@@ -794,6 +849,7 @@
6e8c2f
                     goto fail;
6e8c2f
                 }
6e8c2f
                 PyTuple_SET_ITEM(t, 1, v);
6e8c2f
+		break;
6e8c2f
             }
6e8c2f
 
6e8c2f
             /* and add that rendering to the list */