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

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: bauerb's comments 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
« no previous file with comments | « chrome/browser/ssl/ssl_blocking_page.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 void WaitForIOThread() {
390 base::RunLoop run_loop;
391 content::BrowserThread::PostTaskAndReply(
392 content::BrowserThread::IO, FROM_HERE, base::Bind(&base::DoNothing),
393 run_loop.QuitClosure());
394 run_loop.Run();
395 base::RunLoop().RunUntilIdle();
396 }
397
398 // Helper function for the testing invalid certificate chain reporting.
399 void TestBrokenHTTPSReporting(bool opt_in,
400 bool proceed,
401 bool switch_enabled,
402 bool expect_report,
403 Browser* browser) {
404 ASSERT_TRUE(https_server_expired_.Start());
405
406 // Set up the mock reporter to track the hostnames that reports get
407 // sent for. The request_context argument is NULL here because the
408 // MockReporter doesn't actually use a request_context. (In order to
409 // pass a real request_context, the reporter would have to be
410 // constructed on the IO thread.)
411 MockReporter reporter(nullptr);
412 scoped_refptr<net::URLRequestContextGetter> context_getter =
413 browser->profile()->GetRequestContext();
414
415 content::BrowserThread::PostTask(
416 content::BrowserThread::IO, FROM_HERE,
417 base::Bind(SetUpMockReporter, context_getter, &reporter));
418
419 // Wait until the mock reporter has been set up on the IO thread.
420 WaitForIOThread();
421
422 // Opt in to sending reports for invalid certificate chains.
423 browser->profile()->GetPrefs()->SetBoolean(
424 prefs::kSafeBrowsingExtendedReportingEnabled, opt_in);
425
426 EXPECT_EQ(reporter.GetLatestHostnameReported(), std::string());
427
428 ui_test_utils::NavigateToURL(browser, https_server_expired_.GetURL("/"));
429
430 WebContents* tab = browser->tab_strip_model()->GetActiveWebContents();
431 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID,
432 AuthState::SHOWING_INTERSTITIAL);
433
434 if (proceed) {
435 ProceedThroughInterstitial(tab);
436 } else {
437 // Click "Take me back"
438 InterstitialPage* interstitial_page = tab->GetInterstitialPage();
439 ASSERT_TRUE(interstitial_page);
440 interstitial_page->DontProceed();
441 }
442
443 // Wait until the report has been sent on the IO thread.
444 WaitForIOThread();
Bernhard Bauer 2015/03/03 16:17:45 This one is a bit more tricky... The problem with
estark 2015/03/03 18:06:20 Makes sense! Done. I named it SetCertificateReport
445
446 if (expect_report) {
447 // Check that the mock reporter received a request to send a report.
448 EXPECT_EQ(reporter.GetLatestHostnameReported(),
449 https_server_expired_.GetURL("/").host());
450 } else {
451 EXPECT_EQ(reporter.GetLatestHostnameReported(), std::string());
452 }
453 }
454
352 net::SpawnedTestServer https_server_; 455 net::SpawnedTestServer https_server_;
353 net::SpawnedTestServer https_server_expired_; 456 net::SpawnedTestServer https_server_expired_;
354 net::SpawnedTestServer https_server_mismatched_; 457 net::SpawnedTestServer https_server_mismatched_;
355 net::SpawnedTestServer wss_server_expired_; 458 net::SpawnedTestServer wss_server_expired_;
356 459
357 private: 460 private:
358 typedef net::SpawnedTestServer::SSLOptions SSLOptions; 461 typedef net::SpawnedTestServer::SSLOptions SSLOptions;
359 462
360 DISALLOW_COPY_AND_ASSIGN(SSLUITest); 463 DISALLOW_COPY_AND_ASSIGN(SSLUITest);
361 }; 464 };
(...skipping 21 matching lines...) Expand all
383 class SSLUITestIgnoreLocalhostCertErrors : public SSLUITest { 486 class SSLUITestIgnoreLocalhostCertErrors : public SSLUITest {
384 public: 487 public:
385 SSLUITestIgnoreLocalhostCertErrors() : SSLUITest() {} 488 SSLUITestIgnoreLocalhostCertErrors() : SSLUITest() {}
386 489
387 void SetUpCommandLine(base::CommandLine* command_line) override { 490 void SetUpCommandLine(base::CommandLine* command_line) override {
388 // Browser will ignore certificate errors on localhost. 491 // Browser will ignore certificate errors on localhost.
389 command_line->AppendSwitch(switches::kAllowInsecureLocalhost); 492 command_line->AppendSwitch(switches::kAllowInsecureLocalhost);
390 } 493 }
391 }; 494 };
392 495
496 class SSLUITestWithExtendedReporting : public SSLUITest {
497 public:
498 SSLUITestWithExtendedReporting() : SSLUITest() {}
499
500 void SetUpCommandLine(base::CommandLine* command_line) override {
501 // Enable a checkbox on SSL interstitials that allows users to opt
502 // in to reporting invalid certificate chains.
503 command_line->AppendSwitch(switches::kEnableInvalidCertCollection);
504 }
505 };
506
393 // Visits a regular page over http. 507 // Visits a regular page over http.
394 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) { 508 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) {
395 ASSERT_TRUE(test_server()->Start()); 509 ASSERT_TRUE(test_server()->Start());
396 510
397 ui_test_utils::NavigateToURL(browser(), 511 ui_test_utils::NavigateToURL(browser(),
398 test_server()->GetURL("files/ssl/google.html")); 512 test_server()->GetURL("files/ssl/google.html"));
399 513
400 CheckUnauthenticatedState( 514 CheckUnauthenticatedState(
401 browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE); 515 browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE);
402 } 516 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 CheckAuthenticationBrokenState( 553 CheckAuthenticationBrokenState(
440 tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL); 554 tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
441 555
442 ProceedThroughInterstitial(tab); 556 ProceedThroughInterstitial(tab);
443 557
444 CheckAuthenticationBrokenState(tab, 558 CheckAuthenticationBrokenState(tab,
445 net::CERT_STATUS_DATE_INVALID, 559 net::CERT_STATUS_DATE_INVALID,
446 AuthState::DISPLAYED_INSECURE_CONTENT); 560 AuthState::DISPLAYED_INSECURE_CONTENT);
447 } 561 }
448 562
563 // Test that when the checkbox is checked and the user proceeds through
564 // the interstitial, the FraudulentCertificateReporter sees a request to
565 // send a report.
566 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
567 TestBrokenHTTPSProceedWithReporting) {
568 TestBrokenHTTPSReporting(true, true, true, true, browser());
569 }
570
571 // Test that when the checkbox is checked and the user goes back (does
572 // not proceed through the interstitial), the
573 // FraudulentCertificateReporter sees a request to send a report.
574 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
575 TestBrokenHTTPSGoBackWithReporting) {
576 TestBrokenHTTPSReporting(true, false, true, true, browser());
577 }
578
579 // Test that when the checkbox is not checked and the user proceeds
580 // through the interstitial, the FraudulentCertificateReporter does not
581 // see a request to send a report.
582 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
583 TestBrokenHTTPSProceedWithNoReporting) {
584 TestBrokenHTTPSReporting(false, true, true, false, browser());
585 }
586
587 // Test that when the checkbox is not checked and the user does not proceed
588 // through the interstitial, the FraudulentCertificateReporter does not
589 // see a request to send a report.
590 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
591 TestBrokenHTTPSGoBackWithNoReporting) {
592 TestBrokenHTTPSReporting(false, false, true, false, browser());
593 }
594
595 // Test that when the command-line switch for reporting invalid cert
596 // chains is not enabled, reports don't get sent, even if the opt-in
597 // preference is set. (i.e. if a user enables invalid cert collection in
598 // chrome://flags, checks the box on an interstitial, and then disables
599 // the flag in chrome://flags, reports shouldn't be sent on the next
600 // interstitial).
601 IN_PROC_BROWSER_TEST_F(SSLUITest, TestBrokenHTTPSNoReportingWithoutSwitch) {
602 TestBrokenHTTPSReporting(true, true, false, false, browser());
603 }
604
605 // Test that reports don't get sent in incognito mode even if the opt-in
606 // preference is set and the command-line switch is enabled.
607 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
608 TestBrokenHTTPSNoReportingInIncognito) {
609 TestBrokenHTTPSReporting(true, true, true, false, CreateIncognitoBrowser());
610 }
611
449 // http://crbug.com/91745 612 // http://crbug.com/91745
450 #if defined(OS_CHROMEOS) 613 #if defined(OS_CHROMEOS)
451 #define MAYBE_TestOKHTTPS DISABLED_TestOKHTTPS 614 #define MAYBE_TestOKHTTPS DISABLED_TestOKHTTPS
452 #else 615 #else
453 #define MAYBE_TestOKHTTPS TestOKHTTPS 616 #define MAYBE_TestOKHTTPS TestOKHTTPS
454 #endif 617 #endif
455 618
456 // Visits a page over OK https: 619 // Visits a page over OK https:
457 IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestOKHTTPS) { 620 IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestOKHTTPS) {
458 ASSERT_TRUE(https_server_.Start()); 621 ASSERT_TRUE(https_server_.Start());
(...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 2078
1916 // Visit a page over https that contains a frame with a redirect. 2079 // Visit a page over https that contains a frame with a redirect.
1917 2080
1918 // XMLHttpRequest insecure content in synchronous mode. 2081 // XMLHttpRequest insecure content in synchronous mode.
1919 2082
1920 // XMLHttpRequest insecure content in asynchronous mode. 2083 // XMLHttpRequest insecure content in asynchronous mode.
1921 2084
1922 // XMLHttpRequest over bad ssl in synchronous mode. 2085 // XMLHttpRequest over bad ssl in synchronous mode.
1923 2086
1924 // XMLHttpRequest over OK ssl in synchronous mode. 2087 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW
« no previous file with comments | « chrome/browser/ssl/ssl_blocking_page.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698