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

Side by Side Diff: net/http/http_security_headers.cc

Issue 1211363005: Parse HPKP report-uri and persist in TransportSecurityPersister (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rsleevi comments Created 5 years, 5 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
« no previous file with comments | « net/http/http_security_headers.h ('k') | net/http/http_security_headers_unittest.cc » ('j') | 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 "base/base64.h" 5 #include "base/base64.h"
6 #include "base/basictypes.h" 6 #include "base/basictypes.h"
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_tokenizer.h" 8 #include "base/strings/string_tokenizer.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "net/http/http_security_headers.h" 10 #include "net/http/http_security_headers.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 std::string::const_iterator start = source.begin(); 99 std::string::const_iterator start = source.begin();
100 std::string::const_iterator end = source.end(); 100 std::string::const_iterator end = source.end();
101 HttpUtil::TrimLWS(&start, &end); 101 HttpUtil::TrimLWS(&start, &end);
102 return std::string(start, end); 102 return std::string(start, end);
103 } 103 }
104 104
105 typedef std::pair<std::string, std::string> StringPair; 105 typedef std::pair<std::string, std::string> StringPair;
106 106
107 StringPair Split(const std::string& source, char delimiter) { 107 StringPair Split(const std::string& source, char delimiter) {
108 StringPair pair; 108 StringPair pair;
109 size_t point = source.find(delimiter); 109 size_t point = HttpUtil::FindDelimiter(source, 0, delimiter);
Ryan Sleevi 2015/06/27 12:13:59 Hrm, this was previously dead code, and nothing us
davidben 2015/06/29 22:38:43 That sounds reasonable to me, assuming you mean th
110 110
111 pair.first = source.substr(0, point); 111 pair.first = source.substr(0, point);
112 if (std::string::npos != point) 112
113 if (source.size() != point)
113 pair.second = source.substr(point + 1); 114 pair.second = source.substr(point + 1);
114 115
115 return pair; 116 return pair;
116 } 117 }
117 118
118 bool ParseAndAppendPin(const std::string& value, 119 bool ParseAndAppendPin(const std::string& value,
119 HashValueTag tag, 120 HashValueTag tag,
120 HashValueVector* hashes) { 121 HashValueVector* hashes) {
121 // Pins are always quoted. 122 // Pins are always quoted.
122 if (value.empty() || !HttpUtil::IsQuote(value[0])) 123 if (value.empty() || !HttpUtil::IsQuote(value[0]))
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 case START: 267 case START:
267 case AFTER_MAX_AGE_LABEL: 268 case AFTER_MAX_AGE_LABEL:
268 case AFTER_MAX_AGE_EQUALS: 269 case AFTER_MAX_AGE_EQUALS:
269 return false; 270 return false;
270 default: 271 default:
271 NOTREACHED(); 272 NOTREACHED();
272 return false; 273 return false;
273 } 274 }
274 } 275 }
275 276
276 // "Public-Key-Pins" ":" 277 // "Public-Key-Pins[-Report-Only]" ":"
277 // "max-age" "=" delta-seconds ";" 278 // "max-age" "=" delta-seconds ";"
278 // "pin-" algo "=" base64 [ ";" ... ] 279 // "pin-" algo "=" base64 [ ";" ... ]
280 // [ ";" "includeSubdomains" ]
281 // [ ";" "report-uri" "=" uri-reference ]
279 bool ParseHPKPHeader(const std::string& value, 282 bool ParseHPKPHeader(const std::string& value,
280 const HashValueVector& chain_hashes, 283 const HashValueVector& chain_hashes,
281 base::TimeDelta* max_age, 284 base::TimeDelta* max_age,
282 bool* include_subdomains, 285 bool* include_subdomains,
283 HashValueVector* hashes) { 286 HashValueVector* hashes,
287 std::string* report_uri) {
284 bool parsed_max_age = false; 288 bool parsed_max_age = false;
285 bool include_subdomains_candidate = false; 289 bool include_subdomains_candidate = false;
286 uint32 max_age_candidate = 0; 290 uint32 max_age_candidate = 0;
287 HashValueVector pins; 291 HashValueVector pins;
288 292
289 std::string source = value; 293 std::string source = value;
290 294
291 while (!source.empty()) { 295 while (!source.empty()) {
292 StringPair semicolon = Split(source, ';'); 296 StringPair semicolon = Split(source, ';');
293 semicolon.first = Strip(semicolon.first); 297 semicolon.first = Strip(semicolon.first);
(...skipping 10 matching lines...) Expand all
304 } 308 }
305 parsed_max_age = true; 309 parsed_max_age = true;
306 } else if (base::LowerCaseEqualsASCII(equals.first, "pin-sha1")) { 310 } else if (base::LowerCaseEqualsASCII(equals.first, "pin-sha1")) {
307 if (!ParseAndAppendPin(equals.second, HASH_VALUE_SHA1, &pins)) 311 if (!ParseAndAppendPin(equals.second, HASH_VALUE_SHA1, &pins))
308 return false; 312 return false;
309 } else if (base::LowerCaseEqualsASCII(equals.first, "pin-sha256")) { 313 } else if (base::LowerCaseEqualsASCII(equals.first, "pin-sha256")) {
310 if (!ParseAndAppendPin(equals.second, HASH_VALUE_SHA256, &pins)) 314 if (!ParseAndAppendPin(equals.second, HASH_VALUE_SHA256, &pins))
311 return false; 315 return false;
312 } else if (base::LowerCaseEqualsASCII(equals.first, "includesubdomains")) { 316 } else if (base::LowerCaseEqualsASCII(equals.first, "includesubdomains")) {
313 include_subdomains_candidate = true; 317 include_subdomains_candidate = true;
318 } else if (base::LowerCaseEqualsASCII(equals.first, "report-uri")) {
319 // report-uris are always quoted.
davidben 2015/06/29 22:38:43 Not quoting would be insane, but I don't actually
320 if (equals.second.empty() || !HttpUtil::IsQuote(equals.second[0]) ||
321 equals.second[0] != *equals.second.rbegin())
322 return false;
323
324 *report_uri = HttpUtil::Unquote(equals.second);
325 if (report_uri->empty())
326 return false;
314 } else { 327 } else {
315 // Silently ignore unknown directives for forward compatibility. 328 // Silently ignore unknown directives for forward compatibility.
316 } 329 }
317 330
318 source = semicolon.second; 331 source = semicolon.second;
319 } 332 }
320 333
321 if (!parsed_max_age) 334 if (!parsed_max_age)
322 return false; 335 return false;
323 336
324 if (!IsPinListValid(pins, chain_hashes)) 337 if (!IsPinListValid(pins, chain_hashes))
325 return false; 338 return false;
326 339
327 *max_age = base::TimeDelta::FromSeconds(max_age_candidate); 340 *max_age = base::TimeDelta::FromSeconds(max_age_candidate);
328 *include_subdomains = include_subdomains_candidate; 341 *include_subdomains = include_subdomains_candidate;
329 hashes->swap(pins); 342 hashes->swap(pins);
330 343
331 return true; 344 return true;
332 } 345 }
333 346
334 } // namespace net 347 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_security_headers.h ('k') | net/http/http_security_headers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698