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