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

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

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/BUILD.gn ('k') | device/u2f/u2f_device.cc » ('j') | 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 #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/memory/weak_ptr.h"
12 #include "u2f_apdu_response.h"
13
14 namespace device {
15
16 class U2fApduCommand;
17
18 // Device abstraction for an individual U2F device. A U2F device defines the
19 // standardized Register, Sign, and GetVersion methods.
20 class U2fDevice {
21 public:
22 enum class ProtocolVersion {
23 U2F_V2,
24 UNKNOWN,
25 };
26 enum class ReturnCode { SUCCESS, HW_FAILURE, INVALID_PARAMS };
27
28 using MessageCallback =
29 base::Callback<void(ReturnCode, std::vector<uint8_t>)>;
30 using VersionCallback =
31 base::Callback<void(bool success, ProtocolVersion version)>;
32 using DeviceCallback =
33 base::Callback<void(bool success,
34 scoped_refptr<U2fApduResponse> response)>;
35
36 ~U2fDevice();
37
38 // Raw messages parameters are defined by the specification at
39 // https://fidoalliance.org/specs/fido-u2f-v1.0-nfc-bt-amendment-20150514/fido -u2f-raw-message-formats.html
40 void Register(const std::vector<uint8_t>& appid_digest,
41 const ProtocolVersion version,
42 const std::vector<uint8_t>& challenge_digest,
43 const MessageCallback& callback);
44 void Version(const VersionCallback& callback);
45 void Sign(const std::vector<uint8_t>& appid_digest,
46 const std::vector<uint8_t>& challenge_digest,
47 const std::vector<uint8_t>& key_handle,
48 const MessageCallback& callback);
49
50 protected:
51 U2fDevice();
52
53 // Pure virtual function defined by each device type, implementing
54 // the device communication transaction.
55 virtual void DeviceTransact(scoped_refptr<U2fApduCommand> command,
56 const DeviceCallback& callback) = 0;
57
58 private:
59 // TODO Callback functions for device calls
60 void OnRegisterComplete(const MessageCallback& callback,
61 bool success,
62 scoped_refptr<U2fApduResponse> register_response);
63 void OnSignComplete(const MessageCallback& callback,
64 bool success,
65 scoped_refptr<U2fApduResponse> sign_response);
66 void OnVersionComplete(const VersionCallback& callback,
67 bool success,
68 scoped_refptr<U2fApduResponse> version_response);
69 void OnLegacyVersionComplete(
70 const VersionCallback& callback,
71 bool success,
72 scoped_refptr<U2fApduResponse> legacy_version_response);
73
74 base::WeakPtrFactory<U2fDevice> weak_factory_;
75
76 DISALLOW_COPY_AND_ASSIGN(U2fDevice);
77 };
78
79 } // namespace device
80
81 #endif // DEVICE_U2F_U2F_DEVICE_H_
OLDNEW
« no previous file with comments | « device/u2f/BUILD.gn ('k') | device/u2f/u2f_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698