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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(QuicCryptoServerConfig* crypto_config, |
278 IPAddress server_ip, | 278 IPAddress server_ip, |
279 IPEndPoint client_addr, | 279 IPEndPoint client_addr, |
280 const QuicClock* clock, | 280 const QuicClock* clock, |
281 QuicCryptoProof* proof, | 281 scoped_refptr<QuicCryptoProof> proof, |
282 QuicCompressedCertsCache* compressed_certs_cache, | 282 QuicCompressedCertsCache* compressed_certs_cache, |
283 CryptoHandshakeMessage* out) | 283 CryptoHandshakeMessage* out) |
284 : crypto_config_(crypto_config), | 284 : crypto_config_(crypto_config), |
285 server_ip_(server_ip), | 285 server_ip_(server_ip), |
286 client_addr_(client_addr), | 286 client_addr_(client_addr), |
287 clock_(clock), | 287 clock_(clock), |
288 proof_(proof), | 288 proof_(proof), |
289 compressed_certs_cache_(compressed_certs_cache), | 289 compressed_certs_cache_(compressed_certs_cache), |
290 out_(out) {} | 290 out_(out), |
| 291 params_(new QuicCryptoNegotiatedParameters) {} |
291 | 292 |
292 class ValidateClientHelloCallback : public ValidateClientHelloResultCallback { | 293 class ValidateClientHelloCallback : public ValidateClientHelloResultCallback { |
293 public: | 294 public: |
294 explicit ValidateClientHelloCallback(FullChloGenerator* generator) | 295 explicit ValidateClientHelloCallback(FullChloGenerator* generator) |
295 : generator_(generator) {} | 296 : generator_(generator) {} |
296 void Run(scoped_refptr<ValidateClientHelloResultCallback::Result> result, | 297 void Run(scoped_refptr<ValidateClientHelloResultCallback::Result> result, |
297 std::unique_ptr<ProofSource::Details> /* details */) override { | 298 std::unique_ptr<ProofSource::Details> /* details */) override { |
298 generator_->ValidateClientHelloDone(std::move(result)); | 299 generator_->ValidateClientHelloDone(std::move(result)); |
299 } | 300 } |
300 | 301 |
301 private: | 302 private: |
302 FullChloGenerator* generator_; | 303 FullChloGenerator* generator_; |
303 }; | 304 }; |
304 | 305 |
305 std::unique_ptr<ValidateClientHelloCallback> | 306 std::unique_ptr<ValidateClientHelloCallback> |
306 GetValidateClientHelloCallback() { | 307 GetValidateClientHelloCallback() { |
307 return std::unique_ptr<ValidateClientHelloCallback>( | 308 return std::unique_ptr<ValidateClientHelloCallback>( |
308 new ValidateClientHelloCallback(this)); | 309 new ValidateClientHelloCallback(this)); |
309 } | 310 } |
310 | 311 |
311 private: | 312 private: |
312 void ValidateClientHelloDone( | 313 void ValidateClientHelloDone( |
313 scoped_refptr<ValidateClientHelloResultCallback::Result> result) { | 314 scoped_refptr<ValidateClientHelloResultCallback::Result> result) { |
314 result_ = result; | 315 result_ = result; |
315 crypto_config_->ProcessClientHello( | 316 crypto_config_->ProcessClientHello( |
316 result_, /*reject_only=*/false, /*connection_id=*/1, server_ip_, | 317 result_, /*reject_only=*/false, /*connection_id=*/1, server_ip_, |
317 client_addr_, AllSupportedVersions().front(), AllSupportedVersions(), | 318 client_addr_, AllSupportedVersions().front(), AllSupportedVersions(), |
318 /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0, | 319 /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0, |
319 clock_, QuicRandom::GetInstance(), compressed_certs_cache_, ¶ms_, | 320 clock_, QuicRandom::GetInstance(), compressed_certs_cache_, params_, |
320 proof_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize, | 321 proof_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize, |
321 GetProcessClientHelloCallback()); | 322 GetProcessClientHelloCallback()); |
322 } | 323 } |
323 | 324 |
324 class ProcessClientHelloCallback : public ProcessClientHelloResultCallback { | 325 class ProcessClientHelloCallback : public ProcessClientHelloResultCallback { |
325 public: | 326 public: |
326 explicit ProcessClientHelloCallback(FullChloGenerator* generator) | 327 explicit ProcessClientHelloCallback(FullChloGenerator* generator) |
327 : generator_(generator) {} | 328 : generator_(generator) {} |
328 void Run( | 329 void Run( |
329 QuicErrorCode error, | 330 QuicErrorCode error, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 out_->SetStringPiece(kSourceAddressTokenTag, srct); | 365 out_->SetStringPiece(kSourceAddressTokenTag, srct); |
365 uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting(); | 366 uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting(); |
366 out_->SetValue(kXLCT, xlct); | 367 out_->SetValue(kXLCT, xlct); |
367 } | 368 } |
368 | 369 |
369 protected: | 370 protected: |
370 QuicCryptoServerConfig* crypto_config_; | 371 QuicCryptoServerConfig* crypto_config_; |
371 IPAddress server_ip_; | 372 IPAddress server_ip_; |
372 IPEndPoint client_addr_; | 373 IPEndPoint client_addr_; |
373 const QuicClock* clock_; | 374 const QuicClock* clock_; |
374 QuicCryptoProof* proof_; | 375 scoped_refptr<QuicCryptoProof> proof_; |
375 QuicCompressedCertsCache* compressed_certs_cache_; | 376 QuicCompressedCertsCache* compressed_certs_cache_; |
376 CryptoHandshakeMessage* out_; | 377 CryptoHandshakeMessage* out_; |
377 | 378 |
378 QuicCryptoNegotiatedParameters params_; | 379 scoped_refptr<QuicCryptoNegotiatedParameters> params_; |
379 scoped_refptr<ValidateClientHelloResultCallback::Result> result_; | 380 scoped_refptr<ValidateClientHelloResultCallback::Result> result_; |
380 }; | 381 }; |
381 | 382 |
382 } // namespace | 383 } // namespace |
383 | 384 |
384 // static | 385 // static |
385 int CryptoTestUtils::HandshakeWithFakeServer( | 386 int CryptoTestUtils::HandshakeWithFakeServer( |
386 QuicConfig* server_quic_config, | 387 QuicConfig* server_quic_config, |
387 MockQuicConnectionHelper* helper, | 388 MockQuicConnectionHelper* helper, |
388 MockAlarmFactory* alarm_factory, | 389 MockAlarmFactory* alarm_factory, |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 } | 999 } |
999 | 1000 |
1000 // static | 1001 // static |
1001 void CryptoTestUtils::GenerateFullCHLO( | 1002 void CryptoTestUtils::GenerateFullCHLO( |
1002 const CryptoHandshakeMessage& inchoate_chlo, | 1003 const CryptoHandshakeMessage& inchoate_chlo, |
1003 QuicCryptoServerConfig* crypto_config, | 1004 QuicCryptoServerConfig* crypto_config, |
1004 IPAddress server_ip, | 1005 IPAddress server_ip, |
1005 IPEndPoint client_addr, | 1006 IPEndPoint client_addr, |
1006 QuicVersion version, | 1007 QuicVersion version, |
1007 const QuicClock* clock, | 1008 const QuicClock* clock, |
1008 QuicCryptoProof* proof, | 1009 scoped_refptr<QuicCryptoProof> proof, |
1009 QuicCompressedCertsCache* compressed_certs_cache, | 1010 QuicCompressedCertsCache* compressed_certs_cache, |
1010 CryptoHandshakeMessage* out) { | 1011 CryptoHandshakeMessage* out) { |
1011 // Pass a inchoate CHLO. | 1012 // Pass a inchoate CHLO. |
1012 FullChloGenerator generator(crypto_config, server_ip, client_addr, clock, | 1013 FullChloGenerator generator(crypto_config, server_ip, client_addr, clock, |
1013 proof, compressed_certs_cache, out); | 1014 proof, compressed_certs_cache, out); |
1014 crypto_config->ValidateClientHello( | 1015 crypto_config->ValidateClientHello( |
1015 inchoate_chlo, client_addr.address(), server_ip, version, clock, proof, | 1016 inchoate_chlo, client_addr.address(), server_ip, version, clock, proof, |
1016 generator.GetValidateClientHelloCallback()); | 1017 generator.GetValidateClientHelloCallback()); |
1017 } | 1018 } |
1018 | 1019 |
1019 } // namespace test | 1020 } // namespace test |
1020 } // namespace net | 1021 } // namespace net |
OLD | NEW |