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

Side by Side Diff: net/quic/test_tools/crypto_test_utils_test.cc

Issue 2516033003: Landing Recent QUIC changes until Mon Nov 14 04:43:50 2016 +0000 (Closed)
Patch Set: Remove unused UpdatePacketGapSentHistogram() function. Created 4 years 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
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.cc ('k') | net/quic/test_tools/fake_proof_source.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 scoped_refptr<QuicCryptoProof> proof, 25 scoped_refptr<QuicSignedServerConfig> signed_config,
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 signed_config_(signed_config),
32 compressed_certs_cache_(compressed_certs_cache), 32 compressed_certs_cache_(compressed_certs_cache),
33 params_(new QuicCryptoNegotiatedParameters) {} 33 params_(new QuicCryptoNegotiatedParameters) {}
34 34
35 class ValidateClientHelloCallback : public ValidateClientHelloResultCallback { 35 class ValidateClientHelloCallback : public ValidateClientHelloResultCallback {
36 public: 36 public:
37 explicit ValidateClientHelloCallback(ShloVerifier* shlo_verifier) 37 explicit ValidateClientHelloCallback(ShloVerifier* shlo_verifier)
38 : shlo_verifier_(shlo_verifier) {} 38 : shlo_verifier_(shlo_verifier) {}
39 void Run(scoped_refptr<ValidateClientHelloResultCallback::Result> result, 39 void Run(scoped_refptr<ValidateClientHelloResultCallback::Result> result,
40 std::unique_ptr<ProofSource::Details> /* details */) override { 40 std::unique_ptr<ProofSource::Details> /* details */) override {
41 shlo_verifier_->ValidateClientHelloDone(result); 41 shlo_verifier_->ValidateClientHelloDone(result);
(...skipping 11 matching lines...) Expand all
53 53
54 private: 54 private:
55 void ValidateClientHelloDone( 55 void ValidateClientHelloDone(
56 const scoped_refptr<ValidateClientHelloResultCallback::Result>& result) { 56 const scoped_refptr<ValidateClientHelloResultCallback::Result>& result) {
57 result_ = result; 57 result_ = result;
58 crypto_config_->ProcessClientHello( 58 crypto_config_->ProcessClientHello(
59 result_, /*reject_only=*/false, /*connection_id=*/1, server_ip_, 59 result_, /*reject_only=*/false, /*connection_id=*/1, server_ip_,
60 client_addr_, AllSupportedVersions().front(), AllSupportedVersions(), 60 client_addr_, AllSupportedVersions().front(), AllSupportedVersions(),
61 /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0, 61 /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0,
62 clock_, QuicRandom::GetInstance(), compressed_certs_cache_, params_, 62 clock_, QuicRandom::GetInstance(), compressed_certs_cache_, params_,
63 proof_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize, 63 signed_config_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize,
64 GetProcessClientHelloCallback()); 64 GetProcessClientHelloCallback());
65 } 65 }
66 66
67 class ProcessClientHelloCallback : public ProcessClientHelloResultCallback { 67 class ProcessClientHelloCallback : public ProcessClientHelloResultCallback {
68 public: 68 public:
69 explicit ProcessClientHelloCallback(ShloVerifier* shlo_verifier) 69 explicit ProcessClientHelloCallback(ShloVerifier* shlo_verifier)
70 : shlo_verifier_(shlo_verifier) {} 70 : shlo_verifier_(shlo_verifier) {}
71 void Run( 71 void Run(
72 QuicErrorCode error, 72 QuicErrorCode error,
73 const string& error_details, 73 const string& error_details,
(...skipping 15 matching lines...) Expand all
89 void ProcessClientHelloDone(std::unique_ptr<CryptoHandshakeMessage> message) { 89 void ProcessClientHelloDone(std::unique_ptr<CryptoHandshakeMessage> message) {
90 // Verify output is a SHLO. 90 // Verify output is a SHLO.
91 EXPECT_EQ(message->tag(), kSHLO) << "Fail to pass validation. Get " 91 EXPECT_EQ(message->tag(), kSHLO) << "Fail to pass validation. Get "
92 << message->DebugString(); 92 << message->DebugString();
93 } 93 }
94 94
95 QuicCryptoServerConfig* crypto_config_; 95 QuicCryptoServerConfig* crypto_config_;
96 IPAddress server_ip_; 96 IPAddress server_ip_;
97 IPEndPoint client_addr_; 97 IPEndPoint client_addr_;
98 const QuicClock* clock_; 98 const QuicClock* clock_;
99 scoped_refptr<QuicCryptoProof> proof_; 99 scoped_refptr<QuicSignedServerConfig> signed_config_;
100 QuicCompressedCertsCache* compressed_certs_cache_; 100 QuicCompressedCertsCache* compressed_certs_cache_;
101 101
102 scoped_refptr<QuicCryptoNegotiatedParameters> params_; 102 scoped_refptr<QuicCryptoNegotiatedParameters> params_;
103 scoped_refptr<ValidateClientHelloResultCallback::Result> result_; 103 scoped_refptr<ValidateClientHelloResultCallback::Result> result_;
104 }; 104 };
105 105
106 TEST(CryptoTestUtilsTest, TestGenerateFullCHLO) { 106 TEST(CryptoTestUtilsTest, TestGenerateFullCHLO) {
107 MockClock clock; 107 MockClock clock;
108 QuicCryptoServerConfig crypto_config( 108 QuicCryptoServerConfig crypto_config(
109 QuicCryptoServerConfig::TESTING, QuicRandom::GetInstance(), 109 QuicCryptoServerConfig::TESTING, QuicRandom::GetInstance(),
110 CryptoTestUtils::ProofSourceForTesting()); 110 CryptoTestUtils::ProofSourceForTesting());
111 IPAddress server_ip; 111 IPAddress server_ip;
112 IPEndPoint client_addr(IPAddress::IPv4Localhost(), 1); 112 IPEndPoint client_addr(IPAddress::IPv4Localhost(), 1);
113 scoped_refptr<QuicCryptoProof> proof(new QuicCryptoProof); 113 scoped_refptr<QuicSignedServerConfig> signed_config(
114 new QuicSignedServerConfig);
114 QuicCompressedCertsCache compressed_certs_cache( 115 QuicCompressedCertsCache compressed_certs_cache(
115 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize); 116 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize);
116 CryptoHandshakeMessage full_chlo; 117 CryptoHandshakeMessage full_chlo;
117 118
118 QuicCryptoServerConfig::ConfigOptions old_config_options; 119 QuicCryptoServerConfig::ConfigOptions old_config_options;
119 old_config_options.id = "old-config-id"; 120 old_config_options.id = "old-config-id";
120 delete crypto_config.AddDefaultConfig(QuicRandom::GetInstance(), &clock, 121 delete crypto_config.AddDefaultConfig(QuicRandom::GetInstance(), &clock,
121 old_config_options); 122 old_config_options);
122 QuicCryptoServerConfig::ConfigOptions new_config_options; 123 QuicCryptoServerConfig::ConfigOptions new_config_options;
123 std::unique_ptr<QuicServerConfigProtobuf> primary_config( 124 std::unique_ptr<QuicServerConfigProtobuf> primary_config(
(...skipping 20 matching lines...) Expand all
144 QuicVersion version(AllSupportedVersions().front()); 145 QuicVersion version(AllSupportedVersions().front());
145 // clang-format off 146 // clang-format off
146 CryptoHandshakeMessage inchoate_chlo = CryptoTestUtils::Message( 147 CryptoHandshakeMessage inchoate_chlo = CryptoTestUtils::Message(
147 "CHLO", 148 "CHLO",
148 "PDMD", "X509", 149 "PDMD", "X509",
149 "AEAD", "AESG", 150 "AEAD", "AESG",
150 "KEXS", "C255", 151 "KEXS", "C255",
151 "COPT", "SREJ", 152 "COPT", "SREJ",
152 "PUBS", pub_hex.c_str(), 153 "PUBS", pub_hex.c_str(),
153 "NONC", nonce_hex.c_str(), 154 "NONC", nonce_hex.c_str(),
154 "VER\0", QuicUtils::TagToString(QuicVersionToQuicTag(version)).c_str(), 155 "VER\0", QuicTagToString(QuicVersionToQuicTag(version)).c_str(),
155 "$padding", static_cast<int>(kClientHelloMinimumSize), 156 "$padding", static_cast<int>(kClientHelloMinimumSize),
156 nullptr); 157 nullptr);
157 // clang-format on 158 // clang-format on
158 159
159 CryptoTestUtils::GenerateFullCHLO(inchoate_chlo, &crypto_config, server_ip, 160 CryptoTestUtils::GenerateFullCHLO(inchoate_chlo, &crypto_config, server_ip,
160 client_addr, version, &clock, proof, 161 client_addr, version, &clock, signed_config,
161 &compressed_certs_cache, &full_chlo); 162 &compressed_certs_cache, &full_chlo);
162 // Verify that full_chlo can pass crypto_config's verification. 163 // Verify that full_chlo can pass crypto_config's verification.
163 ShloVerifier shlo_verifier(&crypto_config, server_ip, client_addr, &clock, 164 ShloVerifier shlo_verifier(&crypto_config, server_ip, client_addr, &clock,
164 proof, &compressed_certs_cache); 165 signed_config, &compressed_certs_cache);
165 crypto_config.ValidateClientHello( 166 crypto_config.ValidateClientHello(
166 full_chlo, client_addr.address(), server_ip, version, &clock, proof, 167 full_chlo, client_addr.address(), server_ip, version, &clock,
167 shlo_verifier.GetValidateClientHelloCallback()); 168 signed_config, shlo_verifier.GetValidateClientHelloCallback());
168 } 169 }
169 170
170 } // namespace test 171 } // namespace test
171 } // namespace net 172 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.cc ('k') | net/quic/test_tools/fake_proof_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698