OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/location.h" | 17 #include "base/location.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/ref_counted.h" |
19 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
20 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
22 #include "base/sys_info.h" | 23 #include "base/sys_info.h" |
| 24 #include "base/threading/sequenced_worker_pool.h" |
23 #include "build/build_config.h" | 25 #include "build/build_config.h" |
24 #include "chrome/app/chrome_command_ids.h" | 26 #include "chrome/app/chrome_command_ids.h" |
25 #include "chrome/browser/chrome_content_browser_client.h" | 27 #include "chrome/browser/chrome_content_browser_client.h" |
26 #include "chrome/browser/chrome_notification_types.h" | 28 #include "chrome/browser/chrome_notification_types.h" |
27 #include "chrome/browser/command_updater.h" | 29 #include "chrome/browser/command_updater.h" |
28 #include "chrome/browser/defaults.h" | 30 #include "chrome/browser/defaults.h" |
29 #include "chrome/browser/devtools/devtools_window_testing.h" | 31 #include "chrome/browser/devtools/devtools_window_testing.h" |
30 #include "chrome/browser/extensions/extension_browsertest.h" | 32 #include "chrome/browser/extensions/extension_browsertest.h" |
31 #include "chrome/browser/extensions/extension_service.h" | 33 #include "chrome/browser/extensions/extension_service.h" |
32 #include "chrome/browser/extensions/extension_util.h" | 34 #include "chrome/browser/extensions/extension_util.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 #include "content/public/common/url_constants.h" | 100 #include "content/public/common/url_constants.h" |
99 #include "content/public/test/browser_test_utils.h" | 101 #include "content/public/test/browser_test_utils.h" |
100 #include "content/public/test/test_navigation_observer.h" | 102 #include "content/public/test/test_navigation_observer.h" |
101 #include "extensions/browser/extension_registry.h" | 103 #include "extensions/browser/extension_registry.h" |
102 #include "extensions/browser/extension_system.h" | 104 #include "extensions/browser/extension_system.h" |
103 #include "extensions/browser/uninstall_reason.h" | 105 #include "extensions/browser/uninstall_reason.h" |
104 #include "extensions/common/constants.h" | 106 #include "extensions/common/constants.h" |
105 #include "extensions/common/extension.h" | 107 #include "extensions/common/extension.h" |
106 #include "extensions/common/extension_set.h" | 108 #include "extensions/common/extension_set.h" |
107 #include "net/base/net_errors.h" | 109 #include "net/base/net_errors.h" |
| 110 #include "net/base/test_data_directory.h" |
| 111 #include "net/cert/x509_certificate.h" |
108 #include "net/dns/mock_host_resolver.h" | 112 #include "net/dns/mock_host_resolver.h" |
| 113 #include "net/ssl/ssl_cipher_suite_names.h" |
| 114 #include "net/ssl/ssl_connection_status_flags.h" |
| 115 #include "net/test/cert_test_util.h" |
109 #include "net/test/embedded_test_server/embedded_test_server.h" | 116 #include "net/test/embedded_test_server/embedded_test_server.h" |
110 #include "net/test/embedded_test_server/request_handler_util.h" | 117 #include "net/test/embedded_test_server/request_handler_util.h" |
111 #include "net/test/spawned_test_server/spawned_test_server.h" | 118 #include "net/test/spawned_test_server/spawned_test_server.h" |
112 #include "net/test/url_request/url_request_mock_http_job.h" | 119 #include "net/test/url_request/url_request_mock_http_job.h" |
113 #include "net/url_request/url_request_filter.h" | 120 #include "net/url_request/url_request_filter.h" |
114 #include "net/url_request/url_request_test_util.h" | 121 #include "net/url_request/url_request_test_util.h" |
115 #include "ui/base/l10n/l10n_util.h" | 122 #include "ui/base/l10n/l10n_util.h" |
116 #include "ui/base/page_transition_types.h" | 123 #include "ui/base/page_transition_types.h" |
117 | 124 |
118 #if defined(OS_MACOSX) | 125 #if defined(OS_MACOSX) |
(...skipping 2938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3057 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size()); | 3064 EXPECT_EQ(0u, observer.latest_explanations().broken_explanations.size()); |
3058 CheckSecureExplanations(observer.latest_explanations().secure_explanations, | 3065 CheckSecureExplanations(observer.latest_explanations().secure_explanations, |
3059 VALID_CERTIFICATE, browser()); | 3066 VALID_CERTIFICATE, browser()); |
3060 EXPECT_TRUE(observer.latest_explanations().scheme_is_cryptographic); | 3067 EXPECT_TRUE(observer.latest_explanations().scheme_is_cryptographic); |
3061 EXPECT_FALSE(observer.latest_explanations().displayed_insecure_content); | 3068 EXPECT_FALSE(observer.latest_explanations().displayed_insecure_content); |
3062 EXPECT_FALSE(observer.latest_explanations().ran_insecure_content); | 3069 EXPECT_FALSE(observer.latest_explanations().ran_insecure_content); |
3063 } | 3070 } |
3064 | 3071 |
3065 namespace { | 3072 namespace { |
3066 | 3073 |
| 3074 // After AddNonsecureUrlHandler() is called, requests to this hostname |
| 3075 // will use obsolete TLS settings. |
| 3076 const char kMockNonsecureHostname[] = "example-nonsecure.test"; |
| 3077 |
| 3078 // A URLRequestMockHTTPJob that mocks a TLS connection with an obsolete |
| 3079 // protocol version. |
| 3080 class URLRequestObsoleteTLSJob : public net::URLRequestMockHTTPJob { |
| 3081 public: |
| 3082 URLRequestObsoleteTLSJob(net::URLRequest* request, |
| 3083 net::NetworkDelegate* network_delegate, |
| 3084 const base::FilePath& file_path, |
| 3085 scoped_refptr<net::X509Certificate> cert, |
| 3086 scoped_refptr<base::TaskRunner> task_runner) |
| 3087 : net::URLRequestMockHTTPJob(request, |
| 3088 network_delegate, |
| 3089 file_path, |
| 3090 task_runner), |
| 3091 cert_(std::move(cert)) {} |
| 3092 |
| 3093 void GetResponseInfo(net::HttpResponseInfo* info) override { |
| 3094 net::URLRequestMockHTTPJob::GetResponseInfo(info); |
| 3095 net::SSLConnectionStatusSetVersion(net::SSL_CONNECTION_VERSION_TLS1_1, |
| 3096 &info->ssl_info.connection_status); |
| 3097 const uint16_t kTlsEcdheRsaWithAes128CbcSha = 0xc013; |
| 3098 net::SSLConnectionStatusSetCipherSuite(kTlsEcdheRsaWithAes128CbcSha, |
| 3099 &info->ssl_info.connection_status); |
| 3100 info->ssl_info.cert = cert_; |
| 3101 } |
| 3102 |
| 3103 protected: |
| 3104 ~URLRequestObsoleteTLSJob() override {} |
| 3105 |
| 3106 private: |
| 3107 const scoped_refptr<net::X509Certificate> cert_; |
| 3108 |
| 3109 DISALLOW_COPY_AND_ASSIGN(URLRequestObsoleteTLSJob); |
| 3110 }; |
| 3111 |
| 3112 // A URLRequestInterceptor that handles requests with |
| 3113 // URLRequestObsoleteTLSJob jobs. |
| 3114 class URLRequestNonsecureInterceptor : public net::URLRequestInterceptor { |
| 3115 public: |
| 3116 URLRequestNonsecureInterceptor( |
| 3117 const base::FilePath& base_path, |
| 3118 scoped_refptr<base::SequencedWorkerPool> worker_pool, |
| 3119 scoped_refptr<net::X509Certificate> cert) |
| 3120 : base_path_(base_path), |
| 3121 worker_pool_(std::move(worker_pool)), |
| 3122 cert_(std::move(cert)) {} |
| 3123 |
| 3124 ~URLRequestNonsecureInterceptor() override {} |
| 3125 |
| 3126 // net::URLRequestInterceptor: |
| 3127 net::URLRequestJob* MaybeInterceptRequest( |
| 3128 net::URLRequest* request, |
| 3129 net::NetworkDelegate* network_delegate) const override { |
| 3130 return new URLRequestObsoleteTLSJob( |
| 3131 request, network_delegate, base_path_, cert_, |
| 3132 worker_pool_->GetTaskRunnerWithShutdownBehavior( |
| 3133 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 3134 } |
| 3135 |
| 3136 private: |
| 3137 const base::FilePath base_path_; |
| 3138 const scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
| 3139 const scoped_refptr<net::X509Certificate> cert_; |
| 3140 |
| 3141 DISALLOW_COPY_AND_ASSIGN(URLRequestNonsecureInterceptor); |
| 3142 }; |
| 3143 |
| 3144 // Installs a handler to serve HTTPS requests to |
| 3145 // |kMockNonsecureHostname| with connections that have obsolete TLS |
| 3146 // settings. |
| 3147 void AddNonsecureUrlHandler( |
| 3148 const base::FilePath& base_path, |
| 3149 scoped_refptr<net::X509Certificate> cert, |
| 3150 scoped_refptr<base::SequencedWorkerPool> worker_pool) { |
| 3151 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
| 3152 filter->AddHostnameInterceptor( |
| 3153 "https", kMockNonsecureHostname, |
| 3154 std::unique_ptr<net::URLRequestInterceptor>( |
| 3155 new URLRequestNonsecureInterceptor(base_path, worker_pool, cert))); |
| 3156 } |
| 3157 |
3067 class BrowserTestNonsecureURLRequest : public BrowserTest { | 3158 class BrowserTestNonsecureURLRequest : public BrowserTest { |
3068 public: | 3159 public: |
3069 BrowserTestNonsecureURLRequest() : BrowserTest() {} | 3160 BrowserTestNonsecureURLRequest() : BrowserTest(), cert_(nullptr) {} |
| 3161 |
| 3162 void SetUpInProcessBrowserTestFixture() override { |
| 3163 cert_ = |
| 3164 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); |
| 3165 ASSERT_TRUE(cert_); |
| 3166 } |
| 3167 |
3070 void SetUpOnMainThread() override { | 3168 void SetUpOnMainThread() override { |
3071 base::FilePath root_http; | 3169 base::FilePath serve_file; |
3072 PathService::Get(chrome::DIR_TEST_DATA, &root_http); | 3170 PathService::Get(chrome::DIR_TEST_DATA, &serve_file); |
| 3171 serve_file = serve_file.Append(FILE_PATH_LITERAL("title1.html")); |
3073 content::BrowserThread::PostTask( | 3172 content::BrowserThread::PostTask( |
3074 content::BrowserThread::IO, FROM_HERE, | 3173 content::BrowserThread::IO, FROM_HERE, |
3075 base::Bind( | 3174 base::Bind( |
3076 &net::URLRequestMockHTTPJob::AddUrlHandlers, root_http, | 3175 &AddNonsecureUrlHandler, serve_file, cert_, |
3077 make_scoped_refptr(content::BrowserThread::GetBlockingPool()))); | 3176 make_scoped_refptr(content::BrowserThread::GetBlockingPool()))); |
3078 } | 3177 } |
3079 | 3178 |
3080 private: | 3179 private: |
| 3180 scoped_refptr<net::X509Certificate> cert_; |
| 3181 |
3081 DISALLOW_COPY_AND_ASSIGN(BrowserTestNonsecureURLRequest); | 3182 DISALLOW_COPY_AND_ASSIGN(BrowserTestNonsecureURLRequest); |
3082 }; | 3183 }; |
3083 | 3184 |
3084 } // namespace | 3185 } // namespace |
3085 | 3186 |
3086 // Tests that a nonsecure connection does not get a secure connection | 3187 // Tests that a connection with obsolete TLS settings does not get a |
3087 // explanation. | 3188 // secure connection explanation. |
3088 IN_PROC_BROWSER_TEST_F(BrowserTestNonsecureURLRequest, | 3189 IN_PROC_BROWSER_TEST_F(BrowserTestNonsecureURLRequest, |
3089 SecurityStyleChangedObserverNonsecureConnection) { | 3190 SecurityStyleChangedObserverNonsecureConnection) { |
3090 content::WebContents* web_contents = | 3191 content::WebContents* web_contents = |
3091 browser()->tab_strip_model()->GetActiveWebContents(); | 3192 browser()->tab_strip_model()->GetActiveWebContents(); |
3092 SecurityStyleTestObserver observer(web_contents); | 3193 SecurityStyleTestObserver observer(web_contents); |
3093 | 3194 |
3094 ui_test_utils::NavigateToURL( | 3195 ui_test_utils::NavigateToURL( |
3095 browser(), net::URLRequestMockHTTPJob::GetMockHttpsUrl(std::string())); | 3196 browser(), GURL(std::string("https://") + kMockNonsecureHostname)); |
| 3197 |
| 3198 // The security style of the page doesn't get downgraded for obsolete |
| 3199 // TLS settings, so it should remain at SECURITY_STYLE_AUTHENTICATED. |
| 3200 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED, |
| 3201 observer.latest_security_style()); |
| 3202 |
| 3203 // The messages explaining the security style do, however, get |
| 3204 // downgraded: SECURE_PROTOCOL_AND_CIPHERSUITE should not show up when |
| 3205 // the TLS settings are obsolete. |
3096 for (const auto& explanation : | 3206 for (const auto& explanation : |
3097 observer.latest_explanations().secure_explanations) { | 3207 observer.latest_explanations().secure_explanations) { |
3098 EXPECT_NE(l10n_util::GetStringUTF8(IDS_SECURE_PROTOCOL_AND_CIPHERSUITE), | 3208 EXPECT_NE(l10n_util::GetStringUTF8(IDS_SECURE_PROTOCOL_AND_CIPHERSUITE), |
3099 explanation.summary); | 3209 explanation.summary); |
3100 } | 3210 } |
3101 } | 3211 } |
3102 | 3212 |
3103 namespace { | 3213 namespace { |
3104 class JSBooleanResultGetter { | 3214 class JSBooleanResultGetter { |
3105 public: | 3215 public: |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3248 Browser* browser = new Browser(params); | 3358 Browser* browser = new Browser(params); |
3249 gfx::Rect bounds = browser->window()->GetBounds(); | 3359 gfx::Rect bounds = browser->window()->GetBounds(); |
3250 | 3360 |
3251 // Should be EXPECT_EQ, but this width is inconsistent across platforms. | 3361 // Should be EXPECT_EQ, but this width is inconsistent across platforms. |
3252 // See https://crbug.com/567925. | 3362 // See https://crbug.com/567925. |
3253 EXPECT_GE(bounds.width(), 100); | 3363 EXPECT_GE(bounds.width(), 100); |
3254 EXPECT_EQ(122, bounds.height()); | 3364 EXPECT_EQ(122, bounds.height()); |
3255 browser->window()->Close(); | 3365 browser->window()->Close(); |
3256 } | 3366 } |
3257 } | 3367 } |
OLD | NEW |