| OLD | NEW |
| (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_ |
| OLD | NEW |