OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef NET_CERT_CERT_DATABASE_H_ | 5 #ifndef NET_CERT_CERT_DATABASE_H_ |
6 #define NET_CERT_CERT_DATABASE_H_ | 6 #define NET_CERT_CERT_DATABASE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 public: | 32 public: |
33 // A CertDatabase::Observer will be notified on certificate database changes. | 33 // A CertDatabase::Observer will be notified on certificate database changes. |
34 // The change could be either a user certificate is added/removed or trust on | 34 // The change could be either a user certificate is added/removed or trust on |
35 // a certificate is changed. Observers can be registered via | 35 // a certificate is changed. Observers can be registered via |
36 // CertDatabase::AddObserver, and can un-register with | 36 // CertDatabase::AddObserver, and can un-register with |
37 // CertDatabase::RemoveObserver. | 37 // CertDatabase::RemoveObserver. |
38 class NET_EXPORT Observer { | 38 class NET_EXPORT Observer { |
39 public: | 39 public: |
40 virtual ~Observer() {} | 40 virtual ~Observer() {} |
41 | 41 |
42 // Will be called when a new certificate is added. If the imported cert can | 42 // Called whenever the Cert Database is known to have changed. |
43 // be determined, |cert| will be non-NULL, but if not, or if multiple | 43 // Typically, this will be in response to a CA certificate being added, |
44 // certificates were imported, |cert| may be NULL. | 44 // removed, or its trust changed, but may also signal on client |
45 virtual void OnCertAdded(const X509Certificate* cert) {} | 45 // certificate events when they can be reliably detected. |
46 | 46 virtual void OnCertDBChanged(const X509Certificate* cert) {} |
47 // Will be called when a certificate is removed. | |
48 virtual void OnCertRemoved(const X509Certificate* cert) {} | |
49 | |
50 // Will be called when a CA certificate was added, removed, or its trust | |
51 // changed. This can also mean that a client certificate's trust changed. | |
52 virtual void OnCACertChanged(const X509Certificate* cert) {} | |
53 | 47 |
54 protected: | 48 protected: |
55 Observer() {} | 49 Observer() {} |
56 | 50 |
57 private: | 51 private: |
58 DISALLOW_COPY_AND_ASSIGN(Observer); | 52 DISALLOW_COPY_AND_ASSIGN(Observer); |
59 }; | 53 }; |
60 | 54 |
61 // Returns the CertDatabase singleton. | 55 // Returns the CertDatabase singleton. |
62 static CertDatabase* GetInstance(); | 56 static CertDatabase* GetInstance(); |
63 | 57 |
64 // Check whether this is a valid user cert that we have the private key for. | |
65 // Returns OK or a network error code such as ERR_CERT_CONTAINS_ERRORS. | |
66 int CheckUserCert(X509Certificate* cert); | |
67 | |
68 // Store user (client) certificate. Assumes CheckUserCert has already passed. | |
69 // Returns OK, or ERR_ADD_USER_CERT_FAILED if there was a problem saving to | |
70 // the platform cert database, or possibly other network error codes. | |
71 int AddUserCert(X509Certificate* cert); | |
72 | |
73 // Registers |observer| to receive notifications of certificate changes. The | 58 // Registers |observer| to receive notifications of certificate changes. The |
74 // thread on which this is called is the thread on which |observer| will be | 59 // thread on which this is called is the thread on which |observer| will be |
75 // called back with notifications. | 60 // called back with notifications. |
76 void AddObserver(Observer* observer); | 61 void AddObserver(Observer* observer); |
77 | 62 |
78 // Unregisters |observer| from receiving notifications. This must be called | 63 // Unregisters |observer| from receiving notifications. This must be called |
79 // on the same thread on which AddObserver() was called. | 64 // on the same thread on which AddObserver() was called. |
80 void RemoveObserver(Observer* observer); | 65 void RemoveObserver(Observer* observer); |
81 | 66 |
82 #if defined(OS_MACOSX) && !defined(OS_IOS) | 67 #if defined(OS_MACOSX) && !defined(OS_IOS) |
(...skipping 11 matching lines...) Expand all Loading... |
94 void OnAndroidKeyStoreChanged(); | 79 void OnAndroidKeyStoreChanged(); |
95 | 80 |
96 // On Android, the system database is used. When the system notifies the | 81 // On Android, the system database is used. When the system notifies the |
97 // application that the certificates changed, the observers must be notified. | 82 // application that the certificates changed, the observers must be notified. |
98 void OnAndroidKeyChainChanged(); | 83 void OnAndroidKeyChainChanged(); |
99 #endif | 84 #endif |
100 | 85 |
101 // Synthetically injects notifications to all observers. In general, this | 86 // Synthetically injects notifications to all observers. In general, this |
102 // should only be called by the creator of the CertDatabase. Used to inject | 87 // should only be called by the creator of the CertDatabase. Used to inject |
103 // notifcations from other DB interfaces. | 88 // notifcations from other DB interfaces. |
104 void NotifyObserversOfCertAdded(const X509Certificate* cert); | 89 void NotifyObserversCertDBChanged(const X509Certificate* cert); |
105 void NotifyObserversOfCertRemoved(const X509Certificate* cert); | |
106 void NotifyObserversOfCACertChanged(const X509Certificate* cert); | |
107 | 90 |
108 private: | 91 private: |
109 friend struct base::DefaultSingletonTraits<CertDatabase>; | 92 friend struct base::DefaultSingletonTraits<CertDatabase>; |
110 | 93 |
111 CertDatabase(); | 94 CertDatabase(); |
112 ~CertDatabase(); | 95 ~CertDatabase(); |
113 | 96 |
114 const scoped_refptr<base::ObserverListThreadSafe<Observer>> observer_list_; | 97 const scoped_refptr<base::ObserverListThreadSafe<Observer>> observer_list_; |
115 | 98 |
116 #if defined(OS_MACOSX) && !defined(OS_IOS) | 99 #if defined(OS_MACOSX) && !defined(OS_IOS) |
117 class Notifier; | 100 class Notifier; |
118 friend class Notifier; | 101 friend class Notifier; |
119 std::unique_ptr<Notifier> notifier_; | 102 std::unique_ptr<Notifier> notifier_; |
120 #endif | 103 #endif |
121 | 104 |
122 DISALLOW_COPY_AND_ASSIGN(CertDatabase); | 105 DISALLOW_COPY_AND_ASSIGN(CertDatabase); |
123 }; | 106 }; |
124 | 107 |
125 } // namespace net | 108 } // namespace net |
126 | 109 |
127 #endif // NET_CERT_CERT_DATABASE_H_ | 110 #endif // NET_CERT_CERT_DATABASE_H_ |
OLD | NEW |