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 "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 Loading... |
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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 std::vector<net::SpawnedTestServer::StringPair> | 348 std::vector<net::SpawnedTestServer::StringPair> |
343 replacement_text_for_page_with_unsafe_worker; | 349 replacement_text_for_page_with_unsafe_worker; |
344 replacement_text_for_page_with_unsafe_worker.push_back( | 350 replacement_text_for_page_with_unsafe_worker.push_back( |
345 make_pair("REPLACE_WITH_UNSAFE_WORKER_PATH", unsafe_worker_path)); | 351 make_pair("REPLACE_WITH_UNSAFE_WORKER_PATH", unsafe_worker_path)); |
346 return net::SpawnedTestServer::GetFilePathWithReplacements( | 352 return net::SpawnedTestServer::GetFilePathWithReplacements( |
347 "files/ssl/page_with_unsafe_worker.html", | 353 "files/ssl/page_with_unsafe_worker.html", |
348 replacement_text_for_page_with_unsafe_worker, | 354 replacement_text_for_page_with_unsafe_worker, |
349 page_with_unsafe_worker_path); | 355 page_with_unsafe_worker_path); |
350 } | 356 } |
351 | 357 |
| 358 // Helper function for the testing invalid certificate chain reporting. |
| 359 void TestBrokenHTTPSReporting(bool opt_in, |
| 360 bool proceed, |
| 361 bool switch_enabled = true) { |
| 362 ASSERT_TRUE(https_server_expired_.Start()); |
| 363 |
| 364 // Set up the mock reporter to track the hostnames that reports get |
| 365 // sent for. |
| 366 net::URLRequestContext* context = |
| 367 browser()->profile()->GetRequestContext()->GetURLRequestContext(); |
| 368 MockReporter reporter(context); |
| 369 FraudulentCertificateReporter* orig_reporter = |
| 370 context->fraudulent_certificate_reporter(); |
| 371 context->set_fraudulent_certificate_reporter(&reporter); |
| 372 |
| 373 // Opt in to sending reports for invalid certificate chains. |
| 374 browser()->profile()->GetPrefs()->SetBoolean( |
| 375 prefs::kSafeBrowsingExtendedReportingEnabled, opt_in); |
| 376 |
| 377 EXPECT_EQ(reporter.GetLatestHostnameReported(), ""); |
| 378 |
| 379 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); |
| 380 |
| 381 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 382 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, |
| 383 AuthState::SHOWING_INTERSTITIAL); |
| 384 |
| 385 if (proceed) { |
| 386 ProceedThroughInterstitial(tab); |
| 387 } else { |
| 388 // Click "Take me back" |
| 389 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); |
| 390 ASSERT_TRUE(interstitial_page); |
| 391 interstitial_page->DontProceed(); |
| 392 } |
| 393 |
| 394 if (opt_in) { |
| 395 // Check that the mock reporter received a request to send a report. |
| 396 if (switch_enabled) { |
| 397 EXPECT_EQ(reporter.GetLatestHostnameReported(), |
| 398 https_server_expired_.GetURL("/").host()); |
| 399 } else { |
| 400 EXPECT_EQ(reporter.GetLatestHostnameReported(), ""); |
| 401 } |
| 402 } else { |
| 403 EXPECT_EQ(reporter.GetLatestHostnameReported(), ""); |
| 404 } |
| 405 |
| 406 context->set_fraudulent_certificate_reporter(orig_reporter); |
| 407 } |
| 408 |
352 net::SpawnedTestServer https_server_; | 409 net::SpawnedTestServer https_server_; |
353 net::SpawnedTestServer https_server_expired_; | 410 net::SpawnedTestServer https_server_expired_; |
354 net::SpawnedTestServer https_server_mismatched_; | 411 net::SpawnedTestServer https_server_mismatched_; |
355 net::SpawnedTestServer wss_server_expired_; | 412 net::SpawnedTestServer wss_server_expired_; |
356 | 413 |
357 private: | 414 private: |
358 typedef net::SpawnedTestServer::SSLOptions SSLOptions; | 415 typedef net::SpawnedTestServer::SSLOptions SSLOptions; |
359 | 416 |
| 417 // This class is used to test invalid certificate chain reporting when |
| 418 // the user opts in to do so on the interstitial. |
| 419 class MockReporter : public ChromeFraudulentCertificateReporter { |
| 420 public: |
| 421 explicit MockReporter(net::URLRequestContext* request_context) |
| 422 : ChromeFraudulentCertificateReporter(request_context) { |
| 423 latest_hostname_reported_ = ""; |
| 424 } |
| 425 |
| 426 void SendReport(ReportType type, |
| 427 const std::string& hostname, |
| 428 const net::SSLInfo& ssl_info) override { |
| 429 latest_hostname_reported_ = hostname; |
| 430 EXPECT_EQ(type, REPORT_TYPE_EXTENDED_REPORTING); |
| 431 } |
| 432 |
| 433 const std::string& GetLatestHostnameReported() { |
| 434 return latest_hostname_reported_; |
| 435 } |
| 436 |
| 437 private: |
| 438 std::string latest_hostname_reported_; |
| 439 }; |
| 440 |
360 DISALLOW_COPY_AND_ASSIGN(SSLUITest); | 441 DISALLOW_COPY_AND_ASSIGN(SSLUITest); |
361 }; | 442 }; |
362 | 443 |
363 class SSLUITestBlock : public SSLUITest { | 444 class SSLUITestBlock : public SSLUITest { |
364 public: | 445 public: |
365 SSLUITestBlock() : SSLUITest() {} | 446 SSLUITestBlock() : SSLUITest() {} |
366 | 447 |
367 // Browser will neither run nor display insecure content. | 448 // Browser will neither run nor display insecure content. |
368 void SetUpCommandLine(base::CommandLine* command_line) override { | 449 void SetUpCommandLine(base::CommandLine* command_line) override { |
369 command_line->AppendSwitch(switches::kNoDisplayingInsecureContent); | 450 command_line->AppendSwitch(switches::kNoDisplayingInsecureContent); |
(...skipping 13 matching lines...) Expand all Loading... |
383 class SSLUITestIgnoreLocalhostCertErrors : public SSLUITest { | 464 class SSLUITestIgnoreLocalhostCertErrors : public SSLUITest { |
384 public: | 465 public: |
385 SSLUITestIgnoreLocalhostCertErrors() : SSLUITest() {} | 466 SSLUITestIgnoreLocalhostCertErrors() : SSLUITest() {} |
386 | 467 |
387 void SetUpCommandLine(base::CommandLine* command_line) override { | 468 void SetUpCommandLine(base::CommandLine* command_line) override { |
388 // Browser will ignore certificate errors on localhost. | 469 // Browser will ignore certificate errors on localhost. |
389 command_line->AppendSwitch(switches::kAllowInsecureLocalhost); | 470 command_line->AppendSwitch(switches::kAllowInsecureLocalhost); |
390 } | 471 } |
391 }; | 472 }; |
392 | 473 |
| 474 class SSLUITestWithExtendedReporting : public SSLUITest { |
| 475 public: |
| 476 SSLUITestWithExtendedReporting() : SSLUITest() {} |
| 477 |
| 478 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 479 // Enable a checkbox on SSL interstitials that allows users to opt |
| 480 // in to reporting invalid certificate chains. |
| 481 command_line->AppendSwitch(switches::kEnableInvalidCertCollection); |
| 482 } |
| 483 }; |
| 484 |
393 // Visits a regular page over http. | 485 // Visits a regular page over http. |
394 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) { | 486 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) { |
395 ASSERT_TRUE(test_server()->Start()); | 487 ASSERT_TRUE(test_server()->Start()); |
396 | 488 |
397 ui_test_utils::NavigateToURL(browser(), | 489 ui_test_utils::NavigateToURL(browser(), |
398 test_server()->GetURL("files/ssl/google.html")); | 490 test_server()->GetURL("files/ssl/google.html")); |
399 | 491 |
400 CheckUnauthenticatedState( | 492 CheckUnauthenticatedState( |
401 browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE); | 493 browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE); |
402 } | 494 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 CheckAuthenticationBrokenState( | 531 CheckAuthenticationBrokenState( |
440 tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL); | 532 tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL); |
441 | 533 |
442 ProceedThroughInterstitial(tab); | 534 ProceedThroughInterstitial(tab); |
443 | 535 |
444 CheckAuthenticationBrokenState(tab, | 536 CheckAuthenticationBrokenState(tab, |
445 net::CERT_STATUS_DATE_INVALID, | 537 net::CERT_STATUS_DATE_INVALID, |
446 AuthState::DISPLAYED_INSECURE_CONTENT); | 538 AuthState::DISPLAYED_INSECURE_CONTENT); |
447 } | 539 } |
448 | 540 |
| 541 // Test that when the checkbox is checked and the user proceeds through |
| 542 // the interstitial, the FraudulentCertificateReporter sees a request to |
| 543 // send a report. |
| 544 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, |
| 545 TestBrokenHTTPSProceedWithReporting) { |
| 546 TestBrokenHTTPSReporting(true, true); |
| 547 } |
| 548 |
| 549 // Test that when the checkbox is checked and the user goes back (does |
| 550 // not proceed through the interstitial), the |
| 551 // FraudulentCertificateReporter sees a request to send a report. |
| 552 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, |
| 553 TestBrokenHTTPSGoBackWithReporting) { |
| 554 TestBrokenHTTPSReporting(true, false); |
| 555 } |
| 556 |
| 557 // Test that when the checkbox is not checked and the user proceeds |
| 558 // through the interstitial, the FraudulentCertificateReporter does not |
| 559 // see a request to send a report. |
| 560 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, |
| 561 TestBrokenHTTPSProceedWithNoReporting) { |
| 562 TestBrokenHTTPSReporting(false, true); |
| 563 } |
| 564 |
| 565 // Test that when the checkbox is not checked and the user does not proceed |
| 566 // through the interstitial, the FraudulentCertificateReporter does not |
| 567 // see a request to send a report. |
| 568 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, |
| 569 TestBrokenHTTPSGoBackWithNoReporting) { |
| 570 TestBrokenHTTPSReporting(false, false); |
| 571 } |
| 572 |
| 573 // Test that when the command-line switch for reporting invalid cert |
| 574 // chains is not enabled, reports don't get sent, even if the opt-in |
| 575 // preference is set. (i.e. if a user enables invalid cert collection in |
| 576 // chrome://flags, checks the box on an interstitial, and then disables |
| 577 // the flag in chrome://flags, reports shouldn't be sent on the next |
| 578 // interstitial). |
| 579 IN_PROC_BROWSER_TEST_F(SSLUITest, TestBrokenHTTPSNoReportingWithoutSwitch) { |
| 580 TestBrokenHTTPSReporting(true, true, false); |
| 581 } |
| 582 |
449 // http://crbug.com/91745 | 583 // http://crbug.com/91745 |
450 #if defined(OS_CHROMEOS) | 584 #if defined(OS_CHROMEOS) |
451 #define MAYBE_TestOKHTTPS DISABLED_TestOKHTTPS | 585 #define MAYBE_TestOKHTTPS DISABLED_TestOKHTTPS |
452 #else | 586 #else |
453 #define MAYBE_TestOKHTTPS TestOKHTTPS | 587 #define MAYBE_TestOKHTTPS TestOKHTTPS |
454 #endif | 588 #endif |
455 | 589 |
456 // Visits a page over OK https: | 590 // Visits a page over OK https: |
457 IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestOKHTTPS) { | 591 IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestOKHTTPS) { |
458 ASSERT_TRUE(https_server_.Start()); | 592 ASSERT_TRUE(https_server_.Start()); |
(...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 | 2049 |
1916 // Visit a page over https that contains a frame with a redirect. | 2050 // Visit a page over https that contains a frame with a redirect. |
1917 | 2051 |
1918 // XMLHttpRequest insecure content in synchronous mode. | 2052 // XMLHttpRequest insecure content in synchronous mode. |
1919 | 2053 |
1920 // XMLHttpRequest insecure content in asynchronous mode. | 2054 // XMLHttpRequest insecure content in asynchronous mode. |
1921 | 2055 |
1922 // XMLHttpRequest over bad ssl in synchronous mode. | 2056 // XMLHttpRequest over bad ssl in synchronous mode. |
1923 | 2057 |
1924 // XMLHttpRequest over OK ssl in synchronous mode. | 2058 // XMLHttpRequest over OK ssl in synchronous mode. |
OLD | NEW |