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

Side by Side Diff: net/base/x509_certificate_unittest.cc

Issue 10928107: Support x509 certificate on iOS. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix windows compilation Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/x509_certificate_nss.cc ('k') | net/base/x509_util_ios.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 ASSERT_EQ(2u, cert2_intermediates.size()); 673 ASSERT_EQ(2u, cert2_intermediates.size());
674 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[0], 674 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[0],
675 webkit_cert->os_cert_handle())); 675 webkit_cert->os_cert_handle()));
676 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[1], 676 EXPECT_TRUE(X509Certificate::IsSameOSCert(cert2_intermediates[1],
677 thawte_cert->os_cert_handle())); 677 thawte_cert->os_cert_handle()));
678 678
679 // Cleanup 679 // Cleanup
680 X509Certificate::FreeOSCertHandle(google_handle); 680 X509Certificate::FreeOSCertHandle(google_handle);
681 } 681 }
682 682
683 #if !defined(OS_IOS)
684 // TODO(ios): Not yet implemented on iOS.
683 #if defined(OS_MACOSX) 685 #if defined(OS_MACOSX)
684 TEST(X509CertificateTest, IsIssuedBy) { 686 TEST(X509CertificateTest, IsIssuedBy) {
685 FilePath certs_dir = GetTestCertsDirectory(); 687 FilePath certs_dir = GetTestCertsDirectory();
686 688
687 // Test a client certificate from MIT. 689 // Test a client certificate from MIT.
688 scoped_refptr<X509Certificate> mit_davidben_cert( 690 scoped_refptr<X509Certificate> mit_davidben_cert(
689 ImportCertFromFile(certs_dir, "mit.davidben.der")); 691 ImportCertFromFile(certs_dir, "mit.davidben.der"));
690 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert); 692 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert);
691 693
692 CertPrincipal mit_issuer; 694 CertPrincipal mit_issuer;
(...skipping 26 matching lines...) Expand all
719 // And test some combinations and mismatches. 721 // And test some combinations and mismatches.
720 std::vector<CertPrincipal> both_issuers; 722 std::vector<CertPrincipal> both_issuers;
721 both_issuers.push_back(mit_issuer); 723 both_issuers.push_back(mit_issuer);
722 both_issuers.push_back(foaf_issuer); 724 both_issuers.push_back(foaf_issuer);
723 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers)); 725 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers));
724 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers)); 726 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers));
725 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers)); 727 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers));
726 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers)); 728 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers));
727 } 729 }
728 #endif // defined(OS_MACOSX) 730 #endif // defined(OS_MACOSX)
731 #endif // !defined(OS_IOS)
729 732
733 #if !defined(OS_IOS) // TODO(ios): Unable to create certificates.
730 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 734 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
731 // This test creates a self-signed cert from a private key and then verify the 735 // This test creates a self-signed cert from a private key and then verify the
732 // content of the certificate. 736 // content of the certificate.
733 TEST(X509CertificateTest, CreateSelfSigned) { 737 TEST(X509CertificateTest, CreateSelfSigned) {
734 scoped_ptr<crypto::RSAPrivateKey> private_key( 738 scoped_ptr<crypto::RSAPrivateKey> private_key(
735 crypto::RSAPrivateKey::Create(1024)); 739 crypto::RSAPrivateKey::Create(1024));
736 scoped_refptr<X509Certificate> cert = 740 scoped_refptr<X509Certificate> cert =
737 X509Certificate::CreateSelfSigned( 741 X509Certificate::CreateSelfSigned(
738 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); 742 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
739 743
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 scoped_refptr<X509Certificate> cert = 847 scoped_refptr<X509Certificate> cert =
844 X509Certificate::CreateSelfSigned( 848 X509Certificate::CreateSelfSigned(
845 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1)); 849 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1));
846 850
847 std::string der_cert; 851 std::string der_cert;
848 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(), 852 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
849 &der_cert)); 853 &der_cert));
850 EXPECT_FALSE(der_cert.empty()); 854 EXPECT_FALSE(der_cert.empty());
851 } 855 }
852 #endif 856 #endif
857 #endif // !defined(OS_IOS)
853 858
854 class X509CertificateParseTest 859 class X509CertificateParseTest
855 : public testing::TestWithParam<CertificateFormatTestData> { 860 : public testing::TestWithParam<CertificateFormatTestData> {
856 public: 861 public:
857 virtual ~X509CertificateParseTest() {} 862 virtual ~X509CertificateParseTest() {}
858 virtual void SetUp() { 863 virtual void SetUp() {
859 test_data_ = GetParam(); 864 test_data_ = GetParam();
860 } 865 }
861 virtual void TearDown() {} 866 virtual void TearDown() {}
862 867
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 } 1110 }
1106 1111
1107 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname( 1112 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname(
1108 test_data.hostname, common_name, dns_names, ip_addressses)); 1113 test_data.hostname, common_name, dns_names, ip_addressses));
1109 } 1114 }
1110 1115
1111 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, 1116 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
1112 testing::ValuesIn(kNameVerifyTestData)); 1117 testing::ValuesIn(kNameVerifyTestData));
1113 1118
1114 } // namespace net 1119 } // namespace net
OLDNEW
« no previous file with comments | « net/base/x509_certificate_nss.cc ('k') | net/base/x509_util_ios.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698