OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DEVICE_U2F_U2F_DEVICE_H_ | 5 #ifndef DEVICE_U2F_U2F_DEVICE_H_ |
6 #define DEVICE_U2F_U2F_DEVICE_H_ | 6 #define DEVICE_U2F_U2F_DEVICE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "u2f_apdu_response.h" | 12 #include "u2f_apdu_response.h" |
13 | 13 |
14 namespace device { | 14 namespace device { |
15 | 15 |
16 class U2fApduCommand; | 16 class U2fApduCommand; |
17 | 17 |
18 // Device abstraction for an individual U2F device. A U2F device defines the | 18 // Device abstraction for an individual U2F device. A U2F device defines the |
19 // standardized Register, Sign, and GetVersion methods. | 19 // standardized Register, Sign, and GetVersion methods. |
20 class U2fDevice { | 20 class U2fDevice { |
21 public: | 21 public: |
22 enum class ProtocolVersion { | 22 enum class ProtocolVersion { |
23 U2F_V2, | 23 U2F_V2, |
24 UNKNOWN, | 24 UNKNOWN, |
25 }; | 25 }; |
26 enum class ReturnCode { SUCCESS, HW_FAILURE, INVALID_PARAMS }; | 26 enum class ReturnCode : uint8_t { |
27 SUCCESS, | |
28 FAILURE, | |
29 INVALID_PARAMS, | |
30 CONDITIONS_NOT_SATISFIED, | |
31 }; | |
27 | 32 |
28 using MessageCallback = | 33 using MessageCallback = |
29 base::Callback<void(ReturnCode, std::vector<uint8_t>)>; | 34 base::Callback<void(ReturnCode, std::vector<uint8_t>)>; |
30 using VersionCallback = | 35 using VersionCallback = |
31 base::Callback<void(bool success, ProtocolVersion version)>; | 36 base::Callback<void(bool success, ProtocolVersion version)>; |
32 using DeviceCallback = | 37 using DeviceCallback = |
33 base::Callback<void(bool success, | 38 base::Callback<void(bool success, |
34 scoped_refptr<U2fApduResponse> response)>; | 39 scoped_refptr<U2fApduResponse> response)>; |
40 using WinkCallback = base::Callback<void()>; | |
35 | 41 |
36 ~U2fDevice(); | 42 ~U2fDevice(); |
37 | 43 |
38 // Raw messages parameters are defined by the specification at | 44 // 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 | 45 // 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, | 46 void Register(const std::vector<uint8_t>& appid_digest, |
41 const ProtocolVersion version, | |
42 const std::vector<uint8_t>& challenge_digest, | 47 const std::vector<uint8_t>& challenge_digest, |
43 const MessageCallback& callback); | 48 const MessageCallback& callback); |
44 void Version(const VersionCallback& callback); | 49 void Version(const VersionCallback& callback); |
45 void Sign(const std::vector<uint8_t>& appid_digest, | 50 void Sign(const std::vector<uint8_t>& appid_digest, |
46 const std::vector<uint8_t>& challenge_digest, | 51 const std::vector<uint8_t>& challenge_digest, |
47 const std::vector<uint8_t>& key_handle, | 52 const std::vector<uint8_t>& key_handle, |
48 const MessageCallback& callback); | 53 const MessageCallback& callback); |
54 virtual void TryWink(const WinkCallback& callback) = 0; | |
55 virtual std::string Id() = 0; | |
Reilly Grant (use Gerrit)
2017/03/06 20:49:23
GetId
Casey Piper
2017/03/07 00:53:27
Done.
| |
49 | 56 |
50 protected: | 57 protected: |
58 static constexpr uint8_t kWinkCapability = 0x01; | |
59 static constexpr uint8_t kLockCapability = 0x02; | |
60 static constexpr uint32_t kBroadcastChannel = 0xffffffff; | |
61 | |
51 U2fDevice(); | 62 U2fDevice(); |
52 | 63 |
53 // Pure virtual function defined by each device type, implementing | 64 // Pure virtual function defined by each device type, implementing |
54 // the device communication transaction. | 65 // the device communication transaction. |
55 virtual void DeviceTransact(scoped_refptr<U2fApduCommand> command, | 66 virtual void DeviceTransact(scoped_refptr<U2fApduCommand> command, |
56 const DeviceCallback& callback) = 0; | 67 const DeviceCallback& callback) = 0; |
57 | 68 |
69 uint32_t channel_id_; | |
70 uint8_t capabilities_; | |
71 | |
58 private: | 72 private: |
59 // TODO Callback functions for device calls | |
60 void OnRegisterComplete(const MessageCallback& callback, | 73 void OnRegisterComplete(const MessageCallback& callback, |
61 bool success, | 74 bool success, |
62 scoped_refptr<U2fApduResponse> register_response); | 75 scoped_refptr<U2fApduResponse> register_response); |
63 void OnSignComplete(const MessageCallback& callback, | 76 void OnSignComplete(const MessageCallback& callback, |
64 bool success, | 77 bool success, |
65 scoped_refptr<U2fApduResponse> sign_response); | 78 scoped_refptr<U2fApduResponse> sign_response); |
66 void OnVersionComplete(const VersionCallback& callback, | 79 void OnVersionComplete(const VersionCallback& callback, |
67 bool success, | 80 bool success, |
68 scoped_refptr<U2fApduResponse> version_response); | 81 scoped_refptr<U2fApduResponse> version_response); |
69 void OnLegacyVersionComplete( | 82 void OnLegacyVersionComplete( |
70 const VersionCallback& callback, | 83 const VersionCallback& callback, |
71 bool success, | 84 bool success, |
72 scoped_refptr<U2fApduResponse> legacy_version_response); | 85 scoped_refptr<U2fApduResponse> legacy_version_response); |
86 void OnWink(const WinkCallback& callback, | |
87 bool success, | |
88 scoped_refptr<U2fApduResponse> response); | |
73 | 89 |
74 base::WeakPtrFactory<U2fDevice> weak_factory_; | 90 base::WeakPtrFactory<U2fDevice> weak_factory_; |
75 | 91 |
76 DISALLOW_COPY_AND_ASSIGN(U2fDevice); | 92 DISALLOW_COPY_AND_ASSIGN(U2fDevice); |
77 }; | 93 }; |
78 | 94 |
79 } // namespace device | 95 } // namespace device |
80 | 96 |
81 #endif // DEVICE_U2F_U2F_DEVICE_H_ | 97 #endif // DEVICE_U2F_U2F_DEVICE_H_ |
OLD | NEW |