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

Side by Side Diff: net/quic/chromium/crypto/proof_test_chromium.cc

Issue 2681793002: Landing Recent QUIC changes until 5:30 PM, Feb 3, 2017 UTC-5 (Closed)
Patch Set: sync and rebase Created 3 years, 10 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 QuicVersion quic_version, 58 QuicVersion quic_version,
59 StringPiece chlo_hash, 59 StringPiece chlo_hash,
60 const std::vector<string>& certs, 60 const std::vector<string>& certs,
61 const string& proof, 61 const string& proof,
62 bool expected_ok) { 62 bool expected_ok) {
63 std::unique_ptr<ProofVerifyDetails> details; 63 std::unique_ptr<ProofVerifyDetails> details;
64 TestCompletionCallback comp_callback; 64 TestCompletionCallback comp_callback;
65 bool ok; 65 bool ok;
66 string error_details; 66 string error_details;
67 std::unique_ptr<ProofVerifyContext> verify_context( 67 std::unique_ptr<ProofVerifyContext> verify_context(
68 CryptoTestUtils::ProofVerifyContextForTesting()); 68 crypto_test_utils::ProofVerifyContextForTesting());
69 std::unique_ptr<TestProofVerifierCallback> callback( 69 std::unique_ptr<TestProofVerifierCallback> callback(
70 new TestProofVerifierCallback(&comp_callback, &ok, &error_details)); 70 new TestProofVerifierCallback(&comp_callback, &ok, &error_details));
71 71
72 QuicAsyncStatus status = verifier->VerifyProof( 72 QuicAsyncStatus status = verifier->VerifyProof(
73 hostname, port, server_config, quic_version, chlo_hash, certs, "", proof, 73 hostname, port, server_config, quic_version, chlo_hash, certs, "", proof,
74 verify_context.get(), &error_details, &details, std::move(callback)); 74 verify_context.get(), &error_details, &details, std::move(callback));
75 75
76 switch (status) { 76 switch (status) {
77 case QUIC_FAILURE: 77 case QUIC_FAILURE:
78 ASSERT_FALSE(expected_ok); 78 ASSERT_FALSE(expected_ok);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 class ProofTest : public ::testing::TestWithParam<QuicVersion> {}; 117 class ProofTest : public ::testing::TestWithParam<QuicVersion> {};
118 118
119 } // namespace 119 } // namespace
120 120
121 INSTANTIATE_TEST_CASE_P(QuicVersion, 121 INSTANTIATE_TEST_CASE_P(QuicVersion,
122 ProofTest, 122 ProofTest,
123 ::testing::ValuesIn(AllSupportedVersions())); 123 ::testing::ValuesIn(AllSupportedVersions()));
124 124
125 // TODO(rtenneti): Enable testing of ProofVerifier. See http://crbug.com/514468. 125 // TODO(rtenneti): Enable testing of ProofVerifier. See http://crbug.com/514468.
126 TEST_P(ProofTest, DISABLED_Verify) { 126 TEST_P(ProofTest, DISABLED_Verify) {
127 std::unique_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); 127 std::unique_ptr<ProofSource> source(
128 crypto_test_utils::ProofSourceForTesting());
128 std::unique_ptr<ProofVerifier> verifier( 129 std::unique_ptr<ProofVerifier> verifier(
129 CryptoTestUtils::ProofVerifierForTesting()); 130 crypto_test_utils::ProofVerifierForTesting());
130 131
131 const string server_config = "server config bytes"; 132 const string server_config = "server config bytes";
132 const string hostname = "test.example.com"; 133 const string hostname = "test.example.com";
133 const uint16_t port = 8443; 134 const uint16_t port = 8443;
134 const string first_chlo_hash = "first chlo hash bytes"; 135 const string first_chlo_hash = "first chlo hash bytes";
135 const string second_chlo_hash = "first chlo hash bytes"; 136 const string second_chlo_hash = "first chlo hash bytes";
136 const QuicVersion quic_version = GetParam(); 137 const QuicVersion quic_version = GetParam();
137 138
139 bool called = false;
140 bool first_called = false;
141 bool ok, first_ok;
138 QuicReferenceCountedPointer<ProofSource::Chain> chain; 142 QuicReferenceCountedPointer<ProofSource::Chain> chain;
139 QuicReferenceCountedPointer<ProofSource::Chain> first_chain; 143 QuicReferenceCountedPointer<ProofSource::Chain> first_chain;
140 string error_details; 144 string error_details;
141 QuicCryptoProof proof, first_proof; 145 QuicCryptoProof proof, first_proof;
142 QuicSocketAddress server_addr; 146 QuicSocketAddress server_addr;
143 147
144 ASSERT_TRUE(source->GetProof(server_addr, hostname, server_config, 148 std::unique_ptr<ProofSource::Callback> cb(
145 quic_version, first_chlo_hash, QuicTagVector(), 149 new TestCallback(&called, &ok, &chain, &proof));
146 &first_chain, &first_proof)); 150 std::unique_ptr<ProofSource::Callback> first_cb(
147 ASSERT_TRUE(source->GetProof(server_addr, hostname, server_config, 151 new TestCallback(&first_called, &first_ok, &first_chain, &first_proof));
148 quic_version, second_chlo_hash, QuicTagVector(), 152
149 &chain, &proof)); 153 // GetProof here expects the async method to invoke the callback
154 // synchronously.
155 source->GetProof(server_addr, hostname, server_config, quic_version,
156 first_chlo_hash, QuicTagVector(), std::move(first_cb));
157 source->GetProof(server_addr, hostname, server_config, quic_version,
158 second_chlo_hash, QuicTagVector(), std::move(cb));
159 ASSERT_TRUE(called);
160 ASSERT_TRUE(first_called);
161 ASSERT_TRUE(ok);
162 ASSERT_TRUE(first_ok);
150 163
151 // Check that the proof source is caching correctly: 164 // Check that the proof source is caching correctly:
152 ASSERT_EQ(first_chain->certs, chain->certs); 165 ASSERT_EQ(first_chain->certs, chain->certs);
153 ASSERT_NE(proof.signature, first_proof.signature); 166 ASSERT_NE(proof.signature, first_proof.signature);
154 ASSERT_EQ(first_proof.leaf_cert_scts, proof.leaf_cert_scts); 167 ASSERT_EQ(first_proof.leaf_cert_scts, proof.leaf_cert_scts);
155 168
156 RunVerification(verifier.get(), hostname, port, server_config, quic_version, 169 RunVerification(verifier.get(), hostname, port, server_config, quic_version,
157 first_chlo_hash, chain->certs, proof.signature, true); 170 first_chlo_hash, chain->certs, proof.signature, true);
158 171
159 RunVerification(verifier.get(), "foo.com", port, server_config, quic_version, 172 RunVerification(verifier.get(), "foo.com", port, server_config, quic_version,
160 first_chlo_hash, chain->certs, proof.signature, false); 173 first_chlo_hash, chain->certs, proof.signature, false);
161 174
162 RunVerification(verifier.get(), server_config.substr(1, string::npos), port, 175 RunVerification(verifier.get(), server_config.substr(1, string::npos), port,
163 server_config, quic_version, first_chlo_hash, chain->certs, 176 server_config, quic_version, first_chlo_hash, chain->certs,
164 proof.signature, false); 177 proof.signature, false);
165 178
166 const string corrupt_signature = "1" + proof.signature; 179 const string corrupt_signature = "1" + proof.signature;
167 RunVerification(verifier.get(), hostname, port, server_config, quic_version, 180 RunVerification(verifier.get(), hostname, port, server_config, quic_version,
168 first_chlo_hash, chain->certs, corrupt_signature, false); 181 first_chlo_hash, chain->certs, corrupt_signature, false);
169 182
170 std::vector<string> wrong_certs; 183 std::vector<string> wrong_certs;
171 for (size_t i = 1; i < chain->certs.size(); i++) { 184 for (size_t i = 1; i < chain->certs.size(); i++) {
172 wrong_certs.push_back(chain->certs[i]); 185 wrong_certs.push_back(chain->certs[i]);
173 } 186 }
174 187
175 RunVerification(verifier.get(), "foo.com", port, server_config, quic_version, 188 RunVerification(verifier.get(), "foo.com", port, server_config, quic_version,
176 first_chlo_hash, wrong_certs, corrupt_signature, false); 189 first_chlo_hash, wrong_certs, corrupt_signature, false);
177 } 190 }
178 191
179 TEST_P(ProofTest, VerifySourceAsync) {
180 std::unique_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting());
181
182 const string server_config = "server config bytes";
183 const string hostname = "test.example.com";
184 const string first_chlo_hash = "first chlo hash bytes";
185 const string second_chlo_hash = "first chlo hash bytes";
186 const QuicVersion quic_version = GetParam();
187 QuicSocketAddress server_addr;
188
189 // Call synchronous version
190 QuicReferenceCountedPointer<ProofSource::Chain> expected_chain;
191 QuicCryptoProof expected_proof;
192 ASSERT_TRUE(source->GetProof(server_addr, hostname, server_config,
193 quic_version, first_chlo_hash, QuicTagVector(),
194 &expected_chain, &expected_proof));
195
196 // Call asynchronous version and compare results
197 bool called = false;
198 bool ok;
199 QuicReferenceCountedPointer<ProofSource::Chain> chain;
200 QuicCryptoProof proof;
201 std::unique_ptr<ProofSource::Callback> cb(
202 new TestCallback(&called, &ok, &chain, &proof));
203 source->GetProof(server_addr, hostname, server_config, quic_version,
204 first_chlo_hash, QuicTagVector(), std::move(cb));
205 // TODO(gredner): whan GetProof really invokes the callback asynchronously,
206 // figure out what to do here.
207 ASSERT_TRUE(called);
208 ASSERT_TRUE(ok);
209 EXPECT_THAT(chain->certs, ::testing::ContainerEq(expected_chain->certs));
210 EXPECT_EQ(proof.leaf_cert_scts, expected_proof.leaf_cert_scts);
211 }
212
213 TEST_P(ProofTest, UseAfterFree) { 192 TEST_P(ProofTest, UseAfterFree) {
214 std::unique_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); 193 std::unique_ptr<ProofSource> source(
194 crypto_test_utils::ProofSourceForTesting());
215 195
216 const string server_config = "server config bytes"; 196 const string server_config = "server config bytes";
217 const string hostname = "test.example.com"; 197 const string hostname = "test.example.com";
218 const string chlo_hash = "proof nonce bytes"; 198 const string chlo_hash = "proof nonce bytes";
199 bool called = false;
200 bool ok;
219 QuicReferenceCountedPointer<ProofSource::Chain> chain; 201 QuicReferenceCountedPointer<ProofSource::Chain> chain;
220 string error_details; 202 string error_details;
221 QuicCryptoProof proof; 203 QuicCryptoProof proof;
222 QuicSocketAddress server_addr; 204 QuicSocketAddress server_addr;
205 std::unique_ptr<ProofSource::Callback> cb(
206 new TestCallback(&called, &ok, &chain, &proof));
223 207
224 ASSERT_TRUE(source->GetProof(server_addr, hostname, server_config, GetParam(), 208 // GetProof here expects the async method to invoke the callback
225 chlo_hash, QuicTagVector(), &chain, &proof)); 209 // synchronously.
210 source->GetProof(server_addr, hostname, server_config, GetParam(), chlo_hash,
211 QuicTagVector(), std::move(cb));
212 ASSERT_TRUE(called);
213 ASSERT_TRUE(ok);
226 214
227 // Make sure we can safely access results after deleting where they came from. 215 // Make sure we can safely access results after deleting where they came from.
228 EXPECT_FALSE(chain->HasOneRef()); 216 EXPECT_FALSE(chain->HasOneRef());
229 source = nullptr; 217 source = nullptr;
230 EXPECT_TRUE(chain->HasOneRef()); 218 EXPECT_TRUE(chain->HasOneRef());
231 219
232 EXPECT_FALSE(chain->certs.empty()); 220 EXPECT_FALSE(chain->certs.empty());
233 for (const string& cert : chain->certs) { 221 for (const string& cert : chain->certs) {
234 EXPECT_FALSE(cert.empty()); 222 EXPECT_FALSE(cert.empty());
235 } 223 }
236 } 224 }
237 225
238 } // namespace test 226 } // namespace test
239 } // namespace net 227 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/chromium/crypto/proof_source_chromium.cc ('k') | net/quic/chromium/crypto_test_utils_chromium.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698