| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 16 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_create_keys_oper
ation.h" | 15 #include "base/stl_util.h" |
| 17 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operati
on.h" | 16 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_get_keys_operati
on.h" |
| 18 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_remove_keys_oper
ation.h" | 17 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_refresh_keys_ope
ration.h" |
| 19 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h" | 18 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h" |
| 20 | 19 |
| 21 namespace base { | 20 namespace base { |
| 22 class DictionaryValue; | 21 class DictionaryValue; |
| 23 class ListValue; | 22 class ListValue; |
| 24 } | 23 } |
| 25 | 24 |
| 26 namespace chromeos { | 25 namespace chromeos { |
| 27 | 26 |
| 28 class UserContext; | 27 class UserContext; |
| 29 | 28 |
| 30 // A class to manage Easy unlock cryptohome keys. | 29 // A class to manage Easy unlock cryptohome keys. |
| 31 class EasyUnlockKeyManager { | 30 class EasyUnlockKeyManager { |
| 32 public: | 31 public: |
| 33 typedef EasyUnlockCreateKeysOperation::CreateKeysCallback RefreshKeysCallback; | 32 typedef EasyUnlockRefreshKeysOperation::RefreshKeysCallback |
| 34 typedef EasyUnlockRemoveKeysOperation::RemoveKeysCallback RemoveKeysCallback; | 33 RefreshKeysCallback; |
| 35 typedef EasyUnlockGetKeysOperation::GetKeysCallback GetDeviceDataListCallback; | 34 typedef EasyUnlockGetKeysOperation::GetKeysCallback GetDeviceDataListCallback; |
| 36 | 35 |
| 37 EasyUnlockKeyManager(); | 36 EasyUnlockKeyManager(); |
| 38 ~EasyUnlockKeyManager(); | 37 ~EasyUnlockKeyManager(); |
| 39 | 38 |
| 40 // Nukes existing Easy unlock keys and creates new ones for the given | 39 // Nukes existing Easy unlock keys and creates new ones for the given |
| 41 // |remote_devices| and the given |user_context|. |user_context| must have | 40 // |remote_devices| and the given |user_context|. |user_context| must have |
| 42 // secret to allow keys to be created. | 41 // secret to allow keys to be created. |
| 43 void RefreshKeys(const UserContext& user_context, | 42 void RefreshKeys(const UserContext& user_context, |
| 44 const base::ListValue& remote_devices, | 43 const base::ListValue& remote_devices, |
| 45 const RefreshKeysCallback& callback); | 44 const RefreshKeysCallback& callback); |
| 46 | 45 |
| 47 // Remove Easy unlock keys starting at the given index for the given | |
| 48 // |user_context|. | |
| 49 void RemoveKeys(const UserContext& user_context, | |
| 50 size_t start_index, | |
| 51 const RemoveKeysCallback& callback); | |
| 52 | |
| 53 // Retrieves the remote device data from cryptohome keys for the given | 46 // Retrieves the remote device data from cryptohome keys for the given |
| 54 // |user_context|. | 47 // |user_context|. |
| 55 void GetDeviceDataList(const UserContext& user_context, | 48 void GetDeviceDataList(const UserContext& user_context, |
| 56 const GetDeviceDataListCallback& callback); | 49 const GetDeviceDataListCallback& callback); |
| 57 | 50 |
| 58 // Helpers to convert between DeviceData and remote device dictionary. | 51 // Helpers to convert between DeviceData and remote device dictionary. |
| 59 // DeviceDataToRemoteDeviceDictionary fills the remote device dictionary and | 52 // DeviceDataToRemoteDeviceDictionary fills the remote device dictionary and |
| 60 // always succeeds. RemoteDeviceDictionaryToDeviceData returns false if the | 53 // always succeeds. RemoteDeviceDictionaryToDeviceData returns false if the |
| 61 // conversion fails (missing required propery). Note that | 54 // conversion fails (missing required propery). Note that |
| 62 // EasyUnlockDeviceKeyData contains a sub set of the remote device dictionary. | 55 // EasyUnlockDeviceKeyData contains a sub set of the remote device dictionary. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 75 const EasyUnlockDeviceKeyDataList& data_list, | 68 const EasyUnlockDeviceKeyDataList& data_list, |
| 76 base::ListValue* device_list); | 69 base::ListValue* device_list); |
| 77 static bool RemoteDeviceListToDeviceDataList( | 70 static bool RemoteDeviceListToDeviceDataList( |
| 78 const base::ListValue& device_list, | 71 const base::ListValue& device_list, |
| 79 EasyUnlockDeviceKeyDataList* data_list); | 72 EasyUnlockDeviceKeyDataList* data_list); |
| 80 | 73 |
| 81 // Gets key label for the given key index. | 74 // Gets key label for the given key index. |
| 82 static std::string GetKeyLabel(size_t key_index); | 75 static std::string GetKeyLabel(size_t key_index); |
| 83 | 76 |
| 84 private: | 77 private: |
| 78 // Runs the next operation if there is one. We first run all the operations in |
| 79 // the |write_operation_queue_| and then run all the operations in the |
| 80 // |read_operation_queue_|. |
| 81 void RunNextOperation(); |
| 82 |
| 83 // Called when the TPM key is ready to be used for creating Easy Unlock key |
| 84 // challenges. |
| 85 void RefreshKeysWithTpmKeyPresent(const UserContext& user_context, | 85 void RefreshKeysWithTpmKeyPresent(const UserContext& user_context, |
| 86 base::ListValue* remote_devices, | 86 base::ListValue* remote_devices, |
| 87 const RefreshKeysCallback& callback); | 87 const RefreshKeysCallback& callback); |
| 88 | 88 |
| 89 // Returns true if there are pending operations. | 89 // Returns true if there are pending operations. |
| 90 bool HasPendingOperations() const; | 90 bool HasPendingOperations() const; |
| 91 | 91 |
| 92 // Returns the next operations id. Currently only used for get keys ops. | 92 // Callback invoked after refresh keys operation. |
| 93 int GetNextOperationId(); | 93 void OnKeysRefreshed(const RefreshKeysCallback& callback, |
| 94 | 94 bool create_success); |
| 95 // Runs the first pending op in |pending_ops_|. No-op if |pending_ops_| is | |
| 96 // emtpy. | |
| 97 void RunNextPendingOp(); | |
| 98 | |
| 99 // Callback invoked after create keys op. | |
| 100 void OnKeysCreated(size_t remove_start_index, | |
| 101 const RefreshKeysCallback& callback, | |
| 102 bool create_success); | |
| 103 | |
| 104 // Callback invoked after remove keys op. | |
| 105 void OnKeysRemoved(const RemoveKeysCallback& callback, bool remove_success); | |
| 106 | 95 |
| 107 // Callback invoked after get keys op. | 96 // Callback invoked after get keys op. |
| 108 void OnKeysFetched(int op_id, | 97 void OnKeysFetched(const GetDeviceDataListCallback& callback, |
| 109 const GetDeviceDataListCallback& callback, | |
| 110 bool fetch_success, | 98 bool fetch_success, |
| 111 const EasyUnlockDeviceKeyDataList& fetched_data); | 99 const EasyUnlockDeviceKeyDataList& fetched_data); |
| 112 | 100 |
| 113 int operation_id_; | 101 // Queued operations are stored as raw pointers, as scoped_ptrs may not behave |
| 102 // nicely with std::deque. |
| 103 using WriteOperationQueue = std::deque<EasyUnlockRefreshKeysOperation*>; |
| 104 using ReadOperationQueue = std::deque<EasyUnlockGetKeysOperation*>; |
| 105 WriteOperationQueue write_operation_queue_; |
| 106 ReadOperationQueue read_operation_queue_; |
| 114 | 107 |
| 115 scoped_ptr<EasyUnlockCreateKeysOperation> create_keys_op_; | 108 // Scopes the raw operation pointers to the lifetime of this object. |
| 116 scoped_ptr<EasyUnlockRemoveKeysOperation> remove_keys_op_; | 109 STLElementDeleter<WriteOperationQueue> write_queue_deleter_; |
| 117 std::map<int, EasyUnlockGetKeysOperation*> get_keys_ops_; | 110 STLElementDeleter<ReadOperationQueue> read_queue_deleter_; |
| 118 | 111 |
| 119 std::deque<base::Closure> pending_ops_; | 112 // Stores the current operation in progress. At most one of these variables |
| 113 // can be non-null at any time. |
| 114 scoped_ptr<EasyUnlockRefreshKeysOperation> pending_write_operation_; |
| 115 scoped_ptr<EasyUnlockGetKeysOperation> pending_read_operation_; |
| 120 | 116 |
| 121 base::WeakPtrFactory<EasyUnlockKeyManager> weak_ptr_factory_; | 117 base::WeakPtrFactory<EasyUnlockKeyManager> weak_ptr_factory_; |
| 122 | 118 |
| 123 DISALLOW_COPY_AND_ASSIGN(EasyUnlockKeyManager); | 119 DISALLOW_COPY_AND_ASSIGN(EasyUnlockKeyManager); |
| 124 }; | 120 }; |
| 125 | 121 |
| 126 } // namespace chromeos | 122 } // namespace chromeos |
| 127 | 123 |
| 128 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ | 124 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_KEY_MANAGER_H_ |
| OLD | NEW |