| 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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "chrome/test/base/ui_test_utils.h" | 35 #include "chrome/test/base/ui_test_utils.h" |
| 36 #include "components/content_settings/core/browser/host_content_settings_map.h" | 36 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 37 #include "components/variations/variations_associated_data.h" | 37 #include "components/variations/variations_associated_data.h" |
| 38 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 38 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 39 #include "content/public/browser/browser_context.h" | 39 #include "content/public/browser/browser_context.h" |
| 40 #include "content/public/browser/interstitial_page.h" | 40 #include "content/public/browser/interstitial_page.h" |
| 41 #include "content/public/browser/navigation_controller.h" | 41 #include "content/public/browser/navigation_controller.h" |
| 42 #include "content/public/browser/navigation_entry.h" | 42 #include "content/public/browser/navigation_entry.h" |
| 43 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
| 44 #include "content/public/browser/render_frame_host.h" | 44 #include "content/public/browser/render_frame_host.h" |
| 45 #include "content/public/browser/render_process_host.h" | |
| 46 #include "content/public/browser/render_view_host.h" | 45 #include "content/public/browser/render_view_host.h" |
| 47 #include "content/public/browser/render_widget_host_view.h" | 46 #include "content/public/browser/render_widget_host_view.h" |
| 48 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
| 49 #include "content/public/browser/web_contents_observer.h" | 48 #include "content/public/browser/web_contents_observer.h" |
| 50 #include "content/public/common/security_style.h" | 49 #include "content/public/common/security_style.h" |
| 51 #include "content/public/common/ssl_status.h" | 50 #include "content/public/common/ssl_status.h" |
| 52 #include "content/public/test/browser_test_utils.h" | 51 #include "content/public/test/browser_test_utils.h" |
| 53 #include "content/public/test/download_test_observer.h" | 52 #include "content/public/test/download_test_observer.h" |
| 54 #include "content/public/test/test_renderer_host.h" | 53 #include "content/public/test/test_renderer_host.h" |
| 55 #include "net/base/host_port_pair.h" | 54 #include "net/base/host_port_pair.h" |
| 56 #include "net/base/net_errors.h" | 55 #include "net/base/net_errors.h" |
| 57 #include "net/base/test_data_directory.h" | 56 #include "net/base/test_data_directory.h" |
| 58 #include "net/cert/cert_status_flags.h" | 57 #include "net/cert/cert_status_flags.h" |
| 59 #include "net/cert/test_root_certs.h" | |
| 60 #include "net/cert/x509_certificate.h" | 58 #include "net/cert/x509_certificate.h" |
| 61 #include "net/dns/host_resolver.h" | |
| 62 #include "net/dns/mock_host_resolver.h" | |
| 63 #include "net/http/http_transaction_factory.h" | |
| 64 #include "net/ssl/ssl_info.h" | 59 #include "net/ssl/ssl_info.h" |
| 65 #include "net/test/spawned_test_server/spawned_test_server.h" | 60 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 66 #include "net/url_request/url_request_context.h" | 61 #include "net/url_request/url_request_context.h" |
| 67 #include "net/url_request/url_request_context_getter.h" | |
| 68 | 62 |
| 69 #if defined(USE_NSS_CERTS) | 63 #if defined(USE_NSS_CERTS) |
| 70 #include "chrome/browser/net/nss_context.h" | 64 #include "chrome/browser/net/nss_context.h" |
| 71 #include "net/base/crypto_module.h" | 65 #include "net/base/crypto_module.h" |
| 72 #include "net/cert/nss_cert_database.h" | 66 #include "net/cert/nss_cert_database.h" |
| 73 #endif // defined(USE_NSS_CERTS) | 67 #endif // defined(USE_NSS_CERTS) |
| 74 | 68 |
| 75 using base::ASCIIToUTF16; | 69 using base::ASCIIToUTF16; |
| 76 using chrome_browser_interstitials::SecurityInterstitialIDNTest; | 70 using chrome_browser_interstitials::SecurityInterstitialIDNTest; |
| 77 using chrome_browser_net::CertificateErrorReporter; | 71 using chrome_browser_net::CertificateErrorReporter; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 260 |
| 267 private: | 261 private: |
| 268 const scoped_refptr<SafeBrowsingUIManager> safe_browsing_ui_manager_; | 262 const scoped_refptr<SafeBrowsingUIManager> safe_browsing_ui_manager_; |
| 269 bool reported_; | 263 bool reported_; |
| 270 bool expect_report_; | 264 bool expect_report_; |
| 271 base::Closure report_sent_callback_; | 265 base::Closure report_sent_callback_; |
| 272 }; | 266 }; |
| 273 | 267 |
| 274 } // namespace CertificateReporting | 268 } // namespace CertificateReporting |
| 275 | 269 |
| 276 void RootCertsChangedOnIOThread( | |
| 277 const scoped_refptr<net::URLRequestContextGetter> context_getter) { | |
| 278 net::CertDatabase::GetInstance()->NotifyObserversOfCACertChanged(NULL); | |
| 279 context_getter->GetURLRequestContext() | |
| 280 ->http_transaction_factory() | |
| 281 ->GetSession() | |
| 282 ->CloseAllConnections(); | |
| 283 } | |
| 284 | |
| 285 // Alerts the URLRequestContext for the given WebContents that a root | |
| 286 // certificate has changed state or been removed. This, in turn, clears any | |
| 287 // cached certificate validation in the cert verifier. This will also close all | |
| 288 // connections in the socket pool of |contents|, so calls to this should be made | |
| 289 // with care. | |
| 290 void RootCertsChanged(WebContents* contents) { | |
| 291 scoped_refptr<net::URLRequestContextGetter> url_request_context = | |
| 292 contents->GetBrowserContext()->GetRequestContextForRenderProcess( | |
| 293 contents->GetRenderProcessHost()->GetID()); | |
| 294 base::RunLoop run_loop; | |
| 295 content::BrowserThread::PostTaskAndReply( | |
| 296 content::BrowserThread::IO, FROM_HERE, | |
| 297 base::Bind(&RootCertsChangedOnIOThread, url_request_context), | |
| 298 run_loop.QuitClosure()); | |
| 299 run_loop.Run(); | |
| 300 base::RunLoop().RunUntilIdle(); | |
| 301 } | |
| 302 | |
| 303 } // namespace | 270 } // namespace |
| 304 | 271 |
| 305 class SSLUITest : public InProcessBrowserTest { | 272 class SSLUITest : public InProcessBrowserTest { |
| 306 public: | 273 public: |
| 307 SSLUITest() | 274 SSLUITest() |
| 308 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, | 275 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, |
| 309 SSLOptions(SSLOptions::CERT_OK), | 276 SSLOptions(SSLOptions::CERT_OK), |
| 310 base::FilePath(kDocRoot)), | 277 base::FilePath(kDocRoot)), |
| 311 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, | 278 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, |
| 312 SSLOptions(SSLOptions::CERT_EXPIRED), | 279 SSLOptions(SSLOptions::CERT_EXPIRED), |
| (...skipping 2029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2342 | 2309 |
| 2343 browser()->tab_strip_model()->ActivateTabAt(1, true); | 2310 browser()->tab_strip_model()->ActivateTabAt(1, true); |
| 2344 EXPECT_TRUE(tab->GetRenderWidgetHostView()->IsShowing()); | 2311 EXPECT_TRUE(tab->GetRenderWidgetHostView()->IsShowing()); |
| 2345 } | 2312 } |
| 2346 | 2313 |
| 2347 // Verifies that if a bad certificate is seen for a host and the user proceeds | 2314 // Verifies that if a bad certificate is seen for a host and the user proceeds |
| 2348 // through the interstitial, the decision to proceed is initially remembered. | 2315 // through the interstitial, the decision to proceed is initially remembered. |
| 2349 // However, if this is followed by another visit, and a good certificate | 2316 // However, if this is followed by another visit, and a good certificate |
| 2350 // is seen for the same host, the original exception is forgotten. | 2317 // is seen for the same host, the original exception is forgotten. |
| 2351 IN_PROC_BROWSER_TEST_F(SSLUITest, BadCertFollowedByGoodCert) { | 2318 IN_PROC_BROWSER_TEST_F(SSLUITest, BadCertFollowedByGoodCert) { |
| 2319 // It is necessary to use |https_server_expired_| rather than |
| 2320 // |https_server_mismatched| because the former shares a host with |
| 2321 // |https_server_| and cert exceptions are per host. |
| 2322 ASSERT_TRUE(https_server_expired_.Start()); |
| 2352 ASSERT_TRUE(https_server_.Start()); | 2323 ASSERT_TRUE(https_server_.Start()); |
| 2324 |
| 2325 std::string https_server_expired_host = |
| 2326 https_server_.GetURL("files/ssl/google.html").host(); |
| 2353 std::string https_server_host = | 2327 std::string https_server_host = |
| 2354 https_server_.GetURL("files/ssl/google.html").host(); | 2328 https_server_.GetURL("files/ssl/google.html").host(); |
| 2329 ASSERT_EQ(https_server_expired_host, https_server_host); |
| 2355 | 2330 |
| 2356 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 2331 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2357 net::TestRootCerts* root_certs = net::TestRootCerts::GetInstance(); | |
| 2358 | |
| 2359 ASSERT_TRUE(root_certs); | |
| 2360 root_certs->Clear(); | |
| 2361 | 2332 |
| 2362 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 2333 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
| 2363 ChromeSSLHostStateDelegate* state = | 2334 ChromeSSLHostStateDelegate* state = |
| 2364 reinterpret_cast<ChromeSSLHostStateDelegate*>( | 2335 reinterpret_cast<ChromeSSLHostStateDelegate*>( |
| 2365 profile->GetSSLHostStateDelegate()); | 2336 profile->GetSSLHostStateDelegate()); |
| 2366 | 2337 |
| 2367 ui_test_utils::NavigateToURL(browser(), | 2338 ui_test_utils::NavigateToURL( |
| 2368 https_server_.GetURL("files/ssl/google.html")); | 2339 browser(), https_server_expired_.GetURL("files/ssl/google.html")); |
| 2369 | 2340 |
| 2370 ProceedThroughInterstitial(tab); | 2341 ProceedThroughInterstitial(tab); |
| 2371 EXPECT_TRUE(state->HasAllowException(https_server_host)); | 2342 EXPECT_TRUE(state->HasAllowException(https_server_host)); |
| 2372 | 2343 |
| 2373 ASSERT_TRUE(https_server_.LoadTestRootCert()); | |
| 2374 RootCertsChanged(tab); | |
| 2375 ui_test_utils::NavigateToURL(browser(), | 2344 ui_test_utils::NavigateToURL(browser(), |
| 2376 https_server_.GetURL("files/ssl/google.html")); | 2345 https_server_.GetURL("files/ssl/google.html")); |
| 2377 ASSERT_FALSE(tab->GetInterstitialPage()); | 2346 ASSERT_FALSE(tab->GetInterstitialPage()); |
| 2378 EXPECT_FALSE(state->HasAllowException(https_server_host)); | 2347 EXPECT_FALSE(state->HasAllowException(https_server_host)); |
| 2379 } | 2348 } |
| 2380 | 2349 |
| 2381 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { | 2350 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { |
| 2382 protected: | 2351 protected: |
| 2383 // SecurityInterstitialIDNTest implementation | 2352 // SecurityInterstitialIDNTest implementation |
| 2384 SecurityInterstitialPage* CreateInterstitial( | 2353 SecurityInterstitialPage* CreateInterstitial( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2401 | 2370 |
| 2402 // Visit a page over https that contains a frame with a redirect. | 2371 // Visit a page over https that contains a frame with a redirect. |
| 2403 | 2372 |
| 2404 // XMLHttpRequest insecure content in synchronous mode. | 2373 // XMLHttpRequest insecure content in synchronous mode. |
| 2405 | 2374 |
| 2406 // XMLHttpRequest insecure content in asynchronous mode. | 2375 // XMLHttpRequest insecure content in asynchronous mode. |
| 2407 | 2376 |
| 2408 // XMLHttpRequest over bad ssl in synchronous mode. | 2377 // XMLHttpRequest over bad ssl in synchronous mode. |
| 2409 | 2378 |
| 2410 // XMLHttpRequest over OK ssl in synchronous mode. | 2379 // XMLHttpRequest over OK ssl in synchronous mode. |
| OLD | NEW |