components/python/python27/patches/16-CVE-2013-4238.py27.patch
branchs11u2-sru
changeset 3379 e99da14b537a
parent 3375 3724eda7445e
child 3380 ab1cb904871a
equal deleted inserted replaced
3375:3724eda7445e 3379:e99da14b537a
     1 # CVE-2013-4238
       
     2 # http://bugs.python.org/issue18709
       
     3 #
       
     4 diff -r 9ddc63c039ba Lib/test/nullbytecert.pem
       
     5 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
       
     6 +++ b/Lib/test/nullbytecert.pem	Sun Aug 11 18:13:17 2013 +0200
       
     7 @@ -0,0 +1,90 @@
       
     8 +Certificate:
       
     9 +    Data:
       
    10 +        Version: 3 (0x2)
       
    11 +        Serial Number: 0 (0x0)
       
    12 +    Signature Algorithm: sha1WithRSAEncryption
       
    13 +        Issuer: C=US, ST=Oregon, L=Beaverton, O=Python Software Foundation, OU=Python Core Development, CN=null.python.org\x00example.org/[email protected]
       
    14 +        Validity
       
    15 +            Not Before: Aug  7 13:11:52 2013 GMT
       
    16 +            Not After : Aug  7 13:12:52 2013 GMT
       
    17 +        Subject: C=US, ST=Oregon, L=Beaverton, O=Python Software Foundation, OU=Python Core Development, CN=null.python.org\x00example.org/[email protected]
       
    18 +        Subject Public Key Info:
       
    19 +            Public Key Algorithm: rsaEncryption
       
    20 +                Public-Key: (2048 bit)
       
    21 +                Modulus:
       
    22 +                    00:b5:ea:ed:c9:fb:46:7d:6f:3b:76:80:dd:3a:f3:
       
    23 +                    03:94:0b:a7:a6:db:ec:1d:df:ff:23:74:08:9d:97:
       
    24 +                    16:3f:a3:a4:7b:3e:1b:0e:96:59:25:03:a7:26:e2:
       
    25 +                    88:a9:cf:79:cd:f7:04:56:b0:ab:79:32:6e:59:c1:
       
    26 +                    32:30:54:eb:58:a8:cb:91:f0:42:a5:64:27:cb:d4:
       
    27 +                    56:31:88:52:ad:cf:bd:7f:f0:06:64:1f:cc:27:b8:
       
    28 +                    a3:8b:8c:f3:d8:29:1f:25:0b:f5:46:06:1b:ca:02:
       
    29 +                    45:ad:7b:76:0a:9c:bf:bb:b9:ae:0d:16:ab:60:75:
       
    30 +                    ae:06:3e:9c:7c:31:dc:92:2f:29:1a:e0:4b:0c:91:
       
    31 +                    90:6c:e9:37:c5:90:d7:2a:d7:97:15:a3:80:8f:5d:
       
    32 +                    7b:49:8f:54:30:d4:97:2c:1c:5b:37:b5:ab:69:30:
       
    33 +                    68:43:d3:33:78:4b:02:60:f5:3c:44:80:a1:8f:e7:
       
    34 +                    f0:0f:d1:5e:87:9e:46:cf:62:fc:f9:bf:0c:65:12:
       
    35 +                    f1:93:c8:35:79:3f:c8:ec:ec:47:f5:ef:be:44:d5:
       
    36 +                    ae:82:1e:2d:9a:9f:98:5a:67:65:e1:74:70:7c:cb:
       
    37 +                    d3:c2:ce:0e:45:49:27:dc:e3:2d:d4:fb:48:0e:2f:
       
    38 +                    9e:77:b8:14:46:c0:c4:36:ca:02:ae:6a:91:8c:da:
       
    39 +                    2f:85
       
    40 +                Exponent: 65537 (0x10001)
       
    41 +        X509v3 extensions:
       
    42 +            X509v3 Basic Constraints: critical
       
    43 +                CA:FALSE
       
    44 +            X509v3 Subject Key Identifier:
       
    45 +                88:5A:55:C0:52:FF:61:CD:52:A3:35:0F:EA:5A:9C:24:38:22:F7:5C
       
    46 +            X509v3 Key Usage:
       
    47 +                Digital Signature, Non Repudiation, Key Encipherment
       
    48 +            X509v3 Subject Alternative Name:
       
    49 +                *************************************************************
       
    50 +                WARNING: The values for DNS, email and URI are WRONG. OpenSSL
       
    51 +                         doesn't print the text after a NULL byte.
       
    52 +                *************************************************************
       
    53 +                DNS:altnull.python.org, email:[email protected], URI:http://null.python.org, IP Address:192.0.2.1, IP Address:2001:DB8:0:0:0:0:0:1
       
    54 +    Signature Algorithm: sha1WithRSAEncryption
       
    55 +         ac:4f:45:ef:7d:49:a8:21:70:8e:88:59:3e:d4:36:42:70:f5:
       
    56 +         a3:bd:8b:d7:a8:d0:58:f6:31:4a:b1:a4:a6:dd:6f:d9:e8:44:
       
    57 +         3c:b6:0a:71:d6:7f:b1:08:61:9d:60:ce:75:cf:77:0c:d2:37:
       
    58 +         86:02:8d:5e:5d:f9:0f:71:b4:16:a8:c1:3d:23:1c:f1:11:b3:
       
    59 +         56:6e:ca:d0:8d:34:94:e6:87:2a:99:f2:ae:ae:cc:c2:e8:86:
       
    60 +         de:08:a8:7f:c5:05:fa:6f:81:a7:82:e6:d0:53:9d:34:f4:ac:
       
    61 +         3e:40:fe:89:57:7a:29:a4:91:7e:0b:c6:51:31:e5:10:2f:a4:
       
    62 +         60:76:cd:95:51:1a:be:8b:a1:b0:fd:ad:52:bd:d7:1b:87:60:
       
    63 +         d2:31:c7:17:c4:18:4f:2d:08:25:a3:a7:4f:b7:92:ca:e2:f5:
       
    64 +         25:f1:54:75:81:9d:b3:3d:61:a2:f7:da:ed:e1:c6:6f:2c:60:
       
    65 +         1f:d8:6f:c5:92:05:ab:c9:09:62:49:a9:14:ad:55:11:cc:d6:
       
    66 +         4a:19:94:99:97:37:1d:81:5f:8b:cf:a3:a8:96:44:51:08:3d:
       
    67 +         0b:05:65:12:eb:b6:70:80:88:48:72:4f:c6:c2:da:cf:cd:8e:
       
    68 +         5b:ba:97:2f:60:b4:96:56:49:5e:3a:43:76:63:04:be:2a:f6:
       
    69 +         c1:ca:a9:94
       
    70 +-----BEGIN CERTIFICATE-----
       
    71 +MIIE2DCCA8CgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBxTELMAkGA1UEBhMCVVMx
       
    72 +DzANBgNVBAgMBk9yZWdvbjESMBAGA1UEBwwJQmVhdmVydG9uMSMwIQYDVQQKDBpQ
       
    73 +eXRob24gU29mdHdhcmUgRm91bmRhdGlvbjEgMB4GA1UECwwXUHl0aG9uIENvcmUg
       
    74 +RGV2ZWxvcG1lbnQxJDAiBgNVBAMMG251bGwucHl0aG9uLm9yZwBleGFtcGxlLm9y
       
    75 +ZzEkMCIGCSqGSIb3DQEJARYVcHl0aG9uLWRldkBweXRob24ub3JnMB4XDTEzMDgw
       
    76 +NzEzMTE1MloXDTEzMDgwNzEzMTI1MlowgcUxCzAJBgNVBAYTAlVTMQ8wDQYDVQQI
       
    77 +DAZPcmVnb24xEjAQBgNVBAcMCUJlYXZlcnRvbjEjMCEGA1UECgwaUHl0aG9uIFNv
       
    78 +ZnR3YXJlIEZvdW5kYXRpb24xIDAeBgNVBAsMF1B5dGhvbiBDb3JlIERldmVsb3Bt
       
    79 +ZW50MSQwIgYDVQQDDBtudWxsLnB5dGhvbi5vcmcAZXhhbXBsZS5vcmcxJDAiBgkq
       
    80 +hkiG9w0BCQEWFXB5dGhvbi1kZXZAcHl0aG9uLm9yZzCCASIwDQYJKoZIhvcNAQEB
       
    81 +BQADggEPADCCAQoCggEBALXq7cn7Rn1vO3aA3TrzA5QLp6bb7B3f/yN0CJ2XFj+j
       
    82 +pHs+Gw6WWSUDpybiiKnPec33BFawq3kyblnBMjBU61ioy5HwQqVkJ8vUVjGIUq3P
       
    83 +vX/wBmQfzCe4o4uM89gpHyUL9UYGG8oCRa17dgqcv7u5rg0Wq2B1rgY+nHwx3JIv
       
    84 +KRrgSwyRkGzpN8WQ1yrXlxWjgI9de0mPVDDUlywcWze1q2kwaEPTM3hLAmD1PESA
       
    85 +oY/n8A/RXoeeRs9i/Pm/DGUS8ZPINXk/yOzsR/XvvkTVroIeLZqfmFpnZeF0cHzL
       
    86 +08LODkVJJ9zjLdT7SA4vnne4FEbAxDbKAq5qkYzaL4UCAwEAAaOB0DCBzTAMBgNV
       
    87 +HRMBAf8EAjAAMB0GA1UdDgQWBBSIWlXAUv9hzVKjNQ/qWpwkOCL3XDALBgNVHQ8E
       
    88 +BAMCBeAwgZAGA1UdEQSBiDCBhYIeYWx0bnVsbC5weXRob24ub3JnAGV4YW1wbGUu
       
    89 +Y29tgSBudWxsQHB5dGhvbi5vcmcAdXNlckBleGFtcGxlLm9yZ4YpaHR0cDovL251
       
    90 +bGwucHl0aG9uLm9yZwBodHRwOi8vZXhhbXBsZS5vcmeHBMAAAgGHECABDbgAAAAA
       
    91 +AAAAAAAAAAEwDQYJKoZIhvcNAQEFBQADggEBAKxPRe99SaghcI6IWT7UNkJw9aO9
       
    92 +i9eo0Fj2MUqxpKbdb9noRDy2CnHWf7EIYZ1gznXPdwzSN4YCjV5d+Q9xtBaowT0j
       
    93 +HPERs1ZuytCNNJTmhyqZ8q6uzMLoht4IqH/FBfpvgaeC5tBTnTT0rD5A/olXeimk
       
    94 +kX4LxlEx5RAvpGB2zZVRGr6LobD9rVK91xuHYNIxxxfEGE8tCCWjp0+3ksri9SXx
       
    95 +VHWBnbM9YaL32u3hxm8sYB/Yb8WSBavJCWJJqRStVRHM1koZlJmXNx2BX4vPo6iW
       
    96 +RFEIPQsFZRLrtnCAiEhyT8bC2s/Njlu6ly9gtJZWSV46Q3ZjBL4q9sHKqZQ=
       
    97 +-----END CERTIFICATE-----
       
    98 diff -r 9ddc63c039ba Lib/test/test_ssl.py
       
    99 --- a/Lib/test/test_ssl.py	Sun Aug 11 13:04:50 2013 +0300
       
   100 +++ b/Lib/test/test_ssl.py	Sun Aug 11 18:13:17 2013 +0200
       
   101 @@ -25,6 +25,7 @@
       
   102  HOST = test_support.HOST
       
   103  CERTFILE = None
       
   104  SVN_PYTHON_ORG_ROOT_CERT = None
       
   105 +NULLBYTECERT = None
       
   106  
       
   107  def handle_error(prefix):
       
   108      exc_format = ' '.join(traceback.format_exception(*sys.exc_info()))
       
   109 @@ -123,6 +124,27 @@
       
   110                            ('DNS', 'projects.forum.nokia.com'))
       
   111                          )
       
   112  
       
   113 +    def test_parse_cert_CVE_2013_4073(self):
       
   114 +        p = ssl._ssl._test_decode_cert(NULLBYTECERT)
       
   115 +        if test_support.verbose:
       
   116 +            sys.stdout.write("\n" + pprint.pformat(p) + "\n")
       
   117 +        subject = ((('countryName', 'US'),),
       
   118 +                   (('stateOrProvinceName', 'Oregon'),),
       
   119 +                   (('localityName', 'Beaverton'),),
       
   120 +                   (('organizationName', 'Python Software Foundation'),),
       
   121 +                   (('organizationalUnitName', 'Python Core Development'),),
       
   122 +                   (('commonName', 'null.python.org\x00example.org'),),
       
   123 +                   (('emailAddress', '[email protected]'),))
       
   124 +        self.assertEqual(p['subject'], subject)
       
   125 +        self.assertEqual(p['issuer'], subject)
       
   126 +        self.assertEqual(p['subjectAltName'],
       
   127 +                         (('DNS', 'altnull.python.org\x00example.com'),
       
   128 +                         ('email', '[email protected]\[email protected]'),
       
   129 +                         ('URI', 'http://null.python.org\x00http://example.org'),
       
   130 +                         ('IP Address', '192.0.2.1'),
       
   131 +                         ('IP Address', '2001:DB8:0:0:0:0:0:1\n'))
       
   132 +                        )
       
   133 +
       
   134      def test_DER_to_PEM(self):
       
   135          with open(SVN_PYTHON_ORG_ROOT_CERT, 'r') as f:
       
   136              pem = f.read()
       
   137 @@ -1360,7 +1382,7 @@
       
   138  
       
   139  
       
   140  def test_main(verbose=False):
       
   141 -    global CERTFILE, SVN_PYTHON_ORG_ROOT_CERT, NOKIACERT
       
   142 +    global CERTFILE, SVN_PYTHON_ORG_ROOT_CERT, NOKIACERT, NULLBYTECERT
       
   143      CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir,
       
   144                              "keycert.pem")
       
   145      SVN_PYTHON_ORG_ROOT_CERT = os.path.join(
       
   146 @@ -1368,10 +1390,13 @@
       
   147          "https_svn_python_org_root.pem")
       
   148      NOKIACERT = os.path.join(os.path.dirname(__file__) or os.curdir,
       
   149                               "nokia.pem")
       
   150 +    NULLBYTECERT = os.path.join(os.path.dirname(__file__) or os.curdir,
       
   151 +                                "nullbytecert.pem")
       
   152  
       
   153      if (not os.path.exists(CERTFILE) or
       
   154          not os.path.exists(SVN_PYTHON_ORG_ROOT_CERT) or
       
   155 -        not os.path.exists(NOKIACERT)):
       
   156 +        not os.path.exists(NOKIACERT) or
       
   157 +        not os.path.exists(NULLBYTECERT)):
       
   158          raise test_support.TestFailed("Can't read certificate files!")
       
   159  
       
   160      tests = [BasicTests, BasicSocketTests]
       
   161 diff -r 9ddc63c039ba Modules/_ssl.c
       
   162 --- a/Modules/_ssl.c	Sun Aug 11 13:04:50 2013 +0300
       
   163 +++ b/Modules/_ssl.c	Sun Aug 11 18:13:17 2013 +0200
       
   164 @@ -741,8 +741,13 @@
       
   165  
       
   166              /* get a rendering of each name in the set of names */
       
   167  
       
   168 +            int gntype;
       
   169 +            ASN1_STRING *as = NULL;
       
   170 +
       
   171              name = sk_GENERAL_NAME_value(names, j);
       
   172 -            if (name->type == GEN_DIRNAME) {
       
   173 +            gntype = name-> type;
       
   174 +            switch (gntype) {
       
   175 +            case GEN_DIRNAME:
       
   176  
       
   177                  /* we special-case DirName as a tuple of tuples of attributes */
       
   178  
       
   179 @@ -764,11 +769,61 @@
       
   180                      goto fail;
       
   181                  }
       
   182                  PyTuple_SET_ITEM(t, 1, v);
       
   183 +                break;
       
   184  
       
   185 -            } else {
       
   186 +            case GEN_EMAIL:
       
   187 +            case GEN_DNS:
       
   188 +            case GEN_URI:
       
   189 +                /* GENERAL_NAME_print() doesn't handle NUL bytes in ASN1_string
       
   190 +                   correctly. */
       
   191 +                t = PyTuple_New(2);
       
   192 +                if (t == NULL)
       
   193 +                    goto fail;
       
   194 +                switch (gntype) {
       
   195 +                case GEN_EMAIL:
       
   196 +                    v = PyUnicode_FromString("email");
       
   197 +                    as = name->d.rfc822Name;
       
   198 +                    break;
       
   199 +                case GEN_DNS:
       
   200 +                    v = PyUnicode_FromString("DNS");
       
   201 +                    as = name->d.dNSName;
       
   202 +                    break;
       
   203 +                case GEN_URI:
       
   204 +                    v = PyUnicode_FromString("URI");
       
   205 +                    as = name->d.uniformResourceIdentifier;
       
   206 +                    break;
       
   207 +                }
       
   208 +                if (v == NULL) {
       
   209 +                    Py_DECREF(t);
       
   210 +                    goto fail;
       
   211 +                }
       
   212 +                PyTuple_SET_ITEM(t, 0, v);
       
   213 +                v = PyString_FromStringAndSize((char *)ASN1_STRING_data(as),
       
   214 +                                               ASN1_STRING_length(as));
       
   215 +                if (v == NULL) {
       
   216 +                    Py_DECREF(t);
       
   217 +                    goto fail;
       
   218 +                }
       
   219 +                PyTuple_SET_ITEM(t, 1, v);
       
   220 +                break;
       
   221  
       
   222 +            default:
       
   223                  /* for everything else, we use the OpenSSL print form */
       
   224 -
       
   225 +                switch (gntype) {
       
   226 +                    /* check for new general name type */
       
   227 +                    case GEN_OTHERNAME:
       
   228 +                    case GEN_X400:
       
   229 +                    case GEN_EDIPARTY:
       
   230 +                    case GEN_IPADD:
       
   231 +                    case GEN_RID:
       
   232 +                        break;
       
   233 +                    default:
       
   234 +                        if (PyErr_Warn(PyExc_RuntimeWarning,
       
   235 +				       "Unknown general name type") == -1) {
       
   236 +                            goto fail;
       
   237 +                        }
       
   238 +                        break;
       
   239 +                }
       
   240                  (void) BIO_reset(biobuf);
       
   241                  GENERAL_NAME_print(biobuf, name);
       
   242                  len = BIO_gets(biobuf, buf, sizeof(buf)-1);
       
   243 @@ -794,6 +849,7 @@
       
   244                      goto fail;
       
   245                  }
       
   246                  PyTuple_SET_ITEM(t, 1, v);
       
   247 +		break;
       
   248              }
       
   249  
       
   250              /* and add that rendering to the list */