multi_threaded_cert_verifier.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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
  3. // found in the LICENSE file.
  4. #ifndef NET_CERT_MULTI_THREADED_CERT_VERIFIER_H_
  5. #define NET_CERT_MULTI_THREADED_CERT_VERIFIER_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <map>
  9. #include <memory>
  10. #include "base/containers/linked_list.h"
  11. #include "base/memory/ref_counted.h"
  12. #include "base/threading/thread_checker.h"
  13. #include "crypto/crypto_buildflags.h"
  14. #include "net/base/net_export.h"
  15. #include "net/cert/cert_verifier.h"
  16. #if BUILDFLAG(USE_NSS_CERTS)
  17. #include "net/cert/scoped_nss_types.h"
  18. #endif
  19. namespace net {
  20. class CertVerifyProc;
  21. class CertNetFetcher;
  22. class CertVerifyProcFactory;
  23. class ChromeRootStoreData;
  24. // MultiThreadedCertVerifier is a CertVerifier implementation that runs
  25. // synchronous CertVerifier implementations on worker threads.
  26. class NET_EXPORT_PRIVATE MultiThreadedCertVerifier
  27. : public CertVerifierWithUpdatableProc {
  28. public:
  29. explicit MultiThreadedCertVerifier(scoped_refptr<CertVerifyProc> verify_proc);
  30. explicit MultiThreadedCertVerifier(
  31. scoped_refptr<CertVerifyProc> verify_proc,
  32. scoped_refptr<CertVerifyProcFactory> verify_proc_factory);
  33. MultiThreadedCertVerifier(const MultiThreadedCertVerifier&) = delete;
  34. MultiThreadedCertVerifier& operator=(const MultiThreadedCertVerifier&) =
  35. delete;
  36. // When the verifier is destroyed, all certificate verifications requests are
  37. // canceled, and their completion callbacks will not be called.
  38. ~MultiThreadedCertVerifier() override;
  39. // CertVerifier implementation
  40. int Verify(const RequestParams& params,
  41. CertVerifyResult* verify_result,
  42. CompletionOnceCallback callback,
  43. std::unique_ptr<Request>* out_req,
  44. const NetLogWithSource& net_log) override;
  45. void SetConfig(const CertVerifier::Config& config) override;
  46. void UpdateChromeRootStoreData(
  47. scoped_refptr<CertNetFetcher> cert_net_fetcher,
  48. const ChromeRootStoreData* root_store_data) override;
  49. private:
  50. class InternalRequest;
  51. Config config_;
  52. scoped_refptr<CertVerifyProc> verify_proc_;
  53. scoped_refptr<CertVerifyProcFactory> verify_proc_factory_;
  54. // Holds a list of CertVerifier::Requests that have not yet completed or been
  55. // deleted. It is used to ensure that when the MultiThreadedCertVerifier is
  56. // deleted, we eagerly reset all of the callbacks provided to Verify(), and
  57. // don't call them later, as required by the CertVerifier contract.
  58. base::LinkedList<InternalRequest> request_list_;
  59. #if BUILDFLAG(USE_NSS_CERTS)
  60. // Holds NSS temporary certificates that will be exposed as untrusted
  61. // authorities by SystemCertStoreNSS.
  62. // TODO(https://crbug.com/978854): Pass these into the actual CertVerifyProc
  63. // rather than relying on global side-effects.
  64. net::ScopedCERTCertificateList temp_certs_;
  65. #endif
  66. THREAD_CHECKER(thread_checker_);
  67. };
  68. } // namespace net
  69. #endif // NET_CERT_MULTI_THREADED_CERT_VERIFIER_H_