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

Side by Side Diff: device/u2f/u2f_device.cc

Issue 2655853006: Define FIDO U2f Device abstraction (Closed)
Patch Set: Fix nits 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 unified diff | Download patch
« no previous file with comments | « device/u2f/u2f_device.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "u2f_apdu_command.h"
7 #include "u2f_device.h"
8
9 namespace device {
10
11 U2fDevice::U2fDevice() : weak_factory_(this) {}
12
13 U2fDevice::~U2fDevice() {}
14
15 void U2fDevice::Register(const std::vector<uint8_t>& app_param,
16 U2fDevice::ProtocolVersion version,
17 const std::vector<uint8_t>& challenge_param,
18 const MessageCallback& callback) {
19 scoped_refptr<U2fApduCommand> register_cmd =
20 U2fApduCommand::CreateRegister(app_param, challenge_param);
21 if (!register_cmd) {
22 callback.Run(ReturnCode::INVALID_PARAMS, std::vector<uint8_t>());
23 return;
24 }
25 DeviceTransact(std::move(register_cmd),
26 base::Bind(&U2fDevice::OnRegisterComplete,
27 weak_factory_.GetWeakPtr(), callback));
28 }
29
30 void U2fDevice::Sign(const std::vector<uint8_t>& app_param,
31 const std::vector<uint8_t>& challenge_param,
32 const std::vector<uint8_t>& key_handle,
33 const MessageCallback& callback) {
34 scoped_refptr<U2fApduCommand> sign_cmd =
35 U2fApduCommand::CreateSign(app_param, challenge_param, key_handle);
36 if (!sign_cmd) {
37 callback.Run(ReturnCode::INVALID_PARAMS, std::vector<uint8_t>());
38 return;
39 }
40 DeviceTransact(std::move(sign_cmd),
41 base::Bind(&U2fDevice::OnSignComplete,
42 weak_factory_.GetWeakPtr(), callback));
43 }
44
45 void U2fDevice::Version(const VersionCallback& callback) {
46 scoped_refptr<U2fApduCommand> version_cmd = U2fApduCommand::CreateVersion();
47 if (!version_cmd) {
48 callback.Run(false, ProtocolVersion::UNKNOWN);
49 return;
50 }
51 DeviceTransact(std::move(version_cmd),
52 base::Bind(&U2fDevice::OnVersionComplete,
53 weak_factory_.GetWeakPtr(), callback));
54 }
55
56 void U2fDevice::OnRegisterComplete(
57 const MessageCallback& callback,
58 bool success,
59 scoped_refptr<U2fApduResponse> register_response) {
60 NOTIMPLEMENTED();
61 }
62
63 void U2fDevice::OnSignComplete(const MessageCallback& callback,
64 bool success,
65 scoped_refptr<U2fApduResponse> sign_response) {
66 NOTIMPLEMENTED();
67 }
68
69 void U2fDevice::OnVersionComplete(
70 const VersionCallback& callback,
71 bool success,
72 scoped_refptr<U2fApduResponse> version_response) {
73 if (success && version_response &&
74 version_response->status() == U2fApduResponse::Status::SW_NO_ERROR &&
75 version_response->data() ==
76 std::vector<uint8_t>({'U', '2', 'F', '_', 'V', '2'})) {
77 callback.Run(success, ProtocolVersion::U2F_V2);
78 return;
79 }
80 callback.Run(success, ProtocolVersion::UNKNOWN);
81 }
82
83 void U2fDevice::OnLegacyVersionComplete(
84 const VersionCallback& callback,
85 bool success,
86 scoped_refptr<U2fApduResponse> legacy_version_response) {
87 NOTIMPLEMENTED();
88 }
89
90 } // namespace device
OLDNEW
« 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