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 "chrome/browser/safe_browsing/safe_browsing_service.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
22 #include "base/threading/thread_restrictions.h" | 22 #include "base/threading/thread_restrictions.h" |
| 23 #include "base/threading/worker_pool.h" |
23 #include "base/trace_event/trace_event.h" | 24 #include "base/trace_event/trace_event.h" |
24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
25 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
26 #include "chrome/browser/chrome_notification_types.h" | 27 #include "chrome/browser/chrome_notification_types.h" |
27 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 28 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/browser/profiles/profile_manager.h" | 30 #include "chrome/browser/profiles/profile_manager.h" |
30 #include "chrome/browser/safe_browsing/ping_manager.h" | 31 #include "chrome/browser/safe_browsing/ping_manager.h" |
31 #include "chrome/browser/safe_browsing/ui_manager.h" | 32 #include "chrome/browser/safe_browsing/ui_manager.h" |
32 #include "chrome/common/chrome_constants.h" | 33 #include "chrome/common/chrome_constants.h" |
33 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
34 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
35 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
36 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
37 #include "components/prefs/pref_change_registrar.h" | 38 #include "components/prefs/pref_change_registrar.h" |
38 #include "components/prefs/pref_service.h" | 39 #include "components/prefs/pref_service.h" |
39 #include "components/safe_browsing_db/database_manager.h" | 40 #include "components/safe_browsing_db/database_manager.h" |
40 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | 41 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
41 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h
" | 42 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h
" |
42 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
43 #include "content/public/browser/cookie_store_factory.h" | 44 #include "content/public/browser/cookie_store_factory.h" |
44 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
45 #include "content/public/browser/resource_request_info.h" | 46 #include "content/public/browser/resource_request_info.h" |
46 #include "google_apis/google_api_keys.h" | 47 #include "google_apis/google_api_keys.h" |
47 #include "net/cookies/cookie_store.h" | 48 #include "net/cookies/cookie_store.h" |
48 #include "net/extras/sqlite/cookie_crypto_delegate.h" | 49 #include "net/extras/sqlite/cookie_crypto_delegate.h" |
| 50 #include "net/extras/sqlite/sqlite_channel_id_store.h" |
| 51 #include "net/http/http_network_layer.h" |
| 52 #include "net/http/http_transaction_factory.h" |
| 53 #include "net/ssl/channel_id_service.h" |
| 54 #include "net/ssl/default_channel_id_store.h" |
49 #include "net/url_request/url_request_context.h" | 55 #include "net/url_request/url_request_context.h" |
50 #include "net/url_request/url_request_context_getter.h" | 56 #include "net/url_request/url_request_context_getter.h" |
51 | 57 |
52 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
53 #include "chrome/installer/util/browser_distribution.h" | 59 #include "chrome/installer/util/browser_distribution.h" |
54 #endif | 60 #endif |
55 | 61 |
56 #if defined(SAFE_BROWSING_DB_LOCAL) | 62 #if defined(SAFE_BROWSING_DB_LOCAL) |
57 #include "chrome/browser/safe_browsing/local_database_manager.h" | 63 #include "chrome/browser/safe_browsing/local_database_manager.h" |
58 #elif defined(SAFE_BROWSING_DB_REMOTE) | 64 #elif defined(SAFE_BROWSING_DB_REMOTE) |
(...skipping 14 matching lines...) Expand all Loading... |
73 #endif | 79 #endif |
74 | 80 |
75 using content::BrowserThread; | 81 using content::BrowserThread; |
76 | 82 |
77 namespace safe_browsing { | 83 namespace safe_browsing { |
78 | 84 |
79 namespace { | 85 namespace { |
80 | 86 |
81 // Filename suffix for the cookie database. | 87 // Filename suffix for the cookie database. |
82 const base::FilePath::CharType kCookiesFile[] = FILE_PATH_LITERAL(" Cookies"); | 88 const base::FilePath::CharType kCookiesFile[] = FILE_PATH_LITERAL(" Cookies"); |
| 89 const base::FilePath::CharType kChannelIDFile[] = |
| 90 FILE_PATH_LITERAL(" Channel IDs"); |
83 | 91 |
84 // The default URL prefix where browser fetches chunk updates, hashes, | 92 // The default URL prefix where browser fetches chunk updates, hashes, |
85 // and reports safe browsing hits and malware details. | 93 // and reports safe browsing hits and malware details. |
86 const char kSbDefaultURLPrefix[] = | 94 const char kSbDefaultURLPrefix[] = |
87 "https://safebrowsing.google.com/safebrowsing"; | 95 "https://safebrowsing.google.com/safebrowsing"; |
88 | 96 |
89 // The backup URL prefix used when there are issues establishing a connection | 97 // The backup URL prefix used when there are issues establishing a connection |
90 // with the server at the primary URL. | 98 // with the server at the primary URL. |
91 const char kSbBackupConnectErrorURLPrefix[] = | 99 const char kSbBackupConnectErrorURLPrefix[] = |
92 "https://alt1-safebrowsing.google.com/safebrowsing"; | 100 "https://alt1-safebrowsing.google.com/safebrowsing"; |
93 | 101 |
94 // The backup URL prefix used when there are HTTP-specific issues with the | 102 // The backup URL prefix used when there are HTTP-specific issues with the |
95 // server at the primary URL. | 103 // server at the primary URL. |
96 const char kSbBackupHttpErrorURLPrefix[] = | 104 const char kSbBackupHttpErrorURLPrefix[] = |
97 "https://alt2-safebrowsing.google.com/safebrowsing"; | 105 "https://alt2-safebrowsing.google.com/safebrowsing"; |
98 | 106 |
99 // The backup URL prefix used when there are local network specific issues. | 107 // The backup URL prefix used when there are local network specific issues. |
100 const char kSbBackupNetworkErrorURLPrefix[] = | 108 const char kSbBackupNetworkErrorURLPrefix[] = |
101 "https://alt3-safebrowsing.google.com/safebrowsing"; | 109 "https://alt3-safebrowsing.google.com/safebrowsing"; |
102 | 110 |
103 base::FilePath CookieFilePath() { | 111 base::FilePath CookieFilePath() { |
104 return base::FilePath( | 112 return base::FilePath( |
105 SafeBrowsingService::GetBaseFilename().value() + kCookiesFile); | 113 SafeBrowsingService::GetBaseFilename().value() + kCookiesFile); |
106 } | 114 } |
107 | 115 |
| 116 base::FilePath ChannelIDFilePath() { |
| 117 return base::FilePath(SafeBrowsingService::GetBaseFilename().value() + |
| 118 kChannelIDFile); |
| 119 } |
| 120 |
108 } // namespace | 121 } // namespace |
109 | 122 |
110 class SafeBrowsingURLRequestContextGetter | 123 class SafeBrowsingURLRequestContextGetter |
111 : public net::URLRequestContextGetter { | 124 : public net::URLRequestContextGetter { |
112 public: | 125 public: |
113 explicit SafeBrowsingURLRequestContextGetter( | 126 explicit SafeBrowsingURLRequestContextGetter( |
114 scoped_refptr<net::URLRequestContextGetter> system_context_getter); | 127 scoped_refptr<net::URLRequestContextGetter> system_context_getter); |
115 | 128 |
116 // Implementation for net::UrlRequestContextGetter. | 129 // Implementation for net::UrlRequestContextGetter. |
117 net::URLRequestContext* GetURLRequestContext() override; | 130 net::URLRequestContext* GetURLRequestContext() override; |
(...skipping 10 matching lines...) Expand all Loading... |
128 private: | 141 private: |
129 bool shut_down_; | 142 bool shut_down_; |
130 | 143 |
131 scoped_refptr<net::URLRequestContextGetter> system_context_getter_; | 144 scoped_refptr<net::URLRequestContextGetter> system_context_getter_; |
132 | 145 |
133 std::unique_ptr<net::CookieStore> safe_browsing_cookie_store_; | 146 std::unique_ptr<net::CookieStore> safe_browsing_cookie_store_; |
134 | 147 |
135 std::unique_ptr<net::URLRequestContext> safe_browsing_request_context_; | 148 std::unique_ptr<net::URLRequestContext> safe_browsing_request_context_; |
136 | 149 |
137 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 150 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| 151 |
| 152 std::unique_ptr<net::ChannelIDService> channel_id_service_; |
| 153 std::unique_ptr<net::HttpNetworkSession> http_network_session_; |
| 154 std::unique_ptr<net::HttpTransactionFactory> http_transaction_factory_; |
138 }; | 155 }; |
139 | 156 |
140 SafeBrowsingURLRequestContextGetter::SafeBrowsingURLRequestContextGetter( | 157 SafeBrowsingURLRequestContextGetter::SafeBrowsingURLRequestContextGetter( |
141 scoped_refptr<net::URLRequestContextGetter> system_context_getter) | 158 scoped_refptr<net::URLRequestContextGetter> system_context_getter) |
142 : shut_down_(false), | 159 : shut_down_(false), |
143 system_context_getter_(system_context_getter), | 160 system_context_getter_(system_context_getter), |
144 network_task_runner_( | 161 network_task_runner_( |
145 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) {} | 162 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) {} |
146 | 163 |
147 net::URLRequestContext* | 164 net::URLRequestContext* |
(...skipping 11 matching lines...) Expand all Loading... |
159 safe_browsing_request_context_->CopyFrom( | 176 safe_browsing_request_context_->CopyFrom( |
160 system_context_getter_->GetURLRequestContext()); | 177 system_context_getter_->GetURLRequestContext()); |
161 } | 178 } |
162 safe_browsing_cookie_store_ = | 179 safe_browsing_cookie_store_ = |
163 content::CreateCookieStore(content::CookieStoreConfig( | 180 content::CreateCookieStore(content::CookieStoreConfig( |
164 CookieFilePath(), | 181 CookieFilePath(), |
165 content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, nullptr, | 182 content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, nullptr, |
166 nullptr)); | 183 nullptr)); |
167 safe_browsing_request_context_->set_cookie_store( | 184 safe_browsing_request_context_->set_cookie_store( |
168 safe_browsing_cookie_store_.get()); | 185 safe_browsing_cookie_store_.get()); |
169 // The above cookie store will persist cookies, but the ChannelIDService in | 186 |
170 // the system request context is ephemeral, which could lead to losing the | 187 // Set up the ChannelIDService |
171 // keys that cookies are bound to. Since this is only used for safe | 188 scoped_refptr<net::SQLiteChannelIDStore> channel_id_db = |
172 // browsing, any cookie bindings don't matter. | 189 new net::SQLiteChannelIDStore( |
173 // | 190 ChannelIDFilePath(), |
174 // For crbug.com/548423, the channel ID store and cookie store used for a | 191 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( |
175 // request are being tracked to see if an ephemeral channel ID store is used | 192 base::SequencedWorkerPool::GetSequenceToken())); |
176 // with a persistent cookie store (which apart from here would be a bug). | 193 channel_id_service_.reset(new net::ChannelIDService( |
177 // The following line tells that tracking to ignore the mismatch from this | 194 new net::DefaultChannelIDStore(channel_id_db.get()), |
178 // URLRequestContext. | 195 base::WorkerPool::GetTaskRunner(true))); |
179 safe_browsing_request_context_->set_has_known_mismatched_cookie_store(); | 196 safe_browsing_request_context_->set_channel_id_service( |
| 197 channel_id_service_.get()); |
| 198 |
| 199 // Rebuild the HttpNetworkSession and the HttpTransactionFactory to use the |
| 200 // new ChannelIDService. |
| 201 if (safe_browsing_request_context_->http_transaction_factory() && |
| 202 safe_browsing_request_context_->http_transaction_factory() |
| 203 ->GetSession()) { |
| 204 net::HttpNetworkSession::Params safe_browsing_params = |
| 205 safe_browsing_request_context_->http_transaction_factory() |
| 206 ->GetSession() |
| 207 ->params(); |
| 208 safe_browsing_params.channel_id_service = channel_id_service_.get(); |
| 209 http_network_session_.reset( |
| 210 new net::HttpNetworkSession(safe_browsing_params)); |
| 211 http_transaction_factory_.reset( |
| 212 new net::HttpNetworkLayer(http_network_session_.get())); |
| 213 safe_browsing_request_context_->set_http_transaction_factory( |
| 214 http_transaction_factory_.get()); |
| 215 } |
180 } | 216 } |
181 | 217 |
182 return safe_browsing_request_context_.get(); | 218 return safe_browsing_request_context_.get(); |
183 } | 219 } |
184 | 220 |
185 scoped_refptr<base::SingleThreadTaskRunner> | 221 scoped_refptr<base::SingleThreadTaskRunner> |
186 SafeBrowsingURLRequestContextGetter::GetNetworkTaskRunner() const { | 222 SafeBrowsingURLRequestContextGetter::GetNetworkTaskRunner() const { |
187 return network_task_runner_; | 223 return network_task_runner_; |
188 } | 224 } |
189 | 225 |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 ping_manager()->ReportThreatDetails(report); | 686 ping_manager()->ReportThreatDetails(report); |
651 } | 687 } |
652 | 688 |
653 void SafeBrowsingService::ProcessResourceRequest( | 689 void SafeBrowsingService::ProcessResourceRequest( |
654 const ResourceRequestInfo& request) { | 690 const ResourceRequestInfo& request) { |
655 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 691 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
656 services_delegate_->ProcessResourceRequest(&request); | 692 services_delegate_->ProcessResourceRequest(&request); |
657 } | 693 } |
658 | 694 |
659 } // namespace safe_browsing | 695 } // namespace safe_browsing |
OLD | NEW |