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/cert/x509_certificate_unittest.cc

Issue 17265013: Remove platform-specific implementations of RSAPrivateKey and SignatureCreator (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix colliding serial numbers 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/x509_certificate_openssl.cc ('k') | net/cert/x509_certificate_win.cc » ('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 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 scoped_refptr<X509Certificate> test_cert( 788 scoped_refptr<X509Certificate> test_cert(
789 ImportCertFromFile(certs_dir, "no_subject_common_name_cert.pem")); 789 ImportCertFromFile(certs_dir, "no_subject_common_name_cert.pem"));
790 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert); 790 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
791 791
792 std::string nickname = test_cert->GetDefaultNickname(USER_CERT); 792 std::string nickname = test_cert->GetDefaultNickname(USER_CERT);
793 EXPECT_EQ("wtc@google.com's COMODO Client Authentication and " 793 EXPECT_EQ("wtc@google.com's COMODO Client Authentication and "
794 "Secure Email CA ID", nickname); 794 "Secure Email CA ID", nickname);
795 } 795 }
796 #endif 796 #endif
797 797
798 #if !defined(OS_IOS) // TODO(ios): Unable to create certificates.
799 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
800 // This test creates a self-signed cert from a private key and then verify the
801 // content of the certificate.
802 TEST(X509CertificateTest, CreateSelfSigned) {
803 scoped_ptr<crypto::RSAPrivateKey> private_key(
804 crypto::RSAPrivateKey::Create(1024));
805 scoped_refptr<X509Certificate> cert =
806 X509Certificate::CreateSelfSigned(
807 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
808
809 EXPECT_EQ("subject", cert->subject().GetDisplayName());
810 EXPECT_FALSE(cert->HasExpired());
811
812 const uint8 private_key_info[] = {
813 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30,
814 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
815 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
816 0x02, 0x62, 0x30, 0x82, 0x02, 0x5e, 0x02, 0x01,
817 0x00, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b,
818 0x20, 0xdc, 0x7c, 0x9b, 0x0c, 0xdc, 0x51, 0x61,
819 0x99, 0x0d, 0x36, 0x0f, 0xd4, 0x66, 0x88, 0x08,
820 0x55, 0x84, 0xd5, 0x3a, 0xbf, 0x2b, 0xa4, 0x64,
821 0x85, 0x7b, 0x0c, 0x04, 0x13, 0x3f, 0x8d, 0xf4,
822 0xbc, 0x38, 0x0d, 0x49, 0xfe, 0x6b, 0xc4, 0x5a,
823 0xb0, 0x40, 0x53, 0x3a, 0xd7, 0x66, 0x09, 0x0f,
824 0x9e, 0x36, 0x74, 0x30, 0xda, 0x8a, 0x31, 0x4f,
825 0x1f, 0x14, 0x50, 0xd7, 0xc7, 0x20, 0x94, 0x17,
826 0xde, 0x4e, 0xb9, 0x57, 0x5e, 0x7e, 0x0a, 0xe5,
827 0xb2, 0x65, 0x7a, 0x89, 0x4e, 0xb6, 0x47, 0xff,
828 0x1c, 0xbd, 0xb7, 0x38, 0x13, 0xaf, 0x47, 0x85,
829 0x84, 0x32, 0x33, 0xf3, 0x17, 0x49, 0xbf, 0xe9,
830 0x96, 0xd0, 0xd6, 0x14, 0x6f, 0x13, 0x8d, 0xc5,
831 0xfc, 0x2c, 0x72, 0xba, 0xac, 0xea, 0x7e, 0x18,
832 0x53, 0x56, 0xa6, 0x83, 0xa2, 0xce, 0x93, 0x93,
833 0xe7, 0x1f, 0x0f, 0xe6, 0x0f, 0x02, 0x03, 0x01,
834 0x00, 0x01, 0x02, 0x81, 0x80, 0x03, 0x61, 0x89,
835 0x37, 0xcb, 0xf2, 0x98, 0xa0, 0xce, 0xb4, 0xcb,
836 0x16, 0x13, 0xf0, 0xe6, 0xaf, 0x5c, 0xc5, 0xa7,
837 0x69, 0x71, 0xca, 0xba, 0x8d, 0xe0, 0x4d, 0xdd,
838 0xed, 0xb8, 0x48, 0x8b, 0x16, 0x93, 0x36, 0x95,
839 0xc2, 0x91, 0x40, 0x65, 0x17, 0xbd, 0x7f, 0xd6,
840 0xad, 0x9e, 0x30, 0x28, 0x46, 0xe4, 0x3e, 0xcc,
841 0x43, 0x78, 0xf9, 0xfe, 0x1f, 0x33, 0x23, 0x1e,
842 0x31, 0x12, 0x9d, 0x3c, 0xa7, 0x08, 0x82, 0x7b,
843 0x7d, 0x25, 0x4e, 0x5e, 0x19, 0xa8, 0x9b, 0xed,
844 0x86, 0xb2, 0xcb, 0x3c, 0xfe, 0x4e, 0xa1, 0xfa,
845 0x62, 0x87, 0x3a, 0x17, 0xf7, 0x60, 0xec, 0x38,
846 0x29, 0xe8, 0x4f, 0x34, 0x9f, 0x76, 0x9d, 0xee,
847 0xa3, 0xf6, 0x85, 0x6b, 0x84, 0x43, 0xc9, 0x1e,
848 0x01, 0xff, 0xfd, 0xd0, 0x29, 0x4c, 0xfa, 0x8e,
849 0x57, 0x0c, 0xc0, 0x71, 0xa5, 0xbb, 0x88, 0x46,
850 0x29, 0x5c, 0xc0, 0x4f, 0x01, 0x02, 0x41, 0x00,
851 0xf5, 0x83, 0xa4, 0x64, 0x4a, 0xf2, 0xdd, 0x8c,
852 0x2c, 0xed, 0xa8, 0xd5, 0x60, 0x5a, 0xe4, 0xc7,
853 0xcc, 0x61, 0xcd, 0x38, 0x42, 0x20, 0xd3, 0x82,
854 0x18, 0xf2, 0x35, 0x00, 0x72, 0x2d, 0xf7, 0x89,
855 0x80, 0x67, 0xb5, 0x93, 0x05, 0x5f, 0xdd, 0x42,
856 0xba, 0x16, 0x1a, 0xea, 0x15, 0xc6, 0xf0, 0xb8,
857 0x8c, 0xbc, 0xbf, 0x54, 0x9e, 0xf1, 0xc1, 0xb2,
858 0xb3, 0x8b, 0xb6, 0x26, 0x02, 0x30, 0xc4, 0x81,
859 0x02, 0x41, 0x00, 0xc0, 0x60, 0x62, 0x80, 0xe1,
860 0x22, 0x78, 0xf6, 0x9d, 0x83, 0x18, 0xeb, 0x72,
861 0x45, 0xd7, 0xc8, 0x01, 0x7f, 0xa9, 0xca, 0x8f,
862 0x7d, 0xd6, 0xb8, 0x31, 0x2b, 0x84, 0x7f, 0x62,
863 0xd9, 0xa9, 0x22, 0x17, 0x7d, 0x06, 0x35, 0x6c,
864 0xf3, 0xc1, 0x94, 0x17, 0x85, 0x5a, 0xaf, 0x9c,
865 0x5c, 0x09, 0x3c, 0xcf, 0x2f, 0x44, 0x9d, 0xb6,
866 0x52, 0x68, 0x5f, 0xf9, 0x59, 0xc8, 0x84, 0x2b,
867 0x39, 0x22, 0x8f, 0x02, 0x41, 0x00, 0xb2, 0x04,
868 0xe2, 0x0e, 0x56, 0xca, 0x03, 0x1a, 0xc0, 0xf9,
869 0x12, 0x92, 0xa5, 0x6b, 0x42, 0xb8, 0x1c, 0xda,
870 0x4d, 0x93, 0x9d, 0x5f, 0x6f, 0xfd, 0xc5, 0x58,
871 0xda, 0x55, 0x98, 0x74, 0xfc, 0x28, 0x17, 0x93,
872 0x1b, 0x75, 0x9f, 0x50, 0x03, 0x7f, 0x7e, 0xae,
873 0xc8, 0x95, 0x33, 0x75, 0x2c, 0xd6, 0xa4, 0x35,
874 0xb8, 0x06, 0x03, 0xba, 0x08, 0x59, 0x2b, 0x17,
875 0x02, 0xdc, 0x4c, 0x7a, 0x50, 0x01, 0x02, 0x41,
876 0x00, 0x9d, 0xdb, 0x39, 0x59, 0x09, 0xe4, 0x30,
877 0xa0, 0x24, 0xf5, 0xdb, 0x2f, 0xf0, 0x2f, 0xf1,
878 0x75, 0x74, 0x0d, 0x5e, 0xb5, 0x11, 0x73, 0xb0,
879 0x0a, 0xaa, 0x86, 0x4c, 0x0d, 0xff, 0x7e, 0x1d,
880 0xb4, 0x14, 0xd4, 0x09, 0x91, 0x33, 0x5a, 0xfd,
881 0xa0, 0x58, 0x80, 0x9b, 0xbe, 0x78, 0x2e, 0x69,
882 0x82, 0x15, 0x7c, 0x72, 0xf0, 0x7b, 0x18, 0x39,
883 0xff, 0x6e, 0xeb, 0xc6, 0x86, 0xf5, 0xb4, 0xc7,
884 0x6f, 0x02, 0x41, 0x00, 0x8d, 0x1a, 0x37, 0x0f,
885 0x76, 0xc4, 0x82, 0xfa, 0x5c, 0xc3, 0x79, 0x35,
886 0x3e, 0x70, 0x8a, 0xbf, 0x27, 0x49, 0xb0, 0x99,
887 0x63, 0xcb, 0x77, 0x5f, 0xa8, 0x82, 0x65, 0xf6,
888 0x03, 0x52, 0x51, 0xf1, 0xae, 0x2e, 0x05, 0xb3,
889 0xc6, 0xa4, 0x92, 0xd1, 0xce, 0x6c, 0x72, 0xfb,
890 0x21, 0xb3, 0x02, 0x87, 0xe4, 0xfd, 0x61, 0xca,
891 0x00, 0x42, 0x19, 0xf0, 0xda, 0x5a, 0x53, 0xe3,
892 0xb1, 0xc5, 0x15, 0xf3
893 };
894
895 std::vector<uint8> input;
896 input.resize(sizeof(private_key_info));
897 memcpy(&input.front(), private_key_info, sizeof(private_key_info));
898
899 private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input));
900 ASSERT_TRUE(private_key.get());
901
902 cert = X509Certificate::CreateSelfSigned(
903 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
904
905 EXPECT_EQ("subject", cert->subject().GetDisplayName());
906 EXPECT_FALSE(cert->HasExpired());
907 }
908
909 TEST(X509CertificateTest, GetDEREncoded) {
910 scoped_ptr<crypto::RSAPrivateKey> private_key(
911 crypto::RSAPrivateKey::Create(1024));
912 scoped_refptr<X509Certificate> cert =
913 X509Certificate::CreateSelfSigned(
914 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1));
915
916 std::string der_cert;
917 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
918 &der_cert));
919 EXPECT_FALSE(der_cert.empty());
920 }
921 #endif
922 #endif // !defined(OS_IOS)
923
924 class X509CertificateParseTest 798 class X509CertificateParseTest
925 : public testing::TestWithParam<CertificateFormatTestData> { 799 : public testing::TestWithParam<CertificateFormatTestData> {
926 public: 800 public:
927 virtual ~X509CertificateParseTest() {} 801 virtual ~X509CertificateParseTest() {}
928 virtual void SetUp() { 802 virtual void SetUp() {
929 test_data_ = GetParam(); 803 test_data_ = GetParam();
930 } 804 }
931 virtual void TearDown() {} 805 virtual void TearDown() {}
932 806
933 protected: 807 protected:
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 } 1064 }
1191 1065
1192 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname( 1066 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname(
1193 test_data.hostname, common_name, dns_names, ip_addressses)); 1067 test_data.hostname, common_name, dns_names, ip_addressses));
1194 } 1068 }
1195 1069
1196 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, 1070 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
1197 testing::ValuesIn(kNameVerifyTestData)); 1071 testing::ValuesIn(kNameVerifyTestData));
1198 1072
1199 } // namespace net 1073 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/x509_certificate_openssl.cc ('k') | net/cert/x509_certificate_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698