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

Unified Diff: device/u2f/u2f_device.cc

Issue 2655853006: Define FIDO U2f Device abstraction (Closed)
Patch Set: Update includes 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
« no previous file with comments | « device/u2f/u2f_device.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b6f28a817855f8771155bd717d9feb73492be303
--- /dev/null
+++ b/device/u2f/u2f_device.cc
@@ -0,0 +1,85 @@
+// 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 "base/bind.h"
+#include "u2f_apdu_command.h"
+#include "u2f_device.h"
+
+namespace device {
+
+U2fDevice::U2fDevice() : weak_factory_(this) {}
+
+U2fDevice::~U2fDevice() {}
+
+void U2fDevice::Register(const std::vector<uint8_t>& app_param,
+ U2fDevice::ProtocolVersion version,
+ const std::vector<uint8_t>& challenge_param,
+ const MessageCallback& callback) {
+ scoped_refptr<U2fApduCommand> register_cmd =
+ U2fApduCommand::CreateRegister(app_param, challenge_param);
+ if (register_cmd == nullptr) {
Reilly Grant (use Gerrit) 2017/02/16 02:03:15 if (!register_cmd)
+ callback.Run(ReturnCode::INVALID_PARAMS, std::vector<uint8_t>());
+ return;
+ }
+ DeviceTransact(register_cmd,
Reilly Grant (use Gerrit) 2017/02/16 02:03:14 You can std::move a scoped_refptr when you don't n
+ base::Bind(&U2fDevice::OnRegisterComplete,
+ weak_factory_.GetWeakPtr(), callback));
+}
+
+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 MessageCallback& callback) {
+ scoped_refptr<U2fApduCommand> sign_cmd =
+ U2fApduCommand::CreateSign(app_param, challenge_param, key_handle);
+ if (sign_cmd == nullptr) {
Reilly Grant (use Gerrit) 2017/02/16 02:03:14 if (!sign_cmd)
+ callback.Run(ReturnCode::INVALID_PARAMS, std::vector<uint8_t>());
+ return;
+ }
+ DeviceTransact(sign_cmd, base::Bind(&U2fDevice::OnSignComplete,
+ weak_factory_.GetWeakPtr(), callback));
+}
+
+void U2fDevice::Version(const VersionCallback& callback) {
+ scoped_refptr<U2fApduCommand> version_cmd = U2fApduCommand::CreateVersion();
+ if (version_cmd == nullptr) {
Reilly Grant (use Gerrit) 2017/02/16 02:03:14 if (!version_cmd)
+ callback.Run(false, ProtocolVersion::UNKNOWN);
+ return;
+ }
+ DeviceTransact(version_cmd, base::Bind(&U2fDevice::OnVersionComplete,
+ weak_factory_.GetWeakPtr(), callback));
+}
+
+// TODO
Reilly Grant (use Gerrit) 2017/02/16 02:03:15 Put a NOTIMPLEMENTED(); in the body instead of the
+void U2fDevice::OnRegisterComplete(
+ const MessageCallback& callback,
+ bool success,
+ scoped_refptr<U2fApduResponse> register_response) {}
+
+// TODO
Reilly Grant (use Gerrit) 2017/02/16 02:03:14 Put a NOTIMPLEMENTED(); in the body instead of the
+void U2fDevice::OnSignComplete(const MessageCallback& callback,
+ bool success,
+ scoped_refptr<U2fApduResponse> sign_response) {}
+
+void U2fDevice::OnVersionComplete(
+ const VersionCallback& callback,
+ bool success,
+ scoped_refptr<U2fApduResponse> version_response) {
+ if (success && version_response != nullptr &&
Reilly Grant (use Gerrit) 2017/02/16 02:03:14 && version_response &&
+ version_response->status() == U2fApduResponse::Status::SW_NO_ERROR &&
+ version_response->data() ==
+ std::vector<uint8_t>({'U', '2', 'F', '_', 'V', '2'})) {
+ callback.Run(success, ProtocolVersion::U2F_V2);
+ return;
+ }
+ callback.Run(success, ProtocolVersion::UNKNOWN);
+}
+
+// TODO
Reilly Grant (use Gerrit) 2017/02/16 02:03:14 Put a NOTIMPLEMENTED(); in the body instead of the
+void U2fDevice::OnLegacyVersionComplete(
+ const VersionCallback& callback,
+ bool success,
+ scoped_refptr<U2fApduResponse> legacy_version_response) {}
+
+} // namespace device
« no previous file with comments | « device/u2f/u2f_device.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698