1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_remove_keys_operation.h"
8 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h"
9 #include "chromeos/cryptohome/homedir_methods.h"
10 #include "chromeos/cryptohome/system_salt_getter.h"
11 #include "google_apis/gaia/gaia_auth_util.h"
15 EasyUnlockRemoveKeysOperation::EasyUnlockRemoveKeysOperation(
16 const UserContext
& user_context
,
18 const RemoveKeysCallback
& callback
)
19 : user_context_(user_context
),
21 key_index_(start_index
),
22 weak_ptr_factory_(this) {
23 // Must have the secret and callback.
24 DCHECK(!user_context_
.GetKey()->GetSecret().empty());
25 DCHECK(!callback_
.is_null());
28 EasyUnlockRemoveKeysOperation::~EasyUnlockRemoveKeysOperation() {
31 void EasyUnlockRemoveKeysOperation::Start() {
32 if (user_context_
.GetKey()->GetKeyType() == Key::KEY_TYPE_PASSWORD_PLAIN
) {
33 SystemSaltGetter::Get()->GetSystemSalt(
34 base::Bind(&EasyUnlockRemoveKeysOperation::OnGetSystemSalt
,
35 weak_ptr_factory_
.GetWeakPtr()));
42 void EasyUnlockRemoveKeysOperation::OnGetSystemSalt(
43 const std::string
& system_salt
) {
44 user_context_
.GetKey()->Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF
,
49 void EasyUnlockRemoveKeysOperation::RemoveKey() {
50 std::string canonicalized
=
51 gaia::CanonicalizeEmail(user_context_
.GetUserID());
52 cryptohome::Identification
id(canonicalized
);
53 const Key
* const auth_key
= user_context_
.GetKey();
54 cryptohome::Authorization
auth(auth_key
->GetSecret(), auth_key
->GetLabel());
56 // TODO(xiyuan): Use ListKeyEx and delete by label instead of by index.
57 cryptohome::HomedirMethods::GetInstance()->RemoveKeyEx(
60 EasyUnlockKeyManager::GetKeyLabel(key_index_
),
61 base::Bind(&EasyUnlockRemoveKeysOperation::OnKeyRemoved
,
62 weak_ptr_factory_
.GetWeakPtr()));
65 void EasyUnlockRemoveKeysOperation::OnKeyRemoved(
67 cryptohome::MountError return_code
) {
74 // MOUNT_ERROR_KEY_FAILURE is considered as success. Other error codes are
75 // treated as failures.
76 if (return_code
== cryptohome::MOUNT_ERROR_KEY_FAILURE
) {
79 LOG(ERROR
) << "Easy unlock remove keys operation failed, code="
85 } // namespace chromeos