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

Side by Side Diff: net/cert/internal/path_builder_unittest.cc

Issue 2800993002: Add a key purpose parameter to Certificate PathBuilder. (Closed)
Patch Set: More cast comments Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/cert/internal/path_builder.h" 5 #include "net/cert/internal/path_builder.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "net/cert/internal/cert_issuer_source_static.h" 10 #include "net/cert/internal/cert_issuer_source_static.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // (This test is very similar to TestEndEntityHasSameNameAndSpkiAsTrustAnchor 153 // (This test is very similar to TestEndEntityHasSameNameAndSpkiAsTrustAnchor
154 // but with different data; also in this test the target cert itself is in the 154 // but with different data; also in this test the target cert itself is in the
155 // trust store). 155 // trust store).
156 TEST_F(PathBuilderMultiRootTest, TargetHasNameAndSpkiOfTrustAnchor) { 156 TEST_F(PathBuilderMultiRootTest, TargetHasNameAndSpkiOfTrustAnchor) {
157 TrustStoreInMemory trust_store; 157 TrustStoreInMemory trust_store;
158 AddTrustedCertificate(a_by_b_, &trust_store); 158 AddTrustedCertificate(a_by_b_, &trust_store);
159 AddTrustedCertificate(b_by_f_, &trust_store); 159 AddTrustedCertificate(b_by_f_, &trust_store);
160 160
161 CertPathBuilder::Result result; 161 CertPathBuilder::Result result;
162 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 162 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_,
163 &result); 163 KeyPurpose::KEY_PURPOSE_ANY, &result);
164 164
165 path_builder.Run(); 165 path_builder.Run();
166 166
167 ASSERT_TRUE(result.HasValidPath()); 167 ASSERT_TRUE(result.HasValidPath());
168 const auto& path = result.GetBestValidPath()->path; 168 const auto& path = result.GetBestValidPath()->path;
169 ASSERT_EQ(1U, path.certs.size()); 169 ASSERT_EQ(1U, path.certs.size());
170 EXPECT_EQ(a_by_b_, path.certs[0]); 170 EXPECT_EQ(a_by_b_, path.certs[0]);
171 EXPECT_EQ(b_by_f_, path.trust_anchor->cert()); 171 EXPECT_EQ(b_by_f_, path.trust_anchor->cert());
172 } 172 }
173 173
174 // If the target cert is has the same name and key as a trust anchor, however 174 // If the target cert is has the same name and key as a trust anchor, however
175 // is NOT itself signed by a trust anchor, it fails. Although the provided SPKI 175 // is NOT itself signed by a trust anchor, it fails. Although the provided SPKI
176 // is trusted, the certificate contents cannot be verified. 176 // is trusted, the certificate contents cannot be verified.
177 TEST_F(PathBuilderMultiRootTest, TargetWithSameNameAsTrustAnchorFails) { 177 TEST_F(PathBuilderMultiRootTest, TargetWithSameNameAsTrustAnchorFails) {
178 TrustStoreInMemory trust_store; 178 TrustStoreInMemory trust_store;
179 AddTrustedCertificate(a_by_b_, &trust_store); 179 AddTrustedCertificate(a_by_b_, &trust_store);
180 180
181 CertPathBuilder::Result result; 181 CertPathBuilder::Result result;
182 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 182 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_,
183 &result); 183 KeyPurpose::KEY_PURPOSE_ANY, &result);
184 184
185 path_builder.Run(); 185 path_builder.Run();
186 186
187 EXPECT_FALSE(result.HasValidPath()); 187 EXPECT_FALSE(result.HasValidPath());
188 } 188 }
189 189
190 // Test a failed path building when the trust anchor is provided as a 190 // Test a failed path building when the trust anchor is provided as a
191 // supplemental certificate. Conceptually the following paths can be built: 191 // supplemental certificate. Conceptually the following paths can be built:
192 // 192 //
193 // B(C) <- C(D) <- [Trust anchor D] 193 // B(C) <- C(D) <- [Trust anchor D]
194 // B(C) <- C(D) <- D(D) <- [Trust anchor D] 194 // B(C) <- C(D) <- D(D) <- [Trust anchor D]
195 // 195 //
196 // The second one is extraneous given the shorter one, however path building 196 // The second one is extraneous given the shorter one, however path building
197 // will enumerate it if the shorter one failed validation. 197 // will enumerate it if the shorter one failed validation.
198 TEST_F(PathBuilderMultiRootTest, SelfSignedTrustAnchorSupplementalCert) { 198 TEST_F(PathBuilderMultiRootTest, SelfSignedTrustAnchorSupplementalCert) {
199 TrustStoreInMemory trust_store; 199 TrustStoreInMemory trust_store;
200 AddTrustedCertificate(d_by_d_, &trust_store); 200 AddTrustedCertificate(d_by_d_, &trust_store);
201 201
202 // The (extraneous) trust anchor D(D) is supplied as a certificate, as is the 202 // The (extraneous) trust anchor D(D) is supplied as a certificate, as is the
203 // intermediate needed for path building C(D). 203 // intermediate needed for path building C(D).
204 CertIssuerSourceStatic sync_certs; 204 CertIssuerSourceStatic sync_certs;
205 sync_certs.AddCert(d_by_d_); 205 sync_certs.AddCert(d_by_d_);
206 sync_certs.AddCert(c_by_d_); 206 sync_certs.AddCert(c_by_d_);
207 207
208 // C(D) is not valid at this time, so path building will fail. 208 // C(D) is not valid at this time, so path building will fail.
209 der::GeneralizedTime expired_time = {2016, 1, 1, 0, 0, 0}; 209 der::GeneralizedTime expired_time = {2016, 1, 1, 0, 0, 0};
210 210
211 CertPathBuilder::Result result; 211 CertPathBuilder::Result result;
212 CertPathBuilder path_builder(b_by_c_, &trust_store, &signature_policy_, 212 CertPathBuilder path_builder(b_by_c_, &trust_store, &signature_policy_,
213 expired_time, &result); 213 expired_time, KeyPurpose::KEY_PURPOSE_ANY,
214 &result);
214 path_builder.AddCertIssuerSource(&sync_certs); 215 path_builder.AddCertIssuerSource(&sync_certs);
215 216
216 path_builder.Run(); 217 path_builder.Run();
217 218
218 EXPECT_FALSE(result.HasValidPath()); 219 EXPECT_FALSE(result.HasValidPath());
219 ASSERT_EQ(2U, result.paths.size()); 220 ASSERT_EQ(2U, result.paths.size());
220 221
221 EXPECT_FALSE(result.paths[0]->IsValid()); 222 EXPECT_FALSE(result.paths[0]->IsValid());
222 const auto& path0 = result.paths[0]->path; 223 const auto& path0 = result.paths[0]->path;
223 ASSERT_EQ(2U, path0.certs.size()); 224 ASSERT_EQ(2U, path0.certs.size());
(...skipping 12 matching lines...) Expand all
236 // If the target cert is a self-signed cert whose key is a trust anchor, it 237 // If the target cert is a self-signed cert whose key is a trust anchor, it
237 // should verify. 238 // should verify.
238 TEST_F(PathBuilderMultiRootTest, TargetIsSelfSignedTrustAnchor) { 239 TEST_F(PathBuilderMultiRootTest, TargetIsSelfSignedTrustAnchor) {
239 TrustStoreInMemory trust_store; 240 TrustStoreInMemory trust_store;
240 AddTrustedCertificate(e_by_e_, &trust_store); 241 AddTrustedCertificate(e_by_e_, &trust_store);
241 // This is not necessary for the test, just an extra... 242 // This is not necessary for the test, just an extra...
242 AddTrustedCertificate(f_by_e_, &trust_store); 243 AddTrustedCertificate(f_by_e_, &trust_store);
243 244
244 CertPathBuilder::Result result; 245 CertPathBuilder::Result result;
245 CertPathBuilder path_builder(e_by_e_, &trust_store, &signature_policy_, time_, 246 CertPathBuilder path_builder(e_by_e_, &trust_store, &signature_policy_, time_,
246 &result); 247 KeyPurpose::KEY_PURPOSE_ANY, &result);
247 248
248 path_builder.Run(); 249 path_builder.Run();
249 250
250 ASSERT_TRUE(result.HasValidPath()); 251 ASSERT_TRUE(result.HasValidPath());
251 const auto& path = result.GetBestValidPath()->path; 252 const auto& path = result.GetBestValidPath()->path;
252 ASSERT_EQ(1U, path.certs.size()); 253 ASSERT_EQ(1U, path.certs.size());
253 EXPECT_EQ(e_by_e_, path.certs[0]); 254 EXPECT_EQ(e_by_e_, path.certs[0]);
254 EXPECT_EQ(e_by_e_, path.trust_anchor->cert()); 255 EXPECT_EQ(e_by_e_, path.trust_anchor->cert());
255 } 256 }
256 257
257 // If the target cert is directly issued by a trust anchor, it should verify 258 // If the target cert is directly issued by a trust anchor, it should verify
258 // without any intermediate certs being provided. 259 // without any intermediate certs being provided.
259 TEST_F(PathBuilderMultiRootTest, TargetDirectlySignedByTrustAnchor) { 260 TEST_F(PathBuilderMultiRootTest, TargetDirectlySignedByTrustAnchor) {
260 TrustStoreInMemory trust_store; 261 TrustStoreInMemory trust_store;
261 AddTrustedCertificate(b_by_f_, &trust_store); 262 AddTrustedCertificate(b_by_f_, &trust_store);
262 263
263 CertPathBuilder::Result result; 264 CertPathBuilder::Result result;
264 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 265 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_,
265 &result); 266 KeyPurpose::KEY_PURPOSE_ANY, &result);
266 267
267 path_builder.Run(); 268 path_builder.Run();
268 269
269 ASSERT_TRUE(result.HasValidPath()); 270 ASSERT_TRUE(result.HasValidPath());
270 const auto& path = result.GetBestValidPath()->path; 271 const auto& path = result.GetBestValidPath()->path;
271 ASSERT_EQ(1U, path.certs.size()); 272 ASSERT_EQ(1U, path.certs.size());
272 EXPECT_EQ(a_by_b_, path.certs[0]); 273 EXPECT_EQ(a_by_b_, path.certs[0]);
273 EXPECT_EQ(b_by_f_, path.trust_anchor->cert()); 274 EXPECT_EQ(b_by_f_, path.trust_anchor->cert());
274 } 275 }
275 276
276 // Test that async cert queries are not made if the path can be successfully 277 // Test that async cert queries are not made if the path can be successfully
277 // built with synchronously available certs. 278 // built with synchronously available certs.
278 TEST_F(PathBuilderMultiRootTest, TriesSyncFirst) { 279 TEST_F(PathBuilderMultiRootTest, TriesSyncFirst) {
279 TrustStoreInMemory trust_store; 280 TrustStoreInMemory trust_store;
280 AddTrustedCertificate(e_by_e_, &trust_store); 281 AddTrustedCertificate(e_by_e_, &trust_store);
281 282
282 CertIssuerSourceStatic sync_certs; 283 CertIssuerSourceStatic sync_certs;
283 sync_certs.AddCert(b_by_f_); 284 sync_certs.AddCert(b_by_f_);
284 sync_certs.AddCert(f_by_e_); 285 sync_certs.AddCert(f_by_e_);
285 286
286 AsyncCertIssuerSourceStatic async_certs; 287 AsyncCertIssuerSourceStatic async_certs;
287 async_certs.AddCert(b_by_c_); 288 async_certs.AddCert(b_by_c_);
288 async_certs.AddCert(c_by_e_); 289 async_certs.AddCert(c_by_e_);
289 290
290 CertPathBuilder::Result result; 291 CertPathBuilder::Result result;
291 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 292 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_,
292 &result); 293 KeyPurpose::KEY_PURPOSE_ANY, &result);
293 path_builder.AddCertIssuerSource(&async_certs); 294 path_builder.AddCertIssuerSource(&async_certs);
294 path_builder.AddCertIssuerSource(&sync_certs); 295 path_builder.AddCertIssuerSource(&sync_certs);
295 296
296 path_builder.Run(); 297 path_builder.Run();
297 298
298 EXPECT_TRUE(result.HasValidPath()); 299 EXPECT_TRUE(result.HasValidPath());
299 EXPECT_EQ(0, async_certs.num_async_gets()); 300 EXPECT_EQ(0, async_certs.num_async_gets());
300 } 301 }
301 302
302 // If async queries are needed, all async sources will be queried 303 // If async queries are needed, all async sources will be queried
303 // simultaneously. 304 // simultaneously.
304 TEST_F(PathBuilderMultiRootTest, TestAsyncSimultaneous) { 305 TEST_F(PathBuilderMultiRootTest, TestAsyncSimultaneous) {
305 TrustStoreInMemory trust_store; 306 TrustStoreInMemory trust_store;
306 AddTrustedCertificate(e_by_e_, &trust_store); 307 AddTrustedCertificate(e_by_e_, &trust_store);
307 308
308 CertIssuerSourceStatic sync_certs; 309 CertIssuerSourceStatic sync_certs;
309 sync_certs.AddCert(b_by_c_); 310 sync_certs.AddCert(b_by_c_);
310 sync_certs.AddCert(b_by_f_); 311 sync_certs.AddCert(b_by_f_);
311 312
312 AsyncCertIssuerSourceStatic async_certs1; 313 AsyncCertIssuerSourceStatic async_certs1;
313 async_certs1.AddCert(c_by_e_); 314 async_certs1.AddCert(c_by_e_);
314 315
315 AsyncCertIssuerSourceStatic async_certs2; 316 AsyncCertIssuerSourceStatic async_certs2;
316 async_certs2.AddCert(f_by_e_); 317 async_certs2.AddCert(f_by_e_);
317 318
318 CertPathBuilder::Result result; 319 CertPathBuilder::Result result;
319 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 320 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_,
320 &result); 321 KeyPurpose::KEY_PURPOSE_ANY, &result);
321 path_builder.AddCertIssuerSource(&async_certs1); 322 path_builder.AddCertIssuerSource(&async_certs1);
322 path_builder.AddCertIssuerSource(&async_certs2); 323 path_builder.AddCertIssuerSource(&async_certs2);
323 path_builder.AddCertIssuerSource(&sync_certs); 324 path_builder.AddCertIssuerSource(&sync_certs);
324 325
325 path_builder.Run(); 326 path_builder.Run();
326 327
327 EXPECT_TRUE(result.HasValidPath()); 328 EXPECT_TRUE(result.HasValidPath());
328 EXPECT_EQ(1, async_certs1.num_async_gets()); 329 EXPECT_EQ(1, async_certs1.num_async_gets());
329 EXPECT_EQ(1, async_certs2.num_async_gets()); 330 EXPECT_EQ(1, async_certs2.num_async_gets());
330 } 331 }
331 332
332 // Test that PathBuilder does not generate longer paths than necessary if one of 333 // Test that PathBuilder does not generate longer paths than necessary if one of
333 // the supplied certs is itself a trust anchor. 334 // the supplied certs is itself a trust anchor.
334 TEST_F(PathBuilderMultiRootTest, TestLongChain) { 335 TEST_F(PathBuilderMultiRootTest, TestLongChain) {
335 // Both D(D) and C(D) are trusted roots. 336 // Both D(D) and C(D) are trusted roots.
336 TrustStoreInMemory trust_store; 337 TrustStoreInMemory trust_store;
337 AddTrustedCertificate(d_by_d_, &trust_store); 338 AddTrustedCertificate(d_by_d_, &trust_store);
338 AddTrustedCertificate(c_by_d_, &trust_store); 339 AddTrustedCertificate(c_by_d_, &trust_store);
339 340
340 // Certs B(C), and C(D) are all supplied. 341 // Certs B(C), and C(D) are all supplied.
341 CertIssuerSourceStatic sync_certs; 342 CertIssuerSourceStatic sync_certs;
342 sync_certs.AddCert(b_by_c_); 343 sync_certs.AddCert(b_by_c_);
343 sync_certs.AddCert(c_by_d_); 344 sync_certs.AddCert(c_by_d_);
344 345
345 CertPathBuilder::Result result; 346 CertPathBuilder::Result result;
346 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 347 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_,
347 &result); 348 KeyPurpose::KEY_PURPOSE_ANY, &result);
348 path_builder.AddCertIssuerSource(&sync_certs); 349 path_builder.AddCertIssuerSource(&sync_certs);
349 350
350 path_builder.Run(); 351 path_builder.Run();
351 352
352 ASSERT_TRUE(result.HasValidPath()); 353 ASSERT_TRUE(result.HasValidPath());
353 354
354 // The result path should be A(B) <- B(C) <- C(D) 355 // The result path should be A(B) <- B(C) <- C(D)
355 // not the longer but also valid A(B) <- B(C) <- C(D) <- D(D) 356 // not the longer but also valid A(B) <- B(C) <- C(D) <- D(D)
356 EXPECT_EQ(2U, result.GetBestValidPath()->path.certs.size()); 357 EXPECT_EQ(2U, result.GetBestValidPath()->path.certs.size());
357 } 358 }
(...skipping 12 matching lines...) Expand all
370 sync_certs.AddCert(f_by_e_); 371 sync_certs.AddCert(f_by_e_);
371 372
372 // Certs B(C), and C(D) are supplied asynchronously, so the path 373 // Certs B(C), and C(D) are supplied asynchronously, so the path
373 // A(B) <- B(C) <- C(D) <- D(D) should be tried second. 374 // A(B) <- B(C) <- C(D) <- D(D) should be tried second.
374 AsyncCertIssuerSourceStatic async_certs; 375 AsyncCertIssuerSourceStatic async_certs;
375 async_certs.AddCert(b_by_c_); 376 async_certs.AddCert(b_by_c_);
376 async_certs.AddCert(c_by_d_); 377 async_certs.AddCert(c_by_d_);
377 378
378 CertPathBuilder::Result result; 379 CertPathBuilder::Result result;
379 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 380 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_,
380 &result); 381 KeyPurpose::KEY_PURPOSE_ANY, &result);
381 path_builder.AddCertIssuerSource(&sync_certs); 382 path_builder.AddCertIssuerSource(&sync_certs);
382 path_builder.AddCertIssuerSource(&async_certs); 383 path_builder.AddCertIssuerSource(&async_certs);
383 384
384 path_builder.Run(); 385 path_builder.Run();
385 386
386 ASSERT_TRUE(result.HasValidPath()); 387 ASSERT_TRUE(result.HasValidPath());
387 388
388 // The result path should be A(B) <- B(C) <- C(D) <- D(D) 389 // The result path should be A(B) <- B(C) <- C(D) <- D(D)
389 const auto& path = result.GetBestValidPath()->path; 390 const auto& path = result.GetBestValidPath()->path;
390 ASSERT_EQ(3U, path.certs.size()); 391 ASSERT_EQ(3U, path.certs.size());
(...skipping 18 matching lines...) Expand all
409 if (reverse_order) { 410 if (reverse_order) {
410 for (auto it = certs.rbegin(); it != certs.rend(); ++it) 411 for (auto it = certs.rbegin(); it != certs.rend(); ++it)
411 sync_certs.AddCert(*it); 412 sync_certs.AddCert(*it);
412 } else { 413 } else {
413 for (const auto& cert : certs) 414 for (const auto& cert : certs)
414 sync_certs.AddCert(cert); 415 sync_certs.AddCert(cert);
415 } 416 }
416 417
417 CertPathBuilder::Result result; 418 CertPathBuilder::Result result;
418 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, 419 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_,
419 time_, &result); 420 time_, KeyPurpose::KEY_PURPOSE_ANY, &result);
420 path_builder.AddCertIssuerSource(&sync_certs); 421 path_builder.AddCertIssuerSource(&sync_certs);
421 422
422 path_builder.Run(); 423 path_builder.Run();
423 424
424 ASSERT_TRUE(result.HasValidPath()); 425 ASSERT_TRUE(result.HasValidPath());
425 426
426 // The result path should be A(B) <- B(C) <- C(D) <- D(D) 427 // The result path should be A(B) <- B(C) <- C(D) <- D(D)
427 const auto& path = result.GetBestValidPath()->path; 428 const auto& path = result.GetBestValidPath()->path;
428 ASSERT_EQ(3U, path.certs.size()); 429 ASSERT_EQ(3U, path.certs.size());
429 EXPECT_EQ(a_by_b_, path.certs[0]); 430 EXPECT_EQ(a_by_b_, path.certs[0]);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 trust_store.AddTrustAnchor(oldroot_); 501 trust_store.AddTrustAnchor(oldroot_);
501 502
502 // Old intermediate cert is not provided, so the pathbuilder will need to go 503 // Old intermediate cert is not provided, so the pathbuilder will need to go
503 // through the rollover cert. 504 // through the rollover cert.
504 CertIssuerSourceStatic sync_certs; 505 CertIssuerSourceStatic sync_certs;
505 sync_certs.AddCert(newintermediate_); 506 sync_certs.AddCert(newintermediate_);
506 sync_certs.AddCert(newrootrollover_); 507 sync_certs.AddCert(newrootrollover_);
507 508
508 CertPathBuilder::Result result; 509 CertPathBuilder::Result result;
509 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 510 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_,
510 &result); 511 KeyPurpose::KEY_PURPOSE_ANY, &result);
511 path_builder.AddCertIssuerSource(&sync_certs); 512 path_builder.AddCertIssuerSource(&sync_certs);
512 513
513 path_builder.Run(); 514 path_builder.Run();
514 515
515 EXPECT_TRUE(result.HasValidPath()); 516 EXPECT_TRUE(result.HasValidPath());
516 517
517 // Path builder will first attempt: target <- newintermediate <- oldroot 518 // Path builder will first attempt: target <- newintermediate <- oldroot
518 // but it will fail since newintermediate is signed by newroot. 519 // but it will fail since newintermediate is signed by newroot.
519 ASSERT_EQ(2U, result.paths.size()); 520 ASSERT_EQ(2U, result.paths.size());
520 const auto& path0 = result.paths[0]->path; 521 const auto& path0 = result.paths[0]->path;
(...skipping 27 matching lines...) Expand all
548 AddTrustedCertificate(newroot_, &trust_store); 549 AddTrustedCertificate(newroot_, &trust_store);
549 550
550 // Both old and new intermediates + rollover cert are provided. 551 // Both old and new intermediates + rollover cert are provided.
551 CertIssuerSourceStatic sync_certs; 552 CertIssuerSourceStatic sync_certs;
552 sync_certs.AddCert(oldintermediate_); 553 sync_certs.AddCert(oldintermediate_);
553 sync_certs.AddCert(newintermediate_); 554 sync_certs.AddCert(newintermediate_);
554 sync_certs.AddCert(newrootrollover_); 555 sync_certs.AddCert(newrootrollover_);
555 556
556 CertPathBuilder::Result result; 557 CertPathBuilder::Result result;
557 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 558 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_,
558 &result); 559 KeyPurpose::KEY_PURPOSE_ANY, &result);
559 path_builder.AddCertIssuerSource(&sync_certs); 560 path_builder.AddCertIssuerSource(&sync_certs);
560 561
561 path_builder.Run(); 562 path_builder.Run();
562 563
563 EXPECT_TRUE(result.HasValidPath()); 564 EXPECT_TRUE(result.HasValidPath());
564 565
565 // Path builder willattempt one of: 566 // Path builder willattempt one of:
566 // target <- oldintermediate <- oldroot 567 // target <- oldintermediate <- oldroot
567 // target <- newintermediate <- newroot 568 // target <- newintermediate <- newroot
568 // either will succeed. 569 // either will succeed.
(...skipping 15 matching lines...) Expand all
584 585
585 // If trust anchor query returned no results, and there are no issuer 586 // If trust anchor query returned no results, and there are no issuer
586 // sources, path building should fail at that point. 587 // sources, path building should fail at that point.
587 TEST_F(PathBuilderKeyRolloverTest, TestAnchorsNoMatchAndNoIssuerSources) { 588 TEST_F(PathBuilderKeyRolloverTest, TestAnchorsNoMatchAndNoIssuerSources) {
588 TrustStoreInMemory trust_store; 589 TrustStoreInMemory trust_store;
589 trust_store.AddTrustAnchor( 590 trust_store.AddTrustAnchor(
590 TrustAnchor::CreateFromCertificateNoConstraints(newroot_)); 591 TrustAnchor::CreateFromCertificateNoConstraints(newroot_));
591 592
592 CertPathBuilder::Result result; 593 CertPathBuilder::Result result;
593 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 594 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_,
594 &result); 595 KeyPurpose::KEY_PURPOSE_ANY, &result);
595 596
596 path_builder.Run(); 597 path_builder.Run();
597 598
598 EXPECT_FALSE(result.HasValidPath()); 599 EXPECT_FALSE(result.HasValidPath());
599 600
600 ASSERT_EQ(0U, result.paths.size()); 601 ASSERT_EQ(0U, result.paths.size());
601 } 602 }
602 603
603 // Tests that multiple trust root matches on a single path will be considered. 604 // Tests that multiple trust root matches on a single path will be considered.
604 // Both roots have the same subject but different keys. Only one of them will 605 // Both roots have the same subject but different keys. Only one of them will
(...skipping 11 matching lines...) Expand all
616 TrustAnchor::CreateFromCertificateNoConstraints(newroot_)); 617 TrustAnchor::CreateFromCertificateNoConstraints(newroot_));
617 trust_store2.AddTrustAnchor(oldroot_); 618 trust_store2.AddTrustAnchor(oldroot_);
618 619
619 // Only oldintermediate is supplied, so the path with newroot should fail, 620 // Only oldintermediate is supplied, so the path with newroot should fail,
620 // oldroot should succeed. 621 // oldroot should succeed.
621 CertIssuerSourceStatic sync_certs; 622 CertIssuerSourceStatic sync_certs;
622 sync_certs.AddCert(oldintermediate_); 623 sync_certs.AddCert(oldintermediate_);
623 624
624 CertPathBuilder::Result result; 625 CertPathBuilder::Result result;
625 CertPathBuilder path_builder(target_, &trust_store_collection, 626 CertPathBuilder path_builder(target_, &trust_store_collection,
626 &signature_policy_, time_, &result); 627 &signature_policy_, time_,
628 KeyPurpose::KEY_PURPOSE_ANY, &result);
627 path_builder.AddCertIssuerSource(&sync_certs); 629 path_builder.AddCertIssuerSource(&sync_certs);
628 630
629 path_builder.Run(); 631 path_builder.Run();
630 632
631 EXPECT_TRUE(result.HasValidPath()); 633 EXPECT_TRUE(result.HasValidPath());
632 ASSERT_EQ(2U, result.paths.size()); 634 ASSERT_EQ(2U, result.paths.size());
633 635
634 { 636 {
635 // Path builder may first attempt: target <- oldintermediate <- newroot 637 // Path builder may first attempt: target <- oldintermediate <- newroot
636 // but it will fail since oldintermediate is signed by oldroot. 638 // but it will fail since oldintermediate is signed by oldroot.
(...skipping 29 matching lines...) Expand all
666 sync_certs.AddCert(newintermediate_); 668 sync_certs.AddCert(newintermediate_);
667 sync_certs.AddCert(newroot_); 669 sync_certs.AddCert(newroot_);
668 670
669 // Rollover cert is only provided asynchronously. This will force the 671 // Rollover cert is only provided asynchronously. This will force the
670 // pathbuilder to first try building a longer than necessary path. 672 // pathbuilder to first try building a longer than necessary path.
671 AsyncCertIssuerSourceStatic async_certs; 673 AsyncCertIssuerSourceStatic async_certs;
672 async_certs.AddCert(newrootrollover_); 674 async_certs.AddCert(newrootrollover_);
673 675
674 CertPathBuilder::Result result; 676 CertPathBuilder::Result result;
675 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 677 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_,
676 &result); 678 KeyPurpose::KEY_PURPOSE_ANY, &result);
677 path_builder.AddCertIssuerSource(&sync_certs); 679 path_builder.AddCertIssuerSource(&sync_certs);
678 path_builder.AddCertIssuerSource(&async_certs); 680 path_builder.AddCertIssuerSource(&async_certs);
679 681
680 path_builder.Run(); 682 path_builder.Run();
681 683
682 EXPECT_TRUE(result.HasValidPath()); 684 EXPECT_TRUE(result.HasValidPath());
683 ASSERT_EQ(3U, result.paths.size()); 685 ASSERT_EQ(3U, result.paths.size());
684 686
685 // Path builder will first attempt: target <- newintermediate <- oldroot 687 // Path builder will first attempt: target <- newintermediate <- oldroot
686 // but it will fail since newintermediate is signed by newroot. 688 // but it will fail since newintermediate is signed by newroot.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 // trust anchor matches the SPKI and subject of the targe certificate, but the 725 // trust anchor matches the SPKI and subject of the targe certificate, but the
724 // rest of the certificate cannot be verified). 726 // rest of the certificate cannot be verified).
725 TEST_F(PathBuilderKeyRolloverTest, TestEndEntityIsTrustRoot) { 727 TEST_F(PathBuilderKeyRolloverTest, TestEndEntityIsTrustRoot) {
726 // Trust newintermediate. 728 // Trust newintermediate.
727 TrustStoreInMemory trust_store; 729 TrustStoreInMemory trust_store;
728 AddTrustedCertificate(newintermediate_, &trust_store); 730 AddTrustedCertificate(newintermediate_, &trust_store);
729 731
730 CertPathBuilder::Result result; 732 CertPathBuilder::Result result;
731 // Newintermediate is also the target cert. 733 // Newintermediate is also the target cert.
732 CertPathBuilder path_builder(newintermediate_, &trust_store, 734 CertPathBuilder path_builder(newintermediate_, &trust_store,
733 &signature_policy_, time_, &result); 735 &signature_policy_, time_,
736 KeyPurpose::KEY_PURPOSE_ANY, &result);
734 737
735 path_builder.Run(); 738 path_builder.Run();
736 739
737 EXPECT_FALSE(result.HasValidPath()); 740 EXPECT_FALSE(result.HasValidPath());
738 } 741 }
739 742
740 // If target has same Name+SAN+SPKI as a necessary intermediate, test if a path 743 // If target has same Name+SAN+SPKI as a necessary intermediate, test if a path
741 // can still be built. 744 // can still be built.
742 // Since LoopChecker will prevent the intermediate from being included, this 745 // Since LoopChecker will prevent the intermediate from being included, this
743 // currently does NOT verify. This case shouldn't occur in the web PKI. 746 // currently does NOT verify. This case shouldn't occur in the web PKI.
744 TEST_F(PathBuilderKeyRolloverTest, 747 TEST_F(PathBuilderKeyRolloverTest,
745 TestEndEntityHasSameNameAndSpkiAsIntermediate) { 748 TestEndEntityHasSameNameAndSpkiAsIntermediate) {
746 // Trust oldroot. 749 // Trust oldroot.
747 TrustStoreInMemory trust_store; 750 TrustStoreInMemory trust_store;
748 trust_store.AddTrustAnchor(oldroot_); 751 trust_store.AddTrustAnchor(oldroot_);
749 752
750 // New root rollover is provided synchronously. 753 // New root rollover is provided synchronously.
751 CertIssuerSourceStatic sync_certs; 754 CertIssuerSourceStatic sync_certs;
752 sync_certs.AddCert(newrootrollover_); 755 sync_certs.AddCert(newrootrollover_);
753 756
754 CertPathBuilder::Result result; 757 CertPathBuilder::Result result;
755 // Newroot is the target cert. 758 // Newroot is the target cert.
756 CertPathBuilder path_builder(newroot_, &trust_store, &signature_policy_, 759 CertPathBuilder path_builder(newroot_, &trust_store, &signature_policy_,
757 time_, &result); 760 time_, KeyPurpose::KEY_PURPOSE_ANY, &result);
758 path_builder.AddCertIssuerSource(&sync_certs); 761 path_builder.AddCertIssuerSource(&sync_certs);
759 762
760 path_builder.Run(); 763 path_builder.Run();
761 764
762 // This could actually be OK, but CertPathBuilder does not build the 765 // This could actually be OK, but CertPathBuilder does not build the
763 // newroot <- newrootrollover <- oldroot path. 766 // newroot <- newrootrollover <- oldroot path.
764 EXPECT_FALSE(result.HasValidPath()); 767 EXPECT_FALSE(result.HasValidPath());
765 } 768 }
766 769
767 // If target has same Name+SAN+SPKI as the trust root, test that a (trivial) 770 // If target has same Name+SAN+SPKI as the trust root, test that a (trivial)
768 // path can still be built. 771 // path can still be built.
769 TEST_F(PathBuilderKeyRolloverTest, 772 TEST_F(PathBuilderKeyRolloverTest,
770 TestEndEntityHasSameNameAndSpkiAsTrustAnchor) { 773 TestEndEntityHasSameNameAndSpkiAsTrustAnchor) {
771 // Trust newrootrollover. 774 // Trust newrootrollover.
772 TrustStoreInMemory trust_store; 775 TrustStoreInMemory trust_store;
773 AddTrustedCertificate(newrootrollover_, &trust_store); 776 AddTrustedCertificate(newrootrollover_, &trust_store);
774 777
775 CertPathBuilder::Result result; 778 CertPathBuilder::Result result;
776 // Newroot is the target cert. 779 // Newroot is the target cert.
777 CertPathBuilder path_builder(newroot_, &trust_store, &signature_policy_, 780 CertPathBuilder path_builder(newroot_, &trust_store, &signature_policy_,
778 time_, &result); 781 time_, KeyPurpose::KEY_PURPOSE_ANY, &result);
779 782
780 path_builder.Run(); 783 path_builder.Run();
781 784
782 ASSERT_TRUE(result.HasValidPath()); 785 ASSERT_TRUE(result.HasValidPath());
783 786
784 const CertPathBuilder::ResultPath* best_result = result.GetBestValidPath(); 787 const CertPathBuilder::ResultPath* best_result = result.GetBestValidPath();
785 788
786 // Newroot has same name+SPKI as newrootrollover, thus the path is valid and 789 // Newroot has same name+SPKI as newrootrollover, thus the path is valid and
787 // only contains newroot. 790 // only contains newroot.
788 EXPECT_TRUE(best_result->IsValid()); 791 EXPECT_TRUE(best_result->IsValid());
(...skipping 27 matching lines...) Expand all
816 CertIssuerSourceStatic sync_certs2; 819 CertIssuerSourceStatic sync_certs2;
817 sync_certs2.AddCert(oldintermediate_dupe); 820 sync_certs2.AddCert(oldintermediate_dupe);
818 821
819 // The newintermediate is supplied asynchronously, so the path 822 // The newintermediate is supplied asynchronously, so the path
820 // target <- newintermediate <- newroot should be tried second. 823 // target <- newintermediate <- newroot should be tried second.
821 AsyncCertIssuerSourceStatic async_certs; 824 AsyncCertIssuerSourceStatic async_certs;
822 async_certs.AddCert(newintermediate_); 825 async_certs.AddCert(newintermediate_);
823 826
824 CertPathBuilder::Result result; 827 CertPathBuilder::Result result;
825 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 828 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_,
826 &result); 829 KeyPurpose::KEY_PURPOSE_ANY, &result);
827 path_builder.AddCertIssuerSource(&sync_certs1); 830 path_builder.AddCertIssuerSource(&sync_certs1);
828 path_builder.AddCertIssuerSource(&sync_certs2); 831 path_builder.AddCertIssuerSource(&sync_certs2);
829 path_builder.AddCertIssuerSource(&async_certs); 832 path_builder.AddCertIssuerSource(&async_certs);
830 833
831 path_builder.Run(); 834 path_builder.Run();
832 835
833 EXPECT_TRUE(result.HasValidPath()); 836 EXPECT_TRUE(result.HasValidPath());
834 ASSERT_EQ(2U, result.paths.size()); 837 ASSERT_EQ(2U, result.paths.size());
835 838
836 // Path builder will first attempt: target <- oldintermediate <- newroot 839 // Path builder will first attempt: target <- oldintermediate <- newroot
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 TrustStoreInMemory trust_store; 873 TrustStoreInMemory trust_store;
871 AddTrustedCertificate(newroot_, &trust_store); 874 AddTrustedCertificate(newroot_, &trust_store);
872 875
873 // The oldintermediate and newroot are supplied synchronously by |sync_certs|. 876 // The oldintermediate and newroot are supplied synchronously by |sync_certs|.
874 CertIssuerSourceStatic sync_certs; 877 CertIssuerSourceStatic sync_certs;
875 sync_certs.AddCert(oldintermediate_); 878 sync_certs.AddCert(oldintermediate_);
876 sync_certs.AddCert(newroot_dupe); 879 sync_certs.AddCert(newroot_dupe);
877 880
878 CertPathBuilder::Result result; 881 CertPathBuilder::Result result;
879 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 882 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_,
880 &result); 883 KeyPurpose::KEY_PURPOSE_ANY, &result);
881 path_builder.AddCertIssuerSource(&sync_certs); 884 path_builder.AddCertIssuerSource(&sync_certs);
882 885
883 path_builder.Run(); 886 path_builder.Run();
884 887
885 EXPECT_FALSE(result.HasValidPath()); 888 EXPECT_FALSE(result.HasValidPath());
886 ASSERT_EQ(2U, result.paths.size()); 889 ASSERT_EQ(2U, result.paths.size());
887 // TODO(eroman): Is this right? 890 // TODO(eroman): Is this right?
888 891
889 // Path builder attempt: target <- oldintermediate <- newroot 892 // Path builder attempt: target <- oldintermediate <- newroot
890 // but it will fail since oldintermediate is signed by oldroot. 893 // but it will fail since oldintermediate is signed by oldroot.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 // builder does not request issuers of certs that it shouldn't. 948 // builder does not request issuers of certs that it shouldn't.
946 TEST_F(PathBuilderKeyRolloverTest, TestMultipleAsyncIssuersFromSingleSource) { 949 TEST_F(PathBuilderKeyRolloverTest, TestMultipleAsyncIssuersFromSingleSource) {
947 StrictMock<MockCertIssuerSource> cert_issuer_source; 950 StrictMock<MockCertIssuerSource> cert_issuer_source;
948 951
949 // Only newroot is a trusted root. 952 // Only newroot is a trusted root.
950 TrustStoreInMemory trust_store; 953 TrustStoreInMemory trust_store;
951 AddTrustedCertificate(newroot_, &trust_store); 954 AddTrustedCertificate(newroot_, &trust_store);
952 955
953 CertPathBuilder::Result result; 956 CertPathBuilder::Result result;
954 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 957 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_,
955 &result); 958 KeyPurpose::KEY_PURPOSE_ANY, &result);
956 path_builder.AddCertIssuerSource(&cert_issuer_source); 959 path_builder.AddCertIssuerSource(&cert_issuer_source);
957 960
958 // Create the mock CertIssuerSource::Request... 961 // Create the mock CertIssuerSource::Request...
959 std::unique_ptr<StrictMock<MockCertIssuerSourceRequest>> 962 std::unique_ptr<StrictMock<MockCertIssuerSourceRequest>>
960 target_issuers_req_owner(new StrictMock<MockCertIssuerSourceRequest>()); 963 target_issuers_req_owner(new StrictMock<MockCertIssuerSourceRequest>());
961 // Keep a raw pointer to the Request... 964 // Keep a raw pointer to the Request...
962 StrictMock<MockCertIssuerSourceRequest>* target_issuers_req = 965 StrictMock<MockCertIssuerSourceRequest>* target_issuers_req =
963 target_issuers_req_owner.get(); 966 target_issuers_req_owner.get();
964 // Setup helper class to pass ownership of the Request to the PathBuilder when 967 // Setup helper class to pass ownership of the Request to the PathBuilder when
965 // it calls AsyncGetIssuersOf. 968 // it calls AsyncGetIssuersOf.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 // asynchronously provide the same certificate multiple times. 1027 // asynchronously provide the same certificate multiple times.
1025 TEST_F(PathBuilderKeyRolloverTest, TestDuplicateAsyncIntermediates) { 1028 TEST_F(PathBuilderKeyRolloverTest, TestDuplicateAsyncIntermediates) {
1026 StrictMock<MockCertIssuerSource> cert_issuer_source; 1029 StrictMock<MockCertIssuerSource> cert_issuer_source;
1027 1030
1028 // Only newroot is a trusted root. 1031 // Only newroot is a trusted root.
1029 TrustStoreInMemory trust_store; 1032 TrustStoreInMemory trust_store;
1030 AddTrustedCertificate(newroot_, &trust_store); 1033 AddTrustedCertificate(newroot_, &trust_store);
1031 1034
1032 CertPathBuilder::Result result; 1035 CertPathBuilder::Result result;
1033 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 1036 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_,
1034 &result); 1037 KeyPurpose::KEY_PURPOSE_ANY, &result);
1035 path_builder.AddCertIssuerSource(&cert_issuer_source); 1038 path_builder.AddCertIssuerSource(&cert_issuer_source);
1036 1039
1037 // Create the mock CertIssuerSource::Request... 1040 // Create the mock CertIssuerSource::Request...
1038 std::unique_ptr<StrictMock<MockCertIssuerSourceRequest>> 1041 std::unique_ptr<StrictMock<MockCertIssuerSourceRequest>>
1039 target_issuers_req_owner(new StrictMock<MockCertIssuerSourceRequest>()); 1042 target_issuers_req_owner(new StrictMock<MockCertIssuerSourceRequest>());
1040 // Keep a raw pointer to the Request... 1043 // Keep a raw pointer to the Request...
1041 StrictMock<MockCertIssuerSourceRequest>* target_issuers_req = 1044 StrictMock<MockCertIssuerSourceRequest>* target_issuers_req =
1042 target_issuers_req_owner.get(); 1045 target_issuers_req_owner.get();
1043 // Setup helper class to pass ownership of the Request to the PathBuilder when 1046 // Setup helper class to pass ownership of the Request to the PathBuilder when
1044 // it calls AsyncGetIssuersOf. 1047 // it calls AsyncGetIssuersOf.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 const auto& path1 = result.paths[1]->path; 1107 const auto& path1 = result.paths[1]->path;
1105 ASSERT_EQ(2U, path1.certs.size()); 1108 ASSERT_EQ(2U, path1.certs.size());
1106 EXPECT_EQ(target_, path1.certs[0]); 1109 EXPECT_EQ(target_, path1.certs[0]);
1107 EXPECT_EQ(newintermediate_, path1.certs[1]); 1110 EXPECT_EQ(newintermediate_, path1.certs[1]);
1108 EXPECT_EQ(newroot_, path1.trust_anchor->cert()); 1111 EXPECT_EQ(newroot_, path1.trust_anchor->cert());
1109 } 1112 }
1110 1113
1111 } // namespace 1114 } // namespace
1112 1115
1113 } // namespace net 1116 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698