OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "net/base/cert_status_flags.h" | 9 #include "net/base/cert_status_flags.h" |
10 #include "net/base/cert_test_util.h" | 10 #include "net/base/cert_test_util.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // TODO(avi): turn this on for the Mac once EV checking is implemented. | 245 // TODO(avi): turn this on for the Mac once EV checking is implemented. |
246 CertVerifyResult verify_result; | 246 CertVerifyResult verify_result; |
247 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | | 247 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | |
248 X509Certificate::VERIFY_EV_CERT; | 248 X509Certificate::VERIFY_EV_CERT; |
249 EXPECT_EQ(OK, google_cert->Verify("www.google.com", flags, &verify_result)); | 249 EXPECT_EQ(OK, google_cert->Verify("www.google.com", flags, &verify_result)); |
250 EXPECT_EQ(0, verify_result.cert_status & CERT_STATUS_IS_EV); | 250 EXPECT_EQ(0, verify_result.cert_status & CERT_STATUS_IS_EV); |
251 #endif | 251 #endif |
252 } | 252 } |
253 | 253 |
254 TEST(X509CertificateTest, GoogleCertParsing) { | 254 TEST(X509CertificateTest, GoogleCertParsing) { |
255 scoped_refptr<X509Certificate> google_cert = | 255 scoped_refptr<X509Certificate> google_cert( |
256 X509Certificate::CreateFromBytes( | 256 X509Certificate::CreateFromBytes( |
257 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 257 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
258 | 258 |
259 CheckGoogleCert(google_cert, google_fingerprint, | 259 CheckGoogleCert(google_cert, google_fingerprint, |
260 1238192407, // Mar 27 22:20:07 2009 GMT | 260 1238192407, // Mar 27 22:20:07 2009 GMT |
261 1269728407); // Mar 27 22:20:07 2010 GMT | 261 1269728407); // Mar 27 22:20:07 2010 GMT |
262 } | 262 } |
263 | 263 |
264 TEST(X509CertificateTest, WebkitCertParsing) { | 264 TEST(X509CertificateTest, WebkitCertParsing) { |
265 scoped_refptr<X509Certificate> webkit_cert = X509Certificate::CreateFromBytes( | 265 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( |
266 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)); | 266 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); |
267 | 267 |
268 ASSERT_NE(static_cast<X509Certificate*>(NULL), webkit_cert); | 268 ASSERT_NE(static_cast<X509Certificate*>(NULL), webkit_cert); |
269 | 269 |
270 const CertPrincipal& subject = webkit_cert->subject(); | 270 const CertPrincipal& subject = webkit_cert->subject(); |
271 EXPECT_EQ("Cupertino", subject.locality_name); | 271 EXPECT_EQ("Cupertino", subject.locality_name); |
272 EXPECT_EQ("California", subject.state_or_province_name); | 272 EXPECT_EQ("California", subject.state_or_province_name); |
273 EXPECT_EQ("US", subject.country_name); | 273 EXPECT_EQ("US", subject.country_name); |
274 EXPECT_EQ(0U, subject.street_addresses.size()); | 274 EXPECT_EQ(0U, subject.street_addresses.size()); |
275 ASSERT_EQ(1U, subject.organization_names.size()); | 275 ASSERT_EQ(1U, subject.organization_names.size()); |
276 EXPECT_EQ("Apple Inc.", subject.organization_names[0]); | 276 EXPECT_EQ("Apple Inc.", subject.organization_names[0]); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 #if TEST_EV | 311 #if TEST_EV |
312 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | | 312 int flags = X509Certificate::VERIFY_REV_CHECKING_ENABLED | |
313 X509Certificate::VERIFY_EV_CERT; | 313 X509Certificate::VERIFY_EV_CERT; |
314 CertVerifyResult verify_result; | 314 CertVerifyResult verify_result; |
315 EXPECT_EQ(OK, webkit_cert->Verify("webkit.org", flags, &verify_result)); | 315 EXPECT_EQ(OK, webkit_cert->Verify("webkit.org", flags, &verify_result)); |
316 EXPECT_EQ(0, verify_result.cert_status & CERT_STATUS_IS_EV); | 316 EXPECT_EQ(0, verify_result.cert_status & CERT_STATUS_IS_EV); |
317 #endif | 317 #endif |
318 } | 318 } |
319 | 319 |
320 TEST(X509CertificateTest, ThawteCertParsing) { | 320 TEST(X509CertificateTest, ThawteCertParsing) { |
321 scoped_refptr<X509Certificate> thawte_cert = X509Certificate::CreateFromBytes( | 321 scoped_refptr<X509Certificate> thawte_cert(X509Certificate::CreateFromBytes( |
322 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)); | 322 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); |
323 | 323 |
324 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert); | 324 ASSERT_NE(static_cast<X509Certificate*>(NULL), thawte_cert); |
325 | 325 |
326 const CertPrincipal& subject = thawte_cert->subject(); | 326 const CertPrincipal& subject = thawte_cert->subject(); |
327 EXPECT_EQ("www.thawte.com", subject.common_name); | 327 EXPECT_EQ("www.thawte.com", subject.common_name); |
328 EXPECT_EQ("Mountain View", subject.locality_name); | 328 EXPECT_EQ("Mountain View", subject.locality_name); |
329 EXPECT_EQ("California", subject.state_or_province_name); | 329 EXPECT_EQ("California", subject.state_or_province_name); |
330 EXPECT_EQ("US", subject.country_name); | 330 EXPECT_EQ("US", subject.country_name); |
331 EXPECT_EQ(0U, subject.street_addresses.size()); | 331 EXPECT_EQ(0U, subject.street_addresses.size()); |
332 ASSERT_EQ(1U, subject.organization_names.size()); | 332 ASSERT_EQ(1U, subject.organization_names.size()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 EXPECT_NE(0, verify_result.cert_status & CERT_STATUS_IS_EV); | 372 EXPECT_NE(0, verify_result.cert_status & CERT_STATUS_IS_EV); |
373 // Consequently, if we don't have revocation checking enabled, we can't claim | 373 // Consequently, if we don't have revocation checking enabled, we can't claim |
374 // any cert is EV. | 374 // any cert is EV. |
375 flags = X509Certificate::VERIFY_EV_CERT; | 375 flags = X509Certificate::VERIFY_EV_CERT; |
376 EXPECT_EQ(OK, thawte_cert->Verify("www.thawte.com", flags, &verify_result)); | 376 EXPECT_EQ(OK, thawte_cert->Verify("www.thawte.com", flags, &verify_result)); |
377 EXPECT_EQ(0, verify_result.cert_status & CERT_STATUS_IS_EV); | 377 EXPECT_EQ(0, verify_result.cert_status & CERT_STATUS_IS_EV); |
378 #endif | 378 #endif |
379 } | 379 } |
380 | 380 |
381 TEST(X509CertificateTest, PaypalNullCertParsing) { | 381 TEST(X509CertificateTest, PaypalNullCertParsing) { |
382 scoped_refptr<X509Certificate> paypal_null_cert = | 382 scoped_refptr<X509Certificate> paypal_null_cert( |
383 X509Certificate::CreateFromBytes( | 383 X509Certificate::CreateFromBytes( |
384 reinterpret_cast<const char*>(paypal_null_der), | 384 reinterpret_cast<const char*>(paypal_null_der), |
385 sizeof(paypal_null_der)); | 385 sizeof(paypal_null_der))); |
386 | 386 |
387 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert); | 387 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert); |
388 | 388 |
389 const SHA1Fingerprint& fingerprint = | 389 const SHA1Fingerprint& fingerprint = |
390 paypal_null_cert->fingerprint(); | 390 paypal_null_cert->fingerprint(); |
391 for (size_t i = 0; i < 20; ++i) | 391 for (size_t i = 0; i < 20; ++i) |
392 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]); | 392 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]); |
393 | 393 |
394 int flags = 0; | 394 int flags = 0; |
395 CertVerifyResult verify_result; | 395 CertVerifyResult verify_result; |
396 int error = paypal_null_cert->Verify("www.paypal.com", flags, | 396 int error = paypal_null_cert->Verify("www.paypal.com", flags, |
397 &verify_result); | 397 &verify_result); |
398 EXPECT_NE(OK, error); | 398 EXPECT_NE(OK, error); |
399 // Either the system crypto library should correctly report a certificate | 399 // Either the system crypto library should correctly report a certificate |
400 // name mismatch, or our certificate blacklist should cause us to report an | 400 // name mismatch, or our certificate blacklist should cause us to report an |
401 // invalid certificate. | 401 // invalid certificate. |
402 #if !defined(OS_MACOSX) && !defined(USE_OPENSSL) | 402 #if !defined(OS_MACOSX) && !defined(USE_OPENSSL) |
403 EXPECT_NE(0, verify_result.cert_status & | 403 EXPECT_NE(0, verify_result.cert_status & |
404 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); | 404 (CERT_STATUS_COMMON_NAME_INVALID | CERT_STATUS_INVALID)); |
405 #endif | 405 #endif |
406 } | 406 } |
407 | 407 |
408 // A certificate whose AIA extension contains an LDAP URL without a host name. | 408 // A certificate whose AIA extension contains an LDAP URL without a host name. |
409 // This certificate will expire on 2011-09-08. | 409 // This certificate will expire on 2011-09-08. |
410 TEST(X509CertificateTest, UnoSoftCertParsing) { | 410 TEST(X509CertificateTest, UnoSoftCertParsing) { |
411 FilePath certs_dir = GetTestCertsDirectory(); | 411 FilePath certs_dir = GetTestCertsDirectory(); |
412 scoped_refptr<X509Certificate> unosoft_hu_cert = | 412 scoped_refptr<X509Certificate> unosoft_hu_cert( |
413 ImportCertFromFile(certs_dir, "unosoft_hu_cert.der"); | 413 ImportCertFromFile(certs_dir, "unosoft_hu_cert.der")); |
414 | 414 |
415 ASSERT_NE(static_cast<X509Certificate*>(NULL), unosoft_hu_cert); | 415 ASSERT_NE(static_cast<X509Certificate*>(NULL), unosoft_hu_cert); |
416 | 416 |
417 const SHA1Fingerprint& fingerprint = | 417 const SHA1Fingerprint& fingerprint = |
418 unosoft_hu_cert->fingerprint(); | 418 unosoft_hu_cert->fingerprint(); |
419 for (size_t i = 0; i < 20; ++i) | 419 for (size_t i = 0; i < 20; ++i) |
420 EXPECT_EQ(unosoft_hu_fingerprint[i], fingerprint.data[i]); | 420 EXPECT_EQ(unosoft_hu_fingerprint[i], fingerprint.data[i]); |
421 | 421 |
422 int flags = 0; | 422 int flags = 0; |
423 CertVerifyResult verify_result; | 423 CertVerifyResult verify_result; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 // All the OS certificate handles in this test are actually from the same | 474 // All the OS certificate handles in this test are actually from the same |
475 // source (the bytes of a lone certificate), but we pretend that some of them | 475 // source (the bytes of a lone certificate), but we pretend that some of them |
476 // come from the network. | 476 // come from the network. |
477 TEST(X509CertificateTest, Cache) { | 477 TEST(X509CertificateTest, Cache) { |
478 X509Certificate::OSCertHandle google_cert_handle; | 478 X509Certificate::OSCertHandle google_cert_handle; |
479 | 479 |
480 // Add a certificate from the source SOURCE_LONE_CERT_IMPORT to our | 480 // Add a certificate from the source SOURCE_LONE_CERT_IMPORT to our |
481 // certificate cache. | 481 // certificate cache. |
482 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( | 482 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( |
483 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 483 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
484 scoped_refptr<X509Certificate> cert1 = X509Certificate::CreateFromHandle( | 484 scoped_refptr<X509Certificate> cert1(X509Certificate::CreateFromHandle( |
485 google_cert_handle, X509Certificate::SOURCE_LONE_CERT_IMPORT, | 485 google_cert_handle, X509Certificate::SOURCE_LONE_CERT_IMPORT, |
486 X509Certificate::OSCertHandles()); | 486 X509Certificate::OSCertHandles())); |
487 X509Certificate::FreeOSCertHandle(google_cert_handle); | 487 X509Certificate::FreeOSCertHandle(google_cert_handle); |
488 | 488 |
489 // Add a certificate from the same source (SOURCE_LONE_CERT_IMPORT). This | 489 // Add a certificate from the same source (SOURCE_LONE_CERT_IMPORT). This |
490 // should return the cached certificate (cert1). | 490 // should return the cached certificate (cert1). |
491 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( | 491 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( |
492 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 492 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
493 scoped_refptr<X509Certificate> cert2 = X509Certificate::CreateFromHandle( | 493 scoped_refptr<X509Certificate> cert2(X509Certificate::CreateFromHandle( |
494 google_cert_handle, X509Certificate::SOURCE_LONE_CERT_IMPORT, | 494 google_cert_handle, X509Certificate::SOURCE_LONE_CERT_IMPORT, |
495 X509Certificate::OSCertHandles()); | 495 X509Certificate::OSCertHandles())); |
496 X509Certificate::FreeOSCertHandle(google_cert_handle); | 496 X509Certificate::FreeOSCertHandle(google_cert_handle); |
497 | 497 |
498 EXPECT_EQ(cert1, cert2); | 498 EXPECT_EQ(cert1, cert2); |
499 | 499 |
500 // Add a certificate from the network. This should kick out the original | 500 // Add a certificate from the network. This should kick out the original |
501 // cached certificate (cert1) and return a new certificate. | 501 // cached certificate (cert1) and return a new certificate. |
502 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( | 502 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( |
503 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 503 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
504 scoped_refptr<X509Certificate> cert3 = X509Certificate::CreateFromHandle( | 504 scoped_refptr<X509Certificate> cert3(X509Certificate::CreateFromHandle( |
505 google_cert_handle, X509Certificate::SOURCE_FROM_NETWORK, | 505 google_cert_handle, X509Certificate::SOURCE_FROM_NETWORK, |
506 X509Certificate::OSCertHandles()); | 506 X509Certificate::OSCertHandles())); |
507 X509Certificate::FreeOSCertHandle(google_cert_handle); | 507 X509Certificate::FreeOSCertHandle(google_cert_handle); |
508 | 508 |
509 EXPECT_NE(cert1, cert3); | 509 EXPECT_NE(cert1, cert3); |
510 | 510 |
511 // Add one certificate from each source. Both should return the new cached | 511 // Add one certificate from each source. Both should return the new cached |
512 // certificate (cert3). | 512 // certificate (cert3). |
513 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( | 513 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( |
514 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 514 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
515 scoped_refptr<X509Certificate> cert4 = X509Certificate::CreateFromHandle( | 515 scoped_refptr<X509Certificate> cert4(X509Certificate::CreateFromHandle( |
516 google_cert_handle, X509Certificate::SOURCE_FROM_NETWORK, | 516 google_cert_handle, X509Certificate::SOURCE_FROM_NETWORK, |
517 X509Certificate::OSCertHandles()); | 517 X509Certificate::OSCertHandles())); |
518 X509Certificate::FreeOSCertHandle(google_cert_handle); | 518 X509Certificate::FreeOSCertHandle(google_cert_handle); |
519 | 519 |
520 EXPECT_EQ(cert3, cert4); | 520 EXPECT_EQ(cert3, cert4); |
521 | 521 |
522 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( | 522 google_cert_handle = X509Certificate::CreateOSCertHandleFromBytes( |
523 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 523 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
524 scoped_refptr<X509Certificate> cert5 = X509Certificate::CreateFromHandle( | 524 scoped_refptr<X509Certificate> cert5(X509Certificate::CreateFromHandle( |
525 google_cert_handle, X509Certificate::SOURCE_FROM_NETWORK, | 525 google_cert_handle, X509Certificate::SOURCE_FROM_NETWORK, |
526 X509Certificate::OSCertHandles()); | 526 X509Certificate::OSCertHandles())); |
527 X509Certificate::FreeOSCertHandle(google_cert_handle); | 527 X509Certificate::FreeOSCertHandle(google_cert_handle); |
528 | 528 |
529 EXPECT_EQ(cert3, cert5); | 529 EXPECT_EQ(cert3, cert5); |
530 } | 530 } |
531 | 531 |
532 TEST(X509CertificateTest, Pickle) { | 532 TEST(X509CertificateTest, Pickle) { |
533 scoped_refptr<X509Certificate> cert1 = X509Certificate::CreateFromBytes( | 533 scoped_refptr<X509Certificate> cert1(X509Certificate::CreateFromBytes( |
534 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 534 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
535 | 535 |
536 Pickle pickle; | 536 Pickle pickle; |
537 cert1->Persist(&pickle); | 537 cert1->Persist(&pickle); |
538 | 538 |
539 void* iter = NULL; | 539 void* iter = NULL; |
540 scoped_refptr<X509Certificate> cert2 = | 540 scoped_refptr<X509Certificate> cert2( |
541 X509Certificate::CreateFromPickle(pickle, &iter); | 541 X509Certificate::CreateFromPickle(pickle, &iter)); |
542 | 542 |
543 EXPECT_EQ(cert1, cert2); | 543 EXPECT_EQ(cert1, cert2); |
544 } | 544 } |
545 | 545 |
546 TEST(X509CertificateTest, Policy) { | 546 TEST(X509CertificateTest, Policy) { |
547 scoped_refptr<X509Certificate> google_cert = X509Certificate::CreateFromBytes( | 547 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes( |
548 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 548 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
549 | 549 |
550 scoped_refptr<X509Certificate> webkit_cert = X509Certificate::CreateFromBytes( | 550 scoped_refptr<X509Certificate> webkit_cert(X509Certificate::CreateFromBytes( |
551 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)); | 551 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); |
552 | 552 |
553 CertPolicy policy; | 553 CertPolicy policy; |
554 | 554 |
555 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::UNKNOWN); | 555 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::UNKNOWN); |
556 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::UNKNOWN); | 556 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::UNKNOWN); |
557 EXPECT_FALSE(policy.HasAllowedCert()); | 557 EXPECT_FALSE(policy.HasAllowedCert()); |
558 EXPECT_FALSE(policy.HasDeniedCert()); | 558 EXPECT_FALSE(policy.HasDeniedCert()); |
559 | 559 |
560 policy.Allow(google_cert.get()); | 560 policy.Allow(google_cert.get()); |
561 | 561 |
(...skipping 12 matching lines...) Expand all Loading... |
574 policy.Allow(webkit_cert.get()); | 574 policy.Allow(webkit_cert.get()); |
575 | 575 |
576 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::DENIED); | 576 EXPECT_EQ(policy.Check(google_cert.get()), CertPolicy::DENIED); |
577 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::ALLOWED); | 577 EXPECT_EQ(policy.Check(webkit_cert.get()), CertPolicy::ALLOWED); |
578 EXPECT_TRUE(policy.HasAllowedCert()); | 578 EXPECT_TRUE(policy.HasAllowedCert()); |
579 EXPECT_TRUE(policy.HasDeniedCert()); | 579 EXPECT_TRUE(policy.HasDeniedCert()); |
580 } | 580 } |
581 | 581 |
582 #if defined(OS_MACOSX) || defined(OS_WIN) | 582 #if defined(OS_MACOSX) || defined(OS_WIN) |
583 TEST(X509CertificateTest, IntermediateCertificates) { | 583 TEST(X509CertificateTest, IntermediateCertificates) { |
584 scoped_refptr<X509Certificate> webkit_cert = | 584 scoped_refptr<X509Certificate> webkit_cert( |
585 X509Certificate::CreateFromBytes( | 585 X509Certificate::CreateFromBytes( |
586 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)); | 586 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); |
587 | 587 |
588 scoped_refptr<X509Certificate> thawte_cert = | 588 scoped_refptr<X509Certificate> thawte_cert( |
589 X509Certificate::CreateFromBytes( | 589 X509Certificate::CreateFromBytes( |
590 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der)); | 590 reinterpret_cast<const char*>(thawte_der), sizeof(thawte_der))); |
591 | 591 |
592 scoped_refptr<X509Certificate> paypal_cert = | 592 scoped_refptr<X509Certificate> paypal_cert( |
593 X509Certificate::CreateFromBytes( | 593 X509Certificate::CreateFromBytes( |
594 reinterpret_cast<const char*>(paypal_null_der), | 594 reinterpret_cast<const char*>(paypal_null_der), |
595 sizeof(paypal_null_der)); | 595 sizeof(paypal_null_der))); |
596 | 596 |
597 X509Certificate::OSCertHandle google_handle; | 597 X509Certificate::OSCertHandle google_handle; |
598 // Create object with no intermediates: | 598 // Create object with no intermediates: |
599 google_handle = X509Certificate::CreateOSCertHandleFromBytes( | 599 google_handle = X509Certificate::CreateOSCertHandleFromBytes( |
600 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 600 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
601 X509Certificate::OSCertHandles intermediates1; | 601 X509Certificate::OSCertHandles intermediates1; |
602 scoped_refptr<X509Certificate> cert1; | 602 scoped_refptr<X509Certificate> cert1; |
603 cert1 = X509Certificate::CreateFromHandle( | 603 cert1 = X509Certificate::CreateFromHandle( |
604 google_handle, X509Certificate::SOURCE_FROM_NETWORK, intermediates1); | 604 google_handle, X509Certificate::SOURCE_FROM_NETWORK, intermediates1); |
605 EXPECT_TRUE(cert1->HasIntermediateCertificates(intermediates1)); | 605 EXPECT_TRUE(cert1->HasIntermediateCertificates(intermediates1)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 // Cleanup | 638 // Cleanup |
639 X509Certificate::FreeOSCertHandle(google_handle); | 639 X509Certificate::FreeOSCertHandle(google_handle); |
640 } | 640 } |
641 #endif | 641 #endif |
642 | 642 |
643 #if defined(OS_MACOSX) | 643 #if defined(OS_MACOSX) |
644 TEST(X509CertificateTest, IsIssuedBy) { | 644 TEST(X509CertificateTest, IsIssuedBy) { |
645 FilePath certs_dir = GetTestCertsDirectory(); | 645 FilePath certs_dir = GetTestCertsDirectory(); |
646 | 646 |
647 // Test a client certificate from MIT. | 647 // Test a client certificate from MIT. |
648 scoped_refptr<X509Certificate> mit_davidben_cert = | 648 scoped_refptr<X509Certificate> mit_davidben_cert( |
649 ImportCertFromFile(certs_dir, "mit.davidben.der"); | 649 ImportCertFromFile(certs_dir, "mit.davidben.der")); |
650 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert); | 650 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert); |
651 | 651 |
652 CertPrincipal mit_issuer; | 652 CertPrincipal mit_issuer; |
653 mit_issuer.country_name = "US"; | 653 mit_issuer.country_name = "US"; |
654 mit_issuer.state_or_province_name = "Massachusetts"; | 654 mit_issuer.state_or_province_name = "Massachusetts"; |
655 mit_issuer.organization_names.push_back( | 655 mit_issuer.organization_names.push_back( |
656 "Massachusetts Institute of Technology"); | 656 "Massachusetts Institute of Technology"); |
657 mit_issuer.organization_unit_names.push_back("Client CA v1"); | 657 mit_issuer.organization_unit_names.push_back("Client CA v1"); |
658 | 658 |
659 // IsIssuedBy should return true even if it cannot build a chain | 659 // IsIssuedBy should return true even if it cannot build a chain |
660 // with that principal. | 660 // with that principal. |
661 std::vector<CertPrincipal> mit_issuers(1, mit_issuer); | 661 std::vector<CertPrincipal> mit_issuers(1, mit_issuer); |
662 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(mit_issuers)); | 662 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(mit_issuers)); |
663 | 663 |
664 // Test a client certificate from FOAF.ME. | 664 // Test a client certificate from FOAF.ME. |
665 scoped_refptr<X509Certificate> foaf_me_chromium_test_cert = | 665 scoped_refptr<X509Certificate> foaf_me_chromium_test_cert( |
666 ImportCertFromFile(certs_dir, "foaf.me.chromium-test-cert.der"); | 666 ImportCertFromFile(certs_dir, "foaf.me.chromium-test-cert.der")); |
667 ASSERT_NE(static_cast<X509Certificate*>(NULL), foaf_me_chromium_test_cert); | 667 ASSERT_NE(static_cast<X509Certificate*>(NULL), foaf_me_chromium_test_cert); |
668 | 668 |
669 CertPrincipal foaf_issuer; | 669 CertPrincipal foaf_issuer; |
670 foaf_issuer.common_name = "FOAF.ME"; | 670 foaf_issuer.common_name = "FOAF.ME"; |
671 foaf_issuer.locality_name = "Wimbledon"; | 671 foaf_issuer.locality_name = "Wimbledon"; |
672 foaf_issuer.state_or_province_name = "LONDON"; | 672 foaf_issuer.state_or_province_name = "LONDON"; |
673 foaf_issuer.country_name = "GB"; | 673 foaf_issuer.country_name = "GB"; |
674 foaf_issuer.organization_names.push_back("FOAF.ME"); | 674 foaf_issuer.organization_names.push_back("FOAF.ME"); |
675 | 675 |
676 std::vector<CertPrincipal> foaf_issuers(1, foaf_issuer); | 676 std::vector<CertPrincipal> foaf_issuers(1, foaf_issuer); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 | 729 |
730 for (size_t j = 0; j < 20; ++j) | 730 for (size_t j = 0; j < 20; ++j) |
731 EXPECT_EQ(expected_fingerprint[j], actual_fingerprint.data[j]); | 731 EXPECT_EQ(expected_fingerprint[j], actual_fingerprint.data[j]); |
732 } | 732 } |
733 } | 733 } |
734 | 734 |
735 INSTANTIATE_TEST_CASE_P(, X509CertificateParseTest, | 735 INSTANTIATE_TEST_CASE_P(, X509CertificateParseTest, |
736 testing::ValuesIn(FormatTestData)); | 736 testing::ValuesIn(FormatTestData)); |
737 | 737 |
738 } // namespace net | 738 } // namespace net |
OLD | NEW |