Commit 732b45e0 authored by Maajid's avatar Maajid Committed by Commit Bot

Make AddKeyEx pass-through.

AddKeyEx now takes AuthorizationRequest and AddKeyRequest directly.

Bug: 741274
Change-Id: I200b7bd8255010b51376d15bcff3e190b651fb13
Reviewed-on: https://chromium-review.googlesource.com/776518
Commit-Queue: Maajid <maajid@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517762}
parent 1e2e99ef
...@@ -338,17 +338,18 @@ void EasyUnlockCreateKeysOperation::OnGetSystemSalt( ...@@ -338,17 +338,18 @@ void EasyUnlockCreateKeysOperation::OnGetSystemSalt(
kEasyUnlockKeyMetaNameSerializedBeaconSeeds, kEasyUnlockKeyMetaNameSerializedBeaconSeeds,
device->serialized_beacon_seeds)); device->serialized_beacon_seeds));
// Add cryptohome key.
const cryptohome::Identification id(user_context_.GetAccountId());
std::unique_ptr<Key> auth_key(new Key(*user_context_.GetKey())); std::unique_ptr<Key> auth_key(new Key(*user_context_.GetKey()));
if (auth_key->GetKeyType() == Key::KEY_TYPE_PASSWORD_PLAIN) if (auth_key->GetKeyType() == Key::KEY_TYPE_PASSWORD_PLAIN)
auth_key->Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, system_salt); auth_key->Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, system_salt);
cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); cryptohome::AddKeyRequest request;
KeyDefinitionToKey(key_def, request.mutable_key());
request.set_clobber_if_exists(true);
cryptohome::HomedirMethods::GetInstance()->AddKeyEx( cryptohome::HomedirMethods::GetInstance()->AddKeyEx(
id, auth, key_def, cryptohome::Identification(user_context_.GetAccountId()),
true, // clobber cryptohome::CreateAuthorizationRequest(auth_key->GetLabel(),
auth_key->GetSecret()),
request,
base::Bind(&EasyUnlockCreateKeysOperation::OnKeyCreated, base::Bind(&EasyUnlockCreateKeysOperation::OnKeyCreated,
weak_ptr_factory_.GetWeakPtr(), index, user_key)); weak_ptr_factory_.GetWeakPtr(), index, user_key));
} }
......
...@@ -203,7 +203,7 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest, ...@@ -203,7 +203,7 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest,
mock_homedir_methods_->set_mount_callback(mount_wait_loop.QuitClosure()); mock_homedir_methods_->set_mount_callback(mount_wait_loop.QuitClosure());
mock_homedir_methods_->set_add_key_callback(add_key_wait_loop.QuitClosure()); mock_homedir_methods_->set_add_key_callback(add_key_wait_loop.QuitClosure());
EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1); EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1);
EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1); EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _)).Times(1);
JSEval("$('supervised-user-creation-next-button').click()"); JSEval("$('supervised-user-creation-next-button').click()");
......
...@@ -134,7 +134,7 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest, ...@@ -134,7 +134,7 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
SigninAsManager(1); SigninAsManager(1);
EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1); EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _)).Times(1);
std::string sync_id = std::string sync_id =
ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId( ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId(
...@@ -223,7 +223,7 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest, ...@@ -223,7 +223,7 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
SigninAsManager(1); SigninAsManager(1);
EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1); EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _)).Times(1);
std::string sync_id = std::string sync_id =
ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId( ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId(
......
...@@ -389,7 +389,7 @@ void SupervisedUserTestBase::StartUserCreation( ...@@ -389,7 +389,7 @@ void SupervisedUserTestBase::StartUserCreation(
mock_homedir_methods_->set_mount_callback(mount_wait_loop.QuitClosure()); mock_homedir_methods_->set_mount_callback(mount_wait_loop.QuitClosure());
mock_homedir_methods_->set_add_key_callback(add_key_wait_loop.QuitClosure()); mock_homedir_methods_->set_add_key_callback(add_key_wait_loop.QuitClosure());
EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1); EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1);
EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1); EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _)).Times(1);
JSEval(std::string("$('").append(button_id).append("').click()")); JSEval(std::string("$('").append(button_id).append("').click()"));
......
...@@ -129,16 +129,11 @@ class HomedirMethodsImpl : public HomedirMethods { ...@@ -129,16 +129,11 @@ class HomedirMethodsImpl : public HomedirMethods {
} }
void AddKeyEx(const Identification& id, void AddKeyEx(const Identification& id,
const Authorization& auth, const AuthorizationRequest& auth,
const KeyDefinition& new_key, const AddKeyRequest& request,
bool clobber_if_exists,
const Callback& callback) override { const Callback& callback) override {
cryptohome::AddKeyRequest request;
KeyDefinitionToKey(new_key, request.mutable_key());
request.set_clobber_if_exists(clobber_if_exists);
DBusThreadManager::Get()->GetCryptohomeClient()->AddKeyEx( DBusThreadManager::Get()->GetCryptohomeClient()->AddKeyEx(
id, CreateAuthorizationRequest(auth.label, auth.key), request, id, auth, request,
base::BindOnce(&HomedirMethodsImpl::OnBaseReplyCallback, base::BindOnce(&HomedirMethodsImpl::OnBaseReplyCallback,
weak_ptr_factory_.GetWeakPtr(), callback)); weak_ptr_factory_.GetWeakPtr(), callback));
} }
...@@ -427,6 +422,7 @@ cryptohome::AuthorizationRequest CreateAuthorizationRequest( ...@@ -427,6 +422,7 @@ cryptohome::AuthorizationRequest CreateAuthorizationRequest(
Key* key = auth_request.mutable_key(); Key* key = auth_request.mutable_key();
if (!label.empty()) if (!label.empty())
key->mutable_data()->set_label(label); key->mutable_data()->set_label(label);
key->set_secret(secret); key->set_secret(secret);
return auth_request; return auth_request;
} }
......
...@@ -25,7 +25,7 @@ void CHROMEOS_EXPORT KeyDefinitionToKey(const KeyDefinition& key_def, Key* key); ...@@ -25,7 +25,7 @@ void CHROMEOS_EXPORT KeyDefinitionToKey(const KeyDefinition& key_def, Key* key);
// Creates an AuthorizationRequest from the given secret and label. // Creates an AuthorizationRequest from the given secret and label.
AuthorizationRequest CHROMEOS_EXPORT AuthorizationRequest CHROMEOS_EXPORT
CreateAuthorizationRequest(const std::string& secret, const std::string& label); CreateAuthorizationRequest(const std::string& label, const std::string& secret);
// This class manages calls to Cryptohome service's home directory methods: // This class manages calls to Cryptohome service's home directory methods:
// Mount, CheckKey, Add/UpdateKey. // Mount, CheckKey, Add/UpdateKey.
...@@ -74,17 +74,13 @@ class CHROMEOS_EXPORT HomedirMethods { ...@@ -74,17 +74,13 @@ class CHROMEOS_EXPORT HomedirMethods {
const MountRequest& request, const MountRequest& request,
const MountCallback& callback) = 0; const MountCallback& callback) = 0;
// Asks cryptohomed to try to add another |key| for user identified by |id| // Asks cryptohomed to try to add another key for the user identified by |id|
// using |auth| to unlock the key. // using |auth| to unlock the key.
// |clobber_if_exist| governs action if key with same label already exists for // Key used in |auth| should have the PRIV_ADD privilege.
// this user. if |true| old key will be replaced, if |false| old key will be
// preserved.
// Key used in |auth| should have PRIV_ADD privilege.
// |callback| will be called with status info on completion. // |callback| will be called with status info on completion.
virtual void AddKeyEx(const Identification& id, virtual void AddKeyEx(const Identification& id,
const Authorization& auth, const AuthorizationRequest& auth,
const KeyDefinition& key, const AddKeyRequest& request,
bool clobber_if_exist,
const Callback& callback) = 0; const Callback& callback) = 0;
// Asks cryptohomed to update |key| for user identified by |id| using |auth| // Asks cryptohomed to update |key| for user identified by |id| using |auth|
......
...@@ -29,9 +29,9 @@ void MockHomedirMethods::SetUp(bool success, MountError return_code) { ...@@ -29,9 +29,9 @@ void MockHomedirMethods::SetUp(bool success, MountError return_code) {
WithArgs<3>(Invoke(this, &MockHomedirMethods::DoCallback))); WithArgs<3>(Invoke(this, &MockHomedirMethods::DoCallback)));
ON_CALL(*this, MountEx(_, _, _, _)).WillByDefault( ON_CALL(*this, MountEx(_, _, _, _)).WillByDefault(
WithArgs<3>(Invoke(this, &MockHomedirMethods::DoMountCallback))); WithArgs<3>(Invoke(this, &MockHomedirMethods::DoMountCallback)));
ON_CALL(*this, AddKeyEx(_, _, _, _, _)) ON_CALL(*this, AddKeyEx(_, _, _, _))
.WillByDefault( .WillByDefault(
WithArgs<4>(Invoke(this, &MockHomedirMethods::DoAddKeyCallback))); WithArgs<3>(Invoke(this, &MockHomedirMethods::DoAddKeyCallback)));
ON_CALL(*this, UpdateKeyEx(_, _, _, _, _)).WillByDefault( ON_CALL(*this, UpdateKeyEx(_, _, _, _, _)).WillByDefault(
WithArgs<4>(Invoke(this, &MockHomedirMethods::DoCallback))); WithArgs<4>(Invoke(this, &MockHomedirMethods::DoCallback)));
ON_CALL(*this, RemoveKeyEx(_, _, _, _)).WillByDefault( ON_CALL(*this, RemoveKeyEx(_, _, _, _)).WillByDefault(
......
...@@ -37,11 +37,10 @@ class CHROMEOS_EXPORT MockHomedirMethods : public HomedirMethods { ...@@ -37,11 +37,10 @@ class CHROMEOS_EXPORT MockHomedirMethods : public HomedirMethods {
const AuthorizationRequest& auth, const AuthorizationRequest& auth,
const MountRequest& request, const MountRequest& request,
const MountCallback& callback)); const MountCallback& callback));
MOCK_METHOD5(AddKeyEx, MOCK_METHOD4(AddKeyEx,
void(const Identification& id, void(const Identification& id,
const Authorization& auth, const AuthorizationRequest& auth,
const KeyDefinition& key, const AddKeyRequest& request,
bool clobber_if_exist,
const Callback& callback)); const Callback& callback));
MOCK_METHOD4(RemoveKeyEx, MOCK_METHOD4(RemoveKeyEx,
void(const Identification& id, void(const Identification& id,
......
...@@ -114,15 +114,12 @@ void ExtendedAuthenticatorImpl::CreateMount( ...@@ -114,15 +114,12 @@ void ExtendedAuthenticatorImpl::CreateMount(
} }
void ExtendedAuthenticatorImpl::AddKey(const UserContext& context, void ExtendedAuthenticatorImpl::AddKey(const UserContext& context,
const cryptohome::KeyDefinition& key, const cryptohome::KeyDefinition& key,
bool replace_existing, bool clobber_if_exists,
const base::Closure& success_callback) { const base::Closure& success_callback) {
TransformKeyIfNeeded(context, TransformKeyIfNeeded(
base::Bind(&ExtendedAuthenticatorImpl::DoAddKey, context, base::Bind(&ExtendedAuthenticatorImpl::DoAddKey, this, key,
this, clobber_if_exists, success_callback));
key,
replace_existing,
success_callback));
} }
void ExtendedAuthenticatorImpl::UpdateKeyAuthorized( void ExtendedAuthenticatorImpl::UpdateKeyAuthorized(
...@@ -214,25 +211,22 @@ void ExtendedAuthenticatorImpl::DoAuthenticateToCheck( ...@@ -214,25 +211,22 @@ void ExtendedAuthenticatorImpl::DoAuthenticateToCheck(
} }
void ExtendedAuthenticatorImpl::DoAddKey(const cryptohome::KeyDefinition& key, void ExtendedAuthenticatorImpl::DoAddKey(const cryptohome::KeyDefinition& key,
bool replace_existing, bool clobber_if_exists,
const base::Closure& success_callback, const base::Closure& success_callback,
const UserContext& user_context) { const UserContext& user_context) {
RecordStartMarker("AddKeyEx"); RecordStartMarker("AddKeyEx");
cryptohome::Identification id(user_context.GetAccountId()); cryptohome::AddKeyRequest request;
KeyDefinitionToKey(key, request.mutable_key());
request.set_clobber_if_exists(clobber_if_exists);
const Key* const auth_key = user_context.GetKey(); const Key* const auth_key = user_context.GetKey();
cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel());
cryptohome::HomedirMethods::GetInstance()->AddKeyEx( cryptohome::HomedirMethods::GetInstance()->AddKeyEx(
id, cryptohome::Identification(user_context.GetAccountId()),
auth, cryptohome::CreateAuthorizationRequest(auth_key->GetLabel(),
key, auth_key->GetSecret()),
replace_existing, request,
base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, this,
this, "AddKeyEx", user_context, success_callback));
"AddKeyEx",
user_context,
success_callback));
} }
void ExtendedAuthenticatorImpl::DoUpdateKeyAuthorized( void ExtendedAuthenticatorImpl::DoUpdateKeyAuthorized(
......
...@@ -39,7 +39,7 @@ class CHROMEOS_EXPORT ExtendedAuthenticatorImpl : public ExtendedAuthenticator { ...@@ -39,7 +39,7 @@ class CHROMEOS_EXPORT ExtendedAuthenticatorImpl : public ExtendedAuthenticator {
const ResultCallback& success_callback) override; const ResultCallback& success_callback) override;
void AddKey(const UserContext& context, void AddKey(const UserContext& context,
const cryptohome::KeyDefinition& key, const cryptohome::KeyDefinition& key,
bool replace_existing, bool clobber_if_exists,
const base::Closure& success_callback) override; const base::Closure& success_callback) override;
void UpdateKeyAuthorized(const UserContext& context, void UpdateKeyAuthorized(const UserContext& context,
const cryptohome::KeyDefinition& key, const cryptohome::KeyDefinition& key,
...@@ -63,7 +63,7 @@ class CHROMEOS_EXPORT ExtendedAuthenticatorImpl : public ExtendedAuthenticator { ...@@ -63,7 +63,7 @@ class CHROMEOS_EXPORT ExtendedAuthenticatorImpl : public ExtendedAuthenticator {
void DoAuthenticateToCheck(const base::Closure& success_callback, void DoAuthenticateToCheck(const base::Closure& success_callback,
const UserContext& context); const UserContext& context);
void DoAddKey(const cryptohome::KeyDefinition& key, void DoAddKey(const cryptohome::KeyDefinition& key,
bool replace_existing, bool clobber_if_exists,
const base::Closure& success_callback, const base::Closure& success_callback,
const UserContext& context); const UserContext& context);
void DoUpdateKeyAuthorized(const cryptohome::KeyDefinition& key, void DoUpdateKeyAuthorized(const cryptohome::KeyDefinition& key,
......
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