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

Side by Side Diff: net/cert/x509_util_openssl_unittest.cc

Issue 356713005: Rename ServerBoundCert => ChannelID to reflect the current name (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 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
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "crypto/ec_private_key.h" 6 #include "crypto/ec_private_key.h"
7 #include "crypto/openssl_util.h" 7 #include "crypto/openssl_util.h"
8 #include "net/cert/x509_util.h" 8 #include "net/cert/x509_util.h"
9 #include "net/cert/x509_util_openssl.h" 9 #include "net/cert/x509_util_openssl.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 24 matching lines...) Expand all
35 d2i_PUBKEY(NULL, &pub_key_data, pub_key_len)); 35 d2i_PUBKEY(NULL, &pub_key_data, pub_key_len));
36 ASSERT_TRUE(pub_key.get()); 36 ASSERT_TRUE(pub_key.get());
37 37
38 // NOTE: X509_verify() returns 1 in case of succes, 0 or -1 on error. 38 // NOTE: X509_verify() returns 1 in case of succes, 0 or -1 on error.
39 EXPECT_EQ(1, X509_verify(cert.get(), pub_key.get())); 39 EXPECT_EQ(1, X509_verify(cert.get(), pub_key.get()));
40 } 40 }
41 41
42 // Verify the attributes of a domain-bound certificate. 42 // Verify the attributes of a domain-bound certificate.
43 // |domain| is the bound domain name. 43 // |domain| is the bound domain name.
44 // |der_cert| is the DER-encoded X.509 certificate. 44 // |der_cert| is the DER-encoded X.509 certificate.
45 void VerifyDomainBoundCert(const std::string& domain, 45 void VerifyChannelID(const std::string& domain,
46 const std::string& der_cert) { 46 const std::string& der_cert) {
wtc 2014/07/01 19:50:52 Fix the indentation.
Ryan Hamilton 2014/07/21 19:12:08 Done.
47 // Origin Bound Cert OID. 47 // Origin Bound Cert OID.
48 static const char oid_string[] = "1.3.6.1.4.1.11129.2.1.6"; 48 static const char oid_string[] = "1.3.6.1.4.1.11129.2.1.6";
49 crypto::ScopedOpenSSL<ASN1_OBJECT, ASN1_OBJECT_free> oid_obj( 49 crypto::ScopedOpenSSL<ASN1_OBJECT, ASN1_OBJECT_free> oid_obj(
50 OBJ_txt2obj(oid_string, 0)); 50 OBJ_txt2obj(oid_string, 0));
51 ASSERT_TRUE(oid_obj.get()); 51 ASSERT_TRUE(oid_obj.get());
52 52
53 const unsigned char* cert_data = 53 const unsigned char* cert_data =
54 reinterpret_cast<const unsigned char*>(der_cert.data()); 54 reinterpret_cast<const unsigned char*>(der_cert.data());
55 int cert_data_len = static_cast<int>(der_cert.size()); 55 int cert_data_len = static_cast<int>(der_cert.size());
56 crypto::ScopedOpenSSL<X509, X509_free> cert( 56 crypto::ScopedOpenSSL<X509, X509_free> cert(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 base::Time too_late = base::Time::UnixEpoch() + 105 base::Time too_late = base::Time::UnixEpoch() +
106 base::TimeDelta::FromDays(kDaysFromUnixEpochToYear10000 + 1); 106 base::TimeDelta::FromDays(kDaysFromUnixEpochToYear10000 + 1);
107 107
108 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, too_old)); 108 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, too_old));
109 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, now)); 109 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, now));
110 110
111 EXPECT_FALSE(x509_util::IsSupportedValidityRange(now, too_late)); 111 EXPECT_FALSE(x509_util::IsSupportedValidityRange(now, too_late));
112 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_late, too_late)); 112 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_late, too_late));
113 } 113 }
114 114
115 TEST(X509UtilOpenSSLTest, CreateDomainBoundCertEC) { 115 TEST(X509UtilOpenSSLTest, CreateChannelIDEC) {
116 // Create a sample ASCII weborigin. 116 // Create a sample ASCII weborigin.
117 std::string domain = "weborigin.com"; 117 std::string domain = "weborigin.com";
118 base::Time now = base::Time::Now(); 118 base::Time now = base::Time::Now();
119 119
120 scoped_ptr<crypto::ECPrivateKey> private_key( 120 scoped_ptr<crypto::ECPrivateKey> private_key(
121 crypto::ECPrivateKey::Create()); 121 crypto::ECPrivateKey::Create());
122 std::string der_cert; 122 std::string der_cert;
123 ASSERT_TRUE( 123 ASSERT_TRUE(
124 x509_util::CreateDomainBoundCertEC(private_key.get(), 124 x509_util::CreateChannelIDEC(private_key.get(),
125 x509_util::DIGEST_SHA1, 125 x509_util::DIGEST_SHA1,
126 domain, 126 domain,
127 1, 127 1,
128 now, 128 now,
129 now + base::TimeDelta::FromDays(1), 129 now + base::TimeDelta::FromDays(1),
130 &der_cert)); 130 &der_cert));
wtc 2014/07/01 19:50:52 Fix the indentation of the arguments.
Ryan Hamilton 2014/07/21 19:12:08 Done.
131 131
132 VerifyDomainBoundCert(domain, der_cert); 132 VerifyChannelID(domain, der_cert);
133 133
134 // signature_verifier_win and signature_verifier_mac can't handle EC certs. 134 // signature_verifier_win and signature_verifier_mac can't handle EC certs.
135 std::vector<uint8> spki; 135 std::vector<uint8> spki;
136 ASSERT_TRUE(private_key->ExportPublicKey(&spki)); 136 ASSERT_TRUE(private_key->ExportPublicKey(&spki));
137 VerifyCertificateSignature(der_cert, spki); 137 VerifyCertificateSignature(der_cert, spki);
138 } 138 }
139 139
140 } // namespace net 140 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698