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

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: 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 j = 0; j < required_scts - 1; ++j) {
davidben 2015/03/25 15:00:54 Nit: j -> i
Eran Messeri 2015/03/25 18:27:28 Done.
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() << " j=" << j;
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
171 const size_t validity_period[] = {417 /* 14 months */,
davidben 2015/03/25 15:00:54 time_t? (Though see comment below.)
Eran Messeri 2015/03/25 18:27:28 Left at size_t but grouped the number of required
172 458 /* exactly 15 months */,
173 460 /* over 15 months by a few days */,
174 823 /* exactly 27 months */,
175 826 /* over 27 months by a few days */,
176 1188 /* exactly 39 months */,
177 1190 /* over 39 months by a few days */};
178 const size_t needed_scts[] = {2, 3, 3, 3, 4, 4, 5};
148 179
180 // Fixed start time - Wed Mar 25 11:45:03 GMT 2015
181 base::Time fixed_start(base::Time::FromTimeT(1427283904));
davidben 2015/03/25 15:00:54 Since this is all test code, it might be more unde
Ryan Sleevi 2015/03/25 16:54:23 +1 Easier to just make a set of base::Time::FromU
Eran Messeri 2015/03/25 18:27:28 Done as you suggested - since the TestData structu
149 for (int i = 0; i < 3; ++i) { 182 for (int i = 0; i < 3; ++i) {
davidben 2015/03/25 15:00:54 While you're here, maybe put a SCOPED_TRACE(i) so
davidben 2015/03/25 15:00:54 BUG: 3 -> arraysize(validity_period) (It looks li
Ryan Sleevi 2015/03/25 16:54:23 +1
Ryan Sleevi 2015/03/25 16:54:23 s/int/size_t/
Eran Messeri 2015/03/25 18:27:28 I do - the detail about the number of days is incl
Eran Messeri 2015/03/25 18:27:28 Done.
Eran Messeri 2015/03/25 18:27:28 Done.
150 size_t curr_validity = validity_period[i]; 183 size_t curr_validity = validity_period[i];
151 scoped_refptr<X509Certificate> cert(new X509Certificate( 184 CheckCertificateCompliesWithExactNumberOfEmbeddedSCTs(
152 "subject", "issuer", base::Time::Now(), 185 fixed_start, fixed_start + base::TimeDelta::FromDays(curr_validity),
153 base::Time::Now() + base::TimeDelta::FromDays(31 * curr_validity))); 186 needed_scts[i]);
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 } 187 }
169 } 188 }
170 189
171 TEST_F(CertPolicyEnforcerTest, ConformsToPolicyByEVWhitelistPresence) { 190 TEST_F(CertPolicyEnforcerTest, ConformsToPolicyByEVWhitelistPresence) {
172 scoped_refptr<ct::EVCertsWhitelist> whitelist( 191 scoped_refptr<ct::EVCertsWhitelist> whitelist(
173 new DummyEVCertsWhitelist(true, true)); 192 new DummyEVCertsWhitelist(true, true));
174 193
175 ct::CTVerifyResult result; 194 ct::CTVerifyResult result;
176 FillResultWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 1, 195 FillResultWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 1,
177 &result); 196 &result);
(...skipping 16 matching lines...) Expand all
194 ct::CTVerifyResult result; 213 ct::CTVerifyResult result;
195 FillResultWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 1, 214 FillResultWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 1,
196 &result); 215 &result);
197 EXPECT_FALSE(policy_enforcer_->DoesConformToCTEVPolicy( 216 EXPECT_FALSE(policy_enforcer_->DoesConformToCTEVPolicy(
198 chain_.get(), nullptr, result, BoundNetLog())); 217 chain_.get(), nullptr, result, BoundNetLog()));
199 } 218 }
200 219
201 } // namespace 220 } // namespace
202 221
203 } // namespace net 222 } // 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