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