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

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: Extract OCSPCertStatus::Status from internal 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
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
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/sha1.h" 13 #include "base/sha1.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
20 #include "net/base/url_util.h" 20 #include "net/base/url_util.h"
21 #include "net/cert/cert_status_flags.h" 21 #include "net/cert/cert_status_flags.h"
22 #include "net/cert/cert_verifier.h" 22 #include "net/cert/cert_verifier.h"
23 #include "net/cert/cert_verify_proc_whitelist.h" 23 #include "net/cert/cert_verify_proc_whitelist.h"
24 #include "net/cert/cert_verify_result.h" 24 #include "net/cert/cert_verify_result.h"
25 #include "net/cert/crl_set.h" 25 #include "net/cert/crl_set.h"
26 #include "net/cert/internal/parse_ocsp.h"
27 #include "net/cert/ocsp_revocation_status.h"
26 #include "net/cert/x509_certificate.h" 28 #include "net/cert/x509_certificate.h"
29 #include "net/der/encode_values.h"
27 #include "url/url_canon.h" 30 #include "url/url_canon.h"
28 31
29 #if defined(USE_NSS_CERTS) 32 #if defined(USE_NSS_CERTS)
30 #include "net/cert/cert_verify_proc_nss.h" 33 #include "net/cert/cert_verify_proc_nss.h"
31 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID) 34 #elif defined(USE_OPENSSL_CERTS) && !defined(OS_ANDROID)
32 #include "net/cert/cert_verify_proc_openssl.h" 35 #include "net/cert/cert_verify_proc_openssl.h"
33 #elif defined(OS_ANDROID) 36 #elif defined(OS_ANDROID)
34 #include "net/cert/cert_verify_proc_android.h" 37 #include "net/cert/cert_verify_proc_android.h"
35 #elif defined(OS_IOS) 38 #elif defined(OS_IOS)
36 #include "net/cert/cert_verify_proc_ios.h" 39 #include "net/cert/cert_verify_proc_ios.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 bool IsPastSHA1DeprecationDate(const X509Certificate& cert) { 178 bool IsPastSHA1DeprecationDate(const X509Certificate& cert) {
176 const base::Time& start = cert.valid_start(); 179 const base::Time& start = cert.valid_start();
177 if (start.is_max() || start.is_null()) 180 if (start.is_max() || start.is_null())
178 return true; 181 return true;
179 // 2016-01-01 00:00:00 UTC. 182 // 2016-01-01 00:00:00 UTC.
180 const base::Time kSHA1DeprecationDate = 183 const base::Time kSHA1DeprecationDate =
181 base::Time::FromInternalValue(INT64_C(13096080000000000)); 184 base::Time::FromInternalValue(INT64_C(13096080000000000));
182 return start >= kSHA1DeprecationDate; 185 return start >= kSHA1DeprecationDate;
183 } 186 }
184 187
188 bool CheckCertIDMatchesCertificate(const OCSPCertID& cert_id,
189 const X509Certificate& certificate) {
190 // TODO(dadrian): Verify name and key hashes. https://crbug.com/620005
191 der::Input serial(&certificate.serial_number());
192 return cert_id.serial_number == serial;
193 }
194
195 void CheckOCSP(const std::string& raw_response,
196 CertVerifyResult* verify_result) {
197 verify_result->ocsp.Reset();
198
199 if (raw_response.empty()) {
200 verify_result->ocsp.response_status = OCSPVerifyResult::MISSING;
201 return;
202 }
203 der::Input response_der(&raw_response);
204
205 OCSPResponse response;
206 if (!ParseOCSPResponse(response_der, &response)) {
207 verify_result->ocsp.response_status = OCSPVerifyResult::PARSE_RESPONSE;
208 return;
209 }
210
211 // If the OCSP response isn't status SUCCESSFUL, don't parse the rest of the
212 // data.
213 if (response.status != OCSPResponse::ResponseStatus::SUCCESSFUL) {
214 verify_result->ocsp.response_status = OCSPVerifyResult::BAD_RESPONSE;
215 return;
216 }
217
218 OCSPResponseData response_data;
219 if (!ParseOCSPResponseData(response.data, &response_data)) {
220 verify_result->ocsp.response_status = OCSPVerifyResult::PARSE_RESPONSE_DATA;
221 return;
222 }
223
224 // If producedAt is outside of the certificate validity period, reject the
225 // response.
226 der::GeneralizedTime not_before, not_after;
227 if (!der::EncodeTimeAsGeneralizedTime(
228 verify_result->verified_cert->valid_start(), &not_before) ||
229 !der::EncodeTimeAsGeneralizedTime(
230 verify_result->verified_cert->valid_expiry(), &not_after)) {
231 verify_result->ocsp.response_status = OCSPVerifyResult::BAD_PRODUCED_AT;
232 return;
233 }
234 if (response_data.produced_at < not_before ||
235 response_data.produced_at > not_after) {
236 verify_result->ocsp.response_status = OCSPVerifyResult::BAD_PRODUCED_AT;
237 return;
238 }
239
240 // TODO(svaldez): Unify with GetOCSPCertStatus.
241 base::Time verify_time = base::Time::Now();
242 base::TimeDelta max_age = base::TimeDelta::FromDays(7);
243 verify_result->ocsp.response_status = OCSPVerifyResult::NO_MATCHING_RESPONSE;
244 for (const auto& single_response_der : response_data.responses) {
245 OCSPSingleResponse single_response;
246 if (!ParseOCSPSingleResponse(single_response_der, &single_response))
247 continue;
248 OCSPCertID cert_id;
249 if (!ParseOCSPCertID(single_response.cert_id_tlv, &cert_id))
250 continue;
251 if (!CheckCertIDMatchesCertificate(cert_id, *verify_result->verified_cert))
252 continue;
253 if (!CheckOCSPDateValid(single_response, verify_time, max_age)) {
254 if (verify_result->ocsp.response_status != OCSPVerifyResult::PROVIDED)
255 verify_result->ocsp.response_status = OCSPVerifyResult::INVALID_DATE;
256 continue;
257 }
258 verify_result->ocsp.response_status = OCSPVerifyResult::PROVIDED;
259
260 OCSPRevocationStatus current_status =
261 verify_result->ocsp.cert_status.value_or(OCSPRevocationStatus::GOOD);
262 // In the case that we receive multiple responses, we keep only the
263 // strictest status (REVOKED > UNKNOWN > GOOD).
264 if (current_status == OCSPRevocationStatus::GOOD ||
265 single_response.cert_status.status == OCSPRevocationStatus::REVOKED) {
266 verify_result->ocsp.cert_status = single_response.cert_status.status;
267 }
268 }
269 }
270
185 // Comparison functor used for binary searching whether a given HashValue, 271 // 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 272 // which MUST be a SHA-256 hash, is contained with an array of SHA-256
187 // hashes. 273 // hashes.
188 struct HashToArrayComparator { 274 struct HashToArrayComparator {
189 template <size_t N> 275 template <size_t N>
190 bool operator()(const uint8_t(&lhs)[N], const HashValue& rhs) const { 276 bool operator()(const uint8_t(&lhs)[N], const HashValue& rhs) const {
191 static_assert(N == crypto::kSHA256Length, 277 static_assert(N == crypto::kSHA256Length,
192 "Only SHA-256 hashes are supported"); 278 "Only SHA-256 hashes are supported");
193 return memcmp(lhs, rhs.data(), crypto::kSHA256Length) < 0; 279 return memcmp(lhs, rhs.data(), crypto::kSHA256Length) < 0;
194 } 280 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 int rv = VerifyInternal(cert, hostname, ocsp_response, flags, crl_set, 337 int rv = VerifyInternal(cert, hostname, ocsp_response, flags, crl_set,
252 additional_trust_anchors, verify_result); 338 additional_trust_anchors, verify_result);
253 339
254 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallback", 340 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallback",
255 verify_result->common_name_fallback_used); 341 verify_result->common_name_fallback_used);
256 if (!verify_result->is_issued_by_known_root) { 342 if (!verify_result->is_issued_by_known_root) {
257 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallbackPrivateCA", 343 UMA_HISTOGRAM_BOOLEAN("Net.CertCommonNameFallbackPrivateCA",
258 verify_result->common_name_fallback_used); 344 verify_result->common_name_fallback_used);
259 } 345 }
260 346
347 // Check OCSP information
estark 2016/07/14 21:14:58 nit: non-useful comment, I think you could just de
dadrian 2016/07/15 01:00:50 Done.
348 CheckOCSP(ocsp_response, verify_result);
349
261 // This check is done after VerifyInternal so that VerifyInternal can fill 350 // This check is done after VerifyInternal so that VerifyInternal can fill
262 // in the list of public key hashes. 351 // in the list of public key hashes.
263 if (IsPublicKeyBlacklisted(verify_result->public_key_hashes)) { 352 if (IsPublicKeyBlacklisted(verify_result->public_key_hashes)) {
264 verify_result->cert_status |= CERT_STATUS_REVOKED; 353 verify_result->cert_status |= CERT_STATUS_REVOKED;
265 rv = MapCertStatusToNetError(verify_result->cert_status); 354 rv = MapCertStatusToNetError(verify_result->cert_status);
266 } 355 }
267 356
268 std::vector<std::string> dns_names, ip_addrs; 357 std::vector<std::string> dns_names, ip_addrs;
269 cert->GetSubjectAltName(&dns_names, &ip_addrs); 358 cert->GetSubjectAltName(&dns_names, &ip_addrs);
270 if (HasNameConstraintsViolation(verify_result->public_key_hashes, 359 if (HasNameConstraintsViolation(verify_result->public_key_hashes,
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 return true; 665 return true;
577 666
578 // For certificates issued after 1 April 2015: 39 months. 667 // For certificates issued after 1 April 2015: 39 months.
579 if (start >= time_2015_04_01 && month_diff > 39) 668 if (start >= time_2015_04_01 && month_diff > 39)
580 return true; 669 return true;
581 670
582 return false; 671 return false;
583 } 672 }
584 673
585 } // namespace net 674 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/cert/cert_verify_result.h » ('j') | net/test/spawned_test_server/base_test_server.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698