| 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 <ostream> | 5 #include <ostream> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "crypto/secure_hash.h" | 10 #include "crypto/secure_hash.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return params; | 102 return params; |
| 103 } | 103 } |
| 104 | 104 |
| 105 class CryptoServerTest : public ::testing::TestWithParam<TestParams> { | 105 class CryptoServerTest : public ::testing::TestWithParam<TestParams> { |
| 106 public: | 106 public: |
| 107 CryptoServerTest() | 107 CryptoServerTest() |
| 108 : rand_(QuicRandom::GetInstance()), | 108 : rand_(QuicRandom::GetInstance()), |
| 109 client_address_(Loopback4(), 1234), | 109 client_address_(Loopback4(), 1234), |
| 110 config_(QuicCryptoServerConfig::TESTING, | 110 config_(QuicCryptoServerConfig::TESTING, |
| 111 rand_, | 111 rand_, |
| 112 #if defined(USE_OPENSSL) | |
| 113 CryptoTestUtils::ProofSourceForTesting()) { | 112 CryptoTestUtils::ProofSourceForTesting()) { |
| 114 #else | |
| 115 CryptoTestUtils::FakeProofSourceForTesting()) { | |
| 116 #endif | |
| 117 supported_versions_ = GetParam().supported_versions; | 113 supported_versions_ = GetParam().supported_versions; |
| 118 config_.set_enable_serving_sct(true); | 114 config_.set_enable_serving_sct(true); |
| 119 | 115 |
| 120 client_version_ = supported_versions_.front(); | 116 client_version_ = supported_versions_.front(); |
| 121 client_version_string_ = | 117 client_version_string_ = |
| 122 QuicUtils::TagToString(QuicVersionToQuicTag(client_version_)); | 118 QuicUtils::TagToString(QuicVersionToQuicTag(client_version_)); |
| 123 | 119 |
| 124 FLAGS_use_early_return_when_verifying_chlo = | 120 FLAGS_use_early_return_when_verifying_chlo = |
| 125 GetParam().use_early_return_when_verifying_chlo; | 121 GetParam().use_early_return_when_verifying_chlo; |
| 126 FLAGS_enable_quic_stateless_reject_support = | 122 FLAGS_enable_quic_stateless_reject_support = |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 bool RejectsAreStateless() { | 341 bool RejectsAreStateless() { |
| 346 return GetParam().enable_stateless_rejects && | 342 return GetParam().enable_stateless_rejects && |
| 347 GetParam().use_stateless_rejects; | 343 GetParam().use_stateless_rejects; |
| 348 } | 344 } |
| 349 | 345 |
| 350 string XlctHexString() { | 346 string XlctHexString() { |
| 351 const vector<string>* certs; | 347 const vector<string>* certs; |
| 352 IPAddressNumber server_ip; | 348 IPAddressNumber server_ip; |
| 353 string sig; | 349 string sig; |
| 354 string cert_sct; | 350 string cert_sct; |
| 355 #if defined(USE_OPENSSL) | |
| 356 scoped_ptr<ProofSource> proof_source( | 351 scoped_ptr<ProofSource> proof_source( |
| 357 CryptoTestUtils::ProofSourceForTesting()); | 352 CryptoTestUtils::ProofSourceForTesting()); |
| 358 #else | |
| 359 scoped_ptr<ProofSource> proof_source( | |
| 360 CryptoTestUtils::FakeProofSourceForTesting()); | |
| 361 #endif | |
| 362 if (!proof_source->GetProof(server_ip, "", "", false, &certs, &sig, | 353 if (!proof_source->GetProof(server_ip, "", "", false, &certs, &sig, |
| 363 &cert_sct) || | 354 &cert_sct) || |
| 364 certs->empty()) { | 355 certs->empty()) { |
| 365 return "#0100000000000000"; | 356 return "#0100000000000000"; |
| 366 } | 357 } |
| 367 | 358 |
| 368 std::ostringstream xlct_stream; | 359 std::ostringstream xlct_stream; |
| 369 uint64 xlct = | 360 uint64 xlct = |
| 370 QuicUtils::FNV1a_64_Hash(certs->at(0).c_str(), certs->at(0).length()); | 361 QuicUtils::FNV1a_64_Hash(certs->at(0).c_str(), certs->at(0).length()); |
| 371 return "#" + base::HexEncode(reinterpret_cast<char*>(&xlct), sizeof(xlct)); | 362 return "#" + base::HexEncode(reinterpret_cast<char*>(&xlct), sizeof(xlct)); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 | 768 |
| 778 TEST(CryptoServerConfigGenerationTest, Determinism) { | 769 TEST(CryptoServerConfigGenerationTest, Determinism) { |
| 779 // Test that using a deterministic PRNG causes the server-config to be | 770 // Test that using a deterministic PRNG causes the server-config to be |
| 780 // deterministic. | 771 // deterministic. |
| 781 | 772 |
| 782 MockRandom rand_a, rand_b; | 773 MockRandom rand_a, rand_b; |
| 783 const QuicCryptoServerConfig::ConfigOptions options; | 774 const QuicCryptoServerConfig::ConfigOptions options; |
| 784 MockClock clock; | 775 MockClock clock; |
| 785 | 776 |
| 786 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, | 777 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, |
| 787 #if defined(USE_OPENSSL) | |
| 788 CryptoTestUtils::ProofSourceForTesting()); | 778 CryptoTestUtils::ProofSourceForTesting()); |
| 789 #else | |
| 790 CryptoTestUtils::FakeProofSourceForTesting()); | |
| 791 #endif | |
| 792 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, | 779 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, |
| 793 #if defined(USE_OPENSSL) | |
| 794 CryptoTestUtils::ProofSourceForTesting()); | 780 CryptoTestUtils::ProofSourceForTesting()); |
| 795 #else | |
| 796 CryptoTestUtils::FakeProofSourceForTesting()); | |
| 797 #endif | |
| 798 scoped_ptr<CryptoHandshakeMessage> scfg_a( | 781 scoped_ptr<CryptoHandshakeMessage> scfg_a( |
| 799 a.AddDefaultConfig(&rand_a, &clock, options)); | 782 a.AddDefaultConfig(&rand_a, &clock, options)); |
| 800 scoped_ptr<CryptoHandshakeMessage> scfg_b( | 783 scoped_ptr<CryptoHandshakeMessage> scfg_b( |
| 801 b.AddDefaultConfig(&rand_b, &clock, options)); | 784 b.AddDefaultConfig(&rand_b, &clock, options)); |
| 802 | 785 |
| 803 ASSERT_EQ(scfg_a->DebugString(), scfg_b->DebugString()); | 786 ASSERT_EQ(scfg_a->DebugString(), scfg_b->DebugString()); |
| 804 } | 787 } |
| 805 | 788 |
| 806 TEST(CryptoServerConfigGenerationTest, SCIDVaries) { | 789 TEST(CryptoServerConfigGenerationTest, SCIDVaries) { |
| 807 // This test ensures that the server config ID varies for different server | 790 // This test ensures that the server config ID varies for different server |
| 808 // configs. | 791 // configs. |
| 809 | 792 |
| 810 MockRandom rand_a, rand_b; | 793 MockRandom rand_a, rand_b; |
| 811 const QuicCryptoServerConfig::ConfigOptions options; | 794 const QuicCryptoServerConfig::ConfigOptions options; |
| 812 MockClock clock; | 795 MockClock clock; |
| 813 | 796 |
| 814 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, | 797 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, |
| 815 #if defined(USE_OPENSSL) | |
| 816 CryptoTestUtils::ProofSourceForTesting()); | 798 CryptoTestUtils::ProofSourceForTesting()); |
| 817 #else | |
| 818 CryptoTestUtils::FakeProofSourceForTesting()); | |
| 819 #endif | |
| 820 rand_b.ChangeValue(); | 799 rand_b.ChangeValue(); |
| 821 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, | 800 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, |
| 822 #if defined(USE_OPENSSL) | |
| 823 CryptoTestUtils::ProofSourceForTesting()); | 801 CryptoTestUtils::ProofSourceForTesting()); |
| 824 #else | |
| 825 CryptoTestUtils::FakeProofSourceForTesting()); | |
| 826 #endif | |
| 827 scoped_ptr<CryptoHandshakeMessage> scfg_a( | 802 scoped_ptr<CryptoHandshakeMessage> scfg_a( |
| 828 a.AddDefaultConfig(&rand_a, &clock, options)); | 803 a.AddDefaultConfig(&rand_a, &clock, options)); |
| 829 scoped_ptr<CryptoHandshakeMessage> scfg_b( | 804 scoped_ptr<CryptoHandshakeMessage> scfg_b( |
| 830 b.AddDefaultConfig(&rand_b, &clock, options)); | 805 b.AddDefaultConfig(&rand_b, &clock, options)); |
| 831 | 806 |
| 832 StringPiece scid_a, scid_b; | 807 StringPiece scid_a, scid_b; |
| 833 EXPECT_TRUE(scfg_a->GetStringPiece(kSCID, &scid_a)); | 808 EXPECT_TRUE(scfg_a->GetStringPiece(kSCID, &scid_a)); |
| 834 EXPECT_TRUE(scfg_b->GetStringPiece(kSCID, &scid_b)); | 809 EXPECT_TRUE(scfg_b->GetStringPiece(kSCID, &scid_b)); |
| 835 | 810 |
| 836 EXPECT_NE(scid_a, scid_b); | 811 EXPECT_NE(scid_a, scid_b); |
| 837 } | 812 } |
| 838 | 813 |
| 839 TEST(CryptoServerConfigGenerationTest, SCIDIsHashOfServerConfig) { | 814 TEST(CryptoServerConfigGenerationTest, SCIDIsHashOfServerConfig) { |
| 840 MockRandom rand_a; | 815 MockRandom rand_a; |
| 841 const QuicCryptoServerConfig::ConfigOptions options; | 816 const QuicCryptoServerConfig::ConfigOptions options; |
| 842 MockClock clock; | 817 MockClock clock; |
| 843 | 818 |
| 844 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, | 819 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, |
| 845 #if defined(USE_OPENSSL) | |
| 846 CryptoTestUtils::ProofSourceForTesting()); | 820 CryptoTestUtils::ProofSourceForTesting()); |
| 847 #else | |
| 848 CryptoTestUtils::FakeProofSourceForTesting()); | |
| 849 #endif | |
| 850 scoped_ptr<CryptoHandshakeMessage> scfg( | 821 scoped_ptr<CryptoHandshakeMessage> scfg( |
| 851 a.AddDefaultConfig(&rand_a, &clock, options)); | 822 a.AddDefaultConfig(&rand_a, &clock, options)); |
| 852 | 823 |
| 853 StringPiece scid; | 824 StringPiece scid; |
| 854 EXPECT_TRUE(scfg->GetStringPiece(kSCID, &scid)); | 825 EXPECT_TRUE(scfg->GetStringPiece(kSCID, &scid)); |
| 855 // Need to take a copy of |scid| has we're about to call |Erase|. | 826 // Need to take a copy of |scid| has we're about to call |Erase|. |
| 856 const string scid_str(scid.as_string()); | 827 const string scid_str(scid.as_string()); |
| 857 | 828 |
| 858 scfg->Erase(kSCID); | 829 scfg->Erase(kSCID); |
| 859 scfg->MarkDirty(); | 830 scfg->MarkDirty(); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 | 986 |
| 1016 strike_register_client_->RunPendingVerifications(); | 987 strike_register_client_->RunPendingVerifications(); |
| 1017 ASSERT_TRUE(called); | 988 ASSERT_TRUE(called); |
| 1018 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 989 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
| 1019 // The message should be rejected now. | 990 // The message should be rejected now. |
| 1020 CheckRejectTag(); | 991 CheckRejectTag(); |
| 1021 } | 992 } |
| 1022 | 993 |
| 1023 } // namespace test | 994 } // namespace test |
| 1024 } // namespace net | 995 } // namespace net |
| OLD | NEW |