| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ssl/chrome_security_state_model_client.h" | 5 #include "chrome/browser/ssl/chrome_security_state_model_client.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 secure_explanations.back().summary); | 162 secure_explanations.back().summary); |
| 163 EXPECT_EQ( | 163 EXPECT_EQ( |
| 164 l10n_util::GetStringUTF8(IDS_SECURE_PROTOCOL_AND_CIPHERSUITE_DESCRIPTION), | 164 l10n_util::GetStringUTF8(IDS_SECURE_PROTOCOL_AND_CIPHERSUITE_DESCRIPTION), |
| 165 secure_explanations.back().description); | 165 secure_explanations.back().description); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void CheckSecurityInfoForSecure( | 168 void CheckSecurityInfoForSecure( |
| 169 content::WebContents* contents, | 169 content::WebContents* contents, |
| 170 SecurityStateModel::SecurityLevel expect_security_level, | 170 SecurityStateModel::SecurityLevel expect_security_level, |
| 171 SecurityStateModel::SHA1DeprecationStatus expect_sha1_status, | 171 SecurityStateModel::SHA1DeprecationStatus expect_sha1_status, |
| 172 SecurityStateModel::MixedContentStatus expect_mixed_content_status, | 172 SecurityStateModel::ContentStatus expect_mixed_content_status, |
| 173 bool pkp_bypassed, | 173 bool pkp_bypassed, |
| 174 bool expect_cert_error) { | 174 bool expect_cert_error) { |
| 175 ASSERT_TRUE(contents); | 175 ASSERT_TRUE(contents); |
| 176 | 176 |
| 177 ChromeSecurityStateModelClient* model_client = | 177 ChromeSecurityStateModelClient* model_client = |
| 178 ChromeSecurityStateModelClient::FromWebContents(contents); | 178 ChromeSecurityStateModelClient::FromWebContents(contents); |
| 179 ASSERT_TRUE(model_client); | 179 ASSERT_TRUE(model_client); |
| 180 const SecurityStateModel::SecurityInfo& security_info = | 180 const SecurityStateModel::SecurityInfo& security_info = |
| 181 model_client->GetSecurityInfo(); | 181 model_client->GetSecurityInfo(); |
| 182 EXPECT_EQ(expect_security_level, security_info.security_level); | 182 EXPECT_EQ(expect_security_level, security_info.security_level); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 198 ASSERT_TRUE(contents); | 198 ASSERT_TRUE(contents); |
| 199 | 199 |
| 200 ChromeSecurityStateModelClient* model_client = | 200 ChromeSecurityStateModelClient* model_client = |
| 201 ChromeSecurityStateModelClient::FromWebContents(contents); | 201 ChromeSecurityStateModelClient::FromWebContents(contents); |
| 202 ASSERT_TRUE(model_client); | 202 ASSERT_TRUE(model_client); |
| 203 const SecurityStateModel::SecurityInfo& security_info = | 203 const SecurityStateModel::SecurityInfo& security_info = |
| 204 model_client->GetSecurityInfo(); | 204 model_client->GetSecurityInfo(); |
| 205 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); | 205 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); |
| 206 EXPECT_EQ(SecurityStateModel::NO_DEPRECATED_SHA1, | 206 EXPECT_EQ(SecurityStateModel::NO_DEPRECATED_SHA1, |
| 207 security_info.sha1_deprecation_status); | 207 security_info.sha1_deprecation_status); |
| 208 EXPECT_EQ(SecurityStateModel::NO_MIXED_CONTENT, | 208 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_NONE, |
| 209 security_info.mixed_content_status); | 209 security_info.mixed_content_status); |
| 210 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); | 210 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); |
| 211 EXPECT_FALSE(security_info.scheme_is_cryptographic); | 211 EXPECT_FALSE(security_info.scheme_is_cryptographic); |
| 212 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); | 212 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); |
| 213 EXPECT_EQ(-1, security_info.security_bits); | 213 EXPECT_EQ(-1, security_info.security_bits); |
| 214 EXPECT_EQ(0, security_info.cert_id); | 214 EXPECT_EQ(0, security_info.cert_id); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void ProceedThroughInterstitial(content::WebContents* tab) { | 217 void ProceedThroughInterstitial(content::WebContents* tab) { |
| 218 content::InterstitialPage* interstitial_page = tab->GetInterstitialPage(); | 218 content::InterstitialPage* interstitial_page = tab->GetInterstitialPage(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 ASSERT_TRUE(contents); | 296 ASSERT_TRUE(contents); |
| 297 | 297 |
| 298 ChromeSecurityStateModelClient* model_client = | 298 ChromeSecurityStateModelClient* model_client = |
| 299 ChromeSecurityStateModelClient::FromWebContents(contents); | 299 ChromeSecurityStateModelClient::FromWebContents(contents); |
| 300 ASSERT_TRUE(model_client); | 300 ASSERT_TRUE(model_client); |
| 301 const SecurityStateModel::SecurityInfo& security_info = | 301 const SecurityStateModel::SecurityInfo& security_info = |
| 302 model_client->GetSecurityInfo(); | 302 model_client->GetSecurityInfo(); |
| 303 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); | 303 EXPECT_EQ(SecurityStateModel::NONE, security_info.security_level); |
| 304 EXPECT_EQ(SecurityStateModel::NO_DEPRECATED_SHA1, | 304 EXPECT_EQ(SecurityStateModel::NO_DEPRECATED_SHA1, |
| 305 security_info.sha1_deprecation_status); | 305 security_info.sha1_deprecation_status); |
| 306 EXPECT_EQ(SecurityStateModel::NO_MIXED_CONTENT, | 306 EXPECT_EQ(SecurityStateModel::CONTENT_STATUS_NONE, |
| 307 security_info.mixed_content_status); | 307 security_info.mixed_content_status); |
| 308 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); | 308 EXPECT_TRUE(security_info.sct_verify_statuses.empty()); |
| 309 EXPECT_FALSE(security_info.scheme_is_cryptographic); | 309 EXPECT_FALSE(security_info.scheme_is_cryptographic); |
| 310 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); | 310 EXPECT_FALSE(net::IsCertStatusError(security_info.cert_status)); |
| 311 EXPECT_EQ(0, security_info.cert_id); | 311 EXPECT_EQ(0, security_info.cert_id); |
| 312 EXPECT_EQ(-1, security_info.security_bits); | 312 EXPECT_EQ(-1, security_info.security_bits); |
| 313 EXPECT_EQ(0, security_info.connection_status); | 313 EXPECT_EQ(0, security_info.connection_status); |
| 314 } | 314 } |
| 315 | 315 |
| 316 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, HttpsPage) { | 316 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, HttpsPage) { |
| 317 ASSERT_TRUE(https_server_.Start()); | 317 ASSERT_TRUE(https_server_.Start()); |
| 318 SetUpMockCertVerifierForHttpsServer(0, net::OK); | 318 SetUpMockCertVerifierForHttpsServer(0, net::OK); |
| 319 | 319 |
| 320 ui_test_utils::NavigateToURL(browser(), | 320 ui_test_utils::NavigateToURL(browser(), |
| 321 https_server_.GetURL("/ssl/google.html")); | 321 https_server_.GetURL("/ssl/google.html")); |
| 322 CheckSecurityInfoForSecure( | 322 CheckSecurityInfoForSecure( |
| 323 browser()->tab_strip_model()->GetActiveWebContents(), | 323 browser()->tab_strip_model()->GetActiveWebContents(), |
| 324 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, | 324 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, |
| 325 SecurityStateModel::NO_MIXED_CONTENT, false, | 325 SecurityStateModel::CONTENT_STATUS_NONE, false, |
| 326 false /* expect cert status error */); | 326 false /* expect cert status error */); |
| 327 } | 327 } |
| 328 | 328 |
| 329 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, SHA1Broken) { | 329 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, SHA1Broken) { |
| 330 ASSERT_TRUE(https_server_.Start()); | 330 ASSERT_TRUE(https_server_.Start()); |
| 331 // The test server uses a long-lived cert by default, so a SHA1 | 331 // The test server uses a long-lived cert by default, so a SHA1 |
| 332 // signature in it will register as a "broken" condition rather than | 332 // signature in it will register as a "broken" condition rather than |
| 333 // "warning". | 333 // "warning". |
| 334 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, | 334 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_SHA1_SIGNATURE_PRESENT, |
| 335 net::OK); | 335 net::OK); |
| 336 | 336 |
| 337 ui_test_utils::NavigateToURL(browser(), | 337 ui_test_utils::NavigateToURL(browser(), |
| 338 https_server_.GetURL("/ssl/google.html")); | 338 https_server_.GetURL("/ssl/google.html")); |
| 339 CheckSecurityInfoForSecure( | 339 CheckSecurityInfoForSecure( |
| 340 browser()->tab_strip_model()->GetActiveWebContents(), | 340 browser()->tab_strip_model()->GetActiveWebContents(), |
| 341 SecurityStateModel::SECURITY_ERROR, | 341 SecurityStateModel::SECURITY_ERROR, |
| 342 SecurityStateModel::DEPRECATED_SHA1_MAJOR, | 342 SecurityStateModel::DEPRECATED_SHA1_MAJOR, |
| 343 SecurityStateModel::NO_MIXED_CONTENT, false, | 343 SecurityStateModel::CONTENT_STATUS_NONE, false, |
| 344 false /* expect cert status error */); | 344 false /* expect cert status error */); |
| 345 } | 345 } |
| 346 | 346 |
| 347 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, MixedContent) { | 347 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, MixedContent) { |
| 348 ASSERT_TRUE(embedded_test_server()->Start()); | 348 ASSERT_TRUE(embedded_test_server()->Start()); |
| 349 ASSERT_TRUE(https_server_.Start()); | 349 ASSERT_TRUE(https_server_.Start()); |
| 350 SetUpMockCertVerifierForHttpsServer(0, net::OK); | 350 SetUpMockCertVerifierForHttpsServer(0, net::OK); |
| 351 host_resolver()->AddRule("example.test", | 351 host_resolver()->AddRule("example.test", |
| 352 https_server_.GetURL("/title1.html").host()); | 352 https_server_.GetURL("/title1.html").host()); |
| 353 | 353 |
| 354 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair(); | 354 net::HostPortPair replacement_pair = embedded_test_server()->host_port_pair(); |
| 355 replacement_pair.set_host("example.test"); | 355 replacement_pair.set_host("example.test"); |
| 356 | 356 |
| 357 // Navigate to an HTTPS page that displays mixed content. | 357 // Navigate to an HTTPS page that displays mixed content. |
| 358 std::string replacement_path; | 358 std::string replacement_path; |
| 359 GetFilePathWithHostAndPortReplacement( | 359 GetFilePathWithHostAndPortReplacement( |
| 360 "/ssl/page_displays_insecure_content.html", | 360 "/ssl/page_displays_insecure_content.html", |
| 361 replacement_pair, &replacement_path); | 361 replacement_pair, &replacement_path); |
| 362 ui_test_utils::NavigateToURL(browser(), | 362 ui_test_utils::NavigateToURL(browser(), |
| 363 https_server_.GetURL(replacement_path)); | 363 https_server_.GetURL(replacement_path)); |
| 364 CheckSecurityInfoForSecure( | 364 CheckSecurityInfoForSecure( |
| 365 browser()->tab_strip_model()->GetActiveWebContents(), | 365 browser()->tab_strip_model()->GetActiveWebContents(), |
| 366 SecurityStateModel::NONE, SecurityStateModel::NO_DEPRECATED_SHA1, | 366 SecurityStateModel::NONE, SecurityStateModel::NO_DEPRECATED_SHA1, |
| 367 SecurityStateModel::DISPLAYED_MIXED_CONTENT, false, | 367 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false, |
| 368 false /* expect cert status error */); | 368 false /* expect cert status error */); |
| 369 | 369 |
| 370 // Navigate to an HTTPS page that displays mixed content dynamically. | 370 // Navigate to an HTTPS page that displays mixed content dynamically. |
| 371 GetFilePathWithHostAndPortReplacement( | 371 GetFilePathWithHostAndPortReplacement( |
| 372 "/ssl/page_with_dynamic_insecure_content.html", | 372 "/ssl/page_with_dynamic_insecure_content.html", |
| 373 replacement_pair, &replacement_path); | 373 replacement_pair, &replacement_path); |
| 374 ui_test_utils::NavigateToURL(browser(), | 374 ui_test_utils::NavigateToURL(browser(), |
| 375 https_server_.GetURL(replacement_path)); | 375 https_server_.GetURL(replacement_path)); |
| 376 CheckSecurityInfoForSecure( | 376 CheckSecurityInfoForSecure( |
| 377 browser()->tab_strip_model()->GetActiveWebContents(), | 377 browser()->tab_strip_model()->GetActiveWebContents(), |
| 378 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, | 378 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, |
| 379 SecurityStateModel::NO_MIXED_CONTENT, false, | 379 SecurityStateModel::CONTENT_STATUS_NONE, false, |
| 380 false /* expect cert status error */); | 380 false /* expect cert status error */); |
| 381 // Load the insecure image. | 381 // Load the insecure image. |
| 382 bool js_result = false; | 382 bool js_result = false; |
| 383 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 383 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 384 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", | 384 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", |
| 385 &js_result)); | 385 &js_result)); |
| 386 EXPECT_TRUE(js_result); | 386 EXPECT_TRUE(js_result); |
| 387 CheckSecurityInfoForSecure( | 387 CheckSecurityInfoForSecure( |
| 388 browser()->tab_strip_model()->GetActiveWebContents(), | 388 browser()->tab_strip_model()->GetActiveWebContents(), |
| 389 SecurityStateModel::NONE, SecurityStateModel::NO_DEPRECATED_SHA1, | 389 SecurityStateModel::NONE, SecurityStateModel::NO_DEPRECATED_SHA1, |
| 390 SecurityStateModel::DISPLAYED_MIXED_CONTENT, false, | 390 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false, |
| 391 false /* expect cert status error */); | 391 false /* expect cert status error */); |
| 392 | 392 |
| 393 // Navigate to an HTTPS page that runs mixed content. | 393 // Navigate to an HTTPS page that runs mixed content. |
| 394 GetFilePathWithHostAndPortReplacement( | 394 GetFilePathWithHostAndPortReplacement( |
| 395 "/ssl/page_runs_insecure_content.html", | 395 "/ssl/page_runs_insecure_content.html", |
| 396 replacement_pair, &replacement_path); | 396 replacement_pair, &replacement_path); |
| 397 ui_test_utils::NavigateToURL(browser(), | 397 ui_test_utils::NavigateToURL(browser(), |
| 398 https_server_.GetURL(replacement_path)); | 398 https_server_.GetURL(replacement_path)); |
| 399 CheckSecurityInfoForSecure( | 399 CheckSecurityInfoForSecure( |
| 400 browser()->tab_strip_model()->GetActiveWebContents(), | 400 browser()->tab_strip_model()->GetActiveWebContents(), |
| 401 SecurityStateModel::SECURITY_ERROR, | 401 SecurityStateModel::SECURITY_ERROR, |
| 402 SecurityStateModel::NO_DEPRECATED_SHA1, | 402 SecurityStateModel::NO_DEPRECATED_SHA1, |
| 403 SecurityStateModel::RAN_MIXED_CONTENT, false, | 403 SecurityStateModel::CONTENT_STATUS_RAN, false, |
| 404 false /* expect cert status error */); | 404 false /* expect cert status error */); |
| 405 | 405 |
| 406 // Navigate to an HTTPS page that runs and displays mixed content. | 406 // Navigate to an HTTPS page that runs and displays mixed content. |
| 407 GetFilePathWithHostAndPortReplacement( | 407 GetFilePathWithHostAndPortReplacement( |
| 408 "/ssl/page_runs_and_displays_insecure_content.html", | 408 "/ssl/page_runs_and_displays_insecure_content.html", |
| 409 replacement_pair, &replacement_path); | 409 replacement_pair, &replacement_path); |
| 410 ui_test_utils::NavigateToURL(browser(), | 410 ui_test_utils::NavigateToURL(browser(), |
| 411 https_server_.GetURL(replacement_path)); | 411 https_server_.GetURL(replacement_path)); |
| 412 CheckSecurityInfoForSecure( | 412 CheckSecurityInfoForSecure( |
| 413 browser()->tab_strip_model()->GetActiveWebContents(), | 413 browser()->tab_strip_model()->GetActiveWebContents(), |
| 414 SecurityStateModel::SECURITY_ERROR, | 414 SecurityStateModel::SECURITY_ERROR, |
| 415 SecurityStateModel::NO_DEPRECATED_SHA1, | 415 SecurityStateModel::NO_DEPRECATED_SHA1, |
| 416 SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT, false, | 416 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN, false, |
| 417 false /* expect cert status error */); | 417 false /* expect cert status error */); |
| 418 | 418 |
| 419 // Navigate to an HTTPS page that runs mixed content in an iframe. | 419 // Navigate to an HTTPS page that runs mixed content in an iframe. |
| 420 net::HostPortPair host_port_pair = | 420 net::HostPortPair host_port_pair = |
| 421 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html")); | 421 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html")); |
| 422 host_port_pair.set_host("different-host.test"); | 422 host_port_pair.set_host("different-host.test"); |
| 423 host_resolver()->AddRule("different-host.test", | 423 host_resolver()->AddRule("different-host.test", |
| 424 https_server_.GetURL("/title1.html").host()); | 424 https_server_.GetURL("/title1.html").host()); |
| 425 host_resolver()->AddRule( | 425 host_resolver()->AddRule( |
| 426 "different-http-host.test", | 426 "different-http-host.test", |
| 427 embedded_test_server()->GetURL("/title1.html").host()); | 427 embedded_test_server()->GetURL("/title1.html").host()); |
| 428 GetFilePathWithHostAndPortReplacement( | 428 GetFilePathWithHostAndPortReplacement( |
| 429 "/ssl/page_runs_insecure_content_in_iframe.html", host_port_pair, | 429 "/ssl/page_runs_insecure_content_in_iframe.html", host_port_pair, |
| 430 &replacement_path); | 430 &replacement_path); |
| 431 ui_test_utils::NavigateToURL(browser(), | 431 ui_test_utils::NavigateToURL(browser(), |
| 432 https_server_.GetURL(replacement_path)); | 432 https_server_.GetURL(replacement_path)); |
| 433 CheckSecurityInfoForSecure( | 433 CheckSecurityInfoForSecure( |
| 434 browser()->tab_strip_model()->GetActiveWebContents(), | 434 browser()->tab_strip_model()->GetActiveWebContents(), |
| 435 SecurityStateModel::SECURITY_ERROR, | 435 SecurityStateModel::SECURITY_ERROR, |
| 436 SecurityStateModel::NO_DEPRECATED_SHA1, | 436 SecurityStateModel::NO_DEPRECATED_SHA1, |
| 437 SecurityStateModel::RAN_MIXED_CONTENT, false, | 437 SecurityStateModel::CONTENT_STATUS_RAN, false, |
| 438 false /* expect cert status error */); | 438 false /* expect cert status error */); |
| 439 } | 439 } |
| 440 | 440 |
| 441 // Same as the test above but with a long-lived SHA1 cert. | 441 // Same as the test above but with a long-lived SHA1 cert. |
| 442 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, | 442 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, |
| 443 MixedContentWithBrokenSHA1) { | 443 MixedContentWithBrokenSHA1) { |
| 444 ASSERT_TRUE(embedded_test_server()->Start()); | 444 ASSERT_TRUE(embedded_test_server()->Start()); |
| 445 ASSERT_TRUE(https_server_.Start()); | 445 ASSERT_TRUE(https_server_.Start()); |
| 446 // The test server uses a long-lived cert by default, so a SHA1 | 446 // The test server uses a long-lived cert by default, so a SHA1 |
| 447 // signature in it will register as a "broken" condition rather than | 447 // signature in it will register as a "broken" condition rather than |
| (...skipping 11 matching lines...) Expand all Loading... |
| 459 std::string replacement_path; | 459 std::string replacement_path; |
| 460 GetFilePathWithHostAndPortReplacement( | 460 GetFilePathWithHostAndPortReplacement( |
| 461 "/ssl/page_displays_insecure_content.html", | 461 "/ssl/page_displays_insecure_content.html", |
| 462 replacement_pair, &replacement_path); | 462 replacement_pair, &replacement_path); |
| 463 ui_test_utils::NavigateToURL(browser(), | 463 ui_test_utils::NavigateToURL(browser(), |
| 464 https_server_.GetURL(replacement_path)); | 464 https_server_.GetURL(replacement_path)); |
| 465 CheckSecurityInfoForSecure( | 465 CheckSecurityInfoForSecure( |
| 466 browser()->tab_strip_model()->GetActiveWebContents(), | 466 browser()->tab_strip_model()->GetActiveWebContents(), |
| 467 SecurityStateModel::SECURITY_ERROR, | 467 SecurityStateModel::SECURITY_ERROR, |
| 468 SecurityStateModel::DEPRECATED_SHA1_MAJOR, | 468 SecurityStateModel::DEPRECATED_SHA1_MAJOR, |
| 469 SecurityStateModel::DISPLAYED_MIXED_CONTENT, false, | 469 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false, |
| 470 false /* expect cert status error */); | 470 false /* expect cert status error */); |
| 471 | 471 |
| 472 // Navigate to an HTTPS page that displays mixed content dynamically. | 472 // Navigate to an HTTPS page that displays mixed content dynamically. |
| 473 GetFilePathWithHostAndPortReplacement( | 473 GetFilePathWithHostAndPortReplacement( |
| 474 "/ssl/page_with_dynamic_insecure_content.html", | 474 "/ssl/page_with_dynamic_insecure_content.html", |
| 475 replacement_pair, &replacement_path); | 475 replacement_pair, &replacement_path); |
| 476 ui_test_utils::NavigateToURL(browser(), | 476 ui_test_utils::NavigateToURL(browser(), |
| 477 https_server_.GetURL(replacement_path)); | 477 https_server_.GetURL(replacement_path)); |
| 478 CheckSecurityInfoForSecure( | 478 CheckSecurityInfoForSecure( |
| 479 browser()->tab_strip_model()->GetActiveWebContents(), | 479 browser()->tab_strip_model()->GetActiveWebContents(), |
| 480 SecurityStateModel::SECURITY_ERROR, | 480 SecurityStateModel::SECURITY_ERROR, |
| 481 SecurityStateModel::DEPRECATED_SHA1_MAJOR, | 481 SecurityStateModel::DEPRECATED_SHA1_MAJOR, |
| 482 SecurityStateModel::NO_MIXED_CONTENT, false, | 482 SecurityStateModel::CONTENT_STATUS_NONE, false, |
| 483 false /* expect cert status error */); | 483 false /* expect cert status error */); |
| 484 // Load the insecure image. | 484 // Load the insecure image. |
| 485 bool js_result = false; | 485 bool js_result = false; |
| 486 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 486 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 487 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", | 487 browser()->tab_strip_model()->GetActiveWebContents(), "loadBadImage();", |
| 488 &js_result)); | 488 &js_result)); |
| 489 EXPECT_TRUE(js_result); | 489 EXPECT_TRUE(js_result); |
| 490 CheckSecurityInfoForSecure( | 490 CheckSecurityInfoForSecure( |
| 491 browser()->tab_strip_model()->GetActiveWebContents(), | 491 browser()->tab_strip_model()->GetActiveWebContents(), |
| 492 SecurityStateModel::SECURITY_ERROR, | 492 SecurityStateModel::SECURITY_ERROR, |
| 493 SecurityStateModel::DEPRECATED_SHA1_MAJOR, | 493 SecurityStateModel::DEPRECATED_SHA1_MAJOR, |
| 494 SecurityStateModel::DISPLAYED_MIXED_CONTENT, false, | 494 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false, |
| 495 false /* expect cert status error */); | 495 false /* expect cert status error */); |
| 496 | 496 |
| 497 // Navigate to an HTTPS page that runs mixed content. | 497 // Navigate to an HTTPS page that runs mixed content. |
| 498 GetFilePathWithHostAndPortReplacement( | 498 GetFilePathWithHostAndPortReplacement( |
| 499 "/ssl/page_runs_insecure_content.html", | 499 "/ssl/page_runs_insecure_content.html", |
| 500 replacement_pair, &replacement_path); | 500 replacement_pair, &replacement_path); |
| 501 ui_test_utils::NavigateToURL(browser(), | 501 ui_test_utils::NavigateToURL(browser(), |
| 502 https_server_.GetURL(replacement_path)); | 502 https_server_.GetURL(replacement_path)); |
| 503 CheckSecurityInfoForSecure( | 503 CheckSecurityInfoForSecure( |
| 504 browser()->tab_strip_model()->GetActiveWebContents(), | 504 browser()->tab_strip_model()->GetActiveWebContents(), |
| 505 SecurityStateModel::SECURITY_ERROR, | 505 SecurityStateModel::SECURITY_ERROR, |
| 506 SecurityStateModel::DEPRECATED_SHA1_MAJOR, | 506 SecurityStateModel::DEPRECATED_SHA1_MAJOR, |
| 507 SecurityStateModel::RAN_MIXED_CONTENT, false, | 507 SecurityStateModel::CONTENT_STATUS_RAN, false, |
| 508 false /* expect cert status error */); | 508 false /* expect cert status error */); |
| 509 | 509 |
| 510 // Navigate to an HTTPS page that runs and displays mixed content. | 510 // Navigate to an HTTPS page that runs and displays mixed content. |
| 511 GetFilePathWithHostAndPortReplacement( | 511 GetFilePathWithHostAndPortReplacement( |
| 512 "/ssl/page_runs_and_displays_insecure_content.html", | 512 "/ssl/page_runs_and_displays_insecure_content.html", |
| 513 replacement_pair, &replacement_path); | 513 replacement_pair, &replacement_path); |
| 514 ui_test_utils::NavigateToURL(browser(), | 514 ui_test_utils::NavigateToURL(browser(), |
| 515 https_server_.GetURL(replacement_path)); | 515 https_server_.GetURL(replacement_path)); |
| 516 CheckSecurityInfoForSecure( | 516 CheckSecurityInfoForSecure( |
| 517 browser()->tab_strip_model()->GetActiveWebContents(), | 517 browser()->tab_strip_model()->GetActiveWebContents(), |
| 518 SecurityStateModel::SECURITY_ERROR, | 518 SecurityStateModel::SECURITY_ERROR, |
| 519 SecurityStateModel::DEPRECATED_SHA1_MAJOR, | 519 SecurityStateModel::DEPRECATED_SHA1_MAJOR, |
| 520 SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT, false, | 520 SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN, false, |
| 521 false /* expect cert status error */); | 521 false /* expect cert status error */); |
| 522 } | 522 } |
| 523 | 523 |
| 524 // Tests that the Content Security Policy block-all-mixed-content | 524 // Tests that the Content Security Policy block-all-mixed-content |
| 525 // directive stops mixed content from running. | 525 // directive stops mixed content from running. |
| 526 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, | 526 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, |
| 527 MixedContentStrictBlocking) { | 527 MixedContentStrictBlocking) { |
| 528 ASSERT_TRUE(https_server_.Start()); | 528 ASSERT_TRUE(https_server_.Start()); |
| 529 SetUpMockCertVerifierForHttpsServer(0, net::OK); | 529 SetUpMockCertVerifierForHttpsServer(0, net::OK); |
| 530 | 530 |
| 531 // Navigate to an HTTPS page that tries to run mixed content in an | 531 // Navigate to an HTTPS page that tries to run mixed content in an |
| 532 // iframe, with strict mixed content blocking. | 532 // iframe, with strict mixed content blocking. |
| 533 std::string replacement_path; | 533 std::string replacement_path; |
| 534 net::HostPortPair host_port_pair = | 534 net::HostPortPair host_port_pair = |
| 535 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html")); | 535 net::HostPortPair::FromURL(https_server_.GetURL("/title1.html")); |
| 536 host_port_pair.set_host("different-host.test"); | 536 host_port_pair.set_host("different-host.test"); |
| 537 host_resolver()->AddRule("different-host.test", | 537 host_resolver()->AddRule("different-host.test", |
| 538 https_server_.GetURL("/title1.html").host()); | 538 https_server_.GetURL("/title1.html").host()); |
| 539 GetFilePathWithHostAndPortReplacement( | 539 GetFilePathWithHostAndPortReplacement( |
| 540 "/ssl/page_runs_insecure_content_in_iframe_with_strict_blocking.html", | 540 "/ssl/page_runs_insecure_content_in_iframe_with_strict_blocking.html", |
| 541 host_port_pair, &replacement_path); | 541 host_port_pair, &replacement_path); |
| 542 ui_test_utils::NavigateToURL(browser(), | 542 ui_test_utils::NavigateToURL(browser(), |
| 543 https_server_.GetURL(replacement_path)); | 543 https_server_.GetURL(replacement_path)); |
| 544 CheckSecurityInfoForSecure( | 544 CheckSecurityInfoForSecure( |
| 545 browser()->tab_strip_model()->GetActiveWebContents(), | 545 browser()->tab_strip_model()->GetActiveWebContents(), |
| 546 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, | 546 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, |
| 547 SecurityStateModel::NO_MIXED_CONTENT, false, | 547 SecurityStateModel::CONTENT_STATUS_NONE, false, |
| 548 false /* expect cert status error */); | 548 false /* expect cert status error */); |
| 549 } | 549 } |
| 550 | 550 |
| 551 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, BrokenHTTPS) { | 551 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, BrokenHTTPS) { |
| 552 ASSERT_TRUE(embedded_test_server()->Start()); | 552 ASSERT_TRUE(embedded_test_server()->Start()); |
| 553 ASSERT_TRUE(https_server_.Start()); | 553 ASSERT_TRUE(https_server_.Start()); |
| 554 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_DATE_INVALID, | 554 SetUpMockCertVerifierForHttpsServer(net::CERT_STATUS_DATE_INVALID, |
| 555 net::ERR_CERT_DATE_INVALID); | 555 net::ERR_CERT_DATE_INVALID); |
| 556 | 556 |
| 557 ui_test_utils::NavigateToURL(browser(), | 557 ui_test_utils::NavigateToURL(browser(), |
| 558 https_server_.GetURL("/ssl/google.html")); | 558 https_server_.GetURL("/ssl/google.html")); |
| 559 CheckSecurityInfoForSecure( | 559 CheckSecurityInfoForSecure( |
| 560 browser()->tab_strip_model()->GetActiveWebContents(), | 560 browser()->tab_strip_model()->GetActiveWebContents(), |
| 561 SecurityStateModel::SECURITY_ERROR, | 561 SecurityStateModel::SECURITY_ERROR, |
| 562 SecurityStateModel::NO_DEPRECATED_SHA1, | 562 SecurityStateModel::NO_DEPRECATED_SHA1, |
| 563 SecurityStateModel::NO_MIXED_CONTENT, false, | 563 SecurityStateModel::CONTENT_STATUS_NONE, false, |
| 564 true /* expect cert status error */); | 564 true /* expect cert status error */); |
| 565 | 565 |
| 566 ProceedThroughInterstitial( | 566 ProceedThroughInterstitial( |
| 567 browser()->tab_strip_model()->GetActiveWebContents()); | 567 browser()->tab_strip_model()->GetActiveWebContents()); |
| 568 | 568 |
| 569 CheckSecurityInfoForSecure( | 569 CheckSecurityInfoForSecure( |
| 570 browser()->tab_strip_model()->GetActiveWebContents(), | 570 browser()->tab_strip_model()->GetActiveWebContents(), |
| 571 SecurityStateModel::SECURITY_ERROR, | 571 SecurityStateModel::SECURITY_ERROR, |
| 572 SecurityStateModel::NO_DEPRECATED_SHA1, | 572 SecurityStateModel::NO_DEPRECATED_SHA1, |
| 573 SecurityStateModel::NO_MIXED_CONTENT, false, | 573 SecurityStateModel::CONTENT_STATUS_NONE, false, |
| 574 true /* expect cert status error */); | 574 true /* expect cert status error */); |
| 575 | 575 |
| 576 // Navigate to a broken HTTPS page that displays mixed content. | 576 // Navigate to a broken HTTPS page that displays mixed content. |
| 577 std::string replacement_path; | 577 std::string replacement_path; |
| 578 GetFilePathWithHostAndPortReplacement( | 578 GetFilePathWithHostAndPortReplacement( |
| 579 "/ssl/page_displays_insecure_content.html", | 579 "/ssl/page_displays_insecure_content.html", |
| 580 embedded_test_server()->host_port_pair(), &replacement_path); | 580 embedded_test_server()->host_port_pair(), &replacement_path); |
| 581 ui_test_utils::NavigateToURL(browser(), | 581 ui_test_utils::NavigateToURL(browser(), |
| 582 https_server_.GetURL(replacement_path)); | 582 https_server_.GetURL(replacement_path)); |
| 583 CheckSecurityInfoForSecure( | 583 CheckSecurityInfoForSecure( |
| 584 browser()->tab_strip_model()->GetActiveWebContents(), | 584 browser()->tab_strip_model()->GetActiveWebContents(), |
| 585 SecurityStateModel::SECURITY_ERROR, | 585 SecurityStateModel::SECURITY_ERROR, |
| 586 SecurityStateModel::NO_DEPRECATED_SHA1, | 586 SecurityStateModel::NO_DEPRECATED_SHA1, |
| 587 SecurityStateModel::DISPLAYED_MIXED_CONTENT, false, | 587 SecurityStateModel::CONTENT_STATUS_DISPLAYED, false, |
| 588 true /* expect cert status error */); | 588 true /* expect cert status error */); |
| 589 } | 589 } |
| 590 | 590 |
| 591 const char kReportURI[] = "https://report-hpkp.test"; | 591 const char kReportURI[] = "https://report-hpkp.test"; |
| 592 | 592 |
| 593 class PKPModelClientTest : public ChromeSecurityStateModelClientTest { | 593 class PKPModelClientTest : public ChromeSecurityStateModelClientTest { |
| 594 public: | 594 public: |
| 595 void SetUpOnMainThread() override { | 595 void SetUpOnMainThread() override { |
| 596 ASSERT_TRUE(https_server_.Start()); | 596 ASSERT_TRUE(https_server_.Start()); |
| 597 url_request_context_getter_ = browser()->profile()->GetRequestContext(); | 597 url_request_context_getter_ = browser()->profile()->GetRequestContext(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 verify_result.public_key_hashes.push_back(hash); | 638 verify_result.public_key_hashes.push_back(hash); |
| 639 | 639 |
| 640 mock_cert_verifier()->AddResultForCert(cert.get(), verify_result, net::OK); | 640 mock_cert_verifier()->AddResultForCert(cert.get(), verify_result, net::OK); |
| 641 | 641 |
| 642 ui_test_utils::NavigateToURL(browser(), | 642 ui_test_utils::NavigateToURL(browser(), |
| 643 https_server_.GetURL("/ssl/google.html")); | 643 https_server_.GetURL("/ssl/google.html")); |
| 644 | 644 |
| 645 CheckSecurityInfoForSecure( | 645 CheckSecurityInfoForSecure( |
| 646 browser()->tab_strip_model()->GetActiveWebContents(), | 646 browser()->tab_strip_model()->GetActiveWebContents(), |
| 647 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, | 647 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, |
| 648 SecurityStateModel::NO_MIXED_CONTENT, true, false); | 648 SecurityStateModel::CONTENT_STATUS_NONE, true, false); |
| 649 | 649 |
| 650 const content::SecurityStyleExplanations& explanation = | 650 const content::SecurityStyleExplanations& explanation = |
| 651 observer.latest_explanations(); | 651 observer.latest_explanations(); |
| 652 EXPECT_TRUE(explanation.pkp_bypassed); | 652 EXPECT_TRUE(explanation.pkp_bypassed); |
| 653 EXPECT_FALSE(explanation.info_explanations.empty()); | 653 EXPECT_FALSE(explanation.info_explanations.empty()); |
| 654 } | 654 } |
| 655 | 655 |
| 656 IN_PROC_BROWSER_TEST_F(PKPModelClientTest, PKPEnforced) { | 656 IN_PROC_BROWSER_TEST_F(PKPModelClientTest, PKPEnforced) { |
| 657 content::WebContents* web_contents = | 657 content::WebContents* web_contents = |
| 658 browser()->tab_strip_model()->GetActiveWebContents(); | 658 browser()->tab_strip_model()->GetActiveWebContents(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 IN_PROC_BROWSER_TEST_F(SecurityStateModelLoadingTest, NavigationStateChanges) { | 725 IN_PROC_BROWSER_TEST_F(SecurityStateModelLoadingTest, NavigationStateChanges) { |
| 726 ASSERT_TRUE(https_server_.Start()); | 726 ASSERT_TRUE(https_server_.Start()); |
| 727 SetUpMockCertVerifierForHttpsServer(0, net::OK); | 727 SetUpMockCertVerifierForHttpsServer(0, net::OK); |
| 728 | 728 |
| 729 // Navigate to an HTTPS page. | 729 // Navigate to an HTTPS page. |
| 730 ui_test_utils::NavigateToURL(browser(), | 730 ui_test_utils::NavigateToURL(browser(), |
| 731 https_server_.GetURL("/ssl/google.html")); | 731 https_server_.GetURL("/ssl/google.html")); |
| 732 CheckSecurityInfoForSecure( | 732 CheckSecurityInfoForSecure( |
| 733 browser()->tab_strip_model()->GetActiveWebContents(), | 733 browser()->tab_strip_model()->GetActiveWebContents(), |
| 734 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, | 734 SecurityStateModel::SECURE, SecurityStateModel::NO_DEPRECATED_SHA1, |
| 735 SecurityStateModel::NO_MIXED_CONTENT, false, | 735 SecurityStateModel::CONTENT_STATUS_NONE, false, |
| 736 false /* expect cert status error */); | 736 false /* expect cert status error */); |
| 737 | 737 |
| 738 // Navigate to a page that doesn't finish loading. Test that the | 738 // Navigate to a page that doesn't finish loading. Test that the |
| 739 // security state is neutral while the page is loading. | 739 // security state is neutral while the page is loading. |
| 740 browser()->OpenURL(content::OpenURLParams( | 740 browser()->OpenURL(content::OpenURLParams( |
| 741 embedded_test_server()->GetURL("/title1.html"), content::Referrer(), | 741 embedded_test_server()->GetURL("/title1.html"), content::Referrer(), |
| 742 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); | 742 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); |
| 743 CheckSecurityInfoForNonSecure( | 743 CheckSecurityInfoForNonSecure( |
| 744 browser()->tab_strip_model()->GetActiveWebContents()); | 744 browser()->tab_strip_model()->GetActiveWebContents()); |
| 745 } | 745 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 757 content::WebContents* new_contents = content::WebContents::Create( | 757 content::WebContents* new_contents = content::WebContents::Create( |
| 758 content::WebContents::CreateParams(tab->GetBrowserContext())); | 758 content::WebContents::CreateParams(tab->GetBrowserContext())); |
| 759 content::NavigationController& controller = new_contents->GetController(); | 759 content::NavigationController& controller = new_contents->GetController(); |
| 760 ChromeSecurityStateModelClient::CreateForWebContents(new_contents); | 760 ChromeSecurityStateModelClient::CreateForWebContents(new_contents); |
| 761 CheckSecurityInfoForNonSecure(new_contents); | 761 CheckSecurityInfoForNonSecure(new_contents); |
| 762 controller.LoadURL(https_server_.GetURL("/title1.html"), content::Referrer(), | 762 controller.LoadURL(https_server_.GetURL("/title1.html"), content::Referrer(), |
| 763 ui::PAGE_TRANSITION_TYPED, std::string()); | 763 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 764 EXPECT_TRUE(content::WaitForLoadStop(new_contents)); | 764 EXPECT_TRUE(content::WaitForLoadStop(new_contents)); |
| 765 CheckSecurityInfoForSecure(new_contents, SecurityStateModel::SECURE, | 765 CheckSecurityInfoForSecure(new_contents, SecurityStateModel::SECURE, |
| 766 SecurityStateModel::NO_DEPRECATED_SHA1, | 766 SecurityStateModel::NO_DEPRECATED_SHA1, |
| 767 SecurityStateModel::NO_MIXED_CONTENT, false, | 767 SecurityStateModel::CONTENT_STATUS_NONE, false, |
| 768 false /* expect cert status error */); | 768 false /* expect cert status error */); |
| 769 | 769 |
| 770 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents, | 770 browser()->tab_strip_model()->InsertWebContentsAt(0, new_contents, |
| 771 TabStripModel::ADD_NONE); | 771 TabStripModel::ADD_NONE); |
| 772 CheckSecurityInfoForSecure(new_contents, SecurityStateModel::SECURE, | 772 CheckSecurityInfoForSecure(new_contents, SecurityStateModel::SECURE, |
| 773 SecurityStateModel::NO_DEPRECATED_SHA1, | 773 SecurityStateModel::NO_DEPRECATED_SHA1, |
| 774 SecurityStateModel::NO_MIXED_CONTENT, false, | 774 SecurityStateModel::CONTENT_STATUS_NONE, false, |
| 775 false /* expect cert status error */); | 775 false /* expect cert status error */); |
| 776 } | 776 } |
| 777 | 777 |
| 778 // Tests that the WebContentsObserver::SecurityStyleChanged event fires | 778 // Tests that the WebContentsObserver::SecurityStyleChanged event fires |
| 779 // with the current style on HTTP, broken HTTPS, and valid HTTPS pages. | 779 // with the current style on HTTP, broken HTTPS, and valid HTTPS pages. |
| 780 IN_PROC_BROWSER_TEST_F(SecurityStyleChangedTest, SecurityStyleChangedObserver) { | 780 IN_PROC_BROWSER_TEST_F(SecurityStyleChangedTest, SecurityStyleChangedObserver) { |
| 781 ASSERT_TRUE(https_server_.Start()); | 781 ASSERT_TRUE(https_server_.Start()); |
| 782 ASSERT_TRUE(embedded_test_server()->Start()); | 782 ASSERT_TRUE(embedded_test_server()->Start()); |
| 783 | 783 |
| 784 net::EmbeddedTestServer https_test_server_expired( | 784 net::EmbeddedTestServer https_test_server_expired( |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1249 ChromeSecurityStateModelClient* model_client = | 1249 ChromeSecurityStateModelClient* model_client = |
| 1250 ChromeSecurityStateModelClient::FromWebContents(web_contents); | 1250 ChromeSecurityStateModelClient::FromWebContents(web_contents); |
| 1251 ASSERT_TRUE(model_client); | 1251 ASSERT_TRUE(model_client); |
| 1252 const SecurityStateModel::SecurityInfo& security_info = | 1252 const SecurityStateModel::SecurityInfo& security_info = |
| 1253 model_client->GetSecurityInfo(); | 1253 model_client->GetSecurityInfo(); |
| 1254 EXPECT_EQ(SecurityStateModel::SECURE, security_info.security_level); | 1254 EXPECT_EQ(SecurityStateModel::SECURE, security_info.security_level); |
| 1255 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses); | 1255 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses); |
| 1256 } | 1256 } |
| 1257 | 1257 |
| 1258 } // namespace | 1258 } // namespace |
| OLD | NEW |