| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ui/webui/interstitials/interstitial_ui.h" | 5 #include "chrome/browser/ui/webui/interstitials/interstitial_ui.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 13 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 15 #include "chrome/browser/safe_browsing/test_safe_browsing_blocking_page_quiet.h" |
| 15 #include "chrome/browser/safe_browsing/ui_manager.h" | 16 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 16 #include "chrome/browser/ssl/bad_clock_blocking_page.h" | 17 #include "chrome/browser/ssl/bad_clock_blocking_page.h" |
| 17 #include "chrome/browser/ssl/ssl_blocking_page.h" | 18 #include "chrome/browser/ssl/ssl_blocking_page.h" |
| 18 #include "chrome/browser/supervised_user/supervised_user_interstitial.h" | 19 #include "chrome/browser/supervised_user/supervised_user_interstitial.h" |
| 19 #include "chrome/common/features.h" | 20 #include "chrome/common/features.h" |
| 20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 21 #include "components/grit/components_resources.h" | 22 #include "components/grit/components_resources.h" |
| 22 #include "components/security_interstitials/core/ssl_error_ui.h" | 23 #include "components/security_interstitials/core/ssl_error_ui.h" |
| 23 #include "components/supervised_user_error_page/supervised_user_error_page.h" | 24 #include "components/supervised_user_error_page/supervised_user_error_page.h" |
| 24 #include "content/public/browser/interstitial_page_delegate.h" | 25 #include "content/public/browser/interstitial_page_delegate.h" |
| 25 #include "content/public/browser/render_frame_host.h" | 26 #include "content/public/browser/render_frame_host.h" |
| 26 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
| 27 #include "content/public/browser/url_data_source.h" | 28 #include "content/public/browser/url_data_source.h" |
| 28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
| 30 #include "content/public/browser/web_ui_data_source.h" | 31 #include "content/public/browser/web_ui_data_source.h" |
| 31 #include "crypto/rsa_private_key.h" | 32 #include "crypto/rsa_private_key.h" |
| 32 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
| 33 #include "net/base/url_util.h" | 34 #include "net/base/url_util.h" |
| 34 #include "net/cert/x509_certificate.h" | 35 #include "net/cert/x509_certificate.h" |
| 35 #include "net/cert/x509_util.h" | 36 #include "net/cert/x509_util.h" |
| 36 #include "net/ssl/ssl_info.h" | 37 #include "net/ssl/ssl_info.h" |
| 37 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
| 39 #include "ui/base/webui/web_ui_util.h" |
| 38 | 40 |
| 39 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 41 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 40 #include "chrome/browser/ssl/captive_portal_blocking_page.h" | 42 #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
| 41 #endif | 43 #endif |
| 42 | 44 |
| 45 using security_interstitials::TestSafeBrowsingBlockingPageQuiet; |
| 46 |
| 43 namespace { | 47 namespace { |
| 44 | 48 |
| 45 // NSS requires that serial numbers be unique even for the same issuer; | 49 // NSS requires that serial numbers be unique even for the same issuer; |
| 46 // as all fake certificates will contain the same issuer name, it's | 50 // as all fake certificates will contain the same issuer name, it's |
| 47 // necessary to ensure the serial number is unique, as otherwise | 51 // necessary to ensure the serial number is unique, as otherwise |
| 48 // NSS will fail to parse. | 52 // NSS will fail to parse. |
| 49 base::StaticAtomicSequenceNumber g_serial_number; | 53 base::StaticAtomicSequenceNumber g_serial_number; |
| 50 | 54 |
| 51 scoped_refptr<net::X509Certificate> CreateFakeCert() { | 55 scoped_refptr<net::X509Certificate> CreateFakeCert() { |
| 52 std::unique_ptr<crypto::RSAPrivateKey> unused_key; | 56 std::unique_ptr<crypto::RSAPrivateKey> unused_key; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 // SB_THREAT_TYPE_URL_UNWANTED on main-frame loads) would expect there to be a | 261 // SB_THREAT_TYPE_URL_UNWANTED on main-frame loads) would expect there to be a |
| 258 // pending navigation when the SafeBrowsingBlockingPage is created. This demo | 262 // pending navigation when the SafeBrowsingBlockingPage is created. This demo |
| 259 // creates a SafeBrowsingBlockingPage but does not actually show a real | 263 // creates a SafeBrowsingBlockingPage but does not actually show a real |
| 260 // interstitial. Instead it extracts the html and displays it manually, so the | 264 // interstitial. Instead it extracts the html and displays it manually, so the |
| 261 // parts which depend on the NavigationEntry are not hit. | 265 // parts which depend on the NavigationEntry are not hit. |
| 262 return safe_browsing::SafeBrowsingBlockingPage::CreateBlockingPage( | 266 return safe_browsing::SafeBrowsingBlockingPage::CreateBlockingPage( |
| 263 g_browser_process->safe_browsing_service()->ui_manager().get(), | 267 g_browser_process->safe_browsing_service()->ui_manager().get(), |
| 264 web_contents, main_frame_url, resource); | 268 web_contents, main_frame_url, resource); |
| 265 } | 269 } |
| 266 | 270 |
| 271 TestSafeBrowsingBlockingPageQuiet* CreateSafeBrowsingQuietBlockingPage( |
| 272 content::WebContents* web_contents) { |
| 273 safe_browsing::SBThreatType threat_type = |
| 274 safe_browsing::SB_THREAT_TYPE_URL_MALWARE; |
| 275 GURL request_url("http://example.com"); |
| 276 std::string url_param; |
| 277 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "url", &url_param)) { |
| 278 if (GURL(url_param).is_valid()) |
| 279 request_url = GURL(url_param); |
| 280 } |
| 281 GURL main_frame_url(request_url); |
| 282 std::string type_param; |
| 283 bool is_giant_webview = false; |
| 284 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "type", &type_param)) { |
| 285 if (type_param == "malware") { |
| 286 threat_type = safe_browsing::SB_THREAT_TYPE_URL_MALWARE; |
| 287 } else if (type_param == "phishing") { |
| 288 threat_type = safe_browsing::SB_THREAT_TYPE_URL_PHISHING; |
| 289 } else if (type_param == "giant") { |
| 290 threat_type = safe_browsing::SB_THREAT_TYPE_URL_MALWARE; |
| 291 is_giant_webview = true; |
| 292 } |
| 293 } |
| 294 safe_browsing::SafeBrowsingBlockingPage::UnsafeResource resource; |
| 295 resource.url = request_url; |
| 296 resource.is_subresource = request_url != main_frame_url; |
| 297 resource.is_subframe = false; |
| 298 resource.threat_type = threat_type; |
| 299 resource.web_contents_getter = |
| 300 security_interstitials::UnsafeResource::GetWebContentsGetter( |
| 301 web_contents->GetRenderProcessHost()->GetID(), |
| 302 web_contents->GetMainFrame()->GetRoutingID()); |
| 303 resource.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3; |
| 304 |
| 305 // Normally safebrowsing interstitial types which block the main page load |
| 306 // (SB_THREAT_TYPE_URL_MALWARE, SB_THREAT_TYPE_URL_PHISHING, and |
| 307 // SB_THREAT_TYPE_URL_UNWANTED on main-frame loads) would expect there to be a |
| 308 // pending navigation when the SafeBrowsingBlockingPage is created. This demo |
| 309 // creates a SafeBrowsingBlockingPage but does not actually show a real |
| 310 // interstitial. Instead it extracts the html and displays it manually, so the |
| 311 // parts which depend on the NavigationEntry are not hit. |
| 312 return TestSafeBrowsingBlockingPageQuiet::CreateBlockingPage( |
| 313 g_browser_process->safe_browsing_service()->ui_manager().get(), |
| 314 web_contents, main_frame_url, resource, is_giant_webview); |
| 315 } |
| 316 |
| 267 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 317 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 268 CaptivePortalBlockingPage* CreateCaptivePortalBlockingPage( | 318 CaptivePortalBlockingPage* CreateCaptivePortalBlockingPage( |
| 269 content::WebContents* web_contents) { | 319 content::WebContents* web_contents) { |
| 270 bool is_wifi_connection = false; | 320 bool is_wifi_connection = false; |
| 271 GURL landing_url("https://captive.portal/login"); | 321 GURL landing_url("https://captive.portal/login"); |
| 272 GURL request_url("https://google.com"); | 322 GURL request_url("https://google.com"); |
| 273 // Not initialized to a default value, since non-empty wifi_ssid is | 323 // Not initialized to a default value, since non-empty wifi_ssid is |
| 274 // considered a wifi connection, even if is_wifi_connection is false. | 324 // considered a wifi connection, even if is_wifi_connection is false. |
| 275 std::string wifi_ssid; | 325 std::string wifi_ssid; |
| 276 | 326 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 const std::string& path, | 396 const std::string& path, |
| 347 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | 397 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 348 const content::URLDataSource::GotDataCallback& callback) { | 398 const content::URLDataSource::GotDataCallback& callback) { |
| 349 content::WebContents* web_contents = wc_getter.Run(); | 399 content::WebContents* web_contents = wc_getter.Run(); |
| 350 if (!web_contents) { | 400 if (!web_contents) { |
| 351 // When browser-side navigation is enabled, web_contents can be null if | 401 // When browser-side navigation is enabled, web_contents can be null if |
| 352 // the tab is closing. Nothing to do in this case. | 402 // the tab is closing. Nothing to do in this case. |
| 353 return; | 403 return; |
| 354 } | 404 } |
| 355 std::unique_ptr<content::InterstitialPageDelegate> interstitial_delegate; | 405 std::unique_ptr<content::InterstitialPageDelegate> interstitial_delegate; |
| 406 std::string html; |
| 356 if (base::StartsWith(path, "ssl", base::CompareCase::SENSITIVE)) { | 407 if (base::StartsWith(path, "ssl", base::CompareCase::SENSITIVE)) { |
| 357 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents)); | 408 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents)); |
| 358 } else if (base::StartsWith(path, "safebrowsing", | 409 } else if (base::StartsWith(path, "safebrowsing", |
| 359 base::CompareCase::SENSITIVE)) { | 410 base::CompareCase::SENSITIVE)) { |
| 360 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents)); | 411 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents)); |
| 361 } else if (base::StartsWith(path, "clock", base::CompareCase::SENSITIVE)) { | 412 } else if (base::StartsWith(path, "clock", base::CompareCase::SENSITIVE)) { |
| 362 interstitial_delegate.reset(CreateBadClockBlockingPage(web_contents)); | 413 interstitial_delegate.reset(CreateBadClockBlockingPage(web_contents)); |
| 363 } | 414 } |
| 364 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 415 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 365 else if (base::StartsWith(path, "captiveportal", | 416 else if (base::StartsWith(path, "captiveportal", |
| 366 base::CompareCase::SENSITIVE)) | 417 base::CompareCase::SENSITIVE)) |
| 367 { | 418 { |
| 368 interstitial_delegate.reset(CreateCaptivePortalBlockingPage(web_contents)); | 419 interstitial_delegate.reset(CreateCaptivePortalBlockingPage(web_contents)); |
| 369 } | 420 } |
| 370 #endif | 421 #endif |
| 371 std::string html; | |
| 372 if (base::StartsWith(path, "supervised_user", base::CompareCase::SENSITIVE)) { | 422 if (base::StartsWith(path, "supervised_user", base::CompareCase::SENSITIVE)) { |
| 373 html = GetSupervisedUserInterstitialHTML(path); | 423 html = GetSupervisedUserInterstitialHTML(path); |
| 424 } else if (base::StartsWith(path, "quietsafebrowsing", |
| 425 base::CompareCase::SENSITIVE)) { |
| 426 TestSafeBrowsingBlockingPageQuiet* blocking_page = |
| 427 CreateSafeBrowsingQuietBlockingPage(web_contents); |
| 428 interstitial_delegate.reset(blocking_page); |
| 429 html = blocking_page->GetHTML(); |
| 374 } else if (interstitial_delegate.get()) { | 430 } else if (interstitial_delegate.get()) { |
| 375 html = interstitial_delegate.get()->GetHTMLContents(); | 431 html = interstitial_delegate.get()->GetHTMLContents(); |
| 376 } else { | 432 } else { |
| 377 html = ResourceBundle::GetSharedInstance() | 433 html = ResourceBundle::GetSharedInstance() |
| 378 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) | 434 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) |
| 379 .as_string(); | 435 .as_string(); |
| 380 } | 436 } |
| 381 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; | 437 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; |
| 382 html_bytes->data().assign(html.begin(), html.end()); | 438 html_bytes->data().assign(html.begin(), html.end()); |
| 383 callback.Run(html_bytes.get()); | 439 callback.Run(html_bytes.get()); |
| 384 } | 440 } |
| 385 | 441 |
| 386 std::string InterstitialHTMLSource::GetSupervisedUserInterstitialHTML( | 442 std::string InterstitialHTMLSource::GetSupervisedUserInterstitialHTML( |
| 387 const std::string& path) { | 443 const std::string& path) { |
| 388 GURL url("https://localhost/" + path); | 444 GURL url("https://localhost/" + path); |
| 389 | 445 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 } else if (reason_string == "not_signed_in") { | 482 } else if (reason_string == "not_signed_in") { |
| 427 reason = supervised_user_error_page::NOT_SIGNED_IN; | 483 reason = supervised_user_error_page::NOT_SIGNED_IN; |
| 428 } | 484 } |
| 429 } | 485 } |
| 430 | 486 |
| 431 return supervised_user_error_page::BuildHtml( | 487 return supervised_user_error_page::BuildHtml( |
| 432 allow_access_requests, profile_image_url, profile_image_url2, custodian, | 488 allow_access_requests, profile_image_url, profile_image_url2, custodian, |
| 433 custodian_email, second_custodian, second_custodian_email, | 489 custodian_email, second_custodian, second_custodian_email, |
| 434 is_child_account, reason, g_browser_process->GetApplicationLocale()); | 490 is_child_account, reason, g_browser_process->GetApplicationLocale()); |
| 435 } | 491 } |
| OLD | NEW |