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" |
| 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 Loading... | |
| 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" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 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" |
| 84 #include "net/base/net_errors.h" | 87 #include "net/base/net_errors.h" |
| 85 #include "net/cert/cert_status_flags.h" | 88 #include "net/cert/cert_status_flags.h" |
| 86 #include "net/cert/mock_cert_verifier.h" | 89 #include "net/cert/mock_cert_verifier.h" |
| 87 #include "net/cert/x509_certificate.h" | 90 #include "net/cert/x509_certificate.h" |
| 88 #include "net/dns/mock_host_resolver.h" | 91 #include "net/dns/mock_host_resolver.h" |
| 92 #include "net/http/http_response_headers.h" | |
| 89 #include "net/ssl/ssl_info.h" | 93 #include "net/ssl/ssl_info.h" |
| 90 #include "net/test/cert_test_util.h" | 94 #include "net/test/cert_test_util.h" |
| 91 #include "net/test/embedded_test_server/embedded_test_server.h" | 95 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 92 #include "net/test/embedded_test_server/request_handler_util.h" | 96 #include "net/test/embedded_test_server/request_handler_util.h" |
| 93 #include "net/test/spawned_test_server/spawned_test_server.h" | 97 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 94 #include "net/test/test_certificate_data.h" | 98 #include "net/test/test_certificate_data.h" |
| 95 #include "net/test/test_data_directory.h" | 99 #include "net/test/test_data_directory.h" |
| 96 #include "net/url_request/url_request_context.h" | 100 #include "net/url_request/url_request_context.h" |
| 97 #include "net/url_request/url_request_filter.h" | 101 #include "net/url_request/url_request_filter.h" |
| 98 #include "net/url_request/url_request_job.h" | 102 #include "net/url_request/url_request_job.h" |
| (...skipping 2747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2846 | 2850 |
| 2847 // Grab the SSLStatus from the page and check that it is the same as | 2851 // Grab the SSLStatus from the page and check that it is the same as |
| 2848 // on the clock interstitial. | 2852 // on the clock interstitial. |
| 2849 entry = tab->GetController().GetActiveEntry(); | 2853 entry = tab->GetController().GetActiveEntry(); |
| 2850 ASSERT_TRUE(entry); | 2854 ASSERT_TRUE(entry); |
| 2851 content::SSLStatus after_interstitial_ssl_status = entry->GetSSL(); | 2855 content::SSLStatus after_interstitial_ssl_status = entry->GetSSL(); |
| 2852 ASSERT_NO_FATAL_FAILURE( | 2856 ASSERT_NO_FATAL_FAILURE( |
| 2853 after_interstitial_ssl_status.Equals(clock_interstitial_ssl_status)); | 2857 after_interstitial_ssl_status.Equals(clock_interstitial_ssl_status)); |
| 2854 } | 2858 } |
| 2855 | 2859 |
| 2860 // A URLRequestJob that serves valid time server responses, but delays | |
| 2861 // them until Resume() is called. If Resume() is called before a request | |
| 2862 // is made, then the request will not be delayed. | |
| 2863 class DelayableTimeURLRequestJob : public net::URLRequestJob { | |
|
meacer
2016/11/02 22:43:22
nit: rename to Delayable*Network*TimeURLRequestJob
estark
2016/11/03 01:36:04
Done.
| |
| 2864 public: | |
| 2865 DelayableTimeURLRequestJob(net::URLRequest* request, | |
| 2866 net::NetworkDelegate* network_delegate, | |
| 2867 bool delayed) | |
| 2868 : net::URLRequestJob(request, network_delegate), | |
| 2869 delayed_(delayed), | |
| 2870 weak_factory_(this) {} | |
| 2871 | |
| 2872 ~DelayableTimeURLRequestJob() override {} | |
| 2873 | |
| 2874 /// URLRequestJob: | |
| 2875 void Start() override { | |
| 2876 if (delayed_) { | |
| 2877 // Do nothing until Resume() is called. | |
| 2878 return; | |
| 2879 } | |
| 2880 Resume(response_callback_); | |
| 2881 } | |
| 2882 | |
| 2883 int ReadRawData(net::IOBuffer* buf, int buf_size) override { | |
| 2884 int bytes_read = | |
| 2885 std::min(static_cast<size_t>(buf_size), | |
| 2886 strlen(network_time::kGoodTimeResponseBody) - data_offset_); | |
| 2887 memcpy(buf->data(), network_time::kGoodTimeResponseBody + data_offset_, | |
| 2888 bytes_read); | |
| 2889 data_offset_ += bytes_read; | |
| 2890 return bytes_read; | |
| 2891 } | |
| 2892 | |
| 2893 int GetResponseCode() const override { return 200; } | |
| 2894 | |
| 2895 void GetResponseInfo(net::HttpResponseInfo* info) override { | |
| 2896 std::string raw_headers; | |
| 2897 raw_headers.append( | |
| 2898 "HTTP/1.1 200 OK\n" | |
| 2899 "Content-type: text/plain\n"); | |
| 2900 raw_headers.append(base::StringPrintf( | |
| 2901 "Content-Length: %1d\n", | |
| 2902 static_cast<int>(strlen(network_time::kGoodTimeResponseBody)))); | |
| 2903 info->headers = | |
| 2904 new net::HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders( | |
| 2905 raw_headers.c_str(), static_cast<int>(raw_headers.length()))); | |
| 2906 info->headers->AddHeader( | |
| 2907 "x-cup-server-proof: " + | |
| 2908 std::string(network_time::kGoodTimeResponseServerProofHeader)); | |
| 2909 if (!response_callback_.is_null()) { | |
| 2910 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 2911 response_callback_); | |
| 2912 } | |
| 2913 } | |
| 2914 | |
| 2915 void StartAsync() { | |
| 2916 if (!request_) | |
| 2917 return; | |
| 2918 NotifyHeadersComplete(); | |
| 2919 } | |
| 2920 | |
| 2921 // Resumes delayed requests. When the response info for a request is | |
| 2922 // read (i.e. GetResponseInfo() is called), then |callback| will be | |
| 2923 // called. | |
| 2924 void Resume(const base::Closure& callback) { | |
|
meacer
2016/11/02 22:43:23
nit: dcheck for io thread?
estark
2016/11/03 01:36:04
Done.
| |
| 2925 response_callback_ = callback; | |
| 2926 // Start reading asynchronously as would a normal network request. | |
| 2927 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 2928 FROM_HERE, base::Bind(&DelayableTimeURLRequestJob::StartAsync, | |
| 2929 weak_factory_.GetWeakPtr())); | |
| 2930 } | |
| 2931 | |
| 2932 private: | |
| 2933 bool delayed_; | |
| 2934 int data_offset_ = 0; | |
| 2935 base::Closure response_callback_; | |
| 2936 base::WeakPtrFactory<DelayableTimeURLRequestJob> weak_factory_; | |
| 2937 }; | |
| 2938 | |
| 2939 // A URLRequestInterceptor that intercepts requests to use | |
| 2940 // DelayableTimeURLRequestJobs. | |
| 2941 class DelayedTimeInterceptor : public net::URLRequestInterceptor { | |
|
meacer
2016/11/02 22:43:22
nit: rename to DelayedNetworkTimeInterceptor?
estark
2016/11/03 01:36:05
Done.
| |
| 2942 public: | |
| 2943 DelayedTimeInterceptor() : net::URLRequestInterceptor() {} | |
| 2944 ~DelayedTimeInterceptor() override {} | |
| 2945 | |
| 2946 net::URLRequestJob* MaybeInterceptRequest( | |
| 2947 net::URLRequest* request, | |
| 2948 net::NetworkDelegate* network_delegate) const override { | |
| 2949 // If requests have been resumed before this request is created, | |
| 2950 // then |resumed_| will be true and the request will not delay. | |
|
meacer
2016/11/02 22:43:22
nit: Slightly confusing :) How about a "bool delay
estark
2016/11/03 01:36:05
Done.
| |
| 2951 DelayableTimeURLRequestJob* job = | |
| 2952 new DelayableTimeURLRequestJob(request, network_delegate, !resumed_); | |
| 2953 delayed_requests_.push_back(job); | |
| 2954 return job; | |
| 2955 } | |
| 2956 | |
| 2957 void ResumeAll(const base::Closure& callback) { | |
|
meacer
2016/11/02 22:43:22
nit: Could use a DCHECK for IO thread here.
estark
2016/11/03 01:36:04
Done.
| |
| 2958 if (resumed_) { | |
| 2959 return; | |
| 2960 } | |
| 2961 resumed_ = true; | |
| 2962 for (const auto& request : delayed_requests_) { | |
| 2963 request->Resume(callback); | |
| 2964 } | |
| 2965 delayed_requests_.clear(); | |
| 2966 } | |
| 2967 | |
| 2968 private: | |
| 2969 bool resumed_ = false; | |
| 2970 mutable std::vector<DelayableTimeURLRequestJob*> delayed_requests_; | |
| 2971 }; | |
| 2972 | |
| 2973 // A helper class for tasks that SSLNetworkTimeBrowserTest needs to | |
| 2974 // perform on the IO thread. Installs a DelayedTimeInterceptor and | |
| 2975 // resumes delayed requests when ResumeDelayedNetworkTimeRequests() is | |
| 2976 // called. | |
| 2977 class SSLNetworkTimeIOThreadHelper { | |
|
meacer
2016/11/02 22:43:22
nit: I think you could move the functionality in t
meacer
2016/11/02 22:44:38
And by "one fewer file" I meant "one fewer class".
estark
2016/11/03 01:36:04
Done. What do you mean by "make the interceptor su
meacer
2016/11/04 01:17:26
Never mind that, you're not posting any tasks in t
| |
| 2978 public: | |
| 2979 SSLNetworkTimeIOThreadHelper() {} | |
| 2980 virtual ~SSLNetworkTimeIOThreadHelper() {} | |
| 2981 | |
| 2982 void SetUpOnIOThread(const GURL& intercept_url) { | |
| 2983 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 2984 interceptor_ = new DelayedTimeInterceptor(); | |
| 2985 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | |
| 2986 intercept_url.scheme(), intercept_url.host(), | |
| 2987 std::unique_ptr<net::URLRequestInterceptor>(interceptor_)); | |
| 2988 } | |
| 2989 | |
| 2990 void CleanUpOnIOThread() { | |
| 2991 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 2992 net::URLRequestFilter::GetInstance()->ClearHandlers(); | |
| 2993 } | |
| 2994 | |
| 2995 void ResumeDelayedNetworkTimeRequests(const base::Closure& callback) { | |
| 2996 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 2997 interceptor_->ResumeAll(callback); | |
| 2998 } | |
| 2999 | |
| 3000 private: | |
| 3001 DelayedTimeInterceptor* interceptor_; | |
| 3002 }; | |
| 3003 | |
| 3004 // A fixture for testing on-demand network time queries on SSL | |
| 3005 // certificate date errors. It can simulate delayed network time | |
| 3006 // requests, and it allows the user to configure the experimental | |
| 3007 // parameters of the NetworkTimeTracker. | |
| 3008 class SSLNetworkTimeBrowserTest : public SSLUITest { | |
| 3009 public: | |
| 3010 SSLNetworkTimeBrowserTest() | |
| 3011 : SSLUITest(), | |
| 3012 field_trial_test_(network_time::FieldTrialTest::CreateForBrowserTest()), | |
| 3013 io_thread_helper_(new SSLNetworkTimeIOThreadHelper()) {} | |
| 3014 ~SSLNetworkTimeBrowserTest() override {} | |
| 3015 | |
| 3016 void TearDownOnMainThread() override { | |
| 3017 content::BrowserThread::PostTask( | |
| 3018 content::BrowserThread::IO, FROM_HERE, | |
| 3019 base::Bind(&SSLNetworkTimeIOThreadHelper::CleanUpOnIOThread, | |
| 3020 base::Unretained(io_thread_helper_.get()))); | |
| 3021 } | |
| 3022 | |
| 3023 protected: | |
| 3024 network_time::FieldTrialTest* field_trial_test() const { | |
| 3025 return field_trial_test_.get(); | |
| 3026 } | |
| 3027 | |
| 3028 void SetUpNetworkTimeServer() { | |
| 3029 field_trial_test()->SetNetworkQueriesWithVariationsService( | |
| 3030 true, 0.0, network_time::FieldTrialTest::FETCHES_ON_DEMAND_ONLY); | |
| 3031 | |
| 3032 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 3033 // Install the URL interceptor that serves delayed network time | |
| 3034 // responses. | |
| 3035 content::BrowserThread::PostTask( | |
| 3036 content::BrowserThread::IO, FROM_HERE, | |
| 3037 base::Bind(&SSLNetworkTimeIOThreadHelper::SetUpOnIOThread, | |
| 3038 base::Unretained(io_thread_helper_.get()), | |
| 3039 embedded_test_server()->GetURL("/"))); | |
|
meacer
2016/11/02 22:43:22
Since actual requests won't go through, there shou
estark
2016/11/03 01:36:04
Done.
| |
| 3040 | |
| 3041 g_browser_process->network_time_tracker()->SetTimeServerURLForTesting( | |
| 3042 embedded_test_server()->GetURL("/")); | |
| 3043 } | |
| 3044 | |
| 3045 void TriggerTimeResponse(const base::Closure& callback) { | |
| 3046 content::BrowserThread::PostTask( | |
| 3047 content::BrowserThread::IO, FROM_HERE, | |
| 3048 base::Bind( | |
| 3049 &SSLNetworkTimeIOThreadHelper::ResumeDelayedNetworkTimeRequests, | |
| 3050 base::Unretained(io_thread_helper_.get()), callback)); | |
| 3051 } | |
| 3052 | |
| 3053 private: | |
| 3054 std::unique_ptr<network_time::FieldTrialTest> field_trial_test_; | |
| 3055 std::unique_ptr<SSLNetworkTimeIOThreadHelper> io_thread_helper_; | |
| 3056 | |
| 3057 DISALLOW_COPY_AND_ASSIGN(SSLNetworkTimeBrowserTest); | |
| 3058 }; | |
| 3059 | |
| 3060 // Tests that if an on-demand network time fetch returns that the clock | |
| 3061 // is okay, a normal SSL interstitial is shown. | |
| 3062 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, OnDemandFetchClockOk) { | |
| 3063 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3064 SetUpNetworkTimeServer(); | |
| 3065 // Use a testing clock set to the time that GoodTimeResponseHandler | |
| 3066 // returns, to simulate the system clock matching the network time. | |
| 3067 base::SimpleTestClock testing_clock; | |
| 3068 SSLErrorHandler::SetClockForTest(&testing_clock); | |
| 3069 testing_clock.SetNow( | |
| 3070 base::Time::FromJsTime(network_time::kGoodTimeResponseHandlerTime)); | |
| 3071 // Set the build time to match the testing clock, to ensure that the | |
| 3072 // build time heuristic doesn't fire. | |
| 3073 ssl_errors::SetBuildTimeForTesting(testing_clock.Now()); | |
| 3074 | |
| 3075 // Set a long timeout to ensure that the on-demand time fetch completes. | |
| 3076 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3077 | |
| 3078 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3079 ASSERT_TRUE(contents); | |
| 3080 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3081 | |
| 3082 content::WindowedNotificationObserver observer( | |
| 3083 content::NOTIFICATION_LOAD_STOP, | |
| 3084 content::NotificationService::AllSources()); | |
| 3085 ui_test_utils::NavigateToURLWithDisposition( | |
| 3086 browser(), https_server_expired_.GetURL("/"), | |
| 3087 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3088 | |
| 3089 // Once |interstitial_timer_observer| has fired, the request has been | |
| 3090 // sent. Override the nonce that NetworkTimeTracker expects so that | |
| 3091 // when the response comes back, it will validate. The nonce can only | |
| 3092 // be overriden for the current in-flight request, so the test must | |
| 3093 // call OverrideNonceForTesting() after the request has been sent and | |
| 3094 // before the response has been received. | |
| 3095 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3096 g_browser_process->network_time_tracker()->OverrideNonceForTesting(123123123); | |
| 3097 base::RunLoop wait_for_response; | |
|
meacer
2016/11/02 22:43:22
nit: rename wait_for_time_response? (otherwise it
estark
2016/11/03 01:36:05
Done.
| |
| 3098 TriggerTimeResponse(wait_for_response.QuitClosure()); | |
| 3099 | |
| 3100 EXPECT_TRUE(contents->IsLoading()); | |
| 3101 observer.Wait(); | |
| 3102 content::WaitForInterstitialAttach(contents); | |
| 3103 wait_for_response.Run(); | |
| 3104 | |
| 3105 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 3106 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | |
| 3107 ASSERT_TRUE(interstitial_page); | |
| 3108 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | |
| 3109 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 3110 } | |
| 3111 | |
| 3112 // Tests that if an on-demand network time fetch returns that the clock | |
| 3113 // is wrong, a bad clock interstitial is shown. | |
| 3114 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, OnDemandFetchClockWrong) { | |
| 3115 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3116 SetUpNetworkTimeServer(); | |
| 3117 // Use a testing clock set to a time that is different from what | |
| 3118 // GoodTimeResponseHandler returns, simulating a system clock that is | |
| 3119 // 30 days ahead of the network time. | |
| 3120 base::SimpleTestClock testing_clock; | |
| 3121 SSLErrorHandler::SetClockForTest(&testing_clock); | |
| 3122 testing_clock.SetNow( | |
| 3123 base::Time::FromJsTime(network_time::kGoodTimeResponseHandlerTime)); | |
| 3124 testing_clock.Advance(base::TimeDelta::FromDays(30)); | |
| 3125 // Set the build time to match the testing clock, to ensure that the | |
| 3126 // build time heuristic doesn't fire. | |
| 3127 ssl_errors::SetBuildTimeForTesting(testing_clock.Now()); | |
| 3128 | |
| 3129 // Set a long timeout to ensure that the on-demand time fetch completes. | |
| 3130 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3131 | |
| 3132 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3133 ASSERT_TRUE(contents); | |
| 3134 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3135 | |
| 3136 content::WindowedNotificationObserver observer( | |
| 3137 content::NOTIFICATION_LOAD_STOP, | |
| 3138 content::NotificationService::AllSources()); | |
| 3139 | |
| 3140 ui_test_utils::NavigateToURLWithDisposition( | |
| 3141 browser(), https_server_expired_.GetURL("/"), | |
| 3142 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3143 | |
| 3144 // Once |interstitial_timer_observer| has fired, the request has been | |
| 3145 // sent. Override the nonce that NetworkTimeTracker expects so that | |
| 3146 // when the response comes back, it will validate. The nonce can only | |
| 3147 // be overriden for the current in-flight request, so the test must | |
| 3148 // call OverrideNonceForTesting() after the request has been sent and | |
| 3149 // before the response has been received. | |
| 3150 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3151 g_browser_process->network_time_tracker()->OverrideNonceForTesting(123123123); | |
| 3152 base::RunLoop wait_for_response; | |
| 3153 TriggerTimeResponse(wait_for_response.QuitClosure()); | |
| 3154 | |
| 3155 EXPECT_TRUE(contents->IsLoading()); | |
| 3156 observer.Wait(); | |
| 3157 content::WaitForInterstitialAttach(contents); | |
| 3158 wait_for_response.Run(); | |
| 3159 | |
| 3160 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 3161 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | |
| 3162 ASSERT_TRUE(interstitial_page); | |
| 3163 ASSERT_EQ(BadClockBlockingPage::kTypeForTesting, | |
| 3164 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 3165 } | |
| 3166 | |
| 3167 // Tests that if the timeout expires before the network time fetch | |
| 3168 // returns, then a normal SSL intersitial is shown. | |
| 3169 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, | |
| 3170 TimeoutExpiresBeforeFetchCompletes) { | |
| 3171 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3172 SetUpNetworkTimeServer(); | |
| 3173 // Set the timer to fire immediately. | |
| 3174 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta()); | |
| 3175 | |
| 3176 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); | |
| 3177 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3178 ASSERT_TRUE(contents); | |
| 3179 content::WaitForInterstitialAttach(contents); | |
| 3180 | |
| 3181 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 3182 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | |
| 3183 ASSERT_TRUE(interstitial_page); | |
| 3184 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | |
| 3185 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 3186 | |
| 3187 // Navigate away and then trigger the network time response; no crash | |
| 3188 // should occur. | |
| 3189 ASSERT_TRUE(https_server_.Start()); | |
| 3190 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/")); | |
| 3191 base::RunLoop wait_for_response; | |
| 3192 TriggerTimeResponse(wait_for_response.QuitClosure()); | |
| 3193 wait_for_response.Run(); | |
| 3194 } | |
| 3195 | |
| 3196 // Tests that if the user stops the page load before either the network | |
| 3197 // time fetch completes or the timeout expires, then there is no interstitial. | |
| 3198 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, StopBeforeTimeoutExpires) { | |
| 3199 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3200 SetUpNetworkTimeServer(); | |
| 3201 // Set the timer to a long delay. | |
| 3202 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3203 | |
| 3204 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3205 ASSERT_TRUE(contents); | |
| 3206 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3207 | |
| 3208 ui_test_utils::NavigateToURLWithDisposition( | |
| 3209 browser(), https_server_expired_.GetURL("/"), | |
| 3210 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3211 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3212 | |
| 3213 EXPECT_TRUE(contents->IsLoading()); | |
| 3214 content::WindowedNotificationObserver observer( | |
| 3215 content::NOTIFICATION_LOAD_STOP, | |
| 3216 content::NotificationService::AllSources()); | |
| 3217 contents->Stop(); | |
| 3218 observer.Wait(); | |
| 3219 | |
| 3220 // Make sure that the |SSLErrorHandler| is deleted. | |
| 3221 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents)); | |
| 3222 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 3223 EXPECT_FALSE(contents->IsLoading()); | |
| 3224 | |
| 3225 // Navigate away and then trigger the network time response; no crash | |
| 3226 // should occur. | |
| 3227 ASSERT_TRUE(https_server_.Start()); | |
| 3228 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html")); | |
| 3229 base::RunLoop wait_for_response; | |
| 3230 TriggerTimeResponse(wait_for_response.QuitClosure()); | |
| 3231 wait_for_response.Run(); | |
| 3232 } | |
| 3233 | |
| 3234 // Tests that if the user reloads the page before either the network | |
| 3235 // time fetch completes or the timeout expires, then there is no interstitial. | |
| 3236 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, ReloadBeforeTimeoutExpires) { | |
| 3237 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3238 SetUpNetworkTimeServer(); | |
| 3239 // Set the timer to a long delay. | |
| 3240 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3241 | |
| 3242 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3243 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3244 | |
| 3245 ui_test_utils::NavigateToURLWithDisposition( | |
| 3246 browser(), https_server_expired_.GetURL("/"), | |
| 3247 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3248 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3249 | |
| 3250 EXPECT_TRUE(contents->IsLoading()); | |
| 3251 content::TestNavigationObserver observer(contents, 1); | |
| 3252 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | |
| 3253 observer.Wait(); | |
| 3254 | |
| 3255 // Make sure that the |SSLErrorHandler| is deleted. | |
| 3256 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents)); | |
| 3257 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 3258 EXPECT_FALSE(contents->IsLoading()); | |
| 3259 | |
| 3260 // Navigate away and then trigger the network time response; no crash | |
| 3261 // should occur. | |
| 3262 ASSERT_TRUE(https_server_.Start()); | |
| 3263 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/")); | |
| 3264 base::RunLoop wait_for_response; | |
| 3265 TriggerTimeResponse(wait_for_response.QuitClosure()); | |
|
meacer
2016/11/02 22:43:23
What happens if there were more than one delayed n
estark
2016/11/03 01:36:05
This would only wait for the first one. Subsequent
| |
| 3266 wait_for_response.Run(); | |
| 3267 } | |
| 3268 | |
| 3269 // Tests that if the user navigates away before either the network time | |
| 3270 // fetch completes or the timeout expires, then there is no | |
| 3271 // interstitial. | |
| 3272 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, | |
| 3273 NavigateAwayBeforeTimeoutExpires) { | |
| 3274 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3275 ASSERT_TRUE(https_server_.Start()); | |
| 3276 SetUpNetworkTimeServer(); | |
| 3277 // Set the timer to a long delay. | |
| 3278 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3279 | |
| 3280 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3281 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3282 | |
| 3283 ui_test_utils::NavigateToURLWithDisposition( | |
| 3284 browser(), https_server_expired_.GetURL("/"), | |
| 3285 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3286 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3287 | |
| 3288 EXPECT_TRUE(contents->IsLoading()); | |
| 3289 content::TestNavigationObserver observer(contents, 1); | |
| 3290 browser()->OpenURL(content::OpenURLParams( | |
| 3291 https_server_.GetURL("/"), content::Referrer(), | |
| 3292 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); | |
| 3293 observer.Wait(); | |
| 3294 | |
| 3295 // Make sure that the |SSLErrorHandler| is deleted. | |
| 3296 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents)); | |
| 3297 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 3298 EXPECT_FALSE(contents->IsLoading()); | |
| 3299 | |
| 3300 // Navigate away and then trigger the network time response; no crash | |
| 3301 // should occur. | |
|
meacer
2016/11/02 22:43:23
nit:
"Navigate away, then trigger the network tim
estark
2016/11/03 01:36:04
Done.
| |
| 3302 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/")); | |
| 3303 base::RunLoop wait_for_response; | |
| 3304 TriggerTimeResponse(wait_for_response.QuitClosure()); | |
| 3305 wait_for_response.Run(); | |
| 3306 } | |
| 3307 | |
| 3308 // Tests that if the user closes the tab before the network time fetch | |
| 3309 // completes, it doesn't cause a crash. | |
| 3310 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, | |
| 3311 CloseTabBeforeNetworkFetchCompletes) { | |
| 3312 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3313 SetUpNetworkTimeServer(); | |
| 3314 // Set the timer to fire immediately. | |
| 3315 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta()); | |
| 3316 | |
| 3317 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); | |
| 3318 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3319 ASSERT_TRUE(contents); | |
| 3320 content::WaitForInterstitialAttach(contents); | |
| 3321 | |
| 3322 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 3323 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | |
| 3324 ASSERT_TRUE(interstitial_page); | |
| 3325 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | |
| 3326 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 3327 | |
| 3328 // Open a second tab, close the first, and then trigger the network time | |
| 3329 // response; no crash | |
| 3330 // should occur. | |
|
meacer
2016/11/02 22:43:22
nit: Fits into previous line
estark
2016/11/03 01:36:05
Done.
| |
| 3331 ASSERT_TRUE(https_server_.Start()); | |
| 3332 AddTabAtIndex(1, https_server_.GetURL("/"), ui::PAGE_TRANSITION_TYPED); | |
| 3333 chrome::CloseWebContents(browser(), contents, false); | |
| 3334 base::RunLoop wait_for_response; | |
| 3335 TriggerTimeResponse(wait_for_response.QuitClosure()); | |
| 3336 wait_for_response.Run(); | |
| 3337 } | |
| 3338 | |
| 2856 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest { | 3339 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest { |
| 2857 public: | 3340 public: |
| 2858 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {} | 3341 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {} |
| 2859 ~CommonNameMismatchBrowserTest() override {} | 3342 ~CommonNameMismatchBrowserTest() override {} |
| 2860 | 3343 |
| 2861 void SetUpCommandLine(base::CommandLine* command_line) override { | 3344 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 2862 // Enable finch experiment for SSL common name mismatch handling. | 3345 // Enable finch experiment for SSL common name mismatch handling. |
| 2863 command_line->AppendSwitchASCII(switches::kForceFieldTrials, | 3346 command_line->AppendSwitchASCII(switches::kForceFieldTrials, |
| 2864 "SSLCommonNameMismatchHandling/Enabled/"); | 3347 "SSLCommonNameMismatchHandling/Enabled/"); |
| 2865 } | 3348 } |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3410 | 3893 |
| 3411 // Visit a page over https that contains a frame with a redirect. | 3894 // Visit a page over https that contains a frame with a redirect. |
| 3412 | 3895 |
| 3413 // XMLHttpRequest insecure content in synchronous mode. | 3896 // XMLHttpRequest insecure content in synchronous mode. |
| 3414 | 3897 |
| 3415 // XMLHttpRequest insecure content in asynchronous mode. | 3898 // XMLHttpRequest insecure content in asynchronous mode. |
| 3416 | 3899 |
| 3417 // XMLHttpRequest over bad ssl in synchronous mode. | 3900 // XMLHttpRequest over bad ssl in synchronous mode. |
| 3418 | 3901 |
| 3419 // XMLHttpRequest over OK ssl in synchronous mode. | 3902 // XMLHttpRequest over OK ssl in synchronous mode. |
| OLD | NEW |