Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Unified Diff: device/u2f/u2f_hid_device.h

Issue 2721223002: Add support for U2fHidDevice interaction (Closed)
Patch Set: Modify unittest BUILD file Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/u2f/u2f_hid_device.h
diff --git a/device/u2f/u2f_hid_device.h b/device/u2f/u2f_hid_device.h
new file mode 100644
index 0000000000000000000000000000000000000000..0b4b130c0428c9031aa514816eb34c5609be13b8
--- /dev/null
+++ b/device/u2f/u2f_hid_device.h
@@ -0,0 +1,93 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_U2F_U2F_HID_DEVICE_H_
+#define DEVICE_U2F_U2F_HID_DEVICE_H_
+
+#include "device/hid/hid_service.h"
+#include "u2f_device.h"
+
+namespace net {
+class IOBuffer;
+} // namespace net
+
+namespace device {
+
+class U2fMessage;
+class HidConnection;
+class HidDeviceInfo;
+
+class U2fHidDevice : public U2fDevice {
+ public:
+ U2fHidDevice(scoped_refptr<HidDeviceInfo>);
+ ~U2fHidDevice();
+
+ // Send a U2f command to this device
+ void DeviceTransact(scoped_refptr<U2fApduCommand> command,
+ const DeviceCallback& callback) final;
+ // Send a wink command if supported
+ void TryWink(const WinkCallback& callback) final;
+ // Use a string identifier to compare to other devices
+ std::string Id() final;
+ // Command line flag to enable tests on actual U2f HID hardware
+ static bool IsTestEnabled();
+
+ private:
+ // Internal state machine states
+ enum class State { INIT, CONNECTED, IDLE, DEVICE_ERROR };
+
+ using U2fHidMessageCallback =
+ base::Callback<void(bool, scoped_refptr<U2fMessage>)>;
+
+ // Open a connection to this device
+ void Connect(const HidService::ConnectCallback& callback);
+ void OnConnect(scoped_refptr<U2fApduCommand> command,
+ const DeviceCallback& callback,
+ scoped_refptr<HidConnection> connection);
+ // Ask device to allocate a unique channel id for this connection
+ void AllocateChannel(scoped_refptr<U2fApduCommand> command,
+ const DeviceCallback& callback);
+ void OnAllocateChannel(std::vector<uint8_t> nonce,
+ scoped_refptr<U2fApduCommand> command,
+ const DeviceCallback& callback,
+ bool success,
+ scoped_refptr<U2fMessage> message);
+ void Transition(scoped_refptr<U2fApduCommand> command,
+ const DeviceCallback& callback);
+ // Write all message packets to device, and read response if expected
+ void WriteMessage(scoped_refptr<U2fMessage> message,
+ bool response_expected,
+ const U2fHidMessageCallback&);
+ void PacketWritten(scoped_refptr<U2fMessage> message,
+ bool response_expected,
+ const U2fHidMessageCallback& callback,
+ bool success);
+ // Read all response message packets from device
+ void ReadMessage(const U2fHidMessageCallback& callback);
+ void MessageReceived(const DeviceCallback& callback,
+ bool success,
+ scoped_refptr<U2fMessage> message);
+ void OnRead(const U2fHidMessageCallback& callback,
+ bool success,
+ scoped_refptr<net::IOBuffer> buf,
+ size_t size);
+ void OnReadContinuation(scoped_refptr<U2fMessage> message,
+ const U2fHidMessageCallback&,
+ bool success,
+ scoped_refptr<net::IOBuffer> buf,
+ size_t size);
+ void OnWink(const WinkCallback& callback,
+ bool success,
+ scoped_refptr<U2fMessage> response);
+
+ State state_;
+ scoped_refptr<HidDeviceInfo> device_info_;
+ scoped_refptr<HidConnection> connection_;
+ base::WeakPtrFactory<U2fHidDevice> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(U2fHidDevice);
+};
+}
Reilly Grant (use Gerrit) 2017/03/01 22:48:33 nit: newline and // namespace device
Casey Piper 2017/03/04 02:06:28 Done.
+
+#endif // DEVICE_U2F_U2F_HID_DEVICE_H_

Powered by Google App Engine
This is Rietveld 408576698