cert_verifier_with_trust_anchors.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2013 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 SERVICES_NETWORK_CERT_VERIFIER_WITH_TRUST_ANCHORS_H_
  5. #define SERVICES_NETWORK_CERT_VERIFIER_WITH_TRUST_ANCHORS_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "base/callback.h"
  9. #include "base/compiler_specific.h"
  10. #include "base/component_export.h"
  11. #include "base/memory/ref_counted.h"
  12. #include "base/threading/thread_checker.h"
  13. #include "net/base/completion_once_callback.h"
  14. #include "net/cert/cert_verifier.h"
  15. namespace net {
  16. class CertVerifyResult;
  17. class X509Certificate;
  18. typedef std::vector<scoped_refptr<X509Certificate>> CertificateList;
  19. } // namespace net
  20. namespace network {
  21. // Wraps a net::CertVerifier to make it use the additional trust anchors
  22. // configured by the ONC user policy.
  23. class COMPONENT_EXPORT(NETWORK_SERVICE) CertVerifierWithTrustAnchors
  24. : public net::CertVerifier {
  25. public:
  26. // Except of the constructor, all methods and the destructor must be called on
  27. // the IO thread. Calls |anchor_used_callback| on the IO thread every time a
  28. // certificate from the additional trust anchors (set with SetTrustAnchors) is
  29. // used.
  30. explicit CertVerifierWithTrustAnchors(
  31. const base::RepeatingClosure& anchor_used_callback);
  32. CertVerifierWithTrustAnchors(const CertVerifierWithTrustAnchors&) = delete;
  33. CertVerifierWithTrustAnchors& operator=(const CertVerifierWithTrustAnchors&) =
  34. delete;
  35. ~CertVerifierWithTrustAnchors() override;
  36. // TODO(jam): once the network service is the only path, rename or get rid of
  37. // this method.
  38. void InitializeOnIOThread(std::unique_ptr<net::CertVerifier> delegate);
  39. // Sets the additional trust anchors and untrusted authorities to be
  40. // considered as intermediates.
  41. void SetAdditionalCerts(const net::CertificateList& trust_anchors,
  42. const net::CertificateList& untrusted_authorities);
  43. // CertVerifier:
  44. int Verify(const RequestParams& params,
  45. net::CertVerifyResult* verify_result,
  46. net::CompletionOnceCallback callback,
  47. std::unique_ptr<Request>* out_req,
  48. const net::NetLogWithSource& net_log) override;
  49. void SetConfig(const Config& config) override;
  50. private:
  51. net::CertVerifier::Config orig_config_;
  52. net::CertificateList trust_anchors_;
  53. net::CertificateList untrusted_authorities_;
  54. base::RepeatingClosure anchor_used_callback_;
  55. std::unique_ptr<CertVerifier> delegate_;
  56. THREAD_CHECKER(thread_checker_);
  57. };
  58. } // namespace network
  59. #endif // SERVICES_NETWORK_CERT_VERIFIER_WITH_TRUST_ANCHORS_H_