OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 EXPECT_EQ(valid_to, valid_expiry.ToDoubleT()); | 214 EXPECT_EQ(valid_to, valid_expiry.ToDoubleT()); |
215 | 215 |
216 const SHA1Fingerprint& fingerprint = google_cert->fingerprint(); | 216 const SHA1Fingerprint& fingerprint = google_cert->fingerprint(); |
217 for (size_t i = 0; i < 20; ++i) | 217 for (size_t i = 0; i < 20; ++i) |
218 EXPECT_EQ(expected_fingerprint[i], fingerprint.data[i]); | 218 EXPECT_EQ(expected_fingerprint[i], fingerprint.data[i]); |
219 | 219 |
220 std::vector<std::string> dns_names; | 220 std::vector<std::string> dns_names; |
221 google_cert->GetDNSNames(&dns_names); | 221 google_cert->GetDNSNames(&dns_names); |
222 ASSERT_EQ(1U, dns_names.size()); | 222 ASSERT_EQ(1U, dns_names.size()); |
223 EXPECT_EQ("www.google.com", dns_names[0]); | 223 EXPECT_EQ("www.google.com", dns_names[0]); |
224 | |
225 #if TEST_EV | |
226 // TODO(avi): turn this on for the Mac once EV checking is implemented. | |
227 CertVerifyResult verify_result; | |
228 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | | |
229 X509Certificate::VERIFY_EV_CERT; | |
230 EXPECT_EQ(OK, google_cert->Verify("www.google.com", flags, NULL, | |
231 &verify_result); | |
232 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_IS_EV); | |
233 #endif | |
wtc
2012/03/06 23:10:14
Why did you delete this #if TEST_EV block but keep
Ryan Sleevi
2012/03/10 03:09:12
Missed the other ones, but Adam has already nuked
| |
234 } | 224 } |
235 | 225 |
236 TEST(X509CertificateTest, GoogleCertParsing) { | 226 // TODO(rsleevi): Temporary fixture while refactoring http://crbug.com/114343 |
227 class X509CertificateTest : public testing::Test { | |
228 public: | |
229 X509CertificateTest() {} | |
230 virtual ~X509CertificateTest() {} | |
231 | |
232 protected: | |
233 int Verify(X509Certificate* cert, | |
234 const std::string& hostname, | |
235 int flags, | |
236 CRLSet* crl_set, | |
237 CertVerifyResult* verify_result) { | |
238 return cert->Verify(hostname, flags, crl_set, verify_result); | |
wtc
2012/03/06 23:10:14
Why is this fixture necessary? Are you going to c
Ryan Sleevi
2012/03/10 03:09:12
To make it easier to friend this in X509Certificat
| |
239 } | |
240 }; | |
241 | |
242 TEST_F(X509CertificateTest, GoogleCertParsing) { | |
237 scoped_refptr<X509Certificate> google_cert( | 243 scoped_refptr<X509Certificate> google_cert( |
238 X509Certificate::CreateFromBytes( | 244 X509Certificate::CreateFromBytes( |
239 reinterpret_cast<const char*>(google_der), sizeof(google_der))); | 245 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
240 | 246 |
241 CheckGoogleCert(google_cert, google_fingerprint, | 247 CheckGoogleCert(google_cert, google_fingerprint, |
242 1238192407, // Mar 27 22:20:07 2009 GMT | 248 1238192407, // Mar 27 22:20:07 2009 GMT |
243 1269728407); // Mar 27 22:20:07 2010 GMT | 249 1269728407); // Mar 27 22:20:07 2010 GMT |
244 } | 250 } |
245 | 251 |
246 TEST(X509CertificateTest, WebkitCertParsing) { | 252 TEST_F(X509CertificateTest, WebkitCertParsing) { |
247 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( | 253 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( |
248 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); | 254 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); |
249 | 255 |
250 ASSERT_NE(static_cast<X509Certificate*>(NULL), webkit_cert); | 256 ASSERT_NE(static_cast<X509Certificate*>(NULL), webkit_cert); |
251 | 257 |
252 const CertPrincipal& subject = webkit_cert->subject(); | 258 const CertPrincipal& subject = webkit_cert->subject(); |
253 EXPECT_EQ("Cupertino", subject.locality_name); | 259 EXPECT_EQ("Cupertino", subject.locality_name); |
254 EXPECT_EQ("California", subject.state_or_province_name); | 260 EXPECT_EQ("California", subject.state_or_province_name); |
255 EXPECT_EQ("US", subject.country_name); | 261 EXPECT_EQ("US", subject.country_name); |
256 EXPECT_EQ(0U, subject.street_addresses.size()); | 262 EXPECT_EQ(0U, subject.street_addresses.size()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 #endif | 305 #endif |
300 | 306 |
301 // Test that the wildcard cert matches properly. | 307 // Test that the wildcard cert matches properly. |
302 EXPECT_TRUE(webkit_cert->VerifyNameMatch("www.webkit.org")); | 308 EXPECT_TRUE(webkit_cert->VerifyNameMatch("www.webkit.org")); |
303 EXPECT_TRUE(webkit_cert->VerifyNameMatch("foo.webkit.org")); | 309 EXPECT_TRUE(webkit_cert->VerifyNameMatch("foo.webkit.org")); |
304 EXPECT_TRUE(webkit_cert->VerifyNameMatch("webkit.org")); | 310 EXPECT_TRUE(webkit_cert->VerifyNameMatch("webkit.org")); |
305 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.webkit.com")); | 311 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.webkit.com")); |
306 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.foo.webkit.com")); | 312 EXPECT_FALSE(webkit_cert->VerifyNameMatch("www.foo.webkit.com")); |
307 } | 313 } |
308 | 314 |
309 TEST(X509CertificateTest, WithoutRevocationChecking) { | 315 TEST_F(X509CertificateTest, WithoutRevocationChecking) { |
310 // Check that verification without revocation checking works. | 316 // Check that verification without revocation checking works. |
311 CertificateList certs = CreateCertificateListFromFile( | 317 CertificateList certs = CreateCertificateListFromFile( |
312 GetTestCertsDirectory(), | 318 GetTestCertsDirectory(), |
313 "googlenew.chain.pem", | 319 "googlenew.chain.pem", |
314 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | 320 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); |
315 | 321 |
316 X509Certificate::OSCertHandles intermediates; | 322 X509Certificate::OSCertHandles intermediates; |
317 intermediates.push_back(certs[1]->os_cert_handle()); | 323 intermediates.push_back(certs[1]->os_cert_handle()); |
318 | 324 |
319 scoped_refptr<X509Certificate> google_full_chain = | 325 scoped_refptr<X509Certificate> google_full_chain = |
320 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 326 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
321 intermediates); | 327 intermediates); |
322 | 328 |
323 CertVerifyResult verify_result; | 329 CertVerifyResult verify_result; |
324 EXPECT_EQ(OK, google_full_chain->Verify("www.google.com", 0 /* flags */, NULL, | 330 EXPECT_EQ(OK, Verify(google_full_chain, "www.google.com", 0 /* flags */, NULL, |
325 &verify_result)); | 331 &verify_result)); |
326 } | 332 } |
327 | 333 |
328 TEST(X509CertificateTest, ThawteCertParsing) { | 334 TEST_F(X509CertificateTest, ThawteCertParsing) { |
329 scoped_refptr<X509Certificate> thawte_cert(X509Certificate::CreateFromBytes( | 335 scoped_refptr<X509Certificate> thawte_cert(X509Certificate::CreateFromBytes( |
330 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); | 336 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); |
331 | 337 |
332 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert); | 338 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert); |
333 | 339 |
334 const CertPrincipal& subject = thawte_cert->subject(); | 340 const CertPrincipal& subject = thawte_cert->subject(); |
335 EXPECT_EQ("www.thawte.com", subject.common_name); | 341 EXPECT_EQ("www.thawte.com", subject.common_name); |
336 EXPECT_EQ("Mountain View", subject.locality_name); | 342 EXPECT_EQ("Mountain View", subject.locality_name); |
337 EXPECT_EQ("California", subject.state_or_province_name); | 343 EXPECT_EQ("California", subject.state_or_province_name); |
338 EXPECT_EQ("US", subject.country_name); | 344 EXPECT_EQ("US", subject.country_name); |
(...skipping 30 matching lines...) Expand all Loading... | |
369 std::vector<std::string> dns_names; | 375 std::vector<std::string> dns_names; |
370 thawte_cert->GetDNSNames(&dns_names); | 376 thawte_cert->GetDNSNames(&dns_names); |
371 ASSERT_EQ(1U, dns_names.size()); | 377 ASSERT_EQ(1U, dns_names.size()); |
372 EXPECT_EQ("www.thawte.com", dns_names[0]); | 378 EXPECT_EQ("www.thawte.com", dns_names[0]); |
373 | 379 |
374 #if TEST_EV | 380 #if TEST_EV |
375 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | | 381 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | |
376 X509Certificate::VERIFY_EV_CERT; | 382 X509Certificate::VERIFY_EV_CERT; |
377 CertVerifyResult verify_result; | 383 CertVerifyResult verify_result; |
378 // EV cert verification requires revocation checking. | 384 // EV cert verification requires revocation checking. |
379 EXPECT_EQ(OK, thawte_cert->Verify("www.thawte.com", flags, NULL, | 385 EXPECT_EQ(OK, Verify(thawte_cert, "www.thawte.com", flags, NULL, |
380 &verify_result); | 386 &verify_result); |
381 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); | 387 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); |
382 // Consequently, if we don't have revocation checking enabled, we can't claim | 388 // Consequently, if we don't have revocation checking enabled, we can't claim |
383 // any cert is EV. | 389 // any cert is EV. |
384 flags = X509Certificate::VERIFY_EV_CERT; | 390 flags = X509Certificate::VERIFY_EV_CERT; |
385 EXPECT_EQ(OK, thawte_cert->Verify("www.thawte.com", flags, NULL, | 391 EXPECT_EQ(OK, Verify(thawte_cert, "www.thawte.com", flags, NULL, |
386 &verify_result)); | 392 &verify_result)); |
387 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_IS_EV); | 393 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_IS_EV); |
388 #endif | 394 #endif |
389 } | 395 } |
390 | 396 |
391 // Test that all desired AttributeAndValue pairs can be extracted when only | 397 // Test that all desired AttributeAndValue pairs can be extracted when only |
392 // a single RelativeDistinguishedName is present. "Normally" there is only | 398 // a single RelativeDistinguishedName is present. "Normally" there is only |
393 // one AVA per RDN, but some CAs place all AVAs within a single RDN. | 399 // one AVA per RDN, but some CAs place all AVAs within a single RDN. |
394 // This is a regression test for http://crbug.com/101009 | 400 // This is a regression test for http://crbug.com/101009 |
395 TEST(X509CertificateTest, MultivalueRDN) { | 401 TEST_F(X509CertificateTest, MultivalueRDN) { |
396 FilePath certs_dir = GetTestCertsDirectory(); | 402 FilePath certs_dir = GetTestCertsDirectory(); |
397 | 403 |
398 scoped_refptr<X509Certificate> multivalue_rdn_cert = | 404 scoped_refptr<X509Certificate> multivalue_rdn_cert = |
399 ImportCertFromFile(certs_dir, "multivalue_rdn.pem"); | 405 ImportCertFromFile(certs_dir, "multivalue_rdn.pem"); |
400 ASSERT_NE(static_cast<X509Certificate*>(NULL), multivalue_rdn_cert); | 406 ASSERT_NE(static_cast<X509Certificate*>(NULL), multivalue_rdn_cert); |
401 | 407 |
402 const CertPrincipal& subject = multivalue_rdn_cert->subject(); | 408 const CertPrincipal& subject = multivalue_rdn_cert->subject(); |
403 EXPECT_EQ("Multivalue RDN Test", subject.common_name); | 409 EXPECT_EQ("Multivalue RDN Test", subject.common_name); |
404 EXPECT_EQ("", subject.locality_name); | 410 EXPECT_EQ("", subject.locality_name); |
405 EXPECT_EQ("", subject.state_or_province_name); | 411 EXPECT_EQ("", subject.state_or_province_name); |
406 EXPECT_EQ("US", subject.country_name); | 412 EXPECT_EQ("US", subject.country_name); |
407 EXPECT_EQ(0U, subject.street_addresses.size()); | 413 EXPECT_EQ(0U, subject.street_addresses.size()); |
408 ASSERT_EQ(1U, subject.organization_names.size()); | 414 ASSERT_EQ(1U, subject.organization_names.size()); |
409 EXPECT_EQ("Chromium", subject.organization_names[0]); | 415 EXPECT_EQ("Chromium", subject.organization_names[0]); |
410 ASSERT_EQ(1U, subject.organization_unit_names.size()); | 416 ASSERT_EQ(1U, subject.organization_unit_names.size()); |
411 EXPECT_EQ("Chromium net_unittests", subject.organization_unit_names[0]); | 417 EXPECT_EQ("Chromium net_unittests", subject.organization_unit_names[0]); |
412 ASSERT_EQ(1U, subject.domain_components.size()); | 418 ASSERT_EQ(1U, subject.domain_components.size()); |
413 EXPECT_EQ("Chromium", subject.domain_components[0]); | 419 EXPECT_EQ("Chromium", subject.domain_components[0]); |
414 } | 420 } |
415 | 421 |
416 // Test that characters which would normally be escaped in the string form, | 422 // Test that characters which would normally be escaped in the string form, |
417 // such as '=' or '"', are not escaped when parsed as individual components. | 423 // such as '=' or '"', are not escaped when parsed as individual components. |
418 // This is a regression test for http://crbug.com/102839 | 424 // This is a regression test for http://crbug.com/102839 |
419 TEST(X509CertificateTest, UnescapedSpecialCharacters) { | 425 TEST_F(X509CertificateTest, UnescapedSpecialCharacters) { |
420 FilePath certs_dir = GetTestCertsDirectory(); | 426 FilePath certs_dir = GetTestCertsDirectory(); |
421 | 427 |
422 scoped_refptr<X509Certificate> unescaped_cert = | 428 scoped_refptr<X509Certificate> unescaped_cert = |
423 ImportCertFromFile(certs_dir, "unescaped.pem"); | 429 ImportCertFromFile(certs_dir, "unescaped.pem"); |
424 ASSERT_NE(static_cast<X509Certificate*>(NULL), unescaped_cert); | 430 ASSERT_NE(static_cast<X509Certificate*>(NULL), unescaped_cert); |
425 | 431 |
426 const CertPrincipal& subject = unescaped_cert->subject(); | 432 const CertPrincipal& subject = unescaped_cert->subject(); |
427 EXPECT_EQ("127.0.0.1", subject.common_name); | 433 EXPECT_EQ("127.0.0.1", subject.common_name); |
428 EXPECT_EQ("Mountain View", subject.locality_name); | 434 EXPECT_EQ("Mountain View", subject.locality_name); |
429 EXPECT_EQ("California", subject.state_or_province_name); | 435 EXPECT_EQ("California", subject.state_or_province_name); |
430 EXPECT_EQ("US", subject.country_name); | 436 EXPECT_EQ("US", subject.country_name); |
431 ASSERT_EQ(1U, subject.street_addresses.size()); | 437 ASSERT_EQ(1U, subject.street_addresses.size()); |
432 EXPECT_EQ("1600 Amphitheatre Parkway", subject.street_addresses[0]); | 438 EXPECT_EQ("1600 Amphitheatre Parkway", subject.street_addresses[0]); |
433 ASSERT_EQ(1U, subject.organization_names.size()); | 439 ASSERT_EQ(1U, subject.organization_names.size()); |
434 EXPECT_EQ("Chromium = \"net_unittests\"", subject.organization_names[0]); | 440 EXPECT_EQ("Chromium = \"net_unittests\"", subject.organization_names[0]); |
435 ASSERT_EQ(2U, subject.organization_unit_names.size()); | 441 ASSERT_EQ(2U, subject.organization_unit_names.size()); |
436 EXPECT_EQ("net_unittests", subject.organization_unit_names[0]); | 442 EXPECT_EQ("net_unittests", subject.organization_unit_names[0]); |
437 EXPECT_EQ("Chromium", subject.organization_unit_names[1]); | 443 EXPECT_EQ("Chromium", subject.organization_unit_names[1]); |
438 EXPECT_EQ(0U, subject.domain_components.size()); | 444 EXPECT_EQ(0U, subject.domain_components.size()); |
439 } | 445 } |
440 | 446 |
441 TEST(X509CertificateTest, PaypalNullCertParsing) { | 447 TEST_F(X509CertificateTest, PaypalNullCertParsing) { |
442 scoped_refptr<X509Certificate> paypal_null_cert( | 448 scoped_refptr<X509Certificate> paypal_null_cert( |
443 X509Certificate::CreateFromBytes( | 449 X509Certificate::CreateFromBytes( |
444 reinterpret_cast<const char*>(paypal_null_der), | 450 reinterpret_cast<const char*>(paypal_null_der), |
445 sizeof(paypal_null_der))); | 451 sizeof(paypal_null_der))); |
446 | 452 |
447 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert); | 453 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert); |
448 | 454 |
449 const SHA1Fingerprint& fingerprint = | 455 const SHA1Fingerprint& fingerprint = |
450 paypal_null_cert->fingerprint(); | 456 paypal_null_cert->fingerprint(); |
451 for (size_t i = 0; i < 20; ++i) | 457 for (size_t i = 0; i < 20; ++i) |
452 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]); | 458 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]); |
453 | 459 |
454 int flags = 0; | 460 int flags = 0; |
455 CertVerifyResult verify_result; | 461 CertVerifyResult verify_result; |
456 int error = paypal_null_cert->Verify("www.paypal.com", flags, NULL, | 462 int error = Verify(paypal_null_cert, "www.paypal.com", flags, NULL, |
457 &verify_result); | 463 &verify_result); |
458 #if defined(USE_OPENSSL) || defined(OS_MACOSX) || defined(OS_WIN) | 464 #if defined(USE_OPENSSL) || defined(OS_MACOSX) || defined(OS_WIN) |
459 // TOOD(bulach): investigate why macosx and win aren't returning | 465 // TOOD(bulach): investigate why macosx and win aren't returning |
460 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. | 466 // ERR_CERT_INVALID or ERR_CERT_COMMON_NAME_INVALID. |
461 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); | 467 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); |
462 #else | 468 #else |
463 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error); | 469 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error); |
464 #endif | 470 #endif |
465 // Either the system crypto library should correctly report a certificate | 471 // Either the system crypto library should correctly report a certificate |
466 // name mismatch, or our certificate blacklist should cause us to report an | 472 // name mismatch, or our certificate blacklist should cause us to report an |
467 // invalid certificate. | 473 // invalid certificate. |
468 #if !defined(OS_MACOSX) && !defined(USE_OPENSSL) | 474 #if !defined(OS_MACOSX) && !defined(USE_OPENSSL) |
469 EXPECT_TRUE(verify_result.cert_status & | 475 EXPECT_TRUE(verify_result.cert_status & |
470 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); | 476 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); |
471 #endif | 477 #endif |
472 } | 478 } |
473 | 479 |
474 TEST(X509CertificateTest, SerialNumbers) { | 480 TEST_F(X509CertificateTest, SerialNumbers) { |
475 scoped_refptr<X509Certificate> google_cert( | 481 scoped_refptr<X509Certificate> google_cert( |
476 X509Certificate::CreateFromBytes( | 482 X509Certificate::CreateFromBytes( |
477 reinterpret_cast<const char*>(google_der), sizeof(google_der))); | 483 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
478 | 484 |
479 static const uint8 google_serial[16] = { | 485 static const uint8 google_serial[16] = { |
480 0x01,0x2a,0x39,0x76,0x0d,0x3f,0x4f,0xc9, | 486 0x01,0x2a,0x39,0x76,0x0d,0x3f,0x4f,0xc9, |
481 0x0b,0xe7,0xbd,0x2b,0xcf,0x95,0x2e,0x7a, | 487 0x0b,0xe7,0xbd,0x2b,0xcf,0x95,0x2e,0x7a, |
482 }; | 488 }; |
483 | 489 |
484 ASSERT_EQ(sizeof(google_serial), google_cert->serial_number().size()); | 490 ASSERT_EQ(sizeof(google_serial), google_cert->serial_number().size()); |
485 EXPECT_TRUE(memcmp(google_cert->serial_number().data(), google_serial, | 491 EXPECT_TRUE(memcmp(google_cert->serial_number().data(), google_serial, |
486 sizeof(google_serial)) == 0); | 492 sizeof(google_serial)) == 0); |
487 | 493 |
488 // We also want to check a serial number where the first byte is >= 0x80 in | 494 // We also want to check a serial number where the first byte is >= 0x80 in |
489 // case the underlying library tries to pad it. | 495 // case the underlying library tries to pad it. |
490 scoped_refptr<X509Certificate> paypal_null_cert( | 496 scoped_refptr<X509Certificate> paypal_null_cert( |
491 X509Certificate::CreateFromBytes( | 497 X509Certificate::CreateFromBytes( |
492 reinterpret_cast<const char*>(paypal_null_der), | 498 reinterpret_cast<const char*>(paypal_null_der), |
493 sizeof(paypal_null_der))); | 499 sizeof(paypal_null_der))); |
494 | 500 |
495 static const uint8 paypal_null_serial[3] = {0x00, 0xf0, 0x9b}; | 501 static const uint8 paypal_null_serial[3] = {0x00, 0xf0, 0x9b}; |
496 ASSERT_EQ(sizeof(paypal_null_serial), | 502 ASSERT_EQ(sizeof(paypal_null_serial), |
497 paypal_null_cert->serial_number().size()); | 503 paypal_null_cert->serial_number().size()); |
498 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(), | 504 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(), |
499 paypal_null_serial, sizeof(paypal_null_serial)) == 0); | 505 paypal_null_serial, sizeof(paypal_null_serial)) == 0); |
500 } | 506 } |
501 | 507 |
502 TEST(X509CertificateTest, CAFingerprints) { | 508 TEST_F(X509CertificateTest, CAFingerprints) { |
503 FilePath certs_dir = GetTestCertsDirectory(); | 509 FilePath certs_dir = GetTestCertsDirectory(); |
504 | 510 |
505 scoped_refptr<X509Certificate> server_cert = | 511 scoped_refptr<X509Certificate> server_cert = |
506 ImportCertFromFile(certs_dir, "salesforce_com_test.pem"); | 512 ImportCertFromFile(certs_dir, "salesforce_com_test.pem"); |
507 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | 513 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
508 | 514 |
509 scoped_refptr<X509Certificate> intermediate_cert1 = | 515 scoped_refptr<X509Certificate> intermediate_cert1 = |
510 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem"); | 516 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem"); |
511 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1); | 517 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1); |
512 | 518 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 EXPECT_TRUE(memcmp(cert_chain2->ca_fingerprint().data, | 556 EXPECT_TRUE(memcmp(cert_chain2->ca_fingerprint().data, |
551 cert_chain2_ca_fingerprint, 20) == 0); | 557 cert_chain2_ca_fingerprint, 20) == 0); |
552 EXPECT_TRUE(memcmp(cert_chain3->ca_fingerprint().data, | 558 EXPECT_TRUE(memcmp(cert_chain3->ca_fingerprint().data, |
553 cert_chain3_ca_fingerprint, 20) == 0); | 559 cert_chain3_ca_fingerprint, 20) == 0); |
554 } | 560 } |
555 | 561 |
556 // A regression test for http://crbug.com/31497. | 562 // A regression test for http://crbug.com/31497. |
557 // This certificate will expire on 2012-04-08. The test will still | 563 // This certificate will expire on 2012-04-08. The test will still |
558 // pass if error == ERR_CERT_DATE_INVALID. TODO(wtc): generate test | 564 // pass if error == ERR_CERT_DATE_INVALID. TODO(wtc): generate test |
559 // certificates for this unit test. http://crbug.com/111742 | 565 // certificates for this unit test. http://crbug.com/111742 |
560 TEST(X509CertificateTest, IntermediateCARequireExplicitPolicy) { | 566 TEST_F(X509CertificateTest, IntermediateCARequireExplicitPolicy) { |
561 FilePath certs_dir = GetTestCertsDirectory(); | 567 FilePath certs_dir = GetTestCertsDirectory(); |
562 | 568 |
563 scoped_refptr<X509Certificate> server_cert = | 569 scoped_refptr<X509Certificate> server_cert = |
564 ImportCertFromFile(certs_dir, "www_us_army_mil_cert.der"); | 570 ImportCertFromFile(certs_dir, "www_us_army_mil_cert.der"); |
565 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | 571 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
566 | 572 |
567 // The intermediate CA certificate's policyConstraints extension has a | 573 // The intermediate CA certificate's policyConstraints extension has a |
568 // requireExplicitPolicy field with SkipCerts=0. | 574 // requireExplicitPolicy field with SkipCerts=0. |
569 scoped_refptr<X509Certificate> intermediate_cert = | 575 scoped_refptr<X509Certificate> intermediate_cert = |
570 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); | 576 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); |
571 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); | 577 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
572 | 578 |
573 FilePath root_cert_path = certs_dir.AppendASCII("dod_root_ca_2_cert.der"); | 579 FilePath root_cert_path = certs_dir.AppendASCII("dod_root_ca_2_cert.der"); |
574 TestRootCerts* root_certs = TestRootCerts::GetInstance(); | 580 TestRootCerts* root_certs = TestRootCerts::GetInstance(); |
575 ASSERT_TRUE(root_certs->AddFromFile(root_cert_path)); | 581 ASSERT_TRUE(root_certs->AddFromFile(root_cert_path)); |
576 | 582 |
577 X509Certificate::OSCertHandles intermediates; | 583 X509Certificate::OSCertHandles intermediates; |
578 intermediates.push_back(intermediate_cert->os_cert_handle()); | 584 intermediates.push_back(intermediate_cert->os_cert_handle()); |
579 scoped_refptr<X509Certificate> cert_chain = | 585 scoped_refptr<X509Certificate> cert_chain = |
580 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), | 586 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), |
581 intermediates); | 587 intermediates); |
582 | 588 |
583 int flags = 0; | 589 int flags = 0; |
584 CertVerifyResult verify_result; | 590 CertVerifyResult verify_result; |
585 int error = cert_chain->Verify("www.us.army.mil", flags, NULL, | 591 int error = Verify(cert_chain, "www.us.army.mil", flags, NULL, |
586 &verify_result); | 592 &verify_result); |
587 if (error == OK) { | 593 if (error == OK) { |
588 EXPECT_EQ(0U, verify_result.cert_status); | 594 EXPECT_EQ(0U, verify_result.cert_status); |
589 } else { | 595 } else { |
590 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); | 596 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); |
591 EXPECT_EQ(CERT_STATUS_DATE_INVALID, verify_result.cert_status); | 597 EXPECT_EQ(CERT_STATUS_DATE_INVALID, verify_result.cert_status); |
592 } | 598 } |
593 root_certs->Clear(); | 599 root_certs->Clear(); |
594 } | 600 } |
595 | 601 |
596 // Test for bug 58437. | 602 // Test for bug 58437. |
597 // This certificate will expire on 2011-12-21. The test will still | 603 // This certificate will expire on 2011-12-21. The test will still |
598 // pass if error == ERR_CERT_DATE_INVALID. | 604 // pass if error == ERR_CERT_DATE_INVALID. |
599 // This test is DISABLED because it appears that we cannot do | 605 // This test is DISABLED because it appears that we cannot do |
600 // certificate revocation checking when running all of the net unit tests. | 606 // certificate revocation checking when running all of the net unit tests. |
601 // This test passes when run individually, but when run with all of the net | 607 // This test passes when run individually, but when run with all of the net |
602 // unit tests, the call to PKIXVerifyCert returns the NSS error -8180, which is | 608 // unit tests, the call to PKIXVerifyCert returns the NSS error -8180, which is |
603 // SEC_ERROR_REVOKED_CERTIFICATE. This indicates a lack of revocation | 609 // SEC_ERROR_REVOKED_CERTIFICATE. This indicates a lack of revocation |
604 // status, i.e. that the revocation check is failing for some reason. | 610 // status, i.e. that the revocation check is failing for some reason. |
605 TEST(X509CertificateTest, DISABLED_GlobalSignR3EVTest) { | 611 TEST_F(X509CertificateTest, DISABLED_GlobalSignR3EVTest) { |
606 FilePath certs_dir = GetTestCertsDirectory(); | 612 FilePath certs_dir = GetTestCertsDirectory(); |
607 | 613 |
608 scoped_refptr<X509Certificate> server_cert = | 614 scoped_refptr<X509Certificate> server_cert = |
609 ImportCertFromFile(certs_dir, "2029_globalsign_com_cert.pem"); | 615 ImportCertFromFile(certs_dir, "2029_globalsign_com_cert.pem"); |
610 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | 616 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
611 | 617 |
612 scoped_refptr<X509Certificate> intermediate_cert = | 618 scoped_refptr<X509Certificate> intermediate_cert = |
613 ImportCertFromFile(certs_dir, "globalsign_ev_sha256_ca_cert.pem"); | 619 ImportCertFromFile(certs_dir, "globalsign_ev_sha256_ca_cert.pem"); |
614 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); | 620 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
615 | 621 |
616 X509Certificate::OSCertHandles intermediates; | 622 X509Certificate::OSCertHandles intermediates; |
617 intermediates.push_back(intermediate_cert->os_cert_handle()); | 623 intermediates.push_back(intermediate_cert->os_cert_handle()); |
618 scoped_refptr<X509Certificate> cert_chain = | 624 scoped_refptr<X509Certificate> cert_chain = |
619 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), | 625 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), |
620 intermediates); | 626 intermediates); |
621 | 627 |
622 CertVerifyResult verify_result; | 628 CertVerifyResult verify_result; |
623 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | | 629 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | |
624 X509Certificate::VERIFY_EV_CERT; | 630 X509Certificate::VERIFY_EV_CERT; |
625 int error = cert_chain->Verify("2029.globalsign.com", flags, NULL, | 631 int error = Verify(cert_chain, "2029.globalsign.com", flags, NULL, |
626 &verify_result); | 632 &verify_result); |
627 if (error == OK) | 633 if (error == OK) |
628 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); | 634 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_IS_EV); |
629 else | 635 else |
630 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); | 636 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); |
631 } | 637 } |
632 | 638 |
633 // Currently, only RSA and DSA keys are checked for weakness, and our example | 639 // Currently, only RSA and DSA keys are checked for weakness, and our example |
634 // weak size is 768. These could change in the future. | 640 // weak size is 768. These could change in the future. |
635 // | 641 // |
636 // Note that this means there may be false negatives: keys for other | 642 // Note that this means there may be false negatives: keys for other |
637 // algorithms and which are weak will pass this test. | 643 // algorithms and which are weak will pass this test. |
638 static bool IsWeakKeyType(const std::string& key_type) { | 644 static bool IsWeakKeyType(const std::string& key_type) { |
639 size_t pos = key_type.find("-"); | 645 size_t pos = key_type.find("-"); |
640 std::string size = key_type.substr(0, pos); | 646 std::string size = key_type.substr(0, pos); |
641 std::string type = key_type.substr(pos + 1); | 647 std::string type = key_type.substr(pos + 1); |
642 | 648 |
643 if (type == "rsa" || type == "dsa") | 649 if (type == "rsa" || type == "dsa") |
644 return size == "768"; | 650 return size == "768"; |
645 | 651 |
646 return false; | 652 return false; |
647 } | 653 } |
648 | 654 |
649 TEST(X509CertificateTest, RejectWeakKeys) { | 655 TEST_F(X509CertificateTest, RejectWeakKeys) { |
650 FilePath certs_dir = GetTestCertsDirectory(); | 656 FilePath certs_dir = GetTestCertsDirectory(); |
651 typedef std::vector<std::string> Strings; | 657 typedef std::vector<std::string> Strings; |
652 Strings key_types; | 658 Strings key_types; |
653 | 659 |
654 // generate-weak-test-chains.sh currently has: | 660 // generate-weak-test-chains.sh currently has: |
655 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa" | 661 // key_types="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa" |
656 // We must use the same key types here. The filenames generated look like: | 662 // We must use the same key types here. The filenames generated look like: |
657 // 2048-rsa-ee-by-768-rsa-intermediate.pem | 663 // 2048-rsa-ee-by-768-rsa-intermediate.pem |
658 key_types.push_back("768-rsa"); | 664 key_types.push_back("768-rsa"); |
659 key_types.push_back("1024-rsa"); | 665 key_types.push_back("1024-rsa"); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
692 ImportCertFromFile(certs_dir, basename); | 698 ImportCertFromFile(certs_dir, basename); |
693 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate); | 699 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate); |
694 | 700 |
695 X509Certificate::OSCertHandles intermediates; | 701 X509Certificate::OSCertHandles intermediates; |
696 intermediates.push_back(intermediate->os_cert_handle()); | 702 intermediates.push_back(intermediate->os_cert_handle()); |
697 scoped_refptr<X509Certificate> cert_chain = | 703 scoped_refptr<X509Certificate> cert_chain = |
698 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), | 704 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), |
699 intermediates); | 705 intermediates); |
700 | 706 |
701 CertVerifyResult verify_result; | 707 CertVerifyResult verify_result; |
702 int error = cert_chain->Verify("127.0.0.1", 0, NULL, &verify_result); | 708 int error = Verify(cert_chain, "127.0.0.1", 0, NULL, &verify_result); |
703 | 709 |
704 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { | 710 if (IsWeakKeyType(*ee_type) || IsWeakKeyType(*signer_type)) { |
705 EXPECT_NE(OK, error); | 711 EXPECT_NE(OK, error); |
706 EXPECT_EQ(CERT_STATUS_WEAK_KEY, | 712 EXPECT_EQ(CERT_STATUS_WEAK_KEY, |
707 verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 713 verify_result.cert_status & CERT_STATUS_WEAK_KEY); |
708 } else { | 714 } else { |
709 EXPECT_EQ(OK, error); | 715 EXPECT_EQ(OK, error); |
710 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); | 716 EXPECT_EQ(0U, verify_result.cert_status & CERT_STATUS_WEAK_KEY); |
711 } | 717 } |
712 } | 718 } |
713 } | 719 } |
714 | 720 |
715 TestRootCerts::GetInstance()->Clear(); | 721 TestRootCerts::GetInstance()->Clear(); |
716 } | 722 } |
717 | 723 |
718 // Test for bug 108514. | 724 // Test for bug 108514. |
719 // The certificate will expire on 2012-07-20. The test will still | 725 // The certificate will expire on 2012-07-20. The test will still |
720 // pass if error == ERR_CERT_DATE_INVALID. TODO(rsleevi): generate test | 726 // pass if error == ERR_CERT_DATE_INVALID. TODO(rsleevi): generate test |
721 // certificates for this unit test. http://crbug.com/111730 | 727 // certificates for this unit test. http://crbug.com/111730 |
722 TEST(X509CertificateTest, ExtraneousMD5RootCert) { | 728 TEST_F(X509CertificateTest, ExtraneousMD5RootCert) { |
723 FilePath certs_dir = GetTestCertsDirectory(); | 729 FilePath certs_dir = GetTestCertsDirectory(); |
724 | 730 |
725 scoped_refptr<X509Certificate> server_cert = | 731 scoped_refptr<X509Certificate> server_cert = |
726 ImportCertFromFile(certs_dir, "images_etrade_wallst_com.pem"); | 732 ImportCertFromFile(certs_dir, "images_etrade_wallst_com.pem"); |
727 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | 733 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
728 | 734 |
729 scoped_refptr<X509Certificate> intermediate_cert = | 735 scoped_refptr<X509Certificate> intermediate_cert = |
730 ImportCertFromFile(certs_dir, "globalsign_orgv1_ca.pem"); | 736 ImportCertFromFile(certs_dir, "globalsign_orgv1_ca.pem"); |
731 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); | 737 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
732 | 738 |
733 scoped_refptr<X509Certificate> md5_root_cert = | 739 scoped_refptr<X509Certificate> md5_root_cert = |
734 ImportCertFromFile(certs_dir, "globalsign_root_ca_md5.pem"); | 740 ImportCertFromFile(certs_dir, "globalsign_root_ca_md5.pem"); |
735 ASSERT_NE(static_cast<X509Certificate*>(NULL), md5_root_cert); | 741 ASSERT_NE(static_cast<X509Certificate*>(NULL), md5_root_cert); |
736 | 742 |
737 X509Certificate::OSCertHandles intermediates; | 743 X509Certificate::OSCertHandles intermediates; |
738 intermediates.push_back(intermediate_cert->os_cert_handle()); | 744 intermediates.push_back(intermediate_cert->os_cert_handle()); |
739 intermediates.push_back(md5_root_cert->os_cert_handle()); | 745 intermediates.push_back(md5_root_cert->os_cert_handle()); |
740 scoped_refptr<X509Certificate> cert_chain = | 746 scoped_refptr<X509Certificate> cert_chain = |
741 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), | 747 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), |
742 intermediates); | 748 intermediates); |
743 | 749 |
744 CertVerifyResult verify_result; | 750 CertVerifyResult verify_result; |
745 int flags = 0; | 751 int flags = 0; |
746 int error = cert_chain->Verify("images.etrade.wallst.com", flags, NULL, | 752 int error = Verify(cert_chain, "images.etrade.wallst.com", flags, NULL, |
747 &verify_result); | 753 &verify_result); |
748 if (error != OK) | 754 if (error != OK) |
749 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); | 755 EXPECT_EQ(ERR_CERT_DATE_INVALID, error); |
750 | 756 |
751 EXPECT_FALSE(verify_result.has_md5); | 757 EXPECT_FALSE(verify_result.has_md5); |
752 EXPECT_FALSE(verify_result.has_md5_ca); | 758 EXPECT_FALSE(verify_result.has_md5_ca); |
753 } | 759 } |
754 | 760 |
755 // Test for bug 94673. | 761 // Test for bug 94673. |
756 TEST(X509CertificateTest, GoogleDigiNotarTest) { | 762 TEST_F(X509CertificateTest, GoogleDigiNotarTest) { |
757 FilePath certs_dir = GetTestCertsDirectory(); | 763 FilePath certs_dir = GetTestCertsDirectory(); |
758 | 764 |
759 scoped_refptr<X509Certificate> server_cert = | 765 scoped_refptr<X509Certificate> server_cert = |
760 ImportCertFromFile(certs_dir, "google_diginotar.pem"); | 766 ImportCertFromFile(certs_dir, "google_diginotar.pem"); |
761 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | 767 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
762 | 768 |
763 scoped_refptr<X509Certificate> intermediate_cert = | 769 scoped_refptr<X509Certificate> intermediate_cert = |
764 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem"); | 770 ImportCertFromFile(certs_dir, "diginotar_public_ca_2025.pem"); |
765 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); | 771 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
766 | 772 |
767 X509Certificate::OSCertHandles intermediates; | 773 X509Certificate::OSCertHandles intermediates; |
768 intermediates.push_back(intermediate_cert->os_cert_handle()); | 774 intermediates.push_back(intermediate_cert->os_cert_handle()); |
769 scoped_refptr<X509Certificate> cert_chain = | 775 scoped_refptr<X509Certificate> cert_chain = |
770 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), | 776 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), |
771 intermediates); | 777 intermediates); |
772 | 778 |
773 CertVerifyResult verify_result; | 779 CertVerifyResult verify_result; |
774 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED; | 780 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED; |
775 int error = cert_chain->Verify("mail.google.com", flags, NULL, | 781 int error = Verify(cert_chain, "mail.google.com", flags, NULL, |
776 &verify_result); | 782 &verify_result); |
777 EXPECT_NE(OK, error); | 783 EXPECT_NE(OK, error); |
778 | 784 |
779 // Now turn off revocation checking. Certificate verification should still | 785 // Now turn off revocation checking. Certificate verification should still |
780 // fail. | 786 // fail. |
781 flags = 0; | 787 flags = 0; |
782 error = cert_chain->Verify("mail.google.com", flags, NULL, &verify_result); | 788 error = Verify(cert_chain, "mail.google.com", flags, NULL, &verify_result); |
783 EXPECT_NE(OK, error); | 789 EXPECT_NE(OK, error); |
784 } | 790 } |
785 | 791 |
786 TEST(X509CertificateTest, DigiNotarCerts) { | 792 TEST_F(X509CertificateTest, DigiNotarCerts) { |
787 static const char* const kDigiNotarFilenames[] = { | 793 static const char* const kDigiNotarFilenames[] = { |
788 "diginotar_root_ca.pem", | 794 "diginotar_root_ca.pem", |
789 "diginotar_cyber_ca.pem", | 795 "diginotar_cyber_ca.pem", |
790 "diginotar_services_1024_ca.pem", | 796 "diginotar_services_1024_ca.pem", |
791 "diginotar_pkioverheid.pem", | 797 "diginotar_pkioverheid.pem", |
792 "diginotar_pkioverheid_g2.pem", | 798 "diginotar_pkioverheid_g2.pem", |
793 NULL, | 799 NULL, |
794 }; | 800 }; |
795 | 801 |
796 FilePath certs_dir = GetTestCertsDirectory(); | 802 FilePath certs_dir = GetTestCertsDirectory(); |
(...skipping 15 matching lines...) Expand all Loading... | |
812 ASSERT_EQ(sizeof(fingerprint.data), spki_sha1.size()); | 818 ASSERT_EQ(sizeof(fingerprint.data), spki_sha1.size()); |
813 memcpy(fingerprint.data, spki_sha1.data(), spki_sha1.size()); | 819 memcpy(fingerprint.data, spki_sha1.data(), spki_sha1.size()); |
814 public_keys.push_back(fingerprint); | 820 public_keys.push_back(fingerprint); |
815 | 821 |
816 EXPECT_TRUE(X509Certificate::IsPublicKeyBlacklisted(public_keys)) << | 822 EXPECT_TRUE(X509Certificate::IsPublicKeyBlacklisted(public_keys)) << |
817 "Public key not blocked for " << kDigiNotarFilenames[i]; | 823 "Public key not blocked for " << kDigiNotarFilenames[i]; |
818 } | 824 } |
819 } | 825 } |
820 | 826 |
821 // Bug 111893: This test needs a new certificate. | 827 // Bug 111893: This test needs a new certificate. |
822 TEST(X509CertificateTest, DISABLED_TestKnownRoot) { | 828 TEST_F(X509CertificateTest, DISABLED_TestKnownRoot) { |
823 FilePath certs_dir = GetTestCertsDirectory(); | 829 FilePath certs_dir = GetTestCertsDirectory(); |
824 scoped_refptr<X509Certificate> cert = | 830 scoped_refptr<X509Certificate> cert = |
825 ImportCertFromFile(certs_dir, "nist.der"); | 831 ImportCertFromFile(certs_dir, "nist.der"); |
826 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); | 832 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); |
827 | 833 |
828 // This intermediate is only needed for old Linux machines. Modern NSS | 834 // This intermediate is only needed for old Linux machines. Modern NSS |
829 // includes it as a root already. | 835 // includes it as a root already. |
830 scoped_refptr<X509Certificate> intermediate_cert = | 836 scoped_refptr<X509Certificate> intermediate_cert = |
831 ImportCertFromFile(certs_dir, "nist_intermediate.der"); | 837 ImportCertFromFile(certs_dir, "nist_intermediate.der"); |
832 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); | 838 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
833 | 839 |
834 X509Certificate::OSCertHandles intermediates; | 840 X509Certificate::OSCertHandles intermediates; |
835 intermediates.push_back(intermediate_cert->os_cert_handle()); | 841 intermediates.push_back(intermediate_cert->os_cert_handle()); |
836 scoped_refptr<X509Certificate> cert_chain = | 842 scoped_refptr<X509Certificate> cert_chain = |
837 X509Certificate::CreateFromHandle(cert->os_cert_handle(), | 843 X509Certificate::CreateFromHandle(cert->os_cert_handle(), |
838 intermediates); | 844 intermediates); |
839 | 845 |
840 int flags = 0; | 846 int flags = 0; |
841 CertVerifyResult verify_result; | 847 CertVerifyResult verify_result; |
842 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug | 848 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug |
843 // against agl. Also see PublicKeyHashes in this file. | 849 // against agl. Also see PublicKeyHashes in this file. |
844 int error = cert_chain->Verify("www.nist.gov", flags, NULL, &verify_result); | 850 int error = Verify(cert_chain, "www.nist.gov", flags, NULL, &verify_result); |
845 EXPECT_EQ(OK, error); | 851 EXPECT_EQ(OK, error); |
846 EXPECT_EQ(0U, verify_result.cert_status); | 852 EXPECT_EQ(0U, verify_result.cert_status); |
847 EXPECT_TRUE(verify_result.is_issued_by_known_root); | 853 EXPECT_TRUE(verify_result.is_issued_by_known_root); |
848 } | 854 } |
849 | 855 |
850 // This is the SHA1 hash of the SubjectPublicKeyInfo of nist.der. | 856 // This is the SHA1 hash of the SubjectPublicKeyInfo of nist.der. |
851 static const char nistSPKIHash[] = | 857 static const char nistSPKIHash[] = |
852 "\x15\x60\xde\x65\x4e\x03\x9f\xd0\x08\x82" | 858 "\x15\x60\xde\x65\x4e\x03\x9f\xd0\x08\x82" |
853 "\xa9\x6a\xc4\x65\x8e\x6f\x92\x06\x84\x35"; | 859 "\xa9\x6a\xc4\x65\x8e\x6f\x92\x06\x84\x35"; |
854 | 860 |
855 TEST(X509CertificateTest, ExtractSPKIFromDERCert) { | 861 TEST_F(X509CertificateTest, ExtractSPKIFromDERCert) { |
856 FilePath certs_dir = GetTestCertsDirectory(); | 862 FilePath certs_dir = GetTestCertsDirectory(); |
857 scoped_refptr<X509Certificate> cert = | 863 scoped_refptr<X509Certificate> cert = |
858 ImportCertFromFile(certs_dir, "nist.der"); | 864 ImportCertFromFile(certs_dir, "nist.der"); |
859 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); | 865 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); |
860 | 866 |
861 std::string derBytes; | 867 std::string derBytes; |
862 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), | 868 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), |
863 &derBytes)); | 869 &derBytes)); |
864 | 870 |
865 base::StringPiece spkiBytes; | 871 base::StringPiece spkiBytes; |
866 EXPECT_TRUE(asn1::ExtractSPKIFromDERCert(derBytes, &spkiBytes)); | 872 EXPECT_TRUE(asn1::ExtractSPKIFromDERCert(derBytes, &spkiBytes)); |
867 | 873 |
868 uint8 hash[base::kSHA1Length]; | 874 uint8 hash[base::kSHA1Length]; |
869 base::SHA1HashBytes(reinterpret_cast<const uint8*>(spkiBytes.data()), | 875 base::SHA1HashBytes(reinterpret_cast<const uint8*>(spkiBytes.data()), |
870 spkiBytes.size(), hash); | 876 spkiBytes.size(), hash); |
871 | 877 |
872 EXPECT_EQ(0, memcmp(hash, nistSPKIHash, sizeof(hash))); | 878 EXPECT_EQ(0, memcmp(hash, nistSPKIHash, sizeof(hash))); |
873 } | 879 } |
874 | 880 |
875 TEST(X509CertificateTest, ExtractCRLURLsFromDERCert) { | 881 TEST_F(X509CertificateTest, ExtractCRLURLsFromDERCert) { |
876 FilePath certs_dir = GetTestCertsDirectory(); | 882 FilePath certs_dir = GetTestCertsDirectory(); |
877 scoped_refptr<X509Certificate> cert = | 883 scoped_refptr<X509Certificate> cert = |
878 ImportCertFromFile(certs_dir, "nist.der"); | 884 ImportCertFromFile(certs_dir, "nist.der"); |
879 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); | 885 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); |
880 | 886 |
881 std::string derBytes; | 887 std::string derBytes; |
882 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), | 888 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), |
883 &derBytes)); | 889 &derBytes)); |
884 | 890 |
885 std::vector<base::StringPiece> crl_urls; | 891 std::vector<base::StringPiece> crl_urls; |
886 EXPECT_TRUE(asn1::ExtractCRLURLsFromDERCert(derBytes, &crl_urls)); | 892 EXPECT_TRUE(asn1::ExtractCRLURLsFromDERCert(derBytes, &crl_urls)); |
887 | 893 |
888 EXPECT_EQ(1u, crl_urls.size()); | 894 EXPECT_EQ(1u, crl_urls.size()); |
889 if (crl_urls.size() > 0) { | 895 if (crl_urls.size() > 0) { |
890 EXPECT_EQ("http://SVRSecure-G3-crl.verisign.com/SVRSecureG3.crl", | 896 EXPECT_EQ("http://SVRSecure-G3-crl.verisign.com/SVRSecureG3.crl", |
891 crl_urls[0].as_string()); | 897 crl_urls[0].as_string()); |
892 } | 898 } |
893 } | 899 } |
894 | 900 |
895 // Bug 111893: This test needs a new certificate. | 901 // Bug 111893: This test needs a new certificate. |
896 TEST(X509CertificateTest, DISABLED_PublicKeyHashes) { | 902 TEST_F(X509CertificateTest, DISABLED_PublicKeyHashes) { |
897 FilePath certs_dir = GetTestCertsDirectory(); | 903 FilePath certs_dir = GetTestCertsDirectory(); |
898 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug | 904 // This is going to blow up in Feb 2012. Sorry! Disable and file a bug |
899 // against agl. Also see TestKnownRoot in this file. | 905 // against agl. Also see TestKnownRoot in this file. |
900 scoped_refptr<X509Certificate> cert = | 906 scoped_refptr<X509Certificate> cert = |
901 ImportCertFromFile(certs_dir, "nist.der"); | 907 ImportCertFromFile(certs_dir, "nist.der"); |
902 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); | 908 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); |
903 | 909 |
904 // This intermediate is only needed for old Linux machines. Modern NSS | 910 // This intermediate is only needed for old Linux machines. Modern NSS |
905 // includes it as a root already. | 911 // includes it as a root already. |
906 scoped_refptr<X509Certificate> intermediate_cert = | 912 scoped_refptr<X509Certificate> intermediate_cert = |
907 ImportCertFromFile(certs_dir, "nist_intermediate.der"); | 913 ImportCertFromFile(certs_dir, "nist_intermediate.der"); |
908 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); | 914 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); |
909 | 915 |
910 TestRootCerts::GetInstance()->Add(intermediate_cert.get()); | 916 TestRootCerts::GetInstance()->Add(intermediate_cert.get()); |
911 | 917 |
912 X509Certificate::OSCertHandles intermediates; | 918 X509Certificate::OSCertHandles intermediates; |
913 intermediates.push_back(intermediate_cert->os_cert_handle()); | 919 intermediates.push_back(intermediate_cert->os_cert_handle()); |
914 scoped_refptr<X509Certificate> cert_chain = | 920 scoped_refptr<X509Certificate> cert_chain = |
915 X509Certificate::CreateFromHandle(cert->os_cert_handle(), | 921 X509Certificate::CreateFromHandle(cert->os_cert_handle(), |
916 intermediates); | 922 intermediates); |
917 | 923 |
918 int flags = 0; | 924 int flags = 0; |
919 CertVerifyResult verify_result; | 925 CertVerifyResult verify_result; |
920 | 926 |
921 int error = cert_chain->Verify("www.nist.gov", flags, NULL, &verify_result); | 927 int error = Verify(cert_chain, "www.nist.gov", flags, NULL, &verify_result); |
922 EXPECT_EQ(OK, error); | 928 EXPECT_EQ(OK, error); |
923 EXPECT_EQ(0U, verify_result.cert_status); | 929 EXPECT_EQ(0U, verify_result.cert_status); |
924 ASSERT_LE(2u, verify_result.public_key_hashes.size()); | 930 ASSERT_LE(2u, verify_result.public_key_hashes.size()); |
925 EXPECT_EQ(HexEncode(nistSPKIHash, base::kSHA1Length), | 931 EXPECT_EQ(HexEncode(nistSPKIHash, base::kSHA1Length), |
926 HexEncode(verify_result.public_key_hashes[0].data, base::kSHA1Length)); | 932 HexEncode(verify_result.public_key_hashes[0].data, base::kSHA1Length)); |
927 EXPECT_EQ("83244223D6CBF0A26FC7DE27CEBCA4BDA32612AD", | 933 EXPECT_EQ("83244223D6CBF0A26FC7DE27CEBCA4BDA32612AD", |
928 HexEncode(verify_result.public_key_hashes[1].data, base::kSHA1Length)); | 934 HexEncode(verify_result.public_key_hashes[1].data, base::kSHA1Length)); |
929 | 935 |
930 TestRootCerts::GetInstance()->Clear(); | 936 TestRootCerts::GetInstance()->Clear(); |
931 } | 937 } |
932 | 938 |
933 // A regression test for http://crbug.com/70293. | 939 // A regression test for http://crbug.com/70293. |
934 // The Key Usage extension in this RSA SSL server certificate does not have | 940 // The Key Usage extension in this RSA SSL server certificate does not have |
935 // the keyEncipherment bit. | 941 // the keyEncipherment bit. |
936 TEST(X509CertificateTest, InvalidKeyUsage) { | 942 TEST_F(X509CertificateTest, InvalidKeyUsage) { |
937 FilePath certs_dir = GetTestCertsDirectory(); | 943 FilePath certs_dir = GetTestCertsDirectory(); |
938 | 944 |
939 scoped_refptr<X509Certificate> server_cert = | 945 scoped_refptr<X509Certificate> server_cert = |
940 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); | 946 ImportCertFromFile(certs_dir, "invalid_key_usage_cert.der"); |
941 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | 947 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
942 | 948 |
943 int flags = 0; | 949 int flags = 0; |
944 CertVerifyResult verify_result; | 950 CertVerifyResult verify_result; |
945 int error = server_cert->Verify("jira.aquameta.com", flags, NULL, | 951 int error = Verify(server_cert, "jira.aquameta.com", flags, NULL, |
946 &verify_result); | 952 &verify_result); |
947 #if defined(USE_OPENSSL) | 953 #if defined(USE_OPENSSL) |
948 // This certificate has two errors: "invalid key usage" and "untrusted CA". | 954 // This certificate has two errors: "invalid key usage" and "untrusted CA". |
949 // However, OpenSSL returns only one (the latter), and we can't detect | 955 // However, OpenSSL returns only one (the latter), and we can't detect |
950 // the other errors. | 956 // the other errors. |
951 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); | 957 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, error); |
952 #else | 958 #else |
953 EXPECT_EQ(ERR_CERT_INVALID, error); | 959 EXPECT_EQ(ERR_CERT_INVALID, error); |
954 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); | 960 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_INVALID); |
955 #endif | 961 #endif |
956 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors | 962 // TODO(wtc): fix http://crbug.com/75520 to get all the certificate errors |
957 // from NSS. | 963 // from NSS. |
958 #if !defined(USE_NSS) | 964 #if !defined(USE_NSS) |
959 // The certificate is issued by an unknown CA. | 965 // The certificate is issued by an unknown CA. |
960 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); | 966 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_AUTHORITY_INVALID); |
961 #endif | 967 #endif |
962 } | 968 } |
963 | 969 |
964 // Tests X509CertificateCache via X509Certificate::CreateFromHandle. We | 970 // Tests X509CertificateCache via X509Certificate::CreateFromHandle. We |
965 // call X509Certificate::CreateFromHandle several times and observe whether | 971 // call X509Certificate::CreateFromHandle several times and observe whether |
966 // it returns a cached or new OSCertHandle. | 972 // it returns a cached or new OSCertHandle. |
967 TEST(X509CertificateTest, Cache) { | 973 TEST_F(X509CertificateTest, Cache) { |
968 X509Certificate::OSCertHandle google_cert_handle; | 974 X509Certificate::OSCertHandle google_cert_handle; |
969 X509Certificate::OSCertHandle thawte_cert_handle; | 975 X509Certificate::OSCertHandle thawte_cert_handle; |
970 | 976 |
971 // Add a single certificate to the certificate cache. | 977 // Add a single certificate to the certificate cache. |
972 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( | 978 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( |
973 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 979 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
974 scoped_refptr<X509Certificate> cert1(X509Certificate::CreateFromHandle( | 980 scoped_refptr<X509Certificate> cert1(X509Certificate::CreateFromHandle( |
975 google_cert_handle, X509Certificate::OSCertHandles())); | 981 google_cert_handle, X509Certificate::OSCertHandles())); |
976 X509Certificate::FreeOSCertHandle(google_cert_handle); | 982 X509Certificate::FreeOSCertHandle(google_cert_handle); |
977 | 983 |
(...skipping 26 matching lines...) Expand all Loading... | |
1004 X509Certificate::FreeOSCertHandle(thawte_cert_handle); | 1010 X509Certificate::FreeOSCertHandle(thawte_cert_handle); |
1005 | 1011 |
1006 // Test that the new certificate, even with intermediates, results in the | 1012 // Test that the new certificate, even with intermediates, results in the |
1007 // same underlying handle being used. | 1013 // same underlying handle being used. |
1008 EXPECT_EQ(cert1->os_cert_handle(), cert3->os_cert_handle()); | 1014 EXPECT_EQ(cert1->os_cert_handle(), cert3->os_cert_handle()); |
1009 // Though they use the same OS handle, the intermediates should be different. | 1015 // Though they use the same OS handle, the intermediates should be different. |
1010 EXPECT_NE(cert1->GetIntermediateCertificates().size(), | 1016 EXPECT_NE(cert1->GetIntermediateCertificates().size(), |
1011 cert3->GetIntermediateCertificates().size()); | 1017 cert3->GetIntermediateCertificates().size()); |
1012 } | 1018 } |
1013 | 1019 |
1014 TEST(X509CertificateTest, Pickle) { | 1020 TEST_F(X509CertificateTest, Pickle) { |
1015 X509Certificate::OSCertHandle google_cert_handle = | 1021 X509Certificate::OSCertHandle google_cert_handle = |
1016 X509Certificate::CreateOSCertHandleFromBytes( | 1022 X509Certificate::CreateOSCertHandleFromBytes( |
1017 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 1023 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
1018 X509Certificate::OSCertHandle thawte_cert_handle = | 1024 X509Certificate::OSCertHandle thawte_cert_handle = |
1019 X509Certificate::CreateOSCertHandleFromBytes( | 1025 X509Certificate::CreateOSCertHandleFromBytes( |
1020 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)); | 1026 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)); |
1021 | 1027 |
1022 X509Certificate::OSCertHandles intermediates; | 1028 X509Certificate::OSCertHandles intermediates; |
1023 intermediates.push_back(thawte_cert_handle); | 1029 intermediates.push_back(thawte_cert_handle); |
1024 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( | 1030 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( |
(...skipping 17 matching lines...) Expand all Loading... | |
1042 cert->GetIntermediateCertificates(); | 1048 cert->GetIntermediateCertificates(); |
1043 const X509Certificate::OSCertHandles& pickle_intermediates = | 1049 const X509Certificate::OSCertHandles& pickle_intermediates = |
1044 cert_from_pickle->GetIntermediateCertificates(); | 1050 cert_from_pickle->GetIntermediateCertificates(); |
1045 ASSERT_EQ(cert_intermediates.size(), pickle_intermediates.size()); | 1051 ASSERT_EQ(cert_intermediates.size(), pickle_intermediates.size()); |
1046 for (size_t i = 0; i < cert_intermediates.size(); ++i) { | 1052 for (size_t i = 0; i < cert_intermediates.size(); ++i) { |
1047 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert_intermediates[i], | 1053 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert_intermediates[i], |
1048 pickle_intermediates[i])); | 1054 pickle_intermediates[i])); |
1049 } | 1055 } |
1050 } | 1056 } |
1051 | 1057 |
1052 TEST(X509CertificateTest, Policy) { | 1058 TEST_F(X509CertificateTest, Policy) { |
1053 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes( | 1059 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes( |
1054 reinterpret_cast<const char*>(google_der), sizeof(google_der))); | 1060 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
1055 | 1061 |
1056 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( | 1062 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( |
1057 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); | 1063 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); |
1058 | 1064 |
1059 CertPolicy policy; | 1065 CertPolicy policy; |
1060 | 1066 |
1061 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::UNKNOWN); | 1067 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::UNKNOWN); |
1062 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::UNKNOWN); | 1068 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::UNKNOWN); |
(...skipping 15 matching lines...) Expand all Loading... | |
1078 EXPECT_TRUE(policy.HasDeniedCert()); | 1084 EXPECT_TRUE(policy.HasDeniedCert()); |
1079 | 1085 |
1080 policy.Allow(webkit_cert.get()); | 1086 policy.Allow(webkit_cert.get()); |
1081 | 1087 |
1082 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::DENIED); | 1088 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::DENIED); |
1083 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::ALLOWED); | 1089 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::ALLOWED); |
1084 EXPECT_TRUE(policy.HasAllowedCert()); | 1090 EXPECT_TRUE(policy.HasAllowedCert()); |
1085 EXPECT_TRUE(policy.HasDeniedCert()); | 1091 EXPECT_TRUE(policy.HasDeniedCert()); |
1086 } | 1092 } |
1087 | 1093 |
1088 TEST(X509CertificateTest, IntermediateCertificates) { | 1094 TEST_F(X509CertificateTest, IntermediateCertificates) { |
1089 scoped_refptr<X509Certificate> webkit_cert( | 1095 scoped_refptr<X509Certificate> webkit_cert( |
1090 X509Certificate::CreateFromBytes( | 1096 X509Certificate::CreateFromBytes( |
1091 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); | 1097 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); |
1092 | 1098 |
1093 scoped_refptr<X509Certificate> thawte_cert( | 1099 scoped_refptr<X509Certificate> thawte_cert( |
1094 X509Certificate::CreateFromBytes( | 1100 X509Certificate::CreateFromBytes( |
1095 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); | 1101 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); |
1096 | 1102 |
1097 X509Certificate::OSCertHandle google_handle; | 1103 X509Certificate::OSCertHandle google_handle; |
1098 // Create object with no intermediates: | 1104 // Create object with no intermediates: |
(...skipping 23 matching lines...) Expand all Loading... | |
1122 // Cleanup | 1128 // Cleanup |
1123 X509Certificate::FreeOSCertHandle(google_handle); | 1129 X509Certificate::FreeOSCertHandle(google_handle); |
1124 } | 1130 } |
1125 | 1131 |
1126 // Basic test for returning the chain in CertVerifyResult. Note that the | 1132 // Basic test for returning the chain in CertVerifyResult. Note that the |
1127 // returned chain may just be a reflection of the originally supplied chain; | 1133 // returned chain may just be a reflection of the originally supplied chain; |
1128 // that is, if any errors occur, the default chain returned is an exact copy | 1134 // that is, if any errors occur, the default chain returned is an exact copy |
1129 // of the certificate to be verified. The remaining VerifyReturn* tests are | 1135 // of the certificate to be verified. The remaining VerifyReturn* tests are |
1130 // used to ensure that the actual, verified chain is being returned by | 1136 // used to ensure that the actual, verified chain is being returned by |
1131 // Verify(). | 1137 // Verify(). |
1132 TEST(X509CertificateTest, VerifyReturnChainBasic) { | 1138 TEST_F(X509CertificateTest, VerifyReturnChainBasic) { |
1133 FilePath certs_dir = GetTestCertsDirectory(); | 1139 FilePath certs_dir = GetTestCertsDirectory(); |
1134 CertificateList certs = CreateCertificateListFromFile( | 1140 CertificateList certs = CreateCertificateListFromFile( |
1135 certs_dir, "x509_verify_results.chain.pem", | 1141 certs_dir, "x509_verify_results.chain.pem", |
1136 X509Certificate::FORMAT_AUTO); | 1142 X509Certificate::FORMAT_AUTO); |
1137 ASSERT_EQ(3U, certs.size()); | 1143 ASSERT_EQ(3U, certs.size()); |
1138 | 1144 |
1139 X509Certificate::OSCertHandles intermediates; | 1145 X509Certificate::OSCertHandles intermediates; |
1140 intermediates.push_back(certs[1]->os_cert_handle()); | 1146 intermediates.push_back(certs[1]->os_cert_handle()); |
1141 intermediates.push_back(certs[2]->os_cert_handle()); | 1147 intermediates.push_back(certs[2]->os_cert_handle()); |
1142 | 1148 |
1143 TestRootCerts::GetInstance()->Add(certs[2]); | 1149 TestRootCerts::GetInstance()->Add(certs[2]); |
1144 | 1150 |
1145 scoped_refptr<X509Certificate> google_full_chain = | 1151 scoped_refptr<X509Certificate> google_full_chain = |
1146 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 1152 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
1147 intermediates); | 1153 intermediates); |
1148 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); | 1154 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); |
1149 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); | 1155 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); |
1150 | 1156 |
1151 CertVerifyResult verify_result; | 1157 CertVerifyResult verify_result; |
1152 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); | 1158 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
1153 int error = google_full_chain->Verify("127.0.0.1", 0, NULL, &verify_result); | 1159 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result); |
1154 EXPECT_EQ(OK, error); | 1160 EXPECT_EQ(OK, error); |
1155 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); | 1161 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
1156 | 1162 |
1157 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 1163 EXPECT_NE(google_full_chain, verify_result.verified_cert); |
1158 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 1164 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
1159 google_full_chain->os_cert_handle(), | 1165 google_full_chain->os_cert_handle(), |
1160 verify_result.verified_cert->os_cert_handle())); | 1166 verify_result.verified_cert->os_cert_handle())); |
1161 const X509Certificate::OSCertHandles& return_intermediates = | 1167 const X509Certificate::OSCertHandles& return_intermediates = |
1162 verify_result.verified_cert->GetIntermediateCertificates(); | 1168 verify_result.verified_cert->GetIntermediateCertificates(); |
1163 ASSERT_EQ(2U, return_intermediates.size()); | 1169 ASSERT_EQ(2U, return_intermediates.size()); |
1164 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 1170 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], |
1165 certs[1]->os_cert_handle())); | 1171 certs[1]->os_cert_handle())); |
1166 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 1172 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], |
1167 certs[2]->os_cert_handle())); | 1173 certs[2]->os_cert_handle())); |
1168 | 1174 |
1169 TestRootCerts::GetInstance()->Clear(); | 1175 TestRootCerts::GetInstance()->Clear(); |
1170 } | 1176 } |
1171 | 1177 |
1172 // Test that the certificate returned in CertVerifyResult is able to reorder | 1178 // Test that the certificate returned in CertVerifyResult is able to reorder |
1173 // certificates that are not ordered from end-entity to root. While this is | 1179 // certificates that are not ordered from end-entity to root. While this is |
1174 // a protocol violation if sent during a TLS handshake, if multiple sources | 1180 // a protocol violation if sent during a TLS handshake, if multiple sources |
1175 // of intermediate certificates are combined, it's possible that order may | 1181 // of intermediate certificates are combined, it's possible that order may |
1176 // not be maintained. | 1182 // not be maintained. |
1177 TEST(X509CertificateTest, VerifyReturnChainProperlyOrdered) { | 1183 TEST_F(X509CertificateTest, VerifyReturnChainProperlyOrdered) { |
1178 FilePath certs_dir = GetTestCertsDirectory(); | 1184 FilePath certs_dir = GetTestCertsDirectory(); |
1179 CertificateList certs = CreateCertificateListFromFile( | 1185 CertificateList certs = CreateCertificateListFromFile( |
1180 certs_dir, "x509_verify_results.chain.pem", | 1186 certs_dir, "x509_verify_results.chain.pem", |
1181 X509Certificate::FORMAT_AUTO); | 1187 X509Certificate::FORMAT_AUTO); |
1182 ASSERT_EQ(3U, certs.size()); | 1188 ASSERT_EQ(3U, certs.size()); |
1183 | 1189 |
1184 // Construct the chain out of order. | 1190 // Construct the chain out of order. |
1185 X509Certificate::OSCertHandles intermediates; | 1191 X509Certificate::OSCertHandles intermediates; |
1186 intermediates.push_back(certs[2]->os_cert_handle()); | 1192 intermediates.push_back(certs[2]->os_cert_handle()); |
1187 intermediates.push_back(certs[1]->os_cert_handle()); | 1193 intermediates.push_back(certs[1]->os_cert_handle()); |
1188 | 1194 |
1189 TestRootCerts::GetInstance()->Add(certs[2]); | 1195 TestRootCerts::GetInstance()->Add(certs[2]); |
1190 | 1196 |
1191 scoped_refptr<X509Certificate> google_full_chain = | 1197 scoped_refptr<X509Certificate> google_full_chain = |
1192 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 1198 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
1193 intermediates); | 1199 intermediates); |
1194 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); | 1200 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); |
1195 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); | 1201 ASSERT_EQ(2U, google_full_chain->GetIntermediateCertificates().size()); |
1196 | 1202 |
1197 CertVerifyResult verify_result; | 1203 CertVerifyResult verify_result; |
1198 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); | 1204 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
1199 int error = google_full_chain->Verify("127.0.0.1", 0, NULL, &verify_result); | 1205 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result); |
1200 EXPECT_EQ(OK, error); | 1206 EXPECT_EQ(OK, error); |
1201 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); | 1207 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
1202 | 1208 |
1203 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 1209 EXPECT_NE(google_full_chain, verify_result.verified_cert); |
1204 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 1210 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
1205 google_full_chain->os_cert_handle(), | 1211 google_full_chain->os_cert_handle(), |
1206 verify_result.verified_cert->os_cert_handle())); | 1212 verify_result.verified_cert->os_cert_handle())); |
1207 const X509Certificate::OSCertHandles& return_intermediates = | 1213 const X509Certificate::OSCertHandles& return_intermediates = |
1208 verify_result.verified_cert->GetIntermediateCertificates(); | 1214 verify_result.verified_cert->GetIntermediateCertificates(); |
1209 ASSERT_EQ(2U, return_intermediates.size()); | 1215 ASSERT_EQ(2U, return_intermediates.size()); |
1210 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 1216 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], |
1211 certs[1]->os_cert_handle())); | 1217 certs[1]->os_cert_handle())); |
1212 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 1218 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], |
1213 certs[2]->os_cert_handle())); | 1219 certs[2]->os_cert_handle())); |
1214 | 1220 |
1215 TestRootCerts::GetInstance()->Clear(); | 1221 TestRootCerts::GetInstance()->Clear(); |
1216 } | 1222 } |
1217 | 1223 |
1218 // Test that Verify() filters out certificates which are not related to | 1224 // Test that Verify() filters out certificates which are not related to |
1219 // or part of the certificate chain being verified. | 1225 // or part of the certificate chain being verified. |
1220 TEST(X509CertificateTest, VerifyReturnChainFiltersUnrelatedCerts) { | 1226 TEST_F(X509CertificateTest, VerifyReturnChainFiltersUnrelatedCerts) { |
1221 FilePath certs_dir = GetTestCertsDirectory(); | 1227 FilePath certs_dir = GetTestCertsDirectory(); |
1222 CertificateList certs = CreateCertificateListFromFile( | 1228 CertificateList certs = CreateCertificateListFromFile( |
1223 certs_dir, "x509_verify_results.chain.pem", | 1229 certs_dir, "x509_verify_results.chain.pem", |
1224 X509Certificate::FORMAT_AUTO); | 1230 X509Certificate::FORMAT_AUTO); |
1225 ASSERT_EQ(3U, certs.size()); | 1231 ASSERT_EQ(3U, certs.size()); |
1226 TestRootCerts::GetInstance()->Add(certs[2]); | 1232 TestRootCerts::GetInstance()->Add(certs[2]); |
1227 | 1233 |
1228 scoped_refptr<X509Certificate> unrelated_dod_certificate = | 1234 scoped_refptr<X509Certificate> unrelated_dod_certificate = |
1229 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); | 1235 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); |
1230 scoped_refptr<X509Certificate> unrelated_dod_certificate2 = | 1236 scoped_refptr<X509Certificate> unrelated_dod_certificate2 = |
1231 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der"); | 1237 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der"); |
1232 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate); | 1238 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate); |
1233 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate2); | 1239 ASSERT_NE(static_cast<X509Certificate*>(NULL), unrelated_dod_certificate2); |
1234 | 1240 |
1235 // Interject unrelated certificates into the list of intermediates. | 1241 // Interject unrelated certificates into the list of intermediates. |
1236 X509Certificate::OSCertHandles intermediates; | 1242 X509Certificate::OSCertHandles intermediates; |
1237 intermediates.push_back(unrelated_dod_certificate->os_cert_handle()); | 1243 intermediates.push_back(unrelated_dod_certificate->os_cert_handle()); |
1238 intermediates.push_back(certs[1]->os_cert_handle()); | 1244 intermediates.push_back(certs[1]->os_cert_handle()); |
1239 intermediates.push_back(unrelated_dod_certificate2->os_cert_handle()); | 1245 intermediates.push_back(unrelated_dod_certificate2->os_cert_handle()); |
1240 intermediates.push_back(certs[2]->os_cert_handle()); | 1246 intermediates.push_back(certs[2]->os_cert_handle()); |
1241 | 1247 |
1242 scoped_refptr<X509Certificate> google_full_chain = | 1248 scoped_refptr<X509Certificate> google_full_chain = |
1243 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 1249 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
1244 intermediates); | 1250 intermediates); |
1245 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); | 1251 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_full_chain); |
1246 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size()); | 1252 ASSERT_EQ(4U, google_full_chain->GetIntermediateCertificates().size()); |
1247 | 1253 |
1248 CertVerifyResult verify_result; | 1254 CertVerifyResult verify_result; |
1249 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); | 1255 EXPECT_EQ(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
1250 int error = google_full_chain->Verify("127.0.0.1", 0, NULL, &verify_result); | 1256 int error = Verify(google_full_chain, "127.0.0.1", 0, NULL, &verify_result); |
1251 EXPECT_EQ(OK, error); | 1257 EXPECT_EQ(OK, error); |
1252 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); | 1258 ASSERT_NE(static_cast<X509Certificate*>(NULL), verify_result.verified_cert); |
1253 | 1259 |
1254 EXPECT_NE(google_full_chain, verify_result.verified_cert); | 1260 EXPECT_NE(google_full_chain, verify_result.verified_cert); |
1255 EXPECT_TRUE(X509Certificate::IsSameOSCert( | 1261 EXPECT_TRUE(X509Certificate::IsSameOSCert( |
1256 google_full_chain->os_cert_handle(), | 1262 google_full_chain->os_cert_handle(), |
1257 verify_result.verified_cert->os_cert_handle())); | 1263 verify_result.verified_cert->os_cert_handle())); |
1258 const X509Certificate::OSCertHandles& return_intermediates = | 1264 const X509Certificate::OSCertHandles& return_intermediates = |
1259 verify_result.verified_cert->GetIntermediateCertificates(); | 1265 verify_result.verified_cert->GetIntermediateCertificates(); |
1260 ASSERT_EQ(2U, return_intermediates.size()); | 1266 ASSERT_EQ(2U, return_intermediates.size()); |
1261 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], | 1267 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[0], |
1262 certs[1]->os_cert_handle())); | 1268 certs[1]->os_cert_handle())); |
1263 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], | 1269 EXPECT_TRUE(X509Certificate::IsSameOSCert(return_intermediates[1], |
1264 certs[2]->os_cert_handle())); | 1270 certs[2]->os_cert_handle())); |
1265 TestRootCerts::GetInstance()->Clear(); | 1271 TestRootCerts::GetInstance()->Clear(); |
1266 } | 1272 } |
1267 | 1273 |
1268 #if defined(OS_MACOSX) | 1274 #if defined(OS_MACOSX) |
1269 TEST(X509CertificateTest, IsIssuedBy) { | 1275 TEST_F(X509CertificateTest, IsIssuedBy) { |
1270 FilePath certs_dir = GetTestCertsDirectory(); | 1276 FilePath certs_dir = GetTestCertsDirectory(); |
1271 | 1277 |
1272 // Test a client certificate from MIT. | 1278 // Test a client certificate from MIT. |
1273 scoped_refptr<X509Certificate> mit_davidben_cert( | 1279 scoped_refptr<X509Certificate> mit_davidben_cert( |
1274 ImportCertFromFile(certs_dir, "mit.davidben.der")); | 1280 ImportCertFromFile(certs_dir, "mit.davidben.der")); |
1275 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert); | 1281 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert); |
1276 | 1282 |
1277 CertPrincipal mit_issuer; | 1283 CertPrincipal mit_issuer; |
1278 mit_issuer.country_name = "US"; | 1284 mit_issuer.country_name = "US"; |
1279 mit_issuer.state_or_province_name = "Massachusetts"; | 1285 mit_issuer.state_or_province_name = "Massachusetts"; |
(...skipping 28 matching lines...) Expand all Loading... | |
1308 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers)); | 1314 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers)); |
1309 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers)); | 1315 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers)); |
1310 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers)); | 1316 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers)); |
1311 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers)); | 1317 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers)); |
1312 } | 1318 } |
1313 #endif // defined(OS_MACOSX) | 1319 #endif // defined(OS_MACOSX) |
1314 | 1320 |
1315 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) | 1321 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) |
1316 // This test creates a self-signed cert from a private key and then verify the | 1322 // This test creates a self-signed cert from a private key and then verify the |
1317 // content of the certificate. | 1323 // content of the certificate. |
1318 TEST(X509CertificateTest, CreateSelfSigned) { | 1324 TEST_F(X509CertificateTest, CreateSelfSigned) { |
1319 scoped_ptr<crypto::RSAPrivateKey> private_key( | 1325 scoped_ptr<crypto::RSAPrivateKey> private_key( |
1320 crypto::RSAPrivateKey::Create(1024)); | 1326 crypto::RSAPrivateKey::Create(1024)); |
1321 scoped_refptr<X509Certificate> cert = | 1327 scoped_refptr<X509Certificate> cert = |
1322 X509Certificate::CreateSelfSigned( | 1328 X509Certificate::CreateSelfSigned( |
1323 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); | 1329 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); |
1324 | 1330 |
1325 EXPECT_EQ("subject", cert->subject().GetDisplayName()); | 1331 EXPECT_EQ("subject", cert->subject().GetDisplayName()); |
1326 EXPECT_FALSE(cert->HasExpired()); | 1332 EXPECT_FALSE(cert->HasExpired()); |
1327 | 1333 |
1328 const uint8 private_key_info[] = { | 1334 const uint8 private_key_info[] = { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1415 private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); | 1421 private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); |
1416 ASSERT_TRUE(private_key.get()); | 1422 ASSERT_TRUE(private_key.get()); |
1417 | 1423 |
1418 cert = X509Certificate::CreateSelfSigned( | 1424 cert = X509Certificate::CreateSelfSigned( |
1419 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); | 1425 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); |
1420 | 1426 |
1421 EXPECT_EQ("subject", cert->subject().GetDisplayName()); | 1427 EXPECT_EQ("subject", cert->subject().GetDisplayName()); |
1422 EXPECT_FALSE(cert->HasExpired()); | 1428 EXPECT_FALSE(cert->HasExpired()); |
1423 } | 1429 } |
1424 | 1430 |
1425 TEST(X509CertificateTest, GetDEREncoded) { | 1431 TEST_F(X509CertificateTest, GetDEREncoded) { |
1426 scoped_ptr<crypto::RSAPrivateKey> private_key( | 1432 scoped_ptr<crypto::RSAPrivateKey> private_key( |
1427 crypto::RSAPrivateKey::Create(1024)); | 1433 crypto::RSAPrivateKey::Create(1024)); |
1428 scoped_refptr<X509Certificate> cert = | 1434 scoped_refptr<X509Certificate> cert = |
1429 X509Certificate::CreateSelfSigned( | 1435 X509Certificate::CreateSelfSigned( |
1430 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1)); | 1436 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1)); |
1431 | 1437 |
1432 std::string der_cert; | 1438 std::string der_cert; |
1433 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), | 1439 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), |
1434 &der_cert)); | 1440 &der_cert)); |
1435 EXPECT_FALSE(der_cert.empty()); | 1441 EXPECT_FALSE(der_cert.empty()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1480 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, | 1486 0x31, 0x2c, 0x22, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x50, 0x4b, |
1481 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xe9, 0x7e, 0x8c, 0xc5, 0x1e, 0xd7, | 1487 0x49, 0x73, 0x22, 0x3a, 0x5b, 0x5d, 0x7d, 0xe9, 0x7e, 0x8c, 0xc5, 0x1e, 0xd7, |
1482 0xa4, 0xc4, 0x0a, 0xc4, 0x80, 0x3d, 0x3e, 0x3e, 0xbb, 0xeb, 0xcb, 0xed, 0x52, | 1488 0xa4, 0xc4, 0x0a, 0xc4, 0x80, 0x3d, 0x3e, 0x3e, 0xbb, 0xeb, 0xcb, 0xed, 0x52, |
1483 0x49, 0x33, 0x1f, 0x2c, 0xc0, 0xa2, 0x6a, 0x0e, 0x84, 0xa5, 0x27, 0xce, 0xc5, | 1489 0x49, 0x33, 0x1f, 0x2c, 0xc0, 0xa2, 0x6a, 0x0e, 0x84, 0xa5, 0x27, 0xce, 0xc5, |
1484 0x01, 0x00, 0x00, 0x00, 0x10, 0x4f, 0x9d, 0x96, 0xd9, 0x66, 0xb0, 0x99, 0x2b, | 1490 0x01, 0x00, 0x00, 0x00, 0x10, 0x4f, 0x9d, 0x96, 0xd9, 0x66, 0xb0, 0x99, 0x2b, |
1485 0x54, 0xc2, 0x95, 0x7c, 0xb4, 0x15, 0x7d, 0x4d, | 1491 0x54, 0xc2, 0x95, 0x7c, 0xb4, 0x15, 0x7d, 0x4d, |
1486 }; | 1492 }; |
1487 | 1493 |
1488 // Test that CRLSets are effective in making a certificate appear to be | 1494 // Test that CRLSets are effective in making a certificate appear to be |
1489 // revoked. | 1495 // revoked. |
1490 TEST(X509CertificateTest, CRLSet) { | 1496 TEST_F(X509CertificateTest, CRLSet) { |
1491 CertificateList certs = CreateCertificateListFromFile( | 1497 CertificateList certs = CreateCertificateListFromFile( |
1492 GetTestCertsDirectory(), | 1498 GetTestCertsDirectory(), |
1493 "googlenew.chain.pem", | 1499 "googlenew.chain.pem", |
1494 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | 1500 X509Certificate::FORMAT_PEM_CERT_SEQUENCE); |
1495 | 1501 |
1496 X509Certificate::OSCertHandles intermediates; | 1502 X509Certificate::OSCertHandles intermediates; |
1497 intermediates.push_back(certs[1]->os_cert_handle()); | 1503 intermediates.push_back(certs[1]->os_cert_handle()); |
1498 | 1504 |
1499 scoped_refptr<X509Certificate> google_full_chain = | 1505 scoped_refptr<X509Certificate> google_full_chain = |
1500 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), | 1506 X509Certificate::CreateFromHandle(certs[0]->os_cert_handle(), |
1501 intermediates); | 1507 intermediates); |
1502 | 1508 |
1503 CertVerifyResult verify_result; | 1509 CertVerifyResult verify_result; |
1504 int error = google_full_chain->Verify( | 1510 int error = Verify(google_full_chain, "www.google.com", 0, NULL, |
1505 "www.google.com", 0, NULL, &verify_result); | 1511 &verify_result); |
1506 EXPECT_EQ(OK, error); | 1512 EXPECT_EQ(OK, error); |
1507 | 1513 |
1508 // First test blocking by SPKI. | 1514 // First test blocking by SPKI. |
1509 base::StringPiece crl_set_bytes( | 1515 base::StringPiece crl_set_bytes( |
1510 reinterpret_cast<const char*>(kCRLSetThawteSPKIBlocked), | 1516 reinterpret_cast<const char*>(kCRLSetThawteSPKIBlocked), |
1511 sizeof(kCRLSetThawteSPKIBlocked)); | 1517 sizeof(kCRLSetThawteSPKIBlocked)); |
1512 scoped_refptr<CRLSet> crl_set; | 1518 scoped_refptr<CRLSet> crl_set; |
1513 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); | 1519 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); |
1514 | 1520 |
1515 error = google_full_chain->Verify( | 1521 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(), |
1516 "www.google.com", 0, crl_set.get(), &verify_result); | 1522 &verify_result); |
1517 EXPECT_EQ(ERR_CERT_REVOKED, error); | 1523 EXPECT_EQ(ERR_CERT_REVOKED, error); |
1518 | 1524 |
1519 // Second, test revocation by serial number of a cert directly under the | 1525 // Second, test revocation by serial number of a cert directly under the |
1520 // root. | 1526 // root. |
1521 crl_set_bytes = base::StringPiece( | 1527 crl_set_bytes = base::StringPiece( |
1522 reinterpret_cast<const char*>(kCRLSetThawteSerialBlocked), | 1528 reinterpret_cast<const char*>(kCRLSetThawteSerialBlocked), |
1523 sizeof(kCRLSetThawteSerialBlocked)); | 1529 sizeof(kCRLSetThawteSerialBlocked)); |
1524 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); | 1530 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); |
1525 | 1531 |
1526 error = google_full_chain->Verify( | 1532 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(), |
1527 "www.google.com", 0, crl_set.get(), &verify_result); | 1533 &verify_result); |
1528 EXPECT_EQ(ERR_CERT_REVOKED, error); | 1534 EXPECT_EQ(ERR_CERT_REVOKED, error); |
1529 | 1535 |
1530 // Lastly, test revocation by serial number of a certificate not under the | 1536 // Lastly, test revocation by serial number of a certificate not under the |
1531 // root. | 1537 // root. |
1532 crl_set_bytes = base::StringPiece( | 1538 crl_set_bytes = base::StringPiece( |
1533 reinterpret_cast<const char*>(kCRLSetGoogleSerialBlocked), | 1539 reinterpret_cast<const char*>(kCRLSetGoogleSerialBlocked), |
1534 sizeof(kCRLSetGoogleSerialBlocked)); | 1540 sizeof(kCRLSetGoogleSerialBlocked)); |
1535 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); | 1541 ASSERT_TRUE(CRLSet::Parse(crl_set_bytes, &crl_set)); |
1536 | 1542 |
1537 error = google_full_chain->Verify( | 1543 error = Verify(google_full_chain, "www.google.com", 0, crl_set.get(), |
1538 "www.google.com", 0, crl_set.get(), &verify_result); | 1544 &verify_result); |
1539 EXPECT_EQ(ERR_CERT_REVOKED, error); | 1545 EXPECT_EQ(ERR_CERT_REVOKED, error); |
1540 } | 1546 } |
1541 #endif | 1547 #endif |
1542 | 1548 |
1543 class X509CertificateParseTest | 1549 class X509CertificateParseTest |
1544 : public testing::TestWithParam<CertificateFormatTestData> { | 1550 : public testing::TestWithParam<CertificateFormatTestData> { |
1545 public: | 1551 public: |
1546 virtual ~X509CertificateParseTest() {} | 1552 virtual ~X509CertificateParseTest() {} |
1547 virtual void SetUp() { | 1553 virtual void SetUp() { |
1548 test_data_ = GetParam(); | 1554 test_data_ = GetParam(); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1816 // attempt to print out the first twenty bytes of the object, which depending | 1822 // attempt to print out the first twenty bytes of the object, which depending |
1817 // on platform and alignment, may result in an invalid read. | 1823 // on platform and alignment, may result in an invalid read. |
1818 void PrintTo(const WeakDigestTestData& data, std::ostream* os) { | 1824 void PrintTo(const WeakDigestTestData& data, std::ostream* os) { |
1819 *os << "root: " | 1825 *os << "root: " |
1820 << (data.root_cert_filename ? data.root_cert_filename : "none") | 1826 << (data.root_cert_filename ? data.root_cert_filename : "none") |
1821 << "; intermediate: " << data.intermediate_cert_filename | 1827 << "; intermediate: " << data.intermediate_cert_filename |
1822 << "; end-entity: " << data.ee_cert_filename; | 1828 << "; end-entity: " << data.ee_cert_filename; |
1823 } | 1829 } |
1824 | 1830 |
1825 class X509CertificateWeakDigestTest | 1831 class X509CertificateWeakDigestTest |
1826 : public testing::TestWithParam<WeakDigestTestData> { | 1832 : public X509CertificateTest, |
1833 public testing::WithParamInterface<WeakDigestTestData> { | |
1827 public: | 1834 public: |
1828 X509CertificateWeakDigestTest() {} | 1835 X509CertificateWeakDigestTest() {} |
1829 | 1836 |
1830 virtual void TearDown() { | 1837 virtual void TearDown() { |
1831 TestRootCerts::GetInstance()->Clear(); | 1838 TestRootCerts::GetInstance()->Clear(); |
1832 } | 1839 } |
1833 }; | 1840 }; |
1834 | 1841 |
1835 TEST_P(X509CertificateWeakDigestTest, Verify) { | 1842 TEST_P(X509CertificateWeakDigestTest, Verify) { |
1836 WeakDigestTestData data = GetParam(); | 1843 WeakDigestTestData data = GetParam(); |
(...skipping 16 matching lines...) Expand all Loading... | |
1853 X509Certificate::OSCertHandles intermediates; | 1860 X509Certificate::OSCertHandles intermediates; |
1854 intermediates.push_back(intermediate_cert->os_cert_handle()); | 1861 intermediates.push_back(intermediate_cert->os_cert_handle()); |
1855 | 1862 |
1856 scoped_refptr<X509Certificate> ee_chain = | 1863 scoped_refptr<X509Certificate> ee_chain = |
1857 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), | 1864 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), |
1858 intermediates); | 1865 intermediates); |
1859 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain); | 1866 ASSERT_NE(static_cast<X509Certificate*>(NULL), ee_chain); |
1860 | 1867 |
1861 int flags = 0; | 1868 int flags = 0; |
1862 CertVerifyResult verify_result; | 1869 CertVerifyResult verify_result; |
1863 int rv = ee_chain->Verify("127.0.0.1", flags, NULL, &verify_result); | 1870 int rv = Verify(ee_chain, "127.0.0.1", flags, NULL, &verify_result); |
1864 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5); | 1871 EXPECT_EQ(data.expected_has_md5, verify_result.has_md5); |
1865 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4); | 1872 EXPECT_EQ(data.expected_has_md4, verify_result.has_md4); |
1866 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2); | 1873 EXPECT_EQ(data.expected_has_md2, verify_result.has_md2); |
1867 EXPECT_EQ(data.expected_has_md5_ca, verify_result.has_md5_ca); | 1874 EXPECT_EQ(data.expected_has_md5_ca, verify_result.has_md5_ca); |
1868 EXPECT_EQ(data.expected_has_md2_ca, verify_result.has_md2_ca); | 1875 EXPECT_EQ(data.expected_has_md2_ca, verify_result.has_md2_ca); |
1869 | 1876 |
1870 // Ensure that MD4 and MD2 are tagged as invalid. | 1877 // Ensure that MD4 and MD2 are tagged as invalid. |
1871 if (data.expected_has_md4 || data.expected_has_md2) { | 1878 if (data.expected_has_md4 || data.expected_has_md2) { |
1872 EXPECT_EQ(CERT_STATUS_INVALID, | 1879 EXPECT_EQ(CERT_STATUS_INVALID, |
1873 verify_result.cert_status & CERT_STATUS_INVALID); | 1880 verify_result.cert_status & CERT_STATUS_INVALID); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2027 #define MAYBE_VerifyMixed DISABLED_VerifyMixed | 2034 #define MAYBE_VerifyMixed DISABLED_VerifyMixed |
2028 #else | 2035 #else |
2029 #define MAYBE_VerifyMixed VerifyMixed | 2036 #define MAYBE_VerifyMixed VerifyMixed |
2030 #endif | 2037 #endif |
2031 WRAPPED_INSTANTIATE_TEST_CASE_P( | 2038 WRAPPED_INSTANTIATE_TEST_CASE_P( |
2032 MAYBE_VerifyMixed, | 2039 MAYBE_VerifyMixed, |
2033 X509CertificateWeakDigestTest, | 2040 X509CertificateWeakDigestTest, |
2034 testing::ValuesIn(kVerifyMixedTestData)); | 2041 testing::ValuesIn(kVerifyMixedTestData)); |
2035 | 2042 |
2036 } // namespace net | 2043 } // namespace net |
OLD | NEW |