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

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: 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
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/string_split.h" 9 #include "base/string_split.h"
10 #include "crypto/rsa_private_key.h"
11 #include "net/base/cert_status_flags.h" 11 #include "net/base/cert_status_flags.h"
12 #include "net/base/cert_test_util.h" 12 #include "net/base/cert_test_util.h"
13 #include "net/base/cert_verify_result.h" 13 #include "net/base/cert_verify_result.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/base/test_certificate_data.h" 15 #include "net/base/test_certificate_data.h"
16 #include "net/base/test_root_certs.h" 16 #include "net/base/test_root_certs.h"
17 #include "net/base/x509_certificate.h" 17 #include "net/base/x509_certificate.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 // Unit tests aren't allowed to access external resources. Unfortunately, to 20 // Unit tests aren't allowed to access external resources. Unfortunately, to
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers)); 728 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers));
729 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers)); 729 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers));
730 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers)); 730 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers));
731 } 731 }
732 #endif // defined(OS_MACOSX) 732 #endif // defined(OS_MACOSX)
733 733
734 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 734 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
735 // 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
736 // content of the certificate. 736 // content of the certificate.
737 TEST(X509CertificateTest, CreateSelfSigned) { 737 TEST(X509CertificateTest, CreateSelfSigned) {
738 scoped_ptr<base::RSAPrivateKey> private_key( 738 scoped_ptr<crypto::RSAPrivateKey> private_key(
739 base::RSAPrivateKey::Create(1024)); 739 crypto::RSAPrivateKey::Create(1024));
740 scoped_refptr<X509Certificate> cert = 740 scoped_refptr<X509Certificate> cert =
741 X509Certificate::CreateSelfSigned( 741 X509Certificate::CreateSelfSigned(
742 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); 742 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
743 743
744 EXPECT_EQ("subject", cert->subject().GetDisplayName()); 744 EXPECT_EQ("subject", cert->subject().GetDisplayName());
745 EXPECT_FALSE(cert->HasExpired()); 745 EXPECT_FALSE(cert->HasExpired());
746 746
747 const uint8 private_key_info[] = { 747 const uint8 private_key_info[] = {
748 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30, 748 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30,
749 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 749 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 0xc6, 0xa4, 0x92, 0xd1, 0xce, 0x6c, 0x72, 0xfb, 824 0xc6, 0xa4, 0x92, 0xd1, 0xce, 0x6c, 0x72, 0xfb,
825 0x21, 0xb3, 0x02, 0x87, 0xe4, 0xfd, 0x61, 0xca, 825 0x21, 0xb3, 0x02, 0x87, 0xe4, 0xfd, 0x61, 0xca,
826 0x00, 0x42, 0x19, 0xf0, 0xda, 0x5a, 0x53, 0xe3, 826 0x00, 0x42, 0x19, 0xf0, 0xda, 0x5a, 0x53, 0xe3,
827 0xb1, 0xc5, 0x15, 0xf3 827 0xb1, 0xc5, 0x15, 0xf3
828 }; 828 };
829 829
830 std::vector<uint8> input; 830 std::vector<uint8> input;
831 input.resize(sizeof(private_key_info)); 831 input.resize(sizeof(private_key_info));
832 memcpy(&input.front(), private_key_info, sizeof(private_key_info)); 832 memcpy(&input.front(), private_key_info, sizeof(private_key_info));
833 833
834 private_key.reset(base::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); 834 private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input));
835 ASSERT_TRUE(private_key.get()); 835 ASSERT_TRUE(private_key.get());
836 836
837 cert = X509Certificate::CreateSelfSigned( 837 cert = X509Certificate::CreateSelfSigned(
838 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); 838 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
839 839
840 EXPECT_EQ("subject", cert->subject().GetDisplayName()); 840 EXPECT_EQ("subject", cert->subject().GetDisplayName());
841 EXPECT_FALSE(cert->HasExpired()); 841 EXPECT_FALSE(cert->HasExpired());
842 } 842 }
843 843
844 TEST(X509CertificateTest, GetDEREncoded) { 844 TEST(X509CertificateTest, GetDEREncoded) {
845 scoped_ptr<base::RSAPrivateKey> private_key( 845 scoped_ptr<crypto::RSAPrivateKey> private_key(
846 base::RSAPrivateKey::Create(1024)); 846 crypto::RSAPrivateKey::Create(1024));
847 scoped_refptr<X509Certificate> cert = 847 scoped_refptr<X509Certificate> cert =
848 X509Certificate::CreateSelfSigned( 848 X509Certificate::CreateSelfSigned(
849 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1)); 849 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1));
850 850
851 std::string der_cert; 851 std::string der_cert;
852 EXPECT_TRUE(cert->GetDEREncoded(&der_cert)); 852 EXPECT_TRUE(cert->GetDEREncoded(&der_cert));
853 EXPECT_FALSE(der_cert.empty()); 853 EXPECT_FALSE(der_cert.empty());
854 } 854 }
855 #endif 855 #endif
856 856
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 EXPECT_EQ(test_data.expected, 993 EXPECT_EQ(test_data.expected,
994 X509Certificate::VerifyHostname(test_data.hostname, cert_names)) 994 X509Certificate::VerifyHostname(test_data.hostname, cert_names))
995 << "Host [" << test_data.hostname 995 << "Host [" << test_data.hostname
996 << "], cert name [" << test_data.cert_names << "]"; 996 << "], cert name [" << test_data.cert_names << "]";
997 } 997 }
998 998
999 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, 999 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
1000 testing::ValuesIn(kNameVerifyTestData)); 1000 testing::ValuesIn(kNameVerifyTestData));
1001 1001
1002 } // namespace net 1002 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698