| 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 "net/base/x509_certificate.h" | 5 #include "net/base/x509_certificate.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 ASSERT_EQ(2u, cert2_intermediates.size()); | 674 ASSERT_EQ(2u, cert2_intermediates.size()); |
| 675 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[0], | 675 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[0], |
| 676 webkit_cert->os_cert_handle())); | 676 webkit_cert->os_cert_handle())); |
| 677 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[1], | 677 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[1], |
| 678 thawte_cert->os_cert_handle())); | 678 thawte_cert->os_cert_handle())); |
| 679 | 679 |
| 680 // Cleanup | 680 // Cleanup |
| 681 X509Certificate::FreeOSCertHandle(google_handle); | 681 X509Certificate::FreeOSCertHandle(google_handle); |
| 682 } | 682 } |
| 683 | 683 |
| 684 #if !defined(OS_IOS) | |
| 685 // TODO(ios): Not yet implemented on iOS. | |
| 686 #if defined(OS_MACOSX) | |
| 687 TEST(X509CertificateTest, IsIssuedBy) { | |
| 688 FilePath certs_dir = GetTestCertsDirectory(); | |
| 689 | |
| 690 // Test a client certificate from MIT. | |
| 691 scoped_refptr<X509Certificate> mit_davidben_cert( | |
| 692 ImportCertFromFile(certs_dir, "mit.davidben.der")); | |
| 693 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert); | |
| 694 | |
| 695 CertPrincipal mit_issuer; | |
| 696 mit_issuer.country_name = "US"; | |
| 697 mit_issuer.state_or_province_name = "Massachusetts"; | |
| 698 mit_issuer.organization_names.push_back( | |
| 699 "Massachusetts Institute of Technology"); | |
| 700 mit_issuer.organization_unit_names.push_back("Client CA v1"); | |
| 701 | |
| 702 // IsIssuedBy should return true even if it cannot build a chain | |
| 703 // with that principal. | |
| 704 std::vector<CertPrincipal> mit_issuers(1, mit_issuer); | |
| 705 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(mit_issuers)); | |
| 706 | |
| 707 // Test a client certificate from FOAF.ME. | |
| 708 scoped_refptr<X509Certificate> foaf_me_chromium_test_cert( | |
| 709 ImportCertFromFile(certs_dir, "foaf.me.chromium-test-cert.der")); | |
| 710 ASSERT_NE(static_cast<X509Certificate*>(NULL), foaf_me_chromium_test_cert); | |
| 711 | |
| 712 CertPrincipal foaf_issuer; | |
| 713 foaf_issuer.common_name = "FOAF.ME"; | |
| 714 foaf_issuer.locality_name = "Wimbledon"; | |
| 715 foaf_issuer.state_or_province_name = "LONDON"; | |
| 716 foaf_issuer.country_name = "GB"; | |
| 717 foaf_issuer.organization_names.push_back("FOAF.ME"); | |
| 718 | |
| 719 std::vector<CertPrincipal> foaf_issuers(1, foaf_issuer); | |
| 720 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(foaf_issuers)); | |
| 721 | |
| 722 // And test some combinations and mismatches. | |
| 723 std::vector<CertPrincipal> both_issuers; | |
| 724 both_issuers.push_back(mit_issuer); | |
| 725 both_issuers.push_back(foaf_issuer); | |
| 726 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers)); | |
| 727 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers)); | |
| 728 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers)); | |
| 729 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers)); | |
| 730 } | |
| 731 #endif // defined(OS_MACOSX) | |
| 732 #endif // !defined(OS_IOS) | |
| 733 | |
| 734 TEST(X509CertificateTest, IsIssuedByEncoded) { | 684 TEST(X509CertificateTest, IsIssuedByEncoded) { |
| 735 FilePath certs_dir = GetTestCertsDirectory(); | 685 FilePath certs_dir = GetTestCertsDirectory(); |
| 736 | 686 |
| 737 // Test a client certificate from MIT. | 687 // Test a client certificate from MIT. |
| 738 scoped_refptr<X509Certificate> mit_davidben_cert( | 688 scoped_refptr<X509Certificate> mit_davidben_cert( |
| 739 ImportCertFromFile(certs_dir, "mit.davidben.der")); | 689 ImportCertFromFile(certs_dir, "mit.davidben.der")); |
| 740 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert); | 690 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert); |
| 741 | 691 |
| 742 std::string mit_issuer(reinterpret_cast<const char*>(MITDN), | 692 std::string mit_issuer(reinterpret_cast<const char*>(MITDN), |
| 743 sizeof(MITDN)); | 693 sizeof(MITDN)); |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 } | 1161 } |
| 1212 | 1162 |
| 1213 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname( | 1163 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname( |
| 1214 test_data.hostname, common_name, dns_names, ip_addressses)); | 1164 test_data.hostname, common_name, dns_names, ip_addressses)); |
| 1215 } | 1165 } |
| 1216 | 1166 |
| 1217 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, | 1167 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, |
| 1218 testing::ValuesIn(kNameVerifyTestData)); | 1168 testing::ValuesIn(kNameVerifyTestData)); |
| 1219 | 1169 |
| 1220 } // namespace net | 1170 } // namespace net |
| OLD | NEW |