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

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

Issue 6805019: Move crypto files out of base, to a top level directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixes comments by eroman Created 9 years, 8 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/base/x509_certificate_openssl.cc ('k') | net/base/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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/crypto/rsa_private_key.h"
6 #include "base/file_path.h" 5 #include "base/file_path.h"
7 #include "base/file_util.h" 6 #include "base/file_util.h"
8 #include "base/path_service.h" 7 #include "base/path_service.h"
9 #include "base/pickle.h" 8 #include "base/pickle.h"
10 #include "base/sha1.h" 9 #include "base/sha1.h"
11 #include "base/string_split.h" 10 #include "base/string_split.h"
11 #include "crypto/rsa_private_key.h"
12 #include "net/base/asn1_util.h" 12 #include "net/base/asn1_util.h"
13 #include "net/base/cert_status_flags.h" 13 #include "net/base/cert_status_flags.h"
14 #include "net/base/cert_test_util.h" 14 #include "net/base/cert_test_util.h"
15 #include "net/base/cert_verify_result.h" 15 #include "net/base/cert_verify_result.h"
16 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
17 #include "net/base/test_certificate_data.h" 17 #include "net/base/test_certificate_data.h"
18 #include "net/base/test_root_certs.h" 18 #include "net/base/test_root_certs.h"
19 #include "net/base/x509_certificate.h" 19 #include "net/base/x509_certificate.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers)); 823 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers));
824 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers)); 824 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers));
825 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers)); 825 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers));
826 } 826 }
827 #endif // defined(OS_MACOSX) 827 #endif // defined(OS_MACOSX)
828 828
829 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 829 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
830 // This test creates a self-signed cert from a private key and then verify the 830 // This test creates a self-signed cert from a private key and then verify the
831 // content of the certificate. 831 // content of the certificate.
832 TEST(X509CertificateTest, CreateSelfSigned) { 832 TEST(X509CertificateTest, CreateSelfSigned) {
833 scoped_ptr<base::RSAPrivateKey> private_key( 833 scoped_ptr<crypto::RSAPrivateKey> private_key(
834 base::RSAPrivateKey::Create(1024)); 834 crypto::RSAPrivateKey::Create(1024));
835 scoped_refptr<X509Certificate> cert = 835 scoped_refptr<X509Certificate> cert =
836 X509Certificate::CreateSelfSigned( 836 X509Certificate::CreateSelfSigned(
837 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); 837 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
838 838
839 EXPECT_EQ("subject", cert->subject().GetDisplayName()); 839 EXPECT_EQ("subject", cert->subject().GetDisplayName());
840 EXPECT_FALSE(cert->HasExpired()); 840 EXPECT_FALSE(cert->HasExpired());
841 841
842 const uint8 private_key_info[] = { 842 const uint8 private_key_info[] = {
843 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30, 843 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30,
844 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 844 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 0xc6, 0xa4, 0x92, 0xd1, 0xce, 0x6c, 0x72, 0xfb, 919 0xc6, 0xa4, 0x92, 0xd1, 0xce, 0x6c, 0x72, 0xfb,
920 0x21, 0xb3, 0x02, 0x87, 0xe4, 0xfd, 0x61, 0xca, 920 0x21, 0xb3, 0x02, 0x87, 0xe4, 0xfd, 0x61, 0xca,
921 0x00, 0x42, 0x19, 0xf0, 0xda, 0x5a, 0x53, 0xe3, 921 0x00, 0x42, 0x19, 0xf0, 0xda, 0x5a, 0x53, 0xe3,
922 0xb1, 0xc5, 0x15, 0xf3 922 0xb1, 0xc5, 0x15, 0xf3
923 }; 923 };
924 924
925 std::vector<uint8> input; 925 std::vector<uint8> input;
926 input.resize(sizeof(private_key_info)); 926 input.resize(sizeof(private_key_info));
927 memcpy(&input.front(), private_key_info, sizeof(private_key_info)); 927 memcpy(&input.front(), private_key_info, sizeof(private_key_info));
928 928
929 private_key.reset(base::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); 929 private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input));
930 ASSERT_TRUE(private_key.get()); 930 ASSERT_TRUE(private_key.get());
931 931
932 cert = X509Certificate::CreateSelfSigned( 932 cert = X509Certificate::CreateSelfSigned(
933 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); 933 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
934 934
935 EXPECT_EQ("subject", cert->subject().GetDisplayName()); 935 EXPECT_EQ("subject", cert->subject().GetDisplayName());
936 EXPECT_FALSE(cert->HasExpired()); 936 EXPECT_FALSE(cert->HasExpired());
937 } 937 }
938 938
939 TEST(X509CertificateTest, GetDEREncoded) { 939 TEST(X509CertificateTest, GetDEREncoded) {
940 scoped_ptr<base::RSAPrivateKey> private_key( 940 scoped_ptr<crypto::RSAPrivateKey> private_key(
941 base::RSAPrivateKey::Create(1024)); 941 crypto::RSAPrivateKey::Create(1024));
942 scoped_refptr<X509Certificate> cert = 942 scoped_refptr<X509Certificate> cert =
943 X509Certificate::CreateSelfSigned( 943 X509Certificate::CreateSelfSigned(
944 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1)); 944 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1));
945 945
946 std::string der_cert; 946 std::string der_cert;
947 EXPECT_TRUE(cert->GetDEREncoded(&der_cert)); 947 EXPECT_TRUE(cert->GetDEREncoded(&der_cert));
948 EXPECT_FALSE(der_cert.empty()); 948 EXPECT_FALSE(der_cert.empty());
949 } 949 }
950 #endif 950 #endif
951 951
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 EXPECT_EQ(test_data.expected, 1088 EXPECT_EQ(test_data.expected,
1089 X509Certificate::VerifyHostname(test_data.hostname, cert_names)) 1089 X509Certificate::VerifyHostname(test_data.hostname, cert_names))
1090 << "Host [" << test_data.hostname 1090 << "Host [" << test_data.hostname
1091 << "], cert name [" << test_data.cert_names << "]"; 1091 << "], cert name [" << test_data.cert_names << "]";
1092 } 1092 }
1093 1093
1094 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, 1094 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
1095 testing::ValuesIn(kNameVerifyTestData)); 1095 testing::ValuesIn(kNameVerifyTestData));
1096 1096
1097 } // namespace net 1097 } // namespace net
OLDNEW
« no previous file with comments | « net/base/x509_certificate_openssl.cc ('k') | net/base/x509_certificate_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698