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

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

Issue 159143007: Log QUIC public reset client address mismatch to a histogram. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Address review comments Created 6 years, 10 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/strings/string_number_conversions.h" 6 #include "base/strings/string_number_conversions.h"
7 #include "crypto/secure_hash.h" 7 #include "crypto/secure_hash.h"
8 #include "net/quic/crypto/crypto_utils.h" 8 #include "net/quic/crypto/crypto_utils.h"
9 #include "net/quic/crypto/quic_crypto_server_config.h" 9 #include "net/quic/crypto/quic_crypto_server_config.h"
10 #include "net/quic/crypto/quic_random.h" 10 #include "net/quic/crypto/quic_random.h"
11 #include "net/quic/quic_socket_address_coder.h"
11 #include "net/quic/quic_utils.h" 12 #include "net/quic/quic_utils.h"
12 #include "net/quic/test_tools/crypto_test_utils.h" 13 #include "net/quic/test_tools/crypto_test_utils.h"
13 #include "net/quic/test_tools/delayed_verify_strike_register_client.h" 14 #include "net/quic/test_tools/delayed_verify_strike_register_client.h"
14 #include "net/quic/test_tools/mock_clock.h" 15 #include "net/quic/test_tools/mock_clock.h"
15 #include "net/quic/test_tools/mock_random.h" 16 #include "net/quic/test_tools/mock_random.h"
16 #include "net/quic/test_tools/quic_test_utils.h" 17 #include "net/quic/test_tools/quic_test_utils.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 using base::StringPiece; 20 using base::StringPiece;
20 using std::string; 21 using std::string;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 *called_ = true; 121 *called_ = true;
121 } 122 }
122 123
123 private: 124 private:
124 CryptoServerTest* test_; 125 CryptoServerTest* test_;
125 bool should_succeed_; 126 bool should_succeed_;
126 const char* error_substr_; 127 const char* error_substr_;
127 bool* called_; 128 bool* called_;
128 }; 129 };
129 130
131 void CheckServerHello(const CryptoHandshakeMessage& server_hello) {
132 const QuicTag* versions;
133 size_t num_versions;
134 server_hello.GetTaglist(kVER, &versions, &num_versions);
135 ASSERT_EQ(QuicSupportedVersions().size(), num_versions);
136 for (size_t i = 0; i < num_versions; ++i) {
137 EXPECT_EQ(QuicVersionToQuicTag(QuicSupportedVersions()[i]), versions[i]);
138 }
139
140 StringPiece address;
141 ASSERT_TRUE(server_hello.GetStringPiece(kCADR, &address));
142 QuicSocketAddressCoder decoder;
143 ASSERT_TRUE(decoder.Decode(address.data(), address.size()));
144 EXPECT_EQ(client_address_.address(), decoder.ip());
145 EXPECT_EQ(client_address_.port(), decoder.port());
146 }
147
130 void ShouldSucceed(const CryptoHandshakeMessage& message) { 148 void ShouldSucceed(const CryptoHandshakeMessage& message) {
131 bool called = false; 149 bool called = false;
132 RunValidate(message, new ValidateCallback(this, true, "", &called)); 150 RunValidate(message, new ValidateCallback(this, true, "", &called));
133 EXPECT_TRUE(called); 151 EXPECT_TRUE(called);
134 } 152 }
135 153
136 void RunValidate( 154 void RunValidate(
137 const CryptoHandshakeMessage& message, 155 const CryptoHandshakeMessage& message,
138 ValidateClientHelloResultCallback* cb) { 156 ValidateClientHelloResultCallback* cb) {
139 config_.ValidateClientHello(message, client_address_, &clock_, cb); 157 config_.ValidateClientHello(message, client_address_, &clock_, cb);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 ShouldSucceed(msg); 344 ShouldSucceed(msg);
327 // The message should be rejected because the strike-register is still 345 // The message should be rejected because the strike-register is still
328 // quiescent. 346 // quiescent.
329 ASSERT_EQ(kREJ, out_.tag()); 347 ASSERT_EQ(kREJ, out_.tag());
330 348
331 config_.set_replay_protection(false); 349 config_.set_replay_protection(false);
332 350
333 ShouldSucceed(msg); 351 ShouldSucceed(msg);
334 // The message should be accepted now. 352 // The message should be accepted now.
335 ASSERT_EQ(kSHLO, out_.tag()); 353 ASSERT_EQ(kSHLO, out_.tag());
354 CheckServerHello(out_);
336 355
337 ShouldSucceed(msg); 356 ShouldSucceed(msg);
338 // The message should accepted twice when replay protection is off. 357 // The message should accepted twice when replay protection is off.
339 ASSERT_EQ(kSHLO, out_.tag()); 358 ASSERT_EQ(kSHLO, out_.tag());
340 const QuicTag* versions; 359 CheckServerHello(out_);
341 size_t num_versions;
342 out_.GetTaglist(kVER, &versions, &num_versions);
343 ASSERT_EQ(QuicSupportedVersions().size(), num_versions);
344 for (size_t i = 0; i < num_versions; ++i) {
345 EXPECT_EQ(QuicVersionToQuicTag(QuicSupportedVersions()[i]), versions[i]);
346 }
347 } 360 }
348 361
349 TEST(CryptoServerConfigGenerationTest, Determinism) { 362 TEST(CryptoServerConfigGenerationTest, Determinism) {
350 // Test that using a deterministic PRNG causes the server-config to be 363 // Test that using a deterministic PRNG causes the server-config to be
351 // deterministic. 364 // deterministic.
352 365
353 MockRandom rand_a, rand_b; 366 MockRandom rand_a, rand_b;
354 const QuicCryptoServerConfig::ConfigOptions options; 367 const QuicCryptoServerConfig::ConfigOptions options;
355 MockClock clock; 368 MockClock clock;
356 369
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 502
490 strike_register_client_->RunPendingVerifications(); 503 strike_register_client_->RunPendingVerifications();
491 ASSERT_TRUE(called); 504 ASSERT_TRUE(called);
492 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); 505 EXPECT_EQ(0, strike_register_client_->PendingVerifications());
493 // The message should be rejected now. 506 // The message should be rejected now.
494 EXPECT_EQ(kREJ, out_.tag()); 507 EXPECT_EQ(kREJ, out_.tag());
495 } 508 }
496 509
497 } // namespace test 510 } // namespace test
498 } // namespace net 511 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/crypto_handshake_message.cc ('k') | net/quic/crypto/quic_crypto_client_config.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698