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

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

Issue 2655853006: Define FIDO U2f Device abstraction (Closed)
Patch Set: Define FIDO U2f Device abstraction Created 3 years, 11 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 #ifndef DEVICE_U2F_U2F_DEVICE_H_
6 #define DEVICE_U2F_U2F_DEVICE_H_
7
8 #include <vector>
9
10 #include "base/callback.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/ref_counted.h"
13 #include "u2f_apdu_response.h"
14
15 namespace device {
16
17 class U2fApduCommand;
18 class U2fRegisterResponse;
19 class U2fSignResponse;
20
21 // Device abstraction for an individual U2f device. A U2f device defines the
22 // standardized Register, Sign, and GetVersion methods.
23 class U2fDevice : public base::RefCountedThreadSafe<U2fDevice> {
Reilly Grant (use Gerrit) 2017/01/27 02:06:30 I haven't commented on this in previous reviews be
24 public:
25 enum class ProtocolVersion {
26 U2F_V2,
27 };
28
29 typedef base::Callback<void(
30 bool success,
31 scoped_refptr<U2fRegisterResponse> registration_response)>
32 RegistrationCallback;
33 typedef base::Callback<void(bool success, ProtocolVersion)>
34 GetVersionCallback;
35 typedef base::Callback<void(bool success,
36 scoped_refptr<U2fSignResponse> sign_response)>
37 SignCallback;
38 typedef base::Callback<void(bool success,
39 scoped_refptr<U2fApduResponse> response)>
40 DeviceCallback;
Reilly Grant (use Gerrit) 2017/01/27 02:06:30 Please use "using foo = bar" instead of "typedef b
41 static constexpr size_t kChallengeDigestLen = 32;
42 static constexpr size_t kAppIdDigestLen = 32;
43
44 U2fDevice();
45
46 // Raw messages parameters are defined by the specification at
47 // https://fidoalliance.org/specs/fido-u2f-v1.0-nfc-bt-amendment-20150514/fido -u2f-raw-message-formats.html
48 void Register(const std::vector<uint8_t>& appid_digest,
49 const ProtocolVersion version,
50 const std::vector<uint8_t>& challenge_digest,
51 const RegistrationCallback& callback);
52 void GetVersion(const GetVersionCallback& callback);
53 void Sign(const std::vector<uint8_t>& appid_digest,
54 const std::vector<uint8_t>& challenge_digest,
55 const std::vector<uint8_t>& key_handle,
56 const SignCallback& callback);
57
58 protected:
59 virtual ~U2fDevice();
60
61 // Pure virtual function defined by each device type, implementing
62 // the device communication transaction.
63 virtual void DeviceTransact(scoped_refptr<U2fApduCommand> command,
64 DeviceCallback callback) = 0;
Reilly Grant (use Gerrit) 2017/01/27 02:06:30 const DeviceCallback&
65
66 private:
67 friend class base::RefCountedThreadSafe<U2fDevice>;
68 FRIEND_TEST_ALL_PREFIXES(U2fDeviceTest, TestBuildApdu);
69
70 // APDU instructions
71 static constexpr uint8_t kInsU2fEnroll = 0x01;
72 static constexpr uint8_t kInsU2fSign = 0x02;
73 static constexpr uint8_t kInsU2fVersion = 0x03;
74 static constexpr uint8_t kInsGetResponse = 0xC0;
juanlang (chromium.org) 2017/01/27 18:52:21 Pretty sure this isn't used?
75 // P1 instructions
76 static constexpr uint8_t kP1TupRequired = 0x01;
77 static constexpr uint8_t kP1TupConsumed = 0x02;
78 static constexpr uint8_t kP1TupRequiredConsumed =
79 kP1TupRequired | kP1TupConsumed;
80 static constexpr size_t kMaxKeyHandleLength = 255;
81
82 static scoped_refptr<U2fApduCommand> BuildRegisterCommand(
83 const std::vector<uint8_t>& appid_digest,
84 const std::vector<uint8_t>& challenge_digest);
85 static scoped_refptr<U2fApduCommand> BuildGetVersionCommand();
86 // Early U2F drafts defined a non-ISO 7816-4 conforming layout
87 static scoped_refptr<U2fApduCommand> BuildGetLegacyVersionCommand();
88 static scoped_refptr<U2fApduCommand> BuildSignCommand(
89 const std::vector<uint8_t>& appid_digest,
90 const std::vector<uint8_t>& challenge_digest,
91 const std::vector<uint8_t>& key_handle);
Reilly Grant (use Gerrit) 2017/01/27 02:06:30 Since these methods don't depend on any properties
92 // TODO Callback functions for device calls
93 void OnRegisterComplete(RegistrationCallback callback,
Reilly Grant (use Gerrit) 2017/01/27 02:06:30 const RegistrationCallback& (ditto for other call
94 bool success,
95 scoped_refptr<U2fApduResponse> register_response);
96 void OnSignComplete(SignCallback callback,
97 bool success,
98 scoped_refptr<U2fApduResponse> sign_response);
99 void OnGetVersionComplete(
100 GetVersionCallback callback,
101 bool success,
102 scoped_refptr<U2fApduResponse> get_version_response);
103 void OnGetLegacyVersionComplete(
104 GetVersionCallback callback,
105 bool success,
106 scoped_refptr<U2fApduResponse> legacy_version_response);
107 };
108
109 } // namespace device
110 #endif // DEVICE_U2F_U2F_DEVICE_H_
OLDNEW
« no previous file with comments | « device/u2f/BUILD.gn ('k') | device/u2f/u2f_device.cc » ('j') | device/u2f/u2f_device.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698