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

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

Issue 8414047: Make X509Certificate::GetDEREncoded a static function taking an OSCertHandle (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and tweak comment to wtc's verbiage Created 9 years, 1 month 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/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "base/sha1.h" 9 #include "base/sha1.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 "diginotar_pkioverheid_g2.pem", 588 "diginotar_pkioverheid_g2.pem",
589 NULL, 589 NULL,
590 }; 590 };
591 591
592 FilePath certs_dir = GetTestCertsDirectory(); 592 FilePath certs_dir = GetTestCertsDirectory();
593 593
594 for (size_t i = 0; kDigiNotarFilenames[i]; i++) { 594 for (size_t i = 0; kDigiNotarFilenames[i]; i++) {
595 scoped_refptr<X509Certificate> diginotar_cert = 595 scoped_refptr<X509Certificate> diginotar_cert =
596 ImportCertFromFile(certs_dir, kDigiNotarFilenames[i]); 596 ImportCertFromFile(certs_dir, kDigiNotarFilenames[i]);
597 std::string der_bytes; 597 std::string der_bytes;
598 ASSERT_TRUE(diginotar_cert->GetDEREncoded(&der_bytes)); 598 ASSERT_TRUE(X509Certificate::GetDEREncoded(
599 diginotar_cert->os_cert_handle(), &der_bytes));
599 600
600 base::StringPiece spki; 601 base::StringPiece spki;
601 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(der_bytes, &spki)); 602 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(der_bytes, &spki));
602 603
603 std::string spki_sha1 = base::SHA1HashString(spki.as_string()); 604 std::string spki_sha1 = base::SHA1HashString(spki.as_string());
604 605
605 std::vector<SHA1Fingerprint> public_keys; 606 std::vector<SHA1Fingerprint> public_keys;
606 SHA1Fingerprint fingerprint; 607 SHA1Fingerprint fingerprint;
607 ASSERT_EQ(sizeof(fingerprint.data), spki_sha1.size()); 608 ASSERT_EQ(sizeof(fingerprint.data), spki_sha1.size());
608 memcpy(fingerprint.data, spki_sha1.data(), spki_sha1.size()); 609 memcpy(fingerprint.data, spki_sha1.data(), spki_sha1.size());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 "\x15\x60\xde\x65\x4e\x03\x9f\xd0\x08\x82" 647 "\x15\x60\xde\x65\x4e\x03\x9f\xd0\x08\x82"
647 "\xa9\x6a\xc4\x65\x8e\x6f\x92\x06\x84\x35"; 648 "\xa9\x6a\xc4\x65\x8e\x6f\x92\x06\x84\x35";
648 649
649 TEST(X509CertificateTest, ExtractSPKIFromDERCert) { 650 TEST(X509CertificateTest, ExtractSPKIFromDERCert) {
650 FilePath certs_dir = GetTestCertsDirectory(); 651 FilePath certs_dir = GetTestCertsDirectory();
651 scoped_refptr<X509Certificate> cert = 652 scoped_refptr<X509Certificate> cert =
652 ImportCertFromFile(certs_dir, "nist.der"); 653 ImportCertFromFile(certs_dir, "nist.der");
653 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); 654 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
654 655
655 std::string derBytes; 656 std::string derBytes;
656 EXPECT_TRUE(cert->GetDEREncoded(&derBytes)); 657 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
658 &derBytes));
657 659
658 base::StringPiece spkiBytes; 660 base::StringPiece spkiBytes;
659 EXPECT_TRUE(asn1::ExtractSPKIFromDERCert(derBytes, &spkiBytes)); 661 EXPECT_TRUE(asn1::ExtractSPKIFromDERCert(derBytes, &spkiBytes));
660 662
661 uint8 hash[base::kSHA1Length]; 663 uint8 hash[base::kSHA1Length];
662 base::SHA1HashBytes(reinterpret_cast<const uint8*>(spkiBytes.data()), 664 base::SHA1HashBytes(reinterpret_cast<const uint8*>(spkiBytes.data()),
663 spkiBytes.size(), hash); 665 spkiBytes.size(), hash);
664 666
665 EXPECT_TRUE(0 == memcmp(hash, nistSPKIHash, sizeof(hash))); 667 EXPECT_TRUE(0 == memcmp(hash, nistSPKIHash, sizeof(hash)));
666 } 668 }
667 669
668 TEST(X509CertificateTest, ExtractCRLURLsFromDERCert) { 670 TEST(X509CertificateTest, ExtractCRLURLsFromDERCert) {
669 FilePath certs_dir = GetTestCertsDirectory(); 671 FilePath certs_dir = GetTestCertsDirectory();
670 scoped_refptr<X509Certificate> cert = 672 scoped_refptr<X509Certificate> cert =
671 ImportCertFromFile(certs_dir, "nist.der"); 673 ImportCertFromFile(certs_dir, "nist.der");
672 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert); 674 ASSERT_NE(static_cast<X509Certificate*>(NULL), cert);
673 675
674 std::string derBytes; 676 std::string derBytes;
675 EXPECT_TRUE(cert->GetDEREncoded(&derBytes)); 677 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
678 &derBytes));
676 679
677 std::vector<base::StringPiece> crl_urls; 680 std::vector<base::StringPiece> crl_urls;
678 EXPECT_TRUE(asn1::ExtractCRLURLsFromDERCert(derBytes, &crl_urls)); 681 EXPECT_TRUE(asn1::ExtractCRLURLsFromDERCert(derBytes, &crl_urls));
679 682
680 EXPECT_EQ(1u, crl_urls.size()); 683 EXPECT_EQ(1u, crl_urls.size());
681 if (crl_urls.size() > 0) { 684 if (crl_urls.size() > 0) {
682 EXPECT_EQ("http://SVRSecure-G3-crl.verisign.com/SVRSecureG3.crl", 685 EXPECT_EQ("http://SVRSecure-G3-crl.verisign.com/SVRSecureG3.crl",
683 crl_urls[0].as_string()); 686 crl_urls[0].as_string());
684 } 687 }
685 } 688 }
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 } 1216 }
1214 1217
1215 TEST(X509CertificateTest, GetDEREncoded) { 1218 TEST(X509CertificateTest, GetDEREncoded) {
1216 scoped_ptr<crypto::RSAPrivateKey> private_key( 1219 scoped_ptr<crypto::RSAPrivateKey> private_key(
1217 crypto::RSAPrivateKey::Create(1024)); 1220 crypto::RSAPrivateKey::Create(1024));
1218 scoped_refptr<X509Certificate> cert = 1221 scoped_refptr<X509Certificate> cert =
1219 X509Certificate::CreateSelfSigned( 1222 X509Certificate::CreateSelfSigned(
1220 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1)); 1223 private_key.get(), "CN=subject", 0, base::TimeDelta::FromDays(1));
1221 1224
1222 std::string der_cert; 1225 std::string der_cert;
1223 EXPECT_TRUE(cert->GetDEREncoded(&der_cert)); 1226 EXPECT_TRUE(X509Certificate::GetDEREncoded(cert->os_cert_handle(),
1227 &der_cert));
1224 EXPECT_FALSE(der_cert.empty()); 1228 EXPECT_FALSE(der_cert.empty());
1225 } 1229 }
1226 #endif 1230 #endif
1227 1231
1228 class X509CertificateParseTest 1232 class X509CertificateParseTest
1229 : public testing::TestWithParam<CertificateFormatTestData> { 1233 : public testing::TestWithParam<CertificateFormatTestData> {
1230 public: 1234 public:
1231 virtual ~X509CertificateParseTest() {} 1235 virtual ~X509CertificateParseTest() {}
1232 virtual void SetUp() { 1236 virtual void SetUp() {
1233 test_data_ = GetParam(); 1237 test_data_ = GetParam();
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 } 1499 }
1496 1500
1497 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname( 1501 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname(
1498 test_data.hostname, common_name, dns_names, ip_addressses)); 1502 test_data.hostname, common_name, dns_names, ip_addressses));
1499 } 1503 }
1500 1504
1501 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, 1505 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
1502 testing::ValuesIn(kNameVerifyTestData)); 1506 testing::ValuesIn(kNameVerifyTestData));
1503 1507
1504 } // namespace net 1508 } // 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