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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 INVALID_PARAMS, | 29 INVALID_PARAMS, |
30 CONDITIONS_NOT_SATISFIED, | 30 CONDITIONS_NOT_SATISFIED, |
31 }; | 31 }; |
32 | 32 |
33 using MessageCallback = | 33 using MessageCallback = |
34 base::Callback<void(ReturnCode, std::vector<uint8_t>)>; | 34 base::Callback<void(ReturnCode, std::vector<uint8_t>)>; |
35 using VersionCallback = | 35 using VersionCallback = |
36 base::Callback<void(bool success, ProtocolVersion version)>; | 36 base::Callback<void(bool success, ProtocolVersion version)>; |
37 using DeviceCallback = | 37 using DeviceCallback = |
38 base::Callback<void(bool success, | 38 base::Callback<void(bool success, |
39 scoped_refptr<U2fApduResponse> response)>; | 39 std::unique_ptr<U2fApduResponse> response)>; |
40 using WinkCallback = base::Callback<void()>; | 40 using WinkCallback = base::Callback<void()>; |
41 | 41 |
42 ~U2fDevice(); | 42 ~U2fDevice(); |
43 | 43 |
44 // Raw messages parameters are defined by the specification at | 44 // Raw messages parameters are defined by the specification at |
45 // 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 |
46 void Register(const std::vector<uint8_t>& appid_digest, | 46 void Register(const std::vector<uint8_t>& appid_digest, |
47 const std::vector<uint8_t>& challenge_digest, | 47 const std::vector<uint8_t>& challenge_digest, |
48 const MessageCallback& callback); | 48 const MessageCallback& callback); |
49 void Version(const VersionCallback& callback); | 49 void Version(const VersionCallback& callback); |
50 void Sign(const std::vector<uint8_t>& appid_digest, | 50 void Sign(const std::vector<uint8_t>& appid_digest, |
51 const std::vector<uint8_t>& challenge_digest, | 51 const std::vector<uint8_t>& challenge_digest, |
52 const std::vector<uint8_t>& key_handle, | 52 const std::vector<uint8_t>& key_handle, |
53 const MessageCallback& callback); | 53 const MessageCallback& callback); |
54 virtual void TryWink(const WinkCallback& callback) = 0; | 54 virtual void TryWink(const WinkCallback& callback) = 0; |
55 virtual std::string GetId() = 0; | 55 virtual std::string GetId() = 0; |
56 | 56 |
57 protected: | 57 protected: |
58 static constexpr uint8_t kWinkCapability = 0x01; | 58 static constexpr uint8_t kWinkCapability = 0x01; |
59 static constexpr uint8_t kLockCapability = 0x02; | 59 static constexpr uint8_t kLockCapability = 0x02; |
60 static constexpr uint32_t kBroadcastChannel = 0xffffffff; | 60 static constexpr uint32_t kBroadcastChannel = 0xffffffff; |
61 | 61 |
62 U2fDevice(); | 62 U2fDevice(); |
63 | 63 |
64 // Pure virtual function defined by each device type, implementing | 64 // Pure virtual function defined by each device type, implementing |
65 // the device communication transaction. | 65 // the device communication transaction. |
66 virtual void DeviceTransact(scoped_refptr<U2fApduCommand> command, | 66 virtual void DeviceTransact(std::unique_ptr<U2fApduCommand> command, |
67 const DeviceCallback& callback) = 0; | 67 const DeviceCallback& callback) = 0; |
68 | 68 |
69 uint32_t channel_id_; | 69 uint32_t channel_id_; |
70 uint8_t capabilities_; | 70 uint8_t capabilities_; |
71 | 71 |
72 private: | 72 private: |
73 void OnRegisterComplete(const MessageCallback& callback, | 73 void OnRegisterComplete(const MessageCallback& callback, |
74 bool success, | 74 bool success, |
75 scoped_refptr<U2fApduResponse> register_response); | 75 std::unique_ptr<U2fApduResponse> register_response); |
76 void OnSignComplete(const MessageCallback& callback, | 76 void OnSignComplete(const MessageCallback& callback, |
77 bool success, | 77 bool success, |
78 scoped_refptr<U2fApduResponse> sign_response); | 78 std::unique_ptr<U2fApduResponse> sign_response); |
79 void OnVersionComplete(const VersionCallback& callback, | 79 void OnVersionComplete(const VersionCallback& callback, |
80 bool success, | 80 bool success, |
81 scoped_refptr<U2fApduResponse> version_response); | 81 std::unique_ptr<U2fApduResponse> version_response); |
82 void OnLegacyVersionComplete( | 82 void OnLegacyVersionComplete( |
83 const VersionCallback& callback, | 83 const VersionCallback& callback, |
84 bool success, | 84 bool success, |
85 scoped_refptr<U2fApduResponse> legacy_version_response); | 85 std::unique_ptr<U2fApduResponse> legacy_version_response); |
86 void OnWink(const WinkCallback& callback, | 86 void OnWink(const WinkCallback& callback, |
87 bool success, | 87 bool success, |
88 scoped_refptr<U2fApduResponse> response); | 88 std::unique_ptr<U2fApduResponse> response); |
89 | 89 |
90 base::WeakPtrFactory<U2fDevice> weak_factory_; | 90 base::WeakPtrFactory<U2fDevice> weak_factory_; |
91 | 91 |
92 DISALLOW_COPY_AND_ASSIGN(U2fDevice); | 92 DISALLOW_COPY_AND_ASSIGN(U2fDevice); |
93 }; | 93 }; |
94 | 94 |
95 } // namespace device | 95 } // namespace device |
96 | 96 |
97 #endif // DEVICE_U2F_U2F_DEVICE_H_ | 97 #endif // DEVICE_U2F_U2F_DEVICE_H_ |
OLD | NEW |