| 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_APDU_COMMAND_H_ | 5 #ifndef DEVICE_U2F_U2F_APDU_COMMAND_H_ |
| 6 #define DEVICE_U2F_U2F_APDU_COMMAND_H_ | 6 #define DEVICE_U2F_U2F_APDU_COMMAND_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // Returns serialized message data | 30 // Returns serialized message data |
| 31 std::vector<uint8_t> GetEncodedCommand() const; | 31 std::vector<uint8_t> GetEncodedCommand() const; |
| 32 void set_cla(uint8_t cla) { cla_ = cla; } | 32 void set_cla(uint8_t cla) { cla_ = cla; } |
| 33 void set_ins(uint8_t ins) { ins_ = ins; } | 33 void set_ins(uint8_t ins) { ins_ = ins; } |
| 34 void set_p1(uint8_t p1) { p1_ = p1; } | 34 void set_p1(uint8_t p1) { p1_ = p1; } |
| 35 void set_p2(uint8_t p2) { p2_ = p2; } | 35 void set_p2(uint8_t p2) { p2_ = p2; } |
| 36 void set_data(const std::vector<uint8_t>& data) { data_ = data; } | 36 void set_data(const std::vector<uint8_t>& data) { data_ = data; } |
| 37 void set_response_length(size_t response_length) { | 37 void set_response_length(size_t response_length) { |
| 38 response_length_ = response_length; | 38 response_length_ = response_length; |
| 39 } | 39 } |
| 40 void set_suffix(const std::vector<uint8_t>& suffix) { suffix_ = suffix; } |
| 41 static scoped_refptr<U2fApduCommand> CreateRegister( |
| 42 const std::vector<uint8_t>& appid_digest, |
| 43 const std::vector<uint8_t>& challenge_digest); |
| 44 static scoped_refptr<U2fApduCommand> CreateVersion(); |
| 45 // Early U2F drafts defined a non-ISO 7816-4 conforming layout |
| 46 static scoped_refptr<U2fApduCommand> CreateLegacyVersion(); |
| 47 static scoped_refptr<U2fApduCommand> CreateSign( |
| 48 const std::vector<uint8_t>& appid_digest, |
| 49 const std::vector<uint8_t>& challenge_digest, |
| 50 const std::vector<uint8_t>& key_handle); |
| 40 | 51 |
| 41 private: | 52 private: |
| 42 friend class base::RefCountedThreadSafe<U2fApduCommand>; | 53 friend class base::RefCountedThreadSafe<U2fApduCommand>; |
| 43 friend class U2fApduBuilder; | 54 friend class U2fApduBuilder; |
| 44 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestDeserializeBasic); | 55 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestDeserializeBasic); |
| 45 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestDeserializeComplex); | 56 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestDeserializeComplex); |
| 46 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestSerializeEdgeCases); | 57 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestSerializeEdgeCases); |
| 58 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestCreateSign); |
| 59 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestCreateRegister); |
| 60 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestCreateVersion); |
| 61 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestCreateLegacyVersion); |
| 47 | 62 |
| 48 static constexpr size_t kApduMinHeader = 4; | 63 static constexpr size_t kApduMinHeader = 4; |
| 49 static constexpr size_t kApduMaxHeader = 7; | 64 static constexpr size_t kApduMaxHeader = 7; |
| 50 // As defined in ISO7816-4, extended length APDU request data is limited to | 65 // As defined in ISO7816-4, extended length APDU request data is limited to |
| 51 // 16 bits in length with a maximum value of 65535. Response data length is | 66 // 16 bits in length with a maximum value of 65535. Response data length is |
| 52 // also limited to 16 bits in length with a value of 0x0000 corresponding to | 67 // also limited to 16 bits in length with a value of 0x0000 corresponding to |
| 53 // a length of 65536 | 68 // a length of 65536 |
| 54 static constexpr size_t kApduMaxDataLength = 65535; | 69 static constexpr size_t kApduMaxDataLength = 65535; |
| 55 static constexpr size_t kApduMaxResponseLength = 65536; | 70 static constexpr size_t kApduMaxResponseLength = 65536; |
| 56 static constexpr size_t kApduMaxLength = | 71 static constexpr size_t kApduMaxLength = |
| 57 kApduMaxDataLength + kApduMaxHeader + 2; | 72 kApduMaxDataLength + kApduMaxHeader + 2; |
| 73 // APDU instructions |
| 74 static constexpr uint8_t kInsU2fEnroll = 0x01; |
| 75 static constexpr uint8_t kInsU2fSign = 0x02; |
| 76 static constexpr uint8_t kInsU2fVersion = 0x03; |
| 77 // P1 instructions |
| 78 static constexpr uint8_t kP1TupRequired = 0x01; |
| 79 static constexpr uint8_t kP1TupConsumed = 0x02; |
| 80 static constexpr uint8_t kP1TupRequiredConsumed = |
| 81 kP1TupRequired | kP1TupConsumed; |
| 82 static constexpr size_t kMaxKeyHandleLength = 255; |
| 83 static constexpr size_t kChallengeDigestLen = 32; |
| 84 static constexpr size_t kAppIdDigestLen = 32; |
| 58 | 85 |
| 59 U2fApduCommand(); | 86 U2fApduCommand(); |
| 60 U2fApduCommand(uint8_t cla, | 87 U2fApduCommand(uint8_t cla, |
| 61 uint8_t ins, | 88 uint8_t ins, |
| 62 uint8_t p1, | 89 uint8_t p1, |
| 63 uint8_t p2, | 90 uint8_t p2, |
| 64 size_t response_length, | 91 size_t response_length, |
| 65 std::vector<uint8_t> data); | 92 std::vector<uint8_t> data, |
| 93 std::vector<uint8_t> suffix); |
| 66 ~U2fApduCommand(); | 94 ~U2fApduCommand(); |
| 67 | 95 |
| 68 uint8_t cla_; | 96 uint8_t cla_; |
| 69 uint8_t ins_; | 97 uint8_t ins_; |
| 70 uint8_t p1_; | 98 uint8_t p1_; |
| 71 uint8_t p2_; | 99 uint8_t p2_; |
| 72 size_t response_length_; | 100 size_t response_length_; |
| 73 std::vector<uint8_t> data_; | 101 std::vector<uint8_t> data_; |
| 102 std::vector<uint8_t> suffix_; |
| 74 }; | 103 }; |
| 75 } // namespace device | 104 } // namespace device |
| 76 | 105 |
| 77 #endif // DEVICE_U2F_U2F_APDU_COMMAND_H_ | 106 #endif // DEVICE_U2F_U2F_APDU_COMMAND_H_ |
| OLD | NEW |