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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 EXPECT_TRUE(x509_util::IsSupportedValidityRange(now, now)); 92 EXPECT_TRUE(x509_util::IsSupportedValidityRange(now, now));
93 EXPECT_FALSE(x509_util::IsSupportedValidityRange( 93 EXPECT_FALSE(x509_util::IsSupportedValidityRange(
94 now, now - base::TimeDelta::FromSeconds(1))); 94 now, now - base::TimeDelta::FromSeconds(1)));
95 95
96 // See x509_util_openssl.cc to see how these were computed. 96 // See x509_util_openssl.cc to see how these were computed.
97 const int64 kDaysFromYear0001ToUnixEpoch = 719162; 97 const int64 kDaysFromYear0001ToUnixEpoch = 719162;
98 const int64 kDaysFromUnixEpochToYear10000 = 2932896 + 1; 98 const int64 kDaysFromUnixEpochToYear10000 = 2932896 + 1;
99 99
100 // When computing too_old / too_late, add one day to account for 100 // When computing too_old / too_late, add one day to account for
101 // possible leap seconds. 101 // possible leap seconds.
102 base::Time too_old = base::Time::UnixEpoch() - 102 base::Time too_old =
103 base::Time::UnixEpoch() -
103 base::TimeDelta::FromDays(kDaysFromYear0001ToUnixEpoch + 1); 104 base::TimeDelta::FromDays(kDaysFromYear0001ToUnixEpoch + 1);
104 105
105 base::Time too_late = base::Time::UnixEpoch() + 106 base::Time too_late =
107 base::Time::UnixEpoch() +
106 base::TimeDelta::FromDays(kDaysFromUnixEpochToYear10000 + 1); 108 base::TimeDelta::FromDays(kDaysFromUnixEpochToYear10000 + 1);
107 109
108 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, too_old)); 110 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, too_old));
109 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, now)); 111 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, now));
110 112
111 EXPECT_FALSE(x509_util::IsSupportedValidityRange(now, too_late)); 113 EXPECT_FALSE(x509_util::IsSupportedValidityRange(now, too_late));
112 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_late, too_late)); 114 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_late, too_late));
113 } 115 }
114 116
115 TEST(X509UtilOpenSSLTest, CreateDomainBoundCertEC) { 117 TEST(X509UtilOpenSSLTest, CreateDomainBoundCertEC) {
116 // Create a sample ASCII weborigin. 118 // Create a sample ASCII weborigin.
117 std::string domain = "weborigin.com"; 119 std::string domain = "weborigin.com";
118 base::Time now = base::Time::Now(); 120 base::Time now = base::Time::Now();
119 121
120 scoped_ptr<crypto::ECPrivateKey> private_key( 122 scoped_ptr<crypto::ECPrivateKey> private_key(crypto::ECPrivateKey::Create());
121 crypto::ECPrivateKey::Create());
122 std::string der_cert; 123 std::string der_cert;
123 ASSERT_TRUE( 124 ASSERT_TRUE(
124 x509_util::CreateDomainBoundCertEC(private_key.get(), 125 x509_util::CreateDomainBoundCertEC(private_key.get(),
125 x509_util::DIGEST_SHA1, 126 x509_util::DIGEST_SHA1,
126 domain, 127 domain,
127 1, 128 1,
128 now, 129 now,
129 now + base::TimeDelta::FromDays(1), 130 now + base::TimeDelta::FromDays(1),
130 &der_cert)); 131 &der_cert));
131 132
132 VerifyDomainBoundCert(domain, der_cert); 133 VerifyDomainBoundCert(domain, der_cert);
133 134
134 // signature_verifier_win and signature_verifier_mac can't handle EC certs. 135 // signature_verifier_win and signature_verifier_mac can't handle EC certs.
135 std::vector<uint8> spki; 136 std::vector<uint8> spki;
136 ASSERT_TRUE(private_key->ExportPublicKey(&spki)); 137 ASSERT_TRUE(private_key->ExportPublicKey(&spki));
137 VerifyCertificateSignature(der_cert, spki); 138 VerifyCertificateSignature(der_cert, spki);
138 } 139 }
139 140
140 } // namespace net 141 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698