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

Side by Side Diff: net/quic/crypto/proof_test.cc

Issue 2125063003: Add async variant of ProofSource::GetProof (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@126463885
Patch Set: Created 4 years, 5 months 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 <memory> 5 #include <memory>
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "net/base/ip_endpoint.h" 8 #include "net/base/ip_endpoint.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/base/test_completion_callback.h" 10 #include "net/base/test_completion_callback.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 base::FilePath certs_dir = GetTestCertsDirectory(); 99 base::FilePath certs_dir = GetTestCertsDirectory();
100 scoped_refptr<X509Certificate> cert = 100 scoped_refptr<X509Certificate> cert =
101 ImportCertFromFile(certs_dir, "quic_" + file_name); 101 ImportCertFromFile(certs_dir, "quic_" + file_name);
102 CHECK_NE(static_cast<X509Certificate*>(nullptr), cert.get()); 102 CHECK_NE(static_cast<X509Certificate*>(nullptr), cert.get());
103 103
104 string der_bytes; 104 string der_bytes;
105 CHECK(X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_bytes)); 105 CHECK(X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_bytes));
106 return der_bytes; 106 return der_bytes;
107 } 107 }
108 108
109 class TestCallback : public ProofSource::Callback {
110 public:
111 explicit TestCallback(bool* called,
112 bool* ok,
113 scoped_refptr<ProofSource::Chain>* chain,
114 string* signature,
115 string* leaf_cert_sct)
116 : called_(called),
117 ok_(ok),
118 chain_(chain),
119 signature_(signature),
120 leaf_cert_sct_(leaf_cert_sct) {}
121
122 void Run(bool ok,
123 const scoped_refptr<ProofSource::Chain>& chain,
124 const string& signature,
125 const string& leaf_cert_sct) override {
126 *ok_ = ok;
127 *chain_ = chain;
128 *signature_ = signature;
129 *leaf_cert_sct_ = leaf_cert_sct;
130 *called_ = true;
131 }
132
133 private:
134 bool* called_;
135 bool* ok_;
136 scoped_refptr<ProofSource::Chain>* chain_;
137 string* signature_;
138 string* leaf_cert_sct_;
139 };
140
109 class ProofTest : public ::testing::TestWithParam<QuicVersion> {}; 141 class ProofTest : public ::testing::TestWithParam<QuicVersion> {};
110 142
111 } // namespace 143 } // namespace
112 144
113 INSTANTIATE_TEST_CASE_P(QuicVersion, 145 INSTANTIATE_TEST_CASE_P(QuicVersion,
114 ProofTest, 146 ProofTest,
115 ::testing::ValuesIn(QuicSupportedVersions())); 147 ::testing::ValuesIn(QuicSupportedVersions()));
116 148
117 // TODO(rtenneti): Enable testing of ProofVerifier. See http://crbug.com/514468. 149 // TODO(rtenneti): Enable testing of ProofVerifier. See http://crbug.com/514468.
118 TEST_P(ProofTest, DISABLED_Verify) { 150 TEST_P(ProofTest, DISABLED_Verify) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 197
166 vector<string> wrong_certs; 198 vector<string> wrong_certs;
167 for (size_t i = 1; i < chain->certs.size(); i++) { 199 for (size_t i = 1; i < chain->certs.size(); i++) {
168 wrong_certs.push_back(chain->certs[i]); 200 wrong_certs.push_back(chain->certs[i]);
169 } 201 }
170 202
171 RunVerification(verifier.get(), "foo.com", port, server_config, quic_version, 203 RunVerification(verifier.get(), "foo.com", port, server_config, quic_version,
172 first_chlo_hash, wrong_certs, corrupt_signature, false); 204 first_chlo_hash, wrong_certs, corrupt_signature, false);
173 } 205 }
174 206
207 TEST_P(ProofTest, VerifySourceAsync) {
208 std::unique_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting());
209
210 const string server_config = "server config bytes";
211 const string hostname = "test.example.com";
212 const string first_chlo_hash = "first chlo hash bytes";
213 const string second_chlo_hash = "first chlo hash bytes";
214 const QuicVersion quic_version = GetParam();
215 IPAddress server_ip;
216
217 // Call synchronous version
218 scoped_refptr<ProofSource::Chain> expected_chain;
219 string expected_signature;
220 string expected_leaf_cert_sct;
221 ASSERT_TRUE(source->GetProof(server_ip, hostname, server_config, quic_version,
222 first_chlo_hash, false /* no ECDSA */,
223 &expected_chain, &expected_signature,
224 &expected_leaf_cert_sct));
225
226 // Call asynchronous version and compare results
227 bool called = false;
228 bool ok;
229 scoped_refptr<ProofSource::Chain> chain;
230 string signature;
231 string leaf_cert_sct;
232 std::unique_ptr<ProofSource::Callback> cb(
233 new TestCallback(&called, &ok, &chain, &signature, &leaf_cert_sct));
234 source->GetProof(server_ip, hostname, server_config, quic_version,
235 first_chlo_hash, false /* no ECDSA */, std::move(cb));
236 // TODO(gredner): whan GetProof really invokes the callback asynchronously,
237 // figure out what to do here.
238 ASSERT_TRUE(called);
239 ASSERT_TRUE(ok);
240 EXPECT_THAT(chain->certs, ::testing::ContainerEq(expected_chain->certs));
241 EXPECT_EQ(leaf_cert_sct, expected_leaf_cert_sct);
242 }
243
175 TEST_P(ProofTest, UseAfterFree) { 244 TEST_P(ProofTest, UseAfterFree) {
176 ProofSource* source = CryptoTestUtils::ProofSourceForTesting(); 245 ProofSource* source = CryptoTestUtils::ProofSourceForTesting();
177 246
178 const string server_config = "server config bytes"; 247 const string server_config = "server config bytes";
179 const string hostname = "test.example.com"; 248 const string hostname = "test.example.com";
180 const string chlo_hash = "proof nonce bytes"; 249 const string chlo_hash = "proof nonce bytes";
181 scoped_refptr<ProofSource::Chain> chain; 250 scoped_refptr<ProofSource::Chain> chain;
182 string error_details, signature, cert_sct; 251 string error_details, signature, cert_sct;
183 IPAddress server_ip; 252 IPAddress server_ip;
184 253
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 for (size_t i = 1; i < certs.size(); i++) { 479 for (size_t i = 1; i < certs.size(); i++) {
411 wrong_certs.push_back(certs[i]); 480 wrong_certs.push_back(certs[i]);
412 } 481 }
413 RunVerification(verifier.get(), hostname, port, server_config, quic_version, 482 RunVerification(verifier.get(), hostname, port, server_config, quic_version,
414 chlo_hash, wrong_certs, signature, false); 483 chlo_hash, wrong_certs, signature, false);
415 } 484 }
416 } 485 }
417 486
418 } // namespace test 487 } // namespace test
419 } // namespace net 488 } // namespace net
OLDNEW
« net/quic/crypto/proof_source_chromium.cc ('K') | « net/quic/crypto/proof_source_chromium.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698