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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
12 #include "net/cert/x509_certificate.h" | 12 #include "net/cert/x509_certificate.h" |
13 | 13 |
14 template <typename T> struct DefaultSingletonTraits; | 14 template <typename T> struct DefaultSingletonTraits; |
15 template <class ObserverType> class ObserverListThreadSafe; | 15 template <class ObserverType> class ObserverListThreadSafe; |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 class NSSCertDatabase; | |
20 | |
21 // This class provides cross-platform functions to verify and add user | 19 // This class provides cross-platform functions to verify and add user |
22 // certificates, and to observe changes to the underlying certificate stores. | 20 // certificates, and to observe changes to the underlying certificate stores. |
23 | 21 |
24 // TODO(gauravsh): This class could be augmented with methods | 22 // TODO(gauravsh): This class could be augmented with methods |
25 // for all operations that manipulate the underlying system | 23 // for all operations that manipulate the underlying system |
26 // certificate store. | 24 // certificate store. |
27 | 25 |
28 class NET_EXPORT CertDatabase { | 26 class NET_EXPORT CertDatabase { |
29 public: | 27 public: |
30 // A CertDatabase::Observer will be notified on certificate database changes. | 28 // A CertDatabase::Observer will be notified on certificate database changes. |
31 // The change could be either a new user certificate is added or trust on | 29 // The change could be either a user certificate is added/removed or trust on |
32 // a certificate is changed. Observers can register themselves | 30 // a certificate is changed. Observers can be registered via |
33 // via CertDatabase::AddObserver, and can un-register with | 31 // CertDatabase::AddObserver, and can un-register with |
34 // CertDatabase::RemoveObserver. | 32 // CertDatabase::RemoveObserver. |
35 class NET_EXPORT Observer { | 33 class NET_EXPORT Observer { |
36 public: | 34 public: |
37 virtual ~Observer() {} | 35 virtual ~Observer() {} |
38 | 36 |
39 // Will be called when a new certificate is added. | 37 // Will be called when a new certificate is added. |
38 // Called with |cert| == NULL after an import of multiple certificates. | |
Ryan Sleevi
2014/07/10 21:17:14
I feel like this is committing too much of the int
pneubeck (no reviews)
2014/07/11 08:39:07
Done.
| |
40 virtual void OnCertAdded(const X509Certificate* cert) {} | 39 virtual void OnCertAdded(const X509Certificate* cert) {} |
41 | 40 |
42 // Will be called when a certificate is removed. | 41 // Will be called when a certificate is removed. |
43 virtual void OnCertRemoved(const X509Certificate* cert) {} | 42 virtual void OnCertRemoved(const X509Certificate* cert) {} |
44 | 43 |
45 // Will be called when a CA certificate was added, removed, or its trust | 44 // Will be called when a CA certificate was added, removed, or its trust |
46 // changed. This can also mean that a client certificate's trust changed. | 45 // changed. This can also mean that a client certificate's trust changed. |
46 // Called with |cert| == NULL after an import of multiple certificates. | |
Ryan Sleevi
2014/07/10 21:17:13
This comment feels like an implementation detail t
pneubeck (no reviews)
2014/07/11 08:39:07
Done.
| |
47 virtual void OnCACertChanged(const X509Certificate* cert) {} | 47 virtual void OnCACertChanged(const X509Certificate* cert) {} |
48 | 48 |
49 protected: | 49 protected: |
50 Observer() {} | 50 Observer() {} |
51 | 51 |
52 private: | 52 private: |
53 DISALLOW_COPY_AND_ASSIGN(Observer); | 53 DISALLOW_COPY_AND_ASSIGN(Observer); |
54 }; | 54 }; |
55 | 55 |
56 // Returns the CertDatabase singleton. | 56 // Returns the CertDatabase singleton. |
(...skipping 29 matching lines...) Expand all Loading... | |
86 // KeyStore used for storing client certificates. When the Java side replaces | 86 // KeyStore used for storing client certificates. When the Java side replaces |
87 // the KeyStore used for client certificates, notifies the observers as if a | 87 // the KeyStore used for client certificates, notifies the observers as if a |
88 // new client certificate was added. | 88 // new client certificate was added. |
89 void OnAndroidKeyStoreChanged(); | 89 void OnAndroidKeyStoreChanged(); |
90 | 90 |
91 // On Android, the system database is used. When the system notifies the | 91 // On Android, the system database is used. When the system notifies the |
92 // application that the certificates changed, the observers must be notified. | 92 // application that the certificates changed, the observers must be notified. |
93 void OnAndroidKeyChainChanged(); | 93 void OnAndroidKeyChainChanged(); |
94 #endif | 94 #endif |
95 | 95 |
96 #if defined(USE_NSS) | 96 // Broadcasts notifications to all registered observers. |
Ryan Sleevi
2014/07/10 21:17:13
Perhaps reword, to indicate
// Synthetically inje
| |
97 // Observe events from the |source| and forward them to observers of this | 97 void NotifyObserversOfCertAdded(const X509Certificate* cert); |
98 // CertDatabase. | 98 void NotifyObserversOfCertRemoved(const X509Certificate* cert); |
99 void ObserveNSSCertDatabase(NSSCertDatabase* source); | 99 void NotifyObserversOfCACertChanged(const X509Certificate* cert); |
100 #endif | |
101 | 100 |
102 private: | 101 private: |
103 friend struct DefaultSingletonTraits<CertDatabase>; | 102 friend struct DefaultSingletonTraits<CertDatabase>; |
104 | 103 |
105 CertDatabase(); | 104 CertDatabase(); |
106 ~CertDatabase(); | 105 ~CertDatabase(); |
107 | 106 |
108 // Broadcasts notifications to all registered observers. | |
109 void NotifyObserversOfCertAdded(const X509Certificate* cert); | |
110 void NotifyObserversOfCertRemoved(const X509Certificate* cert); | |
111 void NotifyObserversOfCACertChanged(const X509Certificate* cert); | |
112 | |
113 const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; | 107 const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; |
114 | 108 |
115 #if defined(USE_NSS) || (defined(OS_MACOSX) && !defined(OS_IOS)) | 109 #if defined(OS_MACOSX) && !defined(OS_IOS) |
116 class Notifier; | 110 class Notifier; |
117 friend class Notifier; | 111 friend class Notifier; |
118 scoped_ptr<Notifier> notifier_; | 112 scoped_ptr<Notifier> notifier_; |
119 #endif | 113 #endif |
120 | 114 |
121 DISALLOW_COPY_AND_ASSIGN(CertDatabase); | 115 DISALLOW_COPY_AND_ASSIGN(CertDatabase); |
122 }; | 116 }; |
123 | 117 |
124 } // namespace net | 118 } // namespace net |
125 | 119 |
126 #endif // NET_CERT_CERT_DATABASE_H_ | 120 #endif // NET_CERT_CERT_DATABASE_H_ |
OLD | NEW |