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

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

Issue 2898303005: Wire up certificate policies support in PathBuilder. (Closed)
Patch Set: rebase Created 3 years, 6 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 ASSERT_TRUE(ReadTestCert("multi-root-E-by-E.pem", &e_by_e_)); 128 ASSERT_TRUE(ReadTestCert("multi-root-E-by-E.pem", &e_by_e_));
129 ASSERT_TRUE(ReadTestCert("multi-root-F-by-E.pem", &f_by_e_)); 129 ASSERT_TRUE(ReadTestCert("multi-root-F-by-E.pem", &f_by_e_));
130 } 130 }
131 131
132 protected: 132 protected:
133 scoped_refptr<ParsedCertificate> a_by_b_, b_by_c_, b_by_f_, c_by_d_, c_by_e_, 133 scoped_refptr<ParsedCertificate> a_by_b_, b_by_c_, b_by_f_, c_by_d_, c_by_e_,
134 d_by_d_, e_by_e_, f_by_e_; 134 d_by_d_, e_by_e_, f_by_e_;
135 135
136 SimpleSignaturePolicy signature_policy_; 136 SimpleSignaturePolicy signature_policy_;
137 der::GeneralizedTime time_ = {2017, 3, 1, 0, 0, 0}; 137 der::GeneralizedTime time_ = {2017, 3, 1, 0, 0, 0};
138
139 const InitialExplicitPolicy initial_explicit_policy_ =
140 InitialExplicitPolicy::kFalse;
141 const std::set<der::Input> user_initial_policy_set_ = {AnyPolicy()};
142 const InitialPolicyMappingInhibit initial_policy_mapping_inhibit_ =
143 InitialPolicyMappingInhibit::kFalse;
144 const InitialAnyPolicyInhibit initial_any_policy_inhibit_ =
145 InitialAnyPolicyInhibit::kFalse;
138 }; 146 };
139 147
140 // Tests when the target cert has the same name and key as a trust anchor, 148 // Tests when the target cert has the same name and key as a trust anchor,
141 // however is signed by a different trust anchor. This should successfully build 149 // however is signed by a different trust anchor. This should successfully build
142 // a path, however the trust anchor will be the signer of this cert. 150 // a path, however the trust anchor will be the signer of this cert.
143 // 151 //
144 // (This test is very similar to TestEndEntityHasSameNameAndSpkiAsTrustAnchor 152 // (This test is very similar to TestEndEntityHasSameNameAndSpkiAsTrustAnchor
145 // but with different data; also in this test the target cert itself is in the 153 // but with different data; also in this test the target cert itself is in the
146 // trust store). 154 // trust store).
147 TEST_F(PathBuilderMultiRootTest, TargetHasNameAndSpkiOfTrustAnchor) { 155 TEST_F(PathBuilderMultiRootTest, TargetHasNameAndSpkiOfTrustAnchor) {
148 TrustStoreInMemory trust_store; 156 TrustStoreInMemory trust_store;
149 trust_store.AddTrustAnchor(a_by_b_); 157 trust_store.AddTrustAnchor(a_by_b_);
150 trust_store.AddTrustAnchor(b_by_f_); 158 trust_store.AddTrustAnchor(b_by_f_);
151 159
152 CertPathBuilder::Result result; 160 CertPathBuilder::Result result;
153 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 161 CertPathBuilder path_builder(
154 KeyPurpose::ANY_EKU, &result); 162 a_by_b_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
163 initial_explicit_policy_, user_initial_policy_set_,
164 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
155 165
156 path_builder.Run(); 166 path_builder.Run();
157 167
158 ASSERT_FALSE(result.HasValidPath()); 168 ASSERT_FALSE(result.HasValidPath());
159 169
160 // TODO(eroman): This probably should have succeeded and found the path below. 170 // TODO(eroman): This probably should have succeeded and found the path below.
161 // It fails right now because path building stops on trust anchors (and the 171 // It fails right now because path building stops on trust anchors (and the
162 // end entity is added as a trust anchor). 172 // end entity is added as a trust anchor).
163 // 173 //
164 // const auto& path = result.GetBestValidPath()->path; 174 // const auto& path = result.GetBestValidPath()->path;
165 // ASSERT_EQ(2U, path.certs.size()); 175 // ASSERT_EQ(2U, path.certs.size());
166 // EXPECT_EQ(a_by_b_, path.certs[0]); 176 // EXPECT_EQ(a_by_b_, path.certs[0]);
167 // EXPECT_EQ(b_by_f_, path.certs[1]); 177 // EXPECT_EQ(b_by_f_, path.certs[1]);
168 } 178 }
169 179
170 // If the target cert is has the same name and key as a trust anchor, however 180 // If the target cert is has the same name and key as a trust anchor, however
171 // is NOT itself signed by a trust anchor, it fails. Although the provided SPKI 181 // is NOT itself signed by a trust anchor, it fails. Although the provided SPKI
172 // is trusted, the certificate contents cannot be verified. 182 // is trusted, the certificate contents cannot be verified.
173 TEST_F(PathBuilderMultiRootTest, TargetWithSameNameAsTrustAnchorFails) { 183 TEST_F(PathBuilderMultiRootTest, TargetWithSameNameAsTrustAnchorFails) {
174 TrustStoreInMemory trust_store; 184 TrustStoreInMemory trust_store;
175 trust_store.AddTrustAnchor(a_by_b_); 185 trust_store.AddTrustAnchor(a_by_b_);
176 186
177 CertPathBuilder::Result result; 187 CertPathBuilder::Result result;
178 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 188 CertPathBuilder path_builder(
179 KeyPurpose::ANY_EKU, &result); 189 a_by_b_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
190 initial_explicit_policy_, user_initial_policy_set_,
191 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
180 192
181 path_builder.Run(); 193 path_builder.Run();
182 194
183 EXPECT_FALSE(result.HasValidPath()); 195 EXPECT_FALSE(result.HasValidPath());
184 } 196 }
185 197
186 // Test a failed path building when the trust anchor is provided as a 198 // Test a failed path building when the trust anchor is provided as a
187 // supplemental certificate. Conceptually the following paths could be built: 199 // supplemental certificate. Conceptually the following paths could be built:
188 // 200 //
189 // B(C) <- C(D) <- [Trust anchor D] 201 // B(C) <- C(D) <- [Trust anchor D]
190 // B(C) <- C(D) <- D(D) <- [Trust anchor D] 202 // B(C) <- C(D) <- D(D) <- [Trust anchor D]
191 // 203 //
192 // However the second one is extraneous given the shorter path. 204 // However the second one is extraneous given the shorter path.
193 TEST_F(PathBuilderMultiRootTest, SelfSignedTrustAnchorSupplementalCert) { 205 TEST_F(PathBuilderMultiRootTest, SelfSignedTrustAnchorSupplementalCert) {
194 TrustStoreInMemory trust_store; 206 TrustStoreInMemory trust_store;
195 trust_store.AddTrustAnchor(d_by_d_); 207 trust_store.AddTrustAnchor(d_by_d_);
196 208
197 // The (extraneous) trust anchor D(D) is supplied as a certificate, as is the 209 // The (extraneous) trust anchor D(D) is supplied as a certificate, as is the
198 // intermediate needed for path building C(D). 210 // intermediate needed for path building C(D).
199 CertIssuerSourceStatic sync_certs; 211 CertIssuerSourceStatic sync_certs;
200 sync_certs.AddCert(d_by_d_); 212 sync_certs.AddCert(d_by_d_);
201 sync_certs.AddCert(c_by_d_); 213 sync_certs.AddCert(c_by_d_);
202 214
203 // C(D) is not valid at this time, so path building will fail. 215 // C(D) is not valid at this time, so path building will fail.
204 der::GeneralizedTime expired_time = {2016, 1, 1, 0, 0, 0}; 216 der::GeneralizedTime expired_time = {2016, 1, 1, 0, 0, 0};
205 217
206 CertPathBuilder::Result result; 218 CertPathBuilder::Result result;
207 CertPathBuilder path_builder(b_by_c_, &trust_store, &signature_policy_, 219 CertPathBuilder path_builder(
208 expired_time, KeyPurpose::ANY_EKU, &result); 220 b_by_c_, &trust_store, &signature_policy_, expired_time,
221 KeyPurpose::ANY_EKU, initial_explicit_policy_, user_initial_policy_set_,
222 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
209 path_builder.AddCertIssuerSource(&sync_certs); 223 path_builder.AddCertIssuerSource(&sync_certs);
210 224
211 path_builder.Run(); 225 path_builder.Run();
212 226
213 EXPECT_FALSE(result.HasValidPath()); 227 EXPECT_FALSE(result.HasValidPath());
214 ASSERT_EQ(1U, result.paths.size()); 228 ASSERT_EQ(1U, result.paths.size());
215 229
216 EXPECT_FALSE(result.paths[0]->IsValid()); 230 EXPECT_FALSE(result.paths[0]->IsValid());
217 const auto& path0 = result.paths[0]->path; 231 const auto& path0 = result.paths[0]->path;
218 ASSERT_EQ(3U, path0.certs.size()); 232 ASSERT_EQ(3U, path0.certs.size());
219 EXPECT_EQ(b_by_c_, path0.certs[0]); 233 EXPECT_EQ(b_by_c_, path0.certs[0]);
220 EXPECT_EQ(c_by_d_, path0.certs[1]); 234 EXPECT_EQ(c_by_d_, path0.certs[1]);
221 EXPECT_EQ(d_by_d_, path0.certs[2]); 235 EXPECT_EQ(d_by_d_, path0.certs[2]);
222 } 236 }
223 237
224 // Test verifying a certificate that is a trust anchor. 238 // Test verifying a certificate that is a trust anchor.
225 TEST_F(PathBuilderMultiRootTest, TargetIsSelfSignedTrustAnchor) { 239 TEST_F(PathBuilderMultiRootTest, TargetIsSelfSignedTrustAnchor) {
226 TrustStoreInMemory trust_store; 240 TrustStoreInMemory trust_store;
227 trust_store.AddTrustAnchor(e_by_e_); 241 trust_store.AddTrustAnchor(e_by_e_);
228 // This is not necessary for the test, just an extra... 242 // This is not necessary for the test, just an extra...
229 trust_store.AddTrustAnchor(f_by_e_); 243 trust_store.AddTrustAnchor(f_by_e_);
230 244
231 CertPathBuilder::Result result; 245 CertPathBuilder::Result result;
232 CertPathBuilder path_builder(e_by_e_, &trust_store, &signature_policy_, time_, 246 CertPathBuilder path_builder(
233 KeyPurpose::ANY_EKU, &result); 247 e_by_e_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
248 initial_explicit_policy_, user_initial_policy_set_,
249 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
234 250
235 path_builder.Run(); 251 path_builder.Run();
236 252
237 ASSERT_FALSE(result.HasValidPath()); 253 ASSERT_FALSE(result.HasValidPath());
238 254
239 // TODO(eroman): This test currently fails because path building stops 255 // TODO(eroman): This test currently fails because path building stops
240 // searching once it identifies a certificate as a trust anchor. In this case 256 // searching once it identifies a certificate as a trust anchor. In this case
241 // the target is a trust anchor, however could be verified using the 257 // the target is a trust anchor, however could be verified using the
242 // self-signedness (or even the cert itself). 258 // self-signedness (or even the cert itself).
243 // const auto& path = result.GetBestValidPath()->path; 259 // const auto& path = result.GetBestValidPath()->path;
244 // ASSERT_EQ(2U, path.certs.size()); 260 // ASSERT_EQ(2U, path.certs.size());
245 // EXPECT_EQ(e_by_e_, path.certs[0]); 261 // EXPECT_EQ(e_by_e_, path.certs[0]);
246 // EXPECT_EQ(e_by_e_, path.certs[1]); 262 // EXPECT_EQ(e_by_e_, path.certs[1]);
247 } 263 }
248 264
249 // If the target cert is directly issued by a trust anchor, it should verify 265 // If the target cert is directly issued by a trust anchor, it should verify
250 // without any intermediate certs being provided. 266 // without any intermediate certs being provided.
251 TEST_F(PathBuilderMultiRootTest, TargetDirectlySignedByTrustAnchor) { 267 TEST_F(PathBuilderMultiRootTest, TargetDirectlySignedByTrustAnchor) {
252 TrustStoreInMemory trust_store; 268 TrustStoreInMemory trust_store;
253 trust_store.AddTrustAnchor(b_by_f_); 269 trust_store.AddTrustAnchor(b_by_f_);
254 270
255 CertPathBuilder::Result result; 271 CertPathBuilder::Result result;
256 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 272 CertPathBuilder path_builder(
257 KeyPurpose::ANY_EKU, &result); 273 a_by_b_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
274 initial_explicit_policy_, user_initial_policy_set_,
275 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
258 276
259 path_builder.Run(); 277 path_builder.Run();
260 278
261 ASSERT_TRUE(result.HasValidPath()); 279 ASSERT_TRUE(result.HasValidPath());
262 const auto& path = result.GetBestValidPath()->path; 280 const auto& path = result.GetBestValidPath()->path;
263 ASSERT_EQ(2U, path.certs.size()); 281 ASSERT_EQ(2U, path.certs.size());
264 EXPECT_EQ(a_by_b_, path.certs[0]); 282 EXPECT_EQ(a_by_b_, path.certs[0]);
265 EXPECT_EQ(b_by_f_, path.certs[1]); 283 EXPECT_EQ(b_by_f_, path.certs[1]);
266 } 284 }
267 285
268 // Test that async cert queries are not made if the path can be successfully 286 // Test that async cert queries are not made if the path can be successfully
269 // built with synchronously available certs. 287 // built with synchronously available certs.
270 TEST_F(PathBuilderMultiRootTest, TriesSyncFirst) { 288 TEST_F(PathBuilderMultiRootTest, TriesSyncFirst) {
271 TrustStoreInMemory trust_store; 289 TrustStoreInMemory trust_store;
272 trust_store.AddTrustAnchor(e_by_e_); 290 trust_store.AddTrustAnchor(e_by_e_);
273 291
274 CertIssuerSourceStatic sync_certs; 292 CertIssuerSourceStatic sync_certs;
275 sync_certs.AddCert(b_by_f_); 293 sync_certs.AddCert(b_by_f_);
276 sync_certs.AddCert(f_by_e_); 294 sync_certs.AddCert(f_by_e_);
277 295
278 AsyncCertIssuerSourceStatic async_certs; 296 AsyncCertIssuerSourceStatic async_certs;
279 async_certs.AddCert(b_by_c_); 297 async_certs.AddCert(b_by_c_);
280 async_certs.AddCert(c_by_e_); 298 async_certs.AddCert(c_by_e_);
281 299
282 CertPathBuilder::Result result; 300 CertPathBuilder::Result result;
283 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 301 CertPathBuilder path_builder(
284 KeyPurpose::ANY_EKU, &result); 302 a_by_b_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
303 initial_explicit_policy_, user_initial_policy_set_,
304 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
285 path_builder.AddCertIssuerSource(&async_certs); 305 path_builder.AddCertIssuerSource(&async_certs);
286 path_builder.AddCertIssuerSource(&sync_certs); 306 path_builder.AddCertIssuerSource(&sync_certs);
287 307
288 path_builder.Run(); 308 path_builder.Run();
289 309
290 EXPECT_TRUE(result.HasValidPath()); 310 EXPECT_TRUE(result.HasValidPath());
291 EXPECT_EQ(0, async_certs.num_async_gets()); 311 EXPECT_EQ(0, async_certs.num_async_gets());
292 } 312 }
293 313
294 // If async queries are needed, all async sources will be queried 314 // If async queries are needed, all async sources will be queried
295 // simultaneously. 315 // simultaneously.
296 TEST_F(PathBuilderMultiRootTest, TestAsyncSimultaneous) { 316 TEST_F(PathBuilderMultiRootTest, TestAsyncSimultaneous) {
297 TrustStoreInMemory trust_store; 317 TrustStoreInMemory trust_store;
298 trust_store.AddTrustAnchor(e_by_e_); 318 trust_store.AddTrustAnchor(e_by_e_);
299 319
300 CertIssuerSourceStatic sync_certs; 320 CertIssuerSourceStatic sync_certs;
301 sync_certs.AddCert(b_by_c_); 321 sync_certs.AddCert(b_by_c_);
302 sync_certs.AddCert(b_by_f_); 322 sync_certs.AddCert(b_by_f_);
303 323
304 AsyncCertIssuerSourceStatic async_certs1; 324 AsyncCertIssuerSourceStatic async_certs1;
305 async_certs1.AddCert(c_by_e_); 325 async_certs1.AddCert(c_by_e_);
306 326
307 AsyncCertIssuerSourceStatic async_certs2; 327 AsyncCertIssuerSourceStatic async_certs2;
308 async_certs2.AddCert(f_by_e_); 328 async_certs2.AddCert(f_by_e_);
309 329
310 CertPathBuilder::Result result; 330 CertPathBuilder::Result result;
311 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 331 CertPathBuilder path_builder(
312 KeyPurpose::ANY_EKU, &result); 332 a_by_b_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
333 initial_explicit_policy_, user_initial_policy_set_,
334 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
313 path_builder.AddCertIssuerSource(&async_certs1); 335 path_builder.AddCertIssuerSource(&async_certs1);
314 path_builder.AddCertIssuerSource(&async_certs2); 336 path_builder.AddCertIssuerSource(&async_certs2);
315 path_builder.AddCertIssuerSource(&sync_certs); 337 path_builder.AddCertIssuerSource(&sync_certs);
316 338
317 path_builder.Run(); 339 path_builder.Run();
318 340
319 EXPECT_TRUE(result.HasValidPath()); 341 EXPECT_TRUE(result.HasValidPath());
320 EXPECT_EQ(1, async_certs1.num_async_gets()); 342 EXPECT_EQ(1, async_certs1.num_async_gets());
321 EXPECT_EQ(1, async_certs2.num_async_gets()); 343 EXPECT_EQ(1, async_certs2.num_async_gets());
322 } 344 }
323 345
324 // Test that PathBuilder does not generate longer paths than necessary if one of 346 // Test that PathBuilder does not generate longer paths than necessary if one of
325 // the supplied certs is itself a trust anchor. 347 // the supplied certs is itself a trust anchor.
326 TEST_F(PathBuilderMultiRootTest, TestLongChain) { 348 TEST_F(PathBuilderMultiRootTest, TestLongChain) {
327 // Both D(D) and C(D) are trusted roots. 349 // Both D(D) and C(D) are trusted roots.
328 TrustStoreInMemory trust_store; 350 TrustStoreInMemory trust_store;
329 trust_store.AddTrustAnchor(d_by_d_); 351 trust_store.AddTrustAnchor(d_by_d_);
330 trust_store.AddTrustAnchor(c_by_d_); 352 trust_store.AddTrustAnchor(c_by_d_);
331 353
332 // Certs B(C), and C(D) are all supplied. 354 // Certs B(C), and C(D) are all supplied.
333 CertIssuerSourceStatic sync_certs; 355 CertIssuerSourceStatic sync_certs;
334 sync_certs.AddCert(b_by_c_); 356 sync_certs.AddCert(b_by_c_);
335 sync_certs.AddCert(c_by_d_); 357 sync_certs.AddCert(c_by_d_);
336 358
337 CertPathBuilder::Result result; 359 CertPathBuilder::Result result;
338 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 360 CertPathBuilder path_builder(
339 KeyPurpose::ANY_EKU, &result); 361 a_by_b_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
362 initial_explicit_policy_, user_initial_policy_set_,
363 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
340 path_builder.AddCertIssuerSource(&sync_certs); 364 path_builder.AddCertIssuerSource(&sync_certs);
341 365
342 path_builder.Run(); 366 path_builder.Run();
343 367
344 ASSERT_TRUE(result.HasValidPath()); 368 ASSERT_TRUE(result.HasValidPath());
345 369
346 // The result path should be A(B) <- B(C) <- C(D) 370 // The result path should be A(B) <- B(C) <- C(D)
347 // not the longer but also valid A(B) <- B(C) <- C(D) <- D(D) 371 // not the longer but also valid A(B) <- B(C) <- C(D) <- D(D)
348 EXPECT_EQ(3U, result.GetBestValidPath()->path.certs.size()); 372 EXPECT_EQ(3U, result.GetBestValidPath()->path.certs.size());
349 } 373 }
(...skipping 11 matching lines...) Expand all
361 sync_certs.AddCert(b_by_f_); 385 sync_certs.AddCert(b_by_f_);
362 sync_certs.AddCert(f_by_e_); 386 sync_certs.AddCert(f_by_e_);
363 387
364 // Certs B(C), and C(D) are supplied asynchronously, so the path 388 // Certs B(C), and C(D) are supplied asynchronously, so the path
365 // A(B) <- B(C) <- C(D) <- D(D) should be tried second. 389 // A(B) <- B(C) <- C(D) <- D(D) should be tried second.
366 AsyncCertIssuerSourceStatic async_certs; 390 AsyncCertIssuerSourceStatic async_certs;
367 async_certs.AddCert(b_by_c_); 391 async_certs.AddCert(b_by_c_);
368 async_certs.AddCert(c_by_d_); 392 async_certs.AddCert(c_by_d_);
369 393
370 CertPathBuilder::Result result; 394 CertPathBuilder::Result result;
371 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, time_, 395 CertPathBuilder path_builder(
372 KeyPurpose::ANY_EKU, &result); 396 a_by_b_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
397 initial_explicit_policy_, user_initial_policy_set_,
398 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
373 path_builder.AddCertIssuerSource(&sync_certs); 399 path_builder.AddCertIssuerSource(&sync_certs);
374 path_builder.AddCertIssuerSource(&async_certs); 400 path_builder.AddCertIssuerSource(&async_certs);
375 401
376 path_builder.Run(); 402 path_builder.Run();
377 403
378 ASSERT_TRUE(result.HasValidPath()); 404 ASSERT_TRUE(result.HasValidPath());
379 405
380 // The result path should be A(B) <- B(C) <- C(D) <- D(D) 406 // The result path should be A(B) <- B(C) <- C(D) <- D(D)
381 const auto& path = result.GetBestValidPath()->path; 407 const auto& path = result.GetBestValidPath()->path;
382 ASSERT_EQ(4U, path.certs.size()); 408 ASSERT_EQ(4U, path.certs.size());
(...skipping 17 matching lines...) Expand all
400 CertIssuerSourceStatic sync_certs; 426 CertIssuerSourceStatic sync_certs;
401 if (reverse_order) { 427 if (reverse_order) {
402 for (auto it = certs.rbegin(); it != certs.rend(); ++it) 428 for (auto it = certs.rbegin(); it != certs.rend(); ++it)
403 sync_certs.AddCert(*it); 429 sync_certs.AddCert(*it);
404 } else { 430 } else {
405 for (const auto& cert : certs) 431 for (const auto& cert : certs)
406 sync_certs.AddCert(cert); 432 sync_certs.AddCert(cert);
407 } 433 }
408 434
409 CertPathBuilder::Result result; 435 CertPathBuilder::Result result;
410 CertPathBuilder path_builder(a_by_b_, &trust_store, &signature_policy_, 436 CertPathBuilder path_builder(
411 time_, KeyPurpose::ANY_EKU, &result); 437 a_by_b_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
438 initial_explicit_policy_, user_initial_policy_set_,
439 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
412 path_builder.AddCertIssuerSource(&sync_certs); 440 path_builder.AddCertIssuerSource(&sync_certs);
413 441
414 path_builder.Run(); 442 path_builder.Run();
415 443
416 ASSERT_TRUE(result.HasValidPath()); 444 ASSERT_TRUE(result.HasValidPath());
417 445
418 // The result path should be A(B) <- B(C) <- C(D) <- D(D) 446 // The result path should be A(B) <- B(C) <- C(D) <- D(D)
419 const auto& path = result.GetBestValidPath()->path; 447 const auto& path = result.GetBestValidPath()->path;
420 ASSERT_EQ(4U, path.certs.size()); 448 ASSERT_EQ(4U, path.certs.size());
421 EXPECT_EQ(a_by_b_, path.certs[0]); 449 EXPECT_EQ(a_by_b_, path.certs[0]);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // target 501 // target
474 scoped_refptr<ParsedCertificate> target_; 502 scoped_refptr<ParsedCertificate> target_;
475 scoped_refptr<ParsedCertificate> oldintermediate_; 503 scoped_refptr<ParsedCertificate> oldintermediate_;
476 scoped_refptr<ParsedCertificate> newintermediate_; 504 scoped_refptr<ParsedCertificate> newintermediate_;
477 scoped_refptr<ParsedCertificate> oldroot_; 505 scoped_refptr<ParsedCertificate> oldroot_;
478 scoped_refptr<ParsedCertificate> newroot_; 506 scoped_refptr<ParsedCertificate> newroot_;
479 scoped_refptr<ParsedCertificate> newrootrollover_; 507 scoped_refptr<ParsedCertificate> newrootrollover_;
480 508
481 SimpleSignaturePolicy signature_policy_; 509 SimpleSignaturePolicy signature_policy_;
482 der::GeneralizedTime time_; 510 der::GeneralizedTime time_;
511
512 const InitialExplicitPolicy initial_explicit_policy_ =
513 InitialExplicitPolicy::kFalse;
514 const std::set<der::Input> user_initial_policy_set_ = {AnyPolicy()};
515 const InitialPolicyMappingInhibit initial_policy_mapping_inhibit_ =
516 InitialPolicyMappingInhibit::kFalse;
517 const InitialAnyPolicyInhibit initial_any_policy_inhibit_ =
518 InitialAnyPolicyInhibit::kFalse;
483 }; 519 };
484 520
485 // Tests that if only the old root cert is trusted, the path builder can build a 521 // Tests that if only the old root cert is trusted, the path builder can build a
486 // path through the new intermediate and rollover cert to the old root. 522 // path through the new intermediate and rollover cert to the old root.
487 TEST_F(PathBuilderKeyRolloverTest, TestRolloverOnlyOldRootTrusted) { 523 TEST_F(PathBuilderKeyRolloverTest, TestRolloverOnlyOldRootTrusted) {
488 // Only oldroot is trusted. 524 // Only oldroot is trusted.
489 TrustStoreInMemory trust_store; 525 TrustStoreInMemory trust_store;
490 trust_store.AddTrustAnchor(oldroot_); 526 trust_store.AddTrustAnchor(oldroot_);
491 527
492 // Old intermediate cert is not provided, so the pathbuilder will need to go 528 // Old intermediate cert is not provided, so the pathbuilder will need to go
493 // through the rollover cert. 529 // through the rollover cert.
494 CertIssuerSourceStatic sync_certs; 530 CertIssuerSourceStatic sync_certs;
495 sync_certs.AddCert(newintermediate_); 531 sync_certs.AddCert(newintermediate_);
496 sync_certs.AddCert(newrootrollover_); 532 sync_certs.AddCert(newrootrollover_);
497 533
498 CertPathBuilder::Result result; 534 CertPathBuilder::Result result;
499 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 535 CertPathBuilder path_builder(
500 KeyPurpose::ANY_EKU, &result); 536 target_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
537 initial_explicit_policy_, user_initial_policy_set_,
538 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
501 path_builder.AddCertIssuerSource(&sync_certs); 539 path_builder.AddCertIssuerSource(&sync_certs);
502 540
503 path_builder.Run(); 541 path_builder.Run();
504 542
505 EXPECT_TRUE(result.HasValidPath()); 543 EXPECT_TRUE(result.HasValidPath());
506 544
507 // Path builder will first attempt: target <- newintermediate <- oldroot 545 // Path builder will first attempt: target <- newintermediate <- oldroot
508 // but it will fail since newintermediate is signed by newroot. 546 // but it will fail since newintermediate is signed by newroot.
509 ASSERT_EQ(2U, result.paths.size()); 547 ASSERT_EQ(2U, result.paths.size());
510 const auto& path0 = result.paths[0]->path; 548 const auto& path0 = result.paths[0]->path;
(...skipping 26 matching lines...) Expand all
537 trust_store.AddTrustAnchor(oldroot_); 575 trust_store.AddTrustAnchor(oldroot_);
538 trust_store.AddTrustAnchor(newroot_); 576 trust_store.AddTrustAnchor(newroot_);
539 577
540 // Both old and new intermediates + rollover cert are provided. 578 // Both old and new intermediates + rollover cert are provided.
541 CertIssuerSourceStatic sync_certs; 579 CertIssuerSourceStatic sync_certs;
542 sync_certs.AddCert(oldintermediate_); 580 sync_certs.AddCert(oldintermediate_);
543 sync_certs.AddCert(newintermediate_); 581 sync_certs.AddCert(newintermediate_);
544 sync_certs.AddCert(newrootrollover_); 582 sync_certs.AddCert(newrootrollover_);
545 583
546 CertPathBuilder::Result result; 584 CertPathBuilder::Result result;
547 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 585 CertPathBuilder path_builder(
548 KeyPurpose::ANY_EKU, &result); 586 target_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
587 initial_explicit_policy_, user_initial_policy_set_,
588 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
549 path_builder.AddCertIssuerSource(&sync_certs); 589 path_builder.AddCertIssuerSource(&sync_certs);
550 590
551 path_builder.Run(); 591 path_builder.Run();
552 592
553 EXPECT_TRUE(result.HasValidPath()); 593 EXPECT_TRUE(result.HasValidPath());
554 594
555 // Path builder willattempt one of: 595 // Path builder willattempt one of:
556 // target <- oldintermediate <- oldroot 596 // target <- oldintermediate <- oldroot
557 // target <- newintermediate <- newroot 597 // target <- newintermediate <- newroot
558 // either will succeed. 598 // either will succeed.
(...skipping 13 matching lines...) Expand all
572 } 612 }
573 } 613 }
574 614
575 // If trust anchor query returned no results, and there are no issuer 615 // If trust anchor query returned no results, and there are no issuer
576 // sources, path building should fail at that point. 616 // sources, path building should fail at that point.
577 TEST_F(PathBuilderKeyRolloverTest, TestAnchorsNoMatchAndNoIssuerSources) { 617 TEST_F(PathBuilderKeyRolloverTest, TestAnchorsNoMatchAndNoIssuerSources) {
578 TrustStoreInMemory trust_store; 618 TrustStoreInMemory trust_store;
579 trust_store.AddTrustAnchor(newroot_); 619 trust_store.AddTrustAnchor(newroot_);
580 620
581 CertPathBuilder::Result result; 621 CertPathBuilder::Result result;
582 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 622 CertPathBuilder path_builder(
583 KeyPurpose::ANY_EKU, &result); 623 target_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
624 initial_explicit_policy_, user_initial_policy_set_,
625 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
584 626
585 path_builder.Run(); 627 path_builder.Run();
586 628
587 EXPECT_FALSE(result.HasValidPath()); 629 EXPECT_FALSE(result.HasValidPath());
588 630
589 ASSERT_EQ(0U, result.paths.size()); 631 ASSERT_EQ(0U, result.paths.size());
590 } 632 }
591 633
592 // Tests that multiple trust root matches on a single path will be considered. 634 // Tests that multiple trust root matches on a single path will be considered.
593 // Both roots have the same subject but different keys. Only one of them will 635 // Both roots have the same subject but different keys. Only one of them will
594 // verify. 636 // verify.
595 TEST_F(PathBuilderKeyRolloverTest, TestMultipleRootMatchesOnlyOneWorks) { 637 TEST_F(PathBuilderKeyRolloverTest, TestMultipleRootMatchesOnlyOneWorks) {
596 TrustStoreCollection trust_store_collection; 638 TrustStoreCollection trust_store_collection;
597 TrustStoreInMemory trust_store1; 639 TrustStoreInMemory trust_store1;
598 TrustStoreInMemory trust_store2; 640 TrustStoreInMemory trust_store2;
599 trust_store_collection.AddTrustStore(&trust_store1); 641 trust_store_collection.AddTrustStore(&trust_store1);
600 trust_store_collection.AddTrustStore(&trust_store2); 642 trust_store_collection.AddTrustStore(&trust_store2);
601 // Add two trust anchors (newroot_ and oldroot_). Path building will attempt 643 // Add two trust anchors (newroot_ and oldroot_). Path building will attempt
602 // them in this same order, as trust_store1 was added to 644 // them in this same order, as trust_store1 was added to
603 // trust_store_collection first. 645 // trust_store_collection first.
604 trust_store1.AddTrustAnchor(newroot_); 646 trust_store1.AddTrustAnchor(newroot_);
605 trust_store2.AddTrustAnchor(oldroot_); 647 trust_store2.AddTrustAnchor(oldroot_);
606 648
607 // Only oldintermediate is supplied, so the path with newroot should fail, 649 // Only oldintermediate is supplied, so the path with newroot should fail,
608 // oldroot should succeed. 650 // oldroot should succeed.
609 CertIssuerSourceStatic sync_certs; 651 CertIssuerSourceStatic sync_certs;
610 sync_certs.AddCert(oldintermediate_); 652 sync_certs.AddCert(oldintermediate_);
611 653
612 CertPathBuilder::Result result; 654 CertPathBuilder::Result result;
613 CertPathBuilder path_builder(target_, &trust_store_collection, 655 CertPathBuilder path_builder(
614 &signature_policy_, time_, KeyPurpose::ANY_EKU, 656 target_, &trust_store_collection, &signature_policy_, time_,
615 &result); 657 KeyPurpose::ANY_EKU, initial_explicit_policy_, user_initial_policy_set_,
658 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_,
659
mattm 2017/06/02 02:54:49 extra line
eroman 2017/06/02 17:58:59 Done.
660 &result);
616 path_builder.AddCertIssuerSource(&sync_certs); 661 path_builder.AddCertIssuerSource(&sync_certs);
617 662
618 path_builder.Run(); 663 path_builder.Run();
619 664
620 EXPECT_TRUE(result.HasValidPath()); 665 EXPECT_TRUE(result.HasValidPath());
621 ASSERT_EQ(2U, result.paths.size()); 666 ASSERT_EQ(2U, result.paths.size());
622 667
623 { 668 {
624 // Path builder may first attempt: target <- oldintermediate <- newroot 669 // Path builder may first attempt: target <- oldintermediate <- newroot
625 // but it will fail since oldintermediate is signed by oldroot. 670 // but it will fail since oldintermediate is signed by oldroot.
(...skipping 28 matching lines...) Expand all
654 CertIssuerSourceStatic sync_certs; 699 CertIssuerSourceStatic sync_certs;
655 sync_certs.AddCert(newintermediate_); 700 sync_certs.AddCert(newintermediate_);
656 sync_certs.AddCert(newroot_); 701 sync_certs.AddCert(newroot_);
657 702
658 // Rollover cert is only provided asynchronously. This will force the 703 // Rollover cert is only provided asynchronously. This will force the
659 // pathbuilder to first try building a longer than necessary path. 704 // pathbuilder to first try building a longer than necessary path.
660 AsyncCertIssuerSourceStatic async_certs; 705 AsyncCertIssuerSourceStatic async_certs;
661 async_certs.AddCert(newrootrollover_); 706 async_certs.AddCert(newrootrollover_);
662 707
663 CertPathBuilder::Result result; 708 CertPathBuilder::Result result;
664 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 709 CertPathBuilder path_builder(
665 KeyPurpose::ANY_EKU, &result); 710 target_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
711 initial_explicit_policy_, user_initial_policy_set_,
712 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
666 path_builder.AddCertIssuerSource(&sync_certs); 713 path_builder.AddCertIssuerSource(&sync_certs);
667 path_builder.AddCertIssuerSource(&async_certs); 714 path_builder.AddCertIssuerSource(&async_certs);
668 715
669 path_builder.Run(); 716 path_builder.Run();
670 717
671 EXPECT_TRUE(result.HasValidPath()); 718 EXPECT_TRUE(result.HasValidPath());
672 ASSERT_EQ(3U, result.paths.size()); 719 ASSERT_EQ(3U, result.paths.size());
673 720
674 // Path builder will first attempt: target <- newintermediate <- oldroot 721 // Path builder will first attempt: target <- newintermediate <- oldroot
675 // but it will fail since newintermediate is signed by newroot. 722 // but it will fail since newintermediate is signed by newroot.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 // trust anchor, then it is not considered valid (the SPKI and name of the 758 // trust anchor, then it is not considered valid (the SPKI and name of the
712 // trust anchor matches the SPKI and subject of the targe certificate, but the 759 // trust anchor matches the SPKI and subject of the targe certificate, but the
713 // rest of the certificate cannot be verified). 760 // rest of the certificate cannot be verified).
714 TEST_F(PathBuilderKeyRolloverTest, TestEndEntityIsTrustRoot) { 761 TEST_F(PathBuilderKeyRolloverTest, TestEndEntityIsTrustRoot) {
715 // Trust newintermediate. 762 // Trust newintermediate.
716 TrustStoreInMemory trust_store; 763 TrustStoreInMemory trust_store;
717 trust_store.AddTrustAnchor(newintermediate_); 764 trust_store.AddTrustAnchor(newintermediate_);
718 765
719 CertPathBuilder::Result result; 766 CertPathBuilder::Result result;
720 // Newintermediate is also the target cert. 767 // Newintermediate is also the target cert.
721 CertPathBuilder path_builder(newintermediate_, &trust_store, 768 CertPathBuilder path_builder(
722 &signature_policy_, time_, KeyPurpose::ANY_EKU, 769 newintermediate_, &trust_store, &signature_policy_, time_,
723 &result); 770 KeyPurpose::ANY_EKU, initial_explicit_policy_, user_initial_policy_set_,
771 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
724 772
725 path_builder.Run(); 773 path_builder.Run();
726 774
727 EXPECT_FALSE(result.HasValidPath()); 775 EXPECT_FALSE(result.HasValidPath());
728 } 776 }
729 777
730 // If target has same Name+SAN+SPKI as a necessary intermediate, test if a path 778 // If target has same Name+SAN+SPKI as a necessary intermediate, test if a path
731 // can still be built. 779 // can still be built.
732 // Since LoopChecker will prevent the intermediate from being included, this 780 // Since LoopChecker will prevent the intermediate from being included, this
733 // currently does NOT verify. This case shouldn't occur in the web PKI. 781 // currently does NOT verify. This case shouldn't occur in the web PKI.
734 TEST_F(PathBuilderKeyRolloverTest, 782 TEST_F(PathBuilderKeyRolloverTest,
735 TestEndEntityHasSameNameAndSpkiAsIntermediate) { 783 TestEndEntityHasSameNameAndSpkiAsIntermediate) {
736 // Trust oldroot. 784 // Trust oldroot.
737 TrustStoreInMemory trust_store; 785 TrustStoreInMemory trust_store;
738 trust_store.AddTrustAnchor(oldroot_); 786 trust_store.AddTrustAnchor(oldroot_);
739 787
740 // New root rollover is provided synchronously. 788 // New root rollover is provided synchronously.
741 CertIssuerSourceStatic sync_certs; 789 CertIssuerSourceStatic sync_certs;
742 sync_certs.AddCert(newrootrollover_); 790 sync_certs.AddCert(newrootrollover_);
743 791
744 CertPathBuilder::Result result; 792 CertPathBuilder::Result result;
745 // Newroot is the target cert. 793 // Newroot is the target cert.
746 CertPathBuilder path_builder(newroot_, &trust_store, &signature_policy_, 794 CertPathBuilder path_builder(
747 time_, KeyPurpose::ANY_EKU, &result); 795 newroot_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
796 initial_explicit_policy_, user_initial_policy_set_,
797 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
748 path_builder.AddCertIssuerSource(&sync_certs); 798 path_builder.AddCertIssuerSource(&sync_certs);
749 799
750 path_builder.Run(); 800 path_builder.Run();
751 801
752 // This could actually be OK, but CertPathBuilder does not build the 802 // This could actually be OK, but CertPathBuilder does not build the
753 // newroot <- newrootrollover <- oldroot path. 803 // newroot <- newrootrollover <- oldroot path.
754 EXPECT_FALSE(result.HasValidPath()); 804 EXPECT_FALSE(result.HasValidPath());
755 } 805 }
756 806
757 // If target has same Name+SAN+SPKI as the trust root, test that a (trivial) 807 // If target has same Name+SAN+SPKI as the trust root, test that a (trivial)
758 // path can still be built. 808 // path can still be built.
759 TEST_F(PathBuilderKeyRolloverTest, 809 TEST_F(PathBuilderKeyRolloverTest,
760 TestEndEntityHasSameNameAndSpkiAsTrustAnchor) { 810 TestEndEntityHasSameNameAndSpkiAsTrustAnchor) {
761 // Trust newrootrollover. 811 // Trust newrootrollover.
762 TrustStoreInMemory trust_store; 812 TrustStoreInMemory trust_store;
763 trust_store.AddTrustAnchor(newrootrollover_); 813 trust_store.AddTrustAnchor(newrootrollover_);
764 814
765 CertPathBuilder::Result result; 815 CertPathBuilder::Result result;
766 // Newroot is the target cert. 816 // Newroot is the target cert.
767 CertPathBuilder path_builder(newroot_, &trust_store, &signature_policy_, 817 CertPathBuilder path_builder(
768 time_, KeyPurpose::ANY_EKU, &result); 818 newroot_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
819 initial_explicit_policy_, user_initial_policy_set_,
820 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
769 821
770 path_builder.Run(); 822 path_builder.Run();
771 823
772 ASSERT_TRUE(result.HasValidPath()); 824 ASSERT_TRUE(result.HasValidPath());
773 825
774 const CertPathBuilder::ResultPath* best_result = result.GetBestValidPath(); 826 const CertPathBuilder::ResultPath* best_result = result.GetBestValidPath();
775 827
776 // Newroot has same name+SPKI as newrootrollover, thus the path is valid and 828 // Newroot has same name+SPKI as newrootrollover, thus the path is valid and
777 // only contains newroot. 829 // only contains newroot.
778 EXPECT_TRUE(best_result->IsValid()); 830 EXPECT_TRUE(best_result->IsValid());
(...skipping 26 matching lines...) Expand all
805 sync_certs1.AddCert(oldintermediate_); 857 sync_certs1.AddCert(oldintermediate_);
806 CertIssuerSourceStatic sync_certs2; 858 CertIssuerSourceStatic sync_certs2;
807 sync_certs2.AddCert(oldintermediate_dupe); 859 sync_certs2.AddCert(oldintermediate_dupe);
808 860
809 // The newintermediate is supplied asynchronously, so the path 861 // The newintermediate is supplied asynchronously, so the path
810 // target <- newintermediate <- newroot should be tried second. 862 // target <- newintermediate <- newroot should be tried second.
811 AsyncCertIssuerSourceStatic async_certs; 863 AsyncCertIssuerSourceStatic async_certs;
812 async_certs.AddCert(newintermediate_); 864 async_certs.AddCert(newintermediate_);
813 865
814 CertPathBuilder::Result result; 866 CertPathBuilder::Result result;
815 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 867 CertPathBuilder path_builder(
816 KeyPurpose::ANY_EKU, &result); 868 target_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
869 initial_explicit_policy_, user_initial_policy_set_,
870 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
817 path_builder.AddCertIssuerSource(&sync_certs1); 871 path_builder.AddCertIssuerSource(&sync_certs1);
818 path_builder.AddCertIssuerSource(&sync_certs2); 872 path_builder.AddCertIssuerSource(&sync_certs2);
819 path_builder.AddCertIssuerSource(&async_certs); 873 path_builder.AddCertIssuerSource(&async_certs);
820 874
821 path_builder.Run(); 875 path_builder.Run();
822 876
823 EXPECT_TRUE(result.HasValidPath()); 877 EXPECT_TRUE(result.HasValidPath());
824 ASSERT_EQ(2U, result.paths.size()); 878 ASSERT_EQ(2U, result.paths.size());
825 879
826 // Path builder will first attempt: target <- oldintermediate <- newroot 880 // Path builder will first attempt: target <- oldintermediate <- newroot
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 // Only newroot is a trusted root. 913 // Only newroot is a trusted root.
860 TrustStoreInMemory trust_store; 914 TrustStoreInMemory trust_store;
861 trust_store.AddTrustAnchor(newroot_); 915 trust_store.AddTrustAnchor(newroot_);
862 916
863 // The oldintermediate and newroot are supplied synchronously by |sync_certs|. 917 // The oldintermediate and newroot are supplied synchronously by |sync_certs|.
864 CertIssuerSourceStatic sync_certs; 918 CertIssuerSourceStatic sync_certs;
865 sync_certs.AddCert(oldintermediate_); 919 sync_certs.AddCert(oldintermediate_);
866 sync_certs.AddCert(newroot_dupe); 920 sync_certs.AddCert(newroot_dupe);
867 921
868 CertPathBuilder::Result result; 922 CertPathBuilder::Result result;
869 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 923 CertPathBuilder path_builder(
870 KeyPurpose::ANY_EKU, &result); 924 target_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
925 initial_explicit_policy_, user_initial_policy_set_,
926 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
871 path_builder.AddCertIssuerSource(&sync_certs); 927 path_builder.AddCertIssuerSource(&sync_certs);
872 928
873 path_builder.Run(); 929 path_builder.Run();
874 930
875 EXPECT_FALSE(result.HasValidPath()); 931 EXPECT_FALSE(result.HasValidPath());
876 ASSERT_EQ(1U, result.paths.size()); 932 ASSERT_EQ(1U, result.paths.size());
877 933
878 // Path builder attempt: target <- oldintermediate <- newroot 934 // Path builder attempt: target <- oldintermediate <- newroot
879 // but it will fail since oldintermediate is signed by oldroot. 935 // but it will fail since oldintermediate is signed by oldroot.
880 EXPECT_FALSE(result.paths[0]->IsValid()); 936 EXPECT_FALSE(result.paths[0]->IsValid());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 // issuers is handled correctly. Due to the StrictMocks, it also tests that path 989 // issuers is handled correctly. Due to the StrictMocks, it also tests that path
934 // builder does not request issuers of certs that it shouldn't. 990 // builder does not request issuers of certs that it shouldn't.
935 TEST_F(PathBuilderKeyRolloverTest, TestMultipleAsyncIssuersFromSingleSource) { 991 TEST_F(PathBuilderKeyRolloverTest, TestMultipleAsyncIssuersFromSingleSource) {
936 StrictMock<MockCertIssuerSource> cert_issuer_source; 992 StrictMock<MockCertIssuerSource> cert_issuer_source;
937 993
938 // Only newroot is a trusted root. 994 // Only newroot is a trusted root.
939 TrustStoreInMemory trust_store; 995 TrustStoreInMemory trust_store;
940 trust_store.AddTrustAnchor(newroot_); 996 trust_store.AddTrustAnchor(newroot_);
941 997
942 CertPathBuilder::Result result; 998 CertPathBuilder::Result result;
943 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 999 CertPathBuilder path_builder(
944 KeyPurpose::ANY_EKU, &result); 1000 target_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
1001 initial_explicit_policy_, user_initial_policy_set_,
1002 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
945 path_builder.AddCertIssuerSource(&cert_issuer_source); 1003 path_builder.AddCertIssuerSource(&cert_issuer_source);
946 1004
947 // Create the mock CertIssuerSource::Request... 1005 // Create the mock CertIssuerSource::Request...
948 std::unique_ptr<StrictMock<MockCertIssuerSourceRequest>> 1006 std::unique_ptr<StrictMock<MockCertIssuerSourceRequest>>
949 target_issuers_req_owner(new StrictMock<MockCertIssuerSourceRequest>()); 1007 target_issuers_req_owner(new StrictMock<MockCertIssuerSourceRequest>());
950 // Keep a raw pointer to the Request... 1008 // Keep a raw pointer to the Request...
951 StrictMock<MockCertIssuerSourceRequest>* target_issuers_req = 1009 StrictMock<MockCertIssuerSourceRequest>* target_issuers_req =
952 target_issuers_req_owner.get(); 1010 target_issuers_req_owner.get();
953 // Setup helper class to pass ownership of the Request to the PathBuilder when 1011 // Setup helper class to pass ownership of the Request to the PathBuilder when
954 // it calls AsyncGetIssuersOf. 1012 // it calls AsyncGetIssuersOf.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 // Test that PathBuilder will not try the same path twice if CertIssuerSources 1070 // Test that PathBuilder will not try the same path twice if CertIssuerSources
1013 // asynchronously provide the same certificate multiple times. 1071 // asynchronously provide the same certificate multiple times.
1014 TEST_F(PathBuilderKeyRolloverTest, TestDuplicateAsyncIntermediates) { 1072 TEST_F(PathBuilderKeyRolloverTest, TestDuplicateAsyncIntermediates) {
1015 StrictMock<MockCertIssuerSource> cert_issuer_source; 1073 StrictMock<MockCertIssuerSource> cert_issuer_source;
1016 1074
1017 // Only newroot is a trusted root. 1075 // Only newroot is a trusted root.
1018 TrustStoreInMemory trust_store; 1076 TrustStoreInMemory trust_store;
1019 trust_store.AddTrustAnchor(newroot_); 1077 trust_store.AddTrustAnchor(newroot_);
1020 1078
1021 CertPathBuilder::Result result; 1079 CertPathBuilder::Result result;
1022 CertPathBuilder path_builder(target_, &trust_store, &signature_policy_, time_, 1080 CertPathBuilder path_builder(
1023 KeyPurpose::ANY_EKU, &result); 1081 target_, &trust_store, &signature_policy_, time_, KeyPurpose::ANY_EKU,
1082 initial_explicit_policy_, user_initial_policy_set_,
1083 initial_policy_mapping_inhibit_, initial_any_policy_inhibit_, &result);
1024 path_builder.AddCertIssuerSource(&cert_issuer_source); 1084 path_builder.AddCertIssuerSource(&cert_issuer_source);
1025 1085
1026 // Create the mock CertIssuerSource::Request... 1086 // Create the mock CertIssuerSource::Request...
1027 std::unique_ptr<StrictMock<MockCertIssuerSourceRequest>> 1087 std::unique_ptr<StrictMock<MockCertIssuerSourceRequest>>
1028 target_issuers_req_owner(new StrictMock<MockCertIssuerSourceRequest>()); 1088 target_issuers_req_owner(new StrictMock<MockCertIssuerSourceRequest>());
1029 // Keep a raw pointer to the Request... 1089 // Keep a raw pointer to the Request...
1030 StrictMock<MockCertIssuerSourceRequest>* target_issuers_req = 1090 StrictMock<MockCertIssuerSourceRequest>* target_issuers_req =
1031 target_issuers_req_owner.get(); 1091 target_issuers_req_owner.get();
1032 // Setup helper class to pass ownership of the Request to the PathBuilder when 1092 // Setup helper class to pass ownership of the Request to the PathBuilder when
1033 // it calls AsyncGetIssuersOf. 1093 // it calls AsyncGetIssuersOf.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 trust_store.AddTrustAnchor(test_.chain.back()); 1187 trust_store.AddTrustAnchor(test_.chain.back());
1128 if (distrusted_cert) 1188 if (distrusted_cert)
1129 trust_store.AddDistrustedCertificateForTest(distrusted_cert); 1189 trust_store.AddDistrustedCertificateForTest(distrusted_cert);
1130 1190
1131 // Add the single intermediate. 1191 // Add the single intermediate.
1132 CertIssuerSourceStatic intermediates; 1192 CertIssuerSourceStatic intermediates;
1133 intermediates.AddCert(test_.chain[1]); 1193 intermediates.AddCert(test_.chain[1]);
1134 1194
1135 SimpleSignaturePolicy signature_policy(1024); 1195 SimpleSignaturePolicy signature_policy(1024);
1136 1196
1137 CertPathBuilder path_builder(test_.chain.front(), &trust_store, 1197 const InitialExplicitPolicy initial_explicit_policy =
1138 &signature_policy, test_.time, 1198 InitialExplicitPolicy::kFalse;
1139 KeyPurpose::ANY_EKU, result); 1199 const std::set<der::Input> user_initial_policy_set = {AnyPolicy()};
1200 const InitialPolicyMappingInhibit initial_policy_mapping_inhibit =
1201 InitialPolicyMappingInhibit::kFalse;
1202 const InitialAnyPolicyInhibit initial_any_policy_inhibit =
1203 InitialAnyPolicyInhibit::kFalse;
1204
1205 CertPathBuilder path_builder(
1206 test_.chain.front(), &trust_store, &signature_policy, test_.time,
1207 KeyPurpose::ANY_EKU, initial_explicit_policy, user_initial_policy_set,
1208 initial_policy_mapping_inhibit, initial_any_policy_inhibit, result);
1140 path_builder.AddCertIssuerSource(&intermediates); 1209 path_builder.AddCertIssuerSource(&intermediates);
1141 path_builder.Run(); 1210 path_builder.Run();
1142 } 1211 }
1143 1212
1144 protected: 1213 protected:
1145 VerifyCertChainTest test_; 1214 VerifyCertChainTest test_;
1146 }; 1215 };
1147 1216
1148 // Tests that path building fails when the target, intermediate, or root are 1217 // Tests that path building fails when the target, intermediate, or root are
1149 // distrusted (but the path is otherwise valid). 1218 // distrusted (but the path is otherwise valid).
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 EXPECT_EQ(best_path->path.certs[1], test_.chain[1]); 1275 EXPECT_EQ(best_path->path.certs[1], test_.chain[1]);
1207 EXPECT_EQ(best_path->path.certs[2], test_.chain[2]); 1276 EXPECT_EQ(best_path->path.certs[2], test_.chain[2]);
1208 EXPECT_TRUE(best_path->errors.ContainsHighSeverityErrors()); 1277 EXPECT_TRUE(best_path->errors.ContainsHighSeverityErrors());
1209 best_path->errors.ContainsError(kCertIsDistrusted); 1278 best_path->errors.ContainsError(kCertIsDistrusted);
1210 } 1279 }
1211 } 1280 }
1212 1281
1213 } // namespace 1282 } // namespace
1214 1283
1215 } // namespace net 1284 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/internal/path_builder_pkits_unittest.cc ('k') | net/cert/internal/path_builder_verify_certificate_chain_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698