Chromium Code Reviews| Index: chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operation.cc |
| diff --git a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operation.cc b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operation.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bd6acbc51a819c8dbde67b14f5c28d30e52cd2d5 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operation.cc |
| @@ -0,0 +1,107 @@ |
| +// 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. |
| + |
| +#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operation.h" |
| + |
| +#include <vector> |
| + |
| +#include "base/bind.h" |
| +#include "base/logging.h" |
| +#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
| +#include "google_apis/gaia/gaia_auth_util.h" |
| + |
| +namespace chromeos { |
| + |
| +EasyUnlockGetKeysOperation::EasyUnlockGetKeysOperation( |
| + const UserContext& user_context, |
| + const GetKeysCallback& callback) |
| + : user_context_(user_context), |
| + callback_(callback), |
| + key_index_(-1), |
| + weak_ptr_factory_(this) { |
| +} |
| + |
| +EasyUnlockGetKeysOperation::~EasyUnlockGetKeysOperation() { |
| +} |
| + |
| +void EasyUnlockGetKeysOperation::Start() { |
| + // TODO(xiyuan): Use ListKeyEx. |
| + key_index_ = 0; |
| + GetKeyData(); |
| +} |
| + |
| +void EasyUnlockGetKeysOperation::GetKeyData() { |
| + std::string canonicalized = |
| + gaia::CanonicalizeEmail(user_context_.GetUserID()); |
| + cryptohome::Identification id(canonicalized); |
| + cryptohome::HomedirMethods::GetInstance()->GetKeyDataEx( |
| + id, |
| + EasyUnlockKeyManager::GetKeyLabel(key_index_), |
| + base::Bind(&EasyUnlockGetKeysOperation::OnGetKeyData, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + |
| +} |
| + |
| +void EasyUnlockGetKeysOperation::OnGetKeyData( |
| + bool success, |
| + cryptohome::MountError return_code, |
| + ScopedVector<cryptohome::RetrievedKeyData> retrieved_data) { |
| + if (!success || retrieved_data.empty()) { |
| + // MOUNT_ERROR_KEY_FAILURE is considered as success. Other error codes are |
| + // treated as failures. |
| + if (return_code == cryptohome::MOUNT_ERROR_NONE || |
| + return_code == cryptohome::MOUNT_ERROR_KEY_FAILURE) { |
| + callback_.Run(true, devices_); |
| + return; |
| + } |
| + |
| + LOG(ERROR) << "Easy unlock failed to get key data, code=" << return_code; |
|
tbarzic
2014/09/09 19:32:21
Are you missing
callback_.Run(false, EasyUnlockDev
xiyuan
2014/09/09 20:25:30
Good catch. Fixed.
|
| + return; |
| + } |
| + |
| + DCHECK_EQ(1u, retrieved_data.size()); |
| + |
| + const std::vector<cryptohome::ProviderDataEntry>& provider_data = |
| + retrieved_data.front()->provider_data; |
| + |
| + EasyUnlockDeviceKeyData device; |
| + for (size_t i = 0; i < provider_data.size(); ++i) { |
| + const cryptohome::ProviderDataEntry& entry = provider_data[i]; |
| + if (entry.name == kEasyUnlockKeyMetaNameBluetoothAddress) { |
| + if (entry.has_bytes) |
| + device.bluetooth_address = entry.bytes; |
| + else |
| + NOTREACHED(); |
| + } else if (entry.name == kEasyUnlockKeyMetaNamePubKey) { |
| + if (entry.has_bytes) |
| + device.public_key = entry.bytes; |
| + else |
| + NOTREACHED(); |
| + } else if (entry.name == kEasyUnlockKeyMetaNamePsk) { |
| + if (entry.has_bytes) |
| + device.psk = entry.bytes; |
| + else |
| + NOTREACHED(); |
| + } else if (entry.name == kEasyUnlockKeyMetaNameChallenge) { |
| + if (entry.has_bytes) |
| + device.challenge = entry.bytes; |
| + else |
| + NOTREACHED(); |
| + } else if (entry.name == kEasyUnlockKeyMetaNameWrappedSecret) { |
| + if (entry.has_bytes) |
| + device.wrapped_secret = entry.bytes; |
| + else |
| + NOTREACHED(); |
| + } else { |
| + LOG(WARNING) << "Unknown Easy unlock key data entry, name=" |
| + << entry.name; |
| + } |
| + } |
| + devices_.push_back(device); |
| + |
| + ++key_index_; |
| + GetKeyData(); |
| +} |
| + |
| +} // namespace chromeos |