Commit 03509fc0 authored by Reilly Grant's avatar Reilly Grant Committed by Chromium LUCI CQ

Convert callbacks in //chrome/browser/chromeos/login/easy_unlock

This change converts callbacks from base::Bind and base::Callback to
Once/Repeating in //chrome/browser/chromeos/login/easy_unlock.

This should unblock conversion of //chromeos/components/proximity_auth.

Bug: 1148570
Change-Id: I4da7c25ef8e20d3700bc49348d109424b64975af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2638359
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844914}
parent 6b78ae9c
...@@ -33,8 +33,8 @@ EasyUnlockChallengeWrapper::EasyUnlockChallengeWrapper( ...@@ -33,8 +33,8 @@ EasyUnlockChallengeWrapper::EasyUnlockChallengeWrapper(
EasyUnlockChallengeWrapper::~EasyUnlockChallengeWrapper() {} EasyUnlockChallengeWrapper::~EasyUnlockChallengeWrapper() {}
void EasyUnlockChallengeWrapper::WrapChallenge( void EasyUnlockChallengeWrapper::WrapChallenge(
const WrappedChallengeCallback& callback) { WrappedChallengeCallback callback) {
callback_ = callback; callback_ = std::move(callback);
// Because the TPM is used to sign the channel binding data, we need to // Because the TPM is used to sign the channel binding data, we need to
// construct the SecureMessage by hand instead of using the // construct the SecureMessage by hand instead of using the
...@@ -54,14 +54,14 @@ void EasyUnlockChallengeWrapper::WrapChallenge( ...@@ -54,14 +54,14 @@ void EasyUnlockChallengeWrapper::WrapChallenge(
SignUsingTpmKey( SignUsingTpmKey(
data_to_sign, data_to_sign,
base::Bind(&EasyUnlockChallengeWrapper::OnChannelBindingDataSigned, base::BindOnce(&EasyUnlockChallengeWrapper::OnChannelBindingDataSigned,
weak_ptr_factory_.GetWeakPtr(), signature_metadata)); weak_ptr_factory_.GetWeakPtr(), signature_metadata));
} }
void EasyUnlockChallengeWrapper::SignUsingTpmKey( void EasyUnlockChallengeWrapper::SignUsingTpmKey(
const std::string& data_to_sign, const std::string& data_to_sign,
const base::Callback<void(const std::string&)>& callback) { base::OnceCallback<void(const std::string&)> callback) {
key_manager_->SignUsingTpmKey(account_id_, data_to_sign, callback); key_manager_->SignUsingTpmKey(account_id_, data_to_sign, std::move(callback));
} }
void EasyUnlockChallengeWrapper::OnChannelBindingDataSigned( void EasyUnlockChallengeWrapper::OnChannelBindingDataSigned(
...@@ -77,7 +77,7 @@ void EasyUnlockChallengeWrapper::OnChannelBindingDataSigned( ...@@ -77,7 +77,7 @@ void EasyUnlockChallengeWrapper::OnChannelBindingDataSigned(
wrapped_challenge.set_signature(signature_container.SerializeAsString()); wrapped_challenge.set_signature(signature_container.SerializeAsString());
PA_LOG(VERBOSE) << "Finished wrapping challenge."; PA_LOG(VERBOSE) << "Finished wrapping challenge.";
callback_.Run(wrapped_challenge.SerializeAsString()); std::move(callback_).Run(wrapped_challenge.SerializeAsString());
} }
} // namespace chromeos } // namespace chromeos
...@@ -36,16 +36,16 @@ class EasyUnlockChallengeWrapper { ...@@ -36,16 +36,16 @@ class EasyUnlockChallengeWrapper {
// Wraps the challenge and invokes `callback` with the `wrapped_challenge` // Wraps the challenge and invokes `callback` with the `wrapped_challenge`
// that will be send directly to the remote device. // that will be send directly to the remote device.
typedef base::Callback<void(const std::string& wrapped_challenge)> using WrappedChallengeCallback =
WrappedChallengeCallback; base::OnceCallback<void(const std::string& wrapped_challenge)>;
void WrapChallenge(const WrappedChallengeCallback& callback); void WrapChallenge(WrappedChallengeCallback callback);
protected: protected:
// Signs `data_to_sign` with the TPM. `callback` will be invoked upon // Signs `data_to_sign` with the TPM. `callback` will be invoked upon
// completion. Exposed for testing. // completion. Exposed for testing.
virtual void SignUsingTpmKey( virtual void SignUsingTpmKey(
const std::string& data_to_sign, const std::string& data_to_sign,
const base::Callback<void(const std::string&)>& callback); base::OnceCallback<void(const std::string&)> callback);
private: private:
// Called when the channel binding data is signed by the TPM and completes the // Called when the channel binding data is signed by the TPM and completes the
......
...@@ -37,7 +37,7 @@ class TestableEasyUnlockChallengeWrapper : public EasyUnlockChallengeWrapper { ...@@ -37,7 +37,7 @@ class TestableEasyUnlockChallengeWrapper : public EasyUnlockChallengeWrapper {
private: private:
void SignUsingTpmKey( void SignUsingTpmKey(
const std::string& data_to_sign, const std::string& data_to_sign,
const base::Callback<void(const std::string&)>& callback) override { base::OnceCallback<void(const std::string&)> callback) override {
std::string expected_salt = std::string(kSalt); std::string expected_salt = std::string(kSalt);
std::string expected_channel_binding_data = std::string expected_channel_binding_data =
std::string(kChannelBindingData); std::string(kChannelBindingData);
...@@ -54,7 +54,7 @@ class TestableEasyUnlockChallengeWrapper : public EasyUnlockChallengeWrapper { ...@@ -54,7 +54,7 @@ class TestableEasyUnlockChallengeWrapper : public EasyUnlockChallengeWrapper {
securemessage::HeaderAndBody proto; securemessage::HeaderAndBody proto;
EXPECT_TRUE(proto.ParseFromString(header_and_body)); EXPECT_TRUE(proto.ParseFromString(header_and_body));
callback.Run(kSignature); std::move(callback).Run(kSignature);
} }
DISALLOW_COPY_AND_ASSIGN(TestableEasyUnlockChallengeWrapper); DISALLOW_COPY_AND_ASSIGN(TestableEasyUnlockChallengeWrapper);
...@@ -65,7 +65,7 @@ class TestableEasyUnlockChallengeWrapper : public EasyUnlockChallengeWrapper { ...@@ -65,7 +65,7 @@ class TestableEasyUnlockChallengeWrapper : public EasyUnlockChallengeWrapper {
TEST(EasyUnlockChallengeWrapperTest, TestWrapChallenge) { TEST(EasyUnlockChallengeWrapperTest, TestWrapChallenge) {
TestableEasyUnlockChallengeWrapper wrapper; TestableEasyUnlockChallengeWrapper wrapper;
std::string wrapped_challenge; std::string wrapped_challenge;
wrapper.WrapChallenge(base::Bind(&SaveResult, &wrapped_challenge)); wrapper.WrapChallenge(base::BindOnce(&SaveResult, &wrapped_challenge));
securemessage::SecureMessage challenge_secure_message; securemessage::SecureMessage challenge_secure_message;
ASSERT_TRUE(challenge_secure_message.ParseFromString(wrapped_challenge)); ASSERT_TRUE(challenge_secure_message.ParseFromString(wrapped_challenge));
......
...@@ -47,12 +47,12 @@ const int kEasyUnlockKeyPrivileges = ...@@ -47,12 +47,12 @@ const int kEasyUnlockKeyPrivileges =
class EasyUnlockCreateKeysOperation::ChallengeCreator { class EasyUnlockCreateKeysOperation::ChallengeCreator {
public: public:
typedef base::Callback<void(bool success)> ChallengeCreatedCallback; using ChallengeCreatedCallback = base::OnceCallback<void(bool success)>;
ChallengeCreator(const std::string& user_key, ChallengeCreator(const std::string& user_key,
const std::string& session_key, const std::string& session_key,
const std::string& tpm_pub_key, const std::string& tpm_pub_key,
EasyUnlockDeviceKeyData* device, EasyUnlockDeviceKeyData* device,
const ChallengeCreatedCallback& callback); ChallengeCreatedCallback callback);
~ChallengeCreator(); ~ChallengeCreator();
void Start(); void Start();
...@@ -95,12 +95,12 @@ EasyUnlockCreateKeysOperation::ChallengeCreator::ChallengeCreator( ...@@ -95,12 +95,12 @@ EasyUnlockCreateKeysOperation::ChallengeCreator::ChallengeCreator(
const std::string& session_key, const std::string& session_key,
const std::string& tpm_pub_key, const std::string& tpm_pub_key,
EasyUnlockDeviceKeyData* device, EasyUnlockDeviceKeyData* device,
const ChallengeCreatedCallback& callback) ChallengeCreatedCallback callback)
: user_key_(user_key), : user_key_(user_key),
session_key_(session_key), session_key_(session_key),
tpm_pub_key_(tpm_pub_key), tpm_pub_key_(tpm_pub_key),
device_(device), device_(device),
callback_(callback), callback_(std::move(callback)),
easy_unlock_client_(DBusThreadManager::Get()->GetEasyUnlockClient()) {} easy_unlock_client_(DBusThreadManager::Get()->GetEasyUnlockClient()) {}
EasyUnlockCreateKeysOperation::ChallengeCreator::~ChallengeCreator() {} EasyUnlockCreateKeysOperation::ChallengeCreator::~ChallengeCreator() {}
...@@ -115,7 +115,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnEcKeyPairGenerated( ...@@ -115,7 +115,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnEcKeyPairGenerated(
const std::string& ec_public_key) { const std::string& ec_public_key) {
if (ec_private_key.empty() || ec_public_key.empty()) { if (ec_private_key.empty() || ec_public_key.empty()) {
PA_LOG(ERROR) << "Easy unlock failed to generate ec key pair."; PA_LOG(ERROR) << "Easy unlock failed to generate ec key pair.";
callback_.Run(false); std::move(callback_).Run(false);
return; return;
} }
...@@ -124,7 +124,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnEcKeyPairGenerated( ...@@ -124,7 +124,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnEcKeyPairGenerated(
base::Base64UrlDecodePolicy::REQUIRE_PADDING, base::Base64UrlDecodePolicy::REQUIRE_PADDING,
&device_pub_key)) { &device_pub_key)) {
PA_LOG(ERROR) << "Easy unlock failed to decode device public key."; PA_LOG(ERROR) << "Easy unlock failed to decode device public key.";
callback_.Run(false); std::move(callback_).Run(false);
return; return;
} }
...@@ -139,7 +139,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnEskGenerated( ...@@ -139,7 +139,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnEskGenerated(
const std::string& esk) { const std::string& esk) {
if (esk.empty()) { if (esk.empty()) {
PA_LOG(ERROR) << "Easy unlock failed to generate challenge esk."; PA_LOG(ERROR) << "Easy unlock failed to generate challenge esk.";
callback_.Run(false); std::move(callback_).Run(false);
return; return;
} }
...@@ -158,7 +158,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnTPMPublicKeyWrapped( ...@@ -158,7 +158,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnTPMPublicKeyWrapped(
const std::string& wrapped_key) { const std::string& wrapped_key) {
if (wrapped_key.empty()) { if (wrapped_key.empty()) {
PA_LOG(ERROR) << "Unable to wrap RSA key"; PA_LOG(ERROR) << "Unable to wrap RSA key";
callback_.Run(false); std::move(callback_).Run(false);
return; return;
} }
wrapped_tpm_pub_key_ = wrapped_key; wrapped_tpm_pub_key_ = wrapped_key;
...@@ -196,7 +196,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnPayloadGenerated( ...@@ -196,7 +196,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnPayloadGenerated(
const std::string& payload) { const std::string& payload) {
if (payload.empty()) { if (payload.empty()) {
PA_LOG(ERROR) << "Easy unlock failed to generate challenge payload."; PA_LOG(ERROR) << "Easy unlock failed to generate challenge payload.";
callback_.Run(false); std::move(callback_).Run(false);
return; return;
} }
...@@ -216,12 +216,12 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnChallengeGenerated( ...@@ -216,12 +216,12 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnChallengeGenerated(
const std::string& challenge) { const std::string& challenge) {
if (challenge.empty()) { if (challenge.empty()) {
PA_LOG(ERROR) << "Easy unlock failed to generate challenge."; PA_LOG(ERROR) << "Easy unlock failed to generate challenge.";
callback_.Run(false); std::move(callback_).Run(false);
return; return;
} }
device_->challenge = challenge; device_->challenge = challenge;
callback_.Run(true); std::move(callback_).Run(true);
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
...@@ -231,11 +231,11 @@ EasyUnlockCreateKeysOperation::EasyUnlockCreateKeysOperation( ...@@ -231,11 +231,11 @@ EasyUnlockCreateKeysOperation::EasyUnlockCreateKeysOperation(
const UserContext& user_context, const UserContext& user_context,
const std::string& tpm_public_key, const std::string& tpm_public_key,
const EasyUnlockDeviceKeyDataList& devices, const EasyUnlockDeviceKeyDataList& devices,
const CreateKeysCallback& callback) CreateKeysCallback callback)
: user_context_(user_context), : user_context_(user_context),
tpm_public_key_(tpm_public_key), tpm_public_key_(tpm_public_key),
devices_(devices), devices_(devices),
callback_(callback), callback_(std::move(callback)),
key_creation_index_(0) { key_creation_index_(0) {
// Must have the secret and callback. // Must have the secret and callback.
DCHECK(!user_context_.GetKey()->GetSecret().empty()); DCHECK(!user_context_.GetKey()->GetSecret().empty());
...@@ -252,7 +252,7 @@ void EasyUnlockCreateKeysOperation::Start() { ...@@ -252,7 +252,7 @@ void EasyUnlockCreateKeysOperation::Start() {
void EasyUnlockCreateKeysOperation::CreateKeyForDeviceAtIndex(size_t index) { void EasyUnlockCreateKeysOperation::CreateKeyForDeviceAtIndex(size_t index) {
DCHECK_GE(index, 0u); DCHECK_GE(index, 0u);
if (index == devices_.size()) { if (index == devices_.size()) {
callback_.Run(true); std::move(callback_).Run(true);
return; return;
} }
...@@ -268,20 +268,20 @@ void EasyUnlockCreateKeysOperation::CreateKeyForDeviceAtIndex(size_t index) { ...@@ -268,20 +268,20 @@ void EasyUnlockCreateKeysOperation::CreateKeyForDeviceAtIndex(size_t index) {
crypto::Encryptor encryptor; crypto::Encryptor encryptor;
if (!encryptor.Init(session_key.get(), crypto::Encryptor::CBC, iv)) { if (!encryptor.Init(session_key.get(), crypto::Encryptor::CBC, iv)) {
PA_LOG(ERROR) << "Easy unlock failed to init encryptor for key creation."; PA_LOG(ERROR) << "Easy unlock failed to init encryptor for key creation.";
callback_.Run(false); std::move(callback_).Run(false);
return; return;
} }
EasyUnlockDeviceKeyData* device = &devices_[index]; EasyUnlockDeviceKeyData* device = &devices_[index];
if (!encryptor.Encrypt(user_key, &device->wrapped_secret)) { if (!encryptor.Encrypt(user_key, &device->wrapped_secret)) {
PA_LOG(ERROR) << "Easy unlock failed to encrypt user key for key creation."; PA_LOG(ERROR) << "Easy unlock failed to encrypt user key for key creation.";
callback_.Run(false); std::move(callback_).Run(false);
return; return;
} }
challenge_creator_.reset(new ChallengeCreator( challenge_creator_.reset(new ChallengeCreator(
user_key, session_key->key(), tpm_public_key_, device, user_key, session_key->key(), tpm_public_key_, device,
base::Bind(&EasyUnlockCreateKeysOperation::OnChallengeCreated, base::BindOnce(&EasyUnlockCreateKeysOperation::OnChallengeCreated,
weak_ptr_factory_.GetWeakPtr(), index))); weak_ptr_factory_.GetWeakPtr(), index)));
challenge_creator_->Start(); challenge_creator_->Start();
} }
...@@ -292,7 +292,7 @@ void EasyUnlockCreateKeysOperation::OnChallengeCreated(size_t index, ...@@ -292,7 +292,7 @@ void EasyUnlockCreateKeysOperation::OnChallengeCreated(size_t index,
if (!success) { if (!success) {
PA_LOG(ERROR) << "Easy unlock failed to create challenge for key creation."; PA_LOG(ERROR) << "Easy unlock failed to create challenge for key creation.";
callback_.Run(false); std::move(callback_).Run(false);
return; return;
} }
...@@ -307,7 +307,7 @@ void EasyUnlockCreateKeysOperation::OnGetSystemSalt( ...@@ -307,7 +307,7 @@ void EasyUnlockCreateKeysOperation::OnGetSystemSalt(
DCHECK_EQ(key_creation_index_, index); DCHECK_EQ(key_creation_index_, index);
if (system_salt.empty()) { if (system_salt.empty()) {
PA_LOG(ERROR) << "Easy unlock failed to get system salt for key creation."; PA_LOG(ERROR) << "Easy unlock failed to get system salt for key creation.";
callback_.Run(false); std::move(callback_).Run(false);
return; return;
} }
...@@ -367,7 +367,7 @@ void EasyUnlockCreateKeysOperation::OnKeyCreated( ...@@ -367,7 +367,7 @@ void EasyUnlockCreateKeysOperation::OnKeyCreated(
if (!success) { if (!success) {
PA_LOG(ERROR) << "Easy unlock failed to create key, code=" << return_code; PA_LOG(ERROR) << "Easy unlock failed to create key, code=" << return_code;
callback_.Run(false); std::move(callback_).Run(false);
return; return;
} }
......
...@@ -24,11 +24,11 @@ class UserContext; ...@@ -24,11 +24,11 @@ class UserContext;
// A class to create Easy unlock cryptohome keys for the given user and devices. // A class to create Easy unlock cryptohome keys for the given user and devices.
class EasyUnlockCreateKeysOperation { class EasyUnlockCreateKeysOperation {
public: public:
typedef base::Callback<void(bool success)> CreateKeysCallback; using CreateKeysCallback = base::OnceCallback<void(bool success)>;
EasyUnlockCreateKeysOperation(const UserContext& user_context, EasyUnlockCreateKeysOperation(const UserContext& user_context,
const std::string& tpm_public_key, const std::string& tpm_public_key,
const EasyUnlockDeviceKeyDataList& devices, const EasyUnlockDeviceKeyDataList& devices,
const CreateKeysCallback& callback); CreateKeysCallback callback);
~EasyUnlockCreateKeysOperation(); ~EasyUnlockCreateKeysOperation();
void Start(); void Start();
......
...@@ -22,8 +22,10 @@ namespace chromeos { ...@@ -22,8 +22,10 @@ namespace chromeos {
EasyUnlockGetKeysOperation::EasyUnlockGetKeysOperation( EasyUnlockGetKeysOperation::EasyUnlockGetKeysOperation(
const UserContext& user_context, const UserContext& user_context,
const GetKeysCallback& callback) GetKeysCallback callback)
: user_context_(user_context), callback_(callback), key_index_(0) {} : user_context_(user_context),
callback_(std::move(callback)),
key_index_(0) {}
EasyUnlockGetKeysOperation::~EasyUnlockGetKeysOperation() {} EasyUnlockGetKeysOperation::~EasyUnlockGetKeysOperation() {}
...@@ -37,7 +39,7 @@ void EasyUnlockGetKeysOperation::Start() { ...@@ -37,7 +39,7 @@ void EasyUnlockGetKeysOperation::Start() {
void EasyUnlockGetKeysOperation::OnCryptohomeAvailable(bool available) { void EasyUnlockGetKeysOperation::OnCryptohomeAvailable(bool available) {
if (!available) { if (!available) {
PA_LOG(ERROR) << "Failed to wait for cryptohome to become available"; PA_LOG(ERROR) << "Failed to wait for cryptohome to become available";
callback_.Run(false, EasyUnlockDeviceKeyDataList()); std::move(callback_).Run(false, EasyUnlockDeviceKeyDataList());
return; return;
} }
...@@ -81,12 +83,12 @@ void EasyUnlockGetKeysOperation::OnGetKeyData( ...@@ -81,12 +83,12 @@ void EasyUnlockGetKeysOperation::OnGetKeyData(
if (devices_.size() == 1) if (devices_.size() == 1)
devices_[0].unlock_key = true; devices_[0].unlock_key = true;
callback_.Run(true, devices_); std::move(callback_).Run(true, devices_);
return; return;
} }
PA_LOG(ERROR) << "Easy unlock failed to get key data, code=" << return_code; PA_LOG(ERROR) << "Easy unlock failed to get key data, code=" << return_code;
callback_.Run(false, EasyUnlockDeviceKeyDataList()); std::move(callback_).Run(false, EasyUnlockDeviceKeyDataList());
return; return;
} }
......
...@@ -21,11 +21,11 @@ namespace chromeos { ...@@ -21,11 +21,11 @@ namespace chromeos {
class EasyUnlockGetKeysOperation { class EasyUnlockGetKeysOperation {
public: public:
typedef base::Callback<void(bool success, using GetKeysCallback =
const EasyUnlockDeviceKeyDataList& data_list)> base::OnceCallback<void(bool success,
GetKeysCallback; const EasyUnlockDeviceKeyDataList& data_list)>;
EasyUnlockGetKeysOperation(const UserContext& user_context, EasyUnlockGetKeysOperation(const UserContext& user_context,
const GetKeysCallback& callback); GetKeysCallback callback);
~EasyUnlockGetKeysOperation(); ~EasyUnlockGetKeysOperation();
// Starts the operation. If the cryptohome service is not yet available, the // Starts the operation. If the cryptohome service is not yet available, the
......
...@@ -25,24 +25,26 @@ EasyUnlockKeyManager::~EasyUnlockKeyManager() {} ...@@ -25,24 +25,26 @@ EasyUnlockKeyManager::~EasyUnlockKeyManager() {}
void EasyUnlockKeyManager::RefreshKeys(const UserContext& user_context, void EasyUnlockKeyManager::RefreshKeys(const UserContext& user_context,
const base::ListValue& remote_devices, const base::ListValue& remote_devices,
const RefreshKeysCallback& callback) { RefreshKeysCallback callback) {
base::Closure do_refresh_keys =
base::Bind(&EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent,
weak_ptr_factory_.GetWeakPtr(), user_context,
base::Owned(remote_devices.DeepCopy()), callback);
EasyUnlockTpmKeyManager* tpm_key_manager = EasyUnlockTpmKeyManager* tpm_key_manager =
EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser( EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser(
user_context.GetAccountId().GetUserEmail()); user_context.GetAccountId().GetUserEmail());
if (!tpm_key_manager) { if (!tpm_key_manager) {
PA_LOG(ERROR) << "No TPM key manager."; PA_LOG(ERROR) << "No TPM key manager.";
callback.Run(false); std::move(callback).Run(false);
return; return;
} }
// This callback will only be executed once but must be marked repeating
// because it could be discarded by PrepareTpmKey() and invoked here instead.
auto do_refresh_keys = base::BindRepeating(
&EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent,
weak_ptr_factory_.GetWeakPtr(), user_context,
base::Owned(remote_devices.DeepCopy()), base::Passed(&callback));
// Private TPM key is needed only when adding new keys. // Private TPM key is needed only when adding new keys.
if (remote_devices.empty() || if (remote_devices.empty() ||
tpm_key_manager->PrepareTpmKey(false /* check_private_key */, tpm_key_manager->PrepareTpmKey(/*check_private_key=*/false,
do_refresh_keys)) { do_refresh_keys)) {
do_refresh_keys.Run(); do_refresh_keys.Run();
} else { } else {
...@@ -59,7 +61,7 @@ void EasyUnlockKeyManager::RefreshKeys(const UserContext& user_context, ...@@ -59,7 +61,7 @@ void EasyUnlockKeyManager::RefreshKeys(const UserContext& user_context,
void EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent( void EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent(
const UserContext& user_context, const UserContext& user_context,
base::ListValue* remote_devices, base::ListValue* remote_devices,
const RefreshKeysCallback& callback) { RefreshKeysCallback callback) {
EasyUnlockTpmKeyManager* tpm_key_manager = EasyUnlockTpmKeyManager* tpm_key_manager =
EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser( EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser(
user_context.GetAccountId().GetUserEmail()); user_context.GetAccountId().GetUserEmail());
...@@ -73,17 +75,18 @@ void EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent( ...@@ -73,17 +75,18 @@ void EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent(
write_operation_queue_.push_back( write_operation_queue_.push_back(
std::make_unique<EasyUnlockRefreshKeysOperation>( std::make_unique<EasyUnlockRefreshKeysOperation>(
user_context, tpm_public_key, devices, user_context, tpm_public_key, devices,
base::Bind(&EasyUnlockKeyManager::OnKeysRefreshed, base::BindOnce(&EasyUnlockKeyManager::OnKeysRefreshed,
weak_ptr_factory_.GetWeakPtr(), callback))); weak_ptr_factory_.GetWeakPtr(), std::move(callback))));
RunNextOperation(); RunNextOperation();
} }
void EasyUnlockKeyManager::GetDeviceDataList( void EasyUnlockKeyManager::GetDeviceDataList(
const UserContext& user_context, const UserContext& user_context,
const GetDeviceDataListCallback& callback) { GetDeviceDataListCallback callback) {
read_operation_queue_.push_back(std::make_unique<EasyUnlockGetKeysOperation>( read_operation_queue_.push_back(std::make_unique<EasyUnlockGetKeysOperation>(
user_context, base::Bind(&EasyUnlockKeyManager::OnKeysFetched, user_context,
weak_ptr_factory_.GetWeakPtr(), callback))); base::BindOnce(&EasyUnlockKeyManager::OnKeysFetched,
weak_ptr_factory_.GetWeakPtr(), std::move(callback))));
RunNextOperation(); RunNextOperation();
} }
...@@ -205,10 +208,10 @@ void EasyUnlockKeyManager::RunNextOperation() { ...@@ -205,10 +208,10 @@ void EasyUnlockKeyManager::RunNextOperation() {
} }
} }
void EasyUnlockKeyManager::OnKeysRefreshed(const RefreshKeysCallback& callback, void EasyUnlockKeyManager::OnKeysRefreshed(RefreshKeysCallback callback,
bool refresh_success) { bool refresh_success) {
if (!callback.is_null()) if (!callback.is_null())
callback.Run(refresh_success); std::move(callback).Run(refresh_success);
DCHECK(pending_write_operation_); DCHECK(pending_write_operation_);
pending_write_operation_.reset(); pending_write_operation_.reset();
...@@ -216,11 +219,11 @@ void EasyUnlockKeyManager::OnKeysRefreshed(const RefreshKeysCallback& callback, ...@@ -216,11 +219,11 @@ void EasyUnlockKeyManager::OnKeysRefreshed(const RefreshKeysCallback& callback,
} }
void EasyUnlockKeyManager::OnKeysFetched( void EasyUnlockKeyManager::OnKeysFetched(
const GetDeviceDataListCallback& callback, GetDeviceDataListCallback callback,
bool fetch_success, bool fetch_success,
const EasyUnlockDeviceKeyDataList& fetched_data) { const EasyUnlockDeviceKeyDataList& fetched_data) {
if (!callback.is_null()) if (!callback.is_null())
callback.Run(fetch_success, fetched_data); std::move(callback).Run(fetch_success, fetched_data);
DCHECK(pending_read_operation_); DCHECK(pending_read_operation_);
pending_read_operation_.reset(); pending_read_operation_.reset();
......
...@@ -33,9 +33,9 @@ class UserContext; ...@@ -33,9 +33,9 @@ class UserContext;
// A class to manage Easy unlock cryptohome keys. // A class to manage Easy unlock cryptohome keys.
class EasyUnlockKeyManager { class EasyUnlockKeyManager {
public: public:
typedef EasyUnlockRefreshKeysOperation::RefreshKeysCallback using RefreshKeysCallback =
RefreshKeysCallback; EasyUnlockRefreshKeysOperation::RefreshKeysCallback;
typedef EasyUnlockGetKeysOperation::GetKeysCallback GetDeviceDataListCallback; using GetDeviceDataListCallback = EasyUnlockGetKeysOperation::GetKeysCallback;
EasyUnlockKeyManager(); EasyUnlockKeyManager();
~EasyUnlockKeyManager(); ~EasyUnlockKeyManager();
...@@ -45,12 +45,12 @@ class EasyUnlockKeyManager { ...@@ -45,12 +45,12 @@ class EasyUnlockKeyManager {
// secret to allow keys to be created. // secret to allow keys to be created.
void RefreshKeys(const UserContext& user_context, void RefreshKeys(const UserContext& user_context,
const base::ListValue& remote_devices, const base::ListValue& remote_devices,
const RefreshKeysCallback& callback); RefreshKeysCallback callback);
// Retrieves the remote device data from cryptohome keys for the given // Retrieves the remote device data from cryptohome keys for the given
// `user_context`. // `user_context`.
void GetDeviceDataList(const UserContext& user_context, void GetDeviceDataList(const UserContext& user_context,
const GetDeviceDataListCallback& callback); GetDeviceDataListCallback callback);
// Helpers to convert between DeviceData and remote device dictionary. // Helpers to convert between DeviceData and remote device dictionary.
// DeviceDataToRemoteDeviceDictionary fills the remote device dictionary and // DeviceDataToRemoteDeviceDictionary fills the remote device dictionary and
...@@ -88,14 +88,13 @@ class EasyUnlockKeyManager { ...@@ -88,14 +88,13 @@ class EasyUnlockKeyManager {
// challenges. // challenges.
void RefreshKeysWithTpmKeyPresent(const UserContext& user_context, void RefreshKeysWithTpmKeyPresent(const UserContext& user_context,
base::ListValue* remote_devices, base::ListValue* remote_devices,
const RefreshKeysCallback& callback); RefreshKeysCallback callback);
// Callback invoked after refresh keys operation. // Callback invoked after refresh keys operation.
void OnKeysRefreshed(const RefreshKeysCallback& callback, void OnKeysRefreshed(RefreshKeysCallback callback, bool create_success);
bool create_success);
// Callback invoked after get keys op. // Callback invoked after get keys op.
void OnKeysFetched(const GetDeviceDataListCallback& callback, void OnKeysFetched(GetDeviceDataListCallback callback,
bool fetch_success, bool fetch_success,
const EasyUnlockDeviceKeyDataList& fetched_data); const EasyUnlockDeviceKeyDataList& fetched_data);
......
...@@ -13,11 +13,11 @@ EasyUnlockRefreshKeysOperation::EasyUnlockRefreshKeysOperation( ...@@ -13,11 +13,11 @@ EasyUnlockRefreshKeysOperation::EasyUnlockRefreshKeysOperation(
const UserContext& user_context, const UserContext& user_context,
const std::string& tpm_public_key, const std::string& tpm_public_key,
const EasyUnlockDeviceKeyDataList& devices, const EasyUnlockDeviceKeyDataList& devices,
const RefreshKeysCallback& callback) RefreshKeysCallback callback)
: user_context_(user_context), : user_context_(user_context),
tpm_public_key_(tpm_public_key), tpm_public_key_(tpm_public_key),
devices_(devices), devices_(devices),
callback_(callback) {} callback_(std::move(callback)) {}
EasyUnlockRefreshKeysOperation::~EasyUnlockRefreshKeysOperation() {} EasyUnlockRefreshKeysOperation::~EasyUnlockRefreshKeysOperation() {}
...@@ -30,14 +30,14 @@ void EasyUnlockRefreshKeysOperation::Start() { ...@@ -30,14 +30,14 @@ void EasyUnlockRefreshKeysOperation::Start() {
create_keys_operation_.reset(new EasyUnlockCreateKeysOperation( create_keys_operation_.reset(new EasyUnlockCreateKeysOperation(
user_context_, tpm_public_key_, devices_, user_context_, tpm_public_key_, devices_,
base::Bind(&EasyUnlockRefreshKeysOperation::OnKeysCreated, base::BindOnce(&EasyUnlockRefreshKeysOperation::OnKeysCreated,
weak_ptr_factory_.GetWeakPtr()))); weak_ptr_factory_.GetWeakPtr())));
create_keys_operation_->Start(); create_keys_operation_->Start();
} }
void EasyUnlockRefreshKeysOperation::OnKeysCreated(bool success) { void EasyUnlockRefreshKeysOperation::OnKeysCreated(bool success) {
if (!success) { if (!success) {
callback_.Run(false); std::move(callback_).Run(false);
return; return;
} }
...@@ -56,13 +56,13 @@ void EasyUnlockRefreshKeysOperation::RemoveKeysStartingFromIndex( ...@@ -56,13 +56,13 @@ void EasyUnlockRefreshKeysOperation::RemoveKeysStartingFromIndex(
size_t key_index) { size_t key_index) {
remove_keys_operation_.reset(new EasyUnlockRemoveKeysOperation( remove_keys_operation_.reset(new EasyUnlockRemoveKeysOperation(
user_context_, key_index, user_context_, key_index,
base::Bind(&EasyUnlockRefreshKeysOperation::OnKeysRemoved, base::BindOnce(&EasyUnlockRefreshKeysOperation::OnKeysRemoved,
weak_ptr_factory_.GetWeakPtr()))); weak_ptr_factory_.GetWeakPtr())));
remove_keys_operation_->Start(); remove_keys_operation_->Start();
} }
void EasyUnlockRefreshKeysOperation::OnKeysRemoved(bool success) { void EasyUnlockRefreshKeysOperation::OnKeysRemoved(bool success) {
callback_.Run(success); std::move(callback_).Run(success);
} }
} // namespace chromeos } // namespace chromeos
...@@ -24,11 +24,11 @@ class UserContext; ...@@ -24,11 +24,11 @@ class UserContext;
// remove keys operations. // remove keys operations.
class EasyUnlockRefreshKeysOperation { class EasyUnlockRefreshKeysOperation {
public: public:
typedef base::Callback<void(bool success)> RefreshKeysCallback; using RefreshKeysCallback = base::OnceCallback<void(bool success)>;
EasyUnlockRefreshKeysOperation(const UserContext& user_context, EasyUnlockRefreshKeysOperation(const UserContext& user_context,
const std::string& tpm_public_key, const std::string& tpm_public_key,
const EasyUnlockDeviceKeyDataList& devices, const EasyUnlockDeviceKeyDataList& devices,
const RefreshKeysCallback& callback); RefreshKeysCallback callback);
~EasyUnlockRefreshKeysOperation(); ~EasyUnlockRefreshKeysOperation();
void Start(); void Start();
......
...@@ -17,9 +17,9 @@ namespace chromeos { ...@@ -17,9 +17,9 @@ namespace chromeos {
EasyUnlockRemoveKeysOperation::EasyUnlockRemoveKeysOperation( EasyUnlockRemoveKeysOperation::EasyUnlockRemoveKeysOperation(
const UserContext& user_context, const UserContext& user_context,
size_t start_index, size_t start_index,
const RemoveKeysCallback& callback) RemoveKeysCallback callback)
: user_context_(user_context), : user_context_(user_context),
callback_(callback), callback_(std::move(callback)),
key_index_(start_index) { key_index_(start_index) {
// Must have the secret and callback. // Must have the secret and callback.
DCHECK(!user_context_.GetKey()->GetSecret().empty()); DCHECK(!user_context_.GetKey()->GetSecret().empty());
...@@ -74,11 +74,11 @@ void EasyUnlockRemoveKeysOperation::OnKeyRemoved( ...@@ -74,11 +74,11 @@ void EasyUnlockRemoveKeysOperation::OnKeyRemoved(
// MOUNT_ERROR_KEY_FAILURE is considered as success. Other error codes are // MOUNT_ERROR_KEY_FAILURE is considered as success. Other error codes are
// treated as failures. // treated as failures.
if (return_code == cryptohome::MOUNT_ERROR_KEY_FAILURE) { if (return_code == cryptohome::MOUNT_ERROR_KEY_FAILURE) {
callback_.Run(true); std::move(callback_).Run(true);
} else { } else {
LOG(ERROR) << "Easy unlock remove keys operation failed, code=" LOG(ERROR) << "Easy unlock remove keys operation failed, code="
<< return_code; << return_code;
callback_.Run(false); std::move(callback_).Run(false);
} }
} }
......
...@@ -21,10 +21,10 @@ class UserContext; ...@@ -21,10 +21,10 @@ class UserContext;
// index. // index.
class EasyUnlockRemoveKeysOperation { class EasyUnlockRemoveKeysOperation {
public: public:
typedef base::Callback<void(bool success)> RemoveKeysCallback; using RemoveKeysCallback = base::OnceCallback<void(bool success)>;
EasyUnlockRemoveKeysOperation(const UserContext& user_context, EasyUnlockRemoveKeysOperation(const UserContext& user_context,
size_t start_index, size_t start_index,
const RemoveKeysCallback& callback); RemoveKeysCallback callback);
~EasyUnlockRemoveKeysOperation(); ~EasyUnlockRemoveKeysOperation();
void Start(); void Start();
......
...@@ -397,8 +397,9 @@ void EasyUnlockService::CheckCryptohomeKeysAndMaybeHardlock() { ...@@ -397,8 +397,9 @@ void EasyUnlockService::CheckCryptohomeKeysAndMaybeHardlock() {
DCHECK(user); DCHECK(user);
key_manager->GetDeviceDataList( key_manager->GetDeviceDataList(
UserContext(*user), UserContext(*user),
base::Bind(&EasyUnlockService::OnCryptohomeKeysFetchedForChecking, base::BindOnce(&EasyUnlockService::OnCryptohomeKeysFetchedForChecking,
weak_ptr_factory_.GetWeakPtr(), account_id, paired_devices)); weak_ptr_factory_.GetWeakPtr(), account_id,
paired_devices));
} }
void EasyUnlockService::Shutdown() { void EasyUnlockService::Shutdown() {
...@@ -685,7 +686,7 @@ void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() { ...@@ -685,7 +686,7 @@ void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() {
// TODO(tbarzic): Set check_private_key only if previous sign-in attempt // TODO(tbarzic): Set check_private_key only if previous sign-in attempt
// failed. // failed.
EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_)->PrepareTpmKey( EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_)->PrepareTpmKey(
true /* check_private_key */, base::Closure()); /*check_private_key=*/true, base::OnceClosure());
tpm_key_checked_ = true; tpm_key_checked_ = true;
} }
......
...@@ -326,7 +326,8 @@ void EasyUnlockServiceRegular::InitializeInternal() { ...@@ -326,7 +326,8 @@ void EasyUnlockServiceRegular::InitializeInternal() {
registrar_.Init(profile()->GetPrefs()); registrar_.Init(profile()->GetPrefs());
registrar_.Add( registrar_.Add(
proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled, proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled,
base::Bind(&EasyUnlockServiceRegular::CheckCryptohomeKeysAndMaybeHardlock, base::BindRepeating(
&EasyUnlockServiceRegular::CheckCryptohomeKeysAndMaybeHardlock,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
// If `device_sync_client_` is not ready yet, wait for it to call back on // If `device_sync_client_` is not ready yet, wait for it to call back on
......
...@@ -56,10 +56,9 @@ uint32_t GetNextBackoffInterval(uint32_t backoff) { ...@@ -56,10 +56,9 @@ uint32_t GetNextBackoffInterval(uint32_t backoff) {
return backoff * 2; return backoff * 2;
} }
void LoadDataForUser( void LoadDataForUser(const AccountId& account_id,
const AccountId& account_id,
uint32_t backoff_ms, uint32_t backoff_ms,
const EasyUnlockKeyManager::GetDeviceDataListCallback& callback); EasyUnlockKeyManager::GetDeviceDataListCallback callback);
// Callback passed to `LoadDataForUser()`. // Callback passed to `LoadDataForUser()`.
// If `LoadDataForUser` function succeeded, it invokes `callback` with the // If `LoadDataForUser` function succeeded, it invokes `callback` with the
...@@ -70,31 +69,31 @@ void LoadDataForUser( ...@@ -70,31 +69,31 @@ void LoadDataForUser(
void RetryDataLoadOnError( void RetryDataLoadOnError(
const AccountId& account_id, const AccountId& account_id,
uint32_t backoff_ms, uint32_t backoff_ms,
const EasyUnlockKeyManager::GetDeviceDataListCallback& callback, EasyUnlockKeyManager::GetDeviceDataListCallback callback,
bool success, bool success,
const EasyUnlockDeviceKeyDataList& data_list) { const EasyUnlockDeviceKeyDataList& data_list) {
if (success) { if (success) {
callback.Run(success, data_list); std::move(callback).Run(success, data_list);
return; return;
} }
uint32_t next_backoff_ms = GetNextBackoffInterval(backoff_ms); uint32_t next_backoff_ms = GetNextBackoffInterval(backoff_ms);
if (next_backoff_ms > kMaxCryptohomeBackoffIntervalMs) { if (next_backoff_ms > kMaxCryptohomeBackoffIntervalMs) {
callback.Run(false, data_list); std::move(callback).Run(false, data_list);
return; return;
} }
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&LoadDataForUser, account_id, next_backoff_ms, callback), base::BindOnce(&LoadDataForUser, account_id, next_backoff_ms,
std::move(callback)),
base::TimeDelta::FromMilliseconds(next_backoff_ms)); base::TimeDelta::FromMilliseconds(next_backoff_ms));
} }
// Loads device data list associated with the user's Easy unlock keys. // Loads device data list associated with the user's Easy unlock keys.
void LoadDataForUser( void LoadDataForUser(const AccountId& account_id,
const AccountId& account_id,
uint32_t backoff_ms, uint32_t backoff_ms,
const EasyUnlockKeyManager::GetDeviceDataListCallback& callback) { EasyUnlockKeyManager::GetDeviceDataListCallback callback) {
EasyUnlockKeyManager* key_manager = EasyUnlockKeyManager* key_manager =
UserSessionManager::GetInstance()->GetEasyUnlockKeyManager(); UserSessionManager::GetInstance()->GetEasyUnlockKeyManager();
DCHECK(key_manager); DCHECK(key_manager);
...@@ -103,8 +102,8 @@ void LoadDataForUser( ...@@ -103,8 +102,8 @@ void LoadDataForUser(
user_manager::UserManager::Get()->FindUser(account_id); user_manager::UserManager::Get()->FindUser(account_id);
DCHECK(user); DCHECK(user);
key_manager->GetDeviceDataList( key_manager->GetDeviceDataList(
UserContext(*user), UserContext(*user), base::BindOnce(&RetryDataLoadOnError, account_id,
base::Bind(&RetryDataLoadOnError, account_id, backoff_ms, callback)); backoff_ms, std::move(callback)));
} }
// Deserializes a vector of BeaconSeeds. If an error occurs, an empty vector // Deserializes a vector of BeaconSeeds. If an error occurs, an empty vector
...@@ -183,11 +182,11 @@ void EasyUnlockServiceSignin::WrapChallengeForUserAndDevice( ...@@ -183,11 +182,11 @@ void EasyUnlockServiceSignin::WrapChallengeForUserAndDevice(
const AccountId& account_id, const AccountId& account_id,
const std::string& device_public_key, const std::string& device_public_key,
const std::string& channel_binding_data, const std::string& channel_binding_data,
base::Callback<void(const std::string& wraped_challenge)> callback) { base::OnceCallback<void(const std::string& wraped_challenge)> callback) {
auto it = user_data_.find(account_id); auto it = user_data_.find(account_id);
if (it == user_data_.end() || it->second->state != USER_DATA_STATE_LOADED) { if (it == user_data_.end() || it->second->state != USER_DATA_STATE_LOADED) {
PA_LOG(ERROR) << "TPM data not loaded for " << account_id.Serialize(); PA_LOG(ERROR) << "TPM data not loaded for " << account_id.Serialize();
callback.Run(std::string()); std::move(callback).Run(std::string());
return; return;
} }
...@@ -202,14 +201,14 @@ void EasyUnlockServiceSignin::WrapChallengeForUserAndDevice( ...@@ -202,14 +201,14 @@ void EasyUnlockServiceSignin::WrapChallengeForUserAndDevice(
challenge_wrapper_.reset(new EasyUnlockChallengeWrapper( challenge_wrapper_.reset(new EasyUnlockChallengeWrapper(
device_data.challenge, channel_binding_data, account_id, device_data.challenge, channel_binding_data, account_id,
EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile()))); EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile())));
challenge_wrapper_->WrapChallenge(callback); challenge_wrapper_->WrapChallenge(std::move(callback));
return; return;
} }
} }
PA_LOG(ERROR) << "Unable to find device record for " PA_LOG(ERROR) << "Unable to find device record for "
<< account_id.Serialize(); << account_id.Serialize();
callback.Run(std::string()); std::move(callback).Run(std::string());
} }
proximity_auth::ProximityAuthPrefManager* proximity_auth::ProximityAuthPrefManager*
...@@ -437,7 +436,7 @@ void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() { ...@@ -437,7 +436,7 @@ void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() {
LoadDataForUser( LoadDataForUser(
account_id_, account_id_,
allow_cryptohome_backoff_ ? 0u : kMaxCryptohomeBackoffIntervalMs, allow_cryptohome_backoff_ ? 0u : kMaxCryptohomeBackoffIntervalMs,
base::Bind(&EasyUnlockServiceSignin::OnUserDataLoaded, base::BindOnce(&EasyUnlockServiceSignin::OnUserDataLoaded,
weak_ptr_factory_.GetWeakPtr(), account_id_)); weak_ptr_factory_.GetWeakPtr(), account_id_));
} }
......
...@@ -53,7 +53,7 @@ class EasyUnlockServiceSignin ...@@ -53,7 +53,7 @@ class EasyUnlockServiceSignin
const AccountId& account_id, const AccountId& account_id,
const std::string& device_public_key, const std::string& device_public_key,
const std::string& channel_binding_data, const std::string& channel_binding_data,
base::Callback<void(const std::string& wraped_challenge)> callback); base::OnceCallback<void(const std::string& wraped_challenge)> callback);
private: private:
// The load state of a user's cryptohome key data. // The load state of a user's cryptohome key data.
......
...@@ -58,7 +58,7 @@ class EasyUnlockTpmKeyManager : public KeyedService { ...@@ -58,7 +58,7 @@ class EasyUnlockTpmKeyManager : public KeyedService {
// signin does not remain permanently broken if something goes wrong. // signin does not remain permanently broken if something goes wrong.
// `callback`: If the method cannot return immediately, called when the key // `callback`: If the method cannot return immediately, called when the key
// pair presence is confirmed (or a key pair for the user is created). // pair presence is confirmed (or a key pair for the user is created).
bool PrepareTpmKey(bool check_private_key, const base::Closure& callback); bool PrepareTpmKey(bool check_private_key, base::OnceClosure callback);
// If called, posts a delayed task that cancels `PrepareTpmKey` and all other // If called, posts a delayed task that cancels `PrepareTpmKey` and all other
// started timeouts in case getting system slot takes more than `timeout_ms`. // started timeouts in case getting system slot takes more than `timeout_ms`.
...@@ -75,7 +75,7 @@ class EasyUnlockTpmKeyManager : public KeyedService { ...@@ -75,7 +75,7 @@ class EasyUnlockTpmKeyManager : public KeyedService {
void SignUsingTpmKey( void SignUsingTpmKey(
const AccountId& account_id, const AccountId& account_id,
const std::string& data, const std::string& data,
const base::Callback<void(const std::string& data)> callback); base::OnceCallback<void(const std::string& data)> callback);
bool StartedCreatingTpmKeys() const; bool StartedCreatingTpmKeys() const;
...@@ -117,7 +117,7 @@ class EasyUnlockTpmKeyManager : public KeyedService { ...@@ -117,7 +117,7 @@ class EasyUnlockTpmKeyManager : public KeyedService {
void SignDataWithSystemSlot( void SignDataWithSystemSlot(
const std::string& public_key, const std::string& public_key,
const std::string& data, const std::string& data,
const base::Callback<void(const std::string& data)> callback, base::OnceCallback<void(const std::string& data)> callback,
crypto::ScopedPK11Slot system_slot); crypto::ScopedPK11Slot system_slot);
// Called when a RSA key pair is created for a user in TPM system slot. // Called when a RSA key pair is created for a user in TPM system slot.
...@@ -128,7 +128,7 @@ class EasyUnlockTpmKeyManager : public KeyedService { ...@@ -128,7 +128,7 @@ class EasyUnlockTpmKeyManager : public KeyedService {
// Called when data signing requested in `SignUsingTpmKey` is done. // Called when data signing requested in `SignUsingTpmKey` is done.
// It runs `callback` with the created `signature`. On error the callback will // It runs `callback` with the created `signature`. On error the callback will
// be run with an empty string. // be run with an empty string.
void OnDataSigned(const base::Callback<void(const std::string&)>& callback, void OnDataSigned(base::OnceCallback<void(const std::string&)> callback,
const std::string& signature); const std::string& signature);
const AccountId account_id_; const AccountId account_id_;
...@@ -142,7 +142,7 @@ class EasyUnlockTpmKeyManager : public KeyedService { ...@@ -142,7 +142,7 @@ class EasyUnlockTpmKeyManager : public KeyedService {
CreateTpmKeyState create_tpm_key_state_; CreateTpmKeyState create_tpm_key_state_;
// Queued up `PrepareTpmKey` callbacks. // Queued up `PrepareTpmKey` callbacks.
std::vector<base::Closure> prepare_tpm_key_callbacks_; std::vector<base::OnceClosure> prepare_tpm_key_callbacks_;
base::WeakPtrFactory<EasyUnlockTpmKeyManager> get_tpm_slot_weak_ptr_factory_{ base::WeakPtrFactory<EasyUnlockTpmKeyManager> get_tpm_slot_weak_ptr_factory_{
this}; this};
......
...@@ -188,10 +188,10 @@ void IncreaseCount(int* count) { ...@@ -188,10 +188,10 @@ void IncreaseCount(int* count) {
// Sets `*result` to `value` and runs `callback`. // Sets `*result` to `value` and runs `callback`.
// Used as a callback to EasyUnlockTpmKeyManager::SignUsingTpmKey in tests. // Used as a callback to EasyUnlockTpmKeyManager::SignUsingTpmKey in tests.
void RecordStringAndRunClosure(std::string* result, void RecordStringAndRunClosure(std::string* result,
const base::Closure& callback, base::OnceClosure callback,
const std::string& value) { const std::string& value) {
*result = value; *result = value;
callback.Run(); std::move(callback).Run();
} }
class EasyUnlockTpmKeyManagerTest : public testing::Test { class EasyUnlockTpmKeyManagerTest : public testing::Test {
...@@ -380,7 +380,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPair) { ...@@ -380,7 +380,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPair) {
signin_key_manager()->GetPublicTpmKey(test_account_id_)); signin_key_manager()->GetPublicTpmKey(test_account_id_));
EXPECT_TRUE(user_key_manager()->PrepareTpmKey( EXPECT_TRUE(user_key_manager()->PrepareTpmKey(
false /* check_private_key */, base::Bind(&ExpectNotCalledCallback))); /*check_private_key=*/false, base::BindOnce(&ExpectNotCalledCallback)));
} }
TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPairMultipleCallbacks) { TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPairMultipleCallbacks) {
...@@ -392,14 +392,14 @@ TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPairMultipleCallbacks) { ...@@ -392,14 +392,14 @@ TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPairMultipleCallbacks) {
ASSERT_FALSE(user_key_manager()->PrepareTpmKey(false /* check_private_key */, ASSERT_FALSE(user_key_manager()->PrepareTpmKey(false /* check_private_key */,
run_loop.QuitClosure())); run_loop.QuitClosure()));
EXPECT_FALSE(user_key_manager()->PrepareTpmKey( EXPECT_FALSE(user_key_manager()->PrepareTpmKey(
false /* check_private_key */, /*check_private_key=*/false,
base::Bind(&IncreaseCount, &callback_count))); base::BindOnce(&IncreaseCount, &callback_count)));
EXPECT_FALSE(user_key_manager()->PrepareTpmKey( EXPECT_FALSE(user_key_manager()->PrepareTpmKey(
false /* check_private_key */, /*check_private_key=*/false,
base::Bind(&IncreaseCount, &callback_count))); base::BindOnce(&IncreaseCount, &callback_count)));
// Verify that the method works with empty callback. // Verify that the method works with empty callback.
EXPECT_FALSE(user_key_manager()->PrepareTpmKey(false /* check_private_key */, EXPECT_FALSE(user_key_manager()->PrepareTpmKey(/*check_private_key=*/false,
base::Closure())); base::OnceClosure()));
ASSERT_TRUE(SetUpTestSystemSlot()); ASSERT_TRUE(SetUpTestSystemSlot());
VerifyKeyGenerationNotStartedAndFinalizeTestNssUser(); VerifyKeyGenerationNotStartedAndFinalizeTestNssUser();
...@@ -413,7 +413,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPairMultipleCallbacks) { ...@@ -413,7 +413,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPairMultipleCallbacks) {
signin_key_manager()->GetPublicTpmKey(test_account_id_)); signin_key_manager()->GetPublicTpmKey(test_account_id_));
EXPECT_TRUE(user_key_manager()->PrepareTpmKey( EXPECT_TRUE(user_key_manager()->PrepareTpmKey(
false /* check_private_key */, base::Bind(&ExpectNotCalledCallback))); /*check_private_key=*/false, base::BindOnce(&ExpectNotCalledCallback)));
} }
TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefs) { TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefs) {
...@@ -422,7 +422,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefs) { ...@@ -422,7 +422,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefs) {
std::string(kTestPublicKey, base::size(kTestPublicKey))); std::string(kTestPublicKey, base::size(kTestPublicKey)));
EXPECT_TRUE(user_key_manager()->PrepareTpmKey( EXPECT_TRUE(user_key_manager()->PrepareTpmKey(
false /* check_private_key */, base::Bind(&ExpectNotCalledCallback))); /*check_private_key=*/false, base::BindOnce(&ExpectNotCalledCallback)));
EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty()); EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty());
EXPECT_EQ(user_key_manager()->GetPublicTpmKey(test_account_id_), EXPECT_EQ(user_key_manager()->GetPublicTpmKey(test_account_id_),
...@@ -468,8 +468,8 @@ TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefsCheckPrivateKey_OK) { ...@@ -468,8 +468,8 @@ TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefsCheckPrivateKey_OK) {
run_loop.QuitClosure())); run_loop.QuitClosure()));
EXPECT_FALSE(user_key_manager()->PrepareTpmKey( EXPECT_FALSE(user_key_manager()->PrepareTpmKey(
false /* check_private_key */, /*check_private_key=*/false,
base::Bind(&IncreaseCount, &callback_count))); base::BindOnce(&IncreaseCount, &callback_count)));
run_loop.Run(); run_loop.Run();
...@@ -481,7 +481,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefsCheckPrivateKey_OK) { ...@@ -481,7 +481,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefsCheckPrivateKey_OK) {
signin_key_manager()->GetPublicTpmKey(test_account_id_)); signin_key_manager()->GetPublicTpmKey(test_account_id_));
EXPECT_TRUE(user_key_manager()->PrepareTpmKey( EXPECT_TRUE(user_key_manager()->PrepareTpmKey(
true /* check_private_key */, base::Bind(&ExpectNotCalledCallback))); /*check_private_key=*/true, base::BindOnce(&ExpectNotCalledCallback)));
} }
TEST_F(EasyUnlockTpmKeyManagerTest, GetSystemSlotTimeoutTriggers) { TEST_F(EasyUnlockTpmKeyManagerTest, GetSystemSlotTimeoutTriggers) {
...@@ -559,7 +559,8 @@ TEST_F(EasyUnlockTpmKeyManagerTest, SignData) { ...@@ -559,7 +559,8 @@ TEST_F(EasyUnlockTpmKeyManagerTest, SignData) {
std::string signed_data; std::string signed_data;
signin_key_manager()->SignUsingTpmKey( signin_key_manager()->SignUsingTpmKey(
test_account_id_, "data", test_account_id_, "data",
base::Bind(&RecordStringAndRunClosure, &signed_data, loop.QuitClosure())); base::BindOnce(&RecordStringAndRunClosure, &signed_data,
loop.QuitClosure()));
loop.Run(); loop.Run();
EXPECT_FALSE(signed_data.empty()); EXPECT_FALSE(signed_data.empty());
...@@ -570,7 +571,8 @@ TEST_F(EasyUnlockTpmKeyManagerTest, SignNoPublicKeySet) { ...@@ -570,7 +571,8 @@ TEST_F(EasyUnlockTpmKeyManagerTest, SignNoPublicKeySet) {
std::string signed_data; std::string signed_data;
signin_key_manager()->SignUsingTpmKey( signin_key_manager()->SignUsingTpmKey(
test_account_id_, "data", test_account_id_, "data",
base::Bind(&RecordStringAndRunClosure, &signed_data, loop.QuitClosure())); base::BindOnce(&RecordStringAndRunClosure, &signed_data,
loop.QuitClosure()));
loop.Run(); loop.Run();
EXPECT_TRUE(signed_data.empty()); EXPECT_TRUE(signed_data.empty());
...@@ -585,7 +587,8 @@ TEST_F(EasyUnlockTpmKeyManagerTest, SignDataNoPrivateKeyPresent) { ...@@ -585,7 +587,8 @@ TEST_F(EasyUnlockTpmKeyManagerTest, SignDataNoPrivateKeyPresent) {
std::string signed_data; std::string signed_data;
signin_key_manager()->SignUsingTpmKey( signin_key_manager()->SignUsingTpmKey(
test_account_id_, "data", test_account_id_, "data",
base::Bind(&RecordStringAndRunClosure, &signed_data, loop.QuitClosure())); base::BindOnce(&RecordStringAndRunClosure, &signed_data,
loop.QuitClosure()));
ASSERT_TRUE(SetUpTestSystemSlot()); ASSERT_TRUE(SetUpTestSystemSlot());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment