QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | #include "net/third_party/quiche/src/quic/core/quic_framer.h" |
| 6 | |
| 7 | #include <algorithm> |
| 8 | #include <cstdint> |
| 9 | #include <map> |
| 10 | #include <memory> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 11 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
| 14 | #include "net/third_party/quiche/src/quic/core/crypto/null_decrypter.h" |
| 15 | #include "net/third_party/quiche/src/quic/core/crypto/null_encrypter.h" |
| 16 | #include "net/third_party/quiche/src/quic/core/crypto/quic_decrypter.h" |
| 17 | #include "net/third_party/quiche/src/quic/core/crypto/quic_encrypter.h" |
| 18 | #include "net/third_party/quiche/src/quic/core/quic_connection_id.h" |
| 19 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 20 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
| 21 | #include "net/third_party/quiche/src/quic/core/quic_utils.h" |
| 22 | #include "net/third_party/quiche/src/quic/platform/api/quic_arraysize.h" |
| 23 | #include "net/third_party/quiche/src/quic/platform/api/quic_expect_bug.h" |
| 24 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
| 25 | #include "net/third_party/quiche/src/quic/platform/api/quic_logging.h" |
| 26 | #include "net/third_party/quiche/src/quic/platform/api/quic_ptr_util.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 27 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
| 28 | #include "net/third_party/quiche/src/quic/platform/api/quic_text_utils.h" |
| 29 | #include "net/third_party/quiche/src/quic/test_tools/quic_framer_peer.h" |
| 30 | #include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h" |
| 31 | #include "net/third_party/quiche/src/quic/test_tools/simple_data_producer.h" |
| 32 | |
| 33 | using testing::_; |
| 34 | using testing::Return; |
| 35 | using testing::Truly; |
| 36 | |
| 37 | namespace quic { |
| 38 | namespace test { |
| 39 | namespace { |
| 40 | |
| 41 | const uint64_t kEpoch = UINT64_C(1) << 32; |
| 42 | const uint64_t kMask = kEpoch - 1; |
| 43 | |
| 44 | const QuicUint128 kTestStatelessResetToken = 1010101; // 0x0F69B5 |
| 45 | |
| 46 | // Use fields in which each byte is distinct to ensure that every byte is |
| 47 | // framed correctly. The values are otherwise arbitrary. |
| 48 | QuicConnectionId FramerTestConnectionId() { |
| 49 | return TestConnectionId(UINT64_C(0xFEDCBA9876543210)); |
| 50 | } |
| 51 | |
| 52 | QuicConnectionId FramerTestConnectionIdPlusOne() { |
| 53 | return TestConnectionId(UINT64_C(0xFEDCBA9876543211)); |
| 54 | } |
| 55 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 56 | QuicConnectionId FramerTestConnectionIdNineBytes() { |
| 57 | char connection_id_bytes[9] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, |
| 58 | 0x54, 0x32, 0x10, 0x42}; |
| 59 | return QuicConnectionId(connection_id_bytes, sizeof(connection_id_bytes)); |
| 60 | } |
| 61 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 62 | const QuicPacketNumber kPacketNumber = QuicPacketNumber(UINT64_C(0x12345678)); |
| 63 | const QuicPacketNumber kSmallLargestObserved = |
| 64 | QuicPacketNumber(UINT16_C(0x1234)); |
| 65 | const QuicPacketNumber kSmallMissingPacket = QuicPacketNumber(UINT16_C(0x1233)); |
| 66 | const QuicPacketNumber kLeastUnacked = QuicPacketNumber(UINT64_C(0x012345670)); |
| 67 | const QuicStreamId kStreamId = UINT64_C(0x01020304); |
| 68 | // Note that the high 4 bits of the stream offset must be less than 0x40 |
| 69 | // in order to ensure that the value can be encoded using VarInt62 encoding. |
| 70 | const QuicStreamOffset kStreamOffset = UINT64_C(0x3A98FEDC32107654); |
| 71 | const QuicPublicResetNonceProof kNonceProof = UINT64_C(0xABCDEF0123456789); |
| 72 | |
| 73 | // In testing that we can ack the full range of packets... |
| 74 | // This is the largest packet number that can be represented in IETF QUIC |
| 75 | // varint62 format. |
| 76 | const QuicPacketNumber kLargestIetfLargestObserved = |
| 77 | QuicPacketNumber(UINT64_C(0x3fffffffffffffff)); |
| 78 | // Encodings for the two bits in a VarInt62 that |
| 79 | // describe the length of the VarInt61. For binary packet |
| 80 | // formats in this file, the convention is to code the |
| 81 | // first byte as |
| 82 | // kVarInt62FourBytes + 0x<value_in_that_byte> |
| 83 | const uint8_t kVarInt62OneByte = 0x00; |
| 84 | const uint8_t kVarInt62TwoBytes = 0x40; |
| 85 | const uint8_t kVarInt62FourBytes = 0x80; |
| 86 | const uint8_t kVarInt62EightBytes = 0xc0; |
| 87 | |
| 88 | class TestEncrypter : public QuicEncrypter { |
| 89 | public: |
| 90 | ~TestEncrypter() override {} |
| 91 | bool SetKey(QuicStringPiece key) override { return true; } |
| 92 | bool SetNoncePrefix(QuicStringPiece nonce_prefix) override { return true; } |
| 93 | bool SetIV(QuicStringPiece iv) override { return true; } |
QUICHE team | 2d18797 | 2019-03-19 16:23:47 -0700 | [diff] [blame] | 94 | bool SetHeaderProtectionKey(QuicStringPiece key) override { return true; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 95 | bool EncryptPacket(uint64_t packet_number, |
| 96 | QuicStringPiece associated_data, |
| 97 | QuicStringPiece plaintext, |
| 98 | char* output, |
| 99 | size_t* output_length, |
| 100 | size_t max_output_length) override { |
| 101 | packet_number_ = QuicPacketNumber(packet_number); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 102 | associated_data_ = std::string(associated_data); |
| 103 | plaintext_ = std::string(plaintext); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 104 | memcpy(output, plaintext.data(), plaintext.length()); |
| 105 | *output_length = plaintext.length(); |
| 106 | return true; |
| 107 | } |
QUICHE team | 2d18797 | 2019-03-19 16:23:47 -0700 | [diff] [blame] | 108 | std::string GenerateHeaderProtectionMask(QuicStringPiece sample) override { |
| 109 | return std::string(5, 0); |
| 110 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 111 | size_t GetKeySize() const override { return 0; } |
| 112 | size_t GetNoncePrefixSize() const override { return 0; } |
| 113 | size_t GetIVSize() const override { return 0; } |
| 114 | size_t GetMaxPlaintextSize(size_t ciphertext_size) const override { |
| 115 | return ciphertext_size; |
| 116 | } |
| 117 | size_t GetCiphertextSize(size_t plaintext_size) const override { |
| 118 | return plaintext_size; |
| 119 | } |
| 120 | QuicStringPiece GetKey() const override { return QuicStringPiece(); } |
| 121 | QuicStringPiece GetNoncePrefix() const override { return QuicStringPiece(); } |
| 122 | |
| 123 | QuicPacketNumber packet_number_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 124 | std::string associated_data_; |
| 125 | std::string plaintext_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | class TestDecrypter : public QuicDecrypter { |
| 129 | public: |
| 130 | ~TestDecrypter() override {} |
| 131 | bool SetKey(QuicStringPiece key) override { return true; } |
| 132 | bool SetNoncePrefix(QuicStringPiece nonce_prefix) override { return true; } |
| 133 | bool SetIV(QuicStringPiece iv) override { return true; } |
QUICHE team | 2d18797 | 2019-03-19 16:23:47 -0700 | [diff] [blame] | 134 | bool SetHeaderProtectionKey(QuicStringPiece key) override { return true; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 135 | bool SetPreliminaryKey(QuicStringPiece key) override { |
| 136 | QUIC_BUG << "should not be called"; |
| 137 | return false; |
| 138 | } |
| 139 | bool SetDiversificationNonce(const DiversificationNonce& key) override { |
| 140 | return true; |
| 141 | } |
| 142 | bool DecryptPacket(uint64_t packet_number, |
| 143 | QuicStringPiece associated_data, |
| 144 | QuicStringPiece ciphertext, |
| 145 | char* output, |
| 146 | size_t* output_length, |
| 147 | size_t max_output_length) override { |
| 148 | packet_number_ = QuicPacketNumber(packet_number); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 149 | associated_data_ = std::string(associated_data); |
| 150 | ciphertext_ = std::string(ciphertext); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 151 | memcpy(output, ciphertext.data(), ciphertext.length()); |
| 152 | *output_length = ciphertext.length(); |
| 153 | return true; |
| 154 | } |
QUICHE team | 2d18797 | 2019-03-19 16:23:47 -0700 | [diff] [blame] | 155 | std::string GenerateHeaderProtectionMask( |
| 156 | QuicDataReader* sample_reader) override { |
| 157 | return std::string(5, 0); |
| 158 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 159 | size_t GetKeySize() const override { return 0; } |
| 160 | size_t GetIVSize() const override { return 0; } |
| 161 | QuicStringPiece GetKey() const override { return QuicStringPiece(); } |
| 162 | QuicStringPiece GetNoncePrefix() const override { return QuicStringPiece(); } |
| 163 | // Use a distinct value starting with 0xFFFFFF, which is never used by TLS. |
| 164 | uint32_t cipher_id() const override { return 0xFFFFFFF2; } |
| 165 | QuicPacketNumber packet_number_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 166 | std::string associated_data_; |
| 167 | std::string ciphertext_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | class TestQuicVisitor : public QuicFramerVisitorInterface { |
| 171 | public: |
| 172 | TestQuicVisitor() |
| 173 | : error_count_(0), |
| 174 | version_mismatch_(0), |
| 175 | packet_count_(0), |
| 176 | frame_count_(0), |
| 177 | complete_packets_(0), |
| 178 | accept_packet_(true), |
| 179 | accept_public_header_(true) {} |
| 180 | |
| 181 | ~TestQuicVisitor() override {} |
| 182 | |
| 183 | void OnError(QuicFramer* f) override { |
| 184 | QUIC_DLOG(INFO) << "QuicFramer Error: " << QuicErrorCodeToString(f->error()) |
| 185 | << " (" << f->error() << ")"; |
| 186 | ++error_count_; |
| 187 | } |
| 188 | |
| 189 | void OnPacket() override {} |
| 190 | |
| 191 | void OnPublicResetPacket(const QuicPublicResetPacket& packet) override { |
| 192 | public_reset_packet_ = QuicMakeUnique<QuicPublicResetPacket>((packet)); |
| 193 | } |
| 194 | |
| 195 | void OnVersionNegotiationPacket( |
| 196 | const QuicVersionNegotiationPacket& packet) override { |
| 197 | version_negotiation_packet_ = |
| 198 | QuicMakeUnique<QuicVersionNegotiationPacket>((packet)); |
| 199 | } |
| 200 | |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 201 | void OnRetryPacket(QuicConnectionId original_connection_id, |
| 202 | QuicConnectionId new_connection_id, |
| 203 | QuicStringPiece retry_token) override { |
| 204 | retry_original_connection_id_ = |
| 205 | QuicMakeUnique<QuicConnectionId>(original_connection_id); |
| 206 | retry_new_connection_id_ = |
| 207 | QuicMakeUnique<QuicConnectionId>(new_connection_id); |
| 208 | retry_token_ = QuicMakeUnique<std::string>(std::string(retry_token)); |
| 209 | } |
| 210 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 211 | bool OnProtocolVersionMismatch(ParsedQuicVersion received_version, |
| 212 | PacketHeaderFormat /*form*/) override { |
| 213 | QUIC_DLOG(INFO) << "QuicFramer Version Mismatch, version: " |
| 214 | << received_version; |
| 215 | ++version_mismatch_; |
| 216 | return true; |
| 217 | } |
| 218 | |
| 219 | bool OnUnauthenticatedPublicHeader(const QuicPacketHeader& header) override { |
| 220 | header_ = QuicMakeUnique<QuicPacketHeader>((header)); |
| 221 | return accept_public_header_; |
| 222 | } |
| 223 | |
| 224 | bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override { |
| 225 | return true; |
| 226 | } |
| 227 | |
| 228 | void OnDecryptedPacket(EncryptionLevel level) override {} |
| 229 | |
| 230 | bool OnPacketHeader(const QuicPacketHeader& header) override { |
| 231 | ++packet_count_; |
| 232 | header_ = QuicMakeUnique<QuicPacketHeader>((header)); |
| 233 | return accept_packet_; |
| 234 | } |
| 235 | |
| 236 | void OnCoalescedPacket(const QuicEncryptedPacket& packet) override { |
| 237 | size_t coalesced_data_length = packet.length(); |
| 238 | char* coalesced_data = new char[coalesced_data_length]; |
| 239 | memcpy(coalesced_data, packet.data(), coalesced_data_length); |
| 240 | coalesced_packets_.push_back(QuicMakeUnique<QuicEncryptedPacket>( |
| 241 | coalesced_data, coalesced_data_length, |
| 242 | /*owns_buffer=*/true)); |
| 243 | } |
| 244 | |
| 245 | bool OnStreamFrame(const QuicStreamFrame& frame) override { |
| 246 | ++frame_count_; |
| 247 | // Save a copy of the data so it is valid after the packet is processed. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 248 | std::string* string_data = |
| 249 | new std::string(frame.data_buffer, frame.data_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 250 | stream_data_.push_back(QuicWrapUnique(string_data)); |
| 251 | stream_frames_.push_back(QuicMakeUnique<QuicStreamFrame>( |
| 252 | frame.stream_id, frame.fin, frame.offset, *string_data)); |
| 253 | return true; |
| 254 | } |
| 255 | |
| 256 | bool OnCryptoFrame(const QuicCryptoFrame& frame) override { |
| 257 | ++frame_count_; |
| 258 | // Save a copy of the data so it is valid after the packet is processed. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 259 | std::string* string_data = |
| 260 | new std::string(frame.data_buffer, frame.data_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 261 | crypto_data_.push_back(QuicWrapUnique(string_data)); |
| 262 | crypto_frames_.push_back(QuicMakeUnique<QuicCryptoFrame>( |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 263 | ENCRYPTION_INITIAL, frame.offset, *string_data)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 264 | return true; |
| 265 | } |
| 266 | |
| 267 | bool OnAckFrameStart(QuicPacketNumber largest_acked, |
| 268 | QuicTime::Delta ack_delay_time) override { |
| 269 | ++frame_count_; |
| 270 | QuicAckFrame ack_frame; |
| 271 | ack_frame.largest_acked = largest_acked; |
| 272 | ack_frame.ack_delay_time = ack_delay_time; |
| 273 | ack_frames_.push_back(QuicMakeUnique<QuicAckFrame>(ack_frame)); |
| 274 | return true; |
| 275 | } |
| 276 | |
| 277 | bool OnAckRange(QuicPacketNumber start, QuicPacketNumber end) override { |
| 278 | DCHECK(!ack_frames_.empty()); |
| 279 | ack_frames_[ack_frames_.size() - 1]->packets.AddRange(start, end); |
| 280 | return true; |
| 281 | } |
| 282 | |
| 283 | bool OnAckTimestamp(QuicPacketNumber packet_number, |
| 284 | QuicTime timestamp) override { |
| 285 | ack_frames_[ack_frames_.size() - 1]->received_packet_times.push_back( |
| 286 | std::make_pair(packet_number, timestamp)); |
| 287 | return true; |
| 288 | } |
| 289 | |
| 290 | bool OnAckFrameEnd(QuicPacketNumber /*start*/) override { return true; } |
| 291 | |
| 292 | bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override { |
| 293 | ++frame_count_; |
| 294 | stop_waiting_frames_.push_back(QuicMakeUnique<QuicStopWaitingFrame>(frame)); |
| 295 | return true; |
| 296 | } |
| 297 | |
| 298 | bool OnPaddingFrame(const QuicPaddingFrame& frame) override { |
| 299 | padding_frames_.push_back(QuicMakeUnique<QuicPaddingFrame>(frame)); |
| 300 | return true; |
| 301 | } |
| 302 | |
| 303 | bool OnPingFrame(const QuicPingFrame& frame) override { |
| 304 | ++frame_count_; |
| 305 | ping_frames_.push_back(QuicMakeUnique<QuicPingFrame>(frame)); |
| 306 | return true; |
| 307 | } |
| 308 | |
| 309 | bool OnMessageFrame(const QuicMessageFrame& frame) override { |
| 310 | ++frame_count_; |
| 311 | message_frames_.push_back( |
| 312 | QuicMakeUnique<QuicMessageFrame>(frame.data, frame.message_length)); |
| 313 | return true; |
| 314 | } |
| 315 | |
| 316 | void OnPacketComplete() override { ++complete_packets_; } |
| 317 | |
| 318 | bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override { |
| 319 | rst_stream_frame_ = frame; |
| 320 | return true; |
| 321 | } |
| 322 | |
| 323 | bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override { |
| 324 | connection_close_frame_ = frame; |
| 325 | return true; |
| 326 | } |
| 327 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 328 | bool OnStopSendingFrame(const QuicStopSendingFrame& frame) override { |
| 329 | stop_sending_frame_ = frame; |
| 330 | return true; |
| 331 | } |
| 332 | |
| 333 | bool OnPathChallengeFrame(const QuicPathChallengeFrame& frame) override { |
| 334 | path_challenge_frame_ = frame; |
| 335 | return true; |
| 336 | } |
| 337 | |
| 338 | bool OnPathResponseFrame(const QuicPathResponseFrame& frame) override { |
| 339 | path_response_frame_ = frame; |
| 340 | return true; |
| 341 | } |
| 342 | |
| 343 | bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override { |
| 344 | goaway_frame_ = frame; |
| 345 | return true; |
| 346 | } |
| 347 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 348 | bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame) override { |
| 349 | max_streams_frame_ = frame; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 350 | return true; |
| 351 | } |
| 352 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 353 | bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame) override { |
| 354 | streams_blocked_frame_ = frame; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 355 | return true; |
| 356 | } |
| 357 | |
| 358 | bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override { |
| 359 | window_update_frame_ = frame; |
| 360 | return true; |
| 361 | } |
| 362 | |
| 363 | bool OnBlockedFrame(const QuicBlockedFrame& frame) override { |
| 364 | blocked_frame_ = frame; |
| 365 | return true; |
| 366 | } |
| 367 | |
| 368 | bool OnNewConnectionIdFrame(const QuicNewConnectionIdFrame& frame) override { |
| 369 | new_connection_id_ = frame; |
| 370 | return true; |
| 371 | } |
| 372 | |
| 373 | bool OnRetireConnectionIdFrame( |
| 374 | const QuicRetireConnectionIdFrame& frame) override { |
| 375 | retire_connection_id_ = frame; |
| 376 | return true; |
| 377 | } |
| 378 | |
| 379 | bool OnNewTokenFrame(const QuicNewTokenFrame& frame) override { |
| 380 | new_token_ = frame; |
| 381 | return true; |
| 382 | } |
| 383 | |
| 384 | bool IsValidStatelessResetToken(QuicUint128 token) const override { |
| 385 | return token == kTestStatelessResetToken; |
| 386 | } |
| 387 | |
| 388 | void OnAuthenticatedIetfStatelessResetPacket( |
| 389 | const QuicIetfStatelessResetPacket& packet) override { |
| 390 | stateless_reset_packet_ = |
| 391 | QuicMakeUnique<QuicIetfStatelessResetPacket>(packet); |
| 392 | } |
| 393 | |
| 394 | // Counters from the visitor_ callbacks. |
| 395 | int error_count_; |
| 396 | int version_mismatch_; |
| 397 | int packet_count_; |
| 398 | int frame_count_; |
| 399 | int complete_packets_; |
| 400 | bool accept_packet_; |
| 401 | bool accept_public_header_; |
| 402 | |
| 403 | std::unique_ptr<QuicPacketHeader> header_; |
| 404 | std::unique_ptr<QuicPublicResetPacket> public_reset_packet_; |
| 405 | std::unique_ptr<QuicIetfStatelessResetPacket> stateless_reset_packet_; |
| 406 | std::unique_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_; |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 407 | std::unique_ptr<QuicConnectionId> retry_original_connection_id_; |
| 408 | std::unique_ptr<QuicConnectionId> retry_new_connection_id_; |
| 409 | std::unique_ptr<std::string> retry_token_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 410 | std::vector<std::unique_ptr<QuicStreamFrame>> stream_frames_; |
| 411 | std::vector<std::unique_ptr<QuicCryptoFrame>> crypto_frames_; |
| 412 | std::vector<std::unique_ptr<QuicAckFrame>> ack_frames_; |
| 413 | std::vector<std::unique_ptr<QuicStopWaitingFrame>> stop_waiting_frames_; |
| 414 | std::vector<std::unique_ptr<QuicPaddingFrame>> padding_frames_; |
| 415 | std::vector<std::unique_ptr<QuicPingFrame>> ping_frames_; |
| 416 | std::vector<std::unique_ptr<QuicMessageFrame>> message_frames_; |
| 417 | std::vector<std::unique_ptr<QuicEncryptedPacket>> coalesced_packets_; |
| 418 | QuicRstStreamFrame rst_stream_frame_; |
| 419 | QuicConnectionCloseFrame connection_close_frame_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 420 | QuicStopSendingFrame stop_sending_frame_; |
| 421 | QuicGoAwayFrame goaway_frame_; |
| 422 | QuicPathChallengeFrame path_challenge_frame_; |
| 423 | QuicPathResponseFrame path_response_frame_; |
| 424 | QuicWindowUpdateFrame window_update_frame_; |
| 425 | QuicBlockedFrame blocked_frame_; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 426 | QuicStreamsBlockedFrame streams_blocked_frame_; |
| 427 | QuicMaxStreamsFrame max_streams_frame_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 428 | QuicNewConnectionIdFrame new_connection_id_; |
| 429 | QuicRetireConnectionIdFrame retire_connection_id_; |
| 430 | QuicNewTokenFrame new_token_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 431 | std::vector<std::unique_ptr<std::string>> stream_data_; |
| 432 | std::vector<std::unique_ptr<std::string>> crypto_data_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 433 | }; |
| 434 | |
| 435 | // Simple struct for defining a packet's content, and associated |
| 436 | // parse error. |
| 437 | struct PacketFragment { |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 438 | std::string error_if_missing; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 439 | std::vector<unsigned char> fragment; |
| 440 | }; |
| 441 | |
| 442 | using PacketFragments = std::vector<struct PacketFragment>; |
| 443 | |
| 444 | ParsedQuicVersionVector AllSupportedVersionsIncludingTls() { |
| 445 | QuicFlagSaver flags; |
wub | 4985598 | 2019-05-01 14:16:26 -0700 | [diff] [blame] | 446 | SetQuicFlag(FLAGS_quic_supports_tls_handshake, true); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 447 | return AllSupportedVersions(); |
| 448 | } |
| 449 | |
| 450 | class QuicFramerTest : public QuicTestWithParam<ParsedQuicVersion> { |
| 451 | public: |
| 452 | QuicFramerTest() |
| 453 | : encrypter_(new test::TestEncrypter()), |
| 454 | decrypter_(new test::TestDecrypter()), |
| 455 | version_(GetParam()), |
| 456 | start_(QuicTime::Zero() + QuicTime::Delta::FromMicroseconds(0x10)), |
| 457 | framer_(AllSupportedVersionsIncludingTls(), |
| 458 | start_, |
| 459 | Perspective::IS_SERVER, |
| 460 | kQuicDefaultConnectionIdLength) { |
wub | 4985598 | 2019-05-01 14:16:26 -0700 | [diff] [blame] | 461 | SetQuicFlag(FLAGS_quic_supports_tls_handshake, true); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 462 | framer_.set_version(version_); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 463 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 464 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, |
| 465 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 466 | } else { |
| 467 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 468 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 469 | } |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 470 | framer_.SetEncrypter(ENCRYPTION_INITIAL, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 471 | std::unique_ptr<QuicEncrypter>(encrypter_)); |
| 472 | |
| 473 | framer_.set_visitor(&visitor_); |
| 474 | framer_.InferPacketHeaderTypeFromVersion(); |
| 475 | } |
| 476 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 477 | void SetDecrypterLevel(EncryptionLevel level) { |
| 478 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 479 | return; |
| 480 | } |
| 481 | decrypter_ = new TestDecrypter(); |
| 482 | framer_.InstallDecrypter(level, std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 483 | } |
| 484 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 485 | // Helper function to get unsigned char representation of the handshake |
| 486 | // protocol byte of the current QUIC version number. |
| 487 | unsigned char GetQuicVersionProtocolByte() { |
| 488 | return (CreateQuicVersionLabel(version_) >> 24) & 0xff; |
| 489 | } |
| 490 | |
| 491 | // Helper function to get unsigned char representation of digit in the |
| 492 | // units place of the current QUIC version number. |
| 493 | unsigned char GetQuicVersionDigitOnes() { |
| 494 | return CreateQuicVersionLabel(version_) & 0xff; |
| 495 | } |
| 496 | |
| 497 | // Helper function to get unsigned char representation of digit in the |
| 498 | // tens place of the current QUIC version number. |
| 499 | unsigned char GetQuicVersionDigitTens() { |
| 500 | return (CreateQuicVersionLabel(version_) >> 8) & 0xff; |
| 501 | } |
| 502 | |
| 503 | bool CheckEncryption(QuicPacketNumber packet_number, QuicPacket* packet) { |
| 504 | if (packet_number != encrypter_->packet_number_) { |
| 505 | QUIC_LOG(ERROR) << "Encrypted incorrect packet number. expected " |
| 506 | << packet_number |
| 507 | << " actual: " << encrypter_->packet_number_; |
| 508 | return false; |
| 509 | } |
| 510 | if (packet->AssociatedData(framer_.transport_version()) != |
| 511 | encrypter_->associated_data_) { |
| 512 | QUIC_LOG(ERROR) << "Encrypted incorrect associated data. expected " |
| 513 | << packet->AssociatedData(framer_.transport_version()) |
| 514 | << " actual: " << encrypter_->associated_data_; |
| 515 | return false; |
| 516 | } |
| 517 | if (packet->Plaintext(framer_.transport_version()) != |
| 518 | encrypter_->plaintext_) { |
| 519 | QUIC_LOG(ERROR) << "Encrypted incorrect plaintext data. expected " |
| 520 | << packet->Plaintext(framer_.transport_version()) |
| 521 | << " actual: " << encrypter_->plaintext_; |
| 522 | return false; |
| 523 | } |
| 524 | return true; |
| 525 | } |
| 526 | |
| 527 | bool CheckDecryption(const QuicEncryptedPacket& encrypted, |
| 528 | bool includes_version, |
| 529 | bool includes_diversification_nonce, |
| 530 | QuicConnectionIdLength destination_connection_id_length, |
| 531 | QuicConnectionIdLength source_connection_id_length) { |
| 532 | return CheckDecryption( |
| 533 | encrypted, includes_version, includes_diversification_nonce, |
| 534 | destination_connection_id_length, source_connection_id_length, |
| 535 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 536 | } |
| 537 | |
| 538 | bool CheckDecryption( |
| 539 | const QuicEncryptedPacket& encrypted, |
| 540 | bool includes_version, |
| 541 | bool includes_diversification_nonce, |
| 542 | QuicConnectionIdLength destination_connection_id_length, |
| 543 | QuicConnectionIdLength source_connection_id_length, |
| 544 | QuicVariableLengthIntegerLength retry_token_length_length, |
| 545 | size_t retry_token_length, |
| 546 | QuicVariableLengthIntegerLength length_length) { |
| 547 | if (visitor_.header_->packet_number != decrypter_->packet_number_) { |
| 548 | QUIC_LOG(ERROR) << "Decrypted incorrect packet number. expected " |
| 549 | << visitor_.header_->packet_number |
| 550 | << " actual: " << decrypter_->packet_number_; |
| 551 | return false; |
| 552 | } |
| 553 | QuicStringPiece associated_data = |
| 554 | QuicFramer::GetAssociatedDataFromEncryptedPacket( |
| 555 | framer_.transport_version(), encrypted, |
| 556 | destination_connection_id_length, source_connection_id_length, |
| 557 | includes_version, includes_diversification_nonce, |
| 558 | PACKET_4BYTE_PACKET_NUMBER, retry_token_length_length, |
| 559 | retry_token_length, length_length); |
| 560 | if (associated_data != decrypter_->associated_data_) { |
| 561 | QUIC_LOG(ERROR) << "Decrypted incorrect associated data. expected " |
| 562 | << QuicTextUtils::HexEncode(associated_data) |
| 563 | << " actual: " |
| 564 | << QuicTextUtils::HexEncode(decrypter_->associated_data_); |
| 565 | return false; |
| 566 | } |
| 567 | QuicStringPiece ciphertext( |
| 568 | encrypted.AsStringPiece().substr(GetStartOfEncryptedData( |
| 569 | framer_.transport_version(), destination_connection_id_length, |
| 570 | source_connection_id_length, includes_version, |
| 571 | includes_diversification_nonce, PACKET_4BYTE_PACKET_NUMBER, |
| 572 | retry_token_length_length, retry_token_length, length_length))); |
| 573 | if (ciphertext != decrypter_->ciphertext_) { |
| 574 | QUIC_LOG(ERROR) << "Decrypted incorrect ciphertext data. expected " |
| 575 | << QuicTextUtils::HexEncode(ciphertext) << " actual: " |
| 576 | << QuicTextUtils::HexEncode(decrypter_->ciphertext_) |
| 577 | << " associated data: " |
| 578 | << QuicTextUtils::HexEncode(associated_data); |
| 579 | return false; |
| 580 | } |
| 581 | return true; |
| 582 | } |
| 583 | |
| 584 | char* AsChars(unsigned char* data) { return reinterpret_cast<char*>(data); } |
| 585 | |
| 586 | // Creates a new QuicEncryptedPacket by concatenating the various |
| 587 | // packet fragments in |fragments|. |
| 588 | std::unique_ptr<QuicEncryptedPacket> AssemblePacketFromFragments( |
| 589 | const PacketFragments& fragments) { |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 590 | char* buffer = new char[kMaxOutgoingPacketSize + 1]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 591 | size_t len = 0; |
| 592 | for (const auto& fragment : fragments) { |
| 593 | memcpy(buffer + len, fragment.fragment.data(), fragment.fragment.size()); |
| 594 | len += fragment.fragment.size(); |
| 595 | } |
| 596 | return QuicMakeUnique<QuicEncryptedPacket>(buffer, len, true); |
| 597 | } |
| 598 | |
| 599 | void CheckFramingBoundaries(const PacketFragments& fragments, |
| 600 | QuicErrorCode error_code) { |
| 601 | std::unique_ptr<QuicEncryptedPacket> packet( |
| 602 | AssemblePacketFromFragments(fragments)); |
| 603 | // Check all the various prefixes of |packet| for the expected |
| 604 | // parse error and error code. |
| 605 | for (size_t i = 0; i < packet->length(); ++i) { |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 606 | std::string expected_error; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 607 | size_t len = 0; |
| 608 | for (const auto& fragment : fragments) { |
| 609 | len += fragment.fragment.size(); |
| 610 | if (i < len) { |
| 611 | expected_error = fragment.error_if_missing; |
| 612 | break; |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | if (expected_error.empty()) |
| 617 | continue; |
| 618 | |
| 619 | CheckProcessingFails(*packet, i, expected_error, error_code); |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | void CheckProcessingFails(const QuicEncryptedPacket& packet, |
| 624 | size_t len, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 625 | std::string expected_error, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 626 | QuicErrorCode error_code) { |
| 627 | QuicEncryptedPacket encrypted(packet.data(), len, false); |
| 628 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; |
| 629 | EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; |
| 630 | EXPECT_EQ(error_code, framer_.error()) << "len: " << len; |
| 631 | } |
| 632 | |
| 633 | void CheckProcessingFails(unsigned char* packet, |
| 634 | size_t len, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 635 | std::string expected_error, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 636 | QuicErrorCode error_code) { |
| 637 | QuicEncryptedPacket encrypted(AsChars(packet), len, false); |
| 638 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; |
| 639 | EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; |
| 640 | EXPECT_EQ(error_code, framer_.error()) << "len: " << len; |
| 641 | } |
| 642 | |
| 643 | // Checks if the supplied string matches data in the supplied StreamFrame. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 644 | void CheckStreamFrameData(std::string str, QuicStreamFrame* frame) { |
| 645 | EXPECT_EQ(str, std::string(frame->data_buffer, frame->data_length)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | void CheckCalculatePacketNumber(uint64_t expected_packet_number, |
| 649 | QuicPacketNumber last_packet_number) { |
| 650 | uint64_t wire_packet_number = expected_packet_number & kMask; |
| 651 | EXPECT_EQ(expected_packet_number, |
| 652 | QuicFramerPeer::CalculatePacketNumberFromWire( |
| 653 | &framer_, PACKET_4BYTE_PACKET_NUMBER, last_packet_number, |
| 654 | wire_packet_number)) |
| 655 | << "last_packet_number: " << last_packet_number |
| 656 | << " wire_packet_number: " << wire_packet_number; |
| 657 | } |
| 658 | |
| 659 | std::unique_ptr<QuicPacket> BuildDataPacket(const QuicPacketHeader& header, |
| 660 | const QuicFrames& frames) { |
| 661 | return BuildUnsizedDataPacket(&framer_, header, frames); |
| 662 | } |
| 663 | |
| 664 | std::unique_ptr<QuicPacket> BuildDataPacket(const QuicPacketHeader& header, |
| 665 | const QuicFrames& frames, |
| 666 | size_t packet_size) { |
| 667 | return BuildUnsizedDataPacket(&framer_, header, frames, packet_size); |
| 668 | } |
| 669 | |
| 670 | // N starts at 1. |
| 671 | QuicStreamId GetNthStreamid(QuicTransportVersion transport_version, |
| 672 | Perspective perspective, |
| 673 | bool bidirectional, |
| 674 | int n) { |
| 675 | if (bidirectional) { |
| 676 | return QuicUtils::GetFirstBidirectionalStreamId(transport_version, |
| 677 | perspective) + |
| 678 | ((n - 1) * QuicUtils::StreamIdDelta(transport_version)); |
| 679 | } |
| 680 | // Unidirectional |
| 681 | return QuicUtils::GetFirstUnidirectionalStreamId(transport_version, |
| 682 | perspective) + |
| 683 | ((n - 1) * QuicUtils::StreamIdDelta(transport_version)); |
| 684 | } |
| 685 | |
| 686 | test::TestEncrypter* encrypter_; |
| 687 | test::TestDecrypter* decrypter_; |
| 688 | ParsedQuicVersion version_; |
| 689 | QuicTime start_; |
| 690 | QuicFramer framer_; |
| 691 | test::TestQuicVisitor visitor_; |
| 692 | SimpleBufferAllocator allocator_; |
| 693 | }; |
| 694 | |
| 695 | // Multiple test cases of QuicFramerTest use byte arrays to define packets for |
| 696 | // testing, and these byte arrays contain the QUIC version. This macro explodes |
| 697 | // the 32-bit version into four bytes in network order. Since it uses methods of |
| 698 | // QuicFramerTest, it is only valid to use this in a QuicFramerTest. |
| 699 | #define QUIC_VERSION_BYTES \ |
| 700 | GetQuicVersionProtocolByte(), '0', GetQuicVersionDigitTens(), \ |
| 701 | GetQuicVersionDigitOnes() |
| 702 | |
| 703 | // Run all framer tests with all supported versions of QUIC. |
| 704 | INSTANTIATE_TEST_SUITE_P( |
| 705 | QuicFramerTests, |
| 706 | QuicFramerTest, |
| 707 | ::testing::ValuesIn(AllSupportedVersionsIncludingTls())); |
| 708 | |
| 709 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochStart) { |
| 710 | // A few quick manual sanity checks. |
| 711 | CheckCalculatePacketNumber(UINT64_C(1), QuicPacketNumber()); |
| 712 | CheckCalculatePacketNumber(kEpoch + 1, QuicPacketNumber(kMask)); |
| 713 | CheckCalculatePacketNumber(kEpoch, QuicPacketNumber(kMask)); |
| 714 | for (uint64_t j = 0; j < 10; j++) { |
| 715 | CheckCalculatePacketNumber(j, QuicPacketNumber()); |
| 716 | CheckCalculatePacketNumber(kEpoch - 1 - j, QuicPacketNumber()); |
| 717 | } |
| 718 | |
| 719 | // Cases where the last number was close to the start of the range. |
| 720 | for (QuicPacketNumber last = QuicPacketNumber(1); last < QuicPacketNumber(10); |
| 721 | last++) { |
| 722 | // Small numbers should not wrap (even if they're out of order). |
| 723 | for (uint64_t j = 0; j < 10; j++) { |
| 724 | CheckCalculatePacketNumber(j, last); |
| 725 | } |
| 726 | |
| 727 | // Large numbers should not wrap either (because we're near 0 already). |
| 728 | for (uint64_t j = 0; j < 10; j++) { |
| 729 | CheckCalculatePacketNumber(kEpoch - 1 - j, last); |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochEnd) { |
| 735 | // Cases where the last number was close to the end of the range |
| 736 | for (uint64_t i = 0; i < 10; i++) { |
| 737 | QuicPacketNumber last = QuicPacketNumber(kEpoch - i); |
| 738 | |
| 739 | // Small numbers should wrap. |
| 740 | for (uint64_t j = 0; j < 10; j++) { |
| 741 | CheckCalculatePacketNumber(kEpoch + j, last); |
| 742 | } |
| 743 | |
| 744 | // Large numbers should not (even if they're out of order). |
| 745 | for (uint64_t j = 0; j < 10; j++) { |
| 746 | CheckCalculatePacketNumber(kEpoch - 1 - j, last); |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | // Next check where we're in a non-zero epoch to verify we handle |
| 752 | // reverse wrapping, too. |
| 753 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearPrevEpoch) { |
| 754 | const uint64_t prev_epoch = 1 * kEpoch; |
| 755 | const uint64_t cur_epoch = 2 * kEpoch; |
| 756 | // Cases where the last number was close to the start of the range |
| 757 | for (uint64_t i = 0; i < 10; i++) { |
| 758 | QuicPacketNumber last = QuicPacketNumber(cur_epoch + i); |
| 759 | // Small number should not wrap (even if they're out of order). |
| 760 | for (uint64_t j = 0; j < 10; j++) { |
| 761 | CheckCalculatePacketNumber(cur_epoch + j, last); |
| 762 | } |
| 763 | |
| 764 | // But large numbers should reverse wrap. |
| 765 | for (uint64_t j = 0; j < 10; j++) { |
| 766 | uint64_t num = kEpoch - 1 - j; |
| 767 | CheckCalculatePacketNumber(prev_epoch + num, last); |
| 768 | } |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextEpoch) { |
| 773 | const uint64_t cur_epoch = 2 * kEpoch; |
| 774 | const uint64_t next_epoch = 3 * kEpoch; |
| 775 | // Cases where the last number was close to the end of the range |
| 776 | for (uint64_t i = 0; i < 10; i++) { |
| 777 | QuicPacketNumber last = QuicPacketNumber(next_epoch - 1 - i); |
| 778 | |
| 779 | // Small numbers should wrap. |
| 780 | for (uint64_t j = 0; j < 10; j++) { |
| 781 | CheckCalculatePacketNumber(next_epoch + j, last); |
| 782 | } |
| 783 | |
| 784 | // but large numbers should not (even if they're out of order). |
| 785 | for (uint64_t j = 0; j < 10; j++) { |
| 786 | uint64_t num = kEpoch - 1 - j; |
| 787 | CheckCalculatePacketNumber(cur_epoch + num, last); |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextMax) { |
| 793 | const uint64_t max_number = std::numeric_limits<uint64_t>::max(); |
| 794 | const uint64_t max_epoch = max_number & ~kMask; |
| 795 | |
| 796 | // Cases where the last number was close to the end of the range |
| 797 | for (uint64_t i = 0; i < 10; i++) { |
| 798 | // Subtract 1, because the expected next packet number is 1 more than the |
| 799 | // last packet number. |
| 800 | QuicPacketNumber last = QuicPacketNumber(max_number - i - 1); |
| 801 | |
| 802 | // Small numbers should not wrap, because they have nowhere to go. |
| 803 | for (uint64_t j = 0; j < 10; j++) { |
| 804 | CheckCalculatePacketNumber(max_epoch + j, last); |
| 805 | } |
| 806 | |
| 807 | // Large numbers should not wrap either. |
| 808 | for (uint64_t j = 0; j < 10; j++) { |
| 809 | uint64_t num = kEpoch - 1 - j; |
| 810 | CheckCalculatePacketNumber(max_epoch + num, last); |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | TEST_P(QuicFramerTest, EmptyPacket) { |
| 816 | char packet[] = {0x00}; |
| 817 | QuicEncryptedPacket encrypted(packet, 0, false); |
| 818 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 819 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
| 820 | } |
| 821 | |
| 822 | TEST_P(QuicFramerTest, LargePacket) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 823 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 824 | // clang-format off |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 825 | unsigned char packet[kMaxIncomingPacketSize + 1] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 826 | // public flags (8 byte connection_id) |
| 827 | 0x28, |
| 828 | // connection_id |
| 829 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 830 | // packet number |
| 831 | 0x78, 0x56, 0x34, 0x12, |
| 832 | // private flags |
| 833 | 0x00, |
| 834 | }; |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 835 | unsigned char packet44[kMaxIncomingPacketSize + 1] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 836 | // type (short header 4 byte packet number) |
| 837 | 0x32, |
| 838 | // connection_id |
| 839 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 840 | // packet number |
| 841 | 0x78, 0x56, 0x34, 0x12, |
| 842 | }; |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 843 | unsigned char packet46[kMaxIncomingPacketSize + 1] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 844 | // type (short header 4 byte packet number) |
| 845 | 0x43, |
| 846 | // connection_id |
| 847 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 848 | // packet number |
| 849 | 0x78, 0x56, 0x34, 0x12, |
| 850 | }; |
| 851 | // clang-format on |
| 852 | unsigned char* p = packet; |
| 853 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 854 | if (framer_.transport_version() > QUIC_VERSION_44) { |
| 855 | p = packet46; |
| 856 | p_size = QUIC_ARRAYSIZE(packet46); |
| 857 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 858 | p = packet44; |
| 859 | p_size = QUIC_ARRAYSIZE(packet44); |
| 860 | } |
| 861 | |
| 862 | const size_t header_size = GetPacketHeaderSize( |
| 863 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 864 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 865 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 866 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 867 | |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 868 | memset(p + header_size, 0, kMaxIncomingPacketSize - header_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 869 | |
| 870 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 871 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 872 | |
| 873 | ASSERT_TRUE(visitor_.header_.get()); |
| 874 | // Make sure we've parsed the packet header, so we can send an error. |
| 875 | EXPECT_EQ(FramerTestConnectionId(), |
| 876 | visitor_.header_->destination_connection_id); |
| 877 | // Make sure the correct error is propagated. |
| 878 | EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error()); |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 879 | EXPECT_EQ("Packet too large.", framer_.detailed_error()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | TEST_P(QuicFramerTest, PacketHeader) { |
| 883 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 884 | return; |
| 885 | } |
| 886 | |
| 887 | // clang-format off |
| 888 | PacketFragments packet = { |
| 889 | // public flags (8 byte connection_id) |
| 890 | {"Unable to read public flags.", |
| 891 | {0x28}}, |
| 892 | // connection_id |
| 893 | {"Unable to read ConnectionId.", |
| 894 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 895 | // packet number |
| 896 | {"Unable to read packet number.", |
| 897 | {0x12, 0x34, 0x56, 0x78}}, |
| 898 | }; |
| 899 | // clang-format on |
| 900 | |
| 901 | PacketFragments& fragments = packet; |
| 902 | |
| 903 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 904 | AssemblePacketFromFragments(fragments)); |
| 905 | |
| 906 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 907 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 908 | ASSERT_TRUE(visitor_.header_.get()); |
| 909 | EXPECT_EQ(FramerTestConnectionId(), |
| 910 | visitor_.header_->destination_connection_id); |
| 911 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 912 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 913 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 914 | |
| 915 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 916 | } |
| 917 | |
| 918 | TEST_P(QuicFramerTest, LongPacketHeader) { |
| 919 | // clang-format off |
| 920 | PacketFragments packet44 = { |
| 921 | // type (long header with packet type INITIAL) |
| 922 | {"Unable to read type.", |
| 923 | {0xFF}}, |
| 924 | // version tag |
| 925 | {"Unable to read protocol version.", |
| 926 | {QUIC_VERSION_BYTES}}, |
| 927 | // connection_id length |
| 928 | {"Unable to read ConnectionId length.", |
| 929 | {0x50}}, |
| 930 | // connection_id |
| 931 | {"Unable to read Destination ConnectionId.", |
| 932 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 933 | // packet number |
| 934 | {"Unable to read packet number.", |
| 935 | {0x12, 0x34, 0x56, 0x78}}, |
| 936 | }; |
| 937 | PacketFragments packet46 = { |
| 938 | // type (long header with packet type INITIAL) |
| 939 | {"Unable to read type.", |
| 940 | {0xC3}}, |
| 941 | // version tag |
| 942 | {"Unable to read protocol version.", |
| 943 | {QUIC_VERSION_BYTES}}, |
| 944 | // connection_id length |
| 945 | {"Unable to read ConnectionId length.", |
| 946 | {0x50}}, |
| 947 | // connection_id |
| 948 | {"Unable to read Destination ConnectionId.", |
| 949 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 950 | // packet number |
| 951 | {"Unable to read packet number.", |
| 952 | {0x12, 0x34, 0x56, 0x78}}, |
| 953 | }; |
| 954 | // clang-format on |
| 955 | |
| 956 | if (framer_.transport_version() <= QUIC_VERSION_43 || |
| 957 | QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 958 | return; |
| 959 | } |
| 960 | |
| 961 | PacketFragments& fragments = |
| 962 | framer_.transport_version() > QUIC_VERSION_44 ? packet46 : packet44; |
| 963 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 964 | AssemblePacketFromFragments(fragments)); |
| 965 | |
| 966 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 967 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 968 | ASSERT_TRUE(visitor_.header_.get()); |
| 969 | EXPECT_EQ(FramerTestConnectionId(), |
| 970 | visitor_.header_->destination_connection_id); |
| 971 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 972 | EXPECT_TRUE(visitor_.header_->version_flag); |
| 973 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 974 | |
| 975 | CheckFramingBoundaries( |
| 976 | framer_.transport_version() > QUIC_VERSION_44 ? packet46 : packet44, |
| 977 | QUIC_INVALID_PACKET_HEADER); |
| 978 | } |
| 979 | |
| 980 | TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 981 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 982 | QuicFramerPeer::SetLastSerializedConnectionId(&framer_, |
| 983 | FramerTestConnectionId()); |
| 984 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 985 | |
| 986 | // clang-format off |
| 987 | PacketFragments packet = { |
| 988 | // public flags (0 byte connection_id) |
| 989 | {"Unable to read public flags.", |
| 990 | {0x20}}, |
| 991 | // connection_id |
| 992 | // packet number |
| 993 | {"Unable to read packet number.", |
| 994 | {0x12, 0x34, 0x56, 0x78}}, |
| 995 | }; |
| 996 | |
| 997 | PacketFragments packet44 = { |
| 998 | // type (short header, 4 byte packet number) |
| 999 | {"Unable to read type.", |
| 1000 | {0x32}}, |
| 1001 | // connection_id |
| 1002 | // packet number |
| 1003 | {"Unable to read packet number.", |
| 1004 | {0x12, 0x34, 0x56, 0x78}}, |
| 1005 | }; |
| 1006 | |
| 1007 | PacketFragments packet46 = { |
| 1008 | // type (short header, 4 byte packet number) |
| 1009 | {"Unable to read type.", |
| 1010 | {0x43}}, |
| 1011 | // connection_id |
| 1012 | // packet number |
| 1013 | {"Unable to read packet number.", |
| 1014 | {0x12, 0x34, 0x56, 0x78}}, |
| 1015 | }; |
| 1016 | // clang-format on |
| 1017 | |
| 1018 | PacketFragments& fragments = |
| 1019 | framer_.transport_version() > QUIC_VERSION_44 |
| 1020 | ? packet46 |
| 1021 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 1022 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1023 | AssemblePacketFromFragments(fragments)); |
| 1024 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1025 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1026 | ASSERT_TRUE(visitor_.header_.get()); |
| 1027 | EXPECT_EQ(FramerTestConnectionId(), |
| 1028 | visitor_.header_->destination_connection_id); |
| 1029 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1030 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1031 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1032 | |
| 1033 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1034 | } |
| 1035 | |
| 1036 | TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1037 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1038 | // clang-format off |
| 1039 | PacketFragments packet = { |
| 1040 | // public flags (0 byte connection_id) |
| 1041 | {"Unable to read public flags.", |
| 1042 | {0x29}}, |
| 1043 | // connection_id |
| 1044 | {"Unable to read ConnectionId.", |
| 1045 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1046 | // version tag |
| 1047 | {"Unable to read protocol version.", |
| 1048 | {QUIC_VERSION_BYTES}}, |
| 1049 | // packet number |
| 1050 | {"Unable to read packet number.", |
| 1051 | {0x12, 0x34, 0x56, 0x78}}, |
| 1052 | }; |
| 1053 | |
| 1054 | PacketFragments packet44 = { |
| 1055 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 1056 | {"Unable to read type.", |
| 1057 | {0xFC}}, |
| 1058 | // version tag |
| 1059 | {"Unable to read protocol version.", |
| 1060 | {QUIC_VERSION_BYTES}}, |
| 1061 | // connection_id length |
| 1062 | {"Unable to read ConnectionId length.", |
| 1063 | {0x50}}, |
| 1064 | // connection_id |
| 1065 | {"Unable to read Destination ConnectionId.", |
| 1066 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1067 | // packet number |
| 1068 | {"Unable to read packet number.", |
| 1069 | {0x12, 0x34, 0x56, 0x78}}, |
| 1070 | }; |
| 1071 | |
| 1072 | PacketFragments packet46 = { |
| 1073 | // type (long header with packet type ZERO_RTT_PROTECTED and 4 bytes |
| 1074 | // packet number) |
| 1075 | {"Unable to read type.", |
| 1076 | {0xD3}}, |
| 1077 | // version tag |
| 1078 | {"Unable to read protocol version.", |
| 1079 | {QUIC_VERSION_BYTES}}, |
| 1080 | // connection_id length |
| 1081 | {"Unable to read ConnectionId length.", |
| 1082 | {0x50}}, |
| 1083 | // connection_id |
| 1084 | {"Unable to read Destination ConnectionId.", |
| 1085 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1086 | // packet number |
| 1087 | {"Unable to read packet number.", |
| 1088 | {0x12, 0x34, 0x56, 0x78}}, |
| 1089 | }; |
| 1090 | |
| 1091 | PacketFragments packet99 = { |
| 1092 | // type (long header with packet type ZERO_RTT_PROTECTED and 4 bytes |
| 1093 | // packet number) |
| 1094 | {"Unable to read type.", |
| 1095 | {0xD3}}, |
| 1096 | // version tag |
| 1097 | {"Unable to read protocol version.", |
| 1098 | {QUIC_VERSION_BYTES}}, |
| 1099 | // connection_id length |
| 1100 | {"Unable to read ConnectionId length.", |
| 1101 | {0x50}}, |
| 1102 | // connection_id |
| 1103 | {"Unable to read Destination ConnectionId.", |
| 1104 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1105 | // long header packet length |
| 1106 | {"Unable to read long header payload length.", |
| 1107 | {0x04}}, |
| 1108 | // packet number |
| 1109 | {"Long header payload length longer than packet.", |
| 1110 | {0x12, 0x34, 0x56, 0x78}}, |
| 1111 | }; |
| 1112 | // clang-format on |
| 1113 | |
| 1114 | PacketFragments& fragments = |
| 1115 | framer_.transport_version() == QUIC_VERSION_99 |
| 1116 | ? packet99 |
| 1117 | : framer_.transport_version() > QUIC_VERSION_44 |
| 1118 | ? packet46 |
| 1119 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 1120 | : packet); |
| 1121 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1122 | AssemblePacketFromFragments(fragments)); |
| 1123 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1124 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1125 | ASSERT_TRUE(visitor_.header_.get()); |
| 1126 | EXPECT_EQ(FramerTestConnectionId(), |
| 1127 | visitor_.header_->destination_connection_id); |
| 1128 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1129 | EXPECT_TRUE(visitor_.header_->version_flag); |
| 1130 | EXPECT_EQ(GetParam(), visitor_.header_->version); |
| 1131 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1132 | |
| 1133 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1134 | } |
| 1135 | |
| 1136 | TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1137 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1138 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1139 | |
| 1140 | // clang-format off |
| 1141 | PacketFragments packet = { |
| 1142 | // public flags (8 byte connection_id and 4 byte packet number) |
| 1143 | {"Unable to read public flags.", |
| 1144 | {0x28}}, |
| 1145 | // connection_id |
| 1146 | {"Unable to read ConnectionId.", |
| 1147 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1148 | // packet number |
| 1149 | {"Unable to read packet number.", |
| 1150 | {0x12, 0x34, 0x56, 0x78}}, |
| 1151 | }; |
| 1152 | |
| 1153 | PacketFragments packet44 = { |
| 1154 | // type (short header, 4 byte packet number) |
| 1155 | {"Unable to read type.", |
| 1156 | {0x32}}, |
| 1157 | // connection_id |
| 1158 | {"Unable to read Destination ConnectionId.", |
| 1159 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1160 | // packet number |
| 1161 | {"Unable to read packet number.", |
| 1162 | {0x12, 0x34, 0x56, 0x78}}, |
| 1163 | }; |
| 1164 | |
| 1165 | PacketFragments packet46 = { |
| 1166 | // type (short header, 4 byte packet number) |
| 1167 | {"Unable to read type.", |
| 1168 | {0x43}}, |
| 1169 | // connection_id |
| 1170 | {"Unable to read Destination ConnectionId.", |
| 1171 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1172 | // packet number |
| 1173 | {"Unable to read packet number.", |
| 1174 | {0x12, 0x34, 0x56, 0x78}}, |
| 1175 | }; |
| 1176 | // clang-format on |
| 1177 | |
| 1178 | PacketFragments& fragments = |
| 1179 | framer_.transport_version() > QUIC_VERSION_44 |
| 1180 | ? packet46 |
| 1181 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 1182 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1183 | AssemblePacketFromFragments(fragments)); |
| 1184 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1185 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1186 | ASSERT_TRUE(visitor_.header_.get()); |
| 1187 | EXPECT_EQ(FramerTestConnectionId(), |
| 1188 | visitor_.header_->destination_connection_id); |
| 1189 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1190 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1191 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1192 | |
| 1193 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1194 | } |
| 1195 | |
| 1196 | TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1197 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1198 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1199 | |
| 1200 | // clang-format off |
| 1201 | PacketFragments packet = { |
| 1202 | // public flags (8 byte connection_id and 2 byte packet number) |
| 1203 | {"Unable to read public flags.", |
| 1204 | {0x18}}, |
| 1205 | // connection_id |
| 1206 | {"Unable to read ConnectionId.", |
| 1207 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1208 | // packet number |
| 1209 | {"Unable to read packet number.", |
| 1210 | {0x56, 0x78}}, |
| 1211 | }; |
| 1212 | |
| 1213 | PacketFragments packet44 = { |
| 1214 | // type (short header, 2 byte packet number) |
| 1215 | {"Unable to read type.", |
| 1216 | {0x31}}, |
| 1217 | // connection_id |
| 1218 | {"Unable to read Destination ConnectionId.", |
| 1219 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1220 | // packet number |
| 1221 | {"Unable to read packet number.", |
| 1222 | {0x56, 0x78}}, |
| 1223 | }; |
| 1224 | |
| 1225 | PacketFragments packet46 = { |
| 1226 | // type (short header, 2 byte packet number) |
| 1227 | {"Unable to read type.", |
| 1228 | {0x41}}, |
| 1229 | // connection_id |
| 1230 | {"Unable to read Destination ConnectionId.", |
| 1231 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1232 | // packet number |
| 1233 | {"Unable to read packet number.", |
| 1234 | {0x56, 0x78}}, |
| 1235 | }; |
| 1236 | // clang-format on |
| 1237 | |
| 1238 | PacketFragments& fragments = |
| 1239 | framer_.transport_version() > QUIC_VERSION_44 |
| 1240 | ? packet46 |
| 1241 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 1242 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1243 | AssemblePacketFromFragments(fragments)); |
| 1244 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1245 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1246 | ASSERT_TRUE(visitor_.header_.get()); |
| 1247 | EXPECT_EQ(FramerTestConnectionId(), |
| 1248 | visitor_.header_->destination_connection_id); |
| 1249 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1250 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1251 | EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1252 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1253 | |
| 1254 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1255 | } |
| 1256 | |
| 1257 | TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1258 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1259 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1260 | |
| 1261 | // clang-format off |
| 1262 | PacketFragments packet = { |
| 1263 | // public flags (8 byte connection_id and 1 byte packet number) |
| 1264 | {"Unable to read public flags.", |
| 1265 | {0x08}}, |
| 1266 | // connection_id |
| 1267 | {"Unable to read ConnectionId.", |
| 1268 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1269 | // packet number |
| 1270 | {"Unable to read packet number.", |
| 1271 | {0x78}}, |
| 1272 | }; |
| 1273 | |
| 1274 | PacketFragments packet44 = { |
| 1275 | // type (8 byte connection_id and 1 byte packet number) |
| 1276 | {"Unable to read type.", |
| 1277 | {0x30}}, |
| 1278 | // connection_id |
| 1279 | {"Unable to read Destination ConnectionId.", |
| 1280 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1281 | // packet number |
| 1282 | {"Unable to read packet number.", |
| 1283 | {0x78}}, |
| 1284 | }; |
| 1285 | |
| 1286 | PacketFragments packet46 = { |
| 1287 | // type (8 byte connection_id and 1 byte packet number) |
| 1288 | {"Unable to read type.", |
| 1289 | {0x40}}, |
| 1290 | // connection_id |
| 1291 | {"Unable to read Destination ConnectionId.", |
| 1292 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1293 | // packet number |
| 1294 | {"Unable to read packet number.", |
| 1295 | {0x78}}, |
| 1296 | }; |
| 1297 | |
| 1298 | // clang-format on |
| 1299 | |
| 1300 | PacketFragments& fragments = |
| 1301 | framer_.transport_version() > QUIC_VERSION_44 |
| 1302 | ? packet46 |
| 1303 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 1304 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1305 | AssemblePacketFromFragments(fragments)); |
| 1306 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1307 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1308 | ASSERT_TRUE(visitor_.header_.get()); |
| 1309 | EXPECT_EQ(FramerTestConnectionId(), |
| 1310 | visitor_.header_->destination_connection_id); |
| 1311 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1312 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1313 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1314 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1315 | |
| 1316 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1317 | } |
| 1318 | |
| 1319 | TEST_P(QuicFramerTest, PacketNumberDecreasesThenIncreases) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1320 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1321 | // Test the case when a packet is received from the past and future packet |
| 1322 | // numbers are still calculated relative to the largest received packet. |
| 1323 | QuicPacketHeader header; |
| 1324 | header.destination_connection_id = FramerTestConnectionId(); |
| 1325 | header.reset_flag = false; |
| 1326 | header.version_flag = false; |
| 1327 | header.packet_number = kPacketNumber - 2; |
| 1328 | |
| 1329 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 1330 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1331 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 1332 | ASSERT_TRUE(data != nullptr); |
| 1333 | |
| 1334 | QuicEncryptedPacket encrypted(data->data(), data->length(), false); |
| 1335 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1336 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1337 | ASSERT_TRUE(visitor_.header_.get()); |
| 1338 | EXPECT_EQ(FramerTestConnectionId(), |
| 1339 | visitor_.header_->destination_connection_id); |
| 1340 | EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1341 | EXPECT_EQ(kPacketNumber - 2, visitor_.header_->packet_number); |
| 1342 | |
| 1343 | // Receive a 1 byte packet number. |
| 1344 | header.packet_number = kPacketNumber; |
| 1345 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 1346 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1347 | data = BuildDataPacket(header, frames); |
| 1348 | QuicEncryptedPacket encrypted1(data->data(), data->length(), false); |
| 1349 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1350 | EXPECT_TRUE(framer_.ProcessPacket(encrypted1)); |
| 1351 | ASSERT_TRUE(visitor_.header_.get()); |
| 1352 | EXPECT_EQ(FramerTestConnectionId(), |
| 1353 | visitor_.header_->destination_connection_id); |
| 1354 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1355 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1356 | |
| 1357 | // Process a 2 byte packet number 256 packets ago. |
| 1358 | header.packet_number = kPacketNumber - 256; |
| 1359 | header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; |
| 1360 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1361 | data = BuildDataPacket(header, frames); |
| 1362 | QuicEncryptedPacket encrypted2(data->data(), data->length(), false); |
| 1363 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1364 | EXPECT_TRUE(framer_.ProcessPacket(encrypted2)); |
| 1365 | ASSERT_TRUE(visitor_.header_.get()); |
| 1366 | EXPECT_EQ(FramerTestConnectionId(), |
| 1367 | visitor_.header_->destination_connection_id); |
| 1368 | EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1369 | EXPECT_EQ(kPacketNumber - 256, visitor_.header_->packet_number); |
| 1370 | |
| 1371 | // Process another 1 byte packet number and ensure it works. |
| 1372 | header.packet_number = kPacketNumber - 1; |
| 1373 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 1374 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1375 | data = BuildDataPacket(header, frames); |
| 1376 | QuicEncryptedPacket encrypted3(data->data(), data->length(), false); |
| 1377 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1378 | EXPECT_TRUE(framer_.ProcessPacket(encrypted3)); |
| 1379 | ASSERT_TRUE(visitor_.header_.get()); |
| 1380 | EXPECT_EQ(FramerTestConnectionId(), |
| 1381 | visitor_.header_->destination_connection_id); |
| 1382 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1383 | EXPECT_EQ(kPacketNumber - 1, visitor_.header_->packet_number); |
| 1384 | } |
| 1385 | |
| 1386 | TEST_P(QuicFramerTest, PacketWithDiversificationNonce) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1387 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1388 | // clang-format off |
| 1389 | unsigned char packet[] = { |
| 1390 | // public flags: includes nonce flag |
| 1391 | 0x2C, |
| 1392 | // connection_id |
| 1393 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1394 | // nonce |
| 1395 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1396 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1397 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1398 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1399 | // packet number |
| 1400 | 0x12, 0x34, 0x56, 0x78, |
| 1401 | |
| 1402 | // frame type (padding) |
| 1403 | 0x00, |
| 1404 | 0x00, 0x00, 0x00, 0x00 |
| 1405 | }; |
| 1406 | |
| 1407 | unsigned char packet44[] = { |
| 1408 | // type: Long header with packet type ZERO_RTT_PROTECTED |
| 1409 | 0xFC, |
| 1410 | // version tag |
| 1411 | QUIC_VERSION_BYTES, |
| 1412 | // connection_id length |
| 1413 | 0x05, |
| 1414 | // connection_id |
| 1415 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1416 | // packet number |
| 1417 | 0x12, 0x34, 0x56, 0x78, |
| 1418 | // nonce |
| 1419 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1420 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1421 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1422 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1423 | |
| 1424 | // frame type (padding) |
| 1425 | 0x00, |
| 1426 | 0x00, 0x00, 0x00, 0x00 |
| 1427 | }; |
| 1428 | |
| 1429 | unsigned char packet46[] = { |
| 1430 | // type: Long header with packet type ZERO_RTT_PROTECTED and 1 byte packet |
| 1431 | // number. |
| 1432 | 0xD0, |
| 1433 | // version tag |
| 1434 | QUIC_VERSION_BYTES, |
| 1435 | // connection_id length |
| 1436 | 0x05, |
| 1437 | // connection_id |
| 1438 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1439 | // packet number |
| 1440 | 0x78, |
| 1441 | // nonce |
| 1442 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1443 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1444 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1445 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1446 | |
| 1447 | // frame type (padding) |
| 1448 | 0x00, |
| 1449 | 0x00, 0x00, 0x00, 0x00 |
| 1450 | }; |
| 1451 | |
| 1452 | unsigned char packet99[] = { |
| 1453 | // type: Long header with packet type ZERO_RTT_PROTECTED and 1 byte packet |
| 1454 | // number. |
| 1455 | 0xD0, |
| 1456 | // version tag |
| 1457 | QUIC_VERSION_BYTES, |
| 1458 | // connection_id length |
| 1459 | 0x05, |
| 1460 | // connection_id |
| 1461 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1462 | // long header packet length |
| 1463 | 0x26, |
| 1464 | // packet number |
| 1465 | 0x78, |
| 1466 | // nonce |
| 1467 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1468 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1469 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1470 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1471 | |
| 1472 | // frame type (padding) |
| 1473 | 0x00, |
| 1474 | 0x00, 0x00, 0x00, 0x00 |
| 1475 | }; |
| 1476 | // clang-format on |
| 1477 | |
| 1478 | if (framer_.version().handshake_protocol != PROTOCOL_QUIC_CRYPTO) { |
| 1479 | return; |
| 1480 | } |
| 1481 | |
| 1482 | unsigned char* p = packet; |
| 1483 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 1484 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 1485 | p = packet99; |
| 1486 | p_size = QUIC_ARRAYSIZE(packet99); |
| 1487 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 1488 | p = packet46; |
| 1489 | p_size = QUIC_ARRAYSIZE(packet46); |
| 1490 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 1491 | p = packet44; |
| 1492 | p_size = QUIC_ARRAYSIZE(packet44); |
| 1493 | } |
| 1494 | |
| 1495 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 1496 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1497 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1498 | ASSERT_TRUE(visitor_.header_->nonce != nullptr); |
| 1499 | for (char i = 0; i < 32; ++i) { |
| 1500 | EXPECT_EQ(i, (*visitor_.header_->nonce)[static_cast<size_t>(i)]); |
| 1501 | } |
| 1502 | EXPECT_EQ(1u, visitor_.padding_frames_.size()); |
| 1503 | EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes); |
| 1504 | } |
| 1505 | |
| 1506 | TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) { |
| 1507 | // clang-format off |
| 1508 | unsigned char packet[] = { |
| 1509 | // public flags (8 byte connection_id, version flag and an unknown flag) |
| 1510 | 0x29, |
| 1511 | // connection_id |
| 1512 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1513 | // version tag |
| 1514 | 'Q', '0', '0', '0', |
| 1515 | // packet number |
| 1516 | 0x12, 0x34, 0x56, 0x78, |
| 1517 | |
| 1518 | // frame type (padding frame) |
| 1519 | 0x00, |
| 1520 | 0x00, 0x00, 0x00, 0x00 |
| 1521 | }; |
| 1522 | |
| 1523 | unsigned char packet44[] = { |
| 1524 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 1525 | 0xFC, |
| 1526 | // version tag |
| 1527 | 'Q', '0', '0', '0', |
| 1528 | // connection_id length |
| 1529 | 0x50, |
| 1530 | // connection_id |
| 1531 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1532 | // packet number |
| 1533 | 0x12, 0x34, 0x56, 0x78, |
| 1534 | |
| 1535 | // frame type (padding frame) |
| 1536 | 0x00, |
| 1537 | 0x00, 0x00, 0x00, 0x00 |
| 1538 | }; |
| 1539 | // clang-format on |
| 1540 | |
| 1541 | QuicEncryptedPacket encrypted( |
| 1542 | AsChars(framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 1543 | : packet), |
| 1544 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 1545 | : QUIC_ARRAYSIZE(packet), |
| 1546 | false); |
| 1547 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1548 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1549 | ASSERT_TRUE(visitor_.header_.get()); |
| 1550 | EXPECT_EQ(0, visitor_.frame_count_); |
| 1551 | EXPECT_EQ(1, visitor_.version_mismatch_); |
| 1552 | EXPECT_EQ(1u, visitor_.padding_frames_.size()); |
| 1553 | EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes); |
| 1554 | } |
| 1555 | |
| 1556 | TEST_P(QuicFramerTest, PaddingFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1557 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1558 | // clang-format off |
| 1559 | unsigned char packet[] = { |
| 1560 | // public flags (8 byte connection_id) |
| 1561 | 0x28, |
| 1562 | // connection_id |
| 1563 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1564 | // packet number |
| 1565 | 0x12, 0x34, 0x56, 0x78, |
| 1566 | |
| 1567 | // paddings |
| 1568 | 0x00, 0x00, |
| 1569 | // frame type (stream frame with fin) |
| 1570 | 0xFF, |
| 1571 | // stream id |
| 1572 | 0x01, 0x02, 0x03, 0x04, |
| 1573 | // offset |
| 1574 | 0x3A, 0x98, 0xFE, 0xDC, |
| 1575 | 0x32, 0x10, 0x76, 0x54, |
| 1576 | // data length |
| 1577 | 0x00, 0x0c, |
| 1578 | // data |
| 1579 | 'h', 'e', 'l', 'l', |
| 1580 | 'o', ' ', 'w', 'o', |
| 1581 | 'r', 'l', 'd', '!', |
| 1582 | // paddings |
| 1583 | 0x00, 0x00, |
| 1584 | }; |
| 1585 | |
| 1586 | unsigned char packet44[] = { |
| 1587 | // type (short header, 4 byte packet number) |
| 1588 | 0x32, |
| 1589 | // connection_id |
| 1590 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1591 | // packet number |
| 1592 | 0x12, 0x34, 0x56, 0x78, |
| 1593 | |
| 1594 | // paddings |
| 1595 | 0x00, 0x00, |
| 1596 | // frame type (stream frame with fin) |
| 1597 | 0xFF, |
| 1598 | // stream id |
| 1599 | 0x01, 0x02, 0x03, 0x04, |
| 1600 | // offset |
| 1601 | 0x3A, 0x98, 0xFE, 0xDC, |
| 1602 | 0x32, 0x10, 0x76, 0x54, |
| 1603 | // data length |
| 1604 | 0x00, 0x0c, |
| 1605 | // data |
| 1606 | 'h', 'e', 'l', 'l', |
| 1607 | 'o', ' ', 'w', 'o', |
| 1608 | 'r', 'l', 'd', '!', |
| 1609 | // paddings |
| 1610 | 0x00, 0x00, |
| 1611 | }; |
| 1612 | |
| 1613 | unsigned char packet46[] = { |
| 1614 | // type (short header, 4 byte packet number) |
| 1615 | 0x43, |
| 1616 | // connection_id |
| 1617 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1618 | // packet number |
| 1619 | 0x12, 0x34, 0x56, 0x78, |
| 1620 | |
| 1621 | // paddings |
| 1622 | 0x00, 0x00, |
| 1623 | // frame type (stream frame with fin) |
| 1624 | 0xFF, |
| 1625 | // stream id |
| 1626 | 0x01, 0x02, 0x03, 0x04, |
| 1627 | // offset |
| 1628 | 0x3A, 0x98, 0xFE, 0xDC, |
| 1629 | 0x32, 0x10, 0x76, 0x54, |
| 1630 | // data length |
| 1631 | 0x00, 0x0c, |
| 1632 | // data |
| 1633 | 'h', 'e', 'l', 'l', |
| 1634 | 'o', ' ', 'w', 'o', |
| 1635 | 'r', 'l', 'd', '!', |
| 1636 | // paddings |
| 1637 | 0x00, 0x00, |
| 1638 | }; |
| 1639 | |
| 1640 | unsigned char packet99[] = { |
| 1641 | // type (short header, 4 byte packet number) |
| 1642 | 0x43, |
| 1643 | // connection_id |
| 1644 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1645 | // packet number |
| 1646 | 0x12, 0x34, 0x56, 0x78, |
| 1647 | |
| 1648 | // paddings |
| 1649 | 0x00, 0x00, |
| 1650 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 1651 | 0x08 | 0x01 | 0x02 | 0x04, |
| 1652 | |
| 1653 | // stream id |
| 1654 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 1655 | // offset |
| 1656 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 1657 | 0x32, 0x10, 0x76, 0x54, |
| 1658 | // data length |
| 1659 | kVarInt62OneByte + 0x0c, |
| 1660 | // data |
| 1661 | 'h', 'e', 'l', 'l', |
| 1662 | 'o', ' ', 'w', 'o', |
| 1663 | 'r', 'l', 'd', '!', |
| 1664 | // paddings |
| 1665 | 0x00, 0x00, |
| 1666 | }; |
| 1667 | // clang-format on |
| 1668 | |
| 1669 | unsigned char* p = packet; |
| 1670 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 1671 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 1672 | p = packet99; |
| 1673 | p_size = QUIC_ARRAYSIZE(packet99); |
| 1674 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 1675 | p = packet46; |
| 1676 | p_size = QUIC_ARRAYSIZE(packet46); |
| 1677 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 1678 | p = packet44; |
| 1679 | p_size = QUIC_ARRAYSIZE(packet44); |
| 1680 | } |
| 1681 | |
| 1682 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 1683 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1684 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1685 | ASSERT_TRUE(visitor_.header_.get()); |
| 1686 | EXPECT_TRUE(CheckDecryption( |
| 1687 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 1688 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 1689 | |
| 1690 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1691 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1692 | EXPECT_EQ(2u, visitor_.padding_frames_.size()); |
| 1693 | EXPECT_EQ(2, visitor_.padding_frames_[0]->num_padding_bytes); |
| 1694 | EXPECT_EQ(2, visitor_.padding_frames_[1]->num_padding_bytes); |
| 1695 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 1696 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1697 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 1698 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 1699 | } |
| 1700 | |
| 1701 | TEST_P(QuicFramerTest, StreamFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1702 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1703 | // clang-format off |
| 1704 | PacketFragments packet = { |
| 1705 | // public flags (8 byte connection_id) |
| 1706 | {"", |
| 1707 | {0x28}}, |
| 1708 | // connection_id |
| 1709 | {"", |
| 1710 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1711 | // packet number |
| 1712 | {"", |
| 1713 | {0x12, 0x34, 0x56, 0x78}}, |
| 1714 | // frame type (stream frame with fin) |
| 1715 | {"", |
| 1716 | {0xFF}}, |
| 1717 | // stream id |
| 1718 | {"Unable to read stream_id.", |
| 1719 | {0x01, 0x02, 0x03, 0x04}}, |
| 1720 | // offset |
| 1721 | {"Unable to read offset.", |
| 1722 | {0x3A, 0x98, 0xFE, 0xDC, |
| 1723 | 0x32, 0x10, 0x76, 0x54}}, |
| 1724 | {"Unable to read frame data.", |
| 1725 | { |
| 1726 | // data length |
| 1727 | 0x00, 0x0c, |
| 1728 | // data |
| 1729 | 'h', 'e', 'l', 'l', |
| 1730 | 'o', ' ', 'w', 'o', |
| 1731 | 'r', 'l', 'd', '!'}}, |
| 1732 | }; |
| 1733 | |
| 1734 | PacketFragments packet44 = { |
| 1735 | // type (short header, 4 byte packet number) |
| 1736 | {"", |
| 1737 | {0x32}}, |
| 1738 | // connection_id |
| 1739 | {"", |
| 1740 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1741 | // packet number |
| 1742 | {"", |
| 1743 | {0x12, 0x34, 0x56, 0x78}}, |
| 1744 | // frame type (stream frame with fin) |
| 1745 | {"", |
| 1746 | {0xFF}}, |
| 1747 | // stream id |
| 1748 | {"Unable to read stream_id.", |
| 1749 | {0x01, 0x02, 0x03, 0x04}}, |
| 1750 | // offset |
| 1751 | {"Unable to read offset.", |
| 1752 | {0x3A, 0x98, 0xFE, 0xDC, |
| 1753 | 0x32, 0x10, 0x76, 0x54}}, |
| 1754 | {"Unable to read frame data.", |
| 1755 | { |
| 1756 | // data length |
| 1757 | 0x00, 0x0c, |
| 1758 | // data |
| 1759 | 'h', 'e', 'l', 'l', |
| 1760 | 'o', ' ', 'w', 'o', |
| 1761 | 'r', 'l', 'd', '!'}}, |
| 1762 | }; |
| 1763 | |
| 1764 | PacketFragments packet46 = { |
| 1765 | // type (short header, 4 byte packet number) |
| 1766 | {"", |
| 1767 | {0x43}}, |
| 1768 | // connection_id |
| 1769 | {"", |
| 1770 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1771 | // packet number |
| 1772 | {"", |
| 1773 | {0x12, 0x34, 0x56, 0x78}}, |
| 1774 | // frame type (stream frame with fin) |
| 1775 | {"", |
| 1776 | {0xFF}}, |
| 1777 | // stream id |
| 1778 | {"Unable to read stream_id.", |
| 1779 | {0x01, 0x02, 0x03, 0x04}}, |
| 1780 | // offset |
| 1781 | {"Unable to read offset.", |
| 1782 | {0x3A, 0x98, 0xFE, 0xDC, |
| 1783 | 0x32, 0x10, 0x76, 0x54}}, |
| 1784 | {"Unable to read frame data.", |
| 1785 | { |
| 1786 | // data length |
| 1787 | 0x00, 0x0c, |
| 1788 | // data |
| 1789 | 'h', 'e', 'l', 'l', |
| 1790 | 'o', ' ', 'w', 'o', |
| 1791 | 'r', 'l', 'd', '!'}}, |
| 1792 | }; |
| 1793 | |
| 1794 | PacketFragments packet99 = { |
| 1795 | // type (short header, 4 byte packet number) |
| 1796 | {"", |
| 1797 | {0x43}}, |
| 1798 | // connection_id |
| 1799 | {"", |
| 1800 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1801 | // packet number |
| 1802 | {"", |
| 1803 | {0x12, 0x34, 0x56, 0x78}}, |
| 1804 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 1805 | {"", |
| 1806 | { 0x08 | 0x01 | 0x02 | 0x04 }}, |
| 1807 | // stream id |
| 1808 | {"Unable to read stream_id.", |
| 1809 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 1810 | // offset |
| 1811 | {"Unable to read stream data offset.", |
| 1812 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 1813 | 0x32, 0x10, 0x76, 0x54}}, |
| 1814 | // data length |
| 1815 | {"Unable to read stream data length.", |
| 1816 | {kVarInt62OneByte + 0x0c}}, |
| 1817 | // data |
| 1818 | {"Unable to read frame data.", |
| 1819 | { 'h', 'e', 'l', 'l', |
| 1820 | 'o', ' ', 'w', 'o', |
| 1821 | 'r', 'l', 'd', '!'}}, |
| 1822 | }; |
| 1823 | // clang-format on |
| 1824 | |
| 1825 | PacketFragments& fragments = |
| 1826 | framer_.transport_version() == QUIC_VERSION_99 |
| 1827 | ? packet99 |
| 1828 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 1829 | ? packet46 |
| 1830 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 1831 | : packet)); |
| 1832 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1833 | AssemblePacketFromFragments(fragments)); |
| 1834 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 1835 | |
| 1836 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1837 | ASSERT_TRUE(visitor_.header_.get()); |
| 1838 | EXPECT_TRUE(CheckDecryption( |
| 1839 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 1840 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 1841 | |
| 1842 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1843 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1844 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 1845 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1846 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 1847 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 1848 | |
| 1849 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 1850 | } |
| 1851 | |
| 1852 | // Test an empty (no data) stream frame. |
| 1853 | TEST_P(QuicFramerTest, EmptyStreamFrame) { |
| 1854 | // Only the IETF QUIC spec explicitly says that empty |
| 1855 | // stream frames are supported. |
| 1856 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 1857 | return; |
| 1858 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1859 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1860 | // clang-format off |
| 1861 | PacketFragments packet = { |
| 1862 | // type (short header, 4 byte packet number) |
| 1863 | {"", |
| 1864 | {0x43}}, |
| 1865 | // connection_id |
| 1866 | {"", |
| 1867 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1868 | // packet number |
| 1869 | {"", |
| 1870 | {0x12, 0x34, 0x56, 0x78}}, |
| 1871 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 1872 | {"", |
| 1873 | { 0x08 | 0x01 | 0x02 | 0x04 }}, |
| 1874 | // stream id |
| 1875 | {"Unable to read stream_id.", |
| 1876 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 1877 | // offset |
| 1878 | {"Unable to read stream data offset.", |
| 1879 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 1880 | 0x32, 0x10, 0x76, 0x54}}, |
| 1881 | // data length |
| 1882 | {"Unable to read stream data length.", |
| 1883 | {kVarInt62OneByte + 0x00}}, |
| 1884 | }; |
| 1885 | // clang-format on |
| 1886 | |
| 1887 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1888 | AssemblePacketFromFragments(packet)); |
| 1889 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 1890 | |
| 1891 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1892 | ASSERT_TRUE(visitor_.header_.get()); |
| 1893 | EXPECT_TRUE(CheckDecryption( |
| 1894 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 1895 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 1896 | |
| 1897 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1898 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1899 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 1900 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1901 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 1902 | EXPECT_EQ(visitor_.stream_frames_[0].get()->data_length, 0u); |
| 1903 | |
| 1904 | CheckFramingBoundaries(packet, QUIC_INVALID_STREAM_DATA); |
| 1905 | } |
| 1906 | |
| 1907 | TEST_P(QuicFramerTest, MissingDiversificationNonce) { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1908 | if (framer_.version().handshake_protocol != PROTOCOL_QUIC_CRYPTO) { |
| 1909 | // TLS does not use diversification nonces. |
| 1910 | return; |
| 1911 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1912 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1913 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1914 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 1915 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, QuicMakeUnique<NullDecrypter>( |
| 1916 | Perspective::IS_CLIENT)); |
| 1917 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 1918 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 1919 | } else { |
| 1920 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 1921 | QuicMakeUnique<NullDecrypter>(Perspective::IS_CLIENT)); |
| 1922 | framer_.SetAlternativeDecrypter( |
| 1923 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 1924 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1925 | |
| 1926 | // clang-format off |
| 1927 | unsigned char packet[] = { |
| 1928 | // public flags (8 byte connection_id) |
| 1929 | 0x28, |
| 1930 | // connection_id |
| 1931 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 1932 | // packet number |
| 1933 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1934 | // padding frame |
| 1935 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1936 | }; |
| 1937 | |
| 1938 | unsigned char packet44[] = { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1939 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1940 | 0xFC, |
| 1941 | // version tag |
| 1942 | QUIC_VERSION_BYTES, |
| 1943 | // connection_id length |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1944 | 0x05, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1945 | // connection_id |
| 1946 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 1947 | // packet number |
| 1948 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1949 | // padding frame |
| 1950 | 0x00, |
| 1951 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1952 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1953 | unsigned char packet46[] = { |
| 1954 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 1955 | 0xD3, |
| 1956 | // version tag |
| 1957 | QUIC_VERSION_BYTES, |
| 1958 | // connection_id length |
| 1959 | 0x05, |
| 1960 | // connection_id |
| 1961 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 1962 | // packet number |
| 1963 | 0x12, 0x34, 0x56, 0x78, |
| 1964 | // padding frame |
| 1965 | 0x00, |
| 1966 | }; |
| 1967 | |
| 1968 | unsigned char packet99[] = { |
| 1969 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 1970 | 0xD3, |
| 1971 | // version tag |
| 1972 | QUIC_VERSION_BYTES, |
| 1973 | // connection_id length |
| 1974 | 0x05, |
| 1975 | // connection_id |
| 1976 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 1977 | // IETF long header payload length |
| 1978 | 0x05, |
| 1979 | // packet number |
| 1980 | 0x12, 0x34, 0x56, 0x78, |
| 1981 | // padding frame |
| 1982 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1983 | }; |
| 1984 | // clang-format on |
| 1985 | |
| 1986 | unsigned char* p = packet; |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1987 | size_t p_length = QUIC_ARRAYSIZE(packet); |
| 1988 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 1989 | p = packet99; |
| 1990 | p_length = QUIC_ARRAYSIZE(packet99); |
| 1991 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
| 1992 | p = packet46; |
| 1993 | p_length = QUIC_ARRAYSIZE(packet46); |
| 1994 | } else if (framer_.transport_version() >= QUIC_VERSION_44) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1995 | p = packet44; |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1996 | p_length = QUIC_ARRAYSIZE(packet44); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1997 | } |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1998 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1999 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2000 | if (framer_.transport_version() >= QUIC_VERSION_44) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2001 | // Cannot read diversification nonce. |
| 2002 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2003 | EXPECT_EQ("Unable to read nonce.", framer_.detailed_error()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2004 | } else { |
| 2005 | EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error()); |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { |
| 2010 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 2011 | // This test is nonsensical for IETF Quic. |
| 2012 | return; |
| 2013 | } |
| 2014 | // clang-format off |
| 2015 | PacketFragments packet = { |
| 2016 | // public flags (8 byte connection_id) |
| 2017 | {"", |
| 2018 | {0x28}}, |
| 2019 | // connection_id |
| 2020 | {"", |
| 2021 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2022 | // packet number |
| 2023 | {"", |
| 2024 | {0x12, 0x34, 0x56, 0x78}}, |
| 2025 | // frame type (stream frame with fin) |
| 2026 | {"", |
| 2027 | {0xFE}}, |
| 2028 | // stream id |
| 2029 | {"Unable to read stream_id.", |
| 2030 | {0x02, 0x03, 0x04}}, |
| 2031 | // offset |
| 2032 | {"Unable to read offset.", |
| 2033 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2034 | 0x32, 0x10, 0x76, 0x54}}, |
| 2035 | {"Unable to read frame data.", |
| 2036 | { |
| 2037 | // data length |
| 2038 | 0x00, 0x0c, |
| 2039 | // data |
| 2040 | 'h', 'e', 'l', 'l', |
| 2041 | 'o', ' ', 'w', 'o', |
| 2042 | 'r', 'l', 'd', '!'}}, |
| 2043 | }; |
| 2044 | // clang-format on |
| 2045 | |
| 2046 | PacketFragments& fragments = packet; |
| 2047 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2048 | AssemblePacketFromFragments(fragments)); |
| 2049 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2050 | |
| 2051 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2052 | ASSERT_TRUE(visitor_.header_.get()); |
| 2053 | EXPECT_TRUE(CheckDecryption( |
| 2054 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2055 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2056 | |
| 2057 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2058 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2059 | // Stream ID should be the last 3 bytes of kStreamId. |
| 2060 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2061 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2062 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2063 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2064 | |
| 2065 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2066 | } |
| 2067 | |
| 2068 | TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2069 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2070 | // clang-format off |
| 2071 | PacketFragments packet = { |
| 2072 | // public flags (8 byte connection_id) |
| 2073 | {"", |
| 2074 | {0x28}}, |
| 2075 | // connection_id |
| 2076 | {"", |
| 2077 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2078 | // packet number |
| 2079 | {"", |
| 2080 | {0x12, 0x34, 0x56, 0x78}}, |
| 2081 | // frame type (stream frame with fin) |
| 2082 | {"", |
| 2083 | {0xFD}}, |
| 2084 | // stream id |
| 2085 | {"Unable to read stream_id.", |
| 2086 | {0x03, 0x04}}, |
| 2087 | // offset |
| 2088 | {"Unable to read offset.", |
| 2089 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2090 | 0x32, 0x10, 0x76, 0x54}}, |
| 2091 | {"Unable to read frame data.", |
| 2092 | { |
| 2093 | // data length |
| 2094 | 0x00, 0x0c, |
| 2095 | // data |
| 2096 | 'h', 'e', 'l', 'l', |
| 2097 | 'o', ' ', 'w', 'o', |
| 2098 | 'r', 'l', 'd', '!'}}, |
| 2099 | }; |
| 2100 | |
| 2101 | PacketFragments packet44 = { |
| 2102 | // type (short header, 4 byte packet number) |
| 2103 | {"", |
| 2104 | {0x32}}, |
| 2105 | // connection_id |
| 2106 | {"", |
| 2107 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2108 | // packet number |
| 2109 | {"", |
| 2110 | {0x12, 0x34, 0x56, 0x78}}, |
| 2111 | // frame type (stream frame with fin) |
| 2112 | {"", |
| 2113 | {0xFD}}, |
| 2114 | // stream id |
| 2115 | {"Unable to read stream_id.", |
| 2116 | {0x03, 0x04}}, |
| 2117 | // offset |
| 2118 | {"Unable to read offset.", |
| 2119 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2120 | 0x32, 0x10, 0x76, 0x54}}, |
| 2121 | {"Unable to read frame data.", |
| 2122 | { |
| 2123 | // data length |
| 2124 | 0x00, 0x0c, |
| 2125 | // data |
| 2126 | 'h', 'e', 'l', 'l', |
| 2127 | 'o', ' ', 'w', 'o', |
| 2128 | 'r', 'l', 'd', '!'}}, |
| 2129 | }; |
| 2130 | |
| 2131 | PacketFragments packet46 = { |
| 2132 | // type (short header, 4 byte packet number) |
| 2133 | {"", |
| 2134 | {0x43}}, |
| 2135 | // connection_id |
| 2136 | {"", |
| 2137 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2138 | // packet number |
| 2139 | {"", |
| 2140 | {0x12, 0x34, 0x56, 0x78}}, |
| 2141 | // frame type (stream frame with fin) |
| 2142 | {"", |
| 2143 | {0xFD}}, |
| 2144 | // stream id |
| 2145 | {"Unable to read stream_id.", |
| 2146 | {0x03, 0x04}}, |
| 2147 | // offset |
| 2148 | {"Unable to read offset.", |
| 2149 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2150 | 0x32, 0x10, 0x76, 0x54}}, |
| 2151 | {"Unable to read frame data.", |
| 2152 | { |
| 2153 | // data length |
| 2154 | 0x00, 0x0c, |
| 2155 | // data |
| 2156 | 'h', 'e', 'l', 'l', |
| 2157 | 'o', ' ', 'w', 'o', |
| 2158 | 'r', 'l', 'd', '!'}}, |
| 2159 | }; |
| 2160 | |
| 2161 | PacketFragments packet99 = { |
| 2162 | // type (short header, 4 byte packet number) |
| 2163 | {"", |
| 2164 | {0x43}}, |
| 2165 | // connection_id |
| 2166 | {"", |
| 2167 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2168 | // packet number |
| 2169 | {"", |
| 2170 | {0x12, 0x34, 0x56, 0x78}}, |
| 2171 | // frame type (IETF_STREAM frame with LEN, FIN, and OFFSET bits set) |
| 2172 | {"", |
| 2173 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2174 | // stream id |
| 2175 | {"Unable to read stream_id.", |
| 2176 | {kVarInt62TwoBytes + 0x03, 0x04}}, |
| 2177 | // offset |
| 2178 | {"Unable to read stream data offset.", |
| 2179 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2180 | 0x32, 0x10, 0x76, 0x54}}, |
| 2181 | // data length |
| 2182 | {"Unable to read stream data length.", |
| 2183 | {kVarInt62OneByte + 0x0c}}, |
| 2184 | // data |
| 2185 | {"Unable to read frame data.", |
| 2186 | { 'h', 'e', 'l', 'l', |
| 2187 | 'o', ' ', 'w', 'o', |
| 2188 | 'r', 'l', 'd', '!'}}, |
| 2189 | }; |
| 2190 | // clang-format on |
| 2191 | |
| 2192 | PacketFragments& fragments = |
| 2193 | framer_.transport_version() == QUIC_VERSION_99 |
| 2194 | ? packet99 |
| 2195 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2196 | ? packet46 |
| 2197 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2198 | : packet)); |
| 2199 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2200 | AssemblePacketFromFragments(fragments)); |
| 2201 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2202 | |
| 2203 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2204 | ASSERT_TRUE(visitor_.header_.get()); |
| 2205 | EXPECT_TRUE(CheckDecryption( |
| 2206 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2207 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2208 | |
| 2209 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2210 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2211 | // Stream ID should be the last 2 bytes of kStreamId. |
| 2212 | EXPECT_EQ(0x0000FFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2213 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2214 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2215 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2216 | |
| 2217 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2218 | } |
| 2219 | |
| 2220 | TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2221 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2222 | // clang-format off |
| 2223 | PacketFragments packet = { |
| 2224 | // public flags (8 byte connection_id) |
| 2225 | {"", |
| 2226 | {0x28}}, |
| 2227 | // connection_id |
| 2228 | {"", |
| 2229 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2230 | // packet number |
| 2231 | {"", |
| 2232 | {0x12, 0x34, 0x56, 0x78}}, |
| 2233 | // frame type (stream frame with fin) |
| 2234 | {"", |
| 2235 | {0xFC}}, |
| 2236 | // stream id |
| 2237 | {"Unable to read stream_id.", |
| 2238 | {0x04}}, |
| 2239 | // offset |
| 2240 | {"Unable to read offset.", |
| 2241 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2242 | 0x32, 0x10, 0x76, 0x54}}, |
| 2243 | {"Unable to read frame data.", |
| 2244 | { |
| 2245 | // data length |
| 2246 | 0x00, 0x0c, |
| 2247 | // data |
| 2248 | 'h', 'e', 'l', 'l', |
| 2249 | 'o', ' ', 'w', 'o', |
| 2250 | 'r', 'l', 'd', '!'}}, |
| 2251 | }; |
| 2252 | |
| 2253 | PacketFragments packet44 = { |
| 2254 | // type (short header, 4 byte packet number) |
| 2255 | {"", |
| 2256 | {0x32}}, |
| 2257 | // connection_id |
| 2258 | {"", |
| 2259 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2260 | // packet number |
| 2261 | {"", |
| 2262 | {0x12, 0x34, 0x56, 0x78}}, |
| 2263 | // frame type (stream frame with fin) |
| 2264 | {"", |
| 2265 | {0xFC}}, |
| 2266 | // stream id |
| 2267 | {"Unable to read stream_id.", |
| 2268 | {0x04}}, |
| 2269 | // offset |
| 2270 | {"Unable to read offset.", |
| 2271 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2272 | 0x32, 0x10, 0x76, 0x54}}, |
| 2273 | {"Unable to read frame data.", |
| 2274 | { |
| 2275 | // data length |
| 2276 | 0x00, 0x0c, |
| 2277 | // data |
| 2278 | 'h', 'e', 'l', 'l', |
| 2279 | 'o', ' ', 'w', 'o', |
| 2280 | 'r', 'l', 'd', '!'}}, |
| 2281 | }; |
| 2282 | |
| 2283 | PacketFragments packet46 = { |
| 2284 | // type (short header, 4 byte packet number) |
| 2285 | {"", |
| 2286 | {0x43}}, |
| 2287 | // connection_id |
| 2288 | {"", |
| 2289 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2290 | // packet number |
| 2291 | {"", |
| 2292 | {0x12, 0x34, 0x56, 0x78}}, |
| 2293 | // frame type (stream frame with fin) |
| 2294 | {"", |
| 2295 | {0xFC}}, |
| 2296 | // stream id |
| 2297 | {"Unable to read stream_id.", |
| 2298 | {0x04}}, |
| 2299 | // offset |
| 2300 | {"Unable to read offset.", |
| 2301 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2302 | 0x32, 0x10, 0x76, 0x54}}, |
| 2303 | {"Unable to read frame data.", |
| 2304 | { |
| 2305 | // data length |
| 2306 | 0x00, 0x0c, |
| 2307 | // data |
| 2308 | 'h', 'e', 'l', 'l', |
| 2309 | 'o', ' ', 'w', 'o', |
| 2310 | 'r', 'l', 'd', '!'}}, |
| 2311 | }; |
| 2312 | |
| 2313 | PacketFragments packet99 = { |
| 2314 | // type (short header, 4 byte packet number) |
| 2315 | {"", |
| 2316 | {0x43}}, |
| 2317 | // connection_id |
| 2318 | {"", |
| 2319 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2320 | // packet number |
| 2321 | {"", |
| 2322 | {0x12, 0x34, 0x56, 0x78}}, |
| 2323 | // frame type (IETF_STREAM frame with LEN, FIN, and OFFSET bits set) |
| 2324 | {"", |
| 2325 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2326 | // stream id |
| 2327 | {"Unable to read stream_id.", |
| 2328 | {kVarInt62OneByte + 0x04}}, |
| 2329 | // offset |
| 2330 | {"Unable to read stream data offset.", |
| 2331 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2332 | 0x32, 0x10, 0x76, 0x54}}, |
| 2333 | // data length |
| 2334 | {"Unable to read stream data length.", |
| 2335 | {kVarInt62OneByte + 0x0c}}, |
| 2336 | // data |
| 2337 | {"Unable to read frame data.", |
| 2338 | { 'h', 'e', 'l', 'l', |
| 2339 | 'o', ' ', 'w', 'o', |
| 2340 | 'r', 'l', 'd', '!'}}, |
| 2341 | }; |
| 2342 | // clang-format on |
| 2343 | |
| 2344 | PacketFragments& fragments = |
| 2345 | framer_.transport_version() == QUIC_VERSION_99 |
| 2346 | ? packet99 |
| 2347 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2348 | ? packet46 |
| 2349 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2350 | : packet)); |
| 2351 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2352 | AssemblePacketFromFragments(fragments)); |
| 2353 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2354 | |
| 2355 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2356 | ASSERT_TRUE(visitor_.header_.get()); |
| 2357 | EXPECT_TRUE(CheckDecryption( |
| 2358 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2359 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2360 | |
| 2361 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2362 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2363 | // Stream ID should be the last 1 byte of kStreamId. |
| 2364 | EXPECT_EQ(0x000000FF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2365 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2366 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2367 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2368 | |
| 2369 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2370 | } |
| 2371 | |
| 2372 | TEST_P(QuicFramerTest, StreamFrameWithVersion) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2373 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2374 | // clang-format off |
| 2375 | PacketFragments packet = { |
| 2376 | // public flags (version, 8 byte connection_id) |
| 2377 | {"", |
| 2378 | {0x29}}, |
| 2379 | // connection_id |
| 2380 | {"", |
| 2381 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2382 | // version tag |
| 2383 | {"", |
| 2384 | {QUIC_VERSION_BYTES}}, |
| 2385 | // packet number |
| 2386 | {"", |
| 2387 | {0x12, 0x34, 0x56, 0x78}}, |
| 2388 | // frame type (stream frame with fin) |
| 2389 | {"", |
| 2390 | {0xFE}}, |
| 2391 | // stream id |
| 2392 | {"Unable to read stream_id.", |
| 2393 | {0x02, 0x03, 0x04}}, |
| 2394 | // offset |
| 2395 | {"Unable to read offset.", |
| 2396 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2397 | 0x32, 0x10, 0x76, 0x54}}, |
| 2398 | {"Unable to read frame data.", |
| 2399 | { |
| 2400 | // data length |
| 2401 | 0x00, 0x0c, |
| 2402 | // data |
| 2403 | 'h', 'e', 'l', 'l', |
| 2404 | 'o', ' ', 'w', 'o', |
| 2405 | 'r', 'l', 'd', '!'}}, |
| 2406 | }; |
| 2407 | |
| 2408 | PacketFragments packet44 = { |
| 2409 | // public flags (long header with packet type ZERO_RTT_PROTECTED) |
| 2410 | {"", |
| 2411 | {0xFC}}, |
| 2412 | // version tag |
| 2413 | {"", |
| 2414 | {QUIC_VERSION_BYTES}}, |
| 2415 | // connection_id length |
| 2416 | {"", |
| 2417 | {0x50}}, |
| 2418 | // connection_id |
| 2419 | {"", |
| 2420 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2421 | // packet number |
| 2422 | {"", |
| 2423 | {0x12, 0x34, 0x56, 0x78}}, |
| 2424 | // frame type (stream frame with fin) |
| 2425 | {"", |
| 2426 | {0xFE}}, |
| 2427 | // stream id |
| 2428 | {"Unable to read stream_id.", |
| 2429 | {0x02, 0x03, 0x04}}, |
| 2430 | // offset |
| 2431 | {"Unable to read offset.", |
| 2432 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2433 | 0x32, 0x10, 0x76, 0x54}}, |
| 2434 | {"Unable to read frame data.", |
| 2435 | { |
| 2436 | // data length |
| 2437 | 0x00, 0x0c, |
| 2438 | // data |
| 2439 | 'h', 'e', 'l', 'l', |
| 2440 | 'o', ' ', 'w', 'o', |
| 2441 | 'r', 'l', 'd', '!'}}, |
| 2442 | }; |
| 2443 | |
| 2444 | PacketFragments packet46 = { |
| 2445 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2446 | // 4-byte packet number) |
| 2447 | {"", |
| 2448 | {0xD3}}, |
| 2449 | // version tag |
| 2450 | {"", |
| 2451 | {QUIC_VERSION_BYTES}}, |
| 2452 | // connection_id length |
| 2453 | {"", |
| 2454 | {0x50}}, |
| 2455 | // connection_id |
| 2456 | {"", |
| 2457 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2458 | // packet number |
| 2459 | {"", |
| 2460 | {0x12, 0x34, 0x56, 0x78}}, |
| 2461 | // frame type (stream frame with fin) |
| 2462 | {"", |
| 2463 | {0xFE}}, |
| 2464 | // stream id |
| 2465 | {"Unable to read stream_id.", |
| 2466 | {0x02, 0x03, 0x04}}, |
| 2467 | // offset |
| 2468 | {"Unable to read offset.", |
| 2469 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2470 | 0x32, 0x10, 0x76, 0x54}}, |
| 2471 | {"Unable to read frame data.", |
| 2472 | { |
| 2473 | // data length |
| 2474 | 0x00, 0x0c, |
| 2475 | // data |
| 2476 | 'h', 'e', 'l', 'l', |
| 2477 | 'o', ' ', 'w', 'o', |
| 2478 | 'r', 'l', 'd', '!'}}, |
| 2479 | }; |
| 2480 | |
| 2481 | PacketFragments packet99 = { |
| 2482 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2483 | // 4-byte packet number) |
| 2484 | {"", |
| 2485 | {0xD3}}, |
| 2486 | // version tag |
| 2487 | {"", |
| 2488 | {QUIC_VERSION_BYTES}}, |
| 2489 | // connection_id length |
| 2490 | {"", |
| 2491 | {0x50}}, |
| 2492 | // connection_id |
| 2493 | {"", |
| 2494 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2495 | // long header packet length |
| 2496 | {"", |
| 2497 | {0x1E}}, |
| 2498 | // packet number |
| 2499 | {"", |
| 2500 | {0x12, 0x34, 0x56, 0x78}}, |
| 2501 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 2502 | {"", |
| 2503 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2504 | // stream id |
| 2505 | {"Long header payload length longer than packet.", |
| 2506 | {kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04}}, |
| 2507 | // offset |
| 2508 | {"Long header payload length longer than packet.", |
| 2509 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2510 | 0x32, 0x10, 0x76, 0x54}}, |
| 2511 | // data length |
| 2512 | {"Long header payload length longer than packet.", |
| 2513 | {kVarInt62OneByte + 0x0c}}, |
| 2514 | // data |
| 2515 | {"Long header payload length longer than packet.", |
| 2516 | { 'h', 'e', 'l', 'l', |
| 2517 | 'o', ' ', 'w', 'o', |
| 2518 | 'r', 'l', 'd', '!'}}, |
| 2519 | }; |
| 2520 | // clang-format on |
| 2521 | |
| 2522 | QuicVariableLengthIntegerLength retry_token_length_length = |
| 2523 | VARIABLE_LENGTH_INTEGER_LENGTH_0; |
| 2524 | size_t retry_token_length = 0; |
| 2525 | QuicVariableLengthIntegerLength length_length = |
| 2526 | QuicVersionHasLongHeaderLengths(framer_.transport_version()) |
| 2527 | ? VARIABLE_LENGTH_INTEGER_LENGTH_1 |
| 2528 | : VARIABLE_LENGTH_INTEGER_LENGTH_0; |
| 2529 | |
| 2530 | PacketFragments& fragments = |
| 2531 | framer_.transport_version() == QUIC_VERSION_99 |
| 2532 | ? packet99 |
| 2533 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2534 | ? packet46 |
| 2535 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2536 | : packet)); |
| 2537 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2538 | AssemblePacketFromFragments(fragments)); |
| 2539 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2540 | |
| 2541 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2542 | ASSERT_TRUE(visitor_.header_.get()); |
| 2543 | EXPECT_TRUE(CheckDecryption( |
| 2544 | *encrypted, kIncludeVersion, !kIncludeDiversificationNonce, |
| 2545 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID, |
| 2546 | retry_token_length_length, retry_token_length, length_length)); |
| 2547 | |
| 2548 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2549 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2550 | // Stream ID should be the last 3 bytes of kStreamId. |
| 2551 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2552 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2553 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2554 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2555 | |
| 2556 | CheckFramingBoundaries(fragments, |
| 2557 | framer_.transport_version() == QUIC_VERSION_99 |
| 2558 | ? QUIC_INVALID_PACKET_HEADER |
| 2559 | : QUIC_INVALID_STREAM_DATA); |
| 2560 | } |
| 2561 | |
| 2562 | TEST_P(QuicFramerTest, RejectPacket) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2563 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2564 | visitor_.accept_packet_ = false; |
| 2565 | |
| 2566 | // clang-format off |
| 2567 | unsigned char packet[] = { |
| 2568 | // public flags (8 byte connection_id) |
| 2569 | 0x28, |
| 2570 | // connection_id |
| 2571 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2572 | // packet number |
| 2573 | 0x12, 0x34, 0x56, 0x78, |
| 2574 | |
| 2575 | // frame type (stream frame with fin) |
| 2576 | 0xFF, |
| 2577 | // stream id |
| 2578 | 0x01, 0x02, 0x03, 0x04, |
| 2579 | // offset |
| 2580 | 0x3A, 0x98, 0xFE, 0xDC, |
| 2581 | 0x32, 0x10, 0x76, 0x54, |
| 2582 | // data length |
| 2583 | 0x00, 0x0c, |
| 2584 | // data |
| 2585 | 'h', 'e', 'l', 'l', |
| 2586 | 'o', ' ', 'w', 'o', |
| 2587 | 'r', 'l', 'd', '!', |
| 2588 | }; |
| 2589 | |
| 2590 | unsigned char packet44[] = { |
| 2591 | // type (short header, 4 byte packet number) |
| 2592 | 0x32, |
| 2593 | // connection_id |
| 2594 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2595 | // packet number |
| 2596 | 0x12, 0x34, 0x56, 0x78, |
| 2597 | |
| 2598 | // frame type (STREAM Frame with FIN, LEN, and OFFSET bits set) |
| 2599 | 0x10 | 0x01 | 0x02 | 0x04, |
| 2600 | // stream id |
| 2601 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 2602 | // offset |
| 2603 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2604 | 0x32, 0x10, 0x76, 0x54, |
| 2605 | // data length |
| 2606 | kVarInt62OneByte + 0x0c, |
| 2607 | // data |
| 2608 | 'h', 'e', 'l', 'l', |
| 2609 | 'o', ' ', 'w', 'o', |
| 2610 | 'r', 'l', 'd', '!', |
| 2611 | }; |
| 2612 | |
| 2613 | unsigned char packet46[] = { |
| 2614 | // type (short header, 4 byte packet number) |
| 2615 | 0x43, |
| 2616 | // connection_id |
| 2617 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2618 | // packet number |
| 2619 | 0x12, 0x34, 0x56, 0x78, |
| 2620 | |
| 2621 | // frame type (STREAM Frame with FIN, LEN, and OFFSET bits set) |
| 2622 | 0x10 | 0x01 | 0x02 | 0x04, |
| 2623 | // stream id |
| 2624 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 2625 | // offset |
| 2626 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2627 | 0x32, 0x10, 0x76, 0x54, |
| 2628 | // data length |
| 2629 | kVarInt62OneByte + 0x0c, |
| 2630 | // data |
| 2631 | 'h', 'e', 'l', 'l', |
| 2632 | 'o', ' ', 'w', 'o', |
| 2633 | 'r', 'l', 'd', '!', |
| 2634 | }; |
| 2635 | // clang-format on |
| 2636 | |
| 2637 | unsigned char* p = packet; |
| 2638 | if (framer_.transport_version() > QUIC_VERSION_44) { |
| 2639 | p = packet46; |
| 2640 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 2641 | p = packet44; |
| 2642 | } |
| 2643 | QuicEncryptedPacket encrypted(AsChars(p), |
| 2644 | framer_.transport_version() > QUIC_VERSION_43 |
| 2645 | ? QUIC_ARRAYSIZE(packet44) |
| 2646 | : QUIC_ARRAYSIZE(packet), |
| 2647 | false); |
| 2648 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 2649 | |
| 2650 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2651 | ASSERT_TRUE(visitor_.header_.get()); |
| 2652 | EXPECT_TRUE(CheckDecryption( |
| 2653 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2654 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2655 | |
| 2656 | ASSERT_EQ(0u, visitor_.stream_frames_.size()); |
| 2657 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2658 | } |
| 2659 | |
| 2660 | TEST_P(QuicFramerTest, RejectPublicHeader) { |
| 2661 | visitor_.accept_public_header_ = false; |
| 2662 | |
| 2663 | // clang-format off |
| 2664 | unsigned char packet[] = { |
| 2665 | // public flags (8 byte connection_id) |
| 2666 | 0x28, |
| 2667 | // connection_id |
| 2668 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2669 | }; |
| 2670 | |
| 2671 | unsigned char packet44[] = { |
| 2672 | // type (short header, 1 byte packet number) |
| 2673 | 0x30, |
| 2674 | // connection_id |
| 2675 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2676 | // packet number |
| 2677 | 0x01, |
| 2678 | }; |
| 2679 | |
| 2680 | unsigned char packet46[] = { |
| 2681 | // type (short header, 1 byte packet number) |
| 2682 | 0x40, |
| 2683 | // connection_id |
| 2684 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2685 | // packet number |
| 2686 | 0x01, |
| 2687 | }; |
| 2688 | // clang-format on |
| 2689 | |
| 2690 | QuicEncryptedPacket encrypted( |
| 2691 | framer_.transport_version() > QUIC_VERSION_44 |
| 2692 | ? AsChars(packet46) |
| 2693 | : (framer_.transport_version() > QUIC_VERSION_43 ? AsChars(packet44) |
| 2694 | : AsChars(packet)), |
| 2695 | framer_.transport_version() > QUIC_VERSION_44 |
| 2696 | ? QUIC_ARRAYSIZE(packet46) |
| 2697 | : (framer_.transport_version() > QUIC_VERSION_43 |
| 2698 | ? QUIC_ARRAYSIZE(packet44) |
| 2699 | : QUIC_ARRAYSIZE(packet)), |
| 2700 | false); |
| 2701 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 2702 | |
| 2703 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2704 | ASSERT_TRUE(visitor_.header_.get()); |
| 2705 | EXPECT_FALSE(visitor_.header_->packet_number.IsInitialized()); |
| 2706 | } |
| 2707 | |
| 2708 | TEST_P(QuicFramerTest, AckFrameOneAckBlock) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2709 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2710 | // clang-format off |
| 2711 | PacketFragments packet = { |
| 2712 | // public flags (8 byte connection_id) |
| 2713 | {"", |
| 2714 | {0x2C}}, |
| 2715 | // connection_id |
| 2716 | {"", |
| 2717 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2718 | // packet number |
| 2719 | {"", |
| 2720 | {0x12, 0x34, 0x56, 0x78}}, |
| 2721 | // frame type (ack frame) |
| 2722 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2723 | {"", |
| 2724 | {0x45}}, |
| 2725 | // largest acked |
| 2726 | {"Unable to read largest acked.", |
| 2727 | {0x12, 0x34}}, |
| 2728 | // Zero delta time. |
| 2729 | {"Unable to read ack delay time.", |
| 2730 | {0x00, 0x00}}, |
| 2731 | // first ack block length. |
| 2732 | {"Unable to read first ack block length.", |
| 2733 | {0x12, 0x34}}, |
| 2734 | // num timestamps. |
| 2735 | {"Unable to read num received packets.", |
| 2736 | {0x00}} |
| 2737 | }; |
| 2738 | |
| 2739 | PacketFragments packet44 = { |
| 2740 | // type (short packet, 4 byte packet number) |
| 2741 | {"", |
| 2742 | {0x32}}, |
| 2743 | // connection_id |
| 2744 | {"", |
| 2745 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2746 | // packet number |
| 2747 | {"", |
| 2748 | {0x12, 0x34, 0x56, 0x78}}, |
| 2749 | // frame type (ack frame) |
| 2750 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2751 | {"", |
| 2752 | {0x45}}, |
| 2753 | // largest acked |
| 2754 | {"Unable to read largest acked.", |
| 2755 | {0x12, 0x34}}, |
| 2756 | // Zero delta time. |
| 2757 | {"Unable to read ack delay time.", |
| 2758 | {0x00, 0x00}}, |
| 2759 | // first ack block length. |
| 2760 | {"Unable to read first ack block length.", |
| 2761 | {0x12, 0x34}}, |
| 2762 | // num timestamps. |
| 2763 | {"Unable to read num received packets.", |
| 2764 | {0x00}} |
| 2765 | }; |
| 2766 | |
| 2767 | PacketFragments packet46 = { |
| 2768 | // type (short packet, 4 byte packet number) |
| 2769 | {"", |
| 2770 | {0x43}}, |
| 2771 | // connection_id |
| 2772 | {"", |
| 2773 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2774 | // packet number |
| 2775 | {"", |
| 2776 | {0x12, 0x34, 0x56, 0x78}}, |
| 2777 | // frame type (ack frame) |
| 2778 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2779 | {"", |
| 2780 | {0x45}}, |
| 2781 | // largest acked |
| 2782 | {"Unable to read largest acked.", |
| 2783 | {0x12, 0x34}}, |
| 2784 | // Zero delta time. |
| 2785 | {"Unable to read ack delay time.", |
| 2786 | {0x00, 0x00}}, |
| 2787 | // first ack block length. |
| 2788 | {"Unable to read first ack block length.", |
| 2789 | {0x12, 0x34}}, |
| 2790 | // num timestamps. |
| 2791 | {"Unable to read num received packets.", |
| 2792 | {0x00}} |
| 2793 | }; |
| 2794 | |
| 2795 | PacketFragments packet99 = { |
| 2796 | // type (short packet, 4 byte packet number) |
| 2797 | {"", |
| 2798 | {0x43}}, |
| 2799 | // connection_id |
| 2800 | {"", |
| 2801 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2802 | // packet number |
| 2803 | {"", |
| 2804 | {0x12, 0x34, 0x56, 0x78}}, |
| 2805 | // frame type (IETF_ACK) |
| 2806 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2807 | // IETF-Quic ignores the bit-fields in the ack type, all of |
| 2808 | // that information is encoded elsewhere in the frame. |
| 2809 | {"", |
| 2810 | {0x02}}, |
| 2811 | // largest acked |
| 2812 | {"Unable to read largest acked.", |
| 2813 | {kVarInt62TwoBytes + 0x12, 0x34}}, |
| 2814 | // Zero delta time. |
| 2815 | {"Unable to read ack delay time.", |
| 2816 | {kVarInt62OneByte + 0x00}}, |
| 2817 | // Ack block count (0 -- no blocks after the first) |
| 2818 | {"Unable to read ack block count.", |
| 2819 | {kVarInt62OneByte + 0x00}}, |
| 2820 | // first ack block length - 1. |
| 2821 | // IETF Quic defines the ack block's value as the "number of |
| 2822 | // packets that preceed the largest packet number in the block" |
| 2823 | // which for the 1st ack block is the largest acked field, |
| 2824 | // above. This means that if we are acking just packet 0x1234 |
| 2825 | // then the 1st ack block will be 0. |
| 2826 | {"Unable to read first ack block length.", |
| 2827 | {kVarInt62TwoBytes + 0x12, 0x33}} |
| 2828 | }; |
| 2829 | // clang-format on |
| 2830 | |
| 2831 | PacketFragments& fragments = |
| 2832 | framer_.transport_version() == QUIC_VERSION_99 |
| 2833 | ? packet99 |
| 2834 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2835 | ? packet46 |
| 2836 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2837 | : packet)); |
| 2838 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2839 | AssemblePacketFromFragments(fragments)); |
| 2840 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2841 | |
| 2842 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2843 | ASSERT_TRUE(visitor_.header_.get()); |
| 2844 | EXPECT_TRUE(CheckDecryption( |
| 2845 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2846 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2847 | |
| 2848 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 2849 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 2850 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 2851 | EXPECT_EQ(kSmallLargestObserved, LargestAcked(frame)); |
| 2852 | ASSERT_EQ(4660u, frame.packets.NumPacketsSlow()); |
| 2853 | |
| 2854 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 2855 | } |
| 2856 | |
| 2857 | // This test checks that the ack frame processor correctly identifies |
| 2858 | // and handles the case where the first ack block is larger than the |
| 2859 | // largest_acked packet. |
| 2860 | TEST_P(QuicFramerTest, FirstAckFrameUnderflow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2861 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2862 | // clang-format off |
| 2863 | PacketFragments packet = { |
| 2864 | // public flags (8 byte connection_id) |
| 2865 | {"", |
| 2866 | {0x2C}}, |
| 2867 | // connection_id |
| 2868 | {"", |
| 2869 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2870 | // packet number |
| 2871 | {"", |
| 2872 | {0x12, 0x34, 0x56, 0x78}}, |
| 2873 | // frame type (ack frame) |
| 2874 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2875 | {"", |
| 2876 | {0x45}}, |
| 2877 | // largest acked |
| 2878 | {"Unable to read largest acked.", |
| 2879 | {0x12, 0x34}}, |
| 2880 | // Zero delta time. |
| 2881 | {"Unable to read ack delay time.", |
| 2882 | {0x00, 0x00}}, |
| 2883 | // first ack block length. |
| 2884 | {"Unable to read first ack block length.", |
| 2885 | {0x88, 0x88}}, |
| 2886 | // num timestamps. |
| 2887 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 2888 | {0x00}} |
| 2889 | }; |
| 2890 | |
| 2891 | PacketFragments packet44 = { |
| 2892 | // type (short header, 4 byte packet number) |
| 2893 | {"", |
| 2894 | {0x32}}, |
| 2895 | // connection_id |
| 2896 | {"", |
| 2897 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2898 | // packet number |
| 2899 | {"", |
| 2900 | {0x12, 0x34, 0x56, 0x78}}, |
| 2901 | // frame type (ack frame) |
| 2902 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2903 | {"", |
| 2904 | {0x45}}, |
| 2905 | // largest acked |
| 2906 | {"Unable to read largest acked.", |
| 2907 | {0x12, 0x34}}, |
| 2908 | // Zero delta time. |
| 2909 | {"Unable to read ack delay time.", |
| 2910 | {0x00, 0x00}}, |
| 2911 | // first ack block length. |
| 2912 | {"Unable to read first ack block length.", |
| 2913 | {0x88, 0x88}}, |
| 2914 | // num timestamps. |
| 2915 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 2916 | {0x00}} |
| 2917 | }; |
| 2918 | |
| 2919 | PacketFragments packet46 = { |
| 2920 | // type (short header, 4 byte packet number) |
| 2921 | {"", |
| 2922 | {0x43}}, |
| 2923 | // connection_id |
| 2924 | {"", |
| 2925 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2926 | // packet number |
| 2927 | {"", |
| 2928 | {0x12, 0x34, 0x56, 0x78}}, |
| 2929 | // frame type (ack frame) |
| 2930 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2931 | {"", |
| 2932 | {0x45}}, |
| 2933 | // largest acked |
| 2934 | {"Unable to read largest acked.", |
| 2935 | {0x12, 0x34}}, |
| 2936 | // Zero delta time. |
| 2937 | {"Unable to read ack delay time.", |
| 2938 | {0x00, 0x00}}, |
| 2939 | // first ack block length. |
| 2940 | {"Unable to read first ack block length.", |
| 2941 | {0x88, 0x88}}, |
| 2942 | // num timestamps. |
| 2943 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 2944 | {0x00}} |
| 2945 | }; |
| 2946 | |
| 2947 | PacketFragments packet99 = { |
| 2948 | // type (short header, 4 byte packet number) |
| 2949 | {"", |
| 2950 | {0x43}}, |
| 2951 | // connection_id |
| 2952 | {"", |
| 2953 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2954 | // packet number |
| 2955 | {"", |
| 2956 | {0x12, 0x34, 0x56, 0x78}}, |
| 2957 | // frame type (IETF_ACK) |
| 2958 | {"", |
| 2959 | {0x02}}, |
| 2960 | // largest acked |
| 2961 | {"Unable to read largest acked.", |
| 2962 | {kVarInt62TwoBytes + 0x12, 0x34}}, |
| 2963 | // Zero delta time. |
| 2964 | {"Unable to read ack delay time.", |
| 2965 | {kVarInt62OneByte + 0x00}}, |
| 2966 | // Ack block count (0 -- no blocks after the first) |
| 2967 | {"Unable to read ack block count.", |
| 2968 | {kVarInt62OneByte + 0x00}}, |
| 2969 | // first ack block length. |
| 2970 | {"Unable to read first ack block length.", |
| 2971 | {kVarInt62TwoBytes + 0x28, 0x88}} |
| 2972 | }; |
| 2973 | // clang-format on |
| 2974 | |
| 2975 | PacketFragments& fragments = |
| 2976 | framer_.transport_version() == QUIC_VERSION_99 |
| 2977 | ? packet99 |
| 2978 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2979 | ? packet46 |
| 2980 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2981 | : packet)); |
| 2982 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2983 | AssemblePacketFromFragments(fragments)); |
| 2984 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 2985 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 2986 | } |
| 2987 | |
| 2988 | // This test checks that the ack frame processor correctly identifies |
| 2989 | // and handles the case where the third ack block's gap is larger than the |
| 2990 | // available space in the ack range. |
| 2991 | TEST_P(QuicFramerTest, ThirdAckBlockUnderflowGap) { |
| 2992 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 2993 | // for now, only v99 |
| 2994 | return; |
| 2995 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2996 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2997 | // clang-format off |
| 2998 | PacketFragments packet99 = { |
| 2999 | // type (short header, 4 byte packet number) |
| 3000 | {"", |
| 3001 | {0x43}}, |
| 3002 | // connection_id |
| 3003 | {"", |
| 3004 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3005 | // packet number |
| 3006 | {"", |
| 3007 | {0x12, 0x34, 0x56, 0x78}}, |
| 3008 | // frame type (IETF_ACK frame) |
| 3009 | {"", |
| 3010 | {0x02}}, |
| 3011 | // largest acked |
| 3012 | {"Unable to read largest acked.", |
| 3013 | {kVarInt62OneByte + 63}}, |
| 3014 | // Zero delta time. |
| 3015 | {"Unable to read ack delay time.", |
| 3016 | {kVarInt62OneByte + 0x00}}, |
| 3017 | // Ack block count (2 -- 2 blocks after the first) |
| 3018 | {"Unable to read ack block count.", |
| 3019 | {kVarInt62OneByte + 0x02}}, |
| 3020 | // first ack block length. |
| 3021 | {"Unable to read first ack block length.", |
| 3022 | {kVarInt62OneByte + 13}}, // Ack 14 packets, range 50..63 (inclusive) |
| 3023 | |
| 3024 | {"Unable to read gap block value.", |
| 3025 | {kVarInt62OneByte + 9}}, // Gap 10 packets, 40..49 (inclusive) |
| 3026 | {"Unable to read ack block value.", |
| 3027 | {kVarInt62OneByte + 9}}, // Ack 10 packets, 30..39 (inclusive) |
| 3028 | {"Unable to read gap block value.", |
| 3029 | {kVarInt62OneByte + 29}}, // A gap of 30 packets (0..29 inclusive) |
| 3030 | // should be too big, leaving no room |
| 3031 | // for the ack. |
| 3032 | {"Underflow with gap block length 30 previous ack block start is 30.", |
| 3033 | {kVarInt62OneByte + 10}}, // Don't care |
| 3034 | }; |
| 3035 | // clang-format on |
| 3036 | |
| 3037 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3038 | AssemblePacketFromFragments(packet99)); |
| 3039 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3040 | EXPECT_EQ( |
| 3041 | framer_.detailed_error(), |
| 3042 | "Underflow with gap block length 30 previous ack block start is 30."); |
| 3043 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3044 | } |
| 3045 | |
| 3046 | // This test checks that the ack frame processor correctly identifies |
| 3047 | // and handles the case where the third ack block's length is larger than the |
| 3048 | // available space in the ack range. |
| 3049 | TEST_P(QuicFramerTest, ThirdAckBlockUnderflowAck) { |
| 3050 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 3051 | // for now, only v99 |
| 3052 | return; |
| 3053 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3054 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3055 | // clang-format off |
| 3056 | PacketFragments packet99 = { |
| 3057 | // type (short header, 4 byte packet number) |
| 3058 | {"", |
| 3059 | {0x43}}, |
| 3060 | // connection_id |
| 3061 | {"", |
| 3062 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3063 | // packet number |
| 3064 | {"", |
| 3065 | {0x12, 0x34, 0x56, 0x78}}, |
| 3066 | // frame type (IETF_ACK frame) |
| 3067 | {"", |
| 3068 | {0x02}}, |
| 3069 | // largest acked |
| 3070 | {"Unable to read largest acked.", |
| 3071 | {kVarInt62OneByte + 63}}, |
| 3072 | // Zero delta time. |
| 3073 | {"Unable to read ack delay time.", |
| 3074 | {kVarInt62OneByte + 0x00}}, |
| 3075 | // Ack block count (2 -- 2 blocks after the first) |
| 3076 | {"Unable to read ack block count.", |
| 3077 | {kVarInt62OneByte + 0x02}}, |
| 3078 | // first ack block length. |
| 3079 | {"Unable to read first ack block length.", |
| 3080 | {kVarInt62OneByte + 13}}, // only 50 packet numbers "left" |
| 3081 | |
| 3082 | {"Unable to read gap block value.", |
| 3083 | {kVarInt62OneByte + 10}}, // Only 40 packet numbers left |
| 3084 | {"Unable to read ack block value.", |
| 3085 | {kVarInt62OneByte + 10}}, // only 30 packet numbers left. |
| 3086 | {"Unable to read gap block value.", |
| 3087 | {kVarInt62OneByte + 1}}, // Gap is OK, 29 packet numbers left |
| 3088 | {"Unable to read ack block value.", |
| 3089 | {kVarInt62OneByte + 30}}, // Use up all 30, should be an error |
| 3090 | }; |
| 3091 | // clang-format on |
| 3092 | |
| 3093 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3094 | AssemblePacketFromFragments(packet99)); |
| 3095 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3096 | EXPECT_EQ(framer_.detailed_error(), |
| 3097 | "Underflow with ack block length 31 latest ack block end is 25."); |
| 3098 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3099 | } |
| 3100 | |
| 3101 | // Tests a variety of ack block wrap scenarios. For example, if the |
| 3102 | // N-1th block causes packet 0 to be acked, then a gap would wrap |
| 3103 | // around to 0x3fffffff ffffffff... Make sure we detect this |
| 3104 | // condition. |
| 3105 | TEST_P(QuicFramerTest, AckBlockUnderflowGapWrap) { |
| 3106 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 3107 | // for now, only v99 |
| 3108 | return; |
| 3109 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3110 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3111 | // clang-format off |
| 3112 | PacketFragments packet99 = { |
| 3113 | // type (short header, 4 byte packet number) |
| 3114 | {"", |
| 3115 | {0x43}}, |
| 3116 | // connection_id |
| 3117 | {"", |
| 3118 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3119 | // packet number |
| 3120 | {"", |
| 3121 | {0x12, 0x34, 0x56, 0x78}}, |
| 3122 | // frame type (IETF_ACK frame) |
| 3123 | {"", |
| 3124 | {0x02}}, |
| 3125 | // largest acked |
| 3126 | {"Unable to read largest acked.", |
| 3127 | {kVarInt62OneByte + 10}}, |
| 3128 | // Zero delta time. |
| 3129 | {"Unable to read ack delay time.", |
| 3130 | {kVarInt62OneByte + 0x00}}, |
| 3131 | // Ack block count (1 -- 1 blocks after the first) |
| 3132 | {"Unable to read ack block count.", |
| 3133 | {kVarInt62OneByte + 1}}, |
| 3134 | // first ack block length. |
| 3135 | {"Unable to read first ack block length.", |
| 3136 | {kVarInt62OneByte + 9}}, // Ack packets 1..10 (inclusive) |
| 3137 | |
| 3138 | {"Unable to read gap block value.", |
| 3139 | {kVarInt62OneByte + 1}}, // Gap of 2 packets (-1...0), should wrap |
| 3140 | {"Underflow with gap block length 2 previous ack block start is 1.", |
| 3141 | {kVarInt62OneByte + 9}}, // irrelevant |
| 3142 | }; |
| 3143 | // clang-format on |
| 3144 | |
| 3145 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3146 | AssemblePacketFromFragments(packet99)); |
| 3147 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3148 | EXPECT_EQ(framer_.detailed_error(), |
| 3149 | "Underflow with gap block length 2 previous ack block start is 1."); |
| 3150 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3151 | } |
| 3152 | |
| 3153 | // As AckBlockUnderflowGapWrap, but in this test, it's the ack |
| 3154 | // component of the ack-block that causes the wrap, not the gap. |
| 3155 | TEST_P(QuicFramerTest, AckBlockUnderflowAckWrap) { |
| 3156 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 3157 | // for now, only v99 |
| 3158 | return; |
| 3159 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3160 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3161 | // clang-format off |
| 3162 | PacketFragments packet99 = { |
| 3163 | // type (short header, 4 byte packet number) |
| 3164 | {"", |
| 3165 | {0x43}}, |
| 3166 | // connection_id |
| 3167 | {"", |
| 3168 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3169 | // packet number |
| 3170 | {"", |
| 3171 | {0x12, 0x34, 0x56, 0x78}}, |
| 3172 | // frame type (IETF_ACK frame) |
| 3173 | {"", |
| 3174 | {0x02}}, |
| 3175 | // largest acked |
| 3176 | {"Unable to read largest acked.", |
| 3177 | {kVarInt62OneByte + 10}}, |
| 3178 | // Zero delta time. |
| 3179 | {"Unable to read ack delay time.", |
| 3180 | {kVarInt62OneByte + 0x00}}, |
| 3181 | // Ack block count (1 -- 1 blocks after the first) |
| 3182 | {"Unable to read ack block count.", |
| 3183 | {kVarInt62OneByte + 1}}, |
| 3184 | // first ack block length. |
| 3185 | {"Unable to read first ack block length.", |
| 3186 | {kVarInt62OneByte + 6}}, // Ack packets 4..10 (inclusive) |
| 3187 | |
| 3188 | {"Unable to read gap block value.", |
| 3189 | {kVarInt62OneByte + 1}}, // Gap of 2 packets (2..3) |
| 3190 | {"Unable to read ack block value.", |
| 3191 | {kVarInt62OneByte + 9}}, // Should wrap. |
| 3192 | }; |
| 3193 | // clang-format on |
| 3194 | |
| 3195 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3196 | AssemblePacketFromFragments(packet99)); |
| 3197 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3198 | EXPECT_EQ(framer_.detailed_error(), |
| 3199 | "Underflow with ack block length 10 latest ack block end is 1."); |
| 3200 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3201 | } |
| 3202 | |
| 3203 | // An ack block that acks the entire range, 1...0x3fffffffffffffff |
| 3204 | TEST_P(QuicFramerTest, AckBlockAcksEverything) { |
| 3205 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 3206 | // for now, only v99 |
| 3207 | return; |
| 3208 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3209 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3210 | // clang-format off |
| 3211 | PacketFragments packet99 = { |
| 3212 | // type (short header, 4 byte packet number) |
| 3213 | {"", |
| 3214 | {0x43}}, |
| 3215 | // connection_id |
| 3216 | {"", |
| 3217 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3218 | // packet number |
| 3219 | {"", |
| 3220 | {0x12, 0x34, 0x56, 0x78}}, |
| 3221 | // frame type (IETF_ACK frame) |
| 3222 | {"", |
| 3223 | {0x02}}, |
| 3224 | // largest acked |
| 3225 | {"Unable to read largest acked.", |
| 3226 | {kVarInt62EightBytes + 0x3f, 0xff, 0xff, 0xff, |
| 3227 | 0xff, 0xff, 0xff, 0xff}}, |
| 3228 | // Zero delta time. |
| 3229 | {"Unable to read ack delay time.", |
| 3230 | {kVarInt62OneByte + 0x00}}, |
| 3231 | // Ack block count No additional blocks |
| 3232 | {"Unable to read ack block count.", |
| 3233 | {kVarInt62OneByte + 0}}, |
| 3234 | // first ack block length. |
| 3235 | {"Unable to read first ack block length.", |
| 3236 | {kVarInt62EightBytes + 0x3f, 0xff, 0xff, 0xff, |
| 3237 | 0xff, 0xff, 0xff, 0xfe}}, |
| 3238 | }; |
| 3239 | // clang-format on |
| 3240 | |
| 3241 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3242 | AssemblePacketFromFragments(packet99)); |
| 3243 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3244 | EXPECT_EQ(1u, visitor_.ack_frames_.size()); |
| 3245 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3246 | EXPECT_EQ(1u, frame.packets.NumIntervals()); |
| 3247 | EXPECT_EQ(kLargestIetfLargestObserved, LargestAcked(frame)); |
| 3248 | EXPECT_EQ(kLargestIetfLargestObserved.ToUint64(), |
| 3249 | frame.packets.NumPacketsSlow()); |
| 3250 | } |
| 3251 | |
| 3252 | // This test looks for a malformed ack where |
| 3253 | // - There is a largest-acked value (that is, the frame is acking |
| 3254 | // something, |
| 3255 | // - But the length of the first ack block is 0 saying that no frames |
| 3256 | // are being acked with the largest-acked value or there are no |
| 3257 | // additional ack blocks. |
| 3258 | // |
| 3259 | TEST_P(QuicFramerTest, AckFrameFirstAckBlockLengthZero) { |
| 3260 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 3261 | // Not applicable to version 99 -- first ack block contains the |
| 3262 | // number of packets that preceed the largest_acked packet. |
| 3263 | // A value of 0 means no packets preceed --- that the block's |
| 3264 | // length is 1. Therefore the condition that this test checks can |
| 3265 | // not arise. |
| 3266 | return; |
| 3267 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 3268 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3269 | |
| 3270 | // clang-format off |
| 3271 | PacketFragments packet = { |
| 3272 | // public flags (8 byte connection_id) |
| 3273 | {"", |
| 3274 | { 0x2C }}, |
| 3275 | // connection_id |
| 3276 | {"", |
| 3277 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3278 | // packet number |
| 3279 | {"", |
| 3280 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3281 | |
| 3282 | // frame type (ack frame) |
| 3283 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3284 | {"", |
| 3285 | { 0x65 }}, |
| 3286 | // largest acked |
| 3287 | {"Unable to read largest acked.", |
| 3288 | { 0x12, 0x34 }}, |
| 3289 | // Zero delta time. |
| 3290 | {"Unable to read ack delay time.", |
| 3291 | { 0x00, 0x00 }}, |
| 3292 | // num ack blocks ranges. |
| 3293 | {"Unable to read num of ack blocks.", |
| 3294 | { 0x01 }}, |
| 3295 | // first ack block length. |
| 3296 | {"Unable to read first ack block length.", |
| 3297 | { 0x00, 0x00 }}, |
| 3298 | // gap to next block. |
| 3299 | { "First block length is zero.", |
| 3300 | { 0x01 }}, |
| 3301 | // ack block length. |
| 3302 | { "First block length is zero.", |
| 3303 | { 0x0e, 0xaf }}, |
| 3304 | // Number of timestamps. |
| 3305 | { "First block length is zero.", |
| 3306 | { 0x00 }}, |
| 3307 | }; |
| 3308 | |
| 3309 | PacketFragments packet44 = { |
| 3310 | // type (short header, 4 byte packet number) |
| 3311 | {"", |
| 3312 | { 0x32 }}, |
| 3313 | // connection_id |
| 3314 | {"", |
| 3315 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3316 | // packet number |
| 3317 | {"", |
| 3318 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3319 | |
| 3320 | // frame type (ack frame) |
| 3321 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3322 | {"", |
| 3323 | { 0x65 }}, |
| 3324 | // largest acked |
| 3325 | {"Unable to read largest acked.", |
| 3326 | { 0x12, 0x34 }}, |
| 3327 | // Zero delta time. |
| 3328 | {"Unable to read ack delay time.", |
| 3329 | { 0x00, 0x00 }}, |
| 3330 | // num ack blocks ranges. |
| 3331 | {"Unable to read num of ack blocks.", |
| 3332 | { 0x01 }}, |
| 3333 | // first ack block length. |
| 3334 | {"Unable to read first ack block length.", |
| 3335 | { 0x00, 0x00 }}, |
| 3336 | // gap to next block. |
| 3337 | { "First block length is zero.", |
| 3338 | { 0x01 }}, |
| 3339 | // ack block length. |
| 3340 | { "First block length is zero.", |
| 3341 | { 0x0e, 0xaf }}, |
| 3342 | // Number of timestamps. |
| 3343 | { "First block length is zero.", |
| 3344 | { 0x00 }}, |
| 3345 | }; |
| 3346 | |
| 3347 | PacketFragments packet46 = { |
| 3348 | // type (short header, 4 byte packet number) |
| 3349 | {"", |
| 3350 | { 0x43 }}, |
| 3351 | // connection_id |
| 3352 | {"", |
| 3353 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3354 | // packet number |
| 3355 | {"", |
| 3356 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3357 | |
| 3358 | // frame type (ack frame) |
| 3359 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3360 | {"", |
| 3361 | { 0x65 }}, |
| 3362 | // largest acked |
| 3363 | {"Unable to read largest acked.", |
| 3364 | { 0x12, 0x34 }}, |
| 3365 | // Zero delta time. |
| 3366 | {"Unable to read ack delay time.", |
| 3367 | { 0x00, 0x00 }}, |
| 3368 | // num ack blocks ranges. |
| 3369 | {"Unable to read num of ack blocks.", |
| 3370 | { 0x01 }}, |
| 3371 | // first ack block length. |
| 3372 | {"Unable to read first ack block length.", |
| 3373 | { 0x00, 0x00 }}, |
| 3374 | // gap to next block. |
| 3375 | { "First block length is zero.", |
| 3376 | { 0x01 }}, |
| 3377 | // ack block length. |
| 3378 | { "First block length is zero.", |
| 3379 | { 0x0e, 0xaf }}, |
| 3380 | // Number of timestamps. |
| 3381 | { "First block length is zero.", |
| 3382 | { 0x00 }}, |
| 3383 | }; |
| 3384 | |
| 3385 | // clang-format on |
| 3386 | PacketFragments& fragments = |
| 3387 | framer_.transport_version() > QUIC_VERSION_44 |
| 3388 | ? packet46 |
| 3389 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 3390 | |
| 3391 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3392 | AssemblePacketFromFragments(fragments)); |
| 3393 | |
| 3394 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3395 | EXPECT_EQ(QUIC_INVALID_ACK_DATA, framer_.error()); |
| 3396 | |
| 3397 | ASSERT_TRUE(visitor_.header_.get()); |
| 3398 | EXPECT_TRUE(CheckDecryption( |
| 3399 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3400 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3401 | |
| 3402 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3403 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3404 | |
| 3405 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3406 | } |
| 3407 | |
| 3408 | TEST_P(QuicFramerTest, AckFrameOneAckBlockMaxLength) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3409 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3410 | // clang-format off |
| 3411 | PacketFragments packet = { |
| 3412 | // public flags (8 byte connection_id) |
| 3413 | {"", |
| 3414 | {0x2C}}, |
| 3415 | // connection_id |
| 3416 | {"", |
| 3417 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3418 | // packet number |
| 3419 | {"", |
| 3420 | {0x12, 0x34, 0x56, 0x78}}, |
| 3421 | // frame type (ack frame) |
| 3422 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3423 | {"", |
| 3424 | {0x49}}, |
| 3425 | // largest acked |
| 3426 | {"Unable to read largest acked.", |
| 3427 | {0x12, 0x34, 0x56, 0x78}}, |
| 3428 | // Zero delta time. |
| 3429 | {"Unable to read ack delay time.", |
| 3430 | {0x00, 0x00}}, |
| 3431 | // first ack block length. |
| 3432 | {"Unable to read first ack block length.", |
| 3433 | {0x12, 0x34}}, |
| 3434 | // num timestamps. |
| 3435 | {"Unable to read num received packets.", |
| 3436 | {0x00}} |
| 3437 | }; |
| 3438 | |
| 3439 | PacketFragments packet44 = { |
| 3440 | // type (short header, 4 byte packet number) |
| 3441 | {"", |
| 3442 | {0x32}}, |
| 3443 | // connection_id |
| 3444 | {"", |
| 3445 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3446 | // packet number |
| 3447 | {"", |
| 3448 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3449 | // frame type (ack frame) |
| 3450 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3451 | {"", |
| 3452 | {0x49}}, |
| 3453 | // largest acked |
| 3454 | {"Unable to read largest acked.", |
| 3455 | {0x12, 0x34, 0x56, 0x78}}, |
| 3456 | // Zero delta time. |
| 3457 | {"Unable to read ack delay time.", |
| 3458 | {0x00, 0x00}}, |
| 3459 | // first ack block length. |
| 3460 | {"Unable to read first ack block length.", |
| 3461 | {0x12, 0x34}}, |
| 3462 | // num timestamps. |
| 3463 | {"Unable to read num received packets.", |
| 3464 | {0x00}} |
| 3465 | }; |
| 3466 | |
| 3467 | PacketFragments packet46 = { |
| 3468 | // type (short header, 4 byte packet number) |
| 3469 | {"", |
| 3470 | {0x43}}, |
| 3471 | // connection_id |
| 3472 | {"", |
| 3473 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3474 | // packet number |
| 3475 | {"", |
| 3476 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3477 | // frame type (ack frame) |
| 3478 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3479 | {"", |
| 3480 | {0x49}}, |
| 3481 | // largest acked |
| 3482 | {"Unable to read largest acked.", |
| 3483 | {0x12, 0x34, 0x56, 0x78}}, |
| 3484 | // Zero delta time. |
| 3485 | {"Unable to read ack delay time.", |
| 3486 | {0x00, 0x00}}, |
| 3487 | // first ack block length. |
| 3488 | {"Unable to read first ack block length.", |
| 3489 | {0x12, 0x34}}, |
| 3490 | // num timestamps. |
| 3491 | {"Unable to read num received packets.", |
| 3492 | {0x00}} |
| 3493 | }; |
| 3494 | |
| 3495 | PacketFragments packet99 = { |
| 3496 | // type (short header, 4 byte packet number) |
| 3497 | {"", |
| 3498 | {0x43}}, |
| 3499 | // connection_id |
| 3500 | {"", |
| 3501 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3502 | // packet number |
| 3503 | {"", |
| 3504 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3505 | // frame type (IETF_ACK frame) |
| 3506 | {"", |
| 3507 | {0x02}}, |
| 3508 | // largest acked |
| 3509 | {"Unable to read largest acked.", |
| 3510 | {kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78}}, |
| 3511 | // Zero delta time. |
| 3512 | {"Unable to read ack delay time.", |
| 3513 | {kVarInt62OneByte + 0x00}}, |
| 3514 | // Number of ack blocks after first |
| 3515 | {"Unable to read ack block count.", |
| 3516 | {kVarInt62OneByte + 0x00}}, |
| 3517 | // first ack block length. |
| 3518 | {"Unable to read first ack block length.", |
| 3519 | {kVarInt62TwoBytes + 0x12, 0x33}} |
| 3520 | }; |
| 3521 | // clang-format on |
| 3522 | |
| 3523 | PacketFragments& fragments = |
| 3524 | framer_.transport_version() == QUIC_VERSION_99 |
| 3525 | ? packet99 |
| 3526 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 3527 | ? packet46 |
| 3528 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 3529 | : packet)); |
| 3530 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3531 | AssemblePacketFromFragments(fragments)); |
| 3532 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3533 | |
| 3534 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 3535 | ASSERT_TRUE(visitor_.header_.get()); |
| 3536 | EXPECT_TRUE(CheckDecryption( |
| 3537 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3538 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3539 | |
| 3540 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3541 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3542 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3543 | EXPECT_EQ(kPacketNumber, LargestAcked(frame)); |
| 3544 | ASSERT_EQ(4660u, frame.packets.NumPacketsSlow()); |
| 3545 | |
| 3546 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3547 | } |
| 3548 | |
| 3549 | // Tests ability to handle multiple ackblocks after the first ack |
| 3550 | // block. Non-version-99 tests include multiple timestamps as well. |
| 3551 | TEST_P(QuicFramerTest, AckFrameTwoTimeStampsMultipleAckBlocks) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3552 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3553 | // clang-format off |
| 3554 | PacketFragments packet = { |
| 3555 | // public flags (8 byte connection_id) |
| 3556 | {"", |
| 3557 | { 0x2C }}, |
| 3558 | // connection_id |
| 3559 | {"", |
| 3560 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3561 | // packet number |
| 3562 | {"", |
| 3563 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3564 | |
| 3565 | // frame type (ack frame) |
| 3566 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3567 | {"", |
| 3568 | { 0x65 }}, |
| 3569 | // largest acked |
| 3570 | {"Unable to read largest acked.", |
| 3571 | { 0x12, 0x34 }}, |
| 3572 | // Zero delta time. |
| 3573 | {"Unable to read ack delay time.", |
| 3574 | { 0x00, 0x00 }}, |
| 3575 | // num ack blocks ranges. |
| 3576 | {"Unable to read num of ack blocks.", |
| 3577 | { 0x04 }}, |
| 3578 | // first ack block length. |
| 3579 | {"Unable to read first ack block length.", |
| 3580 | { 0x00, 0x01 }}, |
| 3581 | // gap to next block. |
| 3582 | { "Unable to read gap to next ack block.", |
| 3583 | { 0x01 }}, |
| 3584 | // ack block length. |
| 3585 | { "Unable to ack block length.", |
| 3586 | { 0x0e, 0xaf }}, |
| 3587 | // gap to next block. |
| 3588 | { "Unable to read gap to next ack block.", |
| 3589 | { 0xff }}, |
| 3590 | // ack block length. |
| 3591 | { "Unable to ack block length.", |
| 3592 | { 0x00, 0x00 }}, |
| 3593 | // gap to next block. |
| 3594 | { "Unable to read gap to next ack block.", |
| 3595 | { 0x91 }}, |
| 3596 | // ack block length. |
| 3597 | { "Unable to ack block length.", |
| 3598 | { 0x01, 0xea }}, |
| 3599 | // gap to next block. |
| 3600 | { "Unable to read gap to next ack block.", |
| 3601 | { 0x05 }}, |
| 3602 | // ack block length. |
| 3603 | { "Unable to ack block length.", |
| 3604 | { 0x00, 0x04 }}, |
| 3605 | // Number of timestamps. |
| 3606 | { "Unable to read num received packets.", |
| 3607 | { 0x02 }}, |
| 3608 | // Delta from largest observed. |
| 3609 | { "Unable to read sequence delta in received packets.", |
| 3610 | { 0x01 }}, |
| 3611 | // Delta time. |
| 3612 | { "Unable to read time delta in received packets.", |
| 3613 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3614 | // Delta from largest observed. |
| 3615 | { "Unable to read sequence delta in received packets.", |
| 3616 | { 0x02 }}, |
| 3617 | // Delta time. |
| 3618 | { "Unable to read incremental time delta in received packets.", |
| 3619 | { 0x32, 0x10 }}, |
| 3620 | }; |
| 3621 | |
| 3622 | PacketFragments packet44 = { |
| 3623 | // type (short header, 4 byte packet number) |
| 3624 | {"", |
| 3625 | { 0x32 }}, |
| 3626 | // connection_id |
| 3627 | {"", |
| 3628 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3629 | // packet number |
| 3630 | {"", |
| 3631 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3632 | |
| 3633 | // frame type (ack frame) |
| 3634 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3635 | {"", |
| 3636 | { 0x65 }}, |
| 3637 | // largest acked |
| 3638 | {"Unable to read largest acked.", |
| 3639 | { 0x12, 0x34 }}, |
| 3640 | // Zero delta time. |
| 3641 | {"Unable to read ack delay time.", |
| 3642 | { 0x00, 0x00 }}, |
| 3643 | // num ack blocks ranges. |
| 3644 | {"Unable to read num of ack blocks.", |
| 3645 | { 0x04 }}, |
| 3646 | // first ack block length. |
| 3647 | {"Unable to read first ack block length.", |
| 3648 | { 0x00, 0x01 }}, |
| 3649 | // gap to next block. |
| 3650 | { "Unable to read gap to next ack block.", |
| 3651 | { 0x01 }}, |
| 3652 | // ack block length. |
| 3653 | { "Unable to ack block length.", |
| 3654 | { 0x0e, 0xaf }}, |
| 3655 | // gap to next block. |
| 3656 | { "Unable to read gap to next ack block.", |
| 3657 | { 0xff }}, |
| 3658 | // ack block length. |
| 3659 | { "Unable to ack block length.", |
| 3660 | { 0x00, 0x00 }}, |
| 3661 | // gap to next block. |
| 3662 | { "Unable to read gap to next ack block.", |
| 3663 | { 0x91 }}, |
| 3664 | // ack block length. |
| 3665 | { "Unable to ack block length.", |
| 3666 | { 0x01, 0xea }}, |
| 3667 | // gap to next block. |
| 3668 | { "Unable to read gap to next ack block.", |
| 3669 | { 0x05 }}, |
| 3670 | // ack block length. |
| 3671 | { "Unable to ack block length.", |
| 3672 | { 0x00, 0x04 }}, |
| 3673 | // Number of timestamps. |
| 3674 | { "Unable to read num received packets.", |
| 3675 | { 0x02 }}, |
| 3676 | // Delta from largest observed. |
| 3677 | { "Unable to read sequence delta in received packets.", |
| 3678 | { 0x01 }}, |
| 3679 | // Delta time. |
| 3680 | { "Unable to read time delta in received packets.", |
| 3681 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3682 | // Delta from largest observed. |
| 3683 | { "Unable to read sequence delta in received packets.", |
| 3684 | { 0x02 }}, |
| 3685 | // Delta time. |
| 3686 | { "Unable to read incremental time delta in received packets.", |
| 3687 | { 0x32, 0x10 }}, |
| 3688 | }; |
| 3689 | |
| 3690 | PacketFragments packet46 = { |
| 3691 | // type (short header, 4 byte packet number) |
| 3692 | {"", |
| 3693 | { 0x43 }}, |
| 3694 | // connection_id |
| 3695 | {"", |
| 3696 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3697 | // packet number |
| 3698 | {"", |
| 3699 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3700 | |
| 3701 | // frame type (ack frame) |
| 3702 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3703 | {"", |
| 3704 | { 0x65 }}, |
| 3705 | // largest acked |
| 3706 | {"Unable to read largest acked.", |
| 3707 | { 0x12, 0x34 }}, |
| 3708 | // Zero delta time. |
| 3709 | {"Unable to read ack delay time.", |
| 3710 | { 0x00, 0x00 }}, |
| 3711 | // num ack blocks ranges. |
| 3712 | {"Unable to read num of ack blocks.", |
| 3713 | { 0x04 }}, |
| 3714 | // first ack block length. |
| 3715 | {"Unable to read first ack block length.", |
| 3716 | { 0x00, 0x01 }}, |
| 3717 | // gap to next block. |
| 3718 | { "Unable to read gap to next ack block.", |
| 3719 | { 0x01 }}, |
| 3720 | // ack block length. |
| 3721 | { "Unable to ack block length.", |
| 3722 | { 0x0e, 0xaf }}, |
| 3723 | // gap to next block. |
| 3724 | { "Unable to read gap to next ack block.", |
| 3725 | { 0xff }}, |
| 3726 | // ack block length. |
| 3727 | { "Unable to ack block length.", |
| 3728 | { 0x00, 0x00 }}, |
| 3729 | // gap to next block. |
| 3730 | { "Unable to read gap to next ack block.", |
| 3731 | { 0x91 }}, |
| 3732 | // ack block length. |
| 3733 | { "Unable to ack block length.", |
| 3734 | { 0x01, 0xea }}, |
| 3735 | // gap to next block. |
| 3736 | { "Unable to read gap to next ack block.", |
| 3737 | { 0x05 }}, |
| 3738 | // ack block length. |
| 3739 | { "Unable to ack block length.", |
| 3740 | { 0x00, 0x04 }}, |
| 3741 | // Number of timestamps. |
| 3742 | { "Unable to read num received packets.", |
| 3743 | { 0x02 }}, |
| 3744 | // Delta from largest observed. |
| 3745 | { "Unable to read sequence delta in received packets.", |
| 3746 | { 0x01 }}, |
| 3747 | // Delta time. |
| 3748 | { "Unable to read time delta in received packets.", |
| 3749 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3750 | // Delta from largest observed. |
| 3751 | { "Unable to read sequence delta in received packets.", |
| 3752 | { 0x02 }}, |
| 3753 | // Delta time. |
| 3754 | { "Unable to read incremental time delta in received packets.", |
| 3755 | { 0x32, 0x10 }}, |
| 3756 | }; |
| 3757 | |
| 3758 | PacketFragments packet99 = { |
| 3759 | // type (short header, 4 byte packet number) |
| 3760 | {"", |
| 3761 | { 0x43 }}, |
| 3762 | // connection_id |
| 3763 | {"", |
| 3764 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3765 | // packet number |
| 3766 | {"", |
| 3767 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3768 | |
| 3769 | // frame type (IETF_ACK frame) |
| 3770 | {"", |
| 3771 | { 0x02 }}, |
| 3772 | // largest acked |
| 3773 | {"Unable to read largest acked.", |
| 3774 | { kVarInt62TwoBytes + 0x12, 0x34 }}, // = 4660 |
| 3775 | // Zero delta time. |
| 3776 | {"Unable to read ack delay time.", |
| 3777 | { kVarInt62OneByte + 0x00 }}, |
| 3778 | // number of additional ack blocks |
| 3779 | {"Unable to read ack block count.", |
| 3780 | { kVarInt62OneByte + 0x03 }}, |
| 3781 | // first ack block length. |
| 3782 | {"Unable to read first ack block length.", |
| 3783 | { kVarInt62OneByte + 0x00 }}, // 1st block length = 1 |
| 3784 | |
| 3785 | // Additional ACK Block #1 |
| 3786 | // gap to next block. |
| 3787 | { "Unable to read gap block value.", |
| 3788 | { kVarInt62OneByte + 0x00 }}, // gap of 1 packet |
| 3789 | // ack block length. |
| 3790 | { "Unable to read ack block value.", |
| 3791 | { kVarInt62TwoBytes + 0x0e, 0xae }}, // 3759 |
| 3792 | |
| 3793 | // pre-version-99 test includes an ack block of 0 length. this |
| 3794 | // can not happen in version 99. ergo the second block is not |
| 3795 | // present in the v99 test and the gap length of the next block |
| 3796 | // is the sum of the two gaps in the pre-version-99 tests. |
| 3797 | // Additional ACK Block #2 |
| 3798 | // gap to next block. |
| 3799 | { "Unable to read gap block value.", |
| 3800 | { kVarInt62TwoBytes + 0x01, 0x8f }}, // Gap is 400 (0x190) pkts |
| 3801 | // ack block length. |
| 3802 | { "Unable to read ack block value.", |
| 3803 | { kVarInt62TwoBytes + 0x01, 0xe9 }}, // block is 389 (x1ea) pkts |
| 3804 | |
| 3805 | // Additional ACK Block #3 |
| 3806 | // gap to next block. |
| 3807 | { "Unable to read gap block value.", |
| 3808 | { kVarInt62OneByte + 0x04 }}, // Gap is 5 packets. |
| 3809 | // ack block length. |
| 3810 | { "Unable to read ack block value.", |
| 3811 | { kVarInt62OneByte + 0x03 }}, // block is 3 packets. |
| 3812 | }; |
| 3813 | |
| 3814 | // clang-format on |
| 3815 | PacketFragments& fragments = |
| 3816 | framer_.transport_version() == QUIC_VERSION_99 |
| 3817 | ? packet99 |
| 3818 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 3819 | ? packet46 |
| 3820 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 3821 | : packet)); |
| 3822 | |
| 3823 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3824 | AssemblePacketFromFragments(fragments)); |
| 3825 | |
| 3826 | framer_.set_process_timestamps(true); |
| 3827 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3828 | |
| 3829 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 3830 | ASSERT_TRUE(visitor_.header_.get()); |
| 3831 | EXPECT_TRUE(CheckDecryption( |
| 3832 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3833 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3834 | |
| 3835 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3836 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3837 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3838 | EXPECT_EQ(kSmallLargestObserved, LargestAcked(frame)); |
| 3839 | ASSERT_EQ(4254u, frame.packets.NumPacketsSlow()); |
| 3840 | EXPECT_EQ(4u, frame.packets.NumIntervals()); |
| 3841 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 3842 | EXPECT_EQ(0u, frame.received_packet_times.size()); |
| 3843 | } else { |
| 3844 | EXPECT_EQ(2u, frame.received_packet_times.size()); |
| 3845 | } |
| 3846 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3847 | } |
| 3848 | |
| 3849 | TEST_P(QuicFramerTest, AckFrameTimeStampDeltaTooHigh) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 3850 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3851 | // clang-format off |
| 3852 | unsigned char packet[] = { |
| 3853 | // public flags (8 byte connection_id) |
| 3854 | 0x28, |
| 3855 | // connection_id |
| 3856 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3857 | // packet number |
| 3858 | 0x12, 0x34, 0x56, 0x78, |
| 3859 | |
| 3860 | // frame type (ack frame) |
| 3861 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3862 | 0x40, |
| 3863 | // largest acked |
| 3864 | 0x01, |
| 3865 | // Zero delta time. |
| 3866 | 0x00, 0x00, |
| 3867 | // first ack block length. |
| 3868 | 0x01, |
| 3869 | // num timestamps. |
| 3870 | 0x01, |
| 3871 | // Delta from largest observed. |
| 3872 | 0x01, |
| 3873 | // Delta time. |
| 3874 | 0x10, 0x32, 0x54, 0x76, |
| 3875 | }; |
| 3876 | |
| 3877 | unsigned char packet44[] = { |
| 3878 | // type (short header, 4 byte packet number) |
| 3879 | 0x32, |
| 3880 | // connection_id |
| 3881 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3882 | // packet number |
| 3883 | 0x12, 0x34, 0x56, 0x78, |
| 3884 | |
| 3885 | // frame type (ack frame) |
| 3886 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3887 | 0x40, |
| 3888 | // largest acked |
| 3889 | 0x01, |
| 3890 | // Zero delta time. |
| 3891 | 0x00, 0x00, |
| 3892 | // first ack block length. |
| 3893 | 0x01, |
| 3894 | // num timestamps. |
| 3895 | 0x01, |
| 3896 | // Delta from largest observed. |
| 3897 | 0x01, |
| 3898 | // Delta time. |
| 3899 | 0x10, 0x32, 0x54, 0x76, |
| 3900 | }; |
| 3901 | |
| 3902 | unsigned char packet46[] = { |
| 3903 | // type (short header, 4 byte packet number) |
| 3904 | 0x43, |
| 3905 | // connection_id |
| 3906 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3907 | // packet number |
| 3908 | 0x12, 0x34, 0x56, 0x78, |
| 3909 | |
| 3910 | // frame type (ack frame) |
| 3911 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3912 | 0x40, |
| 3913 | // largest acked |
| 3914 | 0x01, |
| 3915 | // Zero delta time. |
| 3916 | 0x00, 0x00, |
| 3917 | // first ack block length. |
| 3918 | 0x01, |
| 3919 | // num timestamps. |
| 3920 | 0x01, |
| 3921 | // Delta from largest observed. |
| 3922 | 0x01, |
| 3923 | // Delta time. |
| 3924 | 0x10, 0x32, 0x54, 0x76, |
| 3925 | }; |
| 3926 | // clang-format on |
| 3927 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 3928 | return; |
| 3929 | } |
| 3930 | QuicEncryptedPacket encrypted( |
| 3931 | AsChars(framer_.transport_version() > QUIC_VERSION_44 |
| 3932 | ? packet46 |
| 3933 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 3934 | : packet)), |
| 3935 | QUIC_ARRAYSIZE(packet), false); |
| 3936 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 3937 | EXPECT_TRUE(QuicTextUtils::StartsWith( |
| 3938 | framer_.detailed_error(), "delta_from_largest_observed too high")); |
| 3939 | } |
| 3940 | |
| 3941 | TEST_P(QuicFramerTest, AckFrameTimeStampSecondDeltaTooHigh) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 3942 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3943 | // clang-format off |
| 3944 | unsigned char packet[] = { |
| 3945 | // public flags (8 byte connection_id) |
| 3946 | 0x28, |
| 3947 | // connection_id |
| 3948 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3949 | // packet number |
| 3950 | 0x12, 0x34, 0x56, 0x78, |
| 3951 | |
| 3952 | // frame type (ack frame) |
| 3953 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3954 | 0x40, |
| 3955 | // largest acked |
| 3956 | 0x03, |
| 3957 | // Zero delta time. |
| 3958 | 0x00, 0x00, |
| 3959 | // first ack block length. |
| 3960 | 0x03, |
| 3961 | // num timestamps. |
| 3962 | 0x02, |
| 3963 | // Delta from largest observed. |
| 3964 | 0x01, |
| 3965 | // Delta time. |
| 3966 | 0x10, 0x32, 0x54, 0x76, |
| 3967 | // Delta from largest observed. |
| 3968 | 0x03, |
| 3969 | // Delta time. |
| 3970 | 0x10, 0x32, |
| 3971 | }; |
| 3972 | |
| 3973 | unsigned char packet44[] = { |
| 3974 | // type (short header, 4 byte packet number) |
| 3975 | 0x32, |
| 3976 | // connection_id |
| 3977 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3978 | // packet number |
| 3979 | 0x12, 0x34, 0x56, 0x78, |
| 3980 | |
| 3981 | // frame type (ack frame) |
| 3982 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3983 | 0x40, |
| 3984 | // largest acked |
| 3985 | 0x03, |
| 3986 | // Zero delta time. |
| 3987 | 0x00, 0x00, |
| 3988 | // first ack block length. |
| 3989 | 0x03, |
| 3990 | // num timestamps. |
| 3991 | 0x02, |
| 3992 | // Delta from largest observed. |
| 3993 | 0x01, |
| 3994 | // Delta time. |
| 3995 | 0x10, 0x32, 0x54, 0x76, |
| 3996 | // Delta from largest observed. |
| 3997 | 0x03, |
| 3998 | // Delta time. |
| 3999 | 0x10, 0x32, |
| 4000 | }; |
| 4001 | |
| 4002 | unsigned char packet46[] = { |
| 4003 | // type (short header, 4 byte packet number) |
| 4004 | 0x43, |
| 4005 | // connection_id |
| 4006 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4007 | // packet number |
| 4008 | 0x12, 0x34, 0x56, 0x78, |
| 4009 | |
| 4010 | // frame type (ack frame) |
| 4011 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 4012 | 0x40, |
| 4013 | // largest acked |
| 4014 | 0x03, |
| 4015 | // Zero delta time. |
| 4016 | 0x00, 0x00, |
| 4017 | // first ack block length. |
| 4018 | 0x03, |
| 4019 | // num timestamps. |
| 4020 | 0x02, |
| 4021 | // Delta from largest observed. |
| 4022 | 0x01, |
| 4023 | // Delta time. |
| 4024 | 0x10, 0x32, 0x54, 0x76, |
| 4025 | // Delta from largest observed. |
| 4026 | 0x03, |
| 4027 | // Delta time. |
| 4028 | 0x10, 0x32, |
| 4029 | }; |
| 4030 | // clang-format on |
| 4031 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4032 | return; |
| 4033 | } |
| 4034 | QuicEncryptedPacket encrypted( |
| 4035 | AsChars(framer_.transport_version() > QUIC_VERSION_44 |
| 4036 | ? packet46 |
| 4037 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4038 | : packet)), |
| 4039 | QUIC_ARRAYSIZE(packet), false); |
| 4040 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 4041 | EXPECT_TRUE(QuicTextUtils::StartsWith( |
| 4042 | framer_.detailed_error(), "delta_from_largest_observed too high")); |
| 4043 | } |
| 4044 | |
| 4045 | TEST_P(QuicFramerTest, NewStopWaitingFrame) { |
| 4046 | if (version_.transport_version == QUIC_VERSION_99) { |
| 4047 | return; |
| 4048 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4049 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4050 | // clang-format off |
| 4051 | PacketFragments packet = { |
| 4052 | // public flags (8 byte connection_id) |
| 4053 | {"", |
| 4054 | {0x2C}}, |
| 4055 | // connection_id |
| 4056 | {"", |
| 4057 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4058 | // packet number |
| 4059 | {"", |
| 4060 | {0x12, 0x34, 0x56, 0x78}}, |
| 4061 | // frame type (stop waiting frame) |
| 4062 | {"", |
| 4063 | {0x06}}, |
| 4064 | // least packet number awaiting an ack, delta from packet number. |
| 4065 | {"Unable to read least unacked delta.", |
| 4066 | {0x00, 0x00, 0x00, 0x08}} |
| 4067 | }; |
| 4068 | |
| 4069 | PacketFragments packet44 = { |
| 4070 | // type (short header, 4 byte packet number) |
| 4071 | {"", |
| 4072 | {0x32}}, |
| 4073 | // connection_id |
| 4074 | {"", |
| 4075 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4076 | // packet number |
| 4077 | {"", |
| 4078 | {0x12, 0x34, 0x56, 0x78}}, |
| 4079 | // frame type (stop waiting frame) |
| 4080 | {"", |
| 4081 | {0x06}}, |
| 4082 | // least packet number awaiting an ack, delta from packet number. |
| 4083 | {"Unable to read least unacked delta.", |
| 4084 | {0x00, 0x00, 0x00, 0x08}} |
| 4085 | }; |
| 4086 | |
| 4087 | PacketFragments packet46 = { |
| 4088 | // type (short header, 4 byte packet number) |
| 4089 | {"", |
| 4090 | {0x43}}, |
| 4091 | // connection_id |
| 4092 | {"", |
| 4093 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4094 | // packet number |
| 4095 | {"", |
| 4096 | {0x12, 0x34, 0x56, 0x78}}, |
| 4097 | // frame type (stop waiting frame) |
| 4098 | {"", |
| 4099 | {0x06}}, |
| 4100 | // least packet number awaiting an ack, delta from packet number. |
| 4101 | {"Unable to read least unacked delta.", |
| 4102 | {0x00, 0x00, 0x00, 0x08}} |
| 4103 | }; |
| 4104 | // clang-format on |
| 4105 | |
| 4106 | PacketFragments& fragments = |
| 4107 | framer_.transport_version() > QUIC_VERSION_44 |
| 4108 | ? packet46 |
| 4109 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 4110 | |
| 4111 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4112 | AssemblePacketFromFragments(fragments)); |
ianswett | 97b690b | 2019-05-02 15:12:43 -0700 | [diff] [blame] | 4113 | if (GetQuicReloadableFlag(quic_do_not_accept_stop_waiting) && |
| 4114 | version_.transport_version >= QUIC_VERSION_44) { |
| 4115 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 4116 | EXPECT_EQ(QUIC_INVALID_STOP_WAITING_DATA, framer_.error()); |
| 4117 | EXPECT_EQ("STOP WAITING not supported in version 44+.", |
| 4118 | framer_.detailed_error()); |
| 4119 | return; |
| 4120 | } |
| 4121 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4122 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4123 | |
| 4124 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4125 | ASSERT_TRUE(visitor_.header_.get()); |
| 4126 | EXPECT_TRUE(CheckDecryption( |
| 4127 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4128 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4129 | |
| 4130 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4131 | ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size()); |
| 4132 | const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0]; |
| 4133 | EXPECT_EQ(kLeastUnacked, frame.least_unacked); |
| 4134 | |
| 4135 | CheckFramingBoundaries(fragments, QUIC_INVALID_STOP_WAITING_DATA); |
| 4136 | } |
| 4137 | |
| 4138 | TEST_P(QuicFramerTest, InvalidNewStopWaitingFrame) { |
ianswett | 97b690b | 2019-05-02 15:12:43 -0700 | [diff] [blame] | 4139 | if (version_.transport_version == QUIC_VERSION_99 || |
| 4140 | (GetQuicReloadableFlag(quic_do_not_accept_stop_waiting) && |
| 4141 | version_.transport_version >= QUIC_VERSION_44)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4142 | return; |
| 4143 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4144 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4145 | // clang-format off |
| 4146 | unsigned char packet[] = { |
| 4147 | // public flags (8 byte connection_id) |
| 4148 | 0x2C, |
| 4149 | // connection_id |
| 4150 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4151 | // packet number |
| 4152 | 0x12, 0x34, 0x56, 0x78, |
| 4153 | // frame type (stop waiting frame) |
| 4154 | 0x06, |
| 4155 | // least packet number awaiting an ack, delta from packet number. |
| 4156 | 0x13, 0x34, 0x56, 0x78, |
| 4157 | 0x9A, 0xA8, |
| 4158 | }; |
| 4159 | |
| 4160 | unsigned char packet44[] = { |
| 4161 | // type (short header, 4 byte packet number) |
| 4162 | 0x32, |
| 4163 | // connection_id |
| 4164 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4165 | // packet number |
| 4166 | 0x12, 0x34, 0x56, 0x78, |
| 4167 | // frame type (stop waiting frame) |
| 4168 | 0x06, |
| 4169 | // least packet number awaiting an ack, delta from packet number. |
| 4170 | 0x57, 0x78, 0x9A, 0xA8, |
| 4171 | }; |
| 4172 | |
| 4173 | unsigned char packet46[] = { |
| 4174 | // type (short header, 4 byte packet number) |
| 4175 | 0x43, |
| 4176 | // connection_id |
| 4177 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4178 | // packet number |
| 4179 | 0x12, 0x34, 0x56, 0x78, |
| 4180 | // frame type (stop waiting frame) |
| 4181 | 0x06, |
| 4182 | // least packet number awaiting an ack, delta from packet number. |
| 4183 | 0x57, 0x78, 0x9A, 0xA8, |
| 4184 | }; |
| 4185 | // clang-format on |
| 4186 | |
| 4187 | QuicEncryptedPacket encrypted( |
| 4188 | AsChars(framer_.transport_version() > QUIC_VERSION_44 |
| 4189 | ? packet46 |
| 4190 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4191 | : packet)), |
| 4192 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 4193 | : QUIC_ARRAYSIZE(packet), |
| 4194 | false); |
| 4195 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 4196 | EXPECT_EQ(QUIC_INVALID_STOP_WAITING_DATA, framer_.error()); |
| 4197 | EXPECT_EQ("Invalid unacked delta.", framer_.detailed_error()); |
| 4198 | } |
| 4199 | |
| 4200 | TEST_P(QuicFramerTest, RstStreamFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4201 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4202 | // clang-format off |
| 4203 | PacketFragments packet = { |
| 4204 | // public flags (8 byte connection_id) |
| 4205 | {"", |
| 4206 | {0x28}}, |
| 4207 | // connection_id |
| 4208 | {"", |
| 4209 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4210 | // packet number |
| 4211 | {"", |
| 4212 | {0x12, 0x34, 0x56, 0x78}}, |
| 4213 | // frame type (rst stream frame) |
| 4214 | {"", |
| 4215 | {0x01}}, |
| 4216 | // stream id |
| 4217 | {"Unable to read stream_id.", |
| 4218 | {0x01, 0x02, 0x03, 0x04}}, |
| 4219 | // sent byte offset |
| 4220 | {"Unable to read rst stream sent byte offset.", |
| 4221 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4222 | 0x32, 0x10, 0x76, 0x54}}, |
| 4223 | // error code |
| 4224 | {"Unable to read rst stream error code.", |
| 4225 | {0x00, 0x00, 0x00, 0x01}} |
| 4226 | }; |
| 4227 | |
| 4228 | PacketFragments packet44 = { |
| 4229 | // type (short header, 4 byte packet number) |
| 4230 | {"", |
| 4231 | {0x32}}, |
| 4232 | // connection_id |
| 4233 | {"", |
| 4234 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4235 | // packet number |
| 4236 | {"", |
| 4237 | {0x12, 0x34, 0x56, 0x78}}, |
| 4238 | // frame type (rst stream frame) |
| 4239 | {"", |
| 4240 | {0x01}}, |
| 4241 | // stream id |
| 4242 | {"Unable to read stream_id.", |
| 4243 | {0x01, 0x02, 0x03, 0x04}}, |
| 4244 | // sent byte offset |
| 4245 | {"Unable to read rst stream sent byte offset.", |
| 4246 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4247 | 0x32, 0x10, 0x76, 0x54}}, |
| 4248 | // error code |
| 4249 | {"Unable to read rst stream error code.", |
| 4250 | {0x00, 0x00, 0x00, 0x01}} |
| 4251 | }; |
| 4252 | |
| 4253 | PacketFragments packet46 = { |
| 4254 | // type (short header, 4 byte packet number) |
| 4255 | {"", |
| 4256 | {0x43}}, |
| 4257 | // connection_id |
| 4258 | {"", |
| 4259 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4260 | // packet number |
| 4261 | {"", |
| 4262 | {0x12, 0x34, 0x56, 0x78}}, |
| 4263 | // frame type (rst stream frame) |
| 4264 | {"", |
| 4265 | {0x01}}, |
| 4266 | // stream id |
| 4267 | {"Unable to read stream_id.", |
| 4268 | {0x01, 0x02, 0x03, 0x04}}, |
| 4269 | // sent byte offset |
| 4270 | {"Unable to read rst stream sent byte offset.", |
| 4271 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4272 | 0x32, 0x10, 0x76, 0x54}}, |
| 4273 | // error code |
| 4274 | {"Unable to read rst stream error code.", |
| 4275 | {0x00, 0x00, 0x00, 0x01}} |
| 4276 | }; |
| 4277 | |
| 4278 | PacketFragments packet99 = { |
| 4279 | // type (short header, 4 byte packet number) |
| 4280 | {"", |
| 4281 | {0x43}}, |
| 4282 | // connection_id |
| 4283 | {"", |
| 4284 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4285 | // packet number |
| 4286 | {"", |
| 4287 | {0x12, 0x34, 0x56, 0x78}}, |
| 4288 | // frame type (IETF_RST_STREAM frame) |
| 4289 | {"", |
| 4290 | {0x04}}, |
| 4291 | // stream id |
| 4292 | {"Unable to read rst stream stream id.", |
| 4293 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 4294 | // application error code |
| 4295 | {"Unable to read rst stream error code.", |
| 4296 | {0x00, 0x01}}, // Not varint62 encoded |
| 4297 | // Final Offset |
| 4298 | {"Unable to read rst stream sent byte offset.", |
| 4299 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}} |
| 4300 | }; |
| 4301 | // clang-format on |
| 4302 | |
| 4303 | PacketFragments& fragments = |
| 4304 | framer_.transport_version() == QUIC_VERSION_99 |
| 4305 | ? packet99 |
| 4306 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 4307 | ? packet46 |
| 4308 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4309 | : packet)); |
| 4310 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4311 | AssemblePacketFromFragments(fragments)); |
| 4312 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4313 | |
| 4314 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4315 | ASSERT_TRUE(visitor_.header_.get()); |
| 4316 | EXPECT_TRUE(CheckDecryption( |
| 4317 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4318 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4319 | |
| 4320 | EXPECT_EQ(kStreamId, visitor_.rst_stream_frame_.stream_id); |
| 4321 | EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code); |
| 4322 | EXPECT_EQ(kStreamOffset, visitor_.rst_stream_frame_.byte_offset); |
| 4323 | CheckFramingBoundaries(fragments, QUIC_INVALID_RST_STREAM_DATA); |
| 4324 | } |
| 4325 | |
| 4326 | TEST_P(QuicFramerTest, ConnectionCloseFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4327 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4328 | // clang-format off |
| 4329 | PacketFragments packet = { |
| 4330 | // public flags (8 byte connection_id) |
| 4331 | {"", |
| 4332 | {0x28}}, |
| 4333 | // connection_id |
| 4334 | {"", |
| 4335 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4336 | // packet number |
| 4337 | {"", |
| 4338 | {0x12, 0x34, 0x56, 0x78}}, |
| 4339 | // frame type (connection close frame) |
| 4340 | {"", |
| 4341 | {0x02}}, |
| 4342 | // error code |
| 4343 | {"Unable to read connection close error code.", |
| 4344 | {0x00, 0x00, 0x00, 0x11}}, |
| 4345 | {"Unable to read connection close error details.", |
| 4346 | { |
| 4347 | // error details length |
| 4348 | 0x0, 0x0d, |
| 4349 | // error details |
| 4350 | 'b', 'e', 'c', 'a', |
| 4351 | 'u', 's', 'e', ' ', |
| 4352 | 'I', ' ', 'c', 'a', |
| 4353 | 'n'} |
| 4354 | } |
| 4355 | }; |
| 4356 | |
| 4357 | PacketFragments packet44 = { |
| 4358 | // type (short header, 4 byte packet number) |
| 4359 | {"", |
| 4360 | {0x32}}, |
| 4361 | // connection_id |
| 4362 | {"", |
| 4363 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4364 | // packet number |
| 4365 | {"", |
| 4366 | {0x12, 0x34, 0x56, 0x78}}, |
| 4367 | // frame type (connection close frame) |
| 4368 | {"", |
| 4369 | {0x02}}, |
| 4370 | // error code |
| 4371 | {"Unable to read connection close error code.", |
| 4372 | {0x00, 0x00, 0x00, 0x11}}, |
| 4373 | {"Unable to read connection close error details.", |
| 4374 | { |
| 4375 | // error details length |
| 4376 | 0x0, 0x0d, |
| 4377 | // error details |
| 4378 | 'b', 'e', 'c', 'a', |
| 4379 | 'u', 's', 'e', ' ', |
| 4380 | 'I', ' ', 'c', 'a', |
| 4381 | 'n'} |
| 4382 | } |
| 4383 | }; |
| 4384 | |
| 4385 | PacketFragments packet46 = { |
| 4386 | // type (short header, 4 byte packet number) |
| 4387 | {"", |
| 4388 | {0x43}}, |
| 4389 | // connection_id |
| 4390 | {"", |
| 4391 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4392 | // packet number |
| 4393 | {"", |
| 4394 | {0x12, 0x34, 0x56, 0x78}}, |
| 4395 | // frame type (connection close frame) |
| 4396 | {"", |
| 4397 | {0x02}}, |
| 4398 | // error code |
| 4399 | {"Unable to read connection close error code.", |
| 4400 | {0x00, 0x00, 0x00, 0x11}}, |
| 4401 | {"Unable to read connection close error details.", |
| 4402 | { |
| 4403 | // error details length |
| 4404 | 0x0, 0x0d, |
| 4405 | // error details |
| 4406 | 'b', 'e', 'c', 'a', |
| 4407 | 'u', 's', 'e', ' ', |
| 4408 | 'I', ' ', 'c', 'a', |
| 4409 | 'n'} |
| 4410 | } |
| 4411 | }; |
| 4412 | |
| 4413 | PacketFragments packet99 = { |
| 4414 | // type (short header, 4 byte packet number) |
| 4415 | {"", |
| 4416 | {0x43}}, |
| 4417 | // connection_id |
| 4418 | {"", |
| 4419 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4420 | // packet number |
| 4421 | {"", |
| 4422 | {0x12, 0x34, 0x56, 0x78}}, |
| 4423 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 4424 | {"", |
| 4425 | {0x1c}}, |
| 4426 | // error code |
| 4427 | {"Unable to read connection close error code.", |
| 4428 | {0x00, 0x11}}, |
| 4429 | {"Unable to read connection close frame type.", |
| 4430 | {kVarInt62TwoBytes + 0x12, 0x34 }}, |
| 4431 | {"Unable to read connection close error details.", |
| 4432 | { |
| 4433 | // error details length |
| 4434 | kVarInt62OneByte + 0x0d, |
| 4435 | // error details |
| 4436 | 'b', 'e', 'c', 'a', |
| 4437 | 'u', 's', 'e', ' ', |
| 4438 | 'I', ' ', 'c', 'a', |
| 4439 | 'n'} |
| 4440 | } |
| 4441 | }; |
| 4442 | // clang-format on |
| 4443 | |
| 4444 | PacketFragments& fragments = |
| 4445 | framer_.transport_version() == QUIC_VERSION_99 |
| 4446 | ? packet99 |
| 4447 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 4448 | ? packet46 |
| 4449 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4450 | : packet)); |
| 4451 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4452 | AssemblePacketFromFragments(fragments)); |
| 4453 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4454 | |
| 4455 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4456 | ASSERT_TRUE(visitor_.header_.get()); |
| 4457 | EXPECT_TRUE(CheckDecryption( |
| 4458 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4459 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4460 | |
| 4461 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
zhongyi | ba6354a | 2019-04-10 16:49:25 -0700 | [diff] [blame] | 4462 | EXPECT_EQ(0x11u, static_cast<unsigned>( |
| 4463 | visitor_.connection_close_frame_.quic_error_code)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4464 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
| 4465 | if (framer_.transport_version() == QUIC_VERSION_99) { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 4466 | EXPECT_EQ(0x1234u, |
| 4467 | visitor_.connection_close_frame_.transport_close_frame_type); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4468 | } |
| 4469 | |
| 4470 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4471 | |
| 4472 | CheckFramingBoundaries(fragments, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 4473 | } |
| 4474 | |
fkastenholz | 04bd4f3 | 2019-04-16 12:24:38 -0700 | [diff] [blame] | 4475 | // Test the CONNECTION_CLOSE/Application variant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4476 | TEST_P(QuicFramerTest, ApplicationCloseFrame) { |
| 4477 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 4478 | // This frame does not exist in versions other than 99. |
| 4479 | return; |
| 4480 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4481 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4482 | |
| 4483 | // clang-format off |
| 4484 | PacketFragments packet99 = { |
| 4485 | // type (short header, 4 byte packet number) |
| 4486 | {"", |
| 4487 | {0x43}}, |
| 4488 | // connection_id |
| 4489 | {"", |
| 4490 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4491 | // packet number |
| 4492 | {"", |
| 4493 | {0x12, 0x34, 0x56, 0x78}}, |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4494 | // frame type (IETF_CONNECTION_CLOSE/Application frame) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4495 | {"", |
| 4496 | {0x1d}}, |
| 4497 | // error code |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4498 | {"Unable to read connection close error code.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4499 | {0x00, 0x11}}, |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4500 | {"Unable to read connection close error details.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4501 | { |
| 4502 | // error details length |
| 4503 | kVarInt62OneByte + 0x0d, |
| 4504 | // error details |
| 4505 | 'b', 'e', 'c', 'a', |
| 4506 | 'u', 's', 'e', ' ', |
| 4507 | 'I', ' ', 'c', 'a', |
| 4508 | 'n'} |
| 4509 | } |
| 4510 | }; |
| 4511 | // clang-format on |
| 4512 | |
| 4513 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4514 | AssemblePacketFromFragments(packet99)); |
| 4515 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4516 | |
| 4517 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4518 | ASSERT_TRUE(visitor_.header_.get()); |
| 4519 | EXPECT_TRUE(CheckDecryption( |
| 4520 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4521 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4522 | |
| 4523 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4524 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4525 | EXPECT_EQ(IETF_QUIC_APPLICATION_CONNECTION_CLOSE, |
| 4526 | visitor_.connection_close_frame_.close_type); |
| 4527 | EXPECT_EQ(122u, visitor_.connection_close_frame_.extracted_error_code); |
| 4528 | EXPECT_EQ(0x11, visitor_.connection_close_frame_.quic_error_code); |
| 4529 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4530 | |
| 4531 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4532 | |
fkastenholz | 04bd4f3 | 2019-04-16 12:24:38 -0700 | [diff] [blame] | 4533 | CheckFramingBoundaries(packet99, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4534 | } |
| 4535 | |
| 4536 | TEST_P(QuicFramerTest, GoAwayFrame) { |
| 4537 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4538 | // This frame is not supported in version 99. |
| 4539 | return; |
| 4540 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4541 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4542 | // clang-format off |
| 4543 | PacketFragments packet = { |
| 4544 | // public flags (8 byte connection_id) |
| 4545 | {"", |
| 4546 | {0x28}}, |
| 4547 | // connection_id |
| 4548 | {"", |
| 4549 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4550 | // packet number |
| 4551 | {"", |
| 4552 | {0x12, 0x34, 0x56, 0x78}}, |
| 4553 | // frame type (go away frame) |
| 4554 | {"", |
| 4555 | {0x03}}, |
| 4556 | // error code |
| 4557 | {"Unable to read go away error code.", |
| 4558 | {0x00, 0x00, 0x00, 0x09}}, |
| 4559 | // stream id |
| 4560 | {"Unable to read last good stream id.", |
| 4561 | {0x01, 0x02, 0x03, 0x04}}, |
| 4562 | // stream id |
| 4563 | {"Unable to read goaway reason.", |
| 4564 | { |
| 4565 | // error details length |
| 4566 | 0x0, 0x0d, |
| 4567 | // error details |
| 4568 | 'b', 'e', 'c', 'a', |
| 4569 | 'u', 's', 'e', ' ', |
| 4570 | 'I', ' ', 'c', 'a', |
| 4571 | 'n'} |
| 4572 | } |
| 4573 | }; |
| 4574 | |
| 4575 | PacketFragments packet44 = { |
| 4576 | // type (short header, 4 byte packet number) |
| 4577 | {"", |
| 4578 | {0x32}}, |
| 4579 | // connection_id |
| 4580 | {"", |
| 4581 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4582 | // packet number |
| 4583 | {"", |
| 4584 | {0x12, 0x34, 0x56, 0x78}}, |
| 4585 | // frame type (go away frame) |
| 4586 | {"", |
| 4587 | {0x03}}, |
| 4588 | // error code |
| 4589 | {"Unable to read go away error code.", |
| 4590 | {0x00, 0x00, 0x00, 0x09}}, |
| 4591 | // stream id |
| 4592 | {"Unable to read last good stream id.", |
| 4593 | {0x01, 0x02, 0x03, 0x04}}, |
| 4594 | // stream id |
| 4595 | {"Unable to read goaway reason.", |
| 4596 | { |
| 4597 | // error details length |
| 4598 | 0x0, 0x0d, |
| 4599 | // error details |
| 4600 | 'b', 'e', 'c', 'a', |
| 4601 | 'u', 's', 'e', ' ', |
| 4602 | 'I', ' ', 'c', 'a', |
| 4603 | 'n'} |
| 4604 | } |
| 4605 | }; |
| 4606 | |
| 4607 | PacketFragments packet46 = { |
| 4608 | // type (short header, 4 byte packet number) |
| 4609 | {"", |
| 4610 | {0x43}}, |
| 4611 | // connection_id |
| 4612 | {"", |
| 4613 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4614 | // packet number |
| 4615 | {"", |
| 4616 | {0x12, 0x34, 0x56, 0x78}}, |
| 4617 | // frame type (go away frame) |
| 4618 | {"", |
| 4619 | {0x03}}, |
| 4620 | // error code |
| 4621 | {"Unable to read go away error code.", |
| 4622 | {0x00, 0x00, 0x00, 0x09}}, |
| 4623 | // stream id |
| 4624 | {"Unable to read last good stream id.", |
| 4625 | {0x01, 0x02, 0x03, 0x04}}, |
| 4626 | // stream id |
| 4627 | {"Unable to read goaway reason.", |
| 4628 | { |
| 4629 | // error details length |
| 4630 | 0x0, 0x0d, |
| 4631 | // error details |
| 4632 | 'b', 'e', 'c', 'a', |
| 4633 | 'u', 's', 'e', ' ', |
| 4634 | 'I', ' ', 'c', 'a', |
| 4635 | 'n'} |
| 4636 | } |
| 4637 | }; |
| 4638 | // clang-format on |
| 4639 | |
| 4640 | PacketFragments& fragments = |
| 4641 | framer_.transport_version() > QUIC_VERSION_44 |
| 4642 | ? packet46 |
| 4643 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 4644 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4645 | AssemblePacketFromFragments(fragments)); |
| 4646 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4647 | |
| 4648 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4649 | ASSERT_TRUE(visitor_.header_.get()); |
| 4650 | EXPECT_TRUE(CheckDecryption( |
| 4651 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4652 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4653 | |
| 4654 | EXPECT_EQ(kStreamId, visitor_.goaway_frame_.last_good_stream_id); |
| 4655 | EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code); |
| 4656 | EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); |
| 4657 | |
| 4658 | CheckFramingBoundaries(fragments, QUIC_INVALID_GOAWAY_DATA); |
| 4659 | } |
| 4660 | |
| 4661 | TEST_P(QuicFramerTest, WindowUpdateFrame) { |
| 4662 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4663 | // This frame is not in version 99, see MaxDataFrame and MaxStreamDataFrame |
| 4664 | // for Version 99 equivalents. |
| 4665 | return; |
| 4666 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4667 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4668 | // clang-format off |
| 4669 | PacketFragments packet = { |
| 4670 | // public flags (8 byte connection_id) |
| 4671 | {"", |
| 4672 | {0x28}}, |
| 4673 | // connection_id |
| 4674 | {"", |
| 4675 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4676 | // packet number |
| 4677 | {"", |
| 4678 | {0x12, 0x34, 0x56, 0x78}}, |
| 4679 | // frame type (window update frame) |
| 4680 | {"", |
| 4681 | {0x04}}, |
| 4682 | // stream id |
| 4683 | {"Unable to read stream_id.", |
| 4684 | {0x01, 0x02, 0x03, 0x04}}, |
| 4685 | // byte offset |
| 4686 | {"Unable to read window byte_offset.", |
| 4687 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4688 | 0x32, 0x10, 0x76, 0x54}}, |
| 4689 | }; |
| 4690 | |
| 4691 | PacketFragments packet44 = { |
| 4692 | // type (short header, 4 byte packet number) |
| 4693 | {"", |
| 4694 | {0x32}}, |
| 4695 | // connection_id |
| 4696 | {"", |
| 4697 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4698 | // packet number |
| 4699 | {"", |
| 4700 | {0x12, 0x34, 0x56, 0x78}}, |
| 4701 | // frame type (window update frame) |
| 4702 | {"", |
| 4703 | {0x04}}, |
| 4704 | // stream id |
| 4705 | {"Unable to read stream_id.", |
| 4706 | {0x01, 0x02, 0x03, 0x04}}, |
| 4707 | // byte offset |
| 4708 | {"Unable to read window byte_offset.", |
| 4709 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4710 | 0x32, 0x10, 0x76, 0x54}}, |
| 4711 | }; |
| 4712 | |
| 4713 | PacketFragments packet46 = { |
| 4714 | // type (short header, 4 byte packet number) |
| 4715 | {"", |
| 4716 | {0x43}}, |
| 4717 | // connection_id |
| 4718 | {"", |
| 4719 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4720 | // packet number |
| 4721 | {"", |
| 4722 | {0x12, 0x34, 0x56, 0x78}}, |
| 4723 | // frame type (window update frame) |
| 4724 | {"", |
| 4725 | {0x04}}, |
| 4726 | // stream id |
| 4727 | {"Unable to read stream_id.", |
| 4728 | {0x01, 0x02, 0x03, 0x04}}, |
| 4729 | // byte offset |
| 4730 | {"Unable to read window byte_offset.", |
| 4731 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4732 | 0x32, 0x10, 0x76, 0x54}}, |
| 4733 | }; |
| 4734 | |
| 4735 | // clang-format on |
| 4736 | |
| 4737 | PacketFragments& fragments = |
| 4738 | framer_.transport_version() > QUIC_VERSION_44 |
| 4739 | ? packet46 |
| 4740 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 4741 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4742 | AssemblePacketFromFragments(fragments)); |
| 4743 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4744 | |
| 4745 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4746 | ASSERT_TRUE(visitor_.header_.get()); |
| 4747 | EXPECT_TRUE(CheckDecryption( |
| 4748 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4749 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4750 | |
| 4751 | EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); |
| 4752 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); |
| 4753 | |
| 4754 | CheckFramingBoundaries(fragments, QUIC_INVALID_WINDOW_UPDATE_DATA); |
| 4755 | } |
| 4756 | |
| 4757 | TEST_P(QuicFramerTest, MaxDataFrame) { |
| 4758 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 4759 | // This frame is available only in version 99. |
| 4760 | return; |
| 4761 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4762 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4763 | // clang-format off |
| 4764 | PacketFragments packet99 = { |
| 4765 | // type (short header, 4 byte packet number) |
| 4766 | {"", |
| 4767 | {0x43}}, |
| 4768 | // connection_id |
| 4769 | {"", |
| 4770 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4771 | // packet number |
| 4772 | {"", |
| 4773 | {0x12, 0x34, 0x56, 0x78}}, |
| 4774 | // frame type (IETF_MAX_DATA frame) |
| 4775 | {"", |
| 4776 | {0x10}}, |
| 4777 | // byte offset |
| 4778 | {"Can not read MAX_DATA byte-offset", |
| 4779 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 4780 | 0x32, 0x10, 0x76, 0x54}}, |
| 4781 | }; |
| 4782 | // clang-format on |
| 4783 | |
| 4784 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4785 | AssemblePacketFromFragments(packet99)); |
| 4786 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4787 | |
| 4788 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4789 | ASSERT_TRUE(visitor_.header_.get()); |
| 4790 | EXPECT_TRUE(CheckDecryption( |
| 4791 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4792 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4793 | |
| 4794 | EXPECT_EQ(QuicUtils::GetInvalidStreamId(framer_.transport_version()), |
| 4795 | visitor_.window_update_frame_.stream_id); |
| 4796 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); |
| 4797 | |
| 4798 | CheckFramingBoundaries(packet99, QUIC_INVALID_MAX_DATA_FRAME_DATA); |
| 4799 | } |
| 4800 | |
| 4801 | TEST_P(QuicFramerTest, MaxStreamDataFrame) { |
| 4802 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 4803 | // This frame available only in version 99. |
| 4804 | return; |
| 4805 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4806 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4807 | // clang-format off |
| 4808 | PacketFragments packet99 = { |
| 4809 | // type (short header, 4 byte packet number) |
| 4810 | {"", |
| 4811 | {0x43}}, |
| 4812 | // connection_id |
| 4813 | {"", |
| 4814 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4815 | // packet number |
| 4816 | {"", |
| 4817 | {0x12, 0x34, 0x56, 0x78}}, |
| 4818 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 4819 | {"", |
| 4820 | {0x11}}, |
| 4821 | // stream id |
| 4822 | {"Can not read MAX_STREAM_DATA stream id", |
| 4823 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 4824 | // byte offset |
| 4825 | {"Can not read MAX_STREAM_DATA byte-count", |
| 4826 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 4827 | 0x32, 0x10, 0x76, 0x54}}, |
| 4828 | }; |
| 4829 | // clang-format on |
| 4830 | |
| 4831 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4832 | AssemblePacketFromFragments(packet99)); |
| 4833 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4834 | |
| 4835 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4836 | ASSERT_TRUE(visitor_.header_.get()); |
| 4837 | EXPECT_TRUE(CheckDecryption( |
| 4838 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4839 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4840 | |
| 4841 | EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); |
| 4842 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); |
| 4843 | |
| 4844 | CheckFramingBoundaries(packet99, QUIC_INVALID_MAX_STREAM_DATA_FRAME_DATA); |
| 4845 | } |
| 4846 | |
| 4847 | TEST_P(QuicFramerTest, BlockedFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4848 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4849 | // clang-format off |
| 4850 | PacketFragments packet = { |
| 4851 | // public flags (8 byte connection_id) |
| 4852 | {"", |
| 4853 | {0x28}}, |
| 4854 | // connection_id |
| 4855 | {"", |
| 4856 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4857 | // packet number |
| 4858 | {"", |
| 4859 | {0x12, 0x34, 0x56, 0x78}}, |
| 4860 | // frame type (blocked frame) |
| 4861 | {"", |
| 4862 | {0x05}}, |
| 4863 | // stream id |
| 4864 | {"Unable to read stream_id.", |
| 4865 | {0x01, 0x02, 0x03, 0x04}}, |
| 4866 | }; |
| 4867 | |
| 4868 | PacketFragments packet44 = { |
| 4869 | // type (short header, 4 byte packet number) |
| 4870 | {"", |
| 4871 | {0x32}}, |
| 4872 | // connection_id |
| 4873 | {"", |
| 4874 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4875 | // packet number |
| 4876 | {"", |
| 4877 | {0x12, 0x34, 0x56, 0x78}}, |
| 4878 | // frame type (blocked frame) |
| 4879 | {"", |
| 4880 | {0x05}}, |
| 4881 | // stream id |
| 4882 | {"Unable to read stream_id.", |
| 4883 | {0x01, 0x02, 0x03, 0x04}}, |
| 4884 | }; |
| 4885 | |
| 4886 | PacketFragments packet46 = { |
| 4887 | // type (short header, 4 byte packet number) |
| 4888 | {"", |
| 4889 | {0x43}}, |
| 4890 | // connection_id |
| 4891 | {"", |
| 4892 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4893 | // packet number |
| 4894 | {"", |
| 4895 | {0x12, 0x34, 0x56, 0x78}}, |
| 4896 | // frame type (blocked frame) |
| 4897 | {"", |
| 4898 | {0x05}}, |
| 4899 | // stream id |
| 4900 | {"Unable to read stream_id.", |
| 4901 | {0x01, 0x02, 0x03, 0x04}}, |
| 4902 | }; |
| 4903 | |
| 4904 | PacketFragments packet99 = { |
| 4905 | // type (short header, 4 byte packet number) |
| 4906 | {"", |
| 4907 | {0x43}}, |
| 4908 | // connection_id |
| 4909 | {"", |
| 4910 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4911 | // packet number |
| 4912 | {"", |
| 4913 | {0x12, 0x34, 0x56, 0x78}}, |
| 4914 | // frame type (IETF_STREAM_BLOCKED frame) |
| 4915 | {"", |
| 4916 | {0x15}}, |
| 4917 | // stream id |
| 4918 | {"Can not read stream blocked stream id.", |
| 4919 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 4920 | // Offset |
| 4921 | {"Can not read stream blocked offset.", |
| 4922 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 4923 | }; |
| 4924 | // clang-format on |
| 4925 | |
| 4926 | PacketFragments& fragments = |
| 4927 | framer_.transport_version() == QUIC_VERSION_99 |
| 4928 | ? packet99 |
| 4929 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 4930 | ? packet46 |
| 4931 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4932 | : packet)); |
| 4933 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4934 | AssemblePacketFromFragments(fragments)); |
| 4935 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4936 | |
| 4937 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4938 | ASSERT_TRUE(visitor_.header_.get()); |
| 4939 | EXPECT_TRUE(CheckDecryption( |
| 4940 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4941 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4942 | |
| 4943 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4944 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 4945 | } else { |
| 4946 | EXPECT_EQ(0u, visitor_.blocked_frame_.offset); |
| 4947 | } |
| 4948 | EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); |
| 4949 | |
| 4950 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4951 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_BLOCKED_DATA); |
| 4952 | } else { |
| 4953 | CheckFramingBoundaries(fragments, QUIC_INVALID_BLOCKED_DATA); |
| 4954 | } |
| 4955 | } |
| 4956 | |
| 4957 | TEST_P(QuicFramerTest, PingFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4958 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4959 | // clang-format off |
| 4960 | unsigned char packet[] = { |
| 4961 | // public flags (8 byte connection_id) |
| 4962 | 0x28, |
| 4963 | // connection_id |
| 4964 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4965 | // packet number |
| 4966 | 0x12, 0x34, 0x56, 0x78, |
| 4967 | |
| 4968 | // frame type (ping frame) |
| 4969 | 0x07, |
| 4970 | }; |
| 4971 | |
| 4972 | unsigned char packet44[] = { |
| 4973 | // type (short header, 4 byte packet number) |
| 4974 | 0x32, |
| 4975 | // connection_id |
| 4976 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4977 | // packet number |
| 4978 | 0x12, 0x34, 0x56, 0x78, |
| 4979 | |
| 4980 | // frame type |
| 4981 | 0x07, |
| 4982 | }; |
| 4983 | |
| 4984 | unsigned char packet46[] = { |
| 4985 | // type (short header, 4 byte packet number) |
| 4986 | 0x43, |
| 4987 | // connection_id |
| 4988 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4989 | // packet number |
| 4990 | 0x12, 0x34, 0x56, 0x78, |
| 4991 | |
| 4992 | // frame type |
| 4993 | 0x07, |
| 4994 | }; |
| 4995 | |
| 4996 | unsigned char packet99[] = { |
| 4997 | // type (short header, 4 byte packet number) |
| 4998 | 0x43, |
| 4999 | // connection_id |
| 5000 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5001 | // packet number |
| 5002 | 0x12, 0x34, 0x56, 0x78, |
| 5003 | |
| 5004 | // frame type (IETF_PING frame) |
| 5005 | 0x01, |
| 5006 | }; |
| 5007 | // clang-format on |
| 5008 | |
| 5009 | QuicEncryptedPacket encrypted( |
| 5010 | AsChars(framer_.transport_version() == QUIC_VERSION_99 |
| 5011 | ? packet99 |
| 5012 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 5013 | ? packet46 |
| 5014 | : framer_.transport_version() > QUIC_VERSION_43 |
| 5015 | ? packet44 |
| 5016 | : packet)), |
| 5017 | framer_.transport_version() == QUIC_VERSION_99 |
| 5018 | ? QUIC_ARRAYSIZE(packet99) |
| 5019 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 5020 | ? QUIC_ARRAYSIZE(packet46) |
| 5021 | : framer_.transport_version() > QUIC_VERSION_43 |
| 5022 | ? QUIC_ARRAYSIZE(packet44) |
| 5023 | : QUIC_ARRAYSIZE(packet)), |
| 5024 | false); |
| 5025 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5026 | |
| 5027 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5028 | ASSERT_TRUE(visitor_.header_.get()); |
| 5029 | EXPECT_TRUE(CheckDecryption( |
| 5030 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5031 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5032 | |
| 5033 | EXPECT_EQ(1u, visitor_.ping_frames_.size()); |
| 5034 | |
| 5035 | // No need to check the PING frame boundaries because it has no payload. |
| 5036 | } |
| 5037 | |
| 5038 | TEST_P(QuicFramerTest, MessageFrame) { |
| 5039 | if (framer_.transport_version() <= QUIC_VERSION_44) { |
| 5040 | return; |
| 5041 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5042 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5043 | // clang-format off |
| 5044 | PacketFragments packet45 = { |
| 5045 | // type (short header, 4 byte packet number) |
| 5046 | {"", |
| 5047 | {0x32}}, |
| 5048 | // connection_id |
| 5049 | {"", |
| 5050 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5051 | // packet number |
| 5052 | {"", |
| 5053 | {0x12, 0x34, 0x56, 0x78}}, |
| 5054 | // message frame type. |
| 5055 | {"", |
| 5056 | { 0x21 }}, |
| 5057 | // message length |
| 5058 | {"Unable to read message length", |
| 5059 | {0x07}}, |
| 5060 | // message data |
| 5061 | {"Unable to read message data", |
| 5062 | {'m', 'e', 's', 's', 'a', 'g', 'e'}}, |
| 5063 | // message frame no length. |
| 5064 | {"", |
| 5065 | { 0x20 }}, |
| 5066 | // message data |
| 5067 | {{}, |
| 5068 | {'m', 'e', 's', 's', 'a', 'g', 'e', '2'}}, |
| 5069 | }; |
| 5070 | |
| 5071 | PacketFragments packet46 = { |
| 5072 | // type (short header, 4 byte packet number) |
| 5073 | {"", |
| 5074 | {0x43}}, |
| 5075 | // connection_id |
| 5076 | {"", |
| 5077 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5078 | // packet number |
| 5079 | {"", |
| 5080 | {0x12, 0x34, 0x56, 0x78}}, |
| 5081 | // message frame type. |
| 5082 | {"", |
| 5083 | { 0x21 }}, |
| 5084 | // message length |
| 5085 | {"Unable to read message length", |
| 5086 | {0x07}}, |
| 5087 | // message data |
| 5088 | {"Unable to read message data", |
| 5089 | {'m', 'e', 's', 's', 'a', 'g', 'e'}}, |
| 5090 | // message frame no length. |
| 5091 | {"", |
| 5092 | { 0x20 }}, |
| 5093 | // message data |
| 5094 | {{}, |
| 5095 | {'m', 'e', 's', 's', 'a', 'g', 'e', '2'}}, |
| 5096 | }; |
| 5097 | // clang-format on |
| 5098 | |
| 5099 | std::unique_ptr<QuicEncryptedPacket> encrypted(AssemblePacketFromFragments( |
| 5100 | framer_.transport_version() > QUIC_VERSION_44 ? packet46 : packet45)); |
| 5101 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5102 | |
| 5103 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5104 | ASSERT_TRUE(visitor_.header_.get()); |
| 5105 | EXPECT_TRUE(CheckDecryption( |
| 5106 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5107 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5108 | |
| 5109 | ASSERT_EQ(2u, visitor_.message_frames_.size()); |
| 5110 | EXPECT_EQ(7u, visitor_.message_frames_[0]->message_length); |
| 5111 | EXPECT_EQ(8u, visitor_.message_frames_[1]->message_length); |
| 5112 | |
| 5113 | CheckFramingBoundaries( |
| 5114 | framer_.transport_version() > QUIC_VERSION_44 ? packet46 : packet45, |
| 5115 | QUIC_INVALID_MESSAGE_DATA); |
| 5116 | } |
| 5117 | |
| 5118 | TEST_P(QuicFramerTest, PublicResetPacketV33) { |
| 5119 | // clang-format off |
| 5120 | PacketFragments packet = { |
| 5121 | // public flags (public reset, 8 byte connection_id) |
| 5122 | {"", |
| 5123 | {0x0A}}, |
| 5124 | // connection_id |
| 5125 | {"", |
| 5126 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5127 | {"Unable to read reset message.", |
| 5128 | { |
| 5129 | // message tag (kPRST) |
| 5130 | 'P', 'R', 'S', 'T', |
| 5131 | // num_entries (2) + padding |
| 5132 | 0x02, 0x00, 0x00, 0x00, |
| 5133 | // tag kRNON |
| 5134 | 'R', 'N', 'O', 'N', |
| 5135 | // end offset 8 |
| 5136 | 0x08, 0x00, 0x00, 0x00, |
| 5137 | // tag kRSEQ |
| 5138 | 'R', 'S', 'E', 'Q', |
| 5139 | // end offset 16 |
| 5140 | 0x10, 0x00, 0x00, 0x00, |
| 5141 | // nonce proof |
| 5142 | 0x89, 0x67, 0x45, 0x23, |
| 5143 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5144 | // rejected packet number |
| 5145 | 0xBC, 0x9A, 0x78, 0x56, |
| 5146 | 0x34, 0x12, 0x00, 0x00, |
| 5147 | } |
| 5148 | } |
| 5149 | }; |
| 5150 | // clang-format on |
| 5151 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5152 | return; |
| 5153 | } |
| 5154 | |
| 5155 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5156 | AssemblePacketFromFragments(packet)); |
| 5157 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5158 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5159 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5160 | EXPECT_EQ(FramerTestConnectionId(), |
| 5161 | visitor_.public_reset_packet_->connection_id); |
| 5162 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5163 | EXPECT_EQ( |
| 5164 | IpAddressFamily::IP_UNSPEC, |
| 5165 | visitor_.public_reset_packet_->client_address.host().address_family()); |
| 5166 | |
| 5167 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5168 | } |
| 5169 | |
| 5170 | TEST_P(QuicFramerTest, PublicResetPacket) { |
| 5171 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5172 | |
| 5173 | // clang-format off |
| 5174 | PacketFragments packet = { |
| 5175 | // public flags (public reset, 8 byte connection_id) |
| 5176 | {"", |
| 5177 | {0x0E}}, |
| 5178 | // connection_id |
| 5179 | {"", |
| 5180 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5181 | {"Unable to read reset message.", |
| 5182 | { |
| 5183 | // message tag (kPRST) |
| 5184 | 'P', 'R', 'S', 'T', |
| 5185 | // num_entries (2) + padding |
| 5186 | 0x02, 0x00, 0x00, 0x00, |
| 5187 | // tag kRNON |
| 5188 | 'R', 'N', 'O', 'N', |
| 5189 | // end offset 8 |
| 5190 | 0x08, 0x00, 0x00, 0x00, |
| 5191 | // tag kRSEQ |
| 5192 | 'R', 'S', 'E', 'Q', |
| 5193 | // end offset 16 |
| 5194 | 0x10, 0x00, 0x00, 0x00, |
| 5195 | // nonce proof |
| 5196 | 0x89, 0x67, 0x45, 0x23, |
| 5197 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5198 | // rejected packet number |
| 5199 | 0xBC, 0x9A, 0x78, 0x56, |
| 5200 | 0x34, 0x12, 0x00, 0x00, |
| 5201 | } |
| 5202 | } |
| 5203 | }; |
| 5204 | // clang-format on |
| 5205 | |
| 5206 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5207 | return; |
| 5208 | } |
| 5209 | |
| 5210 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5211 | AssemblePacketFromFragments(packet)); |
| 5212 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5213 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5214 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5215 | EXPECT_EQ(FramerTestConnectionId(), |
| 5216 | visitor_.public_reset_packet_->connection_id); |
| 5217 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5218 | EXPECT_EQ( |
| 5219 | IpAddressFamily::IP_UNSPEC, |
| 5220 | visitor_.public_reset_packet_->client_address.host().address_family()); |
| 5221 | |
| 5222 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5223 | } |
| 5224 | |
| 5225 | TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) { |
| 5226 | // clang-format off |
| 5227 | unsigned char packet[] = { |
| 5228 | // public flags (public reset, 8 byte connection_id) |
| 5229 | 0x0A, |
| 5230 | // connection_id |
| 5231 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5232 | // message tag (kPRST) |
| 5233 | 'P', 'R', 'S', 'T', |
| 5234 | // num_entries (2) + padding |
| 5235 | 0x02, 0x00, 0x00, 0x00, |
| 5236 | // tag kRNON |
| 5237 | 'R', 'N', 'O', 'N', |
| 5238 | // end offset 8 |
| 5239 | 0x08, 0x00, 0x00, 0x00, |
| 5240 | // tag kRSEQ |
| 5241 | 'R', 'S', 'E', 'Q', |
| 5242 | // end offset 16 |
| 5243 | 0x10, 0x00, 0x00, 0x00, |
| 5244 | // nonce proof |
| 5245 | 0x89, 0x67, 0x45, 0x23, |
| 5246 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5247 | // rejected packet number |
| 5248 | 0xBC, 0x9A, 0x78, 0x56, |
| 5249 | 0x34, 0x12, 0x00, 0x00, |
| 5250 | // trailing junk |
| 5251 | 'j', 'u', 'n', 'k', |
| 5252 | }; |
| 5253 | // clang-format on |
| 5254 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5255 | return; |
| 5256 | } |
| 5257 | |
| 5258 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5259 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 5260 | ASSERT_EQ(QUIC_INVALID_PUBLIC_RST_PACKET, framer_.error()); |
| 5261 | EXPECT_EQ("Unable to read reset message.", framer_.detailed_error()); |
| 5262 | } |
| 5263 | |
| 5264 | TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) { |
| 5265 | // clang-format off |
| 5266 | PacketFragments packet = { |
| 5267 | // public flags (public reset, 8 byte connection_id) |
| 5268 | {"", |
| 5269 | {0x0A}}, |
| 5270 | // connection_id |
| 5271 | {"", |
| 5272 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5273 | {"Unable to read reset message.", |
| 5274 | { |
| 5275 | // message tag (kPRST) |
| 5276 | 'P', 'R', 'S', 'T', |
| 5277 | // num_entries (2) + padding |
| 5278 | 0x03, 0x00, 0x00, 0x00, |
| 5279 | // tag kRNON |
| 5280 | 'R', 'N', 'O', 'N', |
| 5281 | // end offset 8 |
| 5282 | 0x08, 0x00, 0x00, 0x00, |
| 5283 | // tag kRSEQ |
| 5284 | 'R', 'S', 'E', 'Q', |
| 5285 | // end offset 16 |
| 5286 | 0x10, 0x00, 0x00, 0x00, |
| 5287 | // tag kCADR |
| 5288 | 'C', 'A', 'D', 'R', |
| 5289 | // end offset 24 |
| 5290 | 0x18, 0x00, 0x00, 0x00, |
| 5291 | // nonce proof |
| 5292 | 0x89, 0x67, 0x45, 0x23, |
| 5293 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5294 | // rejected packet number |
| 5295 | 0xBC, 0x9A, 0x78, 0x56, |
| 5296 | 0x34, 0x12, 0x00, 0x00, |
| 5297 | // client address: 4.31.198.44:443 |
| 5298 | 0x02, 0x00, |
| 5299 | 0x04, 0x1F, 0xC6, 0x2C, |
| 5300 | 0xBB, 0x01, |
| 5301 | } |
| 5302 | } |
| 5303 | }; |
| 5304 | // clang-format on |
| 5305 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5306 | return; |
| 5307 | } |
| 5308 | |
| 5309 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5310 | AssemblePacketFromFragments(packet)); |
| 5311 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5312 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5313 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5314 | EXPECT_EQ(FramerTestConnectionId(), |
| 5315 | visitor_.public_reset_packet_->connection_id); |
| 5316 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5317 | EXPECT_EQ("4.31.198.44", |
| 5318 | visitor_.public_reset_packet_->client_address.host().ToString()); |
| 5319 | EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); |
| 5320 | |
| 5321 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5322 | } |
| 5323 | |
| 5324 | TEST_P(QuicFramerTest, IetfStatelessResetPacket) { |
| 5325 | // clang-format off |
| 5326 | unsigned char packet[] = { |
| 5327 | // type (short packet, 1 byte packet number) |
| 5328 | 0x50, |
| 5329 | // connection_id |
| 5330 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5331 | // Random bytes |
| 5332 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5333 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5334 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5335 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5336 | // stateless reset token |
| 5337 | 0xB5, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5338 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5339 | }; |
| 5340 | // clang-format on |
| 5341 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 5342 | return; |
| 5343 | } |
| 5344 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5345 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5346 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 5347 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, QuicMakeUnique<NullDecrypter>( |
| 5348 | Perspective::IS_CLIENT)); |
| 5349 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 5350 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 5351 | } else { |
| 5352 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 5353 | QuicMakeUnique<NullDecrypter>(Perspective::IS_CLIENT)); |
| 5354 | framer_.SetAlternativeDecrypter( |
| 5355 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 5356 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5357 | // This packet cannot be decrypted because diversification nonce is missing. |
| 5358 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5359 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5360 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5361 | ASSERT_TRUE(visitor_.stateless_reset_packet_.get()); |
| 5362 | EXPECT_EQ(kTestStatelessResetToken, |
| 5363 | visitor_.stateless_reset_packet_->stateless_reset_token); |
| 5364 | } |
| 5365 | |
| 5366 | TEST_P(QuicFramerTest, IetfStatelessResetPacketInvalidStatelessResetToken) { |
| 5367 | // clang-format off |
| 5368 | unsigned char packet[] = { |
| 5369 | // type (short packet, 1 byte packet number) |
| 5370 | 0x50, |
| 5371 | // connection_id |
| 5372 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5373 | // stateless reset token |
| 5374 | 0xB6, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5375 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5376 | }; |
| 5377 | // clang-format on |
| 5378 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 5379 | return; |
| 5380 | } |
| 5381 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5382 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5383 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 5384 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, QuicMakeUnique<NullDecrypter>( |
| 5385 | Perspective::IS_CLIENT)); |
| 5386 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 5387 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 5388 | } else { |
| 5389 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 5390 | QuicMakeUnique<NullDecrypter>(Perspective::IS_CLIENT)); |
| 5391 | framer_.SetAlternativeDecrypter( |
| 5392 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 5393 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5394 | // This packet cannot be decrypted because diversification nonce is missing. |
| 5395 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5396 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 5397 | EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error()); |
| 5398 | ASSERT_FALSE(visitor_.stateless_reset_packet_); |
| 5399 | } |
| 5400 | |
| 5401 | TEST_P(QuicFramerTest, VersionNegotiationPacket) { |
| 5402 | // clang-format off |
| 5403 | PacketFragments packet = { |
| 5404 | // public flags (version, 8 byte connection_id) |
| 5405 | {"", |
| 5406 | {0x29}}, |
| 5407 | // connection_id |
| 5408 | {"", |
| 5409 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5410 | // version tag |
| 5411 | {"Unable to read supported version in negotiation.", |
| 5412 | {QUIC_VERSION_BYTES, |
| 5413 | 'Q', '2', '.', '0'}}, |
| 5414 | }; |
| 5415 | |
| 5416 | PacketFragments packet44 = { |
| 5417 | // type (long header) |
| 5418 | {"", |
| 5419 | {0x8F}}, |
| 5420 | // version tag |
| 5421 | {"", |
| 5422 | {0x00, 0x00, 0x00, 0x00}}, |
| 5423 | {"", |
| 5424 | {0x05}}, |
| 5425 | // connection_id |
| 5426 | {"", |
| 5427 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5428 | // Supported versions |
| 5429 | {"Unable to read supported version in negotiation.", |
| 5430 | {QUIC_VERSION_BYTES, |
| 5431 | 'Q', '2', '.', '0'}}, |
| 5432 | }; |
| 5433 | // clang-format on |
| 5434 | |
| 5435 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5436 | |
| 5437 | PacketFragments& fragments = |
| 5438 | framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet; |
| 5439 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5440 | AssemblePacketFromFragments(fragments)); |
| 5441 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5442 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5443 | ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); |
| 5444 | EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size()); |
| 5445 | EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); |
| 5446 | |
| 5447 | // Remove the last version from the packet so that every truncated |
| 5448 | // version of the packet is invalid, otherwise checking boundaries |
| 5449 | // is annoyingly complicated. |
| 5450 | for (size_t i = 0; i < 4; ++i) { |
| 5451 | fragments.back().fragment.pop_back(); |
| 5452 | } |
| 5453 | CheckFramingBoundaries(fragments, QUIC_INVALID_VERSION_NEGOTIATION_PACKET); |
| 5454 | } |
| 5455 | |
| 5456 | TEST_P(QuicFramerTest, OldVersionNegotiationPacket) { |
| 5457 | // clang-format off |
| 5458 | PacketFragments packet = { |
| 5459 | // public flags (version, 8 byte connection_id) |
| 5460 | {"", |
| 5461 | {0x2D}}, |
| 5462 | // connection_id |
| 5463 | {"", |
| 5464 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5465 | // version tag |
| 5466 | {"Unable to read supported version in negotiation.", |
| 5467 | {QUIC_VERSION_BYTES, |
| 5468 | 'Q', '2', '.', '0'}}, |
| 5469 | }; |
| 5470 | // clang-format on |
| 5471 | |
| 5472 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5473 | return; |
| 5474 | } |
| 5475 | |
| 5476 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5477 | |
| 5478 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5479 | AssemblePacketFromFragments(packet)); |
| 5480 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5481 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5482 | ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); |
| 5483 | EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size()); |
| 5484 | EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); |
| 5485 | |
| 5486 | // Remove the last version from the packet so that every truncated |
| 5487 | // version of the packet is invalid, otherwise checking boundaries |
| 5488 | // is annoyingly complicated. |
| 5489 | for (size_t i = 0; i < 4; ++i) { |
| 5490 | packet.back().fragment.pop_back(); |
| 5491 | } |
| 5492 | CheckFramingBoundaries(packet, QUIC_INVALID_VERSION_NEGOTIATION_PACKET); |
| 5493 | } |
| 5494 | |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5495 | TEST_P(QuicFramerTest, ParseIetfRetryPacket) { |
| 5496 | if (!framer_.version().SupportsRetry()) { |
| 5497 | return; |
| 5498 | } |
| 5499 | // IETF RETRY is only sent from client to server. |
| 5500 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5501 | // clang-format off |
| 5502 | unsigned char packet[] = { |
| 5503 | // public flags (long header with packet type RETRY and ODCIL=8) |
| 5504 | 0xF5, |
| 5505 | // version |
| 5506 | QUIC_VERSION_BYTES, |
| 5507 | // connection ID lengths |
| 5508 | 0x05, |
| 5509 | // source connection ID |
| 5510 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 5511 | // original destination connection ID |
| 5512 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5513 | // retry token |
| 5514 | 'H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'i', 's', |
| 5515 | ' ', 'i', 's', ' ', 'R', 'E', 'T', 'R', 'Y', '!', |
| 5516 | }; |
| 5517 | // clang-format on |
| 5518 | |
| 5519 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5520 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5521 | |
| 5522 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5523 | ASSERT_TRUE(visitor_.header_.get()); |
| 5524 | |
| 5525 | ASSERT_TRUE(visitor_.retry_original_connection_id_.get()); |
| 5526 | ASSERT_TRUE(visitor_.retry_new_connection_id_.get()); |
| 5527 | ASSERT_TRUE(visitor_.retry_token_.get()); |
| 5528 | |
| 5529 | EXPECT_EQ(FramerTestConnectionId(), |
| 5530 | *visitor_.retry_original_connection_id_.get()); |
| 5531 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), |
| 5532 | *visitor_.retry_new_connection_id_.get()); |
| 5533 | EXPECT_EQ("Hello this is RETRY!", *visitor_.retry_token_.get()); |
| 5534 | } |
| 5535 | |
| 5536 | TEST_P(QuicFramerTest, RejectIetfRetryPacketAsServer) { |
| 5537 | if (!framer_.version().SupportsRetry()) { |
| 5538 | return; |
| 5539 | } |
| 5540 | // IETF RETRY is only sent from client to server. |
| 5541 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 5542 | // clang-format off |
| 5543 | unsigned char packet[] = { |
| 5544 | // public flags (long header with packet type RETRY and ODCIL=8) |
| 5545 | 0xF5, |
| 5546 | // version |
| 5547 | QUIC_VERSION_BYTES, |
| 5548 | // connection ID lengths |
| 5549 | 0x05, |
| 5550 | // source connection ID |
| 5551 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 5552 | // original destination connection ID |
| 5553 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5554 | // retry token |
| 5555 | 'H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'i', 's', |
| 5556 | ' ', 'i', 's', ' ', 'R', 'E', 'T', 'R', 'Y', '!', |
| 5557 | }; |
| 5558 | // clang-format on |
| 5559 | |
| 5560 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5561 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 5562 | |
| 5563 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
| 5564 | EXPECT_EQ("Client-initiated RETRY is invalid.", framer_.detailed_error()); |
| 5565 | } |
| 5566 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5567 | TEST_P(QuicFramerTest, BuildPaddingFramePacket) { |
| 5568 | QuicPacketHeader header; |
| 5569 | header.destination_connection_id = FramerTestConnectionId(); |
| 5570 | header.reset_flag = false; |
| 5571 | header.version_flag = false; |
| 5572 | header.packet_number = kPacketNumber; |
| 5573 | |
| 5574 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5575 | |
| 5576 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5577 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5578 | // public flags (8 byte connection_id) |
| 5579 | 0x28, |
| 5580 | // connection_id |
| 5581 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5582 | // packet number |
| 5583 | 0x12, 0x34, 0x56, 0x78, |
| 5584 | |
| 5585 | // frame type (padding frame) |
| 5586 | 0x00, |
| 5587 | 0x00, 0x00, 0x00, 0x00 |
| 5588 | }; |
| 5589 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5590 | unsigned char packet44[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5591 | // type (short header, 4 byte packet number) |
| 5592 | 0x32, |
| 5593 | // connection_id |
| 5594 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5595 | // packet number |
| 5596 | 0x12, 0x34, 0x56, 0x78, |
| 5597 | |
| 5598 | // frame type (padding frame) |
| 5599 | 0x00, |
| 5600 | 0x00, 0x00, 0x00, 0x00 |
| 5601 | }; |
| 5602 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5603 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5604 | // type (short header, 4 byte packet number) |
| 5605 | 0x43, |
| 5606 | // connection_id |
| 5607 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5608 | // packet number |
| 5609 | 0x12, 0x34, 0x56, 0x78, |
| 5610 | |
| 5611 | // frame type (padding frame) |
| 5612 | 0x00, |
| 5613 | 0x00, 0x00, 0x00, 0x00 |
| 5614 | }; |
| 5615 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5616 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5617 | // type (short header, 4 byte packet number) |
| 5618 | 0x43, |
| 5619 | // connection_id |
| 5620 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5621 | // packet number |
| 5622 | 0x12, 0x34, 0x56, 0x78, |
| 5623 | |
| 5624 | // frame type (padding frame) |
| 5625 | 0x00, |
| 5626 | 0x00, 0x00, 0x00, 0x00 |
| 5627 | }; |
| 5628 | // clang-format on |
| 5629 | |
| 5630 | unsigned char* p = packet; |
| 5631 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5632 | p = packet99; |
| 5633 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 5634 | p = packet46; |
| 5635 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5636 | p = packet44; |
| 5637 | } |
| 5638 | |
| 5639 | uint64_t header_size = GetPacketHeaderSize( |
| 5640 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 5641 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 5642 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 5643 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5644 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5645 | |
| 5646 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5647 | ASSERT_TRUE(data != nullptr); |
| 5648 | |
| 5649 | test::CompareCharArraysWithHexError( |
| 5650 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 5651 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 5652 | : QUIC_ARRAYSIZE(packet)); |
| 5653 | } |
| 5654 | |
| 5655 | TEST_P(QuicFramerTest, BuildStreamFramePacketWithNewPaddingFrame) { |
| 5656 | QuicPacketHeader header; |
| 5657 | header.destination_connection_id = FramerTestConnectionId(); |
| 5658 | header.reset_flag = false; |
| 5659 | header.version_flag = false; |
| 5660 | header.packet_number = kPacketNumber; |
| 5661 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
| 5662 | QuicStringPiece("hello world!")); |
| 5663 | QuicPaddingFrame padding_frame(2); |
| 5664 | QuicFrames frames = {QuicFrame(padding_frame), QuicFrame(stream_frame), |
| 5665 | QuicFrame(padding_frame)}; |
| 5666 | |
| 5667 | // clang-format off |
| 5668 | unsigned char packet[] = { |
| 5669 | // public flags (8 byte connection_id) |
| 5670 | 0x28, |
| 5671 | // connection_id |
| 5672 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5673 | // packet number |
| 5674 | 0x12, 0x34, 0x56, 0x78, |
| 5675 | |
| 5676 | // paddings |
| 5677 | 0x00, 0x00, |
| 5678 | // frame type (stream frame with fin) |
| 5679 | 0xFF, |
| 5680 | // stream id |
| 5681 | 0x01, 0x02, 0x03, 0x04, |
| 5682 | // offset |
| 5683 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5684 | 0x32, 0x10, 0x76, 0x54, |
| 5685 | // data length |
| 5686 | 0x00, 0x0c, |
| 5687 | // data |
| 5688 | 'h', 'e', 'l', 'l', |
| 5689 | 'o', ' ', 'w', 'o', |
| 5690 | 'r', 'l', 'd', '!', |
| 5691 | // paddings |
| 5692 | 0x00, 0x00, |
| 5693 | }; |
| 5694 | |
| 5695 | unsigned char packet44[] = { |
| 5696 | // type (short header, 4 byte packet number) |
| 5697 | 0x32, |
| 5698 | // connection_id |
| 5699 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5700 | // packet number |
| 5701 | 0x12, 0x34, 0x56, 0x78, |
| 5702 | |
| 5703 | // paddings |
| 5704 | 0x00, 0x00, |
| 5705 | // frame type (stream frame with fin) |
| 5706 | 0xFF, |
| 5707 | // stream id |
| 5708 | 0x01, 0x02, 0x03, 0x04, |
| 5709 | // offset |
| 5710 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5711 | 0x32, 0x10, 0x76, 0x54, |
| 5712 | // data length |
| 5713 | 0x00, 0x0c, |
| 5714 | // data |
| 5715 | 'h', 'e', 'l', 'l', |
| 5716 | 'o', ' ', 'w', 'o', |
| 5717 | 'r', 'l', 'd', '!', |
| 5718 | // paddings |
| 5719 | 0x00, 0x00, |
| 5720 | }; |
| 5721 | |
| 5722 | unsigned char packet46[] = { |
| 5723 | // type (short header, 4 byte packet number) |
| 5724 | 0x43, |
| 5725 | // connection_id |
| 5726 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5727 | // packet number |
| 5728 | 0x12, 0x34, 0x56, 0x78, |
| 5729 | |
| 5730 | // paddings |
| 5731 | 0x00, 0x00, |
| 5732 | // frame type (stream frame with fin) |
| 5733 | 0xFF, |
| 5734 | // stream id |
| 5735 | 0x01, 0x02, 0x03, 0x04, |
| 5736 | // offset |
| 5737 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5738 | 0x32, 0x10, 0x76, 0x54, |
| 5739 | // data length |
| 5740 | 0x00, 0x0c, |
| 5741 | // data |
| 5742 | 'h', 'e', 'l', 'l', |
| 5743 | 'o', ' ', 'w', 'o', |
| 5744 | 'r', 'l', 'd', '!', |
| 5745 | // paddings |
| 5746 | 0x00, 0x00, |
| 5747 | }; |
| 5748 | |
| 5749 | unsigned char packet99[] = { |
| 5750 | // type (short header, 4 byte packet number) |
| 5751 | 0x43, |
| 5752 | // connection_id |
| 5753 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5754 | // packet number |
| 5755 | 0x12, 0x34, 0x56, 0x78, |
| 5756 | |
| 5757 | // paddings |
| 5758 | 0x00, 0x00, |
| 5759 | // frame type (IETF_STREAM with FIN, LEN, and OFFSET bits set) |
| 5760 | 0x08 | 0x01 | 0x02 | 0x04, |
| 5761 | // stream id |
| 5762 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 5763 | // offset |
| 5764 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 5765 | 0x32, 0x10, 0x76, 0x54, |
| 5766 | // data length |
| 5767 | kVarInt62OneByte + 0x0c, |
| 5768 | // data |
| 5769 | 'h', 'e', 'l', 'l', |
| 5770 | 'o', ' ', 'w', 'o', |
| 5771 | 'r', 'l', 'd', '!', |
| 5772 | // paddings |
| 5773 | 0x00, 0x00, |
| 5774 | }; |
| 5775 | // clang-format on |
| 5776 | |
| 5777 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5778 | ASSERT_TRUE(data != nullptr); |
| 5779 | |
| 5780 | unsigned char* p = packet; |
| 5781 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 5782 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5783 | p = packet99; |
| 5784 | p_size = QUIC_ARRAYSIZE(packet99); |
| 5785 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 5786 | p = packet46; |
| 5787 | p_size = QUIC_ARRAYSIZE(packet46); |
| 5788 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5789 | p = packet44; |
| 5790 | p_size = QUIC_ARRAYSIZE(packet44); |
| 5791 | } |
| 5792 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 5793 | |
| 5794 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 5795 | data->length(), AsChars(p), p_size); |
| 5796 | } |
| 5797 | |
| 5798 | TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) { |
| 5799 | QuicPacketHeader header; |
| 5800 | header.destination_connection_id = FramerTestConnectionId(); |
| 5801 | header.reset_flag = false; |
| 5802 | header.version_flag = false; |
| 5803 | header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; |
| 5804 | header.packet_number = kPacketNumber; |
| 5805 | |
| 5806 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5807 | |
| 5808 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5809 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5810 | // public flags (8 byte connection_id and 4 byte packet number) |
| 5811 | 0x28, |
| 5812 | // connection_id |
| 5813 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5814 | // packet number |
| 5815 | 0x12, 0x34, 0x56, 0x78, |
| 5816 | |
| 5817 | // frame type (padding frame) |
| 5818 | 0x00, |
| 5819 | 0x00, 0x00, 0x00, 0x00 |
| 5820 | }; |
| 5821 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5822 | unsigned char packet44[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5823 | // type (short header, 4 byte packet number) |
| 5824 | 0x32, |
| 5825 | // connection_id |
| 5826 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5827 | // packet number |
| 5828 | 0x12, 0x34, 0x56, 0x78, |
| 5829 | |
| 5830 | // frame type (padding frame) |
| 5831 | 0x00, |
| 5832 | 0x00, 0x00, 0x00, 0x00 |
| 5833 | }; |
| 5834 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5835 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5836 | // type (short header, 4 byte packet number) |
| 5837 | 0x43, |
| 5838 | // connection_id |
| 5839 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5840 | // packet number |
| 5841 | 0x12, 0x34, 0x56, 0x78, |
| 5842 | |
| 5843 | // frame type (padding frame) |
| 5844 | 0x00, |
| 5845 | 0x00, 0x00, 0x00, 0x00 |
| 5846 | }; |
| 5847 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5848 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5849 | // type (short header, 4 byte packet number) |
| 5850 | 0x43, |
| 5851 | // connection_id |
| 5852 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5853 | // packet number |
| 5854 | 0x12, 0x34, 0x56, 0x78, |
| 5855 | |
| 5856 | // frame type (padding frame) |
| 5857 | 0x00, |
| 5858 | 0x00, 0x00, 0x00, 0x00 |
| 5859 | }; |
| 5860 | // clang-format on |
| 5861 | |
| 5862 | unsigned char* p = packet; |
| 5863 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5864 | p = packet99; |
| 5865 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 5866 | p = packet46; |
| 5867 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5868 | p = packet44; |
| 5869 | } |
| 5870 | |
| 5871 | uint64_t header_size = GetPacketHeaderSize( |
| 5872 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 5873 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 5874 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 5875 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5876 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5877 | |
| 5878 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5879 | ASSERT_TRUE(data != nullptr); |
| 5880 | |
| 5881 | test::CompareCharArraysWithHexError( |
| 5882 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 5883 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 5884 | : QUIC_ARRAYSIZE(packet)); |
| 5885 | } |
| 5886 | |
| 5887 | TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) { |
| 5888 | QuicPacketHeader header; |
| 5889 | header.destination_connection_id = FramerTestConnectionId(); |
| 5890 | header.reset_flag = false; |
| 5891 | header.version_flag = false; |
| 5892 | header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; |
| 5893 | header.packet_number = kPacketNumber; |
| 5894 | |
| 5895 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5896 | |
| 5897 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5898 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5899 | // public flags (8 byte connection_id and 2 byte packet number) |
| 5900 | 0x18, |
| 5901 | // connection_id |
| 5902 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5903 | // packet number |
| 5904 | 0x56, 0x78, |
| 5905 | |
| 5906 | // frame type (padding frame) |
| 5907 | 0x00, |
| 5908 | 0x00, 0x00, 0x00, 0x00 |
| 5909 | }; |
| 5910 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5911 | unsigned char packet44[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5912 | // type (short header, 2 byte packet number) |
| 5913 | 0x31, |
| 5914 | // connection_id |
| 5915 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5916 | // packet number |
| 5917 | 0x56, 0x78, |
| 5918 | |
| 5919 | // frame type (padding frame) |
| 5920 | 0x00, |
| 5921 | 0x00, 0x00, 0x00, 0x00 |
| 5922 | }; |
| 5923 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5924 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5925 | // type (short header, 2 byte packet number) |
| 5926 | 0x41, |
| 5927 | // connection_id |
| 5928 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5929 | // packet number |
| 5930 | 0x56, 0x78, |
| 5931 | |
| 5932 | // frame type (padding frame) |
| 5933 | 0x00, |
| 5934 | 0x00, 0x00, 0x00, 0x00 |
| 5935 | }; |
| 5936 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5937 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5938 | // type (short header, 2 byte packet number) |
| 5939 | 0x41, |
| 5940 | // connection_id |
| 5941 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5942 | // packet number |
| 5943 | 0x56, 0x78, |
| 5944 | |
| 5945 | // frame type (padding frame) |
| 5946 | 0x00, |
| 5947 | 0x00, 0x00, 0x00, 0x00 |
| 5948 | }; |
| 5949 | // clang-format on |
| 5950 | |
| 5951 | unsigned char* p = packet; |
| 5952 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5953 | p = packet99; |
| 5954 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 5955 | p = packet46; |
| 5956 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5957 | p = packet44; |
| 5958 | } |
| 5959 | |
| 5960 | uint64_t header_size = GetPacketHeaderSize( |
| 5961 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 5962 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 5963 | !kIncludeDiversificationNonce, PACKET_2BYTE_PACKET_NUMBER, |
| 5964 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5965 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5966 | |
| 5967 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5968 | ASSERT_TRUE(data != nullptr); |
| 5969 | |
| 5970 | test::CompareCharArraysWithHexError( |
| 5971 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 5972 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 5973 | : QUIC_ARRAYSIZE(packet)); |
| 5974 | } |
| 5975 | |
| 5976 | TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) { |
| 5977 | QuicPacketHeader header; |
| 5978 | header.destination_connection_id = FramerTestConnectionId(); |
| 5979 | header.reset_flag = false; |
| 5980 | header.version_flag = false; |
| 5981 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 5982 | header.packet_number = kPacketNumber; |
| 5983 | |
| 5984 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5985 | |
| 5986 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5987 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5988 | // public flags (8 byte connection_id and 1 byte packet number) |
| 5989 | 0x08, |
| 5990 | // connection_id |
| 5991 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5992 | // packet number |
| 5993 | 0x78, |
| 5994 | |
| 5995 | // frame type (padding frame) |
| 5996 | 0x00, |
| 5997 | 0x00, 0x00, 0x00, 0x00 |
| 5998 | }; |
| 5999 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6000 | unsigned char packet44[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6001 | // type (short header, 1 byte packet number) |
| 6002 | 0x30, |
| 6003 | // connection_id |
| 6004 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6005 | // packet number |
| 6006 | 0x78, |
| 6007 | |
| 6008 | // frame type (padding frame) |
| 6009 | 0x00, |
| 6010 | 0x00, 0x00, 0x00, 0x00 |
| 6011 | }; |
| 6012 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6013 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6014 | // type (short header, 1 byte packet number) |
| 6015 | 0x40, |
| 6016 | // connection_id |
| 6017 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6018 | // packet number |
| 6019 | 0x78, |
| 6020 | |
| 6021 | // frame type (padding frame) |
| 6022 | 0x00, |
| 6023 | 0x00, 0x00, 0x00, 0x00 |
| 6024 | }; |
| 6025 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6026 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6027 | // type (short header, 1 byte packet number) |
| 6028 | 0x40, |
| 6029 | // connection_id |
| 6030 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6031 | // packet number |
| 6032 | 0x78, |
| 6033 | |
| 6034 | // frame type (padding frame) |
| 6035 | 0x00, |
| 6036 | 0x00, 0x00, 0x00, 0x00 |
| 6037 | }; |
| 6038 | // clang-format on |
| 6039 | |
| 6040 | unsigned char* p = packet; |
| 6041 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6042 | p = packet99; |
| 6043 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6044 | p = packet46; |
| 6045 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6046 | p = packet44; |
| 6047 | } |
| 6048 | |
| 6049 | uint64_t header_size = GetPacketHeaderSize( |
| 6050 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 6051 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 6052 | !kIncludeDiversificationNonce, PACKET_1BYTE_PACKET_NUMBER, |
| 6053 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6054 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6055 | |
| 6056 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6057 | ASSERT_TRUE(data != nullptr); |
| 6058 | |
| 6059 | test::CompareCharArraysWithHexError( |
| 6060 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 6061 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 6062 | : QUIC_ARRAYSIZE(packet)); |
| 6063 | } |
| 6064 | |
| 6065 | TEST_P(QuicFramerTest, BuildStreamFramePacket) { |
| 6066 | QuicPacketHeader header; |
| 6067 | header.destination_connection_id = FramerTestConnectionId(); |
| 6068 | header.reset_flag = false; |
| 6069 | header.version_flag = false; |
| 6070 | header.packet_number = kPacketNumber; |
| 6071 | if (QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 6072 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 6073 | } |
| 6074 | |
| 6075 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
| 6076 | QuicStringPiece("hello world!")); |
| 6077 | |
| 6078 | QuicFrames frames = {QuicFrame(stream_frame)}; |
| 6079 | |
| 6080 | // clang-format off |
| 6081 | unsigned char packet[] = { |
| 6082 | // public flags (8 byte connection_id) |
| 6083 | 0x28, |
| 6084 | // connection_id |
| 6085 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6086 | // packet number |
| 6087 | 0x12, 0x34, 0x56, 0x78, |
| 6088 | |
| 6089 | // frame type (stream frame with fin and no length) |
| 6090 | 0xDF, |
| 6091 | // stream id |
| 6092 | 0x01, 0x02, 0x03, 0x04, |
| 6093 | // offset |
| 6094 | 0x3A, 0x98, 0xFE, 0xDC, |
| 6095 | 0x32, 0x10, 0x76, 0x54, |
| 6096 | // data |
| 6097 | 'h', 'e', 'l', 'l', |
| 6098 | 'o', ' ', 'w', 'o', |
| 6099 | 'r', 'l', 'd', '!', |
| 6100 | }; |
| 6101 | |
| 6102 | unsigned char packet44[] = { |
| 6103 | // type (short header, 4 byte packet number) |
| 6104 | 0x32, |
| 6105 | // connection_id |
| 6106 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6107 | // packet number |
| 6108 | 0x12, 0x34, 0x56, 0x78, |
| 6109 | |
| 6110 | // frame type (stream frame with fin and no length) |
| 6111 | 0xDF, |
| 6112 | // stream id |
| 6113 | 0x01, 0x02, 0x03, 0x04, |
| 6114 | // offset |
| 6115 | 0x3A, 0x98, 0xFE, 0xDC, |
| 6116 | 0x32, 0x10, 0x76, 0x54, |
| 6117 | // data |
| 6118 | 'h', 'e', 'l', 'l', |
| 6119 | 'o', ' ', 'w', 'o', |
| 6120 | 'r', 'l', 'd', '!', |
| 6121 | }; |
| 6122 | |
| 6123 | unsigned char packet46[] = { |
| 6124 | // type (short header, 4 byte packet number) |
| 6125 | 0x43, |
| 6126 | // connection_id |
| 6127 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6128 | // packet number |
| 6129 | 0x12, 0x34, 0x56, 0x78, |
| 6130 | |
| 6131 | // frame type (stream frame with fin and no length) |
| 6132 | 0xDF, |
| 6133 | // stream id |
| 6134 | 0x01, 0x02, 0x03, 0x04, |
| 6135 | // offset |
| 6136 | 0x3A, 0x98, 0xFE, 0xDC, |
| 6137 | 0x32, 0x10, 0x76, 0x54, |
| 6138 | // data |
| 6139 | 'h', 'e', 'l', 'l', |
| 6140 | 'o', ' ', 'w', 'o', |
| 6141 | 'r', 'l', 'd', '!', |
| 6142 | }; |
| 6143 | |
| 6144 | unsigned char packet99[] = { |
| 6145 | // type (short header, 4 byte packet number) |
| 6146 | 0x43, |
| 6147 | // connection_id |
| 6148 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6149 | // packet number |
| 6150 | 0x12, 0x34, 0x56, 0x78, |
| 6151 | |
| 6152 | // frame type (IETF_STREAM frame with FIN and OFFSET, no length) |
| 6153 | 0x08 | 0x01 | 0x04, |
| 6154 | // stream id |
| 6155 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 6156 | // offset |
| 6157 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6158 | 0x32, 0x10, 0x76, 0x54, |
| 6159 | // data |
| 6160 | 'h', 'e', 'l', 'l', |
| 6161 | 'o', ' ', 'w', 'o', |
| 6162 | 'r', 'l', 'd', '!', |
| 6163 | }; |
| 6164 | // clang-format on |
| 6165 | |
| 6166 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6167 | ASSERT_TRUE(data != nullptr); |
| 6168 | |
| 6169 | unsigned char* p = packet; |
| 6170 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6171 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6172 | p = packet99; |
| 6173 | p_size = QUIC_ARRAYSIZE(packet99); |
| 6174 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6175 | p = packet46; |
| 6176 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6177 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6178 | p = packet44; |
| 6179 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6180 | } |
| 6181 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6182 | data->length(), AsChars(p), p_size); |
| 6183 | } |
| 6184 | |
| 6185 | TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) { |
| 6186 | QuicPacketHeader header; |
| 6187 | header.destination_connection_id = FramerTestConnectionId(); |
| 6188 | header.reset_flag = false; |
| 6189 | header.version_flag = true; |
| 6190 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6191 | header.long_packet_type = ZERO_RTT_PROTECTED; |
| 6192 | } |
| 6193 | header.packet_number = kPacketNumber; |
| 6194 | if (QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 6195 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 6196 | } |
| 6197 | |
| 6198 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
| 6199 | QuicStringPiece("hello world!")); |
| 6200 | QuicFrames frames = {QuicFrame(stream_frame)}; |
| 6201 | |
| 6202 | // clang-format off |
| 6203 | unsigned char packet[] = { |
| 6204 | // public flags (version, 8 byte connection_id) |
| 6205 | 0x2D, |
| 6206 | // connection_id |
| 6207 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6208 | // version tag |
| 6209 | QUIC_VERSION_BYTES, |
| 6210 | // packet number |
| 6211 | 0x12, 0x34, 0x56, 0x78, |
| 6212 | |
| 6213 | // frame type (stream frame with fin and no length) |
| 6214 | 0xDF, |
| 6215 | // stream id |
| 6216 | 0x01, 0x02, 0x03, 0x04, |
| 6217 | // offset |
| 6218 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6219 | // data |
| 6220 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6221 | }; |
| 6222 | |
| 6223 | unsigned char packet44[] = { |
| 6224 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6225 | 0xFC, |
| 6226 | // version tag |
| 6227 | QUIC_VERSION_BYTES, |
| 6228 | // connection_id length |
| 6229 | 0x50, |
| 6230 | // connection_id |
| 6231 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6232 | // packet number |
| 6233 | 0x12, 0x34, 0x56, 0x78, |
| 6234 | |
| 6235 | // frame type (stream frame with fin and no length) |
| 6236 | 0xDF, |
| 6237 | // stream id |
| 6238 | 0x01, 0x02, 0x03, 0x04, |
| 6239 | // offset |
| 6240 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6241 | // data |
| 6242 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6243 | }; |
| 6244 | |
| 6245 | unsigned char packet46[] = { |
| 6246 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6247 | 0xD3, |
| 6248 | // version tag |
| 6249 | QUIC_VERSION_BYTES, |
| 6250 | // connection_id length |
| 6251 | 0x50, |
| 6252 | // connection_id |
| 6253 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6254 | // packet number |
| 6255 | 0x12, 0x34, 0x56, 0x78, |
| 6256 | |
| 6257 | // frame type (stream frame with fin and no length) |
| 6258 | 0xDF, |
| 6259 | // stream id |
| 6260 | 0x01, 0x02, 0x03, 0x04, |
| 6261 | // offset |
| 6262 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6263 | // data |
| 6264 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6265 | }; |
| 6266 | |
| 6267 | unsigned char packet99[] = { |
| 6268 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6269 | 0xD3, |
| 6270 | // version tag |
| 6271 | QUIC_VERSION_BYTES, |
| 6272 | // connection_id length |
| 6273 | 0x50, |
| 6274 | // connection_id |
| 6275 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6276 | // length |
| 6277 | 0x40, 0x1D, |
| 6278 | // packet number |
| 6279 | 0x12, 0x34, 0x56, 0x78, |
| 6280 | |
| 6281 | // frame type (IETF_STREAM frame with fin and offset, no length) |
| 6282 | 0x08 | 0x01 | 0x04, |
| 6283 | // stream id |
| 6284 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 6285 | // offset |
| 6286 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6287 | // data |
| 6288 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6289 | }; |
| 6290 | // clang-format on |
| 6291 | |
| 6292 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 6293 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6294 | ASSERT_TRUE(data != nullptr); |
| 6295 | |
| 6296 | unsigned char* p = packet; |
| 6297 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6298 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6299 | p = packet99; |
| 6300 | p_size = QUIC_ARRAYSIZE(packet99); |
| 6301 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6302 | p = packet46; |
| 6303 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6304 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6305 | p = packet44; |
| 6306 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6307 | } |
| 6308 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6309 | data->length(), AsChars(p), p_size); |
| 6310 | } |
| 6311 | |
| 6312 | TEST_P(QuicFramerTest, BuildCryptoFramePacket) { |
| 6313 | if (framer_.transport_version() < QUIC_VERSION_99) { |
| 6314 | // CRYPTO frames aren't supported prior to v46. |
| 6315 | return; |
| 6316 | } |
| 6317 | QuicPacketHeader header; |
| 6318 | header.destination_connection_id = FramerTestConnectionId(); |
| 6319 | header.reset_flag = false; |
| 6320 | header.version_flag = false; |
| 6321 | header.packet_number = kPacketNumber; |
| 6322 | |
| 6323 | SimpleDataProducer data_producer; |
| 6324 | framer_.set_data_producer(&data_producer); |
| 6325 | |
| 6326 | QuicStringPiece crypto_frame_contents("hello world!"); |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 6327 | QuicCryptoFrame crypto_frame(ENCRYPTION_INITIAL, kStreamOffset, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6328 | crypto_frame_contents.length()); |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 6329 | data_producer.SaveCryptoData(ENCRYPTION_INITIAL, kStreamOffset, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6330 | crypto_frame_contents); |
| 6331 | |
| 6332 | QuicFrames frames = {QuicFrame(&crypto_frame)}; |
| 6333 | |
| 6334 | // clang-format off |
| 6335 | unsigned char packet[] = { |
| 6336 | // type (short header, 4 byte packet number) |
| 6337 | 0x43, |
| 6338 | // connection_id |
| 6339 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6340 | // packet number |
| 6341 | 0x12, 0x34, 0x56, 0x78, |
| 6342 | |
| 6343 | // frame type (IETF_CRYPTO frame) |
| 6344 | 0x06, |
| 6345 | // offset |
| 6346 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6347 | 0x32, 0x10, 0x76, 0x54, |
| 6348 | // length |
| 6349 | kVarInt62OneByte + 12, |
| 6350 | // data |
| 6351 | 'h', 'e', 'l', 'l', |
| 6352 | 'o', ' ', 'w', 'o', |
| 6353 | 'r', 'l', 'd', '!', |
| 6354 | }; |
| 6355 | // clang-format on |
| 6356 | |
| 6357 | size_t packet_size = QUIC_ARRAYSIZE(packet); |
| 6358 | |
| 6359 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6360 | ASSERT_TRUE(data != nullptr); |
| 6361 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6362 | data->length(), AsChars(packet), |
| 6363 | packet_size); |
| 6364 | } |
| 6365 | |
| 6366 | TEST_P(QuicFramerTest, CryptoFrame) { |
| 6367 | if (framer_.transport_version() < QUIC_VERSION_99) { |
| 6368 | // CRYPTO frames aren't supported prior to v46. |
| 6369 | return; |
| 6370 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 6371 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6372 | |
| 6373 | // clang-format off |
| 6374 | PacketFragments packet = { |
| 6375 | // type (short header, 4 byte packet number) |
| 6376 | {"", |
| 6377 | {0x43}}, |
| 6378 | // connection_id |
| 6379 | {"", |
| 6380 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 6381 | // packet number |
| 6382 | {"", |
| 6383 | {0x12, 0x34, 0x56, 0x78}}, |
| 6384 | // frame type (IETF_CRYPTO frame) |
| 6385 | {"", |
| 6386 | {0x06}}, |
| 6387 | // offset |
| 6388 | {"", |
| 6389 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6390 | 0x32, 0x10, 0x76, 0x54}}, |
| 6391 | // data length |
| 6392 | {"Invalid data length.", |
| 6393 | {kVarInt62OneByte + 12}}, |
| 6394 | // data |
| 6395 | {"Unable to read frame data.", |
| 6396 | {'h', 'e', 'l', 'l', |
| 6397 | 'o', ' ', 'w', 'o', |
| 6398 | 'r', 'l', 'd', '!'}}, |
| 6399 | }; |
| 6400 | // clang-format on |
| 6401 | |
| 6402 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 6403 | AssemblePacketFromFragments(packet)); |
| 6404 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 6405 | |
| 6406 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 6407 | ASSERT_TRUE(visitor_.header_.get()); |
| 6408 | EXPECT_TRUE(CheckDecryption( |
| 6409 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 6410 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 6411 | ASSERT_EQ(1u, visitor_.crypto_frames_.size()); |
| 6412 | QuicCryptoFrame* frame = visitor_.crypto_frames_[0].get(); |
| 6413 | EXPECT_EQ(kStreamOffset, frame->offset); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 6414 | EXPECT_EQ("hello world!", |
| 6415 | std::string(frame->data_buffer, frame->data_length)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6416 | |
| 6417 | CheckFramingBoundaries(packet, QUIC_INVALID_FRAME_DATA); |
| 6418 | } |
| 6419 | |
| 6420 | TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { |
| 6421 | // clang-format off |
| 6422 | unsigned char packet[] = { |
| 6423 | // public flags (version, 8 byte connection_id) |
| 6424 | 0x0D, |
| 6425 | // connection_id |
| 6426 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6427 | // version tag |
| 6428 | QUIC_VERSION_BYTES, |
| 6429 | }; |
| 6430 | unsigned char packet44[] = { |
| 6431 | // type (long header) |
| 6432 | 0x80, |
| 6433 | // version tag |
| 6434 | 0x00, 0x00, 0x00, 0x00, |
| 6435 | // connection_id length |
| 6436 | 0x05, |
| 6437 | // connection_id |
| 6438 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6439 | // version tag |
| 6440 | QUIC_VERSION_BYTES, |
| 6441 | }; |
| 6442 | // clang-format on |
| 6443 | unsigned char* p = packet; |
| 6444 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6445 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6446 | p = packet44; |
| 6447 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6448 | } |
| 6449 | |
| 6450 | QuicConnectionId connection_id = FramerTestConnectionId(); |
| 6451 | std::unique_ptr<QuicEncryptedPacket> data( |
| 6452 | framer_.BuildVersionNegotiationPacket( |
| 6453 | connection_id, framer_.transport_version() > QUIC_VERSION_43, |
| 6454 | SupportedVersions(GetParam()))); |
| 6455 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6456 | data->length(), AsChars(p), p_size); |
| 6457 | } |
| 6458 | |
| 6459 | TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlock) { |
| 6460 | QuicPacketHeader header; |
| 6461 | header.destination_connection_id = FramerTestConnectionId(); |
| 6462 | header.reset_flag = false; |
| 6463 | header.version_flag = false; |
| 6464 | header.packet_number = kPacketNumber; |
| 6465 | |
| 6466 | // Use kSmallLargestObserved to make this test finished in a short time. |
| 6467 | QuicAckFrame ack_frame = InitAckFrame(kSmallLargestObserved); |
| 6468 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6469 | |
| 6470 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6471 | |
| 6472 | // clang-format off |
| 6473 | unsigned char packet[] = { |
| 6474 | // public flags (8 byte connection_id) |
| 6475 | 0x28, |
| 6476 | // connection_id |
| 6477 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6478 | // packet number |
| 6479 | 0x12, 0x34, 0x56, 0x78, |
| 6480 | |
| 6481 | // frame type (ack frame) |
| 6482 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 6483 | 0x45, |
| 6484 | // largest acked |
| 6485 | 0x12, 0x34, |
| 6486 | // Zero delta time. |
| 6487 | 0x00, 0x00, |
| 6488 | // first ack block length. |
| 6489 | 0x12, 0x34, |
| 6490 | // num timestamps. |
| 6491 | 0x00, |
| 6492 | }; |
| 6493 | |
| 6494 | unsigned char packet44[] = { |
| 6495 | // type (short header, 4 byte packet number) |
| 6496 | 0x32, |
| 6497 | // connection_id |
| 6498 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6499 | // packet number |
| 6500 | 0x12, 0x34, 0x56, 0x78, |
| 6501 | |
| 6502 | // frame type (ack frame) |
| 6503 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 6504 | 0x45, |
| 6505 | // largest acked |
| 6506 | 0x12, 0x34, |
| 6507 | // Zero delta time. |
| 6508 | 0x00, 0x00, |
| 6509 | // first ack block length. |
| 6510 | 0x12, 0x34, |
| 6511 | // num timestamps. |
| 6512 | 0x00, |
| 6513 | }; |
| 6514 | |
| 6515 | unsigned char packet46[] = { |
| 6516 | // type (short header, 4 byte packet number) |
| 6517 | 0x43, |
| 6518 | // connection_id |
| 6519 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6520 | // packet number |
| 6521 | 0x12, 0x34, 0x56, 0x78, |
| 6522 | |
| 6523 | // frame type (ack frame) |
| 6524 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 6525 | 0x45, |
| 6526 | // largest acked |
| 6527 | 0x12, 0x34, |
| 6528 | // Zero delta time. |
| 6529 | 0x00, 0x00, |
| 6530 | // first ack block length. |
| 6531 | 0x12, 0x34, |
| 6532 | // num timestamps. |
| 6533 | 0x00, |
| 6534 | }; |
| 6535 | |
| 6536 | unsigned char packet99[] = { |
| 6537 | // type (short header, 4 byte packet number) |
| 6538 | 0x43, |
| 6539 | // connection_id |
| 6540 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6541 | // packet number |
| 6542 | 0x12, 0x34, 0x56, 0x78, |
| 6543 | |
| 6544 | // frame type (IETF_ACK frame) |
| 6545 | 0x02, |
| 6546 | // largest acked |
| 6547 | kVarInt62TwoBytes + 0x12, 0x34, |
| 6548 | // Zero delta time. |
| 6549 | kVarInt62OneByte + 0x00, |
| 6550 | // Number of additional ack blocks. |
| 6551 | kVarInt62OneByte + 0x00, |
| 6552 | // first ack block length. |
| 6553 | kVarInt62TwoBytes + 0x12, 0x33, |
| 6554 | }; |
| 6555 | // clang-format on |
| 6556 | unsigned char* p = packet; |
| 6557 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6558 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6559 | p = packet99; |
| 6560 | p_size = QUIC_ARRAYSIZE(packet99); |
| 6561 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6562 | p = packet46; |
| 6563 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6564 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6565 | p = packet44; |
| 6566 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6567 | } |
| 6568 | |
| 6569 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6570 | ASSERT_TRUE(data != nullptr); |
| 6571 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6572 | data->length(), AsChars(p), p_size); |
| 6573 | } |
| 6574 | |
| 6575 | TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlockMaxLength) { |
| 6576 | QuicPacketHeader header; |
| 6577 | header.destination_connection_id = FramerTestConnectionId(); |
| 6578 | header.reset_flag = false; |
| 6579 | header.version_flag = false; |
| 6580 | header.packet_number = kPacketNumber; |
| 6581 | |
| 6582 | QuicAckFrame ack_frame = InitAckFrame(kPacketNumber); |
| 6583 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6584 | |
| 6585 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6586 | |
| 6587 | // clang-format off |
| 6588 | unsigned char packet[] = { |
| 6589 | // public flags (8 byte connection_id) |
| 6590 | 0x28, |
| 6591 | // connection_id |
| 6592 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6593 | // packet number |
| 6594 | 0x12, 0x34, 0x56, 0x78, |
| 6595 | |
| 6596 | // frame type (ack frame) |
| 6597 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 6598 | 0x4A, |
| 6599 | // largest acked |
| 6600 | 0x12, 0x34, 0x56, 0x78, |
| 6601 | // Zero delta time. |
| 6602 | 0x00, 0x00, |
| 6603 | // first ack block length. |
| 6604 | 0x12, 0x34, 0x56, 0x78, |
| 6605 | // num timestamps. |
| 6606 | 0x00, |
| 6607 | }; |
| 6608 | |
| 6609 | unsigned char packet44[] = { |
| 6610 | // type (short header, 4 byte packet number) |
| 6611 | 0x32, |
| 6612 | // connection_id |
| 6613 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6614 | // packet number |
| 6615 | 0x12, 0x34, 0x56, 0x78, |
| 6616 | |
| 6617 | // frame type (ack frame) |
| 6618 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 6619 | 0x4A, |
| 6620 | // largest acked |
| 6621 | 0x12, 0x34, 0x56, 0x78, |
| 6622 | // Zero delta time. |
| 6623 | 0x00, 0x00, |
| 6624 | // first ack block length. |
| 6625 | 0x12, 0x34, 0x56, 0x78, |
| 6626 | // num timestamps. |
| 6627 | 0x00, |
| 6628 | }; |
| 6629 | |
| 6630 | unsigned char packet46[] = { |
| 6631 | // type (short header, 4 byte packet number) |
| 6632 | 0x43, |
| 6633 | // connection_id |
| 6634 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6635 | // packet number |
| 6636 | 0x12, 0x34, 0x56, 0x78, |
| 6637 | |
| 6638 | // frame type (ack frame) |
| 6639 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 6640 | 0x4A, |
| 6641 | // largest acked |
| 6642 | 0x12, 0x34, 0x56, 0x78, |
| 6643 | // Zero delta time. |
| 6644 | 0x00, 0x00, |
| 6645 | // first ack block length. |
| 6646 | 0x12, 0x34, 0x56, 0x78, |
| 6647 | // num timestamps. |
| 6648 | 0x00, |
| 6649 | }; |
| 6650 | |
| 6651 | |
| 6652 | unsigned char packet99[] = { |
| 6653 | // type (short header, 4 byte packet number) |
| 6654 | 0x43, |
| 6655 | // connection_id |
| 6656 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6657 | // packet number |
| 6658 | 0x12, 0x34, 0x56, 0x78, |
| 6659 | |
| 6660 | // frame type (IETF_ACK frame) |
| 6661 | 0x02, |
| 6662 | // largest acked |
| 6663 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 6664 | // Zero delta time. |
| 6665 | kVarInt62OneByte + 0x00, |
| 6666 | // Nr. of additional ack blocks |
| 6667 | kVarInt62OneByte + 0x00, |
| 6668 | // first ack block length. |
| 6669 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 6670 | }; |
| 6671 | // clang-format on |
| 6672 | unsigned char* p = packet; |
| 6673 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6674 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6675 | p = packet99; |
| 6676 | p_size = QUIC_ARRAYSIZE(packet99); |
| 6677 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6678 | p = packet46; |
| 6679 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6680 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6681 | p = packet44; |
| 6682 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6683 | } |
| 6684 | |
| 6685 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6686 | ASSERT_TRUE(data != nullptr); |
| 6687 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6688 | data->length(), AsChars(p), p_size); |
| 6689 | } |
| 6690 | |
| 6691 | TEST_P(QuicFramerTest, BuildAckFramePacketMultipleAckBlocks) { |
| 6692 | QuicPacketHeader header; |
| 6693 | header.destination_connection_id = FramerTestConnectionId(); |
| 6694 | header.reset_flag = false; |
| 6695 | header.version_flag = false; |
| 6696 | header.packet_number = kPacketNumber; |
| 6697 | |
| 6698 | // Use kSmallLargestObserved to make this test finished in a short time. |
| 6699 | QuicAckFrame ack_frame = |
| 6700 | InitAckFrame({{QuicPacketNumber(1), QuicPacketNumber(5)}, |
| 6701 | {QuicPacketNumber(10), QuicPacketNumber(500)}, |
| 6702 | {QuicPacketNumber(900), kSmallMissingPacket}, |
| 6703 | {kSmallMissingPacket + 1, kSmallLargestObserved + 1}}); |
| 6704 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6705 | |
| 6706 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6707 | |
| 6708 | // clang-format off |
| 6709 | unsigned char packet[] = { |
| 6710 | // public flags (8 byte connection_id) |
| 6711 | 0x28, |
| 6712 | // connection_id |
| 6713 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6714 | // packet number |
| 6715 | 0x12, 0x34, 0x56, 0x78, |
| 6716 | |
| 6717 | // frame type (ack frame) |
| 6718 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6719 | 0x65, |
| 6720 | // largest acked |
| 6721 | 0x12, 0x34, |
| 6722 | // Zero delta time. |
| 6723 | 0x00, 0x00, |
| 6724 | // num ack blocks ranges. |
| 6725 | 0x04, |
| 6726 | // first ack block length. |
| 6727 | 0x00, 0x01, |
| 6728 | // gap to next block. |
| 6729 | 0x01, |
| 6730 | // ack block length. |
| 6731 | 0x0e, 0xaf, |
| 6732 | // gap to next block. |
| 6733 | 0xff, |
| 6734 | // ack block length. |
| 6735 | 0x00, 0x00, |
| 6736 | // gap to next block. |
| 6737 | 0x91, |
| 6738 | // ack block length. |
| 6739 | 0x01, 0xea, |
| 6740 | // gap to next block. |
| 6741 | 0x05, |
| 6742 | // ack block length. |
| 6743 | 0x00, 0x04, |
| 6744 | // num timestamps. |
| 6745 | 0x00, |
| 6746 | }; |
| 6747 | |
| 6748 | unsigned char packet44[] = { |
| 6749 | // type (short header, 4 byte packet number) |
| 6750 | 0x32, |
| 6751 | // connection_id |
| 6752 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6753 | // packet number |
| 6754 | 0x12, 0x34, 0x56, 0x78, |
| 6755 | |
| 6756 | // frame type (ack frame) |
| 6757 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6758 | 0x65, |
| 6759 | // largest acked |
| 6760 | 0x12, 0x34, |
| 6761 | // Zero delta time. |
| 6762 | 0x00, 0x00, |
| 6763 | // num ack blocks ranges. |
| 6764 | 0x04, |
| 6765 | // first ack block length. |
| 6766 | 0x00, 0x01, |
| 6767 | // gap to next block. |
| 6768 | 0x01, |
| 6769 | // ack block length. |
| 6770 | 0x0e, 0xaf, |
| 6771 | // gap to next block. |
| 6772 | 0xff, |
| 6773 | // ack block length. |
| 6774 | 0x00, 0x00, |
| 6775 | // gap to next block. |
| 6776 | 0x91, |
| 6777 | // ack block length. |
| 6778 | 0x01, 0xea, |
| 6779 | // gap to next block. |
| 6780 | 0x05, |
| 6781 | // ack block length. |
| 6782 | 0x00, 0x04, |
| 6783 | // num timestamps. |
| 6784 | 0x00, |
| 6785 | }; |
| 6786 | |
| 6787 | unsigned char packet46[] = { |
| 6788 | // type (short header, 4 byte packet number) |
| 6789 | 0x43, |
| 6790 | // connection_id |
| 6791 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6792 | // packet number |
| 6793 | 0x12, 0x34, 0x56, 0x78, |
| 6794 | |
| 6795 | // frame type (ack frame) |
| 6796 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6797 | 0x65, |
| 6798 | // largest acked |
| 6799 | 0x12, 0x34, |
| 6800 | // Zero delta time. |
| 6801 | 0x00, 0x00, |
| 6802 | // num ack blocks ranges. |
| 6803 | 0x04, |
| 6804 | // first ack block length. |
| 6805 | 0x00, 0x01, |
| 6806 | // gap to next block. |
| 6807 | 0x01, |
| 6808 | // ack block length. |
| 6809 | 0x0e, 0xaf, |
| 6810 | // gap to next block. |
| 6811 | 0xff, |
| 6812 | // ack block length. |
| 6813 | 0x00, 0x00, |
| 6814 | // gap to next block. |
| 6815 | 0x91, |
| 6816 | // ack block length. |
| 6817 | 0x01, 0xea, |
| 6818 | // gap to next block. |
| 6819 | 0x05, |
| 6820 | // ack block length. |
| 6821 | 0x00, 0x04, |
| 6822 | // num timestamps. |
| 6823 | 0x00, |
| 6824 | }; |
| 6825 | |
| 6826 | unsigned char packet99[] = { |
| 6827 | // type (short header, 4 byte packet number) |
| 6828 | 0x43, |
| 6829 | // connection_id |
| 6830 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6831 | // packet number |
| 6832 | 0x12, 0x34, 0x56, 0x78, |
| 6833 | |
| 6834 | // frame type (IETF_ACK frame) |
| 6835 | 0x02, |
| 6836 | // largest acked |
| 6837 | kVarInt62TwoBytes + 0x12, 0x34, |
| 6838 | // Zero delta time. |
| 6839 | kVarInt62OneByte + 0x00, |
| 6840 | // num additional ack blocks. |
| 6841 | kVarInt62OneByte + 0x03, |
| 6842 | // first ack block length. |
| 6843 | kVarInt62OneByte + 0x00, |
| 6844 | |
| 6845 | // gap to next block. |
| 6846 | kVarInt62OneByte + 0x00, |
| 6847 | // ack block length. |
| 6848 | kVarInt62TwoBytes + 0x0e, 0xae, |
| 6849 | |
| 6850 | // gap to next block. |
| 6851 | kVarInt62TwoBytes + 0x01, 0x8f, |
| 6852 | // ack block length. |
| 6853 | kVarInt62TwoBytes + 0x01, 0xe9, |
| 6854 | |
| 6855 | // gap to next block. |
| 6856 | kVarInt62OneByte + 0x04, |
| 6857 | // ack block length. |
| 6858 | kVarInt62OneByte + 0x03, |
| 6859 | }; |
| 6860 | // clang-format on |
| 6861 | unsigned char* p = packet; |
| 6862 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6863 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6864 | p = packet99; |
| 6865 | p_size = QUIC_ARRAYSIZE(packet99); |
| 6866 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6867 | p = packet46; |
| 6868 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6869 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6870 | p = packet44; |
| 6871 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6872 | } |
| 6873 | |
| 6874 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6875 | ASSERT_TRUE(data != nullptr); |
| 6876 | |
| 6877 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6878 | data->length(), AsChars(p), p_size); |
| 6879 | } |
| 6880 | |
| 6881 | TEST_P(QuicFramerTest, BuildAckFramePacketMaxAckBlocks) { |
| 6882 | QuicPacketHeader header; |
| 6883 | header.destination_connection_id = FramerTestConnectionId(); |
| 6884 | header.reset_flag = false; |
| 6885 | header.version_flag = false; |
| 6886 | header.packet_number = kPacketNumber; |
| 6887 | |
| 6888 | // Use kSmallLargestObservedto make this test finished in a short time. |
| 6889 | QuicAckFrame ack_frame; |
| 6890 | ack_frame.largest_acked = kSmallLargestObserved; |
| 6891 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6892 | // 300 ack blocks. |
| 6893 | for (size_t i = 2; i < 2 * 300; i += 2) { |
| 6894 | ack_frame.packets.Add(QuicPacketNumber(i)); |
| 6895 | } |
| 6896 | ack_frame.packets.AddRange(QuicPacketNumber(600), kSmallLargestObserved + 1); |
| 6897 | |
| 6898 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6899 | |
| 6900 | // clang-format off |
| 6901 | unsigned char packet[] = { |
| 6902 | // public flags (8 byte connection_id) |
| 6903 | 0x28, |
| 6904 | // connection_id |
| 6905 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6906 | // packet number |
| 6907 | 0x12, 0x34, 0x56, 0x78, |
| 6908 | // frame type (ack frame) |
| 6909 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6910 | 0x65, |
| 6911 | // largest acked |
| 6912 | 0x12, 0x34, |
| 6913 | // Zero delta time. |
| 6914 | 0x00, 0x00, |
| 6915 | // num ack blocks ranges. |
| 6916 | 0xff, |
| 6917 | // first ack block length. |
| 6918 | 0x0f, 0xdd, |
| 6919 | // 255 = 4 * 63 + 3 |
| 6920 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6921 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6922 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6923 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6924 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6925 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6926 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6927 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6928 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6929 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6930 | |
| 6931 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6932 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6933 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6934 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6935 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6936 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6937 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6938 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6939 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6940 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6941 | |
| 6942 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6943 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6944 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6945 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6946 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6947 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6948 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6949 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6950 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6951 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6952 | |
| 6953 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6954 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6955 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6956 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6957 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6958 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6959 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6960 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6961 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6962 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6963 | |
| 6964 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6965 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6966 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6967 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6968 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6969 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6970 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6971 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6972 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6973 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6974 | |
| 6975 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6976 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6977 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6978 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6979 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6980 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6981 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6982 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6983 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6984 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6985 | |
| 6986 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6987 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6988 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6989 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6990 | // num timestamps. |
| 6991 | 0x00, |
| 6992 | }; |
| 6993 | |
| 6994 | unsigned char packet44[] = { |
| 6995 | // type (short header, 4 byte packet number) |
| 6996 | 0x32, |
| 6997 | // connection_id |
| 6998 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6999 | // packet number |
| 7000 | 0x12, 0x34, 0x56, 0x78, |
| 7001 | // frame type (ack frame) |
| 7002 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 7003 | 0x65, |
| 7004 | // largest acked |
| 7005 | 0x12, 0x34, |
| 7006 | // Zero delta time. |
| 7007 | 0x00, 0x00, |
| 7008 | // num ack blocks ranges. |
| 7009 | 0xff, |
| 7010 | // first ack block length. |
| 7011 | 0x0f, 0xdd, |
| 7012 | // 255 = 4 * 63 + 3 |
| 7013 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7014 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7015 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7016 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7017 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7018 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7019 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7020 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7021 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7022 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7023 | |
| 7024 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7025 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7026 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7027 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7028 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7029 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7030 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7031 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7032 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7033 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7034 | |
| 7035 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7036 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7037 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7038 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7039 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7040 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7041 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7042 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7043 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7044 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7045 | |
| 7046 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7047 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7048 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7049 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7050 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7051 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7052 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7053 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7054 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7055 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7056 | |
| 7057 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7058 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7059 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7060 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7061 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7062 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7063 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7064 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7065 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7066 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7067 | |
| 7068 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7069 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7070 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7071 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7072 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7073 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7074 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7075 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7076 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7077 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7078 | |
| 7079 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7080 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7081 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7082 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7083 | // num timestamps. |
| 7084 | 0x00, |
| 7085 | }; |
| 7086 | |
| 7087 | unsigned char packet46[] = { |
| 7088 | // type (short header, 4 byte packet number) |
| 7089 | 0x43, |
| 7090 | // connection_id |
| 7091 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7092 | // packet number |
| 7093 | 0x12, 0x34, 0x56, 0x78, |
| 7094 | // frame type (ack frame) |
| 7095 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 7096 | 0x65, |
| 7097 | // largest acked |
| 7098 | 0x12, 0x34, |
| 7099 | // Zero delta time. |
| 7100 | 0x00, 0x00, |
| 7101 | // num ack blocks ranges. |
| 7102 | 0xff, |
| 7103 | // first ack block length. |
| 7104 | 0x0f, 0xdd, |
| 7105 | // 255 = 4 * 63 + 3 |
| 7106 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7107 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7108 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7109 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7110 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7111 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7112 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7113 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7114 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7115 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7116 | |
| 7117 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7118 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7119 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7120 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7121 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7122 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7123 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7124 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7125 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7126 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7127 | |
| 7128 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7129 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7130 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7131 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7132 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7133 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7134 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7135 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7136 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7137 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7138 | |
| 7139 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7140 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7141 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7142 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7143 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7144 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7145 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7146 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7147 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7148 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7149 | |
| 7150 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7151 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7152 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7153 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7154 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7155 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7156 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7157 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7158 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7159 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7160 | |
| 7161 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7162 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7163 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7164 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7165 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7166 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7167 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7168 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7169 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7170 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7171 | |
| 7172 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7173 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7174 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7175 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7176 | // num timestamps. |
| 7177 | 0x00, |
| 7178 | }; |
| 7179 | |
| 7180 | unsigned char packet99[] = { |
| 7181 | // type (short header, 4 byte packet number) |
| 7182 | 0x43, |
| 7183 | // connection_id |
| 7184 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7185 | // packet number |
| 7186 | 0x12, 0x34, 0x56, 0x78, |
| 7187 | // frame type (IETF_ACK frame) |
| 7188 | 0x02, |
| 7189 | // largest acked |
| 7190 | kVarInt62TwoBytes + 0x12, 0x34, |
| 7191 | // Zero delta time. |
| 7192 | kVarInt62OneByte + 0x00, |
| 7193 | // num ack blocks ranges. |
| 7194 | kVarInt62TwoBytes + 0x01, 0x2b, |
| 7195 | // first ack block length. |
| 7196 | kVarInt62TwoBytes + 0x0f, 0xdc, |
| 7197 | // 255 added blocks of gap_size == 1, ack_size == 1 |
| 7198 | #define V99AddedBLOCK kVarInt62OneByte + 0x00, kVarInt62OneByte + 0x00 |
| 7199 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7200 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7201 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7202 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7203 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7204 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7205 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7206 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7207 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7208 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7209 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7210 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7211 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7212 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7213 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7214 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7215 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7216 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7217 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7218 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7219 | |
| 7220 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7221 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7222 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7223 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7224 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7225 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7226 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7227 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7228 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7229 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7230 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7231 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7232 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7233 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7234 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7235 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7236 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7237 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7238 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7239 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7240 | |
| 7241 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7242 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7243 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7244 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7245 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7246 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7247 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7248 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7249 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7250 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7251 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7252 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7253 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7254 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7255 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7256 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7257 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7258 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7259 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7260 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7261 | |
| 7262 | #undef V99AddedBLOCK |
| 7263 | }; |
| 7264 | // clang-format on |
| 7265 | unsigned char* p = packet; |
| 7266 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7267 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7268 | p = packet99; |
| 7269 | p_size = QUIC_ARRAYSIZE(packet99); |
| 7270 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7271 | p = packet46; |
| 7272 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7273 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7274 | p = packet44; |
| 7275 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7276 | } |
| 7277 | |
| 7278 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7279 | ASSERT_TRUE(data != nullptr); |
| 7280 | |
| 7281 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7282 | data->length(), AsChars(p), p_size); |
| 7283 | } |
| 7284 | |
| 7285 | TEST_P(QuicFramerTest, BuildNewStopWaitingPacket) { |
| 7286 | if (version_.transport_version > QUIC_VERSION_43) { |
| 7287 | return; |
| 7288 | } |
| 7289 | QuicPacketHeader header; |
| 7290 | header.destination_connection_id = FramerTestConnectionId(); |
| 7291 | header.reset_flag = false; |
| 7292 | header.version_flag = false; |
| 7293 | header.packet_number = kPacketNumber; |
| 7294 | |
| 7295 | QuicStopWaitingFrame stop_waiting_frame; |
| 7296 | stop_waiting_frame.least_unacked = kLeastUnacked; |
| 7297 | |
| 7298 | QuicFrames frames = {QuicFrame(stop_waiting_frame)}; |
| 7299 | |
| 7300 | // clang-format off |
| 7301 | unsigned char packet[] = { |
| 7302 | // public flags (8 byte connection_id) |
| 7303 | 0x28, |
| 7304 | // connection_id |
| 7305 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7306 | // packet number |
| 7307 | 0x12, 0x34, 0x56, 0x78, |
| 7308 | |
| 7309 | // frame type (stop waiting frame) |
| 7310 | 0x06, |
| 7311 | // least packet number awaiting an ack, delta from packet number. |
| 7312 | 0x00, 0x00, 0x00, 0x08, |
| 7313 | }; |
| 7314 | |
| 7315 | // clang-format on |
| 7316 | |
| 7317 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7318 | ASSERT_TRUE(data != nullptr); |
| 7319 | |
| 7320 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7321 | data->length(), AsChars(packet), |
| 7322 | QUIC_ARRAYSIZE(packet)); |
| 7323 | } |
| 7324 | |
| 7325 | TEST_P(QuicFramerTest, BuildRstFramePacketQuic) { |
| 7326 | QuicPacketHeader header; |
| 7327 | header.destination_connection_id = FramerTestConnectionId(); |
| 7328 | header.reset_flag = false; |
| 7329 | header.version_flag = false; |
| 7330 | header.packet_number = kPacketNumber; |
| 7331 | |
| 7332 | QuicRstStreamFrame rst_frame; |
| 7333 | rst_frame.stream_id = kStreamId; |
| 7334 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7335 | rst_frame.ietf_error_code = 0x01; |
| 7336 | } else { |
| 7337 | rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708); |
| 7338 | } |
| 7339 | rst_frame.byte_offset = 0x0807060504030201; |
| 7340 | |
| 7341 | // clang-format off |
| 7342 | unsigned char packet[] = { |
| 7343 | // public flags (8 byte connection_id) |
| 7344 | 0x28, |
| 7345 | // connection_id |
| 7346 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7347 | // packet number |
| 7348 | 0x12, 0x34, 0x56, 0x78, |
| 7349 | |
| 7350 | // frame type (rst stream frame) |
| 7351 | 0x01, |
| 7352 | // stream id |
| 7353 | 0x01, 0x02, 0x03, 0x04, |
| 7354 | // sent byte offset |
| 7355 | 0x08, 0x07, 0x06, 0x05, |
| 7356 | 0x04, 0x03, 0x02, 0x01, |
| 7357 | // error code |
| 7358 | 0x05, 0x06, 0x07, 0x08, |
| 7359 | }; |
| 7360 | |
| 7361 | unsigned char packet44[] = { |
| 7362 | // type (short packet, 4 byte packet number) |
| 7363 | 0x32, |
| 7364 | // connection_id |
| 7365 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7366 | // packet number |
| 7367 | 0x12, 0x34, 0x56, 0x78, |
| 7368 | |
| 7369 | // frame type (rst stream frame) |
| 7370 | 0x01, |
| 7371 | // stream id |
| 7372 | 0x01, 0x02, 0x03, 0x04, |
| 7373 | // sent byte offset |
| 7374 | 0x08, 0x07, 0x06, 0x05, |
| 7375 | 0x04, 0x03, 0x02, 0x01, |
| 7376 | // error code |
| 7377 | 0x05, 0x06, 0x07, 0x08, |
| 7378 | }; |
| 7379 | |
| 7380 | unsigned char packet46[] = { |
| 7381 | // type (short packet, 4 byte packet number) |
| 7382 | 0x43, |
| 7383 | // connection_id |
| 7384 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7385 | // packet number |
| 7386 | 0x12, 0x34, 0x56, 0x78, |
| 7387 | |
| 7388 | // frame type (rst stream frame) |
| 7389 | 0x01, |
| 7390 | // stream id |
| 7391 | 0x01, 0x02, 0x03, 0x04, |
| 7392 | // sent byte offset |
| 7393 | 0x08, 0x07, 0x06, 0x05, |
| 7394 | 0x04, 0x03, 0x02, 0x01, |
| 7395 | // error code |
| 7396 | 0x05, 0x06, 0x07, 0x08, |
| 7397 | }; |
| 7398 | |
| 7399 | unsigned char packet99[] = { |
| 7400 | // type (short packet, 4 byte packet number) |
| 7401 | 0x43, |
| 7402 | // connection_id |
| 7403 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7404 | // packet number |
| 7405 | 0x12, 0x34, 0x56, 0x78, |
| 7406 | |
| 7407 | // frame type (IETF_RST_STREAM frame) |
| 7408 | 0x04, |
| 7409 | // stream id |
| 7410 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 7411 | // error code (not VarInt32 encoded) |
| 7412 | 0x00, 0x01, |
| 7413 | // sent byte offset |
| 7414 | kVarInt62EightBytes + 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 |
| 7415 | }; |
| 7416 | // clang-format on |
| 7417 | |
| 7418 | QuicFrames frames = {QuicFrame(&rst_frame)}; |
| 7419 | |
| 7420 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7421 | ASSERT_TRUE(data != nullptr); |
| 7422 | |
| 7423 | unsigned char* p = packet; |
| 7424 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7425 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7426 | p = packet99; |
| 7427 | p_size = QUIC_ARRAYSIZE(packet99); |
| 7428 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7429 | p = packet46; |
| 7430 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7431 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7432 | p = packet44; |
| 7433 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7434 | } |
| 7435 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 7436 | |
| 7437 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7438 | data->length(), AsChars(p), p_size); |
| 7439 | } |
| 7440 | |
| 7441 | TEST_P(QuicFramerTest, BuildCloseFramePacket) { |
| 7442 | QuicPacketHeader header; |
| 7443 | header.destination_connection_id = FramerTestConnectionId(); |
| 7444 | header.reset_flag = false; |
| 7445 | header.version_flag = false; |
| 7446 | header.packet_number = kPacketNumber; |
| 7447 | |
| 7448 | QuicConnectionCloseFrame close_frame; |
| 7449 | if (framer_.transport_version() == QUIC_VERSION_99) { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 7450 | close_frame.transport_error_code = |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7451 | static_cast<QuicIetfTransportErrorCodes>(0x11); |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 7452 | close_frame.transport_close_frame_type = 0x05; |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 7453 | close_frame.close_type = IETF_QUIC_TRANSPORT_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7454 | } else { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 7455 | close_frame.quic_error_code = static_cast<QuicErrorCode>(0x05060708); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7456 | } |
| 7457 | close_frame.error_details = "because I can"; |
| 7458 | |
| 7459 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 7460 | |
| 7461 | // clang-format off |
| 7462 | unsigned char packet[] = { |
| 7463 | // public flags (8 byte connection_id) |
| 7464 | 0x28, |
| 7465 | // connection_id |
| 7466 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7467 | // packet number |
| 7468 | 0x12, 0x34, 0x56, 0x78, |
| 7469 | |
| 7470 | // frame type (connection close frame) |
| 7471 | 0x02, |
| 7472 | // error code |
| 7473 | 0x05, 0x06, 0x07, 0x08, |
| 7474 | // error details length |
| 7475 | 0x00, 0x0d, |
| 7476 | // error details |
| 7477 | 'b', 'e', 'c', 'a', |
| 7478 | 'u', 's', 'e', ' ', |
| 7479 | 'I', ' ', 'c', 'a', |
| 7480 | 'n', |
| 7481 | }; |
| 7482 | |
| 7483 | unsigned char packet44[] = { |
| 7484 | // type (short header, 4 byte packet number) |
| 7485 | 0x32, |
| 7486 | // connection_id |
| 7487 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7488 | // packet number |
| 7489 | 0x12, 0x34, 0x56, 0x78, |
| 7490 | |
| 7491 | // frame type (connection close frame) |
| 7492 | 0x02, |
| 7493 | // error code |
| 7494 | 0x05, 0x06, 0x07, 0x08, |
| 7495 | // error details length |
| 7496 | 0x00, 0x0d, |
| 7497 | // error details |
| 7498 | 'b', 'e', 'c', 'a', |
| 7499 | 'u', 's', 'e', ' ', |
| 7500 | 'I', ' ', 'c', 'a', |
| 7501 | 'n', |
| 7502 | }; |
| 7503 | |
| 7504 | unsigned char packet46[] = { |
| 7505 | // type (short header, 4 byte packet number) |
| 7506 | 0x43, |
| 7507 | // connection_id |
| 7508 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7509 | // packet number |
| 7510 | 0x12, 0x34, 0x56, 0x78, |
| 7511 | |
| 7512 | // frame type (connection close frame) |
| 7513 | 0x02, |
| 7514 | // error code |
| 7515 | 0x05, 0x06, 0x07, 0x08, |
| 7516 | // error details length |
| 7517 | 0x00, 0x0d, |
| 7518 | // error details |
| 7519 | 'b', 'e', 'c', 'a', |
| 7520 | 'u', 's', 'e', ' ', |
| 7521 | 'I', ' ', 'c', 'a', |
| 7522 | 'n', |
| 7523 | }; |
| 7524 | |
| 7525 | unsigned char packet99[] = { |
| 7526 | // type (short header, 4 byte packet number) |
| 7527 | 0x43, |
| 7528 | // connection_id |
| 7529 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7530 | // packet number |
| 7531 | 0x12, 0x34, 0x56, 0x78, |
| 7532 | |
| 7533 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 7534 | 0x1c, |
| 7535 | // error code |
| 7536 | 0x00, 0x11, |
| 7537 | // Frame type within the CONNECTION_CLOSE frame |
| 7538 | kVarInt62OneByte + 0x05, |
| 7539 | // error details length |
| 7540 | kVarInt62OneByte + 0x0d, |
| 7541 | // error details |
| 7542 | 'b', 'e', 'c', 'a', |
| 7543 | 'u', 's', 'e', ' ', |
| 7544 | 'I', ' ', 'c', 'a', |
| 7545 | 'n', |
| 7546 | }; |
| 7547 | // clang-format on |
| 7548 | |
| 7549 | unsigned char* p = packet; |
| 7550 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7551 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7552 | p = packet99; |
| 7553 | p_size = QUIC_ARRAYSIZE(packet99); |
| 7554 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7555 | p = packet46; |
| 7556 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7557 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7558 | p = packet44; |
| 7559 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7560 | } |
| 7561 | |
| 7562 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7563 | ASSERT_TRUE(data != nullptr); |
| 7564 | |
| 7565 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7566 | data->length(), AsChars(p), p_size); |
| 7567 | } |
| 7568 | |
| 7569 | TEST_P(QuicFramerTest, BuildTruncatedCloseFramePacket) { |
| 7570 | QuicPacketHeader header; |
| 7571 | header.destination_connection_id = FramerTestConnectionId(); |
| 7572 | header.reset_flag = false; |
| 7573 | header.version_flag = false; |
| 7574 | header.packet_number = kPacketNumber; |
| 7575 | |
| 7576 | QuicConnectionCloseFrame close_frame; |
| 7577 | if (framer_.transport_version() == QUIC_VERSION_99) { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 7578 | close_frame.transport_error_code = PROTOCOL_VIOLATION; // value is 0x0a |
| 7579 | EXPECT_EQ(0u, close_frame.transport_close_frame_type); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 7580 | close_frame.close_type = IETF_QUIC_TRANSPORT_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7581 | } else { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 7582 | close_frame.quic_error_code = static_cast<QuicErrorCode>(0x05060708); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7583 | } |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 7584 | close_frame.error_details = std::string(2048, 'A'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7585 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 7586 | |
| 7587 | // clang-format off |
| 7588 | unsigned char packet[] = { |
| 7589 | // public flags (8 byte connection_id) |
| 7590 | 0x28, |
| 7591 | // connection_id |
| 7592 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7593 | // packet number |
| 7594 | 0x12, 0x34, 0x56, 0x78, |
| 7595 | |
| 7596 | // frame type (connection close frame) |
| 7597 | 0x02, |
| 7598 | // error code |
| 7599 | 0x05, 0x06, 0x07, 0x08, |
| 7600 | // error details length |
| 7601 | 0x01, 0x00, |
| 7602 | // error details (truncated to 256 bytes) |
| 7603 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7604 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7605 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7606 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7607 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7608 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7609 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7610 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7611 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7612 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7613 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7614 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7615 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7616 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7617 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7618 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7619 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7620 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7621 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7622 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7623 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7624 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7625 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7626 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7627 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7628 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7629 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7630 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7631 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7632 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7633 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7634 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7635 | }; |
| 7636 | |
| 7637 | unsigned char packet44[] = { |
| 7638 | // type (short header, 4 byte packet number) |
| 7639 | 0x32, |
| 7640 | // connection_id |
| 7641 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7642 | // packet number |
| 7643 | 0x12, 0x34, 0x56, 0x78, |
| 7644 | |
| 7645 | // frame type (connection close frame) |
| 7646 | 0x02, |
| 7647 | // error code |
| 7648 | 0x05, 0x06, 0x07, 0x08, |
| 7649 | // error details length |
| 7650 | 0x01, 0x00, |
| 7651 | // error details (truncated to 256 bytes) |
| 7652 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7653 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7654 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7655 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7656 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7657 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7658 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7659 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7660 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7661 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7662 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7663 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7664 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7665 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7666 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7667 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7668 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7669 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7670 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7671 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7672 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7673 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7674 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7675 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7676 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7677 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7678 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7679 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7680 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7681 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7682 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7683 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7684 | }; |
| 7685 | |
| 7686 | unsigned char packet46[] = { |
| 7687 | // type (short header, 4 byte packet number) |
| 7688 | 0x43, |
| 7689 | // connection_id |
| 7690 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7691 | // packet number |
| 7692 | 0x12, 0x34, 0x56, 0x78, |
| 7693 | |
| 7694 | // frame type (connection close frame) |
| 7695 | 0x02, |
| 7696 | // error code |
| 7697 | 0x05, 0x06, 0x07, 0x08, |
| 7698 | // error details length |
| 7699 | 0x01, 0x00, |
| 7700 | // error details (truncated to 256 bytes) |
| 7701 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7702 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7703 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7704 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7705 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7706 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7707 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7708 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7709 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7710 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7711 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7712 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7713 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7714 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7715 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7716 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7717 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7718 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7719 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7720 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7721 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7722 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7723 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7724 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7725 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7726 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7727 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7728 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7729 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7730 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7731 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7732 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7733 | }; |
| 7734 | |
| 7735 | unsigned char packet99[] = { |
| 7736 | // type (short header, 4 byte packet number) |
| 7737 | 0x43, |
| 7738 | // connection_id |
| 7739 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7740 | // packet number |
| 7741 | 0x12, 0x34, 0x56, 0x78, |
| 7742 | |
| 7743 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 7744 | 0x1c, |
| 7745 | // error code |
| 7746 | 0x00, 0x0a, |
| 7747 | // Frame type within the CONNECTION_CLOSE frame |
| 7748 | kVarInt62OneByte + 0x00, |
| 7749 | // error details length |
| 7750 | kVarInt62TwoBytes + 0x01, 0x00, |
| 7751 | // error details (truncated to 256 bytes) |
| 7752 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7753 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7754 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7755 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7756 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7757 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7758 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7759 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7760 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7761 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7762 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7763 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7764 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7765 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7766 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7767 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7768 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7769 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7770 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7771 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7772 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7773 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7774 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7775 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7776 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7777 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7778 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7779 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7780 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7781 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7782 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7783 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7784 | }; |
| 7785 | // clang-format on |
| 7786 | |
| 7787 | unsigned char* p = packet; |
| 7788 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7789 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7790 | p = packet99; |
| 7791 | p_size = QUIC_ARRAYSIZE(packet99); |
| 7792 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7793 | p = packet46; |
| 7794 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7795 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7796 | p = packet44; |
| 7797 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7798 | } |
| 7799 | |
| 7800 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7801 | ASSERT_TRUE(data != nullptr); |
| 7802 | |
| 7803 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7804 | data->length(), AsChars(p), p_size); |
| 7805 | } |
| 7806 | |
| 7807 | TEST_P(QuicFramerTest, BuildApplicationCloseFramePacket) { |
| 7808 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 7809 | // Versions other than 99 do not have ApplicationClose |
| 7810 | return; |
| 7811 | } |
| 7812 | QuicPacketHeader header; |
| 7813 | header.destination_connection_id = FramerTestConnectionId(); |
| 7814 | header.reset_flag = false; |
| 7815 | header.version_flag = false; |
| 7816 | header.packet_number = kPacketNumber; |
| 7817 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 7818 | QuicConnectionCloseFrame app_close_frame; |
| 7819 | app_close_frame.quic_error_code = static_cast<QuicErrorCode>(0x11); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7820 | app_close_frame.error_details = "because I can"; |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 7821 | app_close_frame.close_type = IETF_QUIC_APPLICATION_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7822 | |
| 7823 | QuicFrames frames = {QuicFrame(&app_close_frame)}; |
| 7824 | |
| 7825 | // clang-format off |
| 7826 | |
| 7827 | unsigned char packet99[] = { |
| 7828 | // type (short header, 4 byte packet number) |
| 7829 | 0x43, |
| 7830 | // connection_id |
| 7831 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7832 | // packet number |
| 7833 | 0x12, 0x34, 0x56, 0x78, |
| 7834 | |
| 7835 | // frame type (IETF_APPLICATION_CLOSE frame) |
| 7836 | 0x1d, |
| 7837 | // error code |
| 7838 | 0x00, 0x11, |
| 7839 | // error details length |
| 7840 | kVarInt62OneByte + 0x0d, |
| 7841 | // error details |
| 7842 | 'b', 'e', 'c', 'a', |
| 7843 | 'u', 's', 'e', ' ', |
| 7844 | 'I', ' ', 'c', 'a', |
| 7845 | 'n', |
| 7846 | }; |
| 7847 | // clang-format on |
| 7848 | |
| 7849 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7850 | ASSERT_TRUE(data != nullptr); |
| 7851 | |
| 7852 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7853 | data->length(), AsChars(packet99), |
| 7854 | QUIC_ARRAYSIZE(packet99)); |
| 7855 | } |
| 7856 | |
| 7857 | TEST_P(QuicFramerTest, BuildTruncatedApplicationCloseFramePacket) { |
| 7858 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 7859 | // Versions other than 99 do not have this frame. |
| 7860 | return; |
| 7861 | } |
| 7862 | QuicPacketHeader header; |
| 7863 | header.destination_connection_id = FramerTestConnectionId(); |
| 7864 | header.reset_flag = false; |
| 7865 | header.version_flag = false; |
| 7866 | header.packet_number = kPacketNumber; |
| 7867 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 7868 | QuicConnectionCloseFrame app_close_frame; |
| 7869 | app_close_frame.quic_error_code = static_cast<QuicErrorCode>(0x11); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 7870 | app_close_frame.error_details = std::string(2048, 'A'); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 7871 | app_close_frame.close_type = IETF_QUIC_APPLICATION_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7872 | |
| 7873 | QuicFrames frames = {QuicFrame(&app_close_frame)}; |
| 7874 | |
| 7875 | // clang-format off |
| 7876 | unsigned char packet99[] = { |
| 7877 | // type (short header, 4 byte packet number) |
| 7878 | 0x43, |
| 7879 | // connection_id |
| 7880 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7881 | // packet number |
| 7882 | 0x12, 0x34, 0x56, 0x78, |
| 7883 | |
| 7884 | // frame type (IETF_APPLICATION_CLOSE frame) |
| 7885 | 0x1d, |
| 7886 | // error code |
| 7887 | 0x00, 0x11, |
| 7888 | // error details length |
| 7889 | kVarInt62TwoBytes + 0x01, 0x00, |
| 7890 | // error details (truncated to 256 bytes) |
| 7891 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7892 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7893 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7894 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7895 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7896 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7897 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7898 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7899 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7900 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7901 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7902 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7903 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7904 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7905 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7906 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7907 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7908 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7909 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7910 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7911 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7912 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7913 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7914 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7915 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7916 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7917 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7918 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7919 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7920 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7921 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7922 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7923 | }; |
| 7924 | // clang-format on |
| 7925 | |
| 7926 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7927 | ASSERT_TRUE(data != nullptr); |
| 7928 | |
| 7929 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7930 | data->length(), AsChars(packet99), |
| 7931 | QUIC_ARRAYSIZE(packet99)); |
| 7932 | } |
| 7933 | |
| 7934 | TEST_P(QuicFramerTest, BuildGoAwayPacket) { |
| 7935 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7936 | // This frame type is not supported in version 99. |
| 7937 | return; |
| 7938 | } |
| 7939 | QuicPacketHeader header; |
| 7940 | header.destination_connection_id = FramerTestConnectionId(); |
| 7941 | header.reset_flag = false; |
| 7942 | header.version_flag = false; |
| 7943 | header.packet_number = kPacketNumber; |
| 7944 | |
| 7945 | QuicGoAwayFrame goaway_frame; |
| 7946 | goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 7947 | goaway_frame.last_good_stream_id = kStreamId; |
| 7948 | goaway_frame.reason_phrase = "because I can"; |
| 7949 | |
| 7950 | QuicFrames frames = {QuicFrame(&goaway_frame)}; |
| 7951 | |
| 7952 | // clang-format off |
| 7953 | unsigned char packet[] = { |
| 7954 | // public flags (8 byte connection_id) |
| 7955 | 0x28, |
| 7956 | // connection_id |
| 7957 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7958 | // packet number |
| 7959 | 0x12, 0x34, 0x56, 0x78, |
| 7960 | |
| 7961 | // frame type (go away frame) |
| 7962 | 0x03, |
| 7963 | // error code |
| 7964 | 0x05, 0x06, 0x07, 0x08, |
| 7965 | // stream id |
| 7966 | 0x01, 0x02, 0x03, 0x04, |
| 7967 | // error details length |
| 7968 | 0x00, 0x0d, |
| 7969 | // error details |
| 7970 | 'b', 'e', 'c', 'a', |
| 7971 | 'u', 's', 'e', ' ', |
| 7972 | 'I', ' ', 'c', 'a', |
| 7973 | 'n', |
| 7974 | }; |
| 7975 | |
| 7976 | unsigned char packet44[] = { |
| 7977 | // type (short header, 4 byte packet number) |
| 7978 | 0x32, |
| 7979 | // connection_id |
| 7980 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7981 | // packet number |
| 7982 | 0x12, 0x34, 0x56, 0x78, |
| 7983 | |
| 7984 | // frame type (go away frame) |
| 7985 | 0x03, |
| 7986 | // error code |
| 7987 | 0x05, 0x06, 0x07, 0x08, |
| 7988 | // stream id |
| 7989 | 0x01, 0x02, 0x03, 0x04, |
| 7990 | // error details length |
| 7991 | 0x00, 0x0d, |
| 7992 | // error details |
| 7993 | 'b', 'e', 'c', 'a', |
| 7994 | 'u', 's', 'e', ' ', |
| 7995 | 'I', ' ', 'c', 'a', |
| 7996 | 'n', |
| 7997 | }; |
| 7998 | |
| 7999 | unsigned char packet46[] = { |
| 8000 | // type (short header, 4 byte packet number) |
| 8001 | 0x43, |
| 8002 | // connection_id |
| 8003 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8004 | // packet number |
| 8005 | 0x12, 0x34, 0x56, 0x78, |
| 8006 | |
| 8007 | // frame type (go away frame) |
| 8008 | 0x03, |
| 8009 | // error code |
| 8010 | 0x05, 0x06, 0x07, 0x08, |
| 8011 | // stream id |
| 8012 | 0x01, 0x02, 0x03, 0x04, |
| 8013 | // error details length |
| 8014 | 0x00, 0x0d, |
| 8015 | // error details |
| 8016 | 'b', 'e', 'c', 'a', |
| 8017 | 'u', 's', 'e', ' ', |
| 8018 | 'I', ' ', 'c', 'a', |
| 8019 | 'n', |
| 8020 | }; |
| 8021 | |
| 8022 | // clang-format on |
| 8023 | |
| 8024 | unsigned char* p = packet; |
| 8025 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 8026 | if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8027 | p = packet46; |
| 8028 | p_size = QUIC_ARRAYSIZE(packet46); |
| 8029 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8030 | p = packet44; |
| 8031 | p_size = QUIC_ARRAYSIZE(packet44); |
| 8032 | } |
| 8033 | |
| 8034 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8035 | ASSERT_TRUE(data != nullptr); |
| 8036 | |
| 8037 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8038 | data->length(), AsChars(p), p_size); |
| 8039 | } |
| 8040 | |
| 8041 | TEST_P(QuicFramerTest, BuildTruncatedGoAwayPacket) { |
| 8042 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8043 | // This frame type is not supported in version 99. |
| 8044 | return; |
| 8045 | } |
| 8046 | QuicPacketHeader header; |
| 8047 | header.destination_connection_id = FramerTestConnectionId(); |
| 8048 | header.reset_flag = false; |
| 8049 | header.version_flag = false; |
| 8050 | header.packet_number = kPacketNumber; |
| 8051 | |
| 8052 | QuicGoAwayFrame goaway_frame; |
| 8053 | goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 8054 | goaway_frame.last_good_stream_id = kStreamId; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 8055 | goaway_frame.reason_phrase = std::string(2048, 'A'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8056 | |
| 8057 | QuicFrames frames = {QuicFrame(&goaway_frame)}; |
| 8058 | |
| 8059 | // clang-format off |
| 8060 | unsigned char packet[] = { |
| 8061 | // public flags (8 byte connection_id) |
| 8062 | 0x28, |
| 8063 | // connection_id |
| 8064 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8065 | // packet number |
| 8066 | 0x12, 0x34, 0x56, 0x78, |
| 8067 | |
| 8068 | // frame type (go away frame) |
| 8069 | 0x03, |
| 8070 | // error code |
| 8071 | 0x05, 0x06, 0x07, 0x08, |
| 8072 | // stream id |
| 8073 | 0x01, 0x02, 0x03, 0x04, |
| 8074 | // error details length |
| 8075 | 0x01, 0x00, |
| 8076 | // error details (truncated to 256 bytes) |
| 8077 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8078 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8079 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8080 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8081 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8082 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8083 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8084 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8085 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8086 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8087 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8088 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8089 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8090 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8091 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8092 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8093 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8094 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8095 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8096 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8097 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8098 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8099 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8100 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8101 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8102 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8103 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8104 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8105 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8106 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8107 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8108 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8109 | }; |
| 8110 | |
| 8111 | unsigned char packet44[] = { |
| 8112 | // type (short header, 4 byte packet number) |
| 8113 | 0x32, |
| 8114 | // connection_id |
| 8115 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8116 | // packet number |
| 8117 | 0x12, 0x34, 0x56, 0x78, |
| 8118 | |
| 8119 | // frame type (go away frame) |
| 8120 | 0x03, |
| 8121 | // error code |
| 8122 | 0x05, 0x06, 0x07, 0x08, |
| 8123 | // stream id |
| 8124 | 0x01, 0x02, 0x03, 0x04, |
| 8125 | // error details length |
| 8126 | 0x01, 0x00, |
| 8127 | // error details (truncated to 256 bytes) |
| 8128 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8129 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8130 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8131 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8132 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8133 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8134 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8135 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8136 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8137 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8138 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8139 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8140 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8141 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8142 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8143 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8144 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8145 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8146 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8147 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8148 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8149 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8150 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8151 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8152 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8153 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8154 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8155 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8156 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8157 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8158 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8159 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8160 | }; |
| 8161 | |
| 8162 | unsigned char packet46[] = { |
| 8163 | // type (short header, 4 byte packet number) |
| 8164 | 0x43, |
| 8165 | // connection_id |
| 8166 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8167 | // packet number |
| 8168 | 0x12, 0x34, 0x56, 0x78, |
| 8169 | |
| 8170 | // frame type (go away frame) |
| 8171 | 0x03, |
| 8172 | // error code |
| 8173 | 0x05, 0x06, 0x07, 0x08, |
| 8174 | // stream id |
| 8175 | 0x01, 0x02, 0x03, 0x04, |
| 8176 | // error details length |
| 8177 | 0x01, 0x00, |
| 8178 | // error details (truncated to 256 bytes) |
| 8179 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8180 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8181 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8182 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8183 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8184 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8185 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8186 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8187 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8188 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8189 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8190 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8191 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8192 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8193 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8194 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8195 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8196 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8197 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8198 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8199 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8200 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8201 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8202 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8203 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8204 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8205 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8206 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8207 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8208 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8209 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8210 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8211 | }; |
| 8212 | // clang-format on |
| 8213 | |
| 8214 | unsigned char* p = packet; |
| 8215 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 8216 | if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8217 | p = packet46; |
| 8218 | p_size = QUIC_ARRAYSIZE(packet46); |
| 8219 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8220 | p = packet44; |
| 8221 | p_size = QUIC_ARRAYSIZE(packet44); |
| 8222 | } |
| 8223 | |
| 8224 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8225 | ASSERT_TRUE(data != nullptr); |
| 8226 | |
| 8227 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8228 | data->length(), AsChars(p), p_size); |
| 8229 | } |
| 8230 | |
| 8231 | TEST_P(QuicFramerTest, BuildWindowUpdatePacket) { |
| 8232 | QuicPacketHeader header; |
| 8233 | header.destination_connection_id = FramerTestConnectionId(); |
| 8234 | header.reset_flag = false; |
| 8235 | header.version_flag = false; |
| 8236 | header.packet_number = kPacketNumber; |
| 8237 | |
| 8238 | QuicWindowUpdateFrame window_update_frame; |
| 8239 | window_update_frame.stream_id = kStreamId; |
| 8240 | window_update_frame.byte_offset = 0x1122334455667788; |
| 8241 | |
| 8242 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8243 | |
| 8244 | // clang-format off |
| 8245 | unsigned char packet[] = { |
| 8246 | // public flags (8 byte connection_id) |
| 8247 | 0x28, |
| 8248 | // connection_id |
| 8249 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8250 | // packet number |
| 8251 | 0x12, 0x34, 0x56, 0x78, |
| 8252 | |
| 8253 | // frame type (window update frame) |
| 8254 | 0x04, |
| 8255 | // stream id |
| 8256 | 0x01, 0x02, 0x03, 0x04, |
| 8257 | // byte offset |
| 8258 | 0x11, 0x22, 0x33, 0x44, |
| 8259 | 0x55, 0x66, 0x77, 0x88, |
| 8260 | }; |
| 8261 | |
| 8262 | unsigned char packet44[] = { |
| 8263 | // type (short header, 4 byte packet number) |
| 8264 | 0x32, |
| 8265 | // connection_id |
| 8266 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8267 | // packet number |
| 8268 | 0x12, 0x34, 0x56, 0x78, |
| 8269 | |
| 8270 | // frame type (window update frame) |
| 8271 | 0x04, |
| 8272 | // stream id |
| 8273 | 0x01, 0x02, 0x03, 0x04, |
| 8274 | // byte offset |
| 8275 | 0x11, 0x22, 0x33, 0x44, |
| 8276 | 0x55, 0x66, 0x77, 0x88, |
| 8277 | }; |
| 8278 | |
| 8279 | unsigned char packet46[] = { |
| 8280 | // type (short header, 4 byte packet number) |
| 8281 | 0x43, |
| 8282 | // connection_id |
| 8283 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8284 | // packet number |
| 8285 | 0x12, 0x34, 0x56, 0x78, |
| 8286 | |
| 8287 | // frame type (window update frame) |
| 8288 | 0x04, |
| 8289 | // stream id |
| 8290 | 0x01, 0x02, 0x03, 0x04, |
| 8291 | // byte offset |
| 8292 | 0x11, 0x22, 0x33, 0x44, |
| 8293 | 0x55, 0x66, 0x77, 0x88, |
| 8294 | }; |
| 8295 | |
| 8296 | unsigned char packet99[] = { |
| 8297 | // type (short header, 4 byte packet number) |
| 8298 | 0x43, |
| 8299 | // connection_id |
| 8300 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8301 | // packet number |
| 8302 | 0x12, 0x34, 0x56, 0x78, |
| 8303 | |
| 8304 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 8305 | 0x11, |
| 8306 | // stream id |
| 8307 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 8308 | // byte offset |
| 8309 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8310 | 0x55, 0x66, 0x77, 0x88, |
| 8311 | }; |
| 8312 | // clang-format on |
| 8313 | |
| 8314 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8315 | ASSERT_TRUE(data != nullptr); |
| 8316 | |
| 8317 | unsigned char* p = packet; |
| 8318 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 8319 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8320 | p = packet99; |
| 8321 | p_size = QUIC_ARRAYSIZE(packet99); |
| 8322 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8323 | p = packet46; |
| 8324 | p_size = QUIC_ARRAYSIZE(packet46); |
| 8325 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8326 | p = packet44; |
| 8327 | p_size = QUIC_ARRAYSIZE(packet44); |
| 8328 | } |
| 8329 | |
| 8330 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8331 | data->length(), AsChars(p), p_size); |
| 8332 | } |
| 8333 | |
| 8334 | TEST_P(QuicFramerTest, BuildMaxStreamDataPacket) { |
| 8335 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8336 | // This frame is available only in this version. |
| 8337 | return; |
| 8338 | } |
| 8339 | QuicPacketHeader header; |
| 8340 | header.destination_connection_id = FramerTestConnectionId(); |
| 8341 | header.reset_flag = false; |
| 8342 | header.version_flag = false; |
| 8343 | header.packet_number = kPacketNumber; |
| 8344 | |
| 8345 | QuicWindowUpdateFrame window_update_frame; |
| 8346 | window_update_frame.stream_id = kStreamId; |
| 8347 | window_update_frame.byte_offset = 0x1122334455667788; |
| 8348 | |
| 8349 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8350 | |
| 8351 | // clang-format off |
| 8352 | unsigned char packet99[] = { |
| 8353 | // type (short header, 4 byte packet number) |
| 8354 | 0x43, |
| 8355 | // connection_id |
| 8356 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8357 | // packet number |
| 8358 | 0x12, 0x34, 0x56, 0x78, |
| 8359 | |
| 8360 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 8361 | 0x11, |
| 8362 | // stream id |
| 8363 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 8364 | // byte offset |
| 8365 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8366 | 0x55, 0x66, 0x77, 0x88, |
| 8367 | }; |
| 8368 | // clang-format on |
| 8369 | |
| 8370 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8371 | ASSERT_TRUE(data != nullptr); |
| 8372 | |
| 8373 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8374 | data->length(), AsChars(packet99), |
| 8375 | QUIC_ARRAYSIZE(packet99)); |
| 8376 | } |
| 8377 | |
| 8378 | TEST_P(QuicFramerTest, BuildMaxDataPacket) { |
| 8379 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8380 | // This frame is available only in this version. |
| 8381 | return; |
| 8382 | } |
| 8383 | QuicPacketHeader header; |
| 8384 | header.destination_connection_id = FramerTestConnectionId(); |
| 8385 | header.reset_flag = false; |
| 8386 | header.version_flag = false; |
| 8387 | header.packet_number = kPacketNumber; |
| 8388 | |
| 8389 | QuicWindowUpdateFrame window_update_frame; |
| 8390 | window_update_frame.stream_id = |
| 8391 | QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 8392 | window_update_frame.byte_offset = 0x1122334455667788; |
| 8393 | |
| 8394 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8395 | |
| 8396 | // clang-format off |
| 8397 | unsigned char packet99[] = { |
| 8398 | // type (short header, 4 byte packet number) |
| 8399 | 0x43, |
| 8400 | // connection_id |
| 8401 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8402 | // packet number |
| 8403 | 0x12, 0x34, 0x56, 0x78, |
| 8404 | |
| 8405 | // frame type (IETF_MAX_DATA frame) |
| 8406 | 0x10, |
| 8407 | // byte offset |
| 8408 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8409 | 0x55, 0x66, 0x77, 0x88, |
| 8410 | }; |
| 8411 | // clang-format on |
| 8412 | |
| 8413 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8414 | ASSERT_TRUE(data != nullptr); |
| 8415 | |
| 8416 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8417 | data->length(), AsChars(packet99), |
| 8418 | QUIC_ARRAYSIZE(packet99)); |
| 8419 | } |
| 8420 | |
| 8421 | TEST_P(QuicFramerTest, BuildBlockedPacket) { |
| 8422 | QuicPacketHeader header; |
| 8423 | header.destination_connection_id = FramerTestConnectionId(); |
| 8424 | header.reset_flag = false; |
| 8425 | header.version_flag = false; |
| 8426 | header.packet_number = kPacketNumber; |
| 8427 | |
| 8428 | QuicBlockedFrame blocked_frame; |
| 8429 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8430 | // For V99, the stream ID must be <invalid> for the frame |
| 8431 | // to be a BLOCKED frame. if it's valid, it will be a |
| 8432 | // STREAM_BLOCKED frame. |
| 8433 | blocked_frame.stream_id = |
| 8434 | QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 8435 | } else { |
| 8436 | blocked_frame.stream_id = kStreamId; |
| 8437 | } |
| 8438 | blocked_frame.offset = kStreamOffset; |
| 8439 | |
| 8440 | QuicFrames frames = {QuicFrame(&blocked_frame)}; |
| 8441 | |
| 8442 | // clang-format off |
| 8443 | unsigned char packet[] = { |
| 8444 | // public flags (8 byte connection_id) |
| 8445 | 0x28, |
| 8446 | // connection_id |
| 8447 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8448 | // packet number |
| 8449 | 0x12, 0x34, 0x56, 0x78, |
| 8450 | |
| 8451 | // frame type (blocked frame) |
| 8452 | 0x05, |
| 8453 | // stream id |
| 8454 | 0x01, 0x02, 0x03, 0x04, |
| 8455 | }; |
| 8456 | |
| 8457 | unsigned char packet44[] = { |
| 8458 | // type (short packet, 4 byte packet number) |
| 8459 | 0x32, |
| 8460 | // connection_id |
| 8461 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8462 | // packet number |
| 8463 | 0x12, 0x34, 0x56, 0x78, |
| 8464 | |
| 8465 | // frame type (blocked frame) |
| 8466 | 0x05, |
| 8467 | // stream id |
| 8468 | 0x01, 0x02, 0x03, 0x04, |
| 8469 | }; |
| 8470 | |
| 8471 | unsigned char packet46[] = { |
| 8472 | // type (short packet, 4 byte packet number) |
| 8473 | 0x43, |
| 8474 | // connection_id |
| 8475 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8476 | // packet number |
| 8477 | 0x12, 0x34, 0x56, 0x78, |
| 8478 | |
| 8479 | // frame type (blocked frame) |
| 8480 | 0x05, |
| 8481 | // stream id |
| 8482 | 0x01, 0x02, 0x03, 0x04, |
| 8483 | }; |
| 8484 | |
| 8485 | unsigned char packet99[] = { |
| 8486 | // type (short packet, 4 byte packet number) |
| 8487 | 0x43, |
| 8488 | // connection_id |
| 8489 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8490 | // packet number |
| 8491 | 0x12, 0x34, 0x56, 0x78, |
| 8492 | |
| 8493 | // frame type (IETF_BLOCKED frame) |
| 8494 | 0x14, |
| 8495 | // Offset |
| 8496 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 8497 | }; |
| 8498 | // clang-format on |
| 8499 | |
| 8500 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8501 | ASSERT_TRUE(data != nullptr); |
| 8502 | |
| 8503 | unsigned char* p = packet; |
| 8504 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 8505 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8506 | p = packet99; |
| 8507 | p_size = QUIC_ARRAYSIZE(packet99); |
| 8508 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8509 | p = packet46; |
| 8510 | p_size = QUIC_ARRAYSIZE(packet46); |
| 8511 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8512 | p = packet44; |
| 8513 | p_size = QUIC_ARRAYSIZE(packet44); |
| 8514 | } |
| 8515 | |
| 8516 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8517 | data->length(), AsChars(p), p_size); |
| 8518 | } |
| 8519 | |
| 8520 | TEST_P(QuicFramerTest, BuildPingPacket) { |
| 8521 | QuicPacketHeader header; |
| 8522 | header.destination_connection_id = FramerTestConnectionId(); |
| 8523 | header.reset_flag = false; |
| 8524 | header.version_flag = false; |
| 8525 | header.packet_number = kPacketNumber; |
| 8526 | |
| 8527 | QuicFrames frames = {QuicFrame(QuicPingFrame())}; |
| 8528 | |
| 8529 | // clang-format off |
| 8530 | unsigned char packet[] = { |
| 8531 | // public flags (8 byte connection_id) |
| 8532 | 0x28, |
| 8533 | // connection_id |
| 8534 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8535 | // packet number |
| 8536 | 0x12, 0x34, 0x56, 0x78, |
| 8537 | |
| 8538 | // frame type (ping frame) |
| 8539 | 0x07, |
| 8540 | }; |
| 8541 | |
| 8542 | unsigned char packet44[] = { |
| 8543 | // type (short header, 4 byte packet number) |
| 8544 | 0x32, |
| 8545 | // connection_id |
| 8546 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8547 | // packet number |
| 8548 | 0x12, 0x34, 0x56, 0x78, |
| 8549 | |
| 8550 | // frame type |
| 8551 | 0x07, |
| 8552 | }; |
| 8553 | |
| 8554 | unsigned char packet46[] = { |
| 8555 | // type (short header, 4 byte packet number) |
| 8556 | 0x43, |
| 8557 | // connection_id |
| 8558 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8559 | // packet number |
| 8560 | 0x12, 0x34, 0x56, 0x78, |
| 8561 | |
| 8562 | // frame type |
| 8563 | 0x07, |
| 8564 | }; |
| 8565 | |
| 8566 | unsigned char packet99[] = { |
| 8567 | // type (short header, 4 byte packet number) |
| 8568 | 0x43, |
| 8569 | // connection_id |
| 8570 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8571 | // packet number |
| 8572 | 0x12, 0x34, 0x56, 0x78, |
| 8573 | |
| 8574 | // frame type (IETF_PING frame) |
| 8575 | 0x01, |
| 8576 | }; |
| 8577 | // clang-format on |
| 8578 | |
| 8579 | unsigned char* p = packet; |
| 8580 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8581 | p = packet99; |
| 8582 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8583 | p = packet46; |
| 8584 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8585 | p = packet44; |
| 8586 | } |
| 8587 | |
| 8588 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8589 | ASSERT_TRUE(data != nullptr); |
| 8590 | |
| 8591 | test::CompareCharArraysWithHexError( |
| 8592 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 8593 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 8594 | : QUIC_ARRAYSIZE(packet)); |
| 8595 | } |
| 8596 | |
| 8597 | TEST_P(QuicFramerTest, BuildMessagePacket) { |
| 8598 | if (framer_.transport_version() <= QUIC_VERSION_44) { |
| 8599 | return; |
| 8600 | } |
| 8601 | QuicPacketHeader header; |
| 8602 | header.destination_connection_id = FramerTestConnectionId(); |
| 8603 | header.reset_flag = false; |
| 8604 | header.version_flag = false; |
| 8605 | header.packet_number = kPacketNumber; |
| 8606 | QuicMemSliceStorage storage(nullptr, 0, nullptr, 0); |
| 8607 | |
wub | 553a966 | 2019-03-28 20:13:23 -0700 | [diff] [blame] | 8608 | QuicMessageFrame frame(1, MakeSpan(&allocator_, "message", &storage)); |
| 8609 | QuicMessageFrame frame2(2, MakeSpan(&allocator_, "message2", &storage)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8610 | QuicFrames frames = {QuicFrame(&frame), QuicFrame(&frame2)}; |
| 8611 | |
| 8612 | // clang-format off |
| 8613 | unsigned char packet45[] = { |
| 8614 | // type (short header, 4 byte packet number) |
| 8615 | 0x32, |
| 8616 | // connection_id |
| 8617 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8618 | // packet number |
| 8619 | 0x12, 0x34, 0x56, 0x78, |
| 8620 | |
| 8621 | // frame type (message frame) |
| 8622 | 0x21, |
| 8623 | // Length |
| 8624 | 0x07, |
| 8625 | // Message Data |
| 8626 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 8627 | // frame type (message frame no length) |
| 8628 | 0x20, |
| 8629 | // Message Data |
| 8630 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 8631 | }; |
| 8632 | |
| 8633 | unsigned char packet46[] = { |
| 8634 | // type (short header, 4 byte packet number) |
| 8635 | 0x43, |
| 8636 | // connection_id |
| 8637 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8638 | // packet number |
| 8639 | 0x12, 0x34, 0x56, 0x78, |
| 8640 | |
| 8641 | // frame type (message frame) |
| 8642 | 0x21, |
| 8643 | // Length |
| 8644 | 0x07, |
| 8645 | // Message Data |
| 8646 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 8647 | // frame type (message frame no length) |
| 8648 | 0x20, |
| 8649 | // Message Data |
| 8650 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 8651 | }; |
| 8652 | |
| 8653 | unsigned char packet99[] = { |
| 8654 | // type (short header, 4 byte packet number) |
| 8655 | 0x43, |
| 8656 | // connection_id |
| 8657 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8658 | // packet number |
| 8659 | 0x12, 0x34, 0x56, 0x78, |
| 8660 | |
| 8661 | // frame type (IETF_MESSAGE frame) |
| 8662 | 0x21, |
| 8663 | // Length |
| 8664 | 0x07, |
| 8665 | // Message Data |
| 8666 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 8667 | // frame type (message frame no length) |
| 8668 | 0x20, |
| 8669 | // Message Data |
| 8670 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 8671 | }; |
| 8672 | // clang-format on |
| 8673 | |
| 8674 | unsigned char* p = packet45; |
| 8675 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8676 | p = packet99; |
| 8677 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8678 | p = packet46; |
| 8679 | } |
| 8680 | |
| 8681 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8682 | ASSERT_TRUE(data != nullptr); |
| 8683 | |
| 8684 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8685 | data->length(), AsChars(p), |
| 8686 | QUIC_ARRAYSIZE(packet45)); |
| 8687 | } |
| 8688 | |
| 8689 | // Test that the connectivity probing packet is serialized correctly as a |
| 8690 | // padded PING packet. |
| 8691 | TEST_P(QuicFramerTest, BuildConnectivityProbingPacket) { |
| 8692 | QuicPacketHeader header; |
| 8693 | header.destination_connection_id = FramerTestConnectionId(); |
| 8694 | header.reset_flag = false; |
| 8695 | header.version_flag = false; |
| 8696 | header.packet_number = kPacketNumber; |
| 8697 | |
| 8698 | // clang-format off |
| 8699 | unsigned char packet[] = { |
| 8700 | // public flags (8 byte connection_id) |
| 8701 | 0x28, |
| 8702 | // connection_id |
| 8703 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8704 | // packet number |
| 8705 | 0x12, 0x34, 0x56, 0x78, |
| 8706 | |
| 8707 | // frame type (ping frame) |
| 8708 | 0x07, |
| 8709 | // frame type (padding frame) |
| 8710 | 0x00, |
| 8711 | 0x00, 0x00, 0x00, 0x00 |
| 8712 | }; |
| 8713 | |
| 8714 | unsigned char packet44[] = { |
| 8715 | // type (short header, 4 byte packet number) |
| 8716 | 0x32, |
| 8717 | // connection_id |
| 8718 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8719 | // packet number |
| 8720 | 0x12, 0x34, 0x56, 0x78, |
| 8721 | |
| 8722 | // frame type |
| 8723 | 0x07, |
| 8724 | // frame type (padding frame) |
| 8725 | 0x00, |
| 8726 | 0x00, 0x00, 0x00, 0x00 |
| 8727 | }; |
| 8728 | |
| 8729 | unsigned char packet46[] = { |
| 8730 | // type (short header, 4 byte packet number) |
| 8731 | 0x43, |
| 8732 | // connection_id |
| 8733 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8734 | // packet number |
| 8735 | 0x12, 0x34, 0x56, 0x78, |
| 8736 | |
| 8737 | // frame type |
| 8738 | 0x07, |
| 8739 | // frame type (padding frame) |
| 8740 | 0x00, |
| 8741 | 0x00, 0x00, 0x00, 0x00 |
| 8742 | }; |
| 8743 | |
| 8744 | unsigned char packet99[] = { |
| 8745 | // type (short header, 4 byte packet number) |
| 8746 | 0x43, |
| 8747 | // connection_id |
| 8748 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8749 | // packet number |
| 8750 | 0x12, 0x34, 0x56, 0x78, |
| 8751 | |
| 8752 | // frame type (IETF_PING frame) |
| 8753 | 0x01, |
| 8754 | // frame type (padding frame) |
| 8755 | 0x00, |
| 8756 | 0x00, 0x00, 0x00, 0x00 |
| 8757 | }; |
| 8758 | // clang-format on |
| 8759 | |
| 8760 | unsigned char* p = packet; |
| 8761 | size_t packet_size = QUIC_ARRAYSIZE(packet); |
| 8762 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8763 | p = packet99; |
| 8764 | packet_size = QUIC_ARRAYSIZE(packet99); |
| 8765 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8766 | p = packet46; |
| 8767 | packet_size = QUIC_ARRAYSIZE(packet46); |
| 8768 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8769 | p = packet44; |
| 8770 | packet_size = QUIC_ARRAYSIZE(packet44); |
| 8771 | } |
| 8772 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8773 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8774 | |
| 8775 | size_t length = framer_.BuildConnectivityProbingPacket( |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 8776 | header, buffer.get(), packet_size, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8777 | |
| 8778 | EXPECT_NE(0u, length); |
| 8779 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 8780 | header); |
| 8781 | |
| 8782 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 8783 | data.length(), AsChars(p), packet_size); |
| 8784 | } |
| 8785 | |
| 8786 | // Test that the path challenge connectivity probing packet is serialized |
| 8787 | // correctly as a padded PATH CHALLENGE packet. |
| 8788 | TEST_P(QuicFramerTest, BuildPaddedPathChallengePacket) { |
| 8789 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8790 | return; |
| 8791 | } |
| 8792 | |
| 8793 | QuicPacketHeader header; |
| 8794 | header.destination_connection_id = FramerTestConnectionId(); |
| 8795 | header.reset_flag = false; |
| 8796 | header.version_flag = false; |
| 8797 | header.packet_number = kPacketNumber; |
| 8798 | QuicPathFrameBuffer payload; |
| 8799 | |
| 8800 | // clang-format off |
| 8801 | unsigned char packet[] = { |
| 8802 | // type (short header, 4 byte packet number) |
| 8803 | 0x43, |
| 8804 | // connection_id |
| 8805 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8806 | // packet number |
| 8807 | 0x12, 0x34, 0x56, 0x78, |
| 8808 | |
| 8809 | // Path Challenge Frame type (IETF_PATH_CHALLENGE) |
| 8810 | 0x1a, |
| 8811 | // 8 "random" bytes, MockRandom makes lots of r's |
| 8812 | 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', |
| 8813 | // frame type (padding frame) |
| 8814 | 0x00, |
| 8815 | 0x00, 0x00, 0x00, 0x00 |
| 8816 | }; |
| 8817 | // clang-format on |
| 8818 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8819 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8820 | MockRandom randomizer; |
| 8821 | |
| 8822 | size_t length = framer_.BuildPaddedPathChallengePacket( |
| 8823 | header, buffer.get(), QUIC_ARRAYSIZE(packet), &payload, &randomizer, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 8824 | ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8825 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 8826 | |
| 8827 | // Payload has the random bytes that were generated. Copy them into packet, |
| 8828 | // above, before checking that the generated packet is correct. |
| 8829 | EXPECT_EQ(kQuicPathFrameBufferSize, payload.size()); |
| 8830 | |
| 8831 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 8832 | header); |
| 8833 | |
| 8834 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 8835 | data.length(), AsChars(packet), |
| 8836 | QUIC_ARRAYSIZE(packet)); |
| 8837 | } |
| 8838 | |
| 8839 | // Several tests that the path response connectivity probing packet is |
| 8840 | // serialized correctly as either a padded and unpadded PATH RESPONSE |
| 8841 | // packet. Also generates packets with 1 and 3 PATH_RESPONSES in them to |
| 8842 | // exercised the single- and multiple- payload cases. |
| 8843 | TEST_P(QuicFramerTest, BuildPathResponsePacket1ResponseUnpadded) { |
| 8844 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8845 | return; |
| 8846 | } |
| 8847 | |
| 8848 | QuicPacketHeader header; |
| 8849 | header.destination_connection_id = FramerTestConnectionId(); |
| 8850 | header.reset_flag = false; |
| 8851 | header.version_flag = false; |
| 8852 | header.packet_number = kPacketNumber; |
| 8853 | QuicPathFrameBuffer payload0 = { |
| 8854 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 8855 | |
| 8856 | // Build 1 PATH RESPONSE, not padded |
| 8857 | // clang-format off |
| 8858 | unsigned char packet[] = { |
| 8859 | // type (short header, 4 byte packet number) |
| 8860 | 0x43, |
| 8861 | // connection_id |
| 8862 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8863 | // packet number |
| 8864 | 0x12, 0x34, 0x56, 0x78, |
| 8865 | |
| 8866 | // Path Response Frame type (IETF_PATH_RESPONSE) |
| 8867 | 0x1b, |
| 8868 | // 8 "random" bytes |
| 8869 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 8870 | }; |
| 8871 | // clang-format on |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8872 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8873 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 8874 | payloads.push_back(payload0); |
| 8875 | size_t length = framer_.BuildPathResponsePacket( |
| 8876 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 8877 | /*is_padded=*/false, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8878 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 8879 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 8880 | header); |
| 8881 | |
| 8882 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 8883 | data.length(), AsChars(packet), |
| 8884 | QUIC_ARRAYSIZE(packet)); |
| 8885 | } |
| 8886 | |
| 8887 | TEST_P(QuicFramerTest, BuildPathResponsePacket1ResponsePadded) { |
| 8888 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8889 | return; |
| 8890 | } |
| 8891 | |
| 8892 | QuicPacketHeader header; |
| 8893 | header.destination_connection_id = FramerTestConnectionId(); |
| 8894 | header.reset_flag = false; |
| 8895 | header.version_flag = false; |
| 8896 | header.packet_number = kPacketNumber; |
| 8897 | QuicPathFrameBuffer payload0 = { |
| 8898 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 8899 | |
| 8900 | // Build 1 PATH RESPONSE, padded |
| 8901 | // clang-format off |
| 8902 | unsigned char packet[] = { |
| 8903 | // type (short header, 4 byte packet number) |
| 8904 | 0x43, |
| 8905 | // connection_id |
| 8906 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8907 | // packet number |
| 8908 | 0x12, 0x34, 0x56, 0x78, |
| 8909 | |
| 8910 | // Path Response Frame type (IETF_PATH_RESPONSE) |
| 8911 | 0x1b, |
| 8912 | // 8 "random" bytes |
| 8913 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 8914 | // Padding type and pad |
| 8915 | 0x00, 0x00, 0x00, 0x00, 0x00 |
| 8916 | }; |
| 8917 | // clang-format on |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8918 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8919 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 8920 | payloads.push_back(payload0); |
| 8921 | size_t length = framer_.BuildPathResponsePacket( |
| 8922 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 8923 | /*is_padded=*/true, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8924 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 8925 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 8926 | header); |
| 8927 | |
| 8928 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 8929 | data.length(), AsChars(packet), |
| 8930 | QUIC_ARRAYSIZE(packet)); |
| 8931 | } |
| 8932 | |
| 8933 | TEST_P(QuicFramerTest, BuildPathResponsePacket3ResponsesUnpadded) { |
| 8934 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8935 | return; |
| 8936 | } |
| 8937 | |
| 8938 | QuicPacketHeader header; |
| 8939 | header.destination_connection_id = FramerTestConnectionId(); |
| 8940 | header.reset_flag = false; |
| 8941 | header.version_flag = false; |
| 8942 | header.packet_number = kPacketNumber; |
| 8943 | QuicPathFrameBuffer payload0 = { |
| 8944 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 8945 | QuicPathFrameBuffer payload1 = { |
| 8946 | {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}}; |
| 8947 | QuicPathFrameBuffer payload2 = { |
| 8948 | {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28}}; |
| 8949 | |
| 8950 | // Build one packet with 3 PATH RESPONSES, no padding |
| 8951 | // clang-format off |
| 8952 | unsigned char packet[] = { |
| 8953 | // type (short header, 4 byte packet number) |
| 8954 | 0x43, |
| 8955 | // connection_id |
| 8956 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8957 | // packet number |
| 8958 | 0x12, 0x34, 0x56, 0x78, |
| 8959 | |
| 8960 | // 3 path response frames (IETF_PATH_RESPONSE type byte and payload) |
| 8961 | 0x1b, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 8962 | 0x1b, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, |
| 8963 | 0x1b, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, |
| 8964 | }; |
| 8965 | // clang-format on |
| 8966 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8967 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8968 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 8969 | payloads.push_back(payload0); |
| 8970 | payloads.push_back(payload1); |
| 8971 | payloads.push_back(payload2); |
| 8972 | size_t length = framer_.BuildPathResponsePacket( |
| 8973 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 8974 | /*is_padded=*/false, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8975 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 8976 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 8977 | header); |
| 8978 | |
| 8979 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 8980 | data.length(), AsChars(packet), |
| 8981 | QUIC_ARRAYSIZE(packet)); |
| 8982 | } |
| 8983 | |
| 8984 | TEST_P(QuicFramerTest, BuildPathResponsePacket3ResponsesPadded) { |
| 8985 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8986 | return; |
| 8987 | } |
| 8988 | |
| 8989 | QuicPacketHeader header; |
| 8990 | header.destination_connection_id = FramerTestConnectionId(); |
| 8991 | header.reset_flag = false; |
| 8992 | header.version_flag = false; |
| 8993 | header.packet_number = kPacketNumber; |
| 8994 | QuicPathFrameBuffer payload0 = { |
| 8995 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 8996 | QuicPathFrameBuffer payload1 = { |
| 8997 | {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}}; |
| 8998 | QuicPathFrameBuffer payload2 = { |
| 8999 | {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28}}; |
| 9000 | |
| 9001 | // Build one packet with 3 PATH RESPONSES, with padding |
| 9002 | // clang-format off |
| 9003 | unsigned char packet[] = { |
| 9004 | // type (short header, 4 byte packet number) |
| 9005 | 0x43, |
| 9006 | // connection_id |
| 9007 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9008 | // packet number |
| 9009 | 0x12, 0x34, 0x56, 0x78, |
| 9010 | |
| 9011 | // 3 path response frames (IETF_PATH_RESPONSE byte and payload) |
| 9012 | 0x1b, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 9013 | 0x1b, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, |
| 9014 | 0x1b, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, |
| 9015 | // Padding |
| 9016 | 0x00, 0x00, 0x00, 0x00, 0x00 |
| 9017 | }; |
| 9018 | // clang-format on |
| 9019 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9020 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9021 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 9022 | payloads.push_back(payload0); |
| 9023 | payloads.push_back(payload1); |
| 9024 | payloads.push_back(payload2); |
| 9025 | size_t length = framer_.BuildPathResponsePacket( |
| 9026 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9027 | /*is_padded=*/true, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9028 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 9029 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 9030 | header); |
| 9031 | |
| 9032 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 9033 | data.length(), AsChars(packet), |
| 9034 | QUIC_ARRAYSIZE(packet)); |
| 9035 | } |
| 9036 | |
| 9037 | // Test that the MTU discovery packet is serialized correctly as a PING packet. |
| 9038 | TEST_P(QuicFramerTest, BuildMtuDiscoveryPacket) { |
| 9039 | QuicPacketHeader header; |
| 9040 | header.destination_connection_id = FramerTestConnectionId(); |
| 9041 | header.reset_flag = false; |
| 9042 | header.version_flag = false; |
| 9043 | header.packet_number = kPacketNumber; |
| 9044 | |
| 9045 | QuicFrames frames = {QuicFrame(QuicMtuDiscoveryFrame())}; |
| 9046 | |
| 9047 | // clang-format off |
| 9048 | unsigned char packet[] = { |
| 9049 | // public flags (8 byte connection_id) |
| 9050 | 0x28, |
| 9051 | // connection_id |
| 9052 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9053 | // packet number |
| 9054 | 0x12, 0x34, 0x56, 0x78, |
| 9055 | |
| 9056 | // frame type (ping frame) |
| 9057 | 0x07, |
| 9058 | }; |
| 9059 | |
| 9060 | unsigned char packet44[] = { |
| 9061 | // type (short header, 4 byte packet number) |
| 9062 | 0x32, |
| 9063 | // connection_id |
| 9064 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9065 | // packet number |
| 9066 | 0x12, 0x34, 0x56, 0x78, |
| 9067 | |
| 9068 | // frame type |
| 9069 | 0x07, |
| 9070 | }; |
| 9071 | |
| 9072 | unsigned char packet46[] = { |
| 9073 | // type (short header, 4 byte packet number) |
| 9074 | 0x43, |
| 9075 | // connection_id |
| 9076 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9077 | // packet number |
| 9078 | 0x12, 0x34, 0x56, 0x78, |
| 9079 | |
| 9080 | // frame type |
| 9081 | 0x07, |
| 9082 | }; |
| 9083 | |
| 9084 | unsigned char packet99[] = { |
| 9085 | // type (short header, 4 byte packet number) |
| 9086 | 0x43, |
| 9087 | // connection_id |
| 9088 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9089 | // packet number |
| 9090 | 0x12, 0x34, 0x56, 0x78, |
| 9091 | |
| 9092 | // frame type (IETF_PING frame) |
| 9093 | 0x01, |
| 9094 | }; |
| 9095 | // clang-format on |
| 9096 | |
| 9097 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 9098 | ASSERT_TRUE(data != nullptr); |
| 9099 | |
| 9100 | unsigned char* p = packet; |
| 9101 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9102 | p = packet99; |
| 9103 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 9104 | p = packet46; |
| 9105 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9106 | p = packet44; |
| 9107 | } |
| 9108 | |
| 9109 | test::CompareCharArraysWithHexError( |
| 9110 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 9111 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 9112 | : QUIC_ARRAYSIZE(packet)); |
| 9113 | } |
| 9114 | |
| 9115 | TEST_P(QuicFramerTest, BuildPublicResetPacket) { |
| 9116 | QuicPublicResetPacket reset_packet; |
| 9117 | reset_packet.connection_id = FramerTestConnectionId(); |
| 9118 | reset_packet.nonce_proof = kNonceProof; |
| 9119 | |
| 9120 | // clang-format off |
| 9121 | unsigned char packet[] = { |
| 9122 | // public flags (public reset, 8 byte ConnectionId) |
| 9123 | 0x0E, |
| 9124 | // connection_id |
| 9125 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9126 | // message tag (kPRST) |
| 9127 | 'P', 'R', 'S', 'T', |
| 9128 | // num_entries (1) + padding |
| 9129 | 0x01, 0x00, 0x00, 0x00, |
| 9130 | // tag kRNON |
| 9131 | 'R', 'N', 'O', 'N', |
| 9132 | // end offset 8 |
| 9133 | 0x08, 0x00, 0x00, 0x00, |
| 9134 | // nonce proof |
| 9135 | 0x89, 0x67, 0x45, 0x23, |
| 9136 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9137 | }; |
| 9138 | // clang-format on |
| 9139 | |
| 9140 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9141 | return; |
| 9142 | } |
| 9143 | |
| 9144 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9145 | framer_.BuildPublicResetPacket(reset_packet)); |
| 9146 | ASSERT_TRUE(data != nullptr); |
| 9147 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 9148 | data->length(), AsChars(packet), |
| 9149 | QUIC_ARRAYSIZE(packet)); |
| 9150 | } |
| 9151 | |
| 9152 | TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) { |
| 9153 | QuicPublicResetPacket reset_packet; |
| 9154 | reset_packet.connection_id = FramerTestConnectionId(); |
| 9155 | reset_packet.nonce_proof = kNonceProof; |
| 9156 | reset_packet.client_address = |
| 9157 | QuicSocketAddress(QuicIpAddress::Loopback4(), 0x1234); |
| 9158 | |
| 9159 | // clang-format off |
| 9160 | unsigned char packet[] = { |
| 9161 | // public flags (public reset, 8 byte ConnectionId) |
| 9162 | 0x0E, |
| 9163 | // connection_id |
| 9164 | 0xFE, 0xDC, 0xBA, 0x98, |
| 9165 | 0x76, 0x54, 0x32, 0x10, |
| 9166 | // message tag (kPRST) |
| 9167 | 'P', 'R', 'S', 'T', |
| 9168 | // num_entries (2) + padding |
| 9169 | 0x02, 0x00, 0x00, 0x00, |
| 9170 | // tag kRNON |
| 9171 | 'R', 'N', 'O', 'N', |
| 9172 | // end offset 8 |
| 9173 | 0x08, 0x00, 0x00, 0x00, |
| 9174 | // tag kCADR |
| 9175 | 'C', 'A', 'D', 'R', |
| 9176 | // end offset 16 |
| 9177 | 0x10, 0x00, 0x00, 0x00, |
| 9178 | // nonce proof |
| 9179 | 0x89, 0x67, 0x45, 0x23, |
| 9180 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9181 | // client address |
| 9182 | 0x02, 0x00, |
| 9183 | 0x7F, 0x00, 0x00, 0x01, |
| 9184 | 0x34, 0x12, |
| 9185 | }; |
| 9186 | // clang-format on |
| 9187 | |
| 9188 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9189 | return; |
| 9190 | } |
| 9191 | |
| 9192 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9193 | framer_.BuildPublicResetPacket(reset_packet)); |
| 9194 | ASSERT_TRUE(data != nullptr); |
| 9195 | |
| 9196 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 9197 | data->length(), AsChars(packet), |
| 9198 | QUIC_ARRAYSIZE(packet)); |
| 9199 | } |
| 9200 | |
| 9201 | TEST_P(QuicFramerTest, BuildPublicResetPacketWithEndpointId) { |
| 9202 | QuicPublicResetPacket reset_packet; |
| 9203 | reset_packet.connection_id = FramerTestConnectionId(); |
| 9204 | reset_packet.nonce_proof = kNonceProof; |
| 9205 | reset_packet.endpoint_id = "FakeServerId"; |
| 9206 | |
| 9207 | // The tag value map in CryptoHandshakeMessage is a std::map, so the two tags |
| 9208 | // in the packet, kRNON and kEPID, have unspecified ordering w.r.t each other. |
| 9209 | // clang-format off |
| 9210 | unsigned char packet_variant1[] = { |
| 9211 | // public flags (public reset, 8 byte ConnectionId) |
| 9212 | 0x0E, |
| 9213 | // connection_id |
| 9214 | 0xFE, 0xDC, 0xBA, 0x98, |
| 9215 | 0x76, 0x54, 0x32, 0x10, |
| 9216 | // message tag (kPRST) |
| 9217 | 'P', 'R', 'S', 'T', |
| 9218 | // num_entries (2) + padding |
| 9219 | 0x02, 0x00, 0x00, 0x00, |
| 9220 | // tag kRNON |
| 9221 | 'R', 'N', 'O', 'N', |
| 9222 | // end offset 8 |
| 9223 | 0x08, 0x00, 0x00, 0x00, |
| 9224 | // tag kEPID |
| 9225 | 'E', 'P', 'I', 'D', |
| 9226 | // end offset 20 |
| 9227 | 0x14, 0x00, 0x00, 0x00, |
| 9228 | // nonce proof |
| 9229 | 0x89, 0x67, 0x45, 0x23, |
| 9230 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9231 | // Endpoint ID |
| 9232 | 'F', 'a', 'k', 'e', 'S', 'e', 'r', 'v', 'e', 'r', 'I', 'd', |
| 9233 | }; |
| 9234 | unsigned char packet_variant2[] = { |
| 9235 | // public flags (public reset, 8 byte ConnectionId) |
| 9236 | 0x0E, |
| 9237 | // connection_id |
| 9238 | 0xFE, 0xDC, 0xBA, 0x98, |
| 9239 | 0x76, 0x54, 0x32, 0x10, |
| 9240 | // message tag (kPRST) |
| 9241 | 'P', 'R', 'S', 'T', |
| 9242 | // num_entries (2) + padding |
| 9243 | 0x02, 0x00, 0x00, 0x00, |
| 9244 | // tag kEPID |
| 9245 | 'E', 'P', 'I', 'D', |
| 9246 | // end offset 12 |
| 9247 | 0x0C, 0x00, 0x00, 0x00, |
| 9248 | // tag kRNON |
| 9249 | 'R', 'N', 'O', 'N', |
| 9250 | // end offset 20 |
| 9251 | 0x14, 0x00, 0x00, 0x00, |
| 9252 | // Endpoint ID |
| 9253 | 'F', 'a', 'k', 'e', 'S', 'e', 'r', 'v', 'e', 'r', 'I', 'd', |
| 9254 | // nonce proof |
| 9255 | 0x89, 0x67, 0x45, 0x23, |
| 9256 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9257 | }; |
| 9258 | // clang-format on |
| 9259 | |
| 9260 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9261 | return; |
| 9262 | } |
| 9263 | |
| 9264 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9265 | framer_.BuildPublicResetPacket(reset_packet)); |
| 9266 | ASSERT_TRUE(data != nullptr); |
| 9267 | |
| 9268 | // Variant 1 ends with char 'd'. Variant 1 ends with char 0xAB. |
| 9269 | if ('d' == data->data()[data->length() - 1]) { |
| 9270 | test::CompareCharArraysWithHexError( |
| 9271 | "constructed packet", data->data(), data->length(), |
| 9272 | AsChars(packet_variant1), QUIC_ARRAYSIZE(packet_variant1)); |
| 9273 | } else { |
| 9274 | test::CompareCharArraysWithHexError( |
| 9275 | "constructed packet", data->data(), data->length(), |
| 9276 | AsChars(packet_variant2), QUIC_ARRAYSIZE(packet_variant2)); |
| 9277 | } |
| 9278 | } |
| 9279 | |
| 9280 | TEST_P(QuicFramerTest, BuildIetfStatelessResetPacket) { |
| 9281 | // clang-format off |
| 9282 | unsigned char packet44[] = { |
| 9283 | // type (short header, 1 byte packet number) |
| 9284 | 0x70, |
| 9285 | // random packet number |
| 9286 | 0xFE, |
| 9287 | // stateless reset token |
| 9288 | 0xB5, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 9289 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 9290 | }; |
| 9291 | // clang-format on |
| 9292 | |
| 9293 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9294 | framer_.BuildIetfStatelessResetPacket(FramerTestConnectionId(), |
| 9295 | kTestStatelessResetToken)); |
| 9296 | ASSERT_TRUE(data != nullptr); |
| 9297 | // Skip packet number byte which is random in stateless reset packet. |
| 9298 | test::CompareCharArraysWithHexError("constructed packet", data->data(), 1, |
| 9299 | AsChars(packet44), 1); |
| 9300 | const size_t random_bytes_length = |
| 9301 | data->length() - kPacketHeaderTypeSize - sizeof(kTestStatelessResetToken); |
| 9302 | EXPECT_EQ(kMinRandomBytesLengthInStatelessReset, random_bytes_length); |
| 9303 | // Verify stateless reset token is correct. |
| 9304 | test::CompareCharArraysWithHexError( |
| 9305 | "constructed packet", |
| 9306 | data->data() + data->length() - sizeof(kTestStatelessResetToken), |
| 9307 | sizeof(kTestStatelessResetToken), |
| 9308 | AsChars(packet44) + QUIC_ARRAYSIZE(packet44) - |
| 9309 | sizeof(kTestStatelessResetToken), |
| 9310 | sizeof(kTestStatelessResetToken)); |
| 9311 | } |
| 9312 | |
| 9313 | TEST_P(QuicFramerTest, EncryptPacket) { |
| 9314 | QuicPacketNumber packet_number = kPacketNumber; |
| 9315 | // clang-format off |
| 9316 | unsigned char packet[] = { |
| 9317 | // public flags (8 byte connection_id) |
| 9318 | 0x28, |
| 9319 | // connection_id |
| 9320 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9321 | // packet number |
| 9322 | 0x12, 0x34, 0x56, 0x78, |
| 9323 | |
| 9324 | // redundancy |
| 9325 | 'a', 'b', 'c', 'd', |
| 9326 | 'e', 'f', 'g', 'h', |
| 9327 | 'i', 'j', 'k', 'l', |
| 9328 | 'm', 'n', 'o', 'p', |
| 9329 | }; |
| 9330 | |
| 9331 | unsigned char packet44[] = { |
| 9332 | // type (short header, 4 byte packet number) |
| 9333 | 0x32, |
| 9334 | // connection_id |
| 9335 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9336 | // packet number |
| 9337 | 0x12, 0x34, 0x56, 0x78, |
| 9338 | |
| 9339 | // redundancy |
| 9340 | 'a', 'b', 'c', 'd', |
| 9341 | 'e', 'f', 'g', 'h', |
| 9342 | 'i', 'j', 'k', 'l', |
| 9343 | 'm', 'n', 'o', 'p', |
| 9344 | }; |
| 9345 | |
| 9346 | unsigned char packet46[] = { |
| 9347 | // type (short header, 4 byte packet number) |
| 9348 | 0x43, |
| 9349 | // connection_id |
| 9350 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9351 | // packet number |
| 9352 | 0x12, 0x34, 0x56, 0x78, |
| 9353 | |
| 9354 | // redundancy |
| 9355 | 'a', 'b', 'c', 'd', |
| 9356 | 'e', 'f', 'g', 'h', |
| 9357 | 'i', 'j', 'k', 'l', |
| 9358 | 'm', 'n', 'o', 'p', |
| 9359 | }; |
| 9360 | |
| 9361 | unsigned char packet99[] = { |
| 9362 | // type (short header, 4 byte packet number) |
| 9363 | 0x43, |
| 9364 | // connection_id |
| 9365 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9366 | // packet number |
| 9367 | 0x12, 0x34, 0x56, 0x78, |
| 9368 | |
| 9369 | // redundancy |
| 9370 | 'a', 'b', 'c', 'd', |
| 9371 | 'e', 'f', 'g', 'h', |
| 9372 | 'i', 'j', 'k', 'l', |
| 9373 | 'm', 'n', 'o', 'p', |
| 9374 | }; |
| 9375 | // clang-format on |
| 9376 | |
| 9377 | unsigned char* p = packet; |
| 9378 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9379 | p = packet99; |
| 9380 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 9381 | p = packet46; |
| 9382 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9383 | p = packet44; |
| 9384 | } |
| 9385 | |
| 9386 | std::unique_ptr<QuicPacket> raw(new QuicPacket( |
| 9387 | AsChars(p), QUIC_ARRAYSIZE(packet), false, PACKET_8BYTE_CONNECTION_ID, |
| 9388 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 9389 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 9390 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0)); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9391 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9392 | size_t encrypted_length = framer_.EncryptPayload( |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9393 | ENCRYPTION_INITIAL, packet_number, *raw, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9394 | |
| 9395 | ASSERT_NE(0u, encrypted_length); |
| 9396 | EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); |
| 9397 | } |
| 9398 | |
| 9399 | TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { |
| 9400 | QuicPacketNumber packet_number = kPacketNumber; |
| 9401 | // clang-format off |
| 9402 | unsigned char packet[] = { |
| 9403 | // public flags (version, 8 byte connection_id) |
| 9404 | 0x29, |
| 9405 | // connection_id |
| 9406 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9407 | // version tag |
| 9408 | 'Q', '.', '1', '0', |
| 9409 | // packet number |
| 9410 | 0x12, 0x34, 0x56, 0x78, |
| 9411 | |
| 9412 | // redundancy |
| 9413 | 'a', 'b', 'c', 'd', |
| 9414 | 'e', 'f', 'g', 'h', |
| 9415 | 'i', 'j', 'k', 'l', |
| 9416 | 'm', 'n', 'o', 'p', |
| 9417 | }; |
| 9418 | |
| 9419 | unsigned char packet44[] = { |
| 9420 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 9421 | 0xFC, |
| 9422 | // version tag |
| 9423 | 'Q', '.', '1', '0', |
| 9424 | // connection_id length |
| 9425 | 0x50, |
| 9426 | // connection_id |
| 9427 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9428 | // packet number |
| 9429 | 0x12, 0x34, 0x56, 0x78, |
| 9430 | |
| 9431 | // redundancy |
| 9432 | 'a', 'b', 'c', 'd', |
| 9433 | 'e', 'f', 'g', 'h', |
| 9434 | 'i', 'j', 'k', 'l', |
| 9435 | 'm', 'n', 'o', 'p', |
| 9436 | }; |
| 9437 | |
| 9438 | unsigned char packet46[] = { |
| 9439 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 9440 | 0xD3, |
| 9441 | // version tag |
| 9442 | 'Q', '.', '1', '0', |
| 9443 | // connection_id length |
| 9444 | 0x50, |
| 9445 | // connection_id |
| 9446 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9447 | // packet number |
| 9448 | 0x12, 0x34, 0x56, 0x78, |
| 9449 | |
| 9450 | // redundancy |
| 9451 | 'a', 'b', 'c', 'd', |
| 9452 | 'e', 'f', 'g', 'h', |
| 9453 | 'i', 'j', 'k', 'l', |
| 9454 | 'm', 'n', 'o', 'p', |
| 9455 | }; |
| 9456 | |
| 9457 | unsigned char packet99[] = { |
| 9458 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 9459 | 0xD3, |
| 9460 | // version tag |
| 9461 | 'Q', '.', '1', '0', |
| 9462 | // connection_id length |
| 9463 | 0x50, |
| 9464 | // connection_id |
| 9465 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9466 | // packet number |
| 9467 | 0x12, 0x34, 0x56, 0x78, |
| 9468 | |
| 9469 | // redundancy |
| 9470 | 'a', 'b', 'c', 'd', |
| 9471 | 'e', 'f', 'g', 'h', |
| 9472 | 'i', 'j', 'k', 'l', |
| 9473 | 'm', 'n', 'o', 'p', |
| 9474 | }; |
| 9475 | // clang-format on |
| 9476 | |
| 9477 | unsigned char* p = packet; |
| 9478 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9479 | p = packet99; |
| 9480 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 9481 | p = packet46; |
| 9482 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9483 | p = packet44; |
| 9484 | } |
| 9485 | |
| 9486 | std::unique_ptr<QuicPacket> raw(new QuicPacket( |
| 9487 | AsChars(p), |
| 9488 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 9489 | : QUIC_ARRAYSIZE(packet), |
| 9490 | false, PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID, |
| 9491 | kIncludeVersion, !kIncludeDiversificationNonce, |
| 9492 | PACKET_4BYTE_PACKET_NUMBER, VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, |
| 9493 | VARIABLE_LENGTH_INTEGER_LENGTH_0)); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9494 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9495 | size_t encrypted_length = framer_.EncryptPayload( |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9496 | ENCRYPTION_INITIAL, packet_number, *raw, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9497 | |
| 9498 | ASSERT_NE(0u, encrypted_length); |
| 9499 | EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); |
| 9500 | } |
| 9501 | |
| 9502 | TEST_P(QuicFramerTest, AckTruncationLargePacket) { |
| 9503 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9504 | // This test is not applicable to this version; the range count is |
| 9505 | // effectively unlimited |
| 9506 | return; |
| 9507 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9508 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9509 | |
| 9510 | QuicPacketHeader header; |
| 9511 | header.destination_connection_id = FramerTestConnectionId(); |
| 9512 | header.reset_flag = false; |
| 9513 | header.version_flag = false; |
| 9514 | header.packet_number = kPacketNumber; |
| 9515 | |
| 9516 | QuicAckFrame ack_frame; |
| 9517 | // Create a packet with just the ack. |
| 9518 | ack_frame = MakeAckFrameWithAckBlocks(300, 0u); |
| 9519 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9520 | |
| 9521 | // Build an ack packet with truncation due to limit in number of nack ranges. |
| 9522 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9523 | std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); |
| 9524 | ASSERT_TRUE(raw_ack_packet != nullptr); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9525 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9526 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9527 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9528 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9529 | ASSERT_NE(0u, encrypted_length); |
| 9530 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9531 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9532 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9533 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9534 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 9535 | QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; |
| 9536 | EXPECT_EQ(QuicPacketNumber(600u), LargestAcked(processed_ack_frame)); |
| 9537 | ASSERT_EQ(256u, processed_ack_frame.packets.NumPacketsSlow()); |
| 9538 | EXPECT_EQ(QuicPacketNumber(90u), processed_ack_frame.packets.Min()); |
| 9539 | EXPECT_EQ(QuicPacketNumber(600u), processed_ack_frame.packets.Max()); |
| 9540 | } |
| 9541 | |
| 9542 | TEST_P(QuicFramerTest, AckTruncationSmallPacket) { |
| 9543 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9544 | // This test is not applicable to this version; the range count is |
| 9545 | // effectively unlimited |
| 9546 | return; |
| 9547 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9548 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9549 | |
| 9550 | QuicPacketHeader header; |
| 9551 | header.destination_connection_id = FramerTestConnectionId(); |
| 9552 | header.reset_flag = false; |
| 9553 | header.version_flag = false; |
| 9554 | header.packet_number = kPacketNumber; |
| 9555 | |
| 9556 | // Create a packet with just the ack. |
| 9557 | QuicAckFrame ack_frame; |
| 9558 | ack_frame = MakeAckFrameWithAckBlocks(300, 0u); |
| 9559 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9560 | |
| 9561 | // Build an ack packet with truncation due to limit in number of nack ranges. |
| 9562 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9563 | std::unique_ptr<QuicPacket> raw_ack_packet( |
| 9564 | BuildDataPacket(header, frames, 500)); |
| 9565 | ASSERT_TRUE(raw_ack_packet != nullptr); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9566 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9567 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9568 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9569 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9570 | ASSERT_NE(0u, encrypted_length); |
| 9571 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9572 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9573 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9574 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9575 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 9576 | QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; |
| 9577 | EXPECT_EQ(QuicPacketNumber(600u), LargestAcked(processed_ack_frame)); |
| 9578 | ASSERT_EQ(240u, processed_ack_frame.packets.NumPacketsSlow()); |
| 9579 | EXPECT_EQ(QuicPacketNumber(122u), processed_ack_frame.packets.Min()); |
| 9580 | EXPECT_EQ(QuicPacketNumber(600u), processed_ack_frame.packets.Max()); |
| 9581 | } |
| 9582 | |
| 9583 | TEST_P(QuicFramerTest, CleanTruncation) { |
| 9584 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9585 | // This test is not applicable to this version; the range count is |
| 9586 | // effectively unlimited |
| 9587 | return; |
| 9588 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9589 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9590 | |
| 9591 | QuicPacketHeader header; |
| 9592 | header.destination_connection_id = FramerTestConnectionId(); |
| 9593 | header.reset_flag = false; |
| 9594 | header.version_flag = false; |
| 9595 | header.packet_number = kPacketNumber; |
| 9596 | |
| 9597 | QuicAckFrame ack_frame = InitAckFrame(201); |
| 9598 | |
| 9599 | // Create a packet with just the ack. |
| 9600 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9601 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9602 | std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); |
| 9603 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9604 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9605 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9606 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9607 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9608 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9609 | ASSERT_NE(0u, encrypted_length); |
| 9610 | |
| 9611 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9612 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9613 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9614 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9615 | |
| 9616 | // Test for clean truncation of the ack by comparing the length of the |
| 9617 | // original packets to the re-serialized packets. |
| 9618 | frames.clear(); |
| 9619 | frames.push_back(QuicFrame(visitor_.ack_frames_[0].get())); |
| 9620 | |
| 9621 | size_t original_raw_length = raw_ack_packet->length(); |
| 9622 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9623 | raw_ack_packet = BuildDataPacket(header, frames); |
| 9624 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9625 | EXPECT_EQ(original_raw_length, raw_ack_packet->length()); |
| 9626 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9627 | } |
| 9628 | |
| 9629 | TEST_P(QuicFramerTest, StopPacketProcessing) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9630 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9631 | // clang-format off |
| 9632 | unsigned char packet[] = { |
| 9633 | // public flags (8 byte connection_id) |
| 9634 | 0x28, |
| 9635 | // connection_id |
| 9636 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9637 | // packet number |
| 9638 | 0x12, 0x34, 0x56, 0x78, |
| 9639 | |
| 9640 | // frame type (stream frame with fin) |
| 9641 | 0xFF, |
| 9642 | // stream id |
| 9643 | 0x01, 0x02, 0x03, 0x04, |
| 9644 | // offset |
| 9645 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9646 | 0x32, 0x10, 0x76, 0x54, |
| 9647 | // data length |
| 9648 | 0x00, 0x0c, |
| 9649 | // data |
| 9650 | 'h', 'e', 'l', 'l', |
| 9651 | 'o', ' ', 'w', 'o', |
| 9652 | 'r', 'l', 'd', '!', |
| 9653 | |
| 9654 | // frame type (ack frame) |
| 9655 | 0x40, |
| 9656 | // least packet number awaiting an ack |
| 9657 | 0x12, 0x34, 0x56, 0x78, |
| 9658 | 0x9A, 0xA0, |
| 9659 | // largest observed packet number |
| 9660 | 0x12, 0x34, 0x56, 0x78, |
| 9661 | 0x9A, 0xBF, |
| 9662 | // num missing packets |
| 9663 | 0x01, |
| 9664 | // missing packet |
| 9665 | 0x12, 0x34, 0x56, 0x78, |
| 9666 | 0x9A, 0xBE, |
| 9667 | }; |
| 9668 | |
| 9669 | unsigned char packet44[] = { |
| 9670 | // type (short header, 4 byte packet number) |
| 9671 | 0x32, |
| 9672 | // connection_id |
| 9673 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9674 | // packet number |
| 9675 | 0x12, 0x34, 0x56, 0x78, |
| 9676 | |
| 9677 | // frame type (stream frame with fin) |
| 9678 | 0xFF, |
| 9679 | // stream id |
| 9680 | 0x01, 0x02, 0x03, 0x04, |
| 9681 | // offset |
| 9682 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9683 | 0x32, 0x10, 0x76, 0x54, |
| 9684 | // data length |
| 9685 | 0x00, 0x0c, |
| 9686 | // data |
| 9687 | 'h', 'e', 'l', 'l', |
| 9688 | 'o', ' ', 'w', 'o', |
| 9689 | 'r', 'l', 'd', '!', |
| 9690 | |
| 9691 | // frame type (ack frame) |
| 9692 | 0x40, |
| 9693 | // least packet number awaiting an ack |
| 9694 | 0x12, 0x34, 0x56, 0x78, |
| 9695 | 0x9A, 0xA0, |
| 9696 | // largest observed packet number |
| 9697 | 0x12, 0x34, 0x56, 0x78, |
| 9698 | 0x9A, 0xBF, |
| 9699 | // num missing packets |
| 9700 | 0x01, |
| 9701 | // missing packet |
| 9702 | 0x12, 0x34, 0x56, 0x78, |
| 9703 | 0x9A, 0xBE, |
| 9704 | }; |
| 9705 | |
| 9706 | unsigned char packet46[] = { |
| 9707 | // type (short header, 4 byte packet number) |
| 9708 | 0x43, |
| 9709 | // connection_id |
| 9710 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9711 | // packet number |
| 9712 | 0x12, 0x34, 0x56, 0x78, |
| 9713 | |
| 9714 | // frame type (stream frame with fin) |
| 9715 | 0xFF, |
| 9716 | // stream id |
| 9717 | 0x01, 0x02, 0x03, 0x04, |
| 9718 | // offset |
| 9719 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9720 | 0x32, 0x10, 0x76, 0x54, |
| 9721 | // data length |
| 9722 | 0x00, 0x0c, |
| 9723 | // data |
| 9724 | 'h', 'e', 'l', 'l', |
| 9725 | 'o', ' ', 'w', 'o', |
| 9726 | 'r', 'l', 'd', '!', |
| 9727 | |
| 9728 | // frame type (ack frame) |
| 9729 | 0x40, |
| 9730 | // least packet number awaiting an ack |
| 9731 | 0x12, 0x34, 0x56, 0x78, |
| 9732 | 0x9A, 0xA0, |
| 9733 | // largest observed packet number |
| 9734 | 0x12, 0x34, 0x56, 0x78, |
| 9735 | 0x9A, 0xBF, |
| 9736 | // num missing packets |
| 9737 | 0x01, |
| 9738 | // missing packet |
| 9739 | 0x12, 0x34, 0x56, 0x78, |
| 9740 | 0x9A, 0xBE, |
| 9741 | }; |
| 9742 | |
| 9743 | unsigned char packet99[] = { |
| 9744 | // type (short header, 4 byte packet number) |
| 9745 | 0x43, |
| 9746 | // connection_id |
| 9747 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9748 | // packet number |
| 9749 | 0x12, 0x34, 0x56, 0x78, |
| 9750 | |
| 9751 | // frame type (IETF_STREAM frame with fin, length, and offset bits set) |
| 9752 | 0x08 | 0x01 | 0x02 | 0x04, |
| 9753 | // stream id |
| 9754 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 9755 | // offset |
| 9756 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 9757 | 0x32, 0x10, 0x76, 0x54, |
| 9758 | // data length |
| 9759 | kVarInt62TwoBytes + 0x00, 0x0c, |
| 9760 | // data |
| 9761 | 'h', 'e', 'l', 'l', |
| 9762 | 'o', ' ', 'w', 'o', |
| 9763 | 'r', 'l', 'd', '!', |
| 9764 | |
| 9765 | // frame type (ack frame) |
| 9766 | 0x0d, |
| 9767 | // largest observed packet number |
| 9768 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 9769 | // Delta time |
| 9770 | kVarInt62OneByte + 0x00, |
| 9771 | // Ack Block count |
| 9772 | kVarInt62OneByte + 0x01, |
| 9773 | // First block size (one packet) |
| 9774 | kVarInt62OneByte + 0x00, |
| 9775 | |
| 9776 | // Next gap size & ack. Missing all preceding packets |
| 9777 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 9778 | kVarInt62OneByte + 0x00, |
| 9779 | }; |
| 9780 | // clang-format on |
| 9781 | |
| 9782 | MockFramerVisitor visitor; |
| 9783 | framer_.set_visitor(&visitor); |
| 9784 | EXPECT_CALL(visitor, OnPacket()); |
| 9785 | EXPECT_CALL(visitor, OnPacketHeader(_)); |
| 9786 | EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false)); |
| 9787 | EXPECT_CALL(visitor, OnPacketComplete()); |
| 9788 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); |
| 9789 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)).WillOnce(Return(true)); |
| 9790 | EXPECT_CALL(visitor, OnDecryptedPacket(_)); |
| 9791 | |
| 9792 | unsigned char* p = packet; |
| 9793 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 9794 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9795 | p = packet99; |
| 9796 | p_size = QUIC_ARRAYSIZE(packet99); |
| 9797 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 9798 | p = packet46; |
| 9799 | p_size = QUIC_ARRAYSIZE(packet46); |
| 9800 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9801 | p = packet44; |
| 9802 | p_size = QUIC_ARRAYSIZE(packet44); |
| 9803 | } |
| 9804 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 9805 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 9806 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9807 | } |
| 9808 | |
| 9809 | static char kTestString[] = "At least 20 characters."; |
| 9810 | static QuicStreamId kTestQuicStreamId = 1; |
| 9811 | static bool ExpectedStreamFrame(const QuicStreamFrame& frame) { |
| 9812 | return (frame.stream_id == kTestQuicStreamId || |
| 9813 | frame.stream_id == QuicUtils::GetCryptoStreamId(QUIC_VERSION_99)) && |
| 9814 | !frame.fin && frame.offset == 0 && |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 9815 | std::string(frame.data_buffer, frame.data_length) == kTestString; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9816 | // FIN is hard-coded false in ConstructEncryptedPacket. |
| 9817 | // Offset 0 is hard-coded in ConstructEncryptedPacket. |
| 9818 | } |
| 9819 | |
| 9820 | // Verify that the packet returned by ConstructEncryptedPacket() can be properly |
| 9821 | // parsed by the framer. |
| 9822 | TEST_P(QuicFramerTest, ConstructEncryptedPacket) { |
| 9823 | // Since we are using ConstructEncryptedPacket, we have to set the framer's |
| 9824 | // crypto to be Null. |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9825 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 9826 | framer_.InstallDecrypter( |
| 9827 | ENCRYPTION_FORWARD_SECURE, |
| 9828 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
| 9829 | } else { |
| 9830 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 9831 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
| 9832 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9833 | ParsedQuicVersionVector versions; |
| 9834 | versions.push_back(framer_.version()); |
| 9835 | std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
| 9836 | TestConnectionId(), EmptyQuicConnectionId(), false, false, |
| 9837 | kTestQuicStreamId, kTestString, CONNECTION_ID_PRESENT, |
| 9838 | CONNECTION_ID_ABSENT, PACKET_4BYTE_PACKET_NUMBER, &versions)); |
| 9839 | |
| 9840 | MockFramerVisitor visitor; |
| 9841 | framer_.set_visitor(&visitor); |
| 9842 | EXPECT_CALL(visitor, OnPacket()).Times(1); |
| 9843 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) |
| 9844 | .Times(1) |
| 9845 | .WillOnce(Return(true)); |
| 9846 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) |
| 9847 | .Times(1) |
| 9848 | .WillOnce(Return(true)); |
| 9849 | EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1).WillOnce(Return(true)); |
| 9850 | EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); |
| 9851 | EXPECT_CALL(visitor, OnError(_)).Times(0); |
| 9852 | EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); |
QUICHE team | ea74008 | 2019-03-11 17:58:43 -0700 | [diff] [blame] | 9853 | if (!QuicVersionUsesCryptoFrames(framer_.version().transport_version)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9854 | EXPECT_CALL(visitor, OnStreamFrame(Truly(ExpectedStreamFrame))).Times(1); |
| 9855 | } else { |
| 9856 | EXPECT_CALL(visitor, OnCryptoFrame(_)).Times(1); |
| 9857 | } |
| 9858 | EXPECT_CALL(visitor, OnPacketComplete()).Times(1); |
| 9859 | |
| 9860 | EXPECT_TRUE(framer_.ProcessPacket(*packet)); |
| 9861 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9862 | } |
| 9863 | |
| 9864 | // Verify that the packet returned by ConstructMisFramedEncryptedPacket() |
| 9865 | // does cause the framer to return an error. |
| 9866 | TEST_P(QuicFramerTest, ConstructMisFramedEncryptedPacket) { |
| 9867 | // Since we are using ConstructEncryptedPacket, we have to set the framer's |
| 9868 | // crypto to be Null. |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9869 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9870 | framer_.InstallDecrypter( |
| 9871 | ENCRYPTION_FORWARD_SECURE, |
| 9872 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9873 | } else { |
| 9874 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 9875 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
| 9876 | } |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9877 | framer_.SetEncrypter(ENCRYPTION_INITIAL, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9878 | QuicMakeUnique<NullEncrypter>(framer_.perspective())); |
| 9879 | ParsedQuicVersionVector versions; |
| 9880 | versions.push_back(framer_.version()); |
| 9881 | std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( |
| 9882 | TestConnectionId(), EmptyQuicConnectionId(), false, false, |
| 9883 | kTestQuicStreamId, kTestString, CONNECTION_ID_PRESENT, |
| 9884 | CONNECTION_ID_ABSENT, PACKET_4BYTE_PACKET_NUMBER, &versions, |
| 9885 | Perspective::IS_CLIENT)); |
| 9886 | |
| 9887 | MockFramerVisitor visitor; |
| 9888 | framer_.set_visitor(&visitor); |
| 9889 | EXPECT_CALL(visitor, OnPacket()).Times(1); |
| 9890 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) |
| 9891 | .Times(1) |
| 9892 | .WillOnce(Return(true)); |
| 9893 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) |
| 9894 | .Times(1) |
| 9895 | .WillOnce(Return(true)); |
| 9896 | EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1); |
| 9897 | EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); |
| 9898 | EXPECT_CALL(visitor, OnError(_)).Times(1); |
| 9899 | EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); |
| 9900 | EXPECT_CALL(visitor, OnPacketComplete()).Times(0); |
| 9901 | |
| 9902 | EXPECT_FALSE(framer_.ProcessPacket(*packet)); |
| 9903 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 9904 | } |
| 9905 | |
| 9906 | // Tests for fuzzing with Dr. Fuzz |
| 9907 | // Xref http://www.chromium.org/developers/testing/dr-fuzz for more details. |
| 9908 | #ifdef __cplusplus |
| 9909 | extern "C" { |
| 9910 | #endif |
| 9911 | |
| 9912 | // target function to be fuzzed by Dr. Fuzz |
| 9913 | void QuicFramerFuzzFunc(unsigned char* data, |
| 9914 | size_t size, |
| 9915 | const ParsedQuicVersion& version) { |
| 9916 | QuicFramer framer(AllSupportedVersions(), QuicTime::Zero(), |
| 9917 | Perspective::IS_SERVER, kQuicDefaultConnectionIdLength); |
| 9918 | ASSERT_EQ(GetQuicFlag(FLAGS_quic_supports_tls_handshake), true); |
| 9919 | const char* const packet_bytes = reinterpret_cast<const char*>(data); |
| 9920 | |
| 9921 | // Test the CryptoFramer. |
| 9922 | QuicStringPiece crypto_input(packet_bytes, size); |
| 9923 | std::unique_ptr<CryptoHandshakeMessage> handshake_message( |
| 9924 | CryptoFramer::ParseMessage(crypto_input)); |
| 9925 | |
| 9926 | // Test the regular QuicFramer with the same input. |
| 9927 | NoOpFramerVisitor visitor; |
| 9928 | framer.set_visitor(&visitor); |
| 9929 | framer.set_version(version); |
| 9930 | QuicEncryptedPacket packet(packet_bytes, size); |
| 9931 | framer.ProcessPacket(packet); |
| 9932 | } |
| 9933 | |
| 9934 | #ifdef __cplusplus |
| 9935 | } |
| 9936 | #endif |
| 9937 | |
| 9938 | TEST_P(QuicFramerTest, FramerFuzzTest) { |
| 9939 | // clang-format off |
| 9940 | unsigned char packet[] = { |
| 9941 | // public flags (8 byte connection_id) |
| 9942 | 0x2C, |
| 9943 | // connection_id |
| 9944 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9945 | // packet number |
| 9946 | 0x12, 0x34, 0x56, 0x78, |
| 9947 | // private flags |
| 9948 | 0x00, |
| 9949 | |
| 9950 | // frame type (stream frame with fin) |
| 9951 | 0xFF, |
| 9952 | // stream id |
| 9953 | 0x01, 0x02, 0x03, 0x04, |
| 9954 | // offset |
| 9955 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9956 | 0x32, 0x10, 0x76, 0x54, |
| 9957 | // data length |
| 9958 | 0x00, 0x0c, |
| 9959 | // data |
| 9960 | 'h', 'e', 'l', 'l', |
| 9961 | 'o', ' ', 'w', 'o', |
| 9962 | 'r', 'l', 'd', '!', |
| 9963 | }; |
| 9964 | |
| 9965 | unsigned char packet44[] = { |
| 9966 | // type (short header, 4 byte packet number) |
| 9967 | 0x32, |
| 9968 | // packet number |
| 9969 | 0x12, 0x34, 0x56, 0x78, |
| 9970 | |
| 9971 | // frame type (stream frame with fin, length, and offset bits set) |
| 9972 | 0x10 | 0x01 | 0x02 | 0x04, |
| 9973 | // stream id |
| 9974 | 0x01, 0x02, 0x03, 0x04, |
| 9975 | // offset |
| 9976 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9977 | 0x32, 0x10, 0x76, 0x54, |
| 9978 | // data length |
| 9979 | 0x00, 0x0c, |
| 9980 | // data |
| 9981 | 'h', 'e', 'l', 'l', |
| 9982 | 'o', ' ', 'w', 'o', |
| 9983 | 'r', 'l', 'd', '!', |
| 9984 | }; |
| 9985 | |
| 9986 | unsigned char packet46[] = { |
| 9987 | // type (short header, 4 byte packet number) |
| 9988 | 0x43, |
| 9989 | // packet number |
| 9990 | 0x12, 0x34, 0x56, 0x78, |
| 9991 | |
| 9992 | // frame type (stream frame with fin, length, and offset bits set) |
| 9993 | 0x10 | 0x01 | 0x02 | 0x04, |
| 9994 | // stream id |
| 9995 | 0x01, 0x02, 0x03, 0x04, |
| 9996 | // offset |
| 9997 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9998 | 0x32, 0x10, 0x76, 0x54, |
| 9999 | // data length |
| 10000 | 0x00, 0x0c, |
| 10001 | // data |
| 10002 | 'h', 'e', 'l', 'l', |
| 10003 | 'o', ' ', 'w', 'o', |
| 10004 | 'r', 'l', 'd', '!', |
| 10005 | }; |
| 10006 | |
| 10007 | unsigned char packet99[] = { |
| 10008 | // type (short header, 4 byte packet number) |
| 10009 | 0x43, |
| 10010 | // packet number |
| 10011 | 0x12, 0x34, 0x56, 0x78, |
| 10012 | |
| 10013 | // frame type (IETF_STREAM frame with fin, length, and offset bits set) |
| 10014 | 0x08 | 0x01 | 0x02 | 0x04, |
| 10015 | // stream id |
| 10016 | 0x01, 0x02, 0x03, 0x04, |
| 10017 | // offset |
| 10018 | 0x3A, 0x98, 0xFE, 0xDC, |
| 10019 | 0x32, 0x10, 0x76, 0x54, |
| 10020 | // data length |
| 10021 | 0x00, 0x0c, |
| 10022 | // data |
| 10023 | 'h', 'e', 'l', 'l', |
| 10024 | 'o', ' ', 'w', 'o', |
| 10025 | 'r', 'l', 'd', '!', |
| 10026 | }; |
| 10027 | // clang-format on |
| 10028 | |
| 10029 | unsigned char* p = packet; |
| 10030 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 10031 | p = packet99; |
| 10032 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 10033 | p = packet46; |
| 10034 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 10035 | p = packet44; |
| 10036 | } |
| 10037 | QuicFramerFuzzFunc(p, |
| 10038 | framer_.transport_version() > QUIC_VERSION_43 |
| 10039 | ? QUIC_ARRAYSIZE(packet44) |
| 10040 | : QUIC_ARRAYSIZE(packet), |
| 10041 | framer_.version()); |
| 10042 | } |
| 10043 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10044 | TEST_P(QuicFramerTest, IetfBlockedFrame) { |
| 10045 | // This test only for version 99. |
| 10046 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10047 | return; |
| 10048 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10049 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10050 | |
| 10051 | // clang-format off |
| 10052 | PacketFragments packet99 = { |
| 10053 | // type (short header, 4 byte packet number) |
| 10054 | {"", |
| 10055 | {0x43}}, |
| 10056 | // connection_id |
| 10057 | {"", |
| 10058 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10059 | // packet number |
| 10060 | {"", |
| 10061 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10062 | // frame type (IETF_BLOCKED) |
| 10063 | {"", |
| 10064 | {0x14}}, |
| 10065 | // blocked offset |
| 10066 | {"Can not read blocked offset.", |
| 10067 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 10068 | }; |
| 10069 | // clang-format on |
| 10070 | |
| 10071 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10072 | AssemblePacketFromFragments(packet99)); |
| 10073 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10074 | |
| 10075 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10076 | ASSERT_TRUE(visitor_.header_.get()); |
| 10077 | EXPECT_TRUE(CheckDecryption( |
| 10078 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10079 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10080 | |
| 10081 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 10082 | |
| 10083 | CheckFramingBoundaries(packet99, QUIC_INVALID_BLOCKED_DATA); |
| 10084 | } |
| 10085 | |
| 10086 | TEST_P(QuicFramerTest, BuildIetfBlockedPacket) { |
| 10087 | // This test only for version 99. |
| 10088 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10089 | return; |
| 10090 | } |
| 10091 | |
| 10092 | QuicPacketHeader header; |
| 10093 | header.destination_connection_id = FramerTestConnectionId(); |
| 10094 | header.reset_flag = false; |
| 10095 | header.version_flag = false; |
| 10096 | header.packet_number = kPacketNumber; |
| 10097 | |
| 10098 | QuicBlockedFrame frame; |
| 10099 | frame.stream_id = QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 10100 | frame.offset = kStreamOffset; |
| 10101 | QuicFrames frames = {QuicFrame(&frame)}; |
| 10102 | |
| 10103 | // clang-format off |
| 10104 | unsigned char packet99[] = { |
| 10105 | // type (short header, 4 byte packet number) |
| 10106 | 0x43, |
| 10107 | // connection_id |
| 10108 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10109 | // packet number |
| 10110 | 0x12, 0x34, 0x56, 0x78, |
| 10111 | |
| 10112 | // frame type (IETF_BLOCKED) |
| 10113 | 0x14, |
| 10114 | // Offset |
| 10115 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 10116 | }; |
| 10117 | // clang-format on |
| 10118 | |
| 10119 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10120 | ASSERT_TRUE(data != nullptr); |
| 10121 | |
| 10122 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10123 | data->length(), AsChars(packet99), |
| 10124 | QUIC_ARRAYSIZE(packet99)); |
| 10125 | } |
| 10126 | |
| 10127 | TEST_P(QuicFramerTest, IetfStreamBlockedFrame) { |
| 10128 | // This test only for version 99. |
| 10129 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10130 | return; |
| 10131 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10132 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10133 | |
| 10134 | // clang-format off |
| 10135 | PacketFragments packet99 = { |
| 10136 | // type (short header, 4 byte packet number) |
| 10137 | {"", |
| 10138 | {0x43}}, |
| 10139 | // connection_id |
| 10140 | {"", |
| 10141 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10142 | // packet number |
| 10143 | {"", |
| 10144 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10145 | // frame type (IETF_STREAM_BLOCKED) |
| 10146 | {"", |
| 10147 | {0x15}}, |
| 10148 | // blocked offset |
| 10149 | {"Can not read stream blocked stream id.", |
| 10150 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 10151 | {"Can not read stream blocked offset.", |
| 10152 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 10153 | }; |
| 10154 | // clang-format on |
| 10155 | |
| 10156 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10157 | AssemblePacketFromFragments(packet99)); |
| 10158 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10159 | |
| 10160 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10161 | ASSERT_TRUE(visitor_.header_.get()); |
| 10162 | EXPECT_TRUE(CheckDecryption( |
| 10163 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10164 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10165 | |
| 10166 | EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); |
| 10167 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 10168 | |
| 10169 | CheckFramingBoundaries(packet99, QUIC_INVALID_STREAM_BLOCKED_DATA); |
| 10170 | } |
| 10171 | |
| 10172 | TEST_P(QuicFramerTest, BuildIetfStreamBlockedPacket) { |
| 10173 | // This test only for version 99. |
| 10174 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10175 | return; |
| 10176 | } |
| 10177 | |
| 10178 | QuicPacketHeader header; |
| 10179 | header.destination_connection_id = FramerTestConnectionId(); |
| 10180 | header.reset_flag = false; |
| 10181 | header.version_flag = false; |
| 10182 | header.packet_number = kPacketNumber; |
| 10183 | |
| 10184 | QuicBlockedFrame frame; |
| 10185 | frame.stream_id = kStreamId; |
| 10186 | frame.offset = kStreamOffset; |
| 10187 | QuicFrames frames = {QuicFrame(&frame)}; |
| 10188 | |
| 10189 | // clang-format off |
| 10190 | unsigned char packet99[] = { |
| 10191 | // type (short header, 4 byte packet number) |
| 10192 | 0x43, |
| 10193 | // connection_id |
| 10194 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10195 | // packet number |
| 10196 | 0x12, 0x34, 0x56, 0x78, |
| 10197 | |
| 10198 | // frame type (IETF_STREAM_BLOCKED) |
| 10199 | 0x15, |
| 10200 | // Stream ID |
| 10201 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 10202 | // Offset |
| 10203 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 10204 | }; |
| 10205 | // clang-format on |
| 10206 | |
| 10207 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10208 | ASSERT_TRUE(data != nullptr); |
| 10209 | |
| 10210 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10211 | data->length(), AsChars(packet99), |
| 10212 | QUIC_ARRAYSIZE(packet99)); |
| 10213 | } |
| 10214 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10215 | TEST_P(QuicFramerTest, BiDiMaxStreamsFrame) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10216 | // This test only for version 99. |
| 10217 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10218 | return; |
| 10219 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10220 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10221 | |
| 10222 | // clang-format off |
| 10223 | PacketFragments packet99 = { |
| 10224 | // type (short header, 4 byte packet number) |
| 10225 | {"", |
| 10226 | {0x43}}, |
| 10227 | // connection_id |
| 10228 | {"", |
| 10229 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10230 | // packet number |
| 10231 | {"", |
| 10232 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10233 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10234 | {"", |
| 10235 | {0x12}}, |
| 10236 | // max. streams |
| 10237 | {"Can not read MAX_STREAMS stream count.", |
| 10238 | {kVarInt62OneByte + 0x03}}, |
| 10239 | }; |
| 10240 | // clang-format on |
| 10241 | |
| 10242 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10243 | AssemblePacketFromFragments(packet99)); |
| 10244 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10245 | |
| 10246 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10247 | ASSERT_TRUE(visitor_.header_.get()); |
| 10248 | EXPECT_TRUE(CheckDecryption( |
| 10249 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10250 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10251 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10252 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 10253 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
| 10254 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10255 | } |
| 10256 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10257 | TEST_P(QuicFramerTest, UniDiMaxStreamsFrame) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10258 | // This test only for version 99. |
| 10259 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10260 | return; |
| 10261 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10262 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10263 | |
| 10264 | // clang-format off |
| 10265 | PacketFragments packet99 = { |
| 10266 | // type (short header, 4 byte packet number) |
| 10267 | {"", |
| 10268 | {0x43}}, |
| 10269 | // Test runs in client mode, no connection id |
| 10270 | // packet number |
| 10271 | {"", |
| 10272 | {0x12, 0x34, 0x9A, 0xBC}}, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10273 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10274 | {"", |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10275 | {0x13}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10276 | // max. streams |
| 10277 | {"Can not read MAX_STREAMS stream count.", |
| 10278 | {kVarInt62OneByte + 0x03}}, |
| 10279 | }; |
| 10280 | // clang-format on |
| 10281 | |
| 10282 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10283 | AssemblePacketFromFragments(packet99)); |
| 10284 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10285 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10286 | |
| 10287 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10288 | ASSERT_TRUE(visitor_.header_.get()); |
| 10289 | EXPECT_TRUE(CheckDecryption( |
| 10290 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10291 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10292 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10293 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 10294 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 10295 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10296 | } |
| 10297 | |
| 10298 | TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrame) { |
| 10299 | // This test only for version 99. |
| 10300 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10301 | return; |
| 10302 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10303 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10304 | |
| 10305 | // clang-format off |
| 10306 | PacketFragments packet99 = { |
| 10307 | // type (short header, 4 byte packet number) |
| 10308 | {"", |
| 10309 | {0x43}}, |
| 10310 | // connection_id |
| 10311 | {"", |
| 10312 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10313 | // packet number |
| 10314 | {"", |
| 10315 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10316 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 10317 | {"", |
| 10318 | {0x13}}, |
| 10319 | // max. streams |
| 10320 | {"Can not read MAX_STREAMS stream count.", |
| 10321 | {kVarInt62OneByte + 0x03}}, |
| 10322 | }; |
| 10323 | // clang-format on |
| 10324 | |
| 10325 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10326 | AssemblePacketFromFragments(packet99)); |
| 10327 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10328 | |
| 10329 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10330 | ASSERT_TRUE(visitor_.header_.get()); |
| 10331 | EXPECT_TRUE(CheckDecryption( |
| 10332 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10333 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10334 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10335 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 10336 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 10337 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10338 | } |
| 10339 | |
| 10340 | TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrame) { |
| 10341 | // This test only for version 99. |
| 10342 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10343 | return; |
| 10344 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10345 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10346 | |
| 10347 | // clang-format off |
| 10348 | PacketFragments packet99 = { |
| 10349 | // type (short header, 4 byte packet number) |
| 10350 | {"", |
| 10351 | {0x43}}, |
| 10352 | // Test runs in client mode, no connection id |
| 10353 | // packet number |
| 10354 | {"", |
| 10355 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10356 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 10357 | {"", |
| 10358 | {0x13}}, |
| 10359 | // max. streams |
| 10360 | {"Can not read MAX_STREAMS stream count.", |
| 10361 | {kVarInt62OneByte + 0x03}}, |
| 10362 | }; |
| 10363 | // clang-format on |
| 10364 | |
| 10365 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10366 | AssemblePacketFromFragments(packet99)); |
| 10367 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10368 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10369 | |
| 10370 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10371 | ASSERT_TRUE(visitor_.header_.get()); |
| 10372 | EXPECT_TRUE(CheckDecryption( |
| 10373 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10374 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10375 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10376 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 10377 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 10378 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10379 | } |
| 10380 | |
| 10381 | // The following four tests ensure that the framer can deserialize a stream |
| 10382 | // count that is large enough to cause the resulting stream ID to exceed the |
| 10383 | // current implementation limit(32 bits). The intent is that when this happens, |
| 10384 | // the stream limit is pegged to the maximum supported value. There are four |
| 10385 | // tests, for the four combinations of uni- and bi-directional, server- and |
| 10386 | // client- initiated. |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10387 | TEST_P(QuicFramerTest, BiDiMaxStreamsFrameTooBig) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10388 | // This test only for version 99. |
| 10389 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10390 | return; |
| 10391 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10392 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10393 | |
| 10394 | // clang-format off |
| 10395 | unsigned char packet99[] = { |
| 10396 | // type (short header, 4 byte packet number) |
| 10397 | 0x43, |
| 10398 | // connection_id |
| 10399 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10400 | // packet number |
| 10401 | 0x12, 0x34, 0x9A, 0xBC, |
| 10402 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10403 | 0x12, |
| 10404 | |
| 10405 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10406 | // This encodes a count of 0x40000000, leading to stream |
| 10407 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10408 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10409 | }; |
| 10410 | // clang-format on |
| 10411 | |
| 10412 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10413 | false); |
| 10414 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10415 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10416 | ASSERT_TRUE(visitor_.header_.get()); |
| 10417 | EXPECT_TRUE(CheckDecryption( |
| 10418 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10419 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10420 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 10421 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10422 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10423 | } |
| 10424 | |
| 10425 | TEST_P(QuicFramerTest, ClientBiDiMaxStreamsFrameTooBig) { |
| 10426 | // This test only for version 99. |
| 10427 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10428 | return; |
| 10429 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10430 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10431 | |
| 10432 | // clang-format off |
| 10433 | unsigned char packet99[] = { |
| 10434 | // type (short header, 4 byte packet number) |
| 10435 | 0x43, |
| 10436 | // Test runs in client mode, no connection id |
| 10437 | // packet number |
| 10438 | 0x12, 0x34, 0x9A, 0xBC, |
| 10439 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10440 | 0x12, |
| 10441 | |
| 10442 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10443 | // This encodes a count of 0x40000000, leading to stream |
| 10444 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10445 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10446 | }; |
| 10447 | // clang-format on |
| 10448 | |
| 10449 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10450 | false); |
| 10451 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10452 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10453 | |
| 10454 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10455 | ASSERT_TRUE(visitor_.header_.get()); |
| 10456 | EXPECT_TRUE(CheckDecryption( |
| 10457 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10458 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10459 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 10460 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10461 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10462 | } |
| 10463 | |
| 10464 | TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrameTooBig) { |
| 10465 | // This test only for version 99. |
| 10466 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10467 | return; |
| 10468 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10469 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10470 | |
| 10471 | // clang-format off |
| 10472 | unsigned char packet99[] = { |
| 10473 | // type (short header, 4 byte packet number) |
| 10474 | 0x43, |
| 10475 | // connection_id |
| 10476 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10477 | // packet number |
| 10478 | 0x12, 0x34, 0x9A, 0xBC, |
| 10479 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 10480 | 0x13, |
| 10481 | |
| 10482 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10483 | // This encodes a count of 0x40000000, leading to stream |
| 10484 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10485 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10486 | }; |
| 10487 | // clang-format on |
| 10488 | |
| 10489 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10490 | false); |
| 10491 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10492 | |
| 10493 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10494 | ASSERT_TRUE(visitor_.header_.get()); |
| 10495 | EXPECT_TRUE(CheckDecryption( |
| 10496 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10497 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10498 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 10499 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10500 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10501 | } |
| 10502 | |
| 10503 | TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrameTooBig) { |
| 10504 | // This test only for version 99. |
| 10505 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10506 | return; |
| 10507 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10508 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10509 | |
| 10510 | // clang-format off |
| 10511 | unsigned char packet99[] = { |
| 10512 | // type (short header, 4 byte packet number) |
| 10513 | 0x43, |
| 10514 | // Test runs in client mode, no connection id |
| 10515 | // packet number |
| 10516 | 0x12, 0x34, 0x9A, 0xBC, |
| 10517 | // frame type (IETF_MAX_STREAMS_UNDIRECTIONAL) |
| 10518 | 0x13, |
| 10519 | |
| 10520 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10521 | // This encodes a count of 0x40000000, leading to stream |
| 10522 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10523 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10524 | }; |
| 10525 | // clang-format on |
| 10526 | |
| 10527 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10528 | false); |
| 10529 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10530 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10531 | |
| 10532 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10533 | ASSERT_TRUE(visitor_.header_.get()); |
| 10534 | EXPECT_TRUE(CheckDecryption( |
| 10535 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10536 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10537 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 10538 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10539 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10540 | } |
| 10541 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10542 | // Specifically test that count==0 is accepted. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10543 | TEST_P(QuicFramerTest, MaxStreamsFrameZeroCount) { |
| 10544 | // This test only for version 99. |
| 10545 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10546 | return; |
| 10547 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10548 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10549 | |
| 10550 | // clang-format off |
| 10551 | unsigned char packet99[] = { |
| 10552 | // type (short header, 4 byte packet number) |
| 10553 | 0x43, |
| 10554 | // connection_id |
| 10555 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10556 | // packet number |
| 10557 | 0x12, 0x34, 0x9A, 0xBC, |
| 10558 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10559 | 0x12, |
| 10560 | // max. streams == 0. |
| 10561 | kVarInt62OneByte + 0x00 |
| 10562 | }; |
| 10563 | // clang-format on |
| 10564 | |
| 10565 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10566 | false); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10567 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10568 | } |
| 10569 | |
| 10570 | TEST_P(QuicFramerTest, ServerBiDiStreamsBlockedFrame) { |
| 10571 | // This test only for version 99. |
| 10572 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10573 | return; |
| 10574 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10575 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10576 | |
| 10577 | // clang-format off |
| 10578 | PacketFragments packet99 = { |
| 10579 | // type (short header, 4 byte packet number) |
| 10580 | {"", |
| 10581 | {0x43}}, |
| 10582 | // connection_id |
| 10583 | {"", |
| 10584 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10585 | // packet number |
| 10586 | {"", |
| 10587 | {0x12, 0x34, 0x9A, 0xBC}}, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10588 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL frame) |
| 10589 | {"", |
| 10590 | {0x13}}, |
| 10591 | // stream count |
| 10592 | {"Can not read MAX_STREAMS stream count.", |
| 10593 | {kVarInt62OneByte + 0x00}}, |
| 10594 | }; |
| 10595 | // clang-format on |
| 10596 | |
| 10597 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10598 | AssemblePacketFromFragments(packet99)); |
| 10599 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10600 | |
| 10601 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10602 | ASSERT_TRUE(visitor_.header_.get()); |
| 10603 | EXPECT_TRUE(CheckDecryption( |
| 10604 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10605 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10606 | |
| 10607 | EXPECT_EQ(0u, visitor_.max_streams_frame_.stream_count); |
| 10608 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 10609 | |
| 10610 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
| 10611 | } |
| 10612 | |
| 10613 | TEST_P(QuicFramerTest, BiDiStreamsBlockedFrame) { |
| 10614 | // This test only for version 99. |
| 10615 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10616 | return; |
| 10617 | } |
| 10618 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 10619 | |
| 10620 | // clang-format off |
| 10621 | PacketFragments packet99 = { |
| 10622 | // type (short header, 4 byte packet number) |
| 10623 | {"", |
| 10624 | {0x43}}, |
| 10625 | // connection_id |
| 10626 | {"", |
| 10627 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10628 | // packet number |
| 10629 | {"", |
| 10630 | {0x12, 0x34, 0x9A, 0xBC}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10631 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 10632 | {"", |
| 10633 | {0x16}}, |
| 10634 | // stream id |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10635 | {"Can not read STREAMS_BLOCKED stream count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10636 | {kVarInt62OneByte + 0x03}}, |
| 10637 | }; |
| 10638 | // clang-format on |
| 10639 | |
| 10640 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10641 | AssemblePacketFromFragments(packet99)); |
| 10642 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10643 | |
| 10644 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10645 | ASSERT_TRUE(visitor_.header_.get()); |
| 10646 | EXPECT_TRUE(CheckDecryption( |
| 10647 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10648 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10649 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10650 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 10651 | EXPECT_FALSE(visitor_.streams_blocked_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10652 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10653 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10654 | } |
| 10655 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10656 | TEST_P(QuicFramerTest, UniDiStreamsBlockedFrame) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10657 | // This test only for version 99. |
| 10658 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10659 | return; |
| 10660 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10661 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10662 | |
| 10663 | // clang-format off |
| 10664 | PacketFragments packet99 = { |
| 10665 | // type (short header, 4 byte packet number) |
| 10666 | {"", |
| 10667 | {0x43}}, |
| 10668 | // connection_id |
| 10669 | {"", |
| 10670 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10671 | // packet number |
| 10672 | {"", |
| 10673 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10674 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10675 | {"", |
| 10676 | {0x17}}, |
| 10677 | // stream id |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10678 | {"Can not read STREAMS_BLOCKED stream count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10679 | {kVarInt62OneByte + 0x03}}, |
| 10680 | }; |
| 10681 | // clang-format on |
| 10682 | |
| 10683 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10684 | AssemblePacketFromFragments(packet99)); |
| 10685 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10686 | |
| 10687 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10688 | ASSERT_TRUE(visitor_.header_.get()); |
| 10689 | EXPECT_TRUE(CheckDecryption( |
| 10690 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10691 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10692 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10693 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 10694 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 10695 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10696 | } |
| 10697 | |
| 10698 | TEST_P(QuicFramerTest, ClientUniDiStreamsBlockedFrame) { |
| 10699 | // This test only for version 99. |
| 10700 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10701 | return; |
| 10702 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10703 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10704 | |
| 10705 | // clang-format off |
| 10706 | PacketFragments packet99 = { |
| 10707 | // type (short header, 4 byte packet number) |
| 10708 | {"", |
| 10709 | {0x43}}, |
| 10710 | // Test runs in client mode, no connection id |
| 10711 | // packet number |
| 10712 | {"", |
| 10713 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10714 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10715 | {"", |
| 10716 | {0x17}}, |
| 10717 | // stream id |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10718 | {"Can not read STREAMS_BLOCKED stream count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10719 | {kVarInt62OneByte + 0x03}}, |
| 10720 | }; |
| 10721 | // clang-format on |
| 10722 | |
| 10723 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10724 | AssemblePacketFromFragments(packet99)); |
| 10725 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10726 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10727 | |
| 10728 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10729 | ASSERT_TRUE(visitor_.header_.get()); |
| 10730 | EXPECT_TRUE(CheckDecryption( |
| 10731 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10732 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10733 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10734 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 10735 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 10736 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10737 | } |
| 10738 | |
| 10739 | // Check that when we get a STREAMS_BLOCKED frame that specifies too large |
| 10740 | // a stream count, we reject with an appropriate error. There is no need to |
| 10741 | // check for different combinations of Uni/Bi directional and client/server |
| 10742 | // initiated; the logic does not take these into account. |
| 10743 | TEST_P(QuicFramerTest, StreamsBlockedFrameTooBig) { |
| 10744 | // This test only for version 99. |
| 10745 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10746 | return; |
| 10747 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10748 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10749 | |
| 10750 | // clang-format off |
| 10751 | unsigned char packet99[] = { |
| 10752 | // type (short header, 4 byte packet number) |
| 10753 | 0x43, |
| 10754 | // Test runs in client mode, no connection id |
| 10755 | // packet number |
| 10756 | 0x12, 0x34, 0x9A, 0xBC, |
| 10757 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL) |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10758 | 0x16, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10759 | |
| 10760 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10761 | // This encodes a count of 0x40000000, leading to stream |
| 10762 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10763 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01 |
| 10764 | }; |
| 10765 | // clang-format on |
| 10766 | |
| 10767 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10768 | false); |
| 10769 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10770 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 10771 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10772 | EXPECT_EQ(QUIC_STREAMS_BLOCKED_DATA, framer_.error()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10773 | EXPECT_EQ(framer_.detailed_error(), |
| 10774 | "STREAMS_BLOCKED stream count exceeds implementation limit."); |
| 10775 | } |
| 10776 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10777 | // Specifically test that count==0 is accepted. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10778 | TEST_P(QuicFramerTest, StreamsBlockedFrameZeroCount) { |
| 10779 | // This test only for version 99. |
| 10780 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10781 | return; |
| 10782 | } |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10783 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10784 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10785 | |
| 10786 | // clang-format off |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10787 | PacketFragments packet99 = { |
| 10788 | // type (short header, 4 byte packet number) |
| 10789 | {"", |
| 10790 | {0x43}}, |
| 10791 | // connection_id |
| 10792 | {"", |
| 10793 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10794 | // packet number |
| 10795 | {"", |
| 10796 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10797 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10798 | {"", |
| 10799 | {0x17}}, |
| 10800 | // stream id |
| 10801 | {"Can not read STREAMS_BLOCKED stream count.", |
| 10802 | {kVarInt62OneByte + 0x00}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10803 | }; |
| 10804 | // clang-format on |
| 10805 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10806 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10807 | AssemblePacketFromFragments(packet99)); |
| 10808 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10809 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10810 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10811 | ASSERT_TRUE(visitor_.header_.get()); |
| 10812 | EXPECT_TRUE(CheckDecryption( |
| 10813 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10814 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10815 | |
| 10816 | EXPECT_EQ(0u, visitor_.streams_blocked_frame_.stream_count); |
| 10817 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 10818 | |
| 10819 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10820 | } |
| 10821 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10822 | TEST_P(QuicFramerTest, BuildBiDiStreamsBlockedPacket) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10823 | // This test only for version 99. |
| 10824 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10825 | return; |
| 10826 | } |
| 10827 | |
| 10828 | QuicPacketHeader header; |
| 10829 | header.destination_connection_id = FramerTestConnectionId(); |
| 10830 | header.reset_flag = false; |
| 10831 | header.version_flag = false; |
| 10832 | header.packet_number = kPacketNumber; |
| 10833 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10834 | QuicStreamsBlockedFrame frame; |
| 10835 | frame.stream_count = 3; |
| 10836 | frame.unidirectional = false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10837 | |
| 10838 | QuicFrames frames = {QuicFrame(frame)}; |
| 10839 | |
| 10840 | // clang-format off |
| 10841 | unsigned char packet99[] = { |
| 10842 | // type (short header, 4 byte packet number) |
| 10843 | 0x43, |
| 10844 | // connection_id |
| 10845 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10846 | // packet number |
| 10847 | 0x12, 0x34, 0x56, 0x78, |
| 10848 | |
| 10849 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 10850 | 0x16, |
| 10851 | // Stream count |
| 10852 | kVarInt62OneByte + 0x03 |
| 10853 | }; |
| 10854 | // clang-format on |
| 10855 | |
| 10856 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10857 | ASSERT_TRUE(data != nullptr); |
| 10858 | |
| 10859 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10860 | data->length(), AsChars(packet99), |
| 10861 | QUIC_ARRAYSIZE(packet99)); |
| 10862 | } |
| 10863 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10864 | TEST_P(QuicFramerTest, BuildUniStreamsBlockedPacket) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10865 | // This test only for version 99. |
| 10866 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10867 | return; |
| 10868 | } |
| 10869 | |
| 10870 | QuicPacketHeader header; |
| 10871 | header.destination_connection_id = FramerTestConnectionId(); |
| 10872 | header.reset_flag = false; |
| 10873 | header.version_flag = false; |
| 10874 | header.packet_number = kPacketNumber; |
| 10875 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10876 | QuicStreamsBlockedFrame frame; |
| 10877 | frame.stream_count = 3; |
| 10878 | frame.unidirectional = true; |
| 10879 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10880 | QuicFrames frames = {QuicFrame(frame)}; |
| 10881 | |
| 10882 | // clang-format off |
| 10883 | unsigned char packet99[] = { |
| 10884 | // type (short header, 4 byte packet number) |
| 10885 | 0x43, |
| 10886 | // connection_id |
| 10887 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10888 | // packet number |
| 10889 | 0x12, 0x34, 0x56, 0x78, |
| 10890 | |
| 10891 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10892 | 0x17, |
| 10893 | // Stream count |
| 10894 | kVarInt62OneByte + 0x03 |
| 10895 | }; |
| 10896 | // clang-format on |
| 10897 | |
| 10898 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10899 | ASSERT_TRUE(data != nullptr); |
| 10900 | |
| 10901 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10902 | data->length(), AsChars(packet99), |
| 10903 | QUIC_ARRAYSIZE(packet99)); |
| 10904 | } |
| 10905 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10906 | TEST_P(QuicFramerTest, BuildBiDiMaxStreamsPacket) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10907 | // This test only for version 99. |
| 10908 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10909 | return; |
| 10910 | } |
| 10911 | |
| 10912 | QuicPacketHeader header; |
| 10913 | header.destination_connection_id = FramerTestConnectionId(); |
| 10914 | header.reset_flag = false; |
| 10915 | header.version_flag = false; |
| 10916 | header.packet_number = kPacketNumber; |
| 10917 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10918 | QuicMaxStreamsFrame frame; |
| 10919 | frame.stream_count = 3; |
| 10920 | frame.unidirectional = false; |
| 10921 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10922 | QuicFrames frames = {QuicFrame(frame)}; |
| 10923 | |
| 10924 | // clang-format off |
| 10925 | unsigned char packet99[] = { |
| 10926 | // type (short header, 4 byte packet number) |
| 10927 | 0x43, |
| 10928 | // connection_id |
| 10929 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10930 | // packet number |
| 10931 | 0x12, 0x34, 0x56, 0x78, |
| 10932 | |
| 10933 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL frame) |
| 10934 | 0x12, |
| 10935 | // Stream count |
| 10936 | kVarInt62OneByte + 0x03 |
| 10937 | }; |
| 10938 | // clang-format on |
| 10939 | |
| 10940 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10941 | ASSERT_TRUE(data != nullptr); |
| 10942 | |
| 10943 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10944 | data->length(), AsChars(packet99), |
| 10945 | QUIC_ARRAYSIZE(packet99)); |
| 10946 | } |
| 10947 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10948 | TEST_P(QuicFramerTest, BuildUniDiMaxStreamsPacket) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10949 | // This test only for version 99. |
| 10950 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10951 | return; |
| 10952 | } |
| 10953 | |
| 10954 | // This test runs in client mode. |
| 10955 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10956 | |
| 10957 | QuicPacketHeader header; |
| 10958 | header.destination_connection_id = FramerTestConnectionId(); |
| 10959 | header.reset_flag = false; |
| 10960 | header.version_flag = false; |
| 10961 | header.packet_number = kPacketNumber; |
| 10962 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10963 | QuicMaxStreamsFrame frame; |
| 10964 | frame.stream_count = 3; |
| 10965 | frame.unidirectional = true; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10966 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10967 | QuicFrames frames = {QuicFrame(frame)}; |
| 10968 | |
| 10969 | // clang-format off |
| 10970 | unsigned char packet99[] = { |
| 10971 | // type (short header, 4 byte packet number) |
| 10972 | 0x43, |
| 10973 | // connection_id |
| 10974 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10975 | // packet number |
| 10976 | 0x12, 0x34, 0x56, 0x78, |
| 10977 | |
| 10978 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL frame) |
| 10979 | 0x13, |
| 10980 | // Stream count |
| 10981 | kVarInt62OneByte + 0x03 |
| 10982 | }; |
| 10983 | // clang-format on |
| 10984 | |
| 10985 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10986 | ASSERT_TRUE(data != nullptr); |
| 10987 | |
| 10988 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10989 | data->length(), AsChars(packet99), |
| 10990 | QUIC_ARRAYSIZE(packet99)); |
| 10991 | } |
| 10992 | |
| 10993 | TEST_P(QuicFramerTest, NewConnectionIdFrame) { |
| 10994 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10995 | // This frame is only for version 99. |
| 10996 | return; |
| 10997 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10998 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10999 | // clang-format off |
| 11000 | PacketFragments packet99 = { |
| 11001 | // type (short header, 4 byte packet number) |
| 11002 | {"", |
| 11003 | {0x43}}, |
| 11004 | // connection_id |
| 11005 | {"", |
| 11006 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11007 | // packet number |
| 11008 | {"", |
| 11009 | {0x12, 0x34, 0x56, 0x78}}, |
| 11010 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 11011 | {"", |
| 11012 | {0x18}}, |
| 11013 | // error code |
| 11014 | {"Unable to read new connection ID frame sequence number.", |
| 11015 | {kVarInt62OneByte + 0x11}}, |
| 11016 | {"Unable to read new connection ID frame connection id length.", |
| 11017 | {0x08}}, // connection ID length |
| 11018 | {"Unable to read new connection ID frame connection id.", |
| 11019 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11}}, |
| 11020 | {"Can not read new connection ID frame reset token.", |
| 11021 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11022 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 11023 | }; |
| 11024 | // clang-format on |
| 11025 | |
| 11026 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11027 | AssemblePacketFromFragments(packet99)); |
| 11028 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11029 | |
| 11030 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11031 | ASSERT_TRUE(visitor_.header_.get()); |
| 11032 | EXPECT_TRUE(CheckDecryption( |
| 11033 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11034 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11035 | |
| 11036 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 11037 | |
| 11038 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), |
| 11039 | visitor_.new_connection_id_.connection_id); |
| 11040 | EXPECT_EQ(0x11u, visitor_.new_connection_id_.sequence_number); |
| 11041 | EXPECT_EQ(kTestStatelessResetToken, |
| 11042 | visitor_.new_connection_id_.stateless_reset_token); |
| 11043 | |
| 11044 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 11045 | |
| 11046 | CheckFramingBoundaries(packet99, QUIC_INVALID_NEW_CONNECTION_ID_DATA); |
| 11047 | } |
| 11048 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 11049 | TEST_P(QuicFramerTest, NewConnectionIdFrameVariableLength) { |
QUICHE team | 9b41c97 | 2019-03-21 11:22:48 -0700 | [diff] [blame] | 11050 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11051 | // This frame is only for version 99. |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 11052 | return; |
| 11053 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11054 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 11055 | // clang-format off |
| 11056 | PacketFragments packet99 = { |
| 11057 | // type (short header, 4 byte packet number) |
| 11058 | {"", |
| 11059 | {0x43}}, |
| 11060 | // connection_id |
| 11061 | {"", |
| 11062 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11063 | // packet number |
| 11064 | {"", |
| 11065 | {0x12, 0x34, 0x56, 0x78}}, |
| 11066 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 11067 | {"", |
| 11068 | {0x18}}, |
| 11069 | // error code |
| 11070 | {"Unable to read new connection ID frame sequence number.", |
| 11071 | {kVarInt62OneByte + 0x11}}, |
| 11072 | {"Unable to read new connection ID frame connection id length.", |
| 11073 | {0x09}}, // connection ID length |
| 11074 | {"Unable to read new connection ID frame connection id.", |
| 11075 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 11076 | {"Can not read new connection ID frame reset token.", |
| 11077 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11078 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 11079 | }; |
| 11080 | // clang-format on |
| 11081 | |
| 11082 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11083 | AssemblePacketFromFragments(packet99)); |
| 11084 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11085 | |
| 11086 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11087 | ASSERT_TRUE(visitor_.header_.get()); |
| 11088 | EXPECT_TRUE(CheckDecryption( |
| 11089 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11090 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11091 | |
| 11092 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 11093 | |
| 11094 | EXPECT_EQ(FramerTestConnectionIdNineBytes(), |
| 11095 | visitor_.new_connection_id_.connection_id); |
| 11096 | EXPECT_EQ(0x11u, visitor_.new_connection_id_.sequence_number); |
| 11097 | EXPECT_EQ(kTestStatelessResetToken, |
| 11098 | visitor_.new_connection_id_.stateless_reset_token); |
| 11099 | |
| 11100 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 11101 | |
| 11102 | CheckFramingBoundaries(packet99, QUIC_INVALID_NEW_CONNECTION_ID_DATA); |
| 11103 | } |
| 11104 | |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 11105 | // Verifies that parsing a NEW_CONNECTION_ID frame with a length above the |
| 11106 | // specified maximum fails. |
| 11107 | TEST_P(QuicFramerTest, InvalidLongNewConnectionIdFrame) { |
| 11108 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11109 | // The NEW_CONNECTION_ID frame is only for version 99. |
| 11110 | return; |
| 11111 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11112 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 11113 | // clang-format off |
| 11114 | PacketFragments packet99 = { |
| 11115 | // type (short header, 4 byte packet number) |
| 11116 | {"", |
| 11117 | {0x43}}, |
| 11118 | // connection_id |
| 11119 | {"", |
| 11120 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11121 | // packet number |
| 11122 | {"", |
| 11123 | {0x12, 0x34, 0x56, 0x78}}, |
| 11124 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 11125 | {"", |
| 11126 | {0x18}}, |
| 11127 | // error code |
| 11128 | {"Unable to read new connection ID frame sequence number.", |
| 11129 | {kVarInt62OneByte + 0x11}}, |
| 11130 | {"Unable to read new connection ID frame connection id length.", |
| 11131 | {0x13}}, // connection ID length |
| 11132 | {"Unable to read new connection ID frame connection id.", |
| 11133 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11134 | 0xF0, 0xD2, 0xB4, 0x96, 0x78, 0x5A, 0x3C, 0x1E, |
| 11135 | 0x42, 0x33, 0x42}}, |
| 11136 | {"Can not read new connection ID frame reset token.", |
| 11137 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11138 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 11139 | }; |
| 11140 | // clang-format on |
| 11141 | |
| 11142 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11143 | AssemblePacketFromFragments(packet99)); |
| 11144 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11145 | EXPECT_EQ(QUIC_INVALID_NEW_CONNECTION_ID_DATA, framer_.error()); |
| 11146 | EXPECT_EQ("New connection ID length too high.", framer_.detailed_error()); |
| 11147 | } |
| 11148 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11149 | TEST_P(QuicFramerTest, BuildNewConnectionIdFramePacket) { |
| 11150 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11151 | // This frame is only for version 99. |
| 11152 | return; |
| 11153 | } |
| 11154 | QuicPacketHeader header; |
| 11155 | header.destination_connection_id = FramerTestConnectionId(); |
| 11156 | header.reset_flag = false; |
| 11157 | header.version_flag = false; |
| 11158 | header.packet_number = kPacketNumber; |
| 11159 | |
| 11160 | QuicNewConnectionIdFrame frame; |
| 11161 | frame.sequence_number = 0x11; |
| 11162 | // Use this value to force a 4-byte encoded variable length connection ID |
| 11163 | // in the frame. |
| 11164 | frame.connection_id = FramerTestConnectionIdPlusOne(); |
| 11165 | frame.stateless_reset_token = kTestStatelessResetToken; |
| 11166 | |
| 11167 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11168 | |
| 11169 | // clang-format off |
| 11170 | unsigned char packet99[] = { |
| 11171 | // type (short header, 4 byte packet number) |
| 11172 | 0x43, |
| 11173 | // connection_id |
| 11174 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11175 | // packet number |
| 11176 | 0x12, 0x34, 0x56, 0x78, |
| 11177 | |
| 11178 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 11179 | 0x18, |
| 11180 | // sequence number |
| 11181 | kVarInt62OneByte + 0x11, |
| 11182 | // new connection id length |
| 11183 | 0x08, |
| 11184 | // new connection id |
| 11185 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 11186 | // stateless reset token |
| 11187 | 0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11188 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11189 | }; |
| 11190 | // clang-format on |
| 11191 | |
| 11192 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11193 | ASSERT_TRUE(data != nullptr); |
| 11194 | |
| 11195 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11196 | data->length(), AsChars(packet99), |
| 11197 | QUIC_ARRAYSIZE(packet99)); |
| 11198 | } |
| 11199 | |
| 11200 | TEST_P(QuicFramerTest, NewTokenFrame) { |
| 11201 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11202 | // This frame is only for version 99. |
| 11203 | return; |
| 11204 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11205 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11206 | // clang-format off |
| 11207 | PacketFragments packet = { |
| 11208 | // type (short header, 4 byte packet number) |
| 11209 | {"", |
| 11210 | {0x43}}, |
| 11211 | // connection_id |
| 11212 | {"", |
| 11213 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11214 | // packet number |
| 11215 | {"", |
| 11216 | {0x12, 0x34, 0x56, 0x78}}, |
| 11217 | // frame type (IETF_NEW_TOKEN frame) |
| 11218 | {"", |
| 11219 | {0x07}}, |
| 11220 | // Length |
| 11221 | {"Unable to read new token length.", |
| 11222 | {kVarInt62OneByte + 0x08}}, |
| 11223 | {"Unable to read new token data.", |
| 11224 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}} |
| 11225 | }; |
| 11226 | // clang-format on |
| 11227 | uint8_t expected_token_value[] = {0x00, 0x01, 0x02, 0x03, |
| 11228 | 0x04, 0x05, 0x06, 0x07}; |
| 11229 | |
| 11230 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11231 | AssemblePacketFromFragments(packet)); |
| 11232 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11233 | |
| 11234 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11235 | ASSERT_TRUE(visitor_.header_.get()); |
| 11236 | EXPECT_TRUE(CheckDecryption( |
| 11237 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11238 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11239 | |
| 11240 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 11241 | |
| 11242 | EXPECT_EQ(sizeof(expected_token_value), visitor_.new_token_.token.length()); |
| 11243 | EXPECT_EQ(0, memcmp(expected_token_value, visitor_.new_token_.token.data(), |
| 11244 | sizeof(expected_token_value))); |
| 11245 | |
| 11246 | CheckFramingBoundaries(packet, QUIC_INVALID_NEW_TOKEN); |
| 11247 | } |
| 11248 | |
| 11249 | TEST_P(QuicFramerTest, BuildNewTokenFramePacket) { |
| 11250 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11251 | // This frame is only for version 99. |
| 11252 | return; |
| 11253 | } |
| 11254 | QuicPacketHeader header; |
| 11255 | header.destination_connection_id = FramerTestConnectionId(); |
| 11256 | header.reset_flag = false; |
| 11257 | header.version_flag = false; |
| 11258 | header.packet_number = kPacketNumber; |
| 11259 | |
| 11260 | uint8_t expected_token_value[] = {0x00, 0x01, 0x02, 0x03, |
| 11261 | 0x04, 0x05, 0x06, 0x07}; |
| 11262 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 11263 | QuicNewTokenFrame frame(0, std::string((const char*)(expected_token_value), |
| 11264 | sizeof(expected_token_value))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11265 | |
| 11266 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11267 | |
| 11268 | // clang-format off |
| 11269 | unsigned char packet[] = { |
| 11270 | // type (short header, 4 byte packet number) |
| 11271 | 0x43, |
| 11272 | // connection_id |
| 11273 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11274 | // packet number |
| 11275 | 0x12, 0x34, 0x56, 0x78, |
| 11276 | |
| 11277 | // frame type (IETF_NEW_TOKEN frame) |
| 11278 | 0x07, |
| 11279 | // Length and token |
| 11280 | kVarInt62OneByte + 0x08, |
| 11281 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 11282 | }; |
| 11283 | // clang-format on |
| 11284 | |
| 11285 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11286 | ASSERT_TRUE(data != nullptr); |
| 11287 | |
| 11288 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11289 | data->length(), AsChars(packet), |
| 11290 | QUIC_ARRAYSIZE(packet)); |
| 11291 | } |
| 11292 | |
| 11293 | TEST_P(QuicFramerTest, IetfStopSendingFrame) { |
| 11294 | // This test is only for version 99. |
| 11295 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11296 | return; |
| 11297 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11298 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11299 | |
| 11300 | // clang-format off |
| 11301 | PacketFragments packet99 = { |
| 11302 | // type (short header, 4 byte packet number) |
| 11303 | {"", |
| 11304 | {0x43}}, |
| 11305 | // connection_id |
| 11306 | {"", |
| 11307 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11308 | // packet number |
| 11309 | {"", |
| 11310 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11311 | // frame type (IETF_STOP_SENDING frame) |
| 11312 | {"", |
| 11313 | {0x05}}, |
| 11314 | // stream id |
| 11315 | {"Unable to read stop sending stream id.", |
| 11316 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 11317 | {"Unable to read stop sending application error code.", |
| 11318 | {0x76, 0x54}}, |
| 11319 | }; |
| 11320 | // clang-format on |
| 11321 | |
| 11322 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11323 | AssemblePacketFromFragments(packet99)); |
| 11324 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11325 | |
| 11326 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11327 | ASSERT_TRUE(visitor_.header_.get()); |
| 11328 | EXPECT_TRUE(CheckDecryption( |
| 11329 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11330 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11331 | |
| 11332 | EXPECT_EQ(kStreamId, visitor_.stop_sending_frame_.stream_id); |
| 11333 | EXPECT_EQ(0x7654, visitor_.stop_sending_frame_.application_error_code); |
| 11334 | |
| 11335 | CheckFramingBoundaries(packet99, QUIC_INVALID_STOP_SENDING_FRAME_DATA); |
| 11336 | } |
| 11337 | |
| 11338 | TEST_P(QuicFramerTest, BuildIetfStopSendingPacket) { |
| 11339 | // This test is only for version 99. |
| 11340 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11341 | return; |
| 11342 | } |
| 11343 | |
| 11344 | QuicPacketHeader header; |
| 11345 | header.destination_connection_id = FramerTestConnectionId(); |
| 11346 | header.reset_flag = false; |
| 11347 | header.version_flag = false; |
| 11348 | header.packet_number = kPacketNumber; |
| 11349 | |
| 11350 | QuicStopSendingFrame frame; |
| 11351 | frame.stream_id = kStreamId; |
| 11352 | frame.application_error_code = 0xffff; |
| 11353 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11354 | |
| 11355 | // clang-format off |
| 11356 | unsigned char packet99[] = { |
| 11357 | // type (short header, 4 byte packet number) |
| 11358 | 0x43, |
| 11359 | // connection_id |
| 11360 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11361 | // packet number |
| 11362 | 0x12, 0x34, 0x56, 0x78, |
| 11363 | |
| 11364 | // frame type (IETF_STOP_SENDING frame) |
| 11365 | 0x05, |
| 11366 | // Stream ID |
| 11367 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 11368 | // Application error code |
| 11369 | 0xff, 0xff |
| 11370 | }; |
| 11371 | // clang-format on |
| 11372 | |
| 11373 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11374 | ASSERT_TRUE(data != nullptr); |
| 11375 | |
| 11376 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11377 | data->length(), AsChars(packet99), |
| 11378 | QUIC_ARRAYSIZE(packet99)); |
| 11379 | } |
| 11380 | |
| 11381 | TEST_P(QuicFramerTest, IetfPathChallengeFrame) { |
| 11382 | // This test only for version 99. |
| 11383 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11384 | return; |
| 11385 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11386 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11387 | |
| 11388 | // clang-format off |
| 11389 | PacketFragments packet99 = { |
| 11390 | // type (short header, 4 byte packet number) |
| 11391 | {"", |
| 11392 | {0x43}}, |
| 11393 | // connection_id |
| 11394 | {"", |
| 11395 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11396 | // packet number |
| 11397 | {"", |
| 11398 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11399 | // frame type (IETF_PATH_CHALLENGE) |
| 11400 | {"", |
| 11401 | {0x1a}}, |
| 11402 | // data |
| 11403 | {"Can not read path challenge data.", |
| 11404 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}}, |
| 11405 | }; |
| 11406 | // clang-format on |
| 11407 | |
| 11408 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11409 | AssemblePacketFromFragments(packet99)); |
| 11410 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11411 | |
| 11412 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11413 | ASSERT_TRUE(visitor_.header_.get()); |
| 11414 | EXPECT_TRUE(CheckDecryption( |
| 11415 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11416 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11417 | |
| 11418 | EXPECT_EQ(QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}), |
| 11419 | visitor_.path_challenge_frame_.data_buffer); |
| 11420 | |
| 11421 | CheckFramingBoundaries(packet99, QUIC_INVALID_PATH_CHALLENGE_DATA); |
| 11422 | } |
| 11423 | |
| 11424 | TEST_P(QuicFramerTest, BuildIetfPathChallengePacket) { |
| 11425 | // This test only for version 99. |
| 11426 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11427 | return; |
| 11428 | } |
| 11429 | |
| 11430 | QuicPacketHeader header; |
| 11431 | header.destination_connection_id = FramerTestConnectionId(); |
| 11432 | header.reset_flag = false; |
| 11433 | header.version_flag = false; |
| 11434 | header.packet_number = kPacketNumber; |
| 11435 | |
| 11436 | QuicPathChallengeFrame frame; |
| 11437 | frame.data_buffer = QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}); |
| 11438 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11439 | |
| 11440 | // clang-format off |
| 11441 | unsigned char packet99[] = { |
| 11442 | // type (short header, 4 byte packet number) |
| 11443 | 0x43, |
| 11444 | // connection_id |
| 11445 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11446 | // packet number |
| 11447 | 0x12, 0x34, 0x56, 0x78, |
| 11448 | |
| 11449 | // frame type (IETF_PATH_CHALLENGE) |
| 11450 | 0x1a, |
| 11451 | // Data |
| 11452 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 11453 | }; |
| 11454 | // clang-format on |
| 11455 | |
| 11456 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11457 | ASSERT_TRUE(data != nullptr); |
| 11458 | |
| 11459 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11460 | data->length(), AsChars(packet99), |
| 11461 | QUIC_ARRAYSIZE(packet99)); |
| 11462 | } |
| 11463 | |
| 11464 | TEST_P(QuicFramerTest, IetfPathResponseFrame) { |
| 11465 | // This test only for version 99. |
| 11466 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11467 | return; |
| 11468 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11469 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11470 | |
| 11471 | // clang-format off |
| 11472 | PacketFragments packet99 = { |
| 11473 | // type (short header, 4 byte packet number) |
| 11474 | {"", |
| 11475 | {0x43}}, |
| 11476 | // connection_id |
| 11477 | {"", |
| 11478 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11479 | // packet number |
| 11480 | {"", |
| 11481 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11482 | // frame type (IETF_PATH_RESPONSE) |
| 11483 | {"", |
| 11484 | {0x1b}}, |
| 11485 | // data |
| 11486 | {"Can not read path response data.", |
| 11487 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}}, |
| 11488 | }; |
| 11489 | // clang-format on |
| 11490 | |
| 11491 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11492 | AssemblePacketFromFragments(packet99)); |
| 11493 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11494 | |
| 11495 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11496 | ASSERT_TRUE(visitor_.header_.get()); |
| 11497 | EXPECT_TRUE(CheckDecryption( |
| 11498 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11499 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11500 | |
| 11501 | EXPECT_EQ(QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}), |
| 11502 | visitor_.path_response_frame_.data_buffer); |
| 11503 | |
| 11504 | CheckFramingBoundaries(packet99, QUIC_INVALID_PATH_RESPONSE_DATA); |
| 11505 | } |
| 11506 | |
| 11507 | TEST_P(QuicFramerTest, BuildIetfPathResponsePacket) { |
| 11508 | // This test only for version 99. |
| 11509 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11510 | return; |
| 11511 | } |
| 11512 | |
| 11513 | QuicPacketHeader header; |
| 11514 | header.destination_connection_id = FramerTestConnectionId(); |
| 11515 | header.reset_flag = false; |
| 11516 | header.version_flag = false; |
| 11517 | header.packet_number = kPacketNumber; |
| 11518 | |
| 11519 | QuicPathResponseFrame frame; |
| 11520 | frame.data_buffer = QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}); |
| 11521 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11522 | |
| 11523 | // clang-format off |
| 11524 | unsigned char packet99[] = { |
| 11525 | // type (short header, 4 byte packet number) |
| 11526 | 0x43, |
| 11527 | // connection_id |
| 11528 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11529 | // packet number |
| 11530 | 0x12, 0x34, 0x56, 0x78, |
| 11531 | |
| 11532 | // frame type (IETF_PATH_RESPONSE) |
| 11533 | 0x1b, |
| 11534 | // Data |
| 11535 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 11536 | }; |
| 11537 | // clang-format on |
| 11538 | |
| 11539 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11540 | ASSERT_TRUE(data != nullptr); |
| 11541 | |
| 11542 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11543 | data->length(), AsChars(packet99), |
| 11544 | QUIC_ARRAYSIZE(packet99)); |
| 11545 | } |
| 11546 | |
| 11547 | TEST_P(QuicFramerTest, GetRetransmittableControlFrameSize) { |
| 11548 | QuicRstStreamFrame rst_stream(1, 3, QUIC_STREAM_CANCELLED, 1024); |
| 11549 | EXPECT_EQ(QuicFramer::GetRstStreamFrameSize(framer_.transport_version(), |
| 11550 | rst_stream), |
| 11551 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11552 | framer_.transport_version(), QuicFrame(&rst_stream))); |
| 11553 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 11554 | std::string error_detail(2048, 'e'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11555 | QuicConnectionCloseFrame connection_close(QUIC_NETWORK_IDLE_TIMEOUT, |
| 11556 | error_detail); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 11557 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 11558 | connection_close.close_type = IETF_QUIC_TRANSPORT_CONNECTION_CLOSE; |
| 11559 | } |
| 11560 | |
fkastenholz | a037b8b | 2019-05-07 06:00:05 -0700 | [diff] [blame^] | 11561 | EXPECT_EQ(QuicFramer::GetConnectionCloseFrameSize(framer_.transport_version(), |
| 11562 | connection_close), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11563 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11564 | framer_.transport_version(), QuicFrame(&connection_close))); |
| 11565 | |
| 11566 | QuicGoAwayFrame goaway(2, QUIC_PEER_GOING_AWAY, 3, error_detail); |
| 11567 | EXPECT_EQ(QuicFramer::GetMinGoAwayFrameSize() + 256, |
| 11568 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11569 | framer_.transport_version(), QuicFrame(&goaway))); |
| 11570 | |
| 11571 | QuicWindowUpdateFrame window_update(3, 3, 1024); |
| 11572 | EXPECT_EQ(QuicFramer::GetWindowUpdateFrameSize(framer_.transport_version(), |
| 11573 | window_update), |
| 11574 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11575 | framer_.transport_version(), QuicFrame(&window_update))); |
| 11576 | |
| 11577 | QuicBlockedFrame blocked(4, 3, 1024); |
| 11578 | EXPECT_EQ( |
| 11579 | QuicFramer::GetBlockedFrameSize(framer_.transport_version(), blocked), |
| 11580 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11581 | framer_.transport_version(), QuicFrame(&blocked))); |
| 11582 | |
| 11583 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11584 | return; |
| 11585 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11586 | |
| 11587 | QuicNewConnectionIdFrame new_connection_id(5, TestConnectionId(), 1, 101111); |
| 11588 | EXPECT_EQ(QuicFramer::GetNewConnectionIdFrameSize(new_connection_id), |
| 11589 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11590 | framer_.transport_version(), QuicFrame(&new_connection_id))); |
| 11591 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11592 | QuicMaxStreamsFrame max_streams(6, 3, /*unidirectional=*/false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11593 | EXPECT_EQ(QuicFramer::GetMaxStreamsFrameSize(framer_.transport_version(), |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11594 | max_streams), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11595 | QuicFramer::GetRetransmittableControlFrameSize( |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11596 | framer_.transport_version(), QuicFrame(max_streams))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11597 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11598 | QuicStreamsBlockedFrame streams_blocked(7, 3, /*unidirectional=*/false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11599 | EXPECT_EQ(QuicFramer::GetStreamsBlockedFrameSize(framer_.transport_version(), |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11600 | streams_blocked), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11601 | QuicFramer::GetRetransmittableControlFrameSize( |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11602 | framer_.transport_version(), QuicFrame(streams_blocked))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11603 | |
| 11604 | QuicPathFrameBuffer buffer = { |
| 11605 | {0x80, 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe5, 0xf7}}; |
| 11606 | QuicPathResponseFrame path_response_frame(8, buffer); |
| 11607 | EXPECT_EQ(QuicFramer::GetPathResponseFrameSize(path_response_frame), |
| 11608 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11609 | framer_.transport_version(), QuicFrame(&path_response_frame))); |
| 11610 | |
| 11611 | QuicPathChallengeFrame path_challenge_frame(9, buffer); |
| 11612 | EXPECT_EQ(QuicFramer::GetPathChallengeFrameSize(path_challenge_frame), |
| 11613 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11614 | framer_.transport_version(), QuicFrame(&path_challenge_frame))); |
| 11615 | |
| 11616 | QuicStopSendingFrame stop_sending_frame(10, 3, 20); |
| 11617 | EXPECT_EQ(QuicFramer::GetStopSendingFrameSize(stop_sending_frame), |
| 11618 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11619 | framer_.transport_version(), QuicFrame(&stop_sending_frame))); |
| 11620 | } |
| 11621 | |
| 11622 | // A set of tests to ensure that bad frame-type encodings |
| 11623 | // are properly detected and handled. |
| 11624 | // First, four tests to see that unknown frame types generate |
| 11625 | // a QUIC_INVALID_FRAME_DATA error with detailed information |
| 11626 | // "Illegal frame type." This regardless of the encoding of the type |
| 11627 | // (1/2/4/8 bytes). |
| 11628 | // This only for version 99. |
| 11629 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown1Byte) { |
| 11630 | // This test only for version 99. |
| 11631 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11632 | return; |
| 11633 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11634 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11635 | // clang-format off |
| 11636 | PacketFragments packet = { |
| 11637 | // type (short header, 4 byte packet number) |
| 11638 | {"", |
| 11639 | {0x43}}, |
| 11640 | // connection_id |
| 11641 | {"", |
| 11642 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11643 | // packet number |
| 11644 | {"", |
| 11645 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11646 | // frame type (unknown value, single-byte encoding) |
| 11647 | {"", |
| 11648 | {0x38}} |
| 11649 | }; |
| 11650 | // clang-format on |
| 11651 | |
| 11652 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11653 | AssemblePacketFromFragments(packet)); |
| 11654 | |
| 11655 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11656 | |
| 11657 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 11658 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11659 | } |
| 11660 | |
| 11661 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown2Bytes) { |
| 11662 | // This test only for version 99. |
| 11663 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11664 | return; |
| 11665 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11666 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11667 | |
| 11668 | // clang-format off |
| 11669 | PacketFragments packet = { |
| 11670 | // type (short header, 4 byte packet number) |
| 11671 | {"", |
| 11672 | {0x43}}, |
| 11673 | // connection_id |
| 11674 | {"", |
| 11675 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11676 | // packet number |
| 11677 | {"", |
| 11678 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11679 | // frame type (unknown value, two-byte encoding) |
| 11680 | {"", |
| 11681 | {kVarInt62TwoBytes + 0x01, 0x38}} |
| 11682 | }; |
| 11683 | // clang-format on |
| 11684 | |
| 11685 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11686 | AssemblePacketFromFragments(packet)); |
| 11687 | |
| 11688 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11689 | |
| 11690 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 11691 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11692 | } |
| 11693 | |
| 11694 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown4Bytes) { |
| 11695 | // This test only for version 99. |
| 11696 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11697 | return; |
| 11698 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11699 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11700 | |
| 11701 | // clang-format off |
| 11702 | PacketFragments packet = { |
| 11703 | // type (short header, 4 byte packet number) |
| 11704 | {"", |
| 11705 | {0x43}}, |
| 11706 | // connection_id |
| 11707 | {"", |
| 11708 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11709 | // packet number |
| 11710 | {"", |
| 11711 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11712 | // frame type (unknown value, four-byte encoding) |
| 11713 | {"", |
| 11714 | {kVarInt62FourBytes + 0x01, 0x00, 0x00, 0x38}} |
| 11715 | }; |
| 11716 | // clang-format on |
| 11717 | |
| 11718 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11719 | AssemblePacketFromFragments(packet)); |
| 11720 | |
| 11721 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11722 | |
| 11723 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 11724 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11725 | } |
| 11726 | |
| 11727 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown8Bytes) { |
| 11728 | // This test only for version 99. |
| 11729 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11730 | return; |
| 11731 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11732 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11733 | // clang-format off |
| 11734 | PacketFragments packet = { |
| 11735 | // type (short header, 4 byte packet number) |
| 11736 | {"", |
| 11737 | {0x43}}, |
| 11738 | // connection_id |
| 11739 | {"", |
| 11740 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11741 | // packet number |
| 11742 | {"", |
| 11743 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11744 | // frame type (unknown value, eight-byte encoding) |
| 11745 | {"", |
| 11746 | {kVarInt62EightBytes + 0x01, 0x00, 0x00, 0x01, 0x02, 0x34, 0x56, 0x38}} |
| 11747 | }; |
| 11748 | // clang-format on |
| 11749 | |
| 11750 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11751 | AssemblePacketFromFragments(packet)); |
| 11752 | |
| 11753 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11754 | |
| 11755 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 11756 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11757 | } |
| 11758 | |
| 11759 | // Three tests to check that known frame types that are not minimally |
| 11760 | // encoded generate IETF_QUIC_PROTOCOL_VIOLATION errors with detailed |
| 11761 | // information "Frame type not minimally encoded." |
| 11762 | // Look at the frame-type encoded in 2, 4, and 8 bytes. |
| 11763 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2Bytes) { |
| 11764 | // This test only for version 99. |
| 11765 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11766 | return; |
| 11767 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11768 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11769 | |
| 11770 | // clang-format off |
| 11771 | PacketFragments packet = { |
| 11772 | // type (short header, 4 byte packet number) |
| 11773 | {"", |
| 11774 | {0x43}}, |
| 11775 | // connection_id |
| 11776 | {"", |
| 11777 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11778 | // packet number |
| 11779 | {"", |
| 11780 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11781 | // frame type (Blocked, two-byte encoding) |
| 11782 | {"", |
| 11783 | {kVarInt62TwoBytes + 0x00, 0x08}} |
| 11784 | }; |
| 11785 | // clang-format on |
| 11786 | |
| 11787 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11788 | AssemblePacketFromFragments(packet)); |
| 11789 | |
| 11790 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11791 | |
| 11792 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 11793 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11794 | } |
| 11795 | |
| 11796 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown4Bytes) { |
| 11797 | // This test only for version 99. |
| 11798 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11799 | return; |
| 11800 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11801 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11802 | |
| 11803 | // clang-format off |
| 11804 | PacketFragments packet = { |
| 11805 | // type (short header, 4 byte packet number) |
| 11806 | {"", |
| 11807 | {0x43}}, |
| 11808 | // connection_id |
| 11809 | {"", |
| 11810 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11811 | // packet number |
| 11812 | {"", |
| 11813 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11814 | // frame type (Blocked, four-byte encoding) |
| 11815 | {"", |
| 11816 | {kVarInt62FourBytes + 0x00, 0x00, 0x00, 0x08}} |
| 11817 | }; |
| 11818 | // clang-format on |
| 11819 | |
| 11820 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11821 | AssemblePacketFromFragments(packet)); |
| 11822 | |
| 11823 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11824 | |
| 11825 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 11826 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11827 | } |
| 11828 | |
| 11829 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown8Bytes) { |
| 11830 | // This test only for version 99. |
| 11831 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11832 | return; |
| 11833 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11834 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11835 | // clang-format off |
| 11836 | PacketFragments packet = { |
| 11837 | // type (short header, 4 byte packet number) |
| 11838 | {"", |
| 11839 | {0x43}}, |
| 11840 | // connection_id |
| 11841 | {"", |
| 11842 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11843 | // packet number |
| 11844 | {"", |
| 11845 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11846 | // frame type (Blocked, eight-byte encoding) |
| 11847 | {"", |
| 11848 | {kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08}} |
| 11849 | }; |
| 11850 | // clang-format on |
| 11851 | |
| 11852 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11853 | AssemblePacketFromFragments(packet)); |
| 11854 | |
| 11855 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11856 | |
| 11857 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 11858 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11859 | } |
| 11860 | |
| 11861 | // Tests to check that all known OETF frame types that are not minimally |
| 11862 | // encoded generate IETF_QUIC_PROTOCOL_VIOLATION errors with detailed |
| 11863 | // information "Frame type not minimally encoded." |
| 11864 | // Just look at 2-byte encoding. |
| 11865 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2BytesAllTypes) { |
| 11866 | // This test only for version 99. |
| 11867 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11868 | return; |
| 11869 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11870 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11871 | |
| 11872 | // clang-format off |
| 11873 | PacketFragments packets[] = { |
| 11874 | { |
| 11875 | // type (short header, 4 byte packet number) |
| 11876 | {"", |
| 11877 | {0x43}}, |
| 11878 | // connection_id |
| 11879 | {"", |
| 11880 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11881 | // packet number |
| 11882 | {"", |
| 11883 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11884 | // frame type (two-byte encoding) |
| 11885 | {"", |
| 11886 | {kVarInt62TwoBytes + 0x00, 0x00}} |
| 11887 | }, |
| 11888 | { |
| 11889 | // type (short header, 4 byte packet number) |
| 11890 | {"", |
| 11891 | {0x43}}, |
| 11892 | // connection_id |
| 11893 | {"", |
| 11894 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11895 | // packet number |
| 11896 | {"", |
| 11897 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11898 | // frame type (two-byte encoding) |
| 11899 | {"", |
| 11900 | {kVarInt62TwoBytes + 0x00, 0x01}} |
| 11901 | }, |
| 11902 | { |
| 11903 | // type (short header, 4 byte packet number) |
| 11904 | {"", |
| 11905 | {0x43}}, |
| 11906 | // connection_id |
| 11907 | {"", |
| 11908 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11909 | // packet number |
| 11910 | {"", |
| 11911 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11912 | // frame type (two-byte encoding) |
| 11913 | {"", |
| 11914 | {kVarInt62TwoBytes + 0x00, 0x02}} |
| 11915 | }, |
| 11916 | { |
| 11917 | // type (short header, 4 byte packet number) |
| 11918 | {"", |
| 11919 | {0x43}}, |
| 11920 | // connection_id |
| 11921 | {"", |
| 11922 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11923 | // packet number |
| 11924 | {"", |
| 11925 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11926 | // frame type (two-byte encoding) |
| 11927 | {"", |
| 11928 | {kVarInt62TwoBytes + 0x00, 0x03}} |
| 11929 | }, |
| 11930 | { |
| 11931 | // type (short header, 4 byte packet number) |
| 11932 | {"", |
| 11933 | {0x43}}, |
| 11934 | // connection_id |
| 11935 | {"", |
| 11936 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11937 | // packet number |
| 11938 | {"", |
| 11939 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11940 | // frame type (two-byte encoding) |
| 11941 | {"", |
| 11942 | {kVarInt62TwoBytes + 0x00, 0x04}} |
| 11943 | }, |
| 11944 | { |
| 11945 | // type (short header, 4 byte packet number) |
| 11946 | {"", |
| 11947 | {0x43}}, |
| 11948 | // connection_id |
| 11949 | {"", |
| 11950 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11951 | // packet number |
| 11952 | {"", |
| 11953 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11954 | // frame type (two-byte encoding) |
| 11955 | {"", |
| 11956 | {kVarInt62TwoBytes + 0x00, 0x05}} |
| 11957 | }, |
| 11958 | { |
| 11959 | // type (short header, 4 byte packet number) |
| 11960 | {"", |
| 11961 | {0x43}}, |
| 11962 | // connection_id |
| 11963 | {"", |
| 11964 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11965 | // packet number |
| 11966 | {"", |
| 11967 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11968 | // frame type (two-byte encoding) |
| 11969 | {"", |
| 11970 | {kVarInt62TwoBytes + 0x00, 0x06}} |
| 11971 | }, |
| 11972 | { |
| 11973 | // type (short header, 4 byte packet number) |
| 11974 | {"", |
| 11975 | {0x43}}, |
| 11976 | // connection_id |
| 11977 | {"", |
| 11978 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11979 | // packet number |
| 11980 | {"", |
| 11981 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11982 | // frame type (two-byte encoding) |
| 11983 | {"", |
| 11984 | {kVarInt62TwoBytes + 0x00, 0x07}} |
| 11985 | }, |
| 11986 | { |
| 11987 | // type (short header, 4 byte packet number) |
| 11988 | {"", |
| 11989 | {0x43}}, |
| 11990 | // connection_id |
| 11991 | {"", |
| 11992 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11993 | // packet number |
| 11994 | {"", |
| 11995 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11996 | // frame type (two-byte encoding) |
| 11997 | {"", |
| 11998 | {kVarInt62TwoBytes + 0x00, 0x08}} |
| 11999 | }, |
| 12000 | { |
| 12001 | // type (short header, 4 byte packet number) |
| 12002 | {"", |
| 12003 | {0x43}}, |
| 12004 | // connection_id |
| 12005 | {"", |
| 12006 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12007 | // packet number |
| 12008 | {"", |
| 12009 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12010 | // frame type (two-byte encoding) |
| 12011 | {"", |
| 12012 | {kVarInt62TwoBytes + 0x00, 0x09}} |
| 12013 | }, |
| 12014 | { |
| 12015 | // type (short header, 4 byte packet number) |
| 12016 | {"", |
| 12017 | {0x43}}, |
| 12018 | // connection_id |
| 12019 | {"", |
| 12020 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12021 | // packet number |
| 12022 | {"", |
| 12023 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12024 | // frame type (two-byte encoding) |
| 12025 | {"", |
| 12026 | {kVarInt62TwoBytes + 0x00, 0x0a}} |
| 12027 | }, |
| 12028 | { |
| 12029 | // type (short header, 4 byte packet number) |
| 12030 | {"", |
| 12031 | {0x43}}, |
| 12032 | // connection_id |
| 12033 | {"", |
| 12034 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12035 | // packet number |
| 12036 | {"", |
| 12037 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12038 | // frame type (two-byte encoding) |
| 12039 | {"", |
| 12040 | {kVarInt62TwoBytes + 0x00, 0x0b}} |
| 12041 | }, |
| 12042 | { |
| 12043 | // type (short header, 4 byte packet number) |
| 12044 | {"", |
| 12045 | {0x43}}, |
| 12046 | // connection_id |
| 12047 | {"", |
| 12048 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12049 | // packet number |
| 12050 | {"", |
| 12051 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12052 | // frame type (two-byte encoding) |
| 12053 | {"", |
| 12054 | {kVarInt62TwoBytes + 0x00, 0x0c}} |
| 12055 | }, |
| 12056 | { |
| 12057 | // type (short header, 4 byte packet number) |
| 12058 | {"", |
| 12059 | {0x43}}, |
| 12060 | // connection_id |
| 12061 | {"", |
| 12062 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12063 | // packet number |
| 12064 | {"", |
| 12065 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12066 | // frame type (two-byte encoding) |
| 12067 | {"", |
| 12068 | {kVarInt62TwoBytes + 0x00, 0x0d}} |
| 12069 | }, |
| 12070 | { |
| 12071 | // type (short header, 4 byte packet number) |
| 12072 | {"", |
| 12073 | {0x43}}, |
| 12074 | // connection_id |
| 12075 | {"", |
| 12076 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12077 | // packet number |
| 12078 | {"", |
| 12079 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12080 | // frame type (two-byte encoding) |
| 12081 | {"", |
| 12082 | {kVarInt62TwoBytes + 0x00, 0x0e}} |
| 12083 | }, |
| 12084 | { |
| 12085 | // type (short header, 4 byte packet number) |
| 12086 | {"", |
| 12087 | {0x43}}, |
| 12088 | // connection_id |
| 12089 | {"", |
| 12090 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12091 | // packet number |
| 12092 | {"", |
| 12093 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12094 | // frame type (two-byte encoding) |
| 12095 | {"", |
| 12096 | {kVarInt62TwoBytes + 0x00, 0x0f}} |
| 12097 | }, |
| 12098 | { |
| 12099 | // type (short header, 4 byte packet number) |
| 12100 | {"", |
| 12101 | {0x43}}, |
| 12102 | // connection_id |
| 12103 | {"", |
| 12104 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12105 | // packet number |
| 12106 | {"", |
| 12107 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12108 | // frame type (two-byte encoding) |
| 12109 | {"", |
| 12110 | {kVarInt62TwoBytes + 0x00, 0x10}} |
| 12111 | }, |
| 12112 | { |
| 12113 | // type (short header, 4 byte packet number) |
| 12114 | {"", |
| 12115 | {0x43}}, |
| 12116 | // connection_id |
| 12117 | {"", |
| 12118 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12119 | // packet number |
| 12120 | {"", |
| 12121 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12122 | // frame type (two-byte encoding) |
| 12123 | {"", |
| 12124 | {kVarInt62TwoBytes + 0x00, 0x11}} |
| 12125 | }, |
| 12126 | { |
| 12127 | // type (short header, 4 byte packet number) |
| 12128 | {"", |
| 12129 | {0x43}}, |
| 12130 | // connection_id |
| 12131 | {"", |
| 12132 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12133 | // packet number |
| 12134 | {"", |
| 12135 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12136 | // frame type (two-byte encoding) |
| 12137 | {"", |
| 12138 | {kVarInt62TwoBytes + 0x00, 0x12}} |
| 12139 | }, |
| 12140 | { |
| 12141 | // type (short header, 4 byte packet number) |
| 12142 | {"", |
| 12143 | {0x43}}, |
| 12144 | // connection_id |
| 12145 | {"", |
| 12146 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12147 | // packet number |
| 12148 | {"", |
| 12149 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12150 | // frame type (two-byte encoding) |
| 12151 | {"", |
| 12152 | {kVarInt62TwoBytes + 0x00, 0x13}} |
| 12153 | }, |
| 12154 | { |
| 12155 | // type (short header, 4 byte packet number) |
| 12156 | {"", |
| 12157 | {0x43}}, |
| 12158 | // connection_id |
| 12159 | {"", |
| 12160 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12161 | // packet number |
| 12162 | {"", |
| 12163 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12164 | // frame type (two-byte encoding) |
| 12165 | {"", |
| 12166 | {kVarInt62TwoBytes + 0x00, 0x14}} |
| 12167 | }, |
| 12168 | { |
| 12169 | // type (short header, 4 byte packet number) |
| 12170 | {"", |
| 12171 | {0x43}}, |
| 12172 | // connection_id |
| 12173 | {"", |
| 12174 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12175 | // packet number |
| 12176 | {"", |
| 12177 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12178 | // frame type (two-byte encoding) |
| 12179 | {"", |
| 12180 | {kVarInt62TwoBytes + 0x00, 0x15}} |
| 12181 | }, |
| 12182 | { |
| 12183 | // type (short header, 4 byte packet number) |
| 12184 | {"", |
| 12185 | {0x43}}, |
| 12186 | // connection_id |
| 12187 | {"", |
| 12188 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12189 | // packet number |
| 12190 | {"", |
| 12191 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12192 | // frame type (two-byte encoding) |
| 12193 | {"", |
| 12194 | {kVarInt62TwoBytes + 0x00, 0x16}} |
| 12195 | }, |
| 12196 | { |
| 12197 | // type (short header, 4 byte packet number) |
| 12198 | {"", |
| 12199 | {0x43}}, |
| 12200 | // connection_id |
| 12201 | {"", |
| 12202 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12203 | // packet number |
| 12204 | {"", |
| 12205 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12206 | // frame type (two-byte encoding) |
| 12207 | {"", |
| 12208 | {kVarInt62TwoBytes + 0x00, 0x17}} |
| 12209 | }, |
| 12210 | { |
| 12211 | // type (short header, 4 byte packet number) |
| 12212 | {"", |
| 12213 | {0x43}}, |
| 12214 | // connection_id |
| 12215 | {"", |
| 12216 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12217 | // packet number |
| 12218 | {"", |
| 12219 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12220 | // frame type (two-byte encoding) |
| 12221 | {"", |
| 12222 | {kVarInt62TwoBytes + 0x00, 0x18}} |
| 12223 | }, |
| 12224 | { |
| 12225 | // type (short header, 4 byte packet number) |
| 12226 | {"", |
| 12227 | {0x43}}, |
| 12228 | // connection_id |
| 12229 | {"", |
| 12230 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12231 | // packet number |
| 12232 | {"", |
| 12233 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12234 | // frame type (two-byte encoding) |
| 12235 | {"", |
| 12236 | {kVarInt62TwoBytes + 0x00, 0x20}} |
| 12237 | }, |
| 12238 | { |
| 12239 | // type (short header, 4 byte packet number) |
| 12240 | {"", |
| 12241 | {0x43}}, |
| 12242 | // connection_id |
| 12243 | {"", |
| 12244 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12245 | // packet number |
| 12246 | {"", |
| 12247 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12248 | // frame type (two-byte encoding) |
| 12249 | {"", |
| 12250 | {kVarInt62TwoBytes + 0x00, 0x21}} |
| 12251 | }, |
| 12252 | }; |
| 12253 | // clang-format on |
| 12254 | |
| 12255 | for (PacketFragments& packet : packets) { |
| 12256 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12257 | AssemblePacketFromFragments(packet)); |
| 12258 | |
| 12259 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 12260 | |
| 12261 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 12262 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 12263 | } |
| 12264 | } |
| 12265 | |
| 12266 | TEST_P(QuicFramerTest, RetireConnectionIdFrame) { |
| 12267 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 12268 | // This frame is only for version 99. |
| 12269 | return; |
| 12270 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12271 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12272 | // clang-format off |
| 12273 | PacketFragments packet99 = { |
| 12274 | // type (short header, 4 byte packet number) |
| 12275 | {"", |
| 12276 | {0x43}}, |
| 12277 | // connection_id |
| 12278 | {"", |
| 12279 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12280 | // packet number |
| 12281 | {"", |
| 12282 | {0x12, 0x34, 0x56, 0x78}}, |
| 12283 | // frame type (IETF_RETIRE_CONNECTION_ID frame) |
| 12284 | {"", |
| 12285 | {0x19}}, |
| 12286 | // Sequence number |
| 12287 | {"Unable to read retire connection ID frame sequence number.", |
| 12288 | {kVarInt62TwoBytes + 0x11, 0x22}} |
| 12289 | }; |
| 12290 | // clang-format on |
| 12291 | |
| 12292 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12293 | AssemblePacketFromFragments(packet99)); |
| 12294 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 12295 | |
| 12296 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 12297 | ASSERT_TRUE(visitor_.header_.get()); |
| 12298 | EXPECT_TRUE(CheckDecryption( |
| 12299 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 12300 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 12301 | |
| 12302 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 12303 | |
| 12304 | EXPECT_EQ(0x1122u, visitor_.retire_connection_id_.sequence_number); |
| 12305 | |
| 12306 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 12307 | |
| 12308 | CheckFramingBoundaries(packet99, QUIC_INVALID_RETIRE_CONNECTION_ID_DATA); |
| 12309 | } |
| 12310 | |
| 12311 | TEST_P(QuicFramerTest, BuildRetireConnectionIdFramePacket) { |
| 12312 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 12313 | // This frame is only for version 99. |
| 12314 | return; |
| 12315 | } |
| 12316 | QuicPacketHeader header; |
| 12317 | header.destination_connection_id = FramerTestConnectionId(); |
| 12318 | header.reset_flag = false; |
| 12319 | header.version_flag = false; |
| 12320 | header.packet_number = kPacketNumber; |
| 12321 | |
| 12322 | QuicRetireConnectionIdFrame frame; |
| 12323 | frame.sequence_number = 0x1122; |
| 12324 | |
| 12325 | QuicFrames frames = {QuicFrame(&frame)}; |
| 12326 | |
| 12327 | // clang-format off |
| 12328 | unsigned char packet99[] = { |
| 12329 | // type (short header, 4 byte packet number) |
| 12330 | 0x43, |
| 12331 | // connection_id |
| 12332 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12333 | // packet number |
| 12334 | 0x12, 0x34, 0x56, 0x78, |
| 12335 | |
| 12336 | // frame type (IETF_RETIRE_CONNECTION_ID frame) |
| 12337 | 0x19, |
| 12338 | // sequence number |
| 12339 | kVarInt62TwoBytes + 0x11, 0x22 |
| 12340 | }; |
| 12341 | // clang-format on |
| 12342 | |
| 12343 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 12344 | ASSERT_TRUE(data != nullptr); |
| 12345 | |
| 12346 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 12347 | data->length(), AsChars(packet99), |
| 12348 | QUIC_ARRAYSIZE(packet99)); |
| 12349 | } |
| 12350 | |
| 12351 | TEST_P(QuicFramerTest, AckFrameWithInvalidLargestObserved) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12352 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12353 | // clang-format off |
| 12354 | unsigned char packet[] = { |
| 12355 | // public flags (8 byte connection_id) |
| 12356 | 0x2C, |
| 12357 | // connection_id |
| 12358 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12359 | // packet number |
| 12360 | 0x12, 0x34, 0x56, 0x78, |
| 12361 | |
| 12362 | // frame type (ack frame) |
| 12363 | 0x45, |
| 12364 | // largest observed |
| 12365 | 0x00, 0x00, |
| 12366 | // Zero delta time. |
| 12367 | 0x00, 0x00, |
| 12368 | // first ack block length. |
| 12369 | 0x00, 0x00, |
| 12370 | // num timestamps. |
| 12371 | 0x00 |
| 12372 | }; |
| 12373 | |
| 12374 | unsigned char packet44[] = { |
| 12375 | // type (short header, 4 byte packet number) |
| 12376 | 0x32, |
| 12377 | // connection_id |
| 12378 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12379 | // packet number |
| 12380 | 0x12, 0x34, 0x56, 0x78, |
| 12381 | |
| 12382 | // frame type (ack frame) |
| 12383 | 0x45, |
| 12384 | // largest observed |
| 12385 | 0x00, 0x00, |
| 12386 | // Zero delta time. |
| 12387 | 0x00, 0x00, |
| 12388 | // first ack block length. |
| 12389 | 0x00, 0x00, |
| 12390 | // num timestamps. |
| 12391 | 0x00 |
| 12392 | }; |
| 12393 | |
| 12394 | unsigned char packet46[] = { |
| 12395 | // type (short header, 4 byte packet number) |
| 12396 | 0x43, |
| 12397 | // connection_id |
| 12398 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12399 | // packet number |
| 12400 | 0x12, 0x34, 0x56, 0x78, |
| 12401 | |
| 12402 | // frame type (ack frame) |
| 12403 | 0x45, |
| 12404 | // largest observed |
| 12405 | 0x00, 0x00, |
| 12406 | // Zero delta time. |
| 12407 | 0x00, 0x00, |
| 12408 | // first ack block length. |
| 12409 | 0x00, 0x00, |
| 12410 | // num timestamps. |
| 12411 | 0x00 |
| 12412 | }; |
| 12413 | |
| 12414 | unsigned char packet99[] = { |
| 12415 | // type (short header, 4 byte packet number) |
| 12416 | 0x43, |
| 12417 | // connection_id |
| 12418 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12419 | // packet number |
| 12420 | 0x12, 0x34, 0x56, 0x78, |
| 12421 | |
| 12422 | // frame type (IETF_ACK frame) |
| 12423 | 0x02, |
| 12424 | // Largest acked |
| 12425 | kVarInt62OneByte + 0x00, |
| 12426 | // Zero delta time. |
| 12427 | kVarInt62OneByte + 0x00, |
| 12428 | // Ack block count 0 |
| 12429 | kVarInt62OneByte + 0x00, |
| 12430 | // First ack block length |
| 12431 | kVarInt62OneByte + 0x00, |
| 12432 | }; |
| 12433 | // clang-format on |
| 12434 | |
| 12435 | unsigned char* p = packet; |
| 12436 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 12437 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12438 | p = packet99; |
| 12439 | p_size = QUIC_ARRAYSIZE(packet99); |
| 12440 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 12441 | p = packet46; |
| 12442 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 12443 | p = packet44; |
| 12444 | p_size = QUIC_ARRAYSIZE(packet44); |
| 12445 | } |
| 12446 | |
| 12447 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12448 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12449 | EXPECT_EQ(framer_.detailed_error(), "Largest acked is 0."); |
| 12450 | } |
| 12451 | |
| 12452 | TEST_P(QuicFramerTest, FirstAckBlockJustUnderFlow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12453 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12454 | // clang-format off |
| 12455 | unsigned char packet[] = { |
| 12456 | // public flags (8 byte connection_id) |
| 12457 | 0x2C, |
| 12458 | // connection_id |
| 12459 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12460 | // packet number |
| 12461 | 0x12, 0x34, 0x56, 0x78, |
| 12462 | |
| 12463 | // frame type (ack frame) |
| 12464 | 0x45, |
| 12465 | // largest observed |
| 12466 | 0x00, 0x02, |
| 12467 | // Zero delta time. |
| 12468 | 0x00, 0x00, |
| 12469 | // first ack block length. |
| 12470 | 0x00, 0x03, |
| 12471 | // num timestamps. |
| 12472 | 0x00 |
| 12473 | }; |
| 12474 | |
| 12475 | unsigned char packet44[] = { |
| 12476 | // type (short header, 4 byte packet number) |
| 12477 | 0x32, |
| 12478 | // connection_id |
| 12479 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12480 | // packet number |
| 12481 | 0x12, 0x34, 0x56, 0x78, |
| 12482 | |
| 12483 | // frame type (ack frame) |
| 12484 | 0x45, |
| 12485 | // largest observed |
| 12486 | 0x00, 0x02, |
| 12487 | // Zero delta time. |
| 12488 | 0x00, 0x00, |
| 12489 | // first ack block length. |
| 12490 | 0x00, 0x03, |
| 12491 | // num timestamps. |
| 12492 | 0x00 |
| 12493 | }; |
| 12494 | |
| 12495 | unsigned char packet46[] = { |
| 12496 | // type (short header, 4 byte packet number) |
| 12497 | 0x43, |
| 12498 | // connection_id |
| 12499 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12500 | // packet number |
| 12501 | 0x12, 0x34, 0x56, 0x78, |
| 12502 | |
| 12503 | // frame type (ack frame) |
| 12504 | 0x45, |
| 12505 | // largest observed |
| 12506 | 0x00, 0x02, |
| 12507 | // Zero delta time. |
| 12508 | 0x00, 0x00, |
| 12509 | // first ack block length. |
| 12510 | 0x00, 0x03, |
| 12511 | // num timestamps. |
| 12512 | 0x00 |
| 12513 | }; |
| 12514 | |
| 12515 | unsigned char packet99[] = { |
| 12516 | // type (short header, 4 byte packet number) |
| 12517 | 0x43, |
| 12518 | // connection_id |
| 12519 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12520 | // packet number |
| 12521 | 0x12, 0x34, 0x56, 0x78, |
| 12522 | |
| 12523 | // frame type (IETF_ACK frame) |
| 12524 | 0x02, |
| 12525 | // Largest acked |
| 12526 | kVarInt62OneByte + 0x02, |
| 12527 | // Zero delta time. |
| 12528 | kVarInt62OneByte + 0x00, |
| 12529 | // Ack block count 0 |
| 12530 | kVarInt62OneByte + 0x00, |
| 12531 | // First ack block length |
| 12532 | kVarInt62OneByte + 0x02, |
| 12533 | }; |
| 12534 | // clang-format on |
| 12535 | |
| 12536 | unsigned char* p = packet; |
| 12537 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 12538 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12539 | p = packet99; |
| 12540 | p_size = QUIC_ARRAYSIZE(packet99); |
| 12541 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 12542 | p = packet46; |
| 12543 | p_size = QUIC_ARRAYSIZE(packet46); |
| 12544 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 12545 | p = packet44; |
| 12546 | p_size = QUIC_ARRAYSIZE(packet44); |
| 12547 | } |
| 12548 | |
| 12549 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12550 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12551 | EXPECT_EQ(framer_.detailed_error(), |
| 12552 | "Underflow with first ack block length 3 largest acked is 2."); |
| 12553 | } |
| 12554 | |
| 12555 | TEST_P(QuicFramerTest, ThirdAckBlockJustUnderflow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12556 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12557 | // clang-format off |
| 12558 | unsigned char packet[] = { |
| 12559 | // public flags (8 byte connection_id) |
| 12560 | 0x2C, |
| 12561 | // connection_id |
| 12562 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12563 | // packet number |
| 12564 | 0x12, 0x34, 0x56, 0x78, |
| 12565 | |
| 12566 | // frame type (ack frame) |
| 12567 | 0x60, |
| 12568 | // largest observed |
| 12569 | 0x0A, |
| 12570 | // Zero delta time. |
| 12571 | 0x00, 0x00, |
| 12572 | // Num of ack blocks |
| 12573 | 0x02, |
| 12574 | // first ack block length. |
| 12575 | 0x02, |
| 12576 | // gap to next block |
| 12577 | 0x01, |
| 12578 | // ack block length |
| 12579 | 0x01, |
| 12580 | // gap to next block |
| 12581 | 0x01, |
| 12582 | // ack block length |
| 12583 | 0x06, |
| 12584 | // num timestamps. |
| 12585 | 0x00 |
| 12586 | }; |
| 12587 | |
| 12588 | unsigned char packet44[] = { |
| 12589 | // type (short header, 4 byte packet number) |
| 12590 | 0x32, |
| 12591 | // connection_id |
| 12592 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12593 | // packet number |
| 12594 | 0x12, 0x34, 0x56, 0x78, |
| 12595 | |
| 12596 | // frame type (ack frame) |
| 12597 | 0x60, |
| 12598 | // largest observed |
| 12599 | 0x0A, |
| 12600 | // Zero delta time. |
| 12601 | 0x00, 0x00, |
| 12602 | // Num of ack blocks |
| 12603 | 0x02, |
| 12604 | // first ack block length. |
| 12605 | 0x02, |
| 12606 | // gap to next block |
| 12607 | 0x01, |
| 12608 | // ack block length |
| 12609 | 0x01, |
| 12610 | // gap to next block |
| 12611 | 0x01, |
| 12612 | // ack block length |
| 12613 | 0x06, |
| 12614 | // num timestamps. |
| 12615 | 0x00 |
| 12616 | }; |
| 12617 | |
| 12618 | unsigned char packet46[] = { |
| 12619 | // type (short header, 4 byte packet number) |
| 12620 | 0x43, |
| 12621 | // connection_id |
| 12622 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12623 | // packet number |
| 12624 | 0x12, 0x34, 0x56, 0x78, |
| 12625 | |
| 12626 | // frame type (ack frame) |
| 12627 | 0x60, |
| 12628 | // largest observed |
| 12629 | 0x0A, |
| 12630 | // Zero delta time. |
| 12631 | 0x00, 0x00, |
| 12632 | // Num of ack blocks |
| 12633 | 0x02, |
| 12634 | // first ack block length. |
| 12635 | 0x02, |
| 12636 | // gap to next block |
| 12637 | 0x01, |
| 12638 | // ack block length |
| 12639 | 0x01, |
| 12640 | // gap to next block |
| 12641 | 0x01, |
| 12642 | // ack block length |
| 12643 | 0x06, |
| 12644 | // num timestamps. |
| 12645 | 0x00 |
| 12646 | }; |
| 12647 | |
| 12648 | unsigned char packet99[] = { |
| 12649 | // type (short header, 4 byte packet number) |
| 12650 | 0x43, |
| 12651 | // connection_id |
| 12652 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12653 | // packet number |
| 12654 | 0x12, 0x34, 0x56, 0x78, |
| 12655 | |
| 12656 | // frame type (IETF_ACK frame) |
| 12657 | 0x02, |
| 12658 | // Largest acked |
| 12659 | kVarInt62OneByte + 0x0A, |
| 12660 | // Zero delta time. |
| 12661 | kVarInt62OneByte + 0x00, |
| 12662 | // Ack block count 2 |
| 12663 | kVarInt62OneByte + 0x02, |
| 12664 | // First ack block length |
| 12665 | kVarInt62OneByte + 0x01, |
| 12666 | // gap to next block length |
| 12667 | kVarInt62OneByte + 0x00, |
| 12668 | // ack block length |
| 12669 | kVarInt62OneByte + 0x00, |
| 12670 | // gap to next block length |
| 12671 | kVarInt62OneByte + 0x00, |
| 12672 | // ack block length |
| 12673 | kVarInt62OneByte + 0x05, |
| 12674 | }; |
| 12675 | // clang-format on |
| 12676 | |
| 12677 | unsigned char* p = packet; |
| 12678 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 12679 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12680 | p = packet99; |
| 12681 | p_size = QUIC_ARRAYSIZE(packet99); |
| 12682 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 12683 | p = packet46; |
| 12684 | p_size = QUIC_ARRAYSIZE(packet46); |
| 12685 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 12686 | p = packet44; |
| 12687 | p_size = QUIC_ARRAYSIZE(packet44); |
| 12688 | } |
| 12689 | |
| 12690 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12691 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12692 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12693 | EXPECT_EQ(framer_.detailed_error(), |
| 12694 | "Underflow with ack block length 6 latest ack block end is 5."); |
| 12695 | } else { |
| 12696 | EXPECT_EQ(framer_.detailed_error(), |
| 12697 | "Underflow with ack block length 6, end of block is 6."); |
| 12698 | } |
| 12699 | } |
| 12700 | |
| 12701 | TEST_P(QuicFramerTest, CoalescedPacket) { |
| 12702 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 12703 | return; |
| 12704 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12705 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12706 | // clang-format off |
| 12707 | unsigned char packet[] = { |
| 12708 | // first coalesced packet |
| 12709 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12710 | // 4-byte packet number) |
| 12711 | 0xD3, |
| 12712 | // version |
| 12713 | QUIC_VERSION_BYTES, |
| 12714 | // destination connection ID length |
| 12715 | 0x50, |
| 12716 | // destination connection ID |
| 12717 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12718 | // long header packet length |
| 12719 | 0x1E, |
| 12720 | // packet number |
| 12721 | 0x12, 0x34, 0x56, 0x78, |
| 12722 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12723 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12724 | // stream id |
| 12725 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12726 | // offset |
| 12727 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12728 | 0x32, 0x10, 0x76, 0x54, |
| 12729 | // data length |
| 12730 | kVarInt62OneByte + 0x0c, |
| 12731 | // data |
| 12732 | 'h', 'e', 'l', 'l', |
| 12733 | 'o', ' ', 'w', 'o', |
| 12734 | 'r', 'l', 'd', '!', |
| 12735 | // second coalesced packet |
| 12736 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12737 | // 4-byte packet number) |
| 12738 | 0xD3, |
| 12739 | // version |
| 12740 | QUIC_VERSION_BYTES, |
| 12741 | // destination connection ID length |
| 12742 | 0x50, |
| 12743 | // destination connection ID |
| 12744 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12745 | // long header packet length |
| 12746 | 0x1E, |
| 12747 | // packet number |
| 12748 | 0x12, 0x34, 0x56, 0x79, |
| 12749 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12750 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12751 | // stream id |
| 12752 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12753 | // offset |
| 12754 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12755 | 0x32, 0x10, 0x76, 0x54, |
| 12756 | // data length |
| 12757 | kVarInt62OneByte + 0x0c, |
| 12758 | // data |
| 12759 | 'H', 'E', 'L', 'L', |
| 12760 | 'O', '_', 'W', 'O', |
| 12761 | 'R', 'L', 'D', '?', |
| 12762 | }; |
| 12763 | // clang-format on |
| 12764 | |
| 12765 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 12766 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 12767 | |
| 12768 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 12769 | ASSERT_TRUE(visitor_.header_.get()); |
| 12770 | |
| 12771 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12772 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12773 | |
| 12774 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12775 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12776 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12777 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12778 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 12779 | |
| 12780 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 1u); |
| 12781 | EXPECT_TRUE(framer_.ProcessPacket(*visitor_.coalesced_packets_[0].get())); |
| 12782 | |
| 12783 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 12784 | ASSERT_TRUE(visitor_.header_.get()); |
| 12785 | |
| 12786 | ASSERT_EQ(2u, visitor_.stream_frames_.size()); |
| 12787 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12788 | |
| 12789 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12790 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[1]->stream_id); |
| 12791 | EXPECT_TRUE(visitor_.stream_frames_[1]->fin); |
| 12792 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[1]->offset); |
| 12793 | CheckStreamFrameData("HELLO_WORLD?", visitor_.stream_frames_[1].get()); |
| 12794 | } |
| 12795 | |
| 12796 | TEST_P(QuicFramerTest, MismatchedCoalescedPacket) { |
| 12797 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 12798 | return; |
| 12799 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12800 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12801 | // clang-format off |
| 12802 | unsigned char packet[] = { |
| 12803 | // first coalesced packet |
| 12804 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12805 | // 4-byte packet number) |
| 12806 | 0xD3, |
| 12807 | // version |
| 12808 | QUIC_VERSION_BYTES, |
| 12809 | // destination connection ID length |
| 12810 | 0x50, |
| 12811 | // destination connection ID |
| 12812 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12813 | // long header packet length |
| 12814 | 0x1E, |
| 12815 | // packet number |
| 12816 | 0x12, 0x34, 0x56, 0x78, |
| 12817 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12818 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12819 | // stream id |
| 12820 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12821 | // offset |
| 12822 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12823 | 0x32, 0x10, 0x76, 0x54, |
| 12824 | // data length |
| 12825 | kVarInt62OneByte + 0x0c, |
| 12826 | // data |
| 12827 | 'h', 'e', 'l', 'l', |
| 12828 | 'o', ' ', 'w', 'o', |
| 12829 | 'r', 'l', 'd', '!', |
| 12830 | // second coalesced packet |
| 12831 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12832 | // 4-byte packet number) |
| 12833 | 0xD3, |
| 12834 | // version |
| 12835 | QUIC_VERSION_BYTES, |
| 12836 | // destination connection ID length |
| 12837 | 0x50, |
| 12838 | // destination connection ID |
| 12839 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 12840 | // long header packet length |
| 12841 | 0x1E, |
| 12842 | // packet number |
| 12843 | 0x12, 0x34, 0x56, 0x79, |
| 12844 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12845 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12846 | // stream id |
| 12847 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12848 | // offset |
| 12849 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12850 | 0x32, 0x10, 0x76, 0x54, |
| 12851 | // data length |
| 12852 | kVarInt62OneByte + 0x0c, |
| 12853 | // data |
| 12854 | 'H', 'E', 'L', 'L', |
| 12855 | 'O', '_', 'W', 'O', |
| 12856 | 'R', 'L', 'D', '?', |
| 12857 | }; |
| 12858 | // clang-format on |
| 12859 | |
| 12860 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 12861 | EXPECT_QUIC_PEER_BUG(EXPECT_TRUE(framer_.ProcessPacket(encrypted)), |
| 12862 | "Server: Received mismatched coalesced header.*"); |
| 12863 | |
| 12864 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 12865 | ASSERT_TRUE(visitor_.header_.get()); |
| 12866 | |
| 12867 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12868 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12869 | |
| 12870 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12871 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12872 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12873 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12874 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 12875 | |
| 12876 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 0u); |
| 12877 | } |
| 12878 | |
| 12879 | TEST_P(QuicFramerTest, InvalidCoalescedPacket) { |
| 12880 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 12881 | return; |
| 12882 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12883 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12884 | // clang-format off |
| 12885 | unsigned char packet[] = { |
| 12886 | // first coalesced packet |
| 12887 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12888 | // 4-byte packet number) |
| 12889 | 0xD3, |
| 12890 | // version |
| 12891 | QUIC_VERSION_BYTES, |
| 12892 | // destination connection ID length |
| 12893 | 0x50, |
| 12894 | // destination connection ID |
| 12895 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12896 | // long header packet length |
| 12897 | 0x1E, |
| 12898 | // packet number |
| 12899 | 0x12, 0x34, 0x56, 0x78, |
| 12900 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12901 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12902 | // stream id |
| 12903 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12904 | // offset |
| 12905 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12906 | 0x32, 0x10, 0x76, 0x54, |
| 12907 | // data length |
| 12908 | kVarInt62OneByte + 0x0c, |
| 12909 | // data |
| 12910 | 'h', 'e', 'l', 'l', |
| 12911 | 'o', ' ', 'w', 'o', |
| 12912 | 'r', 'l', 'd', '!', |
| 12913 | // second coalesced packet |
| 12914 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12915 | // 4-byte packet number) |
| 12916 | 0xD3, |
| 12917 | // version would be here but we cut off the invalid coalesced header. |
| 12918 | }; |
| 12919 | // clang-format on |
| 12920 | |
| 12921 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 12922 | EXPECT_QUIC_PEER_BUG(EXPECT_TRUE(framer_.ProcessPacket(encrypted)), |
| 12923 | "Server: Failed to parse received coalesced header.*"); |
| 12924 | |
| 12925 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 12926 | ASSERT_TRUE(visitor_.header_.get()); |
| 12927 | |
| 12928 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12929 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12930 | |
| 12931 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12932 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12933 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12934 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12935 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 12936 | |
| 12937 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 0u); |
| 12938 | } |
| 12939 | |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 12940 | TEST_P(QuicFramerTest, ClientReceivesInvalidVersion) { |
| 12941 | if (framer_.transport_version() < QUIC_VERSION_44) { |
| 12942 | return; |
| 12943 | } |
| 12944 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 12945 | |
| 12946 | // clang-format off |
| 12947 | unsigned char packet[] = { |
| 12948 | // public flags (long header with packet type INITIAL) |
| 12949 | 0xFF, |
| 12950 | // version that is different from the framer's version |
| 12951 | 'Q', '0', '4', '3', |
| 12952 | // connection ID lengths |
| 12953 | 0x05, |
| 12954 | // source connection ID |
| 12955 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12956 | // packet number |
| 12957 | 0x01, |
| 12958 | // padding frame |
| 12959 | 0x00, |
| 12960 | }; |
| 12961 | // clang-format on |
| 12962 | |
| 12963 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 12964 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12965 | |
| 12966 | EXPECT_EQ(QUIC_INVALID_VERSION, framer_.error()); |
| 12967 | EXPECT_EQ("Client received unexpected version.", framer_.detailed_error()); |
| 12968 | } |
| 12969 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12970 | TEST_P(QuicFramerTest, PacketHeaderWithVariableLengthConnectionId) { |
| 12971 | if (framer_.transport_version() < QUIC_VERSION_46) { |
| 12972 | return; |
| 12973 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12974 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12975 | char connection_id_bytes[9] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, |
| 12976 | 0x54, 0x32, 0x10, 0x42}; |
| 12977 | QuicConnectionId connection_id(connection_id_bytes, |
| 12978 | sizeof(connection_id_bytes)); |
| 12979 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 12980 | QuicFramerPeer::SetExpectedConnectionIDLength(&framer_, |
| 12981 | connection_id.length()); |
| 12982 | |
| 12983 | // clang-format off |
| 12984 | PacketFragments packet = { |
| 12985 | // type (8 byte connection_id and 1 byte packet number) |
| 12986 | {"Unable to read type.", |
| 12987 | {0x40}}, |
| 12988 | // connection_id |
| 12989 | {"Unable to read Destination ConnectionId.", |
| 12990 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 12991 | // packet number |
| 12992 | {"Unable to read packet number.", |
| 12993 | {0x78}}, |
| 12994 | }; |
| 12995 | // clang-format on |
| 12996 | |
| 12997 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12998 | AssemblePacketFromFragments(packet)); |
| 12999 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 13000 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 13001 | ASSERT_TRUE(visitor_.header_.get()); |
| 13002 | EXPECT_EQ(connection_id, visitor_.header_->destination_connection_id); |
| 13003 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 13004 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 13005 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 13006 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 13007 | |
| 13008 | CheckFramingBoundaries(packet, QUIC_INVALID_PACKET_HEADER); |
| 13009 | } |
| 13010 | |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13011 | TEST_P(QuicFramerTest, UpdateExpectedConnectionIdLength) { |
| 13012 | if (framer_.transport_version() < QUIC_VERSION_46) { |
| 13013 | return; |
| 13014 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13015 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13016 | framer_.SetShouldUpdateExpectedConnectionIdLength(true); |
| 13017 | |
| 13018 | // clang-format off |
| 13019 | unsigned char long_header_packet[] = { |
| 13020 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13021 | // 4-byte packet number) |
| 13022 | 0xD3, |
| 13023 | // version |
| 13024 | QUIC_VERSION_BYTES, |
| 13025 | // destination connection ID length |
| 13026 | 0x60, |
| 13027 | // destination connection ID |
| 13028 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13029 | // packet number |
| 13030 | 0x12, 0x34, 0x56, 0x78, |
| 13031 | // padding frame |
| 13032 | 0x00, |
| 13033 | }; |
| 13034 | unsigned char long_header_packet99[] = { |
| 13035 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13036 | // 4-byte packet number) |
| 13037 | 0xD3, |
| 13038 | // version |
| 13039 | QUIC_VERSION_BYTES, |
| 13040 | // destination connection ID length |
| 13041 | 0x60, |
| 13042 | // destination connection ID |
| 13043 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13044 | // long header packet length |
| 13045 | 0x05, |
| 13046 | // packet number |
| 13047 | 0x12, 0x34, 0x56, 0x78, |
| 13048 | // padding frame |
| 13049 | 0x00, |
| 13050 | }; |
| 13051 | // clang-format on |
| 13052 | |
| 13053 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 13054 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13055 | QuicEncryptedPacket(AsChars(long_header_packet), |
| 13056 | QUIC_ARRAYSIZE(long_header_packet), false))); |
| 13057 | } else { |
| 13058 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13059 | QuicEncryptedPacket(AsChars(long_header_packet99), |
| 13060 | QUIC_ARRAYSIZE(long_header_packet99), false))); |
| 13061 | } |
| 13062 | |
| 13063 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 13064 | ASSERT_TRUE(visitor_.header_.get()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 13065 | EXPECT_EQ(visitor_.header_.get()->destination_connection_id, |
| 13066 | FramerTestConnectionIdNineBytes()); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13067 | EXPECT_EQ(visitor_.header_.get()->packet_number, |
| 13068 | QuicPacketNumber(UINT64_C(0x12345678))); |
| 13069 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13070 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13071 | // clang-format off |
| 13072 | unsigned char short_header_packet[] = { |
| 13073 | // type (short header, 4 byte packet number) |
| 13074 | 0x43, |
| 13075 | // connection_id |
| 13076 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13077 | // packet number |
| 13078 | 0x13, 0x37, 0x42, 0x33, |
| 13079 | // padding frame |
| 13080 | 0x00, |
| 13081 | }; |
| 13082 | // clang-format on |
| 13083 | |
| 13084 | QuicEncryptedPacket short_header_encrypted( |
| 13085 | AsChars(short_header_packet), QUIC_ARRAYSIZE(short_header_packet), false); |
| 13086 | EXPECT_TRUE(framer_.ProcessPacket(short_header_encrypted)); |
| 13087 | |
| 13088 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 13089 | ASSERT_TRUE(visitor_.header_.get()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 13090 | EXPECT_EQ(visitor_.header_.get()->destination_connection_id, |
| 13091 | FramerTestConnectionIdNineBytes()); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13092 | EXPECT_EQ(visitor_.header_.get()->packet_number, |
| 13093 | QuicPacketNumber(UINT64_C(0x13374233))); |
| 13094 | } |
| 13095 | |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13096 | TEST_P(QuicFramerTest, MultiplePacketNumberSpaces) { |
| 13097 | if (framer_.transport_version() < QUIC_VERSION_46) { |
| 13098 | return; |
| 13099 | } |
| 13100 | framer_.SetShouldUpdateExpectedConnectionIdLength(true); |
| 13101 | framer_.EnableMultiplePacketNumberSpacesSupport(); |
| 13102 | |
| 13103 | // clang-format off |
| 13104 | unsigned char long_header_packet[] = { |
| 13105 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13106 | // 4-byte packet number) |
| 13107 | 0xD3, |
| 13108 | // version |
| 13109 | QUIC_VERSION_BYTES, |
| 13110 | // destination connection ID length |
| 13111 | 0x60, |
| 13112 | // destination connection ID |
| 13113 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13114 | // packet number |
| 13115 | 0x12, 0x34, 0x56, 0x78, |
| 13116 | // padding frame |
| 13117 | 0x00, |
| 13118 | }; |
| 13119 | unsigned char long_header_packet99[] = { |
| 13120 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13121 | // 4-byte packet number) |
| 13122 | 0xD3, |
| 13123 | // version |
| 13124 | QUIC_VERSION_BYTES, |
| 13125 | // destination connection ID length |
| 13126 | 0x60, |
| 13127 | // destination connection ID |
| 13128 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13129 | // long header packet length |
| 13130 | 0x05, |
| 13131 | // packet number |
| 13132 | 0x12, 0x34, 0x56, 0x78, |
| 13133 | // padding frame |
| 13134 | 0x00, |
| 13135 | }; |
| 13136 | // clang-format on |
| 13137 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13138 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 13139 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 13140 | QuicMakeUnique<TestDecrypter>()); |
| 13141 | framer_.RemoveDecrypter(ENCRYPTION_INITIAL); |
| 13142 | } else { |
| 13143 | framer_.SetDecrypter(ENCRYPTION_ZERO_RTT, QuicMakeUnique<TestDecrypter>()); |
| 13144 | } |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13145 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 13146 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13147 | QuicEncryptedPacket(AsChars(long_header_packet), |
| 13148 | QUIC_ARRAYSIZE(long_header_packet), false))); |
| 13149 | } else { |
| 13150 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13151 | QuicEncryptedPacket(AsChars(long_header_packet99), |
| 13152 | QUIC_ARRAYSIZE(long_header_packet99), false))); |
| 13153 | } |
| 13154 | |
| 13155 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 13156 | EXPECT_FALSE( |
| 13157 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, INITIAL_DATA) |
| 13158 | .IsInitialized()); |
| 13159 | EXPECT_FALSE( |
| 13160 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, HANDSHAKE_DATA) |
| 13161 | .IsInitialized()); |
| 13162 | EXPECT_EQ(kPacketNumber, QuicFramerPeer::GetLargestDecryptedPacketNumber( |
| 13163 | &framer_, APPLICATION_DATA)); |
| 13164 | |
| 13165 | // clang-format off |
| 13166 | unsigned char short_header_packet[] = { |
| 13167 | // type (short header, 1 byte packet number) |
| 13168 | 0x40, |
| 13169 | // connection_id |
| 13170 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13171 | // packet number |
| 13172 | 0x79, |
| 13173 | // padding frame |
| 13174 | 0x00, |
| 13175 | }; |
| 13176 | // clang-format on |
| 13177 | |
| 13178 | QuicEncryptedPacket short_header_encrypted( |
| 13179 | AsChars(short_header_packet), QUIC_ARRAYSIZE(short_header_packet), false); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13180 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 13181 | framer_.InstallDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 13182 | QuicMakeUnique<TestDecrypter>()); |
| 13183 | framer_.RemoveDecrypter(ENCRYPTION_ZERO_RTT); |
| 13184 | } else { |
| 13185 | framer_.SetDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 13186 | QuicMakeUnique<TestDecrypter>()); |
| 13187 | } |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13188 | EXPECT_TRUE(framer_.ProcessPacket(short_header_encrypted)); |
| 13189 | |
| 13190 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 13191 | EXPECT_FALSE( |
| 13192 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, INITIAL_DATA) |
| 13193 | .IsInitialized()); |
| 13194 | EXPECT_FALSE( |
| 13195 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, HANDSHAKE_DATA) |
| 13196 | .IsInitialized()); |
| 13197 | EXPECT_EQ(kPacketNumber + 1, QuicFramerPeer::GetLargestDecryptedPacketNumber( |
| 13198 | &framer_, APPLICATION_DATA)); |
| 13199 | } |
| 13200 | |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13201 | TEST_P(QuicFramerTest, IetfRetryPacketRejected) { |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13202 | if (!framer_.version().KnowsWhichDecrypterToUse() || |
| 13203 | framer_.version().SupportsRetry()) { |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13204 | return; |
| 13205 | } |
| 13206 | |
| 13207 | // clang-format off |
| 13208 | PacketFragments packet = { |
| 13209 | // public flags (IETF Retry packet, 0-length original destination CID) |
| 13210 | {"Unable to read type.", |
| 13211 | {0xf0}}, |
| 13212 | // version tag |
| 13213 | {"Unable to read protocol version.", |
| 13214 | {QUIC_VERSION_BYTES}}, |
| 13215 | // connection_id length |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 13216 | {"Illegal long header type value.", |
| 13217 | {0x00}}, |
| 13218 | }; |
| 13219 | // clang-format on |
| 13220 | |
| 13221 | // clang-format off |
| 13222 | PacketFragments packet45 = { |
| 13223 | // public flags (IETF Retry packet, 0-length original destination CID) |
| 13224 | {"Unable to read type.", |
| 13225 | {0xf0}}, |
| 13226 | // version tag |
| 13227 | {"Unable to read protocol version.", |
| 13228 | {QUIC_VERSION_BYTES}}, |
| 13229 | // connection_id length |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13230 | {"RETRY not supported in this version.", |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13231 | {0x00}}, |
| 13232 | }; |
| 13233 | // clang-format on |
| 13234 | |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 13235 | PacketFragments& fragments = |
| 13236 | framer_.transport_version() > QUIC_VERSION_44 ? packet45 : packet; |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13237 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 13238 | AssemblePacketFromFragments(fragments)); |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13239 | |
| 13240 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 13241 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 13242 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13243 | } |
| 13244 | |
| 13245 | TEST_P(QuicFramerTest, RetryPacketRejectedWithMultiplePacketNumberSpaces) { |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13246 | if (framer_.transport_version() < QUIC_VERSION_46 || |
| 13247 | framer_.version().SupportsRetry()) { |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13248 | return; |
| 13249 | } |
| 13250 | framer_.EnableMultiplePacketNumberSpacesSupport(); |
| 13251 | |
| 13252 | // clang-format off |
| 13253 | PacketFragments packet = { |
| 13254 | // public flags (IETF Retry packet, 0-length original destination CID) |
| 13255 | {"Unable to read type.", |
| 13256 | {0xf0}}, |
| 13257 | // version tag |
| 13258 | {"Unable to read protocol version.", |
| 13259 | {QUIC_VERSION_BYTES}}, |
| 13260 | // connection_id length |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13261 | {"RETRY not supported in this version.", |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13262 | {0x00}}, |
| 13263 | }; |
| 13264 | // clang-format on |
| 13265 | |
| 13266 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 13267 | AssemblePacketFromFragments(packet)); |
| 13268 | |
| 13269 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 13270 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
| 13271 | CheckFramingBoundaries(packet, QUIC_INVALID_PACKET_HEADER); |
| 13272 | } |
| 13273 | |
nharper | a745e39 | 2019-04-19 12:05:15 -0700 | [diff] [blame] | 13274 | TEST_P(QuicFramerTest, ProcessPublicHeaderNoVersionInferredType) { |
| 13275 | // The framer needs to have Perspective::IS_SERVER and configured to infer the |
| 13276 | // packet header type from the packet (not the version). The framer's version |
| 13277 | // needs to be one that uses the IETF packet format. |
| 13278 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 13279 | return; |
| 13280 | } |
| 13281 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 13282 | |
| 13283 | // Prepare a packet that uses the Google QUIC packet header but has no version |
| 13284 | // field. |
| 13285 | |
| 13286 | // clang-format off |
| 13287 | PacketFragments packet = { |
| 13288 | // public flags (1-byte packet number, 8-byte connection_id, no version) |
| 13289 | {"Unable to read public flags.", |
| 13290 | {0x08}}, |
| 13291 | // connection_id |
| 13292 | {"Unable to read ConnectionId.", |
| 13293 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 13294 | // packet number |
| 13295 | {"Unable to read packet number.", |
| 13296 | {0x01}}, |
| 13297 | // padding |
| 13298 | {"Invalid public header type for expected version.", |
| 13299 | {0x00}}, |
| 13300 | }; |
| 13301 | // clang-format on |
| 13302 | |
| 13303 | PacketFragments& fragments = packet; |
| 13304 | |
| 13305 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 13306 | AssemblePacketFromFragments(fragments)); |
| 13307 | |
| 13308 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 13309 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
nharper | 8b6d63a | 2019-05-03 10:34:53 -0700 | [diff] [blame] | 13310 | EXPECT_EQ("Invalid public header type for expected version.", |
| 13311 | framer_.detailed_error()); |
nharper | a745e39 | 2019-04-19 12:05:15 -0700 | [diff] [blame] | 13312 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 13313 | } |
| 13314 | |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 13315 | TEST_P(QuicFramerTest, ProcessMismatchedHeaderVersion) { |
| 13316 | // The framer needs to have Perspective::IS_SERVER and configured to infer the |
| 13317 | // packet header type from the packet (not the version). The framer's version |
| 13318 | // needs to be one that uses the IETF packet format. |
| 13319 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 13320 | return; |
| 13321 | } |
| 13322 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 13323 | |
| 13324 | // clang-format off |
| 13325 | PacketFragments packet = { |
| 13326 | // public flags (long header with version present) |
| 13327 | {"Unable to read public flags.", |
| 13328 | {0x09}}, |
| 13329 | // connection_id |
| 13330 | {"Unable to read ConnectionId.", |
| 13331 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 13332 | // version tag |
| 13333 | {"Unable to read protocol version.", |
| 13334 | {QUIC_VERSION_BYTES}}, |
| 13335 | // packet number |
| 13336 | {"Unable to read packet number.", |
| 13337 | {0x01}}, |
| 13338 | }; |
| 13339 | // clang-format on |
| 13340 | |
| 13341 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 13342 | AssemblePacketFromFragments(packet)); |
| 13343 | framer_.ProcessPacket(*encrypted); |
| 13344 | |
| 13345 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 13346 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
nharper | 8b6d63a | 2019-05-03 10:34:53 -0700 | [diff] [blame] | 13347 | EXPECT_EQ("Invalid public header type for expected version.", |
| 13348 | framer_.detailed_error()); |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 13349 | CheckFramingBoundaries(packet, QUIC_INVALID_PACKET_HEADER); |
| 13350 | } |
| 13351 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13352 | } // namespace |
| 13353 | } // namespace test |
| 13354 | } // namespace quic |