| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 return params; | 101 return params; |
| 102 } | 102 } |
| 103 | 103 |
| 104 class CryptoServerTest : public ::testing::TestWithParam<TestParams> { | 104 class CryptoServerTest : public ::testing::TestWithParam<TestParams> { |
| 105 public: | 105 public: |
| 106 CryptoServerTest() | 106 CryptoServerTest() |
| 107 : rand_(QuicRandom::GetInstance()), | 107 : rand_(QuicRandom::GetInstance()), |
| 108 client_address_(Loopback4(), 1234), | 108 client_address_(Loopback4(), 1234), |
| 109 config_(QuicCryptoServerConfig::TESTING, rand_) { | 109 config_(QuicCryptoServerConfig::TESTING, |
| 110 rand_, |
| 110 #if defined(USE_OPENSSL) | 111 #if defined(USE_OPENSSL) |
| 111 config_.SetProofSource(CryptoTestUtils::ProofSourceForTesting()); | 112 CryptoTestUtils::ProofSourceForTesting()) { |
| 112 #else | 113 #else |
| 113 config_.SetProofSource(CryptoTestUtils::FakeProofSourceForTesting()); | 114 CryptoTestUtils::FakeProofSourceForTesting()) { |
| 114 #endif | 115 #endif |
| 115 supported_versions_ = GetParam().supported_versions; | 116 supported_versions_ = GetParam().supported_versions; |
| 116 client_version_ = supported_versions_.front(); | 117 client_version_ = supported_versions_.front(); |
| 117 client_version_string_ = | 118 client_version_string_ = |
| 118 QuicUtils::TagToString(QuicVersionToQuicTag(client_version_)); | 119 QuicUtils::TagToString(QuicVersionToQuicTag(client_version_)); |
| 119 | 120 |
| 120 FLAGS_use_early_return_when_verifying_chlo = | 121 FLAGS_use_early_return_when_verifying_chlo = |
| 121 GetParam().use_early_return_when_verifying_chlo; | 122 GetParam().use_early_return_when_verifying_chlo; |
| 122 FLAGS_enable_quic_stateless_reject_support = | 123 FLAGS_enable_quic_stateless_reject_support = |
| 123 GetParam().enable_stateless_rejects; | 124 GetParam().enable_stateless_rejects; |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 } | 767 } |
| 767 | 768 |
| 768 TEST(CryptoServerConfigGenerationTest, Determinism) { | 769 TEST(CryptoServerConfigGenerationTest, Determinism) { |
| 769 // 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 |
| 770 // deterministic. | 771 // deterministic. |
| 771 | 772 |
| 772 MockRandom rand_a, rand_b; | 773 MockRandom rand_a, rand_b; |
| 773 const QuicCryptoServerConfig::ConfigOptions options; | 774 const QuicCryptoServerConfig::ConfigOptions options; |
| 774 MockClock clock; | 775 MockClock clock; |
| 775 | 776 |
| 776 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a); | 777 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, |
| 777 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b); | 778 #if defined(USE_OPENSSL) |
| 779 CryptoTestUtils::ProofSourceForTesting()); |
| 780 #else |
| 781 CryptoTestUtils::FakeProofSourceForTesting()); |
| 782 #endif |
| 783 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, |
| 784 #if defined(USE_OPENSSL) |
| 785 CryptoTestUtils::ProofSourceForTesting()); |
| 786 #else |
| 787 CryptoTestUtils::FakeProofSourceForTesting()); |
| 788 #endif |
| 778 scoped_ptr<CryptoHandshakeMessage> scfg_a( | 789 scoped_ptr<CryptoHandshakeMessage> scfg_a( |
| 779 a.AddDefaultConfig(&rand_a, &clock, options)); | 790 a.AddDefaultConfig(&rand_a, &clock, options)); |
| 780 scoped_ptr<CryptoHandshakeMessage> scfg_b( | 791 scoped_ptr<CryptoHandshakeMessage> scfg_b( |
| 781 b.AddDefaultConfig(&rand_b, &clock, options)); | 792 b.AddDefaultConfig(&rand_b, &clock, options)); |
| 782 | 793 |
| 783 ASSERT_EQ(scfg_a->DebugString(), scfg_b->DebugString()); | 794 ASSERT_EQ(scfg_a->DebugString(), scfg_b->DebugString()); |
| 784 } | 795 } |
| 785 | 796 |
| 786 TEST(CryptoServerConfigGenerationTest, SCIDVaries) { | 797 TEST(CryptoServerConfigGenerationTest, SCIDVaries) { |
| 787 // This test ensures that the server config ID varies for different server | 798 // This test ensures that the server config ID varies for different server |
| 788 // configs. | 799 // configs. |
| 789 | 800 |
| 790 MockRandom rand_a, rand_b; | 801 MockRandom rand_a, rand_b; |
| 791 const QuicCryptoServerConfig::ConfigOptions options; | 802 const QuicCryptoServerConfig::ConfigOptions options; |
| 792 MockClock clock; | 803 MockClock clock; |
| 793 | 804 |
| 794 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a); | 805 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, |
| 806 #if defined(USE_OPENSSL) |
| 807 CryptoTestUtils::ProofSourceForTesting()); |
| 808 #else |
| 809 CryptoTestUtils::FakeProofSourceForTesting()); |
| 810 #endif |
| 795 rand_b.ChangeValue(); | 811 rand_b.ChangeValue(); |
| 796 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b); | 812 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, |
| 813 #if defined(USE_OPENSSL) |
| 814 CryptoTestUtils::ProofSourceForTesting()); |
| 815 #else |
| 816 CryptoTestUtils::FakeProofSourceForTesting()); |
| 817 #endif |
| 797 scoped_ptr<CryptoHandshakeMessage> scfg_a( | 818 scoped_ptr<CryptoHandshakeMessage> scfg_a( |
| 798 a.AddDefaultConfig(&rand_a, &clock, options)); | 819 a.AddDefaultConfig(&rand_a, &clock, options)); |
| 799 scoped_ptr<CryptoHandshakeMessage> scfg_b( | 820 scoped_ptr<CryptoHandshakeMessage> scfg_b( |
| 800 b.AddDefaultConfig(&rand_b, &clock, options)); | 821 b.AddDefaultConfig(&rand_b, &clock, options)); |
| 801 | 822 |
| 802 StringPiece scid_a, scid_b; | 823 StringPiece scid_a, scid_b; |
| 803 EXPECT_TRUE(scfg_a->GetStringPiece(kSCID, &scid_a)); | 824 EXPECT_TRUE(scfg_a->GetStringPiece(kSCID, &scid_a)); |
| 804 EXPECT_TRUE(scfg_b->GetStringPiece(kSCID, &scid_b)); | 825 EXPECT_TRUE(scfg_b->GetStringPiece(kSCID, &scid_b)); |
| 805 | 826 |
| 806 EXPECT_NE(scid_a, scid_b); | 827 EXPECT_NE(scid_a, scid_b); |
| 807 } | 828 } |
| 808 | 829 |
| 809 TEST(CryptoServerConfigGenerationTest, SCIDIsHashOfServerConfig) { | 830 TEST(CryptoServerConfigGenerationTest, SCIDIsHashOfServerConfig) { |
| 810 MockRandom rand_a; | 831 MockRandom rand_a; |
| 811 const QuicCryptoServerConfig::ConfigOptions options; | 832 const QuicCryptoServerConfig::ConfigOptions options; |
| 812 MockClock clock; | 833 MockClock clock; |
| 813 | 834 |
| 814 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a); | 835 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, |
| 836 #if defined(USE_OPENSSL) |
| 837 CryptoTestUtils::ProofSourceForTesting()); |
| 838 #else |
| 839 CryptoTestUtils::FakeProofSourceForTesting()); |
| 840 #endif |
| 815 scoped_ptr<CryptoHandshakeMessage> scfg( | 841 scoped_ptr<CryptoHandshakeMessage> scfg( |
| 816 a.AddDefaultConfig(&rand_a, &clock, options)); | 842 a.AddDefaultConfig(&rand_a, &clock, options)); |
| 817 | 843 |
| 818 StringPiece scid; | 844 StringPiece scid; |
| 819 EXPECT_TRUE(scfg->GetStringPiece(kSCID, &scid)); | 845 EXPECT_TRUE(scfg->GetStringPiece(kSCID, &scid)); |
| 820 // Need to take a copy of |scid| has we're about to call |Erase|. | 846 // Need to take a copy of |scid| has we're about to call |Erase|. |
| 821 const string scid_str(scid.as_string()); | 847 const string scid_str(scid.as_string()); |
| 822 | 848 |
| 823 scfg->Erase(kSCID); | 849 scfg->Erase(kSCID); |
| 824 scfg->MarkDirty(); | 850 scfg->MarkDirty(); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 | 1006 |
| 981 strike_register_client_->RunPendingVerifications(); | 1007 strike_register_client_->RunPendingVerifications(); |
| 982 ASSERT_TRUE(called); | 1008 ASSERT_TRUE(called); |
| 983 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 1009 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
| 984 // The message should be rejected now. | 1010 // The message should be rejected now. |
| 985 CheckRejectTag(); | 1011 CheckRejectTag(); |
| 986 } | 1012 } |
| 987 | 1013 |
| 988 } // namespace test | 1014 } // namespace test |
| 989 } // namespace net | 1015 } // namespace net |
| OLD | NEW |