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

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

Issue 935663004: Add checkbox for reporting invalid TLS/SSL cert chains (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move off the record check before UMA stats collection Created 5 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "chrome/app/chrome_command_ids.h" 13 #include "chrome/app/chrome_command_ids.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ssl/ssl_blocking_page.h" 17 #include "chrome/browser/ssl/ssl_blocking_page.h"
17 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_commands.h" 19 #include "chrome/browser/ui/browser_commands.h"
19 #include "chrome/browser/ui/browser_navigator.h" 20 #include "chrome/browser/ui/browser_navigator.h"
20 #include "chrome/browser/ui/browser_tabstrip.h" 21 #include "chrome/browser/ui/browser_tabstrip.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
(...skipping 13 matching lines...) Expand all
38 #include "content/public/browser/web_contents_observer.h" 39 #include "content/public/browser/web_contents_observer.h"
39 #include "content/public/common/security_style.h" 40 #include "content/public/common/security_style.h"
40 #include "content/public/common/ssl_status.h" 41 #include "content/public/common/ssl_status.h"
41 #include "content/public/test/browser_test_utils.h" 42 #include "content/public/test/browser_test_utils.h"
42 #include "content/public/test/download_test_observer.h" 43 #include "content/public/test/download_test_observer.h"
43 #include "content/public/test/test_renderer_host.h" 44 #include "content/public/test/test_renderer_host.h"
44 #include "net/base/net_errors.h" 45 #include "net/base/net_errors.h"
45 #include "net/base/test_data_directory.h" 46 #include "net/base/test_data_directory.h"
46 #include "net/cert/cert_status_flags.h" 47 #include "net/cert/cert_status_flags.h"
47 #include "net/test/spawned_test_server/spawned_test_server.h" 48 #include "net/test/spawned_test_server/spawned_test_server.h"
49 #include "net/url_request/fraudulent_certificate_reporter.h"
50 #include "net/url_request/url_request_context.h"
51 #include "net/url_request/url_request_context_getter.h"
48 52
49 #if defined(USE_NSS) 53 #if defined(USE_NSS)
50 #include "chrome/browser/net/nss_context.h" 54 #include "chrome/browser/net/nss_context.h"
51 #include "net/base/crypto_module.h" 55 #include "net/base/crypto_module.h"
52 #include "net/cert/nss_cert_database.h" 56 #include "net/cert/nss_cert_database.h"
53 #endif // defined(USE_NSS) 57 #endif // defined(USE_NSS)
54 58
55 using base::ASCIIToUTF16; 59 using base::ASCIIToUTF16;
60 using chrome_browser_net::ChromeFraudulentCertificateReporter;
56 using content::InterstitialPage; 61 using content::InterstitialPage;
57 using content::NavigationController; 62 using content::NavigationController;
58 using content::NavigationEntry; 63 using content::NavigationEntry;
59 using content::SSLStatus; 64 using content::SSLStatus;
60 using content::WebContents; 65 using content::WebContents;
66 using net::FraudulentCertificateReporter;
61 using web_modal::WebContentsModalDialogManager; 67 using web_modal::WebContentsModalDialogManager;
62 68
63 const base::FilePath::CharType kDocRoot[] = 69 const base::FilePath::CharType kDocRoot[] =
64 FILE_PATH_LITERAL("chrome/test/data"); 70 FILE_PATH_LITERAL("chrome/test/data");
65 71
66 namespace { 72 namespace {
67 73
68 class ProvisionalLoadWaiter : public content::WebContentsObserver { 74 class ProvisionalLoadWaiter : public content::WebContentsObserver {
69 public: 75 public:
70 explicit ProvisionalLoadWaiter(WebContents* tab) 76 explicit ProvisionalLoadWaiter(WebContents* tab)
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 content::SecurityStyle expected_security_style, 168 content::SecurityStyle expected_security_style,
163 int expected_authentication_state) { 169 int expected_authentication_state) {
164 ASSERT_FALSE(tab->IsCrashed()); 170 ASSERT_FALSE(tab->IsCrashed());
165 NavigationEntry* entry = tab->GetController().GetActiveEntry(); 171 NavigationEntry* entry = tab->GetController().GetActiveEntry();
166 ASSERT_TRUE(entry); 172 ASSERT_TRUE(entry);
167 CertError::Check(*entry, error); 173 CertError::Check(*entry, error);
168 SecurityStyle::Check(*entry, expected_security_style); 174 SecurityStyle::Check(*entry, expected_security_style);
169 AuthState::Check(*entry, expected_authentication_state); 175 AuthState::Check(*entry, expected_authentication_state);
170 } 176 }
171 177
178 // This class is used to test invalid certificate chain reporting when
179 // the user opts in to do so on the interstitial.
180 class MockReporter : public ChromeFraudulentCertificateReporter {
181 public:
182 explicit MockReporter(net::URLRequestContext* request_context)
183 : ChromeFraudulentCertificateReporter(request_context) {}
184
185 void SendReport(ReportType type,
186 const std::string& hostname,
187 const net::SSLInfo& ssl_info) override {
188 latest_hostname_reported_ = hostname;
189 EXPECT_EQ(type, REPORT_TYPE_EXTENDED_REPORTING);
190 }
191
192 const std::string& GetLatestHostnameReported() {
193 return latest_hostname_reported_;
194 }
195
196 private:
197 std::string latest_hostname_reported_;
198 };
199
200 // A helper function for using a MockReporter on a
201 // URLRequestContext. Must be run on the IO thread.
202 void SetUpMockReporter(
203 const scoped_refptr<net::URLRequestContextGetter> context_getter,
204 MockReporter* reporter) {
205 context_getter->GetURLRequestContext()->set_fraudulent_certificate_reporter(
206 reporter);
207 }
208
172 } // namespace 209 } // namespace
173 210
174 class SSLUITest : public InProcessBrowserTest { 211 class SSLUITest : public InProcessBrowserTest {
175 public: 212 public:
176 SSLUITest() 213 SSLUITest()
177 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, 214 : https_server_(net::SpawnedTestServer::TYPE_HTTPS,
178 SSLOptions(SSLOptions::CERT_OK), 215 SSLOptions(SSLOptions::CERT_OK),
179 base::FilePath(kDocRoot)), 216 base::FilePath(kDocRoot)),
180 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, 217 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS,
181 SSLOptions(SSLOptions::CERT_EXPIRED), 218 SSLOptions(SSLOptions::CERT_EXPIRED),
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 std::vector<net::SpawnedTestServer::StringPair> 379 std::vector<net::SpawnedTestServer::StringPair>
343 replacement_text_for_page_with_unsafe_worker; 380 replacement_text_for_page_with_unsafe_worker;
344 replacement_text_for_page_with_unsafe_worker.push_back( 381 replacement_text_for_page_with_unsafe_worker.push_back(
345 make_pair("REPLACE_WITH_UNSAFE_WORKER_PATH", unsafe_worker_path)); 382 make_pair("REPLACE_WITH_UNSAFE_WORKER_PATH", unsafe_worker_path));
346 return net::SpawnedTestServer::GetFilePathWithReplacements( 383 return net::SpawnedTestServer::GetFilePathWithReplacements(
347 "files/ssl/page_with_unsafe_worker.html", 384 "files/ssl/page_with_unsafe_worker.html",
348 replacement_text_for_page_with_unsafe_worker, 385 replacement_text_for_page_with_unsafe_worker,
349 page_with_unsafe_worker_path); 386 page_with_unsafe_worker_path);
350 } 387 }
351 388
389 // Helper function for the testing invalid certificate chain reporting.
390 void TestBrokenHTTPSReporting(bool opt_in,
391 bool proceed,
392 bool switch_enabled,
393 bool expect_report,
394 Browser* browser) {
395 ASSERT_TRUE(https_server_expired_.Start());
396
397 // Set up the mock reporter to track the hostnames that reports get
398 // sent for. The request_context argument is NULL here because the
399 // MockReporter doesn't actually use a request_context. (In order to
400 // pass a real request_context, the reporter would have to be
401 // constructed on the IO thread.)
402 MockReporter reporter(NULL);
Bernhard Bauer 2015/03/03 09:45:59 nullptr
estark 2015/03/03 15:36:24 Done.
403 scoped_refptr<net::URLRequestContextGetter> context_getter =
404 browser->profile()->GetRequestContext();
405
406 content::BrowserThread::PostTask(
407 content::BrowserThread::IO, FROM_HERE,
408 base::Bind(SetUpMockReporter, context_getter, &reporter));
409
410 // Wait until the mock reporter has been set up on the IO thread.
411 base::RunLoop().RunUntilIdle();
Bernhard Bauer 2015/03/03 09:45:59 Urr... this only spins a message loop on the UI th
estark 2015/03/03 15:36:24 Done, I think -- can you please check that I did t
Bernhard Bauer 2015/03/03 16:17:45 Almost -- but you don't have to post an additional
estark 2015/03/03 18:06:20 Done.
412
413 // Opt in to sending reports for invalid certificate chains.
414 browser->profile()->GetPrefs()->SetBoolean(
415 prefs::kSafeBrowsingExtendedReportingEnabled, opt_in);
416
417 EXPECT_EQ(reporter.GetLatestHostnameReported(), "");
Bernhard Bauer 2015/03/03 09:45:59 Using an empty std::string() constructor saves a h
estark 2015/03/03 15:36:24 Done.
418
419 ui_test_utils::NavigateToURL(browser, https_server_expired_.GetURL("/"));
420
421 WebContents* tab = browser->tab_strip_model()->GetActiveWebContents();
422 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID,
423 AuthState::SHOWING_INTERSTITIAL);
424
425 if (proceed) {
426 ProceedThroughInterstitial(tab);
427 } else {
428 // Click "Take me back"
429 InterstitialPage* interstitial_page = tab->GetInterstitialPage();
430 ASSERT_TRUE(interstitial_page);
431 interstitial_page->DontProceed();
432 }
433
434 // Wait until the report has been sent on the IO thread.
435 base::RunLoop().RunUntilIdle();
436
437 if (expect_report) {
438 // Check that the mock reporter received a request to send a report.
439 EXPECT_EQ(reporter.GetLatestHostnameReported(),
440 https_server_expired_.GetURL("/").host());
441 } else {
442 EXPECT_EQ(reporter.GetLatestHostnameReported(), "");
443 }
444 }
445
352 net::SpawnedTestServer https_server_; 446 net::SpawnedTestServer https_server_;
353 net::SpawnedTestServer https_server_expired_; 447 net::SpawnedTestServer https_server_expired_;
354 net::SpawnedTestServer https_server_mismatched_; 448 net::SpawnedTestServer https_server_mismatched_;
355 net::SpawnedTestServer wss_server_expired_; 449 net::SpawnedTestServer wss_server_expired_;
356 450
357 private: 451 private:
358 typedef net::SpawnedTestServer::SSLOptions SSLOptions; 452 typedef net::SpawnedTestServer::SSLOptions SSLOptions;
359 453
360 DISALLOW_COPY_AND_ASSIGN(SSLUITest); 454 DISALLOW_COPY_AND_ASSIGN(SSLUITest);
361 }; 455 };
(...skipping 21 matching lines...) Expand all
383 class SSLUITestIgnoreLocalhostCertErrors : public SSLUITest { 477 class SSLUITestIgnoreLocalhostCertErrors : public SSLUITest {
384 public: 478 public:
385 SSLUITestIgnoreLocalhostCertErrors() : SSLUITest() {} 479 SSLUITestIgnoreLocalhostCertErrors() : SSLUITest() {}
386 480
387 void SetUpCommandLine(base::CommandLine* command_line) override { 481 void SetUpCommandLine(base::CommandLine* command_line) override {
388 // Browser will ignore certificate errors on localhost. 482 // Browser will ignore certificate errors on localhost.
389 command_line->AppendSwitch(switches::kAllowInsecureLocalhost); 483 command_line->AppendSwitch(switches::kAllowInsecureLocalhost);
390 } 484 }
391 }; 485 };
392 486
487 class SSLUITestWithExtendedReporting : public SSLUITest {
488 public:
489 SSLUITestWithExtendedReporting() : SSLUITest() {}
490
491 void SetUpCommandLine(base::CommandLine* command_line) override {
492 // Enable a checkbox on SSL interstitials that allows users to opt
493 // in to reporting invalid certificate chains.
494 command_line->AppendSwitch(switches::kEnableInvalidCertCollection);
495 }
496 };
497
393 // Visits a regular page over http. 498 // Visits a regular page over http.
394 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) { 499 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) {
395 ASSERT_TRUE(test_server()->Start()); 500 ASSERT_TRUE(test_server()->Start());
396 501
397 ui_test_utils::NavigateToURL(browser(), 502 ui_test_utils::NavigateToURL(browser(),
398 test_server()->GetURL("files/ssl/google.html")); 503 test_server()->GetURL("files/ssl/google.html"));
399 504
400 CheckUnauthenticatedState( 505 CheckUnauthenticatedState(
401 browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE); 506 browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE);
402 } 507 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 CheckAuthenticationBrokenState( 544 CheckAuthenticationBrokenState(
440 tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL); 545 tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
441 546
442 ProceedThroughInterstitial(tab); 547 ProceedThroughInterstitial(tab);
443 548
444 CheckAuthenticationBrokenState(tab, 549 CheckAuthenticationBrokenState(tab,
445 net::CERT_STATUS_DATE_INVALID, 550 net::CERT_STATUS_DATE_INVALID,
446 AuthState::DISPLAYED_INSECURE_CONTENT); 551 AuthState::DISPLAYED_INSECURE_CONTENT);
447 } 552 }
448 553
554 // Test that when the checkbox is checked and the user proceeds through
555 // the interstitial, the FraudulentCertificateReporter sees a request to
556 // send a report.
557 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
558 TestBrokenHTTPSProceedWithReporting) {
559 TestBrokenHTTPSReporting(true, true, true, true, browser());
560 }
561
562 // Test that when the checkbox is checked and the user goes back (does
563 // not proceed through the interstitial), the
564 // FraudulentCertificateReporter sees a request to send a report.
565 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
566 TestBrokenHTTPSGoBackWithReporting) {
567 TestBrokenHTTPSReporting(true, false, true, true, browser());
568 }
569
570 // Test that when the checkbox is not checked and the user proceeds
571 // through the interstitial, the FraudulentCertificateReporter does not
572 // see a request to send a report.
573 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
574 TestBrokenHTTPSProceedWithNoReporting) {
575 TestBrokenHTTPSReporting(false, true, true, false, browser());
576 }
577
578 // Test that when the checkbox is not checked and the user does not proceed
579 // through the interstitial, the FraudulentCertificateReporter does not
580 // see a request to send a report.
581 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
582 TestBrokenHTTPSGoBackWithNoReporting) {
583 TestBrokenHTTPSReporting(false, false, true, false, browser());
584 }
585
586 // Test that when the command-line switch for reporting invalid cert
587 // chains is not enabled, reports don't get sent, even if the opt-in
588 // preference is set. (i.e. if a user enables invalid cert collection in
589 // chrome://flags, checks the box on an interstitial, and then disables
590 // the flag in chrome://flags, reports shouldn't be sent on the next
591 // interstitial).
592 IN_PROC_BROWSER_TEST_F(SSLUITest, TestBrokenHTTPSNoReportingWithoutSwitch) {
593 TestBrokenHTTPSReporting(true, true, false, false, browser());
594 }
595
596 // Test that reports don't get sent in incognito mode even if the opt-in
597 // preference is set and the command-line switch is enabled.
598 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
599 TestBrokenHTTPSNoReportingInIncognito) {
600 TestBrokenHTTPSReporting(true, true, true, false, CreateIncognitoBrowser());
601 }
602
449 // http://crbug.com/91745 603 // http://crbug.com/91745
450 #if defined(OS_CHROMEOS) 604 #if defined(OS_CHROMEOS)
451 #define MAYBE_TestOKHTTPS DISABLED_TestOKHTTPS 605 #define MAYBE_TestOKHTTPS DISABLED_TestOKHTTPS
452 #else 606 #else
453 #define MAYBE_TestOKHTTPS TestOKHTTPS 607 #define MAYBE_TestOKHTTPS TestOKHTTPS
454 #endif 608 #endif
455 609
456 // Visits a page over OK https: 610 // Visits a page over OK https:
457 IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestOKHTTPS) { 611 IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestOKHTTPS) {
458 ASSERT_TRUE(https_server_.Start()); 612 ASSERT_TRUE(https_server_.Start());
(...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 2069
1916 // Visit a page over https that contains a frame with a redirect. 2070 // Visit a page over https that contains a frame with a redirect.
1917 2071
1918 // XMLHttpRequest insecure content in synchronous mode. 2072 // XMLHttpRequest insecure content in synchronous mode.
1919 2073
1920 // XMLHttpRequest insecure content in asynchronous mode. 2074 // XMLHttpRequest insecure content in asynchronous mode.
1921 2075
1922 // XMLHttpRequest over bad ssl in synchronous mode. 2076 // XMLHttpRequest over bad ssl in synchronous mode.
1923 2077
1924 // XMLHttpRequest over OK ssl in synchronous mode. 2078 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698