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