| 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 30 matching lines...) Expand all Loading... |
| 41 return &server_config_->strike_register_client_lock_; | 41 return &server_config_->strike_register_client_lock_; |
| 42 } | 42 } |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 QuicCryptoServerConfig* server_config_; | 45 QuicCryptoServerConfig* server_config_; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 // Run tests with both parities of | 48 // Run tests with both parities of |
| 49 // FLAGS_use_early_return_when_verifying_chlo. | 49 // FLAGS_use_early_return_when_verifying_chlo. |
| 50 struct TestParams { | 50 struct TestParams { |
| 51 explicit TestParams(bool use_early_return_when_verifying_chlo, | 51 TestParams(bool use_early_return_when_verifying_chlo, |
| 52 bool enable_stateless_rejects, | 52 bool enable_stateless_rejects, |
| 53 bool use_stateless_rejects) | 53 bool use_stateless_rejects, |
| 54 QuicVersionVector supported_versions) |
| 54 : use_early_return_when_verifying_chlo( | 55 : use_early_return_when_verifying_chlo( |
| 55 use_early_return_when_verifying_chlo), | 56 use_early_return_when_verifying_chlo), |
| 56 enable_stateless_rejects(enable_stateless_rejects), | 57 enable_stateless_rejects(enable_stateless_rejects), |
| 57 use_stateless_rejects(use_stateless_rejects) {} | 58 use_stateless_rejects(use_stateless_rejects), |
| 59 supported_versions(supported_versions) {} |
| 58 | 60 |
| 59 friend ostream& operator<<(ostream& os, const TestParams& p) { | 61 friend ostream& operator<<(ostream& os, const TestParams& p) { |
| 60 os << "{ use_early_return_when_verifying_chlo: " | 62 os << "{ use_early_return_when_verifying_chlo: " |
| 61 << p.use_early_return_when_verifying_chlo << endl; | 63 << p.use_early_return_when_verifying_chlo << endl; |
| 62 os << " enable_stateless_rejects: " << p.enable_stateless_rejects << endl; | 64 os << " enable_stateless_rejects: " << p.enable_stateless_rejects << endl; |
| 63 os << " use_stateless_rejects: " << p.use_stateless_rejects << " }"; | 65 os << " use_stateless_rejects: " << p.use_stateless_rejects << endl; |
| 66 os << " versions: " << QuicVersionVectorToString(p.supported_versions) |
| 67 << " }"; |
| 64 return os; | 68 return os; |
| 65 } | 69 } |
| 66 | 70 |
| 67 bool use_early_return_when_verifying_chlo; | 71 bool use_early_return_when_verifying_chlo; |
| 68 // This only enables the stateless reject feature via the feature-flag. | 72 // This only enables the stateless reject feature via the feature-flag. |
| 69 // It does not force the crypto server to emit stateless rejects. | 73 // It does not force the crypto server to emit stateless rejects. |
| 70 bool enable_stateless_rejects; | 74 bool enable_stateless_rejects; |
| 71 // If true, this forces the server to send a stateless reject when | 75 // If true, this forces the server to send a stateless reject when |
| 72 // rejecting messages. This should be a no-op if | 76 // rejecting messages. This should be a no-op if |
| 73 // enable_stateless_rejects is false. | 77 // enable_stateless_rejects is false. |
| 74 bool use_stateless_rejects; | 78 bool use_stateless_rejects; |
| 79 // Versions supported by client and server. |
| 80 QuicVersionVector supported_versions; |
| 75 }; | 81 }; |
| 76 | 82 |
| 77 // Constructs various test permutations. | 83 // Constructs various test permutations. |
| 78 vector<TestParams> GetTestParams() { | 84 vector<TestParams> GetTestParams() { |
| 79 vector<TestParams> params; | 85 vector<TestParams> params; |
| 80 static const bool kTrueFalse[] = {true, false}; | 86 static const bool kTrueFalse[] = {true, false}; |
| 81 for (bool use_early_return : kTrueFalse) { | 87 for (bool use_early_return : kTrueFalse) { |
| 82 for (bool enable_stateless_rejects : kTrueFalse) { | 88 for (bool enable_stateless_rejects : kTrueFalse) { |
| 83 for (bool use_stateless_rejects : kTrueFalse) { | 89 for (bool use_stateless_rejects : kTrueFalse) { |
| 84 params.push_back(TestParams(use_early_return, enable_stateless_rejects, | 90 // Start with all versions, remove highest on each iteration. |
| 85 use_stateless_rejects)); | 91 QuicVersionVector supported_versions = QuicSupportedVersions(); |
| 92 while (!supported_versions.empty()) { |
| 93 params.push_back( |
| 94 TestParams(use_early_return, enable_stateless_rejects, |
| 95 use_stateless_rejects, supported_versions)); |
| 96 supported_versions.erase(supported_versions.begin()); |
| 97 } |
| 86 } | 98 } |
| 87 } | 99 } |
| 88 } | 100 } |
| 89 return params; | 101 return params; |
| 90 } | 102 } |
| 91 | 103 |
| 92 class CryptoServerTest : public ::testing::TestWithParam<TestParams> { | 104 class CryptoServerTest : public ::testing::TestWithParam<TestParams> { |
| 93 public: | 105 public: |
| 94 CryptoServerTest() | 106 CryptoServerTest() |
| 95 : rand_(QuicRandom::GetInstance()), | 107 : rand_(QuicRandom::GetInstance()), |
| 96 client_address_(Loopback4(), 1234), | 108 client_address_(Loopback4(), 1234), |
| 97 config_(QuicCryptoServerConfig::TESTING, rand_) { | 109 config_(QuicCryptoServerConfig::TESTING, rand_) { |
| 98 #if defined(USE_OPENSSL) | 110 #if defined(USE_OPENSSL) |
| 99 config_.SetProofSource(CryptoTestUtils::ProofSourceForTesting()); | 111 config_.SetProofSource(CryptoTestUtils::ProofSourceForTesting()); |
| 100 #else | 112 #else |
| 101 config_.SetProofSource(CryptoTestUtils::FakeProofSourceForTesting()); | 113 config_.SetProofSource(CryptoTestUtils::FakeProofSourceForTesting()); |
| 102 #endif | 114 #endif |
| 103 supported_versions_ = QuicSupportedVersions(); | 115 supported_versions_ = GetParam().supported_versions; |
| 104 client_version_ = supported_versions_.front(); | 116 client_version_ = supported_versions_.front(); |
| 105 client_version_string_ = | 117 client_version_string_ = |
| 106 QuicUtils::TagToString(QuicVersionToQuicTag(client_version_)); | 118 QuicUtils::TagToString(QuicVersionToQuicTag(client_version_)); |
| 107 | 119 |
| 108 FLAGS_use_early_return_when_verifying_chlo = | 120 FLAGS_use_early_return_when_verifying_chlo = |
| 109 GetParam().use_early_return_when_verifying_chlo; | 121 GetParam().use_early_return_when_verifying_chlo; |
| 110 FLAGS_enable_quic_stateless_reject_support = | 122 FLAGS_enable_quic_stateless_reject_support = |
| 111 GetParam().enable_stateless_rejects; | 123 GetParam().enable_stateless_rejects; |
| 112 use_stateless_rejects_ = GetParam().use_stateless_rejects; | 124 use_stateless_rejects_ = GetParam().use_stateless_rejects; |
| 113 } | 125 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 CryptoServerTest* test_; | 209 CryptoServerTest* test_; |
| 198 bool should_succeed_; | 210 bool should_succeed_; |
| 199 const char* error_substr_; | 211 const char* error_substr_; |
| 200 bool* called_; | 212 bool* called_; |
| 201 }; | 213 }; |
| 202 | 214 |
| 203 void CheckServerHello(const CryptoHandshakeMessage& server_hello) { | 215 void CheckServerHello(const CryptoHandshakeMessage& server_hello) { |
| 204 const QuicTag* versions; | 216 const QuicTag* versions; |
| 205 size_t num_versions; | 217 size_t num_versions; |
| 206 server_hello.GetTaglist(kVER, &versions, &num_versions); | 218 server_hello.GetTaglist(kVER, &versions, &num_versions); |
| 207 ASSERT_EQ(QuicSupportedVersions().size(), num_versions); | 219 ASSERT_EQ(supported_versions_.size(), num_versions); |
| 208 for (size_t i = 0; i < num_versions; ++i) { | 220 for (size_t i = 0; i < num_versions; ++i) { |
| 209 EXPECT_EQ(QuicVersionToQuicTag(QuicSupportedVersions()[i]), versions[i]); | 221 EXPECT_EQ(QuicVersionToQuicTag(supported_versions_[i]), versions[i]); |
| 210 } | 222 } |
| 211 | 223 |
| 212 StringPiece address; | 224 StringPiece address; |
| 213 ASSERT_TRUE(server_hello.GetStringPiece(kCADR, &address)); | 225 ASSERT_TRUE(server_hello.GetStringPiece(kCADR, &address)); |
| 214 QuicSocketAddressCoder decoder; | 226 QuicSocketAddressCoder decoder; |
| 215 ASSERT_TRUE(decoder.Decode(address.data(), address.size())); | 227 ASSERT_TRUE(decoder.Decode(address.data(), address.size())); |
| 216 EXPECT_EQ(client_address_.address(), decoder.ip()); | 228 EXPECT_EQ(client_address_.address(), decoder.ip()); |
| 217 EXPECT_EQ(client_address_.port(), decoder.port()); | 229 EXPECT_EQ(client_address_.port(), decoder.port()); |
| 218 } | 230 } |
| 219 | 231 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 "$padding", static_cast<int>(kClientHelloMinimumSize), | 436 "$padding", static_cast<int>(kClientHelloMinimumSize), |
| 425 nullptr); | 437 nullptr); |
| 426 // clang-format on | 438 // clang-format on |
| 427 | 439 |
| 428 ShouldSucceed(msg); | 440 ShouldSucceed(msg); |
| 429 StringPiece cert, proof; | 441 StringPiece cert, proof; |
| 430 EXPECT_TRUE(out_.GetStringPiece(kCertificateTag, &cert)); | 442 EXPECT_TRUE(out_.GetStringPiece(kCertificateTag, &cert)); |
| 431 EXPECT_TRUE(out_.GetStringPiece(kPROF, &proof)); | 443 EXPECT_TRUE(out_.GetStringPiece(kPROF, &proof)); |
| 432 EXPECT_NE(0u, cert.size()); | 444 EXPECT_NE(0u, cert.size()); |
| 433 EXPECT_NE(0u, proof.size()); | 445 EXPECT_NE(0u, proof.size()); |
| 434 if (client_version_ <= QUIC_VERSION_26) { | 446 const HandshakeFailureReason kRejectReasons[] = { |
| 435 const HandshakeFailureReason kRejectReasons[] = { | 447 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; |
| 436 CLIENT_NONCE_INVALID_TIME_FAILURE}; | 448 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
| 437 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | |
| 438 } else { | |
| 439 const HandshakeFailureReason kRejectReasons[] = { | |
| 440 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; | |
| 441 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | |
| 442 } | |
| 443 } | 449 } |
| 444 | 450 |
| 445 TEST_P(CryptoServerTest, TooSmall) { | 451 TEST_P(CryptoServerTest, TooSmall) { |
| 446 // clang-format off | 452 // clang-format off |
| 447 ShouldFailMentioning("too small", CryptoTestUtils::Message( | 453 ShouldFailMentioning("too small", CryptoTestUtils::Message( |
| 448 "CHLO", | 454 "CHLO", |
| 449 "VER\0", client_version_string_.c_str(), | 455 "VER\0", client_version_string_.c_str(), |
| 450 nullptr)); | 456 nullptr)); |
| 451 // clang-format on | 457 // clang-format on |
| 452 const HandshakeFailureReason kRejectReasons[] = { | 458 const HandshakeFailureReason kRejectReasons[] = { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 ASSERT_EQ(kSHLO, out_.tag()); | 670 ASSERT_EQ(kSHLO, out_.tag()); |
| 665 CheckServerHello(out_); | 671 CheckServerHello(out_); |
| 666 | 672 |
| 667 ShouldSucceed(msg); | 673 ShouldSucceed(msg); |
| 668 // The message should accepted twice when replay protection is off. | 674 // The message should accepted twice when replay protection is off. |
| 669 ASSERT_EQ(kSHLO, out_.tag()); | 675 ASSERT_EQ(kSHLO, out_.tag()); |
| 670 CheckServerHello(out_); | 676 CheckServerHello(out_); |
| 671 } | 677 } |
| 672 | 678 |
| 673 TEST_P(CryptoServerTest, RejectInvalidXlct) { | 679 TEST_P(CryptoServerTest, RejectInvalidXlct) { |
| 680 if (client_version_ <= QUIC_VERSION_25) { |
| 681 // XLCT tag introduced in QUIC_VERSION_26. |
| 682 return; |
| 683 } |
| 674 // clang-format off | 684 // clang-format off |
| 675 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 685 CryptoHandshakeMessage msg = CryptoTestUtils::Message( |
| 676 "CHLO", | 686 "CHLO", |
| 677 "AEAD", "AESG", | 687 "AEAD", "AESG", |
| 678 "KEXS", "C255", | 688 "KEXS", "C255", |
| 679 "SCID", scid_hex_.c_str(), | 689 "SCID", scid_hex_.c_str(), |
| 680 "#004b5453", srct_hex_.c_str(), | 690 "#004b5453", srct_hex_.c_str(), |
| 681 "PUBS", pub_hex_.c_str(), | 691 "PUBS", pub_hex_.c_str(), |
| 682 "NONC", nonce_hex_.c_str(), | 692 "NONC", nonce_hex_.c_str(), |
| 683 "VER\0", client_version_string_.c_str(), | 693 "VER\0", client_version_string_.c_str(), |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 | 980 |
| 971 strike_register_client_->RunPendingVerifications(); | 981 strike_register_client_->RunPendingVerifications(); |
| 972 ASSERT_TRUE(called); | 982 ASSERT_TRUE(called); |
| 973 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 983 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
| 974 // The message should be rejected now. | 984 // The message should be rejected now. |
| 975 CheckRejectTag(); | 985 CheckRejectTag(); |
| 976 } | 986 } |
| 977 | 987 |
| 978 } // namespace test | 988 } // namespace test |
| 979 } // namespace net | 989 } // namespace net |
| OLD | NEW |