Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: trunk/src/net/base/sdch_manager.cc

Issue 130893005: Revert 243957 "Enable SDCH support over HTTPS if --enable-sdch=2..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/net/base/sdch_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/base/sdch_manager.h" 5 #include "net/base/sdch_manager.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 10 matching lines...) Expand all
21 21
22 // static 22 // static
23 const size_t SdchManager::kMaxDictionaryCount = 20; 23 const size_t SdchManager::kMaxDictionaryCount = 20;
24 24
25 // static 25 // static
26 SdchManager* SdchManager::global_ = NULL; 26 SdchManager* SdchManager::global_ = NULL;
27 27
28 // static 28 // static
29 bool SdchManager::g_sdch_enabled_ = true; 29 bool SdchManager::g_sdch_enabled_ = true;
30 30
31 // static
32 bool SdchManager::g_secure_scheme_supported_ = false;
33
34 //------------------------------------------------------------------------------ 31 //------------------------------------------------------------------------------
35 SdchManager::Dictionary::Dictionary(const std::string& dictionary_text, 32 SdchManager::Dictionary::Dictionary(const std::string& dictionary_text,
36 size_t offset, 33 size_t offset,
37 const std::string& client_hash, 34 const std::string& client_hash,
38 const GURL& gurl, 35 const GURL& gurl,
39 const std::string& domain, 36 const std::string& domain,
40 const std::string& path, 37 const std::string& path,
41 const base::Time& expiration, 38 const base::Time& expiration,
42 const std::set<int>& ports) 39 const std::set<int>& ports)
43 : text_(dictionary_text, offset), 40 : text_(dictionary_text, offset),
(...skipping 15 matching lines...) Expand all
59 Avail-Dictionary header are modeled after the rules for cookie scoping. The 56 Avail-Dictionary header are modeled after the rules for cookie scoping. The
60 terms "domain-match" and "pathmatch" are defined in RFC 2965 [6]. A 57 terms "domain-match" and "pathmatch" are defined in RFC 2965 [6]. A
61 dictionary may be advertised in the Avail-Dictionaries header exactly when 58 dictionary may be advertised in the Avail-Dictionaries header exactly when
62 all of the following are true: 59 all of the following are true:
63 1. The server's effective host name domain-matches the Domain attribute of 60 1. The server's effective host name domain-matches the Domain attribute of
64 the dictionary. 61 the dictionary.
65 2. If the dictionary has a Port attribute, the request port is one of the 62 2. If the dictionary has a Port attribute, the request port is one of the
66 ports listed in the Port attribute. 63 ports listed in the Port attribute.
67 3. The request URI path-matches the path header of the dictionary. 64 3. The request URI path-matches the path header of the dictionary.
68 4. The request is not an HTTPS request. 65 4. The request is not an HTTPS request.
69 We can override (ignore) item (4) only when we have explicitly enabled
70 HTTPS support AND dictionary has been acquired over HTTPS.
71 */ 66 */
72 if (!DomainMatch(target_url, domain_)) 67 if (!DomainMatch(target_url, domain_))
73 return false; 68 return false;
74 if (!ports_.empty() && 0 == ports_.count(target_url.EffectiveIntPort())) 69 if (!ports_.empty() && 0 == ports_.count(target_url.EffectiveIntPort()))
75 return false; 70 return false;
76 if (path_.size() && !PathMatch(target_url.path(), path_)) 71 if (path_.size() && !PathMatch(target_url.path(), path_))
77 return false; 72 return false;
78 if (!SdchManager::secure_scheme_supported() && target_url.SchemeIsSecure()) 73 if (target_url.SchemeIsSecure())
79 return false;
80 if (target_url.SchemeIsSecure() && !url_.SchemeIsSecure())
81 return false; 74 return false;
82 if (base::Time::Now() > expiration_) 75 if (base::Time::Now() > expiration_)
83 return false; 76 return false;
84 return true; 77 return true;
85 } 78 }
86 79
87 //------------------------------------------------------------------------------ 80 //------------------------------------------------------------------------------
88 // Security functions restricting loads and use of dictionaries. 81 // Security functions restricting loads and use of dictionaries.
89 82
90 // static 83 // static
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 bool SdchManager::Dictionary::CanUse(const GURL& referring_url) { 145 bool SdchManager::Dictionary::CanUse(const GURL& referring_url) {
153 if (!SdchManager::Global()->IsInSupportedDomain(referring_url)) 146 if (!SdchManager::Global()->IsInSupportedDomain(referring_url))
154 return false; 147 return false;
155 /* 148 /*
156 1. The request URL's host name domain-matches the Domain attribute of the 149 1. The request URL's host name domain-matches the Domain attribute of the
157 dictionary. 150 dictionary.
158 2. If the dictionary has a Port attribute, the request port is one of the 151 2. If the dictionary has a Port attribute, the request port is one of the
159 ports listed in the Port attribute. 152 ports listed in the Port attribute.
160 3. The request URL path-matches the path attribute of the dictionary. 153 3. The request URL path-matches the path attribute of the dictionary.
161 4. The request is not an HTTPS request. 154 4. The request is not an HTTPS request.
162 We can override (ignore) item (4) only when we have explicitly enabled
163 HTTPS support AND dictionary has been acquired over HTTPS.
164 */ 155 */
165 if (!DomainMatch(referring_url, domain_)) { 156 if (!DomainMatch(referring_url, domain_)) {
166 SdchErrorRecovery(DICTIONARY_FOUND_HAS_WRONG_DOMAIN); 157 SdchErrorRecovery(DICTIONARY_FOUND_HAS_WRONG_DOMAIN);
167 return false; 158 return false;
168 } 159 }
169 if (!ports_.empty() 160 if (!ports_.empty()
170 && 0 == ports_.count(referring_url.EffectiveIntPort())) { 161 && 0 == ports_.count(referring_url.EffectiveIntPort())) {
171 SdchErrorRecovery(DICTIONARY_FOUND_HAS_WRONG_PORT_LIST); 162 SdchErrorRecovery(DICTIONARY_FOUND_HAS_WRONG_PORT_LIST);
172 return false; 163 return false;
173 } 164 }
174 if (path_.size() && !PathMatch(referring_url.path(), path_)) { 165 if (path_.size() && !PathMatch(referring_url.path(), path_)) {
175 SdchErrorRecovery(DICTIONARY_FOUND_HAS_WRONG_PATH); 166 SdchErrorRecovery(DICTIONARY_FOUND_HAS_WRONG_PATH);
176 return false; 167 return false;
177 } 168 }
178 if (!SdchManager::secure_scheme_supported() && 169 if (referring_url.SchemeIsSecure()) {
179 referring_url.SchemeIsSecure()) {
180 SdchErrorRecovery(DICTIONARY_FOUND_HAS_WRONG_SCHEME);
181 return false;
182 }
183 if (referring_url.SchemeIsSecure() && !url_.SchemeIsSecure()) {
184 SdchErrorRecovery(DICTIONARY_FOUND_HAS_WRONG_SCHEME); 170 SdchErrorRecovery(DICTIONARY_FOUND_HAS_WRONG_SCHEME);
185 return false; 171 return false;
186 } 172 }
187 173
188 // TODO(jar): Remove overly restrictive failsafe test (added per security 174 // TODO(jar): Remove overly restrictive failsafe test (added per security
189 // review) when we have a need to be more general. 175 // review) when we have a need to be more general.
190 if (!referring_url.SchemeIsHTTPOrHTTPS()) { 176 if (!referring_url.SchemeIs("http")) {
191 SdchErrorRecovery(ATTEMPT_TO_DECODE_NON_HTTP_DATA); 177 SdchErrorRecovery(ATTEMPT_TO_DECODE_NON_HTTP_DATA);
192 return false; 178 return false;
193 } 179 }
194 180
195 return true; 181 return true;
196 } 182 }
197 183
198 bool SdchManager::Dictionary::PathMatch(const std::string& path, 184 bool SdchManager::Dictionary::PathMatch(const std::string& path,
199 const std::string& restriction) { 185 const std::string& restriction) {
200 /* Must be either: 186 /* Must be either:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 DCHECK(CalledOnValidThread()); 245 DCHECK(CalledOnValidThread());
260 fetcher_.reset(fetcher); 246 fetcher_.reset(fetcher);
261 } 247 }
262 248
263 // static 249 // static
264 void SdchManager::EnableSdchSupport(bool enabled) { 250 void SdchManager::EnableSdchSupport(bool enabled) {
265 g_sdch_enabled_ = enabled; 251 g_sdch_enabled_ = enabled;
266 } 252 }
267 253
268 // static 254 // static
269 void SdchManager::EnableSecureSchemeSupport(bool enabled) {
270 g_secure_scheme_supported_ = enabled;
271 }
272
273 // static
274 void SdchManager::BlacklistDomain(const GURL& url) { 255 void SdchManager::BlacklistDomain(const GURL& url) {
275 if (!global_ ) 256 if (!global_ )
276 return; 257 return;
277 global_->SetAllowLatencyExperiment(url, false); 258 global_->SetAllowLatencyExperiment(url, false);
278 259
279 std::string domain(StringToLowerASCII(url.host())); 260 std::string domain(StringToLowerASCII(url.host()));
280 int count = global_->blacklisted_domains_[domain]; 261 int count = global_->blacklisted_domains_[domain];
281 if (count > 0) 262 if (count > 0)
282 return; // Domain is already blacklisted. 263 return; // Domain is already blacklisted.
283 264
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 if (SdchManager::Global()->CanFetchDictionary(request_url, dictionary_url) && 337 if (SdchManager::Global()->CanFetchDictionary(request_url, dictionary_url) &&
357 fetcher_.get()) 338 fetcher_.get())
358 fetcher_->Schedule(dictionary_url); 339 fetcher_->Schedule(dictionary_url);
359 } 340 }
360 341
361 bool SdchManager::CanFetchDictionary(const GURL& referring_url, 342 bool SdchManager::CanFetchDictionary(const GURL& referring_url,
362 const GURL& dictionary_url) const { 343 const GURL& dictionary_url) const {
363 DCHECK(CalledOnValidThread()); 344 DCHECK(CalledOnValidThread());
364 /* The user agent may retrieve a dictionary from the dictionary URL if all of 345 /* The user agent may retrieve a dictionary from the dictionary URL if all of
365 the following are true: 346 the following are true:
366 1 The dictionary URL host name matches the referrer URL host name and 347 1 The dictionary URL host name matches the referrer URL host name
367 scheme.
368 2 The dictionary URL host name domain matches the parent domain of the 348 2 The dictionary URL host name domain matches the parent domain of the
369 referrer URL host name 349 referrer URL host name
370 3 The parent domain of the referrer URL host name is not a top level 350 3 The parent domain of the referrer URL host name is not a top level
371 domain 351 domain
372 4 The dictionary URL is not an HTTPS URL. 352 4 The dictionary URL is not an HTTPS URL.
373 */ 353 */
374 // Item (1) above implies item (2). Spec should be updated. 354 // Item (1) above implies item (2). Spec should be updated.
375 // I take "host name match" to be "is identical to" 355 // I take "host name match" to be "is identical to"
376 if (referring_url.host() != dictionary_url.host() || 356 if (referring_url.host() != dictionary_url.host()) {
377 referring_url.scheme() != dictionary_url.scheme()) {
378 SdchErrorRecovery(DICTIONARY_LOAD_ATTEMPT_FROM_DIFFERENT_HOST); 357 SdchErrorRecovery(DICTIONARY_LOAD_ATTEMPT_FROM_DIFFERENT_HOST);
379 return false; 358 return false;
380 } 359 }
381 if (!secure_scheme_supported() && referring_url.SchemeIsSecure()) { 360 if (referring_url.SchemeIs("https")) {
382 SdchErrorRecovery(DICTIONARY_SELECTED_FOR_SSL); 361 SdchErrorRecovery(DICTIONARY_SELECTED_FOR_SSL);
383 return false; 362 return false;
384 } 363 }
385 364
386 // TODO(jar): Remove this failsafe conservative hack which is more restrictive 365 // TODO(jar): Remove this failsafe conservative hack which is more restrictive
387 // than current SDCH spec when needed, and justified by security audit. 366 // than current SDCH spec when needed, and justified by security audit.
388 if (!referring_url.SchemeIsHTTPOrHTTPS()) { 367 if (!referring_url.SchemeIs("http")) {
389 SdchErrorRecovery(DICTIONARY_SELECTED_FROM_NON_HTTP); 368 SdchErrorRecovery(DICTIONARY_SELECTED_FROM_NON_HTTP);
390 return false; 369 return false;
391 } 370 }
392 371
393 return true; 372 return true;
394 } 373 }
395 374
396 bool SdchManager::AddSdchDictionary(const std::string& dictionary_text, 375 bool SdchManager::AddSdchDictionary(const std::string& dictionary_text,
397 const GURL& dictionary_url) { 376 const GURL& dictionary_url) {
398 DCHECK(CalledOnValidThread()); 377 DCHECK(CalledOnValidThread());
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 case '/': 557 case '/':
579 (*output)[i] = '_'; 558 (*output)[i] = '_';
580 continue; 559 continue;
581 default: 560 default:
582 continue; 561 continue;
583 } 562 }
584 } 563 }
585 } 564 }
586 565
587 } // namespace net 566 } // namespace net
OLDNEW
« no previous file with comments | « trunk/src/net/base/sdch_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698