OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "net/tools/quic/stateless_rejector.h" | 5 #include "net/tools/quic/stateless_rejector.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/strings/stringprintf.h" | |
12 #include "net/quic/core/crypto/crypto_handshake_message.h" | 11 #include "net/quic/core/crypto/crypto_handshake_message.h" |
13 #include "net/quic/core/crypto/proof_source.h" | 12 #include "net/quic/core/crypto/proof_source.h" |
14 #include "net/quic/core/quic_utils.h" | 13 #include "net/quic/core/quic_utils.h" |
15 #include "net/quic/platform/api/quic_str_cat.h" | 14 #include "net/quic/platform/api/quic_str_cat.h" |
| 15 #include "net/quic/platform/api/quic_text_utils.h" |
16 #include "net/quic/test_tools/crypto_test_utils.h" | 16 #include "net/quic/test_tools/crypto_test_utils.h" |
17 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" | 17 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" |
18 #include "net/quic/test_tools/quic_test_utils.h" | 18 #include "net/quic/test_tools/quic_test_utils.h" |
19 | 19 |
20 using std::string; | 20 using std::string; |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 namespace test { | 23 namespace test { |
24 namespace { | 24 namespace { |
25 | 25 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 FLAGS_quic_reloadable_flag_enable_quic_stateless_reject_support = | 93 FLAGS_quic_reloadable_flag_enable_quic_stateless_reject_support = |
94 GetParam().flags == ENABLED || GetParam().flags == CHEAP_DISABLED; | 94 GetParam().flags == ENABLED || GetParam().flags == CHEAP_DISABLED; |
95 FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects = | 95 FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects = |
96 GetParam().flags == ENABLED || GetParam().flags == STATELESS_DISABLED; | 96 GetParam().flags == ENABLED || GetParam().flags == STATELESS_DISABLED; |
97 | 97 |
98 // Add a new primary config. | 98 // Add a new primary config. |
99 std::unique_ptr<CryptoHandshakeMessage> msg(config_.AddDefaultConfig( | 99 std::unique_ptr<CryptoHandshakeMessage> msg(config_.AddDefaultConfig( |
100 QuicRandom::GetInstance(), &clock_, config_options_)); | 100 QuicRandom::GetInstance(), &clock_, config_options_)); |
101 | 101 |
102 // Save the server config. | 102 // Save the server config. |
103 scid_hex_ = "#" + QuicUtils::HexEncode(config_peer_.GetPrimaryConfig()->id); | 103 scid_hex_ = |
| 104 "#" + QuicTextUtils::HexEncode(config_peer_.GetPrimaryConfig()->id); |
104 | 105 |
105 // Encode the QUIC version. | 106 // Encode the QUIC version. |
106 ver_hex_ = QuicTagToString(QuicVersionToQuicTag(GetParam().version)); | 107 ver_hex_ = QuicTagToString(QuicVersionToQuicTag(GetParam().version)); |
107 | 108 |
108 // Generate a public value. | 109 // Generate a public value. |
109 char public_value[32]; | 110 char public_value[32]; |
110 memset(public_value, 42, sizeof(public_value)); | 111 memset(public_value, 42, sizeof(public_value)); |
111 pubs_hex_ = "#" + QuicUtils::HexEncode(public_value, sizeof(public_value)); | 112 pubs_hex_ = |
| 113 "#" + QuicTextUtils::HexEncode(public_value, sizeof(public_value)); |
112 | 114 |
113 // Generate a client nonce. | 115 // Generate a client nonce. |
114 string nonce; | 116 string nonce; |
115 CryptoUtils::GenerateNonce( | 117 CryptoUtils::GenerateNonce( |
116 clock_.WallNow(), QuicRandom::GetInstance(), | 118 clock_.WallNow(), QuicRandom::GetInstance(), |
117 StringPiece( | 119 StringPiece( |
118 reinterpret_cast<char*>(config_peer_.GetPrimaryConfig()->orbit), | 120 reinterpret_cast<char*>(config_peer_.GetPrimaryConfig()->orbit), |
119 kOrbitSize), | 121 kOrbitSize), |
120 &nonce); | 122 &nonce); |
121 nonc_hex_ = "#" + QuicUtils::HexEncode(nonce); | 123 nonc_hex_ = "#" + QuicTextUtils::HexEncode(nonce); |
122 | 124 |
123 // Generate a source address token. | 125 // Generate a source address token. |
124 SourceAddressTokens previous_tokens; | 126 SourceAddressTokens previous_tokens; |
125 QuicIpAddress ip = QuicIpAddress::Loopback4(); | 127 QuicIpAddress ip = QuicIpAddress::Loopback4(); |
126 MockRandom rand; | 128 MockRandom rand; |
127 string stk = config_peer_.NewSourceAddressToken( | 129 string stk = config_peer_.NewSourceAddressToken( |
128 config_peer_.GetPrimaryConfig()->id, previous_tokens, ip, &rand, | 130 config_peer_.GetPrimaryConfig()->id, previous_tokens, ip, &rand, |
129 clock_.WallNow(), nullptr); | 131 clock_.WallNow(), nullptr); |
130 stk_hex_ = "#" + QuicUtils::HexEncode(stk); | 132 stk_hex_ = "#" + QuicTextUtils::HexEncode(stk); |
131 } | 133 } |
132 | 134 |
133 protected: | 135 protected: |
134 class ProcessDoneCallback : public StatelessRejector::ProcessDoneCallback { | 136 class ProcessDoneCallback : public StatelessRejector::ProcessDoneCallback { |
135 public: | 137 public: |
136 explicit ProcessDoneCallback(StatelessRejectorTest* test) : test_(test) {} | 138 explicit ProcessDoneCallback(StatelessRejectorTest* test) : test_(test) {} |
137 void Run(std::unique_ptr<StatelessRejector> rejector) override { | 139 void Run(std::unique_ptr<StatelessRejector> rejector) override { |
138 test_->rejector_ = std::move(rejector); | 140 test_->rejector_ = std::move(rejector); |
139 } | 141 } |
140 | 142 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 EXPECT_EQ(QUIC_NO_ERROR, | 248 EXPECT_EQ(QUIC_NO_ERROR, |
247 reply.GetTaglist(kRREJ, &reject_reasons, &num_reject_reasons)); | 249 reply.GetTaglist(kRREJ, &reject_reasons, &num_reject_reasons)); |
248 EXPECT_EQ(1u, num_reject_reasons); | 250 EXPECT_EQ(1u, num_reject_reasons); |
249 EXPECT_EQ(INVALID_EXPECTED_LEAF_CERTIFICATE, | 251 EXPECT_EQ(INVALID_EXPECTED_LEAF_CERTIFICATE, |
250 static_cast<HandshakeFailureReason>(reject_reasons[0])); | 252 static_cast<HandshakeFailureReason>(reject_reasons[0])); |
251 } | 253 } |
252 | 254 |
253 TEST_P(StatelessRejectorTest, AcceptChlo) { | 255 TEST_P(StatelessRejectorTest, AcceptChlo) { |
254 const uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting(); | 256 const uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting(); |
255 const string xlct_hex = | 257 const string xlct_hex = |
256 "#" + | 258 "#" + QuicTextUtils::HexEncode(reinterpret_cast<const char*>(&xlct), |
257 QuicUtils::HexEncode(reinterpret_cast<const char*>(&xlct), sizeof(xlct)); | 259 sizeof(xlct)); |
258 // clang-format off | 260 // clang-format off |
259 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( | 261 const CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( |
260 "CHLO", | 262 "CHLO", |
261 "PDMD", "X509", | 263 "PDMD", "X509", |
262 "AEAD", "AESG", | 264 "AEAD", "AESG", |
263 "KEXS", "C255", | 265 "KEXS", "C255", |
264 "COPT", "SREJ", | 266 "COPT", "SREJ", |
265 "SCID", scid_hex_.c_str(), | 267 "SCID", scid_hex_.c_str(), |
266 "PUBS", pubs_hex_.c_str(), | 268 "PUBS", pubs_hex_.c_str(), |
267 "NONC", nonc_hex_.c_str(), | 269 "NONC", nonc_hex_.c_str(), |
(...skipping 15 matching lines...) Expand all Loading... |
283 ASSERT_EQ(StatelessRejector::UNKNOWN, rejector_->state()); | 285 ASSERT_EQ(StatelessRejector::UNKNOWN, rejector_->state()); |
284 StatelessRejector::Process(std::move(rejector_), | 286 StatelessRejector::Process(std::move(rejector_), |
285 base::MakeUnique<ProcessDoneCallback>(this)); | 287 base::MakeUnique<ProcessDoneCallback>(this)); |
286 | 288 |
287 EXPECT_EQ(StatelessRejector::ACCEPTED, rejector_->state()); | 289 EXPECT_EQ(StatelessRejector::ACCEPTED, rejector_->state()); |
288 } | 290 } |
289 | 291 |
290 } // namespace | 292 } // namespace |
291 } // namespace test | 293 } // namespace test |
292 } // namespace net | 294 } // namespace net |
OLD | NEW |