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

Side by Side 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 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 == nullptr) {
Reilly Grant (use Gerrit) 2017/02/16 02:03:15 if (!register_cmd)
22 callback.Run(ReturnCode::INVALID_PARAMS, std::vector<uint8_t>());
23 return;
24 }
25 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
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 == nullptr) {
Reilly Grant (use Gerrit) 2017/02/16 02:03:14 if (!sign_cmd)
37 callback.Run(ReturnCode::INVALID_PARAMS, std::vector<uint8_t>());
38 return;
39 }
40 DeviceTransact(sign_cmd, base::Bind(&U2fDevice::OnSignComplete,
41 weak_factory_.GetWeakPtr(), callback));
42 }
43
44 void U2fDevice::Version(const VersionCallback& callback) {
45 scoped_refptr<U2fApduCommand> version_cmd = U2fApduCommand::CreateVersion();
46 if (version_cmd == nullptr) {
Reilly Grant (use Gerrit) 2017/02/16 02:03:14 if (!version_cmd)
47 callback.Run(false, ProtocolVersion::UNKNOWN);
48 return;
49 }
50 DeviceTransact(version_cmd, base::Bind(&U2fDevice::OnVersionComplete,
51 weak_factory_.GetWeakPtr(), callback));
52 }
53
54 // TODO
Reilly Grant (use Gerrit) 2017/02/16 02:03:15 Put a NOTIMPLEMENTED(); in the body instead of the
55 void U2fDevice::OnRegisterComplete(
56 const MessageCallback& callback,
57 bool success,
58 scoped_refptr<U2fApduResponse> register_response) {}
59
60 // TODO
Reilly Grant (use Gerrit) 2017/02/16 02:03:14 Put a NOTIMPLEMENTED(); in the body instead of the
61 void U2fDevice::OnSignComplete(const MessageCallback& callback,
62 bool success,
63 scoped_refptr<U2fApduResponse> sign_response) {}
64
65 void U2fDevice::OnVersionComplete(
66 const VersionCallback& callback,
67 bool success,
68 scoped_refptr<U2fApduResponse> version_response) {
69 if (success && version_response != nullptr &&
Reilly Grant (use Gerrit) 2017/02/16 02:03:14 && version_response &&
70 version_response->status() == U2fApduResponse::Status::SW_NO_ERROR &&
71 version_response->data() ==
72 std::vector<uint8_t>({'U', '2', 'F', '_', 'V', '2'})) {
73 callback.Run(success, ProtocolVersion::U2F_V2);
74 return;
75 }
76 callback.Run(success, ProtocolVersion::UNKNOWN);
77 }
78
79 // TODO
Reilly Grant (use Gerrit) 2017/02/16 02:03:14 Put a NOTIMPLEMENTED(); in the body instead of the
80 void U2fDevice::OnLegacyVersionComplete(
81 const VersionCallback& callback,
82 bool success,
83 scoped_refptr<U2fApduResponse> legacy_version_response) {}
84
85 } // 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