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_server_stream.h" | 5 #include "net/quic/core/quic_crypto_server_stream.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" | 11 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" |
12 #include "net/quic/core/crypto/crypto_framer.h" | 12 #include "net/quic/core/crypto/crypto_framer.h" |
13 #include "net/quic/core/crypto/crypto_handshake.h" | 13 #include "net/quic/core/crypto/crypto_handshake.h" |
14 #include "net/quic/core/crypto/crypto_protocol.h" | 14 #include "net/quic/core/crypto/crypto_protocol.h" |
15 #include "net/quic/core/crypto/crypto_utils.h" | 15 #include "net/quic/core/crypto/crypto_utils.h" |
16 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 16 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
17 #include "net/quic/core/crypto/quic_decrypter.h" | 17 #include "net/quic/core/crypto/quic_decrypter.h" |
18 #include "net/quic/core/crypto/quic_encrypter.h" | 18 #include "net/quic/core/crypto/quic_encrypter.h" |
19 #include "net/quic/core/crypto/quic_random.h" | 19 #include "net/quic/core/crypto/quic_random.h" |
20 #include "net/quic/core/quic_crypto_client_stream.h" | 20 #include "net/quic/core/quic_crypto_client_stream.h" |
21 #include "net/quic/core/quic_flags.h" | |
22 #include "net/quic/core/quic_packets.h" | 21 #include "net/quic/core/quic_packets.h" |
23 #include "net/quic/core/quic_session.h" | 22 #include "net/quic/core/quic_session.h" |
| 23 #include "net/quic/platform/api/quic_flags.h" |
24 #include "net/quic/platform/api/quic_logging.h" | 24 #include "net/quic/platform/api/quic_logging.h" |
25 #include "net/quic/platform/api/quic_ptr_util.h" | 25 #include "net/quic/platform/api/quic_ptr_util.h" |
26 #include "net/quic/platform/api/quic_socket_address.h" | 26 #include "net/quic/platform/api/quic_socket_address.h" |
27 #include "net/quic/test_tools/crypto_test_utils.h" | 27 #include "net/quic/test_tools/crypto_test_utils.h" |
28 #include "net/quic/test_tools/failing_proof_source.h" | 28 #include "net/quic/test_tools/failing_proof_source.h" |
29 #include "net/quic/test_tools/fake_proof_source.h" | 29 #include "net/quic/test_tools/fake_proof_source.h" |
30 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" | 30 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" |
31 #include "net/quic/test_tools/quic_test_utils.h" | 31 #include "net/quic/test_tools/quic_test_utils.h" |
32 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 CHECK(server_session); | 99 CHECK(server_session); |
100 server_session_.reset(server_session); | 100 server_session_.reset(server_session); |
101 crypto_test_utils::FakeServerOptions options; | 101 crypto_test_utils::FakeServerOptions options; |
102 options.token_binding_params = QuicTagVector{kTB10}; | 102 options.token_binding_params = QuicTagVector{kTB10}; |
103 crypto_test_utils::SetupCryptoServerConfigForTest( | 103 crypto_test_utils::SetupCryptoServerConfigForTest( |
104 server_connection_->clock(), server_connection_->random_generator(), | 104 server_connection_->clock(), server_connection_->random_generator(), |
105 &server_crypto_config_, options); | 105 &server_crypto_config_, options); |
106 } | 106 } |
107 | 107 |
108 QuicCryptoServerStream* server_stream() { | 108 QuicCryptoServerStream* server_stream() { |
109 return server_session_->GetCryptoStream(); | 109 return server_session_->GetMutableCryptoStream(); |
110 } | 110 } |
111 | 111 |
112 QuicCryptoClientStream* client_stream() { | 112 QuicCryptoClientStream* client_stream() { |
113 return client_session_->GetCryptoStream(); | 113 return client_session_->GetMutableCryptoStream(); |
114 } | 114 } |
115 | 115 |
116 // Initializes a fake client, and all its associated state, for | 116 // Initializes a fake client, and all its associated state, for |
117 // testing. May be called multiple times. | 117 // testing. May be called multiple times. |
118 void InitializeFakeClient(bool supports_stateless_rejects) { | 118 void InitializeFakeClient(bool supports_stateless_rejects) { |
119 TestQuicSpdyClientSession* client_session = nullptr; | 119 TestQuicSpdyClientSession* client_session = nullptr; |
120 helpers_.push_back(QuicMakeUnique<MockQuicConnectionHelper>()); | 120 helpers_.push_back(QuicMakeUnique<MockQuicConnectionHelper>()); |
121 alarm_factories_.push_back(QuicMakeUnique<MockAlarmFactory>()); | 121 alarm_factories_.push_back(QuicMakeUnique<MockAlarmFactory>()); |
122 CreateClientSessionForTest( | 122 CreateClientSessionForTest( |
123 server_id_, supports_stateless_rejects, | 123 server_id_, supports_stateless_rejects, |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 INSTANTIATE_TEST_CASE_P(YetMoreTests, | 528 INSTANTIATE_TEST_CASE_P(YetMoreTests, |
529 QuicCryptoServerStreamTestWithFakeProofSource, | 529 QuicCryptoServerStreamTestWithFakeProofSource, |
530 testing::Bool()); | 530 testing::Bool()); |
531 | 531 |
532 // Regression test for b/35422225, in which multiple CHLOs arriving on the same | 532 // Regression test for b/35422225, in which multiple CHLOs arriving on the same |
533 // connection in close succession could cause a crash, especially when the use | 533 // connection in close succession could cause a crash, especially when the use |
534 // of Mentat signing meant that it took a while for each CHLO to be processed. | 534 // of Mentat signing meant that it took a while for each CHLO to be processed. |
535 TEST_P(QuicCryptoServerStreamTestWithFakeProofSource, MultipleChlo) { | 535 TEST_P(QuicCryptoServerStreamTestWithFakeProofSource, MultipleChlo) { |
536 Initialize(); | 536 Initialize(); |
537 GetFakeProofSource()->Activate(); | 537 GetFakeProofSource()->Activate(); |
538 base::SetFlag(&FLAGS_quic_reloadable_flag_fix_quic_callback_crash, true); | |
539 EXPECT_CALL(*server_session_->helper(), CanAcceptClientHello(_, _, _)) | 538 EXPECT_CALL(*server_session_->helper(), CanAcceptClientHello(_, _, _)) |
540 .WillOnce(testing::Return(true)); | 539 .WillOnce(testing::Return(true)); |
541 | 540 |
542 // Create a minimal CHLO | 541 // Create a minimal CHLO |
543 MockClock clock; | 542 MockClock clock; |
544 QuicVersion version = AllSupportedVersions().front(); | 543 QuicVersion version = AllSupportedVersions().front(); |
545 CryptoHandshakeMessage chlo = crypto_test_utils::GenerateDefaultInchoateCHLO( | 544 CryptoHandshakeMessage chlo = crypto_test_utils::GenerateDefaultInchoateCHLO( |
546 &clock, version, &server_crypto_config_); | 545 &clock, version, &server_crypto_config_); |
547 | 546 |
548 // Send in the CHLO, and check that a callback is now pending in the | 547 // Send in the CHLO, and check that a callback is now pending in the |
549 // ProofSource. | 548 // ProofSource. |
550 server_stream()->OnHandshakeMessage(chlo); | 549 server_stream()->OnHandshakeMessage(chlo); |
551 EXPECT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); | 550 EXPECT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); |
552 | 551 |
553 // Send in a second CHLO while processing of the first is still pending. | 552 // Send in a second CHLO while processing of the first is still pending. |
554 // Verify that the server closes the connection rather than crashing. Note | 553 // Verify that the server closes the connection rather than crashing. Note |
555 // that the crash is a use-after-free, so it may only show up consistently in | 554 // that the crash is a use-after-free, so it may only show up consistently in |
556 // ASAN tests. | 555 // ASAN tests. |
557 EXPECT_CALL( | 556 EXPECT_CALL( |
558 *server_connection_, | 557 *server_connection_, |
559 CloseConnection(QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO, | 558 CloseConnection(QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO, |
560 "Unexpected handshake message while processing CHLO", _)); | 559 "Unexpected handshake message while processing CHLO", _)); |
561 server_stream()->OnHandshakeMessage(chlo); | 560 server_stream()->OnHandshakeMessage(chlo); |
562 } | 561 } |
563 | 562 |
564 } // namespace | 563 } // namespace |
565 } // namespace test | 564 } // namespace test |
566 } // namespace net | 565 } // namespace net |
OLD | NEW |