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

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

Issue 2100303002: Add OCSPVerifyResult for tracking stapled OCSP responses cross-platform. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ocsp-date-check
Patch Set: Add tests for REVOKED status Created 4 years, 5 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
« no previous file with comments | « no previous file | net/cert/cert_verify_result.h » ('j') | net/cert/cert_verify_result.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_verify_proc.h" 5 #include "net/cert/cert_verify_proc.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 bool IsPastSHA1DeprecationDate(const X509Certificate& cert) { 175 bool IsPastSHA1DeprecationDate(const X509Certificate& cert) {
176 const base::Time& start = cert.valid_start(); 176 const base::Time& start = cert.valid_start();
177 if (start.is_max() || start.is_null()) 177 if (start.is_max() || start.is_null())
178 return true; 178 return true;
179 // 2016-01-01 00:00:00 UTC. 179 // 2016-01-01 00:00:00 UTC.
180 const base::Time kSHA1DeprecationDate = 180 const base::Time kSHA1DeprecationDate =
181 base::Time::FromInternalValue(INT64_C(13096080000000000)); 181 base::Time::FromInternalValue(INT64_C(13096080000000000));
182 return start >= kSHA1DeprecationDate; 182 return start >= kSHA1DeprecationDate;
183 } 183 }
184 184
185 bool CompareCertIDToCertificate(const OCSPCertID& cert_id,
svaldez 2016/06/29 14:41:22 Might need a different name, since this only retur
dadrian 2016/06/30 21:52:42 Done.
186 const X509Certificate& certificate) {
187 // TODO(dadrian): Verify name and key hashes. https://crbug.com/620005
188 der::Input serial(&certificate.serial_number());
189 return serial == cert_id.serial_number;
svaldez 2016/06/29 14:41:22 nit: Swap to match method name.
dadrian 2016/06/30 21:52:42 Done.
190 }
191
192 void CheckOCSP(const std::string& raw_response,
193 CertVerifyResult* verify_result) {
194 verify_result->ocsp.Reset();
195
196 if (raw_response.empty()) {
197 verify_result->ocsp.response_status = OCSPVerifyResult::MISSING;
198 return;
199 }
200 der::Input response_der(&raw_response);
201
202 OCSPResponse response;
203 if (!ParseOCSPResponse(response_der, &response)) {
204 verify_result->ocsp.response_status = OCSPVerifyResult::PARSE_RESPONSE;
205 return;
206 }
207
208 // If the OCSP response isn't status SUCCESSFUL, don't parse the rest of the
209 // data.
210 if (response.status != OCSPResponse::ResponseStatus::SUCCESSFUL) {
211 verify_result->ocsp.response_status = OCSPVerifyResult::BAD_RESPONSE;
212 return;
213 }
214
215 OCSPResponseData response_data;
216 if (!ParseOCSPResponseData(response.data, &response_data)) {
217 verify_result->ocsp.response_status = OCSPVerifyResult::PARSE_RESPONSE_DATA;
218 return;
219 }
220
221 // TODO(svaldez): Unify with GetOCSPCertStatus.
222 base::Time verify_time = base::Time::Now();
223 base::TimeDelta max_age = base::TimeDelta::FromDays(7);
224 verify_result->ocsp.response_status = OCSPVerifyResult::NO_MATCHING_RESPONSE;
225 for (const auto& single_response_der : response_data.responses) {
226 OCSPSingleResponse single_response;
227 if (!ParseOCSPSingleResponse(single_response_der, &single_response))
svaldez 2016/06/29 14:41:22 Should either of these be setting response_status?
228 continue;
229 OCSPCertID cert_id;
230 if (!ParseOCSPCertID(single_response.cert_id_tlv, &cert_id))
231 continue;
232 if (!CompareCertIDToCertificate(cert_id, *verify_result->verified_cert))
233 continue;
234 if (!CheckOCSPDateValid(single_response, verify_time, max_age)) {
235 if (verify_result->ocsp.response_status != OCSPVerifyResult::PROVIDED)
236 verify_result->ocsp.response_status = OCSPVerifyResult::INVALID_DATE;
237 continue;
238 }
239 verify_result->ocsp.response_status = OCSPVerifyResult::PROVIDED;
240 if (single_response.cert_status.status >=
241 verify_result->ocsp.cert_status.value_or(
242 OCSPCertStatus::Status::GOOD)) {
svaldez 2016/06/29 14:41:22 This really should use the same ordering from pars
dadrian 2016/06/30 21:52:42 Done.
243 verify_result->ocsp.cert_status = single_response.cert_status.status;
244 }
245 }
246 }
247
185 // Comparison functor used for binary searching whether a given HashValue, 248 // Comparison functor used for binary searching whether a given HashValue,
186 // which MUST be a SHA-256 hash, is contained with an array of SHA-256 249 // which MUST be a SHA-256 hash, is contained with an array of SHA-256
187 // hashes. 250 // hashes.
188 struct HashToArrayComparator { 251 struct HashToArrayComparator {
189 template <size_t N> 252 template <size_t N>
190 bool operator()(const uint8_t(&lhs)[N], const HashValue& rhs) const { 253 bool operator()(const uint8_t(&lhs)[N], const HashValue& rhs) const {
191 static_assert(N == crypto::kSHA256Length, 254 static_assert(N == crypto::kSHA256Length,
192 "Only SHA-256 hashes are supported"); 255 "Only SHA-256 hashes are supported");
193 return memcmp(lhs, rhs.data(), crypto::kSHA256Length) < 0; 256 return memcmp(lhs, rhs.data(), crypto::kSHA256Length) < 0;
194 } 257 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 int rv = VerifyInternal(cert, hostname, ocsp_response, flags, crl_set, 314 int rv = VerifyInternal(cert, hostname, ocsp_response, flags, crl_set,
252 additional_trust_anchors, verify_result); 315 additional_trust_anchors, verify_result);
253 316
254 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallback", 317 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallback",
255 verify_result->common_name_fallback_used); 318 verify_result->common_name_fallback_used);
256 if (!verify_result->is_issued_by_known_root) { 319 if (!verify_result->is_issued_by_known_root) {
257 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallbackPrivateCA", 320 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallbackPrivateCA",
258 verify_result->common_name_fallback_used); 321 verify_result->common_name_fallback_used);
259 } 322 }
260 323
324 // Check OCSP information
325 CheckOCSP(ocsp_response, verify_result);
326
261 // This check is done after VerifyInternal so that VerifyInternal can fill 327 // This check is done after VerifyInternal so that VerifyInternal can fill
262 // in the list of public key hashes. 328 // in the list of public key hashes.
263 if (IsPublicKeyBlacklisted(verify_result->public_key_hashes)) { 329 if (IsPublicKeyBlacklisted(verify_result->public_key_hashes)) {
264 verify_result->cert_status |= CERT_STATUS_REVOKED; 330 verify_result->cert_status |= CERT_STATUS_REVOKED;
265 rv = MapCertStatusToNetError(verify_result->cert_status); 331 rv = MapCertStatusToNetError(verify_result->cert_status);
266 } 332 }
267 333
268 std::vector<std::string> dns_names, ip_addrs; 334 std::vector<std::string> dns_names, ip_addrs;
269 cert->GetSubjectAltName(&dns_names, &ip_addrs); 335 cert->GetSubjectAltName(&dns_names, &ip_addrs);
270 if (HasNameConstraintsViolation(verify_result->public_key_hashes, 336 if (HasNameConstraintsViolation(verify_result->public_key_hashes,
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 return true; 642 return true;
577 643
578 // For certificates issued after 1 April 2015: 39 months. 644 // For certificates issued after 1 April 2015: 39 months.
579 if (start >= time_2015_04_01 && month_diff > 39) 645 if (start >= time_2015_04_01 && month_diff > 39)
580 return true; 646 return true;
581 647
582 return false; 648 return false;
583 } 649 }
584 650
585 } // namespace net 651 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/cert/cert_verify_result.h » ('j') | net/cert/cert_verify_result.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698