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

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

Issue 1437023002: Landing Recent QUIC changes until 2015-11-09 20:32 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 28 matching lines...) Expand all
39 connection_ = new PacketSavingConnection(&helper_, Perspective::IS_CLIENT); 39 connection_ = new PacketSavingConnection(&helper_, Perspective::IS_CLIENT);
40 // Advance the time, because timers do not like uninitialized times. 40 // Advance the time, because timers do not like uninitialized times.
41 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); 41 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
42 42
43 session_.reset(new TestQuicSpdyClientSession( 43 session_.reset(new TestQuicSpdyClientSession(
44 connection_, DefaultQuicConfig(), server_id_, &crypto_config_)); 44 connection_, DefaultQuicConfig(), server_id_, &crypto_config_));
45 } 45 }
46 46
47 void CompleteCryptoHandshake() { 47 void CompleteCryptoHandshake() {
48 stream()->CryptoConnect(); 48 stream()->CryptoConnect();
49 CryptoTestUtils::HandshakeWithFakeServer(&helper_, connection_, stream()); 49 CryptoTestUtils::HandshakeWithFakeServer(&helper_, connection_, stream(),
50 server_options_);
50 } 51 }
51 52
52 void ConstructHandshakeMessage() { 53 void ConstructHandshakeMessage() {
53 CryptoFramer framer; 54 CryptoFramer framer;
54 message_data_.reset(framer.ConstructHandshakeMessage(message_)); 55 message_data_.reset(framer.ConstructHandshakeMessage(message_));
55 } 56 }
56 57
57 QuicCryptoClientStream* stream() { return session_->GetCryptoStream(); } 58 QuicCryptoClientStream* stream() { return session_->GetCryptoStream(); }
58 59
59 MockConnectionHelper helper_; 60 MockConnectionHelper helper_;
60 PacketSavingConnection* connection_; 61 PacketSavingConnection* connection_;
61 scoped_ptr<TestQuicSpdyClientSession> session_; 62 scoped_ptr<TestQuicSpdyClientSession> session_;
62 QuicServerId server_id_; 63 QuicServerId server_id_;
63 CryptoHandshakeMessage message_; 64 CryptoHandshakeMessage message_;
64 scoped_ptr<QuicData> message_data_; 65 scoped_ptr<QuicData> message_data_;
65 QuicCryptoClientConfig crypto_config_; 66 QuicCryptoClientConfig crypto_config_;
67 CryptoTestUtils::FakeServerOptions server_options_;
66 }; 68 };
67 69
68 TEST_F(QuicCryptoClientStreamTest, NotInitiallyConected) { 70 TEST_F(QuicCryptoClientStreamTest, NotInitiallyConected) {
69 EXPECT_FALSE(stream()->encryption_established()); 71 EXPECT_FALSE(stream()->encryption_established());
70 EXPECT_FALSE(stream()->handshake_confirmed()); 72 EXPECT_FALSE(stream()->handshake_confirmed());
71 } 73 }
72 74
73 TEST_F(QuicCryptoClientStreamTest, ConnectedAfterSHLO) { 75 TEST_F(QuicCryptoClientStreamTest, ConnectedAfterSHLO) {
74 CompleteCryptoHandshake(); 76 CompleteCryptoHandshake();
75 EXPECT_TRUE(stream()->encryption_established()); 77 EXPECT_TRUE(stream()->encryption_established());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 EXPECT_CALL(*connection_, SendConnectionClose( 190 EXPECT_CALL(*connection_, SendConnectionClose(
189 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE)); 191 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE));
190 CryptoHandshakeMessage server_config_update; 192 CryptoHandshakeMessage server_config_update;
191 server_config_update.set_tag(kSCUP); 193 server_config_update.set_tag(kSCUP);
192 scoped_ptr<QuicData> data( 194 scoped_ptr<QuicData> data(
193 CryptoFramer::ConstructHandshakeMessage(server_config_update)); 195 CryptoFramer::ConstructHandshakeMessage(server_config_update));
194 stream()->OnStreamFrame(QuicStreamFrame(kCryptoStreamId, /*fin=*/false, 196 stream()->OnStreamFrame(QuicStreamFrame(kCryptoStreamId, /*fin=*/false,
195 /*offset=*/0, data->AsStringPiece())); 197 /*offset=*/0, data->AsStringPiece()));
196 } 198 }
197 199
200 TEST_F(QuicCryptoClientStreamTest, TokenBindingNegotiation) {
201 server_options_.token_binding_enabled = true;
202 crypto_config_.tb_key_params.push_back(kP256);
203
204 CompleteCryptoHandshake();
205 EXPECT_TRUE(stream()->encryption_established());
206 EXPECT_TRUE(stream()->handshake_confirmed());
207 EXPECT_EQ(kP256,
208 stream()->crypto_negotiated_params().token_binding_key_param);
209 }
210
211 TEST_F(QuicCryptoClientStreamTest, NoTokenBindingWithoutServerSupport) {
212 crypto_config_.tb_key_params.push_back(kP256);
213
214 CompleteCryptoHandshake();
215 EXPECT_TRUE(stream()->encryption_established());
216 EXPECT_TRUE(stream()->handshake_confirmed());
217 EXPECT_EQ(0u, stream()->crypto_negotiated_params().token_binding_key_param);
218 }
219
220 TEST_F(QuicCryptoClientStreamTest, NoTokenBindingWithoutClientSupport) {
221 server_options_.token_binding_enabled = true;
222
223 CompleteCryptoHandshake();
224 EXPECT_TRUE(stream()->encryption_established());
225 EXPECT_TRUE(stream()->handshake_confirmed());
226 EXPECT_EQ(0u, stream()->crypto_negotiated_params().token_binding_key_param);
227 }
228
229 TEST_F(QuicCryptoClientStreamTest, TokenBindingNotNegotiated) {
230 CompleteCryptoHandshake();
231 EXPECT_TRUE(stream()->encryption_established());
232 EXPECT_TRUE(stream()->handshake_confirmed());
233 EXPECT_EQ(0u, stream()->crypto_negotiated_params().token_binding_key_param);
234 }
235
198 class QuicCryptoClientStreamStatelessTest : public ::testing::Test { 236 class QuicCryptoClientStreamStatelessTest : public ::testing::Test {
199 public: 237 public:
200 QuicCryptoClientStreamStatelessTest() 238 QuicCryptoClientStreamStatelessTest()
201 : client_crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), 239 : client_crypto_config_(CryptoTestUtils::ProofVerifierForTesting()),
202 server_crypto_config_(QuicCryptoServerConfig::TESTING, 240 server_crypto_config_(QuicCryptoServerConfig::TESTING,
203 QuicRandom::GetInstance(), 241 QuicRandom::GetInstance(),
204 CryptoTestUtils::ProofSourceForTesting()), 242 CryptoTestUtils::ProofSourceForTesting()),
205 server_id_(kServerHostname, kServerPort, PRIVACY_MODE_DISABLED) { 243 server_id_(kServerHostname, kServerPort, PRIVACY_MODE_DISABLED) {
206 TestQuicSpdyClientSession* client_session = nullptr; 244 TestQuicSpdyClientSession* client_session = nullptr;
207 CreateClientSessionForTest(server_id_, 245 CreateClientSessionForTest(server_id_,
(...skipping 17 matching lines...) Expand all
225 } 263 }
226 264
227 // Initializes the server_stream_ for stateless rejects. 265 // Initializes the server_stream_ for stateless rejects.
228 void InitializeFakeStatelessRejectServer() { 266 void InitializeFakeStatelessRejectServer() {
229 TestQuicSpdyServerSession* server_session = nullptr; 267 TestQuicSpdyServerSession* server_session = nullptr;
230 CreateServerSessionForTest(server_id_, QuicTime::Delta::FromSeconds(100000), 268 CreateServerSessionForTest(server_id_, QuicTime::Delta::FromSeconds(100000),
231 &helper_, &server_crypto_config_, 269 &helper_, &server_crypto_config_,
232 &server_connection_, &server_session); 270 &server_connection_, &server_session);
233 CHECK(server_session); 271 CHECK(server_session);
234 server_session_.reset(server_session); 272 server_session_.reset(server_session);
273 CryptoTestUtils::FakeServerOptions options;
235 CryptoTestUtils::SetupCryptoServerConfigForTest( 274 CryptoTestUtils::SetupCryptoServerConfigForTest(
236 server_connection_->clock(), server_connection_->random_generator(), 275 server_connection_->clock(), server_connection_->random_generator(),
237 server_session_->config(), &server_crypto_config_); 276 server_session_->config(), &server_crypto_config_, options);
238 FLAGS_enable_quic_stateless_reject_support = true; 277 FLAGS_enable_quic_stateless_reject_support = true;
239 } 278 }
240 279
241 MockConnectionHelper helper_; 280 MockConnectionHelper helper_;
242 281
243 // Client crypto stream state 282 // Client crypto stream state
244 PacketSavingConnection* client_connection_; 283 PacketSavingConnection* client_connection_;
245 scoped_ptr<TestQuicSpdyClientSession> client_session_; 284 scoped_ptr<TestQuicSpdyClientSession> client_session_;
246 QuicCryptoClientConfig client_crypto_config_; 285 QuicCryptoClientConfig client_crypto_config_;
247 286
(...skipping 10 matching lines...) Expand all
258 297
259 QuicCryptoClientConfig::CachedState* client_state = 298 QuicCryptoClientConfig::CachedState* client_state =
260 client_crypto_config_.LookupOrCreate(server_id_); 299 client_crypto_config_.LookupOrCreate(server_id_);
261 300
262 EXPECT_FALSE(client_state->has_server_designated_connection_id()); 301 EXPECT_FALSE(client_state->has_server_designated_connection_id());
263 EXPECT_CALL(*client_session_, OnProofValid(testing::_)); 302 EXPECT_CALL(*client_session_, OnProofValid(testing::_));
264 303
265 InitializeFakeStatelessRejectServer(); 304 InitializeFakeStatelessRejectServer();
266 AdvanceHandshakeWithFakeServer(); 305 AdvanceHandshakeWithFakeServer();
267 306
268 EXPECT_EQ(1, server_stream()->num_handshake_messages()); 307 EXPECT_EQ(1, server_stream()->NumHandshakeMessages());
269 EXPECT_EQ(0, server_stream()->num_handshake_messages_with_server_nonces()); 308 EXPECT_EQ(0, server_stream()->NumHandshakeMessagesWithServerNonces());
270 309
271 EXPECT_FALSE(client_session_->GetCryptoStream()->encryption_established()); 310 EXPECT_FALSE(client_session_->GetCryptoStream()->encryption_established());
272 EXPECT_FALSE(client_session_->GetCryptoStream()->handshake_confirmed()); 311 EXPECT_FALSE(client_session_->GetCryptoStream()->handshake_confirmed());
273 // Even though the handshake was not complete, the cached client_state is 312 // Even though the handshake was not complete, the cached client_state is
274 // complete, and can be used for a subsequent successful handshake. 313 // complete, and can be used for a subsequent successful handshake.
275 EXPECT_TRUE(client_state->IsComplete(QuicWallTime::FromUNIXSeconds(0))); 314 EXPECT_TRUE(client_state->IsComplete(QuicWallTime::FromUNIXSeconds(0)));
276 315
277 ASSERT_TRUE(client_state->has_server_nonce()); 316 ASSERT_TRUE(client_state->has_server_nonce());
278 ASSERT_FALSE(client_state->GetNextServerNonce().empty()); 317 ASSERT_FALSE(client_state->GetNextServerNonce().empty());
279 ASSERT_TRUE(client_state->has_server_designated_connection_id()); 318 ASSERT_TRUE(client_state->has_server_designated_connection_id());
280 QuicConnectionId server_designated_id = 319 QuicConnectionId server_designated_id =
281 client_state->GetNextServerDesignatedConnectionId(); 320 client_state->GetNextServerDesignatedConnectionId();
282 QuicConnectionId expected_id = 321 QuicConnectionId expected_id =
283 server_session_->connection()->random_generator()->RandUint64(); 322 server_session_->connection()->random_generator()->RandUint64();
284 EXPECT_EQ(expected_id, server_designated_id); 323 EXPECT_EQ(expected_id, server_designated_id);
285 EXPECT_FALSE(client_state->has_server_designated_connection_id()); 324 EXPECT_FALSE(client_state->has_server_designated_connection_id());
286 } 325 }
287 326
288 } // namespace 327 } // namespace
289 } // namespace test 328 } // namespace test
290 } // namespace net 329 } // 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