OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include <cstdint> | 6 #include <cstdint> |
7 #include <memory> | 7 #include <memory> |
8 #include <ostream> | 8 #include <ostream> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 return params; | 100 return params; |
101 } | 101 } |
102 | 102 |
103 class CryptoServerTest : public ::testing::TestWithParam<TestParams> { | 103 class CryptoServerTest : public ::testing::TestWithParam<TestParams> { |
104 public: | 104 public: |
105 CryptoServerTest() | 105 CryptoServerTest() |
106 : rand_(QuicRandom::GetInstance()), | 106 : rand_(QuicRandom::GetInstance()), |
107 client_address_(QuicIpAddress::Loopback4(), 1234), | 107 client_address_(QuicIpAddress::Loopback4(), 1234), |
108 config_(QuicCryptoServerConfig::TESTING, | 108 config_(QuicCryptoServerConfig::TESTING, |
109 rand_, | 109 rand_, |
110 CryptoTestUtils::ProofSourceForTesting()), | 110 crypto_test_utils::ProofSourceForTesting()), |
111 peer_(&config_), | 111 peer_(&config_), |
112 compressed_certs_cache_( | 112 compressed_certs_cache_( |
113 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize), | 113 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize), |
114 params_(new QuicCryptoNegotiatedParameters), | 114 params_(new QuicCryptoNegotiatedParameters), |
115 signed_config_(new QuicSignedServerConfig), | 115 signed_config_(new QuicSignedServerConfig), |
116 chlo_packet_size_(kDefaultMaxPacketSize) { | 116 chlo_packet_size_(kDefaultMaxPacketSize) { |
117 supported_versions_ = GetParam().supported_versions; | 117 supported_versions_ = GetParam().supported_versions; |
118 config_.set_enable_serving_sct(true); | 118 config_.set_enable_serving_sct(true); |
119 | 119 |
120 client_version_ = supported_versions_.front(); | 120 client_version_ = supported_versions_.front(); |
(...skipping 22 matching lines...) Expand all Loading... |
143 memcpy(orbit_, orbit.data(), orbit.size()); | 143 memcpy(orbit_, orbit.data(), orbit.size()); |
144 | 144 |
145 char public_value[32]; | 145 char public_value[32]; |
146 memset(public_value, 42, sizeof(public_value)); | 146 memset(public_value, 42, sizeof(public_value)); |
147 | 147 |
148 nonce_hex_ = "#" + QuicTextUtils::HexEncode(GenerateNonce()); | 148 nonce_hex_ = "#" + QuicTextUtils::HexEncode(GenerateNonce()); |
149 pub_hex_ = | 149 pub_hex_ = |
150 "#" + QuicTextUtils::HexEncode(public_value, sizeof(public_value)); | 150 "#" + QuicTextUtils::HexEncode(public_value, sizeof(public_value)); |
151 | 151 |
152 // clang-format off | 152 // clang-format off |
153 CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( | 153 CryptoHandshakeMessage client_hello = crypto_test_utils::Message( |
154 "CHLO", | 154 "CHLO", |
155 "PDMD", "X509", | 155 "PDMD", "X509", |
156 "AEAD", "AESG", | 156 "AEAD", "AESG", |
157 "KEXS", "C255", | 157 "KEXS", "C255", |
158 "PUBS", pub_hex_.c_str(), | 158 "PUBS", pub_hex_.c_str(), |
159 "NONC", nonce_hex_.c_str(), | 159 "NONC", nonce_hex_.c_str(), |
160 "CSCT", "", | 160 "CSCT", "", |
161 "VER\0", client_version_string_.c_str(), | 161 "VER\0", client_version_string_.c_str(), |
162 "$padding", static_cast<int>(kClientHelloMinimumSize), | 162 "$padding", static_cast<int>(kClientHelloMinimumSize), |
163 nullptr); | 163 nullptr); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 ASSERT_EQ(kREJ, out_.tag()) << QuicTagToString(out_.tag()); | 379 ASSERT_EQ(kREJ, out_.tag()) << QuicTagToString(out_.tag()); |
380 } | 380 } |
381 } | 381 } |
382 | 382 |
383 bool RejectsAreStateless() { | 383 bool RejectsAreStateless() { |
384 return GetParam().enable_stateless_rejects && | 384 return GetParam().enable_stateless_rejects && |
385 GetParam().use_stateless_rejects; | 385 GetParam().use_stateless_rejects; |
386 } | 386 } |
387 | 387 |
388 string XlctHexString() { | 388 string XlctHexString() { |
389 uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting(); | 389 uint64_t xlct = crypto_test_utils::LeafCertHashForTesting(); |
390 return "#" + QuicTextUtils::HexEncode(reinterpret_cast<char*>(&xlct), | 390 return "#" + QuicTextUtils::HexEncode(reinterpret_cast<char*>(&xlct), |
391 sizeof(xlct)); | 391 sizeof(xlct)); |
392 } | 392 } |
393 | 393 |
394 protected: | 394 protected: |
395 QuicFlagSaver flags_; // Save/restore all QUIC flag values. | 395 QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
396 QuicRandom* const rand_; | 396 QuicRandom* const rand_; |
397 MockRandom rand_for_id_generation_; | 397 MockRandom rand_for_id_generation_; |
398 MockClock clock_; | 398 MockClock clock_; |
399 QuicSocketAddress client_address_; | 399 QuicSocketAddress client_address_; |
(...skipping 28 matching lines...) Expand all Loading... |
428 "foo", | 428 "foo", |
429 "#00", | 429 "#00", |
430 "#ff00", | 430 "#ff00", |
431 "127.0.0.1", | 431 "127.0.0.1", |
432 "ffee::1", | 432 "ffee::1", |
433 }; | 433 }; |
434 // clang-format on | 434 // clang-format on |
435 | 435 |
436 for (size_t i = 0; i < arraysize(kBadSNIs); i++) { | 436 for (size_t i = 0; i < arraysize(kBadSNIs); i++) { |
437 // clang-format off | 437 // clang-format off |
438 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 438 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
439 "CHLO", | 439 "CHLO", |
440 "PDMD", "X509", | 440 "PDMD", "X509", |
441 "SNI", kBadSNIs[i], | 441 "SNI", kBadSNIs[i], |
442 "VER\0", client_version_string_.c_str(), | 442 "VER\0", client_version_string_.c_str(), |
443 "$padding", static_cast<int>(kClientHelloMinimumSize), | 443 "$padding", static_cast<int>(kClientHelloMinimumSize), |
444 nullptr); | 444 nullptr); |
445 // clang-format on | 445 // clang-format on |
446 ShouldFailMentioning("SNI", msg); | 446 ShouldFailMentioning("SNI", msg); |
447 const HandshakeFailureReason kRejectReasons[] = { | 447 const HandshakeFailureReason kRejectReasons[] = { |
448 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; | 448 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; |
449 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 449 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
450 } | 450 } |
451 } | 451 } |
452 | 452 |
453 TEST_P(CryptoServerTest, DefaultCert) { | 453 TEST_P(CryptoServerTest, DefaultCert) { |
454 // Check that the server replies with a default certificate when no SNI is | 454 // Check that the server replies with a default certificate when no SNI is |
455 // specified. The CHLO is constructed to generate a REJ with certs, so must | 455 // specified. The CHLO is constructed to generate a REJ with certs, so must |
456 // not contain a valid STK, and must include PDMD. | 456 // not contain a valid STK, and must include PDMD. |
457 // clang-format off | 457 // clang-format off |
458 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 458 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
459 "CHLO", | 459 "CHLO", |
460 "AEAD", "AESG", | 460 "AEAD", "AESG", |
461 "KEXS", "C255", | 461 "KEXS", "C255", |
462 "PUBS", pub_hex_.c_str(), | 462 "PUBS", pub_hex_.c_str(), |
463 "NONC", nonce_hex_.c_str(), | 463 "NONC", nonce_hex_.c_str(), |
464 "PDMD", "X509", | 464 "PDMD", "X509", |
465 "VER\0", client_version_string_.c_str(), | 465 "VER\0", client_version_string_.c_str(), |
466 "$padding", static_cast<int>(kClientHelloMinimumSize), | 466 "$padding", static_cast<int>(kClientHelloMinimumSize), |
467 nullptr); | 467 nullptr); |
468 // clang-format on | 468 // clang-format on |
469 | 469 |
470 ShouldSucceed(msg); | 470 ShouldSucceed(msg); |
471 StringPiece cert, proof, cert_sct; | 471 StringPiece cert, proof, cert_sct; |
472 EXPECT_TRUE(out_.GetStringPiece(kCertificateTag, &cert)); | 472 EXPECT_TRUE(out_.GetStringPiece(kCertificateTag, &cert)); |
473 EXPECT_TRUE(out_.GetStringPiece(kPROF, &proof)); | 473 EXPECT_TRUE(out_.GetStringPiece(kPROF, &proof)); |
474 EXPECT_TRUE(out_.GetStringPiece(kCertificateSCTTag, &cert_sct)); | 474 EXPECT_TRUE(out_.GetStringPiece(kCertificateSCTTag, &cert_sct)); |
475 EXPECT_NE(0u, cert.size()); | 475 EXPECT_NE(0u, cert.size()); |
476 EXPECT_NE(0u, proof.size()); | 476 EXPECT_NE(0u, proof.size()); |
477 const HandshakeFailureReason kRejectReasons[] = { | 477 const HandshakeFailureReason kRejectReasons[] = { |
478 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; | 478 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; |
479 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 479 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
480 EXPECT_LT(0u, cert_sct.size()); | 480 EXPECT_LT(0u, cert_sct.size()); |
481 } | 481 } |
482 | 482 |
483 TEST_P(CryptoServerTest, RejectTooLarge) { | 483 TEST_P(CryptoServerTest, RejectTooLarge) { |
484 // Check that the server replies with no certificate when a CHLO is | 484 // Check that the server replies with no certificate when a CHLO is |
485 // constructed with a PDMD but no SKT when the REJ would be too large. | 485 // constructed with a PDMD but no SKT when the REJ would be too large. |
486 // clang-format off | 486 // clang-format off |
487 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 487 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
488 "CHLO", | 488 "CHLO", |
489 "PDMD", "X509", | 489 "PDMD", "X509", |
490 "AEAD", "AESG", | 490 "AEAD", "AESG", |
491 "KEXS", "C255", | 491 "KEXS", "C255", |
492 "PUBS", pub_hex_.c_str(), | 492 "PUBS", pub_hex_.c_str(), |
493 "NONC", nonce_hex_.c_str(), | 493 "NONC", nonce_hex_.c_str(), |
494 "PDMD", "X509", | 494 "PDMD", "X509", |
495 "VER\0", client_version_string_.c_str(), | 495 "VER\0", client_version_string_.c_str(), |
496 "$padding", static_cast<int>(kClientHelloMinimumSize), | 496 "$padding", static_cast<int>(kClientHelloMinimumSize), |
497 nullptr); | 497 nullptr); |
(...skipping 10 matching lines...) Expand all Loading... |
508 const HandshakeFailureReason kRejectReasons[] = { | 508 const HandshakeFailureReason kRejectReasons[] = { |
509 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; | 509 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; |
510 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 510 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
511 } | 511 } |
512 | 512 |
513 TEST_P(CryptoServerTest, RejectNotTooLarge) { | 513 TEST_P(CryptoServerTest, RejectNotTooLarge) { |
514 // When the CHLO packet is large enough, ensure that a full REJ is sent. | 514 // When the CHLO packet is large enough, ensure that a full REJ is sent. |
515 chlo_packet_size_ *= 2; | 515 chlo_packet_size_ *= 2; |
516 | 516 |
517 // clang-format off | 517 // clang-format off |
518 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 518 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
519 "CHLO", | 519 "CHLO", |
520 "PDMD", "X509", | 520 "PDMD", "X509", |
521 "AEAD", "AESG", | 521 "AEAD", "AESG", |
522 "KEXS", "C255", | 522 "KEXS", "C255", |
523 "PUBS", pub_hex_.c_str(), | 523 "PUBS", pub_hex_.c_str(), |
524 "NONC", nonce_hex_.c_str(), | 524 "NONC", nonce_hex_.c_str(), |
525 "PDMD", "X509", | 525 "PDMD", "X509", |
526 "VER\0", client_version_string_.c_str(), | 526 "VER\0", client_version_string_.c_str(), |
527 "$padding", static_cast<int>(kClientHelloMinimumSize), | 527 "$padding", static_cast<int>(kClientHelloMinimumSize), |
528 nullptr); | 528 nullptr); |
529 // clang-format on | 529 // clang-format on |
530 | 530 |
531 // The REJ will be larger than the CHLO so no PROF or CRT will be sent. | 531 // The REJ will be larger than the CHLO so no PROF or CRT will be sent. |
532 config_.set_chlo_multiplier(1); | 532 config_.set_chlo_multiplier(1); |
533 | 533 |
534 ShouldSucceed(msg); | 534 ShouldSucceed(msg); |
535 StringPiece cert, proof, cert_sct; | 535 StringPiece cert, proof, cert_sct; |
536 EXPECT_TRUE(out_.GetStringPiece(kCertificateTag, &cert)); | 536 EXPECT_TRUE(out_.GetStringPiece(kCertificateTag, &cert)); |
537 EXPECT_TRUE(out_.GetStringPiece(kPROF, &proof)); | 537 EXPECT_TRUE(out_.GetStringPiece(kPROF, &proof)); |
538 EXPECT_TRUE(out_.GetStringPiece(kCertificateSCTTag, &cert_sct)); | 538 EXPECT_TRUE(out_.GetStringPiece(kCertificateSCTTag, &cert_sct)); |
539 const HandshakeFailureReason kRejectReasons[] = { | 539 const HandshakeFailureReason kRejectReasons[] = { |
540 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; | 540 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; |
541 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 541 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
542 } | 542 } |
543 | 543 |
544 TEST_P(CryptoServerTest, RejectTooLargeButValidSTK) { | 544 TEST_P(CryptoServerTest, RejectTooLargeButValidSTK) { |
545 // Check that the server replies with no certificate when a CHLO is | 545 // Check that the server replies with no certificate when a CHLO is |
546 // constructed with a PDMD but no SKT when the REJ would be too large. | 546 // constructed with a PDMD but no SKT when the REJ would be too large. |
547 // clang-format off | 547 // clang-format off |
548 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 548 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
549 "CHLO", | 549 "CHLO", |
550 "PDMD", "X509", | 550 "PDMD", "X509", |
551 "AEAD", "AESG", | 551 "AEAD", "AESG", |
552 "KEXS", "C255", | 552 "KEXS", "C255", |
553 "PUBS", pub_hex_.c_str(), | 553 "PUBS", pub_hex_.c_str(), |
554 "NONC", nonce_hex_.c_str(), | 554 "NONC", nonce_hex_.c_str(), |
555 "#004b5453", srct_hex_.c_str(), | 555 "#004b5453", srct_hex_.c_str(), |
556 "PDMD", "X509", | 556 "PDMD", "X509", |
557 "VER\0", client_version_string_.c_str(), | 557 "VER\0", client_version_string_.c_str(), |
558 "$padding", static_cast<int>(kClientHelloMinimumSize), | 558 "$padding", static_cast<int>(kClientHelloMinimumSize), |
(...skipping 10 matching lines...) Expand all Loading... |
569 EXPECT_TRUE(out_.GetStringPiece(kCertificateSCTTag, &cert_sct)); | 569 EXPECT_TRUE(out_.GetStringPiece(kCertificateSCTTag, &cert_sct)); |
570 EXPECT_NE(0u, cert.size()); | 570 EXPECT_NE(0u, cert.size()); |
571 EXPECT_NE(0u, proof.size()); | 571 EXPECT_NE(0u, proof.size()); |
572 const HandshakeFailureReason kRejectReasons[] = { | 572 const HandshakeFailureReason kRejectReasons[] = { |
573 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; | 573 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; |
574 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 574 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
575 } | 575 } |
576 | 576 |
577 TEST_P(CryptoServerTest, TooSmall) { | 577 TEST_P(CryptoServerTest, TooSmall) { |
578 // clang-format off | 578 // clang-format off |
579 ShouldFailMentioning("too small", CryptoTestUtils::Message( | 579 ShouldFailMentioning("too small", crypto_test_utils::Message( |
580 "CHLO", | 580 "CHLO", |
581 "PDMD", "X509", | 581 "PDMD", "X509", |
582 "VER\0", client_version_string_.c_str(), | 582 "VER\0", client_version_string_.c_str(), |
583 nullptr)); | 583 nullptr)); |
584 // clang-format on | 584 // clang-format on |
585 const HandshakeFailureReason kRejectReasons[] = { | 585 const HandshakeFailureReason kRejectReasons[] = { |
586 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; | 586 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; |
587 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 587 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
588 } | 588 } |
589 | 589 |
590 TEST_P(CryptoServerTest, BadSourceAddressToken) { | 590 TEST_P(CryptoServerTest, BadSourceAddressToken) { |
591 // Invalid source-address tokens should be ignored. | 591 // Invalid source-address tokens should be ignored. |
592 // clang-format off | 592 // clang-format off |
593 static const char* const kBadSourceAddressTokens[] = { | 593 static const char* const kBadSourceAddressTokens[] = { |
594 "", | 594 "", |
595 "foo", | 595 "foo", |
596 "#0000", | 596 "#0000", |
597 "#0000000000000000000000000000000000000000", | 597 "#0000000000000000000000000000000000000000", |
598 }; | 598 }; |
599 // clang-format on | 599 // clang-format on |
600 | 600 |
601 for (size_t i = 0; i < arraysize(kBadSourceAddressTokens); i++) { | 601 for (size_t i = 0; i < arraysize(kBadSourceAddressTokens); i++) { |
602 // clang-format off | 602 // clang-format off |
603 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 603 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
604 "CHLO", | 604 "CHLO", |
605 "PDMD", "X509", | 605 "PDMD", "X509", |
606 "STK", kBadSourceAddressTokens[i], | 606 "STK", kBadSourceAddressTokens[i], |
607 "VER\0", client_version_string_.c_str(), | 607 "VER\0", client_version_string_.c_str(), |
608 "$padding", static_cast<int>(kClientHelloMinimumSize), nullptr); | 608 "$padding", static_cast<int>(kClientHelloMinimumSize), nullptr); |
609 // clang-format on | 609 // clang-format on |
610 ShouldSucceed(msg); | 610 ShouldSucceed(msg); |
611 const HandshakeFailureReason kRejectReasons[] = { | 611 const HandshakeFailureReason kRejectReasons[] = { |
612 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; | 612 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; |
613 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 613 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
614 } | 614 } |
615 } | 615 } |
616 | 616 |
617 TEST_P(CryptoServerTest, BadClientNonce) { | 617 TEST_P(CryptoServerTest, BadClientNonce) { |
618 // clang-format off | 618 // clang-format off |
619 static const char* const kBadNonces[] = { | 619 static const char* const kBadNonces[] = { |
620 "", | 620 "", |
621 "#0000", | 621 "#0000", |
622 "#0000000000000000000000000000000000000000", | 622 "#0000000000000000000000000000000000000000", |
623 }; | 623 }; |
624 // clang-format on | 624 // clang-format on |
625 | 625 |
626 for (size_t i = 0; i < arraysize(kBadNonces); i++) { | 626 for (size_t i = 0; i < arraysize(kBadNonces); i++) { |
627 // Invalid nonces should be ignored, in an inchoate CHLO. | 627 // Invalid nonces should be ignored, in an inchoate CHLO. |
628 // clang-format off | 628 // clang-format off |
629 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 629 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
630 "CHLO", | 630 "CHLO", |
631 "PDMD", "X509", | 631 "PDMD", "X509", |
632 "NONC", kBadNonces[i], | 632 "NONC", kBadNonces[i], |
633 "VER\0", client_version_string_.c_str(), | 633 "VER\0", client_version_string_.c_str(), |
634 "$padding", static_cast<int>(kClientHelloMinimumSize), | 634 "$padding", static_cast<int>(kClientHelloMinimumSize), |
635 nullptr); | 635 nullptr); |
636 // clang-format on | 636 // clang-format on |
637 ShouldSucceed(msg); | 637 ShouldSucceed(msg); |
638 const HandshakeFailureReason kRejectReasons[] = { | 638 const HandshakeFailureReason kRejectReasons[] = { |
639 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; | 639 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; |
640 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 640 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
641 | 641 |
642 // Invalid nonces should result in CLIENT_NONCE_INVALID_FAILURE. | 642 // Invalid nonces should result in CLIENT_NONCE_INVALID_FAILURE. |
643 // clang-format off | 643 // clang-format off |
644 CryptoHandshakeMessage msg1 = CryptoTestUtils::Message( | 644 CryptoHandshakeMessage msg1 = crypto_test_utils::Message( |
645 "CHLO", | 645 "CHLO", |
646 "PDMD", "X509", | 646 "PDMD", "X509", |
647 "AEAD", "AESG", | 647 "AEAD", "AESG", |
648 "KEXS", "C255", | 648 "KEXS", "C255", |
649 "SCID", scid_hex_.c_str(), | 649 "SCID", scid_hex_.c_str(), |
650 "#004b5453", srct_hex_.c_str(), | 650 "#004b5453", srct_hex_.c_str(), |
651 "PUBS", pub_hex_.c_str(), | 651 "PUBS", pub_hex_.c_str(), |
652 "NONC", kBadNonces[i], | 652 "NONC", kBadNonces[i], |
653 "NONP", kBadNonces[i], | 653 "NONP", kBadNonces[i], |
654 "XLCT", XlctHexString().c_str(), | 654 "XLCT", XlctHexString().c_str(), |
655 "VER\0", client_version_string_.c_str(), | 655 "VER\0", client_version_string_.c_str(), |
656 "$padding", static_cast<int>(kClientHelloMinimumSize), | 656 "$padding", static_cast<int>(kClientHelloMinimumSize), |
657 nullptr); | 657 nullptr); |
658 // clang-format on | 658 // clang-format on |
659 | 659 |
660 ShouldSucceed(msg1); | 660 ShouldSucceed(msg1); |
661 | 661 |
662 CheckRejectTag(); | 662 CheckRejectTag(); |
663 const HandshakeFailureReason kRejectReasons1[] = { | 663 const HandshakeFailureReason kRejectReasons1[] = { |
664 CLIENT_NONCE_INVALID_FAILURE}; | 664 CLIENT_NONCE_INVALID_FAILURE}; |
665 CheckRejectReasons(kRejectReasons1, arraysize(kRejectReasons1)); | 665 CheckRejectReasons(kRejectReasons1, arraysize(kRejectReasons1)); |
666 } | 666 } |
667 } | 667 } |
668 | 668 |
669 TEST_P(CryptoServerTest, NoClientNonce) { | 669 TEST_P(CryptoServerTest, NoClientNonce) { |
670 // No client nonces should result in INCHOATE_HELLO_FAILURE. | 670 // No client nonces should result in INCHOATE_HELLO_FAILURE. |
671 // clang-format off | 671 // clang-format off |
672 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 672 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
673 "CHLO", | 673 "CHLO", |
674 "PDMD", "X509", | 674 "PDMD", "X509", |
675 "VER\0", client_version_string_.c_str(), | 675 "VER\0", client_version_string_.c_str(), |
676 "$padding", static_cast<int>(kClientHelloMinimumSize), | 676 "$padding", static_cast<int>(kClientHelloMinimumSize), |
677 nullptr); | 677 nullptr); |
678 // clang-format on | 678 // clang-format on |
679 | 679 |
680 ShouldSucceed(msg); | 680 ShouldSucceed(msg); |
681 const HandshakeFailureReason kRejectReasons[] = { | 681 const HandshakeFailureReason kRejectReasons[] = { |
682 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; | 682 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; |
683 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 683 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
684 | 684 |
685 // clang-format off | 685 // clang-format off |
686 CryptoHandshakeMessage msg1 = CryptoTestUtils::Message( | 686 CryptoHandshakeMessage msg1 = crypto_test_utils::Message( |
687 "CHLO", | 687 "CHLO", |
688 "PDMD", "X509", | 688 "PDMD", "X509", |
689 "AEAD", "AESG", | 689 "AEAD", "AESG", |
690 "KEXS", "C255", | 690 "KEXS", "C255", |
691 "SCID", scid_hex_.c_str(), | 691 "SCID", scid_hex_.c_str(), |
692 "#004b5453", srct_hex_.c_str(), | 692 "#004b5453", srct_hex_.c_str(), |
693 "PUBS", pub_hex_.c_str(), | 693 "PUBS", pub_hex_.c_str(), |
694 "XLCT", XlctHexString().c_str(), | 694 "XLCT", XlctHexString().c_str(), |
695 "VER\0", client_version_string_.c_str(), | 695 "VER\0", client_version_string_.c_str(), |
696 "$padding", static_cast<int>(kClientHelloMinimumSize), | 696 "$padding", static_cast<int>(kClientHelloMinimumSize), |
(...skipping 11 matching lines...) Expand all Loading... |
708 if (supported_versions_.size() == 1) { | 708 if (supported_versions_.size() == 1) { |
709 // No downgrade attack is possible if the server only supports one version. | 709 // No downgrade attack is possible if the server only supports one version. |
710 return; | 710 return; |
711 } | 711 } |
712 // Set the client's preferred version to a supported version that | 712 // Set the client's preferred version to a supported version that |
713 // is not the "current" version (supported_versions_.front()). | 713 // is not the "current" version (supported_versions_.front()). |
714 string bad_version = | 714 string bad_version = |
715 QuicTagToString(QuicVersionToQuicTag(supported_versions_.back())); | 715 QuicTagToString(QuicVersionToQuicTag(supported_versions_.back())); |
716 | 716 |
717 // clang-format off | 717 // clang-format off |
718 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 718 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
719 "CHLO", | 719 "CHLO", |
720 "PDMD", "X509", | 720 "PDMD", "X509", |
721 "VER\0", bad_version.c_str(), | 721 "VER\0", bad_version.c_str(), |
722 "$padding", static_cast<int>(kClientHelloMinimumSize), | 722 "$padding", static_cast<int>(kClientHelloMinimumSize), |
723 nullptr); | 723 nullptr); |
724 // clang-format on | 724 // clang-format on |
725 ShouldFailMentioning("Downgrade", msg); | 725 ShouldFailMentioning("Downgrade", msg); |
726 const HandshakeFailureReason kRejectReasons[] = { | 726 const HandshakeFailureReason kRejectReasons[] = { |
727 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; | 727 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; |
728 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 728 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
729 } | 729 } |
730 | 730 |
731 TEST_P(CryptoServerTest, CorruptServerConfig) { | 731 TEST_P(CryptoServerTest, CorruptServerConfig) { |
732 // This tests corrupted server config. | 732 // This tests corrupted server config. |
733 // clang-format off | 733 // clang-format off |
734 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 734 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
735 "CHLO", | 735 "CHLO", |
736 "PDMD", "X509", | 736 "PDMD", "X509", |
737 "AEAD", "AESG", | 737 "AEAD", "AESG", |
738 "KEXS", "C255", | 738 "KEXS", "C255", |
739 "SCID", (string(1, 'X') + scid_hex_).c_str(), | 739 "SCID", (string(1, 'X') + scid_hex_).c_str(), |
740 "#004b5453", srct_hex_.c_str(), | 740 "#004b5453", srct_hex_.c_str(), |
741 "PUBS", pub_hex_.c_str(), | 741 "PUBS", pub_hex_.c_str(), |
742 "NONC", nonce_hex_.c_str(), | 742 "NONC", nonce_hex_.c_str(), |
743 "VER\0", client_version_string_.c_str(), | 743 "VER\0", client_version_string_.c_str(), |
744 "$padding", static_cast<int>(kClientHelloMinimumSize), | 744 "$padding", static_cast<int>(kClientHelloMinimumSize), |
745 nullptr); | 745 nullptr); |
746 // clang-format on | 746 // clang-format on |
747 ShouldSucceed(msg); | 747 ShouldSucceed(msg); |
748 CheckRejectTag(); | 748 CheckRejectTag(); |
749 const HandshakeFailureReason kRejectReasons[] = { | 749 const HandshakeFailureReason kRejectReasons[] = { |
750 SERVER_CONFIG_UNKNOWN_CONFIG_FAILURE}; | 750 SERVER_CONFIG_UNKNOWN_CONFIG_FAILURE}; |
751 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 751 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
752 } | 752 } |
753 | 753 |
754 TEST_P(CryptoServerTest, CorruptSourceAddressToken) { | 754 TEST_P(CryptoServerTest, CorruptSourceAddressToken) { |
755 // This tests corrupted source address token. | 755 // This tests corrupted source address token. |
756 // clang-format off | 756 // clang-format off |
757 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 757 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
758 "CHLO", | 758 "CHLO", |
759 "PDMD", "X509", | 759 "PDMD", "X509", |
760 "AEAD", "AESG", | 760 "AEAD", "AESG", |
761 "KEXS", "C255", | 761 "KEXS", "C255", |
762 "SCID", scid_hex_.c_str(), | 762 "SCID", scid_hex_.c_str(), |
763 "#004b5453", (string(1, 'X') + srct_hex_).c_str(), | 763 "#004b5453", (string(1, 'X') + srct_hex_).c_str(), |
764 "PUBS", pub_hex_.c_str(), | 764 "PUBS", pub_hex_.c_str(), |
765 "NONC", nonce_hex_.c_str(), | 765 "NONC", nonce_hex_.c_str(), |
766 "XLCT", XlctHexString().c_str(), | 766 "XLCT", XlctHexString().c_str(), |
767 "VER\0", client_version_string_.c_str(), | 767 "VER\0", client_version_string_.c_str(), |
768 "$padding", static_cast<int>(kClientHelloMinimumSize), | 768 "$padding", static_cast<int>(kClientHelloMinimumSize), |
769 nullptr); | 769 nullptr); |
770 // clang-format on | 770 // clang-format on |
771 ShouldSucceed(msg); | 771 ShouldSucceed(msg); |
772 CheckRejectTag(); | 772 CheckRejectTag(); |
773 const HandshakeFailureReason kRejectReasons[] = { | 773 const HandshakeFailureReason kRejectReasons[] = { |
774 SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE}; | 774 SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE}; |
775 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 775 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
776 } | 776 } |
777 | 777 |
778 TEST_P(CryptoServerTest, CorruptClientNonceAndSourceAddressToken) { | 778 TEST_P(CryptoServerTest, CorruptClientNonceAndSourceAddressToken) { |
779 // This test corrupts client nonce and source address token. | 779 // This test corrupts client nonce and source address token. |
780 // clang-format off | 780 // clang-format off |
781 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 781 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
782 "CHLO", | 782 "CHLO", |
783 "PDMD", "X509", | 783 "PDMD", "X509", |
784 "AEAD", "AESG", | 784 "AEAD", "AESG", |
785 "KEXS", "C255", | 785 "KEXS", "C255", |
786 "SCID", scid_hex_.c_str(), | 786 "SCID", scid_hex_.c_str(), |
787 "#004b5453", (string(1, 'X') + srct_hex_).c_str(), | 787 "#004b5453", (string(1, 'X') + srct_hex_).c_str(), |
788 "PUBS", pub_hex_.c_str(), | 788 "PUBS", pub_hex_.c_str(), |
789 "NONC", (string(1, 'X') + nonce_hex_).c_str(), | 789 "NONC", (string(1, 'X') + nonce_hex_).c_str(), |
790 "XLCT", XlctHexString().c_str(), | 790 "XLCT", XlctHexString().c_str(), |
791 "VER\0", client_version_string_.c_str(), | 791 "VER\0", client_version_string_.c_str(), |
792 "$padding", static_cast<int>(kClientHelloMinimumSize), | 792 "$padding", static_cast<int>(kClientHelloMinimumSize), |
793 nullptr); | 793 nullptr); |
794 // clang-format on | 794 // clang-format on |
795 ShouldSucceed(msg); | 795 ShouldSucceed(msg); |
796 CheckRejectTag(); | 796 CheckRejectTag(); |
797 const HandshakeFailureReason kRejectReasons[] = { | 797 const HandshakeFailureReason kRejectReasons[] = { |
798 SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE, CLIENT_NONCE_INVALID_FAILURE}; | 798 SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE, CLIENT_NONCE_INVALID_FAILURE}; |
799 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 799 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
800 } | 800 } |
801 | 801 |
802 TEST_P(CryptoServerTest, CorruptMultipleTags) { | 802 TEST_P(CryptoServerTest, CorruptMultipleTags) { |
803 // This test corrupts client nonce, server nonce and source address token. | 803 // This test corrupts client nonce, server nonce and source address token. |
804 // clang-format off | 804 // clang-format off |
805 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 805 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
806 "CHLO", | 806 "CHLO", |
807 "PDMD", "X509", | 807 "PDMD", "X509", |
808 "AEAD", "AESG", | 808 "AEAD", "AESG", |
809 "KEXS", "C255", | 809 "KEXS", "C255", |
810 "SCID", scid_hex_.c_str(), | 810 "SCID", scid_hex_.c_str(), |
811 "#004b5453", (string(1, 'X') + srct_hex_).c_str(), | 811 "#004b5453", (string(1, 'X') + srct_hex_).c_str(), |
812 "PUBS", pub_hex_.c_str(), | 812 "PUBS", pub_hex_.c_str(), |
813 "NONC", (string(1, 'X') + nonce_hex_).c_str(), | 813 "NONC", (string(1, 'X') + nonce_hex_).c_str(), |
814 "NONP", (string(1, 'X') + nonce_hex_).c_str(), | 814 "NONP", (string(1, 'X') + nonce_hex_).c_str(), |
815 "SNO\0", (string(1, 'X') + nonce_hex_).c_str(), | 815 "SNO\0", (string(1, 'X') + nonce_hex_).c_str(), |
816 "XLCT", XlctHexString().c_str(), | 816 "XLCT", XlctHexString().c_str(), |
817 "VER\0", client_version_string_.c_str(), | 817 "VER\0", client_version_string_.c_str(), |
818 "$padding", static_cast<int>(kClientHelloMinimumSize), | 818 "$padding", static_cast<int>(kClientHelloMinimumSize), |
819 nullptr); | 819 nullptr); |
820 // clang-format on | 820 // clang-format on |
821 ShouldSucceed(msg); | 821 ShouldSucceed(msg); |
822 CheckRejectTag(); | 822 CheckRejectTag(); |
823 | 823 |
824 const HandshakeFailureReason kRejectReasons[] = { | 824 const HandshakeFailureReason kRejectReasons[] = { |
825 SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE, CLIENT_NONCE_INVALID_FAILURE}; | 825 SOURCE_ADDRESS_TOKEN_DECRYPTION_FAILURE, CLIENT_NONCE_INVALID_FAILURE}; |
826 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 826 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
827 } | 827 } |
828 | 828 |
829 TEST_P(CryptoServerTest, NoServerNonce) { | 829 TEST_P(CryptoServerTest, NoServerNonce) { |
830 // When no server nonce is present and no strike register is configured, | 830 // When no server nonce is present and no strike register is configured, |
831 // the CHLO should be rejected. | 831 // the CHLO should be rejected. |
832 // clang-format off | 832 // clang-format off |
833 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 833 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
834 "CHLO", | 834 "CHLO", |
835 "PDMD", "X509", | 835 "PDMD", "X509", |
836 "AEAD", "AESG", | 836 "AEAD", "AESG", |
837 "KEXS", "C255", | 837 "KEXS", "C255", |
838 "SCID", scid_hex_.c_str(), | 838 "SCID", scid_hex_.c_str(), |
839 "#004b5453", srct_hex_.c_str(), | 839 "#004b5453", srct_hex_.c_str(), |
840 "PUBS", pub_hex_.c_str(), | 840 "PUBS", pub_hex_.c_str(), |
841 "NONC", nonce_hex_.c_str(), | 841 "NONC", nonce_hex_.c_str(), |
842 "NONP", nonce_hex_.c_str(), | 842 "NONP", nonce_hex_.c_str(), |
843 "XLCT", XlctHexString().c_str(), | 843 "XLCT", XlctHexString().c_str(), |
844 "VER\0", client_version_string_.c_str(), | 844 "VER\0", client_version_string_.c_str(), |
845 "$padding", static_cast<int>(kClientHelloMinimumSize), | 845 "$padding", static_cast<int>(kClientHelloMinimumSize), |
846 nullptr); | 846 nullptr); |
847 // clang-format on | 847 // clang-format on |
848 | 848 |
849 ShouldSucceed(msg); | 849 ShouldSucceed(msg); |
850 | 850 |
851 // Even without a server nonce, this ClientHello should be accepted in | 851 // Even without a server nonce, this ClientHello should be accepted in |
852 // version 33. | 852 // version 33. |
853 ASSERT_EQ(kSHLO, out_.tag()); | 853 ASSERT_EQ(kSHLO, out_.tag()); |
854 CheckServerHello(out_); | 854 CheckServerHello(out_); |
855 } | 855 } |
856 | 856 |
857 TEST_P(CryptoServerTest, ProofForSuppliedServerConfig) { | 857 TEST_P(CryptoServerTest, ProofForSuppliedServerConfig) { |
858 client_address_ = QuicSocketAddress(QuicIpAddress::Loopback6(), 1234); | 858 client_address_ = QuicSocketAddress(QuicIpAddress::Loopback6(), 1234); |
859 // clang-format off | 859 // clang-format off |
860 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 860 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
861 "CHLO", | 861 "CHLO", |
862 "AEAD", "AESG", | 862 "AEAD", "AESG", |
863 "KEXS", "C255", | 863 "KEXS", "C255", |
864 "PDMD", "X509", | 864 "PDMD", "X509", |
865 "SCID", kOldConfigId, | 865 "SCID", kOldConfigId, |
866 "#004b5453", srct_hex_.c_str(), | 866 "#004b5453", srct_hex_.c_str(), |
867 "PUBS", pub_hex_.c_str(), | 867 "PUBS", pub_hex_.c_str(), |
868 "NONC", nonce_hex_.c_str(), | 868 "NONC", nonce_hex_.c_str(), |
869 "NONP", "123456789012345678901234567890", | 869 "NONP", "123456789012345678901234567890", |
870 "VER\0", client_version_string_.c_str(), | 870 "VER\0", client_version_string_.c_str(), |
(...skipping 22 matching lines...) Expand all Loading... |
893 // Get certs from compressed certs. | 893 // Get certs from compressed certs. |
894 const CommonCertSets* common_cert_sets(CommonCertSets::GetInstanceQUIC()); | 894 const CommonCertSets* common_cert_sets(CommonCertSets::GetInstanceQUIC()); |
895 std::vector<string> cached_certs; | 895 std::vector<string> cached_certs; |
896 | 896 |
897 std::vector<string> certs; | 897 std::vector<string> certs; |
898 ASSERT_TRUE(CertCompressor::DecompressChain(cert, cached_certs, | 898 ASSERT_TRUE(CertCompressor::DecompressChain(cert, cached_certs, |
899 common_cert_sets, &certs)); | 899 common_cert_sets, &certs)); |
900 | 900 |
901 // Check that the proof in the REJ message is valid. | 901 // Check that the proof in the REJ message is valid. |
902 std::unique_ptr<ProofVerifier> proof_verifier( | 902 std::unique_ptr<ProofVerifier> proof_verifier( |
903 CryptoTestUtils::ProofVerifierForTesting()); | 903 crypto_test_utils::ProofVerifierForTesting()); |
904 std::unique_ptr<ProofVerifyContext> verify_context( | 904 std::unique_ptr<ProofVerifyContext> verify_context( |
905 CryptoTestUtils::ProofVerifyContextForTesting()); | 905 crypto_test_utils::ProofVerifyContextForTesting()); |
906 std::unique_ptr<ProofVerifyDetails> details; | 906 std::unique_ptr<ProofVerifyDetails> details; |
907 string error_details; | 907 string error_details; |
908 std::unique_ptr<ProofVerifierCallback> callback( | 908 std::unique_ptr<ProofVerifierCallback> callback( |
909 new DummyProofVerifierCallback()); | 909 new DummyProofVerifierCallback()); |
910 string chlo_hash; | 910 string chlo_hash; |
911 CryptoUtils::HashHandshakeMessage(msg, &chlo_hash); | 911 CryptoUtils::HashHandshakeMessage(msg, &chlo_hash); |
912 EXPECT_EQ(QUIC_SUCCESS, | 912 EXPECT_EQ(QUIC_SUCCESS, |
913 proof_verifier->VerifyProof( | 913 proof_verifier->VerifyProof( |
914 "test.example.com", 443, scfg_str.as_string(), client_version_, | 914 "test.example.com", 443, scfg_str.as_string(), client_version_, |
915 chlo_hash, certs, "", proof.as_string(), verify_context.get(), | 915 chlo_hash, certs, "", proof.as_string(), verify_context.get(), |
916 &error_details, &details, std::move(callback))); | 916 &error_details, &details, std::move(callback))); |
917 } | 917 } |
918 | 918 |
919 TEST_P(CryptoServerTest, RejectInvalidXlct) { | 919 TEST_P(CryptoServerTest, RejectInvalidXlct) { |
920 // clang-format off | 920 // clang-format off |
921 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 921 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
922 "CHLO", | 922 "CHLO", |
923 "PDMD", "X509", | 923 "PDMD", "X509", |
924 "AEAD", "AESG", | 924 "AEAD", "AESG", |
925 "KEXS", "C255", | 925 "KEXS", "C255", |
926 "SCID", scid_hex_.c_str(), | 926 "SCID", scid_hex_.c_str(), |
927 "#004b5453", srct_hex_.c_str(), | 927 "#004b5453", srct_hex_.c_str(), |
928 "PUBS", pub_hex_.c_str(), | 928 "PUBS", pub_hex_.c_str(), |
929 "NONC", nonce_hex_.c_str(), | 929 "NONC", nonce_hex_.c_str(), |
930 "VER\0", client_version_string_.c_str(), | 930 "VER\0", client_version_string_.c_str(), |
931 "XLCT", "#0102030405060708", | 931 "XLCT", "#0102030405060708", |
932 "$padding", static_cast<int>(kClientHelloMinimumSize), | 932 "$padding", static_cast<int>(kClientHelloMinimumSize), |
933 nullptr); | 933 nullptr); |
934 // clang-format on | 934 // clang-format on |
935 // If replay protection isn't disabled, then | 935 // If replay protection isn't disabled, then |
936 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false | 936 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false |
937 // and cause ProcessClientHello to exit early (and generate a REJ message). | 937 // and cause ProcessClientHello to exit early (and generate a REJ message). |
938 config_.set_replay_protection(false); | 938 config_.set_replay_protection(false); |
939 | 939 |
940 ShouldSucceed(msg); | 940 ShouldSucceed(msg); |
941 // clang-format off | 941 // clang-format off |
942 const HandshakeFailureReason kRejectReasons[] = { | 942 const HandshakeFailureReason kRejectReasons[] = { |
943 INVALID_EXPECTED_LEAF_CERTIFICATE | 943 INVALID_EXPECTED_LEAF_CERTIFICATE |
944 }; | 944 }; |
945 // clang-format on | 945 // clang-format on |
946 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 946 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
947 } | 947 } |
948 | 948 |
949 TEST_P(CryptoServerTest, ValidXlct) { | 949 TEST_P(CryptoServerTest, ValidXlct) { |
950 // clang-format off | 950 // clang-format off |
951 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 951 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
952 "CHLO", | 952 "CHLO", |
953 "PDMD", "X509", | 953 "PDMD", "X509", |
954 "AEAD", "AESG", | 954 "AEAD", "AESG", |
955 "KEXS", "C255", | 955 "KEXS", "C255", |
956 "SCID", scid_hex_.c_str(), | 956 "SCID", scid_hex_.c_str(), |
957 "#004b5453", srct_hex_.c_str(), | 957 "#004b5453", srct_hex_.c_str(), |
958 "PUBS", pub_hex_.c_str(), | 958 "PUBS", pub_hex_.c_str(), |
959 "NONC", nonce_hex_.c_str(), | 959 "NONC", nonce_hex_.c_str(), |
960 "VER\0", client_version_string_.c_str(), | 960 "VER\0", client_version_string_.c_str(), |
961 "XLCT", XlctHexString().c_str(), | 961 "XLCT", XlctHexString().c_str(), |
962 "$padding", static_cast<int>(kClientHelloMinimumSize), | 962 "$padding", static_cast<int>(kClientHelloMinimumSize), |
963 nullptr); | 963 nullptr); |
964 // clang-format on | 964 // clang-format on |
965 // If replay protection isn't disabled, then | 965 // If replay protection isn't disabled, then |
966 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false | 966 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false |
967 // and cause ProcessClientHello to exit early (and generate a REJ message). | 967 // and cause ProcessClientHello to exit early (and generate a REJ message). |
968 config_.set_replay_protection(false); | 968 config_.set_replay_protection(false); |
969 | 969 |
970 ShouldSucceed(msg); | 970 ShouldSucceed(msg); |
971 EXPECT_EQ(kSHLO, out_.tag()); | 971 EXPECT_EQ(kSHLO, out_.tag()); |
972 } | 972 } |
973 | 973 |
974 TEST_P(CryptoServerTest, NonceInSHLO) { | 974 TEST_P(CryptoServerTest, NonceInSHLO) { |
975 // clang-format off | 975 // clang-format off |
976 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 976 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
977 "CHLO", | 977 "CHLO", |
978 "PDMD", "X509", | 978 "PDMD", "X509", |
979 "AEAD", "AESG", | 979 "AEAD", "AESG", |
980 "KEXS", "C255", | 980 "KEXS", "C255", |
981 "SCID", scid_hex_.c_str(), | 981 "SCID", scid_hex_.c_str(), |
982 "#004b5453", srct_hex_.c_str(), | 982 "#004b5453", srct_hex_.c_str(), |
983 "PUBS", pub_hex_.c_str(), | 983 "PUBS", pub_hex_.c_str(), |
984 "NONC", nonce_hex_.c_str(), | 984 "NONC", nonce_hex_.c_str(), |
985 "VER\0", client_version_string_.c_str(), | 985 "VER\0", client_version_string_.c_str(), |
986 "XLCT", XlctHexString().c_str(), | 986 "XLCT", XlctHexString().c_str(), |
(...skipping 10 matching lines...) Expand all Loading... |
997 | 997 |
998 StringPiece nonce; | 998 StringPiece nonce; |
999 EXPECT_TRUE(out_.GetStringPiece(kServerNonceTag, &nonce)); | 999 EXPECT_TRUE(out_.GetStringPiece(kServerNonceTag, &nonce)); |
1000 } | 1000 } |
1001 | 1001 |
1002 TEST_P(CryptoServerTest, ProofSourceFailure) { | 1002 TEST_P(CryptoServerTest, ProofSourceFailure) { |
1003 // Install a ProofSource which will unconditionally fail | 1003 // Install a ProofSource which will unconditionally fail |
1004 peer_.ResetProofSource(std::unique_ptr<ProofSource>(new FailingProofSource)); | 1004 peer_.ResetProofSource(std::unique_ptr<ProofSource>(new FailingProofSource)); |
1005 | 1005 |
1006 // clang-format off | 1006 // clang-format off |
1007 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 1007 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
1008 "CHLO", | 1008 "CHLO", |
1009 "AEAD", "AESG", | 1009 "AEAD", "AESG", |
1010 "KEXS", "C255", | 1010 "KEXS", "C255", |
1011 "SCID", scid_hex_.c_str(), | 1011 "SCID", scid_hex_.c_str(), |
1012 "PUBS", pub_hex_.c_str(), | 1012 "PUBS", pub_hex_.c_str(), |
1013 "NONC", nonce_hex_.c_str(), | 1013 "NONC", nonce_hex_.c_str(), |
1014 "PDMD", "X509", | 1014 "PDMD", "X509", |
1015 "VER\0", client_version_string_.c_str(), | 1015 "VER\0", client_version_string_.c_str(), |
1016 "$padding", static_cast<int>(kClientHelloMinimumSize), | 1016 "$padding", static_cast<int>(kClientHelloMinimumSize), |
1017 nullptr); | 1017 nullptr); |
1018 // clang-format on | 1018 // clang-format on |
1019 | 1019 |
1020 // Just ensure that we don't crash as occurred in b/33916924. | 1020 // Just ensure that we don't crash as occurred in b/33916924. |
1021 ShouldFailMentioning("", msg); | 1021 ShouldFailMentioning("", msg); |
1022 } | 1022 } |
1023 | 1023 |
1024 TEST(CryptoServerConfigGenerationTest, Determinism) { | 1024 TEST(CryptoServerConfigGenerationTest, Determinism) { |
1025 // Test that using a deterministic PRNG causes the server-config to be | 1025 // Test that using a deterministic PRNG causes the server-config to be |
1026 // deterministic. | 1026 // deterministic. |
1027 | 1027 |
1028 MockRandom rand_a, rand_b; | 1028 MockRandom rand_a, rand_b; |
1029 const QuicCryptoServerConfig::ConfigOptions options; | 1029 const QuicCryptoServerConfig::ConfigOptions options; |
1030 MockClock clock; | 1030 MockClock clock; |
1031 | 1031 |
1032 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, | 1032 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, |
1033 CryptoTestUtils::ProofSourceForTesting()); | 1033 crypto_test_utils::ProofSourceForTesting()); |
1034 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, | 1034 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, |
1035 CryptoTestUtils::ProofSourceForTesting()); | 1035 crypto_test_utils::ProofSourceForTesting()); |
1036 std::unique_ptr<CryptoHandshakeMessage> scfg_a( | 1036 std::unique_ptr<CryptoHandshakeMessage> scfg_a( |
1037 a.AddDefaultConfig(&rand_a, &clock, options)); | 1037 a.AddDefaultConfig(&rand_a, &clock, options)); |
1038 std::unique_ptr<CryptoHandshakeMessage> scfg_b( | 1038 std::unique_ptr<CryptoHandshakeMessage> scfg_b( |
1039 b.AddDefaultConfig(&rand_b, &clock, options)); | 1039 b.AddDefaultConfig(&rand_b, &clock, options)); |
1040 | 1040 |
1041 ASSERT_EQ(scfg_a->DebugString(), scfg_b->DebugString()); | 1041 ASSERT_EQ(scfg_a->DebugString(), scfg_b->DebugString()); |
1042 } | 1042 } |
1043 | 1043 |
1044 TEST(CryptoServerConfigGenerationTest, SCIDVaries) { | 1044 TEST(CryptoServerConfigGenerationTest, SCIDVaries) { |
1045 // This test ensures that the server config ID varies for different server | 1045 // This test ensures that the server config ID varies for different server |
1046 // configs. | 1046 // configs. |
1047 | 1047 |
1048 MockRandom rand_a, rand_b; | 1048 MockRandom rand_a, rand_b; |
1049 const QuicCryptoServerConfig::ConfigOptions options; | 1049 const QuicCryptoServerConfig::ConfigOptions options; |
1050 MockClock clock; | 1050 MockClock clock; |
1051 | 1051 |
1052 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, | 1052 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, |
1053 CryptoTestUtils::ProofSourceForTesting()); | 1053 crypto_test_utils::ProofSourceForTesting()); |
1054 rand_b.ChangeValue(); | 1054 rand_b.ChangeValue(); |
1055 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, | 1055 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, |
1056 CryptoTestUtils::ProofSourceForTesting()); | 1056 crypto_test_utils::ProofSourceForTesting()); |
1057 std::unique_ptr<CryptoHandshakeMessage> scfg_a( | 1057 std::unique_ptr<CryptoHandshakeMessage> scfg_a( |
1058 a.AddDefaultConfig(&rand_a, &clock, options)); | 1058 a.AddDefaultConfig(&rand_a, &clock, options)); |
1059 std::unique_ptr<CryptoHandshakeMessage> scfg_b( | 1059 std::unique_ptr<CryptoHandshakeMessage> scfg_b( |
1060 b.AddDefaultConfig(&rand_b, &clock, options)); | 1060 b.AddDefaultConfig(&rand_b, &clock, options)); |
1061 | 1061 |
1062 StringPiece scid_a, scid_b; | 1062 StringPiece scid_a, scid_b; |
1063 EXPECT_TRUE(scfg_a->GetStringPiece(kSCID, &scid_a)); | 1063 EXPECT_TRUE(scfg_a->GetStringPiece(kSCID, &scid_a)); |
1064 EXPECT_TRUE(scfg_b->GetStringPiece(kSCID, &scid_b)); | 1064 EXPECT_TRUE(scfg_b->GetStringPiece(kSCID, &scid_b)); |
1065 | 1065 |
1066 EXPECT_NE(scid_a, scid_b); | 1066 EXPECT_NE(scid_a, scid_b); |
1067 } | 1067 } |
1068 | 1068 |
1069 TEST(CryptoServerConfigGenerationTest, SCIDIsHashOfServerConfig) { | 1069 TEST(CryptoServerConfigGenerationTest, SCIDIsHashOfServerConfig) { |
1070 MockRandom rand_a; | 1070 MockRandom rand_a; |
1071 const QuicCryptoServerConfig::ConfigOptions options; | 1071 const QuicCryptoServerConfig::ConfigOptions options; |
1072 MockClock clock; | 1072 MockClock clock; |
1073 | 1073 |
1074 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, | 1074 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, |
1075 CryptoTestUtils::ProofSourceForTesting()); | 1075 crypto_test_utils::ProofSourceForTesting()); |
1076 std::unique_ptr<CryptoHandshakeMessage> scfg( | 1076 std::unique_ptr<CryptoHandshakeMessage> scfg( |
1077 a.AddDefaultConfig(&rand_a, &clock, options)); | 1077 a.AddDefaultConfig(&rand_a, &clock, options)); |
1078 | 1078 |
1079 StringPiece scid; | 1079 StringPiece scid; |
1080 EXPECT_TRUE(scfg->GetStringPiece(kSCID, &scid)); | 1080 EXPECT_TRUE(scfg->GetStringPiece(kSCID, &scid)); |
1081 // Need to take a copy of |scid| has we're about to call |Erase|. | 1081 // Need to take a copy of |scid| has we're about to call |Erase|. |
1082 const string scid_str(scid.as_string()); | 1082 const string scid_str(scid.as_string()); |
1083 | 1083 |
1084 scfg->Erase(kSCID); | 1084 scfg->Erase(kSCID); |
1085 scfg->MarkDirty(); | 1085 scfg->MarkDirty(); |
(...skipping 10 matching lines...) Expand all Loading... |
1096 | 1096 |
1097 class CryptoServerTestNoConfig : public CryptoServerTest { | 1097 class CryptoServerTestNoConfig : public CryptoServerTest { |
1098 public: | 1098 public: |
1099 void SetUp() override { | 1099 void SetUp() override { |
1100 // Deliberately don't add a config so that we can test this situation. | 1100 // Deliberately don't add a config so that we can test this situation. |
1101 } | 1101 } |
1102 }; | 1102 }; |
1103 | 1103 |
1104 TEST_P(CryptoServerTestNoConfig, DontCrash) { | 1104 TEST_P(CryptoServerTestNoConfig, DontCrash) { |
1105 // clang-format off | 1105 // clang-format off |
1106 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 1106 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
1107 "CHLO", | 1107 "CHLO", |
1108 "PDMD", "X509", | 1108 "PDMD", "X509", |
1109 "VER\0", client_version_string_.c_str(), | 1109 "VER\0", client_version_string_.c_str(), |
1110 "$padding", static_cast<int>(kClientHelloMinimumSize), | 1110 "$padding", static_cast<int>(kClientHelloMinimumSize), |
1111 nullptr); | 1111 nullptr); |
1112 // clang-format on | 1112 // clang-format on |
1113 ShouldFailMentioning("No config", msg); | 1113 ShouldFailMentioning("No config", msg); |
1114 | 1114 |
1115 const HandshakeFailureReason kRejectReasons[] = { | 1115 const HandshakeFailureReason kRejectReasons[] = { |
1116 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; | 1116 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; |
1117 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 1117 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
1118 } | 1118 } |
1119 | 1119 |
1120 class CryptoServerTestOldVersion : public CryptoServerTest { | 1120 class CryptoServerTestOldVersion : public CryptoServerTest { |
1121 public: | 1121 public: |
1122 void SetUp() override { | 1122 void SetUp() override { |
1123 client_version_ = supported_versions_.back(); | 1123 client_version_ = supported_versions_.back(); |
1124 client_version_string_ = | 1124 client_version_string_ = |
1125 QuicTagToString(QuicVersionToQuicTag(client_version_)); | 1125 QuicTagToString(QuicVersionToQuicTag(client_version_)); |
1126 CryptoServerTest::SetUp(); | 1126 CryptoServerTest::SetUp(); |
1127 } | 1127 } |
1128 }; | 1128 }; |
1129 | 1129 |
1130 TEST_P(CryptoServerTestOldVersion, ServerIgnoresXlct) { | 1130 TEST_P(CryptoServerTestOldVersion, ServerIgnoresXlct) { |
1131 // clang-format off | 1131 // clang-format off |
1132 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 1132 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
1133 "CHLO", | 1133 "CHLO", |
1134 "PDMD", "X509", | 1134 "PDMD", "X509", |
1135 "AEAD", "AESG", | 1135 "AEAD", "AESG", |
1136 "KEXS", "C255", | 1136 "KEXS", "C255", |
1137 "SCID", scid_hex_.c_str(), | 1137 "SCID", scid_hex_.c_str(), |
1138 "#004b5453", srct_hex_.c_str(), | 1138 "#004b5453", srct_hex_.c_str(), |
1139 "PUBS", pub_hex_.c_str(), | 1139 "PUBS", pub_hex_.c_str(), |
1140 "NONC", nonce_hex_.c_str(), | 1140 "NONC", nonce_hex_.c_str(), |
1141 "VER\0", client_version_string_.c_str(), | 1141 "VER\0", client_version_string_.c_str(), |
1142 "XLCT", "#0100000000000000", | 1142 "XLCT", "#0100000000000000", |
1143 "$padding", static_cast<int>(kClientHelloMinimumSize), | 1143 "$padding", static_cast<int>(kClientHelloMinimumSize), |
1144 nullptr); | 1144 nullptr); |
1145 // clang-format on | 1145 // clang-format on |
1146 // If replay protection isn't disabled, then | 1146 // If replay protection isn't disabled, then |
1147 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false | 1147 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false |
1148 // and cause ProcessClientHello to exit early (and generate a REJ message). | 1148 // and cause ProcessClientHello to exit early (and generate a REJ message). |
1149 config_.set_replay_protection(false); | 1149 config_.set_replay_protection(false); |
1150 | 1150 |
1151 ShouldSucceed(msg); | 1151 ShouldSucceed(msg); |
1152 EXPECT_EQ(kSHLO, out_.tag()); | 1152 EXPECT_EQ(kSHLO, out_.tag()); |
1153 } | 1153 } |
1154 | 1154 |
1155 TEST_P(CryptoServerTestOldVersion, XlctNotRequired) { | 1155 TEST_P(CryptoServerTestOldVersion, XlctNotRequired) { |
1156 // clang-format off | 1156 // clang-format off |
1157 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 1157 CryptoHandshakeMessage msg = crypto_test_utils::Message( |
1158 "CHLO", | 1158 "CHLO", |
1159 "PDMD", "X509", | 1159 "PDMD", "X509", |
1160 "AEAD", "AESG", | 1160 "AEAD", "AESG", |
1161 "KEXS", "C255", | 1161 "KEXS", "C255", |
1162 "SCID", scid_hex_.c_str(), | 1162 "SCID", scid_hex_.c_str(), |
1163 "#004b5453", srct_hex_.c_str(), | 1163 "#004b5453", srct_hex_.c_str(), |
1164 "PUBS", pub_hex_.c_str(), | 1164 "PUBS", pub_hex_.c_str(), |
1165 "NONC", nonce_hex_.c_str(), | 1165 "NONC", nonce_hex_.c_str(), |
1166 "VER\0", client_version_string_.c_str(), | 1166 "VER\0", client_version_string_.c_str(), |
1167 "$padding", static_cast<int>(kClientHelloMinimumSize), | 1167 "$padding", static_cast<int>(kClientHelloMinimumSize), |
1168 nullptr); | 1168 nullptr); |
1169 // clang-format on | 1169 // clang-format on |
1170 // If replay protection isn't disabled, then | 1170 // If replay protection isn't disabled, then |
1171 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false | 1171 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false |
1172 // and cause ProcessClientHello to exit early (and generate a REJ message). | 1172 // and cause ProcessClientHello to exit early (and generate a REJ message). |
1173 config_.set_replay_protection(false); | 1173 config_.set_replay_protection(false); |
1174 | 1174 |
1175 ShouldSucceed(msg); | 1175 ShouldSucceed(msg); |
1176 EXPECT_EQ(kSHLO, out_.tag()); | 1176 EXPECT_EQ(kSHLO, out_.tag()); |
1177 } | 1177 } |
1178 | 1178 |
1179 } // namespace test | 1179 } // namespace test |
1180 } // namespace net | 1180 } // namespace net |
OLD | NEW |