Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 3911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3922 } | 3922 } |
| 3923 | 3923 |
| 3924 // Put captive portal related tests under a different namespace for nicer | 3924 // Put captive portal related tests under a different namespace for nicer |
| 3925 // pattern matching. | 3925 // pattern matching. |
| 3926 using SSLUICaptivePortalListTest = SSLUITest; | 3926 using SSLUICaptivePortalListTest = SSLUITest; |
| 3927 | 3927 |
| 3928 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 3928 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 3929 | 3929 |
| 3930 // Tests that the captive portal certificate list is not used when the feature | 3930 // Tests that the captive portal certificate list is not used when the feature |
| 3931 // is disabled via Finch. The list is passed to SSLErrorHandler via a proto. | 3931 // is disabled via Finch. The list is passed to SSLErrorHandler via a proto. |
| 3932 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListTest, | 3932 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListTest, Disabled) { |
| 3933 CaptivePortalCertificateList_Disabled) { | |
| 3934 base::test::ScopedFeatureList scoped_feature_list; | 3933 base::test::ScopedFeatureList scoped_feature_list; |
| 3935 // Use InitFromCommandLine instead of InitAndDisableFeature to avoid making | 3934 // Use InitFromCommandLine instead of InitAndDisableFeature to avoid making |
| 3936 // the feature public in SSLErrorHandler header. | 3935 // the feature public in SSLErrorHandler header. |
| 3937 scoped_feature_list.InitFromCommandLine( | 3936 scoped_feature_list.InitFromCommandLine( |
| 3938 std::string() /* enabled */, | 3937 std::string() /* enabled */, |
| 3939 "CaptivePortalCertificateList" /* disabled */); | 3938 "CaptivePortalCertificateList" /* disabled */); |
| 3940 | 3939 |
| 3941 ASSERT_TRUE(https_server_mismatched_.Start()); | 3940 ASSERT_TRUE(https_server_mismatched_.Start()); |
| 3942 base::HistogramTester histograms; | 3941 base::HistogramTester histograms; |
| 3943 | 3942 |
| 3944 // Mark the server's cert as a captive portal cert. | 3943 // Mark the server's cert as a captive portal cert. |
| 3945 const net::HashValue server_spki_hash = | 3944 const net::HashValue server_spki_hash = |
| 3946 GetSPKIHash(https_server_mismatched_.GetCertificate().get()); | 3945 GetSPKIHash(https_server_mismatched_.GetCertificate().get()); |
| 3947 chrome_browser_ssl::SSLErrorAssistantConfig config_proto; | 3946 auto config_proto = |
| 3948 config_proto.add_captive_portal_cert()->set_sha256_hash( | 3947 base::MakeUnique<chrome_browser_ssl::SSLErrorAssistantConfig>(); |
| 3948 config_proto->add_captive_portal_cert()->set_sha256_hash( | |
| 3949 server_spki_hash.ToString()); | 3949 server_spki_hash.ToString()); |
| 3950 SSLErrorHandler::SetErrorAssistantProtoForTesting(config_proto); | 3950 SSLErrorHandler::SetErrorAssistantProto(std::move(config_proto)); |
| 3951 | 3951 |
| 3952 // Navigate to an unsafe page on the server. A normal SSL interstitial should | 3952 // Navigate to an unsafe page on the server. A normal SSL interstitial should |
| 3953 // be displayed since CaptivePortalCertificateList feature is disabled. | 3953 // be displayed since CaptivePortalCertificateList feature is disabled. |
| 3954 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 3954 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 3955 SSLInterstitialTimerObserver interstitial_timer_observer(tab); | 3955 SSLInterstitialTimerObserver interstitial_timer_observer(tab); |
| 3956 ui_test_utils::NavigateToURL( | 3956 ui_test_utils::NavigateToURL( |
| 3957 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); | 3957 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); |
| 3958 content::WaitForInterstitialAttach(tab); | 3958 content::WaitForInterstitialAttach(tab); |
| 3959 | 3959 |
| 3960 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); | 3960 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); |
| 3961 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | 3961 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, |
| 3962 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | 3962 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); |
| 3963 EXPECT_TRUE(interstitial_timer_observer.timer_started()); | 3963 EXPECT_TRUE(interstitial_timer_observer.timer_started()); |
| 3964 | 3964 |
| 3965 // Check that the histogram for the SSL interstitial was recorded. | 3965 // Check that the histogram for the SSL interstitial was recorded. |
| 3966 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), 2); | 3966 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), 2); |
| 3967 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), | 3967 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), |
| 3968 SSLErrorHandler::HANDLE_ALL, 1); | 3968 SSLErrorHandler::HANDLE_ALL, 1); |
| 3969 histograms.ExpectBucketCount( | 3969 histograms.ExpectBucketCount( |
| 3970 SSLErrorHandler::GetHistogramNameForTesting(), | 3970 SSLErrorHandler::GetHistogramNameForTesting(), |
| 3971 SSLErrorHandler::SHOW_SSL_INTERSTITIAL_OVERRIDABLE, 1); | 3971 SSLErrorHandler::SHOW_SSL_INTERSTITIAL_OVERRIDABLE, 1); |
| 3972 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), | 3972 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), |
| 3973 SSLErrorHandler::CAPTIVE_PORTAL_CERT_FOUND, 0); | 3973 SSLErrorHandler::CAPTIVE_PORTAL_CERT_FOUND, 0); |
| 3974 } | 3974 } |
| 3975 | 3975 |
| 3976 // Tests that the captive portal certificate list is used when the feature | 3976 // Tests that the captive portal certificate list is used when the feature |
| 3977 // is enabled via Finch. The list is passed to SSLErrorHandler via a proto. | 3977 // is enabled via Finch. The list is passed to SSLErrorHandler via a proto. |
| 3978 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListTest, | 3978 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListTest, Enabled_FromProto) { |
| 3979 CaptivePortalCertificateList_Enabled_FromProto) { | |
| 3980 base::test::ScopedFeatureList scoped_feature_list; | 3979 base::test::ScopedFeatureList scoped_feature_list; |
| 3981 scoped_feature_list.InitFromCommandLine( | 3980 scoped_feature_list.InitFromCommandLine( |
| 3982 "CaptivePortalCertificateList" /* enabled */, | 3981 "CaptivePortalCertificateList" /* enabled */, |
| 3983 std::string() /* disabled */); | 3982 std::string() /* disabled */); |
| 3984 | 3983 |
| 3985 ASSERT_TRUE(https_server_mismatched_.Start()); | 3984 ASSERT_TRUE(https_server_mismatched_.Start()); |
| 3986 base::HistogramTester histograms; | 3985 base::HistogramTester histograms; |
| 3987 | 3986 |
| 3988 // Mark the server's cert as a captive portal cert. | 3987 // Mark the server's cert as a captive portal cert. |
| 3989 const net::HashValue server_spki_hash = | 3988 const net::HashValue server_spki_hash = |
| 3990 GetSPKIHash(https_server_mismatched_.GetCertificate().get()); | 3989 GetSPKIHash(https_server_mismatched_.GetCertificate().get()); |
| 3991 chrome_browser_ssl::SSLErrorAssistantConfig config_proto; | 3990 auto config_proto = |
| 3992 config_proto.add_captive_portal_cert()->set_sha256_hash( | 3991 base::MakeUnique<chrome_browser_ssl::SSLErrorAssistantConfig>(); |
| 3992 config_proto->add_captive_portal_cert()->set_sha256_hash( | |
| 3993 server_spki_hash.ToString()); | 3993 server_spki_hash.ToString()); |
| 3994 SSLErrorHandler::SetErrorAssistantProtoForTesting(config_proto); | 3994 SSLErrorHandler::SetErrorAssistantProto(std::move(config_proto)); |
| 3995 | 3995 |
| 3996 // Navigate to an unsafe page on the server. The captive portal interstitial | 3996 // Navigate to an unsafe page on the server. The captive portal interstitial |
| 3997 // should be displayed since CaptivePortalCertificateList feature is enabled. | 3997 // should be displayed since CaptivePortalCertificateList feature is enabled. |
| 3998 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 3998 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 3999 SSLInterstitialTimerObserver interstitial_timer_observer(tab); | 3999 SSLInterstitialTimerObserver interstitial_timer_observer(tab); |
| 4000 ui_test_utils::NavigateToURL( | 4000 ui_test_utils::NavigateToURL( |
| 4001 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); | 4001 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); |
| 4002 content::WaitForInterstitialAttach(tab); | 4002 content::WaitForInterstitialAttach(tab); |
| 4003 | 4003 |
| 4004 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); | 4004 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); |
| 4005 ASSERT_EQ(CaptivePortalBlockingPage::kTypeForTesting, | 4005 ASSERT_EQ(CaptivePortalBlockingPage::kTypeForTesting, |
| 4006 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | 4006 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); |
| 4007 EXPECT_FALSE(interstitial_timer_observer.timer_started()); | 4007 EXPECT_FALSE(interstitial_timer_observer.timer_started()); |
| 4008 | 4008 |
| 4009 // Check that the histogram for the captive portal cert was recorded. | 4009 // Check that the histogram for the captive portal cert was recorded. |
| 4010 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), 3); | 4010 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), 3); |
| 4011 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), | 4011 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), |
| 4012 SSLErrorHandler::HANDLE_ALL, 1); | 4012 SSLErrorHandler::HANDLE_ALL, 1); |
| 4013 histograms.ExpectBucketCount( | 4013 histograms.ExpectBucketCount( |
| 4014 SSLErrorHandler::GetHistogramNameForTesting(), | 4014 SSLErrorHandler::GetHistogramNameForTesting(), |
| 4015 SSLErrorHandler::SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE, 1); | 4015 SSLErrorHandler::SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE, 1); |
| 4016 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), | 4016 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), |
| 4017 SSLErrorHandler::CAPTIVE_PORTAL_CERT_FOUND, 1); | 4017 SSLErrorHandler::CAPTIVE_PORTAL_CERT_FOUND, 1); |
| 4018 } | 4018 } |
| 4019 | 4019 |
| 4020 namespace { | 4020 namespace { |
| 4021 | 4021 |
| 4022 const char kCaptivePortalSPKI[] = | |
| 4023 "sha256/fjZPHewEHTrMDX3I1ecEIeoy3WFxHyGplOLv28kIbtI="; | |
|
estark
2017/02/08 20:31:17
Magic value; I suggest adding a comment explaining
meacer
2017/02/08 22:34:32
Done.
| |
| 4024 | |
| 4022 // Test class that mimics a URL request with a certificate whose SPKI hash is in | 4025 // Test class that mimics a URL request with a certificate whose SPKI hash is in |
| 4023 // ssl_error_assistant.asciipb resource. A better way of testing the SPKI hashes | 4026 // ssl_error_assistant.asciipb resource. A better way of testing the SPKI hashes |
| 4024 // inside the resource bundle would be to serve the actual certificate from the | 4027 // inside the resource bundle would be to serve the actual certificate from the |
| 4025 // embedded test server, but the test server can only serve a limited number of | 4028 // embedded test server, but the test server can only serve a limited number of |
| 4026 // predefined certificates. | 4029 // predefined certificates. |
| 4027 class SSLUICaptivePortalListResourceBundleTest | 4030 class SSLUICaptivePortalListResourceBundleTest |
| 4028 : public CertVerifierBrowserTest { | 4031 : public CertVerifierBrowserTest { |
| 4029 public: | 4032 public: |
| 4030 SSLUICaptivePortalListResourceBundleTest() | 4033 SSLUICaptivePortalListResourceBundleTest() |
| 4031 : CertVerifierBrowserTest(), | 4034 : CertVerifierBrowserTest(), |
| 4032 https_server_(net::EmbeddedTestServer::TYPE_HTTPS), | 4035 https_server_(net::EmbeddedTestServer::TYPE_HTTPS), |
| 4033 https_server_mismatched_(net::EmbeddedTestServer::TYPE_HTTPS) { | 4036 https_server_mismatched_(net::EmbeddedTestServer::TYPE_HTTPS) { |
| 4034 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); | 4037 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); |
| 4035 | 4038 |
| 4036 https_server_mismatched_.SetSSLConfig( | 4039 https_server_mismatched_.SetSSLConfig( |
| 4037 net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | 4040 net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 4038 https_server_mismatched_.AddDefaultHandlers(base::FilePath(kDocRoot)); | 4041 https_server_mismatched_.AddDefaultHandlers(base::FilePath(kDocRoot)); |
| 4039 } | 4042 } |
| 4040 | 4043 |
| 4041 void SetUp() override { | 4044 void SetUp() override { |
| 4042 CertVerifierBrowserTest::SetUp(); | 4045 CertVerifierBrowserTest::SetUp(); |
| 4043 SSLErrorHandler::ResetConfigForTesting(); | 4046 SSLErrorHandler::ResetConfigForTesting(); |
| 4044 SetUpCertVerifier(0, net::OK); | 4047 SetUpCertVerifier(0, net::OK, std::string()); |
| 4045 } | 4048 } |
| 4046 | 4049 |
| 4047 void TearDown() override { | 4050 void TearDown() override { |
| 4048 SSLErrorHandler::ResetConfigForTesting(); | 4051 SSLErrorHandler::ResetConfigForTesting(); |
| 4049 CertVerifierBrowserTest::TearDown(); | 4052 CertVerifierBrowserTest::TearDown(); |
| 4050 } | 4053 } |
| 4051 | 4054 |
| 4052 protected: | 4055 protected: |
| 4053 void SetUpCertVerifier(net::CertStatus cert_status, int net_result) { | 4056 void SetUpCertVerifier(net::CertStatus cert_status, |
| 4057 int net_result, | |
| 4058 const std::string& spki_hash) { | |
| 4054 scoped_refptr<net::X509Certificate> cert(https_server_.GetCertificate()); | 4059 scoped_refptr<net::X509Certificate> cert(https_server_.GetCertificate()); |
| 4055 net::CertVerifyResult verify_result; | 4060 net::CertVerifyResult verify_result; |
| 4056 verify_result.is_issued_by_known_root = | 4061 verify_result.is_issued_by_known_root = |
| 4057 (net_result != net::ERR_CERT_AUTHORITY_INVALID); | 4062 (net_result != net::ERR_CERT_AUTHORITY_INVALID); |
| 4058 verify_result.verified_cert = cert; | 4063 verify_result.verified_cert = cert; |
| 4059 verify_result.cert_status = cert_status; | 4064 verify_result.cert_status = cert_status; |
| 4060 | 4065 |
| 4061 // Set the SPKI hash to captive-portal.badssl.com leaf certificate. This | 4066 // Set the SPKI hash to captive-portal.badssl.com leaf certificate. This |
|
estark
2017/02/08 20:31:17
Ah, I think this comment or something like it belo
meacer
2017/02/08 22:34:32
Done.
| |
| 4062 // doesn't match the actual cert (ok_cert.pem) but is good enough for | 4067 // doesn't match the actual cert (ok_cert.pem) but is good enough for |
| 4063 // testing. | 4068 // testing. |
| 4064 net::HashValue hash; | 4069 if (!spki_hash.empty()) { |
| 4065 ASSERT_TRUE( | 4070 net::HashValue hash; |
| 4066 hash.FromString("sha256/fjZPHewEHTrMDX3I1ecEIeoy3WFxHyGplOLv28kIbtI=")); | 4071 ASSERT_TRUE(hash.FromString(spki_hash)); |
| 4067 verify_result.public_key_hashes.push_back(hash); | 4072 verify_result.public_key_hashes.push_back(hash); |
| 4073 } | |
| 4068 mock_cert_verifier()->AddResultForCert(cert, verify_result, net_result); | 4074 mock_cert_verifier()->AddResultForCert(cert, verify_result, net_result); |
| 4069 } | 4075 } |
| 4070 | 4076 |
| 4071 net::EmbeddedTestServer* https_server() { return &https_server_; } | 4077 net::EmbeddedTestServer* https_server() { return &https_server_; } |
| 4072 net::EmbeddedTestServer* https_server_mismatched() { | 4078 net::EmbeddedTestServer* https_server_mismatched() { |
| 4073 return &https_server_mismatched_; | 4079 return &https_server_mismatched_; |
| 4074 } | 4080 } |
| 4075 | 4081 |
| 4076 private: | 4082 private: |
| 4077 net::EmbeddedTestServer https_server_; | 4083 net::EmbeddedTestServer https_server_; |
| 4078 net::EmbeddedTestServer https_server_mismatched_; | 4084 net::EmbeddedTestServer https_server_mismatched_; |
| 4079 }; | 4085 }; |
| 4080 | 4086 |
| 4081 } // namespace | 4087 } // namespace |
| 4082 | 4088 |
| 4083 // Same as CaptivePortalCertificateList_Enabled_FromProto, but this time the | 4089 // Same as CaptivePortalCertificateList_Enabled_FromProto, but this time the |
| 4084 // cert's SPKI hash is listed in ssl_error_assistant.asciipb. | 4090 // cert's SPKI hash is listed in ssl_error_assistant.asciipb. |
| 4085 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListResourceBundleTest, | 4091 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListResourceBundleTest, Enabled) { |
| 4086 Enabled_FromResource) { | |
| 4087 base::test::ScopedFeatureList scoped_feature_list; | 4092 base::test::ScopedFeatureList scoped_feature_list; |
| 4088 scoped_feature_list.InitFromCommandLine( | 4093 scoped_feature_list.InitFromCommandLine( |
| 4089 "CaptivePortalCertificateList" /* enabled */, | 4094 "CaptivePortalCertificateList" /* enabled */, |
| 4090 std::string() /* disabled */); | 4095 std::string() /* disabled */); |
| 4091 ASSERT_TRUE(https_server()->Start()); | 4096 ASSERT_TRUE(https_server()->Start()); |
| 4092 base::HistogramTester histograms; | 4097 base::HistogramTester histograms; |
| 4093 | 4098 |
| 4094 // Mark the server's cert as a captive portal cert. | 4099 // Mark the server's cert as a captive portal cert. |
| 4095 SetUpCertVerifier(net::CERT_STATUS_COMMON_NAME_INVALID, | 4100 SetUpCertVerifier(net::CERT_STATUS_COMMON_NAME_INVALID, |
| 4096 net::ERR_CERT_COMMON_NAME_INVALID); | 4101 net::ERR_CERT_COMMON_NAME_INVALID, kCaptivePortalSPKI); |
| 4097 | 4102 |
| 4098 // Navigate to an unsafe page on the server. The captive portal interstitial | 4103 // Navigate to an unsafe page on the server. The captive portal interstitial |
| 4099 // should be displayed since CaptivePortalCertificateList feature is enabled. | 4104 // should be displayed since CaptivePortalCertificateList feature is enabled. |
| 4100 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 4105 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 4101 SSLInterstitialTimerObserver interstitial_timer_observer(tab); | 4106 SSLInterstitialTimerObserver interstitial_timer_observer(tab); |
| 4102 ui_test_utils::NavigateToURL(browser(), https_server()->GetURL("/")); | 4107 ui_test_utils::NavigateToURL(browser(), https_server()->GetURL("/")); |
| 4103 content::WaitForInterstitialAttach(tab); | 4108 content::WaitForInterstitialAttach(tab); |
| 4104 | 4109 |
| 4105 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); | 4110 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); |
| 4106 ASSERT_EQ(CaptivePortalBlockingPage::kTypeForTesting, | 4111 ASSERT_EQ(CaptivePortalBlockingPage::kTypeForTesting, |
| 4107 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | 4112 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); |
| 4108 EXPECT_FALSE(interstitial_timer_observer.timer_started()); | 4113 EXPECT_FALSE(interstitial_timer_observer.timer_started()); |
| 4109 | 4114 |
| 4110 // Check that the histogram for the captive portal cert was recorded. | 4115 // Check that the histogram for the captive portal cert was recorded. |
| 4111 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), 3); | 4116 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), 3); |
| 4112 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), | 4117 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), |
| 4113 SSLErrorHandler::HANDLE_ALL, 1); | 4118 SSLErrorHandler::HANDLE_ALL, 1); |
| 4114 histograms.ExpectBucketCount( | 4119 histograms.ExpectBucketCount( |
| 4115 SSLErrorHandler::GetHistogramNameForTesting(), | 4120 SSLErrorHandler::GetHistogramNameForTesting(), |
| 4116 SSLErrorHandler::SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE, 1); | 4121 SSLErrorHandler::SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE, 1); |
| 4117 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), | 4122 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), |
| 4118 SSLErrorHandler::CAPTIVE_PORTAL_CERT_FOUND, 1); | 4123 SSLErrorHandler::CAPTIVE_PORTAL_CERT_FOUND, 1); |
| 4119 } | 4124 } |
| 4120 | 4125 |
| 4126 // Same as SSLUICaptivePortalListResourceBundleTest.Enabled, but this time the | |
| 4127 // proto is dynamically updated (e.g. by the component updater). The dynamic | |
| 4128 // update should always override the proto loaded from the resource bundle. | |
| 4129 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListResourceBundleTest, | |
| 4130 Enabled_DynamicUpdate) { | |
| 4131 base::test::ScopedFeatureList scoped_feature_list; | |
| 4132 scoped_feature_list.InitFromCommandLine( | |
| 4133 "CaptivePortalCertificateList" /* enabled */, | |
| 4134 std::string() /* disabled */); | |
| 4135 ASSERT_TRUE(https_server()->Start()); | |
| 4136 | |
| 4137 // Set interstitial delay to zero. | |
|
estark
2017/02/08 20:31:17
nit: explain why this is needed
meacer
2017/02/08 22:34:32
Not needed, removed.
| |
| 4138 SSLErrorHandler::SetInterstitialDelayForTesting(base::TimeDelta()); | |
| 4139 // Mark the server's cert as a captive portal cert. | |
| 4140 SetUpCertVerifier(net::CERT_STATUS_COMMON_NAME_INVALID, | |
| 4141 net::ERR_CERT_COMMON_NAME_INVALID, kCaptivePortalSPKI); | |
| 4142 | |
| 4143 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 4144 | |
| 4145 { | |
| 4146 // Dynamically update the SSL error assistant config, do not include the | |
| 4147 // captive portal SPKI hash. | |
| 4148 auto config_proto = | |
| 4149 base::MakeUnique<chrome_browser_ssl::SSLErrorAssistantConfig>(); | |
| 4150 config_proto->add_captive_portal_cert()->set_sha256_hash( | |
| 4151 "sha256/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); | |
| 4152 config_proto->add_captive_portal_cert()->set_sha256_hash( | |
| 4153 "sha256/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); | |
| 4154 SSLErrorHandler::SetErrorAssistantProto(std::move(config_proto)); | |
| 4155 | |
| 4156 // Navigate to an unsafe page on the server. A generic SSL interstitial | |
| 4157 // should be displayed because the dynamic update doesn't contain the hash | |
| 4158 // of the captive portal certificate. | |
| 4159 base::HistogramTester histograms; | |
| 4160 SSLInterstitialTimerObserver interstitial_timer_observer(tab); | |
| 4161 ui_test_utils::NavigateToURL(browser(), https_server()->GetURL("/")); | |
| 4162 content::WaitForInterstitialAttach(tab); | |
| 4163 | |
| 4164 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); | |
| 4165 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | |
| 4166 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 4167 EXPECT_TRUE(interstitial_timer_observer.timer_started()); | |
| 4168 | |
| 4169 // Check that the histogram was recorded for an SSL interstitial. | |
| 4170 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4171 2); | |
| 4172 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4173 SSLErrorHandler::HANDLE_ALL, 1); | |
| 4174 histograms.ExpectBucketCount( | |
| 4175 SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4176 SSLErrorHandler::SHOW_SSL_INTERSTITIAL_OVERRIDABLE, 1); | |
| 4177 } | |
| 4178 { | |
| 4179 // Dynamically update the error assistant config and add the captive portal | |
| 4180 // SPKI hash. | |
| 4181 auto config_proto = | |
| 4182 base::MakeUnique<chrome_browser_ssl::SSLErrorAssistantConfig>(); | |
| 4183 config_proto->set_version_id(1); | |
| 4184 config_proto->add_captive_portal_cert()->set_sha256_hash( | |
| 4185 "sha256/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); | |
| 4186 config_proto->add_captive_portal_cert()->set_sha256_hash( | |
| 4187 "sha256/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); | |
| 4188 config_proto->add_captive_portal_cert()->set_sha256_hash( | |
| 4189 kCaptivePortalSPKI); | |
| 4190 SSLErrorHandler::SetErrorAssistantProto(std::move(config_proto)); | |
| 4191 | |
| 4192 // Navigate to the unsafe page again. This time, a captive portal | |
| 4193 // interstitial should be displayed. | |
| 4194 base::HistogramTester histograms; | |
| 4195 SSLInterstitialTimerObserver interstitial_timer_observer(tab); | |
| 4196 ui_test_utils::NavigateToURL(browser(), https_server()->GetURL("/")); | |
| 4197 content::WaitForInterstitialAttach(tab); | |
| 4198 | |
| 4199 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); | |
| 4200 ASSERT_EQ(CaptivePortalBlockingPage::kTypeForTesting, | |
| 4201 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 4202 EXPECT_FALSE(interstitial_timer_observer.timer_started()); | |
| 4203 | |
| 4204 // Check that the histogram was recorded for a captive portal interstitial. | |
| 4205 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4206 3); | |
| 4207 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4208 SSLErrorHandler::HANDLE_ALL, 1); | |
| 4209 histograms.ExpectBucketCount( | |
| 4210 SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4211 SSLErrorHandler::SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE, 1); | |
| 4212 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4213 SSLErrorHandler::CAPTIVE_PORTAL_CERT_FOUND, 1); | |
| 4214 } | |
| 4215 { | |
| 4216 // Try dynamically updating the error assistant config with the an empty | |
|
estark
2017/02/08 20:31:17
nit: extra "the"
meacer
2017/02/08 22:34:32
Done.
| |
| 4217 // config with the same version number. The update should be ignored, and a | |
| 4218 // captive portal interstitial should stil be displayed. | |
| 4219 auto empty_config = | |
| 4220 base::MakeUnique<chrome_browser_ssl::SSLErrorAssistantConfig>(); | |
| 4221 empty_config->set_version_id(1); | |
| 4222 SSLErrorHandler::SetErrorAssistantProto(std::move(empty_config)); | |
| 4223 | |
| 4224 // Navigate to the unsafe page again. This time, a captive portal | |
| 4225 // interstitial should be displayed. | |
| 4226 base::HistogramTester histograms; | |
| 4227 SSLInterstitialTimerObserver interstitial_timer_observer(tab); | |
| 4228 ui_test_utils::NavigateToURL(browser(), https_server()->GetURL("/")); | |
| 4229 content::WaitForInterstitialAttach(tab); | |
| 4230 | |
| 4231 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); | |
| 4232 ASSERT_EQ(CaptivePortalBlockingPage::kTypeForTesting, | |
| 4233 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 4234 EXPECT_FALSE(interstitial_timer_observer.timer_started()); | |
| 4235 | |
| 4236 // Check that the histogram was recorded for a captive portal interstitial. | |
| 4237 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4238 3); | |
| 4239 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4240 SSLErrorHandler::HANDLE_ALL, 1); | |
| 4241 histograms.ExpectBucketCount( | |
| 4242 SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4243 SSLErrorHandler::SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE, 1); | |
| 4244 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), | |
| 4245 SSLErrorHandler::CAPTIVE_PORTAL_CERT_FOUND, 1); | |
| 4246 } | |
| 4247 } | |
| 4248 | |
| 4121 // Same as SSLUICaptivePortalNameMismatchTest, but this time the error is | 4249 // Same as SSLUICaptivePortalNameMismatchTest, but this time the error is |
| 4122 // authority-invalid. Captive portal interstitial should not be shown. | 4250 // authority-invalid. Captive portal interstitial should not be shown. |
| 4123 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListResourceBundleTest, | 4251 IN_PROC_BROWSER_TEST_F(SSLUICaptivePortalListResourceBundleTest, |
| 4124 Enabled_FromResource_AuthorityInvalid) { | 4252 Enabled_AuthorityInvalid) { |
| 4125 base::test::ScopedFeatureList scoped_feature_list; | 4253 base::test::ScopedFeatureList scoped_feature_list; |
| 4126 scoped_feature_list.InitFromCommandLine( | 4254 scoped_feature_list.InitFromCommandLine( |
| 4127 "CaptivePortalCertificateList" /* enabled */, | 4255 "CaptivePortalCertificateList" /* enabled */, |
| 4128 std::string() /* disabled */); | 4256 std::string() /* disabled */); |
| 4129 ASSERT_TRUE(https_server()->Start()); | 4257 ASSERT_TRUE(https_server()->Start()); |
| 4130 base::HistogramTester histograms; | 4258 base::HistogramTester histograms; |
| 4131 | 4259 |
| 4132 // Set interstitial delay to zero. | 4260 // Set interstitial delay to zero. |
| 4133 SSLErrorHandler::SetInterstitialDelayForTesting(base::TimeDelta()); | 4261 SSLErrorHandler::SetInterstitialDelayForTesting(base::TimeDelta()); |
| 4134 // Mark the server's cert as a captive portal cert, but with an | 4262 // Mark the server's cert as a captive portal cert, but with an |
| 4135 // authority-invalid error. | 4263 // authority-invalid error. |
| 4136 SetUpCertVerifier(net::CERT_STATUS_AUTHORITY_INVALID, | 4264 SetUpCertVerifier(net::CERT_STATUS_AUTHORITY_INVALID, |
| 4137 net::ERR_CERT_AUTHORITY_INVALID); | 4265 net::ERR_CERT_AUTHORITY_INVALID, kCaptivePortalSPKI); |
| 4138 | 4266 |
| 4139 // Navigate to an unsafe page on the server. CaptivePortalCertificateList | 4267 // Navigate to an unsafe page on the server. CaptivePortalCertificateList |
| 4140 // feature is enabled but the error is not a name mismatch, so a generic SSL | 4268 // feature is enabled but the error is not a name mismatch, so a generic SSL |
| 4141 // interstitial should be displayed. | 4269 // interstitial should be displayed. |
| 4142 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 4270 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 4143 SSLInterstitialTimerObserver interstitial_timer_observer(tab); | 4271 SSLInterstitialTimerObserver interstitial_timer_observer(tab); |
| 4144 ui_test_utils::NavigateToURL(browser(), https_server()->GetURL("/")); | 4272 ui_test_utils::NavigateToURL(browser(), https_server()->GetURL("/")); |
| 4145 content::WaitForInterstitialAttach(tab); | 4273 content::WaitForInterstitialAttach(tab); |
| 4146 | 4274 |
| 4147 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); | 4275 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 4172 | 4300 |
| 4173 ASSERT_TRUE(https_server_mismatched_.Start()); | 4301 ASSERT_TRUE(https_server_mismatched_.Start()); |
| 4174 base::HistogramTester histograms; | 4302 base::HistogramTester histograms; |
| 4175 | 4303 |
| 4176 // Mark the server's cert as a captive portal cert. | 4304 // Mark the server's cert as a captive portal cert. |
| 4177 const net::HashValue server_spki_hash = | 4305 const net::HashValue server_spki_hash = |
| 4178 GetSPKIHash(https_server_mismatched_.GetCertificate().get()); | 4306 GetSPKIHash(https_server_mismatched_.GetCertificate().get()); |
| 4179 chrome_browser_ssl::SSLErrorAssistantConfig config_proto; | 4307 chrome_browser_ssl::SSLErrorAssistantConfig config_proto; |
| 4180 config_proto.add_captive_portal_cert()->set_sha256_hash( | 4308 config_proto.add_captive_portal_cert()->set_sha256_hash( |
| 4181 server_spki_hash.ToString()); | 4309 server_spki_hash.ToString()); |
| 4182 SSLErrorHandler::SetErrorAssistantProtoForTesting(config_proto); | 4310 SSLErrorHandler::SetErrorAssistantProto(config_proto); |
| 4183 | 4311 |
| 4184 // Navigate to an unsafe page on the server. The captive portal interstitial | 4312 // Navigate to an unsafe page on the server. The captive portal interstitial |
| 4185 // should be displayed since CaptivePortalCertificateList feature is enabled. | 4313 // should be displayed since CaptivePortalCertificateList feature is enabled. |
| 4186 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 4314 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 4187 SSLInterstitialTimerObserver interstitial_timer_observer(tab); | 4315 SSLInterstitialTimerObserver interstitial_timer_observer(tab); |
| 4188 ui_test_utils::NavigateToURL( | 4316 ui_test_utils::NavigateToURL( |
| 4189 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); | 4317 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html")); |
| 4190 content::WaitForInterstitialAttach(tab); | 4318 content::WaitForInterstitialAttach(tab); |
| 4191 | 4319 |
| 4192 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); | 4320 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 4209 | 4337 |
| 4210 // Visit a page over https that contains a frame with a redirect. | 4338 // Visit a page over https that contains a frame with a redirect. |
| 4211 | 4339 |
| 4212 // XMLHttpRequest insecure content in synchronous mode. | 4340 // XMLHttpRequest insecure content in synchronous mode. |
| 4213 | 4341 |
| 4214 // XMLHttpRequest insecure content in asynchronous mode. | 4342 // XMLHttpRequest insecure content in asynchronous mode. |
| 4215 | 4343 |
| 4216 // XMLHttpRequest over bad ssl in synchronous mode. | 4344 // XMLHttpRequest over bad ssl in synchronous mode. |
| 4217 | 4345 |
| 4218 // XMLHttpRequest over OK ssl in synchronous mode. | 4346 // XMLHttpRequest over OK ssl in synchronous mode. |
| OLD | NEW |