Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: net/base/x509_certificate_unittest.cc

Issue 8391036: Add unittests for the detection of md[2,4,5] when verifying certificates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Linux Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/data/ssl/certificates/weak_digest_md2_ee.pem » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "base/sha1.h" 9 #include "base/sha1.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 } 1442 }
1443 } 1443 }
1444 1444
1445 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname( 1445 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname(
1446 test_data.hostname, common_name, dns_names, ip_addressses)); 1446 test_data.hostname, common_name, dns_names, ip_addressses));
1447 } 1447 }
1448 1448
1449 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, 1449 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
1450 testing::ValuesIn(kNameVerifyTestData)); 1450 testing::ValuesIn(kNameVerifyTestData));
1451 1451
1452 // Not implemented on Mac or OpenSSL - http://crbug.com/101123
1453 #if defined(USE_NSS) || defined(OS_WIN)
1454
1455 struct WeakDigestTestData {
1456 const char* root_cert_filename;
1457 const char* intermediate_cert_filename;
1458 const char* ee_cert_filename;
1459 bool expected_has_md5;
1460 bool expected_has_md4;
1461 bool expected_has_md2;
1462 bool expected_has_md5_ca;
1463 bool expected_has_md2_ca;
1464 };
1465
1466 void PrintTo(const WeakDigestTestData& data, std::ostream* os) {
palmer 2011/10/26 19:09:15 You never use this function, so get rid of it.
Ryan Sleevi 2011/10/26 22:27:47 This is GTest "magic" - code.google.com/p/googlete
1467 *os << "root: "
1468 << (data.root_cert_filename ? data.root_cert_filename : "none")
1469 << "; intermediate: " << data.intermediate_cert_filename
1470 << "; end-entity: " << data.ee_cert_filename;
1471 }
1472
1473 const WeakDigestTestData kVerifyWeakDigestTestData[] = {
1474 // The signature algorithm of the root CA should not matter.
1475 { "weak_digest_md2_root.pem", "weak_digest_sha1_intermediate.pem",
1476 "weak_digest_sha1_ee.pem", false, false, false, false, false },
1477 { "weak_digest_md4_root.pem", "weak_digest_sha1_intermediate.pem",
1478 "weak_digest_sha1_ee.pem", false, false, false, false, false },
1479 { "weak_digest_md5_root.pem", "weak_digest_sha1_intermediate.pem",
1480 "weak_digest_sha1_ee.pem", false, false, false, false, false },
1481 // The signature algorithm of intermediates should be properly detected.
1482 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
1483 "weak_digest_sha1_ee.pem", false, false, true, false, true },
1484 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem",
1485 "weak_digest_sha1_ee.pem", false, true, false, false, false },
1486 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem",
1487 "weak_digest_sha1_ee.pem", true, false, false, true, false },
1488 // The signature algorithm of end-entity should be properly detected.
1489 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1490 "weak_digest_md2_ee.pem", false, false, true, false, false },
1491 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1492 "weak_digest_md4_ee.pem", false, true, false, false, false },
1493 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1494 "weak_digest_md5_ee.pem", true, false, false, false, false },
1495 // Disabled on Windows - currently broken for incomplete chains.
1496 // http://crbug.com/101123
1497 #if !defined(OS_WIN)
1498 // Incomplete chains should still report the status of the intermediate.
1499 { NULL, "weak_digest_md2_intermediate.pem", "weak_digest_sha1_ee.pem",
1500 false, false, true, false, true },
1501 { NULL, "weak_digest_md4_intermediate.pem", "weak_digest_sha1_ee.pem",
1502 false, true, false, false, false },
1503 { NULL, "weak_digest_md5_intermediate.pem", "weak_digest_sha1_ee.pem",
1504 true, false, false, true, false },
1505 #endif
1506 // Incomplete chains should still report the status of the end-entity.
1507 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md2_ee.pem",
1508 false, false, true, false, false },
1509 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md4_ee.pem",
1510 false, true, false, false, false },
1511 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md5_ee.pem",
1512 true, false, false, false, false },
1513 // Differing algorithms between the intermediate and the EE should still be
1514 // reported.
1515 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem",
1516 "weak_digest_md2_ee.pem", false, true, true, false, false },
1517 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem",
1518 "weak_digest_md2_ee.pem", true, false, true, true, false },
1519 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
1520 "weak_digest_md5_ee.pem", true, false, true, false, true },
1521 };
1522
1523 class X509CertificateWeakDigestTest
1524 : public testing::TestWithParam<WeakDigestTestData> {
1525 public:
1526 X509CertificateWeakDigestTest() {
1527 }
1528
1529 virtual void TearDown() {
1530 TestRootCerts::GetInstance()->Clear();
1531 }
1532 };
1533
1534 TEST_P(X509CertificateWeakDigestTest, VerifyWithWeakDigest) {
1535 WeakDigestTestData data = GetParam();
1536 FilePath certs_dir = GetTestCertsDirectory();
1537
1538 if (data.root_cert_filename) {
1539 scoped_refptr<X509Certificate> root_cert =
1540 ImportCertFromFile(certs_dir, data.root_cert_filename);
1541 ASSERT_NE(static_cast<X509Certificate*>(NULL), root_cert);
1542 TestRootCerts::GetInstance()->Add(root_cert.get());
1543 }
palmer 2011/10/26 19:09:15 Should be indented two spaces.
1544
1545 scoped_refptr<X509Certificate> intermediate_cert =
1546 ImportCertFromFile(certs_dir, data.intermediate_cert_filename);
1547 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert);
1548 scoped_refptr<X509Certificate> ee_cert =
1549 ImportCertFromFile(certs_dir, data.ee_cert_filename);
1550 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_cert);
1551
1552 X509Certificate::OSCertHandles intermediates;
1553 intermediates.push_back(intermediate_cert->os_cert_handle());
1554
1555 scoped_refptr<X509Certificate> ee_chain =
1556 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(),
1557 intermediates);
1558 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain);
1559
1560 int flags = 0;
1561 CertVerifyResult verify_result;
1562 ee_chain->Verify("127.0.0.1", flags, NULL, &verify_result);
1563 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5);
1564 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4);
1565 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2);
1566 EXPECT_EQ(data.expected_has_md5_ca, verify_result.has_md5_ca);
1567 EXPECT_EQ(data.expected_has_md2_ca, verify_result.has_md2_ca);
1568 }
1569
1570
1571 INSTANTIATE_TEST_CASE_P(, X509CertificateWeakDigestTest,
1572 testing::ValuesIn(kVerifyWeakDigestTestData));
1573 #endif // defined(USE_NSS) || defined(OS_WIN)
1574
1452 } // namespace net 1575 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/data/ssl/certificates/weak_digest_md2_ee.pem » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698