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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 4024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4035 // Test class that mimics a URL request with a certificate whose SPKI hash is in | 4035 // Test class that mimics a URL request with a certificate whose SPKI hash is in |
| 4036 // ssl_error_assistant.asciipb resource. A better way of testing the SPKI hashes | 4036 // ssl_error_assistant.asciipb resource. A better way of testing the SPKI hashes |
| 4037 // inside the resource bundle would be to serve the actual certificate from the | 4037 // inside the resource bundle would be to serve the actual certificate from the |
| 4038 // embedded test server, but the test server can only serve a limited number of | 4038 // embedded test server, but the test server can only serve a limited number of |
| 4039 // predefined certificates. | 4039 // predefined certificates. |
| 4040 class SSLUICaptivePortalListResourceBundleTest | 4040 class SSLUICaptivePortalListResourceBundleTest |
| 4041 : public CertVerifierBrowserTest { | 4041 : public CertVerifierBrowserTest { |
| 4042 public: | 4042 public: |
| 4043 SSLUICaptivePortalListResourceBundleTest() | 4043 SSLUICaptivePortalListResourceBundleTest() |
| 4044 : CertVerifierBrowserTest(), | 4044 : CertVerifierBrowserTest(), |
| 4045 https_server_(net::EmbeddedTestServer::TYPE_HTTPS), | 4045 https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { |
| 4046 https_server_mismatched_(net::EmbeddedTestServer::TYPE_HTTPS) { | |
| 4047 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); | 4046 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); |
| 4048 | |
| 4049 https_server_mismatched_.SetSSLConfig( | |
| 4050 net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | |
| 4051 https_server_mismatched_.AddDefaultHandlers(base::FilePath(kDocRoot)); | |
| 4052 } | 4047 } |
| 4053 | 4048 |
| 4054 void SetUp() override { | 4049 void SetUp() override { |
| 4055 CertVerifierBrowserTest::SetUp(); | 4050 CertVerifierBrowserTest::SetUp(); |
| 4056 SSLErrorHandler::ResetConfigForTesting(); | 4051 SSLErrorHandler::ResetConfigForTesting(); |
| 4057 SetUpCertVerifier(0, net::OK, std::string()); | 4052 SetUpCertVerifier(0, net::OK, std::string()); |
| 4058 } | 4053 } |
| 4059 | 4054 |
| 4060 void TearDown() override { | 4055 void TearDown() override { |
| 4061 SSLErrorHandler::ResetConfigForTesting(); | 4056 SSLErrorHandler::ResetConfigForTesting(); |
| 4062 CertVerifierBrowserTest::TearDown(); | 4057 CertVerifierBrowserTest::TearDown(); |
| 4063 } | 4058 } |
| 4064 | 4059 |
| 4065 protected: | 4060 protected: |
| 4061 // Checks that a captive portal interstitial isn't displayed, even though the | |
| 4062 // server's certificate is marked as a captive portal certificate. | |
| 4063 void TestNoCaptivePortalInterstitial(net::CertStatus cert_status, | |
| 4064 int net_error) { | |
| 4065 ASSERT_TRUE(https_server()->Start()); | |
| 4066 base::HistogramTester histograms; | |
| 4067 | |
| 4068 // Mark the server's cert as a captive portal cert. | |
| 4069 SetUpCertVerifier(cert_status, net_error, kCaptivePortalSPKI); | |
| 4070 | |
| 4071 // Navigate to an unsafe page on the server. CaptivePortalCertificateList | |
| 4072 // feature is enabled but either the error is not name-mismatch, or it's not | |
| 4073 // the only error, so a generic SSL interstitial should be displayed. | |
| 4074 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 4075 SSLInterstitialTimerObserver interstitial_timer_observer(tab); | |
| 4076 ui_test_utils::NavigateToURL(browser(), https_server()->GetURL("/")); | |
| 4077 content::WaitForInterstitialAttach(tab); | |
| 4078 | |
| 4079 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); | |
| 4080 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | |
| 4081 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 4082 EXPECT_TRUE(interstitial_timer_observer.timer_started()); | |
| 4083 | |
| 4084 // Check that the histogram for the captive portal cert was recorded. | |
| 4085 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4086 2); | |
| 4087 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4088 SSLErrorHandler::HANDLE_ALL, 1); | |
| 4089 histograms.ExpectBucketCount( | |
| 4090 SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4091 SSLErrorHandler::SHOW_SSL_INTERSTITIAL_OVERRIDABLE, 1); | |
| 4092 } | |
| 4093 | |
| 4066 void SetUpCertVerifier(net::CertStatus cert_status, | 4094 void SetUpCertVerifier(net::CertStatus cert_status, |
| 4067 int net_result, | 4095 int net_result, |
| 4068 const std::string& spki_hash) { | 4096 const std::string& spki_hash) { |
| 4069 scoped_refptr<net::X509Certificate> cert(https_server_.GetCertificate()); | 4097 scoped_refptr<net::X509Certificate> cert(https_server_.GetCertificate()); |
| 4070 net::CertVerifyResult verify_result; | 4098 net::CertVerifyResult verify_result; |
| 4071 verify_result.is_issued_by_known_root = | 4099 verify_result.is_issued_by_known_root = |
| 4072 (net_result != net::ERR_CERT_AUTHORITY_INVALID); | 4100 (net_result != net::ERR_CERT_AUTHORITY_INVALID); |
| 4073 verify_result.verified_cert = cert; | 4101 verify_result.verified_cert = cert; |
| 4074 verify_result.cert_status = cert_status; | 4102 verify_result.cert_status = cert_status; |
| 4075 | 4103 |
| 4076 // Set the SPKI hash to captive-portal.badssl.com leaf certificate. | 4104 // Set the SPKI hash to captive-portal.badssl.com leaf certificate. |
| 4077 if (!spki_hash.empty()) { | 4105 if (!spki_hash.empty()) { |
| 4078 net::HashValue hash; | 4106 net::HashValue hash; |
| 4079 ASSERT_TRUE(hash.FromString(spki_hash)); | 4107 ASSERT_TRUE(hash.FromString(spki_hash)); |
| 4080 verify_result.public_key_hashes.push_back(hash); | 4108 verify_result.public_key_hashes.push_back(hash); |
| 4081 } | 4109 } |
| 4082 mock_cert_verifier()->AddResultForCert(cert, verify_result, net_result); | 4110 mock_cert_verifier()->AddResultForCert(cert, verify_result, net_result); |
| 4083 } | 4111 } |
| 4084 | 4112 |
| 4085 net::EmbeddedTestServer* https_server() { return &https_server_; } | 4113 net::EmbeddedTestServer* https_server() { return &https_server_; } |
| 4086 net::EmbeddedTestServer* https_server_mismatched() { | |
| 4087 return &https_server_mismatched_; | |
| 4088 } | |
| 4089 | 4114 |
| 4090 private: | 4115 private: |
| 4091 net::EmbeddedTestServer https_server_; | 4116 net::EmbeddedTestServer https_server_; |
| 4092 net::EmbeddedTestServer https_server_mismatched_; | |
| 4093 }; | 4117 }; |
| 4094 | 4118 |
| 4095 } // namespace | 4119 } // namespace |
| 4096 | 4120 |
| 4097 // Same as CaptivePortalCertificateList_Enabled_FromProto, but this time the | 4121 // Same as CaptivePortalCertificateList_Enabled_FromProto, but this time the |
| 4098 // cert's SPKI hash is listed in ssl_error_assistant.asciipb. | 4122 // cert's SPKI hash is listed in ssl_error_assistant.asciipb. |
| 4099 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListResourceBundleTest, Enabled) { | 4123 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListResourceBundleTest, Enabled) { |
| 4100 base::test::ScopedFeatureList scoped_feature_list; | 4124 base::test::ScopedFeatureList scoped_feature_list; |
| 4101 scoped_feature_list.InitFromCommandLine( | 4125 scoped_feature_list.InitFromCommandLine( |
| 4102 "CaptivePortalCertificateList" /* enabled */, | 4126 "CaptivePortalCertificateList" /* enabled */, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4253 } | 4277 } |
| 4254 | 4278 |
| 4255 // Same as SSLUICaptivePortalNameMismatchTest, but this time the error is | 4279 // Same as SSLUICaptivePortalNameMismatchTest, but this time the error is |
| 4256 // authority-invalid. Captive portal interstitial should not be shown. | 4280 // authority-invalid. Captive portal interstitial should not be shown. |
| 4257 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListResourceBundleTest, | 4281 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListResourceBundleTest, |
| 4258 Enabled_AuthorityInvalid) { | 4282 Enabled_AuthorityInvalid) { |
| 4259 base::test::ScopedFeatureList scoped_feature_list; | 4283 base::test::ScopedFeatureList scoped_feature_list; |
| 4260 scoped_feature_list.InitFromCommandLine( | 4284 scoped_feature_list.InitFromCommandLine( |
| 4261 "CaptivePortalCertificateList" /* enabled */, | 4285 "CaptivePortalCertificateList" /* enabled */, |
| 4262 std::string() /* disabled */); | 4286 std::string() /* disabled */); |
| 4263 ASSERT_TRUE(https_server()->Start()); | |
| 4264 base::HistogramTester histograms; | |
| 4265 | 4287 |
| 4266 // Mark the server's cert as a captive portal cert, but with an | 4288 TestNoCaptivePortalInterstitial(net::CERT_STATUS_AUTHORITY_INVALID, |
| 4267 // authority-invalid error. | 4289 net::ERR_CERT_AUTHORITY_INVALID); |
| 4268 SetUpCertVerifier(net::CERT_STATUS_AUTHORITY_INVALID, | 4290 } |
| 4269 net::ERR_CERT_AUTHORITY_INVALID, kCaptivePortalSPKI); | |
| 4270 | 4291 |
| 4271 // Navigate to an unsafe page on the server. CaptivePortalCertificateList | 4292 // Same as SSLUICaptivePortalListResourceBundleTest.Enabled_AuthorityInvalid, |
| 4272 // feature is enabled but the error is not a name mismatch, so a generic SSL | 4293 // but this time there are two errors (name mismatch + weak key). Captive portal |
| 4273 // interstitial should be displayed. | 4294 // interstitial should not be shown when name mismatch isn't the only error. |
| 4274 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 4295 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListResourceBundleTest, |
| 4275 SSLInterstitialTimerObserver interstitial_timer_observer(tab); | 4296 Enabled_NameMismatchAndWeakKey) { |
| 4276 ui_test_utils::NavigateToURL(browser(), https_server()->GetURL("/")); | 4297 base::test::ScopedFeatureList scoped_feature_list; |
| 4277 content::WaitForInterstitialAttach(tab); | 4298 scoped_feature_list.InitFromCommandLine( |
| 4299 "CaptivePortalCertificateList" /* enabled */, | |
| 4300 std::string() /* disabled */); | |
| 4278 | 4301 |
| 4279 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); | 4302 TestNoCaptivePortalInterstitial( |
| 4280 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | 4303 net::CERT_STATUS_COMMON_NAME_INVALID | net::CERT_STATUS_WEAK_KEY, |
|
estark
2017/02/15 00:31:41
nit: it might be good to have a sanity check that
meacer
2017/02/15 00:37:29
Hmm, I thought about checking for name mismatch er
meacer
2017/02/23 23:28:19
Done.
| |
| 4281 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | 4304 net::ERR_CERT_COMMON_NAME_INVALID); |
| 4282 EXPECT_TRUE(interstitial_timer_observer.timer_started()); | |
| 4283 | |
| 4284 // Check that the histogram for the captive portal cert was recorded. | |
| 4285 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), 2); | |
| 4286 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4287 SSLErrorHandler::HANDLE_ALL, 1); | |
| 4288 histograms.ExpectBucketCount( | |
| 4289 SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4290 SSLErrorHandler::SHOW_SSL_INTERSTITIAL_OVERRIDABLE, 1); | |
| 4291 } | 4305 } |
| 4292 | 4306 |
| 4293 #else | 4307 #else |
| 4294 | 4308 |
| 4295 // Tests that the captive portal certificate list is not used when captive | 4309 // Tests that the captive portal certificate list is not used when captive |
| 4296 // portal checks are disabled by build, even if the captive portal certificate | 4310 // portal checks are disabled by build, even if the captive portal certificate |
| 4297 // list feature is enabled via Finch. The list is passed to SSLErrorHandler via | 4311 // list feature is enabled via Finch. The list is passed to SSLErrorHandler via |
| 4298 // a proto. | 4312 // a proto. |
| 4299 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListTest, PortalChecksDisabled) { | 4313 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListTest, PortalChecksDisabled) { |
| 4300 base::test::ScopedFeatureList scoped_feature_list; | 4314 base::test::ScopedFeatureList scoped_feature_list; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4342 | 4356 |
| 4343 // Visit a page over https that contains a frame with a redirect. | 4357 // Visit a page over https that contains a frame with a redirect. |
| 4344 | 4358 |
| 4345 // XMLHttpRequest insecure content in synchronous mode. | 4359 // XMLHttpRequest insecure content in synchronous mode. |
| 4346 | 4360 |
| 4347 // XMLHttpRequest insecure content in asynchronous mode. | 4361 // XMLHttpRequest insecure content in asynchronous mode. |
| 4348 | 4362 |
| 4349 // XMLHttpRequest over bad ssl in synchronous mode. | 4363 // XMLHttpRequest over bad ssl in synchronous mode. |
| 4350 | 4364 |
| 4351 // XMLHttpRequest over OK ssl in synchronous mode. | 4365 // XMLHttpRequest over OK ssl in synchronous mode. |
| OLD | NEW |