1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_EXTENSIONS_API_EASY_UNLOCK_PRIVATE_EASY_UNLOCK_PRIVATE_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_EASY_UNLOCK_PRIVATE_EASY_UNLOCK_PRIVATE_API_H_
#include <stddef.h>
#include <memory>
#include <string>
#include "base/macros.h"
#include "device/bluetooth/bluetooth_device.h"
#include "extensions/browser/api/bluetooth/bluetooth_extension_function.h"
#include "extensions/browser/api/bluetooth_socket/bluetooth_socket_api.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_function.h"
// Implementations for chrome.easyUnlockPrivate API functions.
namespace base {
class Timer;
}
namespace content {
class BrowserContext;
}
namespace cryptauth {
class BluetoothThrottler;
class Connection;
class ExternalDeviceInfo;
class SecureMessageDelegate;
}
namespace proximity_auth {
class BluetoothLowEnergyConnectionFinder;
}
namespace extensions {
class EasyUnlockPrivateConnectionManager;
class EasyUnlockPrivateCryptoDelegate;
class EasyUnlockPrivateAPI : public BrowserContextKeyedAPI {
public:
static BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>*
GetFactoryInstance();
static const bool kServiceRedirectedInIncognito = true;
explicit EasyUnlockPrivateAPI(content::BrowserContext* context);
~EasyUnlockPrivateAPI() override;
EasyUnlockPrivateCryptoDelegate* GetCryptoDelegate();
EasyUnlockPrivateConnectionManager* get_connection_manager() {
return connection_manager_.get();
}
private:
friend class BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>;
// BrowserContextKeyedAPI implementation.
static const char* service_name() { return "EasyUnlockPrivate"; }
std::unique_ptr<EasyUnlockPrivateCryptoDelegate> crypto_delegate_;
std::unique_ptr<EasyUnlockPrivateConnectionManager> connection_manager_;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateAPI);
};
// TODO(tbarzic): Replace SyncExtensionFunction/AsyncExtensionFunction overrides
// with UIThreadExtensionFunction throughout the file.
class EasyUnlockPrivateGetStringsFunction : public UIThreadExtensionFunction {
public:
EasyUnlockPrivateGetStringsFunction();
protected:
~EasyUnlockPrivateGetStringsFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
private:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getStrings",
EASYUNLOCKPRIVATE_GETSTRINGS)
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetStringsFunction);
};
class EasyUnlockPrivatePerformECDHKeyAgreementFunction
: public AsyncExtensionFunction {
public:
EasyUnlockPrivatePerformECDHKeyAgreementFunction();
protected:
~EasyUnlockPrivatePerformECDHKeyAgreementFunction() override;
bool RunAsync() override;
private:
void OnData(const std::string& secret_key);
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.performECDHKeyAgreement",
EASYUNLOCKPRIVATE_PERFORMECDHKEYAGREEMENT)
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivatePerformECDHKeyAgreementFunction);
};
class EasyUnlockPrivateGenerateEcP256KeyPairFunction
: public AsyncExtensionFunction {
public:
EasyUnlockPrivateGenerateEcP256KeyPairFunction();
protected:
~EasyUnlockPrivateGenerateEcP256KeyPairFunction() override;
bool RunAsync() override;
private:
void OnData(const std::string& public_key,
const std::string& private_key);
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.generateEcP256KeyPair",
EASYUNLOCKPRIVATE_GENERATEECP256KEYPAIR)
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGenerateEcP256KeyPairFunction);
};
class EasyUnlockPrivateCreateSecureMessageFunction
: public AsyncExtensionFunction {
public:
EasyUnlockPrivateCreateSecureMessageFunction();
protected:
~EasyUnlockPrivateCreateSecureMessageFunction() override;
bool RunAsync() override;
private:
void OnData(const std::string& message);
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.createSecureMessage",
EASYUNLOCKPRIVATE_CREATESECUREMESSAGE)
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateCreateSecureMessageFunction);
};
class EasyUnlockPrivateUnwrapSecureMessageFunction
: public AsyncExtensionFunction {
public:
EasyUnlockPrivateUnwrapSecureMessageFunction();
protected:
~EasyUnlockPrivateUnwrapSecureMessageFunction() override;
bool RunAsync() override;
private:
void OnData(const std::string& data);
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.unwrapSecureMessage",
EASYUNLOCKPRIVATE_UNWRAPSECUREMESSAGE)
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateUnwrapSecureMessageFunction);
};
class EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction
: public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.seekBluetoothDeviceByAddress",
EASYUNLOCKPRIVATE_SEEKBLUETOOTHDEVICEBYADDRESS)
EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction();
private:
~EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() override;
// AsyncExtensionFunction:
bool RunAsync() override;
// Callbacks that are called when the seek operation succeeds or fails.
void OnSeekSuccess();
void OnSeekFailure(const std::string& error_message);
DISALLOW_COPY_AND_ASSIGN(
EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction);
};
class EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction
: public api::BluetoothSocketAbstractConnectFunction {
public:
DECLARE_EXTENSION_FUNCTION(
"easyUnlockPrivate.connectToBluetoothServiceInsecurely",
EASYUNLOCKPRIVATE_CONNECTTOBLUETOOTHSERVICEINSECURELY)
EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction();
private:
~EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction() override;
// BluetoothSocketAbstractConnectFunction:
void ConnectToService(device::BluetoothDevice* device,
const device::BluetoothUUID& uuid) override;
DISALLOW_COPY_AND_ASSIGN(
EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction);
};
class EasyUnlockPrivateUpdateScreenlockStateFunction
: public UIThreadExtensionFunction {
public:
EasyUnlockPrivateUpdateScreenlockStateFunction();
protected:
~EasyUnlockPrivateUpdateScreenlockStateFunction() override;
ResponseAction Run() override;
private:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.updateScreenlockState",
EASYUNLOCKPRIVATE_UPDATESCREENLOCKSTATE)
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateUpdateScreenlockStateFunction);
};
class EasyUnlockPrivateSetPermitAccessFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setPermitAccess",
EASYUNLOCKPRIVATE_SETPERMITACCESS)
EasyUnlockPrivateSetPermitAccessFunction();
private:
~EasyUnlockPrivateSetPermitAccessFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetPermitAccessFunction);
};
class EasyUnlockPrivateGetPermitAccessFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getPermitAccess",
EASYUNLOCKPRIVATE_GETPERMITACCESS)
EasyUnlockPrivateGetPermitAccessFunction();
protected:
~EasyUnlockPrivateGetPermitAccessFunction() override;
// Writes the user's public and private key in base64 form to the
// |user_public_key| and |user_private_key| fields. Exposed for testing.
virtual void GetKeyPairForExperiment(std::string* user_public_key,
std::string* user_private_key);
private:
// ExtensionFunction:
ResponseAction Run() override;
// Instead of returning the value set by easyUnlockPrivate.setPermitAccess,
// return the permit access used by the native CryptAuthEnrollmentManager.
ResponseAction GetPermitAccessForExperiment();
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetPermitAccessFunction);
};
class EasyUnlockPrivateClearPermitAccessFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.clearPermitAccess",
EASYUNLOCKPRIVATE_CLEARPERMITACCESS)
EasyUnlockPrivateClearPermitAccessFunction();
private:
~EasyUnlockPrivateClearPermitAccessFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateClearPermitAccessFunction);
};
class EasyUnlockPrivateSetRemoteDevicesFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setRemoteDevices",
EASYUNLOCKPRIVATE_SETREMOTEDEVICES)
EasyUnlockPrivateSetRemoteDevicesFunction();
private:
~EasyUnlockPrivateSetRemoteDevicesFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetRemoteDevicesFunction);
};
class EasyUnlockPrivateGetRemoteDevicesFunction
: public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getRemoteDevices",
EASYUNLOCKPRIVATE_GETREMOTEDEVICES)
EasyUnlockPrivateGetRemoteDevicesFunction();
protected:
~EasyUnlockPrivateGetRemoteDevicesFunction() override;
// Returns the user's private key used for the native experiment.
// Exposed for testing.
virtual std::string GetUserPrivateKey();
// Returns the user's unlock keys used for the native experiment.
// Exposed for testing.
virtual std::vector<cryptauth::ExternalDeviceInfo> GetUnlockKeys();
private:
// AsyncExtensionFunction:
bool RunAsync() override;
// Returns devices managed by the native Chrome component if the
// kEnableBluetoothLowEnergyDiscovery flag is set.
void ReturnDevicesForExperiment();
// Callback when the PSK of a device is derived.
void OnPSKDerivedForDevice(const cryptauth::ExternalDeviceInfo& device,
const std::string& persistent_symmetric_key);
// The permit id of the user. Used for the native experiment.
std::string permit_id_;
// The expected number of devices to return. Used for the native experiment.
size_t expected_devices_count_;
// Working list of the devices to return. Used for the native experiment.
std::unique_ptr<base::ListValue> remote_devices_;
// Used to derive devices' PSK. Used for the native experiment.
std::unique_ptr<cryptauth::SecureMessageDelegate>
secure_message_delegate_;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetRemoteDevicesFunction);
};
class EasyUnlockPrivateGetSignInChallengeFunction :
public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getSignInChallenge",
EASYUNLOCKPRIVATE_GETSIGNINCHALLENGE)
EasyUnlockPrivateGetSignInChallengeFunction();
private:
~EasyUnlockPrivateGetSignInChallengeFunction() override;
// AsyncExtensionFunction:
bool RunAsync() override;
// Called when the challenge and the signed nonce have been generated.
void OnDone(const std::string& challenge, const std::string& signed_nonce);
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetSignInChallengeFunction);
};
class EasyUnlockPrivateTrySignInSecretFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.trySignInSecret",
EASYUNLOCKPRIVATE_TRYSIGNINSECRET)
EasyUnlockPrivateTrySignInSecretFunction();
private:
~EasyUnlockPrivateTrySignInSecretFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateTrySignInSecretFunction);
};
class EasyUnlockPrivateGetUserInfoFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getUserInfo",
EASYUNLOCKPRIVATE_GETUSERINFO)
EasyUnlockPrivateGetUserInfoFunction();
private:
~EasyUnlockPrivateGetUserInfoFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetUserInfoFunction);
};
class EasyUnlockPrivateGetConnectionInfoFunction
: public api::BluetoothExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getConnectionInfo",
EASYUNLOCKPRIVATE_GETCONNECTIONINFO)
EasyUnlockPrivateGetConnectionInfoFunction();
private:
~EasyUnlockPrivateGetConnectionInfoFunction() override;
// BluetoothExtensionFunction:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
void OnConnectionInfo(
const device::BluetoothDevice::ConnectionInfo& connection_info);
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetConnectionInfoFunction);
};
class EasyUnlockPrivateShowErrorBubbleFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.showErrorBubble",
EASYUNLOCKPRIVATE_SHOWERRORBUBBLE)
EasyUnlockPrivateShowErrorBubbleFunction();
private:
~EasyUnlockPrivateShowErrorBubbleFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateShowErrorBubbleFunction);
};
class EasyUnlockPrivateHideErrorBubbleFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.hideErrorBubble",
EASYUNLOCKPRIVATE_HIDEERRORBUBBLE)
EasyUnlockPrivateHideErrorBubbleFunction();
private:
~EasyUnlockPrivateHideErrorBubbleFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateHideErrorBubbleFunction);
};
class EasyUnlockPrivateSetAutoPairingResultFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setAutoPairingResult",
EASYUNLOCKPRIVATE_SETAUTOPAIRINGRESULT)
EasyUnlockPrivateSetAutoPairingResultFunction();
private:
~EasyUnlockPrivateSetAutoPairingResultFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetAutoPairingResultFunction);
};
class EasyUnlockPrivateFindSetupConnectionFunction
: public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.findSetupConnection",
EASYUNLOCKPRIVATE_FINDSETUPCONNECTION)
EasyUnlockPrivateFindSetupConnectionFunction();
private:
~EasyUnlockPrivateFindSetupConnectionFunction() override;
// AsyncExtensionFunction:
bool RunAsync() override;
// Called when the connection with the remote device advertising the setup
// service was found.
void OnConnectionFound(std::unique_ptr<cryptauth::Connection> connection);
// Callback when waiting for |connection_finder_| to return.
void OnConnectionFinderTimedOut();
// The BLE connection finder instance.
std::unique_ptr<proximity_auth::BluetoothLowEnergyConnectionFinder>
connection_finder_;
// The connection throttler passed to the BLE connection finder.
std::unique_ptr<cryptauth::BluetoothThrottler> bluetooth_throttler_;
// Used for timing out when waiting for the connection finder to return.
std::unique_ptr<base::Timer> timer_;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateFindSetupConnectionFunction);
};
class EasyUnlockPrivateSetupConnectionStatusFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setupConnectionStatus",
EASYUNLOCKPRIVATE_SETUPCONNECTIONSTATUS)
EasyUnlockPrivateSetupConnectionStatusFunction();
private:
~EasyUnlockPrivateSetupConnectionStatusFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetupConnectionStatusFunction);
};
class EasyUnlockPrivateSetupConnectionDisconnectFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setupConnectionDisconnect",
EASYUNLOCKPRIVATE_SETUPCONNECTIONDISCONNECT)
EasyUnlockPrivateSetupConnectionDisconnectFunction();
private:
~EasyUnlockPrivateSetupConnectionDisconnectFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetupConnectionDisconnectFunction);
};
class EasyUnlockPrivateSetupConnectionSendFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setupConnectionSend",
EASYUNLOCKPRIVATE_SETUPCONNECTIONSEND)
EasyUnlockPrivateSetupConnectionSendFunction();
private:
~EasyUnlockPrivateSetupConnectionSendFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetupConnectionSendFunction);
};
class EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION(
"easyUnlockPrivate.setupConnectionGetDeviceAddress",
EASYUNLOCKPRIVATE_SETUPCONNECTIONGETDEVICEADDRESS)
EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction();
private:
~EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(
EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction);
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_EASY_UNLOCK_PRIVATE_EASY_UNLOCK_PRIVATE_API_H_
|