Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 DEVICE_U2F_U2F_HID_DEVICE_H_ | |
| 6 #define DEVICE_U2F_U2F_HID_DEVICE_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "device/hid/hid_service.h" | |
| 11 #include "u2f_device.h" | |
| 12 | |
| 13 namespace net { | |
| 14 class IOBuffer; | |
| 15 } // namespace net | |
| 16 | |
| 17 namespace device { | |
| 18 | |
| 19 class U2fMessage; | |
| 20 class HidConnection; | |
| 21 class HidDeviceInfo; | |
| 22 | |
| 23 class U2fHidDevice : public U2fDevice { | |
| 24 public: | |
| 25 U2fHidDevice(scoped_refptr<HidDeviceInfo>); | |
| 26 ~U2fHidDevice(); | |
| 27 | |
| 28 // Send a U2f command to this device | |
| 29 void DeviceTransact(scoped_refptr<U2fApduCommand> command, | |
| 30 const DeviceCallback& callback) final; | |
| 31 // Send a wink command if supported | |
| 32 void TryWink(const WinkCallback& callback) final; | |
| 33 // Use a string identifier to compare to other devices | |
| 34 std::string Id() final; | |
| 35 // Command line flag to enable tests on actual U2f HID hardware | |
| 36 static bool IsTestEnabled(); | |
| 37 | |
| 38 private: | |
| 39 // Internal state machine states | |
| 40 enum class State { INIT, CONNECTED, BUSY, IDLE, DEVICE_ERROR }; | |
| 41 | |
| 42 using U2fHidMessageCallback = | |
| 43 base::OnceCallback<void(bool, scoped_refptr<U2fMessage>)>; | |
| 44 | |
| 45 // Open a connection to this device | |
| 46 void Connect(const HidService::ConnectCallback& callback); | |
| 47 void OnConnect(scoped_refptr<U2fApduCommand> command, | |
| 48 const DeviceCallback& callback, | |
| 49 scoped_refptr<HidConnection> connection); | |
| 50 // Ask device to allocate a unique channel id for this connection | |
| 51 void AllocateChannel(scoped_refptr<U2fApduCommand> command, | |
| 52 const DeviceCallback& callback); | |
| 53 void OnAllocateChannel(std::vector<uint8_t> nonce, | |
| 54 scoped_refptr<U2fApduCommand> command, | |
| 55 const DeviceCallback& callback, | |
| 56 bool success, | |
| 57 scoped_refptr<U2fMessage> message); | |
| 58 void Transition(scoped_refptr<U2fApduCommand> command, | |
| 59 const DeviceCallback& callback); | |
| 60 // Write all message packets to device, and read response if expected | |
| 61 void WriteMessage(scoped_refptr<U2fMessage> message, | |
| 62 bool response_expected, | |
| 63 U2fHidMessageCallback); | |
|
Reilly Grant (use Gerrit)
2017/03/06 20:49:23
U2fHidMessageCallback callback
Casey Piper
2017/03/07 00:53:28
Done.
| |
| 64 void PacketWritten(scoped_refptr<U2fMessage> message, | |
| 65 bool response_expected, | |
| 66 U2fHidMessageCallback callback, | |
| 67 bool success); | |
| 68 // Read all response message packets from device | |
| 69 void ReadMessage(U2fHidMessageCallback callback); | |
| 70 void MessageReceived(const DeviceCallback& callback, | |
| 71 bool success, | |
| 72 scoped_refptr<U2fMessage> message); | |
| 73 void OnRead(U2fHidMessageCallback callback, | |
| 74 bool success, | |
| 75 scoped_refptr<net::IOBuffer> buf, | |
| 76 size_t size); | |
| 77 void OnReadContinuation(scoped_refptr<U2fMessage> message, | |
| 78 U2fHidMessageCallback, | |
| 79 bool success, | |
| 80 scoped_refptr<net::IOBuffer> buf, | |
| 81 size_t size); | |
| 82 void OnWink(const WinkCallback& callback, | |
| 83 bool success, | |
| 84 scoped_refptr<U2fMessage> response); | |
| 85 | |
| 86 State state_; | |
| 87 std::vector<std::pair<scoped_refptr<U2fApduCommand>, DeviceCallback>> | |
| 88 pending_transactions_; | |
| 89 scoped_refptr<HidDeviceInfo> device_info_; | |
| 90 scoped_refptr<HidConnection> connection_; | |
| 91 base::WeakPtrFactory<U2fHidDevice> weak_factory_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(U2fHidDevice); | |
| 94 }; | |
| 95 | |
| 96 } // namespace device | |
| 97 | |
| 98 #endif // DEVICE_U2F_U2F_HID_DEVICE_H_ | |
| OLD | NEW |