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

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

Issue 2655853006: Define FIDO U2f Device abstraction (Closed)
Patch Set: Define FIDO U2f Device abstraction 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
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 <vector>
6
7 #include "base/bind.h"
8 #include "u2f_apdu_command.h"
9 #include "u2f_device.h"
10 #include "u2f_responses.h"
11
12 namespace device {
13
14 U2fDevice::U2fDevice() {}
15
16 U2fDevice::~U2fDevice() {}
17
18 void U2fDevice::Register(const std::vector<uint8_t>& app_param,
19 U2fDevice::ProtocolVersion version,
20 const std::vector<uint8_t>& challenge_param,
21 const RegistrationCallback& callback) {
22 scoped_refptr<U2fApduCommand> register_cmd =
23 BuildRegisterCommand(app_param, challenge_param);
24 // TODO Stubbed function. Should call DeviceTransact with given params.
25 }
26
27 void U2fDevice::Sign(const std::vector<uint8_t>& app_param,
28 const std::vector<uint8_t>& challenge_param,
29 const std::vector<uint8_t>& key_handle,
30 const SignCallback& callback) {
31 scoped_refptr<U2fApduCommand> sign_cmd =
32 BuildSignCommand(app_param, challenge_param, key_handle);
33 // TODO Stubbed function. Should call DeviceTransact with given params.
34 }
35
36 void U2fDevice::GetVersion(const GetVersionCallback& callback) {
37 scoped_refptr<U2fApduCommand> version_cmd = BuildGetVersionCommand();
38 // TODO Stubbed function. Should call DeviceTransact with given params.
39 }
40
41 // static
42 scoped_refptr<U2fApduCommand> U2fDevice::BuildRegisterCommand(
43 const std::vector<uint8_t>& appid_digest,
44 const std::vector<uint8_t>& challenge_digest) {
45 if (appid_digest.size() != kAppIdDigestLen ||
46 challenge_digest.size() != kChallengeDigestLen)
47 return nullptr;
48
49 scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
50 std::vector<uint8_t> data(challenge_digest.begin(), challenge_digest.end());
51 data.insert(data.end(), appid_digest.begin(), appid_digest.end());
52 command->set_ins(kInsU2fEnroll);
53 command->set_p1(kP1TupRequiredConsumed);
54 command->set_data(data);
55 return command;
56 }
57
58 // static
59 scoped_refptr<U2fApduCommand> U2fDevice::BuildGetVersionCommand() {
60 scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
61 command->set_ins(kInsU2fVersion);
62 return command;
63 }
64
65 // static
66 scoped_refptr<U2fApduCommand> U2fDevice::BuildGetLegacyVersionCommand() {
67 scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
68 command->set_ins(kInsU2fVersion);
69 command->set_data(std::vector<uint8_t>(2, 0));
70 return command;
71 }
72
73 // static
74 scoped_refptr<U2fApduCommand> U2fDevice::BuildSignCommand(
75 const std::vector<uint8_t>& appid_digest,
76 const std::vector<uint8_t>& challenge_digest,
77 const std::vector<uint8_t>& key_handle) {
78 if (appid_digest.size() != kAppIdDigestLen ||
79 challenge_digest.size() != kChallengeDigestLen ||
80 key_handle.size() > kMaxKeyHandleLength)
81 return nullptr;
Reilly Grant (use Gerrit) 2017/01/27 02:06:30 nit: braces around if body when the condition is m
82
83 scoped_refptr<U2fApduCommand> command = U2fApduCommand::Create();
84 std::vector<uint8_t> data(challenge_digest.begin(), challenge_digest.end());
85 data.insert(data.end(), appid_digest.begin(), appid_digest.end());
86 data.push_back(static_cast<uint8_t>(key_handle.size()));
87 data.insert(data.end(), key_handle.begin(), key_handle.end());
88 command->set_ins(kInsU2fSign);
89 command->set_p1(kP1TupRequiredConsumed);
90 command->set_data(data);
91 return command;
92 }
93
94 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698