Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operati on.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" | |
| 12 #include "google_apis/gaia/gaia_auth_util.h" | |
| 13 | |
| 14 namespace chromeos { | |
| 15 | |
| 16 EasyUnlockGetKeysOperation::EasyUnlockGetKeysOperation( | |
| 17 const UserContext& user_context, | |
| 18 const GetKeysCallback& callback) | |
| 19 : user_context_(user_context), | |
| 20 callback_(callback), | |
| 21 key_index_(-1), | |
| 22 weak_ptr_factory_(this) { | |
| 23 } | |
| 24 | |
| 25 EasyUnlockGetKeysOperation::~EasyUnlockGetKeysOperation() { | |
| 26 } | |
| 27 | |
| 28 void EasyUnlockGetKeysOperation::Start() { | |
| 29 // TODO(xiyuan): Use ListKeyEx. | |
| 30 key_index_ = 0; | |
| 31 GetKeyData(); | |
| 32 } | |
| 33 | |
| 34 void EasyUnlockGetKeysOperation::GetKeyData() { | |
| 35 std::string canonicalized = | |
| 36 gaia::CanonicalizeEmail(user_context_.GetUserID()); | |
| 37 cryptohome::Identification id(canonicalized); | |
| 38 cryptohome::HomedirMethods::GetInstance()->GetKeyDataEx( | |
| 39 id, | |
| 40 EasyUnlockKeyManager::GetKeyLabel(key_index_), | |
| 41 base::Bind(&EasyUnlockGetKeysOperation::OnGetKeyData, | |
| 42 weak_ptr_factory_.GetWeakPtr())); | |
| 43 | |
| 44 } | |
| 45 | |
| 46 void EasyUnlockGetKeysOperation::OnGetKeyData( | |
| 47 bool success, | |
| 48 cryptohome::MountError return_code, | |
| 49 ScopedVector<cryptohome::RetrievedKeyData> retrieved_data) { | |
| 50 if (!success || retrieved_data.empty()) { | |
| 51 // MOUNT_ERROR_KEY_FAILURE is considered as success. Other error codes are | |
| 52 // treated as failures. | |
| 53 if (return_code == cryptohome::MOUNT_ERROR_NONE || | |
| 54 return_code == cryptohome::MOUNT_ERROR_KEY_FAILURE) { | |
| 55 callback_.Run(true, devices_); | |
| 56 return; | |
| 57 } | |
| 58 | |
| 59 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.
| |
| 60 return; | |
| 61 } | |
| 62 | |
| 63 DCHECK_EQ(1u, retrieved_data.size()); | |
| 64 | |
| 65 const std::vector<cryptohome::ProviderDataEntry>& provider_data = | |
| 66 retrieved_data.front()->provider_data; | |
| 67 | |
| 68 EasyUnlockDeviceKeyData device; | |
| 69 for (size_t i = 0; i < provider_data.size(); ++i) { | |
| 70 const cryptohome::ProviderDataEntry& entry = provider_data[i]; | |
| 71 if (entry.name == kEasyUnlockKeyMetaNameBluetoothAddress) { | |
| 72 if (entry.has_bytes) | |
| 73 device.bluetooth_address = entry.bytes; | |
| 74 else | |
| 75 NOTREACHED(); | |
| 76 } else if (entry.name == kEasyUnlockKeyMetaNamePubKey) { | |
| 77 if (entry.has_bytes) | |
| 78 device.public_key = entry.bytes; | |
| 79 else | |
| 80 NOTREACHED(); | |
| 81 } else if (entry.name == kEasyUnlockKeyMetaNamePsk) { | |
| 82 if (entry.has_bytes) | |
| 83 device.psk = entry.bytes; | |
| 84 else | |
| 85 NOTREACHED(); | |
| 86 } else if (entry.name == kEasyUnlockKeyMetaNameChallenge) { | |
| 87 if (entry.has_bytes) | |
| 88 device.challenge = entry.bytes; | |
| 89 else | |
| 90 NOTREACHED(); | |
| 91 } else if (entry.name == kEasyUnlockKeyMetaNameWrappedSecret) { | |
| 92 if (entry.has_bytes) | |
| 93 device.wrapped_secret = entry.bytes; | |
| 94 else | |
| 95 NOTREACHED(); | |
| 96 } else { | |
| 97 LOG(WARNING) << "Unknown Easy unlock key data entry, name=" | |
| 98 << entry.name; | |
| 99 } | |
| 100 } | |
| 101 devices_.push_back(device); | |
| 102 | |
| 103 ++key_index_; | |
| 104 GetKeyData(); | |
| 105 } | |
| 106 | |
| 107 } // namespace chromeos | |
| OLD | NEW |