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

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: Chrome, webkit, remoting and crypto/owners 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 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers)); 758 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers));
759 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers)); 759 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers));
760 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers)); 760 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers));
761 } 761 }
762 #endif // defined(OS_MACOSX) 762 #endif // defined(OS_MACOSX)
763 763
764 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 764 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
765 // This test creates a self-signed cert from a private key and then verify the 765 // This test creates a self-signed cert from a private key and then verify the
766 // content of the certificate. 766 // content of the certificate.
767 TEST(X509CertificateTest, CreateSelfSigned) { 767 TEST(X509CertificateTest, CreateSelfSigned) {
768 scoped_ptr<base::RSAPrivateKey> private_key( 768 scoped_ptr<crypto::RSAPrivateKey> private_key(
769 base::RSAPrivateKey::Create(1024)); 769 crypto::RSAPrivateKey::Create(1024));
770 scoped_refptr<X509Certificate> cert = 770 scoped_refptr<X509Certificate> cert =
771 X509Certificate::CreateSelfSigned( 771 X509Certificate::CreateSelfSigned(
772 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); 772 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
773 773
774 EXPECT_EQ("subject", cert->subject().GetDisplayName()); 774 EXPECT_EQ("subject", cert->subject().GetDisplayName());
775 EXPECT_FALSE(cert->HasExpired()); 775 EXPECT_FALSE(cert->HasExpired());
776 776
777 const uint8 private_key_info[] = { 777 const uint8 private_key_info[] = {
778 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30, 778 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30,
779 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 779 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 0xc6, 0xa4, 0x92, 0xd1, 0xce, 0x6c, 0x72, 0xfb, 854 0xc6, 0xa4, 0x92, 0xd1, 0xce, 0x6c, 0x72, 0xfb,
855 0x21, 0xb3, 0x02, 0x87, 0xe4, 0xfd, 0x61, 0xca, 855 0x21, 0xb3, 0x02, 0x87, 0xe4, 0xfd, 0x61, 0xca,
856 0x00, 0x42, 0x19, 0xf0, 0xda, 0x5a, 0x53, 0xe3, 856 0x00, 0x42, 0x19, 0xf0, 0xda, 0x5a, 0x53, 0xe3,
857 0xb1, 0xc5, 0x15, 0xf3 857 0xb1, 0xc5, 0x15, 0xf3
858 }; 858 };
859 859
860 std::vector<uint8> input; 860 std::vector<uint8> input;
861 input.resize(sizeof(private_key_info)); 861 input.resize(sizeof(private_key_info));
862 memcpy(&input.front(), private_key_info, sizeof(private_key_info)); 862 memcpy(&input.front(), private_key_info, sizeof(private_key_info));
863 863
864 private_key.reset(base::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); 864 private_key.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input));
865 ASSERT_TRUE(private_key.get()); 865 ASSERT_TRUE(private_key.get());
866 866
867 cert = X509Certificate::CreateSelfSigned( 867 cert = X509Certificate::CreateSelfSigned(
868 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); 868 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
869 869
870 EXPECT_EQ("subject", cert->subject().GetDisplayName()); 870 EXPECT_EQ("subject", cert->subject().GetDisplayName());
871 EXPECT_FALSE(cert->HasExpired()); 871 EXPECT_FALSE(cert->HasExpired());
872 } 872 }
873 873
874 TEST(X509CertificateTest, GetDEREncoded) { 874 TEST(X509CertificateTest, GetDEREncoded) {
875 scoped_ptr<base::RSAPrivateKey> private_key( 875 scoped_ptr<crypto::RSAPrivateKey> private_key(
876 base::RSAPrivateKey::Create(1024)); 876 crypto::RSAPrivateKey::Create(1024));
877 scoped_refptr<X509Certificate> cert = 877 scoped_refptr<X509Certificate> cert =
878 X509Certificate::CreateSelfSigned( 878 X509Certificate::CreateSelfSigned(
879 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1)); 879 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1));
880 880
881 std::string der_cert; 881 std::string der_cert;
882 EXPECT_TRUE(cert->GetDEREncoded(&der_cert)); 882 EXPECT_TRUE(cert->GetDEREncoded(&der_cert));
883 EXPECT_FALSE(der_cert.empty()); 883 EXPECT_FALSE(der_cert.empty());
884 } 884 }
885 #endif 885 #endif
886 886
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 EXPECT_EQ(test_data.expected, 1023 EXPECT_EQ(test_data.expected,
1024 X509Certificate::VerifyHostname(test_data.hostname, cert_names)) 1024 X509Certificate::VerifyHostname(test_data.hostname, cert_names))
1025 << "Host [" << test_data.hostname 1025 << "Host [" << test_data.hostname
1026 << "], cert name [" << test_data.cert_names << "]"; 1026 << "], cert name [" << test_data.cert_names << "]";
1027 } 1027 }
1028 1028
1029 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, 1029 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
1030 testing::ValuesIn(kNameVerifyTestData)); 1030 testing::ValuesIn(kNameVerifyTestData));
1031 1031
1032 } // namespace net 1032 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698