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 DelayableNetworkTimeURLRequestJob : public net::URLRequestJob { | |
| 2864 public: | |
| 2865 DelayableNetworkTimeURLRequestJob(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 ~DelayableNetworkTimeURLRequestJob() override {} | |
| 2873 | |
| 2874 /// URLRequestJob: | |
|
mmenke
2016/11/07 15:27:45
nit: Remove extra slash.
estark
2016/11/07 23:24:00
Done.
| |
| 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_, | |
|
mmenke
2016/11/07 15:27:45
Should include net/base/io_buffer.h
estark
2016/11/07 23:24:00
Done.
| |
| 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( | |
|
mmenke
2016/11/07 15:27:45
Terminology is confusing here, but the term "raw h
estark
2016/11/07 23:24:00
Done.
| |
| 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_) | |
|
mmenke
2016/11/07 15:27:45
Not need to check this - the request owns the URLR
estark
2016/11/07 23:24:00
Done.
| |
| 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 |quit_closure| will be | |
| 2923 // called. | |
|
mmenke
2016/11/07 15:27:45
Putting this in GetResponseInfo isn't right - ther
estark
2016/11/07 23:24:00
I removed this callback. (See question above -- no
| |
| 2924 void Resume(const base::Closure& quit_closure) { | |
| 2925 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 2926 response_callback_ = quit_closure; | |
| 2927 // Start reading asynchronously as would a normal network request. | |
| 2928 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 2929 FROM_HERE, base::Bind(&DelayableNetworkTimeURLRequestJob::StartAsync, | |
| 2930 weak_factory_.GetWeakPtr())); | |
|
mmenke
2016/11/07 15:27:45
Should handle jobs that haven't yet had Start() ca
mmenke
2016/11/07 15:27:45
You're using weak_ptrs here, but DelayedNetworkTim
estark
2016/11/07 23:24:00
Done. If Resume() is called before Start(), then w
estark
2016/11/07 23:24:00
I think this should handle premature request destr
| |
| 2931 } | |
| 2932 | |
| 2933 private: | |
| 2934 bool delayed_; | |
| 2935 int data_offset_ = 0; | |
| 2936 base::Closure response_callback_; | |
| 2937 base::WeakPtrFactory<DelayableNetworkTimeURLRequestJob> weak_factory_; | |
| 2938 | |
| 2939 DISALLOW_COPY_AND_ASSIGN(DelayableNetworkTimeURLRequestJob); | |
| 2940 }; | |
| 2941 | |
| 2942 // A URLRequestInterceptor that intercepts requests to use | |
| 2943 // DelayableNetworkTimeURLRequestJobs. | |
| 2944 class DelayedNetworkTimeInterceptor : public net::URLRequestInterceptor { | |
| 2945 public: | |
| 2946 DelayedNetworkTimeInterceptor() : net::URLRequestInterceptor() {} | |
|
mmenke
2016/11/07 15:27:45
net::URLRequestInterceptor() not needed.
estark
2016/11/07 23:24:00
Done.
| |
| 2947 ~DelayedNetworkTimeInterceptor() override {} | |
| 2948 | |
| 2949 net::URLRequestJob* MaybeInterceptRequest( | |
| 2950 net::URLRequest* request, | |
| 2951 net::NetworkDelegate* network_delegate) const override { | |
| 2952 // If requests have been resumed before this request is created, | |
| 2953 // then |delay_requests_| will be false and the request will not delay. | |
| 2954 DelayableNetworkTimeURLRequestJob* job = | |
| 2955 new DelayableNetworkTimeURLRequestJob(request, network_delegate, | |
| 2956 delay_requests_); | |
| 2957 if (delay_requests_) { | |
| 2958 delayed_requests_.push_back(job); | |
| 2959 } | |
|
mmenke
2016/11/07 15:27:45
nit: Remove braces for two-line ifs.
estark
2016/11/07 23:24:00
Done.
| |
| 2960 return job; | |
| 2961 } | |
| 2962 | |
| 2963 void ResumeAll(const base::Closure& quit_closure) { | |
| 2964 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 2965 if (!delay_requests_) { | |
| 2966 return; | |
| 2967 } | |
|
mmenke
2016/11/07 15:27:45
nit: Remove braces for two-line ifs.
estark
2016/11/07 23:24:00
Done.
| |
| 2968 delay_requests_ = false; | |
| 2969 for (const auto& request : delayed_requests_) { | |
| 2970 request->Resume(quit_closure); | |
|
mmenke
2016/11/07 15:27:45
If no requests have been started yet, quit closure
estark
2016/11/07 23:24:00
Done; I changed the interceptor to expect only one
mmenke
2016/11/08 15:24:21
I don't see any waiting on NetworkDelegate::OnComp
estark
2016/11/08 17:54:01
Oh no, I'm sorry, I uploaded this in a weird inter
| |
| 2971 } | |
| 2972 delayed_requests_.clear(); | |
| 2973 } | |
| 2974 | |
| 2975 private: | |
| 2976 bool delay_requests_ = true; | |
| 2977 mutable std::vector<DelayableNetworkTimeURLRequestJob*> delayed_requests_; | |
| 2978 | |
| 2979 DISALLOW_COPY_AND_ASSIGN(DelayedNetworkTimeInterceptor); | |
| 2980 }; | |
| 2981 | |
| 2982 // Helper method for SSLNetworkTimeBrowserTest. | |
| 2983 void CleanUpOnIOThread() { | |
| 2984 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 2985 net::URLRequestFilter::GetInstance()->ClearHandlers(); | |
| 2986 } | |
| 2987 | |
| 2988 // A fixture for testing on-demand network time queries on SSL | |
| 2989 // certificate date errors. It can simulate delayed network time | |
| 2990 // requests, and it allows the user to configure the experimental | |
| 2991 // parameters of the NetworkTimeTracker. | |
| 2992 class SSLNetworkTimeBrowserTest : public SSLUITest { | |
| 2993 public: | |
| 2994 SSLNetworkTimeBrowserTest() | |
| 2995 : SSLUITest(), | |
| 2996 field_trial_test_(network_time::FieldTrialTest::CreateForBrowserTest()), | |
| 2997 interceptor_(nullptr) {} | |
| 2998 ~SSLNetworkTimeBrowserTest() override {} | |
| 2999 | |
| 3000 void TearDownOnMainThread() override { | |
| 3001 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | |
| 3002 base::Bind(&CleanUpOnIOThread)); | |
| 3003 } | |
| 3004 | |
| 3005 protected: | |
| 3006 network_time::FieldTrialTest* field_trial_test() const { | |
| 3007 return field_trial_test_.get(); | |
| 3008 } | |
| 3009 | |
| 3010 void SetUpNetworkTimeServer() { | |
| 3011 field_trial_test()->SetNetworkQueriesWithVariationsService( | |
| 3012 true, 0.0, network_time::FieldTrialTest::FETCHES_ON_DEMAND_ONLY); | |
| 3013 | |
| 3014 // Install the URL interceptor that serves delayed network time | |
| 3015 // responses. | |
| 3016 content::BrowserThread::PostTask( | |
| 3017 content::BrowserThread::IO, FROM_HERE, | |
| 3018 base::Bind( | |
| 3019 &SSLNetworkTimeBrowserTest::SetUpNetworkTimeInterceptorOnIOThread, | |
| 3020 base::Unretained(this), g_browser_process->network_time_tracker() | |
| 3021 ->GetTimeServerURLForTesting())); | |
| 3022 } | |
| 3023 | |
| 3024 void TriggerTimeResponse(const base::Closure& quit_closure) { | |
| 3025 content::BrowserThread::PostTask( | |
| 3026 content::BrowserThread::IO, FROM_HERE, | |
| 3027 base::Bind(&SSLNetworkTimeBrowserTest::ResumeDelayedNetworkTimeRequests, | |
| 3028 base::Unretained(this), quit_closure)); | |
| 3029 } | |
| 3030 | |
| 3031 private: | |
| 3032 void SetUpNetworkTimeInterceptorOnIOThread(const GURL& time_server_url) { | |
| 3033 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 3034 interceptor_ = new DelayedNetworkTimeInterceptor(); | |
|
mmenke
2016/11/07 15:27:45
This works. My own personal style preference woul
estark
2016/11/07 17:17:19
If I were to do that, would I pass a WeakPtr to th
mmenke
2016/11/07 17:21:41
It would be an unretained pointer. The intercepto
estark
2016/11/07 23:24:00
Done.
| |
| 3035 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | |
| 3036 time_server_url.scheme(), time_server_url.host(), | |
| 3037 std::unique_ptr<DelayedNetworkTimeInterceptor>(interceptor_)); | |
| 3038 } | |
| 3039 | |
| 3040 void ResumeDelayedNetworkTimeRequests(const base::Closure& quit_closure) { | |
| 3041 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 3042 interceptor_->ResumeAll(quit_closure); | |
| 3043 } | |
| 3044 | |
| 3045 std::unique_ptr<network_time::FieldTrialTest> field_trial_test_; | |
| 3046 | |
| 3047 // Should only be accessed on the IO thread. | |
| 3048 DelayedNetworkTimeInterceptor* interceptor_; | |
| 3049 | |
| 3050 DISALLOW_COPY_AND_ASSIGN(SSLNetworkTimeBrowserTest); | |
| 3051 }; | |
| 3052 | |
| 3053 // Tests that if an on-demand network time fetch returns that the clock | |
| 3054 // is okay, a normal SSL interstitial is shown. | |
| 3055 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, OnDemandFetchClockOk) { | |
| 3056 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3057 SetUpNetworkTimeServer(); | |
| 3058 // Use a testing clock set to the time that GoodTimeResponseHandler | |
| 3059 // returns, to simulate the system clock matching the network time. | |
| 3060 base::SimpleTestClock testing_clock; | |
| 3061 SSLErrorHandler::SetClockForTest(&testing_clock); | |
| 3062 testing_clock.SetNow( | |
| 3063 base::Time::FromJsTime(network_time::kGoodTimeResponseHandlerJsTime)); | |
| 3064 // Set the build time to match the testing clock, to ensure that the | |
| 3065 // build time heuristic doesn't fire. | |
| 3066 ssl_errors::SetBuildTimeForTesting(testing_clock.Now()); | |
| 3067 | |
| 3068 // Set a long timeout to ensure that the on-demand time fetch completes. | |
| 3069 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3070 | |
| 3071 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3072 ASSERT_TRUE(contents); | |
| 3073 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3074 | |
| 3075 content::WindowedNotificationObserver observer( | |
| 3076 content::NOTIFICATION_LOAD_STOP, | |
| 3077 content::NotificationService::AllSources()); | |
| 3078 ui_test_utils::NavigateToURLWithDisposition( | |
| 3079 browser(), https_server_expired_.GetURL("/"), | |
| 3080 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3081 | |
| 3082 // Once |interstitial_timer_observer| has fired, the request has been | |
| 3083 // sent. Override the nonce that NetworkTimeTracker expects so that | |
| 3084 // when the response comes back, it will validate. The nonce can only | |
| 3085 // be overriden for the current in-flight request, so the test must | |
| 3086 // call OverrideNonceForTesting() after the request has been sent and | |
| 3087 // before the response has been received. | |
| 3088 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3089 g_browser_process->network_time_tracker()->OverrideNonceForTesting(123123123); | |
| 3090 base::RunLoop wait_for_time_response; | |
| 3091 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3092 | |
| 3093 EXPECT_TRUE(contents->IsLoading()); | |
| 3094 observer.Wait(); | |
| 3095 content::WaitForInterstitialAttach(contents); | |
| 3096 wait_for_time_response.Run(); | |
| 3097 | |
| 3098 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 3099 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | |
| 3100 ASSERT_TRUE(interstitial_page); | |
| 3101 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | |
| 3102 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 3103 } | |
| 3104 | |
| 3105 // Tests that if an on-demand network time fetch returns that the clock | |
| 3106 // is wrong, a bad clock interstitial is shown. | |
| 3107 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, OnDemandFetchClockWrong) { | |
| 3108 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3109 SetUpNetworkTimeServer(); | |
| 3110 // Use a testing clock set to a time that is different from what | |
| 3111 // GoodTimeResponseHandler returns, simulating a system clock that is | |
| 3112 // 30 days ahead of the network time. | |
| 3113 base::SimpleTestClock testing_clock; | |
| 3114 SSLErrorHandler::SetClockForTest(&testing_clock); | |
| 3115 testing_clock.SetNow( | |
| 3116 base::Time::FromJsTime(network_time::kGoodTimeResponseHandlerJsTime)); | |
| 3117 testing_clock.Advance(base::TimeDelta::FromDays(30)); | |
| 3118 // Set the build time to match the testing clock, to ensure that the | |
| 3119 // build time heuristic doesn't fire. | |
| 3120 ssl_errors::SetBuildTimeForTesting(testing_clock.Now()); | |
| 3121 | |
| 3122 // Set a long timeout to ensure that the on-demand time fetch completes. | |
| 3123 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3124 | |
| 3125 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3126 ASSERT_TRUE(contents); | |
| 3127 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3128 | |
| 3129 content::WindowedNotificationObserver observer( | |
| 3130 content::NOTIFICATION_LOAD_STOP, | |
| 3131 content::NotificationService::AllSources()); | |
| 3132 | |
| 3133 ui_test_utils::NavigateToURLWithDisposition( | |
| 3134 browser(), https_server_expired_.GetURL("/"), | |
| 3135 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3136 | |
| 3137 // Once |interstitial_timer_observer| has fired, the request has been | |
| 3138 // sent. Override the nonce that NetworkTimeTracker expects so that | |
| 3139 // when the response comes back, it will validate. The nonce can only | |
| 3140 // be overriden for the current in-flight request, so the test must | |
| 3141 // call OverrideNonceForTesting() after the request has been sent and | |
| 3142 // before the response has been received. | |
| 3143 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3144 g_browser_process->network_time_tracker()->OverrideNonceForTesting(123123123); | |
| 3145 base::RunLoop wait_for_time_response; | |
| 3146 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3147 | |
| 3148 EXPECT_TRUE(contents->IsLoading()); | |
| 3149 observer.Wait(); | |
| 3150 content::WaitForInterstitialAttach(contents); | |
| 3151 wait_for_time_response.Run(); | |
| 3152 | |
| 3153 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 3154 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | |
| 3155 ASSERT_TRUE(interstitial_page); | |
| 3156 ASSERT_EQ(BadClockBlockingPage::kTypeForTesting, | |
| 3157 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 3158 } | |
| 3159 | |
| 3160 // Tests that if the timeout expires before the network time fetch | |
| 3161 // returns, then a normal SSL intersitial is shown. | |
| 3162 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, | |
| 3163 TimeoutExpiresBeforeFetchCompletes) { | |
| 3164 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3165 SetUpNetworkTimeServer(); | |
| 3166 // Set the timer to fire immediately. | |
| 3167 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta()); | |
| 3168 | |
| 3169 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); | |
| 3170 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3171 ASSERT_TRUE(contents); | |
| 3172 content::WaitForInterstitialAttach(contents); | |
| 3173 | |
| 3174 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 3175 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | |
| 3176 ASSERT_TRUE(interstitial_page); | |
| 3177 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | |
| 3178 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 3179 | |
| 3180 // Navigate away, and then trigger the network time response and wait | |
| 3181 // for the response; no crash should occur. | |
| 3182 ASSERT_TRUE(https_server_.Start()); | |
| 3183 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/")); | |
| 3184 base::RunLoop wait_for_time_response; | |
| 3185 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3186 wait_for_time_response.Run(); | |
| 3187 } | |
| 3188 | |
| 3189 // Tests that if the user stops the page load before either the network | |
| 3190 // time fetch completes or the timeout expires, then there is no interstitial. | |
| 3191 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, StopBeforeTimeoutExpires) { | |
| 3192 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3193 SetUpNetworkTimeServer(); | |
| 3194 // Set the timer to a long delay. | |
| 3195 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3196 | |
| 3197 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3198 ASSERT_TRUE(contents); | |
| 3199 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3200 | |
| 3201 ui_test_utils::NavigateToURLWithDisposition( | |
| 3202 browser(), https_server_expired_.GetURL("/"), | |
| 3203 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3204 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3205 | |
| 3206 EXPECT_TRUE(contents->IsLoading()); | |
| 3207 content::WindowedNotificationObserver observer( | |
| 3208 content::NOTIFICATION_LOAD_STOP, | |
| 3209 content::NotificationService::AllSources()); | |
| 3210 contents->Stop(); | |
| 3211 observer.Wait(); | |
| 3212 | |
| 3213 // Make sure that the |SSLErrorHandler| is deleted. | |
| 3214 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents)); | |
| 3215 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 3216 EXPECT_FALSE(contents->IsLoading()); | |
| 3217 | |
| 3218 // Navigate away, and then trigger the network time response and wait | |
| 3219 // for the response; no crash should occur. | |
| 3220 ASSERT_TRUE(https_server_.Start()); | |
| 3221 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html")); | |
| 3222 base::RunLoop wait_for_time_response; | |
| 3223 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3224 wait_for_time_response.Run(); | |
| 3225 } | |
| 3226 | |
| 3227 // Tests that if the user reloads the page before either the network | |
| 3228 // time fetch completes or the timeout expires, then there is no interstitial. | |
| 3229 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, ReloadBeforeTimeoutExpires) { | |
| 3230 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3231 SetUpNetworkTimeServer(); | |
| 3232 // Set the timer to a long delay. | |
| 3233 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3234 | |
| 3235 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3236 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3237 | |
| 3238 ui_test_utils::NavigateToURLWithDisposition( | |
| 3239 browser(), https_server_expired_.GetURL("/"), | |
| 3240 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3241 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3242 | |
| 3243 EXPECT_TRUE(contents->IsLoading()); | |
| 3244 content::TestNavigationObserver observer(contents, 1); | |
| 3245 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | |
| 3246 observer.Wait(); | |
| 3247 | |
| 3248 // Make sure that the |SSLErrorHandler| is deleted. | |
| 3249 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents)); | |
| 3250 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 3251 EXPECT_FALSE(contents->IsLoading()); | |
| 3252 | |
| 3253 // Navigate away, and then trigger the network time response and wait | |
| 3254 // for the response; no crash should occur. | |
| 3255 ASSERT_TRUE(https_server_.Start()); | |
| 3256 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/")); | |
| 3257 base::RunLoop wait_for_time_response; | |
| 3258 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3259 wait_for_time_response.Run(); | |
| 3260 } | |
| 3261 | |
| 3262 // Tests that if the user navigates away before either the network time | |
| 3263 // fetch completes or the timeout expires, then there is no | |
| 3264 // interstitial. | |
| 3265 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, | |
| 3266 NavigateAwayBeforeTimeoutExpires) { | |
| 3267 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3268 ASSERT_TRUE(https_server_.Start()); | |
| 3269 SetUpNetworkTimeServer(); | |
| 3270 // Set the timer to a long delay. | |
| 3271 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3272 | |
| 3273 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3274 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3275 | |
| 3276 ui_test_utils::NavigateToURLWithDisposition( | |
| 3277 browser(), https_server_expired_.GetURL("/"), | |
| 3278 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3279 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3280 | |
| 3281 EXPECT_TRUE(contents->IsLoading()); | |
| 3282 content::TestNavigationObserver observer(contents, 1); | |
| 3283 browser()->OpenURL(content::OpenURLParams( | |
| 3284 https_server_.GetURL("/"), content::Referrer(), | |
| 3285 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); | |
| 3286 observer.Wait(); | |
| 3287 | |
| 3288 // Make sure that the |SSLErrorHandler| is deleted. | |
| 3289 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents)); | |
| 3290 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 3291 EXPECT_FALSE(contents->IsLoading()); | |
| 3292 | |
| 3293 // Navigate away, and then trigger the network time response and wait | |
| 3294 // for the response; no crash should occur. | |
| 3295 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/")); | |
| 3296 base::RunLoop wait_for_time_response; | |
| 3297 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3298 wait_for_time_response.Run(); | |
| 3299 } | |
| 3300 | |
| 3301 // Tests that if the user closes the tab before the network time fetch | |
| 3302 // completes, it doesn't cause a crash. | |
| 3303 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, | |
| 3304 CloseTabBeforeNetworkFetchCompletes) { | |
| 3305 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3306 SetUpNetworkTimeServer(); | |
| 3307 // Set the timer to fire immediately. | |
| 3308 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta()); | |
| 3309 | |
| 3310 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); | |
| 3311 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3312 ASSERT_TRUE(contents); | |
| 3313 content::WaitForInterstitialAttach(contents); | |
| 3314 | |
| 3315 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 3316 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | |
| 3317 ASSERT_TRUE(interstitial_page); | |
| 3318 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | |
| 3319 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 3320 | |
| 3321 // Open a second tab, close the first, and then trigger the network time | |
| 3322 // response and wait for the response; no crash should occur. | |
| 3323 ASSERT_TRUE(https_server_.Start()); | |
| 3324 AddTabAtIndex(1, https_server_.GetURL("/"), ui::PAGE_TRANSITION_TYPED); | |
| 3325 chrome::CloseWebContents(browser(), contents, false); | |
| 3326 base::RunLoop wait_for_time_response; | |
| 3327 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3328 wait_for_time_response.Run(); | |
| 3329 } | |
| 3330 | |
| 2856 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest { | 3331 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest { |
| 2857 public: | 3332 public: |
| 2858 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {} | 3333 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {} |
| 2859 ~CommonNameMismatchBrowserTest() override {} | 3334 ~CommonNameMismatchBrowserTest() override {} |
| 2860 | 3335 |
| 2861 void SetUpCommandLine(base::CommandLine* command_line) override { | 3336 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 2862 // Enable finch experiment for SSL common name mismatch handling. | 3337 // Enable finch experiment for SSL common name mismatch handling. |
| 2863 command_line->AppendSwitchASCII(switches::kForceFieldTrials, | 3338 command_line->AppendSwitchASCII(switches::kForceFieldTrials, |
| 2864 "SSLCommonNameMismatchHandling/Enabled/"); | 3339 "SSLCommonNameMismatchHandling/Enabled/"); |
| 2865 } | 3340 } |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3410 | 3885 |
| 3411 // Visit a page over https that contains a frame with a redirect. | 3886 // Visit a page over https that contains a frame with a redirect. |
| 3412 | 3887 |
| 3413 // XMLHttpRequest insecure content in synchronous mode. | 3888 // XMLHttpRequest insecure content in synchronous mode. |
| 3414 | 3889 |
| 3415 // XMLHttpRequest insecure content in asynchronous mode. | 3890 // XMLHttpRequest insecure content in asynchronous mode. |
| 3416 | 3891 |
| 3417 // XMLHttpRequest over bad ssl in synchronous mode. | 3892 // XMLHttpRequest over bad ssl in synchronous mode. |
| 3418 | 3893 |
| 3419 // XMLHttpRequest over OK ssl in synchronous mode. | 3894 // XMLHttpRequest over OK ssl in synchronous mode. |
| OLD | NEW |