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/build_time.h" | 10 #include "base/build_time.h" |
11 #include "base/callback_helpers.h" | |
10 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
11 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
12 #include "base/numerics/safe_conversions.h" | 14 #include "base/numerics/safe_conversions.h" |
13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/values.h" | |
17 #include "net/base/net_log.h" | |
14 #include "net/cert/ct_ev_whitelist.h" | 18 #include "net/cert/ct_ev_whitelist.h" |
15 #include "net/cert/ct_verify_result.h" | 19 #include "net/cert/ct_verify_result.h" |
16 #include "net/cert/signed_certificate_timestamp.h" | 20 #include "net/cert/signed_certificate_timestamp.h" |
17 #include "net/cert/x509_certificate.h" | 21 #include "net/cert/x509_certificate.h" |
22 #include "net/cert/x509_certificate_net_log_param.h" | |
18 | 23 |
19 namespace net { | 24 namespace net { |
20 | 25 |
21 namespace { | 26 namespace { |
22 | 27 |
23 bool IsEmbeddedSCT(const scoped_refptr<ct::SignedCertificateTimestamp>& sct) { | 28 bool IsEmbeddedSCT(const scoped_refptr<ct::SignedCertificateTimestamp>& sct) { |
24 return sct->origin == ct::SignedCertificateTimestamp::SCT_EMBEDDED; | 29 return sct->origin == ct::SignedCertificateTimestamp::SCT_EMBEDDED; |
25 } | 30 } |
26 | 31 |
27 // Returns true if the current build is recent enough to ensure that | 32 // Returns true if the current build is recent enough to ensure that |
(...skipping 30 matching lines...) Expand all Loading... | |
58 CT_IN_WHITELIST = 1, | 63 CT_IN_WHITELIST = 1, |
59 CT_ENOUGH_SCTS = 2, | 64 CT_ENOUGH_SCTS = 2, |
60 CT_COMPLIANCE_MAX, | 65 CT_COMPLIANCE_MAX, |
61 }; | 66 }; |
62 | 67 |
63 void LogCTComplianceStatusToUMA(CTComplianceStatus status) { | 68 void LogCTComplianceStatusToUMA(CTComplianceStatus status) { |
64 UMA_HISTOGRAM_ENUMERATION("Net.SSL_EVCertificateCTCompliance", status, | 69 UMA_HISTOGRAM_ENUMERATION("Net.SSL_EVCertificateCTCompliance", status, |
65 CT_COMPLIANCE_MAX); | 70 CT_COMPLIANCE_MAX); |
66 } | 71 } |
67 | 72 |
73 base::Value* NetLogNonCompliantCertCallback(X509Certificate* cert, | |
74 NetLog::LogLevel log_level) { | |
75 base::DictionaryValue* dict = new base::DictionaryValue(); | |
76 | |
77 dict->Set("non_compliant_cert", | |
78 NetLogX509CertificateCallback(cert, log_level)); | |
79 | |
davidben
2014/12/08 22:42:35
Style nit: I probably wouldn't bother with the bla
Eran Messeri
2014/12/09 19:58:15
Done.
| |
80 return dict; | |
81 } | |
82 | |
68 } // namespace | 83 } // namespace |
69 | 84 |
70 CertPolicyEnforcer::CertPolicyEnforcer(size_t num_ct_logs, | 85 CertPolicyEnforcer::CertPolicyEnforcer(size_t num_ct_logs, |
71 bool require_ct_for_ev) | 86 bool require_ct_for_ev) |
72 : num_ct_logs_(num_ct_logs), require_ct_for_ev_(require_ct_for_ev) { | 87 : num_ct_logs_(num_ct_logs), require_ct_for_ev_(require_ct_for_ev) { |
73 } | 88 } |
74 | 89 |
75 CertPolicyEnforcer::~CertPolicyEnforcer() { | 90 CertPolicyEnforcer::~CertPolicyEnforcer() { |
76 } | 91 } |
77 | 92 |
78 bool CertPolicyEnforcer::DoesConformToCTEVPolicy( | 93 bool CertPolicyEnforcer::DoesConformToCTEVPolicy( |
79 X509Certificate* cert, | 94 X509Certificate* cert, |
80 const ct::EVCertsWhitelist* ev_whitelist, | 95 const ct::EVCertsWhitelist* ev_whitelist, |
81 const ct::CTVerifyResult& ct_result) { | 96 const ct::CTVerifyResult& ct_result, |
97 const BoundNetLog& net_log) { | |
82 if (!require_ct_for_ev_) | 98 if (!require_ct_for_ev_) |
83 return true; | 99 return true; |
84 | 100 |
85 if (!IsBuildTimely()) | 101 if (!IsBuildTimely()) |
86 return false; | 102 return false; |
87 | 103 |
88 if (IsCertificateInWhitelist(cert, ev_whitelist)) { | 104 if (IsCertificateInWhitelist(cert, ev_whitelist)) { |
89 LogCTComplianceStatusToUMA(CT_IN_WHITELIST); | 105 LogCTComplianceStatusToUMA(CT_IN_WHITELIST); |
90 return true; | 106 return true; |
91 } | 107 } |
92 | 108 |
93 if (HasRequiredNumberOfSCTs(cert, ct_result)) { | 109 if (HasRequiredNumberOfSCTs(cert, ct_result)) { |
94 LogCTComplianceStatusToUMA(CT_ENOUGH_SCTS); | 110 LogCTComplianceStatusToUMA(CT_ENOUGH_SCTS); |
95 return true; | 111 return true; |
96 } | 112 } |
97 | 113 |
98 LogCTComplianceStatusToUMA(CT_NOT_COMPLIANT); | 114 LogCTComplianceStatusToUMA(CT_NOT_COMPLIANT); |
115 | |
116 NetLog::ParametersCallback net_log_callback = | |
117 base::Bind(&NetLogNonCompliantCertCallback, base::Unretained(cert)); | |
118 | |
119 net_log.AddEvent(NetLog::TYPE_NON_COMPLIANT_EV_CERT_ENCOUNTERED, | |
120 net_log_callback); | |
99 return false; | 121 return false; |
100 } | 122 } |
101 | 123 |
102 bool CertPolicyEnforcer::IsCertificateInWhitelist( | 124 bool CertPolicyEnforcer::IsCertificateInWhitelist( |
103 X509Certificate* cert, | 125 X509Certificate* cert, |
104 const ct::EVCertsWhitelist* ev_whitelist) { | 126 const ct::EVCertsWhitelist* ev_whitelist) { |
105 bool cert_in_ev_whitelist = false; | 127 bool cert_in_ev_whitelist = false; |
106 if (ev_whitelist && ev_whitelist->IsValid()) { | 128 if (ev_whitelist && ev_whitelist->IsValid()) { |
107 const SHA256HashValue fingerprint( | 129 const SHA256HashValue fingerprint( |
108 X509Certificate::CalculateFingerprint256(cert->os_cert_handle())); | 130 X509Certificate::CalculateFingerprint256(cert->os_cert_handle())); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 } else { | 178 } else { |
157 num_required_embedded_scts = 2; | 179 num_required_embedded_scts = 2; |
158 } | 180 } |
159 | 181 |
160 size_t min_acceptable_logs = std::max(num_ct_logs_, static_cast<size_t>(2u)); | 182 size_t min_acceptable_logs = std::max(num_ct_logs_, static_cast<size_t>(2u)); |
161 return num_embedded_scts >= | 183 return num_embedded_scts >= |
162 std::min(num_required_embedded_scts, min_acceptable_logs); | 184 std::min(num_required_embedded_scts, min_acceptable_logs); |
163 } | 185 } |
164 | 186 |
165 } // namespace net | 187 } // namespace net |
OLD | NEW |