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

Side by Side Diff: net/cert/internal/path_builder.cc

Issue 2292333002: Add errors per ResultPath for CertPathBuilder. (Closed)
Patch Set: Created 4 years, 3 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/internal/path_builder.h" 5 #include "net/cert/internal/path_builder.h"
6 6
7 #include <set> 7 #include <set>
8 #include <unordered_set> 8 #include <unordered_set>
9 9
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 out_path_ = nullptr; 614 out_path_ = nullptr;
615 base::ResetAndReturn(&callback_).Run(); 615 base::ResetAndReturn(&callback_).Run();
616 } 616 }
617 } 617 }
618 618
619 CertPathBuilder::ResultPath::ResultPath() = default; 619 CertPathBuilder::ResultPath::ResultPath() = default;
620 CertPathBuilder::ResultPath::~ResultPath() = default; 620 CertPathBuilder::ResultPath::~ResultPath() = default;
621 CertPathBuilder::Result::Result() = default; 621 CertPathBuilder::Result::Result() = default;
622 CertPathBuilder::Result::~Result() = default; 622 CertPathBuilder::Result::~Result() = default;
623 623
624 const CertPathBuilder::ResultPath* CertPathBuilder::Result::GetBestValidPath()
625 const {
626 DCHECK((paths.empty() && best_result_index == 0) ||
627 best_result_index < paths.size());
628
629 if (best_result_index >= paths.size())
630 return nullptr;
631
632 const ResultPath* result_path = paths[best_result_index].get();
633 if (result_path->valid)
634 return result_path;
635
636 return nullptr;
637 }
638
639 bool CertPathBuilder::Result::HasValidPath() const {
640 return GetBestValidPath() != nullptr;
641 }
642
624 CertPathBuilder::CertPathBuilder(scoped_refptr<ParsedCertificate> cert, 643 CertPathBuilder::CertPathBuilder(scoped_refptr<ParsedCertificate> cert,
625 const TrustStore* trust_store, 644 const TrustStore* trust_store,
626 const SignaturePolicy* signature_policy, 645 const SignaturePolicy* signature_policy,
627 const der::GeneralizedTime& time, 646 const der::GeneralizedTime& time,
628 Result* result) 647 Result* result)
629 : cert_path_iter_(new CertPathIter(std::move(cert), trust_store)), 648 : cert_path_iter_(new CertPathIter(std::move(cert), trust_store)),
630 signature_policy_(signature_policy), 649 signature_policy_(signature_policy),
631 time_(time), 650 time_(time),
632 next_state_(STATE_NONE), 651 next_state_(STATE_NONE),
633 out_result_(result) {} 652 out_result_(result) {}
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 base::ResetAndReturn(&callback_).Run(); 707 base::ResetAndReturn(&callback_).Run();
689 } 708 }
690 709
691 CompletionStatus CertPathBuilder::DoGetNextPathComplete() { 710 CompletionStatus CertPathBuilder::DoGetNextPathComplete() {
692 if (next_path_.IsEmpty()) { 711 if (next_path_.IsEmpty()) {
693 // No more paths to check, signal completion. 712 // No more paths to check, signal completion.
694 next_state_ = STATE_NONE; 713 next_state_ = STATE_NONE;
695 return CompletionStatus::SYNC; 714 return CompletionStatus::SYNC;
696 } 715 }
697 716
698 // TODO(crbug.com/634443): Expose CertErrors on ResultPath. 717 // Verify the entire certificate chain.
699 CertErrors errors; 718 auto result_path = base::MakeUnique<ResultPath>();
700 bool verify_result = 719 bool verify_result =
701 next_path_.trust_anchor.get() &&
eroman 2016/08/31 21:46:50 [1] Reference
702 VerifyCertificateChain(next_path_.certs, next_path_.trust_anchor.get(), 720 VerifyCertificateChain(next_path_.certs, next_path_.trust_anchor.get(),
703 signature_policy_, time_, &errors); 721 signature_policy_, time_, &result_path->errors);
704 DVLOG(1) << "CertPathBuilder VerifyCertificateChain result = " 722 DVLOG(1) << "CertPathBuilder VerifyCertificateChain result = "
705 << verify_result; 723 << result_path->valid;
706 AddResultPath(next_path_, verify_result); 724 result_path->path = next_path_;
725 result_path->valid = verify_result;
726 AddResultPath(std::move(result_path));
707 727
708 if (verify_result) { 728 if (verify_result) {
709 // Found a valid path, return immediately. 729 // Found a valid path, return immediately.
710 // TODO(mattm): add debug/test mode that tries all possible paths. 730 // TODO(mattm): add debug/test mode that tries all possible paths.
711 next_state_ = STATE_NONE; 731 next_state_ = STATE_NONE;
712 return CompletionStatus::SYNC; 732 return CompletionStatus::SYNC;
713 } 733 }
714 734
715 // Path did not verify. Try more paths. If there are no more paths, the result 735 // Path did not verify. Try more paths. If there are no more paths, the result
716 // will be returned next time DoGetNextPathComplete is called with next_path_ 736 // will be returned next time DoGetNextPathComplete is called with next_path_
717 // empty. 737 // empty.
718 next_state_ = STATE_GET_NEXT_PATH; 738 next_state_ = STATE_GET_NEXT_PATH;
719 return CompletionStatus::SYNC; 739 return CompletionStatus::SYNC;
720 } 740 }
721 741
722 void CertPathBuilder::AddResultPath(const CertPath& path, bool is_success) { 742 void CertPathBuilder::AddResultPath(std::unique_ptr<ResultPath> result_path) {
723 std::unique_ptr<ResultPath> result_path(new ResultPath());
724 // TODO(mattm): better error reporting.
725 result_path->error = is_success ? OK : ERR_CERT_AUTHORITY_INVALID;
726 // TODO(mattm): set best_result_index based on number or severity of errors. 743 // TODO(mattm): set best_result_index based on number or severity of errors.
727 if (result_path->error == OK) 744 if (result_path->valid)
728 out_result_->best_result_index = out_result_->paths.size(); 745 out_result_->best_result_index = out_result_->paths.size();
729 // TODO(mattm): add flag to only return a single path or all attempted paths? 746 // TODO(mattm): add flag to only return a single path or all attempted paths?
730 result_path->path = path;
731 out_result_->paths.push_back(std::move(result_path)); 747 out_result_->paths.push_back(std::move(result_path));
732 } 748 }
733 749
734 } // namespace net 750 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698