Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/build_time.h" | 10 #include "base/build_time.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 bool IsBuildTimely() { | 36 bool IsBuildTimely() { |
| 37 #if defined(DONT_EMBED_BUILD_METADATA) && !defined(OFFICIAL_BUILD) | 37 #if defined(DONT_EMBED_BUILD_METADATA) && !defined(OFFICIAL_BUILD) |
| 38 return true; | 38 return true; |
| 39 #else | 39 #else |
| 40 const base::Time build_time = base::GetBuildTime(); | 40 const base::Time build_time = base::GetBuildTime(); |
| 41 // We consider built-in information to be timely for 10 weeks. | 41 // We consider built-in information to be timely for 10 weeks. |
| 42 return (base::Time::Now() - build_time).InDays() < 70 /* 10 weeks */; | 42 return (base::Time::Now() - build_time).InDays() < 70 /* 10 weeks */; |
| 43 #endif | 43 #endif |
| 44 } | 44 } |
| 45 | 45 |
| 46 uint32_t ApproximateMonthDifference(const base::Time& start, | 46 struct MonthsDiff { |
| 47 const base::Time& end) { | 47 MonthsDiff() : num_months(0), last_month_is_full(false) {} |
|
davidben
2015/03/25 19:10:11
Per https://chromium-cpp.appspot.com/, these can b
Ryan Sleevi
2015/03/25 19:16:07
That said, please just use two out variables; don'
Eran Messeri
2015/03/26 10:47:17
Done - as Ryan suggested.
| |
| 48 size_t num_months; | |
| 49 bool last_month_is_full; | |
|
davidben
2015/03/25 19:10:11
last_month_is_full to me reads like you're roundin
Eran Messeri
2015/03/26 10:47:17
Renamed to has_partial_month as suggested.
| |
| 50 }; | |
| 51 | |
| 52 /* | |
|
davidben
2015/03/25 19:10:11
Use // C++-style comments rather than /* C-style *
Eran Messeri
2015/03/26 10:47:17
Done.
| |
| 53 * Returns a rounded-down months difference of |start| and |end|, | |
| 54 * together with an indication of whether the last month was | |
| 55 * a full month, because the range starts specified in the policy | |
| 56 * are not consistent in terms of including the range start value. | |
| 57 */ | |
| 58 MonthsDiff RoundedDownMonthDifference(const base::Time& start, | |
| 59 const base::Time& end) { | |
| 48 base::Time::Exploded exploded_start; | 60 base::Time::Exploded exploded_start; |
| 49 base::Time::Exploded exploded_expiry; | 61 base::Time::Exploded exploded_expiry; |
| 50 start.UTCExplode(&exploded_start); | 62 start.UTCExplode(&exploded_start); |
| 51 end.UTCExplode(&exploded_expiry); | 63 end.UTCExplode(&exploded_expiry); |
| 64 if (end < start) | |
| 65 return MonthsDiff(); | |
|
davidben
2015/03/25 19:10:11
Not that it matters, but I think this actually wan
Eran Messeri
2015/03/26 10:47:17
Done.
| |
| 66 | |
| 67 MonthsDiff ret; | |
| 68 ret.last_month_is_full = false; | |
| 52 uint32_t month_diff = (exploded_expiry.year - exploded_start.year) * 12 + | 69 uint32_t month_diff = (exploded_expiry.year - exploded_start.year) * 12 + |
| 53 (exploded_expiry.month - exploded_start.month); | 70 (exploded_expiry.month - exploded_start.month); |
| 71 if (exploded_expiry.day_of_month < exploded_start.day_of_month) | |
| 72 --month_diff; | |
| 73 else if (exploded_expiry.day_of_month == exploded_start.day_of_month) | |
| 74 ret.last_month_is_full = true; | |
|
davidben
2015/03/25 19:10:11
It occurs to me this also doesn't account for hour
Eran Messeri
2015/03/26 10:47:17
No benefit to being that tedious, it'd be extra co
| |
| 54 | 75 |
| 55 // Add any remainder as a full month. | 76 ret.num_months = month_diff; |
| 56 if (exploded_expiry.day_of_month > exploded_start.day_of_month) | 77 return ret; |
| 57 ++month_diff; | |
| 58 | |
| 59 return month_diff; | |
| 60 } | 78 } |
| 61 | 79 |
| 62 bool HasRequiredNumberOfSCTs(const X509Certificate& cert, | 80 bool HasRequiredNumberOfSCTs(const X509Certificate& cert, |
| 63 const ct::CTVerifyResult& ct_result) { | 81 const ct::CTVerifyResult& ct_result) { |
| 64 // TODO(eranm): Count the number of *independent* SCTs once the information | 82 // TODO(eranm): Count the number of *independent* SCTs once the information |
| 65 // about log operators is available, crbug.com/425174 | 83 // about log operators is available, crbug.com/425174 |
| 66 size_t num_valid_scts = ct_result.verified_scts.size(); | 84 size_t num_valid_scts = ct_result.verified_scts.size(); |
| 67 size_t num_embedded_scts = | 85 size_t num_embedded_scts = |
| 68 std::count_if(ct_result.verified_scts.begin(), | 86 std::count_if(ct_result.verified_scts.begin(), |
| 69 ct_result.verified_scts.end(), IsEmbeddedSCT); | 87 ct_result.verified_scts.end(), IsEmbeddedSCT); |
| 70 | 88 |
| 71 size_t num_non_embedded_scts = num_valid_scts - num_embedded_scts; | 89 size_t num_non_embedded_scts = num_valid_scts - num_embedded_scts; |
| 72 // If at least two valid SCTs were delivered by means other than embedding | 90 // If at least two valid SCTs were delivered by means other than embedding |
| 73 // (i.e. in a TLS extension or OCSP), then the certificate conforms to bullet | 91 // (i.e. in a TLS extension or OCSP), then the certificate conforms to bullet |
| 74 // number 3 of the "Qualifying Certificate" section of the CT/EV policy. | 92 // number 3 of the "Qualifying Certificate" section of the CT/EV policy. |
| 75 if (num_non_embedded_scts >= 2) | 93 if (num_non_embedded_scts >= 2) |
| 76 return true; | 94 return true; |
| 77 | 95 |
| 78 if (cert.valid_start().is_null() || cert.valid_expiry().is_null() || | 96 if (cert.valid_start().is_null() || cert.valid_expiry().is_null() || |
| 79 cert.valid_start().is_max() || cert.valid_expiry().is_max()) { | 97 cert.valid_start().is_max() || cert.valid_expiry().is_max()) { |
| 80 // Will not be able to calculate the certificate's validity period. | 98 // Will not be able to calculate the certificate's validity period. |
| 81 return false; | 99 return false; |
| 82 } | 100 } |
| 83 | 101 |
| 84 uint32_t expiry_in_months_approx = | 102 MonthsDiff exp = |
|
davidben
2015/03/25 19:10:11
exp -> lifetime? I first read that as exponentiati
Eran Messeri
2015/03/26 10:47:17
Done - rename to lifetime. You're right, it's not
| |
| 85 ApproximateMonthDifference(cert.valid_start(), cert.valid_expiry()); | 103 RoundedDownMonthDifference(cert.valid_start(), cert.valid_expiry()); |
| 86 | 104 |
| 87 // For embedded SCTs, if the certificate has the number of SCTs specified in | 105 // For embedded SCTs, if the certificate has the number of SCTs specified in |
| 88 // table 1 of the "Qualifying Certificate" section of the CT/EV policy, then | 106 // table 1 of the "Qualifying Certificate" section of the CT/EV policy, then |
| 89 // it qualifies. | 107 // it qualifies. |
| 90 size_t num_required_embedded_scts; | 108 size_t num_required_embedded_scts; |
| 91 if (expiry_in_months_approx > 39) { | 109 if ((exp.num_months > 39) || |
| 110 (exp.num_months == 39 && !exp.last_month_is_full)) { | |
| 92 num_required_embedded_scts = 5; | 111 num_required_embedded_scts = 5; |
| 93 } else if (expiry_in_months_approx > 27) { | 112 } else if ((exp.num_months > 27) || |
| 113 (exp.num_months == 27 && !exp.last_month_is_full)) { | |
| 94 num_required_embedded_scts = 4; | 114 num_required_embedded_scts = 4; |
| 95 } else if (expiry_in_months_approx >= 15) { | 115 } else if (exp.num_months >= 15) { |
| 96 num_required_embedded_scts = 3; | 116 num_required_embedded_scts = 3; |
| 97 } else { | 117 } else { |
| 98 num_required_embedded_scts = 2; | 118 num_required_embedded_scts = 2; |
| 99 } | 119 } |
| 100 | 120 |
| 101 return num_embedded_scts >= num_required_embedded_scts; | 121 return num_embedded_scts >= num_required_embedded_scts; |
| 102 } | 122 } |
| 103 | 123 |
| 104 enum CTComplianceStatus { | 124 enum CTComplianceStatus { |
| 105 CT_NOT_COMPLIANT = 0, | 125 CT_NOT_COMPLIANT = 0, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 | 286 |
| 267 LogCTComplianceStatusToUMA(details.status, ev_whitelist); | 287 LogCTComplianceStatusToUMA(details.status, ev_whitelist); |
| 268 | 288 |
| 269 if (details.status == CT_IN_WHITELIST || details.status == CT_ENOUGH_SCTS) | 289 if (details.status == CT_IN_WHITELIST || details.status == CT_ENOUGH_SCTS) |
| 270 return true; | 290 return true; |
| 271 | 291 |
| 272 return false; | 292 return false; |
| 273 } | 293 } |
| 274 | 294 |
| 275 } // namespace net | 295 } // namespace net |
| OLD | NEW |