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 <string> | 8 #include <string> |
| 9 #include <vector> |
9 | 10 |
10 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
14 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" | 15 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" |
15 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 class BrowserContext; | 19 class BrowserContext; |
19 } | 20 } |
20 | 21 |
21 namespace base { | 22 namespace base { |
22 class ListValue; | 23 class ListValue; |
23 class Value; | 24 class Value; |
24 } | 25 } |
25 | 26 |
26 namespace extensions { | 27 namespace extensions { |
27 class StateStore; | 28 class StateStore; |
28 } | 29 } |
29 | 30 |
| 31 namespace net { |
| 32 class X509Certificate; |
| 33 typedef std::vector<scoped_refptr<X509Certificate>> CertificateList; |
| 34 } |
| 35 |
30 namespace chromeos { | 36 namespace chromeos { |
31 | 37 |
32 class PlatformKeysService : public KeyedService { | 38 class PlatformKeysService : public KeyedService { |
33 public: | 39 public: |
34 // Stores registration information in |state_store|, i.e. for each extension | 40 // Stores registration information in |state_store|, i.e. for each extension |
35 // the list of public keys that are valid to be used for signing. Each key can | 41 // the list of public keys that are valid to be used for signing. Each key can |
36 // be used for signing at most once. | 42 // be used for signing at most once. |
37 // The format written to |state_store| is: | 43 // The format written to |state_store| is: |
38 // kStateStorePlatformKeys maps to a list of strings. | 44 // kStateStorePlatformKeys maps to a list of strings. |
39 // Each string is the base64 encoding of the DER representation of a public | 45 // Each string is the base64 encoding of the DER representation of a public |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // invoked with the signature or an error message. Currently supports RSA keys | 83 // invoked with the signature or an error message. Currently supports RSA keys |
78 // only. | 84 // only. |
79 // Will only call back during the lifetime of this object. | 85 // Will only call back during the lifetime of this object. |
80 void Sign(const std::string& token_id, | 86 void Sign(const std::string& token_id, |
81 const std::string& public_key_spki_der, | 87 const std::string& public_key_spki_der, |
82 platform_keys::HashAlgorithm hash_algorithm, | 88 platform_keys::HashAlgorithm hash_algorithm, |
83 const std::string& data, | 89 const std::string& data, |
84 const std::string& extension_id, | 90 const std::string& extension_id, |
85 const SignCallback& callback); | 91 const SignCallback& callback); |
86 | 92 |
| 93 // If the certificate request could be processed successfully, |matches| will |
| 94 // contain the list of matching certificates (maybe empty) and |error_message| |
| 95 // will be empty. If an error occurred, |matches| will be null and |
| 96 // |error_message| contain an error message. |
| 97 typedef base::Callback<void(scoped_ptr<net::CertificateList> matches, |
| 98 const std::string& error_message)> |
| 99 SelectCertificatesCallback; |
| 100 |
| 101 // Returns the list of all certificates that match |request|. |callback| will |
| 102 // be invoked with these matches or an error message. |
| 103 // Will only call back during the lifetime of this object. |
| 104 // TODO(pneubeck): Add the interactive option and integrate the select |
| 105 // certificate dialog. |
| 106 void SelectClientCertificates( |
| 107 const platform_keys::ClientCertificateRequest& request, |
| 108 const std::string& extension_id, |
| 109 const SelectCertificatesCallback& callback); |
| 110 |
87 private: | 111 private: |
88 using GetPlatformKeysCallback = | 112 using GetPlatformKeysCallback = |
89 base::Callback<void(scoped_ptr<base::ListValue> platform_keys)>; | 113 base::Callback<void(scoped_ptr<base::ListValue> platform_keys)>; |
90 | 114 |
91 // Registers the given public key as newly generated key, which is allowed to | 115 // Registers the given public key as newly generated key, which is allowed to |
92 // be used for signing for a single time. Afterwards, calls |callback|. If | 116 // be used for signing for a single time. Afterwards, calls |callback|. If |
93 // registration was successful, passes |true| otherwise |false| to the | 117 // registration was successful, passes |true| otherwise |false| to the |
94 // callback. | 118 // callback. |
95 void RegisterPublicKey(const std::string& extension_id, | 119 void RegisterPublicKey(const std::string& extension_id, |
96 const std::string& public_key_spki_der, | 120 const std::string& public_key_spki_der, |
(...skipping 20 matching lines...) Expand all Loading... |
117 // Callback used by |GenerateRSAKey|. | 141 // Callback used by |GenerateRSAKey|. |
118 // If the key generation was successful, registers the generated public key | 142 // If the key generation was successful, registers the generated public key |
119 // for the given extension. If any error occurs during key generation or | 143 // for the given extension. If any error occurs during key generation or |
120 // registration, calls |callback| with an error. Otherwise, on success, calls | 144 // registration, calls |callback| with an error. Otherwise, on success, calls |
121 // |callback| with the public key. | 145 // |callback| with the public key. |
122 void GenerateRSAKeyCallback(const std::string& extension_id, | 146 void GenerateRSAKeyCallback(const std::string& extension_id, |
123 const GenerateKeyCallback& callback, | 147 const GenerateKeyCallback& callback, |
124 const std::string& public_key_spki_der, | 148 const std::string& public_key_spki_der, |
125 const std::string& error_message); | 149 const std::string& error_message); |
126 | 150 |
| 151 // Calback used by |SelectClientCertificates|. |
| 152 // If the certificate request could be processed successfully, |matches| will |
| 153 // contain the list of matching certificates (maybe empty) and |error_message| |
| 154 // will be empty. If an error occurred, |matches| will be null and |
| 155 // |error_message| contain an error message. |
| 156 void SelectClientCertificatesCallback( |
| 157 const std::string& extension_id, |
| 158 const SelectCertificatesCallback& callback, |
| 159 scoped_ptr<net::CertificateList> matches, |
| 160 const std::string& error_message); |
| 161 |
127 // Callback used by |RegisterPublicKey|. | 162 // Callback used by |RegisterPublicKey|. |
128 // Updates the old |platform_keys| read from the StateStore and writes the | 163 // Updates the old |platform_keys| read from the StateStore and writes the |
129 // updated value back to the StateStore. | 164 // updated value back to the StateStore. |
130 void RegisterPublicKeyGotPlatformKeys( | 165 void RegisterPublicKeyGotPlatformKeys( |
131 const std::string& extension_id, | 166 const std::string& extension_id, |
132 const std::string& public_key_spki_der, | 167 const std::string& public_key_spki_der, |
133 const base::Closure& callback, | 168 const base::Closure& callback, |
134 scoped_ptr<base::ListValue> platform_keys); | 169 scoped_ptr<base::ListValue> platform_keys); |
135 | 170 |
136 // Callback used by |ReadValidityAndInvalidateKey|. | 171 // Callback used by |ReadValidityAndInvalidateKey|. |
(...skipping 15 matching lines...) Expand all Loading... |
152 content::BrowserContext* browser_context_; | 187 content::BrowserContext* browser_context_; |
153 extensions::StateStore* state_store_; | 188 extensions::StateStore* state_store_; |
154 base::WeakPtrFactory<PlatformKeysService> weak_factory_; | 189 base::WeakPtrFactory<PlatformKeysService> weak_factory_; |
155 | 190 |
156 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService); | 191 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService); |
157 }; | 192 }; |
158 | 193 |
159 } // namespace chromeos | 194 } // namespace chromeos |
160 | 195 |
161 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ | 196 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ |
OLD | NEW |