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 dict->Set("non_compliant_cert", | |
77 NetLogX509CertificateCallback(cert, log_level)); | |
78 return dict; | |
79 } | |
80 | |
68 } // namespace | 81 } // namespace |
69 | 82 |
70 CertPolicyEnforcer::CertPolicyEnforcer(size_t num_ct_logs, | 83 CertPolicyEnforcer::CertPolicyEnforcer(size_t num_ct_logs, |
71 bool require_ct_for_ev) | 84 bool require_ct_for_ev) |
72 : num_ct_logs_(num_ct_logs), require_ct_for_ev_(require_ct_for_ev) { | 85 : num_ct_logs_(num_ct_logs), require_ct_for_ev_(require_ct_for_ev) { |
73 } | 86 } |
74 | 87 |
75 CertPolicyEnforcer::~CertPolicyEnforcer() { | 88 CertPolicyEnforcer::~CertPolicyEnforcer() { |
76 } | 89 } |
77 | 90 |
78 bool CertPolicyEnforcer::DoesConformToCTEVPolicy( | 91 bool CertPolicyEnforcer::DoesConformToCTEVPolicy( |
79 X509Certificate* cert, | 92 X509Certificate* cert, |
80 const ct::EVCertsWhitelist* ev_whitelist, | 93 const ct::EVCertsWhitelist* ev_whitelist, |
81 const ct::CTVerifyResult& ct_result) { | 94 const ct::CTVerifyResult& ct_result, |
95 const BoundNetLog& net_log) { | |
82 if (!require_ct_for_ev_) | 96 if (!require_ct_for_ev_) |
83 return true; | 97 return true; |
84 | 98 |
85 if (!IsBuildTimely()) | 99 if (!IsBuildTimely()) |
86 return false; | 100 return false; |
87 | 101 |
88 if (IsCertificateInWhitelist(cert, ev_whitelist)) { | 102 if (IsCertificateInWhitelist(cert, ev_whitelist)) { |
89 LogCTComplianceStatusToUMA(CT_IN_WHITELIST); | 103 LogCTComplianceStatusToUMA(CT_IN_WHITELIST); |
90 return true; | 104 return true; |
91 } | 105 } |
92 | 106 |
93 if (HasRequiredNumberOfSCTs(cert, ct_result)) { | 107 if (HasRequiredNumberOfSCTs(cert, ct_result)) { |
94 LogCTComplianceStatusToUMA(CT_ENOUGH_SCTS); | 108 LogCTComplianceStatusToUMA(CT_ENOUGH_SCTS); |
95 return true; | 109 return true; |
96 } | 110 } |
97 | 111 |
98 LogCTComplianceStatusToUMA(CT_NOT_COMPLIANT); | 112 LogCTComplianceStatusToUMA(CT_NOT_COMPLIANT); |
113 | |
114 NetLog::ParametersCallback net_log_callback = | |
115 base::Bind(&NetLogNonCompliantCertCallback, base::Unretained(cert)); | |
116 | |
117 net_log.AddEvent(NetLog::TYPE_NON_COMPLIANT_EV_CERT_ENCOUNTERED, | |
118 net_log_callback); | |
Ryan Sleevi
2014/12/09 20:50:42
Ok, I'm going to push back on this with a "Not LGT
Eran Messeri
2014/12/10 15:38:38
I understand the main concern is not logging all p
| |
99 return false; | 119 return false; |
100 } | 120 } |
101 | 121 |
102 bool CertPolicyEnforcer::IsCertificateInWhitelist( | 122 bool CertPolicyEnforcer::IsCertificateInWhitelist( |
103 X509Certificate* cert, | 123 X509Certificate* cert, |
104 const ct::EVCertsWhitelist* ev_whitelist) { | 124 const ct::EVCertsWhitelist* ev_whitelist) { |
105 bool cert_in_ev_whitelist = false; | 125 bool cert_in_ev_whitelist = false; |
106 if (ev_whitelist && ev_whitelist->IsValid()) { | 126 if (ev_whitelist && ev_whitelist->IsValid()) { |
107 const SHA256HashValue fingerprint( | 127 const SHA256HashValue fingerprint( |
108 X509Certificate::CalculateFingerprint256(cert->os_cert_handle())); | 128 X509Certificate::CalculateFingerprint256(cert->os_cert_handle())); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 } else { | 176 } else { |
157 num_required_embedded_scts = 2; | 177 num_required_embedded_scts = 2; |
158 } | 178 } |
159 | 179 |
160 size_t min_acceptable_logs = std::max(num_ct_logs_, static_cast<size_t>(2u)); | 180 size_t min_acceptable_logs = std::max(num_ct_logs_, static_cast<size_t>(2u)); |
161 return num_embedded_scts >= | 181 return num_embedded_scts >= |
162 std::min(num_required_embedded_scts, min_acceptable_logs); | 182 std::min(num_required_embedded_scts, min_acceptable_logs); |
163 } | 183 } |
164 | 184 |
165 } // namespace net | 185 } // namespace net |
OLD | NEW |