| OLD | NEW |
| 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include "base/base64.h" | 9 #include "base/base64.h" |
| 8 #include "base/sha1.h" | 10 #include "base/sha1.h" |
| 9 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 10 #include "crypto/sha2.h" | 12 #include "crypto/sha2.h" |
| 11 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 12 #include "net/http/http_security_headers.h" | 14 #include "net/http/http_security_headers.h" |
| 13 #include "net/http/http_util.h" | 15 #include "net/http/http_util.h" |
| 14 #include "net/http/transport_security_state.h" | 16 #include "net/http/transport_security_state.h" |
| 15 #include "net/log/net_log.h" | 17 #include "net/log/net_log.h" |
| 16 #include "net/ssl/ssl_info.h" | 18 #include "net/ssl/ssl_info.h" |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 EXPECT_TRUE(ParseHSTSHeader("max-age=394082; incLudesUbdOmains", | 325 EXPECT_TRUE(ParseHSTSHeader("max-age=394082; incLudesUbdOmains", |
| 324 &max_age, &include_subdomains)); | 326 &max_age, &include_subdomains)); |
| 325 expect_max_age = base::TimeDelta::FromSeconds(394082); | 327 expect_max_age = base::TimeDelta::FromSeconds(394082); |
| 326 EXPECT_EQ(expect_max_age, max_age); | 328 EXPECT_EQ(expect_max_age, max_age); |
| 327 EXPECT_TRUE(include_subdomains); | 329 EXPECT_TRUE(include_subdomains); |
| 328 | 330 |
| 329 EXPECT_TRUE(ParseHSTSHeader( | 331 EXPECT_TRUE(ParseHSTSHeader( |
| 330 "max-age=39408299 ;incLudesUbdOmains", &max_age, | 332 "max-age=39408299 ;incLudesUbdOmains", &max_age, |
| 331 &include_subdomains)); | 333 &include_subdomains)); |
| 332 expect_max_age = base::TimeDelta::FromSeconds( | 334 expect_max_age = base::TimeDelta::FromSeconds( |
| 333 std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(39408299)))); | 335 std::min(kMaxHSTSAgeSecs, static_cast<int64>(INT64_C(39408299)))); |
| 334 EXPECT_EQ(expect_max_age, max_age); | 336 EXPECT_EQ(expect_max_age, max_age); |
| 335 EXPECT_TRUE(include_subdomains); | 337 EXPECT_TRUE(include_subdomains); |
| 336 | 338 |
| 337 EXPECT_TRUE(ParseHSTSHeader( | 339 EXPECT_TRUE(ParseHSTSHeader( |
| 338 "max-age=394082038 ; incLudesUbdOmains", &max_age, | 340 "max-age=394082038 ; incLudesUbdOmains", &max_age, |
| 339 &include_subdomains)); | 341 &include_subdomains)); |
| 340 expect_max_age = base::TimeDelta::FromSeconds( | 342 expect_max_age = base::TimeDelta::FromSeconds( |
| 341 std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038)))); | 343 std::min(kMaxHSTSAgeSecs, static_cast<int64>(INT64_C(394082038)))); |
| 342 EXPECT_EQ(expect_max_age, max_age); | 344 EXPECT_EQ(expect_max_age, max_age); |
| 343 EXPECT_TRUE(include_subdomains); | 345 EXPECT_TRUE(include_subdomains); |
| 344 | 346 |
| 345 EXPECT_TRUE(ParseHSTSHeader( | 347 EXPECT_TRUE(ParseHSTSHeader( |
| 346 "max-age=394082038 ; incLudesUbdOmains;", &max_age, | 348 "max-age=394082038 ; incLudesUbdOmains;", &max_age, |
| 347 &include_subdomains)); | 349 &include_subdomains)); |
| 348 expect_max_age = base::TimeDelta::FromSeconds( | 350 expect_max_age = base::TimeDelta::FromSeconds( |
| 349 std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038)))); | 351 std::min(kMaxHSTSAgeSecs, static_cast<int64>(INT64_C(394082038)))); |
| 350 EXPECT_EQ(expect_max_age, max_age); | 352 EXPECT_EQ(expect_max_age, max_age); |
| 351 EXPECT_TRUE(include_subdomains); | 353 EXPECT_TRUE(include_subdomains); |
| 352 | 354 |
| 353 EXPECT_TRUE(ParseHSTSHeader( | 355 EXPECT_TRUE(ParseHSTSHeader( |
| 354 ";; max-age=394082038 ; incLudesUbdOmains; ;", &max_age, | 356 ";; max-age=394082038 ; incLudesUbdOmains; ;", &max_age, |
| 355 &include_subdomains)); | 357 &include_subdomains)); |
| 356 expect_max_age = base::TimeDelta::FromSeconds( | 358 expect_max_age = base::TimeDelta::FromSeconds( |
| 357 std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038)))); | 359 std::min(kMaxHSTSAgeSecs, static_cast<int64>(INT64_C(394082038)))); |
| 358 EXPECT_EQ(expect_max_age, max_age); | 360 EXPECT_EQ(expect_max_age, max_age); |
| 359 EXPECT_TRUE(include_subdomains); | 361 EXPECT_TRUE(include_subdomains); |
| 360 | 362 |
| 361 EXPECT_TRUE(ParseHSTSHeader( | 363 EXPECT_TRUE(ParseHSTSHeader( |
| 362 ";; max-age=394082038 ;", &max_age, | 364 ";; max-age=394082038 ;", &max_age, |
| 363 &include_subdomains)); | 365 &include_subdomains)); |
| 364 expect_max_age = base::TimeDelta::FromSeconds( | 366 expect_max_age = base::TimeDelta::FromSeconds( |
| 365 std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038)))); | 367 std::min(kMaxHSTSAgeSecs, static_cast<int64>(INT64_C(394082038)))); |
| 366 EXPECT_EQ(expect_max_age, max_age); | 368 EXPECT_EQ(expect_max_age, max_age); |
| 367 EXPECT_FALSE(include_subdomains); | 369 EXPECT_FALSE(include_subdomains); |
| 368 | 370 |
| 369 EXPECT_TRUE(ParseHSTSHeader( | 371 EXPECT_TRUE(ParseHSTSHeader( |
| 370 ";; ; ; max-age=394082038;;; includeSubdomains ;; ;", &max_age, | 372 ";; ; ; max-age=394082038;;; includeSubdomains ;; ;", &max_age, |
| 371 &include_subdomains)); | 373 &include_subdomains)); |
| 372 expect_max_age = base::TimeDelta::FromSeconds( | 374 expect_max_age = base::TimeDelta::FromSeconds( |
| 373 std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038)))); | 375 std::min(kMaxHSTSAgeSecs, static_cast<int64>(INT64_C(394082038)))); |
| 374 EXPECT_EQ(expect_max_age, max_age); | 376 EXPECT_EQ(expect_max_age, max_age); |
| 375 EXPECT_TRUE(include_subdomains); | 377 EXPECT_TRUE(include_subdomains); |
| 376 | 378 |
| 377 EXPECT_TRUE(ParseHSTSHeader( | 379 EXPECT_TRUE(ParseHSTSHeader( |
| 378 "incLudesUbdOmains ; max-age=394082038 ;;", &max_age, | 380 "incLudesUbdOmains ; max-age=394082038 ;;", &max_age, |
| 379 &include_subdomains)); | 381 &include_subdomains)); |
| 380 expect_max_age = base::TimeDelta::FromSeconds( | 382 expect_max_age = base::TimeDelta::FromSeconds( |
| 381 std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038)))); | 383 std::min(kMaxHSTSAgeSecs, static_cast<int64>(INT64_C(394082038)))); |
| 382 EXPECT_EQ(expect_max_age, max_age); | 384 EXPECT_EQ(expect_max_age, max_age); |
| 383 EXPECT_TRUE(include_subdomains); | 385 EXPECT_TRUE(include_subdomains); |
| 384 | 386 |
| 385 EXPECT_TRUE(ParseHSTSHeader( | 387 EXPECT_TRUE(ParseHSTSHeader( |
| 386 " max-age=0 ; incLudesUbdOmains ", &max_age, | 388 " max-age=0 ; incLudesUbdOmains ", &max_age, |
| 387 &include_subdomains)); | 389 &include_subdomains)); |
| 388 expect_max_age = base::TimeDelta::FromSeconds(0); | 390 expect_max_age = base::TimeDelta::FromSeconds(0); |
| 389 EXPECT_EQ(expect_max_age, max_age); | 391 EXPECT_EQ(expect_max_age, max_age); |
| 390 EXPECT_TRUE(include_subdomains); | 392 EXPECT_TRUE(include_subdomains); |
| 391 | 393 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 "max-age=394082;" + backup_pin + ";" + good_pin + "; ", | 450 "max-age=394082;" + backup_pin + ";" + good_pin + "; ", |
| 449 chain_hashes, &max_age, &include_subdomains, &hashes)); | 451 chain_hashes, &max_age, &include_subdomains, &hashes)); |
| 450 expect_max_age = base::TimeDelta::FromSeconds(394082); | 452 expect_max_age = base::TimeDelta::FromSeconds(394082); |
| 451 EXPECT_EQ(expect_max_age, max_age); | 453 EXPECT_EQ(expect_max_age, max_age); |
| 452 EXPECT_FALSE(include_subdomains); | 454 EXPECT_FALSE(include_subdomains); |
| 453 | 455 |
| 454 EXPECT_TRUE(ParseHPKPHeader( | 456 EXPECT_TRUE(ParseHPKPHeader( |
| 455 "max-age=39408299 ;" + backup_pin + ";" + good_pin + "; ", | 457 "max-age=39408299 ;" + backup_pin + ";" + good_pin + "; ", |
| 456 chain_hashes, &max_age, &include_subdomains, &hashes)); | 458 chain_hashes, &max_age, &include_subdomains, &hashes)); |
| 457 expect_max_age = base::TimeDelta::FromSeconds( | 459 expect_max_age = base::TimeDelta::FromSeconds( |
| 458 std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(39408299)))); | 460 std::min(kMaxHSTSAgeSecs, static_cast<int64>(INT64_C(39408299)))); |
| 459 EXPECT_EQ(expect_max_age, max_age); | 461 EXPECT_EQ(expect_max_age, max_age); |
| 460 EXPECT_FALSE(include_subdomains); | 462 EXPECT_FALSE(include_subdomains); |
| 461 | 463 |
| 462 EXPECT_TRUE(ParseHPKPHeader( | 464 EXPECT_TRUE(ParseHPKPHeader( |
| 463 "max-age=39408038 ; cybers=39408038 ; includeSubdomains; " + | 465 "max-age=39408038 ; cybers=39408038 ; includeSubdomains; " + |
| 464 good_pin + ";" + backup_pin + "; ", | 466 good_pin + ";" + backup_pin + "; ", |
| 465 chain_hashes, &max_age, &include_subdomains, &hashes)); | 467 chain_hashes, &max_age, &include_subdomains, &hashes)); |
| 466 expect_max_age = base::TimeDelta::FromSeconds( | 468 expect_max_age = base::TimeDelta::FromSeconds( |
| 467 std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038)))); | 469 std::min(kMaxHSTSAgeSecs, static_cast<int64>(INT64_C(394082038)))); |
| 468 EXPECT_EQ(expect_max_age, max_age); | 470 EXPECT_EQ(expect_max_age, max_age); |
| 469 EXPECT_TRUE(include_subdomains); | 471 EXPECT_TRUE(include_subdomains); |
| 470 | 472 |
| 471 EXPECT_TRUE(ParseHPKPHeader( | 473 EXPECT_TRUE(ParseHPKPHeader( |
| 472 " max-age=0 ; " + good_pin + ";" + backup_pin, | 474 " max-age=0 ; " + good_pin + ";" + backup_pin, |
| 473 chain_hashes, &max_age, &include_subdomains, &hashes)); | 475 chain_hashes, &max_age, &include_subdomains, &hashes)); |
| 474 expect_max_age = base::TimeDelta::FromSeconds(0); | 476 expect_max_age = base::TimeDelta::FromSeconds(0); |
| 475 EXPECT_EQ(expect_max_age, max_age); | 477 EXPECT_EQ(expect_max_age, max_age); |
| 476 EXPECT_FALSE(include_subdomains); | 478 EXPECT_FALSE(include_subdomains); |
| 477 | 479 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 ssl_info)); | 762 ssl_info)); |
| 761 | 763 |
| 762 // The old pins must still exist. | 764 // The old pins must still exist. |
| 763 EXPECT_TRUE(state.HasPublicKeyPins("example.com")); | 765 EXPECT_TRUE(state.HasPublicKeyPins("example.com")); |
| 764 EXPECT_TRUE(state.CheckPublicKeyPins("example.com", is_issued_by_known_root, | 766 EXPECT_TRUE(state.CheckPublicKeyPins("example.com", is_issued_by_known_root, |
| 765 ssl_info.public_key_hashes, | 767 ssl_info.public_key_hashes, |
| 766 &failure_log)); | 768 &failure_log)); |
| 767 } | 769 } |
| 768 | 770 |
| 769 }; // namespace net | 771 }; // namespace net |
| OLD | NEW |