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

Side by Side Diff: net/http/http_security_headers_unittest.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, 6 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 <stdint.h> 5 #include <stdint.h>
6 #include <algorithm> 6 #include <algorithm>
7 7
8 #include "base/base64.h" 8 #include "base/base64.h"
9 #include "base/sha1.h" 9 #include "base/sha1.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // values for its predictable fields. 145 // values for its predictable fields.
146 EXPECT_EQ(0, max_age.InSeconds()); 146 EXPECT_EQ(0, max_age.InSeconds());
147 EXPECT_FALSE(include_subdomains); 147 EXPECT_FALSE(include_subdomains);
148 } 148 }
149 149
150 static void TestBogusPinsHeaders(HashValueTag tag) { 150 static void TestBogusPinsHeaders(HashValueTag tag) {
151 base::TimeDelta max_age; 151 base::TimeDelta max_age;
152 bool include_subdomains; 152 bool include_subdomains;
153 HashValueVector hashes; 153 HashValueVector hashes;
154 HashValueVector chain_hashes; 154 HashValueVector chain_hashes;
155 std::string report_uri;
155 156
156 // Set some fake "chain" hashes 157 // Set some fake "chain" hashes
157 chain_hashes.push_back(GetTestHashValue(1, tag)); 158 chain_hashes.push_back(GetTestHashValue(1, tag));
158 chain_hashes.push_back(GetTestHashValue(2, tag)); 159 chain_hashes.push_back(GetTestHashValue(2, tag));
159 chain_hashes.push_back(GetTestHashValue(3, tag)); 160 chain_hashes.push_back(GetTestHashValue(3, tag));
160 161
161 // The good pin must be in the chain, the backup pin must not be 162 // The good pin must be in the chain, the backup pin must not be
162 std::string good_pin = GetTestPin(2, tag); 163 std::string good_pin = GetTestPin(2, tag);
163 std::string good_pin_unquoted = GetTestPinUnquoted(2, tag); 164 std::string good_pin_unquoted = GetTestPinUnquoted(2, tag);
164 std::string backup_pin = GetTestPin(4, tag); 165 std::string backup_pin = GetTestPin(4, tag);
165 166
166 EXPECT_FALSE(ParseHPKPHeader(std::string(), chain_hashes, &max_age, 167 EXPECT_FALSE(ParseHPKPHeader(std::string(), chain_hashes, &max_age,
167 &include_subdomains, &hashes)); 168 &include_subdomains, &hashes, &report_uri));
168 EXPECT_FALSE(ParseHPKPHeader(" ", chain_hashes, &max_age, 169 EXPECT_FALSE(ParseHPKPHeader(" ", chain_hashes, &max_age,
169 &include_subdomains, &hashes)); 170 &include_subdomains, &hashes, &report_uri));
170 EXPECT_FALSE(ParseHPKPHeader("abc", chain_hashes, &max_age, 171 EXPECT_FALSE(ParseHPKPHeader("abc", chain_hashes, &max_age,
171 &include_subdomains, &hashes)); 172 &include_subdomains, &hashes, &report_uri));
172 EXPECT_FALSE(ParseHPKPHeader(" abc", chain_hashes, &max_age, 173 EXPECT_FALSE(ParseHPKPHeader(" abc", chain_hashes, &max_age,
173 &include_subdomains, &hashes)); 174 &include_subdomains, &hashes, &report_uri));
174 EXPECT_FALSE(ParseHPKPHeader(" abc ", chain_hashes, &max_age, 175 EXPECT_FALSE(ParseHPKPHeader(" abc ", chain_hashes, &max_age,
175 &include_subdomains, &hashes)); 176 &include_subdomains, &hashes, &report_uri));
176 EXPECT_FALSE(ParseHPKPHeader("max-age", chain_hashes, &max_age, 177 EXPECT_FALSE(ParseHPKPHeader("max-age", chain_hashes, &max_age,
177 &include_subdomains, &hashes)); 178 &include_subdomains, &hashes, &report_uri));
178 EXPECT_FALSE(ParseHPKPHeader(" max-age", chain_hashes, &max_age, 179 EXPECT_FALSE(ParseHPKPHeader(" max-age", chain_hashes, &max_age,
179 &include_subdomains, &hashes)); 180 &include_subdomains, &hashes, &report_uri));
180 EXPECT_FALSE(ParseHPKPHeader(" max-age ", chain_hashes, &max_age, 181 EXPECT_FALSE(ParseHPKPHeader(" max-age ", chain_hashes, &max_age,
181 &include_subdomains, &hashes)); 182 &include_subdomains, &hashes, &report_uri));
182 EXPECT_FALSE(ParseHPKPHeader("max-age=", chain_hashes, &max_age, 183 EXPECT_FALSE(ParseHPKPHeader("max-age=", chain_hashes, &max_age,
183 &include_subdomains, &hashes)); 184 &include_subdomains, &hashes, &report_uri));
184 EXPECT_FALSE(ParseHPKPHeader(" max-age=", chain_hashes, &max_age, 185 EXPECT_FALSE(ParseHPKPHeader(" max-age=", chain_hashes, &max_age,
185 &include_subdomains, &hashes)); 186 &include_subdomains, &hashes, &report_uri));
186 EXPECT_FALSE(ParseHPKPHeader(" max-age =", chain_hashes, &max_age, 187 EXPECT_FALSE(ParseHPKPHeader(" max-age =", chain_hashes, &max_age,
187 &include_subdomains, &hashes)); 188 &include_subdomains, &hashes, &report_uri));
188 EXPECT_FALSE(ParseHPKPHeader(" max-age= ", chain_hashes, &max_age, 189 EXPECT_FALSE(ParseHPKPHeader(" max-age= ", chain_hashes, &max_age,
189 &include_subdomains, &hashes)); 190 &include_subdomains, &hashes, &report_uri));
190 EXPECT_FALSE(ParseHPKPHeader(" max-age = ", chain_hashes, 191 EXPECT_FALSE(ParseHPKPHeader(" max-age = ", chain_hashes, &max_age,
191 &max_age, &include_subdomains, &hashes)); 192 &include_subdomains, &hashes, &report_uri));
192 EXPECT_FALSE(ParseHPKPHeader(" max-age = xy", chain_hashes, 193 EXPECT_FALSE(ParseHPKPHeader(" max-age = xy", chain_hashes, &max_age,
193 &max_age, &include_subdomains, &hashes)); 194 &include_subdomains, &hashes, &report_uri));
194 EXPECT_FALSE(ParseHPKPHeader(" max-age = 3488a923", 195 EXPECT_FALSE(ParseHPKPHeader(" max-age = 3488a923", chain_hashes,
196 &max_age, &include_subdomains, &hashes,
197 &report_uri));
198 EXPECT_FALSE(ParseHPKPHeader("max-age=3488a923 ", chain_hashes, &max_age,
199 &include_subdomains, &hashes, &report_uri));
200 EXPECT_FALSE(ParseHPKPHeader(
201 "max-ag=3488923pins=" + good_pin + "," + backup_pin, chain_hashes,
202 &max_age, &include_subdomains, &hashes, &report_uri));
203 EXPECT_FALSE(ParseHPKPHeader("max-age=3488923;pins=" + good_pin + "," +
204 backup_pin + "report-uri=\"http://foo.com\"",
195 chain_hashes, &max_age, &include_subdomains, 205 chain_hashes, &max_age, &include_subdomains,
196 &hashes)); 206 &hashes, &report_uri));
197 EXPECT_FALSE(ParseHPKPHeader("max-age=3488a923 ", chain_hashes, 207 EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923" + backup_pin, chain_hashes,
198 &max_age, &include_subdomains, &hashes)); 208 &max_age, &include_subdomains, &hashes,
199 EXPECT_FALSE(ParseHPKPHeader("max-ag=3488923pins=" + good_pin + "," + 209 &report_uri));
200 backup_pin, 210 EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923; " + backup_pin, chain_hashes,
211 &max_age, &include_subdomains, &hashes,
212 &report_uri));
213 EXPECT_FALSE(ParseHPKPHeader(
214 "max-aged=3488923; " + backup_pin + ";" + backup_pin, chain_hashes,
215 &max_age, &include_subdomains, &hashes, &report_uri));
216 EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923; " + good_pin + ";" + good_pin,
201 chain_hashes, &max_age, &include_subdomains, 217 chain_hashes, &max_age, &include_subdomains,
202 &hashes)); 218 &hashes, &report_uri));
203 EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923" + backup_pin, 219 EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923; " + good_pin, chain_hashes,
204 chain_hashes, &max_age, &include_subdomains, 220 &max_age, &include_subdomains, &hashes,
205 &hashes)); 221 &report_uri));
206 EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923; " + backup_pin,
207 chain_hashes, &max_age, &include_subdomains,
208 &hashes));
209 EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923; " + backup_pin + ";" +
210 backup_pin,
211 chain_hashes, &max_age, &include_subdomains,
212 &hashes));
213 EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923; " + good_pin + ";" +
214 good_pin,
215 chain_hashes, &max_age, &include_subdomains,
216 &hashes));
217 EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923; " + good_pin,
218 chain_hashes, &max_age, &include_subdomains,
219 &hashes));
220 EXPECT_FALSE(ParseHPKPHeader("max-age==3488923", chain_hashes, &max_age, 222 EXPECT_FALSE(ParseHPKPHeader("max-age==3488923", chain_hashes, &max_age,
221 &include_subdomains, &hashes)); 223 &include_subdomains, &hashes, &report_uri));
222 EXPECT_FALSE(ParseHPKPHeader("amax-age=3488923", chain_hashes, &max_age, 224 EXPECT_FALSE(ParseHPKPHeader("amax-age=3488923", chain_hashes, &max_age,
223 &include_subdomains, &hashes)); 225 &include_subdomains, &hashes, &report_uri));
224 EXPECT_FALSE(ParseHPKPHeader("max-age=-3488923", chain_hashes, &max_age, 226 EXPECT_FALSE(ParseHPKPHeader("max-age=-3488923", chain_hashes, &max_age,
225 &include_subdomains, &hashes)); 227 &include_subdomains, &hashes, &report_uri));
226 EXPECT_FALSE(ParseHPKPHeader("max-age=3488923;", chain_hashes, &max_age, 228 EXPECT_FALSE(ParseHPKPHeader("max-age=3488923;", chain_hashes, &max_age,
227 &include_subdomains, &hashes)); 229 &include_subdomains, &hashes, &report_uri));
228 EXPECT_FALSE(ParseHPKPHeader("max-age=3488923 e", chain_hashes, 230 EXPECT_FALSE(ParseHPKPHeader("max-age=3488923 e", chain_hashes, &max_age,
229 &max_age, &include_subdomains, &hashes)); 231 &include_subdomains, &hashes, &report_uri));
230 EXPECT_FALSE(ParseHPKPHeader("max-age=3488923 includesubdomain", 232 EXPECT_FALSE(ParseHPKPHeader("max-age=3488923 includesubdomain",
231 chain_hashes, &max_age, &include_subdomains, 233 chain_hashes, &max_age, &include_subdomains,
232 &hashes)); 234 &hashes, &report_uri));
235 EXPECT_FALSE(ParseHPKPHeader(
236 "max-age=3488923 report-uri=\"http://foo.com\"", chain_hashes,
237 &max_age, &include_subdomains, &hashes, &report_uri));
233 EXPECT_FALSE(ParseHPKPHeader("max-age=34889.23", chain_hashes, &max_age, 238 EXPECT_FALSE(ParseHPKPHeader("max-age=34889.23", chain_hashes, &max_age,
234 &include_subdomains, &hashes)); 239 &include_subdomains, &hashes, &report_uri));
235 EXPECT_FALSE( 240 EXPECT_FALSE(ParseHPKPHeader(
236 ParseHPKPHeader("max-age=243; " + good_pin_unquoted + ";" + backup_pin, 241 "max-age=243; " + good_pin_unquoted + ";" + backup_pin, chain_hashes,
237 chain_hashes, &max_age, &include_subdomains, &hashes)); 242 &max_age, &include_subdomains, &hashes, &report_uri));
243 EXPECT_FALSE(ParseHPKPHeader(
244 "max-age=243; " + good_pin + ";" + backup_pin + ";report-uri=;",
245 chain_hashes, &max_age, &include_subdomains, &hashes, &report_uri));
246 EXPECT_FALSE(ParseHPKPHeader("max-age=243; " + good_pin + ";" + backup_pin +
247 ";report-uri=http://foo.com;",
248 chain_hashes, &max_age, &include_subdomains,
249 &hashes, &report_uri));
250 EXPECT_FALSE(ParseHPKPHeader(
251 "max-age=243; " + good_pin + ";" + backup_pin + ";report-uri=''",
252 chain_hashes, &max_age, &include_subdomains, &hashes, &report_uri));
253
254 // Test that the parser rejects misquoted strings.
255 EXPECT_FALSE(ParseHPKPHeader("max-age=999; " + backup_pin + "; " + good_pin +
256 "; report-uri=\"http://foo;bar\'",
257 chain_hashes, &max_age, &include_subdomains,
258 &hashes, &report_uri));
238 259
239 // Check the out args were not updated by checking the default 260 // Check the out args were not updated by checking the default
240 // values for its predictable fields. 261 // values for its predictable fields.
241 EXPECT_EQ(0, max_age.InSeconds()); 262 EXPECT_EQ(0, max_age.InSeconds());
242 EXPECT_EQ(hashes.size(), (size_t)0); 263 EXPECT_EQ(hashes.size(), (size_t)0);
243 } 264 }
244 265
245 TEST_F(HttpSecurityHeadersTest, ValidSTSHeaders) { 266 TEST_F(HttpSecurityHeadersTest, ValidSTSHeaders) {
246 base::TimeDelta max_age; 267 base::TimeDelta max_age;
247 base::TimeDelta expect_max_age; 268 base::TimeDelta expect_max_age;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 EXPECT_EQ(expect_max_age, max_age); 419 EXPECT_EQ(expect_max_age, max_age);
399 EXPECT_TRUE(include_subdomains); 420 EXPECT_TRUE(include_subdomains);
400 } 421 }
401 422
402 static void TestValidPKPHeaders(HashValueTag tag) { 423 static void TestValidPKPHeaders(HashValueTag tag) {
403 base::TimeDelta max_age; 424 base::TimeDelta max_age;
404 base::TimeDelta expect_max_age; 425 base::TimeDelta expect_max_age;
405 bool include_subdomains; 426 bool include_subdomains;
406 HashValueVector hashes; 427 HashValueVector hashes;
407 HashValueVector chain_hashes; 428 HashValueVector chain_hashes;
429 std::string expect_report_uri;
430 std::string report_uri;
408 431
409 // Set some fake "chain" hashes into chain_hashes 432 // Set some fake "chain" hashes into chain_hashes
410 chain_hashes.push_back(GetTestHashValue(1, tag)); 433 chain_hashes.push_back(GetTestHashValue(1, tag));
411 chain_hashes.push_back(GetTestHashValue(2, tag)); 434 chain_hashes.push_back(GetTestHashValue(2, tag));
412 chain_hashes.push_back(GetTestHashValue(3, tag)); 435 chain_hashes.push_back(GetTestHashValue(3, tag));
413 436
414 // The good pin must be in the chain, the backup pin must not be 437 // The good pin must be in the chain, the backup pin must not be
415 std::string good_pin = GetTestPin(2, tag); 438 std::string good_pin = GetTestPin(2, tag);
416 std::string good_pin2 = GetTestPin(3, tag); 439 std::string good_pin2 = GetTestPin(3, tag);
417 std::string backup_pin = GetTestPin(4, tag); 440 std::string backup_pin = GetTestPin(4, tag);
418 441
419 EXPECT_TRUE(ParseHPKPHeader( 442 EXPECT_TRUE(ParseHPKPHeader("max-age=243; " + good_pin + ";" + backup_pin,
420 "max-age=243; " + good_pin + ";" + backup_pin, 443 chain_hashes, &max_age, &include_subdomains,
421 chain_hashes, &max_age, &include_subdomains, &hashes)); 444 &hashes, &report_uri));
422 expect_max_age = base::TimeDelta::FromSeconds(243); 445 expect_max_age = base::TimeDelta::FromSeconds(243);
423 EXPECT_EQ(expect_max_age, max_age); 446 EXPECT_EQ(expect_max_age, max_age);
424 EXPECT_FALSE(include_subdomains); 447 EXPECT_FALSE(include_subdomains);
448 EXPECT_EQ(std::string(), report_uri);
425 449
426 EXPECT_TRUE(ParseHPKPHeader( 450 EXPECT_TRUE(ParseHPKPHeader(
427 " " + good_pin + "; " + backup_pin + " ; Max-agE = 567", 451 "max-age=243; " + good_pin + ";" + backup_pin + "; report-uri= \"/foo\"",
428 chain_hashes, &max_age, &include_subdomains, &hashes)); 452 chain_hashes, &max_age, &include_subdomains, &hashes, &report_uri));
429 expect_max_age = base::TimeDelta::FromSeconds(567); 453 expect_max_age = base::TimeDelta::FromSeconds(243);
454 expect_report_uri = "/foo";
430 EXPECT_EQ(expect_max_age, max_age); 455 EXPECT_EQ(expect_max_age, max_age);
431 EXPECT_FALSE(include_subdomains); 456 EXPECT_FALSE(include_subdomains);
457 EXPECT_EQ(expect_report_uri, report_uri);
432 458
433 EXPECT_TRUE(ParseHPKPHeader( 459 EXPECT_TRUE(ParseHPKPHeader(" " + good_pin + "; " + backup_pin +
434 "includeSubDOMAINS;" + good_pin + ";" + backup_pin + 460 " ; Max-agE = 567; repOrT-URi = \"/foo\"",
435 " ; mAx-aGe = 890 ", 461 chain_hashes, &max_age, &include_subdomains,
436 chain_hashes, &max_age, &include_subdomains, &hashes)); 462 &hashes, &report_uri));
463 expect_max_age = base::TimeDelta::FromSeconds(567);
464 expect_report_uri = "/foo";
465 EXPECT_EQ(expect_max_age, max_age);
466 EXPECT_FALSE(include_subdomains);
467 EXPECT_EQ(expect_report_uri, report_uri);
468
469 EXPECT_TRUE(ParseHPKPHeader("includeSubDOMAINS;" + good_pin + ";" +
470 backup_pin + " ; mAx-aGe = 890 ",
471 chain_hashes, &max_age, &include_subdomains,
472 &hashes, &report_uri));
437 expect_max_age = base::TimeDelta::FromSeconds(890); 473 expect_max_age = base::TimeDelta::FromSeconds(890);
438 EXPECT_EQ(expect_max_age, max_age); 474 EXPECT_EQ(expect_max_age, max_age);
439 EXPECT_TRUE(include_subdomains); 475 EXPECT_TRUE(include_subdomains);
440 476
441 EXPECT_TRUE(ParseHPKPHeader( 477 EXPECT_TRUE(ParseHPKPHeader(
442 good_pin + ";" + backup_pin + "; max-age=123;IGNORED;", 478 good_pin + ";" + backup_pin + "; max-age=123;IGNORED;", chain_hashes,
443 chain_hashes, &max_age, &include_subdomains, &hashes)); 479 &max_age, &include_subdomains, &hashes, &report_uri));
444 expect_max_age = base::TimeDelta::FromSeconds(123); 480 expect_max_age = base::TimeDelta::FromSeconds(123);
445 EXPECT_EQ(expect_max_age, max_age); 481 EXPECT_EQ(expect_max_age, max_age);
446 EXPECT_FALSE(include_subdomains); 482 EXPECT_FALSE(include_subdomains);
447 483
448 EXPECT_TRUE(ParseHPKPHeader( 484 EXPECT_TRUE(ParseHPKPHeader(
449 "max-age=394082;" + backup_pin + ";" + good_pin + "; ", 485 "max-age=394082;" + backup_pin + ";" + good_pin + "; ", chain_hashes,
450 chain_hashes, &max_age, &include_subdomains, &hashes)); 486 &max_age, &include_subdomains, &hashes, &report_uri));
451 expect_max_age = base::TimeDelta::FromSeconds(394082); 487 expect_max_age = base::TimeDelta::FromSeconds(394082);
452 EXPECT_EQ(expect_max_age, max_age); 488 EXPECT_EQ(expect_max_age, max_age);
453 EXPECT_FALSE(include_subdomains); 489 EXPECT_FALSE(include_subdomains);
454 490
455 EXPECT_TRUE(ParseHPKPHeader( 491 EXPECT_TRUE(ParseHPKPHeader(
456 "max-age=39408299 ;" + backup_pin + ";" + good_pin + "; ", 492 "max-age=39408299 ;" + backup_pin + ";" + good_pin + "; ", chain_hashes,
457 chain_hashes, &max_age, &include_subdomains, &hashes)); 493 &max_age, &include_subdomains, &hashes, &report_uri));
458 expect_max_age = base::TimeDelta::FromSeconds( 494 expect_max_age = base::TimeDelta::FromSeconds(
459 std::min(kMaxHSTSAgeSecs, static_cast<int64>(INT64_C(39408299)))); 495 std::min(kMaxHSTSAgeSecs, static_cast<int64>(INT64_C(39408299))));
460 EXPECT_EQ(expect_max_age, max_age); 496 EXPECT_EQ(expect_max_age, max_age);
461 EXPECT_FALSE(include_subdomains); 497 EXPECT_FALSE(include_subdomains);
462 498
463 EXPECT_TRUE(ParseHPKPHeader( 499 EXPECT_TRUE(ParseHPKPHeader(
464 "max-age=39408038 ; cybers=39408038 ; includeSubdomains; " + 500 "max-age=39408038 ; cybers=39408038 ; includeSubdomains; " +
465 good_pin + ";" + backup_pin + "; ", 501 good_pin + ";" + backup_pin + "; ",
466 chain_hashes, &max_age, &include_subdomains, &hashes)); 502 chain_hashes, &max_age, &include_subdomains, &hashes, &report_uri));
467 expect_max_age = base::TimeDelta::FromSeconds( 503 expect_max_age = base::TimeDelta::FromSeconds(
468 std::min(kMaxHSTSAgeSecs, static_cast<int64>(INT64_C(394082038)))); 504 std::min(kMaxHSTSAgeSecs, static_cast<int64>(INT64_C(394082038))));
469 EXPECT_EQ(expect_max_age, max_age); 505 EXPECT_EQ(expect_max_age, max_age);
470 EXPECT_TRUE(include_subdomains); 506 EXPECT_TRUE(include_subdomains);
471 507
472 EXPECT_TRUE(ParseHPKPHeader( 508 EXPECT_TRUE(ParseHPKPHeader(" max-age=0 ; " + good_pin + ";" + backup_pin,
473 " max-age=0 ; " + good_pin + ";" + backup_pin, 509 chain_hashes, &max_age, &include_subdomains,
474 chain_hashes, &max_age, &include_subdomains, &hashes)); 510 &hashes, &report_uri));
475 expect_max_age = base::TimeDelta::FromSeconds(0); 511 expect_max_age = base::TimeDelta::FromSeconds(0);
476 EXPECT_EQ(expect_max_age, max_age); 512 EXPECT_EQ(expect_max_age, max_age);
477 EXPECT_FALSE(include_subdomains); 513 EXPECT_FALSE(include_subdomains);
478 514
479 EXPECT_TRUE(ParseHPKPHeader( 515 EXPECT_TRUE(ParseHPKPHeader(
480 " max-age=0 ; includeSubdomains; " + good_pin + ";" + backup_pin, 516 " max-age=0 ; includeSubdomains; " + good_pin + ";" + backup_pin,
481 chain_hashes, &max_age, &include_subdomains, &hashes)); 517 chain_hashes, &max_age, &include_subdomains, &hashes, &report_uri));
482 expect_max_age = base::TimeDelta::FromSeconds(0); 518 expect_max_age = base::TimeDelta::FromSeconds(0);
483 EXPECT_EQ(expect_max_age, max_age); 519 EXPECT_EQ(expect_max_age, max_age);
484 EXPECT_TRUE(include_subdomains); 520 EXPECT_TRUE(include_subdomains);
485 521
486 EXPECT_TRUE(ParseHPKPHeader( 522 EXPECT_TRUE(ParseHPKPHeader(
487 " max-age=999999999999999999999999999999999999999999999 ; " + 523 " max-age=999999999999999999999999999999999999999999999 ; " +
488 backup_pin + ";" + good_pin + "; ", 524 backup_pin + ";" + good_pin + "; ",
489 chain_hashes, &max_age, &include_subdomains, &hashes)); 525 chain_hashes, &max_age, &include_subdomains, &hashes, &report_uri));
490 expect_max_age = base::TimeDelta::FromSeconds(kMaxHSTSAgeSecs); 526 expect_max_age = base::TimeDelta::FromSeconds(kMaxHSTSAgeSecs);
491 EXPECT_EQ(expect_max_age, max_age); 527 EXPECT_EQ(expect_max_age, max_age);
492 EXPECT_FALSE(include_subdomains); 528 EXPECT_FALSE(include_subdomains);
493 529
530 EXPECT_TRUE(ParseHPKPHeader(
531 " max-age=999999999999999999999999999999999999999999999 ; " +
532 backup_pin + ";" + good_pin + "; report-uri=\"/foo\"",
533 chain_hashes, &max_age, &include_subdomains, &hashes, &report_uri));
534 expect_max_age = base::TimeDelta::FromSeconds(kMaxHSTSAgeSecs);
535 expect_report_uri = "/foo";
536 EXPECT_EQ(expect_max_age, max_age);
537 EXPECT_FALSE(include_subdomains);
538 EXPECT_EQ(expect_report_uri, report_uri);
539
494 // Test that parsing a different header resets the hashes. 540 // Test that parsing a different header resets the hashes.
495 hashes.clear(); 541 hashes.clear();
496 EXPECT_TRUE(ParseHPKPHeader( 542 EXPECT_TRUE(ParseHPKPHeader(
497 " max-age=999; " + 543 " max-age=999; " + backup_pin + ";" + good_pin + "; ", chain_hashes,
498 backup_pin + ";" + good_pin + "; ", 544 &max_age, &include_subdomains, &hashes, &report_uri));
499 chain_hashes, &max_age, &include_subdomains, &hashes));
500 EXPECT_EQ(2u, hashes.size()); 545 EXPECT_EQ(2u, hashes.size());
501 EXPECT_TRUE(ParseHPKPHeader( 546 EXPECT_TRUE(ParseHPKPHeader(
502 " max-age=999; " + backup_pin + ";" + good_pin2 + "; ", chain_hashes, 547 " max-age=999; " + backup_pin + ";" + good_pin2 + "; ", chain_hashes,
503 &max_age, &include_subdomains, &hashes)); 548 &max_age, &include_subdomains, &hashes, &report_uri));
504 EXPECT_EQ(2u, hashes.size()); 549 EXPECT_EQ(2u, hashes.size());
550
551 // Test that the parser correctly parses an unencoded ';' inside a
552 // quoted report-uri.
553 EXPECT_TRUE(ParseHPKPHeader("max-age=999; " + backup_pin + "; " + good_pin +
554 "; report-uri=\"http://foo;bar\"",
555 chain_hashes, &max_age, &include_subdomains,
556 &hashes, &report_uri));
557 expect_max_age = base::TimeDelta::FromSeconds(999);
558 expect_report_uri = "http://foo;bar";
559 EXPECT_EQ(expect_max_age, max_age);
560 EXPECT_FALSE(include_subdomains);
561 EXPECT_EQ(expect_report_uri, report_uri);
562
563 // Test that the parser correctly parses a report-uri with a >0x7f
564 // character.
565 expect_report_uri = "http://foo";
566 expect_report_uri += char(0x7f);
567 EXPECT_TRUE(ParseHPKPHeader("max-age=999; " + backup_pin + "; " + good_pin +
568 "; report-uri=\"" + expect_report_uri + "\"",
569 chain_hashes, &max_age, &include_subdomains,
570 &hashes, &report_uri));
571 expect_max_age = base::TimeDelta::FromSeconds(999);
572 EXPECT_EQ(expect_max_age, max_age);
573 EXPECT_FALSE(include_subdomains);
574 EXPECT_EQ(expect_report_uri, report_uri);
505 } 575 }
506 576
507 TEST_F(HttpSecurityHeadersTest, BogusPinsHeadersSHA1) { 577 TEST_F(HttpSecurityHeadersTest, BogusPinsHeadersSHA1) {
508 TestBogusPinsHeaders(HASH_VALUE_SHA1); 578 TestBogusPinsHeaders(HASH_VALUE_SHA1);
509 } 579 }
510 580
511 TEST_F(HttpSecurityHeadersTest, BogusPinsHeadersSHA256) { 581 TEST_F(HttpSecurityHeadersTest, BogusPinsHeadersSHA256) {
512 TestBogusPinsHeaders(HASH_VALUE_SHA256); 582 TestBogusPinsHeaders(HASH_VALUE_SHA256);
513 } 583 }
514 584
(...skipping 15 matching lines...) Expand all
530 EXPECT_TRUE( 600 EXPECT_TRUE(
531 state.GetStaticDomainState(domain, &static_domain_state)); 601 state.GetStaticDomainState(domain, &static_domain_state));
532 EXPECT_GT(static_domain_state.pkp.spki_hashes.size(), 1UL); 602 EXPECT_GT(static_domain_state.pkp.spki_hashes.size(), 1UL);
533 HashValueVector saved_hashes = static_domain_state.pkp.spki_hashes; 603 HashValueVector saved_hashes = static_domain_state.pkp.spki_hashes;
534 604
535 // Add a header, which should only update the dynamic state. 605 // Add a header, which should only update the dynamic state.
536 HashValue good_hash = GetTestHashValue(1, HASH_VALUE_SHA1); 606 HashValue good_hash = GetTestHashValue(1, HASH_VALUE_SHA1);
537 HashValue backup_hash = GetTestHashValue(2, HASH_VALUE_SHA1); 607 HashValue backup_hash = GetTestHashValue(2, HASH_VALUE_SHA1);
538 std::string good_pin = GetTestPin(1, HASH_VALUE_SHA1); 608 std::string good_pin = GetTestPin(1, HASH_VALUE_SHA1);
539 std::string backup_pin = GetTestPin(2, HASH_VALUE_SHA1); 609 std::string backup_pin = GetTestPin(2, HASH_VALUE_SHA1);
540 std::string header = "max-age = 10000; " + good_pin + "; " + backup_pin; 610 std::string report_uri = "http://google.com";
611 std::string header = "max-age = 10000; " + good_pin + "; " + backup_pin +
612 ";report-uri=\"" + report_uri + "\"";
541 613
542 // Construct a fake SSLInfo that will pass AddHPKPHeader's checks. 614 // Construct a fake SSLInfo that will pass AddHPKPHeader's checks.
543 SSLInfo ssl_info; 615 SSLInfo ssl_info;
544 ssl_info.public_key_hashes.push_back(good_hash); 616 ssl_info.public_key_hashes.push_back(good_hash);
545 ssl_info.public_key_hashes.push_back(saved_hashes[0]); 617 ssl_info.public_key_hashes.push_back(saved_hashes[0]);
546 EXPECT_TRUE(state.AddHPKPHeader(domain, header, ssl_info)); 618 EXPECT_TRUE(state.AddHPKPHeader(domain, header, ssl_info));
547 619
548 // Expect the static state to remain unchanged. 620 // Expect the static state to remain unchanged.
549 TransportSecurityState::DomainState new_static_domain_state; 621 TransportSecurityState::DomainState new_static_domain_state;
550 EXPECT_TRUE(state.GetStaticDomainState( 622 EXPECT_TRUE(state.GetStaticDomainState(
551 domain, &new_static_domain_state)); 623 domain, &new_static_domain_state));
552 for (size_t i = 0; i < saved_hashes.size(); ++i) { 624 for (size_t i = 0; i < saved_hashes.size(); ++i) {
553 EXPECT_TRUE(HashValuesEqual(saved_hashes[i])( 625 EXPECT_TRUE(HashValuesEqual(saved_hashes[i])(
554 new_static_domain_state.pkp.spki_hashes[i])); 626 new_static_domain_state.pkp.spki_hashes[i]));
555 } 627 }
556 628
557 // Expect the dynamic state to reflect the header. 629 // Expect the dynamic state to reflect the header.
558 TransportSecurityState::DomainState dynamic_domain_state; 630 TransportSecurityState::DomainState dynamic_domain_state;
559 EXPECT_TRUE(state.GetDynamicDomainState(domain, &dynamic_domain_state)); 631 EXPECT_TRUE(state.GetDynamicDomainState(domain, &dynamic_domain_state));
560 EXPECT_EQ(2UL, dynamic_domain_state.pkp.spki_hashes.size()); 632 EXPECT_EQ(2UL, dynamic_domain_state.pkp.spki_hashes.size());
633 EXPECT_EQ(report_uri, dynamic_domain_state.pkp.report_uri);
561 634
562 HashValueVector::const_iterator hash = 635 HashValueVector::const_iterator hash =
563 std::find_if(dynamic_domain_state.pkp.spki_hashes.begin(), 636 std::find_if(dynamic_domain_state.pkp.spki_hashes.begin(),
564 dynamic_domain_state.pkp.spki_hashes.end(), 637 dynamic_domain_state.pkp.spki_hashes.end(),
565 HashValuesEqual(good_hash)); 638 HashValuesEqual(good_hash));
566 EXPECT_NE(dynamic_domain_state.pkp.spki_hashes.end(), hash); 639 EXPECT_NE(dynamic_domain_state.pkp.spki_hashes.end(), hash);
567 640
568 hash = std::find_if(dynamic_domain_state.pkp.spki_hashes.begin(), 641 hash = std::find_if(dynamic_domain_state.pkp.spki_hashes.begin(),
569 dynamic_domain_state.pkp.spki_hashes.end(), 642 dynamic_domain_state.pkp.spki_hashes.end(),
570 HashValuesEqual(backup_hash)); 643 HashValuesEqual(backup_hash));
571 EXPECT_NE(dynamic_domain_state.pkp.spki_hashes.end(), hash); 644 EXPECT_NE(dynamic_domain_state.pkp.spki_hashes.end(), hash);
572 645
573 // Expect the overall state to reflect the header, too. 646 // Expect the overall state to reflect the header, too.
574 EXPECT_TRUE(state.HasPublicKeyPins(domain)); 647 EXPECT_TRUE(state.HasPublicKeyPins(domain));
575 HashValueVector hashes; 648 HashValueVector hashes;
576 hashes.push_back(good_hash); 649 hashes.push_back(good_hash);
577 std::string failure_log; 650 std::string failure_log;
578 const bool is_issued_by_known_root = true; 651 const bool is_issued_by_known_root = true;
579 EXPECT_TRUE(state.CheckPublicKeyPins( 652 EXPECT_TRUE(state.CheckPublicKeyPins(
580 domain, is_issued_by_known_root, hashes, &failure_log)); 653 domain, is_issued_by_known_root, hashes, &failure_log));
581 654
582 TransportSecurityState::DomainState new_dynamic_domain_state; 655 TransportSecurityState::DomainState new_dynamic_domain_state;
583 EXPECT_TRUE(state.GetDynamicDomainState(domain, &new_dynamic_domain_state)); 656 EXPECT_TRUE(state.GetDynamicDomainState(domain, &new_dynamic_domain_state));
584 EXPECT_EQ(2UL, new_dynamic_domain_state.pkp.spki_hashes.size()); 657 EXPECT_EQ(2UL, new_dynamic_domain_state.pkp.spki_hashes.size());
658 EXPECT_EQ(report_uri, dynamic_domain_state.pkp.report_uri);
585 659
586 hash = std::find_if(new_dynamic_domain_state.pkp.spki_hashes.begin(), 660 hash = std::find_if(new_dynamic_domain_state.pkp.spki_hashes.begin(),
587 new_dynamic_domain_state.pkp.spki_hashes.end(), 661 new_dynamic_domain_state.pkp.spki_hashes.end(),
588 HashValuesEqual(good_hash)); 662 HashValuesEqual(good_hash));
589 EXPECT_NE(new_dynamic_domain_state.pkp.spki_hashes.end(), hash); 663 EXPECT_NE(new_dynamic_domain_state.pkp.spki_hashes.end(), hash);
590 664
591 hash = std::find_if(new_dynamic_domain_state.pkp.spki_hashes.begin(), 665 hash = std::find_if(new_dynamic_domain_state.pkp.spki_hashes.begin(),
592 new_dynamic_domain_state.pkp.spki_hashes.end(), 666 new_dynamic_domain_state.pkp.spki_hashes.end(),
593 HashValuesEqual(backup_hash)); 667 HashValuesEqual(backup_hash));
594 EXPECT_NE(new_dynamic_domain_state.pkp.spki_hashes.end(), hash); 668 EXPECT_NE(new_dynamic_domain_state.pkp.spki_hashes.end(), hash);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 ssl_info)); 835 ssl_info));
762 836
763 // The old pins must still exist. 837 // The old pins must still exist.
764 EXPECT_TRUE(state.HasPublicKeyPins("example.com")); 838 EXPECT_TRUE(state.HasPublicKeyPins("example.com"));
765 EXPECT_TRUE(state.CheckPublicKeyPins("example.com", is_issued_by_known_root, 839 EXPECT_TRUE(state.CheckPublicKeyPins("example.com", is_issued_by_known_root,
766 ssl_info.public_key_hashes, 840 ssl_info.public_key_hashes,
767 &failure_log)); 841 &failure_log));
768 } 842 }
769 843
770 }; // namespace net 844 }; // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698