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: | |
| 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) { | |
| 2925 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 2926 response_callback_ = callback; | |
| 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())); | |
| 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() {} | |
| 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 } | |
| 2960 return job; | |
| 2961 } | |
| 2962 | |
| 2963 void ResumeAll(const base::Closure& callback) { | |
| 2964 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 2965 if (!delay_requests_) { | |
| 2966 return; | |
| 2967 } | |
| 2968 delay_requests_ = false; | |
| 2969 for (const auto& request : delayed_requests_) { | |
| 2970 request->Resume(callback); | |
| 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 weak_factory_(this) {} | |
| 2999 ~SSLNetworkTimeBrowserTest() override {} | |
| 3000 | |
| 3001 void TearDownOnMainThread() override { | |
| 3002 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | |
| 3003 base::Bind(&CleanUpOnIOThread)); | |
| 3004 } | |
| 3005 | |
| 3006 protected: | |
| 3007 network_time::FieldTrialTest* field_trial_test() const { | |
| 3008 return field_trial_test_.get(); | |
| 3009 } | |
| 3010 | |
| 3011 void SetUpNetworkTimeServer() { | |
| 3012 field_trial_test()->SetNetworkQueriesWithVariationsService( | |
| 3013 true, 0.0, network_time::FieldTrialTest::FETCHES_ON_DEMAND_ONLY); | |
| 3014 | |
| 3015 // Install the URL interceptor that serves delayed network time | |
| 3016 // responses. | |
| 3017 content::BrowserThread::PostTask( | |
| 3018 content::BrowserThread::IO, FROM_HERE, | |
| 3019 base::Bind( | |
| 3020 &SSLNetworkTimeBrowserTest::SetUpNetworkTimeInterceptorOnIOThread, | |
| 3021 weak_factory_.GetWeakPtr(), | |
|
meacer
2016/11/04 01:17:26
You can also create the interceptor here, and pass
estark
2016/11/04 20:43:30
Hmm, not sure if you were making a suggestion here
meacer
2016/11/04 22:23:00
I started with a suggestion then realized it would
| |
| 3022 g_browser_process->network_time_tracker() | |
| 3023 ->GetTimeServerURLForTesting())); | |
| 3024 } | |
| 3025 | |
| 3026 void TriggerTimeResponse(const base::Closure& callback) { | |
|
meacer
2016/11/04 19:21:07
Since |callback| is always a quit closure, you mig
estark
2016/11/04 20:43:30
Done.
| |
| 3027 content::BrowserThread::PostTask( | |
| 3028 content::BrowserThread::IO, FROM_HERE, | |
| 3029 base::Bind(&SSLNetworkTimeBrowserTest::ResumeDelayedNetworkTimeRequests, | |
| 3030 weak_factory_.GetWeakPtr(), callback)); | |
| 3031 } | |
| 3032 | |
| 3033 private: | |
| 3034 void SetUpNetworkTimeInterceptorOnIOThread(const GURL& time_server_url) { | |
| 3035 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 3036 interceptor_ = new DelayedNetworkTimeInterceptor(); | |
| 3037 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | |
| 3038 time_server_url.scheme(), time_server_url.host(), | |
| 3039 std::unique_ptr<DelayedNetworkTimeInterceptor>(interceptor_)); | |
| 3040 } | |
| 3041 | |
| 3042 void ResumeDelayedNetworkTimeRequests(const base::Closure& callback) { | |
| 3043 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 3044 interceptor_->ResumeAll(callback); | |
| 3045 } | |
| 3046 | |
| 3047 std::unique_ptr<network_time::FieldTrialTest> field_trial_test_; | |
| 3048 | |
| 3049 // Should only be accessed on the IO thread. | |
| 3050 DelayedNetworkTimeInterceptor* interceptor_; | |
| 3051 | |
| 3052 base::WeakPtrFactory<SSLNetworkTimeBrowserTest> weak_factory_; | |
|
meacer
2016/11/04 19:21:07
I don't think this is necessary as the fixture wil
estark
2016/11/04 20:43:30
Done.
| |
| 3053 | |
| 3054 DISALLOW_COPY_AND_ASSIGN(SSLNetworkTimeBrowserTest); | |
| 3055 }; | |
| 3056 | |
| 3057 // Tests that if an on-demand network time fetch returns that the clock | |
| 3058 // is okay, a normal SSL interstitial is shown. | |
| 3059 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, OnDemandFetchClockOk) { | |
| 3060 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3061 SetUpNetworkTimeServer(); | |
| 3062 // Use a testing clock set to the time that GoodTimeResponseHandler | |
| 3063 // returns, to simulate the system clock matching the network time. | |
| 3064 base::SimpleTestClock testing_clock; | |
| 3065 SSLErrorHandler::SetClockForTest(&testing_clock); | |
| 3066 testing_clock.SetNow( | |
| 3067 base::Time::FromJsTime(network_time::kGoodTimeResponseHandlerJsTime)); | |
| 3068 // Set the build time to match the testing clock, to ensure that the | |
| 3069 // build time heuristic doesn't fire. | |
| 3070 ssl_errors::SetBuildTimeForTesting(testing_clock.Now()); | |
| 3071 | |
| 3072 // Set a long timeout to ensure that the on-demand time fetch completes. | |
| 3073 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3074 | |
| 3075 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3076 ASSERT_TRUE(contents); | |
| 3077 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3078 | |
| 3079 content::WindowedNotificationObserver observer( | |
| 3080 content::NOTIFICATION_LOAD_STOP, | |
| 3081 content::NotificationService::AllSources()); | |
| 3082 ui_test_utils::NavigateToURLWithDisposition( | |
| 3083 browser(), https_server_expired_.GetURL("/"), | |
| 3084 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3085 | |
| 3086 // Once |interstitial_timer_observer| has fired, the request has been | |
| 3087 // sent. Override the nonce that NetworkTimeTracker expects so that | |
| 3088 // when the response comes back, it will validate. The nonce can only | |
| 3089 // be overriden for the current in-flight request, so the test must | |
| 3090 // call OverrideNonceForTesting() after the request has been sent and | |
| 3091 // before the response has been received. | |
| 3092 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3093 g_browser_process->network_time_tracker()->OverrideNonceForTesting(123123123); | |
| 3094 base::RunLoop wait_for_time_response; | |
| 3095 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3096 | |
| 3097 EXPECT_TRUE(contents->IsLoading()); | |
| 3098 observer.Wait(); | |
| 3099 content::WaitForInterstitialAttach(contents); | |
| 3100 wait_for_time_response.Run(); | |
| 3101 | |
| 3102 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 3103 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | |
| 3104 ASSERT_TRUE(interstitial_page); | |
| 3105 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | |
| 3106 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 3107 } | |
| 3108 | |
| 3109 // Tests that if an on-demand network time fetch returns that the clock | |
| 3110 // is wrong, a bad clock interstitial is shown. | |
| 3111 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, OnDemandFetchClockWrong) { | |
| 3112 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3113 SetUpNetworkTimeServer(); | |
| 3114 // Use a testing clock set to a time that is different from what | |
| 3115 // GoodTimeResponseHandler returns, simulating a system clock that is | |
| 3116 // 30 days ahead of the network time. | |
| 3117 base::SimpleTestClock testing_clock; | |
| 3118 SSLErrorHandler::SetClockForTest(&testing_clock); | |
| 3119 testing_clock.SetNow( | |
| 3120 base::Time::FromJsTime(network_time::kGoodTimeResponseHandlerJsTime)); | |
| 3121 testing_clock.Advance(base::TimeDelta::FromDays(30)); | |
| 3122 // Set the build time to match the testing clock, to ensure that the | |
| 3123 // build time heuristic doesn't fire. | |
| 3124 ssl_errors::SetBuildTimeForTesting(testing_clock.Now()); | |
| 3125 | |
| 3126 // Set a long timeout to ensure that the on-demand time fetch completes. | |
| 3127 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3128 | |
| 3129 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3130 ASSERT_TRUE(contents); | |
| 3131 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3132 | |
| 3133 content::WindowedNotificationObserver observer( | |
| 3134 content::NOTIFICATION_LOAD_STOP, | |
| 3135 content::NotificationService::AllSources()); | |
| 3136 | |
| 3137 ui_test_utils::NavigateToURLWithDisposition( | |
| 3138 browser(), https_server_expired_.GetURL("/"), | |
| 3139 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3140 | |
| 3141 // Once |interstitial_timer_observer| has fired, the request has been | |
| 3142 // sent. Override the nonce that NetworkTimeTracker expects so that | |
| 3143 // when the response comes back, it will validate. The nonce can only | |
| 3144 // be overriden for the current in-flight request, so the test must | |
| 3145 // call OverrideNonceForTesting() after the request has been sent and | |
| 3146 // before the response has been received. | |
| 3147 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3148 g_browser_process->network_time_tracker()->OverrideNonceForTesting(123123123); | |
| 3149 base::RunLoop wait_for_time_response; | |
| 3150 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3151 | |
| 3152 EXPECT_TRUE(contents->IsLoading()); | |
| 3153 observer.Wait(); | |
| 3154 content::WaitForInterstitialAttach(contents); | |
| 3155 wait_for_time_response.Run(); | |
| 3156 | |
| 3157 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 3158 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | |
| 3159 ASSERT_TRUE(interstitial_page); | |
| 3160 ASSERT_EQ(BadClockBlockingPage::kTypeForTesting, | |
| 3161 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 3162 } | |
| 3163 | |
| 3164 // Tests that if the timeout expires before the network time fetch | |
| 3165 // returns, then a normal SSL intersitial is shown. | |
| 3166 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, | |
| 3167 TimeoutExpiresBeforeFetchCompletes) { | |
| 3168 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3169 SetUpNetworkTimeServer(); | |
| 3170 // Set the timer to fire immediately. | |
| 3171 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta()); | |
| 3172 | |
| 3173 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); | |
| 3174 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3175 ASSERT_TRUE(contents); | |
| 3176 content::WaitForInterstitialAttach(contents); | |
| 3177 | |
| 3178 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 3179 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | |
| 3180 ASSERT_TRUE(interstitial_page); | |
| 3181 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | |
| 3182 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 3183 | |
| 3184 // Navigate away, and then trigger the network time response and wait | |
| 3185 // for the response; no crash should occur. | |
| 3186 ASSERT_TRUE(https_server_.Start()); | |
| 3187 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/")); | |
| 3188 base::RunLoop wait_for_time_response; | |
| 3189 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3190 wait_for_time_response.Run(); | |
| 3191 } | |
| 3192 | |
| 3193 // Tests that if the user stops the page load before either the network | |
| 3194 // time fetch completes or the timeout expires, then there is no interstitial. | |
| 3195 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, StopBeforeTimeoutExpires) { | |
| 3196 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3197 SetUpNetworkTimeServer(); | |
| 3198 // Set the timer to a long delay. | |
| 3199 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3200 | |
| 3201 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3202 ASSERT_TRUE(contents); | |
| 3203 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3204 | |
| 3205 ui_test_utils::NavigateToURLWithDisposition( | |
| 3206 browser(), https_server_expired_.GetURL("/"), | |
| 3207 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3208 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3209 | |
| 3210 EXPECT_TRUE(contents->IsLoading()); | |
| 3211 content::WindowedNotificationObserver observer( | |
| 3212 content::NOTIFICATION_LOAD_STOP, | |
| 3213 content::NotificationService::AllSources()); | |
| 3214 contents->Stop(); | |
| 3215 observer.Wait(); | |
| 3216 | |
| 3217 // Make sure that the |SSLErrorHandler| is deleted. | |
| 3218 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents)); | |
| 3219 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 3220 EXPECT_FALSE(contents->IsLoading()); | |
| 3221 | |
| 3222 // Navigate away, and then trigger the network time response and wait | |
| 3223 // for the response; no crash should occur. | |
| 3224 ASSERT_TRUE(https_server_.Start()); | |
| 3225 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html")); | |
| 3226 base::RunLoop wait_for_time_response; | |
| 3227 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3228 wait_for_time_response.Run(); | |
| 3229 } | |
| 3230 | |
| 3231 // Tests that if the user reloads the page before either the network | |
| 3232 // time fetch completes or the timeout expires, then there is no interstitial. | |
| 3233 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, ReloadBeforeTimeoutExpires) { | |
| 3234 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3235 SetUpNetworkTimeServer(); | |
| 3236 // Set the timer to a long delay. | |
| 3237 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3238 | |
| 3239 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3240 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3241 | |
| 3242 ui_test_utils::NavigateToURLWithDisposition( | |
| 3243 browser(), https_server_expired_.GetURL("/"), | |
| 3244 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3245 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3246 | |
| 3247 EXPECT_TRUE(contents->IsLoading()); | |
| 3248 content::TestNavigationObserver observer(contents, 1); | |
| 3249 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | |
| 3250 observer.Wait(); | |
| 3251 | |
| 3252 // Make sure that the |SSLErrorHandler| is deleted. | |
| 3253 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents)); | |
| 3254 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 3255 EXPECT_FALSE(contents->IsLoading()); | |
| 3256 | |
| 3257 // Navigate away, and then trigger the network time response and wait | |
| 3258 // for the response; no crash should occur. | |
| 3259 ASSERT_TRUE(https_server_.Start()); | |
| 3260 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/")); | |
| 3261 base::RunLoop wait_for_time_response; | |
| 3262 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3263 wait_for_time_response.Run(); | |
| 3264 } | |
| 3265 | |
| 3266 // Tests that if the user navigates away before either the network time | |
| 3267 // fetch completes or the timeout expires, then there is no | |
| 3268 // interstitial. | |
| 3269 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, | |
| 3270 NavigateAwayBeforeTimeoutExpires) { | |
| 3271 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3272 ASSERT_TRUE(https_server_.Start()); | |
| 3273 SetUpNetworkTimeServer(); | |
| 3274 // Set the timer to a long delay. | |
| 3275 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1)); | |
| 3276 | |
| 3277 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3278 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 3279 | |
| 3280 ui_test_utils::NavigateToURLWithDisposition( | |
| 3281 browser(), https_server_expired_.GetURL("/"), | |
| 3282 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | |
| 3283 interstitial_timer_observer.WaitForTimerStarted(); | |
| 3284 | |
| 3285 EXPECT_TRUE(contents->IsLoading()); | |
| 3286 content::TestNavigationObserver observer(contents, 1); | |
| 3287 browser()->OpenURL(content::OpenURLParams( | |
| 3288 https_server_.GetURL("/"), content::Referrer(), | |
| 3289 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); | |
| 3290 observer.Wait(); | |
| 3291 | |
| 3292 // Make sure that the |SSLErrorHandler| is deleted. | |
| 3293 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents)); | |
| 3294 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 3295 EXPECT_FALSE(contents->IsLoading()); | |
| 3296 | |
| 3297 // Navigate away, and then trigger the network time response and wait | |
| 3298 // for the response; no crash should occur. | |
| 3299 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/")); | |
| 3300 base::RunLoop wait_for_time_response; | |
| 3301 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3302 wait_for_time_response.Run(); | |
| 3303 } | |
| 3304 | |
| 3305 // Tests that if the user closes the tab before the network time fetch | |
| 3306 // completes, it doesn't cause a crash. | |
| 3307 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, | |
| 3308 CloseTabBeforeNetworkFetchCompletes) { | |
| 3309 ASSERT_TRUE(https_server_expired_.Start()); | |
| 3310 SetUpNetworkTimeServer(); | |
| 3311 // Set the timer to fire immediately. | |
| 3312 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta()); | |
| 3313 | |
| 3314 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); | |
| 3315 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 3316 ASSERT_TRUE(contents); | |
| 3317 content::WaitForInterstitialAttach(contents); | |
| 3318 | |
| 3319 EXPECT_TRUE(contents->ShowingInterstitialPage()); | |
| 3320 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | |
| 3321 ASSERT_TRUE(interstitial_page); | |
| 3322 ASSERT_EQ(SSLBlockingPage::kTypeForTesting, | |
| 3323 interstitial_page->GetDelegateForTesting()->GetTypeForTesting()); | |
| 3324 | |
| 3325 // Open a second tab, close the first, and then trigger the network time | |
| 3326 // response and wait for the response; no crash should occur. | |
| 3327 ASSERT_TRUE(https_server_.Start()); | |
| 3328 AddTabAtIndex(1, https_server_.GetURL("/"), ui::PAGE_TRANSITION_TYPED); | |
| 3329 chrome::CloseWebContents(browser(), contents, false); | |
| 3330 base::RunLoop wait_for_time_response; | |
| 3331 TriggerTimeResponse(wait_for_time_response.QuitClosure()); | |
| 3332 wait_for_time_response.Run(); | |
| 3333 } | |
| 3334 | |
| 2856 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest { | 3335 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest { |
| 2857 public: | 3336 public: |
| 2858 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {} | 3337 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {} |
| 2859 ~CommonNameMismatchBrowserTest() override {} | 3338 ~CommonNameMismatchBrowserTest() override {} |
| 2860 | 3339 |
| 2861 void SetUpCommandLine(base::CommandLine* command_line) override { | 3340 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 2862 // Enable finch experiment for SSL common name mismatch handling. | 3341 // Enable finch experiment for SSL common name mismatch handling. |
| 2863 command_line->AppendSwitchASCII(switches::kForceFieldTrials, | 3342 command_line->AppendSwitchASCII(switches::kForceFieldTrials, |
| 2864 "SSLCommonNameMismatchHandling/Enabled/"); | 3343 "SSLCommonNameMismatchHandling/Enabled/"); |
| 2865 } | 3344 } |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3410 | 3889 |
| 3411 // Visit a page over https that contains a frame with a redirect. | 3890 // Visit a page over https that contains a frame with a redirect. |
| 3412 | 3891 |
| 3413 // XMLHttpRequest insecure content in synchronous mode. | 3892 // XMLHttpRequest insecure content in synchronous mode. |
| 3414 | 3893 |
| 3415 // XMLHttpRequest insecure content in asynchronous mode. | 3894 // XMLHttpRequest insecure content in asynchronous mode. |
| 3416 | 3895 |
| 3417 // XMLHttpRequest over bad ssl in synchronous mode. | 3896 // XMLHttpRequest over bad ssl in synchronous mode. |
| 3418 | 3897 |
| 3419 // XMLHttpRequest over OK ssl in synchronous mode. | 3898 // XMLHttpRequest over OK ssl in synchronous mode. |
| OLD | NEW |