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

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

Issue 9663017: net: add OCSP tests. (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
11 11
12 #include <algorithm> 12 #include <algorithm>
13 #include <string> 13 #include <string>
14 14
15 #include "base/basictypes.h" 15 #include "base/basictypes.h"
16 #include "base/bind.h" 16 #include "base/bind.h"
17 #include "base/compiler_specific.h" 17 #include "base/compiler_specific.h"
18 #include "base/file_util.h" 18 #include "base/file_util.h"
19 #include "base/format_macros.h" 19 #include "base/format_macros.h"
20 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
21 #include "base/message_loop.h" 21 #include "base/message_loop.h"
22 #include "base/path_service.h" 22 #include "base/path_service.h"
23 #include "base/process_util.h" 23 #include "base/process_util.h"
24 #include "base/string_number_conversions.h" 24 #include "base/string_number_conversions.h"
25 #include "base/string_piece.h" 25 #include "base/string_piece.h"
26 #include "base/string_split.h" 26 #include "base/string_split.h"
27 #include "base/string_util.h" 27 #include "base/string_util.h"
28 #include "base/stringprintf.h" 28 #include "base/stringprintf.h"
29 #include "base/utf_string_conversions.h" 29 #include "base/utf_string_conversions.h"
30 #include "net/base/cert_test_util.h"
30 #include "net/base/cookie_monster.h" 31 #include "net/base/cookie_monster.h"
31 #include "net/base/cookie_store_test_helpers.h" 32 #include "net/base/cookie_store_test_helpers.h"
33 #include "net/base/ev_root_ca_metadata.h"
32 #include "net/base/load_flags.h" 34 #include "net/base/load_flags.h"
33 #include "net/base/mock_host_resolver.h" 35 #include "net/base/mock_host_resolver.h"
34 #include "net/base/net_errors.h" 36 #include "net/base/net_errors.h"
35 #include "net/base/net_log.h" 37 #include "net/base/net_log.h"
36 #include "net/base/net_log_unittest.h" 38 #include "net/base/net_log_unittest.h"
37 #include "net/base/net_module.h" 39 #include "net/base/net_module.h"
38 #include "net/base/net_util.h" 40 #include "net/base/net_util.h"
39 #include "net/base/ssl_connection_status_flags.h" 41 #include "net/base/ssl_connection_status_flags.h"
42 #include "net/base/test_root_certs.h"
40 #include "net/base/upload_data.h" 43 #include "net/base/upload_data.h"
41 #include "net/disk_cache/disk_cache.h" 44 #include "net/disk_cache/disk_cache.h"
42 #include "net/ftp/ftp_network_layer.h" 45 #include "net/ftp/ftp_network_layer.h"
43 #include "net/http/http_cache.h" 46 #include "net/http/http_cache.h"
44 #include "net/http/http_network_layer.h" 47 #include "net/http/http_network_layer.h"
45 #include "net/http/http_network_session.h" 48 #include "net/http/http_network_session.h"
46 #include "net/http/http_request_headers.h" 49 #include "net/http/http_request_headers.h"
47 #include "net/http/http_response_headers.h" 50 #include "net/http/http_response_headers.h"
51 #include "net/ocsp/nss_ocsp.h"
48 #include "net/proxy/proxy_service.h" 52 #include "net/proxy/proxy_service.h"
49 #include "net/socket/ssl_client_socket.h" 53 #include "net/socket/ssl_client_socket.h"
50 #include "net/test/test_server.h" 54 #include "net/test/test_server.h"
51 #include "net/url_request/url_request.h" 55 #include "net/url_request/url_request.h"
52 #include "net/url_request/url_request_file_dir_job.h" 56 #include "net/url_request/url_request_file_dir_job.h"
53 #include "net/url_request/url_request_http_job.h" 57 #include "net/url_request/url_request_http_job.h"
54 #include "net/url_request/url_request_job_factory.h" 58 #include "net/url_request/url_request_job_factory.h"
55 #include "net/url_request/url_request_redirect_job.h" 59 #include "net/url_request/url_request_redirect_job.h"
56 #include "net/url_request/url_request_test_job.h" 60 #include "net/url_request/url_request_test_job.h"
57 #include "net/url_request/url_request_test_util.h" 61 #include "net/url_request/url_request_test_util.h"
(...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 if (err_allowed) { 1364 if (err_allowed) {
1361 EXPECT_NE(0, d.bytes_received()); 1365 EXPECT_NE(0, d.bytes_received());
1362 CheckSSLInfo(r.ssl_info()); 1366 CheckSSLInfo(r.ssl_info());
1363 } else { 1367 } else {
1364 EXPECT_EQ(0, d.bytes_received()); 1368 EXPECT_EQ(0, d.bytes_received());
1365 } 1369 }
1366 } 1370 }
1367 } 1371 }
1368 } 1372 }
1369 1373
1374 class RevCheckedEnabledSSLConfigService : public SSLConfigService {
1375 public:
1376 virtual void GetSSLConfig(SSLConfig* config) {
1377 *config = SSLConfig();
1378 config->rev_checking_enabled = true;
1379 config->verify_ev_cert = true;
1380 }
1381 };
1382
1383 // This the fingerprint of the "Testing CA" certificate used by the testserver.
1384 // See net/data/ssl/certificates/ocsp-test-root.pem.
1385 static const SHA1Fingerprint kOCSPTestCertFingerprint =
1386 { { 0xf1, 0xad, 0xf6, 0xce, 0x42, 0xac, 0xe7, 0xb4, 0xf4, 0x24,
1387 0xdb, 0x1a, 0xf7, 0xa0, 0x9f, 0x09, 0xa1, 0xea, 0xf1, 0x5c } };
1388
1389 // This is the policy OID contained in the certificates that testserver
Ryan Sleevi 2012/03/13 23:06:39 nit: testserver -> test server
agl 2012/03/13 23:44:03 It really is called testserver.
1390 // generates.
1391 static const char kOCSPTestCertPolicy[] = "1.3.6.1.4.1.11129.2.4.1";
1392
1393 class HTTPSOCSPTest : public HTTPSRequestTest {
1394 public:
1395 HTTPSOCSPTest()
1396 : context_(new TestURLRequestContext(true)),
1397 ev_test_policy_(EVRootCAMetadata::GetInstance(),
1398 kOCSPTestCertFingerprint,
1399 kOCSPTestCertPolicy) {
1400 context_->set_ssl_config_service(new RevCheckedEnabledSSLConfigService);
1401 context_->Init();
1402
1403 scoped_refptr<net::X509Certificate> root_cert =
1404 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem");
1405 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert);
1406 test_root_.reset(new ScopedTestRoot(root_cert));
1407
1408 #if defined(USE_NSS)
1409 SetURLRequestContextForOCSP(context_.get());
1410 EnsureOCSPInit();
1411 #endif
1412 }
1413
1414 void DoConnection(const TestServer::HTTPSOptions& https_options,
1415 CertStatus* out_cert_status) {
1416 TestServer test_server(https_options,
1417 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
1418 ASSERT_TRUE(test_server.Start());
1419
1420 TestDelegate d;
1421 d.set_allow_certificate_errors(true);
1422 URLRequest r(test_server.GetURL(""), &d);
1423 r.set_context(context_.get());
1424 r.Start();
1425
1426 MessageLoop::current()->Run();
1427
1428 EXPECT_EQ(1, d.response_started_count());
1429 *out_cert_status = r.ssl_info().cert_status;
1430 }
1431
1432 ~HTTPSOCSPTest() {
1433 #if defined(USE_NSS)
1434 ShutdownOCSP();
1435 #endif
1436 }
1437
1438 private:
1439 scoped_ptr<ScopedTestRoot> test_root_;
1440 scoped_refptr<TestURLRequestContext> context_;
1441 ScopedTestEVPolicy ev_test_policy_;
1442 };
1443
1444 #if !defined(OS_ANDROID) && !defined(USE_OPENSSL)
1445 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported.
1446 TEST_F(HTTPSOCSPTest, Valid) {
1447 TestServer::HTTPSOptions https_options(TestServer::HTTPSOptions::CERT_AUTO);
1448 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_OK;
1449
1450 CertStatus cert_status;
1451 DoConnection(https_options, &cert_status);
1452 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS);
1453
1454 #if defined(OS_MACOSX)
1455 // On OS X, we use the system to tell us whether a certificate is EV or not
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
1462 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
1463 }
1464
1465 TEST_F(HTTPSOCSPTest, Revoked) {
1466 TestServer::HTTPSOptions https_options(
1467 TestServer::HTTPSOptions::CERT_AUTO);
1468 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_REVOKED;
1469
1470 CertStatus cert_status;
1471 DoConnection(https_options, &cert_status);
1472 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS);
1473 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
1474 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
1475 }
1476
1477 TEST_F(HTTPSOCSPTest, Invalid) {
1478 TestServer::HTTPSOptions https_options(
1479 TestServer::HTTPSOptions::CERT_AUTO);
1480 https_options.ocsp_status = TestServer::HTTPSOptions::OCSP_INVALID;
1481
1482 CertStatus cert_status;
1483 DoConnection(https_options, &cert_status);
1484
1485 #if defined(OS_WIN)
1486 // Windows can return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION but we don't
1487 // have that ability on other platforms.
1488 EXPECT_EQ(CERT_STATUS_UNABLE_TO_CHECK_REVOCATION,
1489 cert_status & CERT_STATUS_ALL_ERRORS);
1490 #else
1491 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS);
1492 #endif
1493
1494 // Without a positive OCSP response, we shouldn't show the EV status.
1495 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
1496 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
1497 }
1498 #endif // !OS_ANDROID && !USE_OPENSSL
1499
1370 // This tests that a load of www.google.com with a certificate error sets 1500 // This tests that a load of www.google.com with a certificate error sets
1371 // the |certificate_errors_are_fatal| flag correctly. This flag will cause 1501 // the |certificate_errors_are_fatal| flag correctly. This flag will cause
1372 // the interstitial to be fatal. 1502 // the interstitial to be fatal.
1373 TEST_F(HTTPSRequestTest, HTTPSPreloadedHSTSTest) { 1503 TEST_F(HTTPSRequestTest, HTTPSPreloadedHSTSTest) {
1374 TestServer::HTTPSOptions https_options( 1504 TestServer::HTTPSOptions https_options(
1375 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); 1505 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME);
1376 TestServer test_server(https_options, 1506 TestServer test_server(https_options,
1377 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 1507 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
1378 ASSERT_TRUE(test_server.Start()); 1508 ASSERT_TRUE(test_server.Start());
1379 1509
(...skipping 2818 matching lines...) Expand 10 before | Expand all | Expand 10 after
4198 req.SetExtraRequestHeaders(headers); 4328 req.SetExtraRequestHeaders(headers);
4199 req.Start(); 4329 req.Start();
4200 MessageLoop::current()->Run(); 4330 MessageLoop::current()->Run();
4201 // If the net tests are being run with ChromeFrame then we need to allow for 4331 // If the net tests are being run with ChromeFrame then we need to allow for
4202 // the 'chromeframe' suffix which is added to the user agent before the 4332 // the 'chromeframe' suffix which is added to the user agent before the
4203 // closing parentheses. 4333 // closing parentheses.
4204 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); 4334 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true));
4205 } 4335 }
4206 4336
4207 } // namespace net 4337 } // namespace net
OLDNEW
« net/tools/testserver/testserver.py ('K') | « net/tools/testserver/testserver.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698