OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/quic/quic_crypto_server_stream.h" | 5 #include "net/quic/quic_crypto_server_stream.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 const uint16 kServerPort = 443; | 67 const uint16 kServerPort = 443; |
68 | 68 |
69 class QuicCryptoServerStreamTest : public ::testing::TestWithParam<bool> { | 69 class QuicCryptoServerStreamTest : public ::testing::TestWithParam<bool> { |
70 public: | 70 public: |
71 QuicCryptoServerStreamTest() | 71 QuicCryptoServerStreamTest() |
72 : server_crypto_config_(QuicCryptoServerConfig::TESTING, | 72 : server_crypto_config_(QuicCryptoServerConfig::TESTING, |
73 QuicRandom::GetInstance(), | 73 QuicRandom::GetInstance(), |
74 CryptoTestUtils::ProofSourceForTesting()), | 74 CryptoTestUtils::ProofSourceForTesting()), |
75 server_id_(kServerHostname, kServerPort, PRIVACY_MODE_DISABLED), | 75 server_id_(kServerHostname, kServerPort, PRIVACY_MODE_DISABLED), |
76 client_crypto_config_(CryptoTestUtils::ProofVerifierForTesting()) { | 76 client_crypto_config_(CryptoTestUtils::ProofVerifierForTesting()) { |
| 77 FLAGS_enable_quic_stateless_reject_support = false; |
77 server_crypto_config_.set_strike_register_no_startup_period(); | 78 server_crypto_config_.set_strike_register_no_startup_period(); |
78 | 79 |
79 InitializeServer(); | 80 InitializeServer(); |
80 | 81 |
81 if (AsyncStrikeRegisterVerification()) { | 82 if (AsyncStrikeRegisterVerification()) { |
82 string orbit = | 83 string orbit = |
83 QuicCryptoServerConfigPeer::GetPrimaryOrbit(server_crypto_config_); | 84 QuicCryptoServerConfigPeer::GetPrimaryOrbit(server_crypto_config_); |
84 strike_register_client_ = new DelayedVerifyStrikeRegisterClient( | 85 strike_register_client_ = new DelayedVerifyStrikeRegisterClient( |
85 10000, // strike_register_max_entries | 86 10000, // strike_register_max_entries |
86 static_cast<uint32>( | 87 static_cast<uint32>( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // * One to get a source-address token and certificates. | 206 // * One to get a source-address token and certificates. |
206 // * One to complete the handshake. | 207 // * One to complete the handshake. |
207 EXPECT_EQ(2, CompleteCryptoHandshake()); | 208 EXPECT_EQ(2, CompleteCryptoHandshake()); |
208 EXPECT_TRUE(server_stream()->encryption_established()); | 209 EXPECT_TRUE(server_stream()->encryption_established()); |
209 EXPECT_TRUE(server_stream()->handshake_confirmed()); | 210 EXPECT_TRUE(server_stream()->handshake_confirmed()); |
210 } | 211 } |
211 | 212 |
212 TEST_P(QuicCryptoServerStreamTest, StatelessRejectAfterCHLO) { | 213 TEST_P(QuicCryptoServerStreamTest, StatelessRejectAfterCHLO) { |
213 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stateless_reject_support, | 214 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stateless_reject_support, |
214 true); | 215 true); |
215 server_stream()->set_use_stateless_rejects_if_peer_supported(true); | 216 InitializeServer(); |
216 | 217 |
217 InitializeFakeClient(/* supports_stateless_rejects= */ true); | 218 InitializeFakeClient(/* supports_stateless_rejects= */ true); |
218 AdvanceHandshakeWithFakeClient(); | 219 AdvanceHandshakeWithFakeClient(); |
219 | 220 |
220 // Check the server to make the sure the handshake did not succeed. | 221 // Check the server to make the sure the handshake did not succeed. |
221 EXPECT_FALSE(server_stream()->encryption_established()); | 222 EXPECT_FALSE(server_stream()->encryption_established()); |
222 EXPECT_FALSE(server_stream()->handshake_confirmed()); | 223 EXPECT_FALSE(server_stream()->handshake_confirmed()); |
223 | 224 |
224 // Check the client state to make sure that it received a server-designated | 225 // Check the client state to make sure that it received a server-designated |
225 // connection id. | 226 // connection id. |
(...skipping 11 matching lines...) Expand all Loading... |
237 server_connection_->random_generator()->RandUint64(); | 238 server_connection_->random_generator()->RandUint64(); |
238 EXPECT_EQ(expected_id, server_designated_connection_id); | 239 EXPECT_EQ(expected_id, server_designated_connection_id); |
239 EXPECT_FALSE(client_state->has_server_designated_connection_id()); | 240 EXPECT_FALSE(client_state->has_server_designated_connection_id()); |
240 ASSERT_TRUE(client_state->IsComplete(QuicWallTime::FromUNIXSeconds(0))); | 241 ASSERT_TRUE(client_state->IsComplete(QuicWallTime::FromUNIXSeconds(0))); |
241 EXPECT_FALSE(server_connection_->connected()); | 242 EXPECT_FALSE(server_connection_->connected()); |
242 } | 243 } |
243 | 244 |
244 TEST_P(QuicCryptoServerStreamTest, ConnectedAfterStatelessHandshake) { | 245 TEST_P(QuicCryptoServerStreamTest, ConnectedAfterStatelessHandshake) { |
245 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stateless_reject_support, | 246 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stateless_reject_support, |
246 true); | 247 true); |
247 server_stream()->set_use_stateless_rejects_if_peer_supported(true); | 248 InitializeServer(); |
248 | 249 |
249 InitializeFakeClient(/* supports_stateless_rejects= */ true); | 250 InitializeFakeClient(/* supports_stateless_rejects= */ true); |
250 AdvanceHandshakeWithFakeClient(); | 251 AdvanceHandshakeWithFakeClient(); |
251 | 252 |
252 // On the first round, encryption will not be established. | 253 // On the first round, encryption will not be established. |
253 EXPECT_FALSE(server_stream()->encryption_established()); | 254 EXPECT_FALSE(server_stream()->encryption_established()); |
254 EXPECT_FALSE(server_stream()->handshake_confirmed()); | 255 EXPECT_FALSE(server_stream()->handshake_confirmed()); |
255 EXPECT_EQ(1, server_stream()->num_handshake_messages()); | 256 EXPECT_EQ(1, server_stream()->num_handshake_messages()); |
256 EXPECT_EQ(0, server_stream()->num_handshake_messages_with_server_nonces()); | 257 EXPECT_EQ(0, server_stream()->num_handshake_messages_with_server_nonces()); |
257 | 258 |
258 // Now check the client state. | 259 // Now check the client state. |
259 QuicCryptoClientConfig::CachedState* client_state = | 260 QuicCryptoClientConfig::CachedState* client_state = |
260 client_crypto_config_.LookupOrCreate(server_id_); | 261 client_crypto_config_.LookupOrCreate(server_id_); |
261 | 262 |
262 ASSERT_TRUE(client_state->has_server_designated_connection_id()); | 263 ASSERT_TRUE(client_state->has_server_designated_connection_id()); |
263 const QuicConnectionId server_designated_connection_id = | 264 const QuicConnectionId server_designated_connection_id = |
264 client_state->GetNextServerDesignatedConnectionId(); | 265 client_state->GetNextServerDesignatedConnectionId(); |
265 const QuicConnectionId expected_id = | 266 const QuicConnectionId expected_id = |
266 server_connection_->random_generator()->RandUint64(); | 267 server_connection_->random_generator()->RandUint64(); |
267 EXPECT_EQ(expected_id, server_designated_connection_id); | 268 EXPECT_EQ(expected_id, server_designated_connection_id); |
268 EXPECT_FALSE(client_state->has_server_designated_connection_id()); | 269 EXPECT_FALSE(client_state->has_server_designated_connection_id()); |
269 ASSERT_TRUE(client_state->IsComplete(QuicWallTime::FromUNIXSeconds(0))); | 270 ASSERT_TRUE(client_state->IsComplete(QuicWallTime::FromUNIXSeconds(0))); |
270 | 271 |
271 // Now create new client and server streams with the existing config | 272 // Now create new client and server streams with the existing config |
272 // and try the handshake again (0-RTT handshake). | 273 // and try the handshake again (0-RTT handshake). |
273 InitializeServer(); | 274 InitializeServer(); |
274 server_stream()->set_use_stateless_rejects_if_peer_supported(true); | |
275 | 275 |
276 InitializeFakeClient(/* supports_stateless_rejects= */ true); | 276 InitializeFakeClient(/* supports_stateless_rejects= */ true); |
277 | 277 |
278 client_stream()->CryptoConnect(); | 278 client_stream()->CryptoConnect(); |
279 | 279 |
280 // In the stateless case, the second handshake contains a server-nonce, so the | 280 // In the stateless case, the second handshake contains a server-nonce, so the |
281 // AsyncStrikeRegisterVerification() case will still succeed (unlike a 0-RTT | 281 // AsyncStrikeRegisterVerification() case will still succeed (unlike a 0-RTT |
282 // handshake). | 282 // handshake). |
283 AdvanceHandshakeWithFakeClient(); | 283 AdvanceHandshakeWithFakeClient(); |
284 | 284 |
285 // On the second round, encryption will be established. | 285 // On the second round, encryption will be established. |
286 EXPECT_TRUE(server_stream()->encryption_established()); | 286 EXPECT_TRUE(server_stream()->encryption_established()); |
287 EXPECT_TRUE(server_stream()->handshake_confirmed()); | 287 EXPECT_TRUE(server_stream()->handshake_confirmed()); |
288 EXPECT_EQ(2, server_stream()->num_handshake_messages()); | 288 EXPECT_EQ(2, server_stream()->num_handshake_messages()); |
289 EXPECT_EQ(1, server_stream()->num_handshake_messages_with_server_nonces()); | 289 EXPECT_EQ(1, server_stream()->num_handshake_messages_with_server_nonces()); |
290 } | 290 } |
291 | 291 |
292 TEST_P(QuicCryptoServerStreamTest, NoStatelessRejectIfNoClientSupport) { | 292 TEST_P(QuicCryptoServerStreamTest, NoStatelessRejectIfNoClientSupport) { |
293 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stateless_reject_support, | 293 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stateless_reject_support, |
294 true); | 294 true); |
295 server_stream()->set_use_stateless_rejects_if_peer_supported(true); | 295 InitializeServer(); |
296 | 296 |
297 // The server is configured to use stateless rejects, but the client does not | 297 // The server is configured to use stateless rejects, but the client does not |
298 // support it. | 298 // support it. |
299 InitializeFakeClient(/* supports_stateless_rejects= */ false); | 299 InitializeFakeClient(/* supports_stateless_rejects= */ false); |
300 AdvanceHandshakeWithFakeClient(); | 300 AdvanceHandshakeWithFakeClient(); |
301 | 301 |
302 // Check the server to make the sure the handshake did not succeed. | 302 // Check the server to make the sure the handshake did not succeed. |
303 EXPECT_FALSE(server_stream()->encryption_established()); | 303 EXPECT_FALSE(server_stream()->encryption_established()); |
304 EXPECT_FALSE(server_stream()->handshake_confirmed()); | 304 EXPECT_FALSE(server_stream()->handshake_confirmed()); |
305 | 305 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 EXPECT_FALSE( | 423 EXPECT_FALSE( |
424 QuicCryptoServerStreamPeer::DoesPeerSupportStatelessRejects(message_)); | 424 QuicCryptoServerStreamPeer::DoesPeerSupportStatelessRejects(message_)); |
425 } | 425 } |
426 | 426 |
427 } // namespace | 427 } // namespace |
428 | 428 |
429 #endif | 429 #endif |
430 | 430 |
431 } // namespace test | 431 } // namespace test |
432 } // namespace net | 432 } // namespace net |
OLD | NEW |