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); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 916 | |
| 917 | PacketHeaderFormat format; |
| 918 | bool version_flag; |
| 919 | uint8_t destination_connection_id_length; |
| 920 | QuicConnectionId destination_connection_id; |
| 921 | QuicVersionLabel version_label; |
| 922 | std::string detailed_error; |
| 923 | EXPECT_EQ(QUIC_NO_ERROR, QuicFramer::ProcessPacketDispatcher( |
| 924 | *encrypted, kQuicDefaultConnectionIdLength, |
| 925 | &format, &version_flag, &version_label, |
| 926 | &destination_connection_id_length, |
| 927 | &destination_connection_id, &detailed_error)); |
| 928 | EXPECT_EQ(GOOGLE_QUIC_PACKET, format); |
| 929 | EXPECT_FALSE(version_flag); |
| 930 | EXPECT_EQ(kQuicDefaultConnectionIdLength, destination_connection_id_length); |
| 931 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | TEST_P(QuicFramerTest, LongPacketHeader) { |
| 935 | // clang-format off |
| 936 | PacketFragments packet44 = { |
| 937 | // type (long header with packet type INITIAL) |
| 938 | {"Unable to read type.", |
| 939 | {0xFF}}, |
| 940 | // version tag |
| 941 | {"Unable to read protocol version.", |
| 942 | {QUIC_VERSION_BYTES}}, |
| 943 | // connection_id length |
| 944 | {"Unable to read ConnectionId length.", |
| 945 | {0x50}}, |
| 946 | // connection_id |
| 947 | {"Unable to read Destination ConnectionId.", |
| 948 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 949 | // packet number |
| 950 | {"Unable to read packet number.", |
| 951 | {0x12, 0x34, 0x56, 0x78}}, |
| 952 | }; |
| 953 | PacketFragments packet46 = { |
| 954 | // type (long header with packet type INITIAL) |
| 955 | {"Unable to read type.", |
| 956 | {0xC3}}, |
| 957 | // version tag |
| 958 | {"Unable to read protocol version.", |
| 959 | {QUIC_VERSION_BYTES}}, |
| 960 | // connection_id length |
| 961 | {"Unable to read ConnectionId length.", |
| 962 | {0x50}}, |
| 963 | // connection_id |
| 964 | {"Unable to read Destination ConnectionId.", |
| 965 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 966 | // packet number |
| 967 | {"Unable to read packet number.", |
| 968 | {0x12, 0x34, 0x56, 0x78}}, |
| 969 | }; |
| 970 | // clang-format on |
| 971 | |
| 972 | if (framer_.transport_version() <= QUIC_VERSION_43 || |
| 973 | QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 974 | return; |
| 975 | } |
| 976 | |
| 977 | PacketFragments& fragments = |
| 978 | framer_.transport_version() > QUIC_VERSION_44 ? packet46 : packet44; |
| 979 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 980 | AssemblePacketFromFragments(fragments)); |
| 981 | |
| 982 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 983 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 984 | ASSERT_TRUE(visitor_.header_.get()); |
| 985 | EXPECT_EQ(FramerTestConnectionId(), |
| 986 | visitor_.header_->destination_connection_id); |
| 987 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 988 | EXPECT_TRUE(visitor_.header_->version_flag); |
| 989 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 990 | |
| 991 | CheckFramingBoundaries( |
| 992 | framer_.transport_version() > QUIC_VERSION_44 ? packet46 : packet44, |
| 993 | QUIC_INVALID_PACKET_HEADER); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 994 | |
| 995 | PacketHeaderFormat format; |
| 996 | bool version_flag; |
| 997 | uint8_t destination_connection_id_length; |
| 998 | QuicConnectionId destination_connection_id; |
| 999 | QuicVersionLabel version_label; |
| 1000 | std::string detailed_error; |
| 1001 | EXPECT_EQ(QUIC_NO_ERROR, QuicFramer::ProcessPacketDispatcher( |
| 1002 | *encrypted, kQuicDefaultConnectionIdLength, |
| 1003 | &format, &version_flag, &version_label, |
| 1004 | &destination_connection_id_length, |
| 1005 | &destination_connection_id, &detailed_error)); |
| 1006 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 1007 | EXPECT_TRUE(version_flag); |
| 1008 | EXPECT_EQ(kQuicDefaultConnectionIdLength, destination_connection_id_length); |
| 1009 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1013 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1014 | QuicFramerPeer::SetLastSerializedConnectionId(&framer_, |
| 1015 | FramerTestConnectionId()); |
| 1016 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1017 | |
| 1018 | // clang-format off |
| 1019 | PacketFragments packet = { |
| 1020 | // public flags (0 byte connection_id) |
| 1021 | {"Unable to read public flags.", |
| 1022 | {0x20}}, |
| 1023 | // connection_id |
| 1024 | // packet number |
| 1025 | {"Unable to read packet number.", |
| 1026 | {0x12, 0x34, 0x56, 0x78}}, |
| 1027 | }; |
| 1028 | |
| 1029 | PacketFragments packet44 = { |
| 1030 | // type (short header, 4 byte packet number) |
| 1031 | {"Unable to read type.", |
| 1032 | {0x32}}, |
| 1033 | // connection_id |
| 1034 | // packet number |
| 1035 | {"Unable to read packet number.", |
| 1036 | {0x12, 0x34, 0x56, 0x78}}, |
| 1037 | }; |
| 1038 | |
| 1039 | PacketFragments packet46 = { |
| 1040 | // type (short header, 4 byte packet number) |
| 1041 | {"Unable to read type.", |
| 1042 | {0x43}}, |
| 1043 | // connection_id |
| 1044 | // packet number |
| 1045 | {"Unable to read packet number.", |
| 1046 | {0x12, 0x34, 0x56, 0x78}}, |
| 1047 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1048 | |
| 1049 | PacketFragments packet_hp = { |
| 1050 | // type (short header, 4 byte packet number) |
| 1051 | {"Unable to read type.", |
| 1052 | {0x43}}, |
| 1053 | // connection_id |
| 1054 | // packet number |
| 1055 | {"", |
| 1056 | {0x12, 0x34, 0x56, 0x78}}, |
| 1057 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1058 | // clang-format on |
| 1059 | |
| 1060 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1061 | framer_.version().HasHeaderProtection() |
| 1062 | ? packet_hp |
| 1063 | : framer_.transport_version() > QUIC_VERSION_44 |
| 1064 | ? packet46 |
| 1065 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 1066 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1067 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1068 | AssemblePacketFromFragments(fragments)); |
| 1069 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1070 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1071 | ASSERT_TRUE(visitor_.header_.get()); |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 1072 | if (!GetQuicRestartFlag(quic_do_not_override_connection_id)) { |
| 1073 | EXPECT_EQ(FramerTestConnectionId(), |
| 1074 | visitor_.header_->destination_connection_id); |
| 1075 | } else { |
| 1076 | EXPECT_EQ(FramerTestConnectionId(), visitor_.header_->source_connection_id); |
| 1077 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1078 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1079 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1080 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1081 | |
| 1082 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1083 | } |
| 1084 | |
| 1085 | TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1086 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1087 | // clang-format off |
| 1088 | PacketFragments packet = { |
| 1089 | // public flags (0 byte connection_id) |
| 1090 | {"Unable to read public flags.", |
| 1091 | {0x29}}, |
| 1092 | // connection_id |
| 1093 | {"Unable to read ConnectionId.", |
| 1094 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1095 | // version tag |
| 1096 | {"Unable to read protocol version.", |
| 1097 | {QUIC_VERSION_BYTES}}, |
| 1098 | // packet number |
| 1099 | {"Unable to read packet number.", |
| 1100 | {0x12, 0x34, 0x56, 0x78}}, |
| 1101 | }; |
| 1102 | |
| 1103 | PacketFragments packet44 = { |
| 1104 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 1105 | {"Unable to read type.", |
| 1106 | {0xFC}}, |
| 1107 | // version tag |
| 1108 | {"Unable to read protocol version.", |
| 1109 | {QUIC_VERSION_BYTES}}, |
| 1110 | // connection_id length |
| 1111 | {"Unable to read ConnectionId length.", |
| 1112 | {0x50}}, |
| 1113 | // connection_id |
| 1114 | {"Unable to read Destination ConnectionId.", |
| 1115 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1116 | // packet number |
| 1117 | {"Unable to read packet number.", |
| 1118 | {0x12, 0x34, 0x56, 0x78}}, |
| 1119 | }; |
| 1120 | |
| 1121 | PacketFragments packet46 = { |
| 1122 | // type (long header with packet type ZERO_RTT_PROTECTED and 4 bytes |
| 1123 | // packet number) |
| 1124 | {"Unable to read type.", |
| 1125 | {0xD3}}, |
| 1126 | // version tag |
| 1127 | {"Unable to read protocol version.", |
| 1128 | {QUIC_VERSION_BYTES}}, |
| 1129 | // connection_id length |
| 1130 | {"Unable to read ConnectionId length.", |
| 1131 | {0x50}}, |
| 1132 | // connection_id |
| 1133 | {"Unable to read Destination ConnectionId.", |
| 1134 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1135 | // packet number |
| 1136 | {"Unable to read packet number.", |
| 1137 | {0x12, 0x34, 0x56, 0x78}}, |
| 1138 | }; |
| 1139 | |
| 1140 | PacketFragments packet99 = { |
| 1141 | // type (long header with packet type ZERO_RTT_PROTECTED and 4 bytes |
| 1142 | // packet number) |
| 1143 | {"Unable to read type.", |
| 1144 | {0xD3}}, |
| 1145 | // version tag |
| 1146 | {"Unable to read protocol version.", |
| 1147 | {QUIC_VERSION_BYTES}}, |
| 1148 | // connection_id length |
| 1149 | {"Unable to read ConnectionId length.", |
| 1150 | {0x50}}, |
| 1151 | // connection_id |
| 1152 | {"Unable to read Destination ConnectionId.", |
| 1153 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1154 | // long header packet length |
| 1155 | {"Unable to read long header payload length.", |
| 1156 | {0x04}}, |
| 1157 | // packet number |
| 1158 | {"Long header payload length longer than packet.", |
| 1159 | {0x12, 0x34, 0x56, 0x78}}, |
| 1160 | }; |
| 1161 | // clang-format on |
| 1162 | |
| 1163 | PacketFragments& fragments = |
| 1164 | framer_.transport_version() == QUIC_VERSION_99 |
| 1165 | ? packet99 |
| 1166 | : framer_.transport_version() > QUIC_VERSION_44 |
| 1167 | ? packet46 |
| 1168 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 1169 | : packet); |
| 1170 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1171 | AssemblePacketFromFragments(fragments)); |
| 1172 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1173 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1174 | ASSERT_TRUE(visitor_.header_.get()); |
| 1175 | EXPECT_EQ(FramerTestConnectionId(), |
| 1176 | visitor_.header_->destination_connection_id); |
| 1177 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1178 | EXPECT_TRUE(visitor_.header_->version_flag); |
| 1179 | EXPECT_EQ(GetParam(), visitor_.header_->version); |
| 1180 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1181 | |
| 1182 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1183 | } |
| 1184 | |
| 1185 | TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1186 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1187 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1188 | |
| 1189 | // clang-format off |
| 1190 | PacketFragments packet = { |
| 1191 | // public flags (8 byte connection_id and 4 byte packet number) |
| 1192 | {"Unable to read public flags.", |
| 1193 | {0x28}}, |
| 1194 | // connection_id |
| 1195 | {"Unable to read ConnectionId.", |
| 1196 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1197 | // packet number |
| 1198 | {"Unable to read packet number.", |
| 1199 | {0x12, 0x34, 0x56, 0x78}}, |
| 1200 | }; |
| 1201 | |
| 1202 | PacketFragments packet44 = { |
| 1203 | // type (short header, 4 byte packet number) |
| 1204 | {"Unable to read type.", |
| 1205 | {0x32}}, |
| 1206 | // connection_id |
| 1207 | {"Unable to read Destination ConnectionId.", |
| 1208 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1209 | // packet number |
| 1210 | {"Unable to read packet number.", |
| 1211 | {0x12, 0x34, 0x56, 0x78}}, |
| 1212 | }; |
| 1213 | |
| 1214 | PacketFragments packet46 = { |
| 1215 | // type (short header, 4 byte packet number) |
| 1216 | {"Unable to read type.", |
| 1217 | {0x43}}, |
| 1218 | // connection_id |
| 1219 | {"Unable to read Destination ConnectionId.", |
| 1220 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1221 | // packet number |
| 1222 | {"Unable to read packet number.", |
| 1223 | {0x12, 0x34, 0x56, 0x78}}, |
| 1224 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1225 | |
| 1226 | PacketFragments packet_hp = { |
| 1227 | // type (short header, 4 byte packet number) |
| 1228 | {"Unable to read type.", |
| 1229 | {0x43}}, |
| 1230 | // connection_id |
| 1231 | {"Unable to read Destination ConnectionId.", |
| 1232 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1233 | // packet number |
| 1234 | {"", |
| 1235 | {0x12, 0x34, 0x56, 0x78}}, |
| 1236 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1237 | // clang-format on |
| 1238 | |
| 1239 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1240 | framer_.version().HasHeaderProtection() |
| 1241 | ? packet_hp |
| 1242 | : framer_.transport_version() > QUIC_VERSION_44 |
| 1243 | ? packet46 |
| 1244 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 1245 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1246 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1247 | AssemblePacketFromFragments(fragments)); |
| 1248 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1249 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1250 | ASSERT_TRUE(visitor_.header_.get()); |
| 1251 | EXPECT_EQ(FramerTestConnectionId(), |
| 1252 | visitor_.header_->destination_connection_id); |
| 1253 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1254 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1255 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1256 | |
| 1257 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1258 | } |
| 1259 | |
| 1260 | TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1261 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1262 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1263 | |
| 1264 | // clang-format off |
| 1265 | PacketFragments packet = { |
| 1266 | // public flags (8 byte connection_id and 2 byte packet number) |
| 1267 | {"Unable to read public flags.", |
| 1268 | {0x18}}, |
| 1269 | // connection_id |
| 1270 | {"Unable to read ConnectionId.", |
| 1271 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1272 | // packet number |
| 1273 | {"Unable to read packet number.", |
| 1274 | {0x56, 0x78}}, |
| 1275 | }; |
| 1276 | |
| 1277 | PacketFragments packet44 = { |
| 1278 | // type (short header, 2 byte packet number) |
| 1279 | {"Unable to read type.", |
| 1280 | {0x31}}, |
| 1281 | // connection_id |
| 1282 | {"Unable to read Destination ConnectionId.", |
| 1283 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1284 | // packet number |
| 1285 | {"Unable to read packet number.", |
| 1286 | {0x56, 0x78}}, |
| 1287 | }; |
| 1288 | |
| 1289 | PacketFragments packet46 = { |
| 1290 | // type (short header, 2 byte packet number) |
| 1291 | {"Unable to read type.", |
| 1292 | {0x41}}, |
| 1293 | // connection_id |
| 1294 | {"Unable to read Destination ConnectionId.", |
| 1295 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1296 | // packet number |
| 1297 | {"Unable to read packet number.", |
| 1298 | {0x56, 0x78}}, |
| 1299 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1300 | |
| 1301 | PacketFragments packet_hp = { |
| 1302 | // type (short header, 2 byte packet number) |
| 1303 | {"Unable to read type.", |
| 1304 | {0x41}}, |
| 1305 | // connection_id |
| 1306 | {"Unable to read Destination ConnectionId.", |
| 1307 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1308 | // packet number |
| 1309 | {"", |
| 1310 | {0x56, 0x78}}, |
| 1311 | // padding |
| 1312 | {"", {0x00, 0x00}}, |
| 1313 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1314 | // clang-format on |
| 1315 | |
| 1316 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1317 | framer_.version().HasHeaderProtection() |
| 1318 | ? packet_hp |
| 1319 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 1320 | ? packet46 |
| 1321 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 1322 | : packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1323 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1324 | AssemblePacketFromFragments(fragments)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1325 | if (framer_.version().HasHeaderProtection()) { |
| 1326 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 1327 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1328 | } else { |
| 1329 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1330 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1331 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1332 | ASSERT_TRUE(visitor_.header_.get()); |
| 1333 | EXPECT_EQ(FramerTestConnectionId(), |
| 1334 | visitor_.header_->destination_connection_id); |
| 1335 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1336 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1337 | EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1338 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1339 | |
| 1340 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1341 | } |
| 1342 | |
| 1343 | TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1344 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1345 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1346 | |
| 1347 | // clang-format off |
| 1348 | PacketFragments packet = { |
| 1349 | // public flags (8 byte connection_id and 1 byte packet number) |
| 1350 | {"Unable to read public flags.", |
| 1351 | {0x08}}, |
| 1352 | // connection_id |
| 1353 | {"Unable to read ConnectionId.", |
| 1354 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1355 | // packet number |
| 1356 | {"Unable to read packet number.", |
| 1357 | {0x78}}, |
| 1358 | }; |
| 1359 | |
| 1360 | PacketFragments packet44 = { |
| 1361 | // type (8 byte connection_id and 1 byte packet number) |
| 1362 | {"Unable to read type.", |
| 1363 | {0x30}}, |
| 1364 | // connection_id |
| 1365 | {"Unable to read Destination ConnectionId.", |
| 1366 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1367 | // packet number |
| 1368 | {"Unable to read packet number.", |
| 1369 | {0x78}}, |
| 1370 | }; |
| 1371 | |
| 1372 | PacketFragments packet46 = { |
| 1373 | // type (8 byte connection_id and 1 byte packet number) |
| 1374 | {"Unable to read type.", |
| 1375 | {0x40}}, |
| 1376 | // connection_id |
| 1377 | {"Unable to read Destination ConnectionId.", |
| 1378 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1379 | // packet number |
| 1380 | {"Unable to read packet number.", |
| 1381 | {0x78}}, |
| 1382 | }; |
| 1383 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1384 | PacketFragments packet_hp = { |
| 1385 | // type (8 byte connection_id and 1 byte packet number) |
| 1386 | {"Unable to read type.", |
| 1387 | {0x40}}, |
| 1388 | // connection_id |
| 1389 | {"Unable to read Destination ConnectionId.", |
| 1390 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1391 | // packet number |
| 1392 | {"", |
| 1393 | {0x78}}, |
| 1394 | // padding |
| 1395 | {"", {0x00, 0x00, 0x00}}, |
| 1396 | }; |
| 1397 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1398 | // clang-format on |
| 1399 | |
| 1400 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1401 | framer_.version().HasHeaderProtection() |
| 1402 | ? packet_hp |
| 1403 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 1404 | ? packet46 |
| 1405 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 1406 | : packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1407 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1408 | AssemblePacketFromFragments(fragments)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1409 | if (framer_.version().HasHeaderProtection()) { |
| 1410 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 1411 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1412 | } else { |
| 1413 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1414 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1415 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1416 | ASSERT_TRUE(visitor_.header_.get()); |
| 1417 | EXPECT_EQ(FramerTestConnectionId(), |
| 1418 | visitor_.header_->destination_connection_id); |
| 1419 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1420 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1421 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1422 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1423 | |
| 1424 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1425 | } |
| 1426 | |
| 1427 | TEST_P(QuicFramerTest, PacketNumberDecreasesThenIncreases) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1428 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1429 | // Test the case when a packet is received from the past and future packet |
| 1430 | // numbers are still calculated relative to the largest received packet. |
| 1431 | QuicPacketHeader header; |
| 1432 | header.destination_connection_id = FramerTestConnectionId(); |
| 1433 | header.reset_flag = false; |
| 1434 | header.version_flag = false; |
| 1435 | header.packet_number = kPacketNumber - 2; |
| 1436 | |
| 1437 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 1438 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1439 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 1440 | ASSERT_TRUE(data != nullptr); |
| 1441 | |
| 1442 | QuicEncryptedPacket encrypted(data->data(), data->length(), false); |
| 1443 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1444 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1445 | ASSERT_TRUE(visitor_.header_.get()); |
| 1446 | EXPECT_EQ(FramerTestConnectionId(), |
| 1447 | visitor_.header_->destination_connection_id); |
| 1448 | EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1449 | EXPECT_EQ(kPacketNumber - 2, visitor_.header_->packet_number); |
| 1450 | |
| 1451 | // Receive a 1 byte packet number. |
| 1452 | header.packet_number = kPacketNumber; |
| 1453 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 1454 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1455 | data = BuildDataPacket(header, frames); |
| 1456 | QuicEncryptedPacket encrypted1(data->data(), data->length(), false); |
| 1457 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1458 | EXPECT_TRUE(framer_.ProcessPacket(encrypted1)); |
| 1459 | ASSERT_TRUE(visitor_.header_.get()); |
| 1460 | EXPECT_EQ(FramerTestConnectionId(), |
| 1461 | visitor_.header_->destination_connection_id); |
| 1462 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1463 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1464 | |
| 1465 | // Process a 2 byte packet number 256 packets ago. |
| 1466 | header.packet_number = kPacketNumber - 256; |
| 1467 | header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; |
| 1468 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1469 | data = BuildDataPacket(header, frames); |
| 1470 | QuicEncryptedPacket encrypted2(data->data(), data->length(), false); |
| 1471 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1472 | EXPECT_TRUE(framer_.ProcessPacket(encrypted2)); |
| 1473 | ASSERT_TRUE(visitor_.header_.get()); |
| 1474 | EXPECT_EQ(FramerTestConnectionId(), |
| 1475 | visitor_.header_->destination_connection_id); |
| 1476 | EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1477 | EXPECT_EQ(kPacketNumber - 256, visitor_.header_->packet_number); |
| 1478 | |
| 1479 | // Process another 1 byte packet number and ensure it works. |
| 1480 | header.packet_number = kPacketNumber - 1; |
| 1481 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 1482 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1483 | data = BuildDataPacket(header, frames); |
| 1484 | QuicEncryptedPacket encrypted3(data->data(), data->length(), false); |
| 1485 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1486 | EXPECT_TRUE(framer_.ProcessPacket(encrypted3)); |
| 1487 | ASSERT_TRUE(visitor_.header_.get()); |
| 1488 | EXPECT_EQ(FramerTestConnectionId(), |
| 1489 | visitor_.header_->destination_connection_id); |
| 1490 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1491 | EXPECT_EQ(kPacketNumber - 1, visitor_.header_->packet_number); |
| 1492 | } |
| 1493 | |
| 1494 | TEST_P(QuicFramerTest, PacketWithDiversificationNonce) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1495 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1496 | // clang-format off |
| 1497 | unsigned char packet[] = { |
| 1498 | // public flags: includes nonce flag |
| 1499 | 0x2C, |
| 1500 | // connection_id |
| 1501 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1502 | // nonce |
| 1503 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1504 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1505 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1506 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1507 | // packet number |
| 1508 | 0x12, 0x34, 0x56, 0x78, |
| 1509 | |
| 1510 | // frame type (padding) |
| 1511 | 0x00, |
| 1512 | 0x00, 0x00, 0x00, 0x00 |
| 1513 | }; |
| 1514 | |
| 1515 | unsigned char packet44[] = { |
| 1516 | // type: Long header with packet type ZERO_RTT_PROTECTED |
| 1517 | 0xFC, |
| 1518 | // version tag |
| 1519 | QUIC_VERSION_BYTES, |
| 1520 | // connection_id length |
| 1521 | 0x05, |
| 1522 | // connection_id |
| 1523 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1524 | // packet number |
| 1525 | 0x12, 0x34, 0x56, 0x78, |
| 1526 | // nonce |
| 1527 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1528 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1529 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1530 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1531 | |
| 1532 | // frame type (padding) |
| 1533 | 0x00, |
| 1534 | 0x00, 0x00, 0x00, 0x00 |
| 1535 | }; |
| 1536 | |
| 1537 | unsigned char packet46[] = { |
| 1538 | // type: Long header with packet type ZERO_RTT_PROTECTED and 1 byte packet |
| 1539 | // number. |
| 1540 | 0xD0, |
| 1541 | // version tag |
| 1542 | QUIC_VERSION_BYTES, |
| 1543 | // connection_id length |
| 1544 | 0x05, |
| 1545 | // connection_id |
| 1546 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1547 | // packet number |
| 1548 | 0x78, |
| 1549 | // nonce |
| 1550 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1551 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1552 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1553 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1554 | |
| 1555 | // frame type (padding) |
| 1556 | 0x00, |
| 1557 | 0x00, 0x00, 0x00, 0x00 |
| 1558 | }; |
| 1559 | |
| 1560 | unsigned char packet99[] = { |
| 1561 | // type: Long header with packet type ZERO_RTT_PROTECTED and 1 byte packet |
| 1562 | // number. |
| 1563 | 0xD0, |
| 1564 | // version tag |
| 1565 | QUIC_VERSION_BYTES, |
| 1566 | // connection_id length |
| 1567 | 0x05, |
| 1568 | // connection_id |
| 1569 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1570 | // long header packet length |
| 1571 | 0x26, |
| 1572 | // packet number |
| 1573 | 0x78, |
| 1574 | // nonce |
| 1575 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1576 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1577 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1578 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1579 | |
| 1580 | // frame type (padding) |
| 1581 | 0x00, |
| 1582 | 0x00, 0x00, 0x00, 0x00 |
| 1583 | }; |
| 1584 | // clang-format on |
| 1585 | |
| 1586 | if (framer_.version().handshake_protocol != PROTOCOL_QUIC_CRYPTO) { |
| 1587 | return; |
| 1588 | } |
| 1589 | |
| 1590 | unsigned char* p = packet; |
| 1591 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 1592 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 1593 | p = packet99; |
| 1594 | p_size = QUIC_ARRAYSIZE(packet99); |
| 1595 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 1596 | p = packet46; |
| 1597 | p_size = QUIC_ARRAYSIZE(packet46); |
| 1598 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 1599 | p = packet44; |
| 1600 | p_size = QUIC_ARRAYSIZE(packet44); |
| 1601 | } |
| 1602 | |
| 1603 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 1604 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1605 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1606 | ASSERT_TRUE(visitor_.header_->nonce != nullptr); |
| 1607 | for (char i = 0; i < 32; ++i) { |
| 1608 | EXPECT_EQ(i, (*visitor_.header_->nonce)[static_cast<size_t>(i)]); |
| 1609 | } |
| 1610 | EXPECT_EQ(1u, visitor_.padding_frames_.size()); |
| 1611 | EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes); |
| 1612 | } |
| 1613 | |
| 1614 | TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) { |
| 1615 | // clang-format off |
| 1616 | unsigned char packet[] = { |
| 1617 | // public flags (8 byte connection_id, version flag and an unknown flag) |
| 1618 | 0x29, |
| 1619 | // connection_id |
| 1620 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1621 | // version tag |
| 1622 | 'Q', '0', '0', '0', |
| 1623 | // packet number |
| 1624 | 0x12, 0x34, 0x56, 0x78, |
| 1625 | |
| 1626 | // frame type (padding frame) |
| 1627 | 0x00, |
| 1628 | 0x00, 0x00, 0x00, 0x00 |
| 1629 | }; |
| 1630 | |
| 1631 | unsigned char packet44[] = { |
| 1632 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 1633 | 0xFC, |
| 1634 | // version tag |
| 1635 | 'Q', '0', '0', '0', |
| 1636 | // connection_id length |
| 1637 | 0x50, |
| 1638 | // connection_id |
| 1639 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1640 | // packet number |
| 1641 | 0x12, 0x34, 0x56, 0x78, |
| 1642 | |
| 1643 | // frame type (padding frame) |
| 1644 | 0x00, |
| 1645 | 0x00, 0x00, 0x00, 0x00 |
| 1646 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1647 | |
| 1648 | unsigned char packet45[] = { |
| 1649 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 1650 | 0xD3, |
| 1651 | // version tag |
| 1652 | 'Q', '0', '0', '0', |
| 1653 | // connection_id length |
| 1654 | 0x50, |
| 1655 | // connection_id |
| 1656 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1657 | // packet number |
| 1658 | 0x12, 0x34, 0x56, 0x78, |
| 1659 | |
| 1660 | // frame type (padding frame) |
| 1661 | 0x00, |
| 1662 | 0x00, 0x00, 0x00, 0x00 |
| 1663 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1664 | // clang-format on |
| 1665 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1666 | unsigned char* p = packet; |
| 1667 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 1668 | if (framer_.transport_version() > QUIC_VERSION_44) { |
| 1669 | p = packet45; |
| 1670 | p_size = QUIC_ARRAYSIZE(packet45); |
| 1671 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 1672 | p = packet44; |
| 1673 | p_size = QUIC_ARRAYSIZE(packet44); |
| 1674 | } |
| 1675 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1676 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1677 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1678 | ASSERT_TRUE(visitor_.header_.get()); |
| 1679 | EXPECT_EQ(0, visitor_.frame_count_); |
| 1680 | EXPECT_EQ(1, visitor_.version_mismatch_); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1681 | ASSERT_EQ(1u, visitor_.padding_frames_.size()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1682 | EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes); |
| 1683 | } |
| 1684 | |
| 1685 | TEST_P(QuicFramerTest, PaddingFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1686 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1687 | // clang-format off |
| 1688 | unsigned char packet[] = { |
| 1689 | // public flags (8 byte connection_id) |
| 1690 | 0x28, |
| 1691 | // connection_id |
| 1692 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1693 | // packet number |
| 1694 | 0x12, 0x34, 0x56, 0x78, |
| 1695 | |
| 1696 | // paddings |
| 1697 | 0x00, 0x00, |
| 1698 | // frame type (stream frame with fin) |
| 1699 | 0xFF, |
| 1700 | // stream id |
| 1701 | 0x01, 0x02, 0x03, 0x04, |
| 1702 | // offset |
| 1703 | 0x3A, 0x98, 0xFE, 0xDC, |
| 1704 | 0x32, 0x10, 0x76, 0x54, |
| 1705 | // data length |
| 1706 | 0x00, 0x0c, |
| 1707 | // data |
| 1708 | 'h', 'e', 'l', 'l', |
| 1709 | 'o', ' ', 'w', 'o', |
| 1710 | 'r', 'l', 'd', '!', |
| 1711 | // paddings |
| 1712 | 0x00, 0x00, |
| 1713 | }; |
| 1714 | |
| 1715 | unsigned char packet44[] = { |
| 1716 | // type (short header, 4 byte packet number) |
| 1717 | 0x32, |
| 1718 | // connection_id |
| 1719 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1720 | // packet number |
| 1721 | 0x12, 0x34, 0x56, 0x78, |
| 1722 | |
| 1723 | // paddings |
| 1724 | 0x00, 0x00, |
| 1725 | // frame type (stream frame with fin) |
| 1726 | 0xFF, |
| 1727 | // stream id |
| 1728 | 0x01, 0x02, 0x03, 0x04, |
| 1729 | // offset |
| 1730 | 0x3A, 0x98, 0xFE, 0xDC, |
| 1731 | 0x32, 0x10, 0x76, 0x54, |
| 1732 | // data length |
| 1733 | 0x00, 0x0c, |
| 1734 | // data |
| 1735 | 'h', 'e', 'l', 'l', |
| 1736 | 'o', ' ', 'w', 'o', |
| 1737 | 'r', 'l', 'd', '!', |
| 1738 | // paddings |
| 1739 | 0x00, 0x00, |
| 1740 | }; |
| 1741 | |
| 1742 | unsigned char packet46[] = { |
| 1743 | // type (short header, 4 byte packet number) |
| 1744 | 0x43, |
| 1745 | // connection_id |
| 1746 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1747 | // packet number |
| 1748 | 0x12, 0x34, 0x56, 0x78, |
| 1749 | |
| 1750 | // paddings |
| 1751 | 0x00, 0x00, |
| 1752 | // frame type (stream frame with fin) |
| 1753 | 0xFF, |
| 1754 | // stream id |
| 1755 | 0x01, 0x02, 0x03, 0x04, |
| 1756 | // offset |
| 1757 | 0x3A, 0x98, 0xFE, 0xDC, |
| 1758 | 0x32, 0x10, 0x76, 0x54, |
| 1759 | // data length |
| 1760 | 0x00, 0x0c, |
| 1761 | // data |
| 1762 | 'h', 'e', 'l', 'l', |
| 1763 | 'o', ' ', 'w', 'o', |
| 1764 | 'r', 'l', 'd', '!', |
| 1765 | // paddings |
| 1766 | 0x00, 0x00, |
| 1767 | }; |
| 1768 | |
| 1769 | unsigned char packet99[] = { |
| 1770 | // type (short header, 4 byte packet number) |
| 1771 | 0x43, |
| 1772 | // connection_id |
| 1773 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1774 | // packet number |
| 1775 | 0x12, 0x34, 0x56, 0x78, |
| 1776 | |
| 1777 | // paddings |
| 1778 | 0x00, 0x00, |
| 1779 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 1780 | 0x08 | 0x01 | 0x02 | 0x04, |
| 1781 | |
| 1782 | // stream id |
| 1783 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 1784 | // offset |
| 1785 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 1786 | 0x32, 0x10, 0x76, 0x54, |
| 1787 | // data length |
| 1788 | kVarInt62OneByte + 0x0c, |
| 1789 | // data |
| 1790 | 'h', 'e', 'l', 'l', |
| 1791 | 'o', ' ', 'w', 'o', |
| 1792 | 'r', 'l', 'd', '!', |
| 1793 | // paddings |
| 1794 | 0x00, 0x00, |
| 1795 | }; |
| 1796 | // clang-format on |
| 1797 | |
| 1798 | unsigned char* p = packet; |
| 1799 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 1800 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 1801 | p = packet99; |
| 1802 | p_size = QUIC_ARRAYSIZE(packet99); |
| 1803 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 1804 | p = packet46; |
| 1805 | p_size = QUIC_ARRAYSIZE(packet46); |
| 1806 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 1807 | p = packet44; |
| 1808 | p_size = QUIC_ARRAYSIZE(packet44); |
| 1809 | } |
| 1810 | |
| 1811 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 1812 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1813 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1814 | ASSERT_TRUE(visitor_.header_.get()); |
| 1815 | EXPECT_TRUE(CheckDecryption( |
| 1816 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 1817 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 1818 | |
| 1819 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1820 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1821 | EXPECT_EQ(2u, visitor_.padding_frames_.size()); |
| 1822 | EXPECT_EQ(2, visitor_.padding_frames_[0]->num_padding_bytes); |
| 1823 | EXPECT_EQ(2, visitor_.padding_frames_[1]->num_padding_bytes); |
| 1824 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 1825 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1826 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 1827 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 1828 | } |
| 1829 | |
| 1830 | TEST_P(QuicFramerTest, StreamFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1831 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1832 | // clang-format off |
| 1833 | PacketFragments packet = { |
| 1834 | // public flags (8 byte connection_id) |
| 1835 | {"", |
| 1836 | {0x28}}, |
| 1837 | // connection_id |
| 1838 | {"", |
| 1839 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1840 | // packet number |
| 1841 | {"", |
| 1842 | {0x12, 0x34, 0x56, 0x78}}, |
| 1843 | // frame type (stream frame with fin) |
| 1844 | {"", |
| 1845 | {0xFF}}, |
| 1846 | // stream id |
| 1847 | {"Unable to read stream_id.", |
| 1848 | {0x01, 0x02, 0x03, 0x04}}, |
| 1849 | // offset |
| 1850 | {"Unable to read offset.", |
| 1851 | {0x3A, 0x98, 0xFE, 0xDC, |
| 1852 | 0x32, 0x10, 0x76, 0x54}}, |
| 1853 | {"Unable to read frame data.", |
| 1854 | { |
| 1855 | // data length |
| 1856 | 0x00, 0x0c, |
| 1857 | // data |
| 1858 | 'h', 'e', 'l', 'l', |
| 1859 | 'o', ' ', 'w', 'o', |
| 1860 | 'r', 'l', 'd', '!'}}, |
| 1861 | }; |
| 1862 | |
| 1863 | PacketFragments packet44 = { |
| 1864 | // type (short header, 4 byte packet number) |
| 1865 | {"", |
| 1866 | {0x32}}, |
| 1867 | // connection_id |
| 1868 | {"", |
| 1869 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1870 | // packet number |
| 1871 | {"", |
| 1872 | {0x12, 0x34, 0x56, 0x78}}, |
| 1873 | // frame type (stream frame with fin) |
| 1874 | {"", |
| 1875 | {0xFF}}, |
| 1876 | // stream id |
| 1877 | {"Unable to read stream_id.", |
| 1878 | {0x01, 0x02, 0x03, 0x04}}, |
| 1879 | // offset |
| 1880 | {"Unable to read offset.", |
| 1881 | {0x3A, 0x98, 0xFE, 0xDC, |
| 1882 | 0x32, 0x10, 0x76, 0x54}}, |
| 1883 | {"Unable to read frame data.", |
| 1884 | { |
| 1885 | // data length |
| 1886 | 0x00, 0x0c, |
| 1887 | // data |
| 1888 | 'h', 'e', 'l', 'l', |
| 1889 | 'o', ' ', 'w', 'o', |
| 1890 | 'r', 'l', 'd', '!'}}, |
| 1891 | }; |
| 1892 | |
| 1893 | PacketFragments packet46 = { |
| 1894 | // type (short header, 4 byte packet number) |
| 1895 | {"", |
| 1896 | {0x43}}, |
| 1897 | // connection_id |
| 1898 | {"", |
| 1899 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1900 | // packet number |
| 1901 | {"", |
| 1902 | {0x12, 0x34, 0x56, 0x78}}, |
| 1903 | // frame type (stream frame with fin) |
| 1904 | {"", |
| 1905 | {0xFF}}, |
| 1906 | // stream id |
| 1907 | {"Unable to read stream_id.", |
| 1908 | {0x01, 0x02, 0x03, 0x04}}, |
| 1909 | // offset |
| 1910 | {"Unable to read offset.", |
| 1911 | {0x3A, 0x98, 0xFE, 0xDC, |
| 1912 | 0x32, 0x10, 0x76, 0x54}}, |
| 1913 | {"Unable to read frame data.", |
| 1914 | { |
| 1915 | // data length |
| 1916 | 0x00, 0x0c, |
| 1917 | // data |
| 1918 | 'h', 'e', 'l', 'l', |
| 1919 | 'o', ' ', 'w', 'o', |
| 1920 | 'r', 'l', 'd', '!'}}, |
| 1921 | }; |
| 1922 | |
| 1923 | PacketFragments packet99 = { |
| 1924 | // type (short header, 4 byte packet number) |
| 1925 | {"", |
| 1926 | {0x43}}, |
| 1927 | // connection_id |
| 1928 | {"", |
| 1929 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1930 | // packet number |
| 1931 | {"", |
| 1932 | {0x12, 0x34, 0x56, 0x78}}, |
| 1933 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 1934 | {"", |
| 1935 | { 0x08 | 0x01 | 0x02 | 0x04 }}, |
| 1936 | // stream id |
| 1937 | {"Unable to read stream_id.", |
| 1938 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 1939 | // offset |
| 1940 | {"Unable to read stream data offset.", |
| 1941 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 1942 | 0x32, 0x10, 0x76, 0x54}}, |
| 1943 | // data length |
| 1944 | {"Unable to read stream data length.", |
| 1945 | {kVarInt62OneByte + 0x0c}}, |
| 1946 | // data |
| 1947 | {"Unable to read frame data.", |
| 1948 | { 'h', 'e', 'l', 'l', |
| 1949 | 'o', ' ', 'w', 'o', |
| 1950 | 'r', 'l', 'd', '!'}}, |
| 1951 | }; |
| 1952 | // clang-format on |
| 1953 | |
| 1954 | PacketFragments& fragments = |
| 1955 | framer_.transport_version() == QUIC_VERSION_99 |
| 1956 | ? packet99 |
| 1957 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 1958 | ? packet46 |
| 1959 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 1960 | : packet)); |
| 1961 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1962 | AssemblePacketFromFragments(fragments)); |
| 1963 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 1964 | |
| 1965 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1966 | ASSERT_TRUE(visitor_.header_.get()); |
| 1967 | EXPECT_TRUE(CheckDecryption( |
| 1968 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 1969 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 1970 | |
| 1971 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1972 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1973 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 1974 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1975 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 1976 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 1977 | |
| 1978 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 1979 | } |
| 1980 | |
| 1981 | // Test an empty (no data) stream frame. |
| 1982 | TEST_P(QuicFramerTest, EmptyStreamFrame) { |
| 1983 | // Only the IETF QUIC spec explicitly says that empty |
| 1984 | // stream frames are supported. |
| 1985 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 1986 | return; |
| 1987 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1988 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1989 | // clang-format off |
| 1990 | PacketFragments packet = { |
| 1991 | // type (short header, 4 byte packet number) |
| 1992 | {"", |
| 1993 | {0x43}}, |
| 1994 | // connection_id |
| 1995 | {"", |
| 1996 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1997 | // packet number |
| 1998 | {"", |
| 1999 | {0x12, 0x34, 0x56, 0x78}}, |
| 2000 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 2001 | {"", |
| 2002 | { 0x08 | 0x01 | 0x02 | 0x04 }}, |
| 2003 | // stream id |
| 2004 | {"Unable to read stream_id.", |
| 2005 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 2006 | // offset |
| 2007 | {"Unable to read stream data offset.", |
| 2008 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2009 | 0x32, 0x10, 0x76, 0x54}}, |
| 2010 | // data length |
| 2011 | {"Unable to read stream data length.", |
| 2012 | {kVarInt62OneByte + 0x00}}, |
| 2013 | }; |
| 2014 | // clang-format on |
| 2015 | |
| 2016 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2017 | AssemblePacketFromFragments(packet)); |
| 2018 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2019 | |
| 2020 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2021 | ASSERT_TRUE(visitor_.header_.get()); |
| 2022 | EXPECT_TRUE(CheckDecryption( |
| 2023 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2024 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2025 | |
| 2026 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2027 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2028 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2029 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2030 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2031 | EXPECT_EQ(visitor_.stream_frames_[0].get()->data_length, 0u); |
| 2032 | |
| 2033 | CheckFramingBoundaries(packet, QUIC_INVALID_STREAM_DATA); |
| 2034 | } |
| 2035 | |
| 2036 | TEST_P(QuicFramerTest, MissingDiversificationNonce) { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2037 | if (framer_.version().handshake_protocol != PROTOCOL_QUIC_CRYPTO) { |
| 2038 | // TLS does not use diversification nonces. |
| 2039 | return; |
| 2040 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2041 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2042 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2043 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 2044 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, QuicMakeUnique<NullDecrypter>( |
| 2045 | Perspective::IS_CLIENT)); |
| 2046 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 2047 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 2048 | } else { |
| 2049 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 2050 | QuicMakeUnique<NullDecrypter>(Perspective::IS_CLIENT)); |
| 2051 | framer_.SetAlternativeDecrypter( |
| 2052 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 2053 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2054 | |
| 2055 | // clang-format off |
| 2056 | unsigned char packet[] = { |
| 2057 | // public flags (8 byte connection_id) |
| 2058 | 0x28, |
| 2059 | // connection_id |
| 2060 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 2061 | // packet number |
| 2062 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2063 | // padding frame |
| 2064 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2065 | }; |
| 2066 | |
| 2067 | unsigned char packet44[] = { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2068 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2069 | 0xFC, |
| 2070 | // version tag |
| 2071 | QUIC_VERSION_BYTES, |
| 2072 | // connection_id length |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2073 | 0x05, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2074 | // connection_id |
| 2075 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 2076 | // packet number |
| 2077 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2078 | // padding frame |
| 2079 | 0x00, |
| 2080 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2081 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2082 | unsigned char packet46[] = { |
| 2083 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 2084 | 0xD3, |
| 2085 | // version tag |
| 2086 | QUIC_VERSION_BYTES, |
| 2087 | // connection_id length |
| 2088 | 0x05, |
| 2089 | // connection_id |
| 2090 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 2091 | // packet number |
| 2092 | 0x12, 0x34, 0x56, 0x78, |
| 2093 | // padding frame |
| 2094 | 0x00, |
| 2095 | }; |
| 2096 | |
| 2097 | unsigned char packet99[] = { |
| 2098 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 2099 | 0xD3, |
| 2100 | // version tag |
| 2101 | QUIC_VERSION_BYTES, |
| 2102 | // connection_id length |
| 2103 | 0x05, |
| 2104 | // connection_id |
| 2105 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 2106 | // IETF long header payload length |
| 2107 | 0x05, |
| 2108 | // packet number |
| 2109 | 0x12, 0x34, 0x56, 0x78, |
| 2110 | // padding frame |
| 2111 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2112 | }; |
| 2113 | // clang-format on |
| 2114 | |
| 2115 | unsigned char* p = packet; |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2116 | size_t p_length = QUIC_ARRAYSIZE(packet); |
| 2117 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 2118 | p = packet99; |
| 2119 | p_length = QUIC_ARRAYSIZE(packet99); |
| 2120 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
| 2121 | p = packet46; |
| 2122 | p_length = QUIC_ARRAYSIZE(packet46); |
| 2123 | } else if (framer_.transport_version() >= QUIC_VERSION_44) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2124 | p = packet44; |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2125 | p_length = QUIC_ARRAYSIZE(packet44); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2126 | } |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2127 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2128 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 2129 | if (framer_.version().HasHeaderProtection()) { |
| 2130 | EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error()); |
| 2131 | EXPECT_EQ("Unable to decrypt header protection.", framer_.detailed_error()); |
| 2132 | } else if (framer_.transport_version() >= QUIC_VERSION_44) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2133 | // Cannot read diversification nonce. |
| 2134 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2135 | EXPECT_EQ("Unable to read nonce.", framer_.detailed_error()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2136 | } else { |
| 2137 | EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error()); |
| 2138 | } |
| 2139 | } |
| 2140 | |
| 2141 | TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { |
| 2142 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 2143 | // This test is nonsensical for IETF Quic. |
| 2144 | return; |
| 2145 | } |
| 2146 | // clang-format off |
| 2147 | PacketFragments packet = { |
| 2148 | // public flags (8 byte connection_id) |
| 2149 | {"", |
| 2150 | {0x28}}, |
| 2151 | // connection_id |
| 2152 | {"", |
| 2153 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2154 | // packet number |
| 2155 | {"", |
| 2156 | {0x12, 0x34, 0x56, 0x78}}, |
| 2157 | // frame type (stream frame with fin) |
| 2158 | {"", |
| 2159 | {0xFE}}, |
| 2160 | // stream id |
| 2161 | {"Unable to read stream_id.", |
| 2162 | {0x02, 0x03, 0x04}}, |
| 2163 | // offset |
| 2164 | {"Unable to read offset.", |
| 2165 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2166 | 0x32, 0x10, 0x76, 0x54}}, |
| 2167 | {"Unable to read frame data.", |
| 2168 | { |
| 2169 | // data length |
| 2170 | 0x00, 0x0c, |
| 2171 | // data |
| 2172 | 'h', 'e', 'l', 'l', |
| 2173 | 'o', ' ', 'w', 'o', |
| 2174 | 'r', 'l', 'd', '!'}}, |
| 2175 | }; |
| 2176 | // clang-format on |
| 2177 | |
| 2178 | PacketFragments& fragments = packet; |
| 2179 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2180 | AssemblePacketFromFragments(fragments)); |
| 2181 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2182 | |
| 2183 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2184 | ASSERT_TRUE(visitor_.header_.get()); |
| 2185 | EXPECT_TRUE(CheckDecryption( |
| 2186 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2187 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2188 | |
| 2189 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2190 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2191 | // Stream ID should be the last 3 bytes of kStreamId. |
| 2192 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2193 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2194 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2195 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2196 | |
| 2197 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2198 | } |
| 2199 | |
| 2200 | TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2201 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2202 | // clang-format off |
| 2203 | PacketFragments packet = { |
| 2204 | // public flags (8 byte connection_id) |
| 2205 | {"", |
| 2206 | {0x28}}, |
| 2207 | // connection_id |
| 2208 | {"", |
| 2209 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2210 | // packet number |
| 2211 | {"", |
| 2212 | {0x12, 0x34, 0x56, 0x78}}, |
| 2213 | // frame type (stream frame with fin) |
| 2214 | {"", |
| 2215 | {0xFD}}, |
| 2216 | // stream id |
| 2217 | {"Unable to read stream_id.", |
| 2218 | {0x03, 0x04}}, |
| 2219 | // offset |
| 2220 | {"Unable to read offset.", |
| 2221 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2222 | 0x32, 0x10, 0x76, 0x54}}, |
| 2223 | {"Unable to read frame data.", |
| 2224 | { |
| 2225 | // data length |
| 2226 | 0x00, 0x0c, |
| 2227 | // data |
| 2228 | 'h', 'e', 'l', 'l', |
| 2229 | 'o', ' ', 'w', 'o', |
| 2230 | 'r', 'l', 'd', '!'}}, |
| 2231 | }; |
| 2232 | |
| 2233 | PacketFragments packet44 = { |
| 2234 | // type (short header, 4 byte packet number) |
| 2235 | {"", |
| 2236 | {0x32}}, |
| 2237 | // connection_id |
| 2238 | {"", |
| 2239 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2240 | // packet number |
| 2241 | {"", |
| 2242 | {0x12, 0x34, 0x56, 0x78}}, |
| 2243 | // frame type (stream frame with fin) |
| 2244 | {"", |
| 2245 | {0xFD}}, |
| 2246 | // stream id |
| 2247 | {"Unable to read stream_id.", |
| 2248 | {0x03, 0x04}}, |
| 2249 | // offset |
| 2250 | {"Unable to read offset.", |
| 2251 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2252 | 0x32, 0x10, 0x76, 0x54}}, |
| 2253 | {"Unable to read frame data.", |
| 2254 | { |
| 2255 | // data length |
| 2256 | 0x00, 0x0c, |
| 2257 | // data |
| 2258 | 'h', 'e', 'l', 'l', |
| 2259 | 'o', ' ', 'w', 'o', |
| 2260 | 'r', 'l', 'd', '!'}}, |
| 2261 | }; |
| 2262 | |
| 2263 | PacketFragments packet46 = { |
| 2264 | // type (short header, 4 byte packet number) |
| 2265 | {"", |
| 2266 | {0x43}}, |
| 2267 | // connection_id |
| 2268 | {"", |
| 2269 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2270 | // packet number |
| 2271 | {"", |
| 2272 | {0x12, 0x34, 0x56, 0x78}}, |
| 2273 | // frame type (stream frame with fin) |
| 2274 | {"", |
| 2275 | {0xFD}}, |
| 2276 | // stream id |
| 2277 | {"Unable to read stream_id.", |
| 2278 | {0x03, 0x04}}, |
| 2279 | // offset |
| 2280 | {"Unable to read offset.", |
| 2281 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2282 | 0x32, 0x10, 0x76, 0x54}}, |
| 2283 | {"Unable to read frame data.", |
| 2284 | { |
| 2285 | // data length |
| 2286 | 0x00, 0x0c, |
| 2287 | // data |
| 2288 | 'h', 'e', 'l', 'l', |
| 2289 | 'o', ' ', 'w', 'o', |
| 2290 | 'r', 'l', 'd', '!'}}, |
| 2291 | }; |
| 2292 | |
| 2293 | PacketFragments packet99 = { |
| 2294 | // type (short header, 4 byte packet number) |
| 2295 | {"", |
| 2296 | {0x43}}, |
| 2297 | // connection_id |
| 2298 | {"", |
| 2299 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2300 | // packet number |
| 2301 | {"", |
| 2302 | {0x12, 0x34, 0x56, 0x78}}, |
| 2303 | // frame type (IETF_STREAM frame with LEN, FIN, and OFFSET bits set) |
| 2304 | {"", |
| 2305 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2306 | // stream id |
| 2307 | {"Unable to read stream_id.", |
| 2308 | {kVarInt62TwoBytes + 0x03, 0x04}}, |
| 2309 | // offset |
| 2310 | {"Unable to read stream data offset.", |
| 2311 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2312 | 0x32, 0x10, 0x76, 0x54}}, |
| 2313 | // data length |
| 2314 | {"Unable to read stream data length.", |
| 2315 | {kVarInt62OneByte + 0x0c}}, |
| 2316 | // data |
| 2317 | {"Unable to read frame data.", |
| 2318 | { 'h', 'e', 'l', 'l', |
| 2319 | 'o', ' ', 'w', 'o', |
| 2320 | 'r', 'l', 'd', '!'}}, |
| 2321 | }; |
| 2322 | // clang-format on |
| 2323 | |
| 2324 | PacketFragments& fragments = |
| 2325 | framer_.transport_version() == QUIC_VERSION_99 |
| 2326 | ? packet99 |
| 2327 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2328 | ? packet46 |
| 2329 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2330 | : packet)); |
| 2331 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2332 | AssemblePacketFromFragments(fragments)); |
| 2333 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2334 | |
| 2335 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2336 | ASSERT_TRUE(visitor_.header_.get()); |
| 2337 | EXPECT_TRUE(CheckDecryption( |
| 2338 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2339 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2340 | |
| 2341 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2342 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2343 | // Stream ID should be the last 2 bytes of kStreamId. |
| 2344 | EXPECT_EQ(0x0000FFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2345 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2346 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2347 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2348 | |
| 2349 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2350 | } |
| 2351 | |
| 2352 | TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2353 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2354 | // clang-format off |
| 2355 | PacketFragments packet = { |
| 2356 | // public flags (8 byte connection_id) |
| 2357 | {"", |
| 2358 | {0x28}}, |
| 2359 | // connection_id |
| 2360 | {"", |
| 2361 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2362 | // packet number |
| 2363 | {"", |
| 2364 | {0x12, 0x34, 0x56, 0x78}}, |
| 2365 | // frame type (stream frame with fin) |
| 2366 | {"", |
| 2367 | {0xFC}}, |
| 2368 | // stream id |
| 2369 | {"Unable to read stream_id.", |
| 2370 | {0x04}}, |
| 2371 | // offset |
| 2372 | {"Unable to read offset.", |
| 2373 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2374 | 0x32, 0x10, 0x76, 0x54}}, |
| 2375 | {"Unable to read frame data.", |
| 2376 | { |
| 2377 | // data length |
| 2378 | 0x00, 0x0c, |
| 2379 | // data |
| 2380 | 'h', 'e', 'l', 'l', |
| 2381 | 'o', ' ', 'w', 'o', |
| 2382 | 'r', 'l', 'd', '!'}}, |
| 2383 | }; |
| 2384 | |
| 2385 | PacketFragments packet44 = { |
| 2386 | // type (short header, 4 byte packet number) |
| 2387 | {"", |
| 2388 | {0x32}}, |
| 2389 | // connection_id |
| 2390 | {"", |
| 2391 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2392 | // packet number |
| 2393 | {"", |
| 2394 | {0x12, 0x34, 0x56, 0x78}}, |
| 2395 | // frame type (stream frame with fin) |
| 2396 | {"", |
| 2397 | {0xFC}}, |
| 2398 | // stream id |
| 2399 | {"Unable to read stream_id.", |
| 2400 | {0x04}}, |
| 2401 | // offset |
| 2402 | {"Unable to read offset.", |
| 2403 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2404 | 0x32, 0x10, 0x76, 0x54}}, |
| 2405 | {"Unable to read frame data.", |
| 2406 | { |
| 2407 | // data length |
| 2408 | 0x00, 0x0c, |
| 2409 | // data |
| 2410 | 'h', 'e', 'l', 'l', |
| 2411 | 'o', ' ', 'w', 'o', |
| 2412 | 'r', 'l', 'd', '!'}}, |
| 2413 | }; |
| 2414 | |
| 2415 | PacketFragments packet46 = { |
| 2416 | // type (short header, 4 byte packet number) |
| 2417 | {"", |
| 2418 | {0x43}}, |
| 2419 | // connection_id |
| 2420 | {"", |
| 2421 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2422 | // packet number |
| 2423 | {"", |
| 2424 | {0x12, 0x34, 0x56, 0x78}}, |
| 2425 | // frame type (stream frame with fin) |
| 2426 | {"", |
| 2427 | {0xFC}}, |
| 2428 | // stream id |
| 2429 | {"Unable to read stream_id.", |
| 2430 | {0x04}}, |
| 2431 | // offset |
| 2432 | {"Unable to read offset.", |
| 2433 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2434 | 0x32, 0x10, 0x76, 0x54}}, |
| 2435 | {"Unable to read frame data.", |
| 2436 | { |
| 2437 | // data length |
| 2438 | 0x00, 0x0c, |
| 2439 | // data |
| 2440 | 'h', 'e', 'l', 'l', |
| 2441 | 'o', ' ', 'w', 'o', |
| 2442 | 'r', 'l', 'd', '!'}}, |
| 2443 | }; |
| 2444 | |
| 2445 | PacketFragments packet99 = { |
| 2446 | // type (short header, 4 byte packet number) |
| 2447 | {"", |
| 2448 | {0x43}}, |
| 2449 | // connection_id |
| 2450 | {"", |
| 2451 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2452 | // packet number |
| 2453 | {"", |
| 2454 | {0x12, 0x34, 0x56, 0x78}}, |
| 2455 | // frame type (IETF_STREAM frame with LEN, FIN, and OFFSET bits set) |
| 2456 | {"", |
| 2457 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2458 | // stream id |
| 2459 | {"Unable to read stream_id.", |
| 2460 | {kVarInt62OneByte + 0x04}}, |
| 2461 | // offset |
| 2462 | {"Unable to read stream data offset.", |
| 2463 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2464 | 0x32, 0x10, 0x76, 0x54}}, |
| 2465 | // data length |
| 2466 | {"Unable to read stream data length.", |
| 2467 | {kVarInt62OneByte + 0x0c}}, |
| 2468 | // data |
| 2469 | {"Unable to read frame data.", |
| 2470 | { 'h', 'e', 'l', 'l', |
| 2471 | 'o', ' ', 'w', 'o', |
| 2472 | 'r', 'l', 'd', '!'}}, |
| 2473 | }; |
| 2474 | // clang-format on |
| 2475 | |
| 2476 | PacketFragments& fragments = |
| 2477 | framer_.transport_version() == QUIC_VERSION_99 |
| 2478 | ? packet99 |
| 2479 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2480 | ? packet46 |
| 2481 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2482 | : packet)); |
| 2483 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2484 | AssemblePacketFromFragments(fragments)); |
| 2485 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2486 | |
| 2487 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2488 | ASSERT_TRUE(visitor_.header_.get()); |
| 2489 | EXPECT_TRUE(CheckDecryption( |
| 2490 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2491 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2492 | |
| 2493 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2494 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2495 | // Stream ID should be the last 1 byte of kStreamId. |
| 2496 | EXPECT_EQ(0x000000FF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2497 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2498 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2499 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2500 | |
| 2501 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2502 | } |
| 2503 | |
| 2504 | TEST_P(QuicFramerTest, StreamFrameWithVersion) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2505 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2506 | // clang-format off |
| 2507 | PacketFragments packet = { |
| 2508 | // public flags (version, 8 byte connection_id) |
| 2509 | {"", |
| 2510 | {0x29}}, |
| 2511 | // connection_id |
| 2512 | {"", |
| 2513 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2514 | // version tag |
| 2515 | {"", |
| 2516 | {QUIC_VERSION_BYTES}}, |
| 2517 | // packet number |
| 2518 | {"", |
| 2519 | {0x12, 0x34, 0x56, 0x78}}, |
| 2520 | // frame type (stream frame with fin) |
| 2521 | {"", |
| 2522 | {0xFE}}, |
| 2523 | // stream id |
| 2524 | {"Unable to read stream_id.", |
| 2525 | {0x02, 0x03, 0x04}}, |
| 2526 | // offset |
| 2527 | {"Unable to read offset.", |
| 2528 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2529 | 0x32, 0x10, 0x76, 0x54}}, |
| 2530 | {"Unable to read frame data.", |
| 2531 | { |
| 2532 | // data length |
| 2533 | 0x00, 0x0c, |
| 2534 | // data |
| 2535 | 'h', 'e', 'l', 'l', |
| 2536 | 'o', ' ', 'w', 'o', |
| 2537 | 'r', 'l', 'd', '!'}}, |
| 2538 | }; |
| 2539 | |
| 2540 | PacketFragments packet44 = { |
| 2541 | // public flags (long header with packet type ZERO_RTT_PROTECTED) |
| 2542 | {"", |
| 2543 | {0xFC}}, |
| 2544 | // version tag |
| 2545 | {"", |
| 2546 | {QUIC_VERSION_BYTES}}, |
| 2547 | // connection_id length |
| 2548 | {"", |
| 2549 | {0x50}}, |
| 2550 | // connection_id |
| 2551 | {"", |
| 2552 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2553 | // packet number |
| 2554 | {"", |
| 2555 | {0x12, 0x34, 0x56, 0x78}}, |
| 2556 | // frame type (stream frame with fin) |
| 2557 | {"", |
| 2558 | {0xFE}}, |
| 2559 | // stream id |
| 2560 | {"Unable to read stream_id.", |
| 2561 | {0x02, 0x03, 0x04}}, |
| 2562 | // offset |
| 2563 | {"Unable to read offset.", |
| 2564 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2565 | 0x32, 0x10, 0x76, 0x54}}, |
| 2566 | {"Unable to read frame data.", |
| 2567 | { |
| 2568 | // data length |
| 2569 | 0x00, 0x0c, |
| 2570 | // data |
| 2571 | 'h', 'e', 'l', 'l', |
| 2572 | 'o', ' ', 'w', 'o', |
| 2573 | 'r', 'l', 'd', '!'}}, |
| 2574 | }; |
| 2575 | |
| 2576 | PacketFragments packet46 = { |
| 2577 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2578 | // 4-byte packet number) |
| 2579 | {"", |
| 2580 | {0xD3}}, |
| 2581 | // version tag |
| 2582 | {"", |
| 2583 | {QUIC_VERSION_BYTES}}, |
| 2584 | // connection_id length |
| 2585 | {"", |
| 2586 | {0x50}}, |
| 2587 | // connection_id |
| 2588 | {"", |
| 2589 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2590 | // packet number |
| 2591 | {"", |
| 2592 | {0x12, 0x34, 0x56, 0x78}}, |
| 2593 | // frame type (stream frame with fin) |
| 2594 | {"", |
| 2595 | {0xFE}}, |
| 2596 | // stream id |
| 2597 | {"Unable to read stream_id.", |
| 2598 | {0x02, 0x03, 0x04}}, |
| 2599 | // offset |
| 2600 | {"Unable to read offset.", |
| 2601 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2602 | 0x32, 0x10, 0x76, 0x54}}, |
| 2603 | {"Unable to read frame data.", |
| 2604 | { |
| 2605 | // data length |
| 2606 | 0x00, 0x0c, |
| 2607 | // data |
| 2608 | 'h', 'e', 'l', 'l', |
| 2609 | 'o', ' ', 'w', 'o', |
| 2610 | 'r', 'l', 'd', '!'}}, |
| 2611 | }; |
| 2612 | |
| 2613 | PacketFragments packet99 = { |
| 2614 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2615 | // 4-byte packet number) |
| 2616 | {"", |
| 2617 | {0xD3}}, |
| 2618 | // version tag |
| 2619 | {"", |
| 2620 | {QUIC_VERSION_BYTES}}, |
| 2621 | // connection_id length |
| 2622 | {"", |
| 2623 | {0x50}}, |
| 2624 | // connection_id |
| 2625 | {"", |
| 2626 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2627 | // long header packet length |
| 2628 | {"", |
| 2629 | {0x1E}}, |
| 2630 | // packet number |
| 2631 | {"", |
| 2632 | {0x12, 0x34, 0x56, 0x78}}, |
| 2633 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 2634 | {"", |
| 2635 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2636 | // stream id |
| 2637 | {"Long header payload length longer than packet.", |
| 2638 | {kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04}}, |
| 2639 | // offset |
| 2640 | {"Long header payload length longer than packet.", |
| 2641 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2642 | 0x32, 0x10, 0x76, 0x54}}, |
| 2643 | // data length |
| 2644 | {"Long header payload length longer than packet.", |
| 2645 | {kVarInt62OneByte + 0x0c}}, |
| 2646 | // data |
| 2647 | {"Long header payload length longer than packet.", |
| 2648 | { 'h', 'e', 'l', 'l', |
| 2649 | 'o', ' ', 'w', 'o', |
| 2650 | 'r', 'l', 'd', '!'}}, |
| 2651 | }; |
| 2652 | // clang-format on |
| 2653 | |
| 2654 | QuicVariableLengthIntegerLength retry_token_length_length = |
| 2655 | VARIABLE_LENGTH_INTEGER_LENGTH_0; |
| 2656 | size_t retry_token_length = 0; |
| 2657 | QuicVariableLengthIntegerLength length_length = |
| 2658 | QuicVersionHasLongHeaderLengths(framer_.transport_version()) |
| 2659 | ? VARIABLE_LENGTH_INTEGER_LENGTH_1 |
| 2660 | : VARIABLE_LENGTH_INTEGER_LENGTH_0; |
| 2661 | |
| 2662 | PacketFragments& fragments = |
| 2663 | framer_.transport_version() == QUIC_VERSION_99 |
| 2664 | ? packet99 |
| 2665 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2666 | ? packet46 |
| 2667 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2668 | : packet)); |
| 2669 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2670 | AssemblePacketFromFragments(fragments)); |
| 2671 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2672 | |
| 2673 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2674 | ASSERT_TRUE(visitor_.header_.get()); |
| 2675 | EXPECT_TRUE(CheckDecryption( |
| 2676 | *encrypted, kIncludeVersion, !kIncludeDiversificationNonce, |
| 2677 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID, |
| 2678 | retry_token_length_length, retry_token_length, length_length)); |
| 2679 | |
| 2680 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2681 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2682 | // Stream ID should be the last 3 bytes of kStreamId. |
| 2683 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2684 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2685 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2686 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2687 | |
| 2688 | CheckFramingBoundaries(fragments, |
| 2689 | framer_.transport_version() == QUIC_VERSION_99 |
| 2690 | ? QUIC_INVALID_PACKET_HEADER |
| 2691 | : QUIC_INVALID_STREAM_DATA); |
| 2692 | } |
| 2693 | |
| 2694 | TEST_P(QuicFramerTest, RejectPacket) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2695 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2696 | visitor_.accept_packet_ = false; |
| 2697 | |
| 2698 | // clang-format off |
| 2699 | unsigned char packet[] = { |
| 2700 | // public flags (8 byte connection_id) |
| 2701 | 0x28, |
| 2702 | // connection_id |
| 2703 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2704 | // packet number |
| 2705 | 0x12, 0x34, 0x56, 0x78, |
| 2706 | |
| 2707 | // frame type (stream frame with fin) |
| 2708 | 0xFF, |
| 2709 | // stream id |
| 2710 | 0x01, 0x02, 0x03, 0x04, |
| 2711 | // offset |
| 2712 | 0x3A, 0x98, 0xFE, 0xDC, |
| 2713 | 0x32, 0x10, 0x76, 0x54, |
| 2714 | // data length |
| 2715 | 0x00, 0x0c, |
| 2716 | // data |
| 2717 | 'h', 'e', 'l', 'l', |
| 2718 | 'o', ' ', 'w', 'o', |
| 2719 | 'r', 'l', 'd', '!', |
| 2720 | }; |
| 2721 | |
| 2722 | unsigned char packet44[] = { |
| 2723 | // type (short header, 4 byte packet number) |
| 2724 | 0x32, |
| 2725 | // connection_id |
| 2726 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2727 | // packet number |
| 2728 | 0x12, 0x34, 0x56, 0x78, |
| 2729 | |
| 2730 | // frame type (STREAM Frame with FIN, LEN, and OFFSET bits set) |
| 2731 | 0x10 | 0x01 | 0x02 | 0x04, |
| 2732 | // stream id |
| 2733 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 2734 | // offset |
| 2735 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2736 | 0x32, 0x10, 0x76, 0x54, |
| 2737 | // data length |
| 2738 | kVarInt62OneByte + 0x0c, |
| 2739 | // data |
| 2740 | 'h', 'e', 'l', 'l', |
| 2741 | 'o', ' ', 'w', 'o', |
| 2742 | 'r', 'l', 'd', '!', |
| 2743 | }; |
| 2744 | |
| 2745 | unsigned char packet46[] = { |
| 2746 | // type (short header, 4 byte packet number) |
| 2747 | 0x43, |
| 2748 | // connection_id |
| 2749 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2750 | // packet number |
| 2751 | 0x12, 0x34, 0x56, 0x78, |
| 2752 | |
| 2753 | // frame type (STREAM Frame with FIN, LEN, and OFFSET bits set) |
| 2754 | 0x10 | 0x01 | 0x02 | 0x04, |
| 2755 | // stream id |
| 2756 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 2757 | // offset |
| 2758 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2759 | 0x32, 0x10, 0x76, 0x54, |
| 2760 | // data length |
| 2761 | kVarInt62OneByte + 0x0c, |
| 2762 | // data |
| 2763 | 'h', 'e', 'l', 'l', |
| 2764 | 'o', ' ', 'w', 'o', |
| 2765 | 'r', 'l', 'd', '!', |
| 2766 | }; |
| 2767 | // clang-format on |
| 2768 | |
| 2769 | unsigned char* p = packet; |
| 2770 | if (framer_.transport_version() > QUIC_VERSION_44) { |
| 2771 | p = packet46; |
| 2772 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 2773 | p = packet44; |
| 2774 | } |
| 2775 | QuicEncryptedPacket encrypted(AsChars(p), |
| 2776 | framer_.transport_version() > QUIC_VERSION_43 |
| 2777 | ? QUIC_ARRAYSIZE(packet44) |
| 2778 | : QUIC_ARRAYSIZE(packet), |
| 2779 | false); |
| 2780 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 2781 | |
| 2782 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2783 | ASSERT_TRUE(visitor_.header_.get()); |
| 2784 | EXPECT_TRUE(CheckDecryption( |
| 2785 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2786 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2787 | |
| 2788 | ASSERT_EQ(0u, visitor_.stream_frames_.size()); |
| 2789 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2790 | } |
| 2791 | |
| 2792 | TEST_P(QuicFramerTest, RejectPublicHeader) { |
| 2793 | visitor_.accept_public_header_ = false; |
| 2794 | |
| 2795 | // clang-format off |
| 2796 | unsigned char packet[] = { |
| 2797 | // public flags (8 byte connection_id) |
| 2798 | 0x28, |
| 2799 | // connection_id |
| 2800 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2801 | }; |
| 2802 | |
| 2803 | unsigned char packet44[] = { |
| 2804 | // type (short header, 1 byte packet number) |
| 2805 | 0x30, |
| 2806 | // connection_id |
| 2807 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2808 | // packet number |
| 2809 | 0x01, |
| 2810 | }; |
| 2811 | |
| 2812 | unsigned char packet46[] = { |
| 2813 | // type (short header, 1 byte packet number) |
| 2814 | 0x40, |
| 2815 | // connection_id |
| 2816 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2817 | // packet number |
| 2818 | 0x01, |
| 2819 | }; |
| 2820 | // clang-format on |
| 2821 | |
| 2822 | QuicEncryptedPacket encrypted( |
| 2823 | framer_.transport_version() > QUIC_VERSION_44 |
| 2824 | ? AsChars(packet46) |
| 2825 | : (framer_.transport_version() > QUIC_VERSION_43 ? AsChars(packet44) |
| 2826 | : AsChars(packet)), |
| 2827 | framer_.transport_version() > QUIC_VERSION_44 |
| 2828 | ? QUIC_ARRAYSIZE(packet46) |
| 2829 | : (framer_.transport_version() > QUIC_VERSION_43 |
| 2830 | ? QUIC_ARRAYSIZE(packet44) |
| 2831 | : QUIC_ARRAYSIZE(packet)), |
| 2832 | false); |
| 2833 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 2834 | |
| 2835 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2836 | ASSERT_TRUE(visitor_.header_.get()); |
| 2837 | EXPECT_FALSE(visitor_.header_->packet_number.IsInitialized()); |
| 2838 | } |
| 2839 | |
| 2840 | TEST_P(QuicFramerTest, AckFrameOneAckBlock) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2841 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2842 | // clang-format off |
| 2843 | PacketFragments packet = { |
| 2844 | // public flags (8 byte connection_id) |
| 2845 | {"", |
| 2846 | {0x2C}}, |
| 2847 | // connection_id |
| 2848 | {"", |
| 2849 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2850 | // packet number |
| 2851 | {"", |
| 2852 | {0x12, 0x34, 0x56, 0x78}}, |
| 2853 | // frame type (ack frame) |
| 2854 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2855 | {"", |
| 2856 | {0x45}}, |
| 2857 | // largest acked |
| 2858 | {"Unable to read largest acked.", |
| 2859 | {0x12, 0x34}}, |
| 2860 | // Zero delta time. |
| 2861 | {"Unable to read ack delay time.", |
| 2862 | {0x00, 0x00}}, |
| 2863 | // first ack block length. |
| 2864 | {"Unable to read first ack block length.", |
| 2865 | {0x12, 0x34}}, |
| 2866 | // num timestamps. |
| 2867 | {"Unable to read num received packets.", |
| 2868 | {0x00}} |
| 2869 | }; |
| 2870 | |
| 2871 | PacketFragments packet44 = { |
| 2872 | // type (short packet, 4 byte packet number) |
| 2873 | {"", |
| 2874 | {0x32}}, |
| 2875 | // connection_id |
| 2876 | {"", |
| 2877 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2878 | // packet number |
| 2879 | {"", |
| 2880 | {0x12, 0x34, 0x56, 0x78}}, |
| 2881 | // frame type (ack frame) |
| 2882 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2883 | {"", |
| 2884 | {0x45}}, |
| 2885 | // largest acked |
| 2886 | {"Unable to read largest acked.", |
| 2887 | {0x12, 0x34}}, |
| 2888 | // Zero delta time. |
| 2889 | {"Unable to read ack delay time.", |
| 2890 | {0x00, 0x00}}, |
| 2891 | // first ack block length. |
| 2892 | {"Unable to read first ack block length.", |
| 2893 | {0x12, 0x34}}, |
| 2894 | // num timestamps. |
| 2895 | {"Unable to read num received packets.", |
| 2896 | {0x00}} |
| 2897 | }; |
| 2898 | |
| 2899 | PacketFragments packet46 = { |
| 2900 | // type (short packet, 4 byte packet number) |
| 2901 | {"", |
| 2902 | {0x43}}, |
| 2903 | // connection_id |
| 2904 | {"", |
| 2905 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2906 | // packet number |
| 2907 | {"", |
| 2908 | {0x12, 0x34, 0x56, 0x78}}, |
| 2909 | // frame type (ack frame) |
| 2910 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2911 | {"", |
| 2912 | {0x45}}, |
| 2913 | // largest acked |
| 2914 | {"Unable to read largest acked.", |
| 2915 | {0x12, 0x34}}, |
| 2916 | // Zero delta time. |
| 2917 | {"Unable to read ack delay time.", |
| 2918 | {0x00, 0x00}}, |
| 2919 | // first ack block length. |
| 2920 | {"Unable to read first ack block length.", |
| 2921 | {0x12, 0x34}}, |
| 2922 | // num timestamps. |
| 2923 | {"Unable to read num received packets.", |
| 2924 | {0x00}} |
| 2925 | }; |
| 2926 | |
| 2927 | PacketFragments packet99 = { |
| 2928 | // type (short packet, 4 byte packet number) |
| 2929 | {"", |
| 2930 | {0x43}}, |
| 2931 | // connection_id |
| 2932 | {"", |
| 2933 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2934 | // packet number |
| 2935 | {"", |
| 2936 | {0x12, 0x34, 0x56, 0x78}}, |
| 2937 | // frame type (IETF_ACK) |
| 2938 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2939 | // IETF-Quic ignores the bit-fields in the ack type, all of |
| 2940 | // that information is encoded elsewhere in the frame. |
| 2941 | {"", |
| 2942 | {0x02}}, |
| 2943 | // largest acked |
| 2944 | {"Unable to read largest acked.", |
| 2945 | {kVarInt62TwoBytes + 0x12, 0x34}}, |
| 2946 | // Zero delta time. |
| 2947 | {"Unable to read ack delay time.", |
| 2948 | {kVarInt62OneByte + 0x00}}, |
| 2949 | // Ack block count (0 -- no blocks after the first) |
| 2950 | {"Unable to read ack block count.", |
| 2951 | {kVarInt62OneByte + 0x00}}, |
| 2952 | // first ack block length - 1. |
| 2953 | // IETF Quic defines the ack block's value as the "number of |
| 2954 | // packets that preceed the largest packet number in the block" |
| 2955 | // which for the 1st ack block is the largest acked field, |
| 2956 | // above. This means that if we are acking just packet 0x1234 |
| 2957 | // then the 1st ack block will be 0. |
| 2958 | {"Unable to read first ack block length.", |
| 2959 | {kVarInt62TwoBytes + 0x12, 0x33}} |
| 2960 | }; |
| 2961 | // clang-format on |
| 2962 | |
| 2963 | PacketFragments& fragments = |
| 2964 | framer_.transport_version() == QUIC_VERSION_99 |
| 2965 | ? packet99 |
| 2966 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2967 | ? packet46 |
| 2968 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2969 | : packet)); |
| 2970 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2971 | AssemblePacketFromFragments(fragments)); |
| 2972 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2973 | |
| 2974 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2975 | ASSERT_TRUE(visitor_.header_.get()); |
| 2976 | EXPECT_TRUE(CheckDecryption( |
| 2977 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2978 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2979 | |
| 2980 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 2981 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 2982 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 2983 | EXPECT_EQ(kSmallLargestObserved, LargestAcked(frame)); |
| 2984 | ASSERT_EQ(4660u, frame.packets.NumPacketsSlow()); |
| 2985 | |
| 2986 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 2987 | } |
| 2988 | |
| 2989 | // This test checks that the ack frame processor correctly identifies |
| 2990 | // and handles the case where the first ack block is larger than the |
| 2991 | // largest_acked packet. |
| 2992 | TEST_P(QuicFramerTest, FirstAckFrameUnderflow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2993 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2994 | // clang-format off |
| 2995 | PacketFragments packet = { |
| 2996 | // public flags (8 byte connection_id) |
| 2997 | {"", |
| 2998 | {0x2C}}, |
| 2999 | // connection_id |
| 3000 | {"", |
| 3001 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3002 | // packet number |
| 3003 | {"", |
| 3004 | {0x12, 0x34, 0x56, 0x78}}, |
| 3005 | // frame type (ack frame) |
| 3006 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 3007 | {"", |
| 3008 | {0x45}}, |
| 3009 | // largest acked |
| 3010 | {"Unable to read largest acked.", |
| 3011 | {0x12, 0x34}}, |
| 3012 | // Zero delta time. |
| 3013 | {"Unable to read ack delay time.", |
| 3014 | {0x00, 0x00}}, |
| 3015 | // first ack block length. |
| 3016 | {"Unable to read first ack block length.", |
| 3017 | {0x88, 0x88}}, |
| 3018 | // num timestamps. |
| 3019 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 3020 | {0x00}} |
| 3021 | }; |
| 3022 | |
| 3023 | PacketFragments packet44 = { |
| 3024 | // type (short header, 4 byte packet number) |
| 3025 | {"", |
| 3026 | {0x32}}, |
| 3027 | // connection_id |
| 3028 | {"", |
| 3029 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3030 | // packet number |
| 3031 | {"", |
| 3032 | {0x12, 0x34, 0x56, 0x78}}, |
| 3033 | // frame type (ack frame) |
| 3034 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 3035 | {"", |
| 3036 | {0x45}}, |
| 3037 | // largest acked |
| 3038 | {"Unable to read largest acked.", |
| 3039 | {0x12, 0x34}}, |
| 3040 | // Zero delta time. |
| 3041 | {"Unable to read ack delay time.", |
| 3042 | {0x00, 0x00}}, |
| 3043 | // first ack block length. |
| 3044 | {"Unable to read first ack block length.", |
| 3045 | {0x88, 0x88}}, |
| 3046 | // num timestamps. |
| 3047 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 3048 | {0x00}} |
| 3049 | }; |
| 3050 | |
| 3051 | PacketFragments packet46 = { |
| 3052 | // type (short header, 4 byte packet number) |
| 3053 | {"", |
| 3054 | {0x43}}, |
| 3055 | // connection_id |
| 3056 | {"", |
| 3057 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3058 | // packet number |
| 3059 | {"", |
| 3060 | {0x12, 0x34, 0x56, 0x78}}, |
| 3061 | // frame type (ack frame) |
| 3062 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 3063 | {"", |
| 3064 | {0x45}}, |
| 3065 | // largest acked |
| 3066 | {"Unable to read largest acked.", |
| 3067 | {0x12, 0x34}}, |
| 3068 | // Zero delta time. |
| 3069 | {"Unable to read ack delay time.", |
| 3070 | {0x00, 0x00}}, |
| 3071 | // first ack block length. |
| 3072 | {"Unable to read first ack block length.", |
| 3073 | {0x88, 0x88}}, |
| 3074 | // num timestamps. |
| 3075 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 3076 | {0x00}} |
| 3077 | }; |
| 3078 | |
| 3079 | PacketFragments packet99 = { |
| 3080 | // type (short header, 4 byte packet number) |
| 3081 | {"", |
| 3082 | {0x43}}, |
| 3083 | // connection_id |
| 3084 | {"", |
| 3085 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3086 | // packet number |
| 3087 | {"", |
| 3088 | {0x12, 0x34, 0x56, 0x78}}, |
| 3089 | // frame type (IETF_ACK) |
| 3090 | {"", |
| 3091 | {0x02}}, |
| 3092 | // largest acked |
| 3093 | {"Unable to read largest acked.", |
| 3094 | {kVarInt62TwoBytes + 0x12, 0x34}}, |
| 3095 | // Zero delta time. |
| 3096 | {"Unable to read ack delay time.", |
| 3097 | {kVarInt62OneByte + 0x00}}, |
| 3098 | // Ack block count (0 -- no blocks after the first) |
| 3099 | {"Unable to read ack block count.", |
| 3100 | {kVarInt62OneByte + 0x00}}, |
| 3101 | // first ack block length. |
| 3102 | {"Unable to read first ack block length.", |
| 3103 | {kVarInt62TwoBytes + 0x28, 0x88}} |
| 3104 | }; |
| 3105 | // clang-format on |
| 3106 | |
| 3107 | PacketFragments& fragments = |
| 3108 | framer_.transport_version() == QUIC_VERSION_99 |
| 3109 | ? packet99 |
| 3110 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 3111 | ? packet46 |
| 3112 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 3113 | : packet)); |
| 3114 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3115 | AssemblePacketFromFragments(fragments)); |
| 3116 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3117 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3118 | } |
| 3119 | |
| 3120 | // This test checks that the ack frame processor correctly identifies |
| 3121 | // and handles the case where the third ack block's gap is larger than the |
| 3122 | // available space in the ack range. |
| 3123 | TEST_P(QuicFramerTest, ThirdAckBlockUnderflowGap) { |
| 3124 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 3125 | // for now, only v99 |
| 3126 | return; |
| 3127 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3128 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3129 | // clang-format off |
| 3130 | PacketFragments packet99 = { |
| 3131 | // type (short header, 4 byte packet number) |
| 3132 | {"", |
| 3133 | {0x43}}, |
| 3134 | // connection_id |
| 3135 | {"", |
| 3136 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3137 | // packet number |
| 3138 | {"", |
| 3139 | {0x12, 0x34, 0x56, 0x78}}, |
| 3140 | // frame type (IETF_ACK frame) |
| 3141 | {"", |
| 3142 | {0x02}}, |
| 3143 | // largest acked |
| 3144 | {"Unable to read largest acked.", |
| 3145 | {kVarInt62OneByte + 63}}, |
| 3146 | // Zero delta time. |
| 3147 | {"Unable to read ack delay time.", |
| 3148 | {kVarInt62OneByte + 0x00}}, |
| 3149 | // Ack block count (2 -- 2 blocks after the first) |
| 3150 | {"Unable to read ack block count.", |
| 3151 | {kVarInt62OneByte + 0x02}}, |
| 3152 | // first ack block length. |
| 3153 | {"Unable to read first ack block length.", |
| 3154 | {kVarInt62OneByte + 13}}, // Ack 14 packets, range 50..63 (inclusive) |
| 3155 | |
| 3156 | {"Unable to read gap block value.", |
| 3157 | {kVarInt62OneByte + 9}}, // Gap 10 packets, 40..49 (inclusive) |
| 3158 | {"Unable to read ack block value.", |
| 3159 | {kVarInt62OneByte + 9}}, // Ack 10 packets, 30..39 (inclusive) |
| 3160 | {"Unable to read gap block value.", |
| 3161 | {kVarInt62OneByte + 29}}, // A gap of 30 packets (0..29 inclusive) |
| 3162 | // should be too big, leaving no room |
| 3163 | // for the ack. |
| 3164 | {"Underflow with gap block length 30 previous ack block start is 30.", |
| 3165 | {kVarInt62OneByte + 10}}, // Don't care |
| 3166 | }; |
| 3167 | // clang-format on |
| 3168 | |
| 3169 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3170 | AssemblePacketFromFragments(packet99)); |
| 3171 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3172 | EXPECT_EQ( |
| 3173 | framer_.detailed_error(), |
| 3174 | "Underflow with gap block length 30 previous ack block start is 30."); |
| 3175 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3176 | } |
| 3177 | |
| 3178 | // This test checks that the ack frame processor correctly identifies |
| 3179 | // and handles the case where the third ack block's length is larger than the |
| 3180 | // available space in the ack range. |
| 3181 | TEST_P(QuicFramerTest, ThirdAckBlockUnderflowAck) { |
| 3182 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 3183 | // for now, only v99 |
| 3184 | return; |
| 3185 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3186 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3187 | // clang-format off |
| 3188 | PacketFragments packet99 = { |
| 3189 | // type (short header, 4 byte packet number) |
| 3190 | {"", |
| 3191 | {0x43}}, |
| 3192 | // connection_id |
| 3193 | {"", |
| 3194 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3195 | // packet number |
| 3196 | {"", |
| 3197 | {0x12, 0x34, 0x56, 0x78}}, |
| 3198 | // frame type (IETF_ACK frame) |
| 3199 | {"", |
| 3200 | {0x02}}, |
| 3201 | // largest acked |
| 3202 | {"Unable to read largest acked.", |
| 3203 | {kVarInt62OneByte + 63}}, |
| 3204 | // Zero delta time. |
| 3205 | {"Unable to read ack delay time.", |
| 3206 | {kVarInt62OneByte + 0x00}}, |
| 3207 | // Ack block count (2 -- 2 blocks after the first) |
| 3208 | {"Unable to read ack block count.", |
| 3209 | {kVarInt62OneByte + 0x02}}, |
| 3210 | // first ack block length. |
| 3211 | {"Unable to read first ack block length.", |
| 3212 | {kVarInt62OneByte + 13}}, // only 50 packet numbers "left" |
| 3213 | |
| 3214 | {"Unable to read gap block value.", |
| 3215 | {kVarInt62OneByte + 10}}, // Only 40 packet numbers left |
| 3216 | {"Unable to read ack block value.", |
| 3217 | {kVarInt62OneByte + 10}}, // only 30 packet numbers left. |
| 3218 | {"Unable to read gap block value.", |
| 3219 | {kVarInt62OneByte + 1}}, // Gap is OK, 29 packet numbers left |
| 3220 | {"Unable to read ack block value.", |
| 3221 | {kVarInt62OneByte + 30}}, // Use up all 30, should be an error |
| 3222 | }; |
| 3223 | // clang-format on |
| 3224 | |
| 3225 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3226 | AssemblePacketFromFragments(packet99)); |
| 3227 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3228 | EXPECT_EQ(framer_.detailed_error(), |
| 3229 | "Underflow with ack block length 31 latest ack block end is 25."); |
| 3230 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3231 | } |
| 3232 | |
| 3233 | // Tests a variety of ack block wrap scenarios. For example, if the |
| 3234 | // N-1th block causes packet 0 to be acked, then a gap would wrap |
| 3235 | // around to 0x3fffffff ffffffff... Make sure we detect this |
| 3236 | // condition. |
| 3237 | TEST_P(QuicFramerTest, AckBlockUnderflowGapWrap) { |
| 3238 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 3239 | // for now, only v99 |
| 3240 | return; |
| 3241 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3242 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3243 | // clang-format off |
| 3244 | PacketFragments packet99 = { |
| 3245 | // type (short header, 4 byte packet number) |
| 3246 | {"", |
| 3247 | {0x43}}, |
| 3248 | // connection_id |
| 3249 | {"", |
| 3250 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3251 | // packet number |
| 3252 | {"", |
| 3253 | {0x12, 0x34, 0x56, 0x78}}, |
| 3254 | // frame type (IETF_ACK frame) |
| 3255 | {"", |
| 3256 | {0x02}}, |
| 3257 | // largest acked |
| 3258 | {"Unable to read largest acked.", |
| 3259 | {kVarInt62OneByte + 10}}, |
| 3260 | // Zero delta time. |
| 3261 | {"Unable to read ack delay time.", |
| 3262 | {kVarInt62OneByte + 0x00}}, |
| 3263 | // Ack block count (1 -- 1 blocks after the first) |
| 3264 | {"Unable to read ack block count.", |
| 3265 | {kVarInt62OneByte + 1}}, |
| 3266 | // first ack block length. |
| 3267 | {"Unable to read first ack block length.", |
| 3268 | {kVarInt62OneByte + 9}}, // Ack packets 1..10 (inclusive) |
| 3269 | |
| 3270 | {"Unable to read gap block value.", |
| 3271 | {kVarInt62OneByte + 1}}, // Gap of 2 packets (-1...0), should wrap |
| 3272 | {"Underflow with gap block length 2 previous ack block start is 1.", |
| 3273 | {kVarInt62OneByte + 9}}, // irrelevant |
| 3274 | }; |
| 3275 | // clang-format on |
| 3276 | |
| 3277 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3278 | AssemblePacketFromFragments(packet99)); |
| 3279 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3280 | EXPECT_EQ(framer_.detailed_error(), |
| 3281 | "Underflow with gap block length 2 previous ack block start is 1."); |
| 3282 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3283 | } |
| 3284 | |
| 3285 | // As AckBlockUnderflowGapWrap, but in this test, it's the ack |
| 3286 | // component of the ack-block that causes the wrap, not the gap. |
| 3287 | TEST_P(QuicFramerTest, AckBlockUnderflowAckWrap) { |
| 3288 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 3289 | // for now, only v99 |
| 3290 | return; |
| 3291 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3292 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3293 | // clang-format off |
| 3294 | PacketFragments packet99 = { |
| 3295 | // type (short header, 4 byte packet number) |
| 3296 | {"", |
| 3297 | {0x43}}, |
| 3298 | // connection_id |
| 3299 | {"", |
| 3300 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3301 | // packet number |
| 3302 | {"", |
| 3303 | {0x12, 0x34, 0x56, 0x78}}, |
| 3304 | // frame type (IETF_ACK frame) |
| 3305 | {"", |
| 3306 | {0x02}}, |
| 3307 | // largest acked |
| 3308 | {"Unable to read largest acked.", |
| 3309 | {kVarInt62OneByte + 10}}, |
| 3310 | // Zero delta time. |
| 3311 | {"Unable to read ack delay time.", |
| 3312 | {kVarInt62OneByte + 0x00}}, |
| 3313 | // Ack block count (1 -- 1 blocks after the first) |
| 3314 | {"Unable to read ack block count.", |
| 3315 | {kVarInt62OneByte + 1}}, |
| 3316 | // first ack block length. |
| 3317 | {"Unable to read first ack block length.", |
| 3318 | {kVarInt62OneByte + 6}}, // Ack packets 4..10 (inclusive) |
| 3319 | |
| 3320 | {"Unable to read gap block value.", |
| 3321 | {kVarInt62OneByte + 1}}, // Gap of 2 packets (2..3) |
| 3322 | {"Unable to read ack block value.", |
| 3323 | {kVarInt62OneByte + 9}}, // Should wrap. |
| 3324 | }; |
| 3325 | // clang-format on |
| 3326 | |
| 3327 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3328 | AssemblePacketFromFragments(packet99)); |
| 3329 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3330 | EXPECT_EQ(framer_.detailed_error(), |
| 3331 | "Underflow with ack block length 10 latest ack block end is 1."); |
| 3332 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3333 | } |
| 3334 | |
| 3335 | // An ack block that acks the entire range, 1...0x3fffffffffffffff |
| 3336 | TEST_P(QuicFramerTest, AckBlockAcksEverything) { |
| 3337 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 3338 | // for now, only v99 |
| 3339 | return; |
| 3340 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3341 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3342 | // clang-format off |
| 3343 | PacketFragments packet99 = { |
| 3344 | // type (short header, 4 byte packet number) |
| 3345 | {"", |
| 3346 | {0x43}}, |
| 3347 | // connection_id |
| 3348 | {"", |
| 3349 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3350 | // packet number |
| 3351 | {"", |
| 3352 | {0x12, 0x34, 0x56, 0x78}}, |
| 3353 | // frame type (IETF_ACK frame) |
| 3354 | {"", |
| 3355 | {0x02}}, |
| 3356 | // largest acked |
| 3357 | {"Unable to read largest acked.", |
| 3358 | {kVarInt62EightBytes + 0x3f, 0xff, 0xff, 0xff, |
| 3359 | 0xff, 0xff, 0xff, 0xff}}, |
| 3360 | // Zero delta time. |
| 3361 | {"Unable to read ack delay time.", |
| 3362 | {kVarInt62OneByte + 0x00}}, |
| 3363 | // Ack block count No additional blocks |
| 3364 | {"Unable to read ack block count.", |
| 3365 | {kVarInt62OneByte + 0}}, |
| 3366 | // first ack block length. |
| 3367 | {"Unable to read first ack block length.", |
| 3368 | {kVarInt62EightBytes + 0x3f, 0xff, 0xff, 0xff, |
| 3369 | 0xff, 0xff, 0xff, 0xfe}}, |
| 3370 | }; |
| 3371 | // clang-format on |
| 3372 | |
| 3373 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3374 | AssemblePacketFromFragments(packet99)); |
| 3375 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3376 | EXPECT_EQ(1u, visitor_.ack_frames_.size()); |
| 3377 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3378 | EXPECT_EQ(1u, frame.packets.NumIntervals()); |
| 3379 | EXPECT_EQ(kLargestIetfLargestObserved, LargestAcked(frame)); |
| 3380 | EXPECT_EQ(kLargestIetfLargestObserved.ToUint64(), |
| 3381 | frame.packets.NumPacketsSlow()); |
| 3382 | } |
| 3383 | |
| 3384 | // This test looks for a malformed ack where |
| 3385 | // - There is a largest-acked value (that is, the frame is acking |
| 3386 | // something, |
| 3387 | // - But the length of the first ack block is 0 saying that no frames |
| 3388 | // are being acked with the largest-acked value or there are no |
| 3389 | // additional ack blocks. |
| 3390 | // |
| 3391 | TEST_P(QuicFramerTest, AckFrameFirstAckBlockLengthZero) { |
| 3392 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 3393 | // Not applicable to version 99 -- first ack block contains the |
| 3394 | // number of packets that preceed the largest_acked packet. |
| 3395 | // A value of 0 means no packets preceed --- that the block's |
| 3396 | // length is 1. Therefore the condition that this test checks can |
| 3397 | // not arise. |
| 3398 | return; |
| 3399 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 3400 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3401 | |
| 3402 | // clang-format off |
| 3403 | PacketFragments packet = { |
| 3404 | // public flags (8 byte connection_id) |
| 3405 | {"", |
| 3406 | { 0x2C }}, |
| 3407 | // connection_id |
| 3408 | {"", |
| 3409 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3410 | // packet number |
| 3411 | {"", |
| 3412 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3413 | |
| 3414 | // frame type (ack frame) |
| 3415 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3416 | {"", |
| 3417 | { 0x65 }}, |
| 3418 | // largest acked |
| 3419 | {"Unable to read largest acked.", |
| 3420 | { 0x12, 0x34 }}, |
| 3421 | // Zero delta time. |
| 3422 | {"Unable to read ack delay time.", |
| 3423 | { 0x00, 0x00 }}, |
| 3424 | // num ack blocks ranges. |
| 3425 | {"Unable to read num of ack blocks.", |
| 3426 | { 0x01 }}, |
| 3427 | // first ack block length. |
| 3428 | {"Unable to read first ack block length.", |
| 3429 | { 0x00, 0x00 }}, |
| 3430 | // gap to next block. |
| 3431 | { "First block length is zero.", |
| 3432 | { 0x01 }}, |
| 3433 | // ack block length. |
| 3434 | { "First block length is zero.", |
| 3435 | { 0x0e, 0xaf }}, |
| 3436 | // Number of timestamps. |
| 3437 | { "First block length is zero.", |
| 3438 | { 0x00 }}, |
| 3439 | }; |
| 3440 | |
| 3441 | PacketFragments packet44 = { |
| 3442 | // type (short header, 4 byte packet number) |
| 3443 | {"", |
| 3444 | { 0x32 }}, |
| 3445 | // connection_id |
| 3446 | {"", |
| 3447 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3448 | // packet number |
| 3449 | {"", |
| 3450 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3451 | |
| 3452 | // frame type (ack frame) |
| 3453 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3454 | {"", |
| 3455 | { 0x65 }}, |
| 3456 | // largest acked |
| 3457 | {"Unable to read largest acked.", |
| 3458 | { 0x12, 0x34 }}, |
| 3459 | // Zero delta time. |
| 3460 | {"Unable to read ack delay time.", |
| 3461 | { 0x00, 0x00 }}, |
| 3462 | // num ack blocks ranges. |
| 3463 | {"Unable to read num of ack blocks.", |
| 3464 | { 0x01 }}, |
| 3465 | // first ack block length. |
| 3466 | {"Unable to read first ack block length.", |
| 3467 | { 0x00, 0x00 }}, |
| 3468 | // gap to next block. |
| 3469 | { "First block length is zero.", |
| 3470 | { 0x01 }}, |
| 3471 | // ack block length. |
| 3472 | { "First block length is zero.", |
| 3473 | { 0x0e, 0xaf }}, |
| 3474 | // Number of timestamps. |
| 3475 | { "First block length is zero.", |
| 3476 | { 0x00 }}, |
| 3477 | }; |
| 3478 | |
| 3479 | PacketFragments packet46 = { |
| 3480 | // type (short header, 4 byte packet number) |
| 3481 | {"", |
| 3482 | { 0x43 }}, |
| 3483 | // connection_id |
| 3484 | {"", |
| 3485 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3486 | // packet number |
| 3487 | {"", |
| 3488 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3489 | |
| 3490 | // frame type (ack frame) |
| 3491 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3492 | {"", |
| 3493 | { 0x65 }}, |
| 3494 | // largest acked |
| 3495 | {"Unable to read largest acked.", |
| 3496 | { 0x12, 0x34 }}, |
| 3497 | // Zero delta time. |
| 3498 | {"Unable to read ack delay time.", |
| 3499 | { 0x00, 0x00 }}, |
| 3500 | // num ack blocks ranges. |
| 3501 | {"Unable to read num of ack blocks.", |
| 3502 | { 0x01 }}, |
| 3503 | // first ack block length. |
| 3504 | {"Unable to read first ack block length.", |
| 3505 | { 0x00, 0x00 }}, |
| 3506 | // gap to next block. |
| 3507 | { "First block length is zero.", |
| 3508 | { 0x01 }}, |
| 3509 | // ack block length. |
| 3510 | { "First block length is zero.", |
| 3511 | { 0x0e, 0xaf }}, |
| 3512 | // Number of timestamps. |
| 3513 | { "First block length is zero.", |
| 3514 | { 0x00 }}, |
| 3515 | }; |
| 3516 | |
| 3517 | // clang-format on |
| 3518 | PacketFragments& fragments = |
| 3519 | framer_.transport_version() > QUIC_VERSION_44 |
| 3520 | ? packet46 |
| 3521 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 3522 | |
| 3523 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3524 | AssemblePacketFromFragments(fragments)); |
| 3525 | |
| 3526 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3527 | EXPECT_EQ(QUIC_INVALID_ACK_DATA, framer_.error()); |
| 3528 | |
| 3529 | ASSERT_TRUE(visitor_.header_.get()); |
| 3530 | EXPECT_TRUE(CheckDecryption( |
| 3531 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3532 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3533 | |
| 3534 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3535 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3536 | |
| 3537 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3538 | } |
| 3539 | |
| 3540 | TEST_P(QuicFramerTest, AckFrameOneAckBlockMaxLength) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3541 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3542 | // clang-format off |
| 3543 | PacketFragments packet = { |
| 3544 | // public flags (8 byte connection_id) |
| 3545 | {"", |
| 3546 | {0x2C}}, |
| 3547 | // connection_id |
| 3548 | {"", |
| 3549 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3550 | // packet number |
| 3551 | {"", |
| 3552 | {0x12, 0x34, 0x56, 0x78}}, |
| 3553 | // frame type (ack frame) |
| 3554 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3555 | {"", |
| 3556 | {0x49}}, |
| 3557 | // largest acked |
| 3558 | {"Unable to read largest acked.", |
| 3559 | {0x12, 0x34, 0x56, 0x78}}, |
| 3560 | // Zero delta time. |
| 3561 | {"Unable to read ack delay time.", |
| 3562 | {0x00, 0x00}}, |
| 3563 | // first ack block length. |
| 3564 | {"Unable to read first ack block length.", |
| 3565 | {0x12, 0x34}}, |
| 3566 | // num timestamps. |
| 3567 | {"Unable to read num received packets.", |
| 3568 | {0x00}} |
| 3569 | }; |
| 3570 | |
| 3571 | PacketFragments packet44 = { |
| 3572 | // type (short header, 4 byte packet number) |
| 3573 | {"", |
| 3574 | {0x32}}, |
| 3575 | // connection_id |
| 3576 | {"", |
| 3577 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3578 | // packet number |
| 3579 | {"", |
| 3580 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3581 | // frame type (ack frame) |
| 3582 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3583 | {"", |
| 3584 | {0x49}}, |
| 3585 | // largest acked |
| 3586 | {"Unable to read largest acked.", |
| 3587 | {0x12, 0x34, 0x56, 0x78}}, |
| 3588 | // Zero delta time. |
| 3589 | {"Unable to read ack delay time.", |
| 3590 | {0x00, 0x00}}, |
| 3591 | // first ack block length. |
| 3592 | {"Unable to read first ack block length.", |
| 3593 | {0x12, 0x34}}, |
| 3594 | // num timestamps. |
| 3595 | {"Unable to read num received packets.", |
| 3596 | {0x00}} |
| 3597 | }; |
| 3598 | |
| 3599 | PacketFragments packet46 = { |
| 3600 | // type (short header, 4 byte packet number) |
| 3601 | {"", |
| 3602 | {0x43}}, |
| 3603 | // connection_id |
| 3604 | {"", |
| 3605 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3606 | // packet number |
| 3607 | {"", |
| 3608 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3609 | // frame type (ack frame) |
| 3610 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3611 | {"", |
| 3612 | {0x49}}, |
| 3613 | // largest acked |
| 3614 | {"Unable to read largest acked.", |
| 3615 | {0x12, 0x34, 0x56, 0x78}}, |
| 3616 | // Zero delta time. |
| 3617 | {"Unable to read ack delay time.", |
| 3618 | {0x00, 0x00}}, |
| 3619 | // first ack block length. |
| 3620 | {"Unable to read first ack block length.", |
| 3621 | {0x12, 0x34}}, |
| 3622 | // num timestamps. |
| 3623 | {"Unable to read num received packets.", |
| 3624 | {0x00}} |
| 3625 | }; |
| 3626 | |
| 3627 | PacketFragments packet99 = { |
| 3628 | // type (short header, 4 byte packet number) |
| 3629 | {"", |
| 3630 | {0x43}}, |
| 3631 | // connection_id |
| 3632 | {"", |
| 3633 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3634 | // packet number |
| 3635 | {"", |
| 3636 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3637 | // frame type (IETF_ACK frame) |
| 3638 | {"", |
| 3639 | {0x02}}, |
| 3640 | // largest acked |
| 3641 | {"Unable to read largest acked.", |
| 3642 | {kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78}}, |
| 3643 | // Zero delta time. |
| 3644 | {"Unable to read ack delay time.", |
| 3645 | {kVarInt62OneByte + 0x00}}, |
| 3646 | // Number of ack blocks after first |
| 3647 | {"Unable to read ack block count.", |
| 3648 | {kVarInt62OneByte + 0x00}}, |
| 3649 | // first ack block length. |
| 3650 | {"Unable to read first ack block length.", |
| 3651 | {kVarInt62TwoBytes + 0x12, 0x33}} |
| 3652 | }; |
| 3653 | // clang-format on |
| 3654 | |
| 3655 | PacketFragments& fragments = |
| 3656 | framer_.transport_version() == QUIC_VERSION_99 |
| 3657 | ? packet99 |
| 3658 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 3659 | ? packet46 |
| 3660 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 3661 | : packet)); |
| 3662 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3663 | AssemblePacketFromFragments(fragments)); |
| 3664 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3665 | |
| 3666 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 3667 | ASSERT_TRUE(visitor_.header_.get()); |
| 3668 | EXPECT_TRUE(CheckDecryption( |
| 3669 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3670 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3671 | |
| 3672 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3673 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3674 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3675 | EXPECT_EQ(kPacketNumber, LargestAcked(frame)); |
| 3676 | ASSERT_EQ(4660u, frame.packets.NumPacketsSlow()); |
| 3677 | |
| 3678 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3679 | } |
| 3680 | |
| 3681 | // Tests ability to handle multiple ackblocks after the first ack |
| 3682 | // block. Non-version-99 tests include multiple timestamps as well. |
| 3683 | TEST_P(QuicFramerTest, AckFrameTwoTimeStampsMultipleAckBlocks) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3684 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3685 | // clang-format off |
| 3686 | PacketFragments packet = { |
| 3687 | // public flags (8 byte connection_id) |
| 3688 | {"", |
| 3689 | { 0x2C }}, |
| 3690 | // connection_id |
| 3691 | {"", |
| 3692 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3693 | // packet number |
| 3694 | {"", |
| 3695 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3696 | |
| 3697 | // frame type (ack frame) |
| 3698 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3699 | {"", |
| 3700 | { 0x65 }}, |
| 3701 | // largest acked |
| 3702 | {"Unable to read largest acked.", |
| 3703 | { 0x12, 0x34 }}, |
| 3704 | // Zero delta time. |
| 3705 | {"Unable to read ack delay time.", |
| 3706 | { 0x00, 0x00 }}, |
| 3707 | // num ack blocks ranges. |
| 3708 | {"Unable to read num of ack blocks.", |
| 3709 | { 0x04 }}, |
| 3710 | // first ack block length. |
| 3711 | {"Unable to read first ack block length.", |
| 3712 | { 0x00, 0x01 }}, |
| 3713 | // gap to next block. |
| 3714 | { "Unable to read gap to next ack block.", |
| 3715 | { 0x01 }}, |
| 3716 | // ack block length. |
| 3717 | { "Unable to ack block length.", |
| 3718 | { 0x0e, 0xaf }}, |
| 3719 | // gap to next block. |
| 3720 | { "Unable to read gap to next ack block.", |
| 3721 | { 0xff }}, |
| 3722 | // ack block length. |
| 3723 | { "Unable to ack block length.", |
| 3724 | { 0x00, 0x00 }}, |
| 3725 | // gap to next block. |
| 3726 | { "Unable to read gap to next ack block.", |
| 3727 | { 0x91 }}, |
| 3728 | // ack block length. |
| 3729 | { "Unable to ack block length.", |
| 3730 | { 0x01, 0xea }}, |
| 3731 | // gap to next block. |
| 3732 | { "Unable to read gap to next ack block.", |
| 3733 | { 0x05 }}, |
| 3734 | // ack block length. |
| 3735 | { "Unable to ack block length.", |
| 3736 | { 0x00, 0x04 }}, |
| 3737 | // Number of timestamps. |
| 3738 | { "Unable to read num received packets.", |
| 3739 | { 0x02 }}, |
| 3740 | // Delta from largest observed. |
| 3741 | { "Unable to read sequence delta in received packets.", |
| 3742 | { 0x01 }}, |
| 3743 | // Delta time. |
| 3744 | { "Unable to read time delta in received packets.", |
| 3745 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3746 | // Delta from largest observed. |
| 3747 | { "Unable to read sequence delta in received packets.", |
| 3748 | { 0x02 }}, |
| 3749 | // Delta time. |
| 3750 | { "Unable to read incremental time delta in received packets.", |
| 3751 | { 0x32, 0x10 }}, |
| 3752 | }; |
| 3753 | |
| 3754 | PacketFragments packet44 = { |
| 3755 | // type (short header, 4 byte packet number) |
| 3756 | {"", |
| 3757 | { 0x32 }}, |
| 3758 | // connection_id |
| 3759 | {"", |
| 3760 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3761 | // packet number |
| 3762 | {"", |
| 3763 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3764 | |
| 3765 | // frame type (ack frame) |
| 3766 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3767 | {"", |
| 3768 | { 0x65 }}, |
| 3769 | // largest acked |
| 3770 | {"Unable to read largest acked.", |
| 3771 | { 0x12, 0x34 }}, |
| 3772 | // Zero delta time. |
| 3773 | {"Unable to read ack delay time.", |
| 3774 | { 0x00, 0x00 }}, |
| 3775 | // num ack blocks ranges. |
| 3776 | {"Unable to read num of ack blocks.", |
| 3777 | { 0x04 }}, |
| 3778 | // first ack block length. |
| 3779 | {"Unable to read first ack block length.", |
| 3780 | { 0x00, 0x01 }}, |
| 3781 | // gap to next block. |
| 3782 | { "Unable to read gap to next ack block.", |
| 3783 | { 0x01 }}, |
| 3784 | // ack block length. |
| 3785 | { "Unable to ack block length.", |
| 3786 | { 0x0e, 0xaf }}, |
| 3787 | // gap to next block. |
| 3788 | { "Unable to read gap to next ack block.", |
| 3789 | { 0xff }}, |
| 3790 | // ack block length. |
| 3791 | { "Unable to ack block length.", |
| 3792 | { 0x00, 0x00 }}, |
| 3793 | // gap to next block. |
| 3794 | { "Unable to read gap to next ack block.", |
| 3795 | { 0x91 }}, |
| 3796 | // ack block length. |
| 3797 | { "Unable to ack block length.", |
| 3798 | { 0x01, 0xea }}, |
| 3799 | // gap to next block. |
| 3800 | { "Unable to read gap to next ack block.", |
| 3801 | { 0x05 }}, |
| 3802 | // ack block length. |
| 3803 | { "Unable to ack block length.", |
| 3804 | { 0x00, 0x04 }}, |
| 3805 | // Number of timestamps. |
| 3806 | { "Unable to read num received packets.", |
| 3807 | { 0x02 }}, |
| 3808 | // Delta from largest observed. |
| 3809 | { "Unable to read sequence delta in received packets.", |
| 3810 | { 0x01 }}, |
| 3811 | // Delta time. |
| 3812 | { "Unable to read time delta in received packets.", |
| 3813 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3814 | // Delta from largest observed. |
| 3815 | { "Unable to read sequence delta in received packets.", |
| 3816 | { 0x02 }}, |
| 3817 | // Delta time. |
| 3818 | { "Unable to read incremental time delta in received packets.", |
| 3819 | { 0x32, 0x10 }}, |
| 3820 | }; |
| 3821 | |
| 3822 | PacketFragments packet46 = { |
| 3823 | // type (short header, 4 byte packet number) |
| 3824 | {"", |
| 3825 | { 0x43 }}, |
| 3826 | // connection_id |
| 3827 | {"", |
| 3828 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3829 | // packet number |
| 3830 | {"", |
| 3831 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3832 | |
| 3833 | // frame type (ack frame) |
| 3834 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3835 | {"", |
| 3836 | { 0x65 }}, |
| 3837 | // largest acked |
| 3838 | {"Unable to read largest acked.", |
| 3839 | { 0x12, 0x34 }}, |
| 3840 | // Zero delta time. |
| 3841 | {"Unable to read ack delay time.", |
| 3842 | { 0x00, 0x00 }}, |
| 3843 | // num ack blocks ranges. |
| 3844 | {"Unable to read num of ack blocks.", |
| 3845 | { 0x04 }}, |
| 3846 | // first ack block length. |
| 3847 | {"Unable to read first ack block length.", |
| 3848 | { 0x00, 0x01 }}, |
| 3849 | // gap to next block. |
| 3850 | { "Unable to read gap to next ack block.", |
| 3851 | { 0x01 }}, |
| 3852 | // ack block length. |
| 3853 | { "Unable to ack block length.", |
| 3854 | { 0x0e, 0xaf }}, |
| 3855 | // gap to next block. |
| 3856 | { "Unable to read gap to next ack block.", |
| 3857 | { 0xff }}, |
| 3858 | // ack block length. |
| 3859 | { "Unable to ack block length.", |
| 3860 | { 0x00, 0x00 }}, |
| 3861 | // gap to next block. |
| 3862 | { "Unable to read gap to next ack block.", |
| 3863 | { 0x91 }}, |
| 3864 | // ack block length. |
| 3865 | { "Unable to ack block length.", |
| 3866 | { 0x01, 0xea }}, |
| 3867 | // gap to next block. |
| 3868 | { "Unable to read gap to next ack block.", |
| 3869 | { 0x05 }}, |
| 3870 | // ack block length. |
| 3871 | { "Unable to ack block length.", |
| 3872 | { 0x00, 0x04 }}, |
| 3873 | // Number of timestamps. |
| 3874 | { "Unable to read num received packets.", |
| 3875 | { 0x02 }}, |
| 3876 | // Delta from largest observed. |
| 3877 | { "Unable to read sequence delta in received packets.", |
| 3878 | { 0x01 }}, |
| 3879 | // Delta time. |
| 3880 | { "Unable to read time delta in received packets.", |
| 3881 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3882 | // Delta from largest observed. |
| 3883 | { "Unable to read sequence delta in received packets.", |
| 3884 | { 0x02 }}, |
| 3885 | // Delta time. |
| 3886 | { "Unable to read incremental time delta in received packets.", |
| 3887 | { 0x32, 0x10 }}, |
| 3888 | }; |
| 3889 | |
| 3890 | PacketFragments packet99 = { |
| 3891 | // type (short header, 4 byte packet number) |
| 3892 | {"", |
| 3893 | { 0x43 }}, |
| 3894 | // connection_id |
| 3895 | {"", |
| 3896 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3897 | // packet number |
| 3898 | {"", |
| 3899 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3900 | |
| 3901 | // frame type (IETF_ACK frame) |
| 3902 | {"", |
| 3903 | { 0x02 }}, |
| 3904 | // largest acked |
| 3905 | {"Unable to read largest acked.", |
| 3906 | { kVarInt62TwoBytes + 0x12, 0x34 }}, // = 4660 |
| 3907 | // Zero delta time. |
| 3908 | {"Unable to read ack delay time.", |
| 3909 | { kVarInt62OneByte + 0x00 }}, |
| 3910 | // number of additional ack blocks |
| 3911 | {"Unable to read ack block count.", |
| 3912 | { kVarInt62OneByte + 0x03 }}, |
| 3913 | // first ack block length. |
| 3914 | {"Unable to read first ack block length.", |
| 3915 | { kVarInt62OneByte + 0x00 }}, // 1st block length = 1 |
| 3916 | |
| 3917 | // Additional ACK Block #1 |
| 3918 | // gap to next block. |
| 3919 | { "Unable to read gap block value.", |
| 3920 | { kVarInt62OneByte + 0x00 }}, // gap of 1 packet |
| 3921 | // ack block length. |
| 3922 | { "Unable to read ack block value.", |
| 3923 | { kVarInt62TwoBytes + 0x0e, 0xae }}, // 3759 |
| 3924 | |
| 3925 | // pre-version-99 test includes an ack block of 0 length. this |
| 3926 | // can not happen in version 99. ergo the second block is not |
| 3927 | // present in the v99 test and the gap length of the next block |
| 3928 | // is the sum of the two gaps in the pre-version-99 tests. |
| 3929 | // Additional ACK Block #2 |
| 3930 | // gap to next block. |
| 3931 | { "Unable to read gap block value.", |
| 3932 | { kVarInt62TwoBytes + 0x01, 0x8f }}, // Gap is 400 (0x190) pkts |
| 3933 | // ack block length. |
| 3934 | { "Unable to read ack block value.", |
| 3935 | { kVarInt62TwoBytes + 0x01, 0xe9 }}, // block is 389 (x1ea) pkts |
| 3936 | |
| 3937 | // Additional ACK Block #3 |
| 3938 | // gap to next block. |
| 3939 | { "Unable to read gap block value.", |
| 3940 | { kVarInt62OneByte + 0x04 }}, // Gap is 5 packets. |
| 3941 | // ack block length. |
| 3942 | { "Unable to read ack block value.", |
| 3943 | { kVarInt62OneByte + 0x03 }}, // block is 3 packets. |
| 3944 | }; |
| 3945 | |
| 3946 | // clang-format on |
| 3947 | PacketFragments& fragments = |
| 3948 | framer_.transport_version() == QUIC_VERSION_99 |
| 3949 | ? packet99 |
| 3950 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 3951 | ? packet46 |
| 3952 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 3953 | : packet)); |
| 3954 | |
| 3955 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3956 | AssemblePacketFromFragments(fragments)); |
| 3957 | |
| 3958 | framer_.set_process_timestamps(true); |
| 3959 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3960 | |
| 3961 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 3962 | ASSERT_TRUE(visitor_.header_.get()); |
| 3963 | EXPECT_TRUE(CheckDecryption( |
| 3964 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3965 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3966 | |
| 3967 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3968 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3969 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3970 | EXPECT_EQ(kSmallLargestObserved, LargestAcked(frame)); |
| 3971 | ASSERT_EQ(4254u, frame.packets.NumPacketsSlow()); |
| 3972 | EXPECT_EQ(4u, frame.packets.NumIntervals()); |
| 3973 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 3974 | EXPECT_EQ(0u, frame.received_packet_times.size()); |
| 3975 | } else { |
| 3976 | EXPECT_EQ(2u, frame.received_packet_times.size()); |
| 3977 | } |
| 3978 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3979 | } |
| 3980 | |
| 3981 | TEST_P(QuicFramerTest, AckFrameTimeStampDeltaTooHigh) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 3982 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3983 | // clang-format off |
| 3984 | unsigned char packet[] = { |
| 3985 | // public flags (8 byte connection_id) |
| 3986 | 0x28, |
| 3987 | // connection_id |
| 3988 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3989 | // packet number |
| 3990 | 0x12, 0x34, 0x56, 0x78, |
| 3991 | |
| 3992 | // frame type (ack frame) |
| 3993 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3994 | 0x40, |
| 3995 | // largest acked |
| 3996 | 0x01, |
| 3997 | // Zero delta time. |
| 3998 | 0x00, 0x00, |
| 3999 | // first ack block length. |
| 4000 | 0x01, |
| 4001 | // num timestamps. |
| 4002 | 0x01, |
| 4003 | // Delta from largest observed. |
| 4004 | 0x01, |
| 4005 | // Delta time. |
| 4006 | 0x10, 0x32, 0x54, 0x76, |
| 4007 | }; |
| 4008 | |
| 4009 | unsigned char packet44[] = { |
| 4010 | // type (short header, 4 byte packet number) |
| 4011 | 0x32, |
| 4012 | // connection_id |
| 4013 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4014 | // packet number |
| 4015 | 0x12, 0x34, 0x56, 0x78, |
| 4016 | |
| 4017 | // frame type (ack frame) |
| 4018 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 4019 | 0x40, |
| 4020 | // largest acked |
| 4021 | 0x01, |
| 4022 | // Zero delta time. |
| 4023 | 0x00, 0x00, |
| 4024 | // first ack block length. |
| 4025 | 0x01, |
| 4026 | // num timestamps. |
| 4027 | 0x01, |
| 4028 | // Delta from largest observed. |
| 4029 | 0x01, |
| 4030 | // Delta time. |
| 4031 | 0x10, 0x32, 0x54, 0x76, |
| 4032 | }; |
| 4033 | |
| 4034 | unsigned char packet46[] = { |
| 4035 | // type (short header, 4 byte packet number) |
| 4036 | 0x43, |
| 4037 | // connection_id |
| 4038 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4039 | // packet number |
| 4040 | 0x12, 0x34, 0x56, 0x78, |
| 4041 | |
| 4042 | // frame type (ack frame) |
| 4043 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 4044 | 0x40, |
| 4045 | // largest acked |
| 4046 | 0x01, |
| 4047 | // Zero delta time. |
| 4048 | 0x00, 0x00, |
| 4049 | // first ack block length. |
| 4050 | 0x01, |
| 4051 | // num timestamps. |
| 4052 | 0x01, |
| 4053 | // Delta from largest observed. |
| 4054 | 0x01, |
| 4055 | // Delta time. |
| 4056 | 0x10, 0x32, 0x54, 0x76, |
| 4057 | }; |
| 4058 | // clang-format on |
| 4059 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4060 | return; |
| 4061 | } |
| 4062 | QuicEncryptedPacket encrypted( |
| 4063 | AsChars(framer_.transport_version() > QUIC_VERSION_44 |
| 4064 | ? packet46 |
| 4065 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4066 | : packet)), |
| 4067 | QUIC_ARRAYSIZE(packet), false); |
| 4068 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 4069 | EXPECT_TRUE(QuicTextUtils::StartsWith( |
| 4070 | framer_.detailed_error(), "delta_from_largest_observed too high")); |
| 4071 | } |
| 4072 | |
| 4073 | TEST_P(QuicFramerTest, AckFrameTimeStampSecondDeltaTooHigh) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4074 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4075 | // clang-format off |
| 4076 | unsigned char packet[] = { |
| 4077 | // public flags (8 byte connection_id) |
| 4078 | 0x28, |
| 4079 | // connection_id |
| 4080 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4081 | // packet number |
| 4082 | 0x12, 0x34, 0x56, 0x78, |
| 4083 | |
| 4084 | // frame type (ack frame) |
| 4085 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 4086 | 0x40, |
| 4087 | // largest acked |
| 4088 | 0x03, |
| 4089 | // Zero delta time. |
| 4090 | 0x00, 0x00, |
| 4091 | // first ack block length. |
| 4092 | 0x03, |
| 4093 | // num timestamps. |
| 4094 | 0x02, |
| 4095 | // Delta from largest observed. |
| 4096 | 0x01, |
| 4097 | // Delta time. |
| 4098 | 0x10, 0x32, 0x54, 0x76, |
| 4099 | // Delta from largest observed. |
| 4100 | 0x03, |
| 4101 | // Delta time. |
| 4102 | 0x10, 0x32, |
| 4103 | }; |
| 4104 | |
| 4105 | unsigned char packet44[] = { |
| 4106 | // type (short header, 4 byte packet number) |
| 4107 | 0x32, |
| 4108 | // connection_id |
| 4109 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4110 | // packet number |
| 4111 | 0x12, 0x34, 0x56, 0x78, |
| 4112 | |
| 4113 | // frame type (ack frame) |
| 4114 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 4115 | 0x40, |
| 4116 | // largest acked |
| 4117 | 0x03, |
| 4118 | // Zero delta time. |
| 4119 | 0x00, 0x00, |
| 4120 | // first ack block length. |
| 4121 | 0x03, |
| 4122 | // num timestamps. |
| 4123 | 0x02, |
| 4124 | // Delta from largest observed. |
| 4125 | 0x01, |
| 4126 | // Delta time. |
| 4127 | 0x10, 0x32, 0x54, 0x76, |
| 4128 | // Delta from largest observed. |
| 4129 | 0x03, |
| 4130 | // Delta time. |
| 4131 | 0x10, 0x32, |
| 4132 | }; |
| 4133 | |
| 4134 | unsigned char packet46[] = { |
| 4135 | // type (short header, 4 byte packet number) |
| 4136 | 0x43, |
| 4137 | // connection_id |
| 4138 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4139 | // packet number |
| 4140 | 0x12, 0x34, 0x56, 0x78, |
| 4141 | |
| 4142 | // frame type (ack frame) |
| 4143 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 4144 | 0x40, |
| 4145 | // largest acked |
| 4146 | 0x03, |
| 4147 | // Zero delta time. |
| 4148 | 0x00, 0x00, |
| 4149 | // first ack block length. |
| 4150 | 0x03, |
| 4151 | // num timestamps. |
| 4152 | 0x02, |
| 4153 | // Delta from largest observed. |
| 4154 | 0x01, |
| 4155 | // Delta time. |
| 4156 | 0x10, 0x32, 0x54, 0x76, |
| 4157 | // Delta from largest observed. |
| 4158 | 0x03, |
| 4159 | // Delta time. |
| 4160 | 0x10, 0x32, |
| 4161 | }; |
| 4162 | // clang-format on |
| 4163 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4164 | return; |
| 4165 | } |
| 4166 | QuicEncryptedPacket encrypted( |
| 4167 | AsChars(framer_.transport_version() > QUIC_VERSION_44 |
| 4168 | ? packet46 |
| 4169 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4170 | : packet)), |
| 4171 | QUIC_ARRAYSIZE(packet), false); |
| 4172 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 4173 | EXPECT_TRUE(QuicTextUtils::StartsWith( |
| 4174 | framer_.detailed_error(), "delta_from_largest_observed too high")); |
| 4175 | } |
| 4176 | |
| 4177 | TEST_P(QuicFramerTest, NewStopWaitingFrame) { |
| 4178 | if (version_.transport_version == QUIC_VERSION_99) { |
| 4179 | return; |
| 4180 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4181 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4182 | // clang-format off |
| 4183 | PacketFragments packet = { |
| 4184 | // public flags (8 byte connection_id) |
| 4185 | {"", |
| 4186 | {0x2C}}, |
| 4187 | // connection_id |
| 4188 | {"", |
| 4189 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4190 | // packet number |
| 4191 | {"", |
| 4192 | {0x12, 0x34, 0x56, 0x78}}, |
| 4193 | // frame type (stop waiting frame) |
| 4194 | {"", |
| 4195 | {0x06}}, |
| 4196 | // least packet number awaiting an ack, delta from packet number. |
| 4197 | {"Unable to read least unacked delta.", |
| 4198 | {0x00, 0x00, 0x00, 0x08}} |
| 4199 | }; |
| 4200 | |
| 4201 | PacketFragments packet44 = { |
| 4202 | // type (short header, 4 byte packet number) |
| 4203 | {"", |
| 4204 | {0x32}}, |
| 4205 | // connection_id |
| 4206 | {"", |
| 4207 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4208 | // packet number |
| 4209 | {"", |
| 4210 | {0x12, 0x34, 0x56, 0x78}}, |
| 4211 | // frame type (stop waiting frame) |
| 4212 | {"", |
| 4213 | {0x06}}, |
| 4214 | // least packet number awaiting an ack, delta from packet number. |
| 4215 | {"Unable to read least unacked delta.", |
| 4216 | {0x00, 0x00, 0x00, 0x08}} |
| 4217 | }; |
| 4218 | |
| 4219 | PacketFragments packet46 = { |
| 4220 | // type (short header, 4 byte packet number) |
| 4221 | {"", |
| 4222 | {0x43}}, |
| 4223 | // connection_id |
| 4224 | {"", |
| 4225 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4226 | // packet number |
| 4227 | {"", |
| 4228 | {0x12, 0x34, 0x56, 0x78}}, |
| 4229 | // frame type (stop waiting frame) |
| 4230 | {"", |
| 4231 | {0x06}}, |
| 4232 | // least packet number awaiting an ack, delta from packet number. |
| 4233 | {"Unable to read least unacked delta.", |
| 4234 | {0x00, 0x00, 0x00, 0x08}} |
| 4235 | }; |
| 4236 | // clang-format on |
| 4237 | |
| 4238 | PacketFragments& fragments = |
| 4239 | framer_.transport_version() > QUIC_VERSION_44 |
| 4240 | ? packet46 |
| 4241 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 4242 | |
| 4243 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4244 | AssemblePacketFromFragments(fragments)); |
ianswett | 97b690b | 2019-05-02 15:12:43 -0700 | [diff] [blame] | 4245 | if (GetQuicReloadableFlag(quic_do_not_accept_stop_waiting) && |
| 4246 | version_.transport_version >= QUIC_VERSION_44) { |
| 4247 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 4248 | EXPECT_EQ(QUIC_INVALID_STOP_WAITING_DATA, framer_.error()); |
| 4249 | EXPECT_EQ("STOP WAITING not supported in version 44+.", |
| 4250 | framer_.detailed_error()); |
| 4251 | return; |
| 4252 | } |
| 4253 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4254 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4255 | |
| 4256 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4257 | ASSERT_TRUE(visitor_.header_.get()); |
| 4258 | EXPECT_TRUE(CheckDecryption( |
| 4259 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4260 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4261 | |
| 4262 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4263 | ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size()); |
| 4264 | const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0]; |
| 4265 | EXPECT_EQ(kLeastUnacked, frame.least_unacked); |
| 4266 | |
| 4267 | CheckFramingBoundaries(fragments, QUIC_INVALID_STOP_WAITING_DATA); |
| 4268 | } |
| 4269 | |
| 4270 | TEST_P(QuicFramerTest, InvalidNewStopWaitingFrame) { |
ianswett | 97b690b | 2019-05-02 15:12:43 -0700 | [diff] [blame] | 4271 | if (version_.transport_version == QUIC_VERSION_99 || |
| 4272 | (GetQuicReloadableFlag(quic_do_not_accept_stop_waiting) && |
| 4273 | version_.transport_version >= QUIC_VERSION_44)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4274 | return; |
| 4275 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4276 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4277 | // clang-format off |
| 4278 | unsigned char packet[] = { |
| 4279 | // public flags (8 byte connection_id) |
| 4280 | 0x2C, |
| 4281 | // connection_id |
| 4282 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4283 | // packet number |
| 4284 | 0x12, 0x34, 0x56, 0x78, |
| 4285 | // frame type (stop waiting frame) |
| 4286 | 0x06, |
| 4287 | // least packet number awaiting an ack, delta from packet number. |
| 4288 | 0x13, 0x34, 0x56, 0x78, |
| 4289 | 0x9A, 0xA8, |
| 4290 | }; |
| 4291 | |
| 4292 | unsigned char packet44[] = { |
| 4293 | // type (short header, 4 byte packet number) |
| 4294 | 0x32, |
| 4295 | // connection_id |
| 4296 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4297 | // packet number |
| 4298 | 0x12, 0x34, 0x56, 0x78, |
| 4299 | // frame type (stop waiting frame) |
| 4300 | 0x06, |
| 4301 | // least packet number awaiting an ack, delta from packet number. |
| 4302 | 0x57, 0x78, 0x9A, 0xA8, |
| 4303 | }; |
| 4304 | |
| 4305 | unsigned char packet46[] = { |
| 4306 | // type (short header, 4 byte packet number) |
| 4307 | 0x43, |
| 4308 | // connection_id |
| 4309 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4310 | // packet number |
| 4311 | 0x12, 0x34, 0x56, 0x78, |
| 4312 | // frame type (stop waiting frame) |
| 4313 | 0x06, |
| 4314 | // least packet number awaiting an ack, delta from packet number. |
| 4315 | 0x57, 0x78, 0x9A, 0xA8, |
| 4316 | }; |
| 4317 | // clang-format on |
| 4318 | |
| 4319 | QuicEncryptedPacket encrypted( |
| 4320 | AsChars(framer_.transport_version() > QUIC_VERSION_44 |
| 4321 | ? packet46 |
| 4322 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4323 | : packet)), |
| 4324 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 4325 | : QUIC_ARRAYSIZE(packet), |
| 4326 | false); |
| 4327 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 4328 | EXPECT_EQ(QUIC_INVALID_STOP_WAITING_DATA, framer_.error()); |
| 4329 | EXPECT_EQ("Invalid unacked delta.", framer_.detailed_error()); |
| 4330 | } |
| 4331 | |
| 4332 | TEST_P(QuicFramerTest, RstStreamFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4333 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4334 | // clang-format off |
| 4335 | PacketFragments packet = { |
| 4336 | // public flags (8 byte connection_id) |
| 4337 | {"", |
| 4338 | {0x28}}, |
| 4339 | // connection_id |
| 4340 | {"", |
| 4341 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4342 | // packet number |
| 4343 | {"", |
| 4344 | {0x12, 0x34, 0x56, 0x78}}, |
| 4345 | // frame type (rst stream frame) |
| 4346 | {"", |
| 4347 | {0x01}}, |
| 4348 | // stream id |
| 4349 | {"Unable to read stream_id.", |
| 4350 | {0x01, 0x02, 0x03, 0x04}}, |
| 4351 | // sent byte offset |
| 4352 | {"Unable to read rst stream sent byte offset.", |
| 4353 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4354 | 0x32, 0x10, 0x76, 0x54}}, |
| 4355 | // error code |
| 4356 | {"Unable to read rst stream error code.", |
| 4357 | {0x00, 0x00, 0x00, 0x01}} |
| 4358 | }; |
| 4359 | |
| 4360 | PacketFragments packet44 = { |
| 4361 | // type (short header, 4 byte packet number) |
| 4362 | {"", |
| 4363 | {0x32}}, |
| 4364 | // connection_id |
| 4365 | {"", |
| 4366 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4367 | // packet number |
| 4368 | {"", |
| 4369 | {0x12, 0x34, 0x56, 0x78}}, |
| 4370 | // frame type (rst stream frame) |
| 4371 | {"", |
| 4372 | {0x01}}, |
| 4373 | // stream id |
| 4374 | {"Unable to read stream_id.", |
| 4375 | {0x01, 0x02, 0x03, 0x04}}, |
| 4376 | // sent byte offset |
| 4377 | {"Unable to read rst stream sent byte offset.", |
| 4378 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4379 | 0x32, 0x10, 0x76, 0x54}}, |
| 4380 | // error code |
| 4381 | {"Unable to read rst stream error code.", |
| 4382 | {0x00, 0x00, 0x00, 0x01}} |
| 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 (rst stream frame) |
| 4396 | {"", |
| 4397 | {0x01}}, |
| 4398 | // stream id |
| 4399 | {"Unable to read stream_id.", |
| 4400 | {0x01, 0x02, 0x03, 0x04}}, |
| 4401 | // sent byte offset |
| 4402 | {"Unable to read rst stream sent byte offset.", |
| 4403 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4404 | 0x32, 0x10, 0x76, 0x54}}, |
| 4405 | // error code |
| 4406 | {"Unable to read rst stream error code.", |
| 4407 | {0x00, 0x00, 0x00, 0x01}} |
| 4408 | }; |
| 4409 | |
| 4410 | PacketFragments packet99 = { |
| 4411 | // type (short header, 4 byte packet number) |
| 4412 | {"", |
| 4413 | {0x43}}, |
| 4414 | // connection_id |
| 4415 | {"", |
| 4416 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4417 | // packet number |
| 4418 | {"", |
| 4419 | {0x12, 0x34, 0x56, 0x78}}, |
| 4420 | // frame type (IETF_RST_STREAM frame) |
| 4421 | {"", |
| 4422 | {0x04}}, |
| 4423 | // stream id |
| 4424 | {"Unable to read rst stream stream id.", |
| 4425 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 4426 | // application error code |
| 4427 | {"Unable to read rst stream error code.", |
| 4428 | {0x00, 0x01}}, // Not varint62 encoded |
| 4429 | // Final Offset |
| 4430 | {"Unable to read rst stream sent byte offset.", |
| 4431 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}} |
| 4432 | }; |
| 4433 | // clang-format on |
| 4434 | |
| 4435 | PacketFragments& fragments = |
| 4436 | framer_.transport_version() == QUIC_VERSION_99 |
| 4437 | ? packet99 |
| 4438 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 4439 | ? packet46 |
| 4440 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4441 | : packet)); |
| 4442 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4443 | AssemblePacketFromFragments(fragments)); |
| 4444 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4445 | |
| 4446 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4447 | ASSERT_TRUE(visitor_.header_.get()); |
| 4448 | EXPECT_TRUE(CheckDecryption( |
| 4449 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4450 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4451 | |
| 4452 | EXPECT_EQ(kStreamId, visitor_.rst_stream_frame_.stream_id); |
| 4453 | EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code); |
| 4454 | EXPECT_EQ(kStreamOffset, visitor_.rst_stream_frame_.byte_offset); |
| 4455 | CheckFramingBoundaries(fragments, QUIC_INVALID_RST_STREAM_DATA); |
| 4456 | } |
| 4457 | |
| 4458 | TEST_P(QuicFramerTest, ConnectionCloseFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4459 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4460 | // clang-format off |
| 4461 | PacketFragments packet = { |
| 4462 | // public flags (8 byte connection_id) |
| 4463 | {"", |
| 4464 | {0x28}}, |
| 4465 | // connection_id |
| 4466 | {"", |
| 4467 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4468 | // packet number |
| 4469 | {"", |
| 4470 | {0x12, 0x34, 0x56, 0x78}}, |
| 4471 | // frame type (connection close frame) |
| 4472 | {"", |
| 4473 | {0x02}}, |
| 4474 | // error code |
| 4475 | {"Unable to read connection close error code.", |
| 4476 | {0x00, 0x00, 0x00, 0x11}}, |
| 4477 | {"Unable to read connection close error details.", |
| 4478 | { |
| 4479 | // error details length |
| 4480 | 0x0, 0x0d, |
| 4481 | // error details |
| 4482 | 'b', 'e', 'c', 'a', |
| 4483 | 'u', 's', 'e', ' ', |
| 4484 | 'I', ' ', 'c', 'a', |
| 4485 | 'n'} |
| 4486 | } |
| 4487 | }; |
| 4488 | |
| 4489 | PacketFragments packet44 = { |
| 4490 | // type (short header, 4 byte packet number) |
| 4491 | {"", |
| 4492 | {0x32}}, |
| 4493 | // connection_id |
| 4494 | {"", |
| 4495 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4496 | // packet number |
| 4497 | {"", |
| 4498 | {0x12, 0x34, 0x56, 0x78}}, |
| 4499 | // frame type (connection close frame) |
| 4500 | {"", |
| 4501 | {0x02}}, |
| 4502 | // error code |
| 4503 | {"Unable to read connection close error code.", |
| 4504 | {0x00, 0x00, 0x00, 0x11}}, |
| 4505 | {"Unable to read connection close error details.", |
| 4506 | { |
| 4507 | // error details length |
| 4508 | 0x0, 0x0d, |
| 4509 | // error details |
| 4510 | 'b', 'e', 'c', 'a', |
| 4511 | 'u', 's', 'e', ' ', |
| 4512 | 'I', ' ', 'c', 'a', |
| 4513 | 'n'} |
| 4514 | } |
| 4515 | }; |
| 4516 | |
| 4517 | PacketFragments packet46 = { |
| 4518 | // type (short header, 4 byte packet number) |
| 4519 | {"", |
| 4520 | {0x43}}, |
| 4521 | // connection_id |
| 4522 | {"", |
| 4523 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4524 | // packet number |
| 4525 | {"", |
| 4526 | {0x12, 0x34, 0x56, 0x78}}, |
| 4527 | // frame type (connection close frame) |
| 4528 | {"", |
| 4529 | {0x02}}, |
| 4530 | // error code |
| 4531 | {"Unable to read connection close error code.", |
| 4532 | {0x00, 0x00, 0x00, 0x11}}, |
| 4533 | {"Unable to read connection close error details.", |
| 4534 | { |
| 4535 | // error details length |
| 4536 | 0x0, 0x0d, |
| 4537 | // error details |
| 4538 | 'b', 'e', 'c', 'a', |
| 4539 | 'u', 's', 'e', ' ', |
| 4540 | 'I', ' ', 'c', 'a', |
| 4541 | 'n'} |
| 4542 | } |
| 4543 | }; |
| 4544 | |
| 4545 | PacketFragments packet99 = { |
| 4546 | // type (short header, 4 byte packet number) |
| 4547 | {"", |
| 4548 | {0x43}}, |
| 4549 | // connection_id |
| 4550 | {"", |
| 4551 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4552 | // packet number |
| 4553 | {"", |
| 4554 | {0x12, 0x34, 0x56, 0x78}}, |
| 4555 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 4556 | {"", |
| 4557 | {0x1c}}, |
| 4558 | // error code |
| 4559 | {"Unable to read connection close error code.", |
| 4560 | {0x00, 0x11}}, |
| 4561 | {"Unable to read connection close frame type.", |
| 4562 | {kVarInt62TwoBytes + 0x12, 0x34 }}, |
| 4563 | {"Unable to read connection close error details.", |
| 4564 | { |
| 4565 | // error details length |
| 4566 | kVarInt62OneByte + 0x0d, |
| 4567 | // error details |
| 4568 | 'b', 'e', 'c', 'a', |
| 4569 | 'u', 's', 'e', ' ', |
| 4570 | 'I', ' ', 'c', 'a', |
| 4571 | 'n'} |
| 4572 | } |
| 4573 | }; |
| 4574 | // clang-format on |
| 4575 | |
| 4576 | PacketFragments& fragments = |
| 4577 | framer_.transport_version() == QUIC_VERSION_99 |
| 4578 | ? packet99 |
| 4579 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 4580 | ? packet46 |
| 4581 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4582 | : packet)); |
| 4583 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4584 | AssemblePacketFromFragments(fragments)); |
| 4585 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4586 | |
| 4587 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4588 | ASSERT_TRUE(visitor_.header_.get()); |
| 4589 | EXPECT_TRUE(CheckDecryption( |
| 4590 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4591 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4592 | |
| 4593 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
zhongyi | ba6354a | 2019-04-10 16:49:25 -0700 | [diff] [blame] | 4594 | EXPECT_EQ(0x11u, static_cast<unsigned>( |
| 4595 | visitor_.connection_close_frame_.quic_error_code)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4596 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
| 4597 | if (framer_.transport_version() == QUIC_VERSION_99) { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 4598 | EXPECT_EQ(0x1234u, |
| 4599 | visitor_.connection_close_frame_.transport_close_frame_type); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4603 | |
| 4604 | CheckFramingBoundaries(fragments, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 4605 | } |
| 4606 | |
fkastenholz | 04bd4f3 | 2019-04-16 12:24:38 -0700 | [diff] [blame] | 4607 | // Test the CONNECTION_CLOSE/Application variant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4608 | TEST_P(QuicFramerTest, ApplicationCloseFrame) { |
| 4609 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 4610 | // This frame does not exist in versions other than 99. |
| 4611 | return; |
| 4612 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4613 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4614 | |
| 4615 | // clang-format off |
| 4616 | PacketFragments packet99 = { |
| 4617 | // type (short header, 4 byte packet number) |
| 4618 | {"", |
| 4619 | {0x43}}, |
| 4620 | // connection_id |
| 4621 | {"", |
| 4622 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4623 | // packet number |
| 4624 | {"", |
| 4625 | {0x12, 0x34, 0x56, 0x78}}, |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4626 | // frame type (IETF_CONNECTION_CLOSE/Application frame) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4627 | {"", |
| 4628 | {0x1d}}, |
| 4629 | // error code |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4630 | {"Unable to read connection close error code.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4631 | {0x00, 0x11}}, |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4632 | {"Unable to read connection close error details.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4633 | { |
| 4634 | // error details length |
| 4635 | kVarInt62OneByte + 0x0d, |
| 4636 | // error details |
| 4637 | 'b', 'e', 'c', 'a', |
| 4638 | 'u', 's', 'e', ' ', |
| 4639 | 'I', ' ', 'c', 'a', |
| 4640 | 'n'} |
| 4641 | } |
| 4642 | }; |
| 4643 | // clang-format on |
| 4644 | |
| 4645 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4646 | AssemblePacketFromFragments(packet99)); |
| 4647 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4648 | |
| 4649 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4650 | ASSERT_TRUE(visitor_.header_.get()); |
| 4651 | EXPECT_TRUE(CheckDecryption( |
| 4652 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4653 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4654 | |
| 4655 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4656 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4657 | EXPECT_EQ(IETF_QUIC_APPLICATION_CONNECTION_CLOSE, |
| 4658 | visitor_.connection_close_frame_.close_type); |
| 4659 | EXPECT_EQ(122u, visitor_.connection_close_frame_.extracted_error_code); |
| 4660 | EXPECT_EQ(0x11, visitor_.connection_close_frame_.quic_error_code); |
| 4661 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4662 | |
| 4663 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4664 | |
fkastenholz | 04bd4f3 | 2019-04-16 12:24:38 -0700 | [diff] [blame] | 4665 | CheckFramingBoundaries(packet99, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | TEST_P(QuicFramerTest, GoAwayFrame) { |
| 4669 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4670 | // This frame is not supported in version 99. |
| 4671 | return; |
| 4672 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4673 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4674 | // clang-format off |
| 4675 | PacketFragments packet = { |
| 4676 | // public flags (8 byte connection_id) |
| 4677 | {"", |
| 4678 | {0x28}}, |
| 4679 | // connection_id |
| 4680 | {"", |
| 4681 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4682 | // packet number |
| 4683 | {"", |
| 4684 | {0x12, 0x34, 0x56, 0x78}}, |
| 4685 | // frame type (go away frame) |
| 4686 | {"", |
| 4687 | {0x03}}, |
| 4688 | // error code |
| 4689 | {"Unable to read go away error code.", |
| 4690 | {0x00, 0x00, 0x00, 0x09}}, |
| 4691 | // stream id |
| 4692 | {"Unable to read last good stream id.", |
| 4693 | {0x01, 0x02, 0x03, 0x04}}, |
| 4694 | // stream id |
| 4695 | {"Unable to read goaway reason.", |
| 4696 | { |
| 4697 | // error details length |
| 4698 | 0x0, 0x0d, |
| 4699 | // error details |
| 4700 | 'b', 'e', 'c', 'a', |
| 4701 | 'u', 's', 'e', ' ', |
| 4702 | 'I', ' ', 'c', 'a', |
| 4703 | 'n'} |
| 4704 | } |
| 4705 | }; |
| 4706 | |
| 4707 | PacketFragments packet44 = { |
| 4708 | // type (short header, 4 byte packet number) |
| 4709 | {"", |
| 4710 | {0x32}}, |
| 4711 | // connection_id |
| 4712 | {"", |
| 4713 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4714 | // packet number |
| 4715 | {"", |
| 4716 | {0x12, 0x34, 0x56, 0x78}}, |
| 4717 | // frame type (go away frame) |
| 4718 | {"", |
| 4719 | {0x03}}, |
| 4720 | // error code |
| 4721 | {"Unable to read go away error code.", |
| 4722 | {0x00, 0x00, 0x00, 0x09}}, |
| 4723 | // stream id |
| 4724 | {"Unable to read last good stream id.", |
| 4725 | {0x01, 0x02, 0x03, 0x04}}, |
| 4726 | // stream id |
| 4727 | {"Unable to read goaway reason.", |
| 4728 | { |
| 4729 | // error details length |
| 4730 | 0x0, 0x0d, |
| 4731 | // error details |
| 4732 | 'b', 'e', 'c', 'a', |
| 4733 | 'u', 's', 'e', ' ', |
| 4734 | 'I', ' ', 'c', 'a', |
| 4735 | 'n'} |
| 4736 | } |
| 4737 | }; |
| 4738 | |
| 4739 | PacketFragments packet46 = { |
| 4740 | // type (short header, 4 byte packet number) |
| 4741 | {"", |
| 4742 | {0x43}}, |
| 4743 | // connection_id |
| 4744 | {"", |
| 4745 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4746 | // packet number |
| 4747 | {"", |
| 4748 | {0x12, 0x34, 0x56, 0x78}}, |
| 4749 | // frame type (go away frame) |
| 4750 | {"", |
| 4751 | {0x03}}, |
| 4752 | // error code |
| 4753 | {"Unable to read go away error code.", |
| 4754 | {0x00, 0x00, 0x00, 0x09}}, |
| 4755 | // stream id |
| 4756 | {"Unable to read last good stream id.", |
| 4757 | {0x01, 0x02, 0x03, 0x04}}, |
| 4758 | // stream id |
| 4759 | {"Unable to read goaway reason.", |
| 4760 | { |
| 4761 | // error details length |
| 4762 | 0x0, 0x0d, |
| 4763 | // error details |
| 4764 | 'b', 'e', 'c', 'a', |
| 4765 | 'u', 's', 'e', ' ', |
| 4766 | 'I', ' ', 'c', 'a', |
| 4767 | 'n'} |
| 4768 | } |
| 4769 | }; |
| 4770 | // clang-format on |
| 4771 | |
| 4772 | PacketFragments& fragments = |
| 4773 | framer_.transport_version() > QUIC_VERSION_44 |
| 4774 | ? packet46 |
| 4775 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 4776 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4777 | AssemblePacketFromFragments(fragments)); |
| 4778 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4779 | |
| 4780 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4781 | ASSERT_TRUE(visitor_.header_.get()); |
| 4782 | EXPECT_TRUE(CheckDecryption( |
| 4783 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4784 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4785 | |
| 4786 | EXPECT_EQ(kStreamId, visitor_.goaway_frame_.last_good_stream_id); |
| 4787 | EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code); |
| 4788 | EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); |
| 4789 | |
| 4790 | CheckFramingBoundaries(fragments, QUIC_INVALID_GOAWAY_DATA); |
| 4791 | } |
| 4792 | |
| 4793 | TEST_P(QuicFramerTest, WindowUpdateFrame) { |
| 4794 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4795 | // This frame is not in version 99, see MaxDataFrame and MaxStreamDataFrame |
| 4796 | // for Version 99 equivalents. |
| 4797 | return; |
| 4798 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4799 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4800 | // clang-format off |
| 4801 | PacketFragments packet = { |
| 4802 | // public flags (8 byte connection_id) |
| 4803 | {"", |
| 4804 | {0x28}}, |
| 4805 | // connection_id |
| 4806 | {"", |
| 4807 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4808 | // packet number |
| 4809 | {"", |
| 4810 | {0x12, 0x34, 0x56, 0x78}}, |
| 4811 | // frame type (window update frame) |
| 4812 | {"", |
| 4813 | {0x04}}, |
| 4814 | // stream id |
| 4815 | {"Unable to read stream_id.", |
| 4816 | {0x01, 0x02, 0x03, 0x04}}, |
| 4817 | // byte offset |
| 4818 | {"Unable to read window byte_offset.", |
| 4819 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4820 | 0x32, 0x10, 0x76, 0x54}}, |
| 4821 | }; |
| 4822 | |
| 4823 | PacketFragments packet44 = { |
| 4824 | // type (short header, 4 byte packet number) |
| 4825 | {"", |
| 4826 | {0x32}}, |
| 4827 | // connection_id |
| 4828 | {"", |
| 4829 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4830 | // packet number |
| 4831 | {"", |
| 4832 | {0x12, 0x34, 0x56, 0x78}}, |
| 4833 | // frame type (window update frame) |
| 4834 | {"", |
| 4835 | {0x04}}, |
| 4836 | // stream id |
| 4837 | {"Unable to read stream_id.", |
| 4838 | {0x01, 0x02, 0x03, 0x04}}, |
| 4839 | // byte offset |
| 4840 | {"Unable to read window byte_offset.", |
| 4841 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4842 | 0x32, 0x10, 0x76, 0x54}}, |
| 4843 | }; |
| 4844 | |
| 4845 | PacketFragments packet46 = { |
| 4846 | // type (short header, 4 byte packet number) |
| 4847 | {"", |
| 4848 | {0x43}}, |
| 4849 | // connection_id |
| 4850 | {"", |
| 4851 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4852 | // packet number |
| 4853 | {"", |
| 4854 | {0x12, 0x34, 0x56, 0x78}}, |
| 4855 | // frame type (window update frame) |
| 4856 | {"", |
| 4857 | {0x04}}, |
| 4858 | // stream id |
| 4859 | {"Unable to read stream_id.", |
| 4860 | {0x01, 0x02, 0x03, 0x04}}, |
| 4861 | // byte offset |
| 4862 | {"Unable to read window byte_offset.", |
| 4863 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4864 | 0x32, 0x10, 0x76, 0x54}}, |
| 4865 | }; |
| 4866 | |
| 4867 | // clang-format on |
| 4868 | |
| 4869 | PacketFragments& fragments = |
| 4870 | framer_.transport_version() > QUIC_VERSION_44 |
| 4871 | ? packet46 |
| 4872 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 4873 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4874 | AssemblePacketFromFragments(fragments)); |
| 4875 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4876 | |
| 4877 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4878 | ASSERT_TRUE(visitor_.header_.get()); |
| 4879 | EXPECT_TRUE(CheckDecryption( |
| 4880 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4881 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4882 | |
| 4883 | EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); |
| 4884 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); |
| 4885 | |
| 4886 | CheckFramingBoundaries(fragments, QUIC_INVALID_WINDOW_UPDATE_DATA); |
| 4887 | } |
| 4888 | |
| 4889 | TEST_P(QuicFramerTest, MaxDataFrame) { |
| 4890 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 4891 | // This frame is available only in version 99. |
| 4892 | return; |
| 4893 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4894 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4895 | // clang-format off |
| 4896 | PacketFragments packet99 = { |
| 4897 | // type (short header, 4 byte packet number) |
| 4898 | {"", |
| 4899 | {0x43}}, |
| 4900 | // connection_id |
| 4901 | {"", |
| 4902 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4903 | // packet number |
| 4904 | {"", |
| 4905 | {0x12, 0x34, 0x56, 0x78}}, |
| 4906 | // frame type (IETF_MAX_DATA frame) |
| 4907 | {"", |
| 4908 | {0x10}}, |
| 4909 | // byte offset |
| 4910 | {"Can not read MAX_DATA byte-offset", |
| 4911 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 4912 | 0x32, 0x10, 0x76, 0x54}}, |
| 4913 | }; |
| 4914 | // clang-format on |
| 4915 | |
| 4916 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4917 | AssemblePacketFromFragments(packet99)); |
| 4918 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4919 | |
| 4920 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4921 | ASSERT_TRUE(visitor_.header_.get()); |
| 4922 | EXPECT_TRUE(CheckDecryption( |
| 4923 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4924 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4925 | |
| 4926 | EXPECT_EQ(QuicUtils::GetInvalidStreamId(framer_.transport_version()), |
| 4927 | visitor_.window_update_frame_.stream_id); |
| 4928 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); |
| 4929 | |
| 4930 | CheckFramingBoundaries(packet99, QUIC_INVALID_MAX_DATA_FRAME_DATA); |
| 4931 | } |
| 4932 | |
| 4933 | TEST_P(QuicFramerTest, MaxStreamDataFrame) { |
| 4934 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 4935 | // This frame available only in version 99. |
| 4936 | return; |
| 4937 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4938 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4939 | // clang-format off |
| 4940 | PacketFragments packet99 = { |
| 4941 | // type (short header, 4 byte packet number) |
| 4942 | {"", |
| 4943 | {0x43}}, |
| 4944 | // connection_id |
| 4945 | {"", |
| 4946 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4947 | // packet number |
| 4948 | {"", |
| 4949 | {0x12, 0x34, 0x56, 0x78}}, |
| 4950 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 4951 | {"", |
| 4952 | {0x11}}, |
| 4953 | // stream id |
| 4954 | {"Can not read MAX_STREAM_DATA stream id", |
| 4955 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 4956 | // byte offset |
| 4957 | {"Can not read MAX_STREAM_DATA byte-count", |
| 4958 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 4959 | 0x32, 0x10, 0x76, 0x54}}, |
| 4960 | }; |
| 4961 | // clang-format on |
| 4962 | |
| 4963 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4964 | AssemblePacketFromFragments(packet99)); |
| 4965 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4966 | |
| 4967 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4968 | ASSERT_TRUE(visitor_.header_.get()); |
| 4969 | EXPECT_TRUE(CheckDecryption( |
| 4970 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4971 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4972 | |
| 4973 | EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); |
| 4974 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); |
| 4975 | |
| 4976 | CheckFramingBoundaries(packet99, QUIC_INVALID_MAX_STREAM_DATA_FRAME_DATA); |
| 4977 | } |
| 4978 | |
| 4979 | TEST_P(QuicFramerTest, BlockedFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4980 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4981 | // clang-format off |
| 4982 | PacketFragments packet = { |
| 4983 | // public flags (8 byte connection_id) |
| 4984 | {"", |
| 4985 | {0x28}}, |
| 4986 | // connection_id |
| 4987 | {"", |
| 4988 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4989 | // packet number |
| 4990 | {"", |
| 4991 | {0x12, 0x34, 0x56, 0x78}}, |
| 4992 | // frame type (blocked frame) |
| 4993 | {"", |
| 4994 | {0x05}}, |
| 4995 | // stream id |
| 4996 | {"Unable to read stream_id.", |
| 4997 | {0x01, 0x02, 0x03, 0x04}}, |
| 4998 | }; |
| 4999 | |
| 5000 | PacketFragments packet44 = { |
| 5001 | // type (short header, 4 byte packet number) |
| 5002 | {"", |
| 5003 | {0x32}}, |
| 5004 | // connection_id |
| 5005 | {"", |
| 5006 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5007 | // packet number |
| 5008 | {"", |
| 5009 | {0x12, 0x34, 0x56, 0x78}}, |
| 5010 | // frame type (blocked frame) |
| 5011 | {"", |
| 5012 | {0x05}}, |
| 5013 | // stream id |
| 5014 | {"Unable to read stream_id.", |
| 5015 | {0x01, 0x02, 0x03, 0x04}}, |
| 5016 | }; |
| 5017 | |
| 5018 | PacketFragments packet46 = { |
| 5019 | // type (short header, 4 byte packet number) |
| 5020 | {"", |
| 5021 | {0x43}}, |
| 5022 | // connection_id |
| 5023 | {"", |
| 5024 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5025 | // packet number |
| 5026 | {"", |
| 5027 | {0x12, 0x34, 0x56, 0x78}}, |
| 5028 | // frame type (blocked frame) |
| 5029 | {"", |
| 5030 | {0x05}}, |
| 5031 | // stream id |
| 5032 | {"Unable to read stream_id.", |
| 5033 | {0x01, 0x02, 0x03, 0x04}}, |
| 5034 | }; |
| 5035 | |
| 5036 | PacketFragments packet99 = { |
| 5037 | // type (short header, 4 byte packet number) |
| 5038 | {"", |
| 5039 | {0x43}}, |
| 5040 | // connection_id |
| 5041 | {"", |
| 5042 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5043 | // packet number |
| 5044 | {"", |
| 5045 | {0x12, 0x34, 0x56, 0x78}}, |
| 5046 | // frame type (IETF_STREAM_BLOCKED frame) |
| 5047 | {"", |
| 5048 | {0x15}}, |
| 5049 | // stream id |
| 5050 | {"Can not read stream blocked stream id.", |
| 5051 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 5052 | // Offset |
| 5053 | {"Can not read stream blocked offset.", |
| 5054 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 5055 | }; |
| 5056 | // clang-format on |
| 5057 | |
| 5058 | PacketFragments& fragments = |
| 5059 | framer_.transport_version() == QUIC_VERSION_99 |
| 5060 | ? packet99 |
| 5061 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 5062 | ? packet46 |
| 5063 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 5064 | : packet)); |
| 5065 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5066 | AssemblePacketFromFragments(fragments)); |
| 5067 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5068 | |
| 5069 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5070 | ASSERT_TRUE(visitor_.header_.get()); |
| 5071 | EXPECT_TRUE(CheckDecryption( |
| 5072 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5073 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5074 | |
| 5075 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5076 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 5077 | } else { |
| 5078 | EXPECT_EQ(0u, visitor_.blocked_frame_.offset); |
| 5079 | } |
| 5080 | EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); |
| 5081 | |
| 5082 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5083 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_BLOCKED_DATA); |
| 5084 | } else { |
| 5085 | CheckFramingBoundaries(fragments, QUIC_INVALID_BLOCKED_DATA); |
| 5086 | } |
| 5087 | } |
| 5088 | |
| 5089 | TEST_P(QuicFramerTest, PingFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5090 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5091 | // clang-format off |
| 5092 | unsigned char packet[] = { |
| 5093 | // public flags (8 byte connection_id) |
| 5094 | 0x28, |
| 5095 | // connection_id |
| 5096 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5097 | // packet number |
| 5098 | 0x12, 0x34, 0x56, 0x78, |
| 5099 | |
| 5100 | // frame type (ping frame) |
| 5101 | 0x07, |
| 5102 | }; |
| 5103 | |
| 5104 | unsigned char packet44[] = { |
| 5105 | // type (short header, 4 byte packet number) |
| 5106 | 0x32, |
| 5107 | // connection_id |
| 5108 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5109 | // packet number |
| 5110 | 0x12, 0x34, 0x56, 0x78, |
| 5111 | |
| 5112 | // frame type |
| 5113 | 0x07, |
| 5114 | }; |
| 5115 | |
| 5116 | unsigned char packet46[] = { |
| 5117 | // type (short header, 4 byte packet number) |
| 5118 | 0x43, |
| 5119 | // connection_id |
| 5120 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5121 | // packet number |
| 5122 | 0x12, 0x34, 0x56, 0x78, |
| 5123 | |
| 5124 | // frame type |
| 5125 | 0x07, |
| 5126 | }; |
| 5127 | |
| 5128 | unsigned char packet99[] = { |
| 5129 | // type (short header, 4 byte packet number) |
| 5130 | 0x43, |
| 5131 | // connection_id |
| 5132 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5133 | // packet number |
| 5134 | 0x12, 0x34, 0x56, 0x78, |
| 5135 | |
| 5136 | // frame type (IETF_PING frame) |
| 5137 | 0x01, |
| 5138 | }; |
| 5139 | // clang-format on |
| 5140 | |
| 5141 | QuicEncryptedPacket encrypted( |
| 5142 | AsChars(framer_.transport_version() == QUIC_VERSION_99 |
| 5143 | ? packet99 |
| 5144 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 5145 | ? packet46 |
| 5146 | : framer_.transport_version() > QUIC_VERSION_43 |
| 5147 | ? packet44 |
| 5148 | : packet)), |
| 5149 | framer_.transport_version() == QUIC_VERSION_99 |
| 5150 | ? QUIC_ARRAYSIZE(packet99) |
| 5151 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 5152 | ? QUIC_ARRAYSIZE(packet46) |
| 5153 | : framer_.transport_version() > QUIC_VERSION_43 |
| 5154 | ? QUIC_ARRAYSIZE(packet44) |
| 5155 | : QUIC_ARRAYSIZE(packet)), |
| 5156 | false); |
| 5157 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5158 | |
| 5159 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5160 | ASSERT_TRUE(visitor_.header_.get()); |
| 5161 | EXPECT_TRUE(CheckDecryption( |
| 5162 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5163 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5164 | |
| 5165 | EXPECT_EQ(1u, visitor_.ping_frames_.size()); |
| 5166 | |
| 5167 | // No need to check the PING frame boundaries because it has no payload. |
| 5168 | } |
| 5169 | |
| 5170 | TEST_P(QuicFramerTest, MessageFrame) { |
| 5171 | if (framer_.transport_version() <= QUIC_VERSION_44) { |
| 5172 | return; |
| 5173 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5174 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5175 | // clang-format off |
| 5176 | PacketFragments packet45 = { |
| 5177 | // type (short header, 4 byte packet number) |
| 5178 | {"", |
| 5179 | {0x32}}, |
| 5180 | // connection_id |
| 5181 | {"", |
| 5182 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5183 | // packet number |
| 5184 | {"", |
| 5185 | {0x12, 0x34, 0x56, 0x78}}, |
| 5186 | // message frame type. |
| 5187 | {"", |
| 5188 | { 0x21 }}, |
| 5189 | // message length |
| 5190 | {"Unable to read message length", |
| 5191 | {0x07}}, |
| 5192 | // message data |
| 5193 | {"Unable to read message data", |
| 5194 | {'m', 'e', 's', 's', 'a', 'g', 'e'}}, |
| 5195 | // message frame no length. |
| 5196 | {"", |
| 5197 | { 0x20 }}, |
| 5198 | // message data |
| 5199 | {{}, |
| 5200 | {'m', 'e', 's', 's', 'a', 'g', 'e', '2'}}, |
| 5201 | }; |
| 5202 | |
| 5203 | PacketFragments packet46 = { |
| 5204 | // type (short header, 4 byte packet number) |
| 5205 | {"", |
| 5206 | {0x43}}, |
| 5207 | // connection_id |
| 5208 | {"", |
| 5209 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5210 | // packet number |
| 5211 | {"", |
| 5212 | {0x12, 0x34, 0x56, 0x78}}, |
| 5213 | // message frame type. |
| 5214 | {"", |
| 5215 | { 0x21 }}, |
| 5216 | // message length |
| 5217 | {"Unable to read message length", |
| 5218 | {0x07}}, |
| 5219 | // message data |
| 5220 | {"Unable to read message data", |
| 5221 | {'m', 'e', 's', 's', 'a', 'g', 'e'}}, |
| 5222 | // message frame no length. |
| 5223 | {"", |
| 5224 | { 0x20 }}, |
| 5225 | // message data |
| 5226 | {{}, |
| 5227 | {'m', 'e', 's', 's', 'a', 'g', 'e', '2'}}, |
| 5228 | }; |
| 5229 | // clang-format on |
| 5230 | |
| 5231 | std::unique_ptr<QuicEncryptedPacket> encrypted(AssemblePacketFromFragments( |
| 5232 | framer_.transport_version() > QUIC_VERSION_44 ? packet46 : packet45)); |
| 5233 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5234 | |
| 5235 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5236 | ASSERT_TRUE(visitor_.header_.get()); |
| 5237 | EXPECT_TRUE(CheckDecryption( |
| 5238 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5239 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5240 | |
| 5241 | ASSERT_EQ(2u, visitor_.message_frames_.size()); |
| 5242 | EXPECT_EQ(7u, visitor_.message_frames_[0]->message_length); |
| 5243 | EXPECT_EQ(8u, visitor_.message_frames_[1]->message_length); |
| 5244 | |
| 5245 | CheckFramingBoundaries( |
| 5246 | framer_.transport_version() > QUIC_VERSION_44 ? packet46 : packet45, |
| 5247 | QUIC_INVALID_MESSAGE_DATA); |
| 5248 | } |
| 5249 | |
| 5250 | TEST_P(QuicFramerTest, PublicResetPacketV33) { |
| 5251 | // clang-format off |
| 5252 | PacketFragments packet = { |
| 5253 | // public flags (public reset, 8 byte connection_id) |
| 5254 | {"", |
| 5255 | {0x0A}}, |
| 5256 | // connection_id |
| 5257 | {"", |
| 5258 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5259 | {"Unable to read reset message.", |
| 5260 | { |
| 5261 | // message tag (kPRST) |
| 5262 | 'P', 'R', 'S', 'T', |
| 5263 | // num_entries (2) + padding |
| 5264 | 0x02, 0x00, 0x00, 0x00, |
| 5265 | // tag kRNON |
| 5266 | 'R', 'N', 'O', 'N', |
| 5267 | // end offset 8 |
| 5268 | 0x08, 0x00, 0x00, 0x00, |
| 5269 | // tag kRSEQ |
| 5270 | 'R', 'S', 'E', 'Q', |
| 5271 | // end offset 16 |
| 5272 | 0x10, 0x00, 0x00, 0x00, |
| 5273 | // nonce proof |
| 5274 | 0x89, 0x67, 0x45, 0x23, |
| 5275 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5276 | // rejected packet number |
| 5277 | 0xBC, 0x9A, 0x78, 0x56, |
| 5278 | 0x34, 0x12, 0x00, 0x00, |
| 5279 | } |
| 5280 | } |
| 5281 | }; |
| 5282 | // clang-format on |
| 5283 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5284 | return; |
| 5285 | } |
| 5286 | |
| 5287 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5288 | AssemblePacketFromFragments(packet)); |
| 5289 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5290 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5291 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5292 | EXPECT_EQ(FramerTestConnectionId(), |
| 5293 | visitor_.public_reset_packet_->connection_id); |
| 5294 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5295 | EXPECT_EQ( |
| 5296 | IpAddressFamily::IP_UNSPEC, |
| 5297 | visitor_.public_reset_packet_->client_address.host().address_family()); |
| 5298 | |
| 5299 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5300 | } |
| 5301 | |
| 5302 | TEST_P(QuicFramerTest, PublicResetPacket) { |
| 5303 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5304 | |
| 5305 | // clang-format off |
| 5306 | PacketFragments packet = { |
| 5307 | // public flags (public reset, 8 byte connection_id) |
| 5308 | {"", |
| 5309 | {0x0E}}, |
| 5310 | // connection_id |
| 5311 | {"", |
| 5312 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5313 | {"Unable to read reset message.", |
| 5314 | { |
| 5315 | // message tag (kPRST) |
| 5316 | 'P', 'R', 'S', 'T', |
| 5317 | // num_entries (2) + padding |
| 5318 | 0x02, 0x00, 0x00, 0x00, |
| 5319 | // tag kRNON |
| 5320 | 'R', 'N', 'O', 'N', |
| 5321 | // end offset 8 |
| 5322 | 0x08, 0x00, 0x00, 0x00, |
| 5323 | // tag kRSEQ |
| 5324 | 'R', 'S', 'E', 'Q', |
| 5325 | // end offset 16 |
| 5326 | 0x10, 0x00, 0x00, 0x00, |
| 5327 | // nonce proof |
| 5328 | 0x89, 0x67, 0x45, 0x23, |
| 5329 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5330 | // rejected packet number |
| 5331 | 0xBC, 0x9A, 0x78, 0x56, |
| 5332 | 0x34, 0x12, 0x00, 0x00, |
| 5333 | } |
| 5334 | } |
| 5335 | }; |
| 5336 | // clang-format on |
| 5337 | |
| 5338 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5339 | return; |
| 5340 | } |
| 5341 | |
| 5342 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5343 | AssemblePacketFromFragments(packet)); |
| 5344 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5345 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5346 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5347 | EXPECT_EQ(FramerTestConnectionId(), |
| 5348 | visitor_.public_reset_packet_->connection_id); |
| 5349 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5350 | EXPECT_EQ( |
| 5351 | IpAddressFamily::IP_UNSPEC, |
| 5352 | visitor_.public_reset_packet_->client_address.host().address_family()); |
| 5353 | |
| 5354 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5355 | } |
| 5356 | |
| 5357 | TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) { |
| 5358 | // clang-format off |
| 5359 | unsigned char packet[] = { |
| 5360 | // public flags (public reset, 8 byte connection_id) |
| 5361 | 0x0A, |
| 5362 | // connection_id |
| 5363 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5364 | // message tag (kPRST) |
| 5365 | 'P', 'R', 'S', 'T', |
| 5366 | // num_entries (2) + padding |
| 5367 | 0x02, 0x00, 0x00, 0x00, |
| 5368 | // tag kRNON |
| 5369 | 'R', 'N', 'O', 'N', |
| 5370 | // end offset 8 |
| 5371 | 0x08, 0x00, 0x00, 0x00, |
| 5372 | // tag kRSEQ |
| 5373 | 'R', 'S', 'E', 'Q', |
| 5374 | // end offset 16 |
| 5375 | 0x10, 0x00, 0x00, 0x00, |
| 5376 | // nonce proof |
| 5377 | 0x89, 0x67, 0x45, 0x23, |
| 5378 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5379 | // rejected packet number |
| 5380 | 0xBC, 0x9A, 0x78, 0x56, |
| 5381 | 0x34, 0x12, 0x00, 0x00, |
| 5382 | // trailing junk |
| 5383 | 'j', 'u', 'n', 'k', |
| 5384 | }; |
| 5385 | // clang-format on |
| 5386 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5387 | return; |
| 5388 | } |
| 5389 | |
| 5390 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5391 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 5392 | ASSERT_EQ(QUIC_INVALID_PUBLIC_RST_PACKET, framer_.error()); |
| 5393 | EXPECT_EQ("Unable to read reset message.", framer_.detailed_error()); |
| 5394 | } |
| 5395 | |
| 5396 | TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) { |
| 5397 | // clang-format off |
| 5398 | PacketFragments packet = { |
| 5399 | // public flags (public reset, 8 byte connection_id) |
| 5400 | {"", |
| 5401 | {0x0A}}, |
| 5402 | // connection_id |
| 5403 | {"", |
| 5404 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5405 | {"Unable to read reset message.", |
| 5406 | { |
| 5407 | // message tag (kPRST) |
| 5408 | 'P', 'R', 'S', 'T', |
| 5409 | // num_entries (2) + padding |
| 5410 | 0x03, 0x00, 0x00, 0x00, |
| 5411 | // tag kRNON |
| 5412 | 'R', 'N', 'O', 'N', |
| 5413 | // end offset 8 |
| 5414 | 0x08, 0x00, 0x00, 0x00, |
| 5415 | // tag kRSEQ |
| 5416 | 'R', 'S', 'E', 'Q', |
| 5417 | // end offset 16 |
| 5418 | 0x10, 0x00, 0x00, 0x00, |
| 5419 | // tag kCADR |
| 5420 | 'C', 'A', 'D', 'R', |
| 5421 | // end offset 24 |
| 5422 | 0x18, 0x00, 0x00, 0x00, |
| 5423 | // nonce proof |
| 5424 | 0x89, 0x67, 0x45, 0x23, |
| 5425 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5426 | // rejected packet number |
| 5427 | 0xBC, 0x9A, 0x78, 0x56, |
| 5428 | 0x34, 0x12, 0x00, 0x00, |
| 5429 | // client address: 4.31.198.44:443 |
| 5430 | 0x02, 0x00, |
| 5431 | 0x04, 0x1F, 0xC6, 0x2C, |
| 5432 | 0xBB, 0x01, |
| 5433 | } |
| 5434 | } |
| 5435 | }; |
| 5436 | // clang-format on |
| 5437 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5438 | return; |
| 5439 | } |
| 5440 | |
| 5441 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5442 | AssemblePacketFromFragments(packet)); |
| 5443 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5444 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5445 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5446 | EXPECT_EQ(FramerTestConnectionId(), |
| 5447 | visitor_.public_reset_packet_->connection_id); |
| 5448 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5449 | EXPECT_EQ("4.31.198.44", |
| 5450 | visitor_.public_reset_packet_->client_address.host().ToString()); |
| 5451 | EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); |
| 5452 | |
| 5453 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5454 | } |
| 5455 | |
| 5456 | TEST_P(QuicFramerTest, IetfStatelessResetPacket) { |
| 5457 | // clang-format off |
| 5458 | unsigned char packet[] = { |
| 5459 | // type (short packet, 1 byte packet number) |
| 5460 | 0x50, |
| 5461 | // connection_id |
| 5462 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5463 | // Random bytes |
| 5464 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5465 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5466 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5467 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5468 | // stateless reset token |
| 5469 | 0xB5, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5470 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5471 | }; |
| 5472 | // clang-format on |
| 5473 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 5474 | return; |
| 5475 | } |
| 5476 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5477 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5478 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 5479 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, QuicMakeUnique<NullDecrypter>( |
| 5480 | Perspective::IS_CLIENT)); |
| 5481 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 5482 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 5483 | } else { |
| 5484 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 5485 | QuicMakeUnique<NullDecrypter>(Perspective::IS_CLIENT)); |
| 5486 | framer_.SetAlternativeDecrypter( |
| 5487 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 5488 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5489 | // This packet cannot be decrypted because diversification nonce is missing. |
| 5490 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5491 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5492 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5493 | ASSERT_TRUE(visitor_.stateless_reset_packet_.get()); |
| 5494 | EXPECT_EQ(kTestStatelessResetToken, |
| 5495 | visitor_.stateless_reset_packet_->stateless_reset_token); |
| 5496 | } |
| 5497 | |
| 5498 | TEST_P(QuicFramerTest, IetfStatelessResetPacketInvalidStatelessResetToken) { |
| 5499 | // clang-format off |
| 5500 | unsigned char packet[] = { |
| 5501 | // type (short packet, 1 byte packet number) |
| 5502 | 0x50, |
| 5503 | // connection_id |
| 5504 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5505 | // stateless reset token |
| 5506 | 0xB6, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5507 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5508 | }; |
| 5509 | // clang-format on |
| 5510 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 5511 | return; |
| 5512 | } |
| 5513 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5514 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5515 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 5516 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, QuicMakeUnique<NullDecrypter>( |
| 5517 | Perspective::IS_CLIENT)); |
| 5518 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 5519 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 5520 | } else { |
| 5521 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 5522 | QuicMakeUnique<NullDecrypter>(Perspective::IS_CLIENT)); |
| 5523 | framer_.SetAlternativeDecrypter( |
| 5524 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 5525 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5526 | // This packet cannot be decrypted because diversification nonce is missing. |
| 5527 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5528 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 5529 | EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error()); |
| 5530 | ASSERT_FALSE(visitor_.stateless_reset_packet_); |
| 5531 | } |
| 5532 | |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5533 | TEST_P(QuicFramerTest, VersionNegotiationPacketClient) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5534 | // clang-format off |
| 5535 | PacketFragments packet = { |
| 5536 | // public flags (version, 8 byte connection_id) |
| 5537 | {"", |
| 5538 | {0x29}}, |
| 5539 | // connection_id |
| 5540 | {"", |
| 5541 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5542 | // version tag |
| 5543 | {"Unable to read supported version in negotiation.", |
| 5544 | {QUIC_VERSION_BYTES, |
| 5545 | 'Q', '2', '.', '0'}}, |
| 5546 | }; |
| 5547 | |
| 5548 | PacketFragments packet44 = { |
| 5549 | // type (long header) |
| 5550 | {"", |
| 5551 | {0x8F}}, |
| 5552 | // version tag |
| 5553 | {"", |
| 5554 | {0x00, 0x00, 0x00, 0x00}}, |
| 5555 | {"", |
| 5556 | {0x05}}, |
| 5557 | // connection_id |
| 5558 | {"", |
| 5559 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5560 | // Supported versions |
| 5561 | {"Unable to read supported version in negotiation.", |
| 5562 | {QUIC_VERSION_BYTES, |
| 5563 | 'Q', '2', '.', '0'}}, |
| 5564 | }; |
| 5565 | // clang-format on |
| 5566 | |
| 5567 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5568 | |
| 5569 | PacketFragments& fragments = |
| 5570 | framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet; |
| 5571 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5572 | AssemblePacketFromFragments(fragments)); |
| 5573 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5574 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5575 | ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); |
| 5576 | EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size()); |
| 5577 | EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); |
| 5578 | |
| 5579 | // Remove the last version from the packet so that every truncated |
| 5580 | // version of the packet is invalid, otherwise checking boundaries |
| 5581 | // is annoyingly complicated. |
| 5582 | for (size_t i = 0; i < 4; ++i) { |
| 5583 | fragments.back().fragment.pop_back(); |
| 5584 | } |
| 5585 | CheckFramingBoundaries(fragments, QUIC_INVALID_VERSION_NEGOTIATION_PACKET); |
| 5586 | } |
| 5587 | |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5588 | TEST_P(QuicFramerTest, VersionNegotiationPacketServer) { |
| 5589 | if (!GetQuicRestartFlag(quic_server_drop_version_negotiation)) { |
| 5590 | return; |
| 5591 | } |
| 5592 | if (framer_.transport_version() < QUIC_VERSION_44) { |
| 5593 | return; |
| 5594 | } |
| 5595 | |
| 5596 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 5597 | // clang-format off |
| 5598 | unsigned char packet[] = { |
| 5599 | // public flags (long header with all ignored bits set) |
| 5600 | 0xFF, |
| 5601 | // version |
| 5602 | 0x00, 0x00, 0x00, 0x00, |
| 5603 | // connection ID lengths |
| 5604 | 0x50, |
| 5605 | // destination connection ID |
| 5606 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 5607 | // supported versions |
| 5608 | QUIC_VERSION_BYTES, |
| 5609 | 'Q', '2', '.', '0', |
| 5610 | }; |
| 5611 | // clang-format on |
| 5612 | |
| 5613 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5614 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 5615 | EXPECT_EQ(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, framer_.error()); |
| 5616 | EXPECT_EQ("Server received version negotiation packet.", |
| 5617 | framer_.detailed_error()); |
| 5618 | EXPECT_FALSE(visitor_.version_negotiation_packet_.get()); |
| 5619 | } |
| 5620 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5621 | TEST_P(QuicFramerTest, OldVersionNegotiationPacket) { |
| 5622 | // clang-format off |
| 5623 | PacketFragments packet = { |
| 5624 | // public flags (version, 8 byte connection_id) |
| 5625 | {"", |
| 5626 | {0x2D}}, |
| 5627 | // connection_id |
| 5628 | {"", |
| 5629 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5630 | // version tag |
| 5631 | {"Unable to read supported version in negotiation.", |
| 5632 | {QUIC_VERSION_BYTES, |
| 5633 | 'Q', '2', '.', '0'}}, |
| 5634 | }; |
| 5635 | // clang-format on |
| 5636 | |
| 5637 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5638 | return; |
| 5639 | } |
| 5640 | |
| 5641 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5642 | |
| 5643 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5644 | AssemblePacketFromFragments(packet)); |
| 5645 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5646 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5647 | ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); |
| 5648 | EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size()); |
| 5649 | EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); |
| 5650 | |
| 5651 | // Remove the last version from the packet so that every truncated |
| 5652 | // version of the packet is invalid, otherwise checking boundaries |
| 5653 | // is annoyingly complicated. |
| 5654 | for (size_t i = 0; i < 4; ++i) { |
| 5655 | packet.back().fragment.pop_back(); |
| 5656 | } |
| 5657 | CheckFramingBoundaries(packet, QUIC_INVALID_VERSION_NEGOTIATION_PACKET); |
| 5658 | } |
| 5659 | |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5660 | TEST_P(QuicFramerTest, ParseIetfRetryPacket) { |
| 5661 | if (!framer_.version().SupportsRetry()) { |
| 5662 | return; |
| 5663 | } |
| 5664 | // IETF RETRY is only sent from client to server. |
| 5665 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5666 | // clang-format off |
| 5667 | unsigned char packet[] = { |
| 5668 | // public flags (long header with packet type RETRY and ODCIL=8) |
| 5669 | 0xF5, |
| 5670 | // version |
| 5671 | QUIC_VERSION_BYTES, |
| 5672 | // connection ID lengths |
| 5673 | 0x05, |
| 5674 | // source connection ID |
| 5675 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 5676 | // original destination connection ID |
| 5677 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5678 | // retry token |
| 5679 | 'H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'i', 's', |
| 5680 | ' ', 'i', 's', ' ', 'R', 'E', 'T', 'R', 'Y', '!', |
| 5681 | }; |
| 5682 | // clang-format on |
| 5683 | |
| 5684 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5685 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5686 | |
| 5687 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5688 | ASSERT_TRUE(visitor_.header_.get()); |
| 5689 | |
| 5690 | ASSERT_TRUE(visitor_.retry_original_connection_id_.get()); |
| 5691 | ASSERT_TRUE(visitor_.retry_new_connection_id_.get()); |
| 5692 | ASSERT_TRUE(visitor_.retry_token_.get()); |
| 5693 | |
| 5694 | EXPECT_EQ(FramerTestConnectionId(), |
| 5695 | *visitor_.retry_original_connection_id_.get()); |
| 5696 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), |
| 5697 | *visitor_.retry_new_connection_id_.get()); |
| 5698 | EXPECT_EQ("Hello this is RETRY!", *visitor_.retry_token_.get()); |
| 5699 | } |
| 5700 | |
| 5701 | TEST_P(QuicFramerTest, RejectIetfRetryPacketAsServer) { |
| 5702 | if (!framer_.version().SupportsRetry()) { |
| 5703 | return; |
| 5704 | } |
| 5705 | // IETF RETRY is only sent from client to server. |
| 5706 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 5707 | // clang-format off |
| 5708 | unsigned char packet[] = { |
| 5709 | // public flags (long header with packet type RETRY and ODCIL=8) |
| 5710 | 0xF5, |
| 5711 | // version |
| 5712 | QUIC_VERSION_BYTES, |
| 5713 | // connection ID lengths |
| 5714 | 0x05, |
| 5715 | // source connection ID |
| 5716 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 5717 | // original destination connection ID |
| 5718 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5719 | // retry token |
| 5720 | 'H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'i', 's', |
| 5721 | ' ', 'i', 's', ' ', 'R', 'E', 'T', 'R', 'Y', '!', |
| 5722 | }; |
| 5723 | // clang-format on |
| 5724 | |
| 5725 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5726 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 5727 | |
| 5728 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
| 5729 | EXPECT_EQ("Client-initiated RETRY is invalid.", framer_.detailed_error()); |
| 5730 | } |
| 5731 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5732 | TEST_P(QuicFramerTest, BuildPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5733 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5734 | QuicPacketHeader header; |
| 5735 | header.destination_connection_id = FramerTestConnectionId(); |
| 5736 | header.reset_flag = false; |
| 5737 | header.version_flag = false; |
| 5738 | header.packet_number = kPacketNumber; |
| 5739 | |
| 5740 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5741 | |
| 5742 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5743 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5744 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5745 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5746 | // connection_id |
| 5747 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5748 | // packet number |
| 5749 | 0x12, 0x34, 0x56, 0x78, |
| 5750 | |
| 5751 | // frame type (padding frame) |
| 5752 | 0x00, |
| 5753 | 0x00, 0x00, 0x00, 0x00 |
| 5754 | }; |
| 5755 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5756 | unsigned char packet44[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5757 | // type (short header, 4 byte packet number) |
| 5758 | 0x32, |
| 5759 | // connection_id |
| 5760 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5761 | // packet number |
| 5762 | 0x12, 0x34, 0x56, 0x78, |
| 5763 | |
| 5764 | // frame type (padding frame) |
| 5765 | 0x00, |
| 5766 | 0x00, 0x00, 0x00, 0x00 |
| 5767 | }; |
| 5768 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5769 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5770 | // type (short header, 4 byte packet number) |
| 5771 | 0x43, |
| 5772 | // connection_id |
| 5773 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5774 | // packet number |
| 5775 | 0x12, 0x34, 0x56, 0x78, |
| 5776 | |
| 5777 | // frame type (padding frame) |
| 5778 | 0x00, |
| 5779 | 0x00, 0x00, 0x00, 0x00 |
| 5780 | }; |
| 5781 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5782 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5783 | // type (short header, 4 byte packet number) |
| 5784 | 0x43, |
| 5785 | // connection_id |
| 5786 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5787 | // packet number |
| 5788 | 0x12, 0x34, 0x56, 0x78, |
| 5789 | |
| 5790 | // frame type (padding frame) |
| 5791 | 0x00, |
| 5792 | 0x00, 0x00, 0x00, 0x00 |
| 5793 | }; |
| 5794 | // clang-format on |
| 5795 | |
| 5796 | unsigned char* p = packet; |
| 5797 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5798 | p = packet99; |
| 5799 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 5800 | p = packet46; |
| 5801 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5802 | p = packet44; |
| 5803 | } |
| 5804 | |
| 5805 | uint64_t header_size = GetPacketHeaderSize( |
| 5806 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 5807 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 5808 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 5809 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5810 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5811 | |
| 5812 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5813 | ASSERT_TRUE(data != nullptr); |
| 5814 | |
| 5815 | test::CompareCharArraysWithHexError( |
| 5816 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 5817 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 5818 | : QUIC_ARRAYSIZE(packet)); |
| 5819 | } |
| 5820 | |
| 5821 | TEST_P(QuicFramerTest, BuildStreamFramePacketWithNewPaddingFrame) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5822 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5823 | QuicPacketHeader header; |
| 5824 | header.destination_connection_id = FramerTestConnectionId(); |
| 5825 | header.reset_flag = false; |
| 5826 | header.version_flag = false; |
| 5827 | header.packet_number = kPacketNumber; |
| 5828 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
| 5829 | QuicStringPiece("hello world!")); |
| 5830 | QuicPaddingFrame padding_frame(2); |
| 5831 | QuicFrames frames = {QuicFrame(padding_frame), QuicFrame(stream_frame), |
| 5832 | QuicFrame(padding_frame)}; |
| 5833 | |
| 5834 | // clang-format off |
| 5835 | unsigned char packet[] = { |
| 5836 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5837 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5838 | // connection_id |
| 5839 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5840 | // packet number |
| 5841 | 0x12, 0x34, 0x56, 0x78, |
| 5842 | |
| 5843 | // paddings |
| 5844 | 0x00, 0x00, |
| 5845 | // frame type (stream frame with fin) |
| 5846 | 0xFF, |
| 5847 | // stream id |
| 5848 | 0x01, 0x02, 0x03, 0x04, |
| 5849 | // offset |
| 5850 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5851 | 0x32, 0x10, 0x76, 0x54, |
| 5852 | // data length |
| 5853 | 0x00, 0x0c, |
| 5854 | // data |
| 5855 | 'h', 'e', 'l', 'l', |
| 5856 | 'o', ' ', 'w', 'o', |
| 5857 | 'r', 'l', 'd', '!', |
| 5858 | // paddings |
| 5859 | 0x00, 0x00, |
| 5860 | }; |
| 5861 | |
| 5862 | unsigned char packet44[] = { |
| 5863 | // type (short header, 4 byte packet number) |
| 5864 | 0x32, |
| 5865 | // connection_id |
| 5866 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5867 | // packet number |
| 5868 | 0x12, 0x34, 0x56, 0x78, |
| 5869 | |
| 5870 | // paddings |
| 5871 | 0x00, 0x00, |
| 5872 | // frame type (stream frame with fin) |
| 5873 | 0xFF, |
| 5874 | // stream id |
| 5875 | 0x01, 0x02, 0x03, 0x04, |
| 5876 | // offset |
| 5877 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5878 | 0x32, 0x10, 0x76, 0x54, |
| 5879 | // data length |
| 5880 | 0x00, 0x0c, |
| 5881 | // data |
| 5882 | 'h', 'e', 'l', 'l', |
| 5883 | 'o', ' ', 'w', 'o', |
| 5884 | 'r', 'l', 'd', '!', |
| 5885 | // paddings |
| 5886 | 0x00, 0x00, |
| 5887 | }; |
| 5888 | |
| 5889 | unsigned char packet46[] = { |
| 5890 | // type (short header, 4 byte packet number) |
| 5891 | 0x43, |
| 5892 | // connection_id |
| 5893 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5894 | // packet number |
| 5895 | 0x12, 0x34, 0x56, 0x78, |
| 5896 | |
| 5897 | // paddings |
| 5898 | 0x00, 0x00, |
| 5899 | // frame type (stream frame with fin) |
| 5900 | 0xFF, |
| 5901 | // stream id |
| 5902 | 0x01, 0x02, 0x03, 0x04, |
| 5903 | // offset |
| 5904 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5905 | 0x32, 0x10, 0x76, 0x54, |
| 5906 | // data length |
| 5907 | 0x00, 0x0c, |
| 5908 | // data |
| 5909 | 'h', 'e', 'l', 'l', |
| 5910 | 'o', ' ', 'w', 'o', |
| 5911 | 'r', 'l', 'd', '!', |
| 5912 | // paddings |
| 5913 | 0x00, 0x00, |
| 5914 | }; |
| 5915 | |
| 5916 | unsigned char packet99[] = { |
| 5917 | // type (short header, 4 byte packet number) |
| 5918 | 0x43, |
| 5919 | // connection_id |
| 5920 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5921 | // packet number |
| 5922 | 0x12, 0x34, 0x56, 0x78, |
| 5923 | |
| 5924 | // paddings |
| 5925 | 0x00, 0x00, |
| 5926 | // frame type (IETF_STREAM with FIN, LEN, and OFFSET bits set) |
| 5927 | 0x08 | 0x01 | 0x02 | 0x04, |
| 5928 | // stream id |
| 5929 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 5930 | // offset |
| 5931 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 5932 | 0x32, 0x10, 0x76, 0x54, |
| 5933 | // data length |
| 5934 | kVarInt62OneByte + 0x0c, |
| 5935 | // data |
| 5936 | 'h', 'e', 'l', 'l', |
| 5937 | 'o', ' ', 'w', 'o', |
| 5938 | 'r', 'l', 'd', '!', |
| 5939 | // paddings |
| 5940 | 0x00, 0x00, |
| 5941 | }; |
| 5942 | // clang-format on |
| 5943 | |
| 5944 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5945 | ASSERT_TRUE(data != nullptr); |
| 5946 | |
| 5947 | unsigned char* p = packet; |
| 5948 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 5949 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5950 | p = packet99; |
| 5951 | p_size = QUIC_ARRAYSIZE(packet99); |
| 5952 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 5953 | p = packet46; |
| 5954 | p_size = QUIC_ARRAYSIZE(packet46); |
| 5955 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5956 | p = packet44; |
| 5957 | p_size = QUIC_ARRAYSIZE(packet44); |
| 5958 | } |
| 5959 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 5960 | |
| 5961 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 5962 | data->length(), AsChars(p), p_size); |
| 5963 | } |
| 5964 | |
| 5965 | TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5966 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5967 | QuicPacketHeader header; |
| 5968 | header.destination_connection_id = FramerTestConnectionId(); |
| 5969 | header.reset_flag = false; |
| 5970 | header.version_flag = false; |
| 5971 | header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; |
| 5972 | header.packet_number = kPacketNumber; |
| 5973 | |
| 5974 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5975 | |
| 5976 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5977 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5978 | // public flags (8 byte connection_id and 4 byte packet number) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5979 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5980 | // connection_id |
| 5981 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5982 | // packet number |
| 5983 | 0x12, 0x34, 0x56, 0x78, |
| 5984 | |
| 5985 | // frame type (padding frame) |
| 5986 | 0x00, |
| 5987 | 0x00, 0x00, 0x00, 0x00 |
| 5988 | }; |
| 5989 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5990 | unsigned char packet44[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5991 | // type (short header, 4 byte packet number) |
| 5992 | 0x32, |
| 5993 | // connection_id |
| 5994 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5995 | // packet number |
| 5996 | 0x12, 0x34, 0x56, 0x78, |
| 5997 | |
| 5998 | // frame type (padding frame) |
| 5999 | 0x00, |
| 6000 | 0x00, 0x00, 0x00, 0x00 |
| 6001 | }; |
| 6002 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6003 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6004 | // type (short header, 4 byte packet number) |
| 6005 | 0x43, |
| 6006 | // connection_id |
| 6007 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6008 | // packet number |
| 6009 | 0x12, 0x34, 0x56, 0x78, |
| 6010 | |
| 6011 | // frame type (padding frame) |
| 6012 | 0x00, |
| 6013 | 0x00, 0x00, 0x00, 0x00 |
| 6014 | }; |
| 6015 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6016 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6017 | // type (short header, 4 byte packet number) |
| 6018 | 0x43, |
| 6019 | // connection_id |
| 6020 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6021 | // packet number |
| 6022 | 0x12, 0x34, 0x56, 0x78, |
| 6023 | |
| 6024 | // frame type (padding frame) |
| 6025 | 0x00, |
| 6026 | 0x00, 0x00, 0x00, 0x00 |
| 6027 | }; |
| 6028 | // clang-format on |
| 6029 | |
| 6030 | unsigned char* p = packet; |
| 6031 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6032 | p = packet99; |
| 6033 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6034 | p = packet46; |
| 6035 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6036 | p = packet44; |
| 6037 | } |
| 6038 | |
| 6039 | uint64_t header_size = GetPacketHeaderSize( |
| 6040 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 6041 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 6042 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 6043 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6044 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6045 | |
| 6046 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6047 | ASSERT_TRUE(data != nullptr); |
| 6048 | |
| 6049 | test::CompareCharArraysWithHexError( |
| 6050 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 6051 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 6052 | : QUIC_ARRAYSIZE(packet)); |
| 6053 | } |
| 6054 | |
| 6055 | TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6056 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6057 | QuicPacketHeader header; |
| 6058 | header.destination_connection_id = FramerTestConnectionId(); |
| 6059 | header.reset_flag = false; |
| 6060 | header.version_flag = false; |
| 6061 | header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; |
| 6062 | header.packet_number = kPacketNumber; |
| 6063 | |
| 6064 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 6065 | |
| 6066 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6067 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6068 | // public flags (8 byte connection_id and 2 byte packet number) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6069 | 0x1C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6070 | // connection_id |
| 6071 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6072 | // packet number |
| 6073 | 0x56, 0x78, |
| 6074 | |
| 6075 | // frame type (padding frame) |
| 6076 | 0x00, |
| 6077 | 0x00, 0x00, 0x00, 0x00 |
| 6078 | }; |
| 6079 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6080 | unsigned char packet44[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6081 | // type (short header, 2 byte packet number) |
| 6082 | 0x31, |
| 6083 | // connection_id |
| 6084 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6085 | // packet number |
| 6086 | 0x56, 0x78, |
| 6087 | |
| 6088 | // frame type (padding frame) |
| 6089 | 0x00, |
| 6090 | 0x00, 0x00, 0x00, 0x00 |
| 6091 | }; |
| 6092 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6093 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6094 | // type (short header, 2 byte packet number) |
| 6095 | 0x41, |
| 6096 | // connection_id |
| 6097 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6098 | // packet number |
| 6099 | 0x56, 0x78, |
| 6100 | |
| 6101 | // frame type (padding frame) |
| 6102 | 0x00, |
| 6103 | 0x00, 0x00, 0x00, 0x00 |
| 6104 | }; |
| 6105 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6106 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6107 | // type (short header, 2 byte packet number) |
| 6108 | 0x41, |
| 6109 | // connection_id |
| 6110 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6111 | // packet number |
| 6112 | 0x56, 0x78, |
| 6113 | |
| 6114 | // frame type (padding frame) |
| 6115 | 0x00, |
| 6116 | 0x00, 0x00, 0x00, 0x00 |
| 6117 | }; |
| 6118 | // clang-format on |
| 6119 | |
| 6120 | unsigned char* p = packet; |
| 6121 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6122 | p = packet99; |
| 6123 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6124 | p = packet46; |
| 6125 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6126 | p = packet44; |
| 6127 | } |
| 6128 | |
| 6129 | uint64_t header_size = GetPacketHeaderSize( |
| 6130 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 6131 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 6132 | !kIncludeDiversificationNonce, PACKET_2BYTE_PACKET_NUMBER, |
| 6133 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6134 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6135 | |
| 6136 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6137 | ASSERT_TRUE(data != nullptr); |
| 6138 | |
| 6139 | test::CompareCharArraysWithHexError( |
| 6140 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 6141 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 6142 | : QUIC_ARRAYSIZE(packet)); |
| 6143 | } |
| 6144 | |
| 6145 | TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6146 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6147 | QuicPacketHeader header; |
| 6148 | header.destination_connection_id = FramerTestConnectionId(); |
| 6149 | header.reset_flag = false; |
| 6150 | header.version_flag = false; |
| 6151 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 6152 | header.packet_number = kPacketNumber; |
| 6153 | |
| 6154 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 6155 | |
| 6156 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6157 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6158 | // public flags (8 byte connection_id and 1 byte packet number) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6159 | 0x0C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6160 | // connection_id |
| 6161 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6162 | // packet number |
| 6163 | 0x78, |
| 6164 | |
| 6165 | // frame type (padding frame) |
| 6166 | 0x00, |
| 6167 | 0x00, 0x00, 0x00, 0x00 |
| 6168 | }; |
| 6169 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6170 | unsigned char packet44[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6171 | // type (short header, 1 byte packet number) |
| 6172 | 0x30, |
| 6173 | // connection_id |
| 6174 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6175 | // packet number |
| 6176 | 0x78, |
| 6177 | |
| 6178 | // frame type (padding frame) |
| 6179 | 0x00, |
| 6180 | 0x00, 0x00, 0x00, 0x00 |
| 6181 | }; |
| 6182 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6183 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6184 | // type (short header, 1 byte packet number) |
| 6185 | 0x40, |
| 6186 | // connection_id |
| 6187 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6188 | // packet number |
| 6189 | 0x78, |
| 6190 | |
| 6191 | // frame type (padding frame) |
| 6192 | 0x00, |
| 6193 | 0x00, 0x00, 0x00, 0x00 |
| 6194 | }; |
| 6195 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6196 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6197 | // type (short header, 1 byte packet number) |
| 6198 | 0x40, |
| 6199 | // connection_id |
| 6200 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6201 | // packet number |
| 6202 | 0x78, |
| 6203 | |
| 6204 | // frame type (padding frame) |
| 6205 | 0x00, |
| 6206 | 0x00, 0x00, 0x00, 0x00 |
| 6207 | }; |
| 6208 | // clang-format on |
| 6209 | |
| 6210 | unsigned char* p = packet; |
| 6211 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6212 | p = packet99; |
| 6213 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6214 | p = packet46; |
| 6215 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6216 | p = packet44; |
| 6217 | } |
| 6218 | |
| 6219 | uint64_t header_size = GetPacketHeaderSize( |
| 6220 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 6221 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 6222 | !kIncludeDiversificationNonce, PACKET_1BYTE_PACKET_NUMBER, |
| 6223 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6224 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6225 | |
| 6226 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6227 | ASSERT_TRUE(data != nullptr); |
| 6228 | |
| 6229 | test::CompareCharArraysWithHexError( |
| 6230 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 6231 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 6232 | : QUIC_ARRAYSIZE(packet)); |
| 6233 | } |
| 6234 | |
| 6235 | TEST_P(QuicFramerTest, BuildStreamFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6236 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6237 | QuicPacketHeader header; |
| 6238 | header.destination_connection_id = FramerTestConnectionId(); |
| 6239 | header.reset_flag = false; |
| 6240 | header.version_flag = false; |
| 6241 | header.packet_number = kPacketNumber; |
| 6242 | if (QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 6243 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 6244 | } |
| 6245 | |
| 6246 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
| 6247 | QuicStringPiece("hello world!")); |
| 6248 | |
| 6249 | QuicFrames frames = {QuicFrame(stream_frame)}; |
| 6250 | |
| 6251 | // clang-format off |
| 6252 | unsigned char packet[] = { |
| 6253 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6254 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6255 | // connection_id |
| 6256 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6257 | // packet number |
| 6258 | 0x12, 0x34, 0x56, 0x78, |
| 6259 | |
| 6260 | // frame type (stream frame with fin and no length) |
| 6261 | 0xDF, |
| 6262 | // stream id |
| 6263 | 0x01, 0x02, 0x03, 0x04, |
| 6264 | // offset |
| 6265 | 0x3A, 0x98, 0xFE, 0xDC, |
| 6266 | 0x32, 0x10, 0x76, 0x54, |
| 6267 | // data |
| 6268 | 'h', 'e', 'l', 'l', |
| 6269 | 'o', ' ', 'w', 'o', |
| 6270 | 'r', 'l', 'd', '!', |
| 6271 | }; |
| 6272 | |
| 6273 | unsigned char packet44[] = { |
| 6274 | // type (short header, 4 byte packet number) |
| 6275 | 0x32, |
| 6276 | // connection_id |
| 6277 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6278 | // packet number |
| 6279 | 0x12, 0x34, 0x56, 0x78, |
| 6280 | |
| 6281 | // frame type (stream frame with fin and no length) |
| 6282 | 0xDF, |
| 6283 | // stream id |
| 6284 | 0x01, 0x02, 0x03, 0x04, |
| 6285 | // offset |
| 6286 | 0x3A, 0x98, 0xFE, 0xDC, |
| 6287 | 0x32, 0x10, 0x76, 0x54, |
| 6288 | // data |
| 6289 | 'h', 'e', 'l', 'l', |
| 6290 | 'o', ' ', 'w', 'o', |
| 6291 | 'r', 'l', 'd', '!', |
| 6292 | }; |
| 6293 | |
| 6294 | unsigned char packet46[] = { |
| 6295 | // type (short header, 4 byte packet number) |
| 6296 | 0x43, |
| 6297 | // connection_id |
| 6298 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6299 | // packet number |
| 6300 | 0x12, 0x34, 0x56, 0x78, |
| 6301 | |
| 6302 | // frame type (stream frame with fin and no length) |
| 6303 | 0xDF, |
| 6304 | // stream id |
| 6305 | 0x01, 0x02, 0x03, 0x04, |
| 6306 | // offset |
| 6307 | 0x3A, 0x98, 0xFE, 0xDC, |
| 6308 | 0x32, 0x10, 0x76, 0x54, |
| 6309 | // data |
| 6310 | 'h', 'e', 'l', 'l', |
| 6311 | 'o', ' ', 'w', 'o', |
| 6312 | 'r', 'l', 'd', '!', |
| 6313 | }; |
| 6314 | |
| 6315 | unsigned char packet99[] = { |
| 6316 | // type (short header, 4 byte packet number) |
| 6317 | 0x43, |
| 6318 | // connection_id |
| 6319 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6320 | // packet number |
| 6321 | 0x12, 0x34, 0x56, 0x78, |
| 6322 | |
| 6323 | // frame type (IETF_STREAM frame with FIN and OFFSET, no length) |
| 6324 | 0x08 | 0x01 | 0x04, |
| 6325 | // stream id |
| 6326 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 6327 | // offset |
| 6328 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6329 | 0x32, 0x10, 0x76, 0x54, |
| 6330 | // data |
| 6331 | 'h', 'e', 'l', 'l', |
| 6332 | 'o', ' ', 'w', 'o', |
| 6333 | 'r', 'l', 'd', '!', |
| 6334 | }; |
| 6335 | // clang-format on |
| 6336 | |
| 6337 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6338 | ASSERT_TRUE(data != nullptr); |
| 6339 | |
| 6340 | unsigned char* p = packet; |
| 6341 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6342 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6343 | p = packet99; |
| 6344 | p_size = QUIC_ARRAYSIZE(packet99); |
| 6345 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6346 | p = packet46; |
| 6347 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6348 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6349 | p = packet44; |
| 6350 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6351 | } |
| 6352 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6353 | data->length(), AsChars(p), p_size); |
| 6354 | } |
| 6355 | |
| 6356 | TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) { |
| 6357 | QuicPacketHeader header; |
| 6358 | header.destination_connection_id = FramerTestConnectionId(); |
| 6359 | header.reset_flag = false; |
| 6360 | header.version_flag = true; |
| 6361 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6362 | header.long_packet_type = ZERO_RTT_PROTECTED; |
| 6363 | } |
| 6364 | header.packet_number = kPacketNumber; |
| 6365 | if (QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 6366 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 6367 | } |
| 6368 | |
| 6369 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
| 6370 | QuicStringPiece("hello world!")); |
| 6371 | QuicFrames frames = {QuicFrame(stream_frame)}; |
| 6372 | |
| 6373 | // clang-format off |
| 6374 | unsigned char packet[] = { |
| 6375 | // public flags (version, 8 byte connection_id) |
| 6376 | 0x2D, |
| 6377 | // connection_id |
| 6378 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6379 | // version tag |
| 6380 | QUIC_VERSION_BYTES, |
| 6381 | // packet number |
| 6382 | 0x12, 0x34, 0x56, 0x78, |
| 6383 | |
| 6384 | // frame type (stream frame with fin and no length) |
| 6385 | 0xDF, |
| 6386 | // stream id |
| 6387 | 0x01, 0x02, 0x03, 0x04, |
| 6388 | // offset |
| 6389 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6390 | // data |
| 6391 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6392 | }; |
| 6393 | |
| 6394 | unsigned char packet44[] = { |
| 6395 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6396 | 0xFC, |
| 6397 | // version tag |
| 6398 | QUIC_VERSION_BYTES, |
| 6399 | // connection_id length |
| 6400 | 0x50, |
| 6401 | // connection_id |
| 6402 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6403 | // packet number |
| 6404 | 0x12, 0x34, 0x56, 0x78, |
| 6405 | |
| 6406 | // frame type (stream frame with fin and no length) |
| 6407 | 0xDF, |
| 6408 | // stream id |
| 6409 | 0x01, 0x02, 0x03, 0x04, |
| 6410 | // offset |
| 6411 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6412 | // data |
| 6413 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6414 | }; |
| 6415 | |
| 6416 | unsigned char packet46[] = { |
| 6417 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6418 | 0xD3, |
| 6419 | // version tag |
| 6420 | QUIC_VERSION_BYTES, |
| 6421 | // connection_id length |
| 6422 | 0x50, |
| 6423 | // connection_id |
| 6424 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6425 | // packet number |
| 6426 | 0x12, 0x34, 0x56, 0x78, |
| 6427 | |
| 6428 | // frame type (stream frame with fin and no length) |
| 6429 | 0xDF, |
| 6430 | // stream id |
| 6431 | 0x01, 0x02, 0x03, 0x04, |
| 6432 | // offset |
| 6433 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6434 | // data |
| 6435 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6436 | }; |
| 6437 | |
| 6438 | unsigned char packet99[] = { |
| 6439 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6440 | 0xD3, |
| 6441 | // version tag |
| 6442 | QUIC_VERSION_BYTES, |
| 6443 | // connection_id length |
| 6444 | 0x50, |
| 6445 | // connection_id |
| 6446 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6447 | // length |
| 6448 | 0x40, 0x1D, |
| 6449 | // packet number |
| 6450 | 0x12, 0x34, 0x56, 0x78, |
| 6451 | |
| 6452 | // frame type (IETF_STREAM frame with fin and offset, no length) |
| 6453 | 0x08 | 0x01 | 0x04, |
| 6454 | // stream id |
| 6455 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 6456 | // offset |
| 6457 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6458 | // data |
| 6459 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6460 | }; |
| 6461 | // clang-format on |
| 6462 | |
| 6463 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 6464 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6465 | ASSERT_TRUE(data != nullptr); |
| 6466 | |
| 6467 | unsigned char* p = packet; |
| 6468 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6469 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6470 | p = packet99; |
| 6471 | p_size = QUIC_ARRAYSIZE(packet99); |
| 6472 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6473 | p = packet46; |
| 6474 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6475 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6476 | p = packet44; |
| 6477 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6478 | } |
| 6479 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6480 | data->length(), AsChars(p), p_size); |
| 6481 | } |
| 6482 | |
| 6483 | TEST_P(QuicFramerTest, BuildCryptoFramePacket) { |
| 6484 | if (framer_.transport_version() < QUIC_VERSION_99) { |
| 6485 | // CRYPTO frames aren't supported prior to v46. |
| 6486 | return; |
| 6487 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6488 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6489 | QuicPacketHeader header; |
| 6490 | header.destination_connection_id = FramerTestConnectionId(); |
| 6491 | header.reset_flag = false; |
| 6492 | header.version_flag = false; |
| 6493 | header.packet_number = kPacketNumber; |
| 6494 | |
| 6495 | SimpleDataProducer data_producer; |
| 6496 | framer_.set_data_producer(&data_producer); |
| 6497 | |
| 6498 | QuicStringPiece crypto_frame_contents("hello world!"); |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 6499 | QuicCryptoFrame crypto_frame(ENCRYPTION_INITIAL, kStreamOffset, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6500 | crypto_frame_contents.length()); |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 6501 | data_producer.SaveCryptoData(ENCRYPTION_INITIAL, kStreamOffset, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6502 | crypto_frame_contents); |
| 6503 | |
| 6504 | QuicFrames frames = {QuicFrame(&crypto_frame)}; |
| 6505 | |
| 6506 | // clang-format off |
| 6507 | unsigned char packet[] = { |
| 6508 | // type (short header, 4 byte packet number) |
| 6509 | 0x43, |
| 6510 | // connection_id |
| 6511 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6512 | // packet number |
| 6513 | 0x12, 0x34, 0x56, 0x78, |
| 6514 | |
| 6515 | // frame type (IETF_CRYPTO frame) |
| 6516 | 0x06, |
| 6517 | // offset |
| 6518 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6519 | 0x32, 0x10, 0x76, 0x54, |
| 6520 | // length |
| 6521 | kVarInt62OneByte + 12, |
| 6522 | // data |
| 6523 | 'h', 'e', 'l', 'l', |
| 6524 | 'o', ' ', 'w', 'o', |
| 6525 | 'r', 'l', 'd', '!', |
| 6526 | }; |
| 6527 | // clang-format on |
| 6528 | |
| 6529 | size_t packet_size = QUIC_ARRAYSIZE(packet); |
| 6530 | |
| 6531 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6532 | ASSERT_TRUE(data != nullptr); |
| 6533 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6534 | data->length(), AsChars(packet), |
| 6535 | packet_size); |
| 6536 | } |
| 6537 | |
| 6538 | TEST_P(QuicFramerTest, CryptoFrame) { |
| 6539 | if (framer_.transport_version() < QUIC_VERSION_99) { |
| 6540 | // CRYPTO frames aren't supported prior to v46. |
| 6541 | return; |
| 6542 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 6543 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6544 | |
| 6545 | // clang-format off |
| 6546 | PacketFragments packet = { |
| 6547 | // type (short header, 4 byte packet number) |
| 6548 | {"", |
| 6549 | {0x43}}, |
| 6550 | // connection_id |
| 6551 | {"", |
| 6552 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 6553 | // packet number |
| 6554 | {"", |
| 6555 | {0x12, 0x34, 0x56, 0x78}}, |
| 6556 | // frame type (IETF_CRYPTO frame) |
| 6557 | {"", |
| 6558 | {0x06}}, |
| 6559 | // offset |
| 6560 | {"", |
| 6561 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6562 | 0x32, 0x10, 0x76, 0x54}}, |
| 6563 | // data length |
| 6564 | {"Invalid data length.", |
| 6565 | {kVarInt62OneByte + 12}}, |
| 6566 | // data |
| 6567 | {"Unable to read frame data.", |
| 6568 | {'h', 'e', 'l', 'l', |
| 6569 | 'o', ' ', 'w', 'o', |
| 6570 | 'r', 'l', 'd', '!'}}, |
| 6571 | }; |
| 6572 | // clang-format on |
| 6573 | |
| 6574 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 6575 | AssemblePacketFromFragments(packet)); |
| 6576 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 6577 | |
| 6578 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 6579 | ASSERT_TRUE(visitor_.header_.get()); |
| 6580 | EXPECT_TRUE(CheckDecryption( |
| 6581 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 6582 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 6583 | ASSERT_EQ(1u, visitor_.crypto_frames_.size()); |
| 6584 | QuicCryptoFrame* frame = visitor_.crypto_frames_[0].get(); |
| 6585 | EXPECT_EQ(kStreamOffset, frame->offset); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 6586 | EXPECT_EQ("hello world!", |
| 6587 | std::string(frame->data_buffer, frame->data_length)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6588 | |
| 6589 | CheckFramingBoundaries(packet, QUIC_INVALID_FRAME_DATA); |
| 6590 | } |
| 6591 | |
| 6592 | TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { |
| 6593 | // clang-format off |
| 6594 | unsigned char packet[] = { |
| 6595 | // public flags (version, 8 byte connection_id) |
| 6596 | 0x0D, |
| 6597 | // connection_id |
| 6598 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6599 | // version tag |
| 6600 | QUIC_VERSION_BYTES, |
| 6601 | }; |
dschinazi | 9e92fb3 | 2019-05-08 14:47:24 -0700 | [diff] [blame] | 6602 | unsigned char type44 = 0x80; |
| 6603 | if (GetQuicReloadableFlag(quic_send_version_negotiation_fixed_bit)) { |
| 6604 | type44 = 0xC0; |
| 6605 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6606 | unsigned char packet44[] = { |
| 6607 | // type (long header) |
dschinazi | 9e92fb3 | 2019-05-08 14:47:24 -0700 | [diff] [blame] | 6608 | type44, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6609 | // version tag |
| 6610 | 0x00, 0x00, 0x00, 0x00, |
| 6611 | // connection_id length |
| 6612 | 0x05, |
| 6613 | // connection_id |
| 6614 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6615 | // version tag |
| 6616 | QUIC_VERSION_BYTES, |
| 6617 | }; |
| 6618 | // clang-format on |
| 6619 | unsigned char* p = packet; |
| 6620 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6621 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6622 | p = packet44; |
| 6623 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6624 | } |
| 6625 | |
| 6626 | QuicConnectionId connection_id = FramerTestConnectionId(); |
| 6627 | std::unique_ptr<QuicEncryptedPacket> data( |
| 6628 | framer_.BuildVersionNegotiationPacket( |
| 6629 | connection_id, framer_.transport_version() > QUIC_VERSION_43, |
| 6630 | SupportedVersions(GetParam()))); |
| 6631 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6632 | data->length(), AsChars(p), p_size); |
| 6633 | } |
| 6634 | |
| 6635 | TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlock) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6636 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6637 | QuicPacketHeader header; |
| 6638 | header.destination_connection_id = FramerTestConnectionId(); |
| 6639 | header.reset_flag = false; |
| 6640 | header.version_flag = false; |
| 6641 | header.packet_number = kPacketNumber; |
| 6642 | |
| 6643 | // Use kSmallLargestObserved to make this test finished in a short time. |
| 6644 | QuicAckFrame ack_frame = InitAckFrame(kSmallLargestObserved); |
| 6645 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6646 | |
| 6647 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6648 | |
| 6649 | // clang-format off |
| 6650 | unsigned char packet[] = { |
| 6651 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6652 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6653 | // connection_id |
| 6654 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6655 | // packet number |
| 6656 | 0x12, 0x34, 0x56, 0x78, |
| 6657 | |
| 6658 | // frame type (ack frame) |
| 6659 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 6660 | 0x45, |
| 6661 | // largest acked |
| 6662 | 0x12, 0x34, |
| 6663 | // Zero delta time. |
| 6664 | 0x00, 0x00, |
| 6665 | // first ack block length. |
| 6666 | 0x12, 0x34, |
| 6667 | // num timestamps. |
| 6668 | 0x00, |
| 6669 | }; |
| 6670 | |
| 6671 | unsigned char packet44[] = { |
| 6672 | // type (short header, 4 byte packet number) |
| 6673 | 0x32, |
| 6674 | // connection_id |
| 6675 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6676 | // packet number |
| 6677 | 0x12, 0x34, 0x56, 0x78, |
| 6678 | |
| 6679 | // frame type (ack frame) |
| 6680 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 6681 | 0x45, |
| 6682 | // largest acked |
| 6683 | 0x12, 0x34, |
| 6684 | // Zero delta time. |
| 6685 | 0x00, 0x00, |
| 6686 | // first ack block length. |
| 6687 | 0x12, 0x34, |
| 6688 | // num timestamps. |
| 6689 | 0x00, |
| 6690 | }; |
| 6691 | |
| 6692 | unsigned char packet46[] = { |
| 6693 | // type (short header, 4 byte packet number) |
| 6694 | 0x43, |
| 6695 | // connection_id |
| 6696 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6697 | // packet number |
| 6698 | 0x12, 0x34, 0x56, 0x78, |
| 6699 | |
| 6700 | // frame type (ack frame) |
| 6701 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 6702 | 0x45, |
| 6703 | // largest acked |
| 6704 | 0x12, 0x34, |
| 6705 | // Zero delta time. |
| 6706 | 0x00, 0x00, |
| 6707 | // first ack block length. |
| 6708 | 0x12, 0x34, |
| 6709 | // num timestamps. |
| 6710 | 0x00, |
| 6711 | }; |
| 6712 | |
| 6713 | unsigned char packet99[] = { |
| 6714 | // type (short header, 4 byte packet number) |
| 6715 | 0x43, |
| 6716 | // connection_id |
| 6717 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6718 | // packet number |
| 6719 | 0x12, 0x34, 0x56, 0x78, |
| 6720 | |
| 6721 | // frame type (IETF_ACK frame) |
| 6722 | 0x02, |
| 6723 | // largest acked |
| 6724 | kVarInt62TwoBytes + 0x12, 0x34, |
| 6725 | // Zero delta time. |
| 6726 | kVarInt62OneByte + 0x00, |
| 6727 | // Number of additional ack blocks. |
| 6728 | kVarInt62OneByte + 0x00, |
| 6729 | // first ack block length. |
| 6730 | kVarInt62TwoBytes + 0x12, 0x33, |
| 6731 | }; |
| 6732 | // clang-format on |
| 6733 | unsigned char* p = packet; |
| 6734 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6735 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6736 | p = packet99; |
| 6737 | p_size = QUIC_ARRAYSIZE(packet99); |
| 6738 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6739 | p = packet46; |
| 6740 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6741 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6742 | p = packet44; |
| 6743 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6744 | } |
| 6745 | |
| 6746 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6747 | ASSERT_TRUE(data != nullptr); |
| 6748 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6749 | data->length(), AsChars(p), p_size); |
| 6750 | } |
| 6751 | |
| 6752 | TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlockMaxLength) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6753 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6754 | QuicPacketHeader header; |
| 6755 | header.destination_connection_id = FramerTestConnectionId(); |
| 6756 | header.reset_flag = false; |
| 6757 | header.version_flag = false; |
| 6758 | header.packet_number = kPacketNumber; |
| 6759 | |
| 6760 | QuicAckFrame ack_frame = InitAckFrame(kPacketNumber); |
| 6761 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6762 | |
| 6763 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6764 | |
| 6765 | // clang-format off |
| 6766 | unsigned char packet[] = { |
| 6767 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6768 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6769 | // connection_id |
| 6770 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6771 | // packet number |
| 6772 | 0x12, 0x34, 0x56, 0x78, |
| 6773 | |
| 6774 | // frame type (ack frame) |
| 6775 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 6776 | 0x4A, |
| 6777 | // largest acked |
| 6778 | 0x12, 0x34, 0x56, 0x78, |
| 6779 | // Zero delta time. |
| 6780 | 0x00, 0x00, |
| 6781 | // first ack block length. |
| 6782 | 0x12, 0x34, 0x56, 0x78, |
| 6783 | // num timestamps. |
| 6784 | 0x00, |
| 6785 | }; |
| 6786 | |
| 6787 | unsigned char packet44[] = { |
| 6788 | // type (short header, 4 byte packet number) |
| 6789 | 0x32, |
| 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 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 6797 | 0x4A, |
| 6798 | // largest acked |
| 6799 | 0x12, 0x34, 0x56, 0x78, |
| 6800 | // Zero delta time. |
| 6801 | 0x00, 0x00, |
| 6802 | // first ack block length. |
| 6803 | 0x12, 0x34, 0x56, 0x78, |
| 6804 | // num timestamps. |
| 6805 | 0x00, |
| 6806 | }; |
| 6807 | |
| 6808 | unsigned char packet46[] = { |
| 6809 | // type (short header, 4 byte packet number) |
| 6810 | 0x43, |
| 6811 | // connection_id |
| 6812 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6813 | // packet number |
| 6814 | 0x12, 0x34, 0x56, 0x78, |
| 6815 | |
| 6816 | // frame type (ack frame) |
| 6817 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 6818 | 0x4A, |
| 6819 | // largest acked |
| 6820 | 0x12, 0x34, 0x56, 0x78, |
| 6821 | // Zero delta time. |
| 6822 | 0x00, 0x00, |
| 6823 | // first ack block length. |
| 6824 | 0x12, 0x34, 0x56, 0x78, |
| 6825 | // num timestamps. |
| 6826 | 0x00, |
| 6827 | }; |
| 6828 | |
| 6829 | |
| 6830 | unsigned char packet99[] = { |
| 6831 | // type (short header, 4 byte packet number) |
| 6832 | 0x43, |
| 6833 | // connection_id |
| 6834 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6835 | // packet number |
| 6836 | 0x12, 0x34, 0x56, 0x78, |
| 6837 | |
| 6838 | // frame type (IETF_ACK frame) |
| 6839 | 0x02, |
| 6840 | // largest acked |
| 6841 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 6842 | // Zero delta time. |
| 6843 | kVarInt62OneByte + 0x00, |
| 6844 | // Nr. of additional ack blocks |
| 6845 | kVarInt62OneByte + 0x00, |
| 6846 | // first ack block length. |
| 6847 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 6848 | }; |
| 6849 | // clang-format on |
| 6850 | unsigned char* p = packet; |
| 6851 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6852 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6853 | p = packet99; |
| 6854 | p_size = QUIC_ARRAYSIZE(packet99); |
| 6855 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6856 | p = packet46; |
| 6857 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6858 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6859 | p = packet44; |
| 6860 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6861 | } |
| 6862 | |
| 6863 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6864 | ASSERT_TRUE(data != nullptr); |
| 6865 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6866 | data->length(), AsChars(p), p_size); |
| 6867 | } |
| 6868 | |
| 6869 | TEST_P(QuicFramerTest, BuildAckFramePacketMultipleAckBlocks) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6870 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6871 | QuicPacketHeader header; |
| 6872 | header.destination_connection_id = FramerTestConnectionId(); |
| 6873 | header.reset_flag = false; |
| 6874 | header.version_flag = false; |
| 6875 | header.packet_number = kPacketNumber; |
| 6876 | |
| 6877 | // Use kSmallLargestObserved to make this test finished in a short time. |
| 6878 | QuicAckFrame ack_frame = |
| 6879 | InitAckFrame({{QuicPacketNumber(1), QuicPacketNumber(5)}, |
| 6880 | {QuicPacketNumber(10), QuicPacketNumber(500)}, |
| 6881 | {QuicPacketNumber(900), kSmallMissingPacket}, |
| 6882 | {kSmallMissingPacket + 1, kSmallLargestObserved + 1}}); |
| 6883 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6884 | |
| 6885 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6886 | |
| 6887 | // clang-format off |
| 6888 | unsigned char packet[] = { |
| 6889 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6890 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6891 | // connection_id |
| 6892 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6893 | // packet number |
| 6894 | 0x12, 0x34, 0x56, 0x78, |
| 6895 | |
| 6896 | // frame type (ack frame) |
| 6897 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6898 | 0x65, |
| 6899 | // largest acked |
| 6900 | 0x12, 0x34, |
| 6901 | // Zero delta time. |
| 6902 | 0x00, 0x00, |
| 6903 | // num ack blocks ranges. |
| 6904 | 0x04, |
| 6905 | // first ack block length. |
| 6906 | 0x00, 0x01, |
| 6907 | // gap to next block. |
| 6908 | 0x01, |
| 6909 | // ack block length. |
| 6910 | 0x0e, 0xaf, |
| 6911 | // gap to next block. |
| 6912 | 0xff, |
| 6913 | // ack block length. |
| 6914 | 0x00, 0x00, |
| 6915 | // gap to next block. |
| 6916 | 0x91, |
| 6917 | // ack block length. |
| 6918 | 0x01, 0xea, |
| 6919 | // gap to next block. |
| 6920 | 0x05, |
| 6921 | // ack block length. |
| 6922 | 0x00, 0x04, |
| 6923 | // num timestamps. |
| 6924 | 0x00, |
| 6925 | }; |
| 6926 | |
| 6927 | unsigned char packet44[] = { |
| 6928 | // type (short header, 4 byte packet number) |
| 6929 | 0x32, |
| 6930 | // connection_id |
| 6931 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6932 | // packet number |
| 6933 | 0x12, 0x34, 0x56, 0x78, |
| 6934 | |
| 6935 | // frame type (ack frame) |
| 6936 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6937 | 0x65, |
| 6938 | // largest acked |
| 6939 | 0x12, 0x34, |
| 6940 | // Zero delta time. |
| 6941 | 0x00, 0x00, |
| 6942 | // num ack blocks ranges. |
| 6943 | 0x04, |
| 6944 | // first ack block length. |
| 6945 | 0x00, 0x01, |
| 6946 | // gap to next block. |
| 6947 | 0x01, |
| 6948 | // ack block length. |
| 6949 | 0x0e, 0xaf, |
| 6950 | // gap to next block. |
| 6951 | 0xff, |
| 6952 | // ack block length. |
| 6953 | 0x00, 0x00, |
| 6954 | // gap to next block. |
| 6955 | 0x91, |
| 6956 | // ack block length. |
| 6957 | 0x01, 0xea, |
| 6958 | // gap to next block. |
| 6959 | 0x05, |
| 6960 | // ack block length. |
| 6961 | 0x00, 0x04, |
| 6962 | // num timestamps. |
| 6963 | 0x00, |
| 6964 | }; |
| 6965 | |
| 6966 | unsigned char packet46[] = { |
| 6967 | // type (short header, 4 byte packet number) |
| 6968 | 0x43, |
| 6969 | // connection_id |
| 6970 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6971 | // packet number |
| 6972 | 0x12, 0x34, 0x56, 0x78, |
| 6973 | |
| 6974 | // frame type (ack frame) |
| 6975 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6976 | 0x65, |
| 6977 | // largest acked |
| 6978 | 0x12, 0x34, |
| 6979 | // Zero delta time. |
| 6980 | 0x00, 0x00, |
| 6981 | // num ack blocks ranges. |
| 6982 | 0x04, |
| 6983 | // first ack block length. |
| 6984 | 0x00, 0x01, |
| 6985 | // gap to next block. |
| 6986 | 0x01, |
| 6987 | // ack block length. |
| 6988 | 0x0e, 0xaf, |
| 6989 | // gap to next block. |
| 6990 | 0xff, |
| 6991 | // ack block length. |
| 6992 | 0x00, 0x00, |
| 6993 | // gap to next block. |
| 6994 | 0x91, |
| 6995 | // ack block length. |
| 6996 | 0x01, 0xea, |
| 6997 | // gap to next block. |
| 6998 | 0x05, |
| 6999 | // ack block length. |
| 7000 | 0x00, 0x04, |
| 7001 | // num timestamps. |
| 7002 | 0x00, |
| 7003 | }; |
| 7004 | |
| 7005 | unsigned char packet99[] = { |
| 7006 | // type (short header, 4 byte packet number) |
| 7007 | 0x43, |
| 7008 | // connection_id |
| 7009 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7010 | // packet number |
| 7011 | 0x12, 0x34, 0x56, 0x78, |
| 7012 | |
| 7013 | // frame type (IETF_ACK frame) |
| 7014 | 0x02, |
| 7015 | // largest acked |
| 7016 | kVarInt62TwoBytes + 0x12, 0x34, |
| 7017 | // Zero delta time. |
| 7018 | kVarInt62OneByte + 0x00, |
| 7019 | // num additional ack blocks. |
| 7020 | kVarInt62OneByte + 0x03, |
| 7021 | // first ack block length. |
| 7022 | kVarInt62OneByte + 0x00, |
| 7023 | |
| 7024 | // gap to next block. |
| 7025 | kVarInt62OneByte + 0x00, |
| 7026 | // ack block length. |
| 7027 | kVarInt62TwoBytes + 0x0e, 0xae, |
| 7028 | |
| 7029 | // gap to next block. |
| 7030 | kVarInt62TwoBytes + 0x01, 0x8f, |
| 7031 | // ack block length. |
| 7032 | kVarInt62TwoBytes + 0x01, 0xe9, |
| 7033 | |
| 7034 | // gap to next block. |
| 7035 | kVarInt62OneByte + 0x04, |
| 7036 | // ack block length. |
| 7037 | kVarInt62OneByte + 0x03, |
| 7038 | }; |
| 7039 | // clang-format on |
| 7040 | unsigned char* p = packet; |
| 7041 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7042 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7043 | p = packet99; |
| 7044 | p_size = QUIC_ARRAYSIZE(packet99); |
| 7045 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7046 | p = packet46; |
| 7047 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7048 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7049 | p = packet44; |
| 7050 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7051 | } |
| 7052 | |
| 7053 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7054 | ASSERT_TRUE(data != nullptr); |
| 7055 | |
| 7056 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7057 | data->length(), AsChars(p), p_size); |
| 7058 | } |
| 7059 | |
| 7060 | TEST_P(QuicFramerTest, BuildAckFramePacketMaxAckBlocks) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7061 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7062 | QuicPacketHeader header; |
| 7063 | header.destination_connection_id = FramerTestConnectionId(); |
| 7064 | header.reset_flag = false; |
| 7065 | header.version_flag = false; |
| 7066 | header.packet_number = kPacketNumber; |
| 7067 | |
| 7068 | // Use kSmallLargestObservedto make this test finished in a short time. |
| 7069 | QuicAckFrame ack_frame; |
| 7070 | ack_frame.largest_acked = kSmallLargestObserved; |
| 7071 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 7072 | // 300 ack blocks. |
| 7073 | for (size_t i = 2; i < 2 * 300; i += 2) { |
| 7074 | ack_frame.packets.Add(QuicPacketNumber(i)); |
| 7075 | } |
| 7076 | ack_frame.packets.AddRange(QuicPacketNumber(600), kSmallLargestObserved + 1); |
| 7077 | |
| 7078 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 7079 | |
| 7080 | // clang-format off |
| 7081 | unsigned char packet[] = { |
| 7082 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7083 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7084 | // connection_id |
| 7085 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7086 | // packet number |
| 7087 | 0x12, 0x34, 0x56, 0x78, |
| 7088 | // frame type (ack frame) |
| 7089 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 7090 | 0x65, |
| 7091 | // largest acked |
| 7092 | 0x12, 0x34, |
| 7093 | // Zero delta time. |
| 7094 | 0x00, 0x00, |
| 7095 | // num ack blocks ranges. |
| 7096 | 0xff, |
| 7097 | // first ack block length. |
| 7098 | 0x0f, 0xdd, |
| 7099 | // 255 = 4 * 63 + 3 |
| 7100 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7101 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7102 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7103 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7104 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7105 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 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 | |
| 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 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 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 | |
| 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 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 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 | |
| 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 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 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 | |
| 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 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 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 | |
| 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 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 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 | |
| 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, |
| 7170 | // num timestamps. |
| 7171 | 0x00, |
| 7172 | }; |
| 7173 | |
| 7174 | unsigned char packet44[] = { |
| 7175 | // type (short header, 4 byte packet number) |
| 7176 | 0x32, |
| 7177 | // connection_id |
| 7178 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7179 | // packet number |
| 7180 | 0x12, 0x34, 0x56, 0x78, |
| 7181 | // frame type (ack frame) |
| 7182 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 7183 | 0x65, |
| 7184 | // largest acked |
| 7185 | 0x12, 0x34, |
| 7186 | // Zero delta time. |
| 7187 | 0x00, 0x00, |
| 7188 | // num ack blocks ranges. |
| 7189 | 0xff, |
| 7190 | // first ack block length. |
| 7191 | 0x0f, 0xdd, |
| 7192 | // 255 = 4 * 63 + 3 |
| 7193 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7194 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7195 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7196 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7197 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7198 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7199 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7200 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7201 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7202 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7203 | |
| 7204 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7205 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7206 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7207 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7208 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7209 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7210 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7211 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7212 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7213 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7214 | |
| 7215 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7216 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7217 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7218 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7219 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7220 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7221 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7222 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7223 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7224 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7225 | |
| 7226 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7227 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7228 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7229 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7230 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7231 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7232 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7233 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7234 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7235 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7236 | |
| 7237 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7238 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7239 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7240 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7241 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7242 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7243 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7244 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7245 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7246 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7247 | |
| 7248 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7249 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7250 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7251 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7252 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7253 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7254 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7255 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7256 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7257 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7258 | |
| 7259 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7260 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7261 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7262 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7263 | // num timestamps. |
| 7264 | 0x00, |
| 7265 | }; |
| 7266 | |
| 7267 | unsigned char packet46[] = { |
| 7268 | // type (short header, 4 byte packet number) |
| 7269 | 0x43, |
| 7270 | // connection_id |
| 7271 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7272 | // packet number |
| 7273 | 0x12, 0x34, 0x56, 0x78, |
| 7274 | // frame type (ack frame) |
| 7275 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 7276 | 0x65, |
| 7277 | // largest acked |
| 7278 | 0x12, 0x34, |
| 7279 | // Zero delta time. |
| 7280 | 0x00, 0x00, |
| 7281 | // num ack blocks ranges. |
| 7282 | 0xff, |
| 7283 | // first ack block length. |
| 7284 | 0x0f, 0xdd, |
| 7285 | // 255 = 4 * 63 + 3 |
| 7286 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7287 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7288 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7289 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7290 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7291 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7292 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7293 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7294 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7295 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7296 | |
| 7297 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7298 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7299 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7300 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7301 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7302 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7303 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7304 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7305 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7306 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7307 | |
| 7308 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7309 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7310 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7311 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7312 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7313 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7314 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7315 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7316 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7317 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7318 | |
| 7319 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7320 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7321 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7322 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7323 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7324 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7325 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7326 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7327 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7328 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7329 | |
| 7330 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7331 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7332 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7333 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7334 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7335 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7336 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7337 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7338 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7339 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7340 | |
| 7341 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7342 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7343 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7344 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7345 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7346 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7347 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7348 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7349 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7350 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7351 | |
| 7352 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7353 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7354 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7355 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7356 | // num timestamps. |
| 7357 | 0x00, |
| 7358 | }; |
| 7359 | |
| 7360 | unsigned char packet99[] = { |
| 7361 | // type (short header, 4 byte packet number) |
| 7362 | 0x43, |
| 7363 | // connection_id |
| 7364 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7365 | // packet number |
| 7366 | 0x12, 0x34, 0x56, 0x78, |
| 7367 | // frame type (IETF_ACK frame) |
| 7368 | 0x02, |
| 7369 | // largest acked |
| 7370 | kVarInt62TwoBytes + 0x12, 0x34, |
| 7371 | // Zero delta time. |
| 7372 | kVarInt62OneByte + 0x00, |
| 7373 | // num ack blocks ranges. |
| 7374 | kVarInt62TwoBytes + 0x01, 0x2b, |
| 7375 | // first ack block length. |
| 7376 | kVarInt62TwoBytes + 0x0f, 0xdc, |
| 7377 | // 255 added blocks of gap_size == 1, ack_size == 1 |
| 7378 | #define V99AddedBLOCK kVarInt62OneByte + 0x00, kVarInt62OneByte + 0x00 |
| 7379 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7380 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7381 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7382 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7383 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7384 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7385 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7386 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7387 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7388 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7389 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7390 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7391 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7392 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7393 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7394 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7395 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7396 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7397 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7398 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7399 | |
| 7400 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7401 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7402 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7403 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7404 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7405 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7406 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7407 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7408 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7409 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7410 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7411 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7412 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7413 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7414 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7415 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7416 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7417 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7418 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7419 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7420 | |
| 7421 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7422 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7423 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7424 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7425 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7426 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7427 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7428 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7429 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7430 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7431 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7432 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7433 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7434 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7435 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7436 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7437 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7438 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7439 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7440 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7441 | |
| 7442 | #undef V99AddedBLOCK |
| 7443 | }; |
| 7444 | // clang-format on |
| 7445 | unsigned char* p = packet; |
| 7446 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7447 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7448 | p = packet99; |
| 7449 | p_size = QUIC_ARRAYSIZE(packet99); |
| 7450 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7451 | p = packet46; |
| 7452 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7453 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7454 | p = packet44; |
| 7455 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7456 | } |
| 7457 | |
| 7458 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7459 | ASSERT_TRUE(data != nullptr); |
| 7460 | |
| 7461 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7462 | data->length(), AsChars(p), p_size); |
| 7463 | } |
| 7464 | |
| 7465 | TEST_P(QuicFramerTest, BuildNewStopWaitingPacket) { |
| 7466 | if (version_.transport_version > QUIC_VERSION_43) { |
| 7467 | return; |
| 7468 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7469 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7470 | QuicPacketHeader header; |
| 7471 | header.destination_connection_id = FramerTestConnectionId(); |
| 7472 | header.reset_flag = false; |
| 7473 | header.version_flag = false; |
| 7474 | header.packet_number = kPacketNumber; |
| 7475 | |
| 7476 | QuicStopWaitingFrame stop_waiting_frame; |
| 7477 | stop_waiting_frame.least_unacked = kLeastUnacked; |
| 7478 | |
| 7479 | QuicFrames frames = {QuicFrame(stop_waiting_frame)}; |
| 7480 | |
| 7481 | // clang-format off |
| 7482 | unsigned char packet[] = { |
| 7483 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7484 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7485 | // connection_id |
| 7486 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7487 | // packet number |
| 7488 | 0x12, 0x34, 0x56, 0x78, |
| 7489 | |
| 7490 | // frame type (stop waiting frame) |
| 7491 | 0x06, |
| 7492 | // least packet number awaiting an ack, delta from packet number. |
| 7493 | 0x00, 0x00, 0x00, 0x08, |
| 7494 | }; |
| 7495 | |
| 7496 | // clang-format on |
| 7497 | |
| 7498 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7499 | ASSERT_TRUE(data != nullptr); |
| 7500 | |
| 7501 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7502 | data->length(), AsChars(packet), |
| 7503 | QUIC_ARRAYSIZE(packet)); |
| 7504 | } |
| 7505 | |
| 7506 | TEST_P(QuicFramerTest, BuildRstFramePacketQuic) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7507 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7508 | QuicPacketHeader header; |
| 7509 | header.destination_connection_id = FramerTestConnectionId(); |
| 7510 | header.reset_flag = false; |
| 7511 | header.version_flag = false; |
| 7512 | header.packet_number = kPacketNumber; |
| 7513 | |
| 7514 | QuicRstStreamFrame rst_frame; |
| 7515 | rst_frame.stream_id = kStreamId; |
| 7516 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7517 | rst_frame.ietf_error_code = 0x01; |
| 7518 | } else { |
| 7519 | rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708); |
| 7520 | } |
| 7521 | rst_frame.byte_offset = 0x0807060504030201; |
| 7522 | |
| 7523 | // clang-format off |
| 7524 | unsigned char packet[] = { |
| 7525 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7526 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7527 | // connection_id |
| 7528 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7529 | // packet number |
| 7530 | 0x12, 0x34, 0x56, 0x78, |
| 7531 | |
| 7532 | // frame type (rst stream frame) |
| 7533 | 0x01, |
| 7534 | // stream id |
| 7535 | 0x01, 0x02, 0x03, 0x04, |
| 7536 | // sent byte offset |
| 7537 | 0x08, 0x07, 0x06, 0x05, |
| 7538 | 0x04, 0x03, 0x02, 0x01, |
| 7539 | // error code |
| 7540 | 0x05, 0x06, 0x07, 0x08, |
| 7541 | }; |
| 7542 | |
| 7543 | unsigned char packet44[] = { |
| 7544 | // type (short packet, 4 byte packet number) |
| 7545 | 0x32, |
| 7546 | // connection_id |
| 7547 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7548 | // packet number |
| 7549 | 0x12, 0x34, 0x56, 0x78, |
| 7550 | |
| 7551 | // frame type (rst stream frame) |
| 7552 | 0x01, |
| 7553 | // stream id |
| 7554 | 0x01, 0x02, 0x03, 0x04, |
| 7555 | // sent byte offset |
| 7556 | 0x08, 0x07, 0x06, 0x05, |
| 7557 | 0x04, 0x03, 0x02, 0x01, |
| 7558 | // error code |
| 7559 | 0x05, 0x06, 0x07, 0x08, |
| 7560 | }; |
| 7561 | |
| 7562 | unsigned char packet46[] = { |
| 7563 | // type (short packet, 4 byte packet number) |
| 7564 | 0x43, |
| 7565 | // connection_id |
| 7566 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7567 | // packet number |
| 7568 | 0x12, 0x34, 0x56, 0x78, |
| 7569 | |
| 7570 | // frame type (rst stream frame) |
| 7571 | 0x01, |
| 7572 | // stream id |
| 7573 | 0x01, 0x02, 0x03, 0x04, |
| 7574 | // sent byte offset |
| 7575 | 0x08, 0x07, 0x06, 0x05, |
| 7576 | 0x04, 0x03, 0x02, 0x01, |
| 7577 | // error code |
| 7578 | 0x05, 0x06, 0x07, 0x08, |
| 7579 | }; |
| 7580 | |
| 7581 | unsigned char packet99[] = { |
| 7582 | // type (short packet, 4 byte packet number) |
| 7583 | 0x43, |
| 7584 | // connection_id |
| 7585 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7586 | // packet number |
| 7587 | 0x12, 0x34, 0x56, 0x78, |
| 7588 | |
| 7589 | // frame type (IETF_RST_STREAM frame) |
| 7590 | 0x04, |
| 7591 | // stream id |
| 7592 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 7593 | // error code (not VarInt32 encoded) |
| 7594 | 0x00, 0x01, |
| 7595 | // sent byte offset |
| 7596 | kVarInt62EightBytes + 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 |
| 7597 | }; |
| 7598 | // clang-format on |
| 7599 | |
| 7600 | QuicFrames frames = {QuicFrame(&rst_frame)}; |
| 7601 | |
| 7602 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7603 | ASSERT_TRUE(data != nullptr); |
| 7604 | |
| 7605 | unsigned char* p = packet; |
| 7606 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7607 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7608 | p = packet99; |
| 7609 | p_size = QUIC_ARRAYSIZE(packet99); |
| 7610 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7611 | p = packet46; |
| 7612 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7613 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7614 | p = packet44; |
| 7615 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7616 | } |
| 7617 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 7618 | |
| 7619 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7620 | data->length(), AsChars(p), p_size); |
| 7621 | } |
| 7622 | |
| 7623 | TEST_P(QuicFramerTest, BuildCloseFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7624 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7625 | QuicPacketHeader header; |
| 7626 | header.destination_connection_id = FramerTestConnectionId(); |
| 7627 | header.reset_flag = false; |
| 7628 | header.version_flag = false; |
| 7629 | header.packet_number = kPacketNumber; |
| 7630 | |
| 7631 | QuicConnectionCloseFrame close_frame; |
| 7632 | if (framer_.transport_version() == QUIC_VERSION_99) { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 7633 | close_frame.transport_error_code = |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7634 | static_cast<QuicIetfTransportErrorCodes>(0x11); |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 7635 | close_frame.transport_close_frame_type = 0x05; |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 7636 | close_frame.close_type = IETF_QUIC_TRANSPORT_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7637 | } else { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 7638 | close_frame.quic_error_code = static_cast<QuicErrorCode>(0x05060708); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7639 | } |
| 7640 | close_frame.error_details = "because I can"; |
| 7641 | |
| 7642 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 7643 | |
| 7644 | // clang-format off |
| 7645 | unsigned char packet[] = { |
| 7646 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7647 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7648 | // connection_id |
| 7649 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7650 | // packet number |
| 7651 | 0x12, 0x34, 0x56, 0x78, |
| 7652 | |
| 7653 | // frame type (connection close frame) |
| 7654 | 0x02, |
| 7655 | // error code |
| 7656 | 0x05, 0x06, 0x07, 0x08, |
| 7657 | // error details length |
| 7658 | 0x00, 0x0d, |
| 7659 | // error details |
| 7660 | 'b', 'e', 'c', 'a', |
| 7661 | 'u', 's', 'e', ' ', |
| 7662 | 'I', ' ', 'c', 'a', |
| 7663 | 'n', |
| 7664 | }; |
| 7665 | |
| 7666 | unsigned char packet44[] = { |
| 7667 | // type (short header, 4 byte packet number) |
| 7668 | 0x32, |
| 7669 | // connection_id |
| 7670 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7671 | // packet number |
| 7672 | 0x12, 0x34, 0x56, 0x78, |
| 7673 | |
| 7674 | // frame type (connection close frame) |
| 7675 | 0x02, |
| 7676 | // error code |
| 7677 | 0x05, 0x06, 0x07, 0x08, |
| 7678 | // error details length |
| 7679 | 0x00, 0x0d, |
| 7680 | // error details |
| 7681 | 'b', 'e', 'c', 'a', |
| 7682 | 'u', 's', 'e', ' ', |
| 7683 | 'I', ' ', 'c', 'a', |
| 7684 | 'n', |
| 7685 | }; |
| 7686 | |
| 7687 | unsigned char packet46[] = { |
| 7688 | // type (short header, 4 byte packet number) |
| 7689 | 0x43, |
| 7690 | // connection_id |
| 7691 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7692 | // packet number |
| 7693 | 0x12, 0x34, 0x56, 0x78, |
| 7694 | |
| 7695 | // frame type (connection close frame) |
| 7696 | 0x02, |
| 7697 | // error code |
| 7698 | 0x05, 0x06, 0x07, 0x08, |
| 7699 | // error details length |
| 7700 | 0x00, 0x0d, |
| 7701 | // error details |
| 7702 | 'b', 'e', 'c', 'a', |
| 7703 | 'u', 's', 'e', ' ', |
| 7704 | 'I', ' ', 'c', 'a', |
| 7705 | 'n', |
| 7706 | }; |
| 7707 | |
| 7708 | unsigned char packet99[] = { |
| 7709 | // type (short header, 4 byte packet number) |
| 7710 | 0x43, |
| 7711 | // connection_id |
| 7712 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7713 | // packet number |
| 7714 | 0x12, 0x34, 0x56, 0x78, |
| 7715 | |
| 7716 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 7717 | 0x1c, |
| 7718 | // error code |
| 7719 | 0x00, 0x11, |
| 7720 | // Frame type within the CONNECTION_CLOSE frame |
| 7721 | kVarInt62OneByte + 0x05, |
| 7722 | // error details length |
| 7723 | kVarInt62OneByte + 0x0d, |
| 7724 | // error details |
| 7725 | 'b', 'e', 'c', 'a', |
| 7726 | 'u', 's', 'e', ' ', |
| 7727 | 'I', ' ', 'c', 'a', |
| 7728 | 'n', |
| 7729 | }; |
| 7730 | // clang-format on |
| 7731 | |
| 7732 | unsigned char* p = packet; |
| 7733 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7734 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7735 | p = packet99; |
| 7736 | p_size = QUIC_ARRAYSIZE(packet99); |
| 7737 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7738 | p = packet46; |
| 7739 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7740 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7741 | p = packet44; |
| 7742 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7743 | } |
| 7744 | |
| 7745 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7746 | ASSERT_TRUE(data != nullptr); |
| 7747 | |
| 7748 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7749 | data->length(), AsChars(p), p_size); |
| 7750 | } |
| 7751 | |
| 7752 | TEST_P(QuicFramerTest, BuildTruncatedCloseFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7753 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7754 | QuicPacketHeader header; |
| 7755 | header.destination_connection_id = FramerTestConnectionId(); |
| 7756 | header.reset_flag = false; |
| 7757 | header.version_flag = false; |
| 7758 | header.packet_number = kPacketNumber; |
| 7759 | |
| 7760 | QuicConnectionCloseFrame close_frame; |
| 7761 | if (framer_.transport_version() == QUIC_VERSION_99) { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 7762 | close_frame.transport_error_code = PROTOCOL_VIOLATION; // value is 0x0a |
| 7763 | EXPECT_EQ(0u, close_frame.transport_close_frame_type); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 7764 | close_frame.close_type = IETF_QUIC_TRANSPORT_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7765 | } else { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 7766 | close_frame.quic_error_code = static_cast<QuicErrorCode>(0x05060708); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7767 | } |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 7768 | close_frame.error_details = std::string(2048, 'A'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7769 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 7770 | |
| 7771 | // clang-format off |
| 7772 | unsigned char packet[] = { |
| 7773 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7774 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7775 | // connection_id |
| 7776 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7777 | // packet number |
| 7778 | 0x12, 0x34, 0x56, 0x78, |
| 7779 | |
| 7780 | // frame type (connection close frame) |
| 7781 | 0x02, |
| 7782 | // error code |
| 7783 | 0x05, 0x06, 0x07, 0x08, |
| 7784 | // error details length |
| 7785 | 0x01, 0x00, |
| 7786 | // error details (truncated to 256 bytes) |
| 7787 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7788 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7789 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7790 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7791 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7792 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7793 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7794 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7795 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7796 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7797 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7798 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7799 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7800 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7801 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7802 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7803 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7804 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7805 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7806 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7807 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7808 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7809 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7810 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7811 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7812 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7813 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7814 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7815 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7816 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7817 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7818 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7819 | }; |
| 7820 | |
| 7821 | unsigned char packet44[] = { |
| 7822 | // type (short header, 4 byte packet number) |
| 7823 | 0x32, |
| 7824 | // connection_id |
| 7825 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7826 | // packet number |
| 7827 | 0x12, 0x34, 0x56, 0x78, |
| 7828 | |
| 7829 | // frame type (connection close frame) |
| 7830 | 0x02, |
| 7831 | // error code |
| 7832 | 0x05, 0x06, 0x07, 0x08, |
| 7833 | // error details length |
| 7834 | 0x01, 0x00, |
| 7835 | // error details (truncated to 256 bytes) |
| 7836 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7837 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7838 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7839 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7840 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7841 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7842 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7843 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7844 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7845 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7846 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7847 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7848 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7849 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7850 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7851 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7852 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7853 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7854 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7855 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7856 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7857 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7858 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7859 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7860 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7861 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7862 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7863 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7864 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7865 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7866 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7867 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7868 | }; |
| 7869 | |
| 7870 | unsigned char packet46[] = { |
| 7871 | // type (short header, 4 byte packet number) |
| 7872 | 0x43, |
| 7873 | // connection_id |
| 7874 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7875 | // packet number |
| 7876 | 0x12, 0x34, 0x56, 0x78, |
| 7877 | |
| 7878 | // frame type (connection close frame) |
| 7879 | 0x02, |
| 7880 | // error code |
| 7881 | 0x05, 0x06, 0x07, 0x08, |
| 7882 | // error details length |
| 7883 | 0x01, 0x00, |
| 7884 | // error details (truncated to 256 bytes) |
| 7885 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7886 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7887 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7888 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7889 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7890 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 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 | }; |
| 7918 | |
| 7919 | unsigned char packet99[] = { |
| 7920 | // type (short header, 4 byte packet number) |
| 7921 | 0x43, |
| 7922 | // connection_id |
| 7923 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7924 | // packet number |
| 7925 | 0x12, 0x34, 0x56, 0x78, |
| 7926 | |
| 7927 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 7928 | 0x1c, |
| 7929 | // error code |
| 7930 | 0x00, 0x0a, |
| 7931 | // Frame type within the CONNECTION_CLOSE frame |
| 7932 | kVarInt62OneByte + 0x00, |
| 7933 | // error details length |
| 7934 | kVarInt62TwoBytes + 0x01, 0x00, |
| 7935 | // error details (truncated to 256 bytes) |
| 7936 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7937 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7938 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7939 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7940 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7941 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7942 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7943 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7944 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7945 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7946 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7947 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7948 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7949 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7950 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7951 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7952 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7953 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7954 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7955 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7956 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7957 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7958 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7959 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7960 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7961 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7962 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7963 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7964 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7965 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7966 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7967 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7968 | }; |
| 7969 | // clang-format on |
| 7970 | |
| 7971 | unsigned char* p = packet; |
| 7972 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7973 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7974 | p = packet99; |
| 7975 | p_size = QUIC_ARRAYSIZE(packet99); |
| 7976 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7977 | p = packet46; |
| 7978 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7979 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7980 | p = packet44; |
| 7981 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7982 | } |
| 7983 | |
| 7984 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7985 | ASSERT_TRUE(data != nullptr); |
| 7986 | |
| 7987 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7988 | data->length(), AsChars(p), p_size); |
| 7989 | } |
| 7990 | |
| 7991 | TEST_P(QuicFramerTest, BuildApplicationCloseFramePacket) { |
| 7992 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 7993 | // Versions other than 99 do not have ApplicationClose |
| 7994 | return; |
| 7995 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7996 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7997 | QuicPacketHeader header; |
| 7998 | header.destination_connection_id = FramerTestConnectionId(); |
| 7999 | header.reset_flag = false; |
| 8000 | header.version_flag = false; |
| 8001 | header.packet_number = kPacketNumber; |
| 8002 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 8003 | QuicConnectionCloseFrame app_close_frame; |
| 8004 | app_close_frame.quic_error_code = static_cast<QuicErrorCode>(0x11); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8005 | app_close_frame.error_details = "because I can"; |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 8006 | app_close_frame.close_type = IETF_QUIC_APPLICATION_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8007 | |
| 8008 | QuicFrames frames = {QuicFrame(&app_close_frame)}; |
| 8009 | |
| 8010 | // clang-format off |
| 8011 | |
| 8012 | unsigned char packet99[] = { |
| 8013 | // type (short header, 4 byte packet number) |
| 8014 | 0x43, |
| 8015 | // connection_id |
| 8016 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8017 | // packet number |
| 8018 | 0x12, 0x34, 0x56, 0x78, |
| 8019 | |
| 8020 | // frame type (IETF_APPLICATION_CLOSE frame) |
| 8021 | 0x1d, |
| 8022 | // error code |
| 8023 | 0x00, 0x11, |
| 8024 | // error details length |
| 8025 | kVarInt62OneByte + 0x0d, |
| 8026 | // error details |
| 8027 | 'b', 'e', 'c', 'a', |
| 8028 | 'u', 's', 'e', ' ', |
| 8029 | 'I', ' ', 'c', 'a', |
| 8030 | 'n', |
| 8031 | }; |
| 8032 | // clang-format on |
| 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(packet99), |
| 8039 | QUIC_ARRAYSIZE(packet99)); |
| 8040 | } |
| 8041 | |
| 8042 | TEST_P(QuicFramerTest, BuildTruncatedApplicationCloseFramePacket) { |
| 8043 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8044 | // Versions other than 99 do not have this frame. |
| 8045 | return; |
| 8046 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8047 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8048 | QuicPacketHeader header; |
| 8049 | header.destination_connection_id = FramerTestConnectionId(); |
| 8050 | header.reset_flag = false; |
| 8051 | header.version_flag = false; |
| 8052 | header.packet_number = kPacketNumber; |
| 8053 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 8054 | QuicConnectionCloseFrame app_close_frame; |
| 8055 | app_close_frame.quic_error_code = static_cast<QuicErrorCode>(0x11); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 8056 | app_close_frame.error_details = std::string(2048, 'A'); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 8057 | app_close_frame.close_type = IETF_QUIC_APPLICATION_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8058 | |
| 8059 | QuicFrames frames = {QuicFrame(&app_close_frame)}; |
| 8060 | |
| 8061 | // clang-format off |
| 8062 | unsigned char packet99[] = { |
| 8063 | // type (short header, 4 byte packet number) |
| 8064 | 0x43, |
| 8065 | // connection_id |
| 8066 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8067 | // packet number |
| 8068 | 0x12, 0x34, 0x56, 0x78, |
| 8069 | |
| 8070 | // frame type (IETF_APPLICATION_CLOSE frame) |
| 8071 | 0x1d, |
| 8072 | // error code |
| 8073 | 0x00, 0x11, |
| 8074 | // error details length |
| 8075 | kVarInt62TwoBytes + 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 | // clang-format on |
| 8111 | |
| 8112 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8113 | ASSERT_TRUE(data != nullptr); |
| 8114 | |
| 8115 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8116 | data->length(), AsChars(packet99), |
| 8117 | QUIC_ARRAYSIZE(packet99)); |
| 8118 | } |
| 8119 | |
| 8120 | TEST_P(QuicFramerTest, BuildGoAwayPacket) { |
| 8121 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8122 | // This frame type is not supported in version 99. |
| 8123 | return; |
| 8124 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8125 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8126 | QuicPacketHeader header; |
| 8127 | header.destination_connection_id = FramerTestConnectionId(); |
| 8128 | header.reset_flag = false; |
| 8129 | header.version_flag = false; |
| 8130 | header.packet_number = kPacketNumber; |
| 8131 | |
| 8132 | QuicGoAwayFrame goaway_frame; |
| 8133 | goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 8134 | goaway_frame.last_good_stream_id = kStreamId; |
| 8135 | goaway_frame.reason_phrase = "because I can"; |
| 8136 | |
| 8137 | QuicFrames frames = {QuicFrame(&goaway_frame)}; |
| 8138 | |
| 8139 | // clang-format off |
| 8140 | unsigned char packet[] = { |
| 8141 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8142 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8143 | // connection_id |
| 8144 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8145 | // packet number |
| 8146 | 0x12, 0x34, 0x56, 0x78, |
| 8147 | |
| 8148 | // frame type (go away frame) |
| 8149 | 0x03, |
| 8150 | // error code |
| 8151 | 0x05, 0x06, 0x07, 0x08, |
| 8152 | // stream id |
| 8153 | 0x01, 0x02, 0x03, 0x04, |
| 8154 | // error details length |
| 8155 | 0x00, 0x0d, |
| 8156 | // error details |
| 8157 | 'b', 'e', 'c', 'a', |
| 8158 | 'u', 's', 'e', ' ', |
| 8159 | 'I', ' ', 'c', 'a', |
| 8160 | 'n', |
| 8161 | }; |
| 8162 | |
| 8163 | unsigned char packet44[] = { |
| 8164 | // type (short header, 4 byte packet number) |
| 8165 | 0x32, |
| 8166 | // connection_id |
| 8167 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8168 | // packet number |
| 8169 | 0x12, 0x34, 0x56, 0x78, |
| 8170 | |
| 8171 | // frame type (go away frame) |
| 8172 | 0x03, |
| 8173 | // error code |
| 8174 | 0x05, 0x06, 0x07, 0x08, |
| 8175 | // stream id |
| 8176 | 0x01, 0x02, 0x03, 0x04, |
| 8177 | // error details length |
| 8178 | 0x00, 0x0d, |
| 8179 | // error details |
| 8180 | 'b', 'e', 'c', 'a', |
| 8181 | 'u', 's', 'e', ' ', |
| 8182 | 'I', ' ', 'c', 'a', |
| 8183 | 'n', |
| 8184 | }; |
| 8185 | |
| 8186 | unsigned char packet46[] = { |
| 8187 | // type (short header, 4 byte packet number) |
| 8188 | 0x43, |
| 8189 | // connection_id |
| 8190 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8191 | // packet number |
| 8192 | 0x12, 0x34, 0x56, 0x78, |
| 8193 | |
| 8194 | // frame type (go away frame) |
| 8195 | 0x03, |
| 8196 | // error code |
| 8197 | 0x05, 0x06, 0x07, 0x08, |
| 8198 | // stream id |
| 8199 | 0x01, 0x02, 0x03, 0x04, |
| 8200 | // error details length |
| 8201 | 0x00, 0x0d, |
| 8202 | // error details |
| 8203 | 'b', 'e', 'c', 'a', |
| 8204 | 'u', 's', 'e', ' ', |
| 8205 | 'I', ' ', 'c', 'a', |
| 8206 | 'n', |
| 8207 | }; |
| 8208 | |
| 8209 | // clang-format on |
| 8210 | |
| 8211 | unsigned char* p = packet; |
| 8212 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 8213 | if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8214 | p = packet46; |
| 8215 | p_size = QUIC_ARRAYSIZE(packet46); |
| 8216 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8217 | p = packet44; |
| 8218 | p_size = QUIC_ARRAYSIZE(packet44); |
| 8219 | } |
| 8220 | |
| 8221 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8222 | ASSERT_TRUE(data != nullptr); |
| 8223 | |
| 8224 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8225 | data->length(), AsChars(p), p_size); |
| 8226 | } |
| 8227 | |
| 8228 | TEST_P(QuicFramerTest, BuildTruncatedGoAwayPacket) { |
| 8229 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8230 | // This frame type is not supported in version 99. |
| 8231 | return; |
| 8232 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8233 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8234 | QuicPacketHeader header; |
| 8235 | header.destination_connection_id = FramerTestConnectionId(); |
| 8236 | header.reset_flag = false; |
| 8237 | header.version_flag = false; |
| 8238 | header.packet_number = kPacketNumber; |
| 8239 | |
| 8240 | QuicGoAwayFrame goaway_frame; |
| 8241 | goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 8242 | goaway_frame.last_good_stream_id = kStreamId; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 8243 | goaway_frame.reason_phrase = std::string(2048, 'A'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8244 | |
| 8245 | QuicFrames frames = {QuicFrame(&goaway_frame)}; |
| 8246 | |
| 8247 | // clang-format off |
| 8248 | unsigned char packet[] = { |
| 8249 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8250 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8251 | // connection_id |
| 8252 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8253 | // packet number |
| 8254 | 0x12, 0x34, 0x56, 0x78, |
| 8255 | |
| 8256 | // frame type (go away frame) |
| 8257 | 0x03, |
| 8258 | // error code |
| 8259 | 0x05, 0x06, 0x07, 0x08, |
| 8260 | // stream id |
| 8261 | 0x01, 0x02, 0x03, 0x04, |
| 8262 | // error details length |
| 8263 | 0x01, 0x00, |
| 8264 | // error details (truncated to 256 bytes) |
| 8265 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8266 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8267 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8268 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8269 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8270 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8271 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8272 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8273 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8274 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8275 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8276 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8277 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8278 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8279 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8280 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8281 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8282 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8283 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8284 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8285 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8286 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8287 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8288 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8289 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8290 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8291 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8292 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8293 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8294 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8295 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8296 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8297 | }; |
| 8298 | |
| 8299 | unsigned char packet44[] = { |
| 8300 | // type (short header, 4 byte packet number) |
| 8301 | 0x32, |
| 8302 | // connection_id |
| 8303 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8304 | // packet number |
| 8305 | 0x12, 0x34, 0x56, 0x78, |
| 8306 | |
| 8307 | // frame type (go away frame) |
| 8308 | 0x03, |
| 8309 | // error code |
| 8310 | 0x05, 0x06, 0x07, 0x08, |
| 8311 | // stream id |
| 8312 | 0x01, 0x02, 0x03, 0x04, |
| 8313 | // error details length |
| 8314 | 0x01, 0x00, |
| 8315 | // error details (truncated to 256 bytes) |
| 8316 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8317 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8318 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8319 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8320 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8321 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8322 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8323 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8324 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8325 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8326 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8327 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8328 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8329 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8330 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8331 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8332 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8333 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8334 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8335 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8336 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8337 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8338 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8339 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8340 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8341 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8342 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8343 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8344 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8345 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8346 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8347 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8348 | }; |
| 8349 | |
| 8350 | unsigned char packet46[] = { |
| 8351 | // type (short header, 4 byte packet number) |
| 8352 | 0x43, |
| 8353 | // connection_id |
| 8354 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8355 | // packet number |
| 8356 | 0x12, 0x34, 0x56, 0x78, |
| 8357 | |
| 8358 | // frame type (go away frame) |
| 8359 | 0x03, |
| 8360 | // error code |
| 8361 | 0x05, 0x06, 0x07, 0x08, |
| 8362 | // stream id |
| 8363 | 0x01, 0x02, 0x03, 0x04, |
| 8364 | // error details length |
| 8365 | 0x01, 0x00, |
| 8366 | // error details (truncated to 256 bytes) |
| 8367 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8368 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8369 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8370 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8371 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8372 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8373 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8374 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8375 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8376 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8377 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8378 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8379 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8380 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8381 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8382 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8383 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8384 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8385 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8386 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8387 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8388 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8389 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8390 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8391 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8392 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8393 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8394 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8395 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8396 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8397 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8398 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8399 | }; |
| 8400 | // clang-format on |
| 8401 | |
| 8402 | unsigned char* p = packet; |
| 8403 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 8404 | if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8405 | p = packet46; |
| 8406 | p_size = QUIC_ARRAYSIZE(packet46); |
| 8407 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8408 | p = packet44; |
| 8409 | p_size = QUIC_ARRAYSIZE(packet44); |
| 8410 | } |
| 8411 | |
| 8412 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8413 | ASSERT_TRUE(data != nullptr); |
| 8414 | |
| 8415 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8416 | data->length(), AsChars(p), p_size); |
| 8417 | } |
| 8418 | |
| 8419 | TEST_P(QuicFramerTest, BuildWindowUpdatePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8420 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8421 | QuicPacketHeader header; |
| 8422 | header.destination_connection_id = FramerTestConnectionId(); |
| 8423 | header.reset_flag = false; |
| 8424 | header.version_flag = false; |
| 8425 | header.packet_number = kPacketNumber; |
| 8426 | |
| 8427 | QuicWindowUpdateFrame window_update_frame; |
| 8428 | window_update_frame.stream_id = kStreamId; |
| 8429 | window_update_frame.byte_offset = 0x1122334455667788; |
| 8430 | |
| 8431 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8432 | |
| 8433 | // clang-format off |
| 8434 | unsigned char packet[] = { |
| 8435 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8436 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8437 | // connection_id |
| 8438 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8439 | // packet number |
| 8440 | 0x12, 0x34, 0x56, 0x78, |
| 8441 | |
| 8442 | // frame type (window update frame) |
| 8443 | 0x04, |
| 8444 | // stream id |
| 8445 | 0x01, 0x02, 0x03, 0x04, |
| 8446 | // byte offset |
| 8447 | 0x11, 0x22, 0x33, 0x44, |
| 8448 | 0x55, 0x66, 0x77, 0x88, |
| 8449 | }; |
| 8450 | |
| 8451 | unsigned char packet44[] = { |
| 8452 | // type (short header, 4 byte packet number) |
| 8453 | 0x32, |
| 8454 | // connection_id |
| 8455 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8456 | // packet number |
| 8457 | 0x12, 0x34, 0x56, 0x78, |
| 8458 | |
| 8459 | // frame type (window update frame) |
| 8460 | 0x04, |
| 8461 | // stream id |
| 8462 | 0x01, 0x02, 0x03, 0x04, |
| 8463 | // byte offset |
| 8464 | 0x11, 0x22, 0x33, 0x44, |
| 8465 | 0x55, 0x66, 0x77, 0x88, |
| 8466 | }; |
| 8467 | |
| 8468 | unsigned char packet46[] = { |
| 8469 | // type (short header, 4 byte packet number) |
| 8470 | 0x43, |
| 8471 | // connection_id |
| 8472 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8473 | // packet number |
| 8474 | 0x12, 0x34, 0x56, 0x78, |
| 8475 | |
| 8476 | // frame type (window update frame) |
| 8477 | 0x04, |
| 8478 | // stream id |
| 8479 | 0x01, 0x02, 0x03, 0x04, |
| 8480 | // byte offset |
| 8481 | 0x11, 0x22, 0x33, 0x44, |
| 8482 | 0x55, 0x66, 0x77, 0x88, |
| 8483 | }; |
| 8484 | |
| 8485 | unsigned char packet99[] = { |
| 8486 | // type (short header, 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_MAX_STREAM_DATA frame) |
| 8494 | 0x11, |
| 8495 | // stream id |
| 8496 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 8497 | // byte offset |
| 8498 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8499 | 0x55, 0x66, 0x77, 0x88, |
| 8500 | }; |
| 8501 | // clang-format on |
| 8502 | |
| 8503 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8504 | ASSERT_TRUE(data != nullptr); |
| 8505 | |
| 8506 | unsigned char* p = packet; |
| 8507 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 8508 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8509 | p = packet99; |
| 8510 | p_size = QUIC_ARRAYSIZE(packet99); |
| 8511 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8512 | p = packet46; |
| 8513 | p_size = QUIC_ARRAYSIZE(packet46); |
| 8514 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8515 | p = packet44; |
| 8516 | p_size = QUIC_ARRAYSIZE(packet44); |
| 8517 | } |
| 8518 | |
| 8519 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8520 | data->length(), AsChars(p), p_size); |
| 8521 | } |
| 8522 | |
| 8523 | TEST_P(QuicFramerTest, BuildMaxStreamDataPacket) { |
| 8524 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8525 | // This frame is available only in this version. |
| 8526 | return; |
| 8527 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8528 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8529 | QuicPacketHeader header; |
| 8530 | header.destination_connection_id = FramerTestConnectionId(); |
| 8531 | header.reset_flag = false; |
| 8532 | header.version_flag = false; |
| 8533 | header.packet_number = kPacketNumber; |
| 8534 | |
| 8535 | QuicWindowUpdateFrame window_update_frame; |
| 8536 | window_update_frame.stream_id = kStreamId; |
| 8537 | window_update_frame.byte_offset = 0x1122334455667788; |
| 8538 | |
| 8539 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8540 | |
| 8541 | // clang-format off |
| 8542 | unsigned char packet99[] = { |
| 8543 | // type (short header, 4 byte packet number) |
| 8544 | 0x43, |
| 8545 | // connection_id |
| 8546 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8547 | // packet number |
| 8548 | 0x12, 0x34, 0x56, 0x78, |
| 8549 | |
| 8550 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 8551 | 0x11, |
| 8552 | // stream id |
| 8553 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 8554 | // byte offset |
| 8555 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8556 | 0x55, 0x66, 0x77, 0x88, |
| 8557 | }; |
| 8558 | // clang-format on |
| 8559 | |
| 8560 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8561 | ASSERT_TRUE(data != nullptr); |
| 8562 | |
| 8563 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8564 | data->length(), AsChars(packet99), |
| 8565 | QUIC_ARRAYSIZE(packet99)); |
| 8566 | } |
| 8567 | |
| 8568 | TEST_P(QuicFramerTest, BuildMaxDataPacket) { |
| 8569 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8570 | // This frame is available only in this version. |
| 8571 | return; |
| 8572 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8573 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8574 | QuicPacketHeader header; |
| 8575 | header.destination_connection_id = FramerTestConnectionId(); |
| 8576 | header.reset_flag = false; |
| 8577 | header.version_flag = false; |
| 8578 | header.packet_number = kPacketNumber; |
| 8579 | |
| 8580 | QuicWindowUpdateFrame window_update_frame; |
| 8581 | window_update_frame.stream_id = |
| 8582 | QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 8583 | window_update_frame.byte_offset = 0x1122334455667788; |
| 8584 | |
| 8585 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8586 | |
| 8587 | // clang-format off |
| 8588 | unsigned char packet99[] = { |
| 8589 | // type (short header, 4 byte packet number) |
| 8590 | 0x43, |
| 8591 | // connection_id |
| 8592 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8593 | // packet number |
| 8594 | 0x12, 0x34, 0x56, 0x78, |
| 8595 | |
| 8596 | // frame type (IETF_MAX_DATA frame) |
| 8597 | 0x10, |
| 8598 | // byte offset |
| 8599 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8600 | 0x55, 0x66, 0x77, 0x88, |
| 8601 | }; |
| 8602 | // clang-format on |
| 8603 | |
| 8604 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8605 | ASSERT_TRUE(data != nullptr); |
| 8606 | |
| 8607 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8608 | data->length(), AsChars(packet99), |
| 8609 | QUIC_ARRAYSIZE(packet99)); |
| 8610 | } |
| 8611 | |
| 8612 | TEST_P(QuicFramerTest, BuildBlockedPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8613 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8614 | QuicPacketHeader header; |
| 8615 | header.destination_connection_id = FramerTestConnectionId(); |
| 8616 | header.reset_flag = false; |
| 8617 | header.version_flag = false; |
| 8618 | header.packet_number = kPacketNumber; |
| 8619 | |
| 8620 | QuicBlockedFrame blocked_frame; |
| 8621 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8622 | // For V99, the stream ID must be <invalid> for the frame |
| 8623 | // to be a BLOCKED frame. if it's valid, it will be a |
| 8624 | // STREAM_BLOCKED frame. |
| 8625 | blocked_frame.stream_id = |
| 8626 | QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 8627 | } else { |
| 8628 | blocked_frame.stream_id = kStreamId; |
| 8629 | } |
| 8630 | blocked_frame.offset = kStreamOffset; |
| 8631 | |
| 8632 | QuicFrames frames = {QuicFrame(&blocked_frame)}; |
| 8633 | |
| 8634 | // clang-format off |
| 8635 | unsigned char packet[] = { |
| 8636 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8637 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8638 | // connection_id |
| 8639 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8640 | // packet number |
| 8641 | 0x12, 0x34, 0x56, 0x78, |
| 8642 | |
| 8643 | // frame type (blocked frame) |
| 8644 | 0x05, |
| 8645 | // stream id |
| 8646 | 0x01, 0x02, 0x03, 0x04, |
| 8647 | }; |
| 8648 | |
| 8649 | unsigned char packet44[] = { |
| 8650 | // type (short packet, 4 byte packet number) |
| 8651 | 0x32, |
| 8652 | // connection_id |
| 8653 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8654 | // packet number |
| 8655 | 0x12, 0x34, 0x56, 0x78, |
| 8656 | |
| 8657 | // frame type (blocked frame) |
| 8658 | 0x05, |
| 8659 | // stream id |
| 8660 | 0x01, 0x02, 0x03, 0x04, |
| 8661 | }; |
| 8662 | |
| 8663 | unsigned char packet46[] = { |
| 8664 | // type (short packet, 4 byte packet number) |
| 8665 | 0x43, |
| 8666 | // connection_id |
| 8667 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8668 | // packet number |
| 8669 | 0x12, 0x34, 0x56, 0x78, |
| 8670 | |
| 8671 | // frame type (blocked frame) |
| 8672 | 0x05, |
| 8673 | // stream id |
| 8674 | 0x01, 0x02, 0x03, 0x04, |
| 8675 | }; |
| 8676 | |
| 8677 | unsigned char packet99[] = { |
| 8678 | // type (short packet, 4 byte packet number) |
| 8679 | 0x43, |
| 8680 | // connection_id |
| 8681 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8682 | // packet number |
| 8683 | 0x12, 0x34, 0x56, 0x78, |
| 8684 | |
| 8685 | // frame type (IETF_BLOCKED frame) |
| 8686 | 0x14, |
| 8687 | // Offset |
| 8688 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 8689 | }; |
| 8690 | // clang-format on |
| 8691 | |
| 8692 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8693 | ASSERT_TRUE(data != nullptr); |
| 8694 | |
| 8695 | unsigned char* p = packet; |
| 8696 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 8697 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8698 | p = packet99; |
| 8699 | p_size = QUIC_ARRAYSIZE(packet99); |
| 8700 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8701 | p = packet46; |
| 8702 | p_size = QUIC_ARRAYSIZE(packet46); |
| 8703 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8704 | p = packet44; |
| 8705 | p_size = QUIC_ARRAYSIZE(packet44); |
| 8706 | } |
| 8707 | |
| 8708 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8709 | data->length(), AsChars(p), p_size); |
| 8710 | } |
| 8711 | |
| 8712 | TEST_P(QuicFramerTest, BuildPingPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8713 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8714 | QuicPacketHeader header; |
| 8715 | header.destination_connection_id = FramerTestConnectionId(); |
| 8716 | header.reset_flag = false; |
| 8717 | header.version_flag = false; |
| 8718 | header.packet_number = kPacketNumber; |
| 8719 | |
| 8720 | QuicFrames frames = {QuicFrame(QuicPingFrame())}; |
| 8721 | |
| 8722 | // clang-format off |
| 8723 | unsigned char packet[] = { |
| 8724 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8725 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8726 | // connection_id |
| 8727 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8728 | // packet number |
| 8729 | 0x12, 0x34, 0x56, 0x78, |
| 8730 | |
| 8731 | // frame type (ping frame) |
| 8732 | 0x07, |
| 8733 | }; |
| 8734 | |
| 8735 | unsigned char packet44[] = { |
| 8736 | // type (short header, 4 byte packet number) |
| 8737 | 0x32, |
| 8738 | // connection_id |
| 8739 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8740 | // packet number |
| 8741 | 0x12, 0x34, 0x56, 0x78, |
| 8742 | |
| 8743 | // frame type |
| 8744 | 0x07, |
| 8745 | }; |
| 8746 | |
| 8747 | unsigned char packet46[] = { |
| 8748 | // type (short header, 4 byte packet number) |
| 8749 | 0x43, |
| 8750 | // connection_id |
| 8751 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8752 | // packet number |
| 8753 | 0x12, 0x34, 0x56, 0x78, |
| 8754 | |
| 8755 | // frame type |
| 8756 | 0x07, |
| 8757 | }; |
| 8758 | |
| 8759 | unsigned char packet99[] = { |
| 8760 | // type (short header, 4 byte packet number) |
| 8761 | 0x43, |
| 8762 | // connection_id |
| 8763 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8764 | // packet number |
| 8765 | 0x12, 0x34, 0x56, 0x78, |
| 8766 | |
| 8767 | // frame type (IETF_PING frame) |
| 8768 | 0x01, |
| 8769 | }; |
| 8770 | // clang-format on |
| 8771 | |
| 8772 | unsigned char* p = packet; |
| 8773 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8774 | p = packet99; |
| 8775 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8776 | p = packet46; |
| 8777 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8778 | p = packet44; |
| 8779 | } |
| 8780 | |
| 8781 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8782 | ASSERT_TRUE(data != nullptr); |
| 8783 | |
| 8784 | test::CompareCharArraysWithHexError( |
| 8785 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 8786 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 8787 | : QUIC_ARRAYSIZE(packet)); |
| 8788 | } |
| 8789 | |
| 8790 | TEST_P(QuicFramerTest, BuildMessagePacket) { |
| 8791 | if (framer_.transport_version() <= QUIC_VERSION_44) { |
| 8792 | return; |
| 8793 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8794 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8795 | QuicPacketHeader header; |
| 8796 | header.destination_connection_id = FramerTestConnectionId(); |
| 8797 | header.reset_flag = false; |
| 8798 | header.version_flag = false; |
| 8799 | header.packet_number = kPacketNumber; |
| 8800 | QuicMemSliceStorage storage(nullptr, 0, nullptr, 0); |
| 8801 | |
wub | 553a966 | 2019-03-28 20:13:23 -0700 | [diff] [blame] | 8802 | QuicMessageFrame frame(1, MakeSpan(&allocator_, "message", &storage)); |
| 8803 | QuicMessageFrame frame2(2, MakeSpan(&allocator_, "message2", &storage)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8804 | QuicFrames frames = {QuicFrame(&frame), QuicFrame(&frame2)}; |
| 8805 | |
| 8806 | // clang-format off |
| 8807 | unsigned char packet45[] = { |
| 8808 | // type (short header, 4 byte packet number) |
| 8809 | 0x32, |
| 8810 | // connection_id |
| 8811 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8812 | // packet number |
| 8813 | 0x12, 0x34, 0x56, 0x78, |
| 8814 | |
| 8815 | // frame type (message frame) |
| 8816 | 0x21, |
| 8817 | // Length |
| 8818 | 0x07, |
| 8819 | // Message Data |
| 8820 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 8821 | // frame type (message frame no length) |
| 8822 | 0x20, |
| 8823 | // Message Data |
| 8824 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 8825 | }; |
| 8826 | |
| 8827 | unsigned char packet46[] = { |
| 8828 | // type (short header, 4 byte packet number) |
| 8829 | 0x43, |
| 8830 | // connection_id |
| 8831 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8832 | // packet number |
| 8833 | 0x12, 0x34, 0x56, 0x78, |
| 8834 | |
| 8835 | // frame type (message frame) |
| 8836 | 0x21, |
| 8837 | // Length |
| 8838 | 0x07, |
| 8839 | // Message Data |
| 8840 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 8841 | // frame type (message frame no length) |
| 8842 | 0x20, |
| 8843 | // Message Data |
| 8844 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 8845 | }; |
| 8846 | |
| 8847 | unsigned char packet99[] = { |
| 8848 | // type (short header, 4 byte packet number) |
| 8849 | 0x43, |
| 8850 | // connection_id |
| 8851 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8852 | // packet number |
| 8853 | 0x12, 0x34, 0x56, 0x78, |
| 8854 | |
| 8855 | // frame type (IETF_MESSAGE frame) |
| 8856 | 0x21, |
| 8857 | // Length |
| 8858 | 0x07, |
| 8859 | // Message Data |
| 8860 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 8861 | // frame type (message frame no length) |
| 8862 | 0x20, |
| 8863 | // Message Data |
| 8864 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 8865 | }; |
| 8866 | // clang-format on |
| 8867 | |
| 8868 | unsigned char* p = packet45; |
| 8869 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8870 | p = packet99; |
| 8871 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8872 | p = packet46; |
| 8873 | } |
| 8874 | |
| 8875 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8876 | ASSERT_TRUE(data != nullptr); |
| 8877 | |
| 8878 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8879 | data->length(), AsChars(p), |
| 8880 | QUIC_ARRAYSIZE(packet45)); |
| 8881 | } |
| 8882 | |
| 8883 | // Test that the connectivity probing packet is serialized correctly as a |
| 8884 | // padded PING packet. |
| 8885 | TEST_P(QuicFramerTest, BuildConnectivityProbingPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8886 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8887 | QuicPacketHeader header; |
| 8888 | header.destination_connection_id = FramerTestConnectionId(); |
| 8889 | header.reset_flag = false; |
| 8890 | header.version_flag = false; |
| 8891 | header.packet_number = kPacketNumber; |
| 8892 | |
| 8893 | // clang-format off |
| 8894 | unsigned char packet[] = { |
| 8895 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8896 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8897 | // connection_id |
| 8898 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8899 | // packet number |
| 8900 | 0x12, 0x34, 0x56, 0x78, |
| 8901 | |
| 8902 | // frame type (ping frame) |
| 8903 | 0x07, |
| 8904 | // frame type (padding frame) |
| 8905 | 0x00, |
| 8906 | 0x00, 0x00, 0x00, 0x00 |
| 8907 | }; |
| 8908 | |
| 8909 | unsigned char packet44[] = { |
| 8910 | // type (short header, 4 byte packet number) |
| 8911 | 0x32, |
| 8912 | // connection_id |
| 8913 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8914 | // packet number |
| 8915 | 0x12, 0x34, 0x56, 0x78, |
| 8916 | |
| 8917 | // frame type |
| 8918 | 0x07, |
| 8919 | // frame type (padding frame) |
| 8920 | 0x00, |
| 8921 | 0x00, 0x00, 0x00, 0x00 |
| 8922 | }; |
| 8923 | |
| 8924 | unsigned char packet46[] = { |
| 8925 | // type (short header, 4 byte packet number) |
| 8926 | 0x43, |
| 8927 | // connection_id |
| 8928 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8929 | // packet number |
| 8930 | 0x12, 0x34, 0x56, 0x78, |
| 8931 | |
| 8932 | // frame type |
| 8933 | 0x07, |
| 8934 | // frame type (padding frame) |
| 8935 | 0x00, |
| 8936 | 0x00, 0x00, 0x00, 0x00 |
| 8937 | }; |
| 8938 | |
| 8939 | unsigned char packet99[] = { |
| 8940 | // type (short header, 4 byte packet number) |
| 8941 | 0x43, |
| 8942 | // connection_id |
| 8943 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8944 | // packet number |
| 8945 | 0x12, 0x34, 0x56, 0x78, |
| 8946 | |
| 8947 | // frame type (IETF_PING frame) |
| 8948 | 0x01, |
| 8949 | // frame type (padding frame) |
| 8950 | 0x00, |
| 8951 | 0x00, 0x00, 0x00, 0x00 |
| 8952 | }; |
| 8953 | // clang-format on |
| 8954 | |
| 8955 | unsigned char* p = packet; |
| 8956 | size_t packet_size = QUIC_ARRAYSIZE(packet); |
| 8957 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8958 | p = packet99; |
| 8959 | packet_size = QUIC_ARRAYSIZE(packet99); |
| 8960 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8961 | p = packet46; |
| 8962 | packet_size = QUIC_ARRAYSIZE(packet46); |
| 8963 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8964 | p = packet44; |
| 8965 | packet_size = QUIC_ARRAYSIZE(packet44); |
| 8966 | } |
| 8967 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8968 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8969 | |
| 8970 | size_t length = framer_.BuildConnectivityProbingPacket( |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 8971 | header, buffer.get(), packet_size, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8972 | |
| 8973 | EXPECT_NE(0u, length); |
| 8974 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 8975 | header); |
| 8976 | |
| 8977 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 8978 | data.length(), AsChars(p), packet_size); |
| 8979 | } |
| 8980 | |
| 8981 | // Test that the path challenge connectivity probing packet is serialized |
| 8982 | // correctly as a padded PATH CHALLENGE packet. |
| 8983 | TEST_P(QuicFramerTest, BuildPaddedPathChallengePacket) { |
| 8984 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8985 | return; |
| 8986 | } |
| 8987 | |
| 8988 | QuicPacketHeader header; |
| 8989 | header.destination_connection_id = FramerTestConnectionId(); |
| 8990 | header.reset_flag = false; |
| 8991 | header.version_flag = false; |
| 8992 | header.packet_number = kPacketNumber; |
| 8993 | QuicPathFrameBuffer payload; |
| 8994 | |
| 8995 | // clang-format off |
| 8996 | unsigned char packet[] = { |
| 8997 | // type (short header, 4 byte packet number) |
| 8998 | 0x43, |
| 8999 | // connection_id |
| 9000 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9001 | // packet number |
| 9002 | 0x12, 0x34, 0x56, 0x78, |
| 9003 | |
| 9004 | // Path Challenge Frame type (IETF_PATH_CHALLENGE) |
| 9005 | 0x1a, |
| 9006 | // 8 "random" bytes, MockRandom makes lots of r's |
| 9007 | 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', |
| 9008 | // frame type (padding frame) |
| 9009 | 0x00, |
| 9010 | 0x00, 0x00, 0x00, 0x00 |
| 9011 | }; |
| 9012 | // clang-format on |
| 9013 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9014 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9015 | MockRandom randomizer; |
| 9016 | |
| 9017 | size_t length = framer_.BuildPaddedPathChallengePacket( |
| 9018 | header, buffer.get(), QUIC_ARRAYSIZE(packet), &payload, &randomizer, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9019 | ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9020 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 9021 | |
| 9022 | // Payload has the random bytes that were generated. Copy them into packet, |
| 9023 | // above, before checking that the generated packet is correct. |
| 9024 | EXPECT_EQ(kQuicPathFrameBufferSize, payload.size()); |
| 9025 | |
| 9026 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 9027 | header); |
| 9028 | |
| 9029 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 9030 | data.length(), AsChars(packet), |
| 9031 | QUIC_ARRAYSIZE(packet)); |
| 9032 | } |
| 9033 | |
| 9034 | // Several tests that the path response connectivity probing packet is |
| 9035 | // serialized correctly as either a padded and unpadded PATH RESPONSE |
| 9036 | // packet. Also generates packets with 1 and 3 PATH_RESPONSES in them to |
| 9037 | // exercised the single- and multiple- payload cases. |
| 9038 | TEST_P(QuicFramerTest, BuildPathResponsePacket1ResponseUnpadded) { |
| 9039 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9040 | return; |
| 9041 | } |
| 9042 | |
| 9043 | QuicPacketHeader header; |
| 9044 | header.destination_connection_id = FramerTestConnectionId(); |
| 9045 | header.reset_flag = false; |
| 9046 | header.version_flag = false; |
| 9047 | header.packet_number = kPacketNumber; |
| 9048 | QuicPathFrameBuffer payload0 = { |
| 9049 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 9050 | |
| 9051 | // Build 1 PATH RESPONSE, not padded |
| 9052 | // clang-format off |
| 9053 | unsigned char packet[] = { |
| 9054 | // type (short header, 4 byte packet number) |
| 9055 | 0x43, |
| 9056 | // connection_id |
| 9057 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9058 | // packet number |
| 9059 | 0x12, 0x34, 0x56, 0x78, |
| 9060 | |
| 9061 | // Path Response Frame type (IETF_PATH_RESPONSE) |
| 9062 | 0x1b, |
| 9063 | // 8 "random" bytes |
| 9064 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 9065 | }; |
| 9066 | // clang-format on |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9067 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9068 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 9069 | payloads.push_back(payload0); |
| 9070 | size_t length = framer_.BuildPathResponsePacket( |
| 9071 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9072 | /*is_padded=*/false, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9073 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 9074 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 9075 | header); |
| 9076 | |
| 9077 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 9078 | data.length(), AsChars(packet), |
| 9079 | QUIC_ARRAYSIZE(packet)); |
| 9080 | } |
| 9081 | |
| 9082 | TEST_P(QuicFramerTest, BuildPathResponsePacket1ResponsePadded) { |
| 9083 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9084 | return; |
| 9085 | } |
| 9086 | |
| 9087 | QuicPacketHeader header; |
| 9088 | header.destination_connection_id = FramerTestConnectionId(); |
| 9089 | header.reset_flag = false; |
| 9090 | header.version_flag = false; |
| 9091 | header.packet_number = kPacketNumber; |
| 9092 | QuicPathFrameBuffer payload0 = { |
| 9093 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 9094 | |
| 9095 | // Build 1 PATH RESPONSE, padded |
| 9096 | // clang-format off |
| 9097 | unsigned char packet[] = { |
| 9098 | // type (short header, 4 byte packet number) |
| 9099 | 0x43, |
| 9100 | // connection_id |
| 9101 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9102 | // packet number |
| 9103 | 0x12, 0x34, 0x56, 0x78, |
| 9104 | |
| 9105 | // Path Response Frame type (IETF_PATH_RESPONSE) |
| 9106 | 0x1b, |
| 9107 | // 8 "random" bytes |
| 9108 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 9109 | // Padding type and pad |
| 9110 | 0x00, 0x00, 0x00, 0x00, 0x00 |
| 9111 | }; |
| 9112 | // clang-format on |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9113 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9114 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 9115 | payloads.push_back(payload0); |
| 9116 | size_t length = framer_.BuildPathResponsePacket( |
| 9117 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9118 | /*is_padded=*/true, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9119 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 9120 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 9121 | header); |
| 9122 | |
| 9123 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 9124 | data.length(), AsChars(packet), |
| 9125 | QUIC_ARRAYSIZE(packet)); |
| 9126 | } |
| 9127 | |
| 9128 | TEST_P(QuicFramerTest, BuildPathResponsePacket3ResponsesUnpadded) { |
| 9129 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9130 | return; |
| 9131 | } |
| 9132 | |
| 9133 | QuicPacketHeader header; |
| 9134 | header.destination_connection_id = FramerTestConnectionId(); |
| 9135 | header.reset_flag = false; |
| 9136 | header.version_flag = false; |
| 9137 | header.packet_number = kPacketNumber; |
| 9138 | QuicPathFrameBuffer payload0 = { |
| 9139 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 9140 | QuicPathFrameBuffer payload1 = { |
| 9141 | {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}}; |
| 9142 | QuicPathFrameBuffer payload2 = { |
| 9143 | {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28}}; |
| 9144 | |
| 9145 | // Build one packet with 3 PATH RESPONSES, no padding |
| 9146 | // clang-format off |
| 9147 | unsigned char packet[] = { |
| 9148 | // type (short header, 4 byte packet number) |
| 9149 | 0x43, |
| 9150 | // connection_id |
| 9151 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9152 | // packet number |
| 9153 | 0x12, 0x34, 0x56, 0x78, |
| 9154 | |
| 9155 | // 3 path response frames (IETF_PATH_RESPONSE type byte and payload) |
| 9156 | 0x1b, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 9157 | 0x1b, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, |
| 9158 | 0x1b, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, |
| 9159 | }; |
| 9160 | // clang-format on |
| 9161 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9162 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9163 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 9164 | payloads.push_back(payload0); |
| 9165 | payloads.push_back(payload1); |
| 9166 | payloads.push_back(payload2); |
| 9167 | size_t length = framer_.BuildPathResponsePacket( |
| 9168 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9169 | /*is_padded=*/false, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9170 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 9171 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 9172 | header); |
| 9173 | |
| 9174 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 9175 | data.length(), AsChars(packet), |
| 9176 | QUIC_ARRAYSIZE(packet)); |
| 9177 | } |
| 9178 | |
| 9179 | TEST_P(QuicFramerTest, BuildPathResponsePacket3ResponsesPadded) { |
| 9180 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9181 | return; |
| 9182 | } |
| 9183 | |
| 9184 | QuicPacketHeader header; |
| 9185 | header.destination_connection_id = FramerTestConnectionId(); |
| 9186 | header.reset_flag = false; |
| 9187 | header.version_flag = false; |
| 9188 | header.packet_number = kPacketNumber; |
| 9189 | QuicPathFrameBuffer payload0 = { |
| 9190 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 9191 | QuicPathFrameBuffer payload1 = { |
| 9192 | {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}}; |
| 9193 | QuicPathFrameBuffer payload2 = { |
| 9194 | {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28}}; |
| 9195 | |
| 9196 | // Build one packet with 3 PATH RESPONSES, with padding |
| 9197 | // clang-format off |
| 9198 | unsigned char packet[] = { |
| 9199 | // type (short header, 4 byte packet number) |
| 9200 | 0x43, |
| 9201 | // connection_id |
| 9202 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9203 | // packet number |
| 9204 | 0x12, 0x34, 0x56, 0x78, |
| 9205 | |
| 9206 | // 3 path response frames (IETF_PATH_RESPONSE byte and payload) |
| 9207 | 0x1b, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 9208 | 0x1b, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, |
| 9209 | 0x1b, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, |
| 9210 | // Padding |
| 9211 | 0x00, 0x00, 0x00, 0x00, 0x00 |
| 9212 | }; |
| 9213 | // clang-format on |
| 9214 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9215 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9216 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 9217 | payloads.push_back(payload0); |
| 9218 | payloads.push_back(payload1); |
| 9219 | payloads.push_back(payload2); |
| 9220 | size_t length = framer_.BuildPathResponsePacket( |
| 9221 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9222 | /*is_padded=*/true, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9223 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 9224 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 9225 | header); |
| 9226 | |
| 9227 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 9228 | data.length(), AsChars(packet), |
| 9229 | QUIC_ARRAYSIZE(packet)); |
| 9230 | } |
| 9231 | |
| 9232 | // Test that the MTU discovery packet is serialized correctly as a PING packet. |
| 9233 | TEST_P(QuicFramerTest, BuildMtuDiscoveryPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 9234 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9235 | QuicPacketHeader header; |
| 9236 | header.destination_connection_id = FramerTestConnectionId(); |
| 9237 | header.reset_flag = false; |
| 9238 | header.version_flag = false; |
| 9239 | header.packet_number = kPacketNumber; |
| 9240 | |
| 9241 | QuicFrames frames = {QuicFrame(QuicMtuDiscoveryFrame())}; |
| 9242 | |
| 9243 | // clang-format off |
| 9244 | unsigned char packet[] = { |
| 9245 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 9246 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9247 | // connection_id |
| 9248 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9249 | // packet number |
| 9250 | 0x12, 0x34, 0x56, 0x78, |
| 9251 | |
| 9252 | // frame type (ping frame) |
| 9253 | 0x07, |
| 9254 | }; |
| 9255 | |
| 9256 | unsigned char packet44[] = { |
| 9257 | // type (short header, 4 byte packet number) |
| 9258 | 0x32, |
| 9259 | // connection_id |
| 9260 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9261 | // packet number |
| 9262 | 0x12, 0x34, 0x56, 0x78, |
| 9263 | |
| 9264 | // frame type |
| 9265 | 0x07, |
| 9266 | }; |
| 9267 | |
| 9268 | unsigned char packet46[] = { |
| 9269 | // type (short header, 4 byte packet number) |
| 9270 | 0x43, |
| 9271 | // connection_id |
| 9272 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9273 | // packet number |
| 9274 | 0x12, 0x34, 0x56, 0x78, |
| 9275 | |
| 9276 | // frame type |
| 9277 | 0x07, |
| 9278 | }; |
| 9279 | |
| 9280 | unsigned char packet99[] = { |
| 9281 | // type (short header, 4 byte packet number) |
| 9282 | 0x43, |
| 9283 | // connection_id |
| 9284 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9285 | // packet number |
| 9286 | 0x12, 0x34, 0x56, 0x78, |
| 9287 | |
| 9288 | // frame type (IETF_PING frame) |
| 9289 | 0x01, |
| 9290 | }; |
| 9291 | // clang-format on |
| 9292 | |
| 9293 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 9294 | ASSERT_TRUE(data != nullptr); |
| 9295 | |
| 9296 | unsigned char* p = packet; |
| 9297 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9298 | p = packet99; |
| 9299 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 9300 | p = packet46; |
| 9301 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9302 | p = packet44; |
| 9303 | } |
| 9304 | |
| 9305 | test::CompareCharArraysWithHexError( |
| 9306 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 9307 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 9308 | : QUIC_ARRAYSIZE(packet)); |
| 9309 | } |
| 9310 | |
| 9311 | TEST_P(QuicFramerTest, BuildPublicResetPacket) { |
| 9312 | QuicPublicResetPacket reset_packet; |
| 9313 | reset_packet.connection_id = FramerTestConnectionId(); |
| 9314 | reset_packet.nonce_proof = kNonceProof; |
| 9315 | |
| 9316 | // clang-format off |
| 9317 | unsigned char packet[] = { |
| 9318 | // public flags (public reset, 8 byte ConnectionId) |
| 9319 | 0x0E, |
| 9320 | // connection_id |
| 9321 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9322 | // message tag (kPRST) |
| 9323 | 'P', 'R', 'S', 'T', |
| 9324 | // num_entries (1) + padding |
| 9325 | 0x01, 0x00, 0x00, 0x00, |
| 9326 | // tag kRNON |
| 9327 | 'R', 'N', 'O', 'N', |
| 9328 | // end offset 8 |
| 9329 | 0x08, 0x00, 0x00, 0x00, |
| 9330 | // nonce proof |
| 9331 | 0x89, 0x67, 0x45, 0x23, |
| 9332 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9333 | }; |
| 9334 | // clang-format on |
| 9335 | |
| 9336 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9337 | return; |
| 9338 | } |
| 9339 | |
| 9340 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9341 | framer_.BuildPublicResetPacket(reset_packet)); |
| 9342 | ASSERT_TRUE(data != nullptr); |
| 9343 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 9344 | data->length(), AsChars(packet), |
| 9345 | QUIC_ARRAYSIZE(packet)); |
| 9346 | } |
| 9347 | |
| 9348 | TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) { |
| 9349 | QuicPublicResetPacket reset_packet; |
| 9350 | reset_packet.connection_id = FramerTestConnectionId(); |
| 9351 | reset_packet.nonce_proof = kNonceProof; |
| 9352 | reset_packet.client_address = |
| 9353 | QuicSocketAddress(QuicIpAddress::Loopback4(), 0x1234); |
| 9354 | |
| 9355 | // clang-format off |
| 9356 | unsigned char packet[] = { |
| 9357 | // public flags (public reset, 8 byte ConnectionId) |
| 9358 | 0x0E, |
| 9359 | // connection_id |
| 9360 | 0xFE, 0xDC, 0xBA, 0x98, |
| 9361 | 0x76, 0x54, 0x32, 0x10, |
| 9362 | // message tag (kPRST) |
| 9363 | 'P', 'R', 'S', 'T', |
| 9364 | // num_entries (2) + padding |
| 9365 | 0x02, 0x00, 0x00, 0x00, |
| 9366 | // tag kRNON |
| 9367 | 'R', 'N', 'O', 'N', |
| 9368 | // end offset 8 |
| 9369 | 0x08, 0x00, 0x00, 0x00, |
| 9370 | // tag kCADR |
| 9371 | 'C', 'A', 'D', 'R', |
| 9372 | // end offset 16 |
| 9373 | 0x10, 0x00, 0x00, 0x00, |
| 9374 | // nonce proof |
| 9375 | 0x89, 0x67, 0x45, 0x23, |
| 9376 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9377 | // client address |
| 9378 | 0x02, 0x00, |
| 9379 | 0x7F, 0x00, 0x00, 0x01, |
| 9380 | 0x34, 0x12, |
| 9381 | }; |
| 9382 | // clang-format on |
| 9383 | |
| 9384 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9385 | return; |
| 9386 | } |
| 9387 | |
| 9388 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9389 | framer_.BuildPublicResetPacket(reset_packet)); |
| 9390 | ASSERT_TRUE(data != nullptr); |
| 9391 | |
| 9392 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 9393 | data->length(), AsChars(packet), |
| 9394 | QUIC_ARRAYSIZE(packet)); |
| 9395 | } |
| 9396 | |
| 9397 | TEST_P(QuicFramerTest, BuildPublicResetPacketWithEndpointId) { |
| 9398 | QuicPublicResetPacket reset_packet; |
| 9399 | reset_packet.connection_id = FramerTestConnectionId(); |
| 9400 | reset_packet.nonce_proof = kNonceProof; |
| 9401 | reset_packet.endpoint_id = "FakeServerId"; |
| 9402 | |
| 9403 | // The tag value map in CryptoHandshakeMessage is a std::map, so the two tags |
| 9404 | // in the packet, kRNON and kEPID, have unspecified ordering w.r.t each other. |
| 9405 | // clang-format off |
| 9406 | unsigned char packet_variant1[] = { |
| 9407 | // public flags (public reset, 8 byte ConnectionId) |
| 9408 | 0x0E, |
| 9409 | // connection_id |
| 9410 | 0xFE, 0xDC, 0xBA, 0x98, |
| 9411 | 0x76, 0x54, 0x32, 0x10, |
| 9412 | // message tag (kPRST) |
| 9413 | 'P', 'R', 'S', 'T', |
| 9414 | // num_entries (2) + padding |
| 9415 | 0x02, 0x00, 0x00, 0x00, |
| 9416 | // tag kRNON |
| 9417 | 'R', 'N', 'O', 'N', |
| 9418 | // end offset 8 |
| 9419 | 0x08, 0x00, 0x00, 0x00, |
| 9420 | // tag kEPID |
| 9421 | 'E', 'P', 'I', 'D', |
| 9422 | // end offset 20 |
| 9423 | 0x14, 0x00, 0x00, 0x00, |
| 9424 | // nonce proof |
| 9425 | 0x89, 0x67, 0x45, 0x23, |
| 9426 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9427 | // Endpoint ID |
| 9428 | 'F', 'a', 'k', 'e', 'S', 'e', 'r', 'v', 'e', 'r', 'I', 'd', |
| 9429 | }; |
| 9430 | unsigned char packet_variant2[] = { |
| 9431 | // public flags (public reset, 8 byte ConnectionId) |
| 9432 | 0x0E, |
| 9433 | // connection_id |
| 9434 | 0xFE, 0xDC, 0xBA, 0x98, |
| 9435 | 0x76, 0x54, 0x32, 0x10, |
| 9436 | // message tag (kPRST) |
| 9437 | 'P', 'R', 'S', 'T', |
| 9438 | // num_entries (2) + padding |
| 9439 | 0x02, 0x00, 0x00, 0x00, |
| 9440 | // tag kEPID |
| 9441 | 'E', 'P', 'I', 'D', |
| 9442 | // end offset 12 |
| 9443 | 0x0C, 0x00, 0x00, 0x00, |
| 9444 | // tag kRNON |
| 9445 | 'R', 'N', 'O', 'N', |
| 9446 | // end offset 20 |
| 9447 | 0x14, 0x00, 0x00, 0x00, |
| 9448 | // Endpoint ID |
| 9449 | 'F', 'a', 'k', 'e', 'S', 'e', 'r', 'v', 'e', 'r', 'I', 'd', |
| 9450 | // nonce proof |
| 9451 | 0x89, 0x67, 0x45, 0x23, |
| 9452 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9453 | }; |
| 9454 | // clang-format on |
| 9455 | |
| 9456 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9457 | return; |
| 9458 | } |
| 9459 | |
| 9460 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9461 | framer_.BuildPublicResetPacket(reset_packet)); |
| 9462 | ASSERT_TRUE(data != nullptr); |
| 9463 | |
| 9464 | // Variant 1 ends with char 'd'. Variant 1 ends with char 0xAB. |
| 9465 | if ('d' == data->data()[data->length() - 1]) { |
| 9466 | test::CompareCharArraysWithHexError( |
| 9467 | "constructed packet", data->data(), data->length(), |
| 9468 | AsChars(packet_variant1), QUIC_ARRAYSIZE(packet_variant1)); |
| 9469 | } else { |
| 9470 | test::CompareCharArraysWithHexError( |
| 9471 | "constructed packet", data->data(), data->length(), |
| 9472 | AsChars(packet_variant2), QUIC_ARRAYSIZE(packet_variant2)); |
| 9473 | } |
| 9474 | } |
| 9475 | |
| 9476 | TEST_P(QuicFramerTest, BuildIetfStatelessResetPacket) { |
| 9477 | // clang-format off |
| 9478 | unsigned char packet44[] = { |
| 9479 | // type (short header, 1 byte packet number) |
| 9480 | 0x70, |
| 9481 | // random packet number |
| 9482 | 0xFE, |
| 9483 | // stateless reset token |
| 9484 | 0xB5, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 9485 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 9486 | }; |
| 9487 | // clang-format on |
| 9488 | |
| 9489 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9490 | framer_.BuildIetfStatelessResetPacket(FramerTestConnectionId(), |
| 9491 | kTestStatelessResetToken)); |
| 9492 | ASSERT_TRUE(data != nullptr); |
| 9493 | // Skip packet number byte which is random in stateless reset packet. |
| 9494 | test::CompareCharArraysWithHexError("constructed packet", data->data(), 1, |
| 9495 | AsChars(packet44), 1); |
| 9496 | const size_t random_bytes_length = |
| 9497 | data->length() - kPacketHeaderTypeSize - sizeof(kTestStatelessResetToken); |
| 9498 | EXPECT_EQ(kMinRandomBytesLengthInStatelessReset, random_bytes_length); |
| 9499 | // Verify stateless reset token is correct. |
| 9500 | test::CompareCharArraysWithHexError( |
| 9501 | "constructed packet", |
| 9502 | data->data() + data->length() - sizeof(kTestStatelessResetToken), |
| 9503 | sizeof(kTestStatelessResetToken), |
| 9504 | AsChars(packet44) + QUIC_ARRAYSIZE(packet44) - |
| 9505 | sizeof(kTestStatelessResetToken), |
| 9506 | sizeof(kTestStatelessResetToken)); |
| 9507 | } |
| 9508 | |
| 9509 | TEST_P(QuicFramerTest, EncryptPacket) { |
| 9510 | QuicPacketNumber packet_number = kPacketNumber; |
| 9511 | // clang-format off |
| 9512 | unsigned char packet[] = { |
| 9513 | // public flags (8 byte connection_id) |
| 9514 | 0x28, |
| 9515 | // connection_id |
| 9516 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9517 | // packet number |
| 9518 | 0x12, 0x34, 0x56, 0x78, |
| 9519 | |
| 9520 | // redundancy |
| 9521 | 'a', 'b', 'c', 'd', |
| 9522 | 'e', 'f', 'g', 'h', |
| 9523 | 'i', 'j', 'k', 'l', |
| 9524 | 'm', 'n', 'o', 'p', |
| 9525 | }; |
| 9526 | |
| 9527 | unsigned char packet44[] = { |
| 9528 | // type (short header, 4 byte packet number) |
| 9529 | 0x32, |
| 9530 | // connection_id |
| 9531 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9532 | // packet number |
| 9533 | 0x12, 0x34, 0x56, 0x78, |
| 9534 | |
| 9535 | // redundancy |
| 9536 | 'a', 'b', 'c', 'd', |
| 9537 | 'e', 'f', 'g', 'h', |
| 9538 | 'i', 'j', 'k', 'l', |
| 9539 | 'm', 'n', 'o', 'p', |
| 9540 | }; |
| 9541 | |
| 9542 | unsigned char packet46[] = { |
| 9543 | // type (short header, 4 byte packet number) |
| 9544 | 0x43, |
| 9545 | // connection_id |
| 9546 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9547 | // packet number |
| 9548 | 0x12, 0x34, 0x56, 0x78, |
| 9549 | |
| 9550 | // redundancy |
| 9551 | 'a', 'b', 'c', 'd', |
| 9552 | 'e', 'f', 'g', 'h', |
| 9553 | 'i', 'j', 'k', 'l', |
| 9554 | 'm', 'n', 'o', 'p', |
| 9555 | }; |
| 9556 | |
| 9557 | unsigned char packet99[] = { |
| 9558 | // type (short header, 4 byte packet number) |
| 9559 | 0x43, |
| 9560 | // connection_id |
| 9561 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9562 | // packet number |
| 9563 | 0x12, 0x34, 0x56, 0x78, |
| 9564 | |
| 9565 | // redundancy |
| 9566 | 'a', 'b', 'c', 'd', |
| 9567 | 'e', 'f', 'g', 'h', |
| 9568 | 'i', 'j', 'k', 'l', |
| 9569 | 'm', 'n', 'o', 'p', |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9570 | 'q', 'r', 's', 't', |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9571 | }; |
| 9572 | // clang-format on |
| 9573 | |
| 9574 | unsigned char* p = packet; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9575 | size_t p_size = QUIC_ARRAYSIZE(packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9576 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9577 | p = packet99; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9578 | p_size = QUIC_ARRAYSIZE(packet99); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9579 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 9580 | p = packet46; |
| 9581 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9582 | p = packet44; |
| 9583 | } |
| 9584 | |
| 9585 | std::unique_ptr<QuicPacket> raw(new QuicPacket( |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9586 | AsChars(p), p_size, false, PACKET_8BYTE_CONNECTION_ID, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9587 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 9588 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 9589 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0)); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9590 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9591 | size_t encrypted_length = framer_.EncryptPayload( |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9592 | ENCRYPTION_INITIAL, packet_number, *raw, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9593 | |
| 9594 | ASSERT_NE(0u, encrypted_length); |
| 9595 | EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); |
| 9596 | } |
| 9597 | |
| 9598 | TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9599 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9600 | QuicPacketNumber packet_number = kPacketNumber; |
| 9601 | // clang-format off |
| 9602 | unsigned char packet[] = { |
| 9603 | // public flags (version, 8 byte connection_id) |
| 9604 | 0x29, |
| 9605 | // connection_id |
| 9606 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9607 | // version tag |
| 9608 | 'Q', '.', '1', '0', |
| 9609 | // packet number |
| 9610 | 0x12, 0x34, 0x56, 0x78, |
| 9611 | |
| 9612 | // redundancy |
| 9613 | 'a', 'b', 'c', 'd', |
| 9614 | 'e', 'f', 'g', 'h', |
| 9615 | 'i', 'j', 'k', 'l', |
| 9616 | 'm', 'n', 'o', 'p', |
| 9617 | }; |
| 9618 | |
| 9619 | unsigned char packet44[] = { |
| 9620 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 9621 | 0xFC, |
| 9622 | // version tag |
| 9623 | 'Q', '.', '1', '0', |
| 9624 | // connection_id length |
| 9625 | 0x50, |
| 9626 | // connection_id |
| 9627 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9628 | // packet number |
| 9629 | 0x12, 0x34, 0x56, 0x78, |
| 9630 | |
| 9631 | // redundancy |
| 9632 | 'a', 'b', 'c', 'd', |
| 9633 | 'e', 'f', 'g', 'h', |
| 9634 | 'i', 'j', 'k', 'l', |
| 9635 | 'm', 'n', 'o', 'p', |
| 9636 | }; |
| 9637 | |
| 9638 | unsigned char packet46[] = { |
| 9639 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 9640 | 0xD3, |
| 9641 | // version tag |
| 9642 | 'Q', '.', '1', '0', |
| 9643 | // connection_id length |
| 9644 | 0x50, |
| 9645 | // connection_id |
| 9646 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9647 | // packet number |
| 9648 | 0x12, 0x34, 0x56, 0x78, |
| 9649 | |
| 9650 | // redundancy |
| 9651 | 'a', 'b', 'c', 'd', |
| 9652 | 'e', 'f', 'g', 'h', |
| 9653 | 'i', 'j', 'k', 'l', |
| 9654 | 'm', 'n', 'o', 'p', |
| 9655 | }; |
| 9656 | |
| 9657 | unsigned char packet99[] = { |
| 9658 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 9659 | 0xD3, |
| 9660 | // version tag |
| 9661 | 'Q', '.', '1', '0', |
| 9662 | // connection_id length |
| 9663 | 0x50, |
| 9664 | // connection_id |
| 9665 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9666 | // packet number |
| 9667 | 0x12, 0x34, 0x56, 0x78, |
| 9668 | |
| 9669 | // redundancy |
| 9670 | 'a', 'b', 'c', 'd', |
| 9671 | 'e', 'f', 'g', 'h', |
| 9672 | 'i', 'j', 'k', 'l', |
| 9673 | 'm', 'n', 'o', 'p', |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9674 | 'q', 'r', 's', 't', |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9675 | }; |
| 9676 | // clang-format on |
| 9677 | |
| 9678 | unsigned char* p = packet; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9679 | size_t p_size = QUIC_ARRAYSIZE(packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9680 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9681 | p = packet99; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9682 | p_size = QUIC_ARRAYSIZE(packet99); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9683 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 9684 | p = packet46; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9685 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9686 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9687 | p = packet44; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9688 | p_size = QUIC_ARRAYSIZE(packet44); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9689 | } |
| 9690 | |
| 9691 | std::unique_ptr<QuicPacket> raw(new QuicPacket( |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9692 | AsChars(p), p_size, false, PACKET_8BYTE_CONNECTION_ID, |
| 9693 | PACKET_0BYTE_CONNECTION_ID, kIncludeVersion, |
| 9694 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 9695 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0)); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9696 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9697 | size_t encrypted_length = framer_.EncryptPayload( |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9698 | ENCRYPTION_INITIAL, packet_number, *raw, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9699 | |
| 9700 | ASSERT_NE(0u, encrypted_length); |
| 9701 | EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); |
| 9702 | } |
| 9703 | |
| 9704 | TEST_P(QuicFramerTest, AckTruncationLargePacket) { |
| 9705 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9706 | // This test is not applicable to this version; the range count is |
| 9707 | // effectively unlimited |
| 9708 | return; |
| 9709 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9710 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9711 | |
| 9712 | QuicPacketHeader header; |
| 9713 | header.destination_connection_id = FramerTestConnectionId(); |
| 9714 | header.reset_flag = false; |
| 9715 | header.version_flag = false; |
| 9716 | header.packet_number = kPacketNumber; |
| 9717 | |
| 9718 | QuicAckFrame ack_frame; |
| 9719 | // Create a packet with just the ack. |
| 9720 | ack_frame = MakeAckFrameWithAckBlocks(300, 0u); |
| 9721 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9722 | |
| 9723 | // Build an ack packet with truncation due to limit in number of nack ranges. |
| 9724 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9725 | std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); |
| 9726 | ASSERT_TRUE(raw_ack_packet != nullptr); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9727 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9728 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9729 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9730 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9731 | ASSERT_NE(0u, encrypted_length); |
| 9732 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9733 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9734 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9735 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9736 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 9737 | QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; |
| 9738 | EXPECT_EQ(QuicPacketNumber(600u), LargestAcked(processed_ack_frame)); |
| 9739 | ASSERT_EQ(256u, processed_ack_frame.packets.NumPacketsSlow()); |
| 9740 | EXPECT_EQ(QuicPacketNumber(90u), processed_ack_frame.packets.Min()); |
| 9741 | EXPECT_EQ(QuicPacketNumber(600u), processed_ack_frame.packets.Max()); |
| 9742 | } |
| 9743 | |
| 9744 | TEST_P(QuicFramerTest, AckTruncationSmallPacket) { |
| 9745 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9746 | // This test is not applicable to this version; the range count is |
| 9747 | // effectively unlimited |
| 9748 | return; |
| 9749 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9750 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9751 | |
| 9752 | QuicPacketHeader header; |
| 9753 | header.destination_connection_id = FramerTestConnectionId(); |
| 9754 | header.reset_flag = false; |
| 9755 | header.version_flag = false; |
| 9756 | header.packet_number = kPacketNumber; |
| 9757 | |
| 9758 | // Create a packet with just the ack. |
| 9759 | QuicAckFrame ack_frame; |
| 9760 | ack_frame = MakeAckFrameWithAckBlocks(300, 0u); |
| 9761 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9762 | |
| 9763 | // Build an ack packet with truncation due to limit in number of nack ranges. |
| 9764 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9765 | std::unique_ptr<QuicPacket> raw_ack_packet( |
| 9766 | BuildDataPacket(header, frames, 500)); |
| 9767 | ASSERT_TRUE(raw_ack_packet != nullptr); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9768 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9769 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9770 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9771 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9772 | ASSERT_NE(0u, encrypted_length); |
| 9773 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9774 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9775 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9776 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9777 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 9778 | QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; |
| 9779 | EXPECT_EQ(QuicPacketNumber(600u), LargestAcked(processed_ack_frame)); |
| 9780 | ASSERT_EQ(240u, processed_ack_frame.packets.NumPacketsSlow()); |
| 9781 | EXPECT_EQ(QuicPacketNumber(122u), processed_ack_frame.packets.Min()); |
| 9782 | EXPECT_EQ(QuicPacketNumber(600u), processed_ack_frame.packets.Max()); |
| 9783 | } |
| 9784 | |
| 9785 | TEST_P(QuicFramerTest, CleanTruncation) { |
| 9786 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9787 | // This test is not applicable to this version; the range count is |
| 9788 | // effectively unlimited |
| 9789 | return; |
| 9790 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9791 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9792 | |
| 9793 | QuicPacketHeader header; |
| 9794 | header.destination_connection_id = FramerTestConnectionId(); |
| 9795 | header.reset_flag = false; |
| 9796 | header.version_flag = false; |
| 9797 | header.packet_number = kPacketNumber; |
| 9798 | |
| 9799 | QuicAckFrame ack_frame = InitAckFrame(201); |
| 9800 | |
| 9801 | // Create a packet with just the ack. |
| 9802 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9803 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9804 | std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); |
| 9805 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9806 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9807 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9808 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9809 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9810 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9811 | ASSERT_NE(0u, encrypted_length); |
| 9812 | |
| 9813 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9814 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9815 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9816 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9817 | |
| 9818 | // Test for clean truncation of the ack by comparing the length of the |
| 9819 | // original packets to the re-serialized packets. |
| 9820 | frames.clear(); |
| 9821 | frames.push_back(QuicFrame(visitor_.ack_frames_[0].get())); |
| 9822 | |
| 9823 | size_t original_raw_length = raw_ack_packet->length(); |
| 9824 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9825 | raw_ack_packet = BuildDataPacket(header, frames); |
| 9826 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9827 | EXPECT_EQ(original_raw_length, raw_ack_packet->length()); |
| 9828 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9829 | } |
| 9830 | |
| 9831 | TEST_P(QuicFramerTest, StopPacketProcessing) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9832 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9833 | // clang-format off |
| 9834 | unsigned char packet[] = { |
| 9835 | // public flags (8 byte connection_id) |
| 9836 | 0x28, |
| 9837 | // connection_id |
| 9838 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9839 | // packet number |
| 9840 | 0x12, 0x34, 0x56, 0x78, |
| 9841 | |
| 9842 | // frame type (stream frame with fin) |
| 9843 | 0xFF, |
| 9844 | // stream id |
| 9845 | 0x01, 0x02, 0x03, 0x04, |
| 9846 | // offset |
| 9847 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9848 | 0x32, 0x10, 0x76, 0x54, |
| 9849 | // data length |
| 9850 | 0x00, 0x0c, |
| 9851 | // data |
| 9852 | 'h', 'e', 'l', 'l', |
| 9853 | 'o', ' ', 'w', 'o', |
| 9854 | 'r', 'l', 'd', '!', |
| 9855 | |
| 9856 | // frame type (ack frame) |
| 9857 | 0x40, |
| 9858 | // least packet number awaiting an ack |
| 9859 | 0x12, 0x34, 0x56, 0x78, |
| 9860 | 0x9A, 0xA0, |
| 9861 | // largest observed packet number |
| 9862 | 0x12, 0x34, 0x56, 0x78, |
| 9863 | 0x9A, 0xBF, |
| 9864 | // num missing packets |
| 9865 | 0x01, |
| 9866 | // missing packet |
| 9867 | 0x12, 0x34, 0x56, 0x78, |
| 9868 | 0x9A, 0xBE, |
| 9869 | }; |
| 9870 | |
| 9871 | unsigned char packet44[] = { |
| 9872 | // type (short header, 4 byte packet number) |
| 9873 | 0x32, |
| 9874 | // connection_id |
| 9875 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9876 | // packet number |
| 9877 | 0x12, 0x34, 0x56, 0x78, |
| 9878 | |
| 9879 | // frame type (stream frame with fin) |
| 9880 | 0xFF, |
| 9881 | // stream id |
| 9882 | 0x01, 0x02, 0x03, 0x04, |
| 9883 | // offset |
| 9884 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9885 | 0x32, 0x10, 0x76, 0x54, |
| 9886 | // data length |
| 9887 | 0x00, 0x0c, |
| 9888 | // data |
| 9889 | 'h', 'e', 'l', 'l', |
| 9890 | 'o', ' ', 'w', 'o', |
| 9891 | 'r', 'l', 'd', '!', |
| 9892 | |
| 9893 | // frame type (ack frame) |
| 9894 | 0x40, |
| 9895 | // least packet number awaiting an ack |
| 9896 | 0x12, 0x34, 0x56, 0x78, |
| 9897 | 0x9A, 0xA0, |
| 9898 | // largest observed packet number |
| 9899 | 0x12, 0x34, 0x56, 0x78, |
| 9900 | 0x9A, 0xBF, |
| 9901 | // num missing packets |
| 9902 | 0x01, |
| 9903 | // missing packet |
| 9904 | 0x12, 0x34, 0x56, 0x78, |
| 9905 | 0x9A, 0xBE, |
| 9906 | }; |
| 9907 | |
| 9908 | unsigned char packet46[] = { |
| 9909 | // type (short header, 4 byte packet number) |
| 9910 | 0x43, |
| 9911 | // connection_id |
| 9912 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9913 | // packet number |
| 9914 | 0x12, 0x34, 0x56, 0x78, |
| 9915 | |
| 9916 | // frame type (stream frame with fin) |
| 9917 | 0xFF, |
| 9918 | // stream id |
| 9919 | 0x01, 0x02, 0x03, 0x04, |
| 9920 | // offset |
| 9921 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9922 | 0x32, 0x10, 0x76, 0x54, |
| 9923 | // data length |
| 9924 | 0x00, 0x0c, |
| 9925 | // data |
| 9926 | 'h', 'e', 'l', 'l', |
| 9927 | 'o', ' ', 'w', 'o', |
| 9928 | 'r', 'l', 'd', '!', |
| 9929 | |
| 9930 | // frame type (ack frame) |
| 9931 | 0x40, |
| 9932 | // least packet number awaiting an ack |
| 9933 | 0x12, 0x34, 0x56, 0x78, |
| 9934 | 0x9A, 0xA0, |
| 9935 | // largest observed packet number |
| 9936 | 0x12, 0x34, 0x56, 0x78, |
| 9937 | 0x9A, 0xBF, |
| 9938 | // num missing packets |
| 9939 | 0x01, |
| 9940 | // missing packet |
| 9941 | 0x12, 0x34, 0x56, 0x78, |
| 9942 | 0x9A, 0xBE, |
| 9943 | }; |
| 9944 | |
| 9945 | unsigned char packet99[] = { |
| 9946 | // type (short header, 4 byte packet number) |
| 9947 | 0x43, |
| 9948 | // connection_id |
| 9949 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9950 | // packet number |
| 9951 | 0x12, 0x34, 0x56, 0x78, |
| 9952 | |
| 9953 | // frame type (IETF_STREAM frame with fin, length, and offset bits set) |
| 9954 | 0x08 | 0x01 | 0x02 | 0x04, |
| 9955 | // stream id |
| 9956 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 9957 | // offset |
| 9958 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 9959 | 0x32, 0x10, 0x76, 0x54, |
| 9960 | // data length |
| 9961 | kVarInt62TwoBytes + 0x00, 0x0c, |
| 9962 | // data |
| 9963 | 'h', 'e', 'l', 'l', |
| 9964 | 'o', ' ', 'w', 'o', |
| 9965 | 'r', 'l', 'd', '!', |
| 9966 | |
| 9967 | // frame type (ack frame) |
| 9968 | 0x0d, |
| 9969 | // largest observed packet number |
| 9970 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 9971 | // Delta time |
| 9972 | kVarInt62OneByte + 0x00, |
| 9973 | // Ack Block count |
| 9974 | kVarInt62OneByte + 0x01, |
| 9975 | // First block size (one packet) |
| 9976 | kVarInt62OneByte + 0x00, |
| 9977 | |
| 9978 | // Next gap size & ack. Missing all preceding packets |
| 9979 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 9980 | kVarInt62OneByte + 0x00, |
| 9981 | }; |
| 9982 | // clang-format on |
| 9983 | |
| 9984 | MockFramerVisitor visitor; |
| 9985 | framer_.set_visitor(&visitor); |
| 9986 | EXPECT_CALL(visitor, OnPacket()); |
| 9987 | EXPECT_CALL(visitor, OnPacketHeader(_)); |
| 9988 | EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false)); |
| 9989 | EXPECT_CALL(visitor, OnPacketComplete()); |
| 9990 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); |
| 9991 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)).WillOnce(Return(true)); |
| 9992 | EXPECT_CALL(visitor, OnDecryptedPacket(_)); |
| 9993 | |
| 9994 | unsigned char* p = packet; |
| 9995 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 9996 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9997 | p = packet99; |
| 9998 | p_size = QUIC_ARRAYSIZE(packet99); |
| 9999 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 10000 | p = packet46; |
| 10001 | p_size = QUIC_ARRAYSIZE(packet46); |
| 10002 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 10003 | p = packet44; |
| 10004 | p_size = QUIC_ARRAYSIZE(packet44); |
| 10005 | } |
| 10006 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 10007 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10008 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10009 | } |
| 10010 | |
| 10011 | static char kTestString[] = "At least 20 characters."; |
| 10012 | static QuicStreamId kTestQuicStreamId = 1; |
| 10013 | static bool ExpectedStreamFrame(const QuicStreamFrame& frame) { |
| 10014 | return (frame.stream_id == kTestQuicStreamId || |
| 10015 | frame.stream_id == QuicUtils::GetCryptoStreamId(QUIC_VERSION_99)) && |
| 10016 | !frame.fin && frame.offset == 0 && |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 10017 | std::string(frame.data_buffer, frame.data_length) == kTestString; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10018 | // FIN is hard-coded false in ConstructEncryptedPacket. |
| 10019 | // Offset 0 is hard-coded in ConstructEncryptedPacket. |
| 10020 | } |
| 10021 | |
| 10022 | // Verify that the packet returned by ConstructEncryptedPacket() can be properly |
| 10023 | // parsed by the framer. |
| 10024 | TEST_P(QuicFramerTest, ConstructEncryptedPacket) { |
| 10025 | // Since we are using ConstructEncryptedPacket, we have to set the framer's |
| 10026 | // crypto to be Null. |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10027 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 10028 | framer_.InstallDecrypter( |
| 10029 | ENCRYPTION_FORWARD_SECURE, |
| 10030 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
| 10031 | } else { |
| 10032 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 10033 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
| 10034 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10035 | ParsedQuicVersionVector versions; |
| 10036 | versions.push_back(framer_.version()); |
| 10037 | std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
| 10038 | TestConnectionId(), EmptyQuicConnectionId(), false, false, |
| 10039 | kTestQuicStreamId, kTestString, CONNECTION_ID_PRESENT, |
| 10040 | CONNECTION_ID_ABSENT, PACKET_4BYTE_PACKET_NUMBER, &versions)); |
| 10041 | |
| 10042 | MockFramerVisitor visitor; |
| 10043 | framer_.set_visitor(&visitor); |
| 10044 | EXPECT_CALL(visitor, OnPacket()).Times(1); |
| 10045 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) |
| 10046 | .Times(1) |
| 10047 | .WillOnce(Return(true)); |
| 10048 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) |
| 10049 | .Times(1) |
| 10050 | .WillOnce(Return(true)); |
| 10051 | EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1).WillOnce(Return(true)); |
| 10052 | EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); |
| 10053 | EXPECT_CALL(visitor, OnError(_)).Times(0); |
| 10054 | EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); |
QUICHE team | ea74008 | 2019-03-11 17:58:43 -0700 | [diff] [blame] | 10055 | if (!QuicVersionUsesCryptoFrames(framer_.version().transport_version)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10056 | EXPECT_CALL(visitor, OnStreamFrame(Truly(ExpectedStreamFrame))).Times(1); |
| 10057 | } else { |
| 10058 | EXPECT_CALL(visitor, OnCryptoFrame(_)).Times(1); |
| 10059 | } |
| 10060 | EXPECT_CALL(visitor, OnPacketComplete()).Times(1); |
| 10061 | |
| 10062 | EXPECT_TRUE(framer_.ProcessPacket(*packet)); |
| 10063 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10064 | } |
| 10065 | |
| 10066 | // Verify that the packet returned by ConstructMisFramedEncryptedPacket() |
| 10067 | // does cause the framer to return an error. |
| 10068 | TEST_P(QuicFramerTest, ConstructMisFramedEncryptedPacket) { |
| 10069 | // Since we are using ConstructEncryptedPacket, we have to set the framer's |
| 10070 | // crypto to be Null. |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10071 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 10072 | framer_.InstallDecrypter( |
| 10073 | ENCRYPTION_FORWARD_SECURE, |
| 10074 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10075 | } else { |
| 10076 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 10077 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
| 10078 | } |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 10079 | framer_.SetEncrypter(ENCRYPTION_INITIAL, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10080 | QuicMakeUnique<NullEncrypter>(framer_.perspective())); |
| 10081 | ParsedQuicVersionVector versions; |
| 10082 | versions.push_back(framer_.version()); |
| 10083 | std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( |
| 10084 | TestConnectionId(), EmptyQuicConnectionId(), false, false, |
| 10085 | kTestQuicStreamId, kTestString, CONNECTION_ID_PRESENT, |
| 10086 | CONNECTION_ID_ABSENT, PACKET_4BYTE_PACKET_NUMBER, &versions, |
| 10087 | Perspective::IS_CLIENT)); |
| 10088 | |
| 10089 | MockFramerVisitor visitor; |
| 10090 | framer_.set_visitor(&visitor); |
| 10091 | EXPECT_CALL(visitor, OnPacket()).Times(1); |
| 10092 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) |
| 10093 | .Times(1) |
| 10094 | .WillOnce(Return(true)); |
| 10095 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) |
| 10096 | .Times(1) |
| 10097 | .WillOnce(Return(true)); |
| 10098 | EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1); |
| 10099 | EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); |
| 10100 | EXPECT_CALL(visitor, OnError(_)).Times(1); |
| 10101 | EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); |
| 10102 | EXPECT_CALL(visitor, OnPacketComplete()).Times(0); |
| 10103 | |
| 10104 | EXPECT_FALSE(framer_.ProcessPacket(*packet)); |
| 10105 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 10106 | } |
| 10107 | |
| 10108 | // Tests for fuzzing with Dr. Fuzz |
| 10109 | // Xref http://www.chromium.org/developers/testing/dr-fuzz for more details. |
| 10110 | #ifdef __cplusplus |
| 10111 | extern "C" { |
| 10112 | #endif |
| 10113 | |
| 10114 | // target function to be fuzzed by Dr. Fuzz |
| 10115 | void QuicFramerFuzzFunc(unsigned char* data, |
| 10116 | size_t size, |
| 10117 | const ParsedQuicVersion& version) { |
| 10118 | QuicFramer framer(AllSupportedVersions(), QuicTime::Zero(), |
| 10119 | Perspective::IS_SERVER, kQuicDefaultConnectionIdLength); |
| 10120 | ASSERT_EQ(GetQuicFlag(FLAGS_quic_supports_tls_handshake), true); |
| 10121 | const char* const packet_bytes = reinterpret_cast<const char*>(data); |
| 10122 | |
| 10123 | // Test the CryptoFramer. |
| 10124 | QuicStringPiece crypto_input(packet_bytes, size); |
| 10125 | std::unique_ptr<CryptoHandshakeMessage> handshake_message( |
| 10126 | CryptoFramer::ParseMessage(crypto_input)); |
| 10127 | |
| 10128 | // Test the regular QuicFramer with the same input. |
| 10129 | NoOpFramerVisitor visitor; |
| 10130 | framer.set_visitor(&visitor); |
| 10131 | framer.set_version(version); |
| 10132 | QuicEncryptedPacket packet(packet_bytes, size); |
| 10133 | framer.ProcessPacket(packet); |
| 10134 | } |
| 10135 | |
| 10136 | #ifdef __cplusplus |
| 10137 | } |
| 10138 | #endif |
| 10139 | |
| 10140 | TEST_P(QuicFramerTest, FramerFuzzTest) { |
| 10141 | // clang-format off |
| 10142 | unsigned char packet[] = { |
| 10143 | // public flags (8 byte connection_id) |
| 10144 | 0x2C, |
| 10145 | // connection_id |
| 10146 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10147 | // packet number |
| 10148 | 0x12, 0x34, 0x56, 0x78, |
| 10149 | // private flags |
| 10150 | 0x00, |
| 10151 | |
| 10152 | // frame type (stream frame with fin) |
| 10153 | 0xFF, |
| 10154 | // stream id |
| 10155 | 0x01, 0x02, 0x03, 0x04, |
| 10156 | // offset |
| 10157 | 0x3A, 0x98, 0xFE, 0xDC, |
| 10158 | 0x32, 0x10, 0x76, 0x54, |
| 10159 | // data length |
| 10160 | 0x00, 0x0c, |
| 10161 | // data |
| 10162 | 'h', 'e', 'l', 'l', |
| 10163 | 'o', ' ', 'w', 'o', |
| 10164 | 'r', 'l', 'd', '!', |
| 10165 | }; |
| 10166 | |
| 10167 | unsigned char packet44[] = { |
| 10168 | // type (short header, 4 byte packet number) |
| 10169 | 0x32, |
| 10170 | // packet number |
| 10171 | 0x12, 0x34, 0x56, 0x78, |
| 10172 | |
| 10173 | // frame type (stream frame with fin, length, and offset bits set) |
| 10174 | 0x10 | 0x01 | 0x02 | 0x04, |
| 10175 | // stream id |
| 10176 | 0x01, 0x02, 0x03, 0x04, |
| 10177 | // offset |
| 10178 | 0x3A, 0x98, 0xFE, 0xDC, |
| 10179 | 0x32, 0x10, 0x76, 0x54, |
| 10180 | // data length |
| 10181 | 0x00, 0x0c, |
| 10182 | // data |
| 10183 | 'h', 'e', 'l', 'l', |
| 10184 | 'o', ' ', 'w', 'o', |
| 10185 | 'r', 'l', 'd', '!', |
| 10186 | }; |
| 10187 | |
| 10188 | unsigned char packet46[] = { |
| 10189 | // type (short header, 4 byte packet number) |
| 10190 | 0x43, |
| 10191 | // packet number |
| 10192 | 0x12, 0x34, 0x56, 0x78, |
| 10193 | |
| 10194 | // frame type (stream frame with fin, length, and offset bits set) |
| 10195 | 0x10 | 0x01 | 0x02 | 0x04, |
| 10196 | // stream id |
| 10197 | 0x01, 0x02, 0x03, 0x04, |
| 10198 | // offset |
| 10199 | 0x3A, 0x98, 0xFE, 0xDC, |
| 10200 | 0x32, 0x10, 0x76, 0x54, |
| 10201 | // data length |
| 10202 | 0x00, 0x0c, |
| 10203 | // data |
| 10204 | 'h', 'e', 'l', 'l', |
| 10205 | 'o', ' ', 'w', 'o', |
| 10206 | 'r', 'l', 'd', '!', |
| 10207 | }; |
| 10208 | |
| 10209 | unsigned char packet99[] = { |
| 10210 | // type (short header, 4 byte packet number) |
| 10211 | 0x43, |
| 10212 | // packet number |
| 10213 | 0x12, 0x34, 0x56, 0x78, |
| 10214 | |
| 10215 | // frame type (IETF_STREAM frame with fin, length, and offset bits set) |
| 10216 | 0x08 | 0x01 | 0x02 | 0x04, |
| 10217 | // stream id |
| 10218 | 0x01, 0x02, 0x03, 0x04, |
| 10219 | // offset |
| 10220 | 0x3A, 0x98, 0xFE, 0xDC, |
| 10221 | 0x32, 0x10, 0x76, 0x54, |
| 10222 | // data length |
| 10223 | 0x00, 0x0c, |
| 10224 | // data |
| 10225 | 'h', 'e', 'l', 'l', |
| 10226 | 'o', ' ', 'w', 'o', |
| 10227 | 'r', 'l', 'd', '!', |
| 10228 | }; |
| 10229 | // clang-format on |
| 10230 | |
| 10231 | unsigned char* p = packet; |
| 10232 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 10233 | p = packet99; |
| 10234 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 10235 | p = packet46; |
| 10236 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 10237 | p = packet44; |
| 10238 | } |
| 10239 | QuicFramerFuzzFunc(p, |
| 10240 | framer_.transport_version() > QUIC_VERSION_43 |
| 10241 | ? QUIC_ARRAYSIZE(packet44) |
| 10242 | : QUIC_ARRAYSIZE(packet), |
| 10243 | framer_.version()); |
| 10244 | } |
| 10245 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10246 | TEST_P(QuicFramerTest, IetfBlockedFrame) { |
| 10247 | // This test only for version 99. |
| 10248 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10249 | return; |
| 10250 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10251 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10252 | |
| 10253 | // clang-format off |
| 10254 | PacketFragments packet99 = { |
| 10255 | // type (short header, 4 byte packet number) |
| 10256 | {"", |
| 10257 | {0x43}}, |
| 10258 | // connection_id |
| 10259 | {"", |
| 10260 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10261 | // packet number |
| 10262 | {"", |
| 10263 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10264 | // frame type (IETF_BLOCKED) |
| 10265 | {"", |
| 10266 | {0x14}}, |
| 10267 | // blocked offset |
| 10268 | {"Can not read blocked offset.", |
| 10269 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 10270 | }; |
| 10271 | // clang-format on |
| 10272 | |
| 10273 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10274 | AssemblePacketFromFragments(packet99)); |
| 10275 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10276 | |
| 10277 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10278 | ASSERT_TRUE(visitor_.header_.get()); |
| 10279 | EXPECT_TRUE(CheckDecryption( |
| 10280 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10281 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10282 | |
| 10283 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 10284 | |
| 10285 | CheckFramingBoundaries(packet99, QUIC_INVALID_BLOCKED_DATA); |
| 10286 | } |
| 10287 | |
| 10288 | TEST_P(QuicFramerTest, BuildIetfBlockedPacket) { |
| 10289 | // This test only for version 99. |
| 10290 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10291 | return; |
| 10292 | } |
| 10293 | |
| 10294 | QuicPacketHeader header; |
| 10295 | header.destination_connection_id = FramerTestConnectionId(); |
| 10296 | header.reset_flag = false; |
| 10297 | header.version_flag = false; |
| 10298 | header.packet_number = kPacketNumber; |
| 10299 | |
| 10300 | QuicBlockedFrame frame; |
| 10301 | frame.stream_id = QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 10302 | frame.offset = kStreamOffset; |
| 10303 | QuicFrames frames = {QuicFrame(&frame)}; |
| 10304 | |
| 10305 | // clang-format off |
| 10306 | unsigned char packet99[] = { |
| 10307 | // type (short header, 4 byte packet number) |
| 10308 | 0x43, |
| 10309 | // connection_id |
| 10310 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10311 | // packet number |
| 10312 | 0x12, 0x34, 0x56, 0x78, |
| 10313 | |
| 10314 | // frame type (IETF_BLOCKED) |
| 10315 | 0x14, |
| 10316 | // Offset |
| 10317 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 10318 | }; |
| 10319 | // clang-format on |
| 10320 | |
| 10321 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10322 | ASSERT_TRUE(data != nullptr); |
| 10323 | |
| 10324 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10325 | data->length(), AsChars(packet99), |
| 10326 | QUIC_ARRAYSIZE(packet99)); |
| 10327 | } |
| 10328 | |
| 10329 | TEST_P(QuicFramerTest, IetfStreamBlockedFrame) { |
| 10330 | // This test only for version 99. |
| 10331 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10332 | return; |
| 10333 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10334 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10335 | |
| 10336 | // clang-format off |
| 10337 | PacketFragments packet99 = { |
| 10338 | // type (short header, 4 byte packet number) |
| 10339 | {"", |
| 10340 | {0x43}}, |
| 10341 | // connection_id |
| 10342 | {"", |
| 10343 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10344 | // packet number |
| 10345 | {"", |
| 10346 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10347 | // frame type (IETF_STREAM_BLOCKED) |
| 10348 | {"", |
| 10349 | {0x15}}, |
| 10350 | // blocked offset |
| 10351 | {"Can not read stream blocked stream id.", |
| 10352 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 10353 | {"Can not read stream blocked offset.", |
| 10354 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 10355 | }; |
| 10356 | // clang-format on |
| 10357 | |
| 10358 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10359 | AssemblePacketFromFragments(packet99)); |
| 10360 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10361 | |
| 10362 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10363 | ASSERT_TRUE(visitor_.header_.get()); |
| 10364 | EXPECT_TRUE(CheckDecryption( |
| 10365 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10366 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10367 | |
| 10368 | EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); |
| 10369 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 10370 | |
| 10371 | CheckFramingBoundaries(packet99, QUIC_INVALID_STREAM_BLOCKED_DATA); |
| 10372 | } |
| 10373 | |
| 10374 | TEST_P(QuicFramerTest, BuildIetfStreamBlockedPacket) { |
| 10375 | // This test only for version 99. |
| 10376 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10377 | return; |
| 10378 | } |
| 10379 | |
| 10380 | QuicPacketHeader header; |
| 10381 | header.destination_connection_id = FramerTestConnectionId(); |
| 10382 | header.reset_flag = false; |
| 10383 | header.version_flag = false; |
| 10384 | header.packet_number = kPacketNumber; |
| 10385 | |
| 10386 | QuicBlockedFrame frame; |
| 10387 | frame.stream_id = kStreamId; |
| 10388 | frame.offset = kStreamOffset; |
| 10389 | QuicFrames frames = {QuicFrame(&frame)}; |
| 10390 | |
| 10391 | // clang-format off |
| 10392 | unsigned char packet99[] = { |
| 10393 | // type (short header, 4 byte packet number) |
| 10394 | 0x43, |
| 10395 | // connection_id |
| 10396 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10397 | // packet number |
| 10398 | 0x12, 0x34, 0x56, 0x78, |
| 10399 | |
| 10400 | // frame type (IETF_STREAM_BLOCKED) |
| 10401 | 0x15, |
| 10402 | // Stream ID |
| 10403 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 10404 | // Offset |
| 10405 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 10406 | }; |
| 10407 | // clang-format on |
| 10408 | |
| 10409 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10410 | ASSERT_TRUE(data != nullptr); |
| 10411 | |
| 10412 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10413 | data->length(), AsChars(packet99), |
| 10414 | QUIC_ARRAYSIZE(packet99)); |
| 10415 | } |
| 10416 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10417 | TEST_P(QuicFramerTest, BiDiMaxStreamsFrame) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10418 | // This test only for version 99. |
| 10419 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10420 | return; |
| 10421 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10422 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10423 | |
| 10424 | // clang-format off |
| 10425 | PacketFragments packet99 = { |
| 10426 | // type (short header, 4 byte packet number) |
| 10427 | {"", |
| 10428 | {0x43}}, |
| 10429 | // connection_id |
| 10430 | {"", |
| 10431 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10432 | // packet number |
| 10433 | {"", |
| 10434 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10435 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10436 | {"", |
| 10437 | {0x12}}, |
| 10438 | // max. streams |
| 10439 | {"Can not read MAX_STREAMS stream count.", |
| 10440 | {kVarInt62OneByte + 0x03}}, |
| 10441 | }; |
| 10442 | // clang-format on |
| 10443 | |
| 10444 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10445 | AssemblePacketFromFragments(packet99)); |
| 10446 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10447 | |
| 10448 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10449 | ASSERT_TRUE(visitor_.header_.get()); |
| 10450 | EXPECT_TRUE(CheckDecryption( |
| 10451 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10452 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10453 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10454 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 10455 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
| 10456 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10457 | } |
| 10458 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10459 | TEST_P(QuicFramerTest, UniDiMaxStreamsFrame) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10460 | // This test only for version 99. |
| 10461 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10462 | return; |
| 10463 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10464 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10465 | |
| 10466 | // clang-format off |
| 10467 | PacketFragments packet99 = { |
| 10468 | // type (short header, 4 byte packet number) |
| 10469 | {"", |
| 10470 | {0x43}}, |
| 10471 | // Test runs in client mode, no connection id |
| 10472 | // packet number |
| 10473 | {"", |
| 10474 | {0x12, 0x34, 0x9A, 0xBC}}, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10475 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10476 | {"", |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10477 | {0x13}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10478 | // max. streams |
| 10479 | {"Can not read MAX_STREAMS stream count.", |
| 10480 | {kVarInt62OneByte + 0x03}}, |
| 10481 | }; |
| 10482 | // clang-format on |
| 10483 | |
| 10484 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10485 | AssemblePacketFromFragments(packet99)); |
| 10486 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10487 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10488 | |
| 10489 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10490 | ASSERT_TRUE(visitor_.header_.get()); |
| 10491 | EXPECT_TRUE(CheckDecryption( |
| 10492 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10493 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10494 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10495 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 10496 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 10497 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10498 | } |
| 10499 | |
| 10500 | TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrame) { |
| 10501 | // This test only for version 99. |
| 10502 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10503 | return; |
| 10504 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10505 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10506 | |
| 10507 | // clang-format off |
| 10508 | PacketFragments packet99 = { |
| 10509 | // type (short header, 4 byte packet number) |
| 10510 | {"", |
| 10511 | {0x43}}, |
| 10512 | // connection_id |
| 10513 | {"", |
| 10514 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10515 | // packet number |
| 10516 | {"", |
| 10517 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10518 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 10519 | {"", |
| 10520 | {0x13}}, |
| 10521 | // max. streams |
| 10522 | {"Can not read MAX_STREAMS stream count.", |
| 10523 | {kVarInt62OneByte + 0x03}}, |
| 10524 | }; |
| 10525 | // clang-format on |
| 10526 | |
| 10527 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10528 | AssemblePacketFromFragments(packet99)); |
| 10529 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10530 | |
| 10531 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10532 | ASSERT_TRUE(visitor_.header_.get()); |
| 10533 | EXPECT_TRUE(CheckDecryption( |
| 10534 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10535 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10536 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10537 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 10538 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 10539 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10540 | } |
| 10541 | |
| 10542 | TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrame) { |
| 10543 | // This test only for version 99. |
| 10544 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10545 | return; |
| 10546 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10547 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10548 | |
| 10549 | // clang-format off |
| 10550 | PacketFragments packet99 = { |
| 10551 | // type (short header, 4 byte packet number) |
| 10552 | {"", |
| 10553 | {0x43}}, |
| 10554 | // Test runs in client mode, no connection id |
| 10555 | // packet number |
| 10556 | {"", |
| 10557 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10558 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 10559 | {"", |
| 10560 | {0x13}}, |
| 10561 | // max. streams |
| 10562 | {"Can not read MAX_STREAMS stream count.", |
| 10563 | {kVarInt62OneByte + 0x03}}, |
| 10564 | }; |
| 10565 | // clang-format on |
| 10566 | |
| 10567 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10568 | AssemblePacketFromFragments(packet99)); |
| 10569 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10570 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10571 | |
| 10572 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10573 | ASSERT_TRUE(visitor_.header_.get()); |
| 10574 | EXPECT_TRUE(CheckDecryption( |
| 10575 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10576 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10577 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10578 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 10579 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 10580 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10581 | } |
| 10582 | |
| 10583 | // The following four tests ensure that the framer can deserialize a stream |
| 10584 | // count that is large enough to cause the resulting stream ID to exceed the |
| 10585 | // current implementation limit(32 bits). The intent is that when this happens, |
| 10586 | // the stream limit is pegged to the maximum supported value. There are four |
| 10587 | // tests, for the four combinations of uni- and bi-directional, server- and |
| 10588 | // client- initiated. |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10589 | TEST_P(QuicFramerTest, BiDiMaxStreamsFrameTooBig) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10590 | // This test only for version 99. |
| 10591 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10592 | return; |
| 10593 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10594 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10595 | |
| 10596 | // clang-format off |
| 10597 | unsigned char packet99[] = { |
| 10598 | // type (short header, 4 byte packet number) |
| 10599 | 0x43, |
| 10600 | // connection_id |
| 10601 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10602 | // packet number |
| 10603 | 0x12, 0x34, 0x9A, 0xBC, |
| 10604 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10605 | 0x12, |
| 10606 | |
| 10607 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10608 | // This encodes a count of 0x40000000, leading to stream |
| 10609 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10610 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10611 | }; |
| 10612 | // clang-format on |
| 10613 | |
| 10614 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10615 | false); |
| 10616 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10617 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10618 | ASSERT_TRUE(visitor_.header_.get()); |
| 10619 | EXPECT_TRUE(CheckDecryption( |
| 10620 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10621 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10622 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 10623 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10624 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10625 | } |
| 10626 | |
| 10627 | TEST_P(QuicFramerTest, ClientBiDiMaxStreamsFrameTooBig) { |
| 10628 | // This test only for version 99. |
| 10629 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10630 | return; |
| 10631 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10632 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10633 | |
| 10634 | // clang-format off |
| 10635 | unsigned char packet99[] = { |
| 10636 | // type (short header, 4 byte packet number) |
| 10637 | 0x43, |
| 10638 | // Test runs in client mode, no connection id |
| 10639 | // packet number |
| 10640 | 0x12, 0x34, 0x9A, 0xBC, |
| 10641 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10642 | 0x12, |
| 10643 | |
| 10644 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10645 | // This encodes a count of 0x40000000, leading to stream |
| 10646 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10647 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10648 | }; |
| 10649 | // clang-format on |
| 10650 | |
| 10651 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10652 | false); |
| 10653 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10654 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10655 | |
| 10656 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10657 | ASSERT_TRUE(visitor_.header_.get()); |
| 10658 | EXPECT_TRUE(CheckDecryption( |
| 10659 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10660 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10661 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 10662 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10663 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10664 | } |
| 10665 | |
| 10666 | TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrameTooBig) { |
| 10667 | // This test only for version 99. |
| 10668 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10669 | return; |
| 10670 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10671 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10672 | |
| 10673 | // clang-format off |
| 10674 | unsigned char packet99[] = { |
| 10675 | // type (short header, 4 byte packet number) |
| 10676 | 0x43, |
| 10677 | // connection_id |
| 10678 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10679 | // packet number |
| 10680 | 0x12, 0x34, 0x9A, 0xBC, |
| 10681 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 10682 | 0x13, |
| 10683 | |
| 10684 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10685 | // This encodes a count of 0x40000000, leading to stream |
| 10686 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10687 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10688 | }; |
| 10689 | // clang-format on |
| 10690 | |
| 10691 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10692 | false); |
| 10693 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10694 | |
| 10695 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10696 | ASSERT_TRUE(visitor_.header_.get()); |
| 10697 | EXPECT_TRUE(CheckDecryption( |
| 10698 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10699 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10700 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 10701 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10702 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10703 | } |
| 10704 | |
| 10705 | TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrameTooBig) { |
| 10706 | // This test only for version 99. |
| 10707 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10708 | return; |
| 10709 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10710 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10711 | |
| 10712 | // clang-format off |
| 10713 | unsigned char packet99[] = { |
| 10714 | // type (short header, 4 byte packet number) |
| 10715 | 0x43, |
| 10716 | // Test runs in client mode, no connection id |
| 10717 | // packet number |
| 10718 | 0x12, 0x34, 0x9A, 0xBC, |
| 10719 | // frame type (IETF_MAX_STREAMS_UNDIRECTIONAL) |
| 10720 | 0x13, |
| 10721 | |
| 10722 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10723 | // This encodes a count of 0x40000000, leading to stream |
| 10724 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10725 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10726 | }; |
| 10727 | // clang-format on |
| 10728 | |
| 10729 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10730 | false); |
| 10731 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10732 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10733 | |
| 10734 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10735 | ASSERT_TRUE(visitor_.header_.get()); |
| 10736 | EXPECT_TRUE(CheckDecryption( |
| 10737 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10738 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10739 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 10740 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10741 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10742 | } |
| 10743 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10744 | // Specifically test that count==0 is accepted. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10745 | TEST_P(QuicFramerTest, MaxStreamsFrameZeroCount) { |
| 10746 | // This test only for version 99. |
| 10747 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10748 | return; |
| 10749 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10750 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10751 | |
| 10752 | // clang-format off |
| 10753 | unsigned char packet99[] = { |
| 10754 | // type (short header, 4 byte packet number) |
| 10755 | 0x43, |
| 10756 | // connection_id |
| 10757 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10758 | // packet number |
| 10759 | 0x12, 0x34, 0x9A, 0xBC, |
| 10760 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10761 | 0x12, |
| 10762 | // max. streams == 0. |
| 10763 | kVarInt62OneByte + 0x00 |
| 10764 | }; |
| 10765 | // clang-format on |
| 10766 | |
| 10767 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10768 | false); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10769 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10770 | } |
| 10771 | |
| 10772 | TEST_P(QuicFramerTest, ServerBiDiStreamsBlockedFrame) { |
| 10773 | // This test only for version 99. |
| 10774 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10775 | return; |
| 10776 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10777 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10778 | |
| 10779 | // clang-format off |
| 10780 | PacketFragments packet99 = { |
| 10781 | // type (short header, 4 byte packet number) |
| 10782 | {"", |
| 10783 | {0x43}}, |
| 10784 | // connection_id |
| 10785 | {"", |
| 10786 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10787 | // packet number |
| 10788 | {"", |
| 10789 | {0x12, 0x34, 0x9A, 0xBC}}, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10790 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL frame) |
| 10791 | {"", |
| 10792 | {0x13}}, |
| 10793 | // stream count |
| 10794 | {"Can not read MAX_STREAMS stream count.", |
| 10795 | {kVarInt62OneByte + 0x00}}, |
| 10796 | }; |
| 10797 | // clang-format on |
| 10798 | |
| 10799 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10800 | AssemblePacketFromFragments(packet99)); |
| 10801 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10802 | |
| 10803 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10804 | ASSERT_TRUE(visitor_.header_.get()); |
| 10805 | EXPECT_TRUE(CheckDecryption( |
| 10806 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10807 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10808 | |
| 10809 | EXPECT_EQ(0u, visitor_.max_streams_frame_.stream_count); |
| 10810 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 10811 | |
| 10812 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
| 10813 | } |
| 10814 | |
| 10815 | TEST_P(QuicFramerTest, BiDiStreamsBlockedFrame) { |
| 10816 | // This test only for version 99. |
| 10817 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10818 | return; |
| 10819 | } |
| 10820 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 10821 | |
| 10822 | // clang-format off |
| 10823 | PacketFragments packet99 = { |
| 10824 | // type (short header, 4 byte packet number) |
| 10825 | {"", |
| 10826 | {0x43}}, |
| 10827 | // connection_id |
| 10828 | {"", |
| 10829 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10830 | // packet number |
| 10831 | {"", |
| 10832 | {0x12, 0x34, 0x9A, 0xBC}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10833 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 10834 | {"", |
| 10835 | {0x16}}, |
| 10836 | // stream id |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10837 | {"Can not read STREAMS_BLOCKED stream count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10838 | {kVarInt62OneByte + 0x03}}, |
| 10839 | }; |
| 10840 | // clang-format on |
| 10841 | |
| 10842 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10843 | AssemblePacketFromFragments(packet99)); |
| 10844 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10845 | |
| 10846 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10847 | ASSERT_TRUE(visitor_.header_.get()); |
| 10848 | EXPECT_TRUE(CheckDecryption( |
| 10849 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10850 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10851 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10852 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 10853 | EXPECT_FALSE(visitor_.streams_blocked_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10854 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10855 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10856 | } |
| 10857 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10858 | TEST_P(QuicFramerTest, UniDiStreamsBlockedFrame) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10859 | // This test only for version 99. |
| 10860 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10861 | return; |
| 10862 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10863 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10864 | |
| 10865 | // clang-format off |
| 10866 | PacketFragments packet99 = { |
| 10867 | // type (short header, 4 byte packet number) |
| 10868 | {"", |
| 10869 | {0x43}}, |
| 10870 | // connection_id |
| 10871 | {"", |
| 10872 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10873 | // packet number |
| 10874 | {"", |
| 10875 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10876 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10877 | {"", |
| 10878 | {0x17}}, |
| 10879 | // stream id |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10880 | {"Can not read STREAMS_BLOCKED stream count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10881 | {kVarInt62OneByte + 0x03}}, |
| 10882 | }; |
| 10883 | // clang-format on |
| 10884 | |
| 10885 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10886 | AssemblePacketFromFragments(packet99)); |
| 10887 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10888 | |
| 10889 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10890 | ASSERT_TRUE(visitor_.header_.get()); |
| 10891 | EXPECT_TRUE(CheckDecryption( |
| 10892 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10893 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10894 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10895 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 10896 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 10897 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10898 | } |
| 10899 | |
| 10900 | TEST_P(QuicFramerTest, ClientUniDiStreamsBlockedFrame) { |
| 10901 | // This test only for version 99. |
| 10902 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10903 | return; |
| 10904 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10905 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10906 | |
| 10907 | // clang-format off |
| 10908 | PacketFragments packet99 = { |
| 10909 | // type (short header, 4 byte packet number) |
| 10910 | {"", |
| 10911 | {0x43}}, |
| 10912 | // Test runs in client mode, no connection id |
| 10913 | // packet number |
| 10914 | {"", |
| 10915 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10916 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10917 | {"", |
| 10918 | {0x17}}, |
| 10919 | // stream id |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10920 | {"Can not read STREAMS_BLOCKED stream count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10921 | {kVarInt62OneByte + 0x03}}, |
| 10922 | }; |
| 10923 | // clang-format on |
| 10924 | |
| 10925 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10926 | AssemblePacketFromFragments(packet99)); |
| 10927 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10928 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10929 | |
| 10930 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10931 | ASSERT_TRUE(visitor_.header_.get()); |
| 10932 | EXPECT_TRUE(CheckDecryption( |
| 10933 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10934 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10935 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10936 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 10937 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 10938 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10939 | } |
| 10940 | |
| 10941 | // Check that when we get a STREAMS_BLOCKED frame that specifies too large |
| 10942 | // a stream count, we reject with an appropriate error. There is no need to |
| 10943 | // check for different combinations of Uni/Bi directional and client/server |
| 10944 | // initiated; the logic does not take these into account. |
| 10945 | TEST_P(QuicFramerTest, StreamsBlockedFrameTooBig) { |
| 10946 | // This test only for version 99. |
| 10947 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10948 | return; |
| 10949 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10950 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10951 | |
| 10952 | // clang-format off |
| 10953 | unsigned char packet99[] = { |
| 10954 | // type (short header, 4 byte packet number) |
| 10955 | 0x43, |
| 10956 | // Test runs in client mode, no connection id |
| 10957 | // packet number |
| 10958 | 0x12, 0x34, 0x9A, 0xBC, |
| 10959 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL) |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10960 | 0x16, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10961 | |
| 10962 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10963 | // This encodes a count of 0x40000000, leading to stream |
| 10964 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10965 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01 |
| 10966 | }; |
| 10967 | // clang-format on |
| 10968 | |
| 10969 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10970 | false); |
| 10971 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10972 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 10973 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10974 | EXPECT_EQ(QUIC_STREAMS_BLOCKED_DATA, framer_.error()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10975 | EXPECT_EQ(framer_.detailed_error(), |
| 10976 | "STREAMS_BLOCKED stream count exceeds implementation limit."); |
| 10977 | } |
| 10978 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10979 | // Specifically test that count==0 is accepted. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10980 | TEST_P(QuicFramerTest, StreamsBlockedFrameZeroCount) { |
| 10981 | // This test only for version 99. |
| 10982 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10983 | return; |
| 10984 | } |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10985 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10986 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10987 | |
| 10988 | // clang-format off |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10989 | PacketFragments packet99 = { |
| 10990 | // type (short header, 4 byte packet number) |
| 10991 | {"", |
| 10992 | {0x43}}, |
| 10993 | // connection_id |
| 10994 | {"", |
| 10995 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10996 | // packet number |
| 10997 | {"", |
| 10998 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10999 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 11000 | {"", |
| 11001 | {0x17}}, |
| 11002 | // stream id |
| 11003 | {"Can not read STREAMS_BLOCKED stream count.", |
| 11004 | {kVarInt62OneByte + 0x00}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11005 | }; |
| 11006 | // clang-format on |
| 11007 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11008 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11009 | AssemblePacketFromFragments(packet99)); |
| 11010 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11011 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11012 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11013 | ASSERT_TRUE(visitor_.header_.get()); |
| 11014 | EXPECT_TRUE(CheckDecryption( |
| 11015 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11016 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11017 | |
| 11018 | EXPECT_EQ(0u, visitor_.streams_blocked_frame_.stream_count); |
| 11019 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 11020 | |
| 11021 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11022 | } |
| 11023 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11024 | TEST_P(QuicFramerTest, BuildBiDiStreamsBlockedPacket) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11025 | // This test only for version 99. |
| 11026 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11027 | return; |
| 11028 | } |
| 11029 | |
| 11030 | QuicPacketHeader header; |
| 11031 | header.destination_connection_id = FramerTestConnectionId(); |
| 11032 | header.reset_flag = false; |
| 11033 | header.version_flag = false; |
| 11034 | header.packet_number = kPacketNumber; |
| 11035 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11036 | QuicStreamsBlockedFrame frame; |
| 11037 | frame.stream_count = 3; |
| 11038 | frame.unidirectional = false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11039 | |
| 11040 | QuicFrames frames = {QuicFrame(frame)}; |
| 11041 | |
| 11042 | // clang-format off |
| 11043 | unsigned char packet99[] = { |
| 11044 | // type (short header, 4 byte packet number) |
| 11045 | 0x43, |
| 11046 | // connection_id |
| 11047 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11048 | // packet number |
| 11049 | 0x12, 0x34, 0x56, 0x78, |
| 11050 | |
| 11051 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 11052 | 0x16, |
| 11053 | // Stream count |
| 11054 | kVarInt62OneByte + 0x03 |
| 11055 | }; |
| 11056 | // clang-format on |
| 11057 | |
| 11058 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11059 | ASSERT_TRUE(data != nullptr); |
| 11060 | |
| 11061 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11062 | data->length(), AsChars(packet99), |
| 11063 | QUIC_ARRAYSIZE(packet99)); |
| 11064 | } |
| 11065 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11066 | TEST_P(QuicFramerTest, BuildUniStreamsBlockedPacket) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11067 | // This test only for version 99. |
| 11068 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11069 | return; |
| 11070 | } |
| 11071 | |
| 11072 | QuicPacketHeader header; |
| 11073 | header.destination_connection_id = FramerTestConnectionId(); |
| 11074 | header.reset_flag = false; |
| 11075 | header.version_flag = false; |
| 11076 | header.packet_number = kPacketNumber; |
| 11077 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11078 | QuicStreamsBlockedFrame frame; |
| 11079 | frame.stream_count = 3; |
| 11080 | frame.unidirectional = true; |
| 11081 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11082 | QuicFrames frames = {QuicFrame(frame)}; |
| 11083 | |
| 11084 | // clang-format off |
| 11085 | unsigned char packet99[] = { |
| 11086 | // type (short header, 4 byte packet number) |
| 11087 | 0x43, |
| 11088 | // connection_id |
| 11089 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11090 | // packet number |
| 11091 | 0x12, 0x34, 0x56, 0x78, |
| 11092 | |
| 11093 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 11094 | 0x17, |
| 11095 | // Stream count |
| 11096 | kVarInt62OneByte + 0x03 |
| 11097 | }; |
| 11098 | // clang-format on |
| 11099 | |
| 11100 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11101 | ASSERT_TRUE(data != nullptr); |
| 11102 | |
| 11103 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11104 | data->length(), AsChars(packet99), |
| 11105 | QUIC_ARRAYSIZE(packet99)); |
| 11106 | } |
| 11107 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11108 | TEST_P(QuicFramerTest, BuildBiDiMaxStreamsPacket) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11109 | // This test only for version 99. |
| 11110 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11111 | return; |
| 11112 | } |
| 11113 | |
| 11114 | QuicPacketHeader header; |
| 11115 | header.destination_connection_id = FramerTestConnectionId(); |
| 11116 | header.reset_flag = false; |
| 11117 | header.version_flag = false; |
| 11118 | header.packet_number = kPacketNumber; |
| 11119 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11120 | QuicMaxStreamsFrame frame; |
| 11121 | frame.stream_count = 3; |
| 11122 | frame.unidirectional = false; |
| 11123 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11124 | QuicFrames frames = {QuicFrame(frame)}; |
| 11125 | |
| 11126 | // clang-format off |
| 11127 | unsigned char packet99[] = { |
| 11128 | // type (short header, 4 byte packet number) |
| 11129 | 0x43, |
| 11130 | // connection_id |
| 11131 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11132 | // packet number |
| 11133 | 0x12, 0x34, 0x56, 0x78, |
| 11134 | |
| 11135 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL frame) |
| 11136 | 0x12, |
| 11137 | // Stream count |
| 11138 | kVarInt62OneByte + 0x03 |
| 11139 | }; |
| 11140 | // clang-format on |
| 11141 | |
| 11142 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11143 | ASSERT_TRUE(data != nullptr); |
| 11144 | |
| 11145 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11146 | data->length(), AsChars(packet99), |
| 11147 | QUIC_ARRAYSIZE(packet99)); |
| 11148 | } |
| 11149 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11150 | TEST_P(QuicFramerTest, BuildUniDiMaxStreamsPacket) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11151 | // This test only for version 99. |
| 11152 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11153 | return; |
| 11154 | } |
| 11155 | |
| 11156 | // This test runs in client mode. |
| 11157 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 11158 | |
| 11159 | QuicPacketHeader header; |
| 11160 | header.destination_connection_id = FramerTestConnectionId(); |
| 11161 | header.reset_flag = false; |
| 11162 | header.version_flag = false; |
| 11163 | header.packet_number = kPacketNumber; |
| 11164 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11165 | QuicMaxStreamsFrame frame; |
| 11166 | frame.stream_count = 3; |
| 11167 | frame.unidirectional = true; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11168 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11169 | QuicFrames frames = {QuicFrame(frame)}; |
| 11170 | |
| 11171 | // clang-format off |
| 11172 | unsigned char packet99[] = { |
| 11173 | // type (short header, 4 byte packet number) |
| 11174 | 0x43, |
| 11175 | // connection_id |
| 11176 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11177 | // packet number |
| 11178 | 0x12, 0x34, 0x56, 0x78, |
| 11179 | |
| 11180 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL frame) |
| 11181 | 0x13, |
| 11182 | // Stream count |
| 11183 | kVarInt62OneByte + 0x03 |
| 11184 | }; |
| 11185 | // clang-format on |
| 11186 | |
| 11187 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11188 | ASSERT_TRUE(data != nullptr); |
| 11189 | |
| 11190 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11191 | data->length(), AsChars(packet99), |
| 11192 | QUIC_ARRAYSIZE(packet99)); |
| 11193 | } |
| 11194 | |
| 11195 | TEST_P(QuicFramerTest, NewConnectionIdFrame) { |
| 11196 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11197 | // This frame is only for version 99. |
| 11198 | return; |
| 11199 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11200 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11201 | // clang-format off |
| 11202 | PacketFragments packet99 = { |
| 11203 | // type (short header, 4 byte packet number) |
| 11204 | {"", |
| 11205 | {0x43}}, |
| 11206 | // connection_id |
| 11207 | {"", |
| 11208 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11209 | // packet number |
| 11210 | {"", |
| 11211 | {0x12, 0x34, 0x56, 0x78}}, |
| 11212 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 11213 | {"", |
| 11214 | {0x18}}, |
| 11215 | // error code |
| 11216 | {"Unable to read new connection ID frame sequence number.", |
| 11217 | {kVarInt62OneByte + 0x11}}, |
| 11218 | {"Unable to read new connection ID frame connection id length.", |
| 11219 | {0x08}}, // connection ID length |
| 11220 | {"Unable to read new connection ID frame connection id.", |
| 11221 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11}}, |
| 11222 | {"Can not read new connection ID frame reset token.", |
| 11223 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11224 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 11225 | }; |
| 11226 | // clang-format on |
| 11227 | |
| 11228 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11229 | AssemblePacketFromFragments(packet99)); |
| 11230 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11231 | |
| 11232 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11233 | ASSERT_TRUE(visitor_.header_.get()); |
| 11234 | EXPECT_TRUE(CheckDecryption( |
| 11235 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11236 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11237 | |
| 11238 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 11239 | |
| 11240 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), |
| 11241 | visitor_.new_connection_id_.connection_id); |
| 11242 | EXPECT_EQ(0x11u, visitor_.new_connection_id_.sequence_number); |
| 11243 | EXPECT_EQ(kTestStatelessResetToken, |
| 11244 | visitor_.new_connection_id_.stateless_reset_token); |
| 11245 | |
| 11246 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 11247 | |
| 11248 | CheckFramingBoundaries(packet99, QUIC_INVALID_NEW_CONNECTION_ID_DATA); |
| 11249 | } |
| 11250 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 11251 | TEST_P(QuicFramerTest, NewConnectionIdFrameVariableLength) { |
QUICHE team | 9b41c97 | 2019-03-21 11:22:48 -0700 | [diff] [blame] | 11252 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11253 | // This frame is only for version 99. |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 11254 | return; |
| 11255 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11256 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 11257 | // clang-format off |
| 11258 | PacketFragments packet99 = { |
| 11259 | // type (short header, 4 byte packet number) |
| 11260 | {"", |
| 11261 | {0x43}}, |
| 11262 | // connection_id |
| 11263 | {"", |
| 11264 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11265 | // packet number |
| 11266 | {"", |
| 11267 | {0x12, 0x34, 0x56, 0x78}}, |
| 11268 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 11269 | {"", |
| 11270 | {0x18}}, |
| 11271 | // error code |
| 11272 | {"Unable to read new connection ID frame sequence number.", |
| 11273 | {kVarInt62OneByte + 0x11}}, |
| 11274 | {"Unable to read new connection ID frame connection id length.", |
| 11275 | {0x09}}, // connection ID length |
| 11276 | {"Unable to read new connection ID frame connection id.", |
| 11277 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 11278 | {"Can not read new connection ID frame reset token.", |
| 11279 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11280 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 11281 | }; |
| 11282 | // clang-format on |
| 11283 | |
| 11284 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11285 | AssemblePacketFromFragments(packet99)); |
| 11286 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11287 | |
| 11288 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11289 | ASSERT_TRUE(visitor_.header_.get()); |
| 11290 | EXPECT_TRUE(CheckDecryption( |
| 11291 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11292 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11293 | |
| 11294 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 11295 | |
| 11296 | EXPECT_EQ(FramerTestConnectionIdNineBytes(), |
| 11297 | visitor_.new_connection_id_.connection_id); |
| 11298 | EXPECT_EQ(0x11u, visitor_.new_connection_id_.sequence_number); |
| 11299 | EXPECT_EQ(kTestStatelessResetToken, |
| 11300 | visitor_.new_connection_id_.stateless_reset_token); |
| 11301 | |
| 11302 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 11303 | |
| 11304 | CheckFramingBoundaries(packet99, QUIC_INVALID_NEW_CONNECTION_ID_DATA); |
| 11305 | } |
| 11306 | |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 11307 | // Verifies that parsing a NEW_CONNECTION_ID frame with a length above the |
| 11308 | // specified maximum fails. |
| 11309 | TEST_P(QuicFramerTest, InvalidLongNewConnectionIdFrame) { |
| 11310 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11311 | // The NEW_CONNECTION_ID frame is only for version 99. |
| 11312 | return; |
| 11313 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11314 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 11315 | // clang-format off |
| 11316 | PacketFragments packet99 = { |
| 11317 | // type (short header, 4 byte packet number) |
| 11318 | {"", |
| 11319 | {0x43}}, |
| 11320 | // connection_id |
| 11321 | {"", |
| 11322 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11323 | // packet number |
| 11324 | {"", |
| 11325 | {0x12, 0x34, 0x56, 0x78}}, |
| 11326 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 11327 | {"", |
| 11328 | {0x18}}, |
| 11329 | // error code |
| 11330 | {"Unable to read new connection ID frame sequence number.", |
| 11331 | {kVarInt62OneByte + 0x11}}, |
| 11332 | {"Unable to read new connection ID frame connection id length.", |
| 11333 | {0x13}}, // connection ID length |
| 11334 | {"Unable to read new connection ID frame connection id.", |
| 11335 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11336 | 0xF0, 0xD2, 0xB4, 0x96, 0x78, 0x5A, 0x3C, 0x1E, |
| 11337 | 0x42, 0x33, 0x42}}, |
| 11338 | {"Can not read new connection ID frame reset token.", |
| 11339 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11340 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 11341 | }; |
| 11342 | // clang-format on |
| 11343 | |
| 11344 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11345 | AssemblePacketFromFragments(packet99)); |
| 11346 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11347 | EXPECT_EQ(QUIC_INVALID_NEW_CONNECTION_ID_DATA, framer_.error()); |
| 11348 | EXPECT_EQ("New connection ID length too high.", framer_.detailed_error()); |
| 11349 | } |
| 11350 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11351 | TEST_P(QuicFramerTest, BuildNewConnectionIdFramePacket) { |
| 11352 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11353 | // This frame is only for version 99. |
| 11354 | return; |
| 11355 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 11356 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11357 | QuicPacketHeader header; |
| 11358 | header.destination_connection_id = FramerTestConnectionId(); |
| 11359 | header.reset_flag = false; |
| 11360 | header.version_flag = false; |
| 11361 | header.packet_number = kPacketNumber; |
| 11362 | |
| 11363 | QuicNewConnectionIdFrame frame; |
| 11364 | frame.sequence_number = 0x11; |
| 11365 | // Use this value to force a 4-byte encoded variable length connection ID |
| 11366 | // in the frame. |
| 11367 | frame.connection_id = FramerTestConnectionIdPlusOne(); |
| 11368 | frame.stateless_reset_token = kTestStatelessResetToken; |
| 11369 | |
| 11370 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11371 | |
| 11372 | // clang-format off |
| 11373 | unsigned char packet99[] = { |
| 11374 | // type (short header, 4 byte packet number) |
| 11375 | 0x43, |
| 11376 | // connection_id |
| 11377 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11378 | // packet number |
| 11379 | 0x12, 0x34, 0x56, 0x78, |
| 11380 | |
| 11381 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 11382 | 0x18, |
| 11383 | // sequence number |
| 11384 | kVarInt62OneByte + 0x11, |
| 11385 | // new connection id length |
| 11386 | 0x08, |
| 11387 | // new connection id |
| 11388 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 11389 | // stateless reset token |
| 11390 | 0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11391 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11392 | }; |
| 11393 | // clang-format on |
| 11394 | |
| 11395 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11396 | ASSERT_TRUE(data != nullptr); |
| 11397 | |
| 11398 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11399 | data->length(), AsChars(packet99), |
| 11400 | QUIC_ARRAYSIZE(packet99)); |
| 11401 | } |
| 11402 | |
| 11403 | TEST_P(QuicFramerTest, NewTokenFrame) { |
| 11404 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11405 | // This frame is only for version 99. |
| 11406 | return; |
| 11407 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11408 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11409 | // clang-format off |
| 11410 | PacketFragments packet = { |
| 11411 | // type (short header, 4 byte packet number) |
| 11412 | {"", |
| 11413 | {0x43}}, |
| 11414 | // connection_id |
| 11415 | {"", |
| 11416 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11417 | // packet number |
| 11418 | {"", |
| 11419 | {0x12, 0x34, 0x56, 0x78}}, |
| 11420 | // frame type (IETF_NEW_TOKEN frame) |
| 11421 | {"", |
| 11422 | {0x07}}, |
| 11423 | // Length |
| 11424 | {"Unable to read new token length.", |
| 11425 | {kVarInt62OneByte + 0x08}}, |
| 11426 | {"Unable to read new token data.", |
| 11427 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}} |
| 11428 | }; |
| 11429 | // clang-format on |
| 11430 | uint8_t expected_token_value[] = {0x00, 0x01, 0x02, 0x03, |
| 11431 | 0x04, 0x05, 0x06, 0x07}; |
| 11432 | |
| 11433 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11434 | AssemblePacketFromFragments(packet)); |
| 11435 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11436 | |
| 11437 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11438 | ASSERT_TRUE(visitor_.header_.get()); |
| 11439 | EXPECT_TRUE(CheckDecryption( |
| 11440 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11441 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11442 | |
| 11443 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 11444 | |
| 11445 | EXPECT_EQ(sizeof(expected_token_value), visitor_.new_token_.token.length()); |
| 11446 | EXPECT_EQ(0, memcmp(expected_token_value, visitor_.new_token_.token.data(), |
| 11447 | sizeof(expected_token_value))); |
| 11448 | |
| 11449 | CheckFramingBoundaries(packet, QUIC_INVALID_NEW_TOKEN); |
| 11450 | } |
| 11451 | |
| 11452 | TEST_P(QuicFramerTest, BuildNewTokenFramePacket) { |
| 11453 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11454 | // This frame is only for version 99. |
| 11455 | return; |
| 11456 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 11457 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11458 | QuicPacketHeader header; |
| 11459 | header.destination_connection_id = FramerTestConnectionId(); |
| 11460 | header.reset_flag = false; |
| 11461 | header.version_flag = false; |
| 11462 | header.packet_number = kPacketNumber; |
| 11463 | |
| 11464 | uint8_t expected_token_value[] = {0x00, 0x01, 0x02, 0x03, |
| 11465 | 0x04, 0x05, 0x06, 0x07}; |
| 11466 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 11467 | QuicNewTokenFrame frame(0, std::string((const char*)(expected_token_value), |
| 11468 | sizeof(expected_token_value))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11469 | |
| 11470 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11471 | |
| 11472 | // clang-format off |
| 11473 | unsigned char packet[] = { |
| 11474 | // type (short header, 4 byte packet number) |
| 11475 | 0x43, |
| 11476 | // connection_id |
| 11477 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11478 | // packet number |
| 11479 | 0x12, 0x34, 0x56, 0x78, |
| 11480 | |
| 11481 | // frame type (IETF_NEW_TOKEN frame) |
| 11482 | 0x07, |
| 11483 | // Length and token |
| 11484 | kVarInt62OneByte + 0x08, |
| 11485 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 11486 | }; |
| 11487 | // clang-format on |
| 11488 | |
| 11489 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11490 | ASSERT_TRUE(data != nullptr); |
| 11491 | |
| 11492 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11493 | data->length(), AsChars(packet), |
| 11494 | QUIC_ARRAYSIZE(packet)); |
| 11495 | } |
| 11496 | |
| 11497 | TEST_P(QuicFramerTest, IetfStopSendingFrame) { |
| 11498 | // This test is only for version 99. |
| 11499 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11500 | return; |
| 11501 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11502 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11503 | |
| 11504 | // clang-format off |
| 11505 | PacketFragments packet99 = { |
| 11506 | // type (short header, 4 byte packet number) |
| 11507 | {"", |
| 11508 | {0x43}}, |
| 11509 | // connection_id |
| 11510 | {"", |
| 11511 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11512 | // packet number |
| 11513 | {"", |
| 11514 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11515 | // frame type (IETF_STOP_SENDING frame) |
| 11516 | {"", |
| 11517 | {0x05}}, |
| 11518 | // stream id |
| 11519 | {"Unable to read stop sending stream id.", |
| 11520 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 11521 | {"Unable to read stop sending application error code.", |
| 11522 | {0x76, 0x54}}, |
| 11523 | }; |
| 11524 | // clang-format on |
| 11525 | |
| 11526 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11527 | AssemblePacketFromFragments(packet99)); |
| 11528 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11529 | |
| 11530 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11531 | ASSERT_TRUE(visitor_.header_.get()); |
| 11532 | EXPECT_TRUE(CheckDecryption( |
| 11533 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11534 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11535 | |
| 11536 | EXPECT_EQ(kStreamId, visitor_.stop_sending_frame_.stream_id); |
| 11537 | EXPECT_EQ(0x7654, visitor_.stop_sending_frame_.application_error_code); |
| 11538 | |
| 11539 | CheckFramingBoundaries(packet99, QUIC_INVALID_STOP_SENDING_FRAME_DATA); |
| 11540 | } |
| 11541 | |
| 11542 | TEST_P(QuicFramerTest, BuildIetfStopSendingPacket) { |
| 11543 | // This test is only for version 99. |
| 11544 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11545 | return; |
| 11546 | } |
| 11547 | |
| 11548 | QuicPacketHeader header; |
| 11549 | header.destination_connection_id = FramerTestConnectionId(); |
| 11550 | header.reset_flag = false; |
| 11551 | header.version_flag = false; |
| 11552 | header.packet_number = kPacketNumber; |
| 11553 | |
| 11554 | QuicStopSendingFrame frame; |
| 11555 | frame.stream_id = kStreamId; |
| 11556 | frame.application_error_code = 0xffff; |
| 11557 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11558 | |
| 11559 | // clang-format off |
| 11560 | unsigned char packet99[] = { |
| 11561 | // type (short header, 4 byte packet number) |
| 11562 | 0x43, |
| 11563 | // connection_id |
| 11564 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11565 | // packet number |
| 11566 | 0x12, 0x34, 0x56, 0x78, |
| 11567 | |
| 11568 | // frame type (IETF_STOP_SENDING frame) |
| 11569 | 0x05, |
| 11570 | // Stream ID |
| 11571 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 11572 | // Application error code |
| 11573 | 0xff, 0xff |
| 11574 | }; |
| 11575 | // clang-format on |
| 11576 | |
| 11577 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11578 | ASSERT_TRUE(data != nullptr); |
| 11579 | |
| 11580 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11581 | data->length(), AsChars(packet99), |
| 11582 | QUIC_ARRAYSIZE(packet99)); |
| 11583 | } |
| 11584 | |
| 11585 | TEST_P(QuicFramerTest, IetfPathChallengeFrame) { |
| 11586 | // This test only for version 99. |
| 11587 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11588 | return; |
| 11589 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11590 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11591 | |
| 11592 | // clang-format off |
| 11593 | PacketFragments packet99 = { |
| 11594 | // type (short header, 4 byte packet number) |
| 11595 | {"", |
| 11596 | {0x43}}, |
| 11597 | // connection_id |
| 11598 | {"", |
| 11599 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11600 | // packet number |
| 11601 | {"", |
| 11602 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11603 | // frame type (IETF_PATH_CHALLENGE) |
| 11604 | {"", |
| 11605 | {0x1a}}, |
| 11606 | // data |
| 11607 | {"Can not read path challenge data.", |
| 11608 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}}, |
| 11609 | }; |
| 11610 | // clang-format on |
| 11611 | |
| 11612 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11613 | AssemblePacketFromFragments(packet99)); |
| 11614 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11615 | |
| 11616 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11617 | ASSERT_TRUE(visitor_.header_.get()); |
| 11618 | EXPECT_TRUE(CheckDecryption( |
| 11619 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11620 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11621 | |
| 11622 | EXPECT_EQ(QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}), |
| 11623 | visitor_.path_challenge_frame_.data_buffer); |
| 11624 | |
| 11625 | CheckFramingBoundaries(packet99, QUIC_INVALID_PATH_CHALLENGE_DATA); |
| 11626 | } |
| 11627 | |
| 11628 | TEST_P(QuicFramerTest, BuildIetfPathChallengePacket) { |
| 11629 | // This test only for version 99. |
| 11630 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11631 | return; |
| 11632 | } |
| 11633 | |
| 11634 | QuicPacketHeader header; |
| 11635 | header.destination_connection_id = FramerTestConnectionId(); |
| 11636 | header.reset_flag = false; |
| 11637 | header.version_flag = false; |
| 11638 | header.packet_number = kPacketNumber; |
| 11639 | |
| 11640 | QuicPathChallengeFrame frame; |
| 11641 | frame.data_buffer = QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}); |
| 11642 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11643 | |
| 11644 | // clang-format off |
| 11645 | unsigned char packet99[] = { |
| 11646 | // type (short header, 4 byte packet number) |
| 11647 | 0x43, |
| 11648 | // connection_id |
| 11649 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11650 | // packet number |
| 11651 | 0x12, 0x34, 0x56, 0x78, |
| 11652 | |
| 11653 | // frame type (IETF_PATH_CHALLENGE) |
| 11654 | 0x1a, |
| 11655 | // Data |
| 11656 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 11657 | }; |
| 11658 | // clang-format on |
| 11659 | |
| 11660 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11661 | ASSERT_TRUE(data != nullptr); |
| 11662 | |
| 11663 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11664 | data->length(), AsChars(packet99), |
| 11665 | QUIC_ARRAYSIZE(packet99)); |
| 11666 | } |
| 11667 | |
| 11668 | TEST_P(QuicFramerTest, IetfPathResponseFrame) { |
| 11669 | // This test only for version 99. |
| 11670 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11671 | return; |
| 11672 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11673 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11674 | |
| 11675 | // clang-format off |
| 11676 | PacketFragments packet99 = { |
| 11677 | // type (short header, 4 byte packet number) |
| 11678 | {"", |
| 11679 | {0x43}}, |
| 11680 | // connection_id |
| 11681 | {"", |
| 11682 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11683 | // packet number |
| 11684 | {"", |
| 11685 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11686 | // frame type (IETF_PATH_RESPONSE) |
| 11687 | {"", |
| 11688 | {0x1b}}, |
| 11689 | // data |
| 11690 | {"Can not read path response data.", |
| 11691 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}}, |
| 11692 | }; |
| 11693 | // clang-format on |
| 11694 | |
| 11695 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11696 | AssemblePacketFromFragments(packet99)); |
| 11697 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11698 | |
| 11699 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11700 | ASSERT_TRUE(visitor_.header_.get()); |
| 11701 | EXPECT_TRUE(CheckDecryption( |
| 11702 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11703 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11704 | |
| 11705 | EXPECT_EQ(QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}), |
| 11706 | visitor_.path_response_frame_.data_buffer); |
| 11707 | |
| 11708 | CheckFramingBoundaries(packet99, QUIC_INVALID_PATH_RESPONSE_DATA); |
| 11709 | } |
| 11710 | |
| 11711 | TEST_P(QuicFramerTest, BuildIetfPathResponsePacket) { |
| 11712 | // This test only for version 99. |
| 11713 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11714 | return; |
| 11715 | } |
| 11716 | |
| 11717 | QuicPacketHeader header; |
| 11718 | header.destination_connection_id = FramerTestConnectionId(); |
| 11719 | header.reset_flag = false; |
| 11720 | header.version_flag = false; |
| 11721 | header.packet_number = kPacketNumber; |
| 11722 | |
| 11723 | QuicPathResponseFrame frame; |
| 11724 | frame.data_buffer = QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}); |
| 11725 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11726 | |
| 11727 | // clang-format off |
| 11728 | unsigned char packet99[] = { |
| 11729 | // type (short header, 4 byte packet number) |
| 11730 | 0x43, |
| 11731 | // connection_id |
| 11732 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11733 | // packet number |
| 11734 | 0x12, 0x34, 0x56, 0x78, |
| 11735 | |
| 11736 | // frame type (IETF_PATH_RESPONSE) |
| 11737 | 0x1b, |
| 11738 | // Data |
| 11739 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 11740 | }; |
| 11741 | // clang-format on |
| 11742 | |
| 11743 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11744 | ASSERT_TRUE(data != nullptr); |
| 11745 | |
| 11746 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11747 | data->length(), AsChars(packet99), |
| 11748 | QUIC_ARRAYSIZE(packet99)); |
| 11749 | } |
| 11750 | |
| 11751 | TEST_P(QuicFramerTest, GetRetransmittableControlFrameSize) { |
| 11752 | QuicRstStreamFrame rst_stream(1, 3, QUIC_STREAM_CANCELLED, 1024); |
| 11753 | EXPECT_EQ(QuicFramer::GetRstStreamFrameSize(framer_.transport_version(), |
| 11754 | rst_stream), |
| 11755 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11756 | framer_.transport_version(), QuicFrame(&rst_stream))); |
| 11757 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 11758 | std::string error_detail(2048, 'e'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11759 | QuicConnectionCloseFrame connection_close(QUIC_NETWORK_IDLE_TIMEOUT, |
| 11760 | error_detail); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 11761 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 11762 | connection_close.close_type = IETF_QUIC_TRANSPORT_CONNECTION_CLOSE; |
| 11763 | } |
| 11764 | |
fkastenholz | a037b8b | 2019-05-07 06:00:05 -0700 | [diff] [blame] | 11765 | EXPECT_EQ(QuicFramer::GetConnectionCloseFrameSize(framer_.transport_version(), |
| 11766 | connection_close), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11767 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11768 | framer_.transport_version(), QuicFrame(&connection_close))); |
| 11769 | |
| 11770 | QuicGoAwayFrame goaway(2, QUIC_PEER_GOING_AWAY, 3, error_detail); |
| 11771 | EXPECT_EQ(QuicFramer::GetMinGoAwayFrameSize() + 256, |
| 11772 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11773 | framer_.transport_version(), QuicFrame(&goaway))); |
| 11774 | |
| 11775 | QuicWindowUpdateFrame window_update(3, 3, 1024); |
| 11776 | EXPECT_EQ(QuicFramer::GetWindowUpdateFrameSize(framer_.transport_version(), |
| 11777 | window_update), |
| 11778 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11779 | framer_.transport_version(), QuicFrame(&window_update))); |
| 11780 | |
| 11781 | QuicBlockedFrame blocked(4, 3, 1024); |
| 11782 | EXPECT_EQ( |
| 11783 | QuicFramer::GetBlockedFrameSize(framer_.transport_version(), blocked), |
| 11784 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11785 | framer_.transport_version(), QuicFrame(&blocked))); |
| 11786 | |
| 11787 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11788 | return; |
| 11789 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11790 | |
| 11791 | QuicNewConnectionIdFrame new_connection_id(5, TestConnectionId(), 1, 101111); |
| 11792 | EXPECT_EQ(QuicFramer::GetNewConnectionIdFrameSize(new_connection_id), |
| 11793 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11794 | framer_.transport_version(), QuicFrame(&new_connection_id))); |
| 11795 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11796 | QuicMaxStreamsFrame max_streams(6, 3, /*unidirectional=*/false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11797 | EXPECT_EQ(QuicFramer::GetMaxStreamsFrameSize(framer_.transport_version(), |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11798 | max_streams), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11799 | QuicFramer::GetRetransmittableControlFrameSize( |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11800 | framer_.transport_version(), QuicFrame(max_streams))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11801 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11802 | QuicStreamsBlockedFrame streams_blocked(7, 3, /*unidirectional=*/false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11803 | EXPECT_EQ(QuicFramer::GetStreamsBlockedFrameSize(framer_.transport_version(), |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11804 | streams_blocked), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11805 | QuicFramer::GetRetransmittableControlFrameSize( |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11806 | framer_.transport_version(), QuicFrame(streams_blocked))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11807 | |
| 11808 | QuicPathFrameBuffer buffer = { |
| 11809 | {0x80, 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe5, 0xf7}}; |
| 11810 | QuicPathResponseFrame path_response_frame(8, buffer); |
| 11811 | EXPECT_EQ(QuicFramer::GetPathResponseFrameSize(path_response_frame), |
| 11812 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11813 | framer_.transport_version(), QuicFrame(&path_response_frame))); |
| 11814 | |
| 11815 | QuicPathChallengeFrame path_challenge_frame(9, buffer); |
| 11816 | EXPECT_EQ(QuicFramer::GetPathChallengeFrameSize(path_challenge_frame), |
| 11817 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11818 | framer_.transport_version(), QuicFrame(&path_challenge_frame))); |
| 11819 | |
| 11820 | QuicStopSendingFrame stop_sending_frame(10, 3, 20); |
| 11821 | EXPECT_EQ(QuicFramer::GetStopSendingFrameSize(stop_sending_frame), |
| 11822 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11823 | framer_.transport_version(), QuicFrame(&stop_sending_frame))); |
| 11824 | } |
| 11825 | |
| 11826 | // A set of tests to ensure that bad frame-type encodings |
| 11827 | // are properly detected and handled. |
| 11828 | // First, four tests to see that unknown frame types generate |
| 11829 | // a QUIC_INVALID_FRAME_DATA error with detailed information |
| 11830 | // "Illegal frame type." This regardless of the encoding of the type |
| 11831 | // (1/2/4/8 bytes). |
| 11832 | // This only for version 99. |
| 11833 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown1Byte) { |
| 11834 | // This test only for version 99. |
| 11835 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11836 | return; |
| 11837 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11838 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11839 | // clang-format off |
| 11840 | PacketFragments packet = { |
| 11841 | // type (short header, 4 byte packet number) |
| 11842 | {"", |
| 11843 | {0x43}}, |
| 11844 | // connection_id |
| 11845 | {"", |
| 11846 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11847 | // packet number |
| 11848 | {"", |
| 11849 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11850 | // frame type (unknown value, single-byte encoding) |
| 11851 | {"", |
| 11852 | {0x38}} |
| 11853 | }; |
| 11854 | // clang-format on |
| 11855 | |
| 11856 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11857 | AssemblePacketFromFragments(packet)); |
| 11858 | |
| 11859 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11860 | |
| 11861 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 11862 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11863 | } |
| 11864 | |
| 11865 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown2Bytes) { |
| 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 packet = { |
| 11874 | // type (short header, 4 byte packet number) |
| 11875 | {"", |
| 11876 | {0x43}}, |
| 11877 | // connection_id |
| 11878 | {"", |
| 11879 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11880 | // packet number |
| 11881 | {"", |
| 11882 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11883 | // frame type (unknown value, two-byte encoding) |
| 11884 | {"", |
| 11885 | {kVarInt62TwoBytes + 0x01, 0x38}} |
| 11886 | }; |
| 11887 | // clang-format on |
| 11888 | |
| 11889 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11890 | AssemblePacketFromFragments(packet)); |
| 11891 | |
| 11892 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11893 | |
| 11894 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 11895 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11896 | } |
| 11897 | |
| 11898 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown4Bytes) { |
| 11899 | // This test only for version 99. |
| 11900 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11901 | return; |
| 11902 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11903 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11904 | |
| 11905 | // clang-format off |
| 11906 | PacketFragments packet = { |
| 11907 | // type (short header, 4 byte packet number) |
| 11908 | {"", |
| 11909 | {0x43}}, |
| 11910 | // connection_id |
| 11911 | {"", |
| 11912 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11913 | // packet number |
| 11914 | {"", |
| 11915 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11916 | // frame type (unknown value, four-byte encoding) |
| 11917 | {"", |
| 11918 | {kVarInt62FourBytes + 0x01, 0x00, 0x00, 0x38}} |
| 11919 | }; |
| 11920 | // clang-format on |
| 11921 | |
| 11922 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11923 | AssemblePacketFromFragments(packet)); |
| 11924 | |
| 11925 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11926 | |
| 11927 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 11928 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11929 | } |
| 11930 | |
| 11931 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown8Bytes) { |
| 11932 | // This test only for version 99. |
| 11933 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11934 | return; |
| 11935 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11936 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11937 | // clang-format off |
| 11938 | PacketFragments packet = { |
| 11939 | // type (short header, 4 byte packet number) |
| 11940 | {"", |
| 11941 | {0x43}}, |
| 11942 | // connection_id |
| 11943 | {"", |
| 11944 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11945 | // packet number |
| 11946 | {"", |
| 11947 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11948 | // frame type (unknown value, eight-byte encoding) |
| 11949 | {"", |
| 11950 | {kVarInt62EightBytes + 0x01, 0x00, 0x00, 0x01, 0x02, 0x34, 0x56, 0x38}} |
| 11951 | }; |
| 11952 | // clang-format on |
| 11953 | |
| 11954 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11955 | AssemblePacketFromFragments(packet)); |
| 11956 | |
| 11957 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11958 | |
| 11959 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 11960 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11961 | } |
| 11962 | |
| 11963 | // Three tests to check that known frame types that are not minimally |
| 11964 | // encoded generate IETF_QUIC_PROTOCOL_VIOLATION errors with detailed |
| 11965 | // information "Frame type not minimally encoded." |
| 11966 | // Look at the frame-type encoded in 2, 4, and 8 bytes. |
| 11967 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2Bytes) { |
| 11968 | // This test only for version 99. |
| 11969 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11970 | return; |
| 11971 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11972 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11973 | |
| 11974 | // clang-format off |
| 11975 | PacketFragments packet = { |
| 11976 | // type (short header, 4 byte packet number) |
| 11977 | {"", |
| 11978 | {0x43}}, |
| 11979 | // connection_id |
| 11980 | {"", |
| 11981 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11982 | // packet number |
| 11983 | {"", |
| 11984 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11985 | // frame type (Blocked, two-byte encoding) |
| 11986 | {"", |
| 11987 | {kVarInt62TwoBytes + 0x00, 0x08}} |
| 11988 | }; |
| 11989 | // clang-format on |
| 11990 | |
| 11991 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11992 | AssemblePacketFromFragments(packet)); |
| 11993 | |
| 11994 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11995 | |
| 11996 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 11997 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11998 | } |
| 11999 | |
| 12000 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown4Bytes) { |
| 12001 | // This test only for version 99. |
| 12002 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 12003 | return; |
| 12004 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12005 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12006 | |
| 12007 | // clang-format off |
| 12008 | PacketFragments packet = { |
| 12009 | // type (short header, 4 byte packet number) |
| 12010 | {"", |
| 12011 | {0x43}}, |
| 12012 | // connection_id |
| 12013 | {"", |
| 12014 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12015 | // packet number |
| 12016 | {"", |
| 12017 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12018 | // frame type (Blocked, four-byte encoding) |
| 12019 | {"", |
| 12020 | {kVarInt62FourBytes + 0x00, 0x00, 0x00, 0x08}} |
| 12021 | }; |
| 12022 | // clang-format on |
| 12023 | |
| 12024 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12025 | AssemblePacketFromFragments(packet)); |
| 12026 | |
| 12027 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 12028 | |
| 12029 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 12030 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 12031 | } |
| 12032 | |
| 12033 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown8Bytes) { |
| 12034 | // This test only for version 99. |
| 12035 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 12036 | return; |
| 12037 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12038 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12039 | // clang-format off |
| 12040 | PacketFragments packet = { |
| 12041 | // type (short header, 4 byte packet number) |
| 12042 | {"", |
| 12043 | {0x43}}, |
| 12044 | // connection_id |
| 12045 | {"", |
| 12046 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12047 | // packet number |
| 12048 | {"", |
| 12049 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12050 | // frame type (Blocked, eight-byte encoding) |
| 12051 | {"", |
| 12052 | {kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08}} |
| 12053 | }; |
| 12054 | // clang-format on |
| 12055 | |
| 12056 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12057 | AssemblePacketFromFragments(packet)); |
| 12058 | |
| 12059 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 12060 | |
| 12061 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 12062 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 12063 | } |
| 12064 | |
| 12065 | // Tests to check that all known OETF frame types that are not minimally |
| 12066 | // encoded generate IETF_QUIC_PROTOCOL_VIOLATION errors with detailed |
| 12067 | // information "Frame type not minimally encoded." |
| 12068 | // Just look at 2-byte encoding. |
| 12069 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2BytesAllTypes) { |
| 12070 | // This test only for version 99. |
| 12071 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 12072 | return; |
| 12073 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12074 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12075 | |
| 12076 | // clang-format off |
| 12077 | PacketFragments packets[] = { |
| 12078 | { |
| 12079 | // type (short header, 4 byte packet number) |
| 12080 | {"", |
| 12081 | {0x43}}, |
| 12082 | // connection_id |
| 12083 | {"", |
| 12084 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12085 | // packet number |
| 12086 | {"", |
| 12087 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12088 | // frame type (two-byte encoding) |
| 12089 | {"", |
| 12090 | {kVarInt62TwoBytes + 0x00, 0x00}} |
| 12091 | }, |
| 12092 | { |
| 12093 | // type (short header, 4 byte packet number) |
| 12094 | {"", |
| 12095 | {0x43}}, |
| 12096 | // connection_id |
| 12097 | {"", |
| 12098 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12099 | // packet number |
| 12100 | {"", |
| 12101 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12102 | // frame type (two-byte encoding) |
| 12103 | {"", |
| 12104 | {kVarInt62TwoBytes + 0x00, 0x01}} |
| 12105 | }, |
| 12106 | { |
| 12107 | // type (short header, 4 byte packet number) |
| 12108 | {"", |
| 12109 | {0x43}}, |
| 12110 | // connection_id |
| 12111 | {"", |
| 12112 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12113 | // packet number |
| 12114 | {"", |
| 12115 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12116 | // frame type (two-byte encoding) |
| 12117 | {"", |
| 12118 | {kVarInt62TwoBytes + 0x00, 0x02}} |
| 12119 | }, |
| 12120 | { |
| 12121 | // type (short header, 4 byte packet number) |
| 12122 | {"", |
| 12123 | {0x43}}, |
| 12124 | // connection_id |
| 12125 | {"", |
| 12126 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12127 | // packet number |
| 12128 | {"", |
| 12129 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12130 | // frame type (two-byte encoding) |
| 12131 | {"", |
| 12132 | {kVarInt62TwoBytes + 0x00, 0x03}} |
| 12133 | }, |
| 12134 | { |
| 12135 | // type (short header, 4 byte packet number) |
| 12136 | {"", |
| 12137 | {0x43}}, |
| 12138 | // connection_id |
| 12139 | {"", |
| 12140 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12141 | // packet number |
| 12142 | {"", |
| 12143 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12144 | // frame type (two-byte encoding) |
| 12145 | {"", |
| 12146 | {kVarInt62TwoBytes + 0x00, 0x04}} |
| 12147 | }, |
| 12148 | { |
| 12149 | // type (short header, 4 byte packet number) |
| 12150 | {"", |
| 12151 | {0x43}}, |
| 12152 | // connection_id |
| 12153 | {"", |
| 12154 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12155 | // packet number |
| 12156 | {"", |
| 12157 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12158 | // frame type (two-byte encoding) |
| 12159 | {"", |
| 12160 | {kVarInt62TwoBytes + 0x00, 0x05}} |
| 12161 | }, |
| 12162 | { |
| 12163 | // type (short header, 4 byte packet number) |
| 12164 | {"", |
| 12165 | {0x43}}, |
| 12166 | // connection_id |
| 12167 | {"", |
| 12168 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12169 | // packet number |
| 12170 | {"", |
| 12171 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12172 | // frame type (two-byte encoding) |
| 12173 | {"", |
| 12174 | {kVarInt62TwoBytes + 0x00, 0x06}} |
| 12175 | }, |
| 12176 | { |
| 12177 | // type (short header, 4 byte packet number) |
| 12178 | {"", |
| 12179 | {0x43}}, |
| 12180 | // connection_id |
| 12181 | {"", |
| 12182 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12183 | // packet number |
| 12184 | {"", |
| 12185 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12186 | // frame type (two-byte encoding) |
| 12187 | {"", |
| 12188 | {kVarInt62TwoBytes + 0x00, 0x07}} |
| 12189 | }, |
| 12190 | { |
| 12191 | // type (short header, 4 byte packet number) |
| 12192 | {"", |
| 12193 | {0x43}}, |
| 12194 | // connection_id |
| 12195 | {"", |
| 12196 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12197 | // packet number |
| 12198 | {"", |
| 12199 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12200 | // frame type (two-byte encoding) |
| 12201 | {"", |
| 12202 | {kVarInt62TwoBytes + 0x00, 0x08}} |
| 12203 | }, |
| 12204 | { |
| 12205 | // type (short header, 4 byte packet number) |
| 12206 | {"", |
| 12207 | {0x43}}, |
| 12208 | // connection_id |
| 12209 | {"", |
| 12210 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12211 | // packet number |
| 12212 | {"", |
| 12213 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12214 | // frame type (two-byte encoding) |
| 12215 | {"", |
| 12216 | {kVarInt62TwoBytes + 0x00, 0x09}} |
| 12217 | }, |
| 12218 | { |
| 12219 | // type (short header, 4 byte packet number) |
| 12220 | {"", |
| 12221 | {0x43}}, |
| 12222 | // connection_id |
| 12223 | {"", |
| 12224 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12225 | // packet number |
| 12226 | {"", |
| 12227 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12228 | // frame type (two-byte encoding) |
| 12229 | {"", |
| 12230 | {kVarInt62TwoBytes + 0x00, 0x0a}} |
| 12231 | }, |
| 12232 | { |
| 12233 | // type (short header, 4 byte packet number) |
| 12234 | {"", |
| 12235 | {0x43}}, |
| 12236 | // connection_id |
| 12237 | {"", |
| 12238 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12239 | // packet number |
| 12240 | {"", |
| 12241 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12242 | // frame type (two-byte encoding) |
| 12243 | {"", |
| 12244 | {kVarInt62TwoBytes + 0x00, 0x0b}} |
| 12245 | }, |
| 12246 | { |
| 12247 | // type (short header, 4 byte packet number) |
| 12248 | {"", |
| 12249 | {0x43}}, |
| 12250 | // connection_id |
| 12251 | {"", |
| 12252 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12253 | // packet number |
| 12254 | {"", |
| 12255 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12256 | // frame type (two-byte encoding) |
| 12257 | {"", |
| 12258 | {kVarInt62TwoBytes + 0x00, 0x0c}} |
| 12259 | }, |
| 12260 | { |
| 12261 | // type (short header, 4 byte packet number) |
| 12262 | {"", |
| 12263 | {0x43}}, |
| 12264 | // connection_id |
| 12265 | {"", |
| 12266 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12267 | // packet number |
| 12268 | {"", |
| 12269 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12270 | // frame type (two-byte encoding) |
| 12271 | {"", |
| 12272 | {kVarInt62TwoBytes + 0x00, 0x0d}} |
| 12273 | }, |
| 12274 | { |
| 12275 | // type (short header, 4 byte packet number) |
| 12276 | {"", |
| 12277 | {0x43}}, |
| 12278 | // connection_id |
| 12279 | {"", |
| 12280 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12281 | // packet number |
| 12282 | {"", |
| 12283 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12284 | // frame type (two-byte encoding) |
| 12285 | {"", |
| 12286 | {kVarInt62TwoBytes + 0x00, 0x0e}} |
| 12287 | }, |
| 12288 | { |
| 12289 | // type (short header, 4 byte packet number) |
| 12290 | {"", |
| 12291 | {0x43}}, |
| 12292 | // connection_id |
| 12293 | {"", |
| 12294 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12295 | // packet number |
| 12296 | {"", |
| 12297 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12298 | // frame type (two-byte encoding) |
| 12299 | {"", |
| 12300 | {kVarInt62TwoBytes + 0x00, 0x0f}} |
| 12301 | }, |
| 12302 | { |
| 12303 | // type (short header, 4 byte packet number) |
| 12304 | {"", |
| 12305 | {0x43}}, |
| 12306 | // connection_id |
| 12307 | {"", |
| 12308 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12309 | // packet number |
| 12310 | {"", |
| 12311 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12312 | // frame type (two-byte encoding) |
| 12313 | {"", |
| 12314 | {kVarInt62TwoBytes + 0x00, 0x10}} |
| 12315 | }, |
| 12316 | { |
| 12317 | // type (short header, 4 byte packet number) |
| 12318 | {"", |
| 12319 | {0x43}}, |
| 12320 | // connection_id |
| 12321 | {"", |
| 12322 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12323 | // packet number |
| 12324 | {"", |
| 12325 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12326 | // frame type (two-byte encoding) |
| 12327 | {"", |
| 12328 | {kVarInt62TwoBytes + 0x00, 0x11}} |
| 12329 | }, |
| 12330 | { |
| 12331 | // type (short header, 4 byte packet number) |
| 12332 | {"", |
| 12333 | {0x43}}, |
| 12334 | // connection_id |
| 12335 | {"", |
| 12336 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12337 | // packet number |
| 12338 | {"", |
| 12339 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12340 | // frame type (two-byte encoding) |
| 12341 | {"", |
| 12342 | {kVarInt62TwoBytes + 0x00, 0x12}} |
| 12343 | }, |
| 12344 | { |
| 12345 | // type (short header, 4 byte packet number) |
| 12346 | {"", |
| 12347 | {0x43}}, |
| 12348 | // connection_id |
| 12349 | {"", |
| 12350 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12351 | // packet number |
| 12352 | {"", |
| 12353 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12354 | // frame type (two-byte encoding) |
| 12355 | {"", |
| 12356 | {kVarInt62TwoBytes + 0x00, 0x13}} |
| 12357 | }, |
| 12358 | { |
| 12359 | // type (short header, 4 byte packet number) |
| 12360 | {"", |
| 12361 | {0x43}}, |
| 12362 | // connection_id |
| 12363 | {"", |
| 12364 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12365 | // packet number |
| 12366 | {"", |
| 12367 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12368 | // frame type (two-byte encoding) |
| 12369 | {"", |
| 12370 | {kVarInt62TwoBytes + 0x00, 0x14}} |
| 12371 | }, |
| 12372 | { |
| 12373 | // type (short header, 4 byte packet number) |
| 12374 | {"", |
| 12375 | {0x43}}, |
| 12376 | // connection_id |
| 12377 | {"", |
| 12378 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12379 | // packet number |
| 12380 | {"", |
| 12381 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12382 | // frame type (two-byte encoding) |
| 12383 | {"", |
| 12384 | {kVarInt62TwoBytes + 0x00, 0x15}} |
| 12385 | }, |
| 12386 | { |
| 12387 | // type (short header, 4 byte packet number) |
| 12388 | {"", |
| 12389 | {0x43}}, |
| 12390 | // connection_id |
| 12391 | {"", |
| 12392 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12393 | // packet number |
| 12394 | {"", |
| 12395 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12396 | // frame type (two-byte encoding) |
| 12397 | {"", |
| 12398 | {kVarInt62TwoBytes + 0x00, 0x16}} |
| 12399 | }, |
| 12400 | { |
| 12401 | // type (short header, 4 byte packet number) |
| 12402 | {"", |
| 12403 | {0x43}}, |
| 12404 | // connection_id |
| 12405 | {"", |
| 12406 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12407 | // packet number |
| 12408 | {"", |
| 12409 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12410 | // frame type (two-byte encoding) |
| 12411 | {"", |
| 12412 | {kVarInt62TwoBytes + 0x00, 0x17}} |
| 12413 | }, |
| 12414 | { |
| 12415 | // type (short header, 4 byte packet number) |
| 12416 | {"", |
| 12417 | {0x43}}, |
| 12418 | // connection_id |
| 12419 | {"", |
| 12420 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12421 | // packet number |
| 12422 | {"", |
| 12423 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12424 | // frame type (two-byte encoding) |
| 12425 | {"", |
| 12426 | {kVarInt62TwoBytes + 0x00, 0x18}} |
| 12427 | }, |
| 12428 | { |
| 12429 | // type (short header, 4 byte packet number) |
| 12430 | {"", |
| 12431 | {0x43}}, |
| 12432 | // connection_id |
| 12433 | {"", |
| 12434 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12435 | // packet number |
| 12436 | {"", |
| 12437 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12438 | // frame type (two-byte encoding) |
| 12439 | {"", |
| 12440 | {kVarInt62TwoBytes + 0x00, 0x20}} |
| 12441 | }, |
| 12442 | { |
| 12443 | // type (short header, 4 byte packet number) |
| 12444 | {"", |
| 12445 | {0x43}}, |
| 12446 | // connection_id |
| 12447 | {"", |
| 12448 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12449 | // packet number |
| 12450 | {"", |
| 12451 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12452 | // frame type (two-byte encoding) |
| 12453 | {"", |
| 12454 | {kVarInt62TwoBytes + 0x00, 0x21}} |
| 12455 | }, |
| 12456 | }; |
| 12457 | // clang-format on |
| 12458 | |
| 12459 | for (PacketFragments& packet : packets) { |
| 12460 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12461 | AssemblePacketFromFragments(packet)); |
| 12462 | |
| 12463 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 12464 | |
| 12465 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 12466 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 12467 | } |
| 12468 | } |
| 12469 | |
| 12470 | TEST_P(QuicFramerTest, RetireConnectionIdFrame) { |
| 12471 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 12472 | // This frame is only for version 99. |
| 12473 | return; |
| 12474 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12475 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12476 | // clang-format off |
| 12477 | PacketFragments packet99 = { |
| 12478 | // type (short header, 4 byte packet number) |
| 12479 | {"", |
| 12480 | {0x43}}, |
| 12481 | // connection_id |
| 12482 | {"", |
| 12483 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12484 | // packet number |
| 12485 | {"", |
| 12486 | {0x12, 0x34, 0x56, 0x78}}, |
| 12487 | // frame type (IETF_RETIRE_CONNECTION_ID frame) |
| 12488 | {"", |
| 12489 | {0x19}}, |
| 12490 | // Sequence number |
| 12491 | {"Unable to read retire connection ID frame sequence number.", |
| 12492 | {kVarInt62TwoBytes + 0x11, 0x22}} |
| 12493 | }; |
| 12494 | // clang-format on |
| 12495 | |
| 12496 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12497 | AssemblePacketFromFragments(packet99)); |
| 12498 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 12499 | |
| 12500 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 12501 | ASSERT_TRUE(visitor_.header_.get()); |
| 12502 | EXPECT_TRUE(CheckDecryption( |
| 12503 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 12504 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 12505 | |
| 12506 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 12507 | |
| 12508 | EXPECT_EQ(0x1122u, visitor_.retire_connection_id_.sequence_number); |
| 12509 | |
| 12510 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 12511 | |
| 12512 | CheckFramingBoundaries(packet99, QUIC_INVALID_RETIRE_CONNECTION_ID_DATA); |
| 12513 | } |
| 12514 | |
| 12515 | TEST_P(QuicFramerTest, BuildRetireConnectionIdFramePacket) { |
| 12516 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 12517 | // This frame is only for version 99. |
| 12518 | return; |
| 12519 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 12520 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12521 | QuicPacketHeader header; |
| 12522 | header.destination_connection_id = FramerTestConnectionId(); |
| 12523 | header.reset_flag = false; |
| 12524 | header.version_flag = false; |
| 12525 | header.packet_number = kPacketNumber; |
| 12526 | |
| 12527 | QuicRetireConnectionIdFrame frame; |
| 12528 | frame.sequence_number = 0x1122; |
| 12529 | |
| 12530 | QuicFrames frames = {QuicFrame(&frame)}; |
| 12531 | |
| 12532 | // clang-format off |
| 12533 | unsigned char packet99[] = { |
| 12534 | // type (short header, 4 byte packet number) |
| 12535 | 0x43, |
| 12536 | // connection_id |
| 12537 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12538 | // packet number |
| 12539 | 0x12, 0x34, 0x56, 0x78, |
| 12540 | |
| 12541 | // frame type (IETF_RETIRE_CONNECTION_ID frame) |
| 12542 | 0x19, |
| 12543 | // sequence number |
| 12544 | kVarInt62TwoBytes + 0x11, 0x22 |
| 12545 | }; |
| 12546 | // clang-format on |
| 12547 | |
| 12548 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 12549 | ASSERT_TRUE(data != nullptr); |
| 12550 | |
| 12551 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 12552 | data->length(), AsChars(packet99), |
| 12553 | QUIC_ARRAYSIZE(packet99)); |
| 12554 | } |
| 12555 | |
| 12556 | TEST_P(QuicFramerTest, AckFrameWithInvalidLargestObserved) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12557 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12558 | // clang-format off |
| 12559 | unsigned char packet[] = { |
| 12560 | // public flags (8 byte connection_id) |
| 12561 | 0x2C, |
| 12562 | // connection_id |
| 12563 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12564 | // packet number |
| 12565 | 0x12, 0x34, 0x56, 0x78, |
| 12566 | |
| 12567 | // frame type (ack frame) |
| 12568 | 0x45, |
| 12569 | // largest observed |
| 12570 | 0x00, 0x00, |
| 12571 | // Zero delta time. |
| 12572 | 0x00, 0x00, |
| 12573 | // first ack block length. |
| 12574 | 0x00, 0x00, |
| 12575 | // num timestamps. |
| 12576 | 0x00 |
| 12577 | }; |
| 12578 | |
| 12579 | unsigned char packet44[] = { |
| 12580 | // type (short header, 4 byte packet number) |
| 12581 | 0x32, |
| 12582 | // connection_id |
| 12583 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12584 | // packet number |
| 12585 | 0x12, 0x34, 0x56, 0x78, |
| 12586 | |
| 12587 | // frame type (ack frame) |
| 12588 | 0x45, |
| 12589 | // largest observed |
| 12590 | 0x00, 0x00, |
| 12591 | // Zero delta time. |
| 12592 | 0x00, 0x00, |
| 12593 | // first ack block length. |
| 12594 | 0x00, 0x00, |
| 12595 | // num timestamps. |
| 12596 | 0x00 |
| 12597 | }; |
| 12598 | |
| 12599 | unsigned char packet46[] = { |
| 12600 | // type (short header, 4 byte packet number) |
| 12601 | 0x43, |
| 12602 | // connection_id |
| 12603 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12604 | // packet number |
| 12605 | 0x12, 0x34, 0x56, 0x78, |
| 12606 | |
| 12607 | // frame type (ack frame) |
| 12608 | 0x45, |
| 12609 | // largest observed |
| 12610 | 0x00, 0x00, |
| 12611 | // Zero delta time. |
| 12612 | 0x00, 0x00, |
| 12613 | // first ack block length. |
| 12614 | 0x00, 0x00, |
| 12615 | // num timestamps. |
| 12616 | 0x00 |
| 12617 | }; |
| 12618 | |
| 12619 | unsigned char packet99[] = { |
| 12620 | // type (short header, 4 byte packet number) |
| 12621 | 0x43, |
| 12622 | // connection_id |
| 12623 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12624 | // packet number |
| 12625 | 0x12, 0x34, 0x56, 0x78, |
| 12626 | |
| 12627 | // frame type (IETF_ACK frame) |
| 12628 | 0x02, |
| 12629 | // Largest acked |
| 12630 | kVarInt62OneByte + 0x00, |
| 12631 | // Zero delta time. |
| 12632 | kVarInt62OneByte + 0x00, |
| 12633 | // Ack block count 0 |
| 12634 | kVarInt62OneByte + 0x00, |
| 12635 | // First ack block length |
| 12636 | kVarInt62OneByte + 0x00, |
| 12637 | }; |
| 12638 | // clang-format on |
| 12639 | |
| 12640 | unsigned char* p = packet; |
| 12641 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 12642 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12643 | p = packet99; |
| 12644 | p_size = QUIC_ARRAYSIZE(packet99); |
| 12645 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 12646 | p = packet46; |
| 12647 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 12648 | p = packet44; |
| 12649 | p_size = QUIC_ARRAYSIZE(packet44); |
| 12650 | } |
| 12651 | |
| 12652 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12653 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12654 | EXPECT_EQ(framer_.detailed_error(), "Largest acked is 0."); |
| 12655 | } |
| 12656 | |
| 12657 | TEST_P(QuicFramerTest, FirstAckBlockJustUnderFlow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12658 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12659 | // clang-format off |
| 12660 | unsigned char packet[] = { |
| 12661 | // public flags (8 byte connection_id) |
| 12662 | 0x2C, |
| 12663 | // connection_id |
| 12664 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12665 | // packet number |
| 12666 | 0x12, 0x34, 0x56, 0x78, |
| 12667 | |
| 12668 | // frame type (ack frame) |
| 12669 | 0x45, |
| 12670 | // largest observed |
| 12671 | 0x00, 0x02, |
| 12672 | // Zero delta time. |
| 12673 | 0x00, 0x00, |
| 12674 | // first ack block length. |
| 12675 | 0x00, 0x03, |
| 12676 | // num timestamps. |
| 12677 | 0x00 |
| 12678 | }; |
| 12679 | |
| 12680 | unsigned char packet44[] = { |
| 12681 | // type (short header, 4 byte packet number) |
| 12682 | 0x32, |
| 12683 | // connection_id |
| 12684 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12685 | // packet number |
| 12686 | 0x12, 0x34, 0x56, 0x78, |
| 12687 | |
| 12688 | // frame type (ack frame) |
| 12689 | 0x45, |
| 12690 | // largest observed |
| 12691 | 0x00, 0x02, |
| 12692 | // Zero delta time. |
| 12693 | 0x00, 0x00, |
| 12694 | // first ack block length. |
| 12695 | 0x00, 0x03, |
| 12696 | // num timestamps. |
| 12697 | 0x00 |
| 12698 | }; |
| 12699 | |
| 12700 | unsigned char packet46[] = { |
| 12701 | // type (short header, 4 byte packet number) |
| 12702 | 0x43, |
| 12703 | // connection_id |
| 12704 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12705 | // packet number |
| 12706 | 0x12, 0x34, 0x56, 0x78, |
| 12707 | |
| 12708 | // frame type (ack frame) |
| 12709 | 0x45, |
| 12710 | // largest observed |
| 12711 | 0x00, 0x02, |
| 12712 | // Zero delta time. |
| 12713 | 0x00, 0x00, |
| 12714 | // first ack block length. |
| 12715 | 0x00, 0x03, |
| 12716 | // num timestamps. |
| 12717 | 0x00 |
| 12718 | }; |
| 12719 | |
| 12720 | unsigned char packet99[] = { |
| 12721 | // type (short header, 4 byte packet number) |
| 12722 | 0x43, |
| 12723 | // connection_id |
| 12724 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12725 | // packet number |
| 12726 | 0x12, 0x34, 0x56, 0x78, |
| 12727 | |
| 12728 | // frame type (IETF_ACK frame) |
| 12729 | 0x02, |
| 12730 | // Largest acked |
| 12731 | kVarInt62OneByte + 0x02, |
| 12732 | // Zero delta time. |
| 12733 | kVarInt62OneByte + 0x00, |
| 12734 | // Ack block count 0 |
| 12735 | kVarInt62OneByte + 0x00, |
| 12736 | // First ack block length |
| 12737 | kVarInt62OneByte + 0x02, |
| 12738 | }; |
| 12739 | // clang-format on |
| 12740 | |
| 12741 | unsigned char* p = packet; |
| 12742 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 12743 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12744 | p = packet99; |
| 12745 | p_size = QUIC_ARRAYSIZE(packet99); |
| 12746 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 12747 | p = packet46; |
| 12748 | p_size = QUIC_ARRAYSIZE(packet46); |
| 12749 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 12750 | p = packet44; |
| 12751 | p_size = QUIC_ARRAYSIZE(packet44); |
| 12752 | } |
| 12753 | |
| 12754 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12755 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12756 | EXPECT_EQ(framer_.detailed_error(), |
| 12757 | "Underflow with first ack block length 3 largest acked is 2."); |
| 12758 | } |
| 12759 | |
| 12760 | TEST_P(QuicFramerTest, ThirdAckBlockJustUnderflow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12761 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12762 | // clang-format off |
| 12763 | unsigned char packet[] = { |
| 12764 | // public flags (8 byte connection_id) |
| 12765 | 0x2C, |
| 12766 | // connection_id |
| 12767 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12768 | // packet number |
| 12769 | 0x12, 0x34, 0x56, 0x78, |
| 12770 | |
| 12771 | // frame type (ack frame) |
| 12772 | 0x60, |
| 12773 | // largest observed |
| 12774 | 0x0A, |
| 12775 | // Zero delta time. |
| 12776 | 0x00, 0x00, |
| 12777 | // Num of ack blocks |
| 12778 | 0x02, |
| 12779 | // first ack block length. |
| 12780 | 0x02, |
| 12781 | // gap to next block |
| 12782 | 0x01, |
| 12783 | // ack block length |
| 12784 | 0x01, |
| 12785 | // gap to next block |
| 12786 | 0x01, |
| 12787 | // ack block length |
| 12788 | 0x06, |
| 12789 | // num timestamps. |
| 12790 | 0x00 |
| 12791 | }; |
| 12792 | |
| 12793 | unsigned char packet44[] = { |
| 12794 | // type (short header, 4 byte packet number) |
| 12795 | 0x32, |
| 12796 | // connection_id |
| 12797 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12798 | // packet number |
| 12799 | 0x12, 0x34, 0x56, 0x78, |
| 12800 | |
| 12801 | // frame type (ack frame) |
| 12802 | 0x60, |
| 12803 | // largest observed |
| 12804 | 0x0A, |
| 12805 | // Zero delta time. |
| 12806 | 0x00, 0x00, |
| 12807 | // Num of ack blocks |
| 12808 | 0x02, |
| 12809 | // first ack block length. |
| 12810 | 0x02, |
| 12811 | // gap to next block |
| 12812 | 0x01, |
| 12813 | // ack block length |
| 12814 | 0x01, |
| 12815 | // gap to next block |
| 12816 | 0x01, |
| 12817 | // ack block length |
| 12818 | 0x06, |
| 12819 | // num timestamps. |
| 12820 | 0x00 |
| 12821 | }; |
| 12822 | |
| 12823 | unsigned char packet46[] = { |
| 12824 | // type (short header, 4 byte packet number) |
| 12825 | 0x43, |
| 12826 | // connection_id |
| 12827 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12828 | // packet number |
| 12829 | 0x12, 0x34, 0x56, 0x78, |
| 12830 | |
| 12831 | // frame type (ack frame) |
| 12832 | 0x60, |
| 12833 | // largest observed |
| 12834 | 0x0A, |
| 12835 | // Zero delta time. |
| 12836 | 0x00, 0x00, |
| 12837 | // Num of ack blocks |
| 12838 | 0x02, |
| 12839 | // first ack block length. |
| 12840 | 0x02, |
| 12841 | // gap to next block |
| 12842 | 0x01, |
| 12843 | // ack block length |
| 12844 | 0x01, |
| 12845 | // gap to next block |
| 12846 | 0x01, |
| 12847 | // ack block length |
| 12848 | 0x06, |
| 12849 | // num timestamps. |
| 12850 | 0x00 |
| 12851 | }; |
| 12852 | |
| 12853 | unsigned char packet99[] = { |
| 12854 | // type (short header, 4 byte packet number) |
| 12855 | 0x43, |
| 12856 | // connection_id |
| 12857 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12858 | // packet number |
| 12859 | 0x12, 0x34, 0x56, 0x78, |
| 12860 | |
| 12861 | // frame type (IETF_ACK frame) |
| 12862 | 0x02, |
| 12863 | // Largest acked |
| 12864 | kVarInt62OneByte + 0x0A, |
| 12865 | // Zero delta time. |
| 12866 | kVarInt62OneByte + 0x00, |
| 12867 | // Ack block count 2 |
| 12868 | kVarInt62OneByte + 0x02, |
| 12869 | // First ack block length |
| 12870 | kVarInt62OneByte + 0x01, |
| 12871 | // gap to next block length |
| 12872 | kVarInt62OneByte + 0x00, |
| 12873 | // ack block length |
| 12874 | kVarInt62OneByte + 0x00, |
| 12875 | // gap to next block length |
| 12876 | kVarInt62OneByte + 0x00, |
| 12877 | // ack block length |
| 12878 | kVarInt62OneByte + 0x05, |
| 12879 | }; |
| 12880 | // clang-format on |
| 12881 | |
| 12882 | unsigned char* p = packet; |
| 12883 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 12884 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12885 | p = packet99; |
| 12886 | p_size = QUIC_ARRAYSIZE(packet99); |
| 12887 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 12888 | p = packet46; |
| 12889 | p_size = QUIC_ARRAYSIZE(packet46); |
| 12890 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 12891 | p = packet44; |
| 12892 | p_size = QUIC_ARRAYSIZE(packet44); |
| 12893 | } |
| 12894 | |
| 12895 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12896 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12897 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12898 | EXPECT_EQ(framer_.detailed_error(), |
| 12899 | "Underflow with ack block length 6 latest ack block end is 5."); |
| 12900 | } else { |
| 12901 | EXPECT_EQ(framer_.detailed_error(), |
| 12902 | "Underflow with ack block length 6, end of block is 6."); |
| 12903 | } |
| 12904 | } |
| 12905 | |
| 12906 | TEST_P(QuicFramerTest, CoalescedPacket) { |
| 12907 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 12908 | return; |
| 12909 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12910 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12911 | // clang-format off |
| 12912 | unsigned char packet[] = { |
| 12913 | // first coalesced packet |
| 12914 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12915 | // 4-byte packet number) |
| 12916 | 0xD3, |
| 12917 | // version |
| 12918 | QUIC_VERSION_BYTES, |
| 12919 | // destination connection ID length |
| 12920 | 0x50, |
| 12921 | // destination connection ID |
| 12922 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12923 | // long header packet length |
| 12924 | 0x1E, |
| 12925 | // packet number |
| 12926 | 0x12, 0x34, 0x56, 0x78, |
| 12927 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12928 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12929 | // stream id |
| 12930 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12931 | // offset |
| 12932 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12933 | 0x32, 0x10, 0x76, 0x54, |
| 12934 | // data length |
| 12935 | kVarInt62OneByte + 0x0c, |
| 12936 | // data |
| 12937 | 'h', 'e', 'l', 'l', |
| 12938 | 'o', ' ', 'w', 'o', |
| 12939 | 'r', 'l', 'd', '!', |
| 12940 | // second coalesced packet |
| 12941 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12942 | // 4-byte packet number) |
| 12943 | 0xD3, |
| 12944 | // version |
| 12945 | QUIC_VERSION_BYTES, |
| 12946 | // destination connection ID length |
| 12947 | 0x50, |
| 12948 | // destination connection ID |
| 12949 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12950 | // long header packet length |
| 12951 | 0x1E, |
| 12952 | // packet number |
| 12953 | 0x12, 0x34, 0x56, 0x79, |
| 12954 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12955 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12956 | // stream id |
| 12957 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12958 | // offset |
| 12959 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12960 | 0x32, 0x10, 0x76, 0x54, |
| 12961 | // data length |
| 12962 | kVarInt62OneByte + 0x0c, |
| 12963 | // data |
| 12964 | 'H', 'E', 'L', 'L', |
| 12965 | 'O', '_', 'W', 'O', |
| 12966 | 'R', 'L', 'D', '?', |
| 12967 | }; |
| 12968 | // clang-format on |
| 12969 | |
| 12970 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 12971 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 12972 | |
| 12973 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 12974 | ASSERT_TRUE(visitor_.header_.get()); |
| 12975 | |
| 12976 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12977 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12978 | |
| 12979 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12980 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12981 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12982 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12983 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 12984 | |
| 12985 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 1u); |
| 12986 | EXPECT_TRUE(framer_.ProcessPacket(*visitor_.coalesced_packets_[0].get())); |
| 12987 | |
| 12988 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 12989 | ASSERT_TRUE(visitor_.header_.get()); |
| 12990 | |
| 12991 | ASSERT_EQ(2u, visitor_.stream_frames_.size()); |
| 12992 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12993 | |
| 12994 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12995 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[1]->stream_id); |
| 12996 | EXPECT_TRUE(visitor_.stream_frames_[1]->fin); |
| 12997 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[1]->offset); |
| 12998 | CheckStreamFrameData("HELLO_WORLD?", visitor_.stream_frames_[1].get()); |
| 12999 | } |
| 13000 | |
| 13001 | TEST_P(QuicFramerTest, MismatchedCoalescedPacket) { |
| 13002 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 13003 | return; |
| 13004 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13005 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13006 | // clang-format off |
| 13007 | unsigned char packet[] = { |
| 13008 | // first coalesced packet |
| 13009 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13010 | // 4-byte packet number) |
| 13011 | 0xD3, |
| 13012 | // version |
| 13013 | QUIC_VERSION_BYTES, |
| 13014 | // destination connection ID length |
| 13015 | 0x50, |
| 13016 | // destination connection ID |
| 13017 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13018 | // long header packet length |
| 13019 | 0x1E, |
| 13020 | // packet number |
| 13021 | 0x12, 0x34, 0x56, 0x78, |
| 13022 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 13023 | 0x08 | 0x01 | 0x02 | 0x04, |
| 13024 | // stream id |
| 13025 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 13026 | // offset |
| 13027 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 13028 | 0x32, 0x10, 0x76, 0x54, |
| 13029 | // data length |
| 13030 | kVarInt62OneByte + 0x0c, |
| 13031 | // data |
| 13032 | 'h', 'e', 'l', 'l', |
| 13033 | 'o', ' ', 'w', 'o', |
| 13034 | 'r', 'l', 'd', '!', |
| 13035 | // second coalesced packet |
| 13036 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13037 | // 4-byte packet number) |
| 13038 | 0xD3, |
| 13039 | // version |
| 13040 | QUIC_VERSION_BYTES, |
| 13041 | // destination connection ID length |
| 13042 | 0x50, |
| 13043 | // destination connection ID |
| 13044 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 13045 | // long header packet length |
| 13046 | 0x1E, |
| 13047 | // packet number |
| 13048 | 0x12, 0x34, 0x56, 0x79, |
| 13049 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 13050 | 0x08 | 0x01 | 0x02 | 0x04, |
| 13051 | // stream id |
| 13052 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 13053 | // offset |
| 13054 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 13055 | 0x32, 0x10, 0x76, 0x54, |
| 13056 | // data length |
| 13057 | kVarInt62OneByte + 0x0c, |
| 13058 | // data |
| 13059 | 'H', 'E', 'L', 'L', |
| 13060 | 'O', '_', 'W', 'O', |
| 13061 | 'R', 'L', 'D', '?', |
| 13062 | }; |
| 13063 | // clang-format on |
| 13064 | |
| 13065 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 13066 | EXPECT_QUIC_PEER_BUG(EXPECT_TRUE(framer_.ProcessPacket(encrypted)), |
| 13067 | "Server: Received mismatched coalesced header.*"); |
| 13068 | |
| 13069 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 13070 | ASSERT_TRUE(visitor_.header_.get()); |
| 13071 | |
| 13072 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 13073 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 13074 | |
| 13075 | // Stream ID should be the last 3 bytes of kStreamId. |
| 13076 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 13077 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 13078 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 13079 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 13080 | |
| 13081 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 0u); |
| 13082 | } |
| 13083 | |
| 13084 | TEST_P(QuicFramerTest, InvalidCoalescedPacket) { |
| 13085 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 13086 | return; |
| 13087 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13088 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13089 | // clang-format off |
| 13090 | unsigned char packet[] = { |
| 13091 | // first coalesced packet |
| 13092 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13093 | // 4-byte packet number) |
| 13094 | 0xD3, |
| 13095 | // version |
| 13096 | QUIC_VERSION_BYTES, |
| 13097 | // destination connection ID length |
| 13098 | 0x50, |
| 13099 | // destination connection ID |
| 13100 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13101 | // long header packet length |
| 13102 | 0x1E, |
| 13103 | // packet number |
| 13104 | 0x12, 0x34, 0x56, 0x78, |
| 13105 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 13106 | 0x08 | 0x01 | 0x02 | 0x04, |
| 13107 | // stream id |
| 13108 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 13109 | // offset |
| 13110 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 13111 | 0x32, 0x10, 0x76, 0x54, |
| 13112 | // data length |
| 13113 | kVarInt62OneByte + 0x0c, |
| 13114 | // data |
| 13115 | 'h', 'e', 'l', 'l', |
| 13116 | 'o', ' ', 'w', 'o', |
| 13117 | 'r', 'l', 'd', '!', |
| 13118 | // second coalesced packet |
| 13119 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13120 | // 4-byte packet number) |
| 13121 | 0xD3, |
| 13122 | // version would be here but we cut off the invalid coalesced header. |
| 13123 | }; |
| 13124 | // clang-format on |
| 13125 | |
| 13126 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 13127 | EXPECT_QUIC_PEER_BUG(EXPECT_TRUE(framer_.ProcessPacket(encrypted)), |
| 13128 | "Server: Failed to parse received coalesced header.*"); |
| 13129 | |
| 13130 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 13131 | ASSERT_TRUE(visitor_.header_.get()); |
| 13132 | |
| 13133 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 13134 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 13135 | |
| 13136 | // Stream ID should be the last 3 bytes of kStreamId. |
| 13137 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 13138 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 13139 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 13140 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 13141 | |
| 13142 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 0u); |
| 13143 | } |
| 13144 | |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 13145 | TEST_P(QuicFramerTest, ClientReceivesInvalidVersion) { |
| 13146 | if (framer_.transport_version() < QUIC_VERSION_44) { |
| 13147 | return; |
| 13148 | } |
| 13149 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 13150 | |
| 13151 | // clang-format off |
| 13152 | unsigned char packet[] = { |
| 13153 | // public flags (long header with packet type INITIAL) |
| 13154 | 0xFF, |
| 13155 | // version that is different from the framer's version |
| 13156 | 'Q', '0', '4', '3', |
| 13157 | // connection ID lengths |
| 13158 | 0x05, |
| 13159 | // source connection ID |
| 13160 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13161 | // packet number |
| 13162 | 0x01, |
| 13163 | // padding frame |
| 13164 | 0x00, |
| 13165 | }; |
| 13166 | // clang-format on |
| 13167 | |
| 13168 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 13169 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 13170 | |
| 13171 | EXPECT_EQ(QUIC_INVALID_VERSION, framer_.error()); |
| 13172 | EXPECT_EQ("Client received unexpected version.", framer_.detailed_error()); |
| 13173 | } |
| 13174 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13175 | TEST_P(QuicFramerTest, PacketHeaderWithVariableLengthConnectionId) { |
| 13176 | if (framer_.transport_version() < QUIC_VERSION_46) { |
| 13177 | return; |
| 13178 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13179 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13180 | char connection_id_bytes[9] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, |
| 13181 | 0x54, 0x32, 0x10, 0x42}; |
| 13182 | QuicConnectionId connection_id(connection_id_bytes, |
| 13183 | sizeof(connection_id_bytes)); |
| 13184 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 13185 | QuicFramerPeer::SetExpectedConnectionIDLength(&framer_, |
| 13186 | connection_id.length()); |
| 13187 | |
| 13188 | // clang-format off |
| 13189 | PacketFragments packet = { |
| 13190 | // type (8 byte connection_id and 1 byte packet number) |
| 13191 | {"Unable to read type.", |
| 13192 | {0x40}}, |
| 13193 | // connection_id |
| 13194 | {"Unable to read Destination ConnectionId.", |
| 13195 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 13196 | // packet number |
| 13197 | {"Unable to read packet number.", |
| 13198 | {0x78}}, |
| 13199 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13200 | |
| 13201 | PacketFragments packet_with_padding = { |
| 13202 | // type (8 byte connection_id and 1 byte packet number) |
| 13203 | {"Unable to read type.", |
| 13204 | {0x40}}, |
| 13205 | // connection_id |
| 13206 | {"Unable to read Destination ConnectionId.", |
| 13207 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 13208 | // packet number |
| 13209 | {"", |
| 13210 | {0x78}}, |
| 13211 | // padding |
| 13212 | {"", {0x00, 0x00, 0x00}}, |
| 13213 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13214 | // clang-format on |
| 13215 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13216 | PacketFragments& fragments = |
| 13217 | framer_.version().HasHeaderProtection() ? packet_with_padding : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13218 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13219 | AssemblePacketFromFragments(fragments)); |
| 13220 | if (framer_.version().HasHeaderProtection()) { |
| 13221 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 13222 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 13223 | } else { |
| 13224 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 13225 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 13226 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13227 | ASSERT_TRUE(visitor_.header_.get()); |
| 13228 | EXPECT_EQ(connection_id, visitor_.header_->destination_connection_id); |
| 13229 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 13230 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 13231 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 13232 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 13233 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13234 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13235 | } |
| 13236 | |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13237 | TEST_P(QuicFramerTest, UpdateExpectedConnectionIdLength) { |
| 13238 | if (framer_.transport_version() < QUIC_VERSION_46) { |
| 13239 | return; |
| 13240 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13241 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13242 | framer_.SetShouldUpdateExpectedConnectionIdLength(true); |
| 13243 | |
| 13244 | // clang-format off |
| 13245 | unsigned char long_header_packet[] = { |
| 13246 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13247 | // 4-byte packet number) |
| 13248 | 0xD3, |
| 13249 | // version |
| 13250 | QUIC_VERSION_BYTES, |
| 13251 | // destination connection ID length |
| 13252 | 0x60, |
| 13253 | // destination connection ID |
| 13254 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13255 | // packet number |
| 13256 | 0x12, 0x34, 0x56, 0x78, |
| 13257 | // padding frame |
| 13258 | 0x00, |
| 13259 | }; |
| 13260 | unsigned char long_header_packet99[] = { |
| 13261 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13262 | // 4-byte packet number) |
| 13263 | 0xD3, |
| 13264 | // version |
| 13265 | QUIC_VERSION_BYTES, |
| 13266 | // destination connection ID length |
| 13267 | 0x60, |
| 13268 | // destination connection ID |
| 13269 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13270 | // long header packet length |
| 13271 | 0x05, |
| 13272 | // packet number |
| 13273 | 0x12, 0x34, 0x56, 0x78, |
| 13274 | // padding frame |
| 13275 | 0x00, |
| 13276 | }; |
| 13277 | // clang-format on |
| 13278 | |
| 13279 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 13280 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13281 | QuicEncryptedPacket(AsChars(long_header_packet), |
| 13282 | QUIC_ARRAYSIZE(long_header_packet), false))); |
| 13283 | } else { |
| 13284 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13285 | QuicEncryptedPacket(AsChars(long_header_packet99), |
| 13286 | QUIC_ARRAYSIZE(long_header_packet99), false))); |
| 13287 | } |
| 13288 | |
| 13289 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 13290 | ASSERT_TRUE(visitor_.header_.get()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 13291 | EXPECT_EQ(visitor_.header_.get()->destination_connection_id, |
| 13292 | FramerTestConnectionIdNineBytes()); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13293 | EXPECT_EQ(visitor_.header_.get()->packet_number, |
| 13294 | QuicPacketNumber(UINT64_C(0x12345678))); |
| 13295 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13296 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13297 | // clang-format off |
| 13298 | unsigned char short_header_packet[] = { |
| 13299 | // type (short header, 4 byte packet number) |
| 13300 | 0x43, |
| 13301 | // connection_id |
| 13302 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13303 | // packet number |
| 13304 | 0x13, 0x37, 0x42, 0x33, |
| 13305 | // padding frame |
| 13306 | 0x00, |
| 13307 | }; |
| 13308 | // clang-format on |
| 13309 | |
| 13310 | QuicEncryptedPacket short_header_encrypted( |
| 13311 | AsChars(short_header_packet), QUIC_ARRAYSIZE(short_header_packet), false); |
| 13312 | EXPECT_TRUE(framer_.ProcessPacket(short_header_encrypted)); |
| 13313 | |
| 13314 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 13315 | ASSERT_TRUE(visitor_.header_.get()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 13316 | EXPECT_EQ(visitor_.header_.get()->destination_connection_id, |
| 13317 | FramerTestConnectionIdNineBytes()); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13318 | EXPECT_EQ(visitor_.header_.get()->packet_number, |
| 13319 | QuicPacketNumber(UINT64_C(0x13374233))); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 13320 | |
| 13321 | PacketHeaderFormat format; |
| 13322 | bool version_flag; |
| 13323 | uint8_t destination_connection_id_length; |
| 13324 | QuicConnectionId destination_connection_id; |
| 13325 | QuicVersionLabel version_label; |
| 13326 | std::string detailed_error; |
| 13327 | EXPECT_EQ(QUIC_NO_ERROR, |
| 13328 | QuicFramer::ProcessPacketDispatcher( |
| 13329 | QuicEncryptedPacket(AsChars(long_header_packet), |
| 13330 | QUIC_ARRAYSIZE(long_header_packet)), |
| 13331 | kQuicDefaultConnectionIdLength, &format, &version_flag, |
| 13332 | &version_label, &destination_connection_id_length, |
| 13333 | &destination_connection_id, &detailed_error)); |
| 13334 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 13335 | EXPECT_TRUE(version_flag); |
| 13336 | EXPECT_EQ(9, destination_connection_id_length); |
| 13337 | EXPECT_EQ(FramerTestConnectionIdNineBytes(), destination_connection_id); |
| 13338 | |
| 13339 | EXPECT_EQ(QUIC_NO_ERROR, |
| 13340 | QuicFramer::ProcessPacketDispatcher( |
| 13341 | short_header_encrypted, 9, &format, &version_flag, |
| 13342 | &version_label, &destination_connection_id_length, |
| 13343 | &destination_connection_id, &detailed_error)); |
| 13344 | EXPECT_EQ(IETF_QUIC_SHORT_HEADER_PACKET, format); |
| 13345 | EXPECT_FALSE(version_flag); |
| 13346 | EXPECT_EQ(9, destination_connection_id_length); |
| 13347 | EXPECT_EQ(FramerTestConnectionIdNineBytes(), destination_connection_id); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13348 | } |
| 13349 | |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13350 | TEST_P(QuicFramerTest, MultiplePacketNumberSpaces) { |
| 13351 | if (framer_.transport_version() < QUIC_VERSION_46) { |
| 13352 | return; |
| 13353 | } |
| 13354 | framer_.SetShouldUpdateExpectedConnectionIdLength(true); |
| 13355 | framer_.EnableMultiplePacketNumberSpacesSupport(); |
| 13356 | |
| 13357 | // clang-format off |
| 13358 | unsigned char long_header_packet[] = { |
| 13359 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13360 | // 4-byte packet number) |
| 13361 | 0xD3, |
| 13362 | // version |
| 13363 | QUIC_VERSION_BYTES, |
| 13364 | // destination connection ID length |
| 13365 | 0x60, |
| 13366 | // destination connection ID |
| 13367 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13368 | // packet number |
| 13369 | 0x12, 0x34, 0x56, 0x78, |
| 13370 | // padding frame |
| 13371 | 0x00, |
| 13372 | }; |
| 13373 | unsigned char long_header_packet99[] = { |
| 13374 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13375 | // 4-byte packet number) |
| 13376 | 0xD3, |
| 13377 | // version |
| 13378 | QUIC_VERSION_BYTES, |
| 13379 | // destination connection ID length |
| 13380 | 0x60, |
| 13381 | // destination connection ID |
| 13382 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13383 | // long header packet length |
| 13384 | 0x05, |
| 13385 | // packet number |
| 13386 | 0x12, 0x34, 0x56, 0x78, |
| 13387 | // padding frame |
| 13388 | 0x00, |
| 13389 | }; |
| 13390 | // clang-format on |
| 13391 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13392 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 13393 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 13394 | QuicMakeUnique<TestDecrypter>()); |
| 13395 | framer_.RemoveDecrypter(ENCRYPTION_INITIAL); |
| 13396 | } else { |
| 13397 | framer_.SetDecrypter(ENCRYPTION_ZERO_RTT, QuicMakeUnique<TestDecrypter>()); |
| 13398 | } |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13399 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 13400 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13401 | QuicEncryptedPacket(AsChars(long_header_packet), |
| 13402 | QUIC_ARRAYSIZE(long_header_packet), false))); |
| 13403 | } else { |
| 13404 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13405 | QuicEncryptedPacket(AsChars(long_header_packet99), |
| 13406 | QUIC_ARRAYSIZE(long_header_packet99), false))); |
| 13407 | } |
| 13408 | |
| 13409 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 13410 | EXPECT_FALSE( |
| 13411 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, INITIAL_DATA) |
| 13412 | .IsInitialized()); |
| 13413 | EXPECT_FALSE( |
| 13414 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, HANDSHAKE_DATA) |
| 13415 | .IsInitialized()); |
| 13416 | EXPECT_EQ(kPacketNumber, QuicFramerPeer::GetLargestDecryptedPacketNumber( |
| 13417 | &framer_, APPLICATION_DATA)); |
| 13418 | |
| 13419 | // clang-format off |
| 13420 | unsigned char short_header_packet[] = { |
| 13421 | // type (short header, 1 byte packet number) |
| 13422 | 0x40, |
| 13423 | // connection_id |
| 13424 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13425 | // packet number |
| 13426 | 0x79, |
| 13427 | // padding frame |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13428 | 0x00, 0x00, 0x00, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13429 | }; |
| 13430 | // clang-format on |
| 13431 | |
| 13432 | QuicEncryptedPacket short_header_encrypted( |
| 13433 | AsChars(short_header_packet), QUIC_ARRAYSIZE(short_header_packet), false); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13434 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 13435 | framer_.InstallDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 13436 | QuicMakeUnique<TestDecrypter>()); |
| 13437 | framer_.RemoveDecrypter(ENCRYPTION_ZERO_RTT); |
| 13438 | } else { |
| 13439 | framer_.SetDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 13440 | QuicMakeUnique<TestDecrypter>()); |
| 13441 | } |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13442 | EXPECT_TRUE(framer_.ProcessPacket(short_header_encrypted)); |
| 13443 | |
| 13444 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 13445 | EXPECT_FALSE( |
| 13446 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, INITIAL_DATA) |
| 13447 | .IsInitialized()); |
| 13448 | EXPECT_FALSE( |
| 13449 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, HANDSHAKE_DATA) |
| 13450 | .IsInitialized()); |
| 13451 | EXPECT_EQ(kPacketNumber + 1, QuicFramerPeer::GetLargestDecryptedPacketNumber( |
| 13452 | &framer_, APPLICATION_DATA)); |
| 13453 | } |
| 13454 | |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13455 | TEST_P(QuicFramerTest, IetfRetryPacketRejected) { |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13456 | if (!framer_.version().KnowsWhichDecrypterToUse() || |
| 13457 | framer_.version().SupportsRetry()) { |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13458 | return; |
| 13459 | } |
| 13460 | |
| 13461 | // clang-format off |
| 13462 | PacketFragments packet = { |
| 13463 | // public flags (IETF Retry packet, 0-length original destination CID) |
| 13464 | {"Unable to read type.", |
| 13465 | {0xf0}}, |
| 13466 | // version tag |
| 13467 | {"Unable to read protocol version.", |
| 13468 | {QUIC_VERSION_BYTES}}, |
| 13469 | // connection_id length |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 13470 | {"Illegal long header type value.", |
| 13471 | {0x00}}, |
| 13472 | }; |
| 13473 | // clang-format on |
| 13474 | |
| 13475 | // clang-format off |
| 13476 | PacketFragments packet45 = { |
| 13477 | // public flags (IETF Retry packet, 0-length original destination CID) |
| 13478 | {"Unable to read type.", |
| 13479 | {0xf0}}, |
| 13480 | // version tag |
| 13481 | {"Unable to read protocol version.", |
| 13482 | {QUIC_VERSION_BYTES}}, |
| 13483 | // connection_id length |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13484 | {"RETRY not supported in this version.", |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13485 | {0x00}}, |
| 13486 | }; |
| 13487 | // clang-format on |
| 13488 | |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 13489 | PacketFragments& fragments = |
| 13490 | framer_.transport_version() > QUIC_VERSION_44 ? packet45 : packet; |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13491 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 13492 | AssemblePacketFromFragments(fragments)); |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13493 | |
| 13494 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 13495 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 13496 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13497 | } |
| 13498 | |
| 13499 | TEST_P(QuicFramerTest, RetryPacketRejectedWithMultiplePacketNumberSpaces) { |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13500 | if (framer_.transport_version() < QUIC_VERSION_46 || |
| 13501 | framer_.version().SupportsRetry()) { |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13502 | return; |
| 13503 | } |
| 13504 | framer_.EnableMultiplePacketNumberSpacesSupport(); |
| 13505 | |
| 13506 | // clang-format off |
| 13507 | PacketFragments packet = { |
| 13508 | // public flags (IETF Retry packet, 0-length original destination CID) |
| 13509 | {"Unable to read type.", |
| 13510 | {0xf0}}, |
| 13511 | // version tag |
| 13512 | {"Unable to read protocol version.", |
| 13513 | {QUIC_VERSION_BYTES}}, |
| 13514 | // connection_id length |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13515 | {"RETRY not supported in this version.", |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13516 | {0x00}}, |
| 13517 | }; |
| 13518 | // clang-format on |
| 13519 | |
| 13520 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 13521 | AssemblePacketFromFragments(packet)); |
| 13522 | |
| 13523 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 13524 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
| 13525 | CheckFramingBoundaries(packet, QUIC_INVALID_PACKET_HEADER); |
| 13526 | } |
| 13527 | |
nharper | a745e39 | 2019-04-19 12:05:15 -0700 | [diff] [blame] | 13528 | TEST_P(QuicFramerTest, ProcessPublicHeaderNoVersionInferredType) { |
| 13529 | // The framer needs to have Perspective::IS_SERVER and configured to infer the |
| 13530 | // packet header type from the packet (not the version). The framer's version |
| 13531 | // needs to be one that uses the IETF packet format. |
| 13532 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 13533 | return; |
| 13534 | } |
| 13535 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 13536 | |
| 13537 | // Prepare a packet that uses the Google QUIC packet header but has no version |
| 13538 | // field. |
| 13539 | |
| 13540 | // clang-format off |
| 13541 | PacketFragments packet = { |
| 13542 | // public flags (1-byte packet number, 8-byte connection_id, no version) |
| 13543 | {"Unable to read public flags.", |
| 13544 | {0x08}}, |
| 13545 | // connection_id |
| 13546 | {"Unable to read ConnectionId.", |
| 13547 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 13548 | // packet number |
| 13549 | {"Unable to read packet number.", |
| 13550 | {0x01}}, |
| 13551 | // padding |
| 13552 | {"Invalid public header type for expected version.", |
| 13553 | {0x00}}, |
| 13554 | }; |
| 13555 | // clang-format on |
| 13556 | |
| 13557 | PacketFragments& fragments = packet; |
| 13558 | |
| 13559 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 13560 | AssemblePacketFromFragments(fragments)); |
| 13561 | |
| 13562 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 13563 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
nharper | 8b6d63a | 2019-05-03 10:34:53 -0700 | [diff] [blame] | 13564 | EXPECT_EQ("Invalid public header type for expected version.", |
| 13565 | framer_.detailed_error()); |
nharper | a745e39 | 2019-04-19 12:05:15 -0700 | [diff] [blame] | 13566 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 13567 | } |
| 13568 | |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 13569 | TEST_P(QuicFramerTest, ProcessMismatchedHeaderVersion) { |
| 13570 | // The framer needs to have Perspective::IS_SERVER and configured to infer the |
| 13571 | // packet header type from the packet (not the version). The framer's version |
| 13572 | // needs to be one that uses the IETF packet format. |
| 13573 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 13574 | return; |
| 13575 | } |
| 13576 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 13577 | |
| 13578 | // clang-format off |
| 13579 | PacketFragments packet = { |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 13580 | // public flags (Google QUIC header with version present) |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 13581 | {"Unable to read public flags.", |
| 13582 | {0x09}}, |
| 13583 | // connection_id |
| 13584 | {"Unable to read ConnectionId.", |
| 13585 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 13586 | // version tag |
| 13587 | {"Unable to read protocol version.", |
| 13588 | {QUIC_VERSION_BYTES}}, |
| 13589 | // packet number |
| 13590 | {"Unable to read packet number.", |
| 13591 | {0x01}}, |
| 13592 | }; |
| 13593 | // clang-format on |
| 13594 | |
| 13595 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 13596 | AssemblePacketFromFragments(packet)); |
| 13597 | framer_.ProcessPacket(*encrypted); |
| 13598 | |
| 13599 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 13600 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
nharper | 8b6d63a | 2019-05-03 10:34:53 -0700 | [diff] [blame] | 13601 | EXPECT_EQ("Invalid public header type for expected version.", |
| 13602 | framer_.detailed_error()); |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 13603 | CheckFramingBoundaries(packet, QUIC_INVALID_PACKET_HEADER); |
| 13604 | } |
| 13605 | |
dschinazi | de0f6dc | 2019-05-15 16:10:11 -0700 | [diff] [blame^] | 13606 | TEST_P(QuicFramerTest, WriteClientVersionNegotiationProbePacket) { |
| 13607 | // clang-format off |
| 13608 | static const char expected_packet[1200] = { |
| 13609 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 13610 | 0xc0, |
| 13611 | // Version, part of the IETF space reserved for negotiation. |
| 13612 | 0xca, 0xba, 0xda, 0xba, |
| 13613 | // Destination connection ID length 8, source connection ID length 0. |
| 13614 | 0x50, |
| 13615 | // 8-byte destination connection ID. |
| 13616 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 13617 | // 8 bytes of zeroes followed by 8 bytes of ones to ensure that this does |
| 13618 | // not parse with any known version. |
| 13619 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13620 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 13621 | // 2 bytes of zeroes to pad to 16 byte boundary. |
| 13622 | 0x00, 0x00, |
| 13623 | // A polite greeting in case a human sees this in tcpdump. |
| 13624 | 0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x63, |
| 13625 | 0x6b, 0x65, 0x74, 0x20, 0x6f, 0x6e, 0x6c, 0x79, |
| 13626 | 0x20, 0x65, 0x78, 0x69, 0x73, 0x74, 0x73, 0x20, |
| 13627 | 0x74, 0x6f, 0x20, 0x74, 0x72, 0x69, 0x67, 0x67, |
| 13628 | 0x65, 0x72, 0x20, 0x49, 0x45, 0x54, 0x46, 0x20, |
| 13629 | 0x51, 0x55, 0x49, 0x43, 0x20, 0x76, 0x65, 0x72, |
| 13630 | 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x65, 0x67, |
| 13631 | 0x6f, 0x74, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, |
| 13632 | 0x2e, 0x20, 0x50, 0x6c, 0x65, 0x61, 0x73, 0x65, |
| 13633 | 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, |
| 13634 | 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, |
| 13635 | 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, |
| 13636 | 0x4e, 0x65, 0x67, 0x6f, 0x74, 0x69, 0x61, 0x74, |
| 13637 | 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x63, 0x6b, |
| 13638 | 0x65, 0x74, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x63, |
| 13639 | 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x77, 0x68, |
| 13640 | 0x61, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, |
| 13641 | 0x6f, 0x6e, 0x73, 0x20, 0x79, 0x6f, 0x75, 0x20, |
| 13642 | 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2e, |
| 13643 | 0x20, 0x54, 0x68, 0x61, 0x6e, 0x6b, 0x20, 0x79, |
| 13644 | 0x6f, 0x75, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x68, |
| 13645 | 0x61, 0x76, 0x65, 0x20, 0x61, 0x20, 0x6e, 0x69, |
| 13646 | 0x63, 0x65, 0x20, 0x64, 0x61, 0x79, 0x2e, 0x00, |
| 13647 | }; |
| 13648 | // clang-format on |
| 13649 | char packet[1200]; |
| 13650 | char destination_connection_id_bytes[] = {0x56, 0x4e, 0x20, 0x70, |
| 13651 | 0x6c, 0x7a, 0x20, 0x21}; |
| 13652 | EXPECT_TRUE(QuicFramer::WriteClientVersionNegotiationProbePacket( |
| 13653 | packet, sizeof(packet), destination_connection_id_bytes, |
| 13654 | sizeof(destination_connection_id_bytes))); |
| 13655 | test::CompareCharArraysWithHexError("constructed packet", expected_packet, |
| 13656 | sizeof(expected_packet), packet, |
| 13657 | sizeof(packet)); |
| 13658 | QuicEncryptedPacket encrypted(reinterpret_cast<const char*>(packet), |
| 13659 | sizeof(packet), false); |
| 13660 | // Make sure we fail to parse this packet for the version under test. |
| 13661 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 13662 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 13663 | // We can only parse the connection ID with an IETF parser. |
| 13664 | return; |
| 13665 | } |
| 13666 | ASSERT_TRUE(visitor_.header_.get()); |
| 13667 | QuicConnectionId probe_payload_connection_id( |
| 13668 | reinterpret_cast<const char*>(destination_connection_id_bytes), |
| 13669 | sizeof(destination_connection_id_bytes)); |
| 13670 | EXPECT_EQ(probe_payload_connection_id, |
| 13671 | visitor_.header_.get()->destination_connection_id); |
| 13672 | } |
| 13673 | |
| 13674 | TEST_P(QuicFramerTest, ParseServerVersionNegotiationProbeResponse) { |
| 13675 | // clang-format off |
| 13676 | const char packet[] = { |
| 13677 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 13678 | 0xc0, |
| 13679 | // Version of 0, indicating version negotiation. |
| 13680 | 0x00, 0x00, 0x00, 0x00, |
| 13681 | // Destination connection ID length 0, source connection ID length 8. |
| 13682 | 0x05, |
| 13683 | // 8-byte source connection ID. |
| 13684 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 13685 | // A few supported versions. |
| 13686 | 0xaa, 0xaa, 0xaa, 0xaa, |
| 13687 | QUIC_VERSION_BYTES, |
| 13688 | }; |
| 13689 | // clang-format on |
| 13690 | char probe_payload_bytes[] = {0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21}; |
| 13691 | char parsed_probe_payload_bytes[kQuicMaxConnectionIdLength] = {}; |
| 13692 | uint8_t parsed_probe_payload_length = 0; |
| 13693 | std::string parse_detailed_error = ""; |
| 13694 | EXPECT_TRUE(QuicFramer::ParseServerVersionNegotiationProbeResponse( |
| 13695 | reinterpret_cast<const char*>(packet), sizeof(packet), |
| 13696 | reinterpret_cast<char*>(parsed_probe_payload_bytes), |
| 13697 | &parsed_probe_payload_length, &parse_detailed_error)); |
| 13698 | EXPECT_EQ("", parse_detailed_error); |
| 13699 | test::CompareCharArraysWithHexError( |
| 13700 | "parsed probe", probe_payload_bytes, sizeof(probe_payload_bytes), |
| 13701 | parsed_probe_payload_bytes, parsed_probe_payload_length); |
| 13702 | } |
| 13703 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13704 | } // namespace |
| 13705 | } // namespace test |
| 13706 | } // namespace quic |