trial_comparison_cert_verifier.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef NET_CERT_TRIAL_COMPARISON_CERT_VERIFIER_H_
  5. #define NET_CERT_TRIAL_COMPARISON_CERT_VERIFIER_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <set>
  9. #include <string>
  10. #include "base/containers/unique_ptr_adapters.h"
  11. #include "base/memory/ref_counted.h"
  12. #include "base/memory/weak_ptr.h"
  13. #include "base/threading/thread_checker.h"
  14. #include "net/base/net_export.h"
  15. #include "net/cert/cert_verifier.h"
  16. namespace net {
  17. class CertVerifyProc;
  18. class CertVerifyProcFactory;
  19. class CertNetFetcher;
  20. class ChromeRootStoreData;
  21. // TrialComparisonCertVerifier is a CertVerifier that can be used to compare
  22. // the results between two different CertVerifyProcs. The results are reported
  23. // back to the caller via a ReportCallback, allowing the caller to further
  24. // examine the differences.
  25. class NET_EXPORT TrialComparisonCertVerifier
  26. : public CertVerifierWithUpdatableProc {
  27. public:
  28. using ReportCallback = base::RepeatingCallback<void(
  29. const std::string& hostname,
  30. const scoped_refptr<X509Certificate>& unverified_cert,
  31. bool enable_rev_checking,
  32. bool require_rev_checking_local_anchors,
  33. bool enable_sha1_local_anchors,
  34. bool disable_symantec_enforcement,
  35. const std::string& stapled_ocsp,
  36. const std::string& sct_list,
  37. const net::CertVerifyResult& primary_result,
  38. const net::CertVerifyResult& trial_result)>;
  39. // Create a new TrialComparisonCertVerifier. Initially, no trial
  40. // verifications will actually be performed; that is, calls to Verify() will
  41. // be dispatched to the underlying |primary_verify_proc|. This can be changed
  42. // by calling set_trial_allowed().
  43. //
  44. // When trial verifications are enabled, calls to Verify() will first call
  45. // into |primary_verify_proc| to verify. The result of this verification will
  46. // be immediately returned to the caller of Verify, allowing them to proceed.
  47. // However, the verifier will continue in the background, attempting to
  48. // verify the same RequestParams using |trial_verify_proc|. If there are
  49. // differences in the results, they will be reported via |report_callback|,
  50. // allowing the creator to receive information about differences.
  51. //
  52. // If the caller abandons the CertVerifier::Request prior to the primary
  53. // verification completed, no trial verification will be done. However, once
  54. // the primary verifier has returned, the trial verifications will continue,
  55. // provided that the underlying configuration has not been changed by
  56. // calling SetConfig().
  57. //
  58. // Note that there may be multiple calls to both |primary_verify_proc| and
  59. // |trial_verify_proc|, using different parameters to account for platform
  60. // differences.
  61. TrialComparisonCertVerifier(
  62. scoped_refptr<CertVerifyProc> primary_verify_proc,
  63. scoped_refptr<CertVerifyProcFactory> primary_verify_proc_factory,
  64. scoped_refptr<CertVerifyProc> trial_verify_proc,
  65. scoped_refptr<CertVerifyProcFactory> trial_verify_proc_factory,
  66. ReportCallback report_callback);
  67. TrialComparisonCertVerifier(const TrialComparisonCertVerifier&) = delete;
  68. TrialComparisonCertVerifier& operator=(const TrialComparisonCertVerifier&) =
  69. delete;
  70. ~TrialComparisonCertVerifier() override;
  71. void set_trial_allowed(bool allowed) { allowed_ = allowed; }
  72. bool trial_allowed() const { return allowed_; }
  73. // CertVerifier implementation
  74. int Verify(const RequestParams& params,
  75. CertVerifyResult* verify_result,
  76. CompletionOnceCallback callback,
  77. std::unique_ptr<Request>* out_req,
  78. const NetLogWithSource& net_log) override;
  79. void SetConfig(const Config& config) override;
  80. void UpdateChromeRootStoreData(
  81. scoped_refptr<CertNetFetcher> cert_net_fetcher,
  82. const ChromeRootStoreData* root_store_data) override;
  83. private:
  84. class Job;
  85. friend class Job;
  86. CertVerifier* primary_verifier() const { return primary_verifier_.get(); }
  87. CertVerifier* primary_reverifier() const { return primary_reverifier_.get(); }
  88. CertVerifier* trial_verifier() const { return trial_verifier_.get(); }
  89. CertVerifier* revocation_trial_verifier() const {
  90. return revocation_trial_verifier_.get();
  91. }
  92. void RemoveJob(Job* job_ptr);
  93. // Whether the trial is allowed.
  94. bool allowed_ = false;
  95. // Callback that reports are sent to.
  96. ReportCallback report_callback_;
  97. CertVerifier::Config config_;
  98. std::unique_ptr<CertVerifierWithUpdatableProc> primary_verifier_;
  99. std::unique_ptr<CertVerifierWithUpdatableProc> primary_reverifier_;
  100. std::unique_ptr<CertVerifierWithUpdatableProc> trial_verifier_;
  101. // Similar to |trial_verifier_|, except configured to always check
  102. // revocation information.
  103. std::unique_ptr<CertVerifierWithUpdatableProc> revocation_trial_verifier_;
  104. std::set<std::unique_ptr<Job>, base::UniquePtrComparator> jobs_;
  105. THREAD_CHECKER(thread_checker_);
  106. };
  107. } // namespace net
  108. #endif // NET_CERT_TRIAL_COMPARISON_CERT_VERIFIER_H_