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

Unified Diff: device/u2f/u2f_device.h

Issue 2655853006: Define FIDO U2f Device abstraction (Closed)
Patch Set: Define FIDO U2f Device abstraction Created 3 years, 11 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_device.h
diff --git a/device/u2f/u2f_device.h b/device/u2f/u2f_device.h
new file mode 100644
index 0000000000000000000000000000000000000000..cbc9ec21a31731c9166d03285d07855fc6d7b901
--- /dev/null
+++ b/device/u2f/u2f_device.h
@@ -0,0 +1,110 @@
+// 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_DEVICE_H_
+#define DEVICE_U2F_U2F_DEVICE_H_
+
+#include <vector>
+
+#include "base/callback.h"
+#include "base/gtest_prod_util.h"
+#include "base/memory/ref_counted.h"
+#include "u2f_apdu_response.h"
+
+namespace device {
+
+class U2fApduCommand;
+class U2fRegisterResponse;
+class U2fSignResponse;
+
+// Device abstraction for an individual U2f device. A U2f device defines the
+// standardized Register, Sign, and GetVersion methods.
+class U2fDevice : public base::RefCountedThreadSafe<U2fDevice> {
Reilly Grant (use Gerrit) 2017/01/27 02:06:30 I haven't commented on this in previous reviews be
+ public:
+ enum class ProtocolVersion {
+ U2F_V2,
+ };
+
+ typedef base::Callback<void(
+ bool success,
+ scoped_refptr<U2fRegisterResponse> registration_response)>
+ RegistrationCallback;
+ typedef base::Callback<void(bool success, ProtocolVersion)>
+ GetVersionCallback;
+ typedef base::Callback<void(bool success,
+ scoped_refptr<U2fSignResponse> sign_response)>
+ SignCallback;
+ typedef base::Callback<void(bool success,
+ scoped_refptr<U2fApduResponse> response)>
+ DeviceCallback;
Reilly Grant (use Gerrit) 2017/01/27 02:06:30 Please use "using foo = bar" instead of "typedef b
+ static constexpr size_t kChallengeDigestLen = 32;
+ static constexpr size_t kAppIdDigestLen = 32;
+
+ U2fDevice();
+
+ // Raw messages parameters are defined by the specification at
+ // https://fidoalliance.org/specs/fido-u2f-v1.0-nfc-bt-amendment-20150514/fido-u2f-raw-message-formats.html
+ void Register(const std::vector<uint8_t>& appid_digest,
+ const ProtocolVersion version,
+ const std::vector<uint8_t>& challenge_digest,
+ const RegistrationCallback& callback);
+ void GetVersion(const GetVersionCallback& callback);
+ void Sign(const std::vector<uint8_t>& appid_digest,
+ const std::vector<uint8_t>& challenge_digest,
+ const std::vector<uint8_t>& key_handle,
+ const SignCallback& callback);
+
+ protected:
+ virtual ~U2fDevice();
+
+ // Pure virtual function defined by each device type, implementing
+ // the device communication transaction.
+ virtual void DeviceTransact(scoped_refptr<U2fApduCommand> command,
+ DeviceCallback callback) = 0;
Reilly Grant (use Gerrit) 2017/01/27 02:06:30 const DeviceCallback&
+
+ private:
+ friend class base::RefCountedThreadSafe<U2fDevice>;
+ FRIEND_TEST_ALL_PREFIXES(U2fDeviceTest, TestBuildApdu);
+
+ // APDU instructions
+ static constexpr uint8_t kInsU2fEnroll = 0x01;
+ static constexpr uint8_t kInsU2fSign = 0x02;
+ static constexpr uint8_t kInsU2fVersion = 0x03;
+ static constexpr uint8_t kInsGetResponse = 0xC0;
juanlang (chromium.org) 2017/01/27 18:52:21 Pretty sure this isn't used?
+ // P1 instructions
+ static constexpr uint8_t kP1TupRequired = 0x01;
+ static constexpr uint8_t kP1TupConsumed = 0x02;
+ static constexpr uint8_t kP1TupRequiredConsumed =
+ kP1TupRequired | kP1TupConsumed;
+ static constexpr size_t kMaxKeyHandleLength = 255;
+
+ static scoped_refptr<U2fApduCommand> BuildRegisterCommand(
+ const std::vector<uint8_t>& appid_digest,
+ const std::vector<uint8_t>& challenge_digest);
+ static scoped_refptr<U2fApduCommand> BuildGetVersionCommand();
+ // Early U2F drafts defined a non-ISO 7816-4 conforming layout
+ static scoped_refptr<U2fApduCommand> BuildGetLegacyVersionCommand();
+ static scoped_refptr<U2fApduCommand> BuildSignCommand(
+ const std::vector<uint8_t>& appid_digest,
+ const std::vector<uint8_t>& challenge_digest,
+ const std::vector<uint8_t>& key_handle);
Reilly Grant (use Gerrit) 2017/01/27 02:06:30 Since these methods don't depend on any properties
+ // TODO Callback functions for device calls
+ void OnRegisterComplete(RegistrationCallback callback,
Reilly Grant (use Gerrit) 2017/01/27 02:06:30 const RegistrationCallback& (ditto for other call
+ bool success,
+ scoped_refptr<U2fApduResponse> register_response);
+ void OnSignComplete(SignCallback callback,
+ bool success,
+ scoped_refptr<U2fApduResponse> sign_response);
+ void OnGetVersionComplete(
+ GetVersionCallback callback,
+ bool success,
+ scoped_refptr<U2fApduResponse> get_version_response);
+ void OnGetLegacyVersionComplete(
+ GetVersionCallback callback,
+ bool success,
+ scoped_refptr<U2fApduResponse> legacy_version_response);
+};
+
+} // namespace device
+#endif // DEVICE_U2F_U2F_DEVICE_H_
« no previous file with comments | « device/u2f/BUILD.gn ('k') | device/u2f/u2f_device.cc » ('j') | device/u2f/u2f_device.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698