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

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

Issue 15937012: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small bug fixes Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/crypto_handshake.h" 5 #include "net/quic/crypto/crypto_handshake.h"
6 6
7 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" 7 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
8 #include "net/quic/crypto/crypto_server_config.h" 8 #include "net/quic/crypto/crypto_server_config.h"
9 #include "net/quic/crypto/quic_random.h" 9 #include "net/quic/crypto/quic_random.h"
10 #include "net/quic/quic_time.h" 10 #include "net/quic/quic_time.h"
(...skipping 22 matching lines...) Expand all
33 IPEndPoint ip, 33 IPEndPoint ip,
34 QuicWallTime now) { 34 QuicWallTime now) {
35 return server_config_->ValidateSourceAddressToken(srct, ip, now); 35 return server_config_->ValidateSourceAddressToken(srct, ip, now);
36 } 36 }
37 37
38 private: 38 private:
39 QuicCryptoServerConfig* const server_config_; 39 QuicCryptoServerConfig* const server_config_;
40 }; 40 };
41 41
42 TEST(QuicCryptoServerConfigTest, ServerConfig) { 42 TEST(QuicCryptoServerConfigTest, ServerConfig) {
43 QuicCryptoServerConfig server("source address token secret"); 43 QuicRandom* rand = QuicRandom::GetInstance();
44 QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand);
44 MockClock clock; 45 MockClock clock;
45 46
46 scoped_ptr<CryptoHandshakeMessage>( 47 scoped_ptr<CryptoHandshakeMessage>(
47 server.AddDefaultConfig(QuicRandom::GetInstance(), &clock, 48 server.AddDefaultConfig(rand, &clock,
48 QuicCryptoServerConfig::kDefaultExpiry)); 49 QuicCryptoServerConfig::ConfigOptions()));
49 } 50 }
50 51
51 TEST(QuicCryptoServerConfigTest, SourceAddressTokens) { 52 TEST(QuicCryptoServerConfigTest, SourceAddressTokens) {
52 if (!Aes128Gcm12Encrypter::IsSupported()) { 53 if (!Aes128Gcm12Encrypter::IsSupported()) {
53 LOG(INFO) << "AES GCM not supported. Test skipped."; 54 LOG(INFO) << "AES GCM not supported. Test skipped.";
54 return; 55 return;
55 } 56 }
56 57
57 QuicCryptoServerConfig server("source address token secret"); 58 QuicRandom* rand = QuicRandom::GetInstance();
59 QuicCryptoServerConfig server(QuicCryptoServerConfig::TESTING, rand);
58 IPAddressNumber ip; 60 IPAddressNumber ip;
59 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); 61 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip));
60 IPEndPoint ip4 = IPEndPoint(ip, 1); 62 IPEndPoint ip4 = IPEndPoint(ip, 1);
61 CHECK(ParseIPLiteralToNumber("2001:db8:0::42", &ip)); 63 CHECK(ParseIPLiteralToNumber("2001:db8:0::42", &ip));
62 IPEndPoint ip6 = IPEndPoint(ip, 2); 64 IPEndPoint ip6 = IPEndPoint(ip, 2);
63 QuicRandom* rand = QuicRandom::GetInstance();
64 MockClock clock; 65 MockClock clock;
65 clock.AdvanceTime(QuicTime::Delta::FromSeconds(1000000)); 66 clock.AdvanceTime(QuicTime::Delta::FromSeconds(1000000));
66 QuicCryptoServerConfigPeer peer(&server); 67 QuicCryptoServerConfigPeer peer(&server);
67 68
68 QuicWallTime now = clock.WallNow(); 69 QuicWallTime now = clock.WallNow();
69 const QuicWallTime original_time = now; 70 const QuicWallTime original_time = now;
70 71
71 const string token4 = peer.NewSourceAddressToken(ip4, rand, now); 72 const string token4 = peer.NewSourceAddressToken(ip4, rand, now);
72 const string token6 = peer.NewSourceAddressToken(ip6, rand, now); 73 const string token6 = peer.NewSourceAddressToken(ip6, rand, now);
73 EXPECT_TRUE(peer.ValidateSourceAddressToken(token4, ip4, now)); 74 EXPECT_TRUE(peer.ValidateSourceAddressToken(token4, ip4, now));
74 EXPECT_FALSE(peer.ValidateSourceAddressToken(token4, ip6, now)); 75 EXPECT_FALSE(peer.ValidateSourceAddressToken(token4, ip6, now));
75 EXPECT_TRUE(peer.ValidateSourceAddressToken(token6, ip6, now)); 76 EXPECT_TRUE(peer.ValidateSourceAddressToken(token6, ip6, now));
76 77
77 now = original_time.Add(QuicTime::Delta::FromSeconds(86400 * 7)); 78 now = original_time.Add(QuicTime::Delta::FromSeconds(86400 * 7));
78 EXPECT_FALSE(peer.ValidateSourceAddressToken(token4, ip4, now)); 79 EXPECT_FALSE(peer.ValidateSourceAddressToken(token4, ip4, now));
79 80
80 now = original_time.Subtract(QuicTime::Delta::FromSeconds(3600 * 2)); 81 now = original_time.Subtract(QuicTime::Delta::FromSeconds(3600 * 2));
81 EXPECT_FALSE(peer.ValidateSourceAddressToken(token4, ip4, now)); 82 EXPECT_FALSE(peer.ValidateSourceAddressToken(token4, ip4, now));
82 } 83 }
83 84
84 } // namespace test 85 } // namespace test
85 } // namespace net 86 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698