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

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

Issue 18223006: Add script for generating certificates that require an explicit policy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Really fix Android Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « net/cert/cert_verify_proc_unittest.cc ('k') | net/data/ssl/certificates/README » ('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/cert/x509_certificate.h" 5 #include "net/cert/x509_certificate.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/files/file_path.h" 8 #include "base/files/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 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 717
718 // Check that they both pass when given a list of the two issuers. 718 // Check that they both pass when given a list of the two issuers.
719 issuers.clear(); 719 issuers.clear();
720 issuers.push_back(mit_issuer); 720 issuers.push_back(mit_issuer);
721 issuers.push_back(thawte_issuer); 721 issuers.push_back(thawte_issuer);
722 EXPECT_TRUE(mit_davidben_cert->IsIssuedByEncoded(issuers)); 722 EXPECT_TRUE(mit_davidben_cert->IsIssuedByEncoded(issuers));
723 EXPECT_TRUE(google_cert->IsIssuedByEncoded(issuers)); 723 EXPECT_TRUE(google_cert->IsIssuedByEncoded(issuers));
724 } 724 }
725 725
726 TEST(X509CertificateTest, IsIssuedByEncodedWithIntermediates) { 726 TEST(X509CertificateTest, IsIssuedByEncodedWithIntermediates) {
727 static const unsigned char kPolicyRootDN[] = {
728 0x30, 0x1e, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
729 0x13, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x20, 0x54, 0x65, 0x73, 0x74,
730 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41
731 };
732 static const unsigned char kPolicyIntermediateDN[] = {
733 0x30, 0x26, 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
734 0x1b, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x20, 0x54, 0x65, 0x73, 0x74,
735 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x74,
736 0x65, 0x20, 0x43, 0x41
737 };
738
727 base::FilePath certs_dir = GetTestCertsDirectory(); 739 base::FilePath certs_dir = GetTestCertsDirectory();
728 740
729 scoped_refptr<X509Certificate> server_cert = 741 CertificateList policy_chain = CreateCertificateListFromFile(
730 ImportCertFromFile(certs_dir, "www_us_army_mil_cert.der"); 742 certs_dir, "explicit-policy-chain.pem", X509Certificate::FORMAT_AUTO);
731 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 743 ASSERT_EQ(3u, policy_chain.size());
732 744
733 // The intermediate CA certificate's policyConstraints extension has a 745 // The intermediate CA certificate's policyConstraints extension has a
734 // requireExplicitPolicy field with SkipCerts=0. 746 // requireExplicitPolicy field with SkipCerts=0.
735 scoped_refptr<X509Certificate> intermediate_cert = 747 std::string policy_intermediate_dn(
736 ImportCertFromFile(certs_dir, "dod_ca_17_cert.der"); 748 reinterpret_cast<const char*>(kPolicyIntermediateDN),
737 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert); 749 sizeof(kPolicyIntermediateDN));
738 750 std::string policy_root_dn(reinterpret_cast<const char*>(kPolicyRootDN),
739 std::string dod_ca_17_issuer(reinterpret_cast<const char*>(DodCA17DN), 751 sizeof(kPolicyRootDN));
740 sizeof(DodCA17DN));
741
742 scoped_refptr<X509Certificate> root_cert =
743 ImportCertFromFile(certs_dir, "dod_root_ca_2_cert.der");
744
745 std::string dod_root_ca_2_issuer(
746 reinterpret_cast<const char*>(DodRootCA2DN), sizeof(DodRootCA2DN));
747 752
748 X509Certificate::OSCertHandles intermediates; 753 X509Certificate::OSCertHandles intermediates;
749 intermediates.push_back(intermediate_cert->os_cert_handle()); 754 intermediates.push_back(policy_chain[1]->os_cert_handle());
750 scoped_refptr<X509Certificate> cert_chain = 755 scoped_refptr<X509Certificate> cert_chain =
751 X509Certificate::CreateFromHandle(server_cert->os_cert_handle(), 756 X509Certificate::CreateFromHandle(policy_chain[0]->os_cert_handle(),
752 intermediates); 757 intermediates);
753 758
754 std::vector<std::string> issuers; 759 std::vector<std::string> issuers;
755 760
756 // Check that the chain is issued by DOD CA-17. 761 // Check that the chain is issued by the intermediate.
757 issuers.clear(); 762 issuers.clear();
758 issuers.push_back(dod_ca_17_issuer); 763 issuers.push_back(policy_intermediate_dn);
759 EXPECT_TRUE(cert_chain->IsIssuedByEncoded(issuers)); 764 EXPECT_TRUE(cert_chain->IsIssuedByEncoded(issuers));
760 765
761 // Check that the chain is also issued by DoD Root CA 2. 766 // Check that the chain is also issued by the root.
762 issuers.clear(); 767 issuers.clear();
763 issuers.push_back(dod_root_ca_2_issuer); 768 issuers.push_back(policy_root_dn);
764 EXPECT_TRUE(cert_chain->IsIssuedByEncoded(issuers)); 769 EXPECT_TRUE(cert_chain->IsIssuedByEncoded(issuers));
765 770
766 // Check that the chain is issued by either one of the two DOD issuers. 771 // Check that the chain is issued by either the intermediate or the root.
767 issuers.clear(); 772 issuers.clear();
768 issuers.push_back(dod_ca_17_issuer); 773 issuers.push_back(policy_intermediate_dn);
769 issuers.push_back(dod_root_ca_2_issuer); 774 issuers.push_back(policy_root_dn);
770 EXPECT_TRUE(cert_chain->IsIssuedByEncoded(issuers)); 775 EXPECT_TRUE(cert_chain->IsIssuedByEncoded(issuers));
771 776
772 // Check that an empty issuers list returns false. 777 // Check that an empty issuers list returns false.
773 issuers.clear(); 778 issuers.clear();
774 EXPECT_FALSE(cert_chain->IsIssuedByEncoded(issuers)); 779 EXPECT_FALSE(cert_chain->IsIssuedByEncoded(issuers));
775 780
776 // Check that the chain is not issued by MIT 781 // Check that the chain is not issued by Verisign
777 std::string mit_issuer(reinterpret_cast<const char*>(MITDN), 782 std::string mit_issuer(reinterpret_cast<const char*>(VerisignDN),
778 sizeof(MITDN)); 783 sizeof(VerisignDN));
779 issuers.clear(); 784 issuers.clear();
780 issuers.push_back(mit_issuer); 785 issuers.push_back(mit_issuer);
781 EXPECT_FALSE(cert_chain->IsIssuedByEncoded(issuers)); 786 EXPECT_FALSE(cert_chain->IsIssuedByEncoded(issuers));
782 } 787 }
783 788
784 #if defined(USE_NSS) 789 #if defined(USE_NSS)
785 TEST(X509CertificateTest, GetDefaultNickname) { 790 TEST(X509CertificateTest, GetDefaultNickname) {
786 base::FilePath certs_dir = GetTestCertsDirectory(); 791 base::FilePath certs_dir = GetTestCertsDirectory();
787 792
788 scoped_refptr<X509Certificate> test_cert( 793 scoped_refptr<X509Certificate> test_cert(
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 } 1069 }
1065 1070
1066 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname( 1071 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname(
1067 test_data.hostname, common_name, dns_names, ip_addressses)); 1072 test_data.hostname, common_name, dns_names, ip_addressses));
1068 } 1073 }
1069 1074
1070 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, 1075 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
1071 testing::ValuesIn(kNameVerifyTestData)); 1076 testing::ValuesIn(kNameVerifyTestData));
1072 1077
1073 } // namespace net 1078 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/cert_verify_proc_unittest.cc ('k') | net/data/ssl/certificates/README » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698