Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(650)

Side by Side Diff: chrome/browser/ssl/ssl_browser_tests.cc

Issue 2620203003: Add initial version of captive portal list checking. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
24 #include "base/time/default_tick_clock.h" 24 #include "base/time/default_tick_clock.h"
25 #include "base/time/time.h" 25 #include "base/time/time.h"
26 #include "build/build_config.h" 26 #include "build/build_config.h"
27 #include "chrome/app/chrome_command_ids.h" 27 #include "chrome/app/chrome_command_ids.h"
28 #include "chrome/browser/browser_process.h" 28 #include "chrome/browser/browser_process.h"
29 #include "chrome/browser/chrome_notification_types.h" 29 #include "chrome/browser/chrome_notification_types.h"
30 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 30 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
31 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" 31 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
32 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
33 #include "chrome/browser/ssl/bad_clock_blocking_page.h" 33 #include "chrome/browser/ssl/bad_clock_blocking_page.h"
34 #include "chrome/browser/ssl/captive_portal_blocking_page.h"
34 #include "chrome/browser/ssl/cert_report_helper.h" 35 #include "chrome/browser/ssl/cert_report_helper.h"
35 #include "chrome/browser/ssl/cert_verifier_browser_test.h" 36 #include "chrome/browser/ssl/cert_verifier_browser_test.h"
36 #include "chrome/browser/ssl/certificate_reporting_test_utils.h" 37 #include "chrome/browser/ssl/certificate_reporting_test_utils.h"
37 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" 38 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
38 #include "chrome/browser/ssl/common_name_mismatch_handler.h" 39 #include "chrome/browser/ssl/common_name_mismatch_handler.h"
39 #include "chrome/browser/ssl/security_state_tab_helper.h" 40 #include "chrome/browser/ssl/security_state_tab_helper.h"
40 #include "chrome/browser/ssl/ssl_blocking_page.h" 41 #include "chrome/browser/ssl/ssl_blocking_page.h"
41 #include "chrome/browser/ssl/ssl_error_handler.h" 42 #include "chrome/browser/ssl/ssl_error_handler.h"
43 #include "chrome/browser/ssl/tls_error_assistant.pb.h"
42 #include "chrome/browser/ui/browser.h" 44 #include "chrome/browser/ui/browser.h"
43 #include "chrome/browser/ui/browser_commands.h" 45 #include "chrome/browser/ui/browser_commands.h"
44 #include "chrome/browser/ui/browser_finder.h" 46 #include "chrome/browser/ui/browser_finder.h"
45 #include "chrome/browser/ui/browser_navigator.h" 47 #include "chrome/browser/ui/browser_navigator.h"
46 #include "chrome/browser/ui/browser_navigator_params.h" 48 #include "chrome/browser/ui/browser_navigator_params.h"
47 #include "chrome/browser/ui/browser_tabstrip.h" 49 #include "chrome/browser/ui/browser_tabstrip.h"
48 #include "chrome/browser/ui/tabs/tab_strip_model.h" 50 #include "chrome/browser/ui/tabs/tab_strip_model.h"
49 #include "chrome/common/chrome_paths.h" 51 #include "chrome/common/chrome_paths.h"
50 #include "chrome/common/chrome_switches.h" 52 #include "chrome/common/chrome_switches.h"
51 #include "chrome/common/pref_names.h" 53 #include "chrome/common/pref_names.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 using content::NavigationEntry; 117 using content::NavigationEntry;
116 using content::SSLStatus; 118 using content::SSLStatus;
117 using content::WebContents; 119 using content::WebContents;
118 using web_modal::WebContentsModalDialogManager; 120 using web_modal::WebContentsModalDialogManager;
119 121
120 const base::FilePath::CharType kDocRoot[] = 122 const base::FilePath::CharType kDocRoot[] =
121 FILE_PATH_LITERAL("chrome/test/data"); 123 FILE_PATH_LITERAL("chrome/test/data");
122 124
123 namespace { 125 namespace {
124 126
127 // Sha256 fingerprint of okay.pem's Subject Public Key Information.
128 const char* kOkayPemSPKI =
129 "sha256/2zCMVDKgnKec0721Sp1zVh2yiHeW/LJK4STkNnEa1og=";
estark 2017/01/12 18:54:43 Hmmmmm. This is unfortunate, since okay.pem will g
meacer 2017/01/20 21:29:59 How often does it change? If it's, say, yearly, I
estark 2017/01/20 23:31:17 Yeah I think it's relatively rare, so including th
130
125 enum ProceedDecision { 131 enum ProceedDecision {
126 SSL_INTERSTITIAL_PROCEED, 132 SSL_INTERSTITIAL_PROCEED,
127 SSL_INTERSTITIAL_DO_NOT_PROCEED 133 SSL_INTERSTITIAL_DO_NOT_PROCEED
128 }; 134 };
129 135
130 namespace AuthState { 136 namespace AuthState {
131 137
132 enum AuthStateFlags { 138 enum AuthStateFlags {
133 NONE = 0, 139 NONE = 0,
134 DISPLAYED_INSECURE_CONTENT = 1 << 0, 140 DISPLAYED_INSECURE_CONTENT = 1 << 0,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTesting(&callback_); 223 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTesting(&callback_);
218 } 224 }
219 225
220 ~SSLInterstitialTimerObserver() { 226 ~SSLInterstitialTimerObserver() {
221 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTesting(nullptr); 227 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTesting(nullptr);
222 } 228 }
223 229
224 // Waits until the interstitial delay timer in SSLErrorHandler is started. 230 // Waits until the interstitial delay timer in SSLErrorHandler is started.
225 void WaitForTimerStarted() { message_loop_runner_->Run(); } 231 void WaitForTimerStarted() { message_loop_runner_->Run(); }
226 232
233 // Returns true if the timer has been started.
234 bool timer_started() const { return timer_started_; }
235
227 private: 236 private:
228 void OnTimerStarted(content::WebContents* web_contents) { 237 void OnTimerStarted(content::WebContents* web_contents) {
238 timer_started_ = true;
229 if (web_contents_ == web_contents) 239 if (web_contents_ == web_contents)
230 message_loop_runner_->Quit(); 240 message_loop_runner_->Quit();
231 } 241 }
232 242
243 bool timer_started_ = false;
233 const content::WebContents* web_contents_; 244 const content::WebContents* web_contents_;
234 SSLErrorHandler::TimerStartedCallback callback_; 245 SSLErrorHandler::TimerStartedCallback callback_;
235 246
236 std::unique_ptr<base::RunLoop> message_loop_runner_; 247 std::unique_ptr<base::RunLoop> message_loop_runner_;
237 248
238 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver); 249 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver);
239 }; 250 };
240 251
241 class HungJob : public net::URLRequestJob { 252 class HungJob : public net::URLRequestJob {
242 public: 253 public:
(...skipping 1616 matching lines...) Expand 10 before | Expand all | Expand 10 after
1859 // content (even though the image comes from the WebCore memory cache). 1870 // content (even though the image comes from the WebCore memory cache).
1860 const GURL url_https = https_server_.GetURL(replacement_path); 1871 const GURL url_https = https_server_.GetURL(replacement_path);
1861 ui_test_utils::NavigateToURL(browser(), url_https); 1872 ui_test_utils::NavigateToURL(browser(), url_https);
1862 CheckAuthenticationBrokenState(tab, CertError::NONE, 1873 CheckAuthenticationBrokenState(tab, CertError::NONE,
1863 AuthState::RAN_INSECURE_CONTENT); 1874 AuthState::RAN_INSECURE_CONTENT);
1864 } 1875 }
1865 1876
1866 // This test ensures the CN invalid status does not 'stick' to a certificate 1877 // This test ensures the CN invalid status does not 'stick' to a certificate
1867 // (see bug #1044942) and that it depends on the host-name. 1878 // (see bug #1044942) and that it depends on the host-name.
1868 // Test if disabled due to flakiness http://crbug.com/368280 . 1879 // Test if disabled due to flakiness http://crbug.com/368280 .
1869 IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestCNInvalidStickiness) { 1880 IN_PROC_BROWSER_TEST_F(SSLUITest, TestCNInvalidStickiness) {
estark 2017/01/12 18:54:43 Not flaky anymore?
meacer 2017/01/12 23:54:02 I was looking into re-enabling this in another CL.
1870 ASSERT_TRUE(https_server_.Start()); 1881 ASSERT_TRUE(https_server_.Start());
1871 ASSERT_TRUE(https_server_mismatched_.Start()); 1882 ASSERT_TRUE(https_server_mismatched_.Start());
1872 1883
1873 // First we hit the server with hostname, this generates an invalid policy 1884 // First we hit the server with hostname, this generates an invalid policy
1874 // error. 1885 // error.
1875 ui_test_utils::NavigateToURL( 1886 ui_test_utils::NavigateToURL(
1876 browser(), https_server_mismatched_.GetURL("/ssl/google.html")); 1887 browser(), https_server_mismatched_.GetURL("/ssl/google.html"));
1877 1888
1878 // We get an interstitial page as a result. 1889 // We get an interstitial page as a result.
1879 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 1890 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
(...skipping 1998 matching lines...) Expand 10 before | Expand all | Expand 10 after
3878 IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreLocalhostCertErrors, 3889 IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreLocalhostCertErrors,
3879 NoCrashOnLoadWithNoNavigationEntry) { 3890 NoCrashOnLoadWithNoNavigationEntry) {
3880 ASSERT_TRUE(embedded_test_server()->Start()); 3891 ASSERT_TRUE(embedded_test_server()->Start());
3881 3892
3882 ui_test_utils::NavigateToURL( 3893 ui_test_utils::NavigateToURL(
3883 browser(), embedded_test_server()->GetURL("/ssl/google.html")); 3894 browser(), embedded_test_server()->GetURL("/ssl/google.html"));
3884 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 3895 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
3885 ASSERT_TRUE(content::ExecuteScript(tab, "window.open()")); 3896 ASSERT_TRUE(content::ExecuteScript(tab, "window.open()"));
3886 } 3897 }
3887 3898
3899 IN_PROC_BROWSER_TEST_F(SSLUITest, CaptivePortalListTest) {
3900 ASSERT_TRUE(https_server_mismatched_.Start());
3901 base::HistogramTester histograms;
3902
3903 // Mark the server's cert as a captive portal cert.
3904 chrome_browser_ssl::TLSErrorAssistantConfig config_proto;
3905 config_proto.add_captive_portal_cert()->set_sha256_hash(kOkayPemSPKI);
3906 SSLErrorHandler::SetErrorAssistantProtoForTesting(config_proto);
3907
3908 // Navigate to an unsafe site. Proceed with interstitial page to indicate
3909 // the user approves the bad certificate.
3910 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
3911 SSLInterstitialTimerObserver interstitial_timer_observer(tab);
3912 ui_test_utils::NavigateToURL(
3913 browser(), https_server_mismatched_.GetURL("/ssl/blank_page.html"));
3914 content::WaitForInterstitialAttach(tab);
3915
3916 InterstitialPage* interstitial_page = tab->GetInterstitialPage();
3917 ASSERT_EQ(CaptivePortalBlockingPage::kTypeForTesting,
3918 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
3919 EXPECT_FALSE(interstitial_timer_observer.timer_started());
3920
3921 // Check that the histogram for the captive portal cert was recorded.
3922 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(),
3923 SSLErrorHandler::HANDLE_ALL, 1);
3924 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(),
3925 SSLErrorHandler::CAPTIVE_PORTAL_CERT_FOUND, 1);
3926 }
3927
3888 // TODO(jcampan): more tests to do below. 3928 // TODO(jcampan): more tests to do below.
3889 3929
3890 // Visit a page over https that contains a frame with a redirect. 3930 // Visit a page over https that contains a frame with a redirect.
3891 3931
3892 // XMLHttpRequest insecure content in synchronous mode. 3932 // XMLHttpRequest insecure content in synchronous mode.
3893 3933
3894 // XMLHttpRequest insecure content in asynchronous mode. 3934 // XMLHttpRequest insecure content in asynchronous mode.
3895 3935
3896 // XMLHttpRequest over bad ssl in synchronous mode. 3936 // XMLHttpRequest over bad ssl in synchronous mode.
3897 3937
3898 // XMLHttpRequest over OK ssl in synchronous mode. 3938 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698