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/core/quic_crypto_client_stream.h" | 5 #include "net/quic/core/quic_crypto_client_stream.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" | 9 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" |
10 #include "net/quic/core/crypto/quic_decrypter.h" | 10 #include "net/quic/core/crypto/quic_decrypter.h" |
11 #include "net/quic/core/crypto/quic_encrypter.h" | 11 #include "net/quic/core/crypto/quic_encrypter.h" |
12 #include "net/quic/core/quic_flags.h" | |
13 #include "net/quic/core/quic_packets.h" | 12 #include "net/quic/core/quic_packets.h" |
14 #include "net/quic/core/quic_server_id.h" | 13 #include "net/quic/core/quic_server_id.h" |
15 #include "net/quic/core/quic_utils.h" | 14 #include "net/quic/core/quic_utils.h" |
| 15 #include "net/quic/platform/api/quic_flags.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_stream_peer.h" | 17 #include "net/quic/test_tools/quic_stream_peer.h" |
18 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" | 18 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" |
19 #include "net/quic/test_tools/quic_test_utils.h" | 19 #include "net/quic/test_tools/quic_test_utils.h" |
20 #include "net/quic/test_tools/simple_quic_framer.h" | 20 #include "net/quic/test_tools/simple_quic_framer.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 using std::string; | 24 using std::string; |
25 | 25 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 &alarm_factory_, connection_, | 57 &alarm_factory_, connection_, |
58 stream(), server_options_); | 58 stream(), server_options_); |
59 } | 59 } |
60 | 60 |
61 void ConstructHandshakeMessage(Perspective perspective) { | 61 void ConstructHandshakeMessage(Perspective perspective) { |
62 CryptoFramer framer; | 62 CryptoFramer framer; |
63 message_data_.reset( | 63 message_data_.reset( |
64 framer.ConstructHandshakeMessage(message_, perspective)); | 64 framer.ConstructHandshakeMessage(message_, perspective)); |
65 } | 65 } |
66 | 66 |
67 QuicCryptoClientStream* stream() { return session_->GetCryptoStream(); } | 67 QuicCryptoClientStream* stream() { |
| 68 return session_->GetMutableCryptoStream(); |
| 69 } |
68 | 70 |
69 MockQuicConnectionHelper server_helper_; | 71 MockQuicConnectionHelper server_helper_; |
70 MockQuicConnectionHelper client_helper_; | 72 MockQuicConnectionHelper client_helper_; |
71 MockAlarmFactory alarm_factory_; | 73 MockAlarmFactory alarm_factory_; |
72 PacketSavingConnection* connection_; | 74 PacketSavingConnection* connection_; |
73 std::unique_ptr<TestQuicSpdyClientSession> session_; | 75 std::unique_ptr<TestQuicSpdyClientSession> session_; |
74 QuicServerId server_id_; | 76 QuicServerId server_id_; |
75 CryptoHandshakeMessage message_; | 77 CryptoHandshakeMessage message_; |
76 std::unique_ptr<QuicData> message_data_; | 78 std::unique_ptr<QuicData> message_data_; |
77 QuicCryptoClientConfig crypto_config_; | 79 QuicCryptoClientConfig crypto_config_; |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 /* supports_stateless_rejects= */ true, | 367 /* supports_stateless_rejects= */ true, |
366 QuicTime::Delta::FromSeconds(100000), | 368 QuicTime::Delta::FromSeconds(100000), |
367 AllSupportedVersions(), &helper_, | 369 AllSupportedVersions(), &helper_, |
368 &alarm_factory_, &client_crypto_config_, | 370 &alarm_factory_, &client_crypto_config_, |
369 &client_connection_, &client_session); | 371 &client_connection_, &client_session); |
370 CHECK(client_session); | 372 CHECK(client_session); |
371 client_session_.reset(client_session); | 373 client_session_.reset(client_session); |
372 } | 374 } |
373 | 375 |
374 QuicCryptoServerStream* server_stream() { | 376 QuicCryptoServerStream* server_stream() { |
375 return server_session_->GetCryptoStream(); | 377 return server_session_->GetMutableCryptoStream(); |
376 } | 378 } |
377 | 379 |
378 void AdvanceHandshakeWithFakeServer() { | 380 void AdvanceHandshakeWithFakeServer() { |
379 client_session_->GetCryptoStream()->CryptoConnect(); | 381 client_session_->GetMutableCryptoStream()->CryptoConnect(); |
380 crypto_test_utils::AdvanceHandshake(client_connection_, | 382 crypto_test_utils::AdvanceHandshake( |
381 client_session_->GetCryptoStream(), 0, | 383 client_connection_, client_session_->GetMutableCryptoStream(), 0, |
382 server_connection_, server_stream(), 0); | 384 server_connection_, server_stream(), 0); |
383 } | 385 } |
384 | 386 |
385 // Initializes the server_stream_ for stateless rejects. | 387 // Initializes the server_stream_ for stateless rejects. |
386 void InitializeFakeStatelessRejectServer() { | 388 void InitializeFakeStatelessRejectServer() { |
387 TestQuicSpdyServerSession* server_session = nullptr; | 389 TestQuicSpdyServerSession* server_session = nullptr; |
388 CreateServerSessionForTest(server_id_, QuicTime::Delta::FromSeconds(100000), | 390 CreateServerSessionForTest(server_id_, QuicTime::Delta::FromSeconds(100000), |
389 AllSupportedVersions(), &helper_, | 391 AllSupportedVersions(), &helper_, |
390 &alarm_factory_, &server_crypto_config_, | 392 &alarm_factory_, &server_crypto_config_, |
391 &server_compressed_certs_cache_, | 393 &server_compressed_certs_cache_, |
392 &server_connection_, &server_session); | 394 &server_connection_, &server_session); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 | 427 |
426 EXPECT_FALSE(client_state->has_server_designated_connection_id()); | 428 EXPECT_FALSE(client_state->has_server_designated_connection_id()); |
427 EXPECT_CALL(*client_session_, OnProofValid(testing::_)); | 429 EXPECT_CALL(*client_session_, OnProofValid(testing::_)); |
428 | 430 |
429 InitializeFakeStatelessRejectServer(); | 431 InitializeFakeStatelessRejectServer(); |
430 AdvanceHandshakeWithFakeServer(); | 432 AdvanceHandshakeWithFakeServer(); |
431 | 433 |
432 EXPECT_EQ(1, server_stream()->NumHandshakeMessages()); | 434 EXPECT_EQ(1, server_stream()->NumHandshakeMessages()); |
433 EXPECT_EQ(0, server_stream()->NumHandshakeMessagesWithServerNonces()); | 435 EXPECT_EQ(0, server_stream()->NumHandshakeMessagesWithServerNonces()); |
434 | 436 |
435 EXPECT_FALSE(client_session_->GetCryptoStream()->encryption_established()); | 437 EXPECT_FALSE(client_session_->IsEncryptionEstablished()); |
436 EXPECT_FALSE(client_session_->GetCryptoStream()->handshake_confirmed()); | 438 EXPECT_FALSE(client_session_->IsCryptoHandshakeConfirmed()); |
437 // Even though the handshake was not complete, the cached client_state is | 439 // Even though the handshake was not complete, the cached client_state is |
438 // complete, and can be used for a subsequent successful handshake. | 440 // complete, and can be used for a subsequent successful handshake. |
439 EXPECT_TRUE(client_state->IsComplete(QuicWallTime::FromUNIXSeconds(0))); | 441 EXPECT_TRUE(client_state->IsComplete(QuicWallTime::FromUNIXSeconds(0))); |
440 | 442 |
441 ASSERT_TRUE(client_state->has_server_nonce()); | 443 ASSERT_TRUE(client_state->has_server_nonce()); |
442 ASSERT_FALSE(client_state->GetNextServerNonce().empty()); | 444 ASSERT_FALSE(client_state->GetNextServerNonce().empty()); |
443 ASSERT_TRUE(client_state->has_server_designated_connection_id()); | 445 ASSERT_TRUE(client_state->has_server_designated_connection_id()); |
444 QuicConnectionId server_designated_id = | 446 QuicConnectionId server_designated_id = |
445 client_state->GetNextServerDesignatedConnectionId(); | 447 client_state->GetNextServerDesignatedConnectionId(); |
446 QuicConnectionId expected_id = | 448 QuicConnectionId expected_id = |
447 server_session_->connection()->random_generator()->RandUint64(); | 449 server_session_->connection()->random_generator()->RandUint64(); |
448 EXPECT_EQ(GetPeerInMemoryConnectionId(expected_id), server_designated_id); | 450 EXPECT_EQ(GetPeerInMemoryConnectionId(expected_id), server_designated_id); |
449 EXPECT_FALSE(client_state->has_server_designated_connection_id()); | 451 EXPECT_FALSE(client_state->has_server_designated_connection_id()); |
450 } | 452 } |
451 | 453 |
452 } // namespace | 454 } // namespace |
453 } // namespace test | 455 } // namespace test |
454 } // namespace net | 456 } // namespace net |
OLD | NEW |