OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_PROXIMITY_REMOTE_DEVICE_LOADER_H | 5 #ifndef COMPONENTS_PROXIMITY_REMOTE_DEVICE_LOADER_H |
6 #define COMPONENTS_PROXIMITY_REMOTE_DEVICE_LOADER_H | 6 #define COMPONENTS_PROXIMITY_REMOTE_DEVICE_LOADER_H |
7 | 7 |
| 8 #include <memory> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/callback.h" | 11 #include "base/callback.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" | 14 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" |
15 #include "components/proximity_auth/remote_device.h" | 15 #include "components/proximity_auth/remote_device.h" |
16 | 16 |
17 namespace proximity_auth { | 17 namespace proximity_auth { |
18 | 18 |
19 class ProximityAuthPrefManager; | 19 class ProximityAuthPrefManager; |
20 class SecureMessageDelegate; | 20 class SecureMessageDelegate; |
21 | 21 |
22 // Loads a collection of RemoteDevice objects from the given ExternalDeviceInfo | 22 // Loads a collection of RemoteDevice objects from the given ExternalDeviceInfo |
23 // protos that were synced from CryptAuth. We need to derive the PSK, which is | 23 // protos that were synced from CryptAuth. We need to derive the PSK, which is |
24 // a symmetric key used to authenticate each remote device. | 24 // a symmetric key used to authenticate each remote device. |
25 class RemoteDeviceLoader { | 25 class RemoteDeviceLoader { |
26 public: | 26 public: |
27 // Creates the instance: | 27 // Creates the instance: |
28 // |unlock_keys|: The unlock keys previously synced from CryptAuth. | 28 // |unlock_keys|: The unlock keys previously synced from CryptAuth. |
29 // |user_private_key|: The private key of the user's local device. Used to | 29 // |user_private_key|: The private key of the user's local device. Used to |
30 // derive the PSK. | 30 // derive the PSK. |
31 // |secure_message_delegate|: Used to derive each persistent symmetric key. | 31 // |secure_message_delegate|: Used to derive each persistent symmetric key. |
32 // |pref_manager|: Used to retrieve the Bluetooth address of BLE devices. | 32 // |pref_manager|: Used to retrieve the Bluetooth address of BLE devices. |
33 RemoteDeviceLoader( | 33 RemoteDeviceLoader( |
34 const std::vector<cryptauth::ExternalDeviceInfo>& unlock_keys, | 34 const std::vector<cryptauth::ExternalDeviceInfo>& unlock_keys, |
35 const std::string& user_id, | 35 const std::string& user_id, |
36 const std::string& user_private_key, | 36 const std::string& user_private_key, |
37 scoped_ptr<SecureMessageDelegate> secure_message_delegate, | 37 std::unique_ptr<SecureMessageDelegate> secure_message_delegate, |
38 ProximityAuthPrefManager* pref_manager); | 38 ProximityAuthPrefManager* pref_manager); |
39 | 39 |
40 ~RemoteDeviceLoader(); | 40 ~RemoteDeviceLoader(); |
41 | 41 |
42 // Loads the RemoteDevice objects. |callback| will be invoked upon completion. | 42 // Loads the RemoteDevice objects. |callback| will be invoked upon completion. |
43 typedef base::Callback<void(const RemoteDeviceList&)> RemoteDeviceCallback; | 43 typedef base::Callback<void(const RemoteDeviceList&)> RemoteDeviceCallback; |
44 void Load(const RemoteDeviceCallback& callback); | 44 void Load(const RemoteDeviceCallback& callback); |
45 | 45 |
46 private: | 46 private: |
47 // Called when the PSK is derived for each unlock key. If the PSK for all | 47 // Called when the PSK is derived for each unlock key. If the PSK for all |
48 // unlock have been derived, then we can invoke |callback_|. | 48 // unlock have been derived, then we can invoke |callback_|. |
49 void OnPSKDerived(const cryptauth::ExternalDeviceInfo& unlock_key, | 49 void OnPSKDerived(const cryptauth::ExternalDeviceInfo& unlock_key, |
50 const std::string& psk); | 50 const std::string& psk); |
51 | 51 |
52 // The remaining unlock keys whose PSK we're waiting on. | 52 // The remaining unlock keys whose PSK we're waiting on. |
53 std::vector<cryptauth::ExternalDeviceInfo> remaining_unlock_keys_; | 53 std::vector<cryptauth::ExternalDeviceInfo> remaining_unlock_keys_; |
54 | 54 |
55 // The id of the user who the remote devices belong to. | 55 // The id of the user who the remote devices belong to. |
56 const std::string user_id_; | 56 const std::string user_id_; |
57 | 57 |
58 // The private key of the user's local device. | 58 // The private key of the user's local device. |
59 const std::string user_private_key_; | 59 const std::string user_private_key_; |
60 | 60 |
61 // Performs the PSK key derivation. | 61 // Performs the PSK key derivation. |
62 scoped_ptr<SecureMessageDelegate> secure_message_delegate_; | 62 std::unique_ptr<SecureMessageDelegate> secure_message_delegate_; |
63 | 63 |
64 // Used to retrieve the address for BLE devices. Not owned. | 64 // Used to retrieve the address for BLE devices. Not owned. |
65 ProximityAuthPrefManager* pref_manager_; | 65 ProximityAuthPrefManager* pref_manager_; |
66 | 66 |
67 // Invoked when the RemoteDevices are loaded. | 67 // Invoked when the RemoteDevices are loaded. |
68 RemoteDeviceCallback callback_; | 68 RemoteDeviceCallback callback_; |
69 | 69 |
70 // The collection of RemoteDevices to return. | 70 // The collection of RemoteDevices to return. |
71 RemoteDeviceList remote_devices_; | 71 RemoteDeviceList remote_devices_; |
72 | 72 |
73 base::WeakPtrFactory<RemoteDeviceLoader> weak_ptr_factory_; | 73 base::WeakPtrFactory<RemoteDeviceLoader> weak_ptr_factory_; |
74 | 74 |
75 DISALLOW_COPY_AND_ASSIGN(RemoteDeviceLoader); | 75 DISALLOW_COPY_AND_ASSIGN(RemoteDeviceLoader); |
76 }; | 76 }; |
77 | 77 |
78 } // namespace proximity_auth | 78 } // namespace proximity_auth |
79 | 79 |
80 #endif // COMPONENTS_PROXIMITY_REMOTE_DEVICE_LOADER_H | 80 #endif // COMPONENTS_PROXIMITY_REMOTE_DEVICE_LOADER_H |
OLD | NEW |