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

Unified Diff: device/u2f/u2f_device.cc

Issue 2721223002: Add support for U2fHidDevice interaction (Closed)
Patch Set: Use MockHidConnection to fail writes in unittest Created 3 years, 9 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') | device/u2f/u2f_hid_device.h » ('j') | 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
index f065c69d8b1707de136b6bc48446f14c7e299fae..21ee7b9fce62d28b95454a4537ad25c4c4d34c54 100644
--- a/device/u2f/u2f_device.cc
+++ b/device/u2f/u2f_device.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "u2f_device.h"
+
#include "base/bind.h"
#include "u2f_apdu_command.h"
-#include "u2f_device.h"
+#include "u2f_apdu_response.h"
namespace device {
@@ -13,7 +15,6 @@ 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 =
@@ -57,13 +58,49 @@ void U2fDevice::OnRegisterComplete(
const MessageCallback& callback,
bool success,
scoped_refptr<U2fApduResponse> register_response) {
- NOTIMPLEMENTED();
+ if (!success || !register_response) {
+ callback.Run(ReturnCode::FAILURE, std::vector<uint8_t>());
+ return;
+ }
+ switch (register_response->status()) {
+ case U2fApduResponse::Status::SW_CONDITIONS_NOT_SATISFIED:
+ callback.Run(ReturnCode::CONDITIONS_NOT_SATISFIED,
+ std::vector<uint8_t>());
+ break;
+ case U2fApduResponse::Status::SW_NO_ERROR:
+ callback.Run(ReturnCode::SUCCESS, register_response->data());
+ break;
+ case U2fApduResponse::Status::SW_WRONG_DATA:
+ callback.Run(ReturnCode::INVALID_PARAMS, std::vector<uint8_t>());
+ break;
+ default:
+ callback.Run(ReturnCode::FAILURE, std::vector<uint8_t>());
+ break;
+ }
}
void U2fDevice::OnSignComplete(const MessageCallback& callback,
bool success,
scoped_refptr<U2fApduResponse> sign_response) {
- NOTIMPLEMENTED();
+ if (!success || !sign_response) {
+ callback.Run(ReturnCode::FAILURE, std::vector<uint8_t>());
+ return;
+ }
+ switch (sign_response->status()) {
+ case U2fApduResponse::Status::SW_CONDITIONS_NOT_SATISFIED:
+ callback.Run(ReturnCode::CONDITIONS_NOT_SATISFIED,
+ std::vector<uint8_t>());
+ break;
+ case U2fApduResponse::Status::SW_NO_ERROR:
+ callback.Run(ReturnCode::SUCCESS, sign_response->data());
+ break;
+ case U2fApduResponse::Status::SW_WRONG_DATA:
+ callback.Run(ReturnCode::INVALID_PARAMS, std::vector<uint8_t>());
+ break;
+ default:
+ callback.Run(ReturnCode::FAILURE, std::vector<uint8_t>());
+ break;
+ }
}
void U2fDevice::OnVersionComplete(
@@ -84,7 +121,15 @@ void U2fDevice::OnLegacyVersionComplete(
const VersionCallback& callback,
bool success,
scoped_refptr<U2fApduResponse> legacy_version_response) {
- NOTIMPLEMENTED();
+ if (success && legacy_version_response &&
+ legacy_version_response->status() ==
+ U2fApduResponse::Status::SW_NO_ERROR &&
+ legacy_version_response->data() ==
+ std::vector<uint8_t>({'U', '2', 'F', '_', 'V', '2'})) {
+ callback.Run(success, ProtocolVersion::U2F_V2);
+ return;
+ }
+ callback.Run(success, ProtocolVersion::UNKNOWN);
}
} // namespace device
« no previous file with comments | « device/u2f/u2f_device.h ('k') | device/u2f/u2f_hid_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698