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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 9699043: net: fallback to online revocation checks for EV status when CRLSet has expired. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 8 years, 9 months 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
OLDNEW
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 <shlobj.h> 8 #include <shlobj.h>
9 #include <windows.h> 9 #include <windows.h>
10 #endif 10 #endif
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 if (err_allowed) { 1364 if (err_allowed) {
1365 EXPECT_NE(0, d.bytes_received()); 1365 EXPECT_NE(0, d.bytes_received());
1366 CheckSSLInfo(r.ssl_info()); 1366 CheckSSLInfo(r.ssl_info());
1367 } else { 1367 } else {
1368 EXPECT_EQ(0, d.bytes_received()); 1368 EXPECT_EQ(0, d.bytes_received());
1369 } 1369 }
1370 } 1370 }
1371 } 1371 }
1372 } 1372 }
1373 1373
1374 class RevCheckedEnabledSSLConfigService : public SSLConfigService { 1374 #if !defined(OS_ANDROID) && !defined(USE_OPENSSL)
1375 public: 1375 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported.
1376 virtual void GetSSLConfig(SSLConfig* config) {
1377 *config = SSLConfig();
1378 config->rev_checking_enabled = true;
1379 config->verify_ev_cert = true;
1380 }
1381 };
1382 1376
1383 // This the fingerprint of the "Testing CA" certificate used by the testserver. 1377 // This the fingerprint of the "Testing CA" certificate used by the testserver.
1384 // See net/data/ssl/certificates/ocsp-test-root.pem. 1378 // See net/data/ssl/certificates/ocsp-test-root.pem.
1385 static const SHA1Fingerprint kOCSPTestCertFingerprint = 1379 static const SHA1Fingerprint kOCSPTestCertFingerprint =
1386 { { 0xf1, 0xad, 0xf6, 0xce, 0x42, 0xac, 0xe7, 0xb4, 0xf4, 0x24, 1380 { { 0xf1, 0xad, 0xf6, 0xce, 0x42, 0xac, 0xe7, 0xb4, 0xf4, 0x24,
1387 0xdb, 0x1a, 0xf7, 0xa0, 0x9f, 0x09, 0xa1, 0xea, 0xf1, 0x5c } }; 1381 0xdb, 0x1a, 0xf7, 0xa0, 0x9f, 0x09, 0xa1, 0xea, 0xf1, 0x5c } };
1388 1382
1389 // This is the policy OID contained in the certificates that testserver 1383 // This is the policy OID contained in the certificates that testserver
1390 // generates. 1384 // generates.
1391 static const char kOCSPTestCertPolicy[] = "1.3.6.1.4.1.11129.2.4.1"; 1385 static const char kOCSPTestCertPolicy[] = "1.3.6.1.4.1.11129.2.4.1";
1392 1386
1393 class HTTPSOCSPTest : public HTTPSRequestTest { 1387 class HTTPSOCSPTest : public HTTPSRequestTest {
1394 public: 1388 public:
1395 HTTPSOCSPTest() 1389 HTTPSOCSPTest()
1396 : context_(new TestURLRequestContext(true)), 1390 : context_(new TestURLRequestContext(true)),
1397 ev_test_policy_(EVRootCAMetadata::GetInstance(), 1391 ev_test_policy_(EVRootCAMetadata::GetInstance(),
1398 kOCSPTestCertFingerprint, 1392 kOCSPTestCertFingerprint,
1399 kOCSPTestCertPolicy) { 1393 kOCSPTestCertPolicy) {
1400 context_->set_ssl_config_service(new RevCheckedEnabledSSLConfigService); 1394 }
1395
1396 virtual void SetUp() OVERRIDE {
1397 InitContext(context_);
1401 context_->Init(); 1398 context_->Init();
wtc 2012/03/16 00:33:10 InitContext(context_) and context_->Init() sound t
agl 2012/03/20 20:02:19 Changed to SetupContext.
1402 1399
1403 scoped_refptr<net::X509Certificate> root_cert = 1400 scoped_refptr<net::X509Certificate> root_cert =
1404 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); 1401 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem");
1405 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert); 1402 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert);
1406 test_root_.reset(new ScopedTestRoot(root_cert)); 1403 test_root_.reset(new ScopedTestRoot(root_cert));
1407 1404
1408 #if defined(USE_NSS) 1405 #if defined(USE_NSS)
1409 SetURLRequestContextForNSSHttpIO(context_.get()); 1406 SetURLRequestContextForNSSHttpIO(context_.get());
1410 EnsureNSSHttpIOInit(); 1407 EnsureNSSHttpIOInit();
1411 #endif 1408 #endif
(...skipping 16 matching lines...) Expand all
1428 EXPECT_EQ(1, d.response_started_count()); 1425 EXPECT_EQ(1, d.response_started_count());
1429 *out_cert_status = r.ssl_info().cert_status; 1426 *out_cert_status = r.ssl_info().cert_status;
1430 } 1427 }
1431 1428
1432 ~HTTPSOCSPTest() { 1429 ~HTTPSOCSPTest() {
1433 #if defined(USE_NSS) 1430 #if defined(USE_NSS)
1434 ShutdownNSSHttpIO(); 1431 ShutdownNSSHttpIO();
1435 #endif 1432 #endif
1436 } 1433 }
1437 1434
1438 private: 1435 protected:
1436 class RevCheckedEnabledSSLConfigService : public SSLConfigService {
1437 public:
1438 virtual void GetSSLConfig(SSLConfig* config) {
1439 *config = SSLConfig();
1440 config->rev_checking_enabled = true;
1441 config->verify_ev_cert = true;
1442 }
1443 };
1444
1445 // InitContext configures the URLRequestContext that will be used for making
1446 // connetions to testserver. This can be overridden in test subclasses for
1447 // different behaviour.
1448 virtual void InitContext(URLRequestContext* context) {
1449 context->set_ssl_config_service(new RevCheckedEnabledSSLConfigService);
1450 }
1451
1439 scoped_ptr<ScopedTestRoot> test_root_; 1452 scoped_ptr<ScopedTestRoot> test_root_;
1440 scoped_refptr<TestURLRequestContext> context_; 1453 scoped_refptr<TestURLRequestContext> context_;
1441 ScopedTestEVPolicy ev_test_policy_; 1454 ScopedTestEVPolicy ev_test_policy_;
1442 }; 1455 };
1443 1456
1444 #if !defined(OS_ANDROID) && !defined(USE_OPENSSL) 1457 static CertStatus ExpectedCertStatusForFailedOnlineRevocationCheck() {
1445 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported. 1458 #if defined(OS_WIN)
1459 // Windows can return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION but we don't
1460 // have that ability on other platforms.
1461 return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION;
1462 #else
1463 return 0;
1464 #endif
1465 }
1466
1467 // SystemUsesChromiumEVMetadata returns true iff the current operating system
1468 // uses Chromium's EV metadata (i.e. EVRootCAMetadata). If it does not, then
1469 // several tests are effected because our testing EV certificate won't be
1470 // recognised as EV.
1471 static bool SystemUsesChromiumEVMetadata() {
1472 #if defined(OS_MACOSX)
1473 // On OS X, we use the system to tell us whether a certificate is EV or not
1474 // and the system won't recognise our testing root.
1475 return false;
1476 #else
1477 return true;
1478 #endif
1479 }
1480
1446 TEST_F(HTTPSOCSPTest, Valid) { 1481 TEST_F(HTTPSOCSPTest, Valid) {
1447 TestServer::HTTPSOptions https_options(TestServer::HTTPSOptions::CERT_AUTO); 1482 TestServer::HTTPSOptions https_options(TestServer::HTTPSOptions::CERT_AUTO);
1448 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_OK; 1483 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_OK;
1449 1484
1450 CertStatus cert_status; 1485 CertStatus cert_status;
1451 DoConnection(https_options, &cert_status); 1486 DoConnection(https_options, &cert_status);
1452 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); 1487 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS);
1453 1488
1454 #if defined(OS_MACOSX) 1489 EXPECT_EQ(SystemUsesChromiumEVMetadata(),
1455 // On OS X, we use the system to tell us whether a certificate is EV or not 1490 static_cast<bool>(cert_status & CERT_STATUS_IS_EV));
Ryan Sleevi 2012/03/16 00:50:52 nit: !!(cert_status & CERT_STATUS_IS_EV) ? The st
1456 // and the system won't recognise our testing root.
1457 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
1458 #else
1459 EXPECT_TRUE(cert_status & CERT_STATUS_IS_EV);
1460 #endif
1461 1491
1462 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); 1492 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
1463 } 1493 }
1464 1494
1465 TEST_F(HTTPSOCSPTest, Revoked) { 1495 TEST_F(HTTPSOCSPTest, Revoked) {
1466 TestServer::HTTPSOptions https_options( 1496 TestServer::HTTPSOptions https_options(
1467 TestServer::HTTPSOptions::CERT_AUTO); 1497 TestServer::HTTPSOptions::CERT_AUTO);
1468 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_REVOKED; 1498 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_REVOKED;
1469 1499
1470 CertStatus cert_status; 1500 CertStatus cert_status;
1471 DoConnection(https_options, &cert_status); 1501 DoConnection(https_options, &cert_status);
1472 #if !defined(OS_MACOSX) 1502 #if !defined(OS_MACOSX)
1473 // Doesn't pass on OS X yet for reasons that need to be investigated. 1503 // Doesn't pass on OS X yet for reasons that need to be investigated.
1474 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); 1504 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS);
1475 #endif 1505 #endif
1476 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); 1506 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
1477 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); 1507 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
1478 } 1508 }
1479 1509
1480 TEST_F(HTTPSOCSPTest, Invalid) { 1510 TEST_F(HTTPSOCSPTest, Invalid) {
1481 TestServer::HTTPSOptions https_options( 1511 TestServer::HTTPSOptions https_options(
1482 TestServer::HTTPSOptions::CERT_AUTO); 1512 TestServer::HTTPSOptions::CERT_AUTO);
1483 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_INVALID; 1513 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_INVALID;
1484 1514
1485 CertStatus cert_status; 1515 CertStatus cert_status;
1486 DoConnection(https_options, &cert_status); 1516 DoConnection(https_options, &cert_status);
1487 1517
1488 #if defined(OS_WIN) 1518 EXPECT_EQ(ExpectedCertStatusForFailedOnlineRevocationCheck(),
1489 // Windows can return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION but we don't
1490 // have that ability on other platforms.
1491 EXPECT_EQ(CERT_STATUS_UNABLE_TO_CHECK_REVOCATION,
1492 cert_status & CERT_STATUS_ALL_ERRORS); 1519 cert_status & CERT_STATUS_ALL_ERRORS);
1493 #else
1494 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS);
1495 #endif
1496 1520
1497 // Without a positive OCSP response, we shouldn't show the EV status. 1521 // Without a positive OCSP response, we shouldn't show the EV status.
1498 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); 1522 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
1499 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); 1523 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
1500 } 1524 }
1525
1526 class HTTPSEVCRLSetTest : public HTTPSOCSPTest {
1527 protected:
1528 class RevCheckedDisabledSSLConfigService : public SSLConfigService {
1529 public:
1530 virtual void GetSSLConfig(SSLConfig* config) {
1531 *config = SSLConfig();
1532 config->rev_checking_enabled = false;
1533 config->verify_ev_cert = true;
1534 }
1535 };
1536
1537 virtual void InitContext(URLRequestContext* context) OVERRIDE {
1538 context->set_ssl_config_service(new RevCheckedDisabledSSLConfigService);
1539 }
1540 };
1541
1542 TEST_F(HTTPSEVCRLSetTest, MissingCRLSetAndInvalidOCSP) {
1543 TestServer::HTTPSOptions https_options(
1544 TestServer::HTTPSOptions::CERT_AUTO);
1545 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_INVALID;
1546 SSLConfigService::SetCRLSet(scoped_refptr<CRLSet>());
1547
1548 CertStatus cert_status;
1549 DoConnection(https_options, &cert_status);
1550
1551 EXPECT_EQ(ExpectedCertStatusForFailedOnlineRevocationCheck(),
1552 cert_status & CERT_STATUS_ALL_ERRORS);
1553
1554 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
1555 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
1556 }
1557
1558 TEST_F(HTTPSEVCRLSetTest, MissingCRLSetAndGoodOCSP) {
1559 TestServer::HTTPSOptions https_options(
1560 TestServer::HTTPSOptions::CERT_AUTO);
1561 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_OK;
1562 SSLConfigService::SetCRLSet(scoped_refptr<CRLSet>());
1563
1564 CertStatus cert_status;
1565 DoConnection(https_options, &cert_status);
1566
1567 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS);
1568
1569 EXPECT_EQ(SystemUsesChromiumEVMetadata(),
1570 static_cast<bool>(cert_status & CERT_STATUS_IS_EV));
1571
1572 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
1573 }
1574
1575 TEST_F(HTTPSEVCRLSetTest, ExpiredCRLSet) {
1576 TestServer::HTTPSOptions https_options(
1577 TestServer::HTTPSOptions::CERT_AUTO);
1578 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_INVALID;
1579 SSLConfigService::SetCRLSet(
1580 scoped_refptr<CRLSet>(CRLSet::ExpiredCRLSetForTesting()));
1581
1582 CertStatus cert_status;
1583 DoConnection(https_options, &cert_status);
1584
1585 EXPECT_EQ(ExpectedCertStatusForFailedOnlineRevocationCheck(),
1586 cert_status & CERT_STATUS_ALL_ERRORS);
1587
1588 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
1589 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
1590 }
1591
1592 TEST_F(HTTPSEVCRLSetTest, FreshCRLSet) {
1593 TestServer::HTTPSOptions https_options(
1594 TestServer::HTTPSOptions::CERT_AUTO);
1595 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_INVALID;
1596 SSLConfigService::SetCRLSet(
1597 scoped_refptr<CRLSet>(CRLSet::EmptyCRLSetForTesting()));
1598
1599 CertStatus cert_status;
1600 DoConnection(https_options, &cert_status);
1601
1602 // With a valid, fresh CRLSet the bad OCSP response shouldn't matter because
1603 // we wont check it.
1604 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS);
1605
1606 EXPECT_EQ(SystemUsesChromiumEVMetadata(),
1607 static_cast<bool>(cert_status & CERT_STATUS_IS_EV));
1608
1609 EXPECT_FALSE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
1610 }
1611
1612 class HTTPSCRLSetTest : public HTTPSOCSPTest {
1613 protected:
1614 class RevCheckedDisabledSSLConfigService : public SSLConfigService {
Ryan Sleevi 2012/03/16 00:50:52 nit: Just create a single SSLConfigService that ta
agl 2012/03/20 20:02:19 Done. Makes more sense now that there are three of
1615 public:
1616 virtual void GetSSLConfig(SSLConfig* config) {
1617 *config = SSLConfig();
1618 config->rev_checking_enabled = false;
1619 config->verify_ev_cert = false;
1620 }
1621 };
1622
1623 virtual void InitContext(URLRequestContext* context) OVERRIDE {
1624 context->set_ssl_config_service(new RevCheckedDisabledSSLConfigService);
1625 }
1626 };
1627
1628 TEST_F(HTTPSCRLSetTest, ExpiredCRLSet) {
1629 TestServer::HTTPSOptions https_options(
1630 TestServer::HTTPSOptions::CERT_AUTO);
1631 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_INVALID;
1632 SSLConfigService::SetCRLSet(
1633 scoped_refptr<CRLSet>(CRLSet::ExpiredCRLSetForTesting()));
1634
1635 CertStatus cert_status;
1636 DoConnection(https_options, &cert_status);
1637
1638 // If we're not trying EV verification then, even if the CRLSet has expired,
1639 // we don't fall back to online revocation checks.
1640 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS);
1641 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
1642 EXPECT_FALSE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
1643 }
1644
1501 #endif // !OS_ANDROID && !USE_OPENSSL 1645 #endif // !OS_ANDROID && !USE_OPENSSL
1502 1646
1503 // This tests that a load of www.google.com with a certificate error sets 1647 // This tests that a load of www.google.com with a certificate error sets
1504 // the |certificate_errors_are_fatal| flag correctly. This flag will cause 1648 // the |certificate_errors_are_fatal| flag correctly. This flag will cause
1505 // the interstitial to be fatal. 1649 // the interstitial to be fatal.
1506 TEST_F(HTTPSRequestTest, HTTPSPreloadedHSTSTest) { 1650 TEST_F(HTTPSRequestTest, HTTPSPreloadedHSTSTest) {
1507 TestServer::HTTPSOptions https_options( 1651 TestServer::HTTPSOptions https_options(
1508 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); 1652 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME);
1509 TestServer test_server(https_options, 1653 TestServer test_server(https_options,
1510 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 1654 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
(...skipping 2820 matching lines...) Expand 10 before | Expand all | Expand 10 after
4331 req.SetExtraRequestHeaders(headers); 4475 req.SetExtraRequestHeaders(headers);
4332 req.Start(); 4476 req.Start();
4333 MessageLoop::current()->Run(); 4477 MessageLoop::current()->Run();
4334 // If the net tests are being run with ChromeFrame then we need to allow for 4478 // If the net tests are being run with ChromeFrame then we need to allow for
4335 // the 'chromeframe' suffix which is added to the user agent before the 4479 // the 'chromeframe' suffix which is added to the user agent before the
4336 // closing parentheses. 4480 // closing parentheses.
4337 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); 4481 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true));
4338 } 4482 }
4339 4483
4340 } // namespace net 4484 } // namespace net
OLDNEW
« net/base/x509_certificate_win.cc ('K') | « net/data/ssl/certificates/README ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698