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

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

Issue 2502103002: Add FIDO U2F message and packet classes (Closed)
Patch Set: Add //net dependency to fuzzer in BUILD.gn Created 4 years 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 | « device/u2f/DEPS ('k') | device/u2f/u2f_message.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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_MESSAGE_H_
6 #define DEVICE_U2F_U2F_MESSAGE_H_
7
8 #include <list>
9 #include <vector>
10
11 #include "base/gtest_prod_util.h"
12 #include "device/u2f/u2f_packet.h"
13
14 namespace net {
15 class IOBufferWithSize;
16 } // namespace net
17
18 namespace device {
19
20 // U2fMessages are defined by the specification at
21 // http://fidoalliance.org/specs/u2f-specs-1.0-bt-nfc-id-amendment/fido-u2f-hid- protocol.html
22 // A U2fMessage object represents a list of U2fPackets. Basic information
23 // about the message are available through class methods.
24 class U2fMessage : public base::RefCountedThreadSafe<U2fMessage> {
25 public:
26 enum class Type : uint8_t {
27 CMD_PING = 0x81,
28 CMD_MSG = 0x83,
29 CMD_INIT = 0x86,
30 CMD_WINK = 0x88,
31 CMD_ERROR = 0xbf,
32 };
33
34 static scoped_refptr<U2fMessage> Create(uint32_t channel_id,
35 Type type,
36 const std::vector<uint8_t>& data);
37 // Reconstruct a message from serialized message data
38 static scoped_refptr<U2fMessage> CreateFromSerializedData(
39 scoped_refptr<net::IOBufferWithSize> buf);
40 // Pop front of queue with next packet
41 scoped_refptr<net::IOBufferWithSize> PopNextPacket();
42 // Adds a continuation packet to the packet list, from the serialized
43 // response value
44 bool AddContinuationPacket(scoped_refptr<net::IOBufferWithSize> packet_buf);
45 size_t NumPackets();
46 // Returns entire message payload
47 std::vector<uint8_t> GetMessagePayload() const;
48 uint32_t channel_id() { return channel_id_; }
49 // Message construction complete
50 bool MessageComplete();
51 std::list<scoped_refptr<U2fPacket>>::const_iterator begin();
52 std::list<scoped_refptr<U2fPacket>>::const_iterator end();
53
54 protected:
55 virtual ~U2fMessage();
56
57 private:
58 friend class base::RefCountedThreadSafe<U2fMessage>;
59 FRIEND_TEST_ALL_PREFIXES(U2fMessageTest, TestMaxLengthPacketConstructors);
60 FRIEND_TEST_ALL_PREFIXES(U2fMessageTest, TestMessagePartitoning);
61 FRIEND_TEST_ALL_PREFIXES(U2fMessageTest, TestDeconstruct);
62 FRIEND_TEST_ALL_PREFIXES(U2fMessageTest, TestMaxSize);
63 FRIEND_TEST_ALL_PREFIXES(U2fMessageTest, TestDeserialize);
64
65 static constexpr size_t kInitPacketHeader = 7;
66 static constexpr size_t kContinuationPacketHeader = 5;
67 static constexpr size_t kMaxHidPacketSize = 64;
68 static constexpr size_t kInitPacketDataSize =
69 kMaxHidPacketSize - kInitPacketHeader;
70 static constexpr size_t kContinuationPacketDataSize =
71 kMaxHidPacketSize - kContinuationPacketHeader;
72 // Messages are limited to an init packet and 128 continuation packets
73 // Maximum payload length therefore is 64-7 + 128 * (64-5) = 7609 bytes
74 static constexpr size_t kMaxMessageSize = 7609;
75
76 U2fMessage(uint32_t channel_id, Type type, const std::vector<uint8_t>& data);
77 U2fMessage(scoped_refptr<U2fInitPacket> init_packet, size_t remaining_size);
78
79 std::list<scoped_refptr<U2fPacket>> packets_;
80 size_t remaining_size_;
81 uint32_t channel_id_;
82 };
83 } // namespace device
84
85 #endif // DEVICE_U2F_U2F_MESSAGE_H_
OLDNEW
« no previous file with comments | « device/u2f/DEPS ('k') | device/u2f/u2f_message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698