cpython: bd2360476bdb (original) (raw)
Mercurial > cpython
changeset 85214:bd2360476bdb 2.7
Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes inside subjectAltName correctly. Formerly the module has used OpenSSL's GENERAL_NAME_print() function to get the string represention of ASN.1 strings for rfc822Name (email), dNSName (DNS) and uniformResourceIdentifier (URI). [#18709]
Christian Heimes christian@cheimes.de | |
---|---|
date | Sat, 17 Aug 2013 00:54:47 +0200 |
parents | 87fcc13ade91 |
children | aea67c35e3ce d4ac6eee7061 |
files | Lib/test/nullbytecert.pem Lib/test/test_ssl.py Misc/NEWS Modules/_ssl.c |
diffstat | 4 files changed, 184 insertions(+), 9 deletions(-)[+] [-] Lib/test/nullbytecert.pem 90 Lib/test/test_ssl.py 29 Misc/NEWS 6 Modules/_ssl.c 68 |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/Lib/test/nullbytecert.pem @@ -0,0 +1,90 @@ +Certificate:
- Data:
Version: 3 (0x2)[](#l1.7)
Serial Number: 0 (0x0)[](#l1.8)
- Signature Algorithm: sha1WithRSAEncryption
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[](#l1.10)
Validity[](#l1.11)
Not Before: Aug 7 13:11:52 2013 GMT[](#l1.12)
Not After : Aug 7 13:12:52 2013 GMT[](#l1.13)
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[](#l1.14)
Subject Public Key Info:[](#l1.15)
Public Key Algorithm: rsaEncryption[](#l1.16)
Public-Key: (2048 bit)[](#l1.17)
Modulus:[](#l1.18)
00:b5:ea:ed:c9:fb:46:7d:6f:3b:76:80:dd:3a:f3:[](#l1.19)
03:94:0b:a7:a6:db:ec:1d:df:ff:23:74:08:9d:97:[](#l1.20)
16:3f:a3:a4:7b:3e:1b:0e:96:59:25:03:a7:26:e2:[](#l1.21)
88:a9:cf:79:cd:f7:04:56:b0🆎79:32:6e:59:c1:[](#l1.22)
32:30:54:eb:58:a8:cb:91:f0:42:a5:64:27:cb:d4:[](#l1.23)
56:31:88:52:ad:cf:bd:7f:f0:06:64:1f:cc:27:b8:[](#l1.24)
a3:8b:8c:f3:d8:29:1f:25:0b:f5:46:06:1b:ca:02:[](#l1.25)
45:ad:7b:76:0a:9c:bf:bb:b9:ae:0d:16:ab:60:75:[](#l1.26)
ae:06:3e:9c:7c:31:dc:92:2f:29:1a:e0:4b:0c:91:[](#l1.27)
90:6c:e9:37:c5:90:d7:2a:d7:97:15:a3:80:8f:5d:[](#l1.28)
7b:49:8f:54:30:d4:97:2c:1c:5b:37:b5:ab:69:30:[](#l1.29)
68:43:d3:33:78:4b:02:60:f5:3c:44:80:a1:8f:e7:[](#l1.30)
f0:0f:d1:5e:87:9e:46:cf:62:fc:f9:bf:0c:65:12:[](#l1.31)
f1:93:c8:35:79:3f:c8:ec:ec:47:f5:ef:be:44:d5:[](#l1.32)
ae:82:1e:2d:9a:9f:98:5a:67:65:e1:74:70:7c:cb:[](#l1.33)
d3:c2:ce:0e:45:49:27:dc:e3:2d:d4:fb:48:0e:2f:[](#l1.34)
9e:77:b8:14:46:c0:c4:36:ca:02:ae:6a:91:8c:da:[](#l1.35)
2f:85[](#l1.36)
Exponent: 65537 (0x10001)[](#l1.37)
X509v3 extensions:[](#l1.38)
X509v3 Basic Constraints: critical[](#l1.39)
CA:FALSE[](#l1.40)
X509v3 Subject Key Identifier:[](#l1.41)
88:5A:55:C0:52:FF:61:CD:52:A3:35:0F:EA:5A:9C:24:38:22:F7:5C[](#l1.42)
X509v3 Key Usage:[](#l1.43)
Digital Signature, Non Repudiation, Key Encipherment[](#l1.44)
X509v3 Subject Alternative Name:[](#l1.45)
*************************************************************[](#l1.46)
WARNING: The values for DNS, email and URI are WRONG. OpenSSL[](#l1.47)
doesn't print the text after a NULL byte.[](#l1.48)
*************************************************************[](#l1.49)
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[](#l1.50)
- Signature Algorithm: sha1WithRSAEncryption
ac:4f:45:ef:7d:49:a8:21:70:8e:88:59:3e:d4:36:42:70:f5:[](#l1.52)
a3:bd:8b:d7:a8:d0:58:f6:31:4a:b1:a4:a6:dd:6f:d9:e8:44:[](#l1.53)
3c:b6:0a:71:d6:7f:b1:08:61:9d:60:ce:75:cf:77:0c:d2:37:[](#l1.54)
86:02:8d:5e:5d:f9:0f:71:b4:16:a8:c1:3d:23:1c:f1:11:b3:[](#l1.55)
56:6e:ca:d0:8d:34:94:e6:87:2a:99:f2:ae:ae:cc:c2:e8:86:[](#l1.56)
de:08:a8:7f:c5:05:fa:6f:81:a7:82:e6:d0:53:9d:34:f4:ac:[](#l1.57)
3e:40:fe:89:57:7a:29:a4:91:7e:0b:c6:51:31:e5:10:2f:a4:[](#l1.58)
60:76:cd:95:51:1a:be:8b:a1:b0:fd:ad:52:bd:d7:1b:87:60:[](#l1.59)
d2:31:c7:17:c4🔞4f:2d:08:25:a3:a7:4f:b7:92:ca:e2:f5:[](#l1.60)
25:f1:54:75:81:9d:b3:3d:61:a2:f7:da:ed:e1:c6:6f:2c:60:[](#l1.61)
1f:d8:6f:c5:92:05:ab:c9:09:62:49:a9:14:ad:55:11:cc:d6:[](#l1.62)
4a:19:94:99:97:37:1d:81:5f:8b:cf:a3:a8:96:44:51:08:3d:[](#l1.63)
0b:05:65:12:eb:b6:70:80:88:48:72:4f:c6:c2:da:cf:cd:8e:[](#l1.64)
5b:ba:97:2f:60:b4:96:56:49:5e:3a:43:76:63:04:be:2a:f6:[](#l1.65)
c1:ca:a9:94[](#l1.66)
+-----BEGIN CERTIFICATE----- +MIIE2DCCA8CgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBxTELMAkGA1UEBhMCVVMx +DzANBgNVBAgMBk9yZWdvbjESMBAGA1UEBwwJQmVhdmVydG9uMSMwIQYDVQQKDBp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dGhvbi5vcmcAdXNlckBleGFtcGxlLm9yZ4YpaHR0cDovL251 +bGwucHl0aG9uLm9yZwBodHRwOi8vZXhhbXBsZS5vcmeHBMAAAgGHECABDbgAAAAA +AAAAAAAAAAEwDQYJKoZIhvcNAQEFBQADggEBAKxPRe99SaghcI6IWT7UNkJw9aO9 +i9eo0Fj2MUqxpKbdb9noRDy2CnHWf7EIYZ1gznXPdwzSN4YCjV5d+Q9xtBaowT0j +HPERs1ZuytCNNJTmhyqZ8q6uzMLoht4IqH/FBfpvgaeC5tBTnTT0rD5A/olXeimk +kX4LxlEx5RAvpGB2zZVRGr6LobD9rVK91xuHYNIxxxfEGE8tCCWjp0+3ksri9SXx +VHWBnbM9YaL32u3hxm8sYB/Yb8WSBavJCWJJqRStVRHM1koZlJmXNx2BX4vPo6iW +RFEIPQsFZRLrtnCAiEhyT8bC2s/Njlu6ly9gtJZWSV46Q3ZjBL4q9sHKqZQ= +-----END CERTIFICATE-----
--- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -25,6 +25,7 @@ ssl = test_support.import_module("ssl") HOST = test_support.HOST CERTFILE = None SVN_PYTHON_ORG_ROOT_CERT = None +NULLBYTECERT = None def handle_error(prefix): exc_format = ' '.join(traceback.format_exception(*sys.exc_info())) @@ -123,6 +124,27 @@ class BasicSocketTests(unittest.TestCase ('DNS', 'projects.forum.nokia.com')) )
- def test_parse_cert_CVE_2013_4238(self):
p = ssl._ssl._test_decode_cert(NULLBYTECERT)[](#l2.16)
if test_support.verbose:[](#l2.17)
sys.stdout.write("\n" + pprint.pformat(p) + "\n")[](#l2.18)
subject = ((('countryName', 'US'),),[](#l2.19)
(('stateOrProvinceName', 'Oregon'),),[](#l2.20)
(('localityName', 'Beaverton'),),[](#l2.21)
(('organizationName', 'Python Software Foundation'),),[](#l2.22)
(('organizationalUnitName', 'Python Core Development'),),[](#l2.23)
(('commonName', 'null.python.org\x00example.org'),),[](#l2.24)
(('emailAddress', 'python-dev@python.org'),))[](#l2.25)
self.assertEqual(p['subject'], subject)[](#l2.26)
self.assertEqual(p['issuer'], subject)[](#l2.27)
self.assertEqual(p['subjectAltName'],[](#l2.28)
(('DNS', 'altnull.python.org\x00example.com'),[](#l2.29)
('email', 'null@python.org\x00user@example.org'),[](#l2.30)
('URI', 'http://null.python.org\x00http://example.org'),[](#l2.31)
('IP Address', '192.0.2.1'),[](#l2.32)
('IP Address', '2001:DB8:0:0:0:0:0:1\n'))[](#l2.33)
)[](#l2.34)
+ def test_DER_to_PEM(self): with open(SVN_PYTHON_ORG_ROOT_CERT, 'r') as f: pem = f.read() @@ -1360,7 +1382,7 @@ else: def test_main(verbose=False):
- global CERTFILE, SVN_PYTHON_ORG_ROOT_CERT, NOKIACERT, NULLBYTECERT CERTFILE = os.path.join(os.path.dirname(file) or os.curdir, "keycert.pem") SVN_PYTHON_ORG_ROOT_CERT = os.path.join( @@ -1368,10 +1390,13 @@ def test_main(verbose=False): "https_svn_python_org_root.pem") NOKIACERT = os.path.join(os.path.dirname(file) or os.curdir, "nokia.pem")
- NULLBYTECERT = os.path.join(os.path.dirname(file) or os.curdir,
"nullbytecert.pem")[](#l2.53)
if (not os.path.exists(CERTFILE) or not os.path.exists(SVN_PYTHON_ORG_ROOT_CERT) or
not os.path.exists(NOKIACERT)):[](#l2.57)
not os.path.exists(NOKIACERT) or[](#l2.58)
not os.path.exists(NULLBYTECERT)):[](#l2.59) raise test_support.TestFailed("Can't read certificate files!")[](#l2.60)
tests = [BasicTests, BasicSocketTests]
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -29,6 +29,12 @@ Core and Builtins Library ------- +- Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
- inside subjectAltName correctly. Formerly the module has used OpenSSL's
- GENERAL_NAME_print() function to get the string represention of ASN.1
- strings for
rfc822Name
(email),dNSName
(DNS) and uniformResourceIdentifier
(URI). +
- Issue #18756: Improve error reporting in os.urandom() when the failure is due to something else than /dev/urandom not existing (for example, exhausting the file descriptor limit).
--- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -738,13 +738,16 @@ static PyObject ext->value->length)); for(j = 0; j < sk_GENERAL_NAME_num(names); j++) { - / get a rendering of each name in the set of names */
int gntype;[](#l4.9)
ASN1_STRING *as = NULL;[](#l4.10)
name = sk_GENERAL_NAME_value(names, j);
if (name->type == GEN_DIRNAME) {[](#l4.13)
/* we special-case DirName as a tuple of tuples of attributes */[](#l4.15)
gntype = name-> type;[](#l4.16)
switch (gntype) {[](#l4.17)
case GEN_DIRNAME:[](#l4.18)
/* we special-case DirName as a tuple of[](#l4.19)
tuples of attributes */[](#l4.20)
t = PyTuple_New(2); if (t == NULL) { @@ -764,11 +767,61 @@ static PyObject * goto fail; } PyTuple_SET_ITEM(t, 1, v); -
} else {[](#l4.29)
break;[](#l4.30)
case GEN_EMAIL:[](#l4.32)
case GEN_DNS:[](#l4.33)
case GEN_URI:[](#l4.34)
/* GENERAL_NAME_print() doesn't handle NULL bytes in ASN1_string[](#l4.35)
correctly, CVE-2013-4238 */[](#l4.36)
t = PyTuple_New(2);[](#l4.37)
if (t == NULL)[](#l4.38)
goto fail;[](#l4.39)
switch (gntype) {[](#l4.40)
case GEN_EMAIL:[](#l4.41)
v = PyString_FromString("email");[](#l4.42)
as = name->d.rfc822Name;[](#l4.43)
break;[](#l4.44)
case GEN_DNS:[](#l4.45)
v = PyString_FromString("DNS");[](#l4.46)
as = name->d.dNSName;[](#l4.47)
break;[](#l4.48)
case GEN_URI:[](#l4.49)
v = PyString_FromString("URI");[](#l4.50)
as = name->d.uniformResourceIdentifier;[](#l4.51)
break;[](#l4.52)
}[](#l4.53)
if (v == NULL) {[](#l4.54)
Py_DECREF(t);[](#l4.55)
goto fail;[](#l4.56)
}[](#l4.57)
PyTuple_SET_ITEM(t, 0, v);[](#l4.58)
v = PyString_FromStringAndSize((char *)ASN1_STRING_data(as),[](#l4.59)
ASN1_STRING_length(as));[](#l4.60)
if (v == NULL) {[](#l4.61)
Py_DECREF(t);[](#l4.62)
goto fail;[](#l4.63)
}[](#l4.64)
PyTuple_SET_ITEM(t, 1, v);[](#l4.65)
break;[](#l4.66)
default:[](#l4.68) /* for everything else, we use the OpenSSL print form */[](#l4.69)
switch (gntype) {[](#l4.71)
/* check for new general name type */[](#l4.72)
case GEN_OTHERNAME:[](#l4.73)
case GEN_X400:[](#l4.74)
case GEN_EDIPARTY:[](#l4.75)
case GEN_IPADD:[](#l4.76)
case GEN_RID:[](#l4.77)
break;[](#l4.78)
default:[](#l4.79)
if (PyErr_Warn(PyExc_RuntimeWarning,[](#l4.80)
"Unknown general name type") == -1) {[](#l4.81)
goto fail;[](#l4.82)
}[](#l4.83)
break;[](#l4.84)
}[](#l4.85) (void) BIO_reset(biobuf);[](#l4.86) GENERAL_NAME_print(biobuf, name);[](#l4.87) len = BIO_gets(biobuf, buf, sizeof(buf)-1);[](#l4.88)
@@ -794,6 +847,7 @@ static PyObject * goto fail; } PyTuple_SET_ITEM(t, 1, v);
break;[](#l4.93) }[](#l4.94)