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

Unified Diff: device/u2f/u2f_device.cc

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.cc
diff --git a/device/u2f/u2f_device.cc b/device/u2f/u2f_device.cc
new file mode 100644
index 0000000000000000000000000000000000000000..efbbd1f5777646003c467559baff67b50a022c5e
--- /dev/null
+++ b/device/u2f/u2f_device.cc
@@ -0,0 +1,94 @@
+// 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.
+
+#include <vector>
+
+#include "base/bind.h"
+#include "u2f_apdu_command.h"
+#include "u2f_device.h"
+#include "u2f_responses.h"
+
+namespace device {
+
+U2fDevice::U2fDevice() {}
+
+U2fDevice::~U2fDevice() {}
+
+void U2fDevice::Register(const std::vector<uint8_t>& app_param,
+ U2fDevice::ProtocolVersion version,
+ const std::vector<uint8_t>& challenge_param,
+ const RegistrationCallback& callback) {
+ scoped_refptr<U2fApduCommand> register_cmd =
+ BuildRegisterCommand(app_param, challenge_param);
+ // TODO Stubbed function. Should call DeviceTransact with given params.
+}
+
+void U2fDevice::Sign(const std::vector<uint8_t>& app_param,
+ const std::vector<uint8_t>& challenge_param,
+ const std::vector<uint8_t>& key_handle,
+ const SignCallback& callback) {
+ scoped_refptr<U2fApduCommand> sign_cmd =
+ BuildSignCommand(app_param, challenge_param, key_handle);
+ // TODO Stubbed function. Should call DeviceTransact with given params.
+}
+
+void U2fDevice::GetVersion(const GetVersionCallback& callback) {
+ scoped_refptr<U2fApduCommand> version_cmd = BuildGetVersionCommand();
+ // TODO Stubbed function. Should call DeviceTransact with given params.
+}
+
+// static
+scoped_refptr<U2fApduCommand> U2fDevice::BuildRegisterCommand(
+ const std::vector<uint8_t>& appid_digest,
+ const std::vector<uint8_t>& challenge_digest) {
+ if (appid_digest.size() != kAppIdDigestLen ||
+ challenge_digest.size() != kChallengeDigestLen)
+ return nullptr;
+
+ scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
+ std::vector<uint8_t> data(challenge_digest.begin(), challenge_digest.end());
+ data.insert(data.end(), appid_digest.begin(), appid_digest.end());
+ command->set_ins(kInsU2fEnroll);
+ command->set_p1(kP1TupRequiredConsumed);
+ command->set_data(data);
+ return command;
+}
+
+// static
+scoped_refptr<U2fApduCommand> U2fDevice::BuildGetVersionCommand() {
+ scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
+ command->set_ins(kInsU2fVersion);
+ return command;
+}
+
+// static
+scoped_refptr<U2fApduCommand> U2fDevice::BuildGetLegacyVersionCommand() {
+ scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
+ command->set_ins(kInsU2fVersion);
+ command->set_data(std::vector<uint8_t>(2, 0));
+ return command;
+}
+
+// static
+scoped_refptr<U2fApduCommand> U2fDevice::BuildSignCommand(
+ const std::vector<uint8_t>& appid_digest,
+ const std::vector<uint8_t>& challenge_digest,
+ const std::vector<uint8_t>& key_handle) {
+ if (appid_digest.size() != kAppIdDigestLen ||
+ challenge_digest.size() != kChallengeDigestLen ||
+ key_handle.size() > kMaxKeyHandleLength)
+ return nullptr;
Reilly Grant (use Gerrit) 2017/01/27 02:06:30 nit: braces around if body when the condition is m
+
+ scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
+ std::vector<uint8_t> data(challenge_digest.begin(), challenge_digest.end());
+ data.insert(data.end(), appid_digest.begin(), appid_digest.end());
+ data.push_back(static_cast<uint8_t>(key_handle.size()));
+ data.insert(data.end(), key_handle.begin(), key_handle.end());
+ command->set_ins(kInsU2fSign);
+ command->set_p1(kP1TupRequiredConsumed);
+ command->set_data(data);
+ return command;
+}
+
+} // namespace device

Powered by Google App Engine
This is Rietveld 408576698