OLD | NEW |
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/test_tools/crypto_test_utils.h" | 5 #include "net/quic/test_tools/crypto_test_utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "crypto/openssl_util.h" | 10 #include "crypto/openssl_util.h" |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 : channel_id_enabled(false), channel_id_source_async(false) {} | 267 : channel_id_enabled(false), channel_id_source_async(false) {} |
268 | 268 |
269 CryptoTestUtils::FakeClientOptions::~FakeClientOptions() {} | 269 CryptoTestUtils::FakeClientOptions::~FakeClientOptions() {} |
270 | 270 |
271 namespace { | 271 namespace { |
272 // This class is used by GenerateFullCHLO() to extract SCID and STK from | 272 // This class is used by GenerateFullCHLO() to extract SCID and STK from |
273 // REJ/SREJ and to construct a full CHLO with these fields and given inchoate | 273 // REJ/SREJ and to construct a full CHLO with these fields and given inchoate |
274 // CHLO. | 274 // CHLO. |
275 class FullChloGenerator { | 275 class FullChloGenerator { |
276 public: | 276 public: |
277 FullChloGenerator(QuicCryptoServerConfig* crypto_config, | 277 FullChloGenerator( |
278 QuicSocketAddress server_addr, | 278 QuicCryptoServerConfig* crypto_config, |
279 QuicSocketAddress client_addr, | 279 QuicSocketAddress server_addr, |
280 const QuicClock* clock, | 280 QuicSocketAddress client_addr, |
281 scoped_refptr<QuicSignedServerConfig> signed_config, | 281 const QuicClock* clock, |
282 QuicCompressedCertsCache* compressed_certs_cache, | 282 QuicReferenceCountedPointer<QuicSignedServerConfig> signed_config, |
283 CryptoHandshakeMessage* out) | 283 QuicCompressedCertsCache* compressed_certs_cache, |
| 284 CryptoHandshakeMessage* out) |
284 : crypto_config_(crypto_config), | 285 : crypto_config_(crypto_config), |
285 server_addr_(server_addr), | 286 server_addr_(server_addr), |
286 client_addr_(client_addr), | 287 client_addr_(client_addr), |
287 clock_(clock), | 288 clock_(clock), |
288 signed_config_(signed_config), | 289 signed_config_(signed_config), |
289 compressed_certs_cache_(compressed_certs_cache), | 290 compressed_certs_cache_(compressed_certs_cache), |
290 out_(out), | 291 out_(out), |
291 params_(new QuicCryptoNegotiatedParameters) {} | 292 params_(new QuicCryptoNegotiatedParameters) {} |
292 | 293 |
293 class ValidateClientHelloCallback : public ValidateClientHelloResultCallback { | 294 class ValidateClientHelloCallback : public ValidateClientHelloResultCallback { |
294 public: | 295 public: |
295 explicit ValidateClientHelloCallback(FullChloGenerator* generator) | 296 explicit ValidateClientHelloCallback(FullChloGenerator* generator) |
296 : generator_(generator) {} | 297 : generator_(generator) {} |
297 void Run(scoped_refptr<ValidateClientHelloResultCallback::Result> result, | 298 void Run(QuicReferenceCountedPointer< |
| 299 ValidateClientHelloResultCallback::Result> result, |
298 std::unique_ptr<ProofSource::Details> /* details */) override { | 300 std::unique_ptr<ProofSource::Details> /* details */) override { |
299 generator_->ValidateClientHelloDone(std::move(result)); | 301 generator_->ValidateClientHelloDone(std::move(result)); |
300 } | 302 } |
301 | 303 |
302 private: | 304 private: |
303 FullChloGenerator* generator_; | 305 FullChloGenerator* generator_; |
304 }; | 306 }; |
305 | 307 |
306 std::unique_ptr<ValidateClientHelloCallback> | 308 std::unique_ptr<ValidateClientHelloCallback> |
307 GetValidateClientHelloCallback() { | 309 GetValidateClientHelloCallback() { |
308 return std::unique_ptr<ValidateClientHelloCallback>( | 310 return std::unique_ptr<ValidateClientHelloCallback>( |
309 new ValidateClientHelloCallback(this)); | 311 new ValidateClientHelloCallback(this)); |
310 } | 312 } |
311 | 313 |
312 private: | 314 private: |
313 void ValidateClientHelloDone( | 315 void ValidateClientHelloDone( |
314 scoped_refptr<ValidateClientHelloResultCallback::Result> result) { | 316 QuicReferenceCountedPointer<ValidateClientHelloResultCallback::Result> |
| 317 result) { |
315 result_ = result; | 318 result_ = result; |
316 crypto_config_->ProcessClientHello( | 319 crypto_config_->ProcessClientHello( |
317 result_, /*reject_only=*/false, /*connection_id=*/1, server_addr_, | 320 result_, /*reject_only=*/false, /*connection_id=*/1, server_addr_, |
318 client_addr_, AllSupportedVersions().front(), AllSupportedVersions(), | 321 client_addr_, AllSupportedVersions().front(), AllSupportedVersions(), |
319 /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0, | 322 /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0, |
320 clock_, QuicRandom::GetInstance(), compressed_certs_cache_, params_, | 323 clock_, QuicRandom::GetInstance(), compressed_certs_cache_, params_, |
321 signed_config_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize, | 324 signed_config_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize, |
322 GetProcessClientHelloCallback()); | 325 GetProcessClientHelloCallback()); |
323 } | 326 } |
324 | 327 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 out_->SetStringPiece(kSourceAddressTokenTag, srct); | 369 out_->SetStringPiece(kSourceAddressTokenTag, srct); |
367 uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting(); | 370 uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting(); |
368 out_->SetValue(kXLCT, xlct); | 371 out_->SetValue(kXLCT, xlct); |
369 } | 372 } |
370 | 373 |
371 protected: | 374 protected: |
372 QuicCryptoServerConfig* crypto_config_; | 375 QuicCryptoServerConfig* crypto_config_; |
373 QuicSocketAddress server_addr_; | 376 QuicSocketAddress server_addr_; |
374 QuicSocketAddress client_addr_; | 377 QuicSocketAddress client_addr_; |
375 const QuicClock* clock_; | 378 const QuicClock* clock_; |
376 scoped_refptr<QuicSignedServerConfig> signed_config_; | 379 QuicReferenceCountedPointer<QuicSignedServerConfig> signed_config_; |
377 QuicCompressedCertsCache* compressed_certs_cache_; | 380 QuicCompressedCertsCache* compressed_certs_cache_; |
378 CryptoHandshakeMessage* out_; | 381 CryptoHandshakeMessage* out_; |
379 | 382 |
380 scoped_refptr<QuicCryptoNegotiatedParameters> params_; | 383 QuicReferenceCountedPointer<QuicCryptoNegotiatedParameters> params_; |
381 scoped_refptr<ValidateClientHelloResultCallback::Result> result_; | 384 QuicReferenceCountedPointer<ValidateClientHelloResultCallback::Result> |
| 385 result_; |
382 }; | 386 }; |
383 | 387 |
384 } // namespace | 388 } // namespace |
385 | 389 |
386 // static | 390 // static |
387 int CryptoTestUtils::HandshakeWithFakeServer( | 391 int CryptoTestUtils::HandshakeWithFakeServer( |
388 QuicConfig* server_quic_config, | 392 QuicConfig* server_quic_config, |
389 MockQuicConnectionHelper* helper, | 393 MockQuicConnectionHelper* helper, |
390 MockAlarmFactory* alarm_factory, | 394 MockAlarmFactory* alarm_factory, |
391 PacketSavingConnection* client_conn, | 395 PacketSavingConnection* client_conn, |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message, | 562 string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message, |
559 QuicTag tag) { | 563 QuicTag tag) { |
560 QuicTagValueMap::const_iterator it = message.tag_value_map().find(tag); | 564 QuicTagValueMap::const_iterator it = message.tag_value_map().find(tag); |
561 if (it == message.tag_value_map().end()) { | 565 if (it == message.tag_value_map().end()) { |
562 return string(); | 566 return string(); |
563 } | 567 } |
564 return it->second; | 568 return it->second; |
565 } | 569 } |
566 | 570 |
567 uint64_t CryptoTestUtils::LeafCertHashForTesting() { | 571 uint64_t CryptoTestUtils::LeafCertHashForTesting() { |
568 scoped_refptr<ProofSource::Chain> chain; | 572 QuicReferenceCountedPointer<ProofSource::Chain> chain; |
569 QuicSocketAddress server_address; | 573 QuicSocketAddress server_address; |
570 QuicCryptoProof proof; | 574 QuicCryptoProof proof; |
571 std::unique_ptr<ProofSource> proof_source( | 575 std::unique_ptr<ProofSource> proof_source( |
572 CryptoTestUtils::ProofSourceForTesting()); | 576 CryptoTestUtils::ProofSourceForTesting()); |
573 if (!proof_source->GetProof(server_address, "", "", | 577 if (!proof_source->GetProof(server_address, "", "", |
574 AllSupportedVersions().front(), "", | 578 AllSupportedVersions().front(), "", |
575 QuicTagVector(), &chain, &proof) || | 579 QuicTagVector(), &chain, &proof) || |
576 chain->certs.empty()) { | 580 chain->certs.empty()) { |
577 DCHECK(false) << "Proof generation failed"; | 581 DCHECK(false) << "Proof generation failed"; |
578 return 0; | 582 return 0; |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 } | 1003 } |
1000 | 1004 |
1001 // static | 1005 // static |
1002 void CryptoTestUtils::GenerateFullCHLO( | 1006 void CryptoTestUtils::GenerateFullCHLO( |
1003 const CryptoHandshakeMessage& inchoate_chlo, | 1007 const CryptoHandshakeMessage& inchoate_chlo, |
1004 QuicCryptoServerConfig* crypto_config, | 1008 QuicCryptoServerConfig* crypto_config, |
1005 QuicSocketAddress server_addr, | 1009 QuicSocketAddress server_addr, |
1006 QuicSocketAddress client_addr, | 1010 QuicSocketAddress client_addr, |
1007 QuicVersion version, | 1011 QuicVersion version, |
1008 const QuicClock* clock, | 1012 const QuicClock* clock, |
1009 scoped_refptr<QuicSignedServerConfig> proof, | 1013 QuicReferenceCountedPointer<QuicSignedServerConfig> proof, |
1010 QuicCompressedCertsCache* compressed_certs_cache, | 1014 QuicCompressedCertsCache* compressed_certs_cache, |
1011 CryptoHandshakeMessage* out) { | 1015 CryptoHandshakeMessage* out) { |
1012 // Pass a inchoate CHLO. | 1016 // Pass a inchoate CHLO. |
1013 FullChloGenerator generator(crypto_config, server_addr, client_addr, clock, | 1017 FullChloGenerator generator(crypto_config, server_addr, client_addr, clock, |
1014 proof, compressed_certs_cache, out); | 1018 proof, compressed_certs_cache, out); |
1015 crypto_config->ValidateClientHello( | 1019 crypto_config->ValidateClientHello( |
1016 inchoate_chlo, client_addr.host(), server_addr, version, clock, proof, | 1020 inchoate_chlo, client_addr.host(), server_addr, version, clock, proof, |
1017 generator.GetValidateClientHelloCallback()); | 1021 generator.GetValidateClientHelloCallback()); |
1018 } | 1022 } |
1019 | 1023 |
1020 } // namespace test | 1024 } // namespace test |
1021 } // namespace net | 1025 } // namespace net |
OLD | NEW |