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