| 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 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
api.h" | 5 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
api.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 base::Bind(&EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData, | 342 base::Bind(&EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData, |
| 343 this)); | 343 this)); |
| 344 return true; | 344 return true; |
| 345 } | 345 } |
| 346 | 346 |
| 347 void EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData( | 347 void EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData( |
| 348 const std::string& secret_key) { | 348 const std::string& secret_key) { |
| 349 // TODO(tbarzic): Improve error handling. | 349 // TODO(tbarzic): Improve error handling. |
| 350 if (!secret_key.empty()) { | 350 if (!secret_key.empty()) { |
| 351 results_ = easy_unlock_private::PerformECDHKeyAgreement::Results::Create( | 351 results_ = easy_unlock_private::PerformECDHKeyAgreement::Results::Create( |
| 352 secret_key); | 352 std::vector<char>(secret_key.begin(), secret_key.end())); |
| 353 } | 353 } |
| 354 SendResponse(true); | 354 SendResponse(true); |
| 355 } | 355 } |
| 356 | 356 |
| 357 EasyUnlockPrivateGenerateEcP256KeyPairFunction:: | 357 EasyUnlockPrivateGenerateEcP256KeyPairFunction:: |
| 358 EasyUnlockPrivateGenerateEcP256KeyPairFunction() {} | 358 EasyUnlockPrivateGenerateEcP256KeyPairFunction() {} |
| 359 | 359 |
| 360 EasyUnlockPrivateGenerateEcP256KeyPairFunction:: | 360 EasyUnlockPrivateGenerateEcP256KeyPairFunction:: |
| 361 ~EasyUnlockPrivateGenerateEcP256KeyPairFunction() {} | 361 ~EasyUnlockPrivateGenerateEcP256KeyPairFunction() {} |
| 362 | 362 |
| 363 bool EasyUnlockPrivateGenerateEcP256KeyPairFunction::RunAsync() { | 363 bool EasyUnlockPrivateGenerateEcP256KeyPairFunction::RunAsync() { |
| 364 GetCryptoDelegate(browser_context())->GenerateEcP256KeyPair( | 364 GetCryptoDelegate(browser_context())->GenerateEcP256KeyPair( |
| 365 base::Bind(&EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData, | 365 base::Bind(&EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData, |
| 366 this)); | 366 this)); |
| 367 return true; | 367 return true; |
| 368 } | 368 } |
| 369 | 369 |
| 370 void EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData( | 370 void EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData( |
| 371 const std::string& private_key, | 371 const std::string& private_key, |
| 372 const std::string& public_key) { | 372 const std::string& public_key) { |
| 373 // TODO(tbarzic): Improve error handling. | 373 // TODO(tbarzic): Improve error handling. |
| 374 if (!public_key.empty() && !private_key.empty()) { | 374 if (!public_key.empty() && !private_key.empty()) { |
| 375 results_ = easy_unlock_private::GenerateEcP256KeyPair::Results::Create( | 375 results_ = easy_unlock_private::GenerateEcP256KeyPair::Results::Create( |
| 376 public_key, private_key); | 376 std::vector<char>(public_key.begin(), public_key.end()), |
| 377 std::vector<char>(private_key.begin(), private_key.end())); |
| 377 } | 378 } |
| 378 SendResponse(true); | 379 SendResponse(true); |
| 379 } | 380 } |
| 380 | 381 |
| 381 EasyUnlockPrivateCreateSecureMessageFunction:: | 382 EasyUnlockPrivateCreateSecureMessageFunction:: |
| 382 EasyUnlockPrivateCreateSecureMessageFunction() {} | 383 EasyUnlockPrivateCreateSecureMessageFunction() {} |
| 383 | 384 |
| 384 EasyUnlockPrivateCreateSecureMessageFunction:: | 385 EasyUnlockPrivateCreateSecureMessageFunction:: |
| 385 ~EasyUnlockPrivateCreateSecureMessageFunction() {} | 386 ~EasyUnlockPrivateCreateSecureMessageFunction() {} |
| 386 | 387 |
| 387 bool EasyUnlockPrivateCreateSecureMessageFunction::RunAsync() { | 388 bool EasyUnlockPrivateCreateSecureMessageFunction::RunAsync() { |
| 388 scoped_ptr<easy_unlock_private::CreateSecureMessage::Params> params = | 389 scoped_ptr<easy_unlock_private::CreateSecureMessage::Params> params = |
| 389 easy_unlock_private::CreateSecureMessage::Params::Create(*args_); | 390 easy_unlock_private::CreateSecureMessage::Params::Create(*args_); |
| 390 EXTENSION_FUNCTION_VALIDATE(params); | 391 EXTENSION_FUNCTION_VALIDATE(params); |
| 391 | 392 |
| 392 GetCryptoDelegate(browser_context())->CreateSecureMessage( | 393 GetCryptoDelegate(browser_context())->CreateSecureMessage( |
| 393 *params, | 394 *params, |
| 394 base::Bind(&EasyUnlockPrivateCreateSecureMessageFunction::OnData, | 395 base::Bind(&EasyUnlockPrivateCreateSecureMessageFunction::OnData, |
| 395 this)); | 396 this)); |
| 396 return true; | 397 return true; |
| 397 } | 398 } |
| 398 | 399 |
| 399 void EasyUnlockPrivateCreateSecureMessageFunction::OnData( | 400 void EasyUnlockPrivateCreateSecureMessageFunction::OnData( |
| 400 const std::string& message) { | 401 const std::string& message) { |
| 401 // TODO(tbarzic): Improve error handling. | 402 // TODO(tbarzic): Improve error handling. |
| 402 if (!message.empty()) { | 403 if (!message.empty()) { |
| 403 results_ = easy_unlock_private::CreateSecureMessage::Results::Create( | 404 results_ = easy_unlock_private::CreateSecureMessage::Results::Create( |
| 404 message); | 405 std::vector<char>(message.begin(), message.end())); |
| 405 } | 406 } |
| 406 SendResponse(true); | 407 SendResponse(true); |
| 407 } | 408 } |
| 408 | 409 |
| 409 EasyUnlockPrivateUnwrapSecureMessageFunction:: | 410 EasyUnlockPrivateUnwrapSecureMessageFunction:: |
| 410 EasyUnlockPrivateUnwrapSecureMessageFunction() {} | 411 EasyUnlockPrivateUnwrapSecureMessageFunction() {} |
| 411 | 412 |
| 412 EasyUnlockPrivateUnwrapSecureMessageFunction:: | 413 EasyUnlockPrivateUnwrapSecureMessageFunction:: |
| 413 ~EasyUnlockPrivateUnwrapSecureMessageFunction() {} | 414 ~EasyUnlockPrivateUnwrapSecureMessageFunction() {} |
| 414 | 415 |
| 415 bool EasyUnlockPrivateUnwrapSecureMessageFunction::RunAsync() { | 416 bool EasyUnlockPrivateUnwrapSecureMessageFunction::RunAsync() { |
| 416 scoped_ptr<easy_unlock_private::UnwrapSecureMessage::Params> params = | 417 scoped_ptr<easy_unlock_private::UnwrapSecureMessage::Params> params = |
| 417 easy_unlock_private::UnwrapSecureMessage::Params::Create(*args_); | 418 easy_unlock_private::UnwrapSecureMessage::Params::Create(*args_); |
| 418 EXTENSION_FUNCTION_VALIDATE(params); | 419 EXTENSION_FUNCTION_VALIDATE(params); |
| 419 | 420 |
| 420 GetCryptoDelegate(browser_context())->UnwrapSecureMessage( | 421 GetCryptoDelegate(browser_context())->UnwrapSecureMessage( |
| 421 *params, | 422 *params, |
| 422 base::Bind(&EasyUnlockPrivateUnwrapSecureMessageFunction::OnData, | 423 base::Bind(&EasyUnlockPrivateUnwrapSecureMessageFunction::OnData, |
| 423 this)); | 424 this)); |
| 424 return true; | 425 return true; |
| 425 } | 426 } |
| 426 | 427 |
| 427 void EasyUnlockPrivateUnwrapSecureMessageFunction::OnData( | 428 void EasyUnlockPrivateUnwrapSecureMessageFunction::OnData( |
| 428 const std::string& data) { | 429 const std::string& data) { |
| 429 // TODO(tbarzic): Improve error handling. | 430 // TODO(tbarzic): Improve error handling. |
| 430 if (!data.empty()) | 431 if (!data.empty()) { |
| 431 results_ = easy_unlock_private::UnwrapSecureMessage::Results::Create(data); | 432 results_ = easy_unlock_private::UnwrapSecureMessage::Results::Create( |
| 433 std::vector<char>(data.begin(), data.end())); |
| 434 } |
| 432 SendResponse(true); | 435 SendResponse(true); |
| 433 } | 436 } |
| 434 | 437 |
| 435 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction:: | 438 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction:: |
| 436 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() {} | 439 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() {} |
| 437 | 440 |
| 438 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction:: | 441 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction:: |
| 439 ~EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() {} | 442 ~EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() {} |
| 440 | 443 |
| 441 bool EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::RunAsync() { | 444 bool EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::RunAsync() { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 EasyUnlockService::Get(profile)->GetChallenge(); | 621 EasyUnlockService::Get(profile)->GetChallenge(); |
| 619 if (!challenge.empty() && !params->nonce.empty()) { | 622 if (!challenge.empty() && !params->nonce.empty()) { |
| 620 EasyUnlockTpmKeyManager* key_manager = | 623 EasyUnlockTpmKeyManager* key_manager = |
| 621 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile); | 624 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile); |
| 622 if (!key_manager) { | 625 if (!key_manager) { |
| 623 SetError("No EasyUnlockTpmKeyManager."); | 626 SetError("No EasyUnlockTpmKeyManager."); |
| 624 return false; | 627 return false; |
| 625 } | 628 } |
| 626 key_manager->SignUsingTpmKey( | 629 key_manager->SignUsingTpmKey( |
| 627 EasyUnlockService::Get(profile)->GetUserEmail(), | 630 EasyUnlockService::Get(profile)->GetUserEmail(), |
| 628 params->nonce, | 631 std::string(params->nonce.begin(), params->nonce.end()), |
| 629 base::Bind(&EasyUnlockPrivateGetSignInChallengeFunction::OnDone, | 632 base::Bind(&EasyUnlockPrivateGetSignInChallengeFunction::OnDone, this, |
| 630 this, | |
| 631 challenge)); | 633 challenge)); |
| 632 } else { | 634 } else { |
| 633 OnDone(challenge, std::string()); | 635 OnDone(challenge, std::string()); |
| 634 } | 636 } |
| 635 return true; | 637 return true; |
| 636 #else // if !defined(OS_CHROMEOS) | 638 #else // if !defined(OS_CHROMEOS) |
| 637 SetError("Sign-in not supported."); | 639 SetError("Sign-in not supported."); |
| 638 return false; | 640 return false; |
| 639 #endif // defined(OS_CHROMEOS) | 641 #endif // defined(OS_CHROMEOS) |
| 640 } | 642 } |
| 641 | 643 |
| 642 void EasyUnlockPrivateGetSignInChallengeFunction::OnDone( | 644 void EasyUnlockPrivateGetSignInChallengeFunction::OnDone( |
| 643 const std::string& challenge, | 645 const std::string& challenge, |
| 644 const std::string& signed_nonce) { | 646 const std::string& signed_nonce) { |
| 645 results_ = easy_unlock_private::GetSignInChallenge::Results::Create( | 647 results_ = easy_unlock_private::GetSignInChallenge::Results::Create( |
| 646 challenge, signed_nonce); | 648 std::vector<char>(challenge.begin(), challenge.end()), |
| 649 std::vector<char>(signed_nonce.begin(), signed_nonce.end())); |
| 647 SendResponse(true); | 650 SendResponse(true); |
| 648 } | 651 } |
| 649 | 652 |
| 650 EasyUnlockPrivateTrySignInSecretFunction:: | 653 EasyUnlockPrivateTrySignInSecretFunction:: |
| 651 EasyUnlockPrivateTrySignInSecretFunction() { | 654 EasyUnlockPrivateTrySignInSecretFunction() { |
| 652 } | 655 } |
| 653 | 656 |
| 654 EasyUnlockPrivateTrySignInSecretFunction:: | 657 EasyUnlockPrivateTrySignInSecretFunction:: |
| 655 ~EasyUnlockPrivateTrySignInSecretFunction() { | 658 ~EasyUnlockPrivateTrySignInSecretFunction() { |
| 656 } | 659 } |
| 657 | 660 |
| 658 bool EasyUnlockPrivateTrySignInSecretFunction::RunSync() { | 661 bool EasyUnlockPrivateTrySignInSecretFunction::RunSync() { |
| 659 scoped_ptr<easy_unlock_private::TrySignInSecret::Params> params( | 662 scoped_ptr<easy_unlock_private::TrySignInSecret::Params> params( |
| 660 easy_unlock_private::TrySignInSecret::Params::Create(*args_)); | 663 easy_unlock_private::TrySignInSecret::Params::Create(*args_)); |
| 661 EXTENSION_FUNCTION_VALIDATE(params.get()); | 664 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 662 | 665 |
| 663 Profile* profile = Profile::FromBrowserContext(browser_context()); | 666 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 664 EasyUnlockService::Get(profile)->FinalizeSignin(params->sign_in_secret); | 667 EasyUnlockService::Get(profile)->FinalizeSignin(std::string( |
| 668 params->sign_in_secret.begin(), params->sign_in_secret.end())); |
| 665 return true; | 669 return true; |
| 666 } | 670 } |
| 667 | 671 |
| 668 EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() { | 672 EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() { |
| 669 } | 673 } |
| 670 | 674 |
| 671 EasyUnlockPrivateGetUserInfoFunction::~EasyUnlockPrivateGetUserInfoFunction() { | 675 EasyUnlockPrivateGetUserInfoFunction::~EasyUnlockPrivateGetUserInfoFunction() { |
| 672 } | 676 } |
| 673 | 677 |
| 674 bool EasyUnlockPrivateGetUserInfoFunction::RunSync() { | 678 bool EasyUnlockPrivateGetUserInfoFunction::RunSync() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 700 #if defined(OS_CHROMEOS) | 704 #if defined(OS_CHROMEOS) |
| 701 EasyUnlockService* service = | 705 EasyUnlockService* service = |
| 702 EasyUnlockService::Get(Profile::FromBrowserContext(browser_context())); | 706 EasyUnlockService::Get(Profile::FromBrowserContext(browser_context())); |
| 703 const std::vector<ui::ScaleFactor>& supported_scale_factors = | 707 const std::vector<ui::ScaleFactor>& supported_scale_factors = |
| 704 ui::GetSupportedScaleFactors(); | 708 ui::GetSupportedScaleFactors(); |
| 705 | 709 |
| 706 base::RefCountedMemory* user_image = | 710 base::RefCountedMemory* user_image = |
| 707 chromeos::options::UserImageSource::GetUserImage( | 711 chromeos::options::UserImageSource::GetUserImage( |
| 708 service->GetUserEmail(), supported_scale_factors.back()); | 712 service->GetUserEmail(), supported_scale_factors.back()); |
| 709 | 713 |
| 710 results_ = easy_unlock_private::GetUserImage::Results::Create(std::string( | 714 results_ = |
| 711 reinterpret_cast<const char*>(user_image->front()), user_image->size())); | 715 easy_unlock_private::GetUserImage::Results::Create(std::vector<char>( |
| 716 user_image->front(), user_image->front() + user_image->size())); |
| 712 #else | 717 #else |
| 713 // TODO(tengs): Find a way to get the profile picture for non-ChromeOS | 718 // TODO(tengs): Find a way to get the profile picture for non-ChromeOS |
| 714 // devices. | 719 // devices. |
| 715 results_ = easy_unlock_private::GetUserImage::Results::Create(""); | 720 results_ = |
| 721 easy_unlock_private::GetUserImage::Results::Create(std::vector<char>()); |
| 716 SetError("Not supported on non-ChromeOS platforms."); | 722 SetError("Not supported on non-ChromeOS platforms."); |
| 717 #endif | 723 #endif |
| 718 return true; | 724 return true; |
| 719 } | 725 } |
| 720 | 726 |
| 721 EasyUnlockPrivateGetConnectionInfoFunction:: | 727 EasyUnlockPrivateGetConnectionInfoFunction:: |
| 722 EasyUnlockPrivateGetConnectionInfoFunction() { | 728 EasyUnlockPrivateGetConnectionInfoFunction() { |
| 723 } | 729 } |
| 724 | 730 |
| 725 EasyUnlockPrivateGetConnectionInfoFunction:: | 731 EasyUnlockPrivateGetConnectionInfoFunction:: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 scoped_ptr<base::ListValue> results(new base::ListValue()); | 769 scoped_ptr<base::ListValue> results(new base::ListValue()); |
| 764 results->AppendInteger(connection_info.rssi); | 770 results->AppendInteger(connection_info.rssi); |
| 765 results->AppendInteger(connection_info.transmit_power); | 771 results->AppendInteger(connection_info.transmit_power); |
| 766 results->AppendInteger(connection_info.max_transmit_power); | 772 results->AppendInteger(connection_info.max_transmit_power); |
| 767 SetResultList(results.Pass()); | 773 SetResultList(results.Pass()); |
| 768 SendResponse(true); | 774 SendResponse(true); |
| 769 } | 775 } |
| 770 | 776 |
| 771 } // namespace api | 777 } // namespace api |
| 772 } // namespace extensions | 778 } // namespace extensions |
| OLD | NEW |