Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(606)

Side by Side Diff: net/quic/quic_crypto_client_stream_test.cc

Issue 1139183002: Flag-protected. Add stateless reject support to crypto streams. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@QuicCryptoClientConfig_ProcessRejection_92637704
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_crypto_client_stream.cc ('k') | net/quic/quic_crypto_server_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_client_stream.h" 5 #include "net/quic/quic_crypto_client_stream.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" 8 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
9 #include "net/quic/crypto/quic_decrypter.h" 9 #include "net/quic/crypto/quic_decrypter.h"
10 #include "net/quic/crypto/quic_encrypter.h" 10 #include "net/quic/crypto/quic_encrypter.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 TEST_F(QuicCryptoClientStreamTest, ServerConfigUpdateBeforeHandshake) { 193 TEST_F(QuicCryptoClientStreamTest, ServerConfigUpdateBeforeHandshake) {
194 EXPECT_CALL(*connection_, SendConnectionClose( 194 EXPECT_CALL(*connection_, SendConnectionClose(
195 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE)); 195 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE));
196 CryptoHandshakeMessage server_config_update; 196 CryptoHandshakeMessage server_config_update;
197 server_config_update.set_tag(kSCUP); 197 server_config_update.set_tag(kSCUP);
198 scoped_ptr<QuicData> data( 198 scoped_ptr<QuicData> data(
199 CryptoFramer::ConstructHandshakeMessage(server_config_update)); 199 CryptoFramer::ConstructHandshakeMessage(server_config_update));
200 stream_->ProcessRawData(data->data(), data->length()); 200 stream_->ProcessRawData(data->data(), data->length());
201 } 201 }
202 202
203 class QuicCryptoClientStreamStatelessTest : public ::testing::Test {
204 public:
205 QuicCryptoClientStreamStatelessTest()
206 : server_crypto_config_(QuicCryptoServerConfig::TESTING,
207 QuicRandom::GetInstance()),
208 server_id_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED) {
209 TestClientSession* client_session = nullptr;
210 QuicCryptoClientStream* client_stream = nullptr;
211 SetupCryptoClientStreamForTest(server_id_,
212 /* supports_stateless_rejects= */ true,
213 QuicTime::Delta::FromSeconds(100000),
214 &client_crypto_config_, &client_connection_,
215 &client_session, &client_stream);
216 CHECK(client_session);
217 CHECK(client_stream);
218 client_session_.reset(client_session);
219 client_stream_.reset(client_stream);
220 }
221
222 void AdvanceHandshakeWithFakeServer() {
223 client_stream_->CryptoConnect();
224 CryptoTestUtils::AdvanceHandshake(client_connection_, client_stream_.get(),
225 0, server_connection_,
226 server_stream_.get(), 0);
227 }
228
229 // Initializes the server_stream_ for stateless rejects.
230 void InitializeFakeStatelessRejectServer() {
231 TestServerSession* server_session = nullptr;
232 QuicCryptoServerStream* server_stream = nullptr;
233 SetupCryptoServerStreamForTest(server_id_,
234 QuicTime::Delta::FromSeconds(100000),
235 &server_crypto_config_, &server_connection_,
236 &server_session, &server_stream);
237 CHECK(server_session);
238 CHECK(server_stream);
239 server_session_.reset(server_session);
240 server_stream_.reset(server_stream);
241 CryptoTestUtils::SetupCryptoServerConfigForTest(
242 server_connection_->clock(), server_connection_->random_generator(),
243 server_session_->config(), &server_crypto_config_);
244 server_stream_->set_use_stateless_rejects_if_peer_supported(true);
245 }
246
247 // Client crypto stream state
248 PacketSavingConnection* client_connection_;
249 scoped_ptr<TestClientSession> client_session_;
250 scoped_ptr<QuicCryptoClientStream> client_stream_;
251 QuicCryptoClientConfig client_crypto_config_;
252
253 // Server crypto stream state
254 PacketSavingConnection* server_connection_;
255 scoped_ptr<TestServerSession> server_session_;
256 QuicCryptoServerConfig server_crypto_config_;
257 scoped_ptr<QuicCryptoServerStream> server_stream_;
258 QuicServerId server_id_;
259 };
260
261 TEST_F(QuicCryptoClientStreamStatelessTest, StatelessReject) {
262 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stateless_reject_support,
263 true);
264
265 QuicCryptoClientConfig::CachedState* client_state =
266 client_crypto_config_.LookupOrCreate(server_id_);
267
268 EXPECT_FALSE(client_state->has_server_designated_connection_id());
269 EXPECT_CALL(*client_session_, OnProofValid(testing::_));
270
271 InitializeFakeStatelessRejectServer();
272 AdvanceHandshakeWithFakeServer();
273
274 EXPECT_FALSE(client_stream_->encryption_established());
275 EXPECT_FALSE(client_stream_->handshake_confirmed());
276 // Even though the handshake was not complete, the cached client_state is
277 // complete, and can be used for a subsequent successful handshake.
278 EXPECT_TRUE(client_state->IsComplete(QuicWallTime::FromUNIXSeconds(0)));
279
280 ASSERT_TRUE(client_state->has_server_designated_connection_id());
281 QuicConnectionId server_designated_id =
282 client_state->GetNextServerDesignatedConnectionId();
283 QuicConnectionId expected_id =
284 server_session_->connection()->random_generator()->RandUint64();
285 EXPECT_EQ(expected_id, server_designated_id);
286 EXPECT_FALSE(client_state->has_server_designated_connection_id());
287 }
288
203 } // namespace 289 } // namespace
204 } // namespace test 290 } // namespace test
205 } // namespace net 291 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_crypto_client_stream.cc ('k') | net/quic/quic_crypto_server_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698