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

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

Issue 2067843003: Require a CTVerifier and CTPolicyEnforcer for TLS/QUIC sockets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Extensions Created 4 years, 6 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
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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "net/base/load_timing_info.h" 51 #include "net/base/load_timing_info.h"
52 #include "net/base/load_timing_info_test_util.h" 52 #include "net/base/load_timing_info_test_util.h"
53 #include "net/base/net_errors.h" 53 #include "net/base/net_errors.h"
54 #include "net/base/net_module.h" 54 #include "net/base/net_module.h"
55 #include "net/base/request_priority.h" 55 #include "net/base/request_priority.h"
56 #include "net/base/test_data_directory.h" 56 #include "net/base/test_data_directory.h"
57 #include "net/base/upload_bytes_element_reader.h" 57 #include "net/base/upload_bytes_element_reader.h"
58 #include "net/base/upload_data_stream.h" 58 #include "net/base/upload_data_stream.h"
59 #include "net/base/upload_file_element_reader.h" 59 #include "net/base/upload_file_element_reader.h"
60 #include "net/base/url_util.h" 60 #include "net/base/url_util.h"
61 #include "net/cert/ct_policy_enforcer.h"
61 #include "net/cert/ct_policy_status.h" 62 #include "net/cert/ct_policy_status.h"
62 #include "net/cert/ct_verifier.h" 63 #include "net/cert/ct_verifier.h"
63 #include "net/cert/ct_verify_result.h" 64 #include "net/cert/ct_verify_result.h"
64 #include "net/cert/ev_root_ca_metadata.h" 65 #include "net/cert/ev_root_ca_metadata.h"
65 #include "net/cert/mock_cert_verifier.h" 66 #include "net/cert/mock_cert_verifier.h"
66 #include "net/cert/test_root_certs.h" 67 #include "net/cert/test_root_certs.h"
67 #include "net/cert_net/nss_ocsp.h" 68 #include "net/cert_net/nss_ocsp.h"
68 #include "net/cookies/cookie_monster.h" 69 #include "net/cookies/cookie_monster.h"
69 #include "net/cookies/cookie_store_test_helpers.h" 70 #include "net/cookies/cookie_store_test_helpers.h"
70 #include "net/disk_cache/disk_cache.h" 71 #include "net/disk_cache/disk_cache.h"
(...skipping 6408 matching lines...) Expand 10 before | Expand all | Expand 10 after
6479 // Use a MockHostResolver (which by default maps all hosts to 6480 // Use a MockHostResolver (which by default maps all hosts to
6480 // 127.0.0.1) so that the request can be sent to a site on the Expect 6481 // 127.0.0.1) so that the request can be sent to a site on the Expect
6481 // CT preload list. 6482 // CT preload list.
6482 MockHostResolver host_resolver; 6483 MockHostResolver host_resolver;
6483 TestURLRequestContext context(true); 6484 TestURLRequestContext context(true);
6484 context.set_host_resolver(&host_resolver); 6485 context.set_host_resolver(&host_resolver);
6485 context.set_transport_security_state(&transport_security_state); 6486 context.set_transport_security_state(&transport_security_state);
6486 context.set_network_delegate(&network_delegate); 6487 context.set_network_delegate(&network_delegate);
6487 context.set_cert_verifier(&cert_verifier); 6488 context.set_cert_verifier(&cert_verifier);
6488 context.set_cert_transparency_verifier(&ct_verifier); 6489 context.set_cert_transparency_verifier(&ct_verifier);
6489 context.set_ct_policy_enforcer(&ct_policy_enforcer); 6490 context.set_ct_policy_enforcer(std::move(&ct_policy_enforcer));
6490 context.Init(); 6491 context.Init();
6491 6492
6492 // Now send a request to trigger the violation. 6493 // Now send a request to trigger the violation.
6493 TestDelegate d; 6494 TestDelegate d;
6494 GURL url = https_test_server.GetURL("/expect-ct-header.html"); 6495 GURL url = https_test_server.GetURL("/expect-ct-header.html");
6495 GURL::Replacements replace_host; 6496 GURL::Replacements replace_host;
6496 replace_host.SetHostStr(kExpectCTStaticHostname); 6497 replace_host.SetHostStr(kExpectCTStaticHostname);
6497 url = url.ReplaceComponents(replace_host); 6498 url = url.ReplaceComponents(replace_host);
6498 std::unique_ptr<URLRequest> violating_request( 6499 std::unique_ptr<URLRequest> violating_request(
6499 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 6500 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
(...skipping 2321 matching lines...) Expand 10 before | Expand all | Expand 10 after
8821 base::RunLoop().Run(); 8822 base::RunLoop().Run();
8822 8823
8823 EXPECT_EQ(1, d.response_started_count()); 8824 EXPECT_EQ(1, d.response_started_count());
8824 } 8825 }
8825 8826
8826 // Now create a new HttpCache with a different ssl_session_cache_shard value. 8827 // Now create a new HttpCache with a different ssl_session_cache_shard value.
8827 HttpNetworkSession::Params params; 8828 HttpNetworkSession::Params params;
8828 params.host_resolver = default_context_.host_resolver(); 8829 params.host_resolver = default_context_.host_resolver();
8829 params.cert_verifier = default_context_.cert_verifier(); 8830 params.cert_verifier = default_context_.cert_verifier();
8830 params.transport_security_state = default_context_.transport_security_state(); 8831 params.transport_security_state = default_context_.transport_security_state();
8832 params.cert_transparency_verifier =
8833 default_context_.cert_transparency_verifier();
8834 params.ct_policy_enforcer = default_context_.ct_policy_enforcer();
8831 params.proxy_service = default_context_.proxy_service(); 8835 params.proxy_service = default_context_.proxy_service();
8832 params.ssl_config_service = default_context_.ssl_config_service(); 8836 params.ssl_config_service = default_context_.ssl_config_service();
8833 params.http_auth_handler_factory = 8837 params.http_auth_handler_factory =
8834 default_context_.http_auth_handler_factory(); 8838 default_context_.http_auth_handler_factory();
8835 params.http_server_properties = default_context_.http_server_properties(); 8839 params.http_server_properties = default_context_.http_server_properties();
8836 8840
8837 HttpNetworkSession network_session(params); 8841 HttpNetworkSession network_session(params);
8838 std::unique_ptr<HttpCache> cache(new HttpCache( 8842 std::unique_ptr<HttpCache> cache(new HttpCache(
8839 &network_session, HttpCache::DefaultBackend::InMemory(0), false)); 8843 &network_session, HttpCache::DefaultBackend::InMemory(0), false));
8840 8844
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
9210 public: 9214 public:
9211 HTTPSOCSPTest() 9215 HTTPSOCSPTest()
9212 : context_(true), 9216 : context_(true),
9213 ev_test_policy_( 9217 ev_test_policy_(
9214 new ScopedTestEVPolicy(EVRootCAMetadata::GetInstance(), 9218 new ScopedTestEVPolicy(EVRootCAMetadata::GetInstance(),
9215 kOCSPTestCertFingerprint, 9219 kOCSPTestCertFingerprint,
9216 kOCSPTestCertPolicy)) { 9220 kOCSPTestCertPolicy)) {
9217 } 9221 }
9218 9222
9219 void SetUp() override { 9223 void SetUp() override {
9220 SetupContext(&context_); 9224 context_.SetCTPolicyEnforcer(
9225 base::MakeUnique<AllowAnyCertCTPolicyEnforcer>());
9226 SetupContext();
9221 context_.Init(); 9227 context_.Init();
9222 9228
9223 scoped_refptr<X509Certificate> root_cert = 9229 scoped_refptr<X509Certificate> root_cert =
9224 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); 9230 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem");
9225 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert.get()); 9231 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert.get());
9226 test_root_.reset(new ScopedTestRoot(root_cert.get())); 9232 test_root_.reset(new ScopedTestRoot(root_cert.get()));
9227 9233
9228 #if defined(USE_NSS_CERTS) 9234 #if defined(USE_NSS_CERTS)
9229 SetURLRequestContextForNSSHttpIO(&context_); 9235 SetURLRequestContextForNSSHttpIO(&context_);
9230 EnsureNSSHttpIOInit(); 9236 EnsureNSSHttpIOInit();
(...skipping 22 matching lines...) Expand all
9253 *out_cert_status = r->ssl_info().cert_status; 9259 *out_cert_status = r->ssl_info().cert_status;
9254 } 9260 }
9255 9261
9256 ~HTTPSOCSPTest() override { 9262 ~HTTPSOCSPTest() override {
9257 #if defined(USE_NSS_CERTS) 9263 #if defined(USE_NSS_CERTS)
9258 ShutdownNSSHttpIO(); 9264 ShutdownNSSHttpIO();
9259 #endif 9265 #endif
9260 } 9266 }
9261 9267
9262 protected: 9268 protected:
9269 class AllowAnyCertCTPolicyEnforcer : public CTPolicyEnforcer {
9270 public:
9271 AllowAnyCertCTPolicyEnforcer() = default;
9272 ~AllowAnyCertCTPolicyEnforcer() override = default;
9273
9274 ct::CertPolicyCompliance DoesConformToCertPolicy(
9275 X509Certificate* cert,
9276 const SCTList& verified_scts,
9277 const BoundNetLog& net_log) override {
9278 return ct::CertPolicyCompliance::CERT_POLICY_COMPLIES_VIA_SCTS;
9279 }
9280
9281 ct::EVPolicyCompliance DoesConformToCTEVPolicy(
9282 X509Certificate* cert,
9283 const ct::EVCertsWhitelist* ev_whitelist,
9284 const SCTList& verified_scts,
9285 const BoundNetLog& net_log) override {
9286 return ct::EVPolicyCompliance::EV_POLICY_COMPLIES_VIA_SCTS;
9287 }
9288 };
9263 // SetupContext configures the URLRequestContext that will be used for making 9289 // SetupContext configures the URLRequestContext that will be used for making
9264 // connetions to testserver. This can be overridden in test subclasses for 9290 // connetions to testserver. This can be overridden in test subclasses for
9265 // different behaviour. 9291 // different behaviour.
9266 virtual void SetupContext(URLRequestContext* context) { 9292 virtual void SetupContext() {
9267 context->set_ssl_config_service(new TestSSLConfigService( 9293 context_.set_ssl_config_service(new TestSSLConfigService(
9268 true /* check for EV */, true /* online revocation checking */, 9294 true /* check for EV */, true /* online revocation checking */,
9269 false /* require rev. checking for local 9295 false /* require rev. checking for local
9270 anchors */, 9296 anchors */,
9271 false /* token binding enabled */)); 9297 false /* token binding enabled */));
9272 } 9298 }
9273 9299
9274 std::unique_ptr<ScopedTestRoot> test_root_; 9300 std::unique_ptr<ScopedTestRoot> test_root_;
9275 TestURLRequestContext context_; 9301 TestURLRequestContext context_;
9276 std::unique_ptr<ScopedTestEVPolicy> ev_test_policy_; 9302 std::unique_ptr<ScopedTestEVPolicy> ev_test_policy_;
9277 }; 9303 };
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
9444 CertStatus cert_status; 9470 CertStatus cert_status;
9445 DoConnection(ssl_options, &cert_status); 9471 DoConnection(ssl_options, &cert_status);
9446 9472
9447 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); 9473 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS);
9448 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); 9474 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
9449 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); 9475 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
9450 } 9476 }
9451 9477
9452 class HTTPSHardFailTest : public HTTPSOCSPTest { 9478 class HTTPSHardFailTest : public HTTPSOCSPTest {
9453 protected: 9479 protected:
9454 void SetupContext(URLRequestContext* context) override { 9480 void SetupContext() override {
9455 context->set_ssl_config_service(new TestSSLConfigService( 9481 context_.set_ssl_config_service(new TestSSLConfigService(
9456 false /* check for EV */, false /* online revocation checking */, 9482 false /* check for EV */, false /* online revocation checking */,
9457 true /* require rev. checking for local 9483 true /* require rev. checking for local
9458 anchors */, 9484 anchors */,
9459 false /* token binding enabled */)); 9485 false /* token binding enabled */));
9460 } 9486 }
9461 }; 9487 };
9462 9488
9463 TEST_F(HTTPSHardFailTest, FailsOnOCSPInvalid) { 9489 TEST_F(HTTPSHardFailTest, FailsOnOCSPInvalid) {
9464 if (!SystemSupportsOCSP()) { 9490 if (!SystemSupportsOCSP()) {
9465 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; 9491 LOG(WARNING) << "Skipping test because system doesn't support OCSP";
(...skipping 15 matching lines...) Expand all
9481 9507
9482 EXPECT_EQ(CERT_STATUS_REVOKED, 9508 EXPECT_EQ(CERT_STATUS_REVOKED,
9483 cert_status & CERT_STATUS_REVOKED); 9509 cert_status & CERT_STATUS_REVOKED);
9484 9510
9485 // Without a positive OCSP response, we shouldn't show the EV status. 9511 // Without a positive OCSP response, we shouldn't show the EV status.
9486 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); 9512 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
9487 } 9513 }
9488 9514
9489 class HTTPSEVCRLSetTest : public HTTPSOCSPTest { 9515 class HTTPSEVCRLSetTest : public HTTPSOCSPTest {
9490 protected: 9516 protected:
9491 void SetupContext(URLRequestContext* context) override { 9517 void SetupContext() override {
9492 context->set_ssl_config_service(new TestSSLConfigService( 9518 context_.set_ssl_config_service(new TestSSLConfigService(
9493 true /* check for EV */, false /* online revocation checking */, 9519 true /* check for EV */, false /* online revocation checking */,
9494 false /* require rev. checking for local 9520 false /* require rev. checking for local
9495 anchors */, 9521 anchors */,
9496 false /* token binding enabled */)); 9522 false /* token binding enabled */));
9497 } 9523 }
9498 }; 9524 };
9499 9525
9500 TEST_F(HTTPSEVCRLSetTest, MissingCRLSetAndInvalidOCSP) { 9526 TEST_F(HTTPSEVCRLSetTest, MissingCRLSetAndInvalidOCSP) {
9501 if (!SystemSupportsOCSP()) { 9527 if (!SystemSupportsOCSP()) {
9502 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; 9528 LOG(WARNING) << "Skipping test because system doesn't support OCSP";
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
9666 DoConnection(ssl_options, &cert_status); 9692 DoConnection(ssl_options, &cert_status);
9667 9693
9668 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS); 9694 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS);
9669 9695
9670 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); 9696 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
9671 EXPECT_FALSE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); 9697 EXPECT_FALSE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
9672 } 9698 }
9673 9699
9674 class HTTPSCRLSetTest : public HTTPSOCSPTest { 9700 class HTTPSCRLSetTest : public HTTPSOCSPTest {
9675 protected: 9701 protected:
9676 void SetupContext(URLRequestContext* context) override { 9702 void SetupContext() override {
9677 context->set_ssl_config_service(new TestSSLConfigService( 9703 context_.set_ssl_config_service(new TestSSLConfigService(
9678 false /* check for EV */, false /* online revocation checking */, 9704 false /* check for EV */, false /* online revocation checking */,
9679 false /* require rev. checking for local 9705 false /* require rev. checking for local
9680 anchors */, 9706 anchors */,
9681 false /* token binding enabled */)); 9707 false /* token binding enabled */));
9682 } 9708 }
9683 }; 9709 };
9684 9710
9685 TEST_F(HTTPSCRLSetTest, ExpiredCRLSet) { 9711 TEST_F(HTTPSCRLSetTest, ExpiredCRLSet) {
9686 SpawnedTestServer::SSLOptions ssl_options( 9712 SpawnedTestServer::SSLOptions ssl_options(
9687 SpawnedTestServer::SSLOptions::CERT_AUTO); 9713 SpawnedTestServer::SSLOptions::CERT_AUTO);
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
10099 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10125 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10100 10126
10101 req->Start(); 10127 req->Start();
10102 req->Cancel(); 10128 req->Cancel();
10103 base::RunLoop().RunUntilIdle(); 10129 base::RunLoop().RunUntilIdle();
10104 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 10130 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
10105 EXPECT_EQ(0, d.received_redirect_count()); 10131 EXPECT_EQ(0, d.received_redirect_count());
10106 } 10132 }
10107 10133
10108 } // namespace net 10134 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698