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 |
40 // key's SPKI. | 46 // key's SPKI. |
41 explicit PlatformKeysService(content::BrowserContext* browser_context, | 47 explicit PlatformKeysService(content::BrowserContext* browser_context, |
42 extensions::StateStore* state_store); | 48 extensions::StateStore* state_store); |
43 ~PlatformKeysService() override; | 49 ~PlatformKeysService() override; |
44 | 50 |
| 51 // Disables the checks whether an extension is allowed to read client |
| 52 // certificates. |
| 53 // TODO(pneubeck): Remove this once a permissions are implemented. |
| 54 void DisablePermissionCheckForTesting(); |
| 55 |
45 // If the generation was successful, |public_key_spki_der| will contain the | 56 // If the generation was successful, |public_key_spki_der| will contain the |
46 // DER encoding of the SubjectPublicKeyInfo of the generated key and | 57 // DER encoding of the SubjectPublicKeyInfo of the generated key and |
47 // |error_message| will be empty. If it failed, |public_key_spki_der| will be | 58 // |error_message| will be empty. If it failed, |public_key_spki_der| will be |
48 // empty and |error_message| contain an error message. | 59 // empty and |error_message| contain an error message. |
49 typedef base::Callback<void(const std::string& public_key_spki_der, | 60 typedef base::Callback<void(const std::string& public_key_spki_der, |
50 const std::string& error_message)> | 61 const std::string& error_message)> |
51 GenerateKeyCallback; | 62 GenerateKeyCallback; |
52 | 63 |
53 // Generates a RSA key pair with |modulus_length_bits| and registers the key | 64 // Generates a RSA key pair with |modulus_length_bits| and registers the key |
54 // to allow a single sign operation by the given extension. |token_id| is | 65 // to allow a single sign operation by the given extension. |token_id| is |
(...skipping 22 matching lines...) Expand all Loading... |
77 // invoked with the signature or an error message. Currently supports RSA keys | 88 // invoked with the signature or an error message. Currently supports RSA keys |
78 // only. | 89 // only. |
79 // Will only call back during the lifetime of this object. | 90 // Will only call back during the lifetime of this object. |
80 void Sign(const std::string& token_id, | 91 void Sign(const std::string& token_id, |
81 const std::string& public_key_spki_der, | 92 const std::string& public_key_spki_der, |
82 platform_keys::HashAlgorithm hash_algorithm, | 93 platform_keys::HashAlgorithm hash_algorithm, |
83 const std::string& data, | 94 const std::string& data, |
84 const std::string& extension_id, | 95 const std::string& extension_id, |
85 const SignCallback& callback); | 96 const SignCallback& callback); |
86 | 97 |
| 98 // If the certificate request could be processed successfully, |matches| will |
| 99 // contain the list of matching certificates (maybe empty) and |error_message| |
| 100 // will be empty. If an error occurred, |matches| will be null and |
| 101 // |error_message| contain an error message. |
| 102 typedef base::Callback<void(scoped_ptr<net::CertificateList> matches, |
| 103 const std::string& error_message)> |
| 104 SelectCertificatesCallback; |
| 105 |
| 106 // Returns the list of all certificates that match |request|. |callback| will |
| 107 // be invoked with these matches or an error message. |
| 108 // Will only call back during the lifetime of this object. |
| 109 // TODO(pneubeck): Add the interactive option and integrate the select |
| 110 // certificate dialog. |
| 111 void SelectClientCertificates( |
| 112 const platform_keys::ClientCertificateRequest& request, |
| 113 const std::string& extension_id, |
| 114 const SelectCertificatesCallback& callback); |
| 115 |
87 private: | 116 private: |
88 using GetPlatformKeysCallback = | 117 using GetPlatformKeysCallback = |
89 base::Callback<void(scoped_ptr<base::ListValue> platform_keys)>; | 118 base::Callback<void(scoped_ptr<base::ListValue> platform_keys)>; |
90 | 119 |
91 // Registers the given public key as newly generated key, which is allowed to | 120 // 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 | 121 // be used for signing for a single time. Afterwards, calls |callback|. If |
93 // registration was successful, passes |true| otherwise |false| to the | 122 // registration was successful, passes |true| otherwise |false| to the |
94 // callback. | 123 // callback. |
95 void RegisterPublicKey(const std::string& extension_id, | 124 void RegisterPublicKey(const std::string& extension_id, |
96 const std::string& public_key_spki_der, | 125 const std::string& public_key_spki_der, |
(...skipping 20 matching lines...) Expand all Loading... |
117 // Callback used by |GenerateRSAKey|. | 146 // Callback used by |GenerateRSAKey|. |
118 // If the key generation was successful, registers the generated public key | 147 // If the key generation was successful, registers the generated public key |
119 // for the given extension. If any error occurs during key generation or | 148 // for the given extension. If any error occurs during key generation or |
120 // registration, calls |callback| with an error. Otherwise, on success, calls | 149 // registration, calls |callback| with an error. Otherwise, on success, calls |
121 // |callback| with the public key. | 150 // |callback| with the public key. |
122 void GenerateRSAKeyCallback(const std::string& extension_id, | 151 void GenerateRSAKeyCallback(const std::string& extension_id, |
123 const GenerateKeyCallback& callback, | 152 const GenerateKeyCallback& callback, |
124 const std::string& public_key_spki_der, | 153 const std::string& public_key_spki_der, |
125 const std::string& error_message); | 154 const std::string& error_message); |
126 | 155 |
| 156 // Calback used by |SelectClientCertificates|. |
| 157 // If the certificate request could be processed successfully, |matches| will |
| 158 // contain the list of matching certificates (maybe empty) and |error_message| |
| 159 // will be empty. If an error occurred, |matches| will be null and |
| 160 // |error_message| contain an error message. |
| 161 void SelectClientCertificatesCallback( |
| 162 const std::string& extension_id, |
| 163 const SelectCertificatesCallback& callback, |
| 164 scoped_ptr<net::CertificateList> matches, |
| 165 const std::string& error_message); |
| 166 |
127 // Callback used by |RegisterPublicKey|. | 167 // Callback used by |RegisterPublicKey|. |
128 // Updates the old |platform_keys| read from the StateStore and writes the | 168 // Updates the old |platform_keys| read from the StateStore and writes the |
129 // updated value back to the StateStore. | 169 // updated value back to the StateStore. |
130 void RegisterPublicKeyGotPlatformKeys( | 170 void RegisterPublicKeyGotPlatformKeys( |
131 const std::string& extension_id, | 171 const std::string& extension_id, |
132 const std::string& public_key_spki_der, | 172 const std::string& public_key_spki_der, |
133 const base::Closure& callback, | 173 const base::Closure& callback, |
134 scoped_ptr<base::ListValue> platform_keys); | 174 scoped_ptr<base::ListValue> platform_keys); |
135 | 175 |
136 // Callback used by |ReadValidityAndInvalidateKey|. | 176 // Callback used by |ReadValidityAndInvalidateKey|. |
137 // Invalidates the given public key so that future signing is prohibited and | 177 // Invalidates the given public key so that future signing is prohibited and |
138 // calls |callback| with the old validity. | 178 // calls |callback| with the old validity. |
139 void InvalidateKey(const std::string& extension_id, | 179 void InvalidateKey(const std::string& extension_id, |
140 const std::string& public_key_spki_der, | 180 const std::string& public_key_spki_der, |
141 const base::Callback<void(bool)>& callback, | 181 const base::Callback<void(bool)>& callback, |
142 scoped_ptr<base::ListValue> platform_keys); | 182 scoped_ptr<base::ListValue> platform_keys); |
143 | 183 |
144 // Callback used by |GetPlatformKeysOfExtension|. | 184 // Callback used by |GetPlatformKeysOfExtension|. |
145 // Is called with |value| set to the PlatformKeys value read from the | 185 // Is called with |value| set to the PlatformKeys value read from the |
146 // StateStore, which it forwards to |callback|. On error, calls |callback| | 186 // StateStore, which it forwards to |callback|. On error, calls |callback| |
147 // with NULL; if no value existed, with an empty list. | 187 // with NULL; if no value existed, with an empty list. |
148 void GotPlatformKeysOfExtension(const std::string& extension_id, | 188 void GotPlatformKeysOfExtension(const std::string& extension_id, |
149 const GetPlatformKeysCallback& callback, | 189 const GetPlatformKeysCallback& callback, |
150 scoped_ptr<base::Value> value); | 190 scoped_ptr<base::Value> value); |
151 | 191 |
152 content::BrowserContext* browser_context_; | 192 content::BrowserContext* browser_context_; |
153 extensions::StateStore* state_store_; | 193 extensions::StateStore* state_store_; |
| 194 bool permission_check_enabled_ = true; |
154 base::WeakPtrFactory<PlatformKeysService> weak_factory_; | 195 base::WeakPtrFactory<PlatformKeysService> weak_factory_; |
155 | 196 |
156 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService); | 197 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService); |
157 }; | 198 }; |
158 | 199 |
159 } // namespace chromeos | 200 } // namespace chromeos |
160 | 201 |
161 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ | 202 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ |
OLD | NEW |