| 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" | 21 #include "net/quic/core/quic_flags.h" |
| 22 #include "net/quic/core/quic_packets.h" | 22 #include "net/quic/core/quic_packets.h" |
| 23 #include "net/quic/core/quic_session.h" | 23 #include "net/quic/core/quic_session.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/quic_crypto_server_config_peer.h" | 30 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" |
| 30 #include "net/quic/test_tools/quic_test_utils.h" | 31 #include "net/quic/test_tools/quic_test_utils.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 34 |
| 34 namespace net { | 35 namespace net { |
| 35 class QuicConnection; | 36 class QuicConnection; |
| 36 class QuicStream; | 37 class QuicStream; |
| 37 } // namespace net | 38 } // namespace net |
| 38 | 39 |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 TEST_P(QuicCryptoServerStreamTestWithFailingProofSource, Test) { | 499 TEST_P(QuicCryptoServerStreamTestWithFailingProofSource, Test) { |
| 499 Initialize(); | 500 Initialize(); |
| 500 InitializeFakeClient(/* supports_stateless_rejects= */ false); | 501 InitializeFakeClient(/* supports_stateless_rejects= */ false); |
| 501 | 502 |
| 502 // Regression test for b/31521252, in which a crash would happen here. | 503 // Regression test for b/31521252, in which a crash would happen here. |
| 503 AdvanceHandshakeWithFakeClient(); | 504 AdvanceHandshakeWithFakeClient(); |
| 504 EXPECT_FALSE(server_stream()->encryption_established()); | 505 EXPECT_FALSE(server_stream()->encryption_established()); |
| 505 EXPECT_FALSE(server_stream()->handshake_confirmed()); | 506 EXPECT_FALSE(server_stream()->handshake_confirmed()); |
| 506 } | 507 } |
| 507 | 508 |
| 509 class QuicCryptoServerStreamTestWithFakeProofSource |
| 510 : public QuicCryptoServerStreamTest { |
| 511 public: |
| 512 QuicCryptoServerStreamTestWithFakeProofSource() |
| 513 : QuicCryptoServerStreamTest( |
| 514 std::unique_ptr<FakeProofSource>(new FakeProofSource)), |
| 515 crypto_config_peer_(&server_crypto_config_) {} |
| 516 |
| 517 FakeProofSource* GetFakeProofSource() const { |
| 518 return static_cast<FakeProofSource*>(crypto_config_peer_.GetProofSource()); |
| 519 } |
| 520 |
| 521 protected: |
| 522 QuicCryptoServerConfigPeer crypto_config_peer_; |
| 523 }; |
| 524 |
| 525 INSTANTIATE_TEST_CASE_P(YetMoreTests, |
| 526 QuicCryptoServerStreamTestWithFakeProofSource, |
| 527 testing::Bool()); |
| 528 |
| 529 // Regression test for b/35422225, in which multiple CHLOs arriving on the same |
| 530 // connection in close succession could cause a crash, especially when the use |
| 531 // of Mentat signing meant that it took a while for each CHLO to be processed. |
| 532 TEST_P(QuicCryptoServerStreamTestWithFakeProofSource, MultipleChlo) { |
| 533 Initialize(); |
| 534 GetFakeProofSource()->Activate(); |
| 535 base::SetFlag(&FLAGS_quic_reloadable_flag_fix_quic_callback_crash, true); |
| 536 EXPECT_CALL(*server_session_->helper(), CanAcceptClientHello(_, _, _)) |
| 537 .WillOnce(testing::Return(true)); |
| 538 |
| 539 // Create a minimal CHLO |
| 540 MockClock clock; |
| 541 QuicVersion version = AllSupportedVersions().front(); |
| 542 CryptoHandshakeMessage chlo = crypto_test_utils::GenerateDefaultInchoateCHLO( |
| 543 &clock, version, &server_crypto_config_); |
| 544 |
| 545 // Send in the CHLO, and check that a callback is now pending in the |
| 546 // ProofSource. |
| 547 server_stream()->OnHandshakeMessage(chlo); |
| 548 EXPECT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 1); |
| 549 |
| 550 // Send in a second CHLO while processing of the first is still pending. |
| 551 // Verify that the server closes the connection rather than crashing. Note |
| 552 // that the crash is a use-after-free, so it may only show up consistently in |
| 553 // ASAN tests. |
| 554 EXPECT_CALL( |
| 555 *server_connection_, |
| 556 CloseConnection(QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO, |
| 557 "Unexpected handshake message while processing CHLO", _)); |
| 558 server_stream()->OnHandshakeMessage(chlo); |
| 559 } |
| 560 |
| 508 } // namespace | 561 } // namespace |
| 509 } // namespace test | 562 } // namespace test |
| 510 } // namespace net | 563 } // namespace net |
| OLD | NEW |