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

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

Issue 1492403002: Remove kuint32max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win Created 5 years 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_piece.h" 8 #include "base/strings/string_piece.h"
9 #include "base/strings/string_tokenizer.h" 9 #include "base/strings/string_tokenizer.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "net/http/http_security_headers.h" 11 #include "net/http/http_security_headers.h"
12 #include "net/http/http_util.h" 12 #include "net/http/http_util.h"
13 #include "url/gurl.h" 13 #include "url/gurl.h"
14 14
15 namespace net { 15 namespace net {
16 16
17 namespace { 17 namespace {
18 18
19 enum MaxAgeParsing { REQUIRE_MAX_AGE, DO_NOT_REQUIRE_MAX_AGE }; 19 enum MaxAgeParsing { REQUIRE_MAX_AGE, DO_NOT_REQUIRE_MAX_AGE };
20 20
21 static_assert(kMaxHSTSAgeSecs <= kuint32max, "kMaxHSTSAgeSecs too large"); 21 static_assert(kMaxHSTSAgeSecs <= UINT32_MAX, "kMaxHSTSAgeSecs too large");
asanka 2015/12/04 15:12:34 Why not numeric_limits? Isn't it required to be co
Avi (use Gerrit) 2015/12/04 15:19:28 There was some rumbling about whether we can rely
22 22
23 // MaxAgeToInt converts a string representation of a "whole number" of 23 // MaxAgeToInt converts a string representation of a "whole number" of
24 // seconds into a uint32. The string may contain an arbitrarily large number, 24 // seconds into a uint32_t. The string may contain an arbitrarily large number,
25 // which will be clipped to kMaxHSTSAgeSecs and which is guaranteed to fit 25 // which will be clipped to kMaxHSTSAgeSecs and which is guaranteed to fit
26 // within a 32-bit unsigned integer. False is returned on any parse error. 26 // within a 32-bit unsigned integer. False is returned on any parse error.
27 bool MaxAgeToInt(std::string::const_iterator begin, 27 bool MaxAgeToInt(std::string::const_iterator begin,
28 std::string::const_iterator end, 28 std::string::const_iterator end,
29 uint32* result) { 29 uint32_t* result) {
30 const base::StringPiece s(begin, end); 30 const base::StringPiece s(begin, end);
31 if (s.empty()) 31 if (s.empty())
32 return false; 32 return false;
33 33
34 int64 i = 0; 34 int64_t i = 0;
35 35
36 // Return false on any StringToInt64 parse errors *except* for 36 // Return false on any StringToInt64 parse errors *except* for
37 // int64 overflow. StringToInt64 is used, rather than StringToUint64, 37 // int64_t overflow. StringToInt64 is used, rather than StringToUint64,
38 // in order to properly handle and reject negative numbers 38 // in order to properly handle and reject negative numbers
39 // (StringToUint64 does not return false on negative numbers). 39 // (StringToUint64 does not return false on negative numbers).
40 // For values too large to be stored in an int64, StringToInt64 will 40 // For values too large to be stored in an int64_t, StringToInt64 will
41 // return false with i set to kint64max, so this case is detected 41 // return false with i set to INT64_MAX, so this case is detected
42 // by the immediately following if-statement and allowed to fall 42 // by the immediately following if-statement and allowed to fall
43 // through so that i gets clipped to kMaxHSTSAgeSecs. 43 // through so that i gets clipped to kMaxHSTSAgeSecs.
44 if (!base::StringToInt64(s, &i) && i != kint64max) 44 if (!base::StringToInt64(s, &i) && i != INT64_MAX)
asanka 2015/12/04 15:12:34 Why INT64_MAX instead of numeric_limits? This doe
Avi (use Gerrit) 2015/12/04 15:19:28 Consistency with above. I'll switch if you want.
asanka 2015/12/04 15:41:43 I'd prefer if we switch this instance and keep the
Avi (use Gerrit) 2015/12/04 15:48:16 Done.
45 return false; 45 return false;
46 if (i < 0) 46 if (i < 0)
47 return false; 47 return false;
48 if (i > kMaxHSTSAgeSecs) 48 if (i > kMaxHSTSAgeSecs)
49 i = kMaxHSTSAgeSecs; 49 i = kMaxHSTSAgeSecs;
50 *result = (uint32)i; 50 *result = (uint32_t)i;
51 return true; 51 return true;
52 } 52 }
53 53
54 // Returns true iff there is an item in |pins| which is not present in 54 // Returns true iff there is an item in |pins| which is not present in
55 // |from_cert_chain|. Such an SPKI hash is called a "backup pin". 55 // |from_cert_chain|. Such an SPKI hash is called a "backup pin".
56 bool IsBackupPinPresent(const HashValueVector& pins, 56 bool IsBackupPinPresent(const HashValueVector& pins,
57 const HashValueVector& from_cert_chain) { 57 const HashValueVector& from_cert_chain) {
58 for (HashValueVector::const_iterator i = pins.begin(); i != pins.end(); 58 for (HashValueVector::const_iterator i = pins.begin(); i != pins.end();
59 ++i) { 59 ++i) {
60 HashValueVector::const_iterator j = 60 HashValueVector::const_iterator j =
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 121 }
122 122
123 bool ParseHPKPHeaderImpl(const std::string& value, 123 bool ParseHPKPHeaderImpl(const std::string& value,
124 MaxAgeParsing max_age_status, 124 MaxAgeParsing max_age_status,
125 base::TimeDelta* max_age, 125 base::TimeDelta* max_age,
126 bool* include_subdomains, 126 bool* include_subdomains,
127 HashValueVector* hashes, 127 HashValueVector* hashes,
128 GURL* report_uri) { 128 GURL* report_uri) {
129 bool parsed_max_age = false; 129 bool parsed_max_age = false;
130 bool include_subdomains_candidate = false; 130 bool include_subdomains_candidate = false;
131 uint32 max_age_candidate = 0; 131 uint32_t max_age_candidate = 0;
132 GURL parsed_report_uri; 132 GURL parsed_report_uri;
133 HashValueVector pins; 133 HashValueVector pins;
134 bool require_max_age = max_age_status == REQUIRE_MAX_AGE; 134 bool require_max_age = max_age_status == REQUIRE_MAX_AGE;
135 135
136 HttpUtil::NameValuePairsIterator name_value_pairs( 136 HttpUtil::NameValuePairsIterator name_value_pairs(
137 value.begin(), value.end(), ';', 137 value.begin(), value.end(), ';',
138 HttpUtil::NameValuePairsIterator::VALUES_OPTIONAL); 138 HttpUtil::NameValuePairsIterator::VALUES_OPTIONAL);
139 139
140 while (name_value_pairs.GetNext()) { 140 while (name_value_pairs.GetNext()) {
141 if (base::LowerCaseEqualsASCII( 141 if (base::LowerCaseEqualsASCII(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // other header field value data, that does not conform to the 217 // other header field value data, that does not conform to the
218 // syntax defined in this specification. 218 // syntax defined in this specification.
219 // 219 //
220 // 5. If an STS header field contains directive(s) not recognized by 220 // 5. If an STS header field contains directive(s) not recognized by
221 // the UA, the UA MUST ignore the unrecognized directives and if the 221 // the UA, the UA MUST ignore the unrecognized directives and if the
222 // STS header field otherwise satisfies the above requirements (1 222 // STS header field otherwise satisfies the above requirements (1
223 // through 4), the UA MUST process the recognized directives. 223 // through 4), the UA MUST process the recognized directives.
224 bool ParseHSTSHeader(const std::string& value, 224 bool ParseHSTSHeader(const std::string& value,
225 base::TimeDelta* max_age, 225 base::TimeDelta* max_age,
226 bool* include_subdomains) { 226 bool* include_subdomains) {
227 uint32 max_age_candidate = 0; 227 uint32_t max_age_candidate = 0;
228 bool include_subdomains_candidate = false; 228 bool include_subdomains_candidate = false;
229 229
230 // We must see max-age exactly once. 230 // We must see max-age exactly once.
231 int max_age_observed = 0; 231 int max_age_observed = 0;
232 // We must see includeSubdomains exactly 0 or 1 times. 232 // We must see includeSubdomains exactly 0 or 1 times.
233 int include_subdomains_observed = 0; 233 int include_subdomains_observed = 0;
234 234
235 enum ParserState { 235 enum ParserState {
236 START, 236 START,
237 AFTER_MAX_AGE_LABEL, 237 AFTER_MAX_AGE_LABEL,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 bool* include_subdomains, 368 bool* include_subdomains,
369 HashValueVector* hashes, 369 HashValueVector* hashes,
370 GURL* report_uri) { 370 GURL* report_uri) {
371 // max-age is irrelevant for Report-Only headers. 371 // max-age is irrelevant for Report-Only headers.
372 base::TimeDelta unused_max_age; 372 base::TimeDelta unused_max_age;
373 return ParseHPKPHeaderImpl(value, DO_NOT_REQUIRE_MAX_AGE, &unused_max_age, 373 return ParseHPKPHeaderImpl(value, DO_NOT_REQUIRE_MAX_AGE, &unused_max_age,
374 include_subdomains, hashes, report_uri); 374 include_subdomains, hashes, report_uri);
375 } 375 }
376 376
377 } // namespace net 377 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698