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

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

Issue 2665493002: Add builders to APDU command class (Closed)
Patch Set: Remove unused constant 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 | « no previous file | device/u2f/u2f_apdu_command.cc » ('j') | device/u2f/u2f_apdu_command.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 static scoped_refptr<U2fApduCommand> BuildRegisterCommand(
juanlang (chromium.org) 2017/01/28 00:08:39 Maybe remove Command? The caller will be using U2f
Reilly Grant (use Gerrit) 2017/01/28 00:29:29 I suggest U2fApduCommand::CreateRegister to match
Casey Piper 2017/01/30 21:51:41 Done.
Casey Piper 2017/01/30 21:51:41 Acknowledged.
41 const std::vector<uint8_t>& appid_digest,
42 const std::vector<uint8_t>& challenge_digest);
43 static scoped_refptr<U2fApduCommand> BuildGetVersionCommand();
juanlang (chromium.org) 2017/01/28 00:08:39 Remove Get, it's cleaner that way.
Casey Piper 2017/01/30 21:51:41 Done.
44 // Early U2F drafts defined a non-ISO 7816-4 conforming layout
45 static scoped_refptr<U2fApduCommand> BuildGetLegacyVersionCommand();
juanlang (chromium.org) 2017/01/28 00:08:39 Ditto.
Casey Piper 2017/01/30 21:51:41 Done.
46 static scoped_refptr<U2fApduCommand> BuildSignCommand(
47 const std::vector<uint8_t>& appid_digest,
48 const std::vector<uint8_t>& challenge_digest,
49 const std::vector<uint8_t>& key_handle);
40 50
41 private: 51 private:
42 friend class base::RefCountedThreadSafe<U2fApduCommand>; 52 friend class base::RefCountedThreadSafe<U2fApduCommand>;
43 friend class U2fApduBuilder; 53 friend class U2fApduBuilder;
44 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestDeserializeBasic); 54 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestDeserializeBasic);
45 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestDeserializeComplex); 55 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestDeserializeComplex);
46 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestSerializeEdgeCases); 56 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestSerializeEdgeCases);
57 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestBuildApdu);
47 58
48 static constexpr size_t kApduMinHeader = 4; 59 static constexpr size_t kApduMinHeader = 4;
49 static constexpr size_t kApduMaxHeader = 7; 60 static constexpr size_t kApduMaxHeader = 7;
50 // As defined in ISO7816-4, extended length APDU request data is limited to 61 // 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 62 // 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 63 // also limited to 16 bits in length with a value of 0x0000 corresponding to
53 // a length of 65536 64 // a length of 65536
54 static constexpr size_t kApduMaxDataLength = 65535; 65 static constexpr size_t kApduMaxDataLength = 65535;
55 static constexpr size_t kApduMaxResponseLength = 65536; 66 static constexpr size_t kApduMaxResponseLength = 65536;
56 static constexpr size_t kApduMaxLength = 67 static constexpr size_t kApduMaxLength =
57 kApduMaxDataLength + kApduMaxHeader + 2; 68 kApduMaxDataLength + kApduMaxHeader + 2;
69 // APDU instructions
70 static constexpr uint8_t kInsU2fEnroll = 0x01;
71 static constexpr uint8_t kInsU2fSign = 0x02;
72 static constexpr uint8_t kInsU2fVersion = 0x03;
73 // P1 instructions
74 static constexpr uint8_t kP1TupRequired = 0x01;
75 static constexpr uint8_t kP1TupConsumed = 0x02;
76 static constexpr uint8_t kP1TupRequiredConsumed =
77 kP1TupRequired | kP1TupConsumed;
78 static constexpr size_t kMaxKeyHandleLength = 255;
79 static constexpr size_t kChallengeDigestLen = 32;
80 static constexpr size_t kAppIdDigestLen = 32;
58 81
59 U2fApduCommand(); 82 U2fApduCommand();
60 U2fApduCommand(uint8_t cla, 83 U2fApduCommand(uint8_t cla,
61 uint8_t ins, 84 uint8_t ins,
62 uint8_t p1, 85 uint8_t p1,
63 uint8_t p2, 86 uint8_t p2,
64 size_t response_length, 87 size_t response_length,
65 std::vector<uint8_t> data); 88 std::vector<uint8_t> data);
66 ~U2fApduCommand(); 89 ~U2fApduCommand();
67 90
68 uint8_t cla_; 91 uint8_t cla_;
69 uint8_t ins_; 92 uint8_t ins_;
70 uint8_t p1_; 93 uint8_t p1_;
71 uint8_t p2_; 94 uint8_t p2_;
72 size_t response_length_; 95 size_t response_length_;
73 std::vector<uint8_t> data_; 96 std::vector<uint8_t> data_;
74 }; 97 };
75 } // namespace device 98 } // namespace device
76 99
77 #endif // DEVICE_U2F_U2F_APDU_COMMAND_H_ 100 #endif // DEVICE_U2F_U2F_APDU_COMMAND_H_
OLDNEW
« no previous file with comments | « no previous file | device/u2f/u2f_apdu_command.cc » ('j') | device/u2f/u2f_apdu_command.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698