Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / extensions / api / easy_unlock_private / easy_unlock_private_api.h
blobc289d0b9690e960b56086ce652cf1d9b5ba770a2
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_EASY_UNLOCK_PRIVATE_EASY_UNLOCK_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_EASY_UNLOCK_PRIVATE_EASY_UNLOCK_PRIVATE_API_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "device/bluetooth/bluetooth_device.h"
13 #include "extensions/browser/api/bluetooth/bluetooth_extension_function.h"
14 #include "extensions/browser/api/bluetooth_socket/bluetooth_socket_api.h"
15 #include "extensions/browser/browser_context_keyed_api_factory.h"
16 #include "extensions/browser/extension_function.h"
18 // Implementations for chrome.easyUnlockPrivate API functions.
20 namespace content {
21 class BrowserContext;
24 namespace cryptauth {
25 class ExternalDeviceInfo;
28 namespace proximity_auth {
29 class SecureMessageDelegate;
32 namespace extensions {
34 class EasyUnlockPrivateCryptoDelegate;
36 class EasyUnlockPrivateAPI : public BrowserContextKeyedAPI {
37 public:
38 static BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>*
39 GetFactoryInstance();
41 static const bool kServiceRedirectedInIncognito = true;
43 explicit EasyUnlockPrivateAPI(content::BrowserContext* context);
44 ~EasyUnlockPrivateAPI() override;
46 EasyUnlockPrivateCryptoDelegate* GetCryptoDelegate();
48 private:
49 friend class BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>;
51 // BrowserContextKeyedAPI implementation.
52 static const char* service_name() { return "EasyUnlockPrivate"; }
54 scoped_ptr<EasyUnlockPrivateCryptoDelegate> crypto_delegate_;
56 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateAPI);
59 // TODO(tbarzic): Replace SyncExtensionFunction/AsyncExtensionFunction overrides
60 // with UIThreadExtensionFunction throughout the file.
61 class EasyUnlockPrivateGetStringsFunction : public SyncExtensionFunction {
62 public:
63 EasyUnlockPrivateGetStringsFunction();
65 protected:
66 ~EasyUnlockPrivateGetStringsFunction() override;
68 // SyncExtensionFunction:
69 bool RunSync() override;
71 private:
72 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getStrings",
73 EASYUNLOCKPRIVATE_GETSTRINGS)
75 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetStringsFunction);
78 class EasyUnlockPrivatePerformECDHKeyAgreementFunction
79 : public AsyncExtensionFunction {
80 public:
81 EasyUnlockPrivatePerformECDHKeyAgreementFunction();
83 protected:
84 ~EasyUnlockPrivatePerformECDHKeyAgreementFunction() override;
86 bool RunAsync() override;
88 private:
89 void OnData(const std::string& secret_key);
91 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.performECDHKeyAgreement",
92 EASYUNLOCKPRIVATE_PERFORMECDHKEYAGREEMENT)
94 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivatePerformECDHKeyAgreementFunction);
97 class EasyUnlockPrivateGenerateEcP256KeyPairFunction
98 : public AsyncExtensionFunction {
99 public:
100 EasyUnlockPrivateGenerateEcP256KeyPairFunction();
102 protected:
103 ~EasyUnlockPrivateGenerateEcP256KeyPairFunction() override;
105 bool RunAsync() override;
107 private:
108 void OnData(const std::string& public_key,
109 const std::string& private_key);
111 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.generateEcP256KeyPair",
112 EASYUNLOCKPRIVATE_GENERATEECP256KEYPAIR)
114 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGenerateEcP256KeyPairFunction);
117 class EasyUnlockPrivateCreateSecureMessageFunction
118 : public AsyncExtensionFunction {
119 public:
120 EasyUnlockPrivateCreateSecureMessageFunction();
122 protected:
123 ~EasyUnlockPrivateCreateSecureMessageFunction() override;
125 bool RunAsync() override;
127 private:
128 void OnData(const std::string& message);
130 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.createSecureMessage",
131 EASYUNLOCKPRIVATE_CREATESECUREMESSAGE)
133 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateCreateSecureMessageFunction);
136 class EasyUnlockPrivateUnwrapSecureMessageFunction
137 : public AsyncExtensionFunction {
138 public:
139 EasyUnlockPrivateUnwrapSecureMessageFunction();
141 protected:
142 ~EasyUnlockPrivateUnwrapSecureMessageFunction() override;
144 bool RunAsync() override;
146 private:
147 void OnData(const std::string& data);
149 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.unwrapSecureMessage",
150 EASYUNLOCKPRIVATE_UNWRAPSECUREMESSAGE)
152 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateUnwrapSecureMessageFunction);
155 class EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction
156 : public AsyncExtensionFunction {
157 public:
158 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.seekBluetoothDeviceByAddress",
159 EASYUNLOCKPRIVATE_SEEKBLUETOOTHDEVICEBYADDRESS)
160 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction();
162 private:
163 ~EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() override;
165 // AsyncExtensionFunction:
166 bool RunAsync() override;
168 // Callbacks that are called when the seek operation succeeds or fails.
169 void OnSeekSuccess();
170 void OnSeekFailure(const std::string& error_message);
172 DISALLOW_COPY_AND_ASSIGN(
173 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction);
176 class EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction
177 : public api::BluetoothSocketAbstractConnectFunction {
178 public:
179 DECLARE_EXTENSION_FUNCTION(
180 "easyUnlockPrivate.connectToBluetoothServiceInsecurely",
181 EASYUNLOCKPRIVATE_CONNECTTOBLUETOOTHSERVICEINSECURELY)
182 EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction();
184 private:
185 ~EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction() override;
187 // BluetoothSocketAbstractConnectFunction:
188 void ConnectToService(device::BluetoothDevice* device,
189 const device::BluetoothUUID& uuid) override;
191 DISALLOW_COPY_AND_ASSIGN(
192 EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction);
195 class EasyUnlockPrivateUpdateScreenlockStateFunction
196 : public SyncExtensionFunction {
197 public:
198 EasyUnlockPrivateUpdateScreenlockStateFunction();
200 protected:
201 ~EasyUnlockPrivateUpdateScreenlockStateFunction() override;
203 bool RunSync() override;
205 private:
206 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.updateScreenlockState",
207 EASYUNLOCKPRIVATE_UPDATESCREENLOCKSTATE)
209 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateUpdateScreenlockStateFunction);
212 class EasyUnlockPrivateSetPermitAccessFunction : public SyncExtensionFunction {
213 public:
214 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setPermitAccess",
215 EASYUNLOCKPRIVATE_SETPERMITACCESS)
216 EasyUnlockPrivateSetPermitAccessFunction();
218 private:
219 ~EasyUnlockPrivateSetPermitAccessFunction() override;
221 // SyncExtensionFunction:
222 bool RunSync() override;
224 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetPermitAccessFunction);
227 class EasyUnlockPrivateGetPermitAccessFunction : public SyncExtensionFunction {
228 public:
229 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getPermitAccess",
230 EASYUNLOCKPRIVATE_GETPERMITACCESS)
231 EasyUnlockPrivateGetPermitAccessFunction();
233 protected:
234 ~EasyUnlockPrivateGetPermitAccessFunction() override;
236 // Writes the user's public and private key in base64 form to the
237 // |user_public_key| and |user_private_key| fields. Exposed for testing.
238 virtual void GetKeyPairForExperiment(std::string* user_public_key,
239 std::string* user_private_key);
241 private:
242 // SyncExtensionFunction:
243 bool RunSync() override;
245 // Instead of returning the value set by easyUnlockPrivate.setPermitAccess,
246 // return the permit access used by the native CryptAuthEnrollmentManager.
247 void ReturnPermitAccessForExperiment();
249 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetPermitAccessFunction);
252 class EasyUnlockPrivateClearPermitAccessFunction
253 : public SyncExtensionFunction {
254 public:
255 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.clearPermitAccess",
256 EASYUNLOCKPRIVATE_CLEARPERMITACCESS)
257 EasyUnlockPrivateClearPermitAccessFunction();
259 private:
260 ~EasyUnlockPrivateClearPermitAccessFunction() override;
262 // SyncExtensionFunction:
263 bool RunSync() override;
265 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateClearPermitAccessFunction);
268 class EasyUnlockPrivateSetRemoteDevicesFunction : public SyncExtensionFunction {
269 public:
270 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setRemoteDevices",
271 EASYUNLOCKPRIVATE_SETREMOTEDEVICES)
272 EasyUnlockPrivateSetRemoteDevicesFunction();
274 private:
275 ~EasyUnlockPrivateSetRemoteDevicesFunction() override;
277 // SyncExtensionFunction:
278 bool RunSync() override;
280 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetRemoteDevicesFunction);
283 class EasyUnlockPrivateGetRemoteDevicesFunction
284 : public AsyncExtensionFunction {
285 public:
286 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getRemoteDevices",
287 EASYUNLOCKPRIVATE_GETREMOTEDEVICES)
288 EasyUnlockPrivateGetRemoteDevicesFunction();
290 protected:
291 ~EasyUnlockPrivateGetRemoteDevicesFunction() override;
293 // Returns the user's private key used for the native experiment.
294 // Exposed for testing.
295 virtual std::string GetUserPrivateKey();
297 // Returns the user's unlock keys used for the native experiment.
298 // Exposed for testing.
299 virtual std::vector<cryptauth::ExternalDeviceInfo> GetUnlockKeys();
301 private:
302 // AsyncExtensionFunction:
303 bool RunAsync() override;
305 // Returns devices managed by the native Chrome component if the
306 // kEnableBluetoothLowEnergyDiscovery flag is set.
307 void ReturnDevicesForExperiment();
309 // Callback when the PSK of a device is derived.
310 void OnPSKDerivedForDevice(const cryptauth::ExternalDeviceInfo& device,
311 const std::string& persistent_symmetric_key);
313 // The permit id of the user. Used for the native experiment.
314 std::string permit_id_;
316 // The expected number of devices to return. Used for the native experiment.
317 size_t expected_devices_count_;
319 // Working list of the devices to return. Used for the native experiment.
320 scoped_ptr<base::ListValue> remote_devices_;
322 // Used to derive devices' PSK. Used for the native experiment.
323 scoped_ptr<proximity_auth::SecureMessageDelegate> secure_message_delegate_;
325 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetRemoteDevicesFunction);
328 class EasyUnlockPrivateGetSignInChallengeFunction :
329 public AsyncExtensionFunction {
330 public:
331 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getSignInChallenge",
332 EASYUNLOCKPRIVATE_GETSIGNINCHALLENGE)
333 EasyUnlockPrivateGetSignInChallengeFunction();
335 private:
336 ~EasyUnlockPrivateGetSignInChallengeFunction() override;
338 // AsyncExtensionFunction:
339 bool RunAsync() override;
341 // Called when the challenge and the signed nonce have been generated.
342 void OnDone(const std::string& challenge, const std::string& signed_nonce);
344 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetSignInChallengeFunction);
347 class EasyUnlockPrivateTrySignInSecretFunction :
348 public SyncExtensionFunction {
349 public:
350 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.trySignInSecret",
351 EASYUNLOCKPRIVATE_TRYSIGNINSECRET)
352 EasyUnlockPrivateTrySignInSecretFunction();
354 private:
355 ~EasyUnlockPrivateTrySignInSecretFunction() override;
357 // SyncExtensionFunction:
358 bool RunSync() override;
360 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateTrySignInSecretFunction);
363 class EasyUnlockPrivateGetUserInfoFunction : public SyncExtensionFunction {
364 public:
365 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getUserInfo",
366 EASYUNLOCKPRIVATE_GETUSERINFO)
367 EasyUnlockPrivateGetUserInfoFunction();
369 private:
370 ~EasyUnlockPrivateGetUserInfoFunction() override;
372 // SyncExtensionFunction:
373 bool RunSync() override;
375 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetUserInfoFunction);
378 class EasyUnlockPrivateGetConnectionInfoFunction
379 : public api::BluetoothExtensionFunction {
380 public:
381 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getConnectionInfo",
382 EASYUNLOCKPRIVATE_GETCONNECTIONINFO)
383 EasyUnlockPrivateGetConnectionInfoFunction();
385 private:
386 ~EasyUnlockPrivateGetConnectionInfoFunction() override;
388 // BluetoothExtensionFunction:
389 bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
391 void OnConnectionInfo(
392 const device::BluetoothDevice::ConnectionInfo& connection_info);
394 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetConnectionInfoFunction);
397 class EasyUnlockPrivateShowErrorBubbleFunction : public SyncExtensionFunction {
398 public:
399 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.showErrorBubble",
400 EASYUNLOCKPRIVATE_SHOWERRORBUBBLE)
401 EasyUnlockPrivateShowErrorBubbleFunction();
403 private:
404 ~EasyUnlockPrivateShowErrorBubbleFunction() override;
406 // SyncExtensionFunction:
407 bool RunSync() override;
409 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateShowErrorBubbleFunction);
412 class EasyUnlockPrivateHideErrorBubbleFunction : public SyncExtensionFunction {
413 public:
414 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.hideErrorBubble",
415 EASYUNLOCKPRIVATE_HIDEERRORBUBBLE)
416 EasyUnlockPrivateHideErrorBubbleFunction();
418 private:
419 ~EasyUnlockPrivateHideErrorBubbleFunction() override;
421 // SyncExtensionFunction:
422 bool RunSync() override;
424 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateHideErrorBubbleFunction);
427 class EasyUnlockPrivateSetAutoPairingResultFunction
428 : public SyncExtensionFunction {
429 public:
430 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setAutoPairingResult",
431 EASYUNLOCKPRIVATE_SETAUTOPAIRINGRESULT)
432 EasyUnlockPrivateSetAutoPairingResultFunction();
434 private:
435 ~EasyUnlockPrivateSetAutoPairingResultFunction() override;
437 // SyncExtensionFunction:
438 bool RunSync() override;
440 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetAutoPairingResultFunction);
443 } // namespace extensions
445 #endif // CHROME_BROWSER_EXTENSIONS_API_EASY_UNLOCK_PRIVATE_EASY_UNLOCK_PRIVATE_API_H_