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

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

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
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"
11 #include "net/http/http_util.h" 11 #include "net/http/http_util.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 namespace { 15 namespace {
16 16
17 COMPILE_ASSERT(kMaxHSTSAgeSecs <= kuint32max, kMaxHSTSAgeSecsTooLarge); 17 static_assert(kMaxHSTSAgeSecs <= kuint32max, "kMaxHSTSAgeSecs too large");
18 18
19 // MaxAgeToInt converts a string representation of a "whole number" of 19 // MaxAgeToInt converts a string representation of a "whole number" of
20 // seconds into a uint32. The string may contain an arbitrarily large number, 20 // seconds into a uint32. The string may contain an arbitrarily large number,
21 // which will be clipped to kMaxHSTSAgeSecs and which is guaranteed to fit 21 // which will be clipped to kMaxHSTSAgeSecs and which is guaranteed to fit
22 // within a 32-bit unsigned integer. False is returned on any parse error. 22 // within a 32-bit unsigned integer. False is returned on any parse error.
23 bool MaxAgeToInt(std::string::const_iterator begin, 23 bool MaxAgeToInt(std::string::const_iterator begin,
24 std::string::const_iterator end, 24 std::string::const_iterator end,
25 uint32* result) { 25 uint32* result) {
26 const std::string s(begin, end); 26 const std::string s(begin, end);
27 int64 i = 0; 27 int64 i = 0;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 pair.first = source.substr(0, point); 111 pair.first = source.substr(0, point);
112 if (std::string::npos != point) 112 if (std::string::npos != point)
113 pair.second = source.substr(point + 1); 113 pair.second = source.substr(point + 1);
114 114
115 return pair; 115 return pair;
116 } 116 }
117 117
118 bool ParseAndAppendPin(const std::string& value, 118 bool ParseAndAppendPin(const std::string& value,
119 HashValueTag tag, 119 HashValueTag tag,
120 HashValueVector* hashes) { 120 HashValueVector* hashes) {
121 // Pins are always quoted.
122 if (value.empty() || !HttpUtil::IsQuote(value[0]))
123 return false;
124
121 std::string unquoted = HttpUtil::Unquote(value); 125 std::string unquoted = HttpUtil::Unquote(value);
122 std::string decoded;
123
124 if (unquoted.empty()) 126 if (unquoted.empty())
125 return false; 127 return false;
126 128
129 std::string decoded;
127 if (!base::Base64Decode(unquoted, &decoded)) 130 if (!base::Base64Decode(unquoted, &decoded))
128 return false; 131 return false;
129 132
130 HashValue hash(tag); 133 HashValue hash(tag);
131 if (decoded.size() != hash.size()) 134 if (decoded.size() != hash.size())
132 return false; 135 return false;
133 136
134 memcpy(hash.data(), decoded.data(), hash.size()); 137 memcpy(hash.data(), decoded.data(), hash.size());
135 hashes->push_back(hash); 138 hashes->push_back(hash);
136 return true; 139 return true;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } 319 }
317 320
318 if (!parsed_max_age) 321 if (!parsed_max_age)
319 return false; 322 return false;
320 323
321 if (!IsPinListValid(pins, chain_hashes)) 324 if (!IsPinListValid(pins, chain_hashes))
322 return false; 325 return false;
323 326
324 *max_age = base::TimeDelta::FromSeconds(max_age_candidate); 327 *max_age = base::TimeDelta::FromSeconds(max_age_candidate);
325 *include_subdomains = include_subdomains_candidate; 328 *include_subdomains = include_subdomains_candidate;
326 for (HashValueVector::const_iterator i = pins.begin(); 329 hashes->swap(pins);
327 i != pins.end(); ++i) {
328 bool found = false;
329
330 for (HashValueVector::const_iterator j = hashes->begin();
331 j != hashes->end(); ++j) {
332 if (j->Equals(*i)) {
333 found = true;
334 break;
335 }
336 }
337
338 if (!found)
339 hashes->push_back(*i);
340 }
341 330
342 return true; 331 return true;
343 } 332 }
344 333
345 } // namespace net 334 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698