| 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 <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 Loading... |
| 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"; |
| 5963 const char kHPKPReportUri[] = "https://hpkp-report.test"; | 5965 const char kHPKPReportUri[] = "https://hpkp-report.test"; |
| 5964 } // namespace | 5966 } // namespace |
| 5965 | 5967 |
| 5966 // Tests that enabling HPKP on a domain does not affect the HSTS | 5968 // Tests that enabling HPKP on a domain does not affect the HSTS |
| 5967 // validity/expiration. | 5969 // validity/expiration. |
| 5968 TEST_F(URLRequestTestHTTP, ProcessPKP) { | 5970 TEST_F(URLRequestTestHTTP, ProcessPKP) { |
| 5969 GURL report_uri(kHPKPReportUri); | 5971 GURL report_uri(kHPKPReportUri); |
| 5970 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 5972 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5971 https_test_server.SetSSLConfig( | 5973 https_test_server.SetSSLConfig( |
| 5972 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); | 5974 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| (...skipping 3257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9230 ssl_options.ocsp_server_unavailable = true; | 9232 ssl_options.ocsp_server_unavailable = true; |
| 9231 | 9233 |
| 9232 CertStatus cert_status; | 9234 CertStatus cert_status; |
| 9233 DoConnection(ssl_options, &cert_status); | 9235 DoConnection(ssl_options, &cert_status); |
| 9234 | 9236 |
| 9235 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); | 9237 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); |
| 9236 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); | 9238 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); |
| 9237 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); | 9239 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); |
| 9238 } | 9240 } |
| 9239 | 9241 |
| 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 |
| 9240 static const struct OCSPVerifyTestData { | 9346 static const struct OCSPVerifyTestData { |
| 9241 std::vector<SpawnedTestServer::SSLOptions::OCSPSingleResponse> ocsp_responses; | 9347 std::vector<SpawnedTestServer::SSLOptions::OCSPSingleResponse> ocsp_responses; |
| 9242 SpawnedTestServer::SSLOptions::OCSPProduced ocsp_produced; | 9348 SpawnedTestServer::SSLOptions::OCSPProduced ocsp_produced; |
| 9243 OCSPVerifyResult::ResponseStatus response_status; | 9349 OCSPVerifyResult::ResponseStatus response_status; |
| 9244 bool has_revocation_status; | 9350 bool has_revocation_status; |
| 9245 OCSPRevocationStatus cert_status; | 9351 OCSPRevocationStatus cert_status; |
| 9246 } kOCSPVerifyData[] = { | 9352 } kOCSPVerifyData[] = { |
| 9247 | 9353 |
| 9248 {{{SpawnedTestServer::SSLOptions::OCSP_OK, | 9354 {{{SpawnedTestServer::SSLOptions::OCSP_OK, |
| 9249 SpawnedTestServer::SSLOptions::OCSP_DATE_VALID}}, | 9355 SpawnedTestServer::SSLOptions::OCSP_DATE_VALID}}, |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10148 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 10254 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 10149 | 10255 |
| 10150 req->Start(); | 10256 req->Start(); |
| 10151 req->Cancel(); | 10257 req->Cancel(); |
| 10152 base::RunLoop().RunUntilIdle(); | 10258 base::RunLoop().RunUntilIdle(); |
| 10153 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 10259 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 10154 EXPECT_EQ(0, d.received_redirect_count()); | 10260 EXPECT_EQ(0, d.received_redirect_count()); |
| 10155 } | 10261 } |
| 10156 | 10262 |
| 10157 } // namespace net | 10263 } // namespace net |
| OLD | NEW |