| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #endif | 10 #endif |
| (...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1368 if (err_allowed) { | 1368 if (err_allowed) { |
| 1369 EXPECT_NE(0, d.bytes_received()); | 1369 EXPECT_NE(0, d.bytes_received()); |
| 1370 CheckSSLInfo(r.ssl_info()); | 1370 CheckSSLInfo(r.ssl_info()); |
| 1371 } else { | 1371 } else { |
| 1372 EXPECT_EQ(0, d.bytes_received()); | 1372 EXPECT_EQ(0, d.bytes_received()); |
| 1373 } | 1373 } |
| 1374 } | 1374 } |
| 1375 } | 1375 } |
| 1376 } | 1376 } |
| 1377 | 1377 |
| 1378 class RevCheckedEnabledSSLConfigService : public SSLConfigService { | 1378 class TestSSLConfigService : public SSLConfigService { |
| 1379 public: | 1379 public: |
| 1380 TestSSLConfigService(bool ev_enabled, bool online_rev_checking) |
| 1381 : ev_enabled_(ev_enabled), |
| 1382 online_rev_checking_(online_rev_checking) { |
| 1383 } |
| 1384 |
| 1380 virtual void GetSSLConfig(SSLConfig* config) { | 1385 virtual void GetSSLConfig(SSLConfig* config) { |
| 1381 *config = SSLConfig(); | 1386 *config = SSLConfig(); |
| 1382 config->rev_checking_enabled = true; | 1387 config->rev_checking_enabled = online_rev_checking_; |
| 1383 config->verify_ev_cert = true; | 1388 config->verify_ev_cert = ev_enabled_; |
| 1384 } | 1389 } |
| 1390 |
| 1391 private: |
| 1392 const bool ev_enabled_; |
| 1393 const bool online_rev_checking_; |
| 1385 }; | 1394 }; |
| 1386 | 1395 |
| 1387 // This the fingerprint of the "Testing CA" certificate used by the testserver. | 1396 // This the fingerprint of the "Testing CA" certificate used by the testserver. |
| 1388 // See net/data/ssl/certificates/ocsp-test-root.pem. | 1397 // See net/data/ssl/certificates/ocsp-test-root.pem. |
| 1389 static const SHA1Fingerprint kOCSPTestCertFingerprint = | 1398 static const SHA1Fingerprint kOCSPTestCertFingerprint = |
| 1390 { { 0xf1, 0xad, 0xf6, 0xce, 0x42, 0xac, 0xe7, 0xb4, 0xf4, 0x24, | 1399 { { 0xf1, 0xad, 0xf6, 0xce, 0x42, 0xac, 0xe7, 0xb4, 0xf4, 0x24, |
| 1391 0xdb, 0x1a, 0xf7, 0xa0, 0x9f, 0x09, 0xa1, 0xea, 0xf1, 0x5c } }; | 1400 0xdb, 0x1a, 0xf7, 0xa0, 0x9f, 0x09, 0xa1, 0xea, 0xf1, 0x5c } }; |
| 1392 | 1401 |
| 1393 // This is the policy OID contained in the certificates that testserver | 1402 // This is the policy OID contained in the certificates that testserver |
| 1394 // generates. | 1403 // generates. |
| 1395 static const char kOCSPTestCertPolicy[] = "1.3.6.1.4.1.11129.2.4.1"; | 1404 static const char kOCSPTestCertPolicy[] = "1.3.6.1.4.1.11129.2.4.1"; |
| 1396 | 1405 |
| 1397 class HTTPSOCSPTest : public HTTPSRequestTest { | 1406 class HTTPSOCSPTest : public HTTPSRequestTest { |
| 1398 public: | 1407 public: |
| 1399 HTTPSOCSPTest() | 1408 HTTPSOCSPTest() |
| 1400 : context_(new TestURLRequestContext(true)), | 1409 : context_(new TestURLRequestContext(true)), |
| 1401 ev_test_policy_(EVRootCAMetadata::GetInstance(), | 1410 ev_test_policy_(EVRootCAMetadata::GetInstance(), |
| 1402 kOCSPTestCertFingerprint, | 1411 kOCSPTestCertFingerprint, |
| 1403 kOCSPTestCertPolicy) { | 1412 kOCSPTestCertPolicy) { |
| 1404 context_->set_ssl_config_service(new RevCheckedEnabledSSLConfigService); | 1413 } |
| 1414 |
| 1415 virtual void SetUp() OVERRIDE { |
| 1416 SetupContext(context_); |
| 1405 context_->Init(); | 1417 context_->Init(); |
| 1406 | 1418 |
| 1407 scoped_refptr<net::X509Certificate> root_cert = | 1419 scoped_refptr<net::X509Certificate> root_cert = |
| 1408 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); | 1420 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); |
| 1409 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert); | 1421 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert); |
| 1410 test_root_.reset(new ScopedTestRoot(root_cert)); | 1422 test_root_.reset(new ScopedTestRoot(root_cert)); |
| 1411 | 1423 |
| 1412 #if defined(USE_NSS) | 1424 #if defined(USE_NSS) |
| 1413 SetURLRequestContextForNSSHttpIO(context_.get()); | 1425 SetURLRequestContextForNSSHttpIO(context_.get()); |
| 1414 EnsureNSSHttpIOInit(); | 1426 EnsureNSSHttpIOInit(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1432 EXPECT_EQ(1, d.response_started_count()); | 1444 EXPECT_EQ(1, d.response_started_count()); |
| 1433 *out_cert_status = r.ssl_info().cert_status; | 1445 *out_cert_status = r.ssl_info().cert_status; |
| 1434 } | 1446 } |
| 1435 | 1447 |
| 1436 ~HTTPSOCSPTest() { | 1448 ~HTTPSOCSPTest() { |
| 1437 #if defined(USE_NSS) | 1449 #if defined(USE_NSS) |
| 1438 ShutdownNSSHttpIO(); | 1450 ShutdownNSSHttpIO(); |
| 1439 #endif | 1451 #endif |
| 1440 } | 1452 } |
| 1441 | 1453 |
| 1442 private: | 1454 protected: |
| 1455 // SetupContext configures the URLRequestContext that will be used for making |
| 1456 // connetions to testserver. This can be overridden in test subclasses for |
| 1457 // different behaviour. |
| 1458 virtual void SetupContext(URLRequestContext* context) { |
| 1459 context->set_ssl_config_service( |
| 1460 new TestSSLConfigService(true /* check for EV */, |
| 1461 true /* online revocation checking */)); |
| 1462 } |
| 1463 |
| 1443 scoped_ptr<ScopedTestRoot> test_root_; | 1464 scoped_ptr<ScopedTestRoot> test_root_; |
| 1444 scoped_refptr<TestURLRequestContext> context_; | 1465 scoped_refptr<TestURLRequestContext> context_; |
| 1445 ScopedTestEVPolicy ev_test_policy_; | 1466 ScopedTestEVPolicy ev_test_policy_; |
| 1446 }; | 1467 }; |
| 1447 | 1468 |
| 1448 #if !defined(OS_ANDROID) && !defined(USE_OPENSSL) | 1469 static CertStatus ExpectedCertStatusForFailedOnlineRevocationCheck() { |
| 1470 #if defined(OS_WIN) |
| 1471 // Windows can return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION but we don't |
| 1472 // have that ability on other platforms. |
| 1473 return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION; |
| 1474 #else |
| 1475 return 0; |
| 1476 #endif |
| 1477 } |
| 1478 |
| 1479 // SystemUsesChromiumEVMetadata returns true iff the current operating system |
| 1480 // uses Chromium's EV metadata (i.e. EVRootCAMetadata). If it does not, then |
| 1481 // several tests are effected because our testing EV certificate won't be |
| 1482 // recognised as EV. |
| 1483 static bool SystemUsesChromiumEVMetadata() { |
| 1484 #if defined(OS_MACOSX) |
| 1485 // On OS X, we use the system to tell us whether a certificate is EV or not |
| 1486 // and the system won't recognise our testing root. |
| 1487 return false; |
| 1488 #else |
| 1489 return true; |
| 1490 #endif |
| 1491 } |
| 1449 | 1492 |
| 1450 static bool | 1493 static bool |
| 1451 SystemSupportsOCSP() { | 1494 SystemSupportsOCSP() { |
| 1452 #if defined(OS_WIN) | 1495 #if defined(OS_WIN) |
| 1453 return base::win::GetVersion() >= base::win::VERSION_VISTA; | 1496 return base::win::GetVersion() >= base::win::VERSION_VISTA; |
| 1454 #elif defined(OS_ANDROID) | 1497 #elif defined(OS_ANDROID) |
| 1498 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported. |
| 1455 return false; | 1499 return false; |
| 1456 #else | 1500 #else |
| 1457 return true; | 1501 return true; |
| 1458 #endif | 1502 #endif |
| 1459 } | 1503 } |
| 1460 | 1504 |
| 1461 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported. | |
| 1462 TEST_F(HTTPSOCSPTest, Valid) { | 1505 TEST_F(HTTPSOCSPTest, Valid) { |
| 1463 if (!SystemSupportsOCSP()) { | 1506 if (!SystemSupportsOCSP()) { |
| 1464 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; | 1507 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; |
| 1465 return; | 1508 return; |
| 1466 } | 1509 } |
| 1467 | 1510 |
| 1468 TestServer::HTTPSOptions https_options(TestServer::HTTPSOptions::CERT_AUTO); | 1511 TestServer::HTTPSOptions https_options(TestServer::HTTPSOptions::CERT_AUTO); |
| 1469 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_OK; | 1512 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_OK; |
| 1470 | 1513 |
| 1471 CertStatus cert_status; | 1514 CertStatus cert_status; |
| 1472 DoConnection(https_options, &cert_status); | 1515 DoConnection(https_options, &cert_status); |
| 1473 | 1516 |
| 1474 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); | 1517 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); |
| 1475 | 1518 |
| 1476 #if defined(OS_MACOSX) | 1519 EXPECT_EQ(SystemUsesChromiumEVMetadata(), |
| 1477 // On OS X, we use the system to tell us whether a certificate is EV or not | 1520 static_cast<bool>(cert_status & CERT_STATUS_IS_EV)); |
| 1478 // and the system won't recognise our testing root. | |
| 1479 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); | |
| 1480 #else | |
| 1481 EXPECT_TRUE(cert_status & CERT_STATUS_IS_EV); | |
| 1482 #endif | |
| 1483 | 1521 |
| 1484 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); | 1522 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); |
| 1485 } | 1523 } |
| 1486 | 1524 |
| 1487 TEST_F(HTTPSOCSPTest, Revoked) { | 1525 TEST_F(HTTPSOCSPTest, Revoked) { |
| 1488 if (!SystemSupportsOCSP()) { | 1526 if (!SystemSupportsOCSP()) { |
| 1489 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; | 1527 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; |
| 1490 return; | 1528 return; |
| 1491 } | 1529 } |
| 1492 | 1530 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1511 return; | 1549 return; |
| 1512 } | 1550 } |
| 1513 | 1551 |
| 1514 TestServer::HTTPSOptions https_options( | 1552 TestServer::HTTPSOptions https_options( |
| 1515 TestServer::HTTPSOptions::CERT_AUTO); | 1553 TestServer::HTTPSOptions::CERT_AUTO); |
| 1516 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_INVALID; | 1554 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_INVALID; |
| 1517 | 1555 |
| 1518 CertStatus cert_status; | 1556 CertStatus cert_status; |
| 1519 DoConnection(https_options, &cert_status); | 1557 DoConnection(https_options, &cert_status); |
| 1520 | 1558 |
| 1521 #if defined(OS_WIN) | 1559 EXPECT_EQ(ExpectedCertStatusForFailedOnlineRevocationCheck(), |
| 1522 // Windows can return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION but we don't | |
| 1523 // have that ability on other platforms. | |
| 1524 EXPECT_EQ(CERT_STATUS_UNABLE_TO_CHECK_REVOCATION, | |
| 1525 cert_status & CERT_STATUS_ALL_ERRORS); | 1560 cert_status & CERT_STATUS_ALL_ERRORS); |
| 1526 #else | |
| 1527 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); | |
| 1528 #endif | |
| 1529 | 1561 |
| 1530 // Without a positive OCSP response, we shouldn't show the EV status. | 1562 // Without a positive OCSP response, we shouldn't show the EV status. |
| 1531 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); | 1563 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); |
| 1532 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); | 1564 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); |
| 1533 } | 1565 } |
| 1534 #endif // !OS_ANDROID && !USE_OPENSSL | 1566 |
| 1567 class HTTPSEVCRLSetTest : public HTTPSOCSPTest { |
| 1568 protected: |
| 1569 virtual void SetupContext(URLRequestContext* context) OVERRIDE { |
| 1570 context->set_ssl_config_service( |
| 1571 new TestSSLConfigService(true /* check for EV */, |
| 1572 false /* online revocation checking */)); |
| 1573 } |
| 1574 }; |
| 1575 |
| 1576 TEST_F(HTTPSEVCRLSetTest, MissingCRLSetAndInvalidOCSP) { |
| 1577 if (!SystemSupportsOCSP()) { |
| 1578 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; |
| 1579 return; |
| 1580 } |
| 1581 |
| 1582 TestServer::HTTPSOptions https_options( |
| 1583 TestServer::HTTPSOptions::CERT_AUTO); |
| 1584 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_INVALID; |
| 1585 SSLConfigService::SetCRLSet(scoped_refptr<CRLSet>()); |
| 1586 |
| 1587 CertStatus cert_status; |
| 1588 DoConnection(https_options, &cert_status); |
| 1589 |
| 1590 EXPECT_EQ(ExpectedCertStatusForFailedOnlineRevocationCheck(), |
| 1591 cert_status & CERT_STATUS_ALL_ERRORS); |
| 1592 |
| 1593 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); |
| 1594 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); |
| 1595 } |
| 1596 |
| 1597 TEST_F(HTTPSEVCRLSetTest, MissingCRLSetAndGoodOCSP) { |
| 1598 if (!SystemSupportsOCSP()) { |
| 1599 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; |
| 1600 return; |
| 1601 } |
| 1602 |
| 1603 TestServer::HTTPSOptions https_options( |
| 1604 TestServer::HTTPSOptions::CERT_AUTO); |
| 1605 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_OK; |
| 1606 SSLConfigService::SetCRLSet(scoped_refptr<CRLSet>()); |
| 1607 |
| 1608 CertStatus cert_status; |
| 1609 DoConnection(https_options, &cert_status); |
| 1610 |
| 1611 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); |
| 1612 |
| 1613 EXPECT_EQ(SystemUsesChromiumEVMetadata(), |
| 1614 static_cast<bool>(cert_status & CERT_STATUS_IS_EV)); |
| 1615 |
| 1616 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); |
| 1617 } |
| 1618 |
| 1619 TEST_F(HTTPSEVCRLSetTest, ExpiredCRLSet) { |
| 1620 if (!SystemSupportsOCSP()) { |
| 1621 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; |
| 1622 return; |
| 1623 } |
| 1624 |
| 1625 TestServer::HTTPSOptions https_options( |
| 1626 TestServer::HTTPSOptions::CERT_AUTO); |
| 1627 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_INVALID; |
| 1628 SSLConfigService::SetCRLSet( |
| 1629 scoped_refptr<CRLSet>(CRLSet::ExpiredCRLSetForTesting())); |
| 1630 |
| 1631 CertStatus cert_status; |
| 1632 DoConnection(https_options, &cert_status); |
| 1633 |
| 1634 EXPECT_EQ(ExpectedCertStatusForFailedOnlineRevocationCheck(), |
| 1635 cert_status & CERT_STATUS_ALL_ERRORS); |
| 1636 |
| 1637 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); |
| 1638 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); |
| 1639 } |
| 1640 |
| 1641 TEST_F(HTTPSEVCRLSetTest, FreshCRLSet) { |
| 1642 TestServer::HTTPSOptions https_options( |
| 1643 TestServer::HTTPSOptions::CERT_AUTO); |
| 1644 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_INVALID; |
| 1645 SSLConfigService::SetCRLSet( |
| 1646 scoped_refptr<CRLSet>(CRLSet::EmptyCRLSetForTesting())); |
| 1647 |
| 1648 CertStatus cert_status; |
| 1649 DoConnection(https_options, &cert_status); |
| 1650 |
| 1651 // With a valid, fresh CRLSet the bad OCSP response shouldn't matter because |
| 1652 // we wont check it. |
| 1653 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); |
| 1654 |
| 1655 EXPECT_EQ(SystemUsesChromiumEVMetadata(), |
| 1656 static_cast<bool>(cert_status & CERT_STATUS_IS_EV)); |
| 1657 |
| 1658 EXPECT_FALSE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); |
| 1659 } |
| 1660 |
| 1661 class HTTPSCRLSetTest : public HTTPSOCSPTest { |
| 1662 protected: |
| 1663 virtual void SetupContext(URLRequestContext* context) OVERRIDE { |
| 1664 context->set_ssl_config_service( |
| 1665 new TestSSLConfigService(false /* check for EV */, |
| 1666 false /* online revocation checking */)); |
| 1667 } |
| 1668 }; |
| 1669 |
| 1670 TEST_F(HTTPSCRLSetTest, ExpiredCRLSet) { |
| 1671 TestServer::HTTPSOptions https_options( |
| 1672 TestServer::HTTPSOptions::CERT_AUTO); |
| 1673 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_INVALID; |
| 1674 SSLConfigService::SetCRLSet( |
| 1675 scoped_refptr<CRLSet>(CRLSet::ExpiredCRLSetForTesting())); |
| 1676 |
| 1677 CertStatus cert_status; |
| 1678 DoConnection(https_options, &cert_status); |
| 1679 |
| 1680 // If we're not trying EV verification then, even if the CRLSet has expired, |
| 1681 // we don't fall back to online revocation checks. |
| 1682 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); |
| 1683 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); |
| 1684 EXPECT_FALSE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); |
| 1685 } |
| 1535 | 1686 |
| 1536 // This tests that a load of www.google.com with a certificate error sets | 1687 // This tests that a load of www.google.com with a certificate error sets |
| 1537 // the |certificate_errors_are_fatal| flag correctly. This flag will cause | 1688 // the |certificate_errors_are_fatal| flag correctly. This flag will cause |
| 1538 // the interstitial to be fatal. | 1689 // the interstitial to be fatal. |
| 1539 TEST_F(HTTPSRequestTest, HTTPSPreloadedHSTSTest) { | 1690 TEST_F(HTTPSRequestTest, HTTPSPreloadedHSTSTest) { |
| 1540 TestServer::HTTPSOptions https_options( | 1691 TestServer::HTTPSOptions https_options( |
| 1541 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); | 1692 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); |
| 1542 TestServer test_server(https_options, | 1693 TestServer test_server(https_options, |
| 1543 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1694 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 1544 ASSERT_TRUE(test_server.Start()); | 1695 ASSERT_TRUE(test_server.Start()); |
| (...skipping 2819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4364 req.SetExtraRequestHeaders(headers); | 4515 req.SetExtraRequestHeaders(headers); |
| 4365 req.Start(); | 4516 req.Start(); |
| 4366 MessageLoop::current()->Run(); | 4517 MessageLoop::current()->Run(); |
| 4367 // If the net tests are being run with ChromeFrame then we need to allow for | 4518 // If the net tests are being run with ChromeFrame then we need to allow for |
| 4368 // the 'chromeframe' suffix which is added to the user agent before the | 4519 // the 'chromeframe' suffix which is added to the user agent before the |
| 4369 // closing parentheses. | 4520 // closing parentheses. |
| 4370 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 4521 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
| 4371 } | 4522 } |
| 4372 | 4523 |
| 4373 } // namespace net | 4524 } // namespace net |
| OLD | NEW |