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

Side by Side Diff: components/cast_certificate/cast_cert_validator.cc

Issue 2050983002: Cast device revocation checking. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (Rebase only) 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 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 "components/cast_certificate/cast_cert_validator.h" 5 #include "components/cast_certificate/cast_cert_validator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <memory> 11 #include <memory>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
16 #include "net/cert/internal/cert_issuer_source_static.h" 16 #include "net/cert/internal/cert_issuer_source_static.h"
17 #include "components/cast_certificate/cast_crl.h"
17 #include "net/cert/internal/certificate_policies.h" 18 #include "net/cert/internal/certificate_policies.h"
18 #include "net/cert/internal/extended_key_usage.h" 19 #include "net/cert/internal/extended_key_usage.h"
19 #include "net/cert/internal/parse_certificate.h" 20 #include "net/cert/internal/parse_certificate.h"
20 #include "net/cert/internal/parse_name.h" 21 #include "net/cert/internal/parse_name.h"
21 #include "net/cert/internal/parsed_certificate.h" 22 #include "net/cert/internal/parsed_certificate.h"
22 #include "net/cert/internal/path_builder.h" 23 #include "net/cert/internal/path_builder.h"
23 #include "net/cert/internal/signature_algorithm.h" 24 #include "net/cert/internal/signature_algorithm.h"
24 #include "net/cert/internal/signature_policy.h" 25 #include "net/cert/internal/signature_policy.h"
25 #include "net/cert/internal/trust_store.h" 26 #include "net/cert/internal/trust_store.h"
26 #include "net/cert/internal/verify_signed_data.h" 27 #include "net/cert/internal/verify_signed_data.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // necessary. Should revisit this for removal in 2017 if not earlier. 261 // necessary. Should revisit this for removal in 2017 if not earlier.
261 options.allow_invalid_serial_numbers = true; 262 options.allow_invalid_serial_numbers = true;
262 return options; 263 return options;
263 } 264 }
264 265
265 } // namespace 266 } // namespace
266 267
267 bool VerifyDeviceCert(const std::vector<std::string>& certs, 268 bool VerifyDeviceCert(const std::vector<std::string>& certs,
268 const base::Time::Exploded& time, 269 const base::Time::Exploded& time,
269 std::unique_ptr<CertVerificationContext>* context, 270 std::unique_ptr<CertVerificationContext>* context,
270 CastDeviceCertPolicy* policy) { 271 CastDeviceCertPolicy* policy,
272 const CastCRL* crl,
273 CRLOptions& crl_options) {
271 if (certs.empty()) 274 if (certs.empty())
272 return false; 275 return false;
273 276
274 // No reference to these ParsedCertificates is kept past the end of this 277 // No reference to these ParsedCertificates is kept past the end of this
275 // function, so using EXTERNAL_REFERENCE here is safe. 278 // function, so using EXTERNAL_REFERENCE here is safe.
276 scoped_refptr<net::ParsedCertificate> target_cert; 279 scoped_refptr<net::ParsedCertificate> target_cert;
277 net::CertIssuerSourceStatic intermediate_cert_issuer_source; 280 net::CertIssuerSourceStatic intermediate_cert_issuer_source;
278 for (size_t i = 0; i < certs.size(); ++i) { 281 for (size_t i = 0; i < certs.size(); ++i) {
279 scoped_refptr<net::ParsedCertificate> cert( 282 scoped_refptr<net::ParsedCertificate> cert(
280 net::ParsedCertificate::CreateFromCertificateData( 283 net::ParsedCertificate::CreateFromCertificateData(
(...skipping 19 matching lines...) Expand all
300 signature_policy.get(), 303 signature_policy.get(),
301 ConvertExplodedTime(time), &result); 304 ConvertExplodedTime(time), &result);
302 path_builder.AddCertIssuerSource(&intermediate_cert_issuer_source); 305 path_builder.AddCertIssuerSource(&intermediate_cert_issuer_source);
303 net::CompletionStatus rv = path_builder.Run(base::Closure()); 306 net::CompletionStatus rv = path_builder.Run(base::Closure());
304 DCHECK_EQ(rv, net::CompletionStatus::SYNC); 307 DCHECK_EQ(rv, net::CompletionStatus::SYNC);
305 if (!result.is_success()) 308 if (!result.is_success())
306 return false; 309 return false;
307 310
308 // Check properties of the leaf certificate (key usage, policy), and construct 311 // Check properties of the leaf certificate (key usage, policy), and construct
309 // a CertVerificationContext that uses its public key. 312 // a CertVerificationContext that uses its public key.
310 return CheckTargetCertificate(target_cert.get(), context, policy); 313 if (!CheckTargetCertificate(target_cert.get(), context, policy))
314 return false;
315
316 // Check if a CRL is available.
317 if (!crl) {
318 if (crl_options.crl_required) {
319 return false;
320 }
321 return true;
eroman 2016/07/12 21:21:59 Can you remove this "return true" and instead have
ryanchung 2016/07/14 16:15:25 Done. Thanks!
322 }
323 if (result.paths.empty() ||
324 !result.paths[result.best_result_index]->is_success())
325 return false;
326
327 return crl->CheckRevocation(result.paths[result.best_result_index]->path,
328 time);
311 } 329 }
312 330
313 std::unique_ptr<CertVerificationContext> CertVerificationContextImplForTest( 331 std::unique_ptr<CertVerificationContext> CertVerificationContextImplForTest(
314 const base::StringPiece& spki) { 332 const base::StringPiece& spki) {
315 // Use a bogus CommonName, since this is just exposed for testing signature 333 // Use a bogus CommonName, since this is just exposed for testing signature
316 // verification by unittests. 334 // verification by unittests.
317 return base::WrapUnique( 335 return base::WrapUnique(
318 new CertVerificationContextImpl(net::der::Input(spki), "CommonName")); 336 new CertVerificationContextImpl(net::der::Input(spki), "CommonName"));
319 } 337 }
320 338
321 bool AddTrustAnchorForTest(const uint8_t* data, size_t length) { 339 bool SetTrustAnchorForTest(const uint8_t* data, size_t length) {
322 scoped_refptr<net::ParsedCertificate> anchor( 340 scoped_refptr<net::ParsedCertificate> anchor(
323 net::ParsedCertificate::CreateFromCertificateData( 341 net::ParsedCertificate::CreateFromCertificateData(
324 data, length, net::ParsedCertificate::DataSource::EXTERNAL_REFERENCE, 342 data, length, net::ParsedCertificate::DataSource::EXTERNAL_REFERENCE,
325 GetCertParsingOptions())); 343 GetCertParsingOptions()));
326 if (!anchor) 344 if (!anchor)
327 return false; 345 return false;
346 CastTrustStore::Get().Clear();
eroman 2016/07/12 21:22:00 optional: Maybe this should be done unconditionall
ryanchung 2016/07/14 16:15:24 Sounds good. Should the return value still be fals
eroman 2016/07/15 22:52:48 Good question... Perhaps your approach is better
ryanchung 2016/07/18 23:39:07 I'll stick with original plan. Replace only if anc
328 CastTrustStore::Get().AddTrustedCertificate(std::move(anchor)); 347 CastTrustStore::Get().AddTrustedCertificate(std::move(anchor));
329 return true; 348 return true;
330 } 349 }
331 350
332 } // namespace cast_certificate 351 } // namespace cast_certificate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698