Chromium Code Reviews| 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 9601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9612 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 9612 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 9613 violating_request->Start(); | 9613 violating_request->Start(); |
| 9614 base::RunLoop().Run(); | 9614 base::RunLoop().Run(); |
| 9615 | 9615 |
| 9616 // Confirm a report was sent. | 9616 // Confirm a report was sent. |
| 9617 EXPECT_FALSE(mock_report_sender.latest_report().empty()); | 9617 EXPECT_FALSE(mock_report_sender.latest_report().empty()); |
| 9618 EXPECT_EQ(GURL(kExpectStapleReportURI), | 9618 EXPECT_EQ(GURL(kExpectStapleReportURI), |
| 9619 mock_report_sender.latest_report_uri()); | 9619 mock_report_sender.latest_report_uri()); |
| 9620 } | 9620 } |
| 9621 | 9621 |
| 9622 // Tests that Expect-Staple reports are sent for connections even when there is | |
| 9623 // a certificate error on the connection. | |
| 9624 TEST_F(HTTPSOCSPTest, ExpectStapleReportSentOnMissingWithCertError) { | |
| 9625 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | |
| 9626 https_test_server.SetSSLConfig( | |
| 9627 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); | |
| 9628 https_test_server.ServeFilesFromSourceDirectory( | |
| 9629 base::FilePath(kTestFilePath)); | |
| 9630 ASSERT_TRUE(https_test_server.Start()); | |
| 9631 | |
| 9632 // Set up a MockCertVerifier to accept the certificate that the server sends, | |
| 9633 // but not provide any OCSP information. | |
|
Ryan Sleevi
2016/12/21 01:35:29
The MockCertVerifier doesn't accept this certifica
estark
2016/12/21 17:53:12
Done.
| |
| 9634 scoped_refptr<X509Certificate> cert = https_test_server.GetCertificate(); | |
| 9635 ASSERT_TRUE(cert); | |
| 9636 MockCertVerifier cert_verifier; | |
| 9637 CertVerifyResult verify_result; | |
| 9638 // Simulate a certificate verification error. | |
| 9639 verify_result.cert_status = CERT_STATUS_DATE_INVALID; | |
| 9640 verify_result.verified_cert = cert; | |
| 9641 verify_result.is_issued_by_known_root = true; | |
| 9642 verify_result.ocsp_result.response_status = OCSPVerifyResult::MISSING; | |
|
Ryan Sleevi
2016/12/21 01:35:29
Is this really an accurate simulation? Your descri
estark
2016/12/21 17:53:12
This test is for the first connection that hits a
| |
| 9643 cert_verifier.AddResultForCert(cert.get(), verify_result, | |
| 9644 ERR_CERT_DATE_INVALID); | |
| 9645 | |
| 9646 // Catch the Expect-Staple report. | |
|
Ryan Sleevi
2016/12/21 01:35:29
This comment reads a little weird, because this co
estark
2016/12/21 17:53:12
Changed to "Set up a mock report sender to..."
| |
| 9647 TransportSecurityState transport_security_state; | |
| 9648 MockCertificateReportSender mock_report_sender; | |
| 9649 transport_security_state.SetReportSender(&mock_report_sender); | |
| 9650 | |
| 9651 // Use a MockHostResolver (which by default maps all hosts to 127.0.0.1) so | |
| 9652 // that the request can be sent to a site on the Expect-Staple preload list. | |
| 9653 MockHostResolver host_resolver; | |
|
Ryan Sleevi
2016/12/21 01:35:29
Logically, it seems like there should be a newline
estark
2016/12/21 17:53:12
Done.
| |
| 9654 TestNetworkDelegate network_delegate; | |
| 9655 TestURLRequestContext context(true); | |
| 9656 context.set_host_resolver(&host_resolver); | |
| 9657 context.set_transport_security_state(&transport_security_state); | |
| 9658 context.set_network_delegate(&network_delegate); | |
| 9659 context.set_cert_verifier(&cert_verifier); | |
| 9660 context.Init(); | |
| 9661 | |
| 9662 // Now send a request to trigger the violation. | |
|
Ryan Sleevi
2016/12/21 01:35:29
What violation? What is it violating? That's the f
estark
2016/12/21 17:53:12
Done.
| |
| 9663 TestDelegate d; | |
| 9664 GURL url = https_test_server.GetURL("/"); | |
| 9665 GURL::Replacements replace_host; | |
| 9666 replace_host.SetHostStr(kExpectStapleStaticHostname); | |
| 9667 url = url.ReplaceComponents(replace_host); | |
| 9668 std::unique_ptr<URLRequest> violating_request( | |
| 9669 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | |
| 9670 violating_request->Start(); | |
| 9671 base::RunLoop().Run(); | |
| 9672 | |
| 9673 // Confirm a report was sent. | |
| 9674 EXPECT_FALSE(mock_report_sender.latest_report().empty()); | |
| 9675 EXPECT_EQ(GURL(kExpectStapleReportURI), | |
| 9676 mock_report_sender.latest_report_uri()); | |
| 9677 } | |
| 9678 | |
| 9622 TEST_F(HTTPSOCSPTest, ExpectStapleReportNotSentOnValid) { | 9679 TEST_F(HTTPSOCSPTest, ExpectStapleReportNotSentOnValid) { |
| 9623 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 9680 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 9624 https_test_server.SetSSLConfig( | 9681 https_test_server.SetSSLConfig( |
| 9625 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); | 9682 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 9626 https_test_server.ServeFilesFromSourceDirectory( | 9683 https_test_server.ServeFilesFromSourceDirectory( |
| 9627 base::FilePath(kTestFilePath)); | 9684 base::FilePath(kTestFilePath)); |
| 9628 ASSERT_TRUE(https_test_server.Start()); | 9685 ASSERT_TRUE(https_test_server.Start()); |
| 9629 | 9686 |
| 9630 // Set up a MockCertVerifier to accept the certificate that the server sends, | 9687 // Set up a MockCertVerifier to accept the certificate that the server sends, |
| 9631 // and provide GOOD revocation status. | 9688 // and provide GOOD revocation status. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9664 std::unique_ptr<URLRequest> ok_request( | 9721 std::unique_ptr<URLRequest> ok_request( |
| 9665 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 9722 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 9666 ok_request->Start(); | 9723 ok_request->Start(); |
| 9667 base::RunLoop().Run(); | 9724 base::RunLoop().Run(); |
| 9668 | 9725 |
| 9669 // Check that no report was sent. | 9726 // Check that no report was sent. |
| 9670 EXPECT_TRUE(mock_report_sender.latest_report().empty()); | 9727 EXPECT_TRUE(mock_report_sender.latest_report().empty()); |
| 9671 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); | 9728 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); |
| 9672 } | 9729 } |
| 9673 | 9730 |
| 9731 // Tests that an Expect-Staple report is not sent when OCSP details are not | |
| 9732 // checked on the connection. | |
| 9733 TEST_F(HTTPSOCSPTest, ExpectStapleReportNotSentOnUnknown) { | |
| 9734 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | |
| 9735 https_test_server.SetSSLConfig( | |
| 9736 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); | |
| 9737 https_test_server.ServeFilesFromSourceDirectory( | |
| 9738 base::FilePath(kTestFilePath)); | |
| 9739 ASSERT_TRUE(https_test_server.Start()); | |
| 9740 | |
| 9741 // Set up a MockCertVerifier to accept the certificate that the server sends, | |
| 9742 // and provide UNKNOWN response status. | |
| 9743 scoped_refptr<X509Certificate> cert = https_test_server.GetCertificate(); | |
| 9744 ASSERT_TRUE(cert); | |
| 9745 MockCertVerifier cert_verifier; | |
| 9746 CertVerifyResult verify_result; | |
| 9747 verify_result.verified_cert = cert; | |
| 9748 verify_result.is_issued_by_known_root = true; | |
| 9749 verify_result.ocsp_result.response_status = OCSPVerifyResult::UNKNOWN; | |
| 9750 cert_verifier.AddResultForCert(cert.get(), verify_result, OK); | |
| 9751 | |
| 9752 // Catch the Expect-Staple report. | |
| 9753 TransportSecurityState transport_security_state; | |
| 9754 MockCertificateReportSender mock_report_sender; | |
| 9755 transport_security_state.SetReportSender(&mock_report_sender); | |
| 9756 | |
| 9757 // Use a MockHostResolver (which by default maps all hosts to 127.0.0.1) so | |
| 9758 // that the request can be sent to a site on the Expect-Staple preload list. | |
| 9759 MockHostResolver host_resolver; | |
| 9760 TestNetworkDelegate network_delegate; | |
| 9761 TestURLRequestContext context(true); | |
| 9762 context.set_host_resolver(&host_resolver); | |
| 9763 context.set_transport_security_state(&transport_security_state); | |
| 9764 context.set_network_delegate(&network_delegate); | |
| 9765 context.set_cert_verifier(&cert_verifier); | |
| 9766 context.Init(); | |
| 9767 | |
| 9768 // This request should not not trigger an Expect-Staple violation. | |
| 9769 TestDelegate d; | |
| 9770 GURL url = https_test_server.GetURL("/"); | |
| 9771 GURL::Replacements replace_host; | |
| 9772 replace_host.SetHostStr(kExpectStapleStaticHostname); | |
| 9773 url = url.ReplaceComponents(replace_host); | |
| 9774 std::unique_ptr<URLRequest> ok_request( | |
| 9775 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | |
| 9776 ok_request->Start(); | |
| 9777 base::RunLoop().Run(); | |
| 9778 | |
| 9779 // Check that no report was sent. | |
| 9780 EXPECT_TRUE(mock_report_sender.latest_report().empty()); | |
| 9781 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); | |
| 9782 } | |
| 9783 | |
| 9674 static const struct OCSPVerifyTestData { | 9784 static const struct OCSPVerifyTestData { |
| 9675 std::vector<SpawnedTestServer::SSLOptions::OCSPSingleResponse> ocsp_responses; | 9785 std::vector<SpawnedTestServer::SSLOptions::OCSPSingleResponse> ocsp_responses; |
| 9676 SpawnedTestServer::SSLOptions::OCSPProduced ocsp_produced; | 9786 SpawnedTestServer::SSLOptions::OCSPProduced ocsp_produced; |
| 9677 OCSPVerifyResult::ResponseStatus response_status; | 9787 OCSPVerifyResult::ResponseStatus response_status; |
| 9678 bool has_revocation_status; | 9788 bool has_revocation_status; |
| 9679 OCSPRevocationStatus cert_status; | 9789 OCSPRevocationStatus cert_status; |
| 9680 } kOCSPVerifyData[] = { | 9790 } kOCSPVerifyData[] = { |
| 9681 | 9791 |
| 9682 {{{SpawnedTestServer::SSLOptions::OCSP_OK, | 9792 {{{SpawnedTestServer::SSLOptions::OCSP_OK, |
| 9683 SpawnedTestServer::SSLOptions::OCSP_DATE_VALID}}, | 9793 SpawnedTestServer::SSLOptions::OCSP_DATE_VALID}}, |
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10634 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 10744 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 10635 | 10745 |
| 10636 req->Start(); | 10746 req->Start(); |
| 10637 req->Cancel(); | 10747 req->Cancel(); |
| 10638 base::RunLoop().RunUntilIdle(); | 10748 base::RunLoop().RunUntilIdle(); |
| 10639 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 10749 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 10640 EXPECT_EQ(0, d.received_redirect_count()); | 10750 EXPECT_EQ(0, d.received_redirect_count()); |
| 10641 } | 10751 } |
| 10642 | 10752 |
| 10643 } // namespace net | 10753 } // namespace net |
| OLD | NEW |