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

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

Issue 2176183003: Revert of Enable Expect-Staple in SSLClientSocket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ocsp-reporting
Patch Set: Created 4 years, 4 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
« no previous file with comments | « net/socket/ssl_client_socket_impl.cc ('k') | no next file » | 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) 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 "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 5942 matching lines...) Expand 10 before | Expand all | Expand 10 after
5953 base::RunLoop().Run(); 5953 base::RunLoop().Run();
5954 TransportSecurityState* security_state = 5954 TransportSecurityState* security_state =
5955 default_context_.transport_security_state(); 5955 default_context_.transport_security_state();
5956 TransportSecurityState::STSState sts_state; 5956 TransportSecurityState::STSState sts_state;
5957 EXPECT_FALSE( 5957 EXPECT_FALSE(
5958 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); 5958 security_state->GetDynamicSTSState(test_server_hostname, &sts_state));
5959 } 5959 }
5960 5960
5961 namespace { 5961 namespace {
5962 const char kExpectCTStaticHostname[] = "preloaded-expect-ct.badssl.com"; 5962 const char kExpectCTStaticHostname[] = "preloaded-expect-ct.badssl.com";
5963 const char kExpectStapleStaticHostname[] = "preloaded-expect-staple.badssl.com";
5964 const char kExpectStapleReportURI[] = "https://report.badssl.com/expect-staple";
5965 const char kHPKPReportUri[] = "https://hpkp-report.test"; 5963 const char kHPKPReportUri[] = "https://hpkp-report.test";
5966 } // namespace 5964 } // namespace
5967 5965
5968 // Tests that enabling HPKP on a domain does not affect the HSTS 5966 // Tests that enabling HPKP on a domain does not affect the HSTS
5969 // validity/expiration. 5967 // validity/expiration.
5970 TEST_F(URLRequestTestHTTP, ProcessPKP) { 5968 TEST_F(URLRequestTestHTTP, ProcessPKP) {
5971 GURL report_uri(kHPKPReportUri); 5969 GURL report_uri(kHPKPReportUri);
5972 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); 5970 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS);
5973 https_test_server.SetSSLConfig( 5971 https_test_server.SetSSLConfig(
5974 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); 5972 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN);
(...skipping 3257 matching lines...) Expand 10 before | Expand all | Expand 10 after
9232 ssl_options.ocsp_server_unavailable = true; 9230 ssl_options.ocsp_server_unavailable = true;
9233 9231
9234 CertStatus cert_status; 9232 CertStatus cert_status;
9235 DoConnection(ssl_options, &cert_status); 9233 DoConnection(ssl_options, &cert_status);
9236 9234
9237 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); 9235 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS);
9238 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); 9236 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
9239 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); 9237 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
9240 } 9238 }
9241 9239
9242 TEST_F(HTTPSOCSPTest, ExpectStapleReportSentOnMissing) {
9243 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS);
9244 https_test_server.SetSSLConfig(
9245 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN);
9246 https_test_server.ServeFilesFromSourceDirectory(
9247 base::FilePath(kTestFilePath));
9248 ASSERT_TRUE(https_test_server.Start());
9249
9250 // Set up a MockCertVerifier to accept the certificate that the server sends,
9251 // but not provide any OCSP information.
9252 scoped_refptr<X509Certificate> cert = https_test_server.GetCertificate();
9253 ASSERT_TRUE(cert);
9254 MockCertVerifier cert_verifier;
9255 CertVerifyResult verify_result;
9256 verify_result.verified_cert = cert;
9257 verify_result.is_issued_by_known_root = true;
9258 verify_result.ocsp_result.response_status = OCSPVerifyResult::MISSING;
9259 cert_verifier.AddResultForCert(cert.get(), verify_result, OK);
9260
9261 // Catch the Expect-Staple report.
9262 TransportSecurityState transport_security_state;
9263 MockCertificateReportSender mock_report_sender;
9264 transport_security_state.SetReportSender(&mock_report_sender);
9265
9266 // Use a MockHostResolver (which by default maps all hosts to 127.0.0.1) so
9267 // that the request can be sent to a site on the Expect-Staple preload list.
9268 MockHostResolver host_resolver;
9269 TestNetworkDelegate network_delegate;
9270 TestURLRequestContext context(true);
9271 context.set_host_resolver(&host_resolver);
9272 context.set_transport_security_state(&transport_security_state);
9273 context.set_network_delegate(&network_delegate);
9274 context.set_cert_verifier(&cert_verifier);
9275 context.Init();
9276
9277 // Now send a request to trigger the violation.
9278 TestDelegate d;
9279 GURL url = https_test_server.GetURL("/");
9280 GURL::Replacements replace_host;
9281 replace_host.SetHostStr(kExpectStapleStaticHostname);
9282 url = url.ReplaceComponents(replace_host);
9283 std::unique_ptr<URLRequest> violating_request(
9284 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
9285 violating_request->Start();
9286 base::RunLoop().Run();
9287
9288 // Confirm a report was sent.
9289 EXPECT_FALSE(mock_report_sender.latest_report().empty());
9290 EXPECT_EQ(GURL(kExpectStapleReportURI),
9291 mock_report_sender.latest_report_uri());
9292 }
9293
9294 TEST_F(HTTPSOCSPTest, ExpectStapleReportNotSentOnValid) {
9295 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS);
9296 https_test_server.SetSSLConfig(
9297 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN);
9298 https_test_server.ServeFilesFromSourceDirectory(
9299 base::FilePath(kTestFilePath));
9300 ASSERT_TRUE(https_test_server.Start());
9301
9302 // Set up a MockCertVerifier to accept the certificate that the server sends,
9303 // and provide GOOD revocation status.
9304 scoped_refptr<X509Certificate> cert = https_test_server.GetCertificate();
9305 ASSERT_TRUE(cert);
9306 MockCertVerifier cert_verifier;
9307 CertVerifyResult verify_result;
9308 verify_result.verified_cert = cert;
9309 verify_result.is_issued_by_known_root = true;
9310 verify_result.ocsp_result.response_status = OCSPVerifyResult::PROVIDED;
9311 verify_result.ocsp_result.revocation_status = OCSPRevocationStatus::GOOD;
9312 cert_verifier.AddResultForCert(cert.get(), verify_result, OK);
9313
9314 // Catch the Expect-Staple report.
9315 TransportSecurityState transport_security_state;
9316 MockCertificateReportSender mock_report_sender;
9317 transport_security_state.SetReportSender(&mock_report_sender);
9318
9319 // Use a MockHostResolver (which by default maps all hosts to 127.0.0.1) so
9320 // that the request can be sent to a site on the Expect-Staple preload list.
9321 MockHostResolver host_resolver;
9322 TestNetworkDelegate network_delegate;
9323 TestURLRequestContext context(true);
9324 context.set_host_resolver(&host_resolver);
9325 context.set_transport_security_state(&transport_security_state);
9326 context.set_network_delegate(&network_delegate);
9327 context.set_cert_verifier(&cert_verifier);
9328 context.Init();
9329
9330 // This request should not not trigger an Expect-Staple violation.
9331 TestDelegate d;
9332 GURL url = https_test_server.GetURL("/");
9333 GURL::Replacements replace_host;
9334 replace_host.SetHostStr(kExpectStapleStaticHostname);
9335 url = url.ReplaceComponents(replace_host);
9336 std::unique_ptr<URLRequest> ok_request(
9337 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
9338 ok_request->Start();
9339 base::RunLoop().Run();
9340
9341 // Check that no report was sent.
9342 EXPECT_TRUE(mock_report_sender.latest_report().empty());
9343 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri());
9344 }
9345
9346 static const struct OCSPVerifyTestData { 9240 static const struct OCSPVerifyTestData {
9347 std::vector<SpawnedTestServer::SSLOptions::OCSPSingleResponse> ocsp_responses; 9241 std::vector<SpawnedTestServer::SSLOptions::OCSPSingleResponse> ocsp_responses;
9348 SpawnedTestServer::SSLOptions::OCSPProduced ocsp_produced; 9242 SpawnedTestServer::SSLOptions::OCSPProduced ocsp_produced;
9349 OCSPVerifyResult::ResponseStatus response_status; 9243 OCSPVerifyResult::ResponseStatus response_status;
9350 bool has_revocation_status; 9244 bool has_revocation_status;
9351 OCSPRevocationStatus cert_status; 9245 OCSPRevocationStatus cert_status;
9352 } kOCSPVerifyData[] = { 9246 } kOCSPVerifyData[] = {
9353 9247
9354 {{{SpawnedTestServer::SSLOptions::OCSP_OK, 9248 {{{SpawnedTestServer::SSLOptions::OCSP_OK,
9355 SpawnedTestServer::SSLOptions::OCSP_DATE_VALID}}, 9249 SpawnedTestServer::SSLOptions::OCSP_DATE_VALID}},
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
10254 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10148 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10255 10149
10256 req->Start(); 10150 req->Start();
10257 req->Cancel(); 10151 req->Cancel();
10258 base::RunLoop().RunUntilIdle(); 10152 base::RunLoop().RunUntilIdle();
10259 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 10153 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
10260 EXPECT_EQ(0, d.received_redirect_count()); 10154 EXPECT_EQ(0, d.received_redirect_count());
10261 } 10155 }
10262 10156
10263 } // namespace net 10157 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698