Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_PACKET_H_ | |
| 6 #define DEVICE_U2F_U2F_PACKET_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "net/base/io_buffer.h" | |
| 10 | |
| 11 namespace device { | |
| 12 | |
| 13 // U2fPackets are defined by the specification at | |
| 14 // http://fidoalliance.org/specs/u2f-specs-1.0-bt-nfc-id-amendment/fido-u2f-hid- protocol.html | |
| 15 // Packets are one of two types, initialization packets and continuation | |
| 16 // packets, | |
| 17 // (U2fInitPacket and U2fContinuationPacket). U2fPackets have header information | |
| 18 // and a payload. If a U2fInitPacket cannot store the entire payload, further | |
| 19 // payload information is stored in U2fContinuationPackets. | |
| 20 class U2fPacket : public base::RefCountedThreadSafe<U2fPacket> { | |
| 21 public: | |
| 22 U2fPacket(const std::vector<uint8_t> data, const uint32_t channel_id); | |
| 23 | |
| 24 scoped_refptr<net::IOBufferWithSize> GetSerializedBuffer(); | |
| 25 const std::vector<uint8_t> GetPacketPayload(); | |
| 26 uint32_t GetChannelId(); | |
| 27 | |
| 28 protected: | |
| 29 U2fPacket(); | |
| 30 virtual ~U2fPacket(); | |
| 31 | |
| 32 // Packet size of 64 bytes + 1 byte report ID | |
| 33 static const size_t kPacketSize = 65; | |
| 34 std::vector<uint8_t> data_; | |
| 35 uint32_t channel_id_; | |
| 36 scoped_refptr<net::IOBufferWithSize> serialized_; | |
| 37 | |
| 38 private: | |
| 39 friend class base::RefCountedThreadSafe<U2fPacket>; | |
| 40 friend class U2fMessage; | |
| 41 }; | |
| 42 | |
| 43 // U2fInitPacket, based on the U2f specification consists of a header with data | |
| 44 // that is serialized into a IOBuffer. A channel identifier is allocated by the | |
| 45 // U2F device to ensure its system-wide uniqueness. Command identifiers | |
| 46 // determine the type of message the packet corresponds to. Payload length | |
| 47 // is the length of the entire message payload, and the data is only the portion | |
| 48 // of the payload that will fit into the U2fInitPacket. | |
| 49 class U2fInitPacket : public U2fPacket { | |
| 50 public: | |
| 51 U2fInitPacket(const uint32_t channel_id, | |
| 52 const uint8_t cmd, | |
| 53 const std::vector<uint8_t> data, | |
| 54 const uint16_t payload_length); | |
| 55 | |
| 56 // Creates a packet from the serialized data of an initialization packet. As | |
| 57 // this is the first packet, the payload length of the entire message will be | |
| 58 // included within the serialized data. Remaining size will be returned to | |
| 59 // inform the callee how many additional packets to expect. | |
| 60 static scoped_refptr<U2fInitPacket> CreateFromSerializedData( | |
| 61 scoped_refptr<net::IOBufferWithSize> buf, | |
| 62 size_t* remaining_size); | |
| 63 uint8_t GetCommand(); | |
| 64 uint16_t GetPayloadLength(); | |
| 65 | |
| 66 protected: | |
| 67 ~U2fInitPacket() final; | |
| 68 | |
| 69 private: | |
| 70 U2fInitPacket(scoped_refptr<net::IOBufferWithSize> buf, | |
| 71 size_t* remaining_size); | |
| 72 | |
| 73 uint8_t command_; | |
| 74 uint16_t payload_length_; | |
| 75 }; | |
| 76 | |
| 77 // U2fContinuationPacket, based on the U2f Specification consists of a header | |
| 78 // with data that is serialized into an IOBuffer. The channel identifier will | |
| 79 // be identical to the identifier in all other packets of the message. The | |
| 80 // packet sequence will be the sequence number of this particular packet, from | |
| 81 // 0x00 to 0x7f. | |
| 82 class U2fContinuationPacket : public U2fPacket { | |
| 83 public: | |
| 84 U2fContinuationPacket(const uint32_t channel_id, | |
| 85 const uint8_t sequence, | |
| 86 std::vector<uint8_t> data); | |
| 87 | |
| 88 // Creates a packet from the serialized data of a continuation packet. As an | |
| 89 // U2fInitPacket would have arrived earlier with the total payload size, | |
| 90 // the remaining size should be passed to inform the packet of how much data | |
| 91 // to expect. | |
| 92 static scoped_refptr<U2fContinuationPacket> CreateFromSerializedData( | |
| 93 scoped_refptr<net::IOBufferWithSize> buf, | |
| 94 size_t* remaining_size); | |
| 95 | |
| 96 uint8_t GetSequence(); | |
|
Reilly Grant (use Gerrit)
2016/12/09 01:19:43
uint8_t sequence() { return sequence_; }
(For tri
Casey Piper
2016/12/09 18:56:50
Done.
| |
| 97 | |
| 98 protected: | |
| 99 ~U2fContinuationPacket() final; | |
| 100 | |
| 101 private: | |
| 102 U2fContinuationPacket(scoped_refptr<net::IOBufferWithSize> buf, | |
| 103 size_t* remaining_size); | |
| 104 | |
| 105 uint8_t sequence_; | |
| 106 }; | |
| 107 } // namespace device | |
| 108 | |
| 109 #endif // DEVICE_U2F_U2F_PACKET_H_ | |
| OLD | NEW |