| 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 "base/stl_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" | 12 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" |
| 13 #include "net/quic/core/crypto/crypto_framer.h" | 13 #include "net/quic/core/crypto/crypto_framer.h" |
| 14 #include "net/quic/core/crypto/crypto_handshake.h" | 14 #include "net/quic/core/crypto/crypto_handshake.h" |
| 15 #include "net/quic/core/crypto/crypto_protocol.h" | 15 #include "net/quic/core/crypto/crypto_protocol.h" |
| 16 #include "net/quic/core/crypto/crypto_utils.h" | 16 #include "net/quic/core/crypto/crypto_utils.h" |
| 17 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 17 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
| 18 #include "net/quic/core/crypto/quic_decrypter.h" | 18 #include "net/quic/core/crypto/quic_decrypter.h" |
| 19 #include "net/quic/core/crypto/quic_encrypter.h" | 19 #include "net/quic/core/crypto/quic_encrypter.h" |
| 20 #include "net/quic/core/crypto/quic_random.h" | 20 #include "net/quic/core/crypto/quic_random.h" |
| 21 #include "net/quic/core/quic_crypto_client_stream.h" | 21 #include "net/quic/core/quic_crypto_client_stream.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 strike_register_client_->StartDelayingVerification(); | 87 strike_register_client_->StartDelayingVerification(); |
| 88 server_crypto_config_.SetStrikeRegisterClient(strike_register_client_); | 88 server_crypto_config_.SetStrikeRegisterClient(strike_register_client_); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 ~QuicCryptoServerStreamTest() override { | 92 ~QuicCryptoServerStreamTest() override { |
| 93 // Ensure that anything that might reference |helpers_| is destroyed before | 93 // Ensure that anything that might reference |helpers_| is destroyed before |
| 94 // |helpers_| is destroyed. | 94 // |helpers_| is destroyed. |
| 95 server_session_.reset(); | 95 server_session_.reset(); |
| 96 client_session_.reset(); | 96 client_session_.reset(); |
| 97 base::STLDeleteElements(&helpers_); | 97 helpers_.clear(); |
| 98 base::STLDeleteElements(&alarm_factories_); | 98 alarm_factories_.clear(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Initializes the crypto server stream state for testing. May be | 101 // Initializes the crypto server stream state for testing. May be |
| 102 // called multiple times. | 102 // called multiple times. |
| 103 void InitializeServer() { | 103 void InitializeServer() { |
| 104 TestQuicSpdyServerSession* server_session = nullptr; | 104 TestQuicSpdyServerSession* server_session = nullptr; |
| 105 helpers_.push_back(new MockQuicConnectionHelper); | 105 helpers_.push_back(base::MakeUnique<MockQuicConnectionHelper>()); |
| 106 alarm_factories_.push_back(new MockAlarmFactory); | 106 alarm_factories_.push_back(base::MakeUnique<MockAlarmFactory>()); |
| 107 CreateServerSessionForTest( | 107 CreateServerSessionForTest( |
| 108 server_id_, QuicTime::Delta::FromSeconds(100000), supported_versions_, | 108 server_id_, QuicTime::Delta::FromSeconds(100000), supported_versions_, |
| 109 helpers_.back(), alarm_factories_.back(), &server_crypto_config_, | 109 helpers_.back().get(), alarm_factories_.back().get(), |
| 110 &server_compressed_certs_cache_, &server_connection_, &server_session); | 110 &server_crypto_config_, &server_compressed_certs_cache_, |
| 111 &server_connection_, &server_session); |
| 111 CHECK(server_session); | 112 CHECK(server_session); |
| 112 server_session_.reset(server_session); | 113 server_session_.reset(server_session); |
| 113 CryptoTestUtils::FakeServerOptions options; | 114 CryptoTestUtils::FakeServerOptions options; |
| 114 options.token_binding_params = QuicTagVector{kTB10}; | 115 options.token_binding_params = QuicTagVector{kTB10}; |
| 115 CryptoTestUtils::SetupCryptoServerConfigForTest( | 116 CryptoTestUtils::SetupCryptoServerConfigForTest( |
| 116 server_connection_->clock(), server_connection_->random_generator(), | 117 server_connection_->clock(), server_connection_->random_generator(), |
| 117 server_session_->config(), &server_crypto_config_, options); | 118 server_session_->config(), &server_crypto_config_, options); |
| 118 } | 119 } |
| 119 | 120 |
| 120 QuicCryptoServerStream* server_stream() { | 121 QuicCryptoServerStream* server_stream() { |
| 121 return server_session_->GetCryptoStream(); | 122 return server_session_->GetCryptoStream(); |
| 122 } | 123 } |
| 123 | 124 |
| 124 QuicCryptoClientStream* client_stream() { | 125 QuicCryptoClientStream* client_stream() { |
| 125 return client_session_->GetCryptoStream(); | 126 return client_session_->GetCryptoStream(); |
| 126 } | 127 } |
| 127 | 128 |
| 128 // Initializes a fake client, and all its associated state, for | 129 // Initializes a fake client, and all its associated state, for |
| 129 // testing. May be called multiple times. | 130 // testing. May be called multiple times. |
| 130 void InitializeFakeClient(bool supports_stateless_rejects) { | 131 void InitializeFakeClient(bool supports_stateless_rejects) { |
| 131 TestQuicSpdyClientSession* client_session = nullptr; | 132 TestQuicSpdyClientSession* client_session = nullptr; |
| 132 helpers_.push_back(new MockQuicConnectionHelper); | 133 helpers_.push_back(base::MakeUnique<MockQuicConnectionHelper>()); |
| 133 alarm_factories_.push_back(new MockAlarmFactory); | 134 alarm_factories_.push_back(base::MakeUnique<MockAlarmFactory>()); |
| 134 CreateClientSessionForTest( | 135 CreateClientSessionForTest( |
| 135 server_id_, supports_stateless_rejects, | 136 server_id_, supports_stateless_rejects, |
| 136 QuicTime::Delta::FromSeconds(100000), supported_versions_, | 137 QuicTime::Delta::FromSeconds(100000), supported_versions_, |
| 137 | 138 helpers_.back().get(), alarm_factories_.back().get(), |
| 138 helpers_.back(), alarm_factories_.back(), &client_crypto_config_, | 139 &client_crypto_config_, &client_connection_, &client_session); |
| 139 &client_connection_, &client_session); | |
| 140 CHECK(client_session); | 140 CHECK(client_session); |
| 141 client_session_.reset(client_session); | 141 client_session_.reset(client_session); |
| 142 } | 142 } |
| 143 | 143 |
| 144 bool AsyncStrikeRegisterVerification() { | 144 bool AsyncStrikeRegisterVerification() { |
| 145 if (server_connection_->version() > QUIC_VERSION_32) { | 145 if (server_connection_->version() > QUIC_VERSION_32) { |
| 146 return false; | 146 return false; |
| 147 } | 147 } |
| 148 return GetParam(); | 148 return GetParam(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void ConstructHandshakeMessage() { | 151 void ConstructHandshakeMessage() { |
| 152 CryptoFramer framer; | 152 CryptoFramer framer; |
| 153 message_data_.reset(framer.ConstructHandshakeMessage(message_)); | 153 message_data_.reset(framer.ConstructHandshakeMessage(message_)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 int CompleteCryptoHandshake() { | 156 int CompleteCryptoHandshake() { |
| 157 CHECK(server_connection_); | 157 CHECK(server_connection_); |
| 158 CHECK(server_session_ != nullptr); | 158 CHECK(server_session_ != nullptr); |
| 159 return CryptoTestUtils::HandshakeWithFakeClient( | 159 return CryptoTestUtils::HandshakeWithFakeClient( |
| 160 helpers_.back(), alarm_factories_.back(), server_connection_, | 160 helpers_.back().get(), alarm_factories_.back().get(), |
| 161 server_stream(), server_id_, client_options_); | 161 server_connection_, server_stream(), server_id_, client_options_); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Performs a single round of handshake message-exchange between the | 164 // Performs a single round of handshake message-exchange between the |
| 165 // client and server. | 165 // client and server. |
| 166 void AdvanceHandshakeWithFakeClient() { | 166 void AdvanceHandshakeWithFakeClient() { |
| 167 CHECK(server_connection_); | 167 CHECK(server_connection_); |
| 168 CHECK(client_session_ != nullptr); | 168 CHECK(client_session_ != nullptr); |
| 169 | 169 |
| 170 EXPECT_CALL(*client_session_, OnProofValid(_)).Times(testing::AnyNumber()); | 170 EXPECT_CALL(*client_session_, OnProofValid(_)).Times(testing::AnyNumber()); |
| 171 client_stream()->CryptoConnect(); | 171 client_stream()->CryptoConnect(); |
| 172 CryptoTestUtils::AdvanceHandshake(client_connection_, client_stream(), 0, | 172 CryptoTestUtils::AdvanceHandshake(client_connection_, client_stream(), 0, |
| 173 server_connection_, server_stream(), 0); | 173 server_connection_, server_stream(), 0); |
| 174 } | 174 } |
| 175 | 175 |
| 176 protected: | 176 protected: |
| 177 QuicFlagSaver flags_; // Save/restore all QUIC flag values. | 177 QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
| 178 | 178 |
| 179 // Every connection gets its own MockQuicConnectionHelper and | 179 // Every connection gets its own MockQuicConnectionHelper and |
| 180 // MockAlarmFactory, | 180 // MockAlarmFactory, tracked separately from the server and client state so |
| 181 // tracked separately from | 181 // their lifetimes persist through the whole test. |
| 182 // the server and client state so their lifetimes persist through the whole | 182 std::vector<std::unique_ptr<MockQuicConnectionHelper>> helpers_; |
| 183 // test. | 183 std::vector<std::unique_ptr<MockAlarmFactory>> alarm_factories_; |
| 184 std::vector<MockQuicConnectionHelper*> helpers_; | |
| 185 std::vector<MockAlarmFactory*> alarm_factories_; | |
| 186 | 184 |
| 187 // Server state | 185 // Server state. |
| 188 PacketSavingConnection* server_connection_; | 186 PacketSavingConnection* server_connection_; |
| 189 std::unique_ptr<TestQuicSpdyServerSession> server_session_; | 187 std::unique_ptr<TestQuicSpdyServerSession> server_session_; |
| 190 QuicCryptoServerConfig server_crypto_config_; | 188 QuicCryptoServerConfig server_crypto_config_; |
| 191 QuicCompressedCertsCache server_compressed_certs_cache_; | 189 QuicCompressedCertsCache server_compressed_certs_cache_; |
| 192 QuicServerId server_id_; | 190 QuicServerId server_id_; |
| 193 | 191 |
| 194 // Client state | 192 // Client state. |
| 195 PacketSavingConnection* client_connection_; | 193 PacketSavingConnection* client_connection_; |
| 196 QuicCryptoClientConfig client_crypto_config_; | 194 QuicCryptoClientConfig client_crypto_config_; |
| 197 std::unique_ptr<TestQuicSpdyClientSession> client_session_; | 195 std::unique_ptr<TestQuicSpdyClientSession> client_session_; |
| 198 | 196 |
| 199 CryptoHandshakeMessage message_; | 197 CryptoHandshakeMessage message_; |
| 200 std::unique_ptr<QuicData> message_data_; | 198 std::unique_ptr<QuicData> message_data_; |
| 201 CryptoTestUtils::FakeClientOptions client_options_; | 199 CryptoTestUtils::FakeClientOptions client_options_; |
| 202 DelayedVerifyStrikeRegisterClient* strike_register_client_; | 200 DelayedVerifyStrikeRegisterClient* strike_register_client_; |
| 203 | 201 |
| 204 // Which QUIC versions the client and server support. | 202 // Which QUIC versions the client and server support. |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 // Regression test for b/31521252, in which a crash would happen here. | 618 // Regression test for b/31521252, in which a crash would happen here. |
| 621 AdvanceHandshakeWithFakeClient(); | 619 AdvanceHandshakeWithFakeClient(); |
| 622 EXPECT_FALSE(server_stream()->encryption_established()); | 620 EXPECT_FALSE(server_stream()->encryption_established()); |
| 623 EXPECT_FALSE(server_stream()->handshake_confirmed()); | 621 EXPECT_FALSE(server_stream()->handshake_confirmed()); |
| 624 } | 622 } |
| 625 | 623 |
| 626 } // namespace | 624 } // namespace |
| 627 | 625 |
| 628 } // namespace test | 626 } // namespace test |
| 629 } // namespace net | 627 } // namespace net |
| OLD | NEW |