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

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

Issue 2449193002: Attempt an on-demand time fetch when encountering a date invalid error (Closed)
Patch Set: meacer nits Created 4 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/ssl/ssl_error_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/test/histogram_tester.h" 20 #include "base/test/histogram_tester.h"
21 #include "base/test/simple_test_clock.h" 21 #include "base/test/simple_test_clock.h"
22 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/time/default_clock.h"
24 #include "base/time/default_tick_clock.h"
23 #include "base/time/time.h" 25 #include "base/time/time.h"
24 #include "build/build_config.h" 26 #include "build/build_config.h"
25 #include "chrome/app/chrome_command_ids.h" 27 #include "chrome/app/chrome_command_ids.h"
26 #include "chrome/browser/browser_process.h" 28 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/chrome_notification_types.h" 29 #include "chrome/browser/chrome_notification_types.h"
28 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 30 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
29 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" 31 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
30 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/ssl/bad_clock_blocking_page.h" 33 #include "chrome/browser/ssl/bad_clock_blocking_page.h"
32 #include "chrome/browser/ssl/cert_report_helper.h" 34 #include "chrome/browser/ssl/cert_report_helper.h"
(...skipping 10 matching lines...) Expand all
43 #include "chrome/browser/ui/browser_navigator.h" 45 #include "chrome/browser/ui/browser_navigator.h"
44 #include "chrome/browser/ui/browser_navigator_params.h" 46 #include "chrome/browser/ui/browser_navigator_params.h"
45 #include "chrome/browser/ui/browser_tabstrip.h" 47 #include "chrome/browser/ui/browser_tabstrip.h"
46 #include "chrome/browser/ui/tabs/tab_strip_model.h" 48 #include "chrome/browser/ui/tabs/tab_strip_model.h"
47 #include "chrome/common/chrome_paths.h" 49 #include "chrome/common/chrome_paths.h"
48 #include "chrome/common/chrome_switches.h" 50 #include "chrome/common/chrome_switches.h"
49 #include "chrome/common/pref_names.h" 51 #include "chrome/common/pref_names.h"
50 #include "chrome/test/base/in_process_browser_test.h" 52 #include "chrome/test/base/in_process_browser_test.h"
51 #include "chrome/test/base/ui_test_utils.h" 53 #include "chrome/test/base/ui_test_utils.h"
52 #include "components/content_settings/core/browser/host_content_settings_map.h" 54 #include "components/content_settings/core/browser/host_content_settings_map.h"
55 #include "components/network_time/network_time_test_utils.h"
53 #include "components/network_time/network_time_tracker.h" 56 #include "components/network_time/network_time_tracker.h"
54 #include "components/prefs/pref_service.h" 57 #include "components/prefs/testing_pref_service.h"
55 #include "components/security_interstitials/core/controller_client.h" 58 #include "components/security_interstitials/core/controller_client.h"
56 #include "components/security_interstitials/core/metrics_helper.h" 59 #include "components/security_interstitials/core/metrics_helper.h"
57 #include "components/security_state/security_state_model.h" 60 #include "components/security_state/security_state_model.h"
58 #include "components/security_state/switches.h" 61 #include "components/security_state/switches.h"
59 #include "components/ssl_errors/error_classification.h" 62 #include "components/ssl_errors/error_classification.h"
60 #include "components/variations/variations_associated_data.h" 63 #include "components/variations/variations_associated_data.h"
61 #include "components/web_modal/web_contents_modal_dialog_manager.h" 64 #include "components/web_modal/web_contents_modal_dialog_manager.h"
62 #include "content/public/browser/browser_context.h" 65 #include "content/public/browser/browser_context.h"
63 #include "content/public/browser/interstitial_page.h" 66 #include "content/public/browser/interstitial_page.h"
64 #include "content/public/browser/navigation_controller.h" 67 #include "content/public/browser/navigation_controller.h"
65 #include "content/public/browser/navigation_entry.h" 68 #include "content/public/browser/navigation_entry.h"
66 #include "content/public/browser/notification_details.h" 69 #include "content/public/browser/notification_details.h"
67 #include "content/public/browser/notification_service.h" 70 #include "content/public/browser/notification_service.h"
68 #include "content/public/browser/render_frame_host.h" 71 #include "content/public/browser/render_frame_host.h"
69 #include "content/public/browser/render_view_host.h" 72 #include "content/public/browser/render_view_host.h"
70 #include "content/public/browser/render_widget_host_view.h" 73 #include "content/public/browser/render_widget_host_view.h"
71 #include "content/public/browser/restore_type.h" 74 #include "content/public/browser/restore_type.h"
72 #include "content/public/browser/ssl_status.h" 75 #include "content/public/browser/ssl_status.h"
73 #include "content/public/browser/web_contents.h" 76 #include "content/public/browser/web_contents.h"
74 #include "content/public/browser/web_contents_observer.h" 77 #include "content/public/browser/web_contents_observer.h"
75 #include "content/public/common/browser_side_navigation_policy.h" 78 #include "content/public/common/browser_side_navigation_policy.h"
76 #include "content/public/common/content_switches.h" 79 #include "content/public/common/content_switches.h"
77 #include "content/public/common/page_state.h" 80 #include "content/public/common/page_state.h"
78 #include "content/public/test/browser_test_utils.h" 81 #include "content/public/test/browser_test_utils.h"
79 #include "content/public/test/download_test_observer.h" 82 #include "content/public/test/download_test_observer.h"
80 #include "content/public/test/test_navigation_observer.h" 83 #include "content/public/test/test_navigation_observer.h"
81 #include "content/public/test/test_renderer_host.h" 84 #include "content/public/test/test_renderer_host.h"
82 #include "content/public/test/test_utils.h" 85 #include "content/public/test/test_utils.h"
83 #include "net/base/host_port_pair.h" 86 #include "net/base/host_port_pair.h"
87 #include "net/base/io_buffer.h"
84 #include "net/base/net_errors.h" 88 #include "net/base/net_errors.h"
85 #include "net/cert/cert_status_flags.h" 89 #include "net/cert/cert_status_flags.h"
86 #include "net/cert/mock_cert_verifier.h" 90 #include "net/cert/mock_cert_verifier.h"
87 #include "net/cert/x509_certificate.h" 91 #include "net/cert/x509_certificate.h"
88 #include "net/dns/mock_host_resolver.h" 92 #include "net/dns/mock_host_resolver.h"
93 #include "net/http/http_response_headers.h"
89 #include "net/ssl/ssl_info.h" 94 #include "net/ssl/ssl_info.h"
90 #include "net/test/cert_test_util.h" 95 #include "net/test/cert_test_util.h"
91 #include "net/test/embedded_test_server/embedded_test_server.h" 96 #include "net/test/embedded_test_server/embedded_test_server.h"
92 #include "net/test/embedded_test_server/request_handler_util.h" 97 #include "net/test/embedded_test_server/request_handler_util.h"
93 #include "net/test/spawned_test_server/spawned_test_server.h" 98 #include "net/test/spawned_test_server/spawned_test_server.h"
94 #include "net/test/test_certificate_data.h" 99 #include "net/test/test_certificate_data.h"
95 #include "net/test/test_data_directory.h" 100 #include "net/test/test_data_directory.h"
96 #include "net/url_request/url_request_context.h" 101 #include "net/url_request/url_request_context.h"
97 #include "net/url_request/url_request_filter.h" 102 #include "net/url_request/url_request_filter.h"
98 #include "net/url_request/url_request_job.h" 103 #include "net/url_request/url_request_job.h"
(...skipping 2747 matching lines...) Expand 10 before | Expand all | Expand 10 after
2846 2851
2847 // Grab the SSLStatus from the page and check that it is the same as 2852 // Grab the SSLStatus from the page and check that it is the same as
2848 // on the clock interstitial. 2853 // on the clock interstitial.
2849 entry = tab->GetController().GetActiveEntry(); 2854 entry = tab->GetController().GetActiveEntry();
2850 ASSERT_TRUE(entry); 2855 ASSERT_TRUE(entry);
2851 content::SSLStatus after_interstitial_ssl_status = entry->GetSSL(); 2856 content::SSLStatus after_interstitial_ssl_status = entry->GetSSL();
2852 ASSERT_NO_FATAL_FAILURE( 2857 ASSERT_NO_FATAL_FAILURE(
2853 after_interstitial_ssl_status.Equals(clock_interstitial_ssl_status)); 2858 after_interstitial_ssl_status.Equals(clock_interstitial_ssl_status));
2854 } 2859 }
2855 2860
2861 // A URLRequestJob that serves valid time server responses, but delays
2862 // them until Resume() is called. If Resume() is called before a request
2863 // is made, then the request will not be delayed.
2864 class DelayableNetworkTimeURLRequestJob : public net::URLRequestJob {
2865 public:
2866 DelayableNetworkTimeURLRequestJob(net::URLRequest* request,
2867 net::NetworkDelegate* network_delegate,
2868 bool delayed)
2869 : net::URLRequestJob(request, network_delegate),
2870 delayed_(delayed),
2871 weak_factory_(this) {}
2872
2873 ~DelayableNetworkTimeURLRequestJob() override {}
2874
2875 base::WeakPtr<DelayableNetworkTimeURLRequestJob> GetWeakPtr() {
2876 return weak_factory_.GetWeakPtr();
2877 }
2878
2879 // URLRequestJob:
2880 void Start() override {
2881 started_ = true;
2882 if (delayed_) {
2883 // Do nothing until Resume() is called.
2884 return;
2885 }
2886 Resume();
2887 }
2888
2889 int ReadRawData(net::IOBuffer* buf, int buf_size) override {
2890 int bytes_read =
2891 std::min(static_cast<size_t>(buf_size),
2892 strlen(network_time::kGoodTimeResponseBody) - data_offset_);
2893 memcpy(buf->data(), network_time::kGoodTimeResponseBody + data_offset_,
2894 bytes_read);
2895 data_offset_ += bytes_read;
2896 return bytes_read;
2897 }
2898
2899 int GetResponseCode() const override { return 200; }
2900
2901 void GetResponseInfo(net::HttpResponseInfo* info) override {
2902 std::string headers;
2903 headers.append(
2904 "HTTP/1.1 200 OK\n"
2905 "Content-type: text/plain\n");
2906 headers.append(base::StringPrintf(
2907 "Content-Length: %1d\n",
2908 static_cast<int>(strlen(network_time::kGoodTimeResponseBody))));
2909 info->headers =
2910 new net::HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders(
2911 headers.c_str(), static_cast<int>(headers.length())));
2912 info->headers->AddHeader(
2913 "x-cup-server-proof: " +
2914 std::string(network_time::kGoodTimeResponseServerProofHeader));
2915 }
2916
2917 // Resumes a previously started request that was delayed. If no
2918 // request has been started yet, then when Start() is called it will
2919 // not delay.
2920 void Resume() {
2921 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
2922 DCHECK(delayed_);
2923 if (!started_) {
2924 // If Start() hasn't been called yet, then unset |delayed_| so
2925 // that when Start() is called, the request will begin
2926 // immediately.
2927 delayed_ = false;
2928 return;
2929 }
2930
2931 // Start reading asynchronously as would a normal network request.
2932 base::ThreadTaskRunnerHandle::Get()->PostTask(
2933 FROM_HERE,
2934 base::Bind(&DelayableNetworkTimeURLRequestJob::NotifyHeadersComplete,
2935 weak_factory_.GetWeakPtr()));
2936 }
2937
2938 private:
2939 bool delayed_;
2940 bool started_ = false;
2941 int data_offset_ = 0;
2942 base::WeakPtrFactory<DelayableNetworkTimeURLRequestJob> weak_factory_;
2943
2944 DISALLOW_COPY_AND_ASSIGN(DelayableNetworkTimeURLRequestJob);
2945 };
2946
2947 // A URLRequestInterceptor that intercepts requests to use
2948 // DelayableNetworkTimeURLRequestJobs. Expects to intercept only a
2949 // single request in its lifetime.
2950 class DelayedNetworkTimeInterceptor : public net::URLRequestInterceptor {
2951 public:
2952 DelayedNetworkTimeInterceptor() {}
2953 ~DelayedNetworkTimeInterceptor() override {}
2954
2955 // Intercepts |request| to use a DelayableNetworkTimeURLRequestJob. If
2956 // Resume() has been called before MaybeInterceptRequest(), then the
2957 // request will not be delayed.
2958 net::URLRequestJob* MaybeInterceptRequest(
2959 net::URLRequest* request,
2960 net::NetworkDelegate* network_delegate) const override {
2961 // Only support one intercepted request.
2962 EXPECT_FALSE(intercepted_request_);
2963 intercepted_request_ = true;
2964 // If the request has been resumed before this request is created,
2965 // then |should_delay_requests_| will be false and the request will
2966 // not delay.
2967 DelayableNetworkTimeURLRequestJob* job =
2968 new DelayableNetworkTimeURLRequestJob(request, network_delegate,
2969 should_delay_requests_);
2970 if (should_delay_requests_)
2971 delayed_request_ = job->GetWeakPtr();
2972 return job;
2973 }
2974
2975 void Resume() {
2976 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
2977 if (!should_delay_requests_)
2978 return;
2979 should_delay_requests_ = false;
2980 if (delayed_request_)
2981 delayed_request_->Resume();
2982 }
2983
2984 private:
2985 // True if a request has been intercepted. Used to enforce that only
2986 // one request is intercepted in this object's lifetime.
2987 mutable bool intercepted_request_ = false;
2988 // True until Resume() is called. If Resume() is called before a
2989 // request is intercepted, then a request that is intercepted later
2990 // will continue without a delay.
2991 bool should_delay_requests_ = true;
2992 // Use a WeakPtr in case the request is cancelled before Resume() is called.
2993 mutable base::WeakPtr<DelayableNetworkTimeURLRequestJob> delayed_request_ =
2994 nullptr;
2995
2996 DISALLOW_COPY_AND_ASSIGN(DelayedNetworkTimeInterceptor);
2997 };
2998
2999 // IO-thread helper methods for SSLNetworkTimeBrowserTest.
3000
3001 void ResumeDelayedNetworkTimeRequest(
3002 DelayedNetworkTimeInterceptor* interceptor) {
3003 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
3004 interceptor->Resume();
3005 }
3006
3007 void SetUpNetworkTimeInterceptorOnIOThread(
3008 DelayedNetworkTimeInterceptor* interceptor,
3009 const GURL& time_server_url) {
3010 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
3011 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor(
3012 time_server_url.scheme(), time_server_url.host(),
3013 std::unique_ptr<DelayedNetworkTimeInterceptor>(interceptor));
3014 }
3015
3016 void CleanUpOnIOThread() {
3017 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
3018 net::URLRequestFilter::GetInstance()->ClearHandlers();
3019 }
3020
3021 // A fixture for testing on-demand network time queries on SSL
3022 // certificate date errors. It can simulate a delayed network time
3023 // request, and it allows the user to configure the experimental
3024 // parameters of the NetworkTimeTracker. Expects only one network time
3025 // request to be issued during the test.
3026 class SSLNetworkTimeBrowserTest : public SSLUITest {
3027 public:
3028 SSLNetworkTimeBrowserTest()
3029 : SSLUITest(),
3030 field_trial_test_(network_time::FieldTrialTest::CreateForBrowserTest()),
3031 interceptor_(nullptr) {}
3032 ~SSLNetworkTimeBrowserTest() override {}
3033
3034 void SetUpOnMainThread() override { SetUpNetworkTimeServer(); }
3035
3036 void TearDownOnMainThread() override {
3037 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
3038 base::Bind(&CleanUpOnIOThread));
3039 }
3040
3041 protected:
3042 network_time::FieldTrialTest* field_trial_test() const {
3043 return field_trial_test_.get();
3044 }
3045
3046 void SetUpNetworkTimeServer() {
3047 field_trial_test()->SetNetworkQueriesWithVariationsService(
3048 true, 0.0, network_time::FieldTrialTest::FETCHES_ON_DEMAND_ONLY);
3049
3050 // Install the URL interceptor that serves delayed network time
3051 // responses.
3052 interceptor_ = new DelayedNetworkTimeInterceptor();
3053 content::BrowserThread::PostTask(
3054 content::BrowserThread::IO, FROM_HERE,
3055 base::Bind(&SetUpNetworkTimeInterceptorOnIOThread,
3056 base::Unretained(interceptor_),
3057 g_browser_process->network_time_tracker()
3058 ->GetTimeServerURLForTesting()));
3059 }
3060
3061 void TriggerTimeResponse() {
3062 content::BrowserThread::PostTask(
3063 content::BrowserThread::IO, FROM_HERE,
3064 base::Bind(&ResumeDelayedNetworkTimeRequest,
3065 base::Unretained(interceptor_)));
3066 }
3067
3068 // Asserts that the first time request to the server is currently pending.
3069 void CheckTimeQueryPending() {
3070 base::Time unused_time;
3071 base::TimeDelta unused_uncertainty;
3072 ASSERT_EQ(network_time::NetworkTimeTracker::NETWORK_TIME_FIRST_SYNC_PENDING,
3073 g_browser_process->network_time_tracker()->GetNetworkTime(
3074 &unused_time, &unused_uncertainty));
3075 }
3076
3077 private:
3078 std::unique_ptr<network_time::FieldTrialTest> field_trial_test_;
3079 DelayedNetworkTimeInterceptor* interceptor_;
3080
3081 DISALLOW_COPY_AND_ASSIGN(SSLNetworkTimeBrowserTest);
3082 };
3083
3084 // Tests that if an on-demand network time fetch returns that the clock
3085 // is okay, a normal SSL interstitial is shown.
3086 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, OnDemandFetchClockOk) {
3087 ASSERT_TRUE(https_server_expired_.Start());
3088 // Use a testing clock set to the time that GoodTimeResponseHandler
3089 // returns, to simulate the system clock matching the network time.
3090 base::SimpleTestClock testing_clock;
3091 SSLErrorHandler::SetClockForTest(&testing_clock);
3092 testing_clock.SetNow(
3093 base::Time::FromJsTime(network_time::kGoodTimeResponseHandlerJsTime));
3094 // Set the build time to match the testing clock, to ensure that the
3095 // build time heuristic doesn't fire.
3096 ssl_errors::SetBuildTimeForTesting(testing_clock.Now());
3097
3098 // Set a long timeout to ensure that the on-demand time fetch completes.
3099 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1));
3100
3101 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3102 ASSERT_TRUE(contents);
3103 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
3104
3105 content::WindowedNotificationObserver observer(
3106 content::NOTIFICATION_LOAD_STOP,
3107 content::NotificationService::AllSources());
3108 ui_test_utils::NavigateToURLWithDisposition(
3109 browser(), https_server_expired_.GetURL("/"),
3110 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
3111
3112 // Once |interstitial_timer_observer| has fired, the request has been
3113 // sent. Override the nonce that NetworkTimeTracker expects so that
3114 // when the response comes back, it will validate. The nonce can only
3115 // be overriden for the current in-flight request, so the test must
3116 // call OverrideNonceForTesting() after the request has been sent and
3117 // before the response has been received.
3118 interstitial_timer_observer.WaitForTimerStarted();
3119 g_browser_process->network_time_tracker()->OverrideNonceForTesting(123123123);
3120 TriggerTimeResponse();
3121
3122 EXPECT_TRUE(contents->IsLoading());
3123 observer.Wait();
3124 content::WaitForInterstitialAttach(contents);
3125
3126 EXPECT_TRUE(contents->ShowingInterstitialPage());
3127 InterstitialPage* interstitial_page = contents->GetInterstitialPage();
3128 ASSERT_TRUE(interstitial_page);
3129 ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
3130 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
3131 }
3132
3133 // Tests that if an on-demand network time fetch returns that the clock
3134 // is wrong, a bad clock interstitial is shown.
3135 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, OnDemandFetchClockWrong) {
3136 ASSERT_TRUE(https_server_expired_.Start());
3137 // Use a testing clock set to a time that is different from what
3138 // GoodTimeResponseHandler returns, simulating a system clock that is
3139 // 30 days ahead of the network time.
3140 base::SimpleTestClock testing_clock;
3141 SSLErrorHandler::SetClockForTest(&testing_clock);
3142 testing_clock.SetNow(
3143 base::Time::FromJsTime(network_time::kGoodTimeResponseHandlerJsTime));
3144 testing_clock.Advance(base::TimeDelta::FromDays(30));
3145 // Set the build time to match the testing clock, to ensure that the
3146 // build time heuristic doesn't fire.
3147 ssl_errors::SetBuildTimeForTesting(testing_clock.Now());
3148
3149 // Set a long timeout to ensure that the on-demand time fetch completes.
3150 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1));
3151
3152 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3153 ASSERT_TRUE(contents);
3154 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
3155
3156 content::WindowedNotificationObserver observer(
3157 content::NOTIFICATION_LOAD_STOP,
3158 content::NotificationService::AllSources());
3159
3160 ui_test_utils::NavigateToURLWithDisposition(
3161 browser(), https_server_expired_.GetURL("/"),
3162 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
3163
3164 // Once |interstitial_timer_observer| has fired, the request has been
3165 // sent. Override the nonce that NetworkTimeTracker expects so that
3166 // when the response comes back, it will validate. The nonce can only
3167 // be overriden for the current in-flight request, so the test must
3168 // call OverrideNonceForTesting() after the request has been sent and
3169 // before the response has been received.
3170 interstitial_timer_observer.WaitForTimerStarted();
3171 g_browser_process->network_time_tracker()->OverrideNonceForTesting(123123123);
3172 TriggerTimeResponse();
3173
3174 EXPECT_TRUE(contents->IsLoading());
3175 observer.Wait();
3176 content::WaitForInterstitialAttach(contents);
3177
3178 EXPECT_TRUE(contents->ShowingInterstitialPage());
3179 InterstitialPage* interstitial_page = contents->GetInterstitialPage();
3180 ASSERT_TRUE(interstitial_page);
3181 ASSERT_EQ(BadClockBlockingPage::kTypeForTesting,
3182 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
3183 }
3184
3185 // Tests that if the timeout expires before the network time fetch
3186 // returns, then a normal SSL intersitial is shown.
3187 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest,
3188 TimeoutExpiresBeforeFetchCompletes) {
3189 ASSERT_TRUE(https_server_expired_.Start());
3190 // Set the timer to fire immediately.
3191 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta());
3192
3193 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/"));
3194 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3195 ASSERT_TRUE(contents);
3196 content::WaitForInterstitialAttach(contents);
3197
3198 EXPECT_TRUE(contents->ShowingInterstitialPage());
3199 InterstitialPage* interstitial_page = contents->GetInterstitialPage();
3200 ASSERT_TRUE(interstitial_page);
3201 ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
3202 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
3203
3204 // Navigate away, and then trigger the network time response; no crash should
3205 // occur.
3206 ASSERT_TRUE(https_server_.Start());
3207 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/"));
3208 ASSERT_NO_FATAL_FAILURE(CheckTimeQueryPending());
3209 TriggerTimeResponse();
3210 }
3211
3212 // Tests that if the user stops the page load before either the network
3213 // time fetch completes or the timeout expires, then there is no interstitial.
3214 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, StopBeforeTimeoutExpires) {
3215 ASSERT_TRUE(https_server_expired_.Start());
3216 // Set the timer to a long delay.
3217 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1));
3218
3219 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3220 ASSERT_TRUE(contents);
3221 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
3222
3223 ui_test_utils::NavigateToURLWithDisposition(
3224 browser(), https_server_expired_.GetURL("/"),
3225 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
3226 interstitial_timer_observer.WaitForTimerStarted();
3227
3228 EXPECT_TRUE(contents->IsLoading());
3229 content::WindowedNotificationObserver observer(
3230 content::NOTIFICATION_LOAD_STOP,
3231 content::NotificationService::AllSources());
3232 contents->Stop();
3233 observer.Wait();
3234
3235 // Make sure that the |SSLErrorHandler| is deleted.
3236 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents));
3237 EXPECT_FALSE(contents->ShowingInterstitialPage());
3238 EXPECT_FALSE(contents->IsLoading());
3239
3240 // Navigate away, and then trigger the network time response; no crash should
3241 // occur.
3242 ASSERT_TRUE(https_server_.Start());
3243 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html"));
3244 ASSERT_NO_FATAL_FAILURE(CheckTimeQueryPending());
3245 TriggerTimeResponse();
3246 }
3247
3248 // Tests that if the user reloads the page before either the network
3249 // time fetch completes or the timeout expires, then there is no interstitial.
3250 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, ReloadBeforeTimeoutExpires) {
3251 ASSERT_TRUE(https_server_expired_.Start());
3252 // Set the timer to a long delay.
3253 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1));
3254
3255 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3256 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
3257
3258 ui_test_utils::NavigateToURLWithDisposition(
3259 browser(), https_server_expired_.GetURL("/"),
3260 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
3261 interstitial_timer_observer.WaitForTimerStarted();
3262
3263 EXPECT_TRUE(contents->IsLoading());
3264 content::TestNavigationObserver observer(contents, 1);
3265 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
3266 observer.Wait();
3267
3268 // Make sure that the |SSLErrorHandler| is deleted.
3269 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents));
3270 EXPECT_FALSE(contents->ShowingInterstitialPage());
3271 EXPECT_FALSE(contents->IsLoading());
3272
3273 // Navigate away, and then trigger the network time response and wait
3274 // for the response; no crash should occur.
3275 ASSERT_TRUE(https_server_.Start());
3276 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/"));
3277 ASSERT_NO_FATAL_FAILURE(CheckTimeQueryPending());
3278 TriggerTimeResponse();
3279 }
3280
3281 // Tests that if the user navigates away before either the network time
3282 // fetch completes or the timeout expires, then there is no
3283 // interstitial.
3284 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest,
3285 NavigateAwayBeforeTimeoutExpires) {
3286 ASSERT_TRUE(https_server_expired_.Start());
3287 ASSERT_TRUE(https_server_.Start());
3288 // Set the timer to a long delay.
3289 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1));
3290
3291 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3292 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
3293
3294 ui_test_utils::NavigateToURLWithDisposition(
3295 browser(), https_server_expired_.GetURL("/"),
3296 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
3297 interstitial_timer_observer.WaitForTimerStarted();
3298
3299 EXPECT_TRUE(contents->IsLoading());
3300 content::TestNavigationObserver observer(contents, 1);
3301 browser()->OpenURL(content::OpenURLParams(
3302 https_server_.GetURL("/"), content::Referrer(),
3303 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
3304 observer.Wait();
3305
3306 // Make sure that the |SSLErrorHandler| is deleted.
3307 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents));
3308 EXPECT_FALSE(contents->ShowingInterstitialPage());
3309 EXPECT_FALSE(contents->IsLoading());
3310
3311 // Navigate away, and then trigger the network time response and wait
3312 // for the response; no crash should occur.
3313 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/"));
3314 ASSERT_NO_FATAL_FAILURE(CheckTimeQueryPending());
3315 TriggerTimeResponse();
3316 }
3317
3318 // Tests that if the user closes the tab before the network time fetch
3319 // completes, it doesn't cause a crash.
3320 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest,
3321 CloseTabBeforeNetworkFetchCompletes) {
3322 ASSERT_TRUE(https_server_expired_.Start());
3323 // Set the timer to fire immediately.
3324 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta());
3325
3326 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/"));
3327 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3328 ASSERT_TRUE(contents);
3329 content::WaitForInterstitialAttach(contents);
3330
3331 EXPECT_TRUE(contents->ShowingInterstitialPage());
3332 InterstitialPage* interstitial_page = contents->GetInterstitialPage();
3333 ASSERT_TRUE(interstitial_page);
3334 ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
3335 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
3336
3337 // Open a second tab, close the first, and then trigger the network time
3338 // response and wait for the response; no crash should occur.
3339 ASSERT_TRUE(https_server_.Start());
3340 AddTabAtIndex(1, https_server_.GetURL("/"), ui::PAGE_TRANSITION_TYPED);
3341 chrome::CloseWebContents(browser(), contents, false);
3342 ASSERT_NO_FATAL_FAILURE(CheckTimeQueryPending());
3343 TriggerTimeResponse();
3344 }
3345
2856 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest { 3346 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest {
2857 public: 3347 public:
2858 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {} 3348 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {}
2859 ~CommonNameMismatchBrowserTest() override {} 3349 ~CommonNameMismatchBrowserTest() override {}
2860 3350
2861 void SetUpCommandLine(base::CommandLine* command_line) override { 3351 void SetUpCommandLine(base::CommandLine* command_line) override {
2862 // Enable finch experiment for SSL common name mismatch handling. 3352 // Enable finch experiment for SSL common name mismatch handling.
2863 command_line->AppendSwitchASCII(switches::kForceFieldTrials, 3353 command_line->AppendSwitchASCII(switches::kForceFieldTrials,
2864 "SSLCommonNameMismatchHandling/Enabled/"); 3354 "SSLCommonNameMismatchHandling/Enabled/");
2865 } 3355 }
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
3410 3900
3411 // Visit a page over https that contains a frame with a redirect. 3901 // Visit a page over https that contains a frame with a redirect.
3412 3902
3413 // XMLHttpRequest insecure content in synchronous mode. 3903 // XMLHttpRequest insecure content in synchronous mode.
3414 3904
3415 // XMLHttpRequest insecure content in asynchronous mode. 3905 // XMLHttpRequest insecure content in asynchronous mode.
3416 3906
3417 // XMLHttpRequest over bad ssl in synchronous mode. 3907 // XMLHttpRequest over bad ssl in synchronous mode.
3418 3908
3419 // XMLHttpRequest over OK ssl in synchronous mode. 3909 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ssl/ssl_error_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698