Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/browser/chromeos/platform_keys/platform_keys_service.h

Issue 905523002: platformKeys: Add per-extension sign permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pks_sign_task
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <queue>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 21 matching lines...) Expand all
32 32
33 namespace net { 33 namespace net {
34 class X509Certificate; 34 class X509Certificate;
35 typedef std::vector<scoped_refptr<X509Certificate>> CertificateList; 35 typedef std::vector<scoped_refptr<X509Certificate>> CertificateList;
36 } 36 }
37 37
38 namespace chromeos { 38 namespace chromeos {
39 39
40 class PlatformKeysService : public KeyedService { 40 class PlatformKeysService : public KeyedService {
41 public: 41 public:
42 struct KeyEntry;
43 using KeyEntries = std::vector<KeyEntry>;
44
45 class SelectDelegate {
Andrew T Wilson (Slow) 2015/02/18 19:53:35 Would be nice if we had some class-level documenta
pneubeck (no reviews) 2015/02/19 11:08:40 Done.
46 public:
47 // TODO(pneubeck): Handle if the selection was aborted, e.g. by the user.
48 using Callback =
Andrew T Wilson (Slow) 2015/02/18 19:53:35 nit: I'm not a huge fan of overloading names (Sele
pneubeck (no reviews) 2015/02/19 11:08:40 Done.
49 base::Callback<void(scoped_refptr<net::X509Certificate> selection)>;
50
51 SelectDelegate();
52 virtual ~SelectDelegate();
53
54 // Called on an interactive SelectClientCertificates call with the list of
55 // matching certificates, |certs|. Must eventually call |callback| or be
56 // destructed. |callback| will not be called after this delegate is
Andrew T Wilson (Slow) 2015/02/18 19:53:35 What do you mean |callback| will not be called aft
pneubeck (no reviews) 2015/02/19 11:08:40 Yes, that's the point. This is part of the contrac
Andrew T Wilson (Slow) 2015/02/19 11:16:44 OK, then you should word this prescriptively, not
57 // destructed.
58 // The certificate passed to |callback| will be forwarded to the
59 // calling extension and the extension will get unlimited sign permission
60 // for this cert. By passing null to |callback|, no cert will be selected.
61 virtual void Select(const std::string& extension_id,
62 const net::CertificateList& certs,
63 const Callback& callback) = 0;
64
65 private:
Andrew T Wilson (Slow) 2015/02/18 19:53:35 This class has no data members - why are you restr
pneubeck (no reviews) 2015/02/19 11:08:40 the assignment operator is not virtual. calling it
66 DISALLOW_ASSIGN(SelectDelegate);
67 };
68
42 // Stores registration information in |state_store|, i.e. for each extension 69 // Stores registration information in |state_store|, i.e. for each extension
43 // the list of public keys that are valid to be used for signing. Each key can 70 // the list of public keys that are valid to be used for signing. Each key can
44 // be used for signing at most once. 71 // be used for signing at most once.
45 // The format written to |state_store| is: 72 // The format written to |state_store| is:
46 // kStateStorePlatformKeys maps to a list of strings. 73 // kStateStorePlatformKeys maps to a list of strings.
47 // Each string is the base64 encoding of the DER representation of a public 74 // Each string is the base64 encoding of the DER representation of a public
48 // key's SPKI. 75 // key's SPKI.
49 explicit PlatformKeysService(content::BrowserContext* browser_context, 76 explicit PlatformKeysService(content::BrowserContext* browser_context,
50 extensions::StateStore* state_store); 77 extensions::StateStore* state_store);
51 ~PlatformKeysService() override; 78 ~PlatformKeysService() override;
52 79
53 // Disables the checks whether an extension is allowed to read client 80 // Sets the delegate which will be used for interactive
54 // certificates or allowed to use the signing function of a key. 81 // SelectClientCertificates calls.
55 // TODO(pneubeck): Remove this once a permissions are implemented. 82 void SetSelectDelegate(scoped_ptr<SelectDelegate> delegate);
56 void DisablePermissionCheckForTesting(); 83
84 // Grants unlimited sign permission for |cert| to the extension with the ID
85 // |extension_id|.
86 void GrantUnlimitedSignPermission(const std::string& extension_id,
87 scoped_refptr<net::X509Certificate> cert);
57 88
58 // If the generation was successful, |public_key_spki_der| will contain the 89 // If the generation was successful, |public_key_spki_der| will contain the
59 // DER encoding of the SubjectPublicKeyInfo of the generated key and 90 // DER encoding of the SubjectPublicKeyInfo of the generated key and
60 // |error_message| will be empty. If it failed, |public_key_spki_der| will be 91 // |error_message| will be empty. If it failed, |public_key_spki_der| will be
61 // empty and |error_message| contain an error message. 92 // empty and |error_message| contain an error message.
62 typedef base::Callback<void(const std::string& public_key_spki_der, 93 using GenerateKeyCallback =
63 const std::string& error_message)> 94 base::Callback<void(const std::string& public_key_spki_der,
64 GenerateKeyCallback; 95 const std::string& error_message)>;
65 96
66 // Generates an RSA key pair with |modulus_length_bits| and registers the key 97 // Generates an RSA key pair with |modulus_length_bits| and registers the key
67 // to allow a single sign operation by the given extension. |token_id| is 98 // to allow a single sign operation by the given extension. |token_id| is
68 // currently ignored, instead the user token associated with |browser_context| 99 // currently ignored, instead the user token associated with |browser_context|
69 // is always used. |callback| will be invoked with the resulting public key or 100 // is always used. |callback| will be invoked with the resulting public key or
70 // an error. 101 // an error.
71 // Will only call back during the lifetime of this object. 102 // Will only call back during the lifetime of this object.
72 void GenerateRSAKey(const std::string& token_id, 103 void GenerateRSAKey(const std::string& token_id,
73 unsigned int modulus_length_bits, 104 unsigned int modulus_length_bits,
74 const std::string& extension_id, 105 const std::string& extension_id,
75 const GenerateKeyCallback& callback); 106 const GenerateKeyCallback& callback);
76 107
77 // If signing was successful, |signature| will be contain the signature and 108 // If signing was successful, |signature| will be contain the signature and
78 // |error_message| will be empty. If it failed, |signature| will be empty and 109 // |error_message| will be empty. If it failed, |signature| will be empty and
79 // |error_message| contain an error message. 110 // |error_message| contain an error message.
80 typedef base::Callback<void(const std::string& signature, 111 using SignCallback = base::Callback<void(const std::string& signature,
81 const std::string& error_message)> SignCallback; 112 const std::string& error_message)>;
82 113
83 // Digests |data|, applies PKCS1 padding and afterwards signs the data with 114 // Digests |data|, applies PKCS1 padding and afterwards signs the data with
84 // the private key matching |params.public_key|. If a non empty token id is 115 // the private key matching |params.public_key|. If a non empty token id is
85 // provided and the key is not found in that token, the operation aborts. 116 // provided and the key is not found in that token, the operation aborts.
86 // If the extension does not have permissions for signing with this key, the 117 // If the extension does not have permissions for signing with this key, the
87 // operation aborts. In case of a one time permission (granted after 118 // operation aborts. In case of a one time permission (granted after
88 // generating the key), this function also removes the permission to prevent 119 // generating the key), this function also removes the permission to prevent
89 // future signing attempts. 120 // future signing attempts.
90 // |callback| will be invoked with the signature or an error message. 121 // |callback| will be invoked with the signature or an error message.
91 // Will only call back during the lifetime of this object. 122 // Will only call back during the lifetime of this object.
(...skipping 19 matching lines...) Expand all
111 void SignRSAPKCS1Raw(const std::string& token_id, 142 void SignRSAPKCS1Raw(const std::string& token_id,
112 const std::string& data, 143 const std::string& data,
113 const std::string& public_key, 144 const std::string& public_key,
114 const std::string& extension_id, 145 const std::string& extension_id,
115 const SignCallback& callback); 146 const SignCallback& callback);
116 147
117 // If the certificate request could be processed successfully, |matches| will 148 // If the certificate request could be processed successfully, |matches| will
118 // contain the list of matching certificates (maybe empty) and |error_message| 149 // contain the list of matching certificates (maybe empty) and |error_message|
119 // will be empty. If an error occurred, |matches| will be null and 150 // will be empty. If an error occurred, |matches| will be null and
120 // |error_message| contain an error message. 151 // |error_message| contain an error message.
121 typedef base::Callback<void(scoped_ptr<net::CertificateList> matches, 152 using SelectCertificatesCallback =
122 const std::string& error_message)> 153 base::Callback<void(scoped_ptr<net::CertificateList> matches,
123 SelectCertificatesCallback; 154 const std::string& error_message)>;
124 155
125 // Returns the list of all certificates that match |request|. |callback| will 156 // Returns the list of all certificates that match |request|. If |interactive|
126 // be invoked with these matches or an error message. 157 // is true will select from these matches using the currently set
158 // SelectDelegate. Afterwards filters only the certificates that the extension
Andrew T Wilson (Slow) 2015/02/18 19:53:35 I couldn't quite understand what "Afterwards filte
pneubeck (no reviews) 2015/02/19 11:08:40 I made a bit more verbose.
159 // has unlimited sign permission for. |callback| will be invoked with these
160 // certificates or an error message.
127 // Will only call back during the lifetime of this object. 161 // Will only call back during the lifetime of this object.
128 // TODO(pneubeck): Add the interactive option and integrate the select
129 // certificate dialog.
130 void SelectClientCertificates( 162 void SelectClientCertificates(
131 const platform_keys::ClientCertificateRequest& request, 163 const platform_keys::ClientCertificateRequest& request,
164 bool interactive,
132 const std::string& extension_id, 165 const std::string& extension_id,
133 const SelectCertificatesCallback& callback); 166 const SelectCertificatesCallback& callback);
134 167
135 private: 168 private:
136 using GetPlatformKeysCallback = 169 using GetPlatformKeysCallback =
137 base::Callback<void(scoped_ptr<base::ListValue> platform_keys)>; 170 base::Callback<void(scoped_ptr<KeyEntries> platform_keys)>;
171
172 enum SignPermission { ONCE, UNLIMITED };
138 173
139 class Task; 174 class Task;
175 class SelectTask;
Andrew T Wilson (Slow) 2015/02/18 19:53:35 Should these classes be ordered somehow?
pneubeck (no reviews) 2015/02/19 11:08:40 Done.
140 class SignTask; 176 class SignTask;
141 class PermissionUpdateTask; 177 class PermissionUpdateTask;
142 178
143 // Starts |task| eventually. To ensure that at most one |Task| is running at a 179 // Starts |task| eventually. To ensure that at most one |Task| is running at a
144 // time, it queues |task| for later execution if necessary. 180 // time, it queues |task| for later execution if necessary.
145 void StartOrQueueTask(scoped_ptr<Task> task); 181 void StartOrQueueTask(scoped_ptr<Task> task);
146 182
147 // Must be called after |task| is done. |task| will be invalid after this 183 // Must be called after |task| is done. |task| will be invalid after this
148 // call. This must not be called for any but the task that ran last. If any 184 // 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 185 // other tasks are queued (see StartOrQueueTask()), it will start the next
150 // one. 186 // one.
151 void TaskFinished(Task* task); 187 void TaskFinished(Task* task);
152 188
153 // Reads the list of public keys currently registered for |extension_id| from 189 // Reads the list of public keys currently registered for |extension_id| from
154 // StateStore. Calls |callback| with the read list, or a new empty list if 190 // StateStore. Calls |callback| with the read list, or a new empty list if
155 // none existed. If an error occurred, calls |callback| with NULL. 191 // none existed. If an error occurred, calls |callback| with NULL.
156 void GetPlatformKeysOfExtension(const std::string& extension_id, 192 void GetPlatformKeysOfExtension(const std::string& extension_id,
157 const GetPlatformKeysCallback& callback); 193 const GetPlatformKeysCallback& callback);
158 194
159 // Writes |platform_keys| to the state store of the extension with id 195 // Writes |platform_keys| to the state store of the extension with id
160 // |extension_id|. 196 // |extension_id|.
161 void SetPlatformKeysOfExtension(const std::string& extension_id, 197 void SetPlatformKeysOfExtension(const std::string& extension_id,
162 scoped_ptr<base::ListValue> platform_keys); 198 const KeyEntries& platform_keys);
163 199
164 // Callback used by |GenerateRSAKey|. 200 // Callback used by |GenerateRSAKey|.
165 // If the key generation was successful, registers the generated public key 201 // If the key generation was successful, registers the generated public key
166 // for the given extension. If any error occurs during key generation or 202 // for the given extension. If any error occurs during key generation or
167 // registration, calls |callback| with an error. Otherwise, on success, calls 203 // registration, calls |callback| with an error. Otherwise, on success, calls
168 // |callback| with the public key. 204 // |callback| with the public key.
169 void GeneratedKey(const std::string& extension_id, 205 void GeneratedKey(const std::string& extension_id,
170 const GenerateKeyCallback& callback, 206 const GenerateKeyCallback& callback,
171 const std::string& public_key_spki_der, 207 const std::string& public_key_spki_der,
172 const std::string& error_message); 208 const std::string& error_message);
173 209
174 // Callback used by |GeneratedKey|. 210 // Callback used by |GeneratedKey|.
175 // |public_key_spki_der| will contain the X.509 Subject Public Key Info of 211 // |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| 212 // the generated key in DER encoding. |task| points to the finished |Task|
177 // object. 213 // object.
178 void RegisteredGeneratedKey(const GenerateKeyCallback& callback, 214 void RegisteredGeneratedKey(const GenerateKeyCallback& callback,
179 const std::string& public_key_spki_der, 215 const std::string& public_key_spki_der,
180 Task* task); 216 Task* task);
181 217
182 // Calback used by |SelectClientCertificates|.
183 // If the certificate request could be processed successfully, |matches| will
184 // contain the list of matching certificates (maybe empty) and |error_message|
185 // will be empty. If an error occurred, |matches| will be null and
186 // |error_message| contain an error message.
187 void SelectClientCertificatesCallback(
188 const std::string& extension_id,
189 const SelectCertificatesCallback& callback,
190 scoped_ptr<net::CertificateList> matches,
191 const std::string& error_message);
192
193 // Callback used by |GetPlatformKeysOfExtension|. 218 // Callback used by |GetPlatformKeysOfExtension|.
194 // Is called with |value| set to the PlatformKeys value read from the 219 // Is called with |value| set to the PlatformKeys value read from the
195 // StateStore, which it forwards to |callback|. On error, calls |callback| 220 // StateStore, which it forwards to |callback|. On error, calls |callback|
196 // with NULL; if no value existed, with an empty list. 221 // with NULL; if no value existed, with an empty list.
197 void GotPlatformKeysOfExtension(const std::string& extension_id, 222 void GotPlatformKeysOfExtension(const std::string& extension_id,
198 const GetPlatformKeysCallback& callback, 223 const GetPlatformKeysCallback& callback,
199 scoped_ptr<base::Value> value); 224 scoped_ptr<base::Value> value);
200 225
201 content::BrowserContext* browser_context_; 226 content::BrowserContext* browser_context_;
202 extensions::StateStore* state_store_; 227 extensions::StateStore* state_store_;
203 bool permission_check_enabled_ = true; 228 scoped_ptr<SelectDelegate> select_delegate_;
204 std::queue<linked_ptr<Task>> tasks_; 229 std::queue<linked_ptr<Task>> tasks_;
205 base::WeakPtrFactory<PlatformKeysService> weak_factory_; 230 base::WeakPtrFactory<PlatformKeysService> weak_factory_;
206 231
207 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService); 232 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService);
208 }; 233 };
209 234
210 } // namespace chromeos 235 } // namespace chromeos
211 236
212 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ 237 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698