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

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: reorder some function definitions to more closely match declaration order (out-of-band tip from rsl… Created 5 years, 10 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 = true) {
Ryan Sleevi 2015/02/27 03:49:59 Alas, defaults for arguments are not allowed - htt
estark 2015/02/27 04:47:50 Curses! Done.
393 ASSERT_TRUE(https_server_expired_.Start());
394
395 // Set up the mock reporter to track the hostnames that reports get
396 // sent for. The request_context argument is NULL here because the
397 // MockReporter doesn't actually use a request_context. (In order to
398 // pass a real request_context, the reporter would have to be
399 // constructed on the IO thread.)
400 MockReporter reporter(NULL);
401 scoped_refptr<net::URLRequestContextGetter> context_getter =
402 browser()->profile()->GetRequestContext();
403
404 content::BrowserThread::PostTask(
405 content::BrowserThread::IO, FROM_HERE,
406 base::Bind(SetUpMockReporter, context_getter, &reporter));
407
408 // Wait until the mock reporter has been set up on the IO thread.
409 base::RunLoop().RunUntilIdle();
410
411 // Opt in to sending reports for invalid certificate chains.
412 browser()->profile()->GetPrefs()->SetBoolean(
413 prefs::kSafeBrowsingExtendedReportingEnabled, opt_in);
414
415 EXPECT_EQ(reporter.GetLatestHostnameReported(), "");
416
417 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/"));
418
419 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
420 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID,
421 AuthState::SHOWING_INTERSTITIAL);
422
423 if (proceed) {
424 ProceedThroughInterstitial(tab);
425 } else {
426 // Click "Take me back"
427 InterstitialPage* interstitial_page = tab->GetInterstitialPage();
428 ASSERT_TRUE(interstitial_page);
429 interstitial_page->DontProceed();
430 }
431
432 // Wait until the report has been sent on the IO thread.
433 base::RunLoop().RunUntilIdle();
434
435 if (opt_in) {
436 // Check that the mock reporter received a request to send a report.
437 if (switch_enabled) {
438 EXPECT_EQ(reporter.GetLatestHostnameReported(),
439 https_server_expired_.GetURL("/").host());
440 } else {
441 EXPECT_EQ(reporter.GetLatestHostnameReported(), "");
442 }
443 } else {
444 EXPECT_EQ(reporter.GetLatestHostnameReported(), "");
445 }
446 }
447
352 net::SpawnedTestServer https_server_; 448 net::SpawnedTestServer https_server_;
353 net::SpawnedTestServer https_server_expired_; 449 net::SpawnedTestServer https_server_expired_;
354 net::SpawnedTestServer https_server_mismatched_; 450 net::SpawnedTestServer https_server_mismatched_;
355 net::SpawnedTestServer wss_server_expired_; 451 net::SpawnedTestServer wss_server_expired_;
356 452
357 private: 453 private:
358 typedef net::SpawnedTestServer::SSLOptions SSLOptions; 454 typedef net::SpawnedTestServer::SSLOptions SSLOptions;
359 455
360 DISALLOW_COPY_AND_ASSIGN(SSLUITest); 456 DISALLOW_COPY_AND_ASSIGN(SSLUITest);
361 }; 457 };
(...skipping 21 matching lines...) Expand all
383 class SSLUITestIgnoreLocalhostCertErrors : public SSLUITest { 479 class SSLUITestIgnoreLocalhostCertErrors : public SSLUITest {
384 public: 480 public:
385 SSLUITestIgnoreLocalhostCertErrors() : SSLUITest() {} 481 SSLUITestIgnoreLocalhostCertErrors() : SSLUITest() {}
386 482
387 void SetUpCommandLine(base::CommandLine* command_line) override { 483 void SetUpCommandLine(base::CommandLine* command_line) override {
388 // Browser will ignore certificate errors on localhost. 484 // Browser will ignore certificate errors on localhost.
389 command_line->AppendSwitch(switches::kAllowInsecureLocalhost); 485 command_line->AppendSwitch(switches::kAllowInsecureLocalhost);
390 } 486 }
391 }; 487 };
392 488
489 class SSLUITestWithExtendedReporting : public SSLUITest {
490 public:
491 SSLUITestWithExtendedReporting() : SSLUITest() {}
492
493 void SetUpCommandLine(base::CommandLine* command_line) override {
494 // Enable a checkbox on SSL interstitials that allows users to opt
495 // in to reporting invalid certificate chains.
496 command_line->AppendSwitch(switches::kEnableInvalidCertCollection);
497 }
498 };
499
393 // Visits a regular page over http. 500 // Visits a regular page over http.
394 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) { 501 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) {
395 ASSERT_TRUE(test_server()->Start()); 502 ASSERT_TRUE(test_server()->Start());
396 503
397 ui_test_utils::NavigateToURL(browser(), 504 ui_test_utils::NavigateToURL(browser(),
398 test_server()->GetURL("files/ssl/google.html")); 505 test_server()->GetURL("files/ssl/google.html"));
399 506
400 CheckUnauthenticatedState( 507 CheckUnauthenticatedState(
401 browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE); 508 browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE);
402 } 509 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 CheckAuthenticationBrokenState( 546 CheckAuthenticationBrokenState(
440 tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL); 547 tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
441 548
442 ProceedThroughInterstitial(tab); 549 ProceedThroughInterstitial(tab);
443 550
444 CheckAuthenticationBrokenState(tab, 551 CheckAuthenticationBrokenState(tab,
445 net::CERT_STATUS_DATE_INVALID, 552 net::CERT_STATUS_DATE_INVALID,
446 AuthState::DISPLAYED_INSECURE_CONTENT); 553 AuthState::DISPLAYED_INSECURE_CONTENT);
447 } 554 }
448 555
556 // Test that when the checkbox is checked and the user proceeds through
557 // the interstitial, the FraudulentCertificateReporter sees a request to
558 // send a report.
559 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
560 TestBrokenHTTPSProceedWithReporting) {
561 TestBrokenHTTPSReporting(true, true);
562 }
563
564 // Test that when the checkbox is checked and the user goes back (does
565 // not proceed through the interstitial), the
566 // FraudulentCertificateReporter sees a request to send a report.
567 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
568 TestBrokenHTTPSGoBackWithReporting) {
569 TestBrokenHTTPSReporting(true, false);
570 }
571
572 // Test that when the checkbox is not checked and the user proceeds
573 // through the interstitial, the FraudulentCertificateReporter does not
574 // see a request to send a report.
575 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
576 TestBrokenHTTPSProceedWithNoReporting) {
577 TestBrokenHTTPSReporting(false, true);
578 }
579
580 // Test that when the checkbox is not checked and the user does not proceed
581 // through the interstitial, the FraudulentCertificateReporter does not
582 // see a request to send a report.
583 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
584 TestBrokenHTTPSGoBackWithNoReporting) {
585 TestBrokenHTTPSReporting(false, false);
586 }
587
588 // Test that when the command-line switch for reporting invalid cert
589 // chains is not enabled, reports don't get sent, even if the opt-in
590 // preference is set. (i.e. if a user enables invalid cert collection in
591 // chrome://flags, checks the box on an interstitial, and then disables
592 // the flag in chrome://flags, reports shouldn't be sent on the next
593 // interstitial).
594 IN_PROC_BROWSER_TEST_F(SSLUITest, TestBrokenHTTPSNoReportingWithoutSwitch) {
595 TestBrokenHTTPSReporting(true, true, false);
596 }
597
449 // http://crbug.com/91745 598 // http://crbug.com/91745
450 #if defined(OS_CHROMEOS) 599 #if defined(OS_CHROMEOS)
451 #define MAYBE_TestOKHTTPS DISABLED_TestOKHTTPS 600 #define MAYBE_TestOKHTTPS DISABLED_TestOKHTTPS
452 #else 601 #else
453 #define MAYBE_TestOKHTTPS TestOKHTTPS 602 #define MAYBE_TestOKHTTPS TestOKHTTPS
454 #endif 603 #endif
455 604
456 // Visits a page over OK https: 605 // Visits a page over OK https:
457 IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestOKHTTPS) { 606 IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestOKHTTPS) {
458 ASSERT_TRUE(https_server_.Start()); 607 ASSERT_TRUE(https_server_.Start());
(...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 2064
1916 // Visit a page over https that contains a frame with a redirect. 2065 // Visit a page over https that contains a frame with a redirect.
1917 2066
1918 // XMLHttpRequest insecure content in synchronous mode. 2067 // XMLHttpRequest insecure content in synchronous mode.
1919 2068
1920 // XMLHttpRequest insecure content in asynchronous mode. 2069 // XMLHttpRequest insecure content in asynchronous mode.
1921 2070
1922 // XMLHttpRequest over bad ssl in synchronous mode. 2071 // XMLHttpRequest over bad ssl in synchronous mode.
1923 2072
1924 // XMLHttpRequest over OK ssl in synchronous mode. 2073 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698