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 10 matching lines...) Expand all Loading... | |
| 21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" | 22 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" |
| 23 #include "chrome/browser/net/certificate_error_reporter.h" | 23 #include "chrome/browser/net/certificate_error_reporter.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ssl/cert_logger.pb.h" | 25 #include "chrome/browser/ssl/cert_logger.pb.h" |
| 26 #include "chrome/browser/ssl/cert_report_helper.h" | 26 #include "chrome/browser/ssl/cert_report_helper.h" |
| 27 #include "chrome/browser/ssl/cert_verifier_browser_test.h" | 27 #include "chrome/browser/ssl/cert_verifier_browser_test.h" |
| 28 #include "chrome/browser/ssl/certificate_error_report.h" | 28 #include "chrome/browser/ssl/certificate_error_report.h" |
| 29 #include "chrome/browser/ssl/certificate_reporting_test_utils.h" | 29 #include "chrome/browser/ssl/certificate_reporting_test_utils.h" |
| 30 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" | 30 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
| 31 #include "chrome/browser/ssl/common_name_mismatch_handler.h" | |
| 31 #include "chrome/browser/ssl/ssl_blocking_page.h" | 32 #include "chrome/browser/ssl/ssl_blocking_page.h" |
| 33 #include "chrome/browser/ssl/ssl_error_handler.h" | |
| 32 #include "chrome/browser/ui/browser.h" | 34 #include "chrome/browser/ui/browser.h" |
| 33 #include "chrome/browser/ui/browser_commands.h" | 35 #include "chrome/browser/ui/browser_commands.h" |
| 34 #include "chrome/browser/ui/browser_navigator.h" | 36 #include "chrome/browser/ui/browser_navigator.h" |
| 35 #include "chrome/browser/ui/browser_tabstrip.h" | 37 #include "chrome/browser/ui/browser_tabstrip.h" |
| 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 38 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 37 #include "chrome/common/chrome_paths.h" | 39 #include "chrome/common/chrome_paths.h" |
| 38 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
| 39 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
| 40 #include "chrome/test/base/in_process_browser_test.h" | 42 #include "chrome/test/base/in_process_browser_test.h" |
| 41 #include "chrome/test/base/ui_test_utils.h" | 43 #include "chrome/test/base/ui_test_utils.h" |
| 42 #include "components/content_settings/core/browser/host_content_settings_map.h" | 44 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 43 #include "components/security_interstitials/core/metrics_helper.h" | 45 #include "components/security_interstitials/core/metrics_helper.h" |
| 44 #include "components/variations/variations_associated_data.h" | 46 #include "components/variations/variations_associated_data.h" |
| 45 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 47 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 46 #include "content/public/browser/browser_context.h" | 48 #include "content/public/browser/browser_context.h" |
| 47 #include "content/public/browser/interstitial_page.h" | 49 #include "content/public/browser/interstitial_page.h" |
| 48 #include "content/public/browser/navigation_controller.h" | 50 #include "content/public/browser/navigation_controller.h" |
| 49 #include "content/public/browser/navigation_entry.h" | 51 #include "content/public/browser/navigation_entry.h" |
| 50 #include "content/public/browser/notification_service.h" | 52 #include "content/public/browser/notification_service.h" |
| 51 #include "content/public/browser/render_frame_host.h" | 53 #include "content/public/browser/render_frame_host.h" |
| 52 #include "content/public/browser/render_view_host.h" | 54 #include "content/public/browser/render_view_host.h" |
| 53 #include "content/public/browser/render_widget_host_view.h" | 55 #include "content/public/browser/render_widget_host_view.h" |
| 54 #include "content/public/browser/web_contents.h" | 56 #include "content/public/browser/web_contents.h" |
| 55 #include "content/public/browser/web_contents_observer.h" | 57 #include "content/public/browser/web_contents_observer.h" |
| 56 #include "content/public/common/security_style.h" | 58 #include "content/public/common/security_style.h" |
| 57 #include "content/public/common/ssl_status.h" | 59 #include "content/public/common/ssl_status.h" |
| 58 #include "content/public/test/browser_test_utils.h" | 60 #include "content/public/test/browser_test_utils.h" |
| 59 #include "content/public/test/download_test_observer.h" | 61 #include "content/public/test/download_test_observer.h" |
| 62 #include "content/public/test/test_navigation_observer.h" | |
| 60 #include "content/public/test/test_renderer_host.h" | 63 #include "content/public/test/test_renderer_host.h" |
| 61 #include "net/base/host_port_pair.h" | 64 #include "net/base/host_port_pair.h" |
| 62 #include "net/base/net_errors.h" | 65 #include "net/base/net_errors.h" |
| 63 #include "net/base/test_data_directory.h" | 66 #include "net/base/test_data_directory.h" |
| 64 #include "net/cert/cert_status_flags.h" | 67 #include "net/cert/cert_status_flags.h" |
| 65 #include "net/cert/mock_cert_verifier.h" | 68 #include "net/cert/mock_cert_verifier.h" |
| 66 #include "net/cert/x509_certificate.h" | 69 #include "net/cert/x509_certificate.h" |
| 70 #include "net/dns/mock_host_resolver.h" | |
| 67 #include "net/ssl/ssl_info.h" | 71 #include "net/ssl/ssl_info.h" |
| 72 #include "net/test/cert_test_util.h" | |
| 68 #include "net/test/spawned_test_server/spawned_test_server.h" | 73 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 74 #include "net/test/test_certificate_data.h" | |
| 69 #include "net/url_request/url_request_context.h" | 75 #include "net/url_request/url_request_context.h" |
| 70 | 76 |
| 71 #if defined(USE_NSS_CERTS) | 77 #if defined(USE_NSS_CERTS) |
| 72 #include "chrome/browser/net/nss_context.h" | 78 #include "chrome/browser/net/nss_context.h" |
| 73 #include "net/base/crypto_module.h" | 79 #include "net/base/crypto_module.h" |
| 74 #include "net/cert/nss_cert_database.h" | 80 #include "net/cert/nss_cert_database.h" |
| 75 #endif // defined(USE_NSS_CERTS) | 81 #endif // defined(USE_NSS_CERTS) |
| 76 | 82 |
| 77 using base::ASCIIToUTF16; | 83 using base::ASCIIToUTF16; |
| 78 using chrome_browser_interstitials::SecurityInterstitialIDNTest; | 84 using chrome_browser_interstitials::SecurityInterstitialIDNTest; |
| (...skipping 2177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2256 | 2262 |
| 2257 ProceedThroughInterstitial(tab); | 2263 ProceedThroughInterstitial(tab); |
| 2258 EXPECT_TRUE(state->HasAllowException(https_server_host)); | 2264 EXPECT_TRUE(state->HasAllowException(https_server_host)); |
| 2259 | 2265 |
| 2260 ui_test_utils::NavigateToURL(browser(), | 2266 ui_test_utils::NavigateToURL(browser(), |
| 2261 https_server_.GetURL("files/ssl/google.html")); | 2267 https_server_.GetURL("files/ssl/google.html")); |
| 2262 ASSERT_FALSE(tab->GetInterstitialPage()); | 2268 ASSERT_FALSE(tab->GetInterstitialPage()); |
| 2263 EXPECT_FALSE(state->HasAllowException(https_server_host)); | 2269 EXPECT_FALSE(state->HasAllowException(https_server_host)); |
| 2264 } | 2270 } |
| 2265 | 2271 |
| 2272 typedef CertVerifierBrowserTest CommonNameMismatchBrowserTest; | |
| 2273 | |
| 2274 // Visit the URL www.mail.example.com on a server that presents a valid | |
| 2275 // certificate for mail.example.com. Verify that the page navigates to | |
| 2276 // mail.example.com. | |
| 2277 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
| 2278 ShouldShowWWWSubdomainMismatchInterstitial) { | |
| 2279 net::SpawnedTestServer https_server_example_domain_( | |
| 2280 net::SpawnedTestServer::TYPE_HTTPS, | |
| 2281 net::SpawnedTestServer::SSLOptions( | |
| 2282 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
| 2283 base::FilePath(kDocRoot)); | |
| 2284 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2285 | |
| 2286 host_resolver()->AddRule( | |
| 2287 "mail.example.com", https_server_example_domain_.host_port_pair().host()); | |
| 2288 host_resolver()->AddRule( | |
| 2289 "www.mail.example.com", | |
| 2290 https_server_example_domain_.host_port_pair().host()); | |
| 2291 | |
| 2292 // The pem file does not matter. | |
| 2293 scoped_refptr<net::X509Certificate> cert1 = | |
| 2294 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
| 2295 | |
| 2296 // Use the "spdy_pooling.pem" cert which has "mail.example.com" | |
| 2297 // as one of its SANs. | |
| 2298 net::CertVerifyResult verify_result; | |
| 2299 verify_result.verified_cert = | |
| 2300 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2301 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
| 2302 | |
| 2303 // Request to "www.test.example.com" should result in | |
| 2304 // |net::ERR_CERT_COMMON_NAME_INVALID| error. | |
| 2305 mock_cert_verifier()->AddResultForCertAndHost( | |
| 2306 cert1.get(), "www.mail.example.com", verify_result, | |
| 2307 net::ERR_CERT_COMMON_NAME_INVALID); | |
| 2308 | |
| 2309 net::CertVerifyResult verify_result_valid; | |
| 2310 verify_result_valid.verified_cert = | |
| 2311 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2312 // Request to "www.test.example.com" should not result in any error. | |
| 2313 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "mail.example.com", | |
| 2314 verify_result_valid, net::OK); | |
| 2315 | |
| 2316 // The path does not matter. | |
| 2317 GURL https_server_url = | |
| 2318 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2319 GURL::Replacements replacements; | |
| 2320 replacements.SetHostStr("www.mail.example.com"); | |
| 2321 GURL https_server_mismatched_url = | |
| 2322 https_server_url.ReplaceComponents(replacements); | |
| 2323 | |
| 2324 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2325 content::TestNavigationObserver observer(contents, 2); | |
| 2326 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); | |
| 2327 observer.Wait(); | |
| 2328 | |
| 2329 CheckSecurityState(contents, CertError::NONE, | |
| 2330 content::SECURITY_STYLE_AUTHENTICATED, AuthState::NONE); | |
| 2331 replacements.SetHostStr("mail.example.com"); | |
| 2332 GURL https_server_new_url = https_server_url.ReplaceComponents(replacements); | |
| 2333 // Verify that the current URL is the suggested URL. | |
| 2334 EXPECT_EQ(https_server_new_url.spec(), | |
| 2335 contents->GetLastCommittedURL().spec()); | |
| 2336 } | |
| 2337 | |
| 2338 // Visit the URL example.org on a server that presents a valid certificate | |
| 2339 // for www.example.org. Verify that the page redirects to www.example.org. | |
| 2340 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
| 2341 CheckWWWSubdomainMismatchInverse) { | |
| 2342 net::SpawnedTestServer https_server_example_domain_( | |
| 2343 net::SpawnedTestServer::TYPE_HTTPS, | |
| 2344 net::SpawnedTestServer::SSLOptions( | |
| 2345 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
| 2346 base::FilePath(kDocRoot)); | |
| 2347 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2348 | |
| 2349 host_resolver()->AddRule( | |
| 2350 "www.example.org", https_server_example_domain_.host_port_pair().host()); | |
| 2351 host_resolver()->AddRule( | |
| 2352 "example.org", https_server_example_domain_.host_port_pair().host()); | |
| 2353 | |
| 2354 scoped_refptr<net::X509Certificate> cert1 = | |
| 2355 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
| 2356 | |
| 2357 net::CertVerifyResult verify_result; | |
| 2358 verify_result.verified_cert = | |
| 2359 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2360 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
| 2361 | |
| 2362 mock_cert_verifier()->AddResultForCertAndHost( | |
| 2363 cert1.get(), "example.org", verify_result, | |
| 2364 net::ERR_CERT_COMMON_NAME_INVALID); | |
| 2365 | |
| 2366 net::CertVerifyResult verify_result_valid; | |
| 2367 verify_result_valid.verified_cert = | |
| 2368 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2369 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "www.example.org", | |
| 2370 verify_result_valid, net::OK); | |
| 2371 | |
| 2372 GURL https_server_url = | |
| 2373 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2374 GURL::Replacements replacements; | |
| 2375 replacements.SetHostStr("example.org"); | |
| 2376 GURL https_server_mismatched_url = | |
| 2377 https_server_url.ReplaceComponents(replacements); | |
| 2378 | |
| 2379 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2380 content::TestNavigationObserver observer(contents, 2); | |
| 2381 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); | |
| 2382 observer.Wait(); | |
| 2383 | |
| 2384 CheckSecurityState(contents, CertError::NONE, | |
| 2385 content::SECURITY_STYLE_AUTHENTICATED, AuthState::NONE); | |
| 2386 } | |
| 2387 | |
| 2388 // This observer waits for the SSLErrorHandler to start an interstitial timer | |
| 2389 // for the given web contents. | |
| 2390 class SSLInterstitialTimerObserver { | |
|
Ryan Sleevi
2015/08/14 00:40:17
ODR VIOLATION DANGER: Putting this helper in the m
Bhanu Dev
2015/08/15 00:18:53
Done.
| |
| 2391 public: | |
| 2392 explicit SSLInterstitialTimerObserver(content::WebContents* web_contents); | |
| 2393 ~SSLInterstitialTimerObserver(); | |
| 2394 | |
| 2395 // Waits until the interstitial delay timer in SSLErrorHandler is started. | |
| 2396 void WaitForTimerStarted(); | |
| 2397 | |
| 2398 private: | |
| 2399 void OnTimerStarted(content::WebContents* web_contents); | |
| 2400 | |
| 2401 const content::WebContents* web_contents_; | |
| 2402 SSLErrorHandler::TimerStartedCallback callback_; | |
| 2403 | |
| 2404 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
|
Ryan Sleevi
2015/08/14 00:40:17
Wow, I'm surprised jam@ hasn't nuked this.
base::
Bhanu Dev
2015/08/15 00:18:53
Done.
| |
| 2405 | |
| 2406 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver); | |
| 2407 }; | |
| 2408 | |
| 2409 SSLInterstitialTimerObserver::SSLInterstitialTimerObserver( | |
| 2410 content::WebContents* web_contents) | |
| 2411 : web_contents_(web_contents), | |
| 2412 message_loop_runner_(new content::MessageLoopRunner) { | |
| 2413 callback_ = base::Bind(&SSLInterstitialTimerObserver::OnTimerStarted, | |
| 2414 base::Unretained(this)); | |
| 2415 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(&callback_); | |
| 2416 } | |
| 2417 | |
| 2418 SSLInterstitialTimerObserver::~SSLInterstitialTimerObserver() { | |
| 2419 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(nullptr); | |
| 2420 } | |
| 2421 | |
| 2422 void SSLInterstitialTimerObserver::WaitForTimerStarted() { | |
| 2423 message_loop_runner_->Run(); | |
| 2424 } | |
| 2425 | |
| 2426 void SSLInterstitialTimerObserver::OnTimerStarted( | |
| 2427 content::WebContents* web_contents) { | |
| 2428 if (web_contents_ == web_contents && message_loop_runner_.get()) | |
| 2429 message_loop_runner_->Quit(); | |
| 2430 } | |
| 2431 | |
| 2432 // Tests this scenario: | |
| 2433 // - |CommonNameMismatchHandler| does not give a callback as it's set into the | |
| 2434 // state |IGNORE_REQUESTS_FOR_TESTING|. So no suggested URL check result can | |
| 2435 // arrive. | |
| 2436 // - A cert error triggers an interstitial timer with a very long timeout. | |
| 2437 // - No suggested URL check results arrive, causing the tab to appear as loading | |
| 2438 // indefinitely (also because the timer has a long timeout). | |
| 2439 // - Stopping the page load shouldn't result in any interstitials. | |
| 2440 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
| 2441 InterstitialStopNavigationWhileLoading) { | |
| 2442 net::SpawnedTestServer https_server_example_domain_( | |
| 2443 net::SpawnedTestServer::TYPE_HTTPS, | |
| 2444 net::SpawnedTestServer::SSLOptions( | |
| 2445 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
| 2446 base::FilePath(kDocRoot)); | |
| 2447 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2448 | |
| 2449 host_resolver()->AddRule( | |
| 2450 "mail.example.com", https_server_example_domain_.host_port_pair().host()); | |
| 2451 host_resolver()->AddRule( | |
| 2452 "www.mail.example.com", | |
| 2453 https_server_example_domain_.host_port_pair().host()); | |
| 2454 | |
| 2455 scoped_refptr<net::X509Certificate> cert1 = | |
| 2456 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
| 2457 | |
| 2458 net::CertVerifyResult verify_result; | |
| 2459 verify_result.verified_cert = | |
| 2460 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2461 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
| 2462 | |
| 2463 mock_cert_verifier()->AddResultForCertAndHost( | |
| 2464 cert1.get(), "www.mail.example.com", verify_result, | |
| 2465 net::ERR_CERT_COMMON_NAME_INVALID); | |
| 2466 | |
| 2467 net::CertVerifyResult verify_result_valid; | |
| 2468 verify_result_valid.verified_cert = | |
| 2469 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2470 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "mail.example.com", | |
| 2471 verify_result_valid, net::OK); | |
| 2472 | |
| 2473 GURL https_server_url = | |
| 2474 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2475 GURL::Replacements replacements; | |
| 2476 replacements.SetHostStr("www.mail.example.com"); | |
| 2477 GURL https_server_mismatched_url = | |
| 2478 https_server_url.ReplaceComponents(replacements); | |
| 2479 | |
| 2480 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2481 CommonNameMismatchHandler::set_state_for_testing( | |
| 2482 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
| 2483 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 2484 | |
| 2485 ui_test_utils::NavigateToURLWithDisposition( | |
| 2486 browser(), https_server_mismatched_url, CURRENT_TAB, | |
| 2487 ui_test_utils::BROWSER_TEST_NONE); | |
| 2488 interstitial_timer_observer.WaitForTimerStarted(); | |
| 2489 | |
| 2490 EXPECT_TRUE(contents->IsLoading()); | |
| 2491 content::WindowedNotificationObserver observer( | |
| 2492 content::NOTIFICATION_LOAD_STOP, | |
| 2493 content::NotificationService::AllSources()); | |
| 2494 contents->Stop(); | |
| 2495 observer.Wait(); | |
| 2496 | |
| 2497 SSLErrorHandler* ssl_error_handler = | |
| 2498 SSLErrorHandler::FromWebContents(contents); | |
| 2499 // Make sure that the |SSLErrorHandler| is deleted. | |
| 2500 EXPECT_FALSE(ssl_error_handler); | |
| 2501 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 2502 EXPECT_FALSE(contents->IsLoading()); | |
| 2503 } | |
| 2504 | |
| 2505 // Same as above, but instead of stopping, the loading page is reloaded. The end | |
| 2506 // result is the same. (i.e. page load stops, no interstitials shown) | |
| 2507 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
| 2508 InterstitialReloadNavigationWhileLoading) { | |
| 2509 net::SpawnedTestServer https_server_example_domain_( | |
| 2510 net::SpawnedTestServer::TYPE_HTTPS, | |
| 2511 net::SpawnedTestServer::SSLOptions( | |
| 2512 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
| 2513 base::FilePath(kDocRoot)); | |
| 2514 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2515 | |
| 2516 host_resolver()->AddRule( | |
| 2517 "mail.example.com", https_server_example_domain_.host_port_pair().host()); | |
| 2518 host_resolver()->AddRule( | |
| 2519 "www.mail.example.com", | |
| 2520 https_server_example_domain_.host_port_pair().host()); | |
| 2521 | |
| 2522 scoped_refptr<net::X509Certificate> cert1 = | |
| 2523 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
| 2524 | |
| 2525 net::CertVerifyResult verify_result; | |
| 2526 verify_result.verified_cert = | |
| 2527 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2528 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
| 2529 | |
| 2530 mock_cert_verifier()->AddResultForCertAndHost( | |
| 2531 cert1.get(), "www.mail.example.com", verify_result, | |
| 2532 net::ERR_CERT_COMMON_NAME_INVALID); | |
| 2533 | |
| 2534 net::CertVerifyResult verify_result_valid; | |
| 2535 verify_result_valid.verified_cert = | |
| 2536 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2537 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "mail.example.com", | |
| 2538 verify_result_valid, net::OK); | |
| 2539 | |
| 2540 GURL https_server_url = | |
| 2541 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2542 GURL::Replacements replacements; | |
| 2543 replacements.SetHostStr("www.mail.example.com"); | |
| 2544 GURL https_server_mismatched_url = | |
| 2545 https_server_url.ReplaceComponents(replacements); | |
| 2546 | |
| 2547 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2548 CommonNameMismatchHandler::set_state_for_testing( | |
| 2549 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
| 2550 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 2551 | |
| 2552 ui_test_utils::NavigateToURLWithDisposition( | |
| 2553 browser(), https_server_mismatched_url, CURRENT_TAB, | |
| 2554 ui_test_utils::BROWSER_TEST_NONE); | |
| 2555 interstitial_timer_observer.WaitForTimerStarted(); | |
| 2556 | |
| 2557 EXPECT_TRUE(contents->IsLoading()); | |
| 2558 content::TestNavigationObserver observer(contents, 1); | |
| 2559 chrome::Reload(browser(), CURRENT_TAB); | |
| 2560 observer.Wait(); | |
| 2561 | |
| 2562 SSLErrorHandler* ssl_error_handler = | |
| 2563 SSLErrorHandler::FromWebContents(contents); | |
| 2564 // Make sure that the |SSLErrorHandler| is deleted. | |
| 2565 EXPECT_FALSE(ssl_error_handler); | |
| 2566 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 2567 EXPECT_FALSE(contents->IsLoading()); | |
| 2568 } | |
| 2569 | |
| 2570 // Same as above, but instead of reloading, the page is navigated away. The | |
| 2571 // new page should load, and no interstitials should be shown. | |
| 2572 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
| 2573 InterstitialNavigateAwayWhileLoading) { | |
| 2574 net::SpawnedTestServer https_server_example_domain_( | |
| 2575 net::SpawnedTestServer::TYPE_HTTPS, | |
| 2576 net::SpawnedTestServer::SSLOptions( | |
| 2577 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
| 2578 base::FilePath(kDocRoot)); | |
| 2579 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2580 | |
| 2581 host_resolver()->AddRule( | |
| 2582 "mail.example.com", https_server_example_domain_.host_port_pair().host()); | |
| 2583 host_resolver()->AddRule( | |
| 2584 "www.mail.example.com", | |
| 2585 https_server_example_domain_.host_port_pair().host()); | |
| 2586 | |
| 2587 scoped_refptr<net::X509Certificate> cert1 = | |
| 2588 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
| 2589 | |
| 2590 net::CertVerifyResult verify_result; | |
| 2591 verify_result.verified_cert = | |
| 2592 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2593 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
| 2594 | |
| 2595 mock_cert_verifier()->AddResultForCertAndHost( | |
| 2596 cert1.get(), "www.mail.example.com", verify_result, | |
| 2597 net::ERR_CERT_COMMON_NAME_INVALID); | |
| 2598 | |
| 2599 net::CertVerifyResult verify_result_valid; | |
| 2600 verify_result_valid.verified_cert = | |
| 2601 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2602 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "mail.example.com", | |
| 2603 verify_result_valid, net::OK); | |
| 2604 | |
| 2605 GURL https_server_url = | |
| 2606 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2607 GURL::Replacements replacements; | |
| 2608 replacements.SetHostStr("www.mail.example.com"); | |
| 2609 GURL https_server_mismatched_url = | |
| 2610 https_server_url.ReplaceComponents(replacements); | |
| 2611 | |
| 2612 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2613 CommonNameMismatchHandler::set_state_for_testing( | |
| 2614 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
| 2615 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 2616 | |
| 2617 ui_test_utils::NavigateToURLWithDisposition( | |
| 2618 browser(), https_server_mismatched_url, CURRENT_TAB, | |
| 2619 ui_test_utils::BROWSER_TEST_NONE); | |
| 2620 interstitial_timer_observer.WaitForTimerStarted(); | |
| 2621 | |
| 2622 EXPECT_TRUE(contents->IsLoading()); | |
| 2623 content::TestNavigationObserver observer(contents, 1); | |
| 2624 browser()->OpenURL(content::OpenURLParams(GURL("https://google.com"), | |
| 2625 content::Referrer(), CURRENT_TAB, | |
| 2626 ui::PAGE_TRANSITION_TYPED, false)); | |
| 2627 observer.Wait(); | |
| 2628 | |
| 2629 SSLErrorHandler* ssl_error_handler = | |
| 2630 SSLErrorHandler::FromWebContents(contents); | |
| 2631 // Make sure that the |SSLErrorHandler| is deleted. | |
| 2632 EXPECT_FALSE(ssl_error_handler); | |
| 2633 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 2634 EXPECT_FALSE(contents->IsLoading()); | |
| 2635 } | |
| 2636 | |
| 2266 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { | 2637 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { |
| 2267 protected: | 2638 protected: |
| 2268 // SecurityInterstitialIDNTest implementation | 2639 // SecurityInterstitialIDNTest implementation |
| 2269 SecurityInterstitialPage* CreateInterstitial( | 2640 SecurityInterstitialPage* CreateInterstitial( |
| 2270 content::WebContents* contents, | 2641 content::WebContents* contents, |
| 2271 const GURL& request_url) const override { | 2642 const GURL& request_url) const override { |
| 2272 net::SSLInfo ssl_info; | 2643 net::SSLInfo ssl_info; |
| 2273 ssl_info.cert = new net::X509Certificate( | 2644 ssl_info.cert = new net::X509Certificate( |
| 2274 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); | 2645 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); |
| 2275 return new SSLBlockingPage( | 2646 return new SSLBlockingPage( |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2306 | 2677 |
| 2307 // Visit a page over https that contains a frame with a redirect. | 2678 // Visit a page over https that contains a frame with a redirect. |
| 2308 | 2679 |
| 2309 // XMLHttpRequest insecure content in synchronous mode. | 2680 // XMLHttpRequest insecure content in synchronous mode. |
| 2310 | 2681 |
| 2311 // XMLHttpRequest insecure content in asynchronous mode. | 2682 // XMLHttpRequest insecure content in asynchronous mode. |
| 2312 | 2683 |
| 2313 // XMLHttpRequest over bad ssl in synchronous mode. | 2684 // XMLHttpRequest over bad ssl in synchronous mode. |
| 2314 | 2685 |
| 2315 // XMLHttpRequest over OK ssl in synchronous mode. | 2686 // XMLHttpRequest over OK ssl in synchronous mode. |
| OLD | NEW |