OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ |
7 | 7 |
| 8 #include <queue> |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/linked_ptr.h" |
13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
15 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" | 17 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" |
16 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
17 | 19 |
18 namespace content { | 20 namespace content { |
19 class BrowserContext; | 21 class BrowserContext; |
20 } | 22 } |
21 | 23 |
22 namespace base { | 24 namespace base { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // certificate dialog. | 129 // certificate dialog. |
128 void SelectClientCertificates( | 130 void SelectClientCertificates( |
129 const platform_keys::ClientCertificateRequest& request, | 131 const platform_keys::ClientCertificateRequest& request, |
130 const std::string& extension_id, | 132 const std::string& extension_id, |
131 const SelectCertificatesCallback& callback); | 133 const SelectCertificatesCallback& callback); |
132 | 134 |
133 private: | 135 private: |
134 using GetPlatformKeysCallback = | 136 using GetPlatformKeysCallback = |
135 base::Callback<void(scoped_ptr<base::ListValue> platform_keys)>; | 137 base::Callback<void(scoped_ptr<base::ListValue> platform_keys)>; |
136 | 138 |
137 // Registers the given public key as newly generated key, which is allowed to | 139 class Task; |
138 // be used for signing for a single time. Afterwards, calls |callback|. If | 140 class SignTask; |
139 // registration was successful, passes |true| otherwise |false| to the | 141 class PermissionUpdateTask; |
140 // callback. | |
141 void RegisterPublicKey(const std::string& extension_id, | |
142 const std::string& public_key_spki_der, | |
143 const base::Closure& callback); | |
144 | 142 |
145 // Gets the current validity of the given public key by reading StateStore. | 143 // Starts |task| eventually. To ensure that at most one |Task| is running at a |
146 // Invalidates the key if it was found to be valid. Finally, calls |callback| | 144 // time, it queues |task| for later execution if necessary. |
147 // with the old validity. | 145 void StartOrQueueTask(scoped_ptr<Task> task); |
148 void ReadValidityAndInvalidateKey(const std::string& extension_id, | 146 |
149 const std::string& public_key_spki_der, | 147 // Must be called after |task| is done. |task| will be invalid after this |
150 const base::Callback<void(bool)>& callback); | 148 // call. This must not be called for any but the task that ran last. If any |
| 149 // other tasks are queued (see StartOrQueueTask()), it will start the next |
| 150 // one. |
| 151 void TaskFinished(Task* task); |
151 | 152 |
152 // Reads the list of public keys currently registered for |extension_id| from | 153 // Reads the list of public keys currently registered for |extension_id| from |
153 // StateStore. Calls |callback| with the read list, or a new empty list if | 154 // StateStore. Calls |callback| with the read list, or a new empty list if |
154 // none existed. If an error occurred, calls |callback| with NULL. | 155 // none existed. If an error occurred, calls |callback| with NULL. |
155 void GetPlatformKeysOfExtension(const std::string& extension_id, | 156 void GetPlatformKeysOfExtension(const std::string& extension_id, |
156 const GetPlatformKeysCallback& callback); | 157 const GetPlatformKeysCallback& callback); |
157 | 158 |
158 // Writes |platform_keys| to the state store of the extension with id | 159 // Writes |platform_keys| to the state store of the extension with id |
159 // |extension_id|. | 160 // |extension_id|. |
160 void SetPlatformKeysOfExtension(const std::string& extension_id, | 161 void SetPlatformKeysOfExtension(const std::string& extension_id, |
161 scoped_ptr<base::ListValue> platform_keys); | 162 scoped_ptr<base::ListValue> platform_keys); |
162 | 163 |
163 // Callback used by |GenerateRSAKey|. | 164 // Callback used by |GenerateRSAKey|. |
164 // If the key generation was successful, registers the generated public key | 165 // If the key generation was successful, registers the generated public key |
165 // for the given extension. If any error occurs during key generation or | 166 // for the given extension. If any error occurs during key generation or |
166 // registration, calls |callback| with an error. Otherwise, on success, calls | 167 // registration, calls |callback| with an error. Otherwise, on success, calls |
167 // |callback| with the public key. | 168 // |callback| with the public key. |
168 void GenerateRSAKeyCallback(const std::string& extension_id, | 169 void GeneratedKey(const std::string& extension_id, |
169 const GenerateKeyCallback& callback, | 170 const GenerateKeyCallback& callback, |
| 171 const std::string& public_key_spki_der, |
| 172 const std::string& error_message); |
| 173 |
| 174 // Callback used by |GeneratedKey|. |
| 175 // |public_key_spki_der| will contain the X.509 Subject Public Key Info of |
| 176 // the generated key in DER encoding. |task| points to the finished |Task| |
| 177 // object. |
| 178 void RegisteredGeneratedKey(const GenerateKeyCallback& callback, |
170 const std::string& public_key_spki_der, | 179 const std::string& public_key_spki_der, |
171 const std::string& error_message); | 180 Task* task); |
172 | 181 |
173 // Calback used by |SelectClientCertificates|. | 182 // Calback used by |SelectClientCertificates|. |
174 // If the certificate request could be processed successfully, |matches| will | 183 // If the certificate request could be processed successfully, |matches| will |
175 // contain the list of matching certificates (maybe empty) and |error_message| | 184 // contain the list of matching certificates (maybe empty) and |error_message| |
176 // will be empty. If an error occurred, |matches| will be null and | 185 // will be empty. If an error occurred, |matches| will be null and |
177 // |error_message| contain an error message. | 186 // |error_message| contain an error message. |
178 void SelectClientCertificatesCallback( | 187 void SelectClientCertificatesCallback( |
179 const std::string& extension_id, | 188 const std::string& extension_id, |
180 const SelectCertificatesCallback& callback, | 189 const SelectCertificatesCallback& callback, |
181 scoped_ptr<net::CertificateList> matches, | 190 scoped_ptr<net::CertificateList> matches, |
182 const std::string& error_message); | 191 const std::string& error_message); |
183 | 192 |
184 // Callback used by |RegisterPublicKey|. | |
185 // Updates the old |platform_keys| read from the StateStore and writes the | |
186 // updated value back to the StateStore. | |
187 void RegisterPublicKeyGotPlatformKeys( | |
188 const std::string& extension_id, | |
189 const std::string& public_key_spki_der, | |
190 const base::Closure& callback, | |
191 scoped_ptr<base::ListValue> platform_keys); | |
192 | |
193 // Callback used by |ReadValidityAndInvalidateKey|. | |
194 // Invalidates the given public key so that future signing is prohibited and | |
195 // calls |callback| with the old validity. | |
196 void InvalidateKey(const std::string& extension_id, | |
197 const std::string& public_key_spki_der, | |
198 const base::Callback<void(bool)>& callback, | |
199 scoped_ptr<base::ListValue> platform_keys); | |
200 | |
201 // Callback used by |GetPlatformKeysOfExtension|. | 193 // Callback used by |GetPlatformKeysOfExtension|. |
202 // Is called with |value| set to the PlatformKeys value read from the | 194 // Is called with |value| set to the PlatformKeys value read from the |
203 // StateStore, which it forwards to |callback|. On error, calls |callback| | 195 // StateStore, which it forwards to |callback|. On error, calls |callback| |
204 // with NULL; if no value existed, with an empty list. | 196 // with NULL; if no value existed, with an empty list. |
205 void GotPlatformKeysOfExtension(const std::string& extension_id, | 197 void GotPlatformKeysOfExtension(const std::string& extension_id, |
206 const GetPlatformKeysCallback& callback, | 198 const GetPlatformKeysCallback& callback, |
207 scoped_ptr<base::Value> value); | 199 scoped_ptr<base::Value> value); |
208 | 200 |
209 content::BrowserContext* browser_context_; | 201 content::BrowserContext* browser_context_; |
210 extensions::StateStore* state_store_; | 202 extensions::StateStore* state_store_; |
211 bool permission_check_enabled_ = true; | 203 bool permission_check_enabled_ = true; |
| 204 std::queue<linked_ptr<Task>> tasks_; |
212 base::WeakPtrFactory<PlatformKeysService> weak_factory_; | 205 base::WeakPtrFactory<PlatformKeysService> weak_factory_; |
213 | 206 |
214 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService); | 207 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService); |
215 }; | 208 }; |
216 | 209 |
217 } // namespace chromeos | 210 } // namespace chromeos |
218 | 211 |
219 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ | 212 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ |
OLD | NEW |