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

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

Issue 2453113002: Fix object-lifetime issues in async GetProof callpaths (Closed)
Patch Set: Updated patchset dependency Created 4 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
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 <algorithm> 5 #include <algorithm>
6 #include <cstdint> 6 #include <cstdint>
7 #include <memory> 7 #include <memory>
8 #include <ostream> 8 #include <ostream>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 class CryptoServerTest : public ::testing::TestWithParam<TestParams> { 105 class CryptoServerTest : public ::testing::TestWithParam<TestParams> {
106 public: 106 public:
107 CryptoServerTest() 107 CryptoServerTest()
108 : rand_(QuicRandom::GetInstance()), 108 : rand_(QuicRandom::GetInstance()),
109 client_address_(Loopback4(), 1234), 109 client_address_(Loopback4(), 1234),
110 config_(QuicCryptoServerConfig::TESTING, 110 config_(QuicCryptoServerConfig::TESTING,
111 rand_, 111 rand_,
112 CryptoTestUtils::ProofSourceForTesting()), 112 CryptoTestUtils::ProofSourceForTesting()),
113 compressed_certs_cache_( 113 compressed_certs_cache_(
114 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize), 114 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize),
115 params_(new QuicCryptoNegotiatedParameters),
116 crypto_proof_(new QuicCryptoProof),
115 chlo_packet_size_(kDefaultMaxPacketSize) { 117 chlo_packet_size_(kDefaultMaxPacketSize) {
116 supported_versions_ = GetParam().supported_versions; 118 supported_versions_ = GetParam().supported_versions;
117 config_.set_enable_serving_sct(true); 119 config_.set_enable_serving_sct(true);
118 120
119 client_version_ = supported_versions_.front(); 121 client_version_ = supported_versions_.front();
120 client_version_string_ = 122 client_version_string_ =
121 QuicUtils::TagToString(QuicVersionToQuicTag(client_version_)); 123 QuicUtils::TagToString(QuicVersionToQuicTag(client_version_));
122 124
123 FLAGS_quic_require_handshake_confirmation_pre33 = false; 125 FLAGS_quic_require_handshake_confirmation_pre33 = false;
124 FLAGS_enable_quic_stateless_reject_support = 126 FLAGS_enable_quic_stateless_reject_support =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 srct_hex_ = "#" + QuicUtils::HexEncode(srct); 177 srct_hex_ = "#" + QuicUtils::HexEncode(srct);
176 178
177 StringPiece scfg; 179 StringPiece scfg;
178 ASSERT_TRUE(out_.GetStringPiece(kSCFG, &scfg)); 180 ASSERT_TRUE(out_.GetStringPiece(kSCFG, &scfg));
179 server_config_.reset(CryptoFramer::ParseMessage(scfg)); 181 server_config_.reset(CryptoFramer::ParseMessage(scfg));
180 182
181 StringPiece scid; 183 StringPiece scid;
182 ASSERT_TRUE(server_config_->GetStringPiece(kSCID, &scid)); 184 ASSERT_TRUE(server_config_->GetStringPiece(kSCID, &scid));
183 scid_hex_ = "#" + QuicUtils::HexEncode(scid); 185 scid_hex_ = "#" + QuicUtils::HexEncode(scid);
184 186
185 crypto_proof_ = QuicCryptoProof(); 187 crypto_proof_ = scoped_refptr<QuicCryptoProof>(new QuicCryptoProof());
186 DCHECK(crypto_proof_.chain.get() == nullptr); 188 DCHECK(crypto_proof_->chain.get() == nullptr);
187 } 189 }
188 190
189 // Helper used to accept the result of ValidateClientHello and pass 191 // Helper used to accept the result of ValidateClientHello and pass
190 // it on to ProcessClientHello. 192 // it on to ProcessClientHello.
191 class ValidateCallback : public ValidateClientHelloResultCallback { 193 class ValidateCallback : public ValidateClientHelloResultCallback {
192 public: 194 public:
193 ValidateCallback(CryptoServerTest* test, 195 ValidateCallback(CryptoServerTest* test,
194 bool should_succeed, 196 bool should_succeed,
195 const char* error_substr, 197 const char* error_substr,
196 bool* called) 198 bool* called)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 ASSERT_TRUE(decoder.Decode(address.data(), address.size())); 242 ASSERT_TRUE(decoder.Decode(address.data(), address.size()));
241 EXPECT_EQ(client_address_.address(), decoder.ip()); 243 EXPECT_EQ(client_address_.address(), decoder.ip());
242 EXPECT_EQ(client_address_.port(), decoder.port()); 244 EXPECT_EQ(client_address_.port(), decoder.port());
243 } 245 }
244 246
245 void ShouldSucceed(const CryptoHandshakeMessage& message) { 247 void ShouldSucceed(const CryptoHandshakeMessage& message) {
246 bool called = false; 248 bool called = false;
247 IPAddress server_ip; 249 IPAddress server_ip;
248 config_.ValidateClientHello( 250 config_.ValidateClientHello(
249 message, client_address_.address(), server_ip, 251 message, client_address_.address(), server_ip,
250 supported_versions_.front(), &clock_, &crypto_proof_, 252 supported_versions_.front(), &clock_, crypto_proof_,
251 std::unique_ptr<ValidateCallback>( 253 std::unique_ptr<ValidateCallback>(
252 new ValidateCallback(this, true, "", &called))); 254 new ValidateCallback(this, true, "", &called)));
253 EXPECT_TRUE(called); 255 EXPECT_TRUE(called);
254 } 256 }
255 257
256 void ShouldFailMentioning(const char* error_substr, 258 void ShouldFailMentioning(const char* error_substr,
257 const CryptoHandshakeMessage& message) { 259 const CryptoHandshakeMessage& message) {
258 bool called = false; 260 bool called = false;
259 ShouldFailMentioning(error_substr, message, &called); 261 ShouldFailMentioning(error_substr, message, &called);
260 EXPECT_TRUE(called); 262 EXPECT_TRUE(called);
261 } 263 }
262 264
263 void ShouldFailMentioning(const char* error_substr, 265 void ShouldFailMentioning(const char* error_substr,
264 const CryptoHandshakeMessage& message, 266 const CryptoHandshakeMessage& message,
265 bool* called) { 267 bool* called) {
266 IPAddress server_ip; 268 IPAddress server_ip;
267 config_.ValidateClientHello( 269 config_.ValidateClientHello(
268 message, client_address_.address(), server_ip, 270 message, client_address_.address(), server_ip,
269 supported_versions_.front(), &clock_, &crypto_proof_, 271 supported_versions_.front(), &clock_, crypto_proof_,
270 std::unique_ptr<ValidateCallback>( 272 std::unique_ptr<ValidateCallback>(
271 new ValidateCallback(this, false, error_substr, called))); 273 new ValidateCallback(this, false, error_substr, called)));
272 } 274 }
273 275
274 class ProcessCallback : public ProcessClientHelloResultCallback { 276 class ProcessCallback : public ProcessClientHelloResultCallback {
275 public: 277 public:
276 ProcessCallback(scoped_refptr<ValidateCallback::Result> result, 278 ProcessCallback(scoped_refptr<ValidateCallback::Result> result,
277 bool should_succeed, 279 bool should_succeed,
278 const char* error_substr, 280 const char* error_substr,
279 bool* called, 281 bool* called,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 bool should_succeed, 322 bool should_succeed,
321 const char* error_substr) { 323 const char* error_substr) {
322 IPAddress server_ip; 324 IPAddress server_ip;
323 QuicConnectionId server_designated_connection_id = 325 QuicConnectionId server_designated_connection_id =
324 rand_for_id_generation_.RandUint64(); 326 rand_for_id_generation_.RandUint64();
325 bool called; 327 bool called;
326 config_.ProcessClientHello( 328 config_.ProcessClientHello(
327 result, /*reject_only=*/false, /*connection_id=*/1, server_ip, 329 result, /*reject_only=*/false, /*connection_id=*/1, server_ip,
328 client_address_, supported_versions_.front(), supported_versions_, 330 client_address_, supported_versions_.front(), supported_versions_,
329 use_stateless_rejects_, server_designated_connection_id, &clock_, rand_, 331 use_stateless_rejects_, server_designated_connection_id, &clock_, rand_,
330 &compressed_certs_cache_, &params_, &crypto_proof_, 332 &compressed_certs_cache_, params_, crypto_proof_,
331 /*total_framing_overhead=*/50, chlo_packet_size_, 333 /*total_framing_overhead=*/50, chlo_packet_size_,
332 std::unique_ptr<ProcessCallback>(new ProcessCallback( 334 std::unique_ptr<ProcessCallback>(new ProcessCallback(
333 result, should_succeed, error_substr, &called, &out_))); 335 result, should_succeed, error_substr, &called, &out_)));
334 EXPECT_TRUE(called); 336 EXPECT_TRUE(called);
335 } 337 }
336 338
337 string GenerateNonce() { 339 string GenerateNonce() {
338 string nonce; 340 string nonce;
339 CryptoUtils::GenerateNonce( 341 CryptoUtils::GenerateNonce(
340 clock_.WallNow(), rand_, 342 clock_.WallNow(), rand_,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 QuicRandom* const rand_; 402 QuicRandom* const rand_;
401 MockRandom rand_for_id_generation_; 403 MockRandom rand_for_id_generation_;
402 MockClock clock_; 404 MockClock clock_;
403 IPEndPoint client_address_; 405 IPEndPoint client_address_;
404 QuicVersionVector supported_versions_; 406 QuicVersionVector supported_versions_;
405 QuicVersion client_version_; 407 QuicVersion client_version_;
406 string client_version_string_; 408 string client_version_string_;
407 QuicCryptoServerConfig config_; 409 QuicCryptoServerConfig config_;
408 QuicCompressedCertsCache compressed_certs_cache_; 410 QuicCompressedCertsCache compressed_certs_cache_;
409 QuicCryptoServerConfig::ConfigOptions config_options_; 411 QuicCryptoServerConfig::ConfigOptions config_options_;
410 QuicCryptoNegotiatedParameters params_; 412 scoped_refptr<QuicCryptoNegotiatedParameters> params_;
411 QuicCryptoProof crypto_proof_; 413 scoped_refptr<QuicCryptoProof> crypto_proof_;
412 CryptoHandshakeMessage out_; 414 CryptoHandshakeMessage out_;
413 uint8_t orbit_[kOrbitSize]; 415 uint8_t orbit_[kOrbitSize];
414 bool use_stateless_rejects_; 416 bool use_stateless_rejects_;
415 size_t chlo_packet_size_; 417 size_t chlo_packet_size_;
416 418
417 // These strings contain hex escaped values from the server suitable for using 419 // These strings contain hex escaped values from the server suitable for using
418 // when constructing client hello messages. 420 // when constructing client hello messages.
419 string nonce_hex_, pub_hex_, srct_hex_, scid_hex_; 421 string nonce_hex_, pub_hex_, srct_hex_, scid_hex_;
420 std::unique_ptr<CryptoHandshakeMessage> server_config_; 422 std::unique_ptr<CryptoHandshakeMessage> server_config_;
421 }; 423 };
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 nullptr); 1212 nullptr);
1211 // clang-format on 1213 // clang-format on
1212 1214
1213 // Clear the message tag. 1215 // Clear the message tag.
1214 out_.set_tag(0); 1216 out_.set_tag(0);
1215 1217
1216 bool called = false; 1218 bool called = false;
1217 IPAddress server_ip; 1219 IPAddress server_ip;
1218 config_.ValidateClientHello( 1220 config_.ValidateClientHello(
1219 msg, client_address_.address(), server_ip, client_version_, &clock_, 1221 msg, client_address_.address(), server_ip, client_version_, &clock_,
1220 &crypto_proof_, std::unique_ptr<ValidateCallback>( 1222 crypto_proof_, std::unique_ptr<ValidateCallback>(
1221 new ValidateCallback(this, true, "", &called))); 1223 new ValidateCallback(this, true, "", &called)));
1222 // The verification request was queued. 1224 // The verification request was queued.
1223 ASSERT_FALSE(called); 1225 ASSERT_FALSE(called);
1224 EXPECT_EQ(0u, out_.tag()); 1226 EXPECT_EQ(0u, out_.tag());
1225 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); 1227 EXPECT_EQ(1, strike_register_client_->PendingVerifications());
1226 1228
1227 // Continue processing the verification request. 1229 // Continue processing the verification request.
1228 strike_register_client_->RunPendingVerifications(); 1230 strike_register_client_->RunPendingVerifications();
1229 ASSERT_TRUE(called); 1231 ASSERT_TRUE(called);
1230 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); 1232 EXPECT_EQ(0, strike_register_client_->PendingVerifications());
1231 // The message should be accepted now. 1233 // The message should be accepted now.
1232 EXPECT_EQ(kSHLO, out_.tag()); 1234 EXPECT_EQ(kSHLO, out_.tag());
1233 1235
1234 // Rejected if replayed. 1236 // Rejected if replayed.
1235 config_.ValidateClientHello( 1237 config_.ValidateClientHello(
1236 msg, client_address_.address(), server_ip, client_version_, &clock_, 1238 msg, client_address_.address(), server_ip, client_version_, &clock_,
1237 &crypto_proof_, std::unique_ptr<ValidateCallback>( 1239 crypto_proof_, std::unique_ptr<ValidateCallback>(
1238 new ValidateCallback(this, true, "", &called))); 1240 new ValidateCallback(this, true, "", &called)));
1239 // The verification request was queued. 1241 // The verification request was queued.
1240 ASSERT_FALSE(called); 1242 ASSERT_FALSE(called);
1241 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); 1243 EXPECT_EQ(1, strike_register_client_->PendingVerifications());
1242 1244
1243 strike_register_client_->RunPendingVerifications(); 1245 strike_register_client_->RunPendingVerifications();
1244 ASSERT_TRUE(called); 1246 ASSERT_TRUE(called);
1245 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); 1247 EXPECT_EQ(0, strike_register_client_->PendingVerifications());
1246 // The message should be rejected now. 1248 // The message should be rejected now.
1247 CheckRejectTag(); 1249 CheckRejectTag();
1248 } 1250 }
(...skipping 30 matching lines...) Expand all
1279 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); 1281 EXPECT_EQ(0, strike_register_client_->PendingVerifications());
1280 } else { 1282 } else {
1281 // version 33. 1283 // version 33.
1282 ASSERT_EQ(kSHLO, out_.tag()); 1284 ASSERT_EQ(kSHLO, out_.tag());
1283 CheckServerHello(out_); 1285 CheckServerHello(out_);
1284 } 1286 }
1285 } 1287 }
1286 1288
1287 } // namespace test 1289 } // namespace test
1288 } // namespace net 1290 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/crypto/crypto_handshake.h ('k') | net/quic/core/crypto/quic_crypto_client_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698