| 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 <memory> |
| 8 #include <queue> | 9 #include <queue> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "chrome/browser/chromeos/platform_keys/key_permissions.h" | 17 #include "chrome/browser/chromeos/platform_keys/key_permissions.h" |
| 18 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" | 18 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" |
| 19 #include "components/keyed_service/core/keyed_service.h" | 19 #include "components/keyed_service/core/keyed_service.h" |
| 20 | 20 |
| 21 class PrefService; | 21 class PrefService; |
| 22 | 22 |
| 23 namespace base { | 23 namespace base { |
| 24 class ListValue; | 24 class ListValue; |
| 25 class Value; | 25 class Value; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 explicit PlatformKeysService(bool profile_is_managed, | 85 explicit PlatformKeysService(bool profile_is_managed, |
| 86 PrefService* profile_prefs, | 86 PrefService* profile_prefs, |
| 87 policy::PolicyService* profile_policies, | 87 policy::PolicyService* profile_policies, |
| 88 content::BrowserContext* browser_context, | 88 content::BrowserContext* browser_context, |
| 89 extensions::StateStore* state_store); | 89 extensions::StateStore* state_store); |
| 90 | 90 |
| 91 ~PlatformKeysService() override; | 91 ~PlatformKeysService() override; |
| 92 | 92 |
| 93 // Sets the delegate which will be used for interactive | 93 // Sets the delegate which will be used for interactive |
| 94 // SelectClientCertificates calls. | 94 // SelectClientCertificates calls. |
| 95 void SetSelectDelegate(scoped_ptr<SelectDelegate> delegate); | 95 void SetSelectDelegate(std::unique_ptr<SelectDelegate> delegate); |
| 96 | 96 |
| 97 // If the generation was successful, |public_key_spki_der| will contain the | 97 // If the generation was successful, |public_key_spki_der| will contain the |
| 98 // DER encoding of the SubjectPublicKeyInfo of the generated key and | 98 // DER encoding of the SubjectPublicKeyInfo of the generated key and |
| 99 // |error_message| will be empty. If it failed, |public_key_spki_der| will be | 99 // |error_message| will be empty. If it failed, |public_key_spki_der| will be |
| 100 // empty and |error_message| contain an error message. | 100 // empty and |error_message| contain an error message. |
| 101 using GenerateKeyCallback = | 101 using GenerateKeyCallback = |
| 102 base::Callback<void(const std::string& public_key_spki_der, | 102 base::Callback<void(const std::string& public_key_spki_der, |
| 103 const std::string& error_message)>; | 103 const std::string& error_message)>; |
| 104 | 104 |
| 105 // Generates an RSA key pair with |modulus_length_bits| and registers the key | 105 // Generates an RSA key pair with |modulus_length_bits| and registers the key |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 const std::string& data, | 151 const std::string& data, |
| 152 const std::string& public_key, | 152 const std::string& public_key, |
| 153 const std::string& extension_id, | 153 const std::string& extension_id, |
| 154 const SignCallback& callback); | 154 const SignCallback& callback); |
| 155 | 155 |
| 156 // If the certificate request could be processed successfully, |matches| will | 156 // If the certificate request could be processed successfully, |matches| will |
| 157 // contain the list of matching certificates (maybe empty) and |error_message| | 157 // contain the list of matching certificates (maybe empty) and |error_message| |
| 158 // will be empty. If an error occurred, |matches| will be null and | 158 // will be empty. If an error occurred, |matches| will be null and |
| 159 // |error_message| contain an error message. | 159 // |error_message| contain an error message. |
| 160 using SelectCertificatesCallback = | 160 using SelectCertificatesCallback = |
| 161 base::Callback<void(scoped_ptr<net::CertificateList> matches, | 161 base::Callback<void(std::unique_ptr<net::CertificateList> matches, |
| 162 const std::string& error_message)>; | 162 const std::string& error_message)>; |
| 163 | 163 |
| 164 // Returns a list of certificates matching |request|. | 164 // Returns a list of certificates matching |request|. |
| 165 // 1) all certificates that match the request (like being rooted in one of the | 165 // 1) all certificates that match the request (like being rooted in one of the |
| 166 // give CAs) are determined. | 166 // give CAs) are determined. |
| 167 // 2) if |client_certificates| is not null, drops all certificates that are | 167 // 2) if |client_certificates| is not null, drops all certificates that are |
| 168 // not elements of |client_certificates|, | 168 // not elements of |client_certificates|, |
| 169 // 3) if |interactive| is true, the currently set SelectDelegate is used to | 169 // 3) if |interactive| is true, the currently set SelectDelegate is used to |
| 170 // select a single certificate from these matches | 170 // select a single certificate from these matches |
| 171 // which will the extension will also be granted access to. | 171 // which will the extension will also be granted access to. |
| 172 // 4) only certificates, that the extension has unlimited sign permission for, | 172 // 4) only certificates, that the extension has unlimited sign permission for, |
| 173 // will be returned. | 173 // will be returned. |
| 174 // |callback| will be invoked with these certificates or an error message. | 174 // |callback| will be invoked with these certificates or an error message. |
| 175 // Will only call back during the lifetime of this object. |web_contents| must | 175 // Will only call back during the lifetime of this object. |web_contents| must |
| 176 // not be null. | 176 // not be null. |
| 177 void SelectClientCertificates( | 177 void SelectClientCertificates( |
| 178 const platform_keys::ClientCertificateRequest& request, | 178 const platform_keys::ClientCertificateRequest& request, |
| 179 scoped_ptr<net::CertificateList> client_certificates, | 179 std::unique_ptr<net::CertificateList> client_certificates, |
| 180 bool interactive, | 180 bool interactive, |
| 181 const std::string& extension_id, | 181 const std::string& extension_id, |
| 182 const SelectCertificatesCallback& callback, | 182 const SelectCertificatesCallback& callback, |
| 183 content::WebContents* web_contents); | 183 content::WebContents* web_contents); |
| 184 | 184 |
| 185 private: | 185 private: |
| 186 class GenerateRSAKeyTask; | 186 class GenerateRSAKeyTask; |
| 187 class SelectTask; | 187 class SelectTask; |
| 188 class SignTask; | 188 class SignTask; |
| 189 class Task; | 189 class Task; |
| 190 | 190 |
| 191 // Starts |task| eventually. To ensure that at most one |Task| is running at a | 191 // Starts |task| eventually. To ensure that at most one |Task| is running at a |
| 192 // time, it queues |task| for later execution if necessary. | 192 // time, it queues |task| for later execution if necessary. |
| 193 void StartOrQueueTask(scoped_ptr<Task> task); | 193 void StartOrQueueTask(std::unique_ptr<Task> task); |
| 194 | 194 |
| 195 // Must be called after |task| is done. |task| will be invalid after this | 195 // Must be called after |task| is done. |task| will be invalid after this |
| 196 // call. This must not be called for any but the task that ran last. If any | 196 // call. This must not be called for any but the task that ran last. If any |
| 197 // other tasks are queued (see StartOrQueueTask()), it will start the next | 197 // other tasks are queued (see StartOrQueueTask()), it will start the next |
| 198 // one. | 198 // one. |
| 199 void TaskFinished(Task* task); | 199 void TaskFinished(Task* task); |
| 200 | 200 |
| 201 // Callback used by |GenerateRSAKey|. | 201 // Callback used by |GenerateRSAKey|. |
| 202 // If the key generation was successful, registers the generated public key | 202 // If the key generation was successful, registers the generated public key |
| 203 // for the given extension. If any error occurs during key generation or | 203 // for the given extension. If any error occurs during key generation or |
| 204 // registration, calls |callback| with an error. Otherwise, on success, calls | 204 // registration, calls |callback| with an error. Otherwise, on success, calls |
| 205 // |callback| with the public key. | 205 // |callback| with the public key. |
| 206 void GeneratedKey(const std::string& extension_id, | 206 void GeneratedKey(const std::string& extension_id, |
| 207 const GenerateKeyCallback& callback, | 207 const GenerateKeyCallback& callback, |
| 208 const std::string& public_key_spki_der, | 208 const std::string& public_key_spki_der, |
| 209 const std::string& error_message); | 209 const std::string& error_message); |
| 210 | 210 |
| 211 // Callback used by |GeneratedKey|. | 211 // Callback used by |GeneratedKey|. |
| 212 // |public_key_spki_der| will contain the X.509 Subject Public Key Info of | 212 // |public_key_spki_der| will contain the X.509 Subject Public Key Info of |
| 213 // the generated key in DER encoding. |task| points to the finished |Task| | 213 // the generated key in DER encoding. |task| points to the finished |Task| |
| 214 // object. | 214 // object. |
| 215 void RegisteredGeneratedKey(const GenerateKeyCallback& callback, | 215 void RegisteredGeneratedKey(const GenerateKeyCallback& callback, |
| 216 const std::string& public_key_spki_der, | 216 const std::string& public_key_spki_der, |
| 217 Task* task); | 217 Task* task); |
| 218 | 218 |
| 219 content::BrowserContext* browser_context_; | 219 content::BrowserContext* browser_context_; |
| 220 KeyPermissions key_permissions_; | 220 KeyPermissions key_permissions_; |
| 221 scoped_ptr<SelectDelegate> select_delegate_; | 221 std::unique_ptr<SelectDelegate> select_delegate_; |
| 222 std::queue<linked_ptr<Task>> tasks_; | 222 std::queue<linked_ptr<Task>> tasks_; |
| 223 base::WeakPtrFactory<PlatformKeysService> weak_factory_; | 223 base::WeakPtrFactory<PlatformKeysService> weak_factory_; |
| 224 | 224 |
| 225 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService); | 225 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService); |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 } // namespace chromeos | 228 } // namespace chromeos |
| 229 | 229 |
| 230 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ | 230 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ |
| OLD | NEW |