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

Side by Side Diff: net/quic/crypto/quic_crypto_server_config_test.cc

Issue 623003002: QUIC: if client provides an STK which includes CachedNetworkParams, then (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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/crypto/quic_crypto_server_config.cc ('k') | net/quic/crypto/source_address_token.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/crypto/quic_crypto_server_config.h" 5 #include "net/quic/crypto/quic_crypto_server_config.h"
6 6
7 #include <stdarg.h> 7 #include <stdarg.h>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" 10 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
11 #include "net/quic/crypto/crypto_handshake_message.h" 11 #include "net/quic/crypto/crypto_handshake_message.h"
12 #include "net/quic/crypto/crypto_secret_boxer.h" 12 #include "net/quic/crypto/crypto_secret_boxer.h"
13 #include "net/quic/crypto/crypto_server_config_protobuf.h" 13 #include "net/quic/crypto/crypto_server_config_protobuf.h"
14 #include "net/quic/crypto/quic_random.h" 14 #include "net/quic/crypto/quic_random.h"
15 #include "net/quic/crypto/strike_register_client.h" 15 #include "net/quic/crypto/strike_register_client.h"
16 #include "net/quic/quic_flags.h"
16 #include "net/quic/quic_time.h" 17 #include "net/quic/quic_time.h"
17 #include "net/quic/test_tools/mock_clock.h" 18 #include "net/quic/test_tools/mock_clock.h"
18 #include "net/quic/test_tools/quic_test_utils.h" 19 #include "net/quic/test_tools/quic_test_utils.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 using base::StringPiece; 23 using base::StringPiece;
23 using std::make_pair; 24 using std::make_pair;
24 using std::map; 25 using std::map;
25 using std::pair; 26 using std::pair;
(...skipping 19 matching lines...) Expand all
45 } 46 }
46 47
47 bool ConfigHasDefaultSourceAddressTokenBoxer(string config_id) { 48 bool ConfigHasDefaultSourceAddressTokenBoxer(string config_id) {
48 scoped_refptr<QuicCryptoServerConfig::Config> config = GetConfig(config_id); 49 scoped_refptr<QuicCryptoServerConfig::Config> config = GetConfig(config_id);
49 return config->source_address_token_boxer == 50 return config->source_address_token_boxer ==
50 &(server_config_->default_source_address_token_boxer_); 51 &(server_config_->default_source_address_token_boxer_);
51 } 52 }
52 53
53 string NewSourceAddressToken( 54 string NewSourceAddressToken(
54 string config_id, 55 string config_id,
55 IPEndPoint ip, 56 const IPEndPoint& ip,
56 QuicRandom* rand, 57 QuicRandom* rand,
57 QuicWallTime now) { 58 QuicWallTime now) {
59 return NewSourceAddressToken(config_id, ip, rand, now, NULL);
60 }
61
62 string NewSourceAddressToken(
63 string config_id,
64 const IPEndPoint& ip,
65 QuicRandom* rand,
66 QuicWallTime now,
67 CachedNetworkParameters* cached_network_params) {
58 return server_config_->NewSourceAddressToken( 68 return server_config_->NewSourceAddressToken(
59 *GetConfig(config_id), ip, rand, now, nullptr); 69 *GetConfig(config_id), ip, rand, now, cached_network_params);
60 } 70 }
61 71
62 HandshakeFailureReason ValidateSourceAddressToken(string config_id, 72 HandshakeFailureReason ValidateSourceAddressToken(string config_id,
63 StringPiece srct, 73 StringPiece srct,
64 IPEndPoint ip, 74 const IPEndPoint& ip,
65 QuicWallTime now) { 75 QuicWallTime now) {
76 return ValidateSourceAddressToken(config_id, srct, ip, now, NULL);
77 }
78
79 HandshakeFailureReason ValidateSourceAddressToken(
80 string config_id,
81 StringPiece srct,
82 const IPEndPoint& ip,
83 QuicWallTime now,
84 CachedNetworkParameters* cached_network_params) {
66 return server_config_->ValidateSourceAddressToken( 85 return server_config_->ValidateSourceAddressToken(
67 *GetConfig(config_id), srct, ip, now); 86 *GetConfig(config_id), srct, ip, now, cached_network_params);
68 } 87 }
69 88
70 string NewServerNonce(QuicRandom* rand, QuicWallTime now) const { 89 string NewServerNonce(QuicRandom* rand, QuicWallTime now) const {
71 return server_config_->NewServerNonce(rand, now); 90 return server_config_->NewServerNonce(rand, now);
72 } 91 }
73 92
74 HandshakeFailureReason ValidateServerNonce(StringPiece token, 93 HandshakeFailureReason ValidateServerNonce(StringPiece token,
75 QuicWallTime now) { 94 QuicWallTime now) {
76 return server_config_->ValidateServerNonce(token, now); 95 return server_config_->ValidateServerNonce(token, now);
77 } 96 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 new TestStrikeRegisterClient(&server); 253 new TestStrikeRegisterClient(&server);
235 server.SetStrikeRegisterClient(strike_register); 254 server.SetStrikeRegisterClient(strike_register);
236 255
237 QuicCryptoServerConfig::ConfigOptions options; 256 QuicCryptoServerConfig::ConfigOptions options;
238 scoped_ptr<CryptoHandshakeMessage>( 257 scoped_ptr<CryptoHandshakeMessage>(
239 server.AddDefaultConfig(rand, &clock, options)); 258 server.AddDefaultConfig(rand, &clock, options));
240 EXPECT_TRUE(strike_register->is_known_orbit_called()); 259 EXPECT_TRUE(strike_register->is_known_orbit_called());
241 } 260 }
242 261
243 TEST(QuicCryptoServerConfigTest, SourceAddressTokens) { 262 TEST(QuicCryptoServerConfigTest, SourceAddressTokens) {
263 ValueRestore<bool> old_flag(&FLAGS_quic_store_cached_network_params_from_chlo,
264 true);
244 const string kPrimary = "<primary>"; 265 const string kPrimary = "<primary>";
245 const string kOverride = "Config with custom source address token key"; 266 const string kOverride = "Config with custom source address token key";
246 267
247 MockClock clock; 268 MockClock clock;
248 clock.AdvanceTime(QuicTime::Delta::FromSeconds(1000000)); 269 clock.AdvanceTime(QuicTime::Delta::FromSeconds(1000000));
249 270
250 QuicWallTime now = clock.WallNow(); 271 QuicWallTime now = clock.WallNow();
251 const QuicWallTime original_time = now; 272 const QuicWallTime original_time = now;
252 273
253 QuicRandom* rand = QuicRandom::GetInstance(); 274 QuicRandom* rand = QuicRandom::GetInstance();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 now)); 343 now));
323 344
324 // Validation fails after tokens expire. 345 // Validation fails after tokens expire.
325 now = original_time.Add(QuicTime::Delta::FromSeconds(86400 * 7)); 346 now = original_time.Add(QuicTime::Delta::FromSeconds(86400 * 7));
326 DCHECK_EQ(SOURCE_ADDRESS_TOKEN_EXPIRED_FAILURE, 347 DCHECK_EQ(SOURCE_ADDRESS_TOKEN_EXPIRED_FAILURE,
327 peer.ValidateSourceAddressToken(kPrimary, token4, ip4, now)); 348 peer.ValidateSourceAddressToken(kPrimary, token4, ip4, now));
328 349
329 now = original_time.Subtract(QuicTime::Delta::FromSeconds(3600 * 2)); 350 now = original_time.Subtract(QuicTime::Delta::FromSeconds(3600 * 2));
330 DCHECK_EQ(SOURCE_ADDRESS_TOKEN_CLOCK_SKEW_FAILURE, 351 DCHECK_EQ(SOURCE_ADDRESS_TOKEN_CLOCK_SKEW_FAILURE,
331 peer.ValidateSourceAddressToken(kPrimary, token4, ip4, now)); 352 peer.ValidateSourceAddressToken(kPrimary, token4, ip4, now));
353
354 // Make sure that if the source address token contains CachedNetworkParameters
355 // that this gets written to ValidateSourceAddressToken output argument.
356 CachedNetworkParameters cached_network_params_input;
357 cached_network_params_input.set_bandwidth_estimate_bytes_per_second(1234);
358 const string token4_with_cached_network_params = peer.NewSourceAddressToken(
359 kPrimary, ip4, rand, now, &cached_network_params_input);
360
361 CachedNetworkParameters cached_network_params_output;
362 EXPECT_NE(cached_network_params_output, cached_network_params_input);
363 peer.ValidateSourceAddressToken(kPrimary, token4_with_cached_network_params,
364 ip4, now, &cached_network_params_output);
365 // TODO(rtenneti): For server, enable the following check after serialization
366 // of optional CachedNetworkParameters is implemented.
367 // EXPECT_EQ(cached_network_params_output, cached_network_params_input);
332 } 368 }
333 369
334 TEST(QuicCryptoServerConfigTest, ValidateServerNonce) { 370 TEST(QuicCryptoServerConfigTest, ValidateServerNonce) {
335 QuicRandom* rand = QuicRandom::GetInstance(); 371 QuicRandom* rand = QuicRandom::GetInstance();
336 QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand); 372 QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand);
337 QuicCryptoServerConfigPeer peer(&server); 373 QuicCryptoServerConfigPeer peer(&server);
338 374
339 StringPiece message("hello world"); 375 StringPiece message("hello world");
340 const size_t key_size = CryptoSecretBoxer::GetKeySize(); 376 const size_t key_size = CryptoSecretBoxer::GetKeySize();
341 scoped_ptr<uint8[]> key(new uint8[key_size]); 377 scoped_ptr<uint8[]> key(new uint8[key_size]);
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 nullptr); 696 nullptr);
661 test_peer_.CheckConfigs( 697 test_peer_.CheckConfigs(
662 "a", false, 698 "a", false,
663 "b", true, 699 "b", true,
664 "c", false, 700 "c", false,
665 nullptr); 701 nullptr);
666 } 702 }
667 703
668 } // namespace test 704 } // namespace test
669 } // namespace net 705 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/quic_crypto_server_config.cc ('k') | net/quic/crypto/source_address_token.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698