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

Side by Side Diff: net/quic/test_tools/crypto_test_utils_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) 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 "net/quic/core/crypto/crypto_server_config_protobuf.h" 7 #include "net/quic/core/crypto/crypto_server_config_protobuf.h"
8 #include "net/quic/core/quic_utils.h" 8 #include "net/quic/core/quic_utils.h"
9 #include "net/quic/test_tools/mock_clock.h" 9 #include "net/quic/test_tools/mock_clock.h"
10 #include "net/test/gtest_util.h" 10 #include "net/test/gtest_util.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 using std::string; 14 using std::string;
15 15
16 namespace net { 16 namespace net {
17 namespace test { 17 namespace test {
18 18
19 class ShloVerifier { 19 class ShloVerifier {
20 public: 20 public:
21 ShloVerifier(QuicCryptoServerConfig* crypto_config, 21 ShloVerifier(QuicCryptoServerConfig* crypto_config,
22 IPAddress server_ip, 22 IPAddress server_ip,
23 IPEndPoint client_addr, 23 IPEndPoint client_addr,
24 const QuicClock* clock, 24 const QuicClock* clock,
25 QuicCryptoProof* proof, 25 scoped_refptr<QuicCryptoProof> proof,
26 QuicCompressedCertsCache* compressed_certs_cache) 26 QuicCompressedCertsCache* compressed_certs_cache)
27 : crypto_config_(crypto_config), 27 : crypto_config_(crypto_config),
28 server_ip_(server_ip), 28 server_ip_(server_ip),
29 client_addr_(client_addr), 29 client_addr_(client_addr),
30 clock_(clock), 30 clock_(clock),
31 proof_(proof), 31 proof_(proof),
32 compressed_certs_cache_(compressed_certs_cache) {} 32 compressed_certs_cache_(compressed_certs_cache),
33 params_(new QuicCryptoNegotiatedParameters) {}
33 34
34 class ValidateClientHelloCallback : public ValidateClientHelloResultCallback { 35 class ValidateClientHelloCallback : public ValidateClientHelloResultCallback {
35 public: 36 public:
36 explicit ValidateClientHelloCallback(ShloVerifier* shlo_verifier) 37 explicit ValidateClientHelloCallback(ShloVerifier* shlo_verifier)
37 : shlo_verifier_(shlo_verifier) {} 38 : shlo_verifier_(shlo_verifier) {}
38 void Run(scoped_refptr<ValidateClientHelloResultCallback::Result> result, 39 void Run(scoped_refptr<ValidateClientHelloResultCallback::Result> result,
39 std::unique_ptr<ProofSource::Details> /* details */) override { 40 std::unique_ptr<ProofSource::Details> /* details */) override {
40 shlo_verifier_->ValidateClientHelloDone(result); 41 shlo_verifier_->ValidateClientHelloDone(result);
41 } 42 }
42 43
43 private: 44 private:
44 ShloVerifier* shlo_verifier_; 45 ShloVerifier* shlo_verifier_;
45 }; 46 };
46 47
47 std::unique_ptr<ValidateClientHelloCallback> 48 std::unique_ptr<ValidateClientHelloCallback>
48 GetValidateClientHelloCallback() { 49 GetValidateClientHelloCallback() {
49 return std::unique_ptr<ValidateClientHelloCallback>( 50 return std::unique_ptr<ValidateClientHelloCallback>(
50 new ValidateClientHelloCallback(this)); 51 new ValidateClientHelloCallback(this));
51 } 52 }
52 53
53 private: 54 private:
54 void ValidateClientHelloDone( 55 void ValidateClientHelloDone(
55 const scoped_refptr<ValidateClientHelloResultCallback::Result>& result) { 56 const scoped_refptr<ValidateClientHelloResultCallback::Result>& result) {
56 result_ = result; 57 result_ = result;
57 crypto_config_->ProcessClientHello( 58 crypto_config_->ProcessClientHello(
58 result_, /*reject_only=*/false, /*connection_id=*/1, server_ip_, 59 result_, /*reject_only=*/false, /*connection_id=*/1, server_ip_,
59 client_addr_, AllSupportedVersions().front(), AllSupportedVersions(), 60 client_addr_, AllSupportedVersions().front(), AllSupportedVersions(),
60 /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0, 61 /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0,
61 clock_, QuicRandom::GetInstance(), compressed_certs_cache_, &params_, 62 clock_, QuicRandom::GetInstance(), compressed_certs_cache_, params_,
62 proof_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize, 63 proof_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize,
63 GetProcessClientHelloCallback()); 64 GetProcessClientHelloCallback());
64 } 65 }
65 66
66 class ProcessClientHelloCallback : public ProcessClientHelloResultCallback { 67 class ProcessClientHelloCallback : public ProcessClientHelloResultCallback {
67 public: 68 public:
68 explicit ProcessClientHelloCallback(ShloVerifier* shlo_verifier) 69 explicit ProcessClientHelloCallback(ShloVerifier* shlo_verifier)
69 : shlo_verifier_(shlo_verifier) {} 70 : shlo_verifier_(shlo_verifier) {}
70 void Run( 71 void Run(
71 QuicErrorCode error, 72 QuicErrorCode error,
(...skipping 15 matching lines...) Expand all
87 void ProcessClientHelloDone(std::unique_ptr<CryptoHandshakeMessage> message) { 88 void ProcessClientHelloDone(std::unique_ptr<CryptoHandshakeMessage> message) {
88 // Verify output is a SHLO. 89 // Verify output is a SHLO.
89 EXPECT_EQ(message->tag(), kSHLO) << "Fail to pass validation. Get " 90 EXPECT_EQ(message->tag(), kSHLO) << "Fail to pass validation. Get "
90 << message->DebugString(); 91 << message->DebugString();
91 } 92 }
92 93
93 QuicCryptoServerConfig* crypto_config_; 94 QuicCryptoServerConfig* crypto_config_;
94 IPAddress server_ip_; 95 IPAddress server_ip_;
95 IPEndPoint client_addr_; 96 IPEndPoint client_addr_;
96 const QuicClock* clock_; 97 const QuicClock* clock_;
97 QuicCryptoProof* proof_; 98 scoped_refptr<QuicCryptoProof> proof_;
98 QuicCompressedCertsCache* compressed_certs_cache_; 99 QuicCompressedCertsCache* compressed_certs_cache_;
99 100
100 QuicCryptoNegotiatedParameters params_; 101 scoped_refptr<QuicCryptoNegotiatedParameters> params_;
101 scoped_refptr<ValidateClientHelloResultCallback::Result> result_; 102 scoped_refptr<ValidateClientHelloResultCallback::Result> result_;
102 }; 103 };
103 104
104 TEST(CryptoTestUtilsTest, TestGenerateFullCHLO) { 105 TEST(CryptoTestUtilsTest, TestGenerateFullCHLO) {
105 MockClock clock; 106 MockClock clock;
106 QuicCryptoServerConfig crypto_config( 107 QuicCryptoServerConfig crypto_config(
107 QuicCryptoServerConfig::TESTING, QuicRandom::GetInstance(), 108 QuicCryptoServerConfig::TESTING, QuicRandom::GetInstance(),
108 CryptoTestUtils::ProofSourceForTesting()); 109 CryptoTestUtils::ProofSourceForTesting());
109 IPAddress server_ip; 110 IPAddress server_ip;
110 IPEndPoint client_addr(IPAddress::IPv4Localhost(), 1); 111 IPEndPoint client_addr(IPAddress::IPv4Localhost(), 1);
111 QuicCryptoProof proof; 112 scoped_refptr<QuicCryptoProof> proof(new QuicCryptoProof);
112 QuicCompressedCertsCache compressed_certs_cache( 113 QuicCompressedCertsCache compressed_certs_cache(
113 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize); 114 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize);
114 CryptoHandshakeMessage full_chlo; 115 CryptoHandshakeMessage full_chlo;
115 116
116 QuicCryptoServerConfig::ConfigOptions old_config_options; 117 QuicCryptoServerConfig::ConfigOptions old_config_options;
117 old_config_options.id = "old-config-id"; 118 old_config_options.id = "old-config-id";
118 delete crypto_config.AddDefaultConfig(QuicRandom::GetInstance(), &clock, 119 delete crypto_config.AddDefaultConfig(QuicRandom::GetInstance(), &clock,
119 old_config_options); 120 old_config_options);
120 QuicCryptoServerConfig::ConfigOptions new_config_options; 121 QuicCryptoServerConfig::ConfigOptions new_config_options;
121 std::unique_ptr<QuicServerConfigProtobuf> primary_config( 122 std::unique_ptr<QuicServerConfigProtobuf> primary_config(
(...skipping 26 matching lines...) Expand all
148 "KEXS", "C255", 149 "KEXS", "C255",
149 "COPT", "SREJ", 150 "COPT", "SREJ",
150 "PUBS", pub_hex.c_str(), 151 "PUBS", pub_hex.c_str(),
151 "NONC", nonce_hex.c_str(), 152 "NONC", nonce_hex.c_str(),
152 "VER\0", QuicUtils::TagToString(QuicVersionToQuicTag(version)).c_str(), 153 "VER\0", QuicUtils::TagToString(QuicVersionToQuicTag(version)).c_str(),
153 "$padding", static_cast<int>(kClientHelloMinimumSize), 154 "$padding", static_cast<int>(kClientHelloMinimumSize),
154 nullptr); 155 nullptr);
155 // clang-format on 156 // clang-format on
156 157
157 CryptoTestUtils::GenerateFullCHLO(inchoate_chlo, &crypto_config, server_ip, 158 CryptoTestUtils::GenerateFullCHLO(inchoate_chlo, &crypto_config, server_ip,
158 client_addr, version, &clock, &proof, 159 client_addr, version, &clock, proof,
159 &compressed_certs_cache, &full_chlo); 160 &compressed_certs_cache, &full_chlo);
160 // Verify that full_chlo can pass crypto_config's verification. 161 // Verify that full_chlo can pass crypto_config's verification.
161 ShloVerifier shlo_verifier(&crypto_config, server_ip, client_addr, &clock, 162 ShloVerifier shlo_verifier(&crypto_config, server_ip, client_addr, &clock,
162 &proof, &compressed_certs_cache); 163 proof, &compressed_certs_cache);
163 crypto_config.ValidateClientHello( 164 crypto_config.ValidateClientHello(
164 full_chlo, client_addr.address(), server_ip, version, &clock, &proof, 165 full_chlo, client_addr.address(), server_ip, version, &clock, proof,
165 shlo_verifier.GetValidateClientHelloCallback()); 166 shlo_verifier.GetValidateClientHelloCallback());
166 } 167 }
167 168
168 } // namespace test 169 } // namespace test
169 } // namespace net 170 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.cc ('k') | net/quic/test_tools/mock_crypto_client_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698