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.test.example.com on a server that presents a valid | |
| 2275 // certificate for test.example.com. Verify that the common name mismatch | |
| 2276 // interstitial is displayed with a link to test.example.com. Click the | |
| 2277 // suggested URL link and make sure the page navigates to suggested URL. | |
| 2278 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
| 2279 ShouldShowWWWSubdomainMismatchInterstitial) { | |
| 2280 net::SpawnedTestServer https_server_example_domain_( | |
| 2281 net::SpawnedTestServer::TYPE_HTTPS, | |
| 2282 net::SpawnedTestServer::SSLOptions( | |
| 2283 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
| 2284 base::FilePath(kDocRoot)); | |
| 2285 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2286 | |
| 2287 host_resolver()->AddRule( | |
| 2288 "mail.example.com", https_server_example_domain_.host_port_pair().host()); | |
| 2289 host_resolver()->AddRule( | |
| 2290 "www.mail.example.com", | |
| 2291 https_server_example_domain_.host_port_pair().host()); | |
| 2292 | |
| 2293 scoped_refptr<net::X509Certificate> cert1 = | |
| 2294 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
| 2295 | |
| 2296 net::CertVerifyResult verify_result; | |
| 2297 verify_result.verified_cert = | |
| 2298 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
|
meacer
2015/08/12 22:32:56
Can you add a comment here saying the pem file doe
Bhanu Dev
2015/08/13 01:28:00
Done.
The file path matters here, the file path d
| |
| 2299 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
| 2300 | |
| 2301 // Request to "www.test.example.com" should result in | |
| 2302 // |net::ERR_CERT_COMMON_NAME_INVALID| error. | |
| 2303 mock_cert_verifier()->AddResultForCertAndHost( | |
| 2304 cert1.get(), "www.mail.example.com", verify_result, | |
| 2305 net::ERR_CERT_COMMON_NAME_INVALID); | |
| 2306 | |
| 2307 net::CertVerifyResult verify_result_valid; | |
| 2308 verify_result_valid.verified_cert = | |
| 2309 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2310 // Request to "www.test.example.com" should not result in any error. | |
| 2311 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "mail.example.com", | |
| 2312 verify_result_valid, net::OK); | |
| 2313 | |
| 2314 // The path does not matter. | |
| 2315 GURL https_server_url = | |
| 2316 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2317 GURL::Replacements replacements; | |
| 2318 replacements.SetHostStr("www.mail.example.com"); | |
| 2319 GURL https_server_mismatched_url = | |
| 2320 https_server_url.ReplaceComponents(replacements); | |
| 2321 | |
| 2322 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2323 content::TestNavigationObserver observer(contents, 2); | |
| 2324 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); | |
| 2325 observer.Wait(); | |
| 2326 | |
| 2327 CheckSecurityState(contents, CertError::NONE, | |
| 2328 content::SECURITY_STYLE_AUTHENTICATED, AuthState::NONE); | |
| 2329 replacements.SetHostStr("mail.example.com"); | |
| 2330 GURL https_server_new_url = https_server_url.ReplaceComponents(replacements); | |
| 2331 // Verify that the current URL is the suggested URL. | |
| 2332 EXPECT_EQ(https_server_new_url.spec(), | |
| 2333 contents->GetLastCommittedURL().spec()); | |
| 2334 } | |
| 2335 | |
| 2336 // Visit the URL example.org on a server that presents a valid certificate | |
| 2337 // for www.example.org. Verify that the common name mismatch interstitial is | |
| 2338 // displayed with a link to www.example.org. | |
| 2339 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
| 2340 CheckWWWSubdomainMismatchInverse) { | |
| 2341 net::SpawnedTestServer https_server_example_domain_( | |
| 2342 net::SpawnedTestServer::TYPE_HTTPS, | |
| 2343 net::SpawnedTestServer::SSLOptions( | |
| 2344 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
| 2345 base::FilePath(kDocRoot)); | |
| 2346 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2347 | |
| 2348 host_resolver()->AddRule( | |
| 2349 "www.example.org", https_server_example_domain_.host_port_pair().host()); | |
| 2350 host_resolver()->AddRule( | |
| 2351 "example.org", https_server_example_domain_.host_port_pair().host()); | |
| 2352 | |
| 2353 scoped_refptr<net::X509Certificate> cert1 = | |
| 2354 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
| 2355 | |
| 2356 net::CertVerifyResult verify_result; | |
| 2357 verify_result.verified_cert = | |
| 2358 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2359 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
| 2360 | |
| 2361 mock_cert_verifier()->AddResultForCertAndHost( | |
| 2362 cert1.get(), "example.org", verify_result, | |
| 2363 net::ERR_CERT_COMMON_NAME_INVALID); | |
| 2364 | |
| 2365 net::CertVerifyResult verify_result_valid; | |
| 2366 verify_result_valid.verified_cert = | |
| 2367 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2368 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "www.example.org", | |
| 2369 verify_result_valid, net::OK); | |
| 2370 | |
| 2371 GURL https_server_url = | |
| 2372 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2373 GURL::Replacements replacements; | |
| 2374 replacements.SetHostStr("example.org"); | |
| 2375 GURL https_server_mismatched_url = | |
| 2376 https_server_url.ReplaceComponents(replacements); | |
| 2377 | |
| 2378 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2379 content::TestNavigationObserver observer(contents, 2); | |
| 2380 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); | |
| 2381 observer.Wait(); | |
| 2382 | |
| 2383 CheckSecurityState(contents, CertError::NONE, | |
| 2384 content::SECURITY_STYLE_AUTHENTICATED, AuthState::NONE); | |
| 2385 } | |
| 2386 | |
| 2387 // This observer waits for the SSLErrorHandler to start an interstitial timer | |
| 2388 // for the given web contents. | |
| 2389 class SSLInterstitialTimerObserver { | |
| 2390 public: | |
| 2391 explicit SSLInterstitialTimerObserver(content::WebContents* web_contents); | |
| 2392 ~SSLInterstitialTimerObserver(); | |
| 2393 | |
| 2394 // Waits until the interstitial delay timer in SSLErrorHandler is started. | |
| 2395 void WaitForTimerStarted(); | |
| 2396 | |
| 2397 private: | |
| 2398 void OnTimerStarted(content::WebContents* web_contents); | |
| 2399 | |
| 2400 const content::WebContents* web_contents_; | |
| 2401 SSLErrorHandler::TimerStartedCallback callback_; | |
| 2402 | |
| 2403 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 2404 | |
| 2405 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver); | |
| 2406 }; | |
| 2407 | |
| 2408 SSLInterstitialTimerObserver::SSLInterstitialTimerObserver( | |
| 2409 content::WebContents* web_contents) | |
| 2410 : web_contents_(web_contents), | |
| 2411 message_loop_runner_(new content::MessageLoopRunner) { | |
| 2412 callback_ = base::Bind(&SSLInterstitialTimerObserver::OnTimerStarted, | |
| 2413 base::Unretained(this)); | |
| 2414 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(&callback_); | |
| 2415 } | |
| 2416 | |
| 2417 SSLInterstitialTimerObserver::~SSLInterstitialTimerObserver() { | |
| 2418 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(nullptr); | |
| 2419 } | |
| 2420 | |
| 2421 void SSLInterstitialTimerObserver::WaitForTimerStarted() { | |
| 2422 message_loop_runner_->Run(); | |
| 2423 } | |
| 2424 | |
| 2425 void SSLInterstitialTimerObserver::OnTimerStarted( | |
| 2426 content::WebContents* web_contents) { | |
| 2427 if (web_contents_ == web_contents && message_loop_runner_.get()) | |
| 2428 message_loop_runner_->Quit(); | |
| 2429 } | |
| 2430 | |
| 2431 // Tests this scenario: | |
| 2432 // - |CommonNameMismatchHandler| does not give a callback as it's set into the | |
| 2433 // state |IGNORE_REQUESTS_FOR_TESTING|. So no suggested URL check result can | |
| 2434 // arrive. | |
| 2435 // - A cert error triggers an interstitial timer with a very long timeout. | |
| 2436 // - No suggested URL check results arrive, causing the tab to appear as loading | |
| 2437 // indefinitely (also because the timer has a long timeout). | |
| 2438 // - Stopping the page load shouldn't result in any interstitials. | |
| 2439 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
| 2440 InterstitialStopNavigationWhileLoading) { | |
| 2441 net::SpawnedTestServer https_server_example_domain_( | |
| 2442 net::SpawnedTestServer::TYPE_HTTPS, | |
| 2443 net::SpawnedTestServer::SSLOptions( | |
| 2444 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
| 2445 base::FilePath(kDocRoot)); | |
| 2446 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2447 | |
| 2448 host_resolver()->AddRule( | |
| 2449 "mail.example.com", https_server_example_domain_.host_port_pair().host()); | |
| 2450 host_resolver()->AddRule( | |
| 2451 "www.mail.example.com", | |
| 2452 https_server_example_domain_.host_port_pair().host()); | |
| 2453 | |
| 2454 scoped_refptr<net::X509Certificate> cert1 = | |
| 2455 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
| 2456 | |
| 2457 net::CertVerifyResult verify_result; | |
| 2458 verify_result.verified_cert = | |
| 2459 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2460 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
| 2461 | |
| 2462 mock_cert_verifier()->AddResultForCertAndHost( | |
| 2463 cert1.get(), "www.mail.example.com", verify_result, | |
| 2464 net::ERR_CERT_COMMON_NAME_INVALID); | |
| 2465 | |
| 2466 net::CertVerifyResult verify_result_valid; | |
| 2467 verify_result_valid.verified_cert = | |
| 2468 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2469 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "mail.example.com", | |
| 2470 verify_result_valid, net::OK); | |
| 2471 | |
| 2472 GURL https_server_url = | |
| 2473 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2474 GURL::Replacements replacements; | |
| 2475 replacements.SetHostStr("www.mail.example.com"); | |
| 2476 GURL https_server_mismatched_url = | |
| 2477 https_server_url.ReplaceComponents(replacements); | |
| 2478 | |
| 2479 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2480 CommonNameMismatchHandler::set_state_for_testing( | |
| 2481 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
| 2482 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 2483 | |
| 2484 ui_test_utils::NavigateToURLWithDisposition( | |
| 2485 browser(), https_server_mismatched_url, CURRENT_TAB, | |
| 2486 ui_test_utils::BROWSER_TEST_NONE); | |
| 2487 interstitial_timer_observer.WaitForTimerStarted(); | |
| 2488 | |
| 2489 EXPECT_TRUE(contents->IsLoading()); | |
| 2490 content::WindowedNotificationObserver observer( | |
| 2491 content::NOTIFICATION_LOAD_STOP, | |
| 2492 content::NotificationService::AllSources()); | |
| 2493 contents->Stop(); | |
| 2494 observer.Wait(); | |
| 2495 | |
| 2496 SSLErrorHandler* ssl_error_handler = | |
| 2497 SSLErrorHandler::FromWebContents(contents); | |
| 2498 // Make sure that the |SSLErrorHandler| is deleted. | |
| 2499 EXPECT_FALSE(ssl_error_handler); | |
| 2500 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 2501 EXPECT_FALSE(contents->IsLoading()); | |
| 2502 } | |
| 2503 | |
| 2504 // Same as above, but instead of stopping, the loading page is reloaded. The end | |
| 2505 // result is the same. (i.e. page load stops, no interstitials shown) | |
| 2506 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
| 2507 InterstitialReloadNavigationWhileLoading) { | |
| 2508 net::SpawnedTestServer https_server_example_domain_( | |
| 2509 net::SpawnedTestServer::TYPE_HTTPS, | |
| 2510 net::SpawnedTestServer::SSLOptions( | |
| 2511 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
| 2512 base::FilePath(kDocRoot)); | |
| 2513 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2514 | |
| 2515 host_resolver()->AddRule( | |
| 2516 "mail.example.com", https_server_example_domain_.host_port_pair().host()); | |
| 2517 host_resolver()->AddRule( | |
| 2518 "www.mail.example.com", | |
| 2519 https_server_example_domain_.host_port_pair().host()); | |
| 2520 | |
| 2521 scoped_refptr<net::X509Certificate> cert1 = | |
| 2522 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
| 2523 | |
| 2524 net::CertVerifyResult verify_result; | |
| 2525 verify_result.verified_cert = | |
| 2526 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2527 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
| 2528 | |
| 2529 mock_cert_verifier()->AddResultForCertAndHost( | |
| 2530 cert1.get(), "www.mail.example.com", verify_result, | |
| 2531 net::ERR_CERT_COMMON_NAME_INVALID); | |
| 2532 | |
| 2533 net::CertVerifyResult verify_result_valid; | |
| 2534 verify_result_valid.verified_cert = | |
| 2535 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2536 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "mail.example.com", | |
| 2537 verify_result_valid, net::OK); | |
| 2538 | |
| 2539 GURL https_server_url = | |
| 2540 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2541 GURL::Replacements replacements; | |
| 2542 replacements.SetHostStr("www.mail.example.com"); | |
| 2543 GURL https_server_mismatched_url = | |
| 2544 https_server_url.ReplaceComponents(replacements); | |
| 2545 | |
| 2546 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2547 CommonNameMismatchHandler::set_state_for_testing( | |
| 2548 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
| 2549 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 2550 | |
| 2551 ui_test_utils::NavigateToURLWithDisposition( | |
| 2552 browser(), https_server_mismatched_url, CURRENT_TAB, | |
| 2553 ui_test_utils::BROWSER_TEST_NONE); | |
| 2554 interstitial_timer_observer.WaitForTimerStarted(); | |
| 2555 | |
| 2556 EXPECT_TRUE(contents->IsLoading()); | |
| 2557 content::TestNavigationObserver observer(contents, 1); | |
| 2558 chrome::Reload(browser(), CURRENT_TAB); | |
| 2559 observer.Wait(); | |
| 2560 | |
| 2561 SSLErrorHandler* ssl_error_handler = | |
| 2562 SSLErrorHandler::FromWebContents(contents); | |
| 2563 // Make sure that the |SSLErrorHandler| is deleted. | |
| 2564 EXPECT_FALSE(ssl_error_handler); | |
| 2565 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 2566 EXPECT_FALSE(contents->IsLoading()); | |
| 2567 } | |
| 2568 | |
| 2569 // Same as above, but instead of reloading, the page is navigated away. The | |
| 2570 // new page should load, and no interstitials should be shown. | |
| 2571 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
| 2572 InterstitialNavigateAwayWhileLoading) { | |
| 2573 net::SpawnedTestServer https_server_example_domain_( | |
| 2574 net::SpawnedTestServer::TYPE_HTTPS, | |
| 2575 net::SpawnedTestServer::SSLOptions( | |
| 2576 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
| 2577 base::FilePath(kDocRoot)); | |
| 2578 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2579 | |
| 2580 host_resolver()->AddRule( | |
| 2581 "mail.example.com", https_server_example_domain_.host_port_pair().host()); | |
| 2582 host_resolver()->AddRule( | |
| 2583 "www.mail.example.com", | |
| 2584 https_server_example_domain_.host_port_pair().host()); | |
| 2585 | |
| 2586 scoped_refptr<net::X509Certificate> cert1 = | |
| 2587 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
| 2588 | |
| 2589 net::CertVerifyResult verify_result; | |
| 2590 verify_result.verified_cert = | |
| 2591 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2592 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
| 2593 | |
| 2594 mock_cert_verifier()->AddResultForCertAndHost( | |
| 2595 cert1.get(), "www.mail.example.com", verify_result, | |
| 2596 net::ERR_CERT_COMMON_NAME_INVALID); | |
| 2597 | |
| 2598 net::CertVerifyResult verify_result_valid; | |
| 2599 verify_result_valid.verified_cert = | |
| 2600 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 2601 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "mail.example.com", | |
| 2602 verify_result_valid, net::OK); | |
| 2603 | |
| 2604 GURL https_server_url = | |
| 2605 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2606 GURL::Replacements replacements; | |
| 2607 replacements.SetHostStr("www.mail.example.com"); | |
| 2608 GURL https_server_mismatched_url = | |
| 2609 https_server_url.ReplaceComponents(replacements); | |
| 2610 | |
| 2611 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2612 CommonNameMismatchHandler::set_state_for_testing( | |
| 2613 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
| 2614 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 2615 | |
| 2616 ui_test_utils::NavigateToURLWithDisposition( | |
| 2617 browser(), https_server_mismatched_url, CURRENT_TAB, | |
| 2618 ui_test_utils::BROWSER_TEST_NONE); | |
| 2619 interstitial_timer_observer.WaitForTimerStarted(); | |
| 2620 | |
| 2621 EXPECT_TRUE(contents->IsLoading()); | |
| 2622 content::TestNavigationObserver observer(contents, 1); | |
| 2623 browser()->OpenURL(content::OpenURLParams(GURL("https://google.com"), | |
| 2624 content::Referrer(), CURRENT_TAB, | |
| 2625 ui::PAGE_TRANSITION_TYPED, false)); | |
| 2626 observer.Wait(); | |
| 2627 | |
| 2628 SSLErrorHandler* ssl_error_handler = | |
| 2629 SSLErrorHandler::FromWebContents(contents); | |
| 2630 // Make sure that the |SSLErrorHandler| is deleted. | |
| 2631 EXPECT_FALSE(ssl_error_handler); | |
| 2632 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 2633 EXPECT_FALSE(contents->IsLoading()); | |
| 2634 } | |
| 2635 | |
| 2266 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { | 2636 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { |
| 2267 protected: | 2637 protected: |
| 2268 // SecurityInterstitialIDNTest implementation | 2638 // SecurityInterstitialIDNTest implementation |
| 2269 SecurityInterstitialPage* CreateInterstitial( | 2639 SecurityInterstitialPage* CreateInterstitial( |
| 2270 content::WebContents* contents, | 2640 content::WebContents* contents, |
| 2271 const GURL& request_url) const override { | 2641 const GURL& request_url) const override { |
| 2272 net::SSLInfo ssl_info; | 2642 net::SSLInfo ssl_info; |
| 2273 ssl_info.cert = new net::X509Certificate( | 2643 ssl_info.cert = new net::X509Certificate( |
| 2274 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); | 2644 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); |
| 2275 return new SSLBlockingPage( | 2645 return new SSLBlockingPage( |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2306 | 2676 |
| 2307 // Visit a page over https that contains a frame with a redirect. | 2677 // Visit a page over https that contains a frame with a redirect. |
| 2308 | 2678 |
| 2309 // XMLHttpRequest insecure content in synchronous mode. | 2679 // XMLHttpRequest insecure content in synchronous mode. |
| 2310 | 2680 |
| 2311 // XMLHttpRequest insecure content in asynchronous mode. | 2681 // XMLHttpRequest insecure content in asynchronous mode. |
| 2312 | 2682 |
| 2313 // XMLHttpRequest over bad ssl in synchronous mode. | 2683 // XMLHttpRequest over bad ssl in synchronous mode. |
| 2314 | 2684 |
| 2315 // XMLHttpRequest over OK ssl in synchronous mode. | 2685 // XMLHttpRequest over OK ssl in synchronous mode. |
| OLD | NEW |