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 // Verifies that invoking the SSL Blocking page with a suggested URL displays | |
2273 // the common name mismatch interstitial with a link to suggested URL. | |
2274 IN_PROC_BROWSER_TEST_F(SSLUITest, SSLBlockingPageWithSuggestedURL) { | |
2275 content::WebContents* contents = | |
2276 browser()->tab_strip_model()->GetActiveWebContents(); | |
2277 net::SSLInfo ssl_info; | |
2278 ssl_info.cert = net::X509Certificate::CreateFromBytes( | |
2279 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | |
Ryan Sleevi
2015/08/07 00:14:11
Same comments; like I said on email, use ImportCer
Bhanu Dev
2015/08/07 22:28:48
Done.
| |
2280 // Create a new SSL blocking page for https://example.com with | |
2281 // https://www.example.com as the suggested URL. | |
2282 SSLBlockingPage* blocking_page = new SSLBlockingPage( | |
2283 contents, net::ERR_CERT_COMMON_NAME_INVALID, ssl_info, | |
2284 GURL("https://example.com"), 0, base::Time::NowFromSystemTime(), nullptr, | |
2285 base::Callback<void(bool)>(), GURL("https://www.example.com")); | |
2286 blocking_page->Show(); | |
2287 | |
2288 WaitForInterstitialAttach(contents); | |
2289 | |
2290 EXPECT_TRUE( | |
2291 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | |
2292 // The interstitial should display a link to www.example.com | |
2293 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( | |
2294 contents->GetInterstitialPage(), "www.example.com")); | |
2295 // Verify that the link has the text "suggest-link", the id of the | |
2296 // link element displayed. | |
2297 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( | |
2298 contents->GetInterstitialPage(), "suggest-link")); | |
2299 } | |
2300 | |
2301 // Visit the URL www.test.example.com on a server that presents a valid | |
2302 // certificate for test.example.com. Verify that the common name mismatch | |
2303 // interstitial is displayed with a link to test.example.com. Click the | |
2304 // suggested URL link and make sure the page navigates to suggested URL. | |
2305 IN_PROC_BROWSER_TEST_F(CertVerifierBrowserTest, | |
Ryan Sleevi
2015/08/07 00:14:11
From a testing design, normally the fixture naming
Bhanu Dev
2015/08/07 22:28:48
Done.
Thank you for letting me know about this.
| |
2306 ShouldShowWWWSubdomainMismatchInterstitial) { | |
2307 net::SpawnedTestServer https_server_example_domain_( | |
2308 net::SpawnedTestServer::TYPE_HTTPS, | |
2309 net::SpawnedTestServer::SSLOptions( | |
2310 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
2311 base::FilePath(kDocRoot)); | |
2312 ASSERT_TRUE(https_server_example_domain_.Start()); | |
2313 | |
2314 host_resolver()->AddRule("test.example.com", "127.0.0.1"); | |
Ryan Sleevi
2015/08/07 00:14:11
BUG: You shouldn't assume that SpawnedTestServer i
Bhanu Dev
2015/08/07 22:28:48
Done.
I was using 127.0.0.1 as I verified that Get
| |
2315 host_resolver()->AddRule("www.test.example.com", "127.0.0.1"); | |
2316 | |
2317 scoped_refptr<net::X509Certificate> cert1 = | |
2318 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
2319 | |
2320 net::CertVerifyResult verify_result; | |
2321 verify_result.verified_cert = net::ImportCertFromFile( | |
2322 net::GetTestCertsDirectory(), "quic_test.example.com.crt"); | |
Ryan Sleevi
2015/08/07 00:14:11
Haha, I should have been clearer in my email. Out
Bhanu Dev
2015/08/07 22:28:48
Haha. Ok, I went through most of the certs and *pi
| |
2323 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
2324 | |
2325 // Request to "www.test.example.com" should result in | |
2326 // |net::ERR_CERT_COMMON_NAME_INVALID| error. | |
2327 mock_cert_verifier()->AddResultForCertAndHost( | |
2328 cert1.get(), "www.test.example.com", verify_result, | |
2329 net::ERR_CERT_COMMON_NAME_INVALID); | |
2330 | |
2331 net::CertVerifyResult verify_result_valid; | |
2332 verify_result_valid.verified_cert = net::ImportCertFromFile( | |
2333 net::GetTestCertsDirectory(), "quic_test.example.com.crt"); | |
2334 // Request to "www.test.example.com" should not result in any error. | |
2335 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "test.example.com", | |
2336 verify_result_valid, net::OK); | |
2337 | |
2338 // The path does not matter. | |
2339 GURL https_server_url = | |
2340 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
2341 GURL::Replacements replacements; | |
2342 replacements.SetHostStr("www.test.example.com"); | |
2343 GURL https_server_mismatched_url = | |
2344 https_server_url.ReplaceComponents(replacements); | |
2345 | |
2346 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); | |
2347 | |
2348 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
2349 WaitForInterstitialAttach(contents); | |
2350 // An interstitial should be displayed with a | |
2351 // |CERT_STATUS_COMMON_NAME_INVALID| error. | |
2352 CheckSecurityState(contents, net::CERT_STATUS_COMMON_NAME_INVALID, | |
2353 content::SECURITY_STYLE_AUTHENTICATION_BROKEN, | |
2354 AuthState::SHOWING_INTERSTITIAL); | |
2355 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() | |
2356 ->GetDelegateForTesting() | |
2357 ->GetTypeForTesting()); | |
Ryan Sleevi
2015/08/07 00:14:11
did git cl format do this? Weirdest formatting I'v
Bhanu Dev
2015/08/07 22:28:48
Yes. Anyway, the browser tests are changed now, so
| |
2358 | |
2359 content::RenderFrameHost* rfh = | |
2360 contents->GetInterstitialPage()->GetMainFrame(); | |
2361 EXPECT_TRUE(WaitForRenderFrameReady(rfh)); | |
2362 // The interstitial should display a link to www.test.example.com | |
2363 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( | |
2364 contents->GetInterstitialPage(), "test.example.com")); | |
2365 // Verify that the link has the text "suggest-link", the id of the | |
2366 // link element displayed. | |
2367 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( | |
2368 contents->GetInterstitialPage(), "suggest-link")); | |
2369 | |
2370 const char kOpenSuggestedLinkJS[] = | |
2371 "document.getElementById('suggest-link').click();"; | |
2372 content::TestNavigationObserver observer(contents, 1); | |
2373 EXPECT_TRUE(content::ExecuteScript(rfh, kOpenSuggestedLinkJS)); | |
2374 observer.Wait(); | |
2375 | |
2376 CheckSecurityState(contents, CertError::NONE, | |
2377 content::SECURITY_STYLE_AUTHENTICATED, AuthState::NONE); | |
2378 replacements.SetHostStr("test.example.com"); | |
2379 GURL https_server_new_url = https_server_url.ReplaceComponents(replacements); | |
2380 // Verify that the current URL is the suggested URL. | |
2381 EXPECT_EQ(https_server_new_url.spec(), | |
2382 contents->GetLastCommittedURL().spec()); | |
2383 } | |
2384 | |
2385 // Visit the URL example.org on a server that presents a valid certificate | |
2386 // for www.example.org. Verify that the common name mismatch interstitial is | |
2387 // displayed with a link to www.example.org. | |
2388 IN_PROC_BROWSER_TEST_F(CertVerifierBrowserTest, | |
2389 CheckWWWSubdomainMismatchInverse) { | |
2390 net::SpawnedTestServer https_server_example_domain_( | |
2391 net::SpawnedTestServer::TYPE_HTTPS, | |
2392 net::SpawnedTestServer::SSLOptions( | |
2393 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
2394 base::FilePath(kDocRoot)); | |
2395 ASSERT_TRUE(https_server_example_domain_.Start()); | |
2396 | |
2397 host_resolver()->AddRule("www.example.org", "127.0.0.1"); | |
2398 host_resolver()->AddRule("example.org", "127.0.0.1"); | |
2399 | |
2400 scoped_refptr<net::X509Certificate> cert1 = | |
2401 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
2402 | |
2403 net::CertVerifyResult verify_result; | |
2404 verify_result.verified_cert = | |
2405 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
2406 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
2407 | |
2408 mock_cert_verifier()->AddResultForCertAndHost( | |
2409 cert1.get(), "example.org", verify_result, | |
2410 net::ERR_CERT_COMMON_NAME_INVALID); | |
2411 | |
2412 net::CertVerifyResult verify_result_valid; | |
2413 verify_result_valid.verified_cert = | |
2414 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
2415 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "www.example.org", | |
2416 verify_result_valid, net::OK); | |
2417 | |
2418 GURL https_server_url = | |
2419 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
2420 GURL::Replacements replacements; | |
2421 replacements.SetHostStr("example.org"); | |
2422 GURL https_server_mismatched_url = | |
2423 https_server_url.ReplaceComponents(replacements); | |
2424 | |
2425 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); | |
2426 | |
2427 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
2428 WaitForInterstitialAttach(contents); | |
2429 CheckSecurityState(contents, net::CERT_STATUS_COMMON_NAME_INVALID, | |
2430 content::SECURITY_STYLE_AUTHENTICATION_BROKEN, | |
2431 AuthState::SHOWING_INTERSTITIAL); | |
2432 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() | |
2433 ->GetDelegateForTesting() | |
2434 ->GetTypeForTesting()); | |
2435 | |
2436 EXPECT_TRUE( | |
2437 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | |
2438 // The interstitial should display a link to www.example.org | |
2439 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( | |
2440 contents->GetInterstitialPage(), "www.example.org")); | |
2441 // Verify that the link has the text "suggest-link", the id of the | |
2442 // link element displayed. | |
2443 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( | |
2444 contents->GetInterstitialPage(), "suggest-link")); | |
2445 } | |
2446 | |
2447 // This observer waits for the SSLErrorHandler to start an interstitial timer | |
2448 // for the given web contents. | |
2449 class SSLInterstitialTimerObserver { | |
2450 public: | |
2451 explicit SSLInterstitialTimerObserver(content::WebContents* web_contents); | |
2452 ~SSLInterstitialTimerObserver(); | |
2453 | |
2454 // Waits until the interstitial delay timer in SSLErrorHandler is started. | |
2455 void WaitForTimerStarted(); | |
2456 | |
2457 private: | |
2458 void OnTimerStarted(content::WebContents* web_contents); | |
2459 | |
2460 const content::WebContents* web_contents_; | |
2461 SSLErrorHandler::TimerStartedCallback callback_; | |
2462 | |
2463 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
2464 | |
2465 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver); | |
2466 }; | |
2467 | |
2468 SSLInterstitialTimerObserver::SSLInterstitialTimerObserver( | |
2469 content::WebContents* web_contents) | |
2470 : web_contents_(web_contents), | |
2471 message_loop_runner_(new content::MessageLoopRunner) { | |
2472 callback_ = base::Bind(&SSLInterstitialTimerObserver::OnTimerStarted, | |
2473 base::Unretained(this)); | |
2474 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(&callback_); | |
2475 } | |
2476 | |
2477 SSLInterstitialTimerObserver::~SSLInterstitialTimerObserver() { | |
2478 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(nullptr); | |
2479 } | |
2480 | |
2481 void SSLInterstitialTimerObserver::WaitForTimerStarted() { | |
2482 message_loop_runner_->Run(); | |
2483 } | |
2484 | |
2485 void SSLInterstitialTimerObserver::OnTimerStarted( | |
2486 content::WebContents* web_contents) { | |
2487 if (web_contents_ == web_contents && message_loop_runner_.get()) | |
2488 message_loop_runner_->Quit(); | |
2489 } | |
2490 | |
2491 // Tests this scenario: | |
2492 // - |CommonNameMismatchHandler| does not give a callback as it's set into the | |
2493 // state |IGNORE_REQUESTS_FOR_TESTING|. So no suggested URL check result can | |
2494 // arrive. | |
2495 // - A cert error triggers an interstitial timer with a very long timeout. | |
2496 // - No suggested URL check results arrive, causing the tab to appear as loading | |
2497 // indefinitely (also because the timer has a long timeout). | |
2498 // - Stopping the page load shouldn't result in any interstitials. | |
2499 IN_PROC_BROWSER_TEST_F(CertVerifierBrowserTest, | |
2500 InterstitialStopNavigationWhileLoading) { | |
2501 net::SpawnedTestServer https_server_example_domain_( | |
2502 net::SpawnedTestServer::TYPE_HTTPS, | |
2503 net::SpawnedTestServer::SSLOptions( | |
2504 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
2505 base::FilePath(kDocRoot)); | |
2506 ASSERT_TRUE(https_server_example_domain_.Start()); | |
2507 | |
2508 host_resolver()->AddRule("test.example.com", "127.0.0.1"); | |
2509 host_resolver()->AddRule("www.test.example.com", "127.0.0.1"); | |
2510 | |
2511 scoped_refptr<net::X509Certificate> cert1 = | |
2512 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
2513 | |
2514 net::CertVerifyResult verify_result; | |
2515 verify_result.verified_cert = net::ImportCertFromFile( | |
2516 net::GetTestCertsDirectory(), "quic_test.example.com.crt"); | |
2517 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
2518 | |
2519 mock_cert_verifier()->AddResultForCertAndHost( | |
2520 cert1.get(), "www.test.example.com", verify_result, | |
2521 net::ERR_CERT_COMMON_NAME_INVALID); | |
2522 | |
2523 net::CertVerifyResult verify_result_valid; | |
2524 verify_result_valid.verified_cert = net::ImportCertFromFile( | |
2525 net::GetTestCertsDirectory(), "quic_test.example.com.crt"); | |
2526 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "test.example.com", | |
2527 verify_result_valid, net::OK); | |
2528 | |
2529 GURL https_server_url = | |
2530 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
2531 GURL::Replacements replacements; | |
2532 replacements.SetHostStr("www.test.example.com"); | |
2533 GURL https_server_mismatched_url = | |
2534 https_server_url.ReplaceComponents(replacements); | |
2535 | |
2536 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
2537 CommonNameMismatchHandler::set_state_for_testing( | |
2538 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
2539 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
2540 | |
2541 ui_test_utils::NavigateToURLWithDisposition( | |
2542 browser(), https_server_mismatched_url, CURRENT_TAB, | |
2543 ui_test_utils::BROWSER_TEST_NONE); | |
2544 interstitial_timer_observer.WaitForTimerStarted(); | |
2545 | |
2546 EXPECT_TRUE(contents->IsLoading()); | |
2547 content::WindowedNotificationObserver observer( | |
2548 content::NOTIFICATION_LOAD_STOP, | |
2549 content::NotificationService::AllSources()); | |
2550 contents->Stop(); | |
2551 observer.Wait(); | |
2552 | |
2553 SSLErrorHandler* ssl_error_handler = | |
2554 SSLErrorHandler::FromWebContents(contents); | |
2555 // Make sure that the |SSLErrorHandler| is deleted. | |
2556 EXPECT_FALSE(ssl_error_handler); | |
2557 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
2558 EXPECT_FALSE(contents->IsLoading()); | |
2559 } | |
2560 | |
2561 // Same as above, but instead of stopping, the loading page is reloaded. The end | |
2562 // result is the same. (i.e. page load stops, no interstitials shown) | |
2563 IN_PROC_BROWSER_TEST_F(CertVerifierBrowserTest, | |
2564 InterstitialReloadNavigationWhileLoading) { | |
2565 net::SpawnedTestServer https_server_example_domain_( | |
2566 net::SpawnedTestServer::TYPE_HTTPS, | |
2567 net::SpawnedTestServer::SSLOptions( | |
2568 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
2569 base::FilePath(kDocRoot)); | |
2570 ASSERT_TRUE(https_server_example_domain_.Start()); | |
2571 | |
2572 host_resolver()->AddRule("test.example.com", "127.0.0.1"); | |
2573 host_resolver()->AddRule("www.test.example.com", "127.0.0.1"); | |
2574 | |
2575 scoped_refptr<net::X509Certificate> cert1 = | |
2576 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
2577 | |
2578 net::CertVerifyResult verify_result; | |
2579 verify_result.verified_cert = net::ImportCertFromFile( | |
2580 net::GetTestCertsDirectory(), "quic_test.example.com.crt"); | |
2581 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
2582 | |
2583 mock_cert_verifier()->AddResultForCertAndHost( | |
2584 cert1.get(), "www.test.example.com", verify_result, | |
2585 net::ERR_CERT_COMMON_NAME_INVALID); | |
2586 | |
2587 net::CertVerifyResult verify_result_valid; | |
2588 verify_result_valid.verified_cert = net::ImportCertFromFile( | |
2589 net::GetTestCertsDirectory(), "quic_test.example.com.crt"); | |
2590 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "test.example.com", | |
2591 verify_result_valid, net::OK); | |
2592 | |
2593 GURL https_server_url = | |
2594 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
2595 GURL::Replacements replacements; | |
2596 replacements.SetHostStr("www.test.example.com"); | |
2597 GURL https_server_mismatched_url = | |
2598 https_server_url.ReplaceComponents(replacements); | |
2599 | |
2600 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
2601 CommonNameMismatchHandler::set_state_for_testing( | |
2602 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
2603 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
2604 | |
2605 ui_test_utils::NavigateToURLWithDisposition( | |
2606 browser(), https_server_mismatched_url, CURRENT_TAB, | |
2607 ui_test_utils::BROWSER_TEST_NONE); | |
2608 interstitial_timer_observer.WaitForTimerStarted(); | |
2609 | |
2610 EXPECT_TRUE(contents->IsLoading()); | |
2611 content::TestNavigationObserver observer(contents, 1); | |
2612 chrome::Reload(browser(), CURRENT_TAB); | |
2613 observer.Wait(); | |
2614 | |
2615 SSLErrorHandler* ssl_error_handler = | |
2616 SSLErrorHandler::FromWebContents(contents); | |
2617 // Make sure that the |SSLErrorHandler| is deleted. | |
2618 EXPECT_FALSE(ssl_error_handler); | |
2619 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
2620 EXPECT_FALSE(contents->IsLoading()); | |
2621 } | |
2622 | |
2623 // Same as above, but instead of reloading, the page is navigated away. The | |
2624 // new page should load, and no interstitials should be shown. | |
2625 IN_PROC_BROWSER_TEST_F(CertVerifierBrowserTest, | |
2626 InterstitialNavigateAwayWhileLoading) { | |
2627 net::SpawnedTestServer https_server_example_domain_( | |
2628 net::SpawnedTestServer::TYPE_HTTPS, | |
2629 net::SpawnedTestServer::SSLOptions( | |
2630 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
2631 base::FilePath(kDocRoot)); | |
2632 ASSERT_TRUE(https_server_example_domain_.Start()); | |
2633 | |
2634 host_resolver()->AddRule("test.example.com", "127.0.0.1"); | |
2635 host_resolver()->AddRule("www.test.example.com", "127.0.0.1"); | |
2636 | |
2637 scoped_refptr<net::X509Certificate> cert1 = | |
2638 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
2639 | |
2640 net::CertVerifyResult verify_result; | |
2641 verify_result.verified_cert = net::ImportCertFromFile( | |
2642 net::GetTestCertsDirectory(), "quic_test.example.com.crt"); | |
2643 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
2644 | |
2645 mock_cert_verifier()->AddResultForCertAndHost( | |
2646 cert1.get(), "www.test.example.com", verify_result, | |
2647 net::ERR_CERT_COMMON_NAME_INVALID); | |
2648 | |
2649 net::CertVerifyResult verify_result_valid; | |
2650 verify_result_valid.verified_cert = net::ImportCertFromFile( | |
2651 net::GetTestCertsDirectory(), "quic_test.example.com.crt"); | |
2652 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "test.example.com", | |
2653 verify_result_valid, net::OK); | |
2654 | |
2655 GURL https_server_url = | |
2656 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
2657 GURL::Replacements replacements; | |
2658 replacements.SetHostStr("www.test.example.com"); | |
2659 GURL https_server_mismatched_url = | |
2660 https_server_url.ReplaceComponents(replacements); | |
2661 | |
2662 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
2663 CommonNameMismatchHandler::set_state_for_testing( | |
2664 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
2665 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
2666 | |
2667 ui_test_utils::NavigateToURLWithDisposition( | |
2668 browser(), https_server_mismatched_url, CURRENT_TAB, | |
2669 ui_test_utils::BROWSER_TEST_NONE); | |
2670 interstitial_timer_observer.WaitForTimerStarted(); | |
2671 | |
2672 EXPECT_TRUE(contents->IsLoading()); | |
2673 content::TestNavigationObserver observer(contents, 1); | |
2674 browser()->OpenURL(content::OpenURLParams(GURL("https://google.com"), | |
2675 content::Referrer(), CURRENT_TAB, | |
2676 ui::PAGE_TRANSITION_TYPED, false)); | |
2677 observer.Wait(); | |
2678 | |
2679 SSLErrorHandler* ssl_error_handler = | |
2680 SSLErrorHandler::FromWebContents(contents); | |
2681 // Make sure that the |SSLErrorHandler| is deleted. | |
2682 EXPECT_FALSE(ssl_error_handler); | |
2683 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
2684 EXPECT_FALSE(contents->IsLoading()); | |
2685 } | |
2686 | |
2266 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { | 2687 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { |
2267 protected: | 2688 protected: |
2268 // SecurityInterstitialIDNTest implementation | 2689 // SecurityInterstitialIDNTest implementation |
2269 SecurityInterstitialPage* CreateInterstitial( | 2690 SecurityInterstitialPage* CreateInterstitial( |
2270 content::WebContents* contents, | 2691 content::WebContents* contents, |
2271 const GURL& request_url) const override { | 2692 const GURL& request_url) const override { |
2272 net::SSLInfo ssl_info; | 2693 net::SSLInfo ssl_info; |
2273 ssl_info.cert = new net::X509Certificate( | 2694 ssl_info.cert = new net::X509Certificate( |
2274 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); | 2695 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); |
2275 return new SSLBlockingPage( | 2696 return new SSLBlockingPage(contents, net::ERR_CERT_CONTAINS_ERRORS, |
2276 contents, net::ERR_CERT_CONTAINS_ERRORS, ssl_info, request_url, 0, | 2697 ssl_info, request_url, 0, |
2277 base::Time::NowFromSystemTime(), nullptr, base::Callback<void(bool)>()); | 2698 base::Time::NowFromSystemTime(), nullptr, |
2699 base::Callback<void(bool)>(), GURL()); | |
2278 } | 2700 } |
2279 }; | 2701 }; |
2280 | 2702 |
2281 IN_PROC_BROWSER_TEST_F(SSLBlockingPageIDNTest, SSLBlockingPageDecodesIDN) { | 2703 IN_PROC_BROWSER_TEST_F(SSLBlockingPageIDNTest, SSLBlockingPageDecodesIDN) { |
2282 EXPECT_TRUE(VerifyIDNDecoded()); | 2704 EXPECT_TRUE(VerifyIDNDecoded()); |
2283 } | 2705 } |
2284 | 2706 |
2285 IN_PROC_BROWSER_TEST_F(CertVerifierBrowserTest, MockCertVerifierSmokeTest) { | 2707 IN_PROC_BROWSER_TEST_F(CertVerifierBrowserTest, MockCertVerifierSmokeTest) { |
2286 net::SpawnedTestServer https_server( | 2708 net::SpawnedTestServer https_server( |
2287 net::SpawnedTestServer::TYPE_HTTPS, | 2709 net::SpawnedTestServer::TYPE_HTTPS, |
(...skipping 18 matching lines...) Expand all Loading... | |
2306 | 2728 |
2307 // Visit a page over https that contains a frame with a redirect. | 2729 // Visit a page over https that contains a frame with a redirect. |
2308 | 2730 |
2309 // XMLHttpRequest insecure content in synchronous mode. | 2731 // XMLHttpRequest insecure content in synchronous mode. |
2310 | 2732 |
2311 // XMLHttpRequest insecure content in asynchronous mode. | 2733 // XMLHttpRequest insecure content in asynchronous mode. |
2312 | 2734 |
2313 // XMLHttpRequest over bad ssl in synchronous mode. | 2735 // XMLHttpRequest over bad ssl in synchronous mode. |
2314 | 2736 |
2315 // XMLHttpRequest over OK ssl in synchronous mode. | 2737 // XMLHttpRequest over OK ssl in synchronous mode. |
OLD | NEW |