Chromium Code Reviews| 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/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 #include "chrome/common/chrome_paths.h" | 40 #include "chrome/common/chrome_paths.h" |
| 41 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
| 42 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
| 43 #include "chrome/test/base/in_process_browser_test.h" | 43 #include "chrome/test/base/in_process_browser_test.h" |
| 44 #include "chrome/test/base/ui_test_utils.h" | 44 #include "chrome/test/base/ui_test_utils.h" |
| 45 #include "components/content_settings/core/browser/host_content_settings_map.h" | 45 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 46 #include "components/security_interstitials/core/metrics_helper.h" | 46 #include "components/security_interstitials/core/metrics_helper.h" |
| 47 #include "components/variations/variations_associated_data.h" | 47 #include "components/variations/variations_associated_data.h" |
| 48 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 48 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 49 #include "content/public/browser/browser_context.h" | 49 #include "content/public/browser/browser_context.h" |
| 50 #include "content/public/browser/cert_store.h" | |
| 50 #include "content/public/browser/interstitial_page.h" | 51 #include "content/public/browser/interstitial_page.h" |
| 51 #include "content/public/browser/navigation_controller.h" | 52 #include "content/public/browser/navigation_controller.h" |
| 52 #include "content/public/browser/navigation_entry.h" | 53 #include "content/public/browser/navigation_entry.h" |
| 53 #include "content/public/browser/notification_service.h" | 54 #include "content/public/browser/notification_service.h" |
| 54 #include "content/public/browser/render_frame_host.h" | 55 #include "content/public/browser/render_frame_host.h" |
| 55 #include "content/public/browser/render_view_host.h" | 56 #include "content/public/browser/render_view_host.h" |
| 56 #include "content/public/browser/render_widget_host_view.h" | 57 #include "content/public/browser/render_widget_host_view.h" |
| 57 #include "content/public/browser/web_contents.h" | 58 #include "content/public/browser/web_contents.h" |
| 58 #include "content/public/browser/web_contents_observer.h" | 59 #include "content/public/browser/web_contents_observer.h" |
| 59 #include "content/public/common/security_style.h" | 60 #include "content/public/common/security_style.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 } | 231 } |
| 231 | 232 |
| 232 const content::WebContents* web_contents_; | 233 const content::WebContents* web_contents_; |
| 233 SSLErrorHandler::TimerStartedCallback callback_; | 234 SSLErrorHandler::TimerStartedCallback callback_; |
| 234 | 235 |
| 235 scoped_ptr<base::RunLoop> message_loop_runner_; | 236 scoped_ptr<base::RunLoop> message_loop_runner_; |
| 236 | 237 |
| 237 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver); | 238 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver); |
| 238 }; | 239 }; |
| 239 | 240 |
| 241 // Checks that two SSLStatuses will result in the same security UI: that | |
| 242 // is, the cert ids can differ as long as they refer to the same cert, | |
| 243 // and otherwise SSLStatus::Equals() must be true. | |
| 244 void CheckSSLStatusesEquals(const content::SSLStatus& one, | |
| 245 const content::SSLStatus& two) { | |
| 246 content::CertStore* cert_store = content::CertStore::GetInstance(); | |
| 247 scoped_refptr<net::X509Certificate> cert1; | |
| 248 scoped_refptr<net::X509Certificate> cert2; | |
| 249 cert_store->RetrieveCert(one.cert_id, &cert1); | |
| 250 cert_store->RetrieveCert(two.cert_id, &cert2); | |
| 251 EXPECT_TRUE(cert1); | |
|
meacer
2015/09/10 17:55:22
nit: EXPECT_TRUE(cert1 && cert2)?
estark
2015/09/11 05:22:52
Done.
| |
| 252 EXPECT_TRUE(cert1->Equals(cert2.get())); | |
| 253 | |
| 254 SSLStatus one_without_cert_id = one; | |
| 255 one_without_cert_id.cert_id = 0; | |
| 256 SSLStatus two_without_cert_id = two; | |
| 257 two_without_cert_id.cert_id = 0; | |
|
meacer
2015/09/10 17:55:22
nit: I'm wondering if these should be done in SSLS
estark
2015/09/10 17:59:28
The bummer is that SSLStatus is in content/public/
meacer
2015/09/10 18:02:23
Ah, right. I suppose we could make SSLStatus::Equa
| |
| 258 EXPECT_TRUE(one_without_cert_id.Equals(two_without_cert_id)); | |
| 259 } | |
| 260 | |
| 240 } // namespace | 261 } // namespace |
| 241 | 262 |
| 242 class SSLUITest | 263 class SSLUITest |
| 243 : public certificate_reporting_test_utils::CertificateReportingTest { | 264 : public certificate_reporting_test_utils::CertificateReportingTest { |
| 244 public: | 265 public: |
| 245 SSLUITest() | 266 SSLUITest() |
| 246 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, | 267 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, |
| 247 SSLOptions(SSLOptions::CERT_OK), | 268 SSLOptions(SSLOptions::CERT_OK), |
| 248 base::FilePath(kDocRoot)), | 269 base::FilePath(kDocRoot)), |
| 249 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, | 270 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, |
| (...skipping 2097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2347 | 2368 |
| 2348 ProceedThroughInterstitial(tab); | 2369 ProceedThroughInterstitial(tab); |
| 2349 EXPECT_TRUE(state->HasAllowException(https_server_host)); | 2370 EXPECT_TRUE(state->HasAllowException(https_server_host)); |
| 2350 | 2371 |
| 2351 ui_test_utils::NavigateToURL(browser(), | 2372 ui_test_utils::NavigateToURL(browser(), |
| 2352 https_server_.GetURL("files/ssl/google.html")); | 2373 https_server_.GetURL("files/ssl/google.html")); |
| 2353 ASSERT_FALSE(tab->GetInterstitialPage()); | 2374 ASSERT_FALSE(tab->GetInterstitialPage()); |
| 2354 EXPECT_FALSE(state->HasAllowException(https_server_host)); | 2375 EXPECT_FALSE(state->HasAllowException(https_server_host)); |
| 2355 } | 2376 } |
| 2356 | 2377 |
| 2378 // Tests that the SSLStatus of a navigation entry for an SSL | |
| 2379 // interstitial matches the navigation entry once the interstitial is | |
| 2380 // clicked through. https://crbug.com/529456 | |
| 2381 IN_PROC_BROWSER_TEST_F(SSLUITest, | |
| 2382 SSLStatusMatchesOnInterstitialAndAfterProceed) { | |
| 2383 ASSERT_TRUE(https_server_expired_.Start()); | |
| 2384 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2385 ASSERT_TRUE(tab); | |
| 2386 | |
| 2387 ui_test_utils::NavigateToURL( | |
| 2388 browser(), https_server_expired_.GetURL("files/ssl/google.html")); | |
| 2389 content::WaitForInterstitialAttach(tab); | |
| 2390 EXPECT_TRUE(tab->ShowingInterstitialPage()); | |
| 2391 | |
| 2392 content::NavigationEntry* entry = tab->GetController().GetActiveEntry(); | |
| 2393 ASSERT_TRUE(entry); | |
| 2394 content::SSLStatus interstitial_ssl_status = entry->GetSSL(); | |
| 2395 | |
| 2396 ProceedThroughInterstitial(tab); | |
| 2397 EXPECT_FALSE(tab->ShowingInterstitialPage()); | |
| 2398 entry = tab->GetController().GetActiveEntry(); | |
| 2399 ASSERT_TRUE(entry); | |
| 2400 | |
| 2401 content::SSLStatus after_interstitial_ssl_status = entry->GetSSL(); | |
| 2402 ASSERT_NO_FATAL_FAILURE(CheckSSLStatusesEquals(after_interstitial_ssl_status, | |
| 2403 interstitial_ssl_status)); | |
| 2404 } | |
| 2405 | |
| 2406 // As above, but for a bad clock interstitial. Tests that a clock | |
| 2407 // interstitial's SSLStatus matches the SSLStatus of the HTTPS page | |
| 2408 // after proceeding through a normal SSL interstitial. | |
| 2409 IN_PROC_BROWSER_TEST_F(SSLUITest, | |
| 2410 SSLStatusMatchesonClockInterstitialAndAfterProceed) { | |
| 2411 ASSERT_TRUE(https_server_expired_.Start()); | |
| 2412 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2413 ASSERT_TRUE(tab); | |
| 2414 | |
| 2415 // Set up the build and current clock times to be more than a year apart. | |
| 2416 base::SimpleTestClock mock_clock; | |
| 2417 mock_clock.SetNow(base::Time::NowFromSystemTime()); | |
| 2418 mock_clock.Advance(base::TimeDelta::FromDays(367)); | |
| 2419 SSLErrorHandler::SetClockForTest(&mock_clock); | |
| 2420 SSLErrorClassification::SetBuildTimeForTesting( | |
| 2421 base::Time::NowFromSystemTime()); | |
| 2422 | |
| 2423 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); | |
| 2424 content::WaitForInterstitialAttach(tab); | |
| 2425 InterstitialPage* clock_interstitial = tab->GetInterstitialPage(); | |
| 2426 ASSERT_TRUE(clock_interstitial); | |
| 2427 EXPECT_EQ(BadClockBlockingPage::kTypeForTesting, | |
| 2428 clock_interstitial->GetDelegateForTesting()->GetTypeForTesting()); | |
| 2429 | |
| 2430 // Grab the SSLStatus on the clock interstitial. | |
| 2431 content::NavigationEntry* entry = tab->GetController().GetActiveEntry(); | |
| 2432 ASSERT_TRUE(entry); | |
| 2433 content::SSLStatus clock_interstitial_ssl_status = entry->GetSSL(); | |
| 2434 | |
| 2435 // Put the clock back to normal, trigger a normal SSL interstitial, | |
| 2436 // and proceed through it. | |
| 2437 mock_clock.SetNow(base::Time::NowFromSystemTime()); | |
| 2438 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); | |
| 2439 content::WaitForInterstitialAttach(tab); | |
| 2440 InterstitialPage* ssl_interstitial = tab->GetInterstitialPage(); | |
| 2441 ASSERT_TRUE(ssl_interstitial); | |
| 2442 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | |
| 2443 ssl_interstitial->GetDelegateForTesting()->GetTypeForTesting()); | |
| 2444 ProceedThroughInterstitial(tab); | |
| 2445 EXPECT_FALSE(tab->ShowingInterstitialPage()); | |
| 2446 | |
| 2447 // Grab the SSLStatus from the page and check that it is the same as | |
| 2448 // on the clock interstitial. | |
| 2449 entry = tab->GetController().GetActiveEntry(); | |
| 2450 ASSERT_TRUE(entry); | |
| 2451 content::SSLStatus after_interstitial_ssl_status = entry->GetSSL(); | |
| 2452 ASSERT_NO_FATAL_FAILURE(CheckSSLStatusesEquals( | |
| 2453 after_interstitial_ssl_status, clock_interstitial_ssl_status)); | |
| 2454 } | |
| 2455 | |
| 2357 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest { | 2456 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest { |
| 2358 public: | 2457 public: |
| 2359 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {} | 2458 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {} |
| 2360 ~CommonNameMismatchBrowserTest() override {} | 2459 ~CommonNameMismatchBrowserTest() override {} |
| 2361 | 2460 |
| 2362 void SetUpCommandLine(base::CommandLine* command_line) override { | 2461 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 2363 // Enable finch experiment for SSL common name mismatch handling. | 2462 // Enable finch experiment for SSL common name mismatch handling. |
| 2364 command_line->AppendSwitchASCII(switches::kForceFieldTrials, | 2463 command_line->AppendSwitchASCII(switches::kForceFieldTrials, |
| 2365 "SSLCommonNameMismatchHandling/Enabled/"); | 2464 "SSLCommonNameMismatchHandling/Enabled/"); |
| 2366 } | 2465 } |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2734 | 2833 |
| 2735 // Visit a page over https that contains a frame with a redirect. | 2834 // Visit a page over https that contains a frame with a redirect. |
| 2736 | 2835 |
| 2737 // XMLHttpRequest insecure content in synchronous mode. | 2836 // XMLHttpRequest insecure content in synchronous mode. |
| 2738 | 2837 |
| 2739 // XMLHttpRequest insecure content in asynchronous mode. | 2838 // XMLHttpRequest insecure content in asynchronous mode. |
| 2740 | 2839 |
| 2741 // XMLHttpRequest over bad ssl in synchronous mode. | 2840 // XMLHttpRequest over bad ssl in synchronous mode. |
| 2742 | 2841 |
| 2743 // XMLHttpRequest over OK ssl in synchronous mode. | 2842 // XMLHttpRequest over OK ssl in synchronous mode. |
| OLD | NEW |