• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_CERT_INTERNAL_TRUST_STORE_ANDROID_H_
6 #define NET_CERT_INTERNAL_TRUST_STORE_ANDROID_H_
7 
8 #include <atomic>
9 
10 #include "base/memory/ptr_util.h"
11 #include "base/memory/scoped_refptr.h"
12 #include "base/synchronization/lock.h"
13 #include "net/base/net_export.h"
14 #include "net/cert/cert_database.h"
15 #include "net/cert/pki/trust_store.h"
16 #include "net/cert/pki/trust_store_in_memory.h"
17 
18 namespace net {
19 
20 // TrustStoreAndroid is an implementation of TrustStore which uses the Android
21 // cert systems to find user-added trust anchors for path building. It ignores
22 // the Android builtin trust anchors.
23 class NET_EXPORT TrustStoreAndroid : public TrustStore,
24                                      public CertDatabase::Observer {
25  public:
26   TrustStoreAndroid();
27   ~TrustStoreAndroid() override;
28   TrustStoreAndroid(const TrustStoreAndroid& other) = delete;
29   TrustStoreAndroid& operator=(const TrustStoreAndroid& other) = delete;
30 
31   // Load user settings from Android.
32   void Initialize();
33 
34   void SyncGetIssuersOf(const ParsedCertificate* cert,
35                         ParsedCertificateList* issuers) override;
36 
37   CertificateTrust GetTrust(const ParsedCertificate* cert,
38                             base::SupportsUserData* debug_data) override;
39 
40   // CertDatabase::Observer:
41   void OnCertDBChanged() override;
42 
43   // Have this object start listening for CertDB changes.
44   // This function is not thread safe, and must be called from a sequence.
45   void ObserveCertDBChanges();
46 
47  private:
48   bool is_observing_certdb_changes = false;
49 
50   // Inner Impl class for use in initializing stores.
51   class Impl;
52 
53   // Loads user settings from Windows CertStores if not already done and
54   // returns scoped_refptr<Impl>.
55   scoped_refptr<Impl> MaybeInitializeAndGetImpl();
56 
57   base::Lock init_lock_;
58   scoped_refptr<Impl> impl_ GUARDED_BY(init_lock_);
59   // Generation number that is incremented whenever the backing Android trust
60   // store changes.
61   std::atomic_int generation_ = 0;
62 };
63 
64 }  // namespace net
65 
66 #endif  // NET_CERT_INTERNAL_TRUST_STORE_ANDROID_H_
67