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

Side by Side Diff: chrome/browser/ssl/ssl_browser_tests.cc

Issue 2690333006: Captive portal certificate list should be checked when name mismatch is the only error (Closed)
Patch Set: estark comments Created 3 years, 9 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 <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
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
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 const net::CertStatus cert_status =
4280 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, 4303 net::CERT_STATUS_COMMON_NAME_INVALID | net::CERT_STATUS_WEAK_KEY;
4281 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); 4304 EXPECT_EQ(net::ERR_CERT_COMMON_NAME_INVALID,
estark 2017/02/25 01:33:17 nit: maybe explain what you're doing here: "Sanity
meacer 2017/02/27 23:50:58 Done.
4282 EXPECT_TRUE(interstitial_timer_observer.timer_started()); 4305 net::MapCertStatusToNetError(cert_status));
4283 4306 TestNoCaptivePortalInterstitial(cert_status,
4284 // Check that the histogram for the captive portal cert was recorded. 4307 net::ERR_CERT_COMMON_NAME_INVALID);
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 } 4308 }
4292 4309
4293 #else 4310 #else
4294 4311
4295 // Tests that the captive portal certificate list is not used when captive 4312 // 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 4313 // 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 4314 // list feature is enabled via Finch. The list is passed to SSLErrorHandler via
4298 // a proto. 4315 // a proto.
4299 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListTest, PortalChecksDisabled) { 4316 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListTest, PortalChecksDisabled) {
4300 base::test::ScopedFeatureList scoped_feature_list; 4317 base::test::ScopedFeatureList scoped_feature_list;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4342 4359
4343 // Visit a page over https that contains a frame with a redirect. 4360 // Visit a page over https that contains a frame with a redirect.
4344 4361
4345 // XMLHttpRequest insecure content in synchronous mode. 4362 // XMLHttpRequest insecure content in synchronous mode.
4346 4363
4347 // XMLHttpRequest insecure content in asynchronous mode. 4364 // XMLHttpRequest insecure content in asynchronous mode.
4348 4365
4349 // XMLHttpRequest over bad ssl in synchronous mode. 4366 // XMLHttpRequest over bad ssl in synchronous mode.
4350 4367
4351 // XMLHttpRequest over OK ssl in synchronous mode. 4368 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ssl/ssl_error_handler.cc » ('j') | chrome/browser/ssl/ssl_error_handler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698