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

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

Issue 1032093002: Certificate Transparency: Correct month calculation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing review comments Created 5 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "net/cert/cert_policy_enforcer.h" 5 #include "net/cert/cert_policy_enforcer.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/version.h" 10 #include "base/version.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 int num_scts, 60 int num_scts,
61 ct::CTVerifyResult* result) { 61 ct::CTVerifyResult* result) {
62 for (int i = 0; i < num_scts; ++i) { 62 for (int i = 0; i < num_scts; ++i) {
63 scoped_refptr<ct::SignedCertificateTimestamp> sct( 63 scoped_refptr<ct::SignedCertificateTimestamp> sct(
64 new ct::SignedCertificateTimestamp()); 64 new ct::SignedCertificateTimestamp());
65 sct->origin = desired_origin; 65 sct->origin = desired_origin;
66 result->verified_scts.push_back(sct); 66 result->verified_scts.push_back(sct);
67 } 67 }
68 } 68 }
69 69
70 void CheckCertificateCompliesWithExactNumberOfEmbeddedSCTs(
71 const base::Time& start,
72 const base::Time& end,
73 size_t required_scts) {
74 scoped_refptr<X509Certificate> cert(
75 new X509Certificate("subject", "issuer", start, end));
76 ct::CTVerifyResult result;
77 for (size_t i = 0; i < required_scts - 1; ++i) {
78 FillResultWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED,
79 1, &result);
80 EXPECT_FALSE(policy_enforcer_->DoesConformToCTEVPolicy(
81 cert.get(), nullptr, result, BoundNetLog()))
82 << " for: " << (end - start).InDays() << " and " << required_scts
83 << " scts=" << result.verified_scts.size() << " i=" << i;
84 }
85 FillResultWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 1,
86 &result);
87 EXPECT_TRUE(policy_enforcer_->DoesConformToCTEVPolicy(
88 cert.get(), nullptr, result, BoundNetLog()))
89 << " for: " << (end - start).InDays() << " and " << required_scts
90 << " scts=" << result.verified_scts.size();
91 }
92
70 protected: 93 protected:
71 scoped_ptr<CertPolicyEnforcer> policy_enforcer_; 94 scoped_ptr<CertPolicyEnforcer> policy_enforcer_;
72 scoped_refptr<X509Certificate> chain_; 95 scoped_refptr<X509Certificate> chain_;
73 }; 96 };
74 97
75 TEST_F(CertPolicyEnforcerTest, ConformsToCTEVPolicyWithNonEmbeddedSCTs) { 98 TEST_F(CertPolicyEnforcerTest, ConformsToCTEVPolicyWithNonEmbeddedSCTs) {
76 ct::CTVerifyResult result; 99 ct::CTVerifyResult result;
77 FillResultWithSCTsOfOrigin( 100 FillResultWithSCTsOfOrigin(
78 ct::SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION, 2, &result); 101 ct::SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION, 2, &result);
79 102
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 no_valid_dates_cert.get(), nullptr, result, BoundNetLog())); 156 no_valid_dates_cert.get(), nullptr, result, BoundNetLog()));
134 // ... but should be OK if whitelisted. 157 // ... but should be OK if whitelisted.
135 scoped_refptr<ct::EVCertsWhitelist> whitelist( 158 scoped_refptr<ct::EVCertsWhitelist> whitelist(
136 new DummyEVCertsWhitelist(true, true)); 159 new DummyEVCertsWhitelist(true, true));
137 EXPECT_TRUE(policy_enforcer_->DoesConformToCTEVPolicy( 160 EXPECT_TRUE(policy_enforcer_->DoesConformToCTEVPolicy(
138 chain_.get(), whitelist.get(), result, BoundNetLog())); 161 chain_.get(), whitelist.get(), result, BoundNetLog()));
139 } 162 }
140 163
141 TEST_F(CertPolicyEnforcerTest, 164 TEST_F(CertPolicyEnforcerTest,
142 ConformsToPolicyExactNumberOfSCTsForValidityPeriod) { 165 ConformsToPolicyExactNumberOfSCTsForValidityPeriod) {
143 // Test multiple validity periods: Over 27 months, Over 15 months (but less 166 // Test multiple validity periods:
144 // than 27 months), 167 // Under 15 months
145 // Less than 15 months. 168 // Over 15 months, less than 27 months
146 const size_t validity_period[] = {12, 19, 30, 50}; 169 // Over 27 months, less than 39 months
147 const size_t needed_scts[] = {2, 3, 4, 5}; 170 // Over 39 months
davidben 2015/03/25 19:10:11 This list in the comment seems to be slightly out
Eran Messeri 2015/03/26 10:47:17 Done.
171 const struct TestData {
172 base::Time validity_start;
173 base::Time validity_end;
174 size_t scts_required;
175 } kTestData[] = {{// 14 months, need 2
davidben 2015/03/25 19:10:11 Oh clang-format. :-/ I don't know how to convince
Eran Messeri 2015/03/26 10:47:17 Yes, clang-format. While I don't like it either my
176 base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
177 base::Time::FromUTCExploded({2016, 6, 0, 6, 11, 25, 0, 0}),
178 2},
179 {// exactly 15 months, need 3
davidben 2015/03/25 19:10:11 Nit: They're not really complete sentences, but be
Eran Messeri 2015/03/26 10:47:18 Done.
180 base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
181 base::Time::FromUTCExploded({2016, 6, 0, 25, 11, 25, 0, 0}),
182 3},
183 {// over 15 months by a few days, need 3
184 base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
185 base::Time::FromUTCExploded({2016, 6, 0, 27, 11, 25, 0, 0}),
186 3},
187 {// exactly 27 months, need 3
188 base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
189 base::Time::FromUTCExploded({2017, 6, 0, 25, 11, 25, 0, 0}),
190 3},
191 {// over 27 months by a few days, need 4
192 base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
193 base::Time::FromUTCExploded({2017, 6, 0, 28, 11, 25, 0, 0}),
194 4},
195 {// exactly 39 months, need 4
196 base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
197 base::Time::FromUTCExploded({2018, 6, 0, 25, 11, 25, 0, 0}),
198 4},
199 {// over 39 months by a few days, need 5
200 base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
201 base::Time::FromUTCExploded({2018, 6, 0, 27, 11, 25, 0, 0}),
202 5}};
148 203
149 for (int i = 0; i < 3; ++i) { 204 for (size_t i = 0; i < arraysize(kTestData); ++i) {
davidben 2015/03/25 19:10:11 Still would prefer adding the SCOPED_TRACE. It's i
Eran Messeri 2015/03/26 10:47:17 Done.
150 size_t curr_validity = validity_period[i]; 205 CheckCertificateCompliesWithExactNumberOfEmbeddedSCTs(
151 scoped_refptr<X509Certificate> cert(new X509Certificate( 206 kTestData[i].validity_start, kTestData[i].validity_end,
152 "subject", "issuer", base::Time::Now(), 207 kTestData[i].scts_required);
153 base::Time::Now() + base::TimeDelta::FromDays(31 * curr_validity)));
154 size_t curr_required_scts = needed_scts[i];
155 ct::CTVerifyResult result;
156 for (size_t j = 0; j < curr_required_scts - 1; ++j) {
157 FillResultWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED,
158 1, &result);
159 EXPECT_FALSE(policy_enforcer_->DoesConformToCTEVPolicy(
160 cert.get(), nullptr, result, BoundNetLog()))
161 << " for: " << curr_validity << " and " << curr_required_scts
162 << " scts=" << result.verified_scts.size() << " j=" << j;
163 }
164 FillResultWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 1,
165 &result);
166 EXPECT_TRUE(policy_enforcer_->DoesConformToCTEVPolicy(
167 cert.get(), nullptr, result, BoundNetLog()));
168 } 208 }
169 } 209 }
170 210
171 TEST_F(CertPolicyEnforcerTest, ConformsToPolicyByEVWhitelistPresence) { 211 TEST_F(CertPolicyEnforcerTest, ConformsToPolicyByEVWhitelistPresence) {
172 scoped_refptr<ct::EVCertsWhitelist> whitelist( 212 scoped_refptr<ct::EVCertsWhitelist> whitelist(
173 new DummyEVCertsWhitelist(true, true)); 213 new DummyEVCertsWhitelist(true, true));
174 214
175 ct::CTVerifyResult result; 215 ct::CTVerifyResult result;
176 FillResultWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 1, 216 FillResultWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 1,
177 &result); 217 &result);
(...skipping 16 matching lines...) Expand all
194 ct::CTVerifyResult result; 234 ct::CTVerifyResult result;
195 FillResultWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 1, 235 FillResultWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 1,
196 &result); 236 &result);
197 EXPECT_FALSE(policy_enforcer_->DoesConformToCTEVPolicy( 237 EXPECT_FALSE(policy_enforcer_->DoesConformToCTEVPolicy(
198 chain_.get(), nullptr, result, BoundNetLog())); 238 chain_.get(), nullptr, result, BoundNetLog()));
199 } 239 }
200 240
201 } // namespace 241 } // namespace
202 242
203 } // namespace net 243 } // namespace net
OLDNEW
« net/cert/cert_policy_enforcer.cc ('K') | « net/cert/cert_policy_enforcer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698