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 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 444 | class QuicFramerTest : public QuicTestWithParam<ParsedQuicVersion> { |
| 445 | public: |
| 446 | QuicFramerTest() |
| 447 | : encrypter_(new test::TestEncrypter()), |
| 448 | decrypter_(new test::TestDecrypter()), |
| 449 | version_(GetParam()), |
| 450 | start_(QuicTime::Zero() + QuicTime::Delta::FromMicroseconds(0x10)), |
nharper | f5e6845 | 2019-05-29 17:24:18 -0700 | [diff] [blame] | 451 | framer_(AllSupportedVersions(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 452 | start_, |
| 453 | Perspective::IS_SERVER, |
| 454 | kQuicDefaultConnectionIdLength) { |
wub | 4985598 | 2019-05-01 14:16:26 -0700 | [diff] [blame] | 455 | SetQuicFlag(FLAGS_quic_supports_tls_handshake, true); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 456 | framer_.set_version(version_); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 457 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 458 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, |
| 459 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 460 | } else { |
| 461 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 462 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 463 | } |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 464 | framer_.SetEncrypter(ENCRYPTION_INITIAL, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 465 | std::unique_ptr<QuicEncrypter>(encrypter_)); |
| 466 | |
| 467 | framer_.set_visitor(&visitor_); |
| 468 | framer_.InferPacketHeaderTypeFromVersion(); |
| 469 | } |
| 470 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 471 | void SetDecrypterLevel(EncryptionLevel level) { |
| 472 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 473 | return; |
| 474 | } |
| 475 | decrypter_ = new TestDecrypter(); |
| 476 | framer_.InstallDecrypter(level, std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 477 | } |
| 478 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 479 | // Helper function to get unsigned char representation of the handshake |
| 480 | // protocol byte of the current QUIC version number. |
| 481 | unsigned char GetQuicVersionProtocolByte() { |
| 482 | return (CreateQuicVersionLabel(version_) >> 24) & 0xff; |
| 483 | } |
| 484 | |
| 485 | // Helper function to get unsigned char representation of digit in the |
| 486 | // units place of the current QUIC version number. |
| 487 | unsigned char GetQuicVersionDigitOnes() { |
| 488 | return CreateQuicVersionLabel(version_) & 0xff; |
| 489 | } |
| 490 | |
| 491 | // Helper function to get unsigned char representation of digit in the |
| 492 | // tens place of the current QUIC version number. |
| 493 | unsigned char GetQuicVersionDigitTens() { |
| 494 | return (CreateQuicVersionLabel(version_) >> 8) & 0xff; |
| 495 | } |
| 496 | |
| 497 | bool CheckEncryption(QuicPacketNumber packet_number, QuicPacket* packet) { |
| 498 | if (packet_number != encrypter_->packet_number_) { |
| 499 | QUIC_LOG(ERROR) << "Encrypted incorrect packet number. expected " |
| 500 | << packet_number |
| 501 | << " actual: " << encrypter_->packet_number_; |
| 502 | return false; |
| 503 | } |
| 504 | if (packet->AssociatedData(framer_.transport_version()) != |
| 505 | encrypter_->associated_data_) { |
| 506 | QUIC_LOG(ERROR) << "Encrypted incorrect associated data. expected " |
| 507 | << packet->AssociatedData(framer_.transport_version()) |
| 508 | << " actual: " << encrypter_->associated_data_; |
| 509 | return false; |
| 510 | } |
| 511 | if (packet->Plaintext(framer_.transport_version()) != |
| 512 | encrypter_->plaintext_) { |
| 513 | QUIC_LOG(ERROR) << "Encrypted incorrect plaintext data. expected " |
| 514 | << packet->Plaintext(framer_.transport_version()) |
| 515 | << " actual: " << encrypter_->plaintext_; |
| 516 | return false; |
| 517 | } |
| 518 | return true; |
| 519 | } |
| 520 | |
| 521 | bool CheckDecryption(const QuicEncryptedPacket& encrypted, |
| 522 | bool includes_version, |
| 523 | bool includes_diversification_nonce, |
| 524 | QuicConnectionIdLength destination_connection_id_length, |
| 525 | QuicConnectionIdLength source_connection_id_length) { |
| 526 | return CheckDecryption( |
| 527 | encrypted, includes_version, includes_diversification_nonce, |
| 528 | destination_connection_id_length, source_connection_id_length, |
| 529 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 530 | } |
| 531 | |
| 532 | bool CheckDecryption( |
| 533 | const QuicEncryptedPacket& encrypted, |
| 534 | bool includes_version, |
| 535 | bool includes_diversification_nonce, |
| 536 | QuicConnectionIdLength destination_connection_id_length, |
| 537 | QuicConnectionIdLength source_connection_id_length, |
| 538 | QuicVariableLengthIntegerLength retry_token_length_length, |
| 539 | size_t retry_token_length, |
| 540 | QuicVariableLengthIntegerLength length_length) { |
| 541 | if (visitor_.header_->packet_number != decrypter_->packet_number_) { |
| 542 | QUIC_LOG(ERROR) << "Decrypted incorrect packet number. expected " |
| 543 | << visitor_.header_->packet_number |
| 544 | << " actual: " << decrypter_->packet_number_; |
| 545 | return false; |
| 546 | } |
| 547 | QuicStringPiece associated_data = |
| 548 | QuicFramer::GetAssociatedDataFromEncryptedPacket( |
| 549 | framer_.transport_version(), encrypted, |
| 550 | destination_connection_id_length, source_connection_id_length, |
| 551 | includes_version, includes_diversification_nonce, |
| 552 | PACKET_4BYTE_PACKET_NUMBER, retry_token_length_length, |
| 553 | retry_token_length, length_length); |
| 554 | if (associated_data != decrypter_->associated_data_) { |
| 555 | QUIC_LOG(ERROR) << "Decrypted incorrect associated data. expected " |
| 556 | << QuicTextUtils::HexEncode(associated_data) |
| 557 | << " actual: " |
| 558 | << QuicTextUtils::HexEncode(decrypter_->associated_data_); |
| 559 | return false; |
| 560 | } |
| 561 | QuicStringPiece ciphertext( |
| 562 | encrypted.AsStringPiece().substr(GetStartOfEncryptedData( |
| 563 | framer_.transport_version(), destination_connection_id_length, |
| 564 | source_connection_id_length, includes_version, |
| 565 | includes_diversification_nonce, PACKET_4BYTE_PACKET_NUMBER, |
| 566 | retry_token_length_length, retry_token_length, length_length))); |
| 567 | if (ciphertext != decrypter_->ciphertext_) { |
| 568 | QUIC_LOG(ERROR) << "Decrypted incorrect ciphertext data. expected " |
| 569 | << QuicTextUtils::HexEncode(ciphertext) << " actual: " |
| 570 | << QuicTextUtils::HexEncode(decrypter_->ciphertext_) |
| 571 | << " associated data: " |
| 572 | << QuicTextUtils::HexEncode(associated_data); |
| 573 | return false; |
| 574 | } |
| 575 | return true; |
| 576 | } |
| 577 | |
| 578 | char* AsChars(unsigned char* data) { return reinterpret_cast<char*>(data); } |
| 579 | |
| 580 | // Creates a new QuicEncryptedPacket by concatenating the various |
| 581 | // packet fragments in |fragments|. |
| 582 | std::unique_ptr<QuicEncryptedPacket> AssemblePacketFromFragments( |
| 583 | const PacketFragments& fragments) { |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 584 | char* buffer = new char[kMaxOutgoingPacketSize + 1]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 585 | size_t len = 0; |
| 586 | for (const auto& fragment : fragments) { |
| 587 | memcpy(buffer + len, fragment.fragment.data(), fragment.fragment.size()); |
| 588 | len += fragment.fragment.size(); |
| 589 | } |
| 590 | return QuicMakeUnique<QuicEncryptedPacket>(buffer, len, true); |
| 591 | } |
| 592 | |
| 593 | void CheckFramingBoundaries(const PacketFragments& fragments, |
| 594 | QuicErrorCode error_code) { |
| 595 | std::unique_ptr<QuicEncryptedPacket> packet( |
| 596 | AssemblePacketFromFragments(fragments)); |
| 597 | // Check all the various prefixes of |packet| for the expected |
| 598 | // parse error and error code. |
| 599 | for (size_t i = 0; i < packet->length(); ++i) { |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 600 | std::string expected_error; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 601 | size_t len = 0; |
| 602 | for (const auto& fragment : fragments) { |
| 603 | len += fragment.fragment.size(); |
| 604 | if (i < len) { |
| 605 | expected_error = fragment.error_if_missing; |
| 606 | break; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | if (expected_error.empty()) |
| 611 | continue; |
| 612 | |
| 613 | CheckProcessingFails(*packet, i, expected_error, error_code); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | void CheckProcessingFails(const QuicEncryptedPacket& packet, |
| 618 | size_t len, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 619 | std::string expected_error, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 620 | QuicErrorCode error_code) { |
| 621 | QuicEncryptedPacket encrypted(packet.data(), len, false); |
| 622 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; |
| 623 | EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; |
| 624 | EXPECT_EQ(error_code, framer_.error()) << "len: " << len; |
| 625 | } |
| 626 | |
| 627 | void CheckProcessingFails(unsigned char* packet, |
| 628 | size_t len, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 629 | std::string expected_error, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 630 | QuicErrorCode error_code) { |
| 631 | QuicEncryptedPacket encrypted(AsChars(packet), len, false); |
| 632 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; |
| 633 | EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; |
| 634 | EXPECT_EQ(error_code, framer_.error()) << "len: " << len; |
| 635 | } |
| 636 | |
| 637 | // Checks if the supplied string matches data in the supplied StreamFrame. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 638 | void CheckStreamFrameData(std::string str, QuicStreamFrame* frame) { |
| 639 | EXPECT_EQ(str, std::string(frame->data_buffer, frame->data_length)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | void CheckCalculatePacketNumber(uint64_t expected_packet_number, |
| 643 | QuicPacketNumber last_packet_number) { |
| 644 | uint64_t wire_packet_number = expected_packet_number & kMask; |
| 645 | EXPECT_EQ(expected_packet_number, |
| 646 | QuicFramerPeer::CalculatePacketNumberFromWire( |
| 647 | &framer_, PACKET_4BYTE_PACKET_NUMBER, last_packet_number, |
| 648 | wire_packet_number)) |
| 649 | << "last_packet_number: " << last_packet_number |
| 650 | << " wire_packet_number: " << wire_packet_number; |
| 651 | } |
| 652 | |
| 653 | std::unique_ptr<QuicPacket> BuildDataPacket(const QuicPacketHeader& header, |
| 654 | const QuicFrames& frames) { |
| 655 | return BuildUnsizedDataPacket(&framer_, header, frames); |
| 656 | } |
| 657 | |
| 658 | std::unique_ptr<QuicPacket> BuildDataPacket(const QuicPacketHeader& header, |
| 659 | const QuicFrames& frames, |
| 660 | size_t packet_size) { |
| 661 | return BuildUnsizedDataPacket(&framer_, header, frames, packet_size); |
| 662 | } |
| 663 | |
| 664 | // N starts at 1. |
| 665 | QuicStreamId GetNthStreamid(QuicTransportVersion transport_version, |
| 666 | Perspective perspective, |
| 667 | bool bidirectional, |
| 668 | int n) { |
| 669 | if (bidirectional) { |
| 670 | return QuicUtils::GetFirstBidirectionalStreamId(transport_version, |
| 671 | perspective) + |
| 672 | ((n - 1) * QuicUtils::StreamIdDelta(transport_version)); |
| 673 | } |
| 674 | // Unidirectional |
| 675 | return QuicUtils::GetFirstUnidirectionalStreamId(transport_version, |
| 676 | perspective) + |
| 677 | ((n - 1) * QuicUtils::StreamIdDelta(transport_version)); |
| 678 | } |
| 679 | |
| 680 | test::TestEncrypter* encrypter_; |
| 681 | test::TestDecrypter* decrypter_; |
| 682 | ParsedQuicVersion version_; |
| 683 | QuicTime start_; |
| 684 | QuicFramer framer_; |
| 685 | test::TestQuicVisitor visitor_; |
| 686 | SimpleBufferAllocator allocator_; |
| 687 | }; |
| 688 | |
| 689 | // Multiple test cases of QuicFramerTest use byte arrays to define packets for |
| 690 | // testing, and these byte arrays contain the QUIC version. This macro explodes |
| 691 | // the 32-bit version into four bytes in network order. Since it uses methods of |
| 692 | // QuicFramerTest, it is only valid to use this in a QuicFramerTest. |
| 693 | #define QUIC_VERSION_BYTES \ |
| 694 | GetQuicVersionProtocolByte(), '0', GetQuicVersionDigitTens(), \ |
| 695 | GetQuicVersionDigitOnes() |
| 696 | |
| 697 | // Run all framer tests with all supported versions of QUIC. |
nharper | f5e6845 | 2019-05-29 17:24:18 -0700 | [diff] [blame] | 698 | INSTANTIATE_TEST_SUITE_P(QuicFramerTests, |
| 699 | QuicFramerTest, |
| 700 | ::testing::ValuesIn(AllSupportedVersions())); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 701 | |
| 702 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochStart) { |
| 703 | // A few quick manual sanity checks. |
| 704 | CheckCalculatePacketNumber(UINT64_C(1), QuicPacketNumber()); |
| 705 | CheckCalculatePacketNumber(kEpoch + 1, QuicPacketNumber(kMask)); |
| 706 | CheckCalculatePacketNumber(kEpoch, QuicPacketNumber(kMask)); |
| 707 | for (uint64_t j = 0; j < 10; j++) { |
| 708 | CheckCalculatePacketNumber(j, QuicPacketNumber()); |
| 709 | CheckCalculatePacketNumber(kEpoch - 1 - j, QuicPacketNumber()); |
| 710 | } |
| 711 | |
| 712 | // Cases where the last number was close to the start of the range. |
| 713 | for (QuicPacketNumber last = QuicPacketNumber(1); last < QuicPacketNumber(10); |
| 714 | last++) { |
| 715 | // Small numbers should not wrap (even if they're out of order). |
| 716 | for (uint64_t j = 0; j < 10; j++) { |
| 717 | CheckCalculatePacketNumber(j, last); |
| 718 | } |
| 719 | |
| 720 | // Large numbers should not wrap either (because we're near 0 already). |
| 721 | for (uint64_t j = 0; j < 10; j++) { |
| 722 | CheckCalculatePacketNumber(kEpoch - 1 - j, last); |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochEnd) { |
| 728 | // Cases where the last number was close to the end of the range |
| 729 | for (uint64_t i = 0; i < 10; i++) { |
| 730 | QuicPacketNumber last = QuicPacketNumber(kEpoch - i); |
| 731 | |
| 732 | // Small numbers should wrap. |
| 733 | for (uint64_t j = 0; j < 10; j++) { |
| 734 | CheckCalculatePacketNumber(kEpoch + j, last); |
| 735 | } |
| 736 | |
| 737 | // Large numbers should not (even if they're out of order). |
| 738 | for (uint64_t j = 0; j < 10; j++) { |
| 739 | CheckCalculatePacketNumber(kEpoch - 1 - j, last); |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | // Next check where we're in a non-zero epoch to verify we handle |
| 745 | // reverse wrapping, too. |
| 746 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearPrevEpoch) { |
| 747 | const uint64_t prev_epoch = 1 * kEpoch; |
| 748 | const uint64_t cur_epoch = 2 * kEpoch; |
| 749 | // Cases where the last number was close to the start of the range |
| 750 | for (uint64_t i = 0; i < 10; i++) { |
| 751 | QuicPacketNumber last = QuicPacketNumber(cur_epoch + i); |
| 752 | // Small number should not wrap (even if they're out of order). |
| 753 | for (uint64_t j = 0; j < 10; j++) { |
| 754 | CheckCalculatePacketNumber(cur_epoch + j, last); |
| 755 | } |
| 756 | |
| 757 | // But large numbers should reverse wrap. |
| 758 | for (uint64_t j = 0; j < 10; j++) { |
| 759 | uint64_t num = kEpoch - 1 - j; |
| 760 | CheckCalculatePacketNumber(prev_epoch + num, last); |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextEpoch) { |
| 766 | const uint64_t cur_epoch = 2 * kEpoch; |
| 767 | const uint64_t next_epoch = 3 * kEpoch; |
| 768 | // Cases where the last number was close to the end of the range |
| 769 | for (uint64_t i = 0; i < 10; i++) { |
| 770 | QuicPacketNumber last = QuicPacketNumber(next_epoch - 1 - i); |
| 771 | |
| 772 | // Small numbers should wrap. |
| 773 | for (uint64_t j = 0; j < 10; j++) { |
| 774 | CheckCalculatePacketNumber(next_epoch + j, last); |
| 775 | } |
| 776 | |
| 777 | // but large numbers should not (even if they're out of order). |
| 778 | for (uint64_t j = 0; j < 10; j++) { |
| 779 | uint64_t num = kEpoch - 1 - j; |
| 780 | CheckCalculatePacketNumber(cur_epoch + num, last); |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextMax) { |
| 786 | const uint64_t max_number = std::numeric_limits<uint64_t>::max(); |
| 787 | const uint64_t max_epoch = max_number & ~kMask; |
| 788 | |
| 789 | // Cases where the last number was close to the end of the range |
| 790 | for (uint64_t i = 0; i < 10; i++) { |
| 791 | // Subtract 1, because the expected next packet number is 1 more than the |
| 792 | // last packet number. |
| 793 | QuicPacketNumber last = QuicPacketNumber(max_number - i - 1); |
| 794 | |
| 795 | // Small numbers should not wrap, because they have nowhere to go. |
| 796 | for (uint64_t j = 0; j < 10; j++) { |
| 797 | CheckCalculatePacketNumber(max_epoch + j, last); |
| 798 | } |
| 799 | |
| 800 | // Large numbers should not wrap either. |
| 801 | for (uint64_t j = 0; j < 10; j++) { |
| 802 | uint64_t num = kEpoch - 1 - j; |
| 803 | CheckCalculatePacketNumber(max_epoch + num, last); |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | TEST_P(QuicFramerTest, EmptyPacket) { |
| 809 | char packet[] = {0x00}; |
| 810 | QuicEncryptedPacket encrypted(packet, 0, false); |
| 811 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 812 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
| 813 | } |
| 814 | |
| 815 | TEST_P(QuicFramerTest, LargePacket) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 816 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 817 | // clang-format off |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 818 | unsigned char packet[kMaxIncomingPacketSize + 1] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 819 | // public flags (8 byte connection_id) |
| 820 | 0x28, |
| 821 | // connection_id |
| 822 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 823 | // packet number |
| 824 | 0x78, 0x56, 0x34, 0x12, |
| 825 | // private flags |
| 826 | 0x00, |
| 827 | }; |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 828 | unsigned char packet46[kMaxIncomingPacketSize + 1] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 829 | // type (short header 4 byte packet number) |
| 830 | 0x43, |
| 831 | // connection_id |
| 832 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 833 | // packet number |
| 834 | 0x78, 0x56, 0x34, 0x12, |
| 835 | }; |
| 836 | // clang-format on |
| 837 | unsigned char* p = packet; |
| 838 | size_t p_size = QUIC_ARRAYSIZE(packet); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 839 | if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 840 | p = packet46; |
| 841 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | const size_t header_size = GetPacketHeaderSize( |
| 845 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 846 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 847 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 848 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 849 | |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 850 | memset(p + header_size, 0, kMaxIncomingPacketSize - header_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 851 | |
| 852 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 853 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 854 | |
| 855 | ASSERT_TRUE(visitor_.header_.get()); |
| 856 | // Make sure we've parsed the packet header, so we can send an error. |
| 857 | EXPECT_EQ(FramerTestConnectionId(), |
| 858 | visitor_.header_->destination_connection_id); |
| 859 | // Make sure the correct error is propagated. |
| 860 | EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error()); |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 861 | EXPECT_EQ("Packet too large.", framer_.detailed_error()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | TEST_P(QuicFramerTest, PacketHeader) { |
| 865 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | // clang-format off |
| 870 | PacketFragments packet = { |
| 871 | // public flags (8 byte connection_id) |
| 872 | {"Unable to read public flags.", |
| 873 | {0x28}}, |
| 874 | // connection_id |
| 875 | {"Unable to read ConnectionId.", |
| 876 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 877 | // packet number |
| 878 | {"Unable to read packet number.", |
| 879 | {0x12, 0x34, 0x56, 0x78}}, |
| 880 | }; |
| 881 | // clang-format on |
| 882 | |
| 883 | PacketFragments& fragments = packet; |
| 884 | |
| 885 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 886 | AssemblePacketFromFragments(fragments)); |
| 887 | |
| 888 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 889 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 890 | ASSERT_TRUE(visitor_.header_.get()); |
| 891 | EXPECT_EQ(FramerTestConnectionId(), |
| 892 | visitor_.header_->destination_connection_id); |
| 893 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 894 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 895 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 896 | |
| 897 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 898 | |
| 899 | PacketHeaderFormat format; |
| 900 | bool version_flag; |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 901 | QuicConnectionId destination_connection_id, source_connection_id; |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 902 | QuicVersionLabel version_label; |
| 903 | std::string detailed_error; |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 904 | EXPECT_EQ(QUIC_NO_ERROR, |
| 905 | QuicFramer::ProcessPacketDispatcher( |
| 906 | *encrypted, kQuicDefaultConnectionIdLength, &format, |
| 907 | &version_flag, &version_label, &destination_connection_id, |
| 908 | &source_connection_id, &detailed_error)); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 909 | EXPECT_EQ(GOOGLE_QUIC_PACKET, format); |
| 910 | EXPECT_FALSE(version_flag); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 911 | EXPECT_EQ(kQuicDefaultConnectionIdLength, destination_connection_id.length()); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 912 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 913 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | TEST_P(QuicFramerTest, LongPacketHeader) { |
| 917 | // clang-format off |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 918 | PacketFragments packet46 = { |
| 919 | // type (long header with packet type INITIAL) |
| 920 | {"Unable to read type.", |
| 921 | {0xC3}}, |
| 922 | // version tag |
| 923 | {"Unable to read protocol version.", |
| 924 | {QUIC_VERSION_BYTES}}, |
| 925 | // connection_id length |
| 926 | {"Unable to read ConnectionId length.", |
| 927 | {0x50}}, |
| 928 | // connection_id |
| 929 | {"Unable to read Destination ConnectionId.", |
| 930 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 931 | // packet number |
| 932 | {"Unable to read packet number.", |
| 933 | {0x12, 0x34, 0x56, 0x78}}, |
| 934 | }; |
| 935 | // clang-format on |
| 936 | |
| 937 | if (framer_.transport_version() <= QUIC_VERSION_43 || |
| 938 | QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 939 | return; |
| 940 | } |
| 941 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 942 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 943 | AssemblePacketFromFragments(packet46)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 944 | |
| 945 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 946 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 947 | ASSERT_TRUE(visitor_.header_.get()); |
| 948 | EXPECT_EQ(FramerTestConnectionId(), |
| 949 | visitor_.header_->destination_connection_id); |
| 950 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 951 | EXPECT_TRUE(visitor_.header_->version_flag); |
| 952 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 953 | |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 954 | CheckFramingBoundaries(packet46, QUIC_INVALID_PACKET_HEADER); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 955 | |
| 956 | PacketHeaderFormat format; |
| 957 | bool version_flag; |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 958 | QuicConnectionId destination_connection_id, source_connection_id; |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 959 | QuicVersionLabel version_label; |
| 960 | std::string detailed_error; |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 961 | EXPECT_EQ(QUIC_NO_ERROR, |
| 962 | QuicFramer::ProcessPacketDispatcher( |
| 963 | *encrypted, kQuicDefaultConnectionIdLength, &format, |
| 964 | &version_flag, &version_label, &destination_connection_id, |
| 965 | &source_connection_id, &detailed_error)); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 966 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 967 | EXPECT_TRUE(version_flag); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 968 | EXPECT_EQ(kQuicDefaultConnectionIdLength, destination_connection_id.length()); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 969 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 970 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
| 971 | } |
| 972 | |
| 973 | TEST_P(QuicFramerTest, LongPacketHeaderWithBothConnectionIds) { |
| 974 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 975 | // This test requires an IETF long header. |
| 976 | return; |
| 977 | } |
| 978 | SetQuicRestartFlag(quic_do_not_override_connection_id, true); |
| 979 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 980 | // clang-format off |
| 981 | unsigned char packet[] = { |
| 982 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 983 | // 4-byte packet number) |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 984 | 0xD3, |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 985 | // version |
| 986 | QUIC_VERSION_BYTES, |
| 987 | // connection ID lengths |
| 988 | 0x55, |
| 989 | // destination connection ID |
| 990 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 991 | // source connection ID |
| 992 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 993 | // long header packet length |
| 994 | 0x05, |
| 995 | // packet number |
| 996 | 0x12, 0x34, 0x56, 0x00, |
| 997 | // padding frame |
| 998 | 0x00, |
| 999 | }; |
| 1000 | // clang-format on |
| 1001 | |
| 1002 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 1003 | PacketHeaderFormat format = GOOGLE_QUIC_PACKET; |
| 1004 | bool version_flag = false; |
| 1005 | QuicConnectionId destination_connection_id, source_connection_id; |
| 1006 | QuicVersionLabel version_label = 0; |
| 1007 | std::string detailed_error = ""; |
| 1008 | EXPECT_EQ(QUIC_NO_ERROR, |
| 1009 | QuicFramer::ProcessPacketDispatcher( |
| 1010 | encrypted, kQuicDefaultConnectionIdLength, &format, |
| 1011 | &version_flag, &version_label, &destination_connection_id, |
| 1012 | &source_connection_id, &detailed_error)); |
| 1013 | EXPECT_EQ("", detailed_error); |
| 1014 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 1015 | EXPECT_TRUE(version_flag); |
| 1016 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
| 1017 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), source_connection_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1021 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
dschinazi | 7b9278c | 2019-05-20 07:36:21 -0700 | [diff] [blame] | 1022 | QuicFramerPeer::SetLastSerializedServerConnectionId(&framer_, |
| 1023 | FramerTestConnectionId()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1024 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1025 | |
| 1026 | // clang-format off |
| 1027 | PacketFragments packet = { |
| 1028 | // public flags (0 byte connection_id) |
| 1029 | {"Unable to read public flags.", |
| 1030 | {0x20}}, |
| 1031 | // connection_id |
| 1032 | // packet number |
| 1033 | {"Unable to read packet number.", |
| 1034 | {0x12, 0x34, 0x56, 0x78}}, |
| 1035 | }; |
| 1036 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1037 | PacketFragments packet46 = { |
| 1038 | // type (short header, 4 byte packet number) |
| 1039 | {"Unable to read type.", |
| 1040 | {0x43}}, |
| 1041 | // connection_id |
| 1042 | // packet number |
| 1043 | {"Unable to read packet number.", |
| 1044 | {0x12, 0x34, 0x56, 0x78}}, |
| 1045 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1046 | |
| 1047 | PacketFragments packet_hp = { |
| 1048 | // type (short header, 4 byte packet number) |
| 1049 | {"Unable to read type.", |
| 1050 | {0x43}}, |
| 1051 | // connection_id |
| 1052 | // packet number |
| 1053 | {"", |
| 1054 | {0x12, 0x34, 0x56, 0x78}}, |
| 1055 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1056 | // clang-format on |
| 1057 | |
| 1058 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1059 | framer_.version().HasHeaderProtection() |
| 1060 | ? packet_hp |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 1061 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1062 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1063 | AssemblePacketFromFragments(fragments)); |
| 1064 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1065 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1066 | ASSERT_TRUE(visitor_.header_.get()); |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 1067 | if (!GetQuicRestartFlag(quic_do_not_override_connection_id)) { |
| 1068 | EXPECT_EQ(FramerTestConnectionId(), |
| 1069 | visitor_.header_->destination_connection_id); |
| 1070 | } else { |
| 1071 | EXPECT_EQ(FramerTestConnectionId(), visitor_.header_->source_connection_id); |
| 1072 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1073 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1074 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1075 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1076 | |
| 1077 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1078 | } |
| 1079 | |
| 1080 | TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1081 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1082 | // clang-format off |
| 1083 | PacketFragments packet = { |
| 1084 | // public flags (0 byte connection_id) |
| 1085 | {"Unable to read public flags.", |
| 1086 | {0x29}}, |
| 1087 | // connection_id |
| 1088 | {"Unable to read ConnectionId.", |
| 1089 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1090 | // version tag |
| 1091 | {"Unable to read protocol version.", |
| 1092 | {QUIC_VERSION_BYTES}}, |
| 1093 | // packet number |
| 1094 | {"Unable to read packet number.", |
| 1095 | {0x12, 0x34, 0x56, 0x78}}, |
| 1096 | }; |
| 1097 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1098 | PacketFragments packet46 = { |
| 1099 | // type (long header with packet type ZERO_RTT_PROTECTED and 4 bytes |
| 1100 | // packet number) |
| 1101 | {"Unable to read type.", |
| 1102 | {0xD3}}, |
| 1103 | // version tag |
| 1104 | {"Unable to read protocol version.", |
| 1105 | {QUIC_VERSION_BYTES}}, |
| 1106 | // connection_id length |
| 1107 | {"Unable to read ConnectionId length.", |
| 1108 | {0x50}}, |
| 1109 | // connection_id |
| 1110 | {"Unable to read Destination ConnectionId.", |
| 1111 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1112 | // packet number |
| 1113 | {"Unable to read packet number.", |
| 1114 | {0x12, 0x34, 0x56, 0x78}}, |
| 1115 | }; |
| 1116 | |
| 1117 | PacketFragments packet99 = { |
| 1118 | // type (long header with packet type ZERO_RTT_PROTECTED and 4 bytes |
| 1119 | // packet number) |
| 1120 | {"Unable to read type.", |
| 1121 | {0xD3}}, |
| 1122 | // version tag |
| 1123 | {"Unable to read protocol version.", |
| 1124 | {QUIC_VERSION_BYTES}}, |
| 1125 | // connection_id length |
| 1126 | {"Unable to read ConnectionId length.", |
| 1127 | {0x50}}, |
| 1128 | // connection_id |
| 1129 | {"Unable to read Destination ConnectionId.", |
| 1130 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1131 | // long header packet length |
| 1132 | {"Unable to read long header payload length.", |
| 1133 | {0x04}}, |
| 1134 | // packet number |
| 1135 | {"Long header payload length longer than packet.", |
| 1136 | {0x12, 0x34, 0x56, 0x78}}, |
| 1137 | }; |
| 1138 | // clang-format on |
| 1139 | |
| 1140 | PacketFragments& fragments = |
| 1141 | framer_.transport_version() == QUIC_VERSION_99 |
| 1142 | ? packet99 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 1143 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1144 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1145 | AssemblePacketFromFragments(fragments)); |
| 1146 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1147 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1148 | ASSERT_TRUE(visitor_.header_.get()); |
| 1149 | EXPECT_EQ(FramerTestConnectionId(), |
| 1150 | visitor_.header_->destination_connection_id); |
| 1151 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1152 | EXPECT_TRUE(visitor_.header_->version_flag); |
| 1153 | EXPECT_EQ(GetParam(), visitor_.header_->version); |
| 1154 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1155 | |
| 1156 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1157 | } |
| 1158 | |
| 1159 | TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1160 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1161 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1162 | |
| 1163 | // clang-format off |
| 1164 | PacketFragments packet = { |
| 1165 | // public flags (8 byte connection_id and 4 byte packet number) |
| 1166 | {"Unable to read public flags.", |
| 1167 | {0x28}}, |
| 1168 | // connection_id |
| 1169 | {"Unable to read ConnectionId.", |
| 1170 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1171 | // packet number |
| 1172 | {"Unable to read packet number.", |
| 1173 | {0x12, 0x34, 0x56, 0x78}}, |
| 1174 | }; |
| 1175 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1176 | PacketFragments packet46 = { |
| 1177 | // type (short header, 4 byte packet number) |
| 1178 | {"Unable to read type.", |
| 1179 | {0x43}}, |
| 1180 | // connection_id |
| 1181 | {"Unable to read Destination ConnectionId.", |
| 1182 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1183 | // packet number |
| 1184 | {"Unable to read packet number.", |
| 1185 | {0x12, 0x34, 0x56, 0x78}}, |
| 1186 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1187 | |
| 1188 | PacketFragments packet_hp = { |
| 1189 | // type (short header, 4 byte packet number) |
| 1190 | {"Unable to read type.", |
| 1191 | {0x43}}, |
| 1192 | // connection_id |
| 1193 | {"Unable to read Destination ConnectionId.", |
| 1194 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1195 | // packet number |
| 1196 | {"", |
| 1197 | {0x12, 0x34, 0x56, 0x78}}, |
| 1198 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1199 | // clang-format on |
| 1200 | |
| 1201 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1202 | framer_.version().HasHeaderProtection() |
| 1203 | ? packet_hp |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 1204 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1205 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1206 | AssemblePacketFromFragments(fragments)); |
| 1207 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1208 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1209 | ASSERT_TRUE(visitor_.header_.get()); |
| 1210 | EXPECT_EQ(FramerTestConnectionId(), |
| 1211 | visitor_.header_->destination_connection_id); |
| 1212 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1213 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1214 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1215 | |
| 1216 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1217 | } |
| 1218 | |
| 1219 | TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1220 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1221 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1222 | |
| 1223 | // clang-format off |
| 1224 | PacketFragments packet = { |
| 1225 | // public flags (8 byte connection_id and 2 byte packet number) |
| 1226 | {"Unable to read public flags.", |
| 1227 | {0x18}}, |
| 1228 | // connection_id |
| 1229 | {"Unable to read ConnectionId.", |
| 1230 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1231 | // packet number |
| 1232 | {"Unable to read packet number.", |
| 1233 | {0x56, 0x78}}, |
| 1234 | }; |
| 1235 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1236 | PacketFragments packet46 = { |
| 1237 | // type (short header, 2 byte packet number) |
| 1238 | {"Unable to read type.", |
| 1239 | {0x41}}, |
| 1240 | // connection_id |
| 1241 | {"Unable to read Destination ConnectionId.", |
| 1242 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1243 | // packet number |
| 1244 | {"Unable to read packet number.", |
| 1245 | {0x56, 0x78}}, |
| 1246 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1247 | |
| 1248 | PacketFragments packet_hp = { |
| 1249 | // type (short header, 2 byte packet number) |
| 1250 | {"Unable to read type.", |
| 1251 | {0x41}}, |
| 1252 | // connection_id |
| 1253 | {"Unable to read Destination ConnectionId.", |
| 1254 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1255 | // packet number |
| 1256 | {"", |
| 1257 | {0x56, 0x78}}, |
| 1258 | // padding |
| 1259 | {"", {0x00, 0x00}}, |
| 1260 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1261 | // clang-format on |
| 1262 | |
| 1263 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1264 | framer_.version().HasHeaderProtection() |
| 1265 | ? packet_hp |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 1266 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1267 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1268 | AssemblePacketFromFragments(fragments)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1269 | if (framer_.version().HasHeaderProtection()) { |
| 1270 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 1271 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1272 | } else { |
| 1273 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1274 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1275 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1276 | ASSERT_TRUE(visitor_.header_.get()); |
| 1277 | EXPECT_EQ(FramerTestConnectionId(), |
| 1278 | visitor_.header_->destination_connection_id); |
| 1279 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1280 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1281 | EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1282 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1283 | |
| 1284 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1285 | } |
| 1286 | |
| 1287 | TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1288 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1289 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1290 | |
| 1291 | // clang-format off |
| 1292 | PacketFragments packet = { |
| 1293 | // public flags (8 byte connection_id and 1 byte packet number) |
| 1294 | {"Unable to read public flags.", |
| 1295 | {0x08}}, |
| 1296 | // connection_id |
| 1297 | {"Unable to read ConnectionId.", |
| 1298 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1299 | // packet number |
| 1300 | {"Unable to read packet number.", |
| 1301 | {0x78}}, |
| 1302 | }; |
| 1303 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1304 | PacketFragments packet46 = { |
| 1305 | // type (8 byte connection_id and 1 byte packet number) |
| 1306 | {"Unable to read type.", |
| 1307 | {0x40}}, |
| 1308 | // connection_id |
| 1309 | {"Unable to read Destination ConnectionId.", |
| 1310 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1311 | // packet number |
| 1312 | {"Unable to read packet number.", |
| 1313 | {0x78}}, |
| 1314 | }; |
| 1315 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1316 | PacketFragments packet_hp = { |
| 1317 | // type (8 byte connection_id and 1 byte packet number) |
| 1318 | {"Unable to read type.", |
| 1319 | {0x40}}, |
| 1320 | // connection_id |
| 1321 | {"Unable to read Destination ConnectionId.", |
| 1322 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1323 | // packet number |
| 1324 | {"", |
| 1325 | {0x78}}, |
| 1326 | // padding |
| 1327 | {"", {0x00, 0x00, 0x00}}, |
| 1328 | }; |
| 1329 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1330 | // clang-format on |
| 1331 | |
| 1332 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1333 | framer_.version().HasHeaderProtection() |
| 1334 | ? packet_hp |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 1335 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1336 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1337 | AssemblePacketFromFragments(fragments)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1338 | if (framer_.version().HasHeaderProtection()) { |
| 1339 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 1340 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1341 | } else { |
| 1342 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1343 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1344 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1345 | ASSERT_TRUE(visitor_.header_.get()); |
| 1346 | EXPECT_EQ(FramerTestConnectionId(), |
| 1347 | visitor_.header_->destination_connection_id); |
| 1348 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1349 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1350 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1351 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1352 | |
| 1353 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1354 | } |
| 1355 | |
| 1356 | TEST_P(QuicFramerTest, PacketNumberDecreasesThenIncreases) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1357 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1358 | // Test the case when a packet is received from the past and future packet |
| 1359 | // numbers are still calculated relative to the largest received packet. |
| 1360 | QuicPacketHeader header; |
| 1361 | header.destination_connection_id = FramerTestConnectionId(); |
| 1362 | header.reset_flag = false; |
| 1363 | header.version_flag = false; |
| 1364 | header.packet_number = kPacketNumber - 2; |
| 1365 | |
| 1366 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 1367 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1368 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 1369 | ASSERT_TRUE(data != nullptr); |
| 1370 | |
| 1371 | QuicEncryptedPacket encrypted(data->data(), data->length(), false); |
| 1372 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1373 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1374 | ASSERT_TRUE(visitor_.header_.get()); |
| 1375 | EXPECT_EQ(FramerTestConnectionId(), |
| 1376 | visitor_.header_->destination_connection_id); |
| 1377 | EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1378 | EXPECT_EQ(kPacketNumber - 2, visitor_.header_->packet_number); |
| 1379 | |
| 1380 | // Receive a 1 byte packet number. |
| 1381 | header.packet_number = kPacketNumber; |
| 1382 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 1383 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1384 | data = BuildDataPacket(header, frames); |
| 1385 | QuicEncryptedPacket encrypted1(data->data(), data->length(), false); |
| 1386 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1387 | EXPECT_TRUE(framer_.ProcessPacket(encrypted1)); |
| 1388 | ASSERT_TRUE(visitor_.header_.get()); |
| 1389 | EXPECT_EQ(FramerTestConnectionId(), |
| 1390 | visitor_.header_->destination_connection_id); |
| 1391 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1392 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1393 | |
| 1394 | // Process a 2 byte packet number 256 packets ago. |
| 1395 | header.packet_number = kPacketNumber - 256; |
| 1396 | header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; |
| 1397 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1398 | data = BuildDataPacket(header, frames); |
| 1399 | QuicEncryptedPacket encrypted2(data->data(), data->length(), false); |
| 1400 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1401 | EXPECT_TRUE(framer_.ProcessPacket(encrypted2)); |
| 1402 | ASSERT_TRUE(visitor_.header_.get()); |
| 1403 | EXPECT_EQ(FramerTestConnectionId(), |
| 1404 | visitor_.header_->destination_connection_id); |
| 1405 | EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1406 | EXPECT_EQ(kPacketNumber - 256, visitor_.header_->packet_number); |
| 1407 | |
| 1408 | // Process another 1 byte packet number and ensure it works. |
| 1409 | header.packet_number = kPacketNumber - 1; |
| 1410 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 1411 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1412 | data = BuildDataPacket(header, frames); |
| 1413 | QuicEncryptedPacket encrypted3(data->data(), data->length(), false); |
| 1414 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1415 | EXPECT_TRUE(framer_.ProcessPacket(encrypted3)); |
| 1416 | ASSERT_TRUE(visitor_.header_.get()); |
| 1417 | EXPECT_EQ(FramerTestConnectionId(), |
| 1418 | visitor_.header_->destination_connection_id); |
| 1419 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1420 | EXPECT_EQ(kPacketNumber - 1, visitor_.header_->packet_number); |
| 1421 | } |
| 1422 | |
| 1423 | TEST_P(QuicFramerTest, PacketWithDiversificationNonce) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1424 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1425 | // clang-format off |
| 1426 | unsigned char packet[] = { |
| 1427 | // public flags: includes nonce flag |
| 1428 | 0x2C, |
| 1429 | // connection_id |
| 1430 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1431 | // nonce |
| 1432 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1433 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1434 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1435 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1436 | // packet number |
| 1437 | 0x12, 0x34, 0x56, 0x78, |
| 1438 | |
| 1439 | // frame type (padding) |
| 1440 | 0x00, |
| 1441 | 0x00, 0x00, 0x00, 0x00 |
| 1442 | }; |
| 1443 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1444 | unsigned char packet46[] = { |
| 1445 | // type: Long header with packet type ZERO_RTT_PROTECTED and 1 byte packet |
| 1446 | // number. |
| 1447 | 0xD0, |
| 1448 | // version tag |
| 1449 | QUIC_VERSION_BYTES, |
| 1450 | // connection_id length |
| 1451 | 0x05, |
| 1452 | // connection_id |
| 1453 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1454 | // packet number |
| 1455 | 0x78, |
| 1456 | // nonce |
| 1457 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1458 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1459 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1460 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1461 | |
| 1462 | // frame type (padding) |
| 1463 | 0x00, |
| 1464 | 0x00, 0x00, 0x00, 0x00 |
| 1465 | }; |
| 1466 | |
| 1467 | unsigned char packet99[] = { |
| 1468 | // type: Long header with packet type ZERO_RTT_PROTECTED and 1 byte packet |
| 1469 | // number. |
| 1470 | 0xD0, |
| 1471 | // version tag |
| 1472 | QUIC_VERSION_BYTES, |
| 1473 | // connection_id length |
| 1474 | 0x05, |
| 1475 | // connection_id |
| 1476 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1477 | // long header packet length |
| 1478 | 0x26, |
| 1479 | // packet number |
| 1480 | 0x78, |
| 1481 | // nonce |
| 1482 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1483 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1484 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1485 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1486 | |
| 1487 | // frame type (padding) |
| 1488 | 0x00, |
| 1489 | 0x00, 0x00, 0x00, 0x00 |
| 1490 | }; |
| 1491 | // clang-format on |
| 1492 | |
| 1493 | if (framer_.version().handshake_protocol != PROTOCOL_QUIC_CRYPTO) { |
| 1494 | return; |
| 1495 | } |
| 1496 | |
| 1497 | unsigned char* p = packet; |
| 1498 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 1499 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 1500 | p = packet99; |
| 1501 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 1502 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1503 | p = packet46; |
| 1504 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 1508 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1509 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1510 | ASSERT_TRUE(visitor_.header_->nonce != nullptr); |
| 1511 | for (char i = 0; i < 32; ++i) { |
| 1512 | EXPECT_EQ(i, (*visitor_.header_->nonce)[static_cast<size_t>(i)]); |
| 1513 | } |
| 1514 | EXPECT_EQ(1u, visitor_.padding_frames_.size()); |
| 1515 | EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes); |
| 1516 | } |
| 1517 | |
| 1518 | TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) { |
| 1519 | // clang-format off |
| 1520 | unsigned char packet[] = { |
| 1521 | // public flags (8 byte connection_id, version flag and an unknown flag) |
| 1522 | 0x29, |
| 1523 | // connection_id |
| 1524 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1525 | // version tag |
| 1526 | 'Q', '0', '0', '0', |
| 1527 | // packet number |
| 1528 | 0x12, 0x34, 0x56, 0x78, |
| 1529 | |
| 1530 | // frame type (padding frame) |
| 1531 | 0x00, |
| 1532 | 0x00, 0x00, 0x00, 0x00 |
| 1533 | }; |
| 1534 | |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 1535 | unsigned char packet46[] = { |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1536 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 1537 | 0xD3, |
| 1538 | // version tag |
| 1539 | 'Q', '0', '0', '0', |
| 1540 | // connection_id length |
| 1541 | 0x50, |
| 1542 | // connection_id |
| 1543 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1544 | // packet number |
| 1545 | 0x12, 0x34, 0x56, 0x78, |
| 1546 | |
| 1547 | // frame type (padding frame) |
| 1548 | 0x00, |
| 1549 | 0x00, 0x00, 0x00, 0x00 |
| 1550 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1551 | // clang-format on |
| 1552 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1553 | unsigned char* p = packet; |
| 1554 | size_t p_size = QUIC_ARRAYSIZE(packet); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 1555 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 1556 | p = packet46; |
| 1557 | p_size = QUIC_ARRAYSIZE(packet46); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1558 | } |
| 1559 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1560 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1561 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1562 | ASSERT_TRUE(visitor_.header_.get()); |
| 1563 | EXPECT_EQ(0, visitor_.frame_count_); |
| 1564 | EXPECT_EQ(1, visitor_.version_mismatch_); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1565 | ASSERT_EQ(1u, visitor_.padding_frames_.size()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1566 | EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes); |
| 1567 | } |
| 1568 | |
| 1569 | TEST_P(QuicFramerTest, PaddingFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1570 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1571 | // clang-format off |
| 1572 | unsigned char packet[] = { |
| 1573 | // public flags (8 byte connection_id) |
| 1574 | 0x28, |
| 1575 | // connection_id |
| 1576 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1577 | // packet number |
| 1578 | 0x12, 0x34, 0x56, 0x78, |
| 1579 | |
| 1580 | // paddings |
| 1581 | 0x00, 0x00, |
| 1582 | // frame type (stream frame with fin) |
| 1583 | 0xFF, |
| 1584 | // stream id |
| 1585 | 0x01, 0x02, 0x03, 0x04, |
| 1586 | // offset |
| 1587 | 0x3A, 0x98, 0xFE, 0xDC, |
| 1588 | 0x32, 0x10, 0x76, 0x54, |
| 1589 | // data length |
| 1590 | 0x00, 0x0c, |
| 1591 | // data |
| 1592 | 'h', 'e', 'l', 'l', |
| 1593 | 'o', ' ', 'w', 'o', |
| 1594 | 'r', 'l', 'd', '!', |
| 1595 | // paddings |
| 1596 | 0x00, 0x00, |
| 1597 | }; |
| 1598 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1599 | unsigned char packet46[] = { |
| 1600 | // type (short header, 4 byte packet number) |
| 1601 | 0x43, |
| 1602 | // connection_id |
| 1603 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1604 | // packet number |
| 1605 | 0x12, 0x34, 0x56, 0x78, |
| 1606 | |
| 1607 | // paddings |
| 1608 | 0x00, 0x00, |
| 1609 | // frame type (stream frame with fin) |
| 1610 | 0xFF, |
| 1611 | // stream id |
| 1612 | 0x01, 0x02, 0x03, 0x04, |
| 1613 | // offset |
| 1614 | 0x3A, 0x98, 0xFE, 0xDC, |
| 1615 | 0x32, 0x10, 0x76, 0x54, |
| 1616 | // data length |
| 1617 | 0x00, 0x0c, |
| 1618 | // data |
| 1619 | 'h', 'e', 'l', 'l', |
| 1620 | 'o', ' ', 'w', 'o', |
| 1621 | 'r', 'l', 'd', '!', |
| 1622 | // paddings |
| 1623 | 0x00, 0x00, |
| 1624 | }; |
| 1625 | |
| 1626 | unsigned char packet99[] = { |
| 1627 | // type (short header, 4 byte packet number) |
| 1628 | 0x43, |
| 1629 | // connection_id |
| 1630 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1631 | // packet number |
| 1632 | 0x12, 0x34, 0x56, 0x78, |
| 1633 | |
| 1634 | // paddings |
| 1635 | 0x00, 0x00, |
| 1636 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 1637 | 0x08 | 0x01 | 0x02 | 0x04, |
| 1638 | |
| 1639 | // stream id |
| 1640 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 1641 | // offset |
| 1642 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 1643 | 0x32, 0x10, 0x76, 0x54, |
| 1644 | // data length |
| 1645 | kVarInt62OneByte + 0x0c, |
| 1646 | // data |
| 1647 | 'h', 'e', 'l', 'l', |
| 1648 | 'o', ' ', 'w', 'o', |
| 1649 | 'r', 'l', 'd', '!', |
| 1650 | // paddings |
| 1651 | 0x00, 0x00, |
| 1652 | }; |
| 1653 | // clang-format on |
| 1654 | |
| 1655 | unsigned char* p = packet; |
| 1656 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 1657 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 1658 | p = packet99; |
| 1659 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 1660 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1661 | p = packet46; |
| 1662 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 1666 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1667 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1668 | ASSERT_TRUE(visitor_.header_.get()); |
| 1669 | EXPECT_TRUE(CheckDecryption( |
| 1670 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 1671 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 1672 | |
| 1673 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1674 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1675 | EXPECT_EQ(2u, visitor_.padding_frames_.size()); |
| 1676 | EXPECT_EQ(2, visitor_.padding_frames_[0]->num_padding_bytes); |
| 1677 | EXPECT_EQ(2, visitor_.padding_frames_[1]->num_padding_bytes); |
| 1678 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 1679 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1680 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 1681 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 1682 | } |
| 1683 | |
| 1684 | TEST_P(QuicFramerTest, StreamFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1685 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1686 | // clang-format off |
| 1687 | PacketFragments packet = { |
| 1688 | // public flags (8 byte connection_id) |
| 1689 | {"", |
| 1690 | {0x28}}, |
| 1691 | // connection_id |
| 1692 | {"", |
| 1693 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1694 | // packet number |
| 1695 | {"", |
| 1696 | {0x12, 0x34, 0x56, 0x78}}, |
| 1697 | // frame type (stream frame with fin) |
| 1698 | {"", |
| 1699 | {0xFF}}, |
| 1700 | // stream id |
| 1701 | {"Unable to read stream_id.", |
| 1702 | {0x01, 0x02, 0x03, 0x04}}, |
| 1703 | // offset |
| 1704 | {"Unable to read offset.", |
| 1705 | {0x3A, 0x98, 0xFE, 0xDC, |
| 1706 | 0x32, 0x10, 0x76, 0x54}}, |
| 1707 | {"Unable to read frame data.", |
| 1708 | { |
| 1709 | // data length |
| 1710 | 0x00, 0x0c, |
| 1711 | // data |
| 1712 | 'h', 'e', 'l', 'l', |
| 1713 | 'o', ' ', 'w', 'o', |
| 1714 | 'r', 'l', 'd', '!'}}, |
| 1715 | }; |
| 1716 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1717 | PacketFragments packet46 = { |
| 1718 | // type (short header, 4 byte packet number) |
| 1719 | {"", |
| 1720 | {0x43}}, |
| 1721 | // connection_id |
| 1722 | {"", |
| 1723 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1724 | // packet number |
| 1725 | {"", |
| 1726 | {0x12, 0x34, 0x56, 0x78}}, |
| 1727 | // frame type (stream frame with fin) |
| 1728 | {"", |
| 1729 | {0xFF}}, |
| 1730 | // stream id |
| 1731 | {"Unable to read stream_id.", |
| 1732 | {0x01, 0x02, 0x03, 0x04}}, |
| 1733 | // offset |
| 1734 | {"Unable to read offset.", |
| 1735 | {0x3A, 0x98, 0xFE, 0xDC, |
| 1736 | 0x32, 0x10, 0x76, 0x54}}, |
| 1737 | {"Unable to read frame data.", |
| 1738 | { |
| 1739 | // data length |
| 1740 | 0x00, 0x0c, |
| 1741 | // data |
| 1742 | 'h', 'e', 'l', 'l', |
| 1743 | 'o', ' ', 'w', 'o', |
| 1744 | 'r', 'l', 'd', '!'}}, |
| 1745 | }; |
| 1746 | |
| 1747 | PacketFragments packet99 = { |
| 1748 | // type (short header, 4 byte packet number) |
| 1749 | {"", |
| 1750 | {0x43}}, |
| 1751 | // connection_id |
| 1752 | {"", |
| 1753 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1754 | // packet number |
| 1755 | {"", |
| 1756 | {0x12, 0x34, 0x56, 0x78}}, |
| 1757 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 1758 | {"", |
| 1759 | { 0x08 | 0x01 | 0x02 | 0x04 }}, |
| 1760 | // stream id |
| 1761 | {"Unable to read stream_id.", |
| 1762 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 1763 | // offset |
| 1764 | {"Unable to read stream data offset.", |
| 1765 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 1766 | 0x32, 0x10, 0x76, 0x54}}, |
| 1767 | // data length |
| 1768 | {"Unable to read stream data length.", |
| 1769 | {kVarInt62OneByte + 0x0c}}, |
| 1770 | // data |
| 1771 | {"Unable to read frame data.", |
| 1772 | { 'h', 'e', 'l', 'l', |
| 1773 | 'o', ' ', 'w', 'o', |
| 1774 | 'r', 'l', 'd', '!'}}, |
| 1775 | }; |
| 1776 | // clang-format on |
| 1777 | |
| 1778 | PacketFragments& fragments = |
| 1779 | framer_.transport_version() == QUIC_VERSION_99 |
| 1780 | ? packet99 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 1781 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1782 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1783 | AssemblePacketFromFragments(fragments)); |
| 1784 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 1785 | |
| 1786 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1787 | ASSERT_TRUE(visitor_.header_.get()); |
| 1788 | EXPECT_TRUE(CheckDecryption( |
| 1789 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 1790 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 1791 | |
| 1792 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1793 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1794 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 1795 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1796 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 1797 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 1798 | |
| 1799 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 1800 | } |
| 1801 | |
| 1802 | // Test an empty (no data) stream frame. |
| 1803 | TEST_P(QuicFramerTest, EmptyStreamFrame) { |
| 1804 | // Only the IETF QUIC spec explicitly says that empty |
| 1805 | // stream frames are supported. |
| 1806 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 1807 | return; |
| 1808 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1809 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1810 | // clang-format off |
| 1811 | PacketFragments packet = { |
| 1812 | // type (short header, 4 byte packet number) |
| 1813 | {"", |
| 1814 | {0x43}}, |
| 1815 | // connection_id |
| 1816 | {"", |
| 1817 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1818 | // packet number |
| 1819 | {"", |
| 1820 | {0x12, 0x34, 0x56, 0x78}}, |
| 1821 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 1822 | {"", |
| 1823 | { 0x08 | 0x01 | 0x02 | 0x04 }}, |
| 1824 | // stream id |
| 1825 | {"Unable to read stream_id.", |
| 1826 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 1827 | // offset |
| 1828 | {"Unable to read stream data offset.", |
| 1829 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 1830 | 0x32, 0x10, 0x76, 0x54}}, |
| 1831 | // data length |
| 1832 | {"Unable to read stream data length.", |
| 1833 | {kVarInt62OneByte + 0x00}}, |
| 1834 | }; |
| 1835 | // clang-format on |
| 1836 | |
| 1837 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1838 | AssemblePacketFromFragments(packet)); |
| 1839 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 1840 | |
| 1841 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1842 | ASSERT_TRUE(visitor_.header_.get()); |
| 1843 | EXPECT_TRUE(CheckDecryption( |
| 1844 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 1845 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 1846 | |
| 1847 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1848 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1849 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 1850 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1851 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 1852 | EXPECT_EQ(visitor_.stream_frames_[0].get()->data_length, 0u); |
| 1853 | |
| 1854 | CheckFramingBoundaries(packet, QUIC_INVALID_STREAM_DATA); |
| 1855 | } |
| 1856 | |
| 1857 | TEST_P(QuicFramerTest, MissingDiversificationNonce) { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1858 | if (framer_.version().handshake_protocol != PROTOCOL_QUIC_CRYPTO) { |
| 1859 | // TLS does not use diversification nonces. |
| 1860 | return; |
| 1861 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1862 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1863 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1864 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 1865 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, QuicMakeUnique<NullDecrypter>( |
| 1866 | Perspective::IS_CLIENT)); |
| 1867 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 1868 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 1869 | } else { |
| 1870 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 1871 | QuicMakeUnique<NullDecrypter>(Perspective::IS_CLIENT)); |
| 1872 | framer_.SetAlternativeDecrypter( |
| 1873 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 1874 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1875 | |
| 1876 | // clang-format off |
| 1877 | unsigned char packet[] = { |
| 1878 | // public flags (8 byte connection_id) |
| 1879 | 0x28, |
| 1880 | // connection_id |
| 1881 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 1882 | // packet number |
| 1883 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1884 | // padding frame |
| 1885 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1886 | }; |
| 1887 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1888 | unsigned char packet46[] = { |
| 1889 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 1890 | 0xD3, |
| 1891 | // version tag |
| 1892 | QUIC_VERSION_BYTES, |
| 1893 | // connection_id length |
| 1894 | 0x05, |
| 1895 | // connection_id |
| 1896 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 1897 | // packet number |
| 1898 | 0x12, 0x34, 0x56, 0x78, |
| 1899 | // padding frame |
| 1900 | 0x00, |
| 1901 | }; |
| 1902 | |
| 1903 | unsigned char packet99[] = { |
| 1904 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 1905 | 0xD3, |
| 1906 | // version tag |
| 1907 | QUIC_VERSION_BYTES, |
| 1908 | // connection_id length |
| 1909 | 0x05, |
| 1910 | // connection_id |
| 1911 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 1912 | // IETF long header payload length |
| 1913 | 0x05, |
| 1914 | // packet number |
| 1915 | 0x12, 0x34, 0x56, 0x78, |
| 1916 | // padding frame |
| 1917 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1918 | }; |
| 1919 | // clang-format on |
| 1920 | |
| 1921 | unsigned char* p = packet; |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1922 | size_t p_length = QUIC_ARRAYSIZE(packet); |
| 1923 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 1924 | p = packet99; |
| 1925 | p_length = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 1926 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1927 | p = packet46; |
| 1928 | p_length = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1929 | } |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1930 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1931 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1932 | if (framer_.version().HasHeaderProtection()) { |
| 1933 | EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error()); |
| 1934 | EXPECT_EQ("Unable to decrypt header protection.", framer_.detailed_error()); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 1935 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1936 | // Cannot read diversification nonce. |
| 1937 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 1938 | EXPECT_EQ("Unable to read nonce.", framer_.detailed_error()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1939 | } else { |
| 1940 | EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error()); |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { |
| 1945 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 1946 | // This test is nonsensical for IETF Quic. |
| 1947 | return; |
| 1948 | } |
| 1949 | // clang-format off |
| 1950 | PacketFragments packet = { |
| 1951 | // public flags (8 byte connection_id) |
| 1952 | {"", |
| 1953 | {0x28}}, |
| 1954 | // connection_id |
| 1955 | {"", |
| 1956 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1957 | // packet number |
| 1958 | {"", |
| 1959 | {0x12, 0x34, 0x56, 0x78}}, |
| 1960 | // frame type (stream frame with fin) |
| 1961 | {"", |
| 1962 | {0xFE}}, |
| 1963 | // stream id |
| 1964 | {"Unable to read stream_id.", |
| 1965 | {0x02, 0x03, 0x04}}, |
| 1966 | // offset |
| 1967 | {"Unable to read offset.", |
| 1968 | {0x3A, 0x98, 0xFE, 0xDC, |
| 1969 | 0x32, 0x10, 0x76, 0x54}}, |
| 1970 | {"Unable to read frame data.", |
| 1971 | { |
| 1972 | // data length |
| 1973 | 0x00, 0x0c, |
| 1974 | // data |
| 1975 | 'h', 'e', 'l', 'l', |
| 1976 | 'o', ' ', 'w', 'o', |
| 1977 | 'r', 'l', 'd', '!'}}, |
| 1978 | }; |
| 1979 | // clang-format on |
| 1980 | |
| 1981 | PacketFragments& fragments = packet; |
| 1982 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1983 | AssemblePacketFromFragments(fragments)); |
| 1984 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 1985 | |
| 1986 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1987 | ASSERT_TRUE(visitor_.header_.get()); |
| 1988 | EXPECT_TRUE(CheckDecryption( |
| 1989 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 1990 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 1991 | |
| 1992 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1993 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1994 | // Stream ID should be the last 3 bytes of kStreamId. |
| 1995 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 1996 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1997 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 1998 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 1999 | |
| 2000 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2001 | } |
| 2002 | |
| 2003 | TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2004 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2005 | // clang-format off |
| 2006 | PacketFragments packet = { |
| 2007 | // public flags (8 byte connection_id) |
| 2008 | {"", |
| 2009 | {0x28}}, |
| 2010 | // connection_id |
| 2011 | {"", |
| 2012 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2013 | // packet number |
| 2014 | {"", |
| 2015 | {0x12, 0x34, 0x56, 0x78}}, |
| 2016 | // frame type (stream frame with fin) |
| 2017 | {"", |
| 2018 | {0xFD}}, |
| 2019 | // stream id |
| 2020 | {"Unable to read stream_id.", |
| 2021 | {0x03, 0x04}}, |
| 2022 | // offset |
| 2023 | {"Unable to read offset.", |
| 2024 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2025 | 0x32, 0x10, 0x76, 0x54}}, |
| 2026 | {"Unable to read frame data.", |
| 2027 | { |
| 2028 | // data length |
| 2029 | 0x00, 0x0c, |
| 2030 | // data |
| 2031 | 'h', 'e', 'l', 'l', |
| 2032 | 'o', ' ', 'w', 'o', |
| 2033 | 'r', 'l', 'd', '!'}}, |
| 2034 | }; |
| 2035 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2036 | PacketFragments packet46 = { |
| 2037 | // type (short header, 4 byte packet number) |
| 2038 | {"", |
| 2039 | {0x43}}, |
| 2040 | // connection_id |
| 2041 | {"", |
| 2042 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2043 | // packet number |
| 2044 | {"", |
| 2045 | {0x12, 0x34, 0x56, 0x78}}, |
| 2046 | // frame type (stream frame with fin) |
| 2047 | {"", |
| 2048 | {0xFD}}, |
| 2049 | // stream id |
| 2050 | {"Unable to read stream_id.", |
| 2051 | {0x03, 0x04}}, |
| 2052 | // offset |
| 2053 | {"Unable to read offset.", |
| 2054 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2055 | 0x32, 0x10, 0x76, 0x54}}, |
| 2056 | {"Unable to read frame data.", |
| 2057 | { |
| 2058 | // data length |
| 2059 | 0x00, 0x0c, |
| 2060 | // data |
| 2061 | 'h', 'e', 'l', 'l', |
| 2062 | 'o', ' ', 'w', 'o', |
| 2063 | 'r', 'l', 'd', '!'}}, |
| 2064 | }; |
| 2065 | |
| 2066 | PacketFragments packet99 = { |
| 2067 | // type (short header, 4 byte packet number) |
| 2068 | {"", |
| 2069 | {0x43}}, |
| 2070 | // connection_id |
| 2071 | {"", |
| 2072 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2073 | // packet number |
| 2074 | {"", |
| 2075 | {0x12, 0x34, 0x56, 0x78}}, |
| 2076 | // frame type (IETF_STREAM frame with LEN, FIN, and OFFSET bits set) |
| 2077 | {"", |
| 2078 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2079 | // stream id |
| 2080 | {"Unable to read stream_id.", |
| 2081 | {kVarInt62TwoBytes + 0x03, 0x04}}, |
| 2082 | // offset |
| 2083 | {"Unable to read stream data offset.", |
| 2084 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2085 | 0x32, 0x10, 0x76, 0x54}}, |
| 2086 | // data length |
| 2087 | {"Unable to read stream data length.", |
| 2088 | {kVarInt62OneByte + 0x0c}}, |
| 2089 | // data |
| 2090 | {"Unable to read frame data.", |
| 2091 | { 'h', 'e', 'l', 'l', |
| 2092 | 'o', ' ', 'w', 'o', |
| 2093 | 'r', 'l', 'd', '!'}}, |
| 2094 | }; |
| 2095 | // clang-format on |
| 2096 | |
| 2097 | PacketFragments& fragments = |
| 2098 | framer_.transport_version() == QUIC_VERSION_99 |
| 2099 | ? packet99 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 2100 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2101 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2102 | AssemblePacketFromFragments(fragments)); |
| 2103 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2104 | |
| 2105 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2106 | ASSERT_TRUE(visitor_.header_.get()); |
| 2107 | EXPECT_TRUE(CheckDecryption( |
| 2108 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2109 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2110 | |
| 2111 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2112 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2113 | // Stream ID should be the last 2 bytes of kStreamId. |
| 2114 | EXPECT_EQ(0x0000FFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2115 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2116 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2117 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2118 | |
| 2119 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2120 | } |
| 2121 | |
| 2122 | TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2123 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2124 | // clang-format off |
| 2125 | PacketFragments packet = { |
| 2126 | // public flags (8 byte connection_id) |
| 2127 | {"", |
| 2128 | {0x28}}, |
| 2129 | // connection_id |
| 2130 | {"", |
| 2131 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2132 | // packet number |
| 2133 | {"", |
| 2134 | {0x12, 0x34, 0x56, 0x78}}, |
| 2135 | // frame type (stream frame with fin) |
| 2136 | {"", |
| 2137 | {0xFC}}, |
| 2138 | // stream id |
| 2139 | {"Unable to read stream_id.", |
| 2140 | {0x04}}, |
| 2141 | // offset |
| 2142 | {"Unable to read offset.", |
| 2143 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2144 | 0x32, 0x10, 0x76, 0x54}}, |
| 2145 | {"Unable to read frame data.", |
| 2146 | { |
| 2147 | // data length |
| 2148 | 0x00, 0x0c, |
| 2149 | // data |
| 2150 | 'h', 'e', 'l', 'l', |
| 2151 | 'o', ' ', 'w', 'o', |
| 2152 | 'r', 'l', 'd', '!'}}, |
| 2153 | }; |
| 2154 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2155 | PacketFragments packet46 = { |
| 2156 | // type (short header, 4 byte packet number) |
| 2157 | {"", |
| 2158 | {0x43}}, |
| 2159 | // connection_id |
| 2160 | {"", |
| 2161 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2162 | // packet number |
| 2163 | {"", |
| 2164 | {0x12, 0x34, 0x56, 0x78}}, |
| 2165 | // frame type (stream frame with fin) |
| 2166 | {"", |
| 2167 | {0xFC}}, |
| 2168 | // stream id |
| 2169 | {"Unable to read stream_id.", |
| 2170 | {0x04}}, |
| 2171 | // offset |
| 2172 | {"Unable to read offset.", |
| 2173 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2174 | 0x32, 0x10, 0x76, 0x54}}, |
| 2175 | {"Unable to read frame data.", |
| 2176 | { |
| 2177 | // data length |
| 2178 | 0x00, 0x0c, |
| 2179 | // data |
| 2180 | 'h', 'e', 'l', 'l', |
| 2181 | 'o', ' ', 'w', 'o', |
| 2182 | 'r', 'l', 'd', '!'}}, |
| 2183 | }; |
| 2184 | |
| 2185 | PacketFragments packet99 = { |
| 2186 | // type (short header, 4 byte packet number) |
| 2187 | {"", |
| 2188 | {0x43}}, |
| 2189 | // connection_id |
| 2190 | {"", |
| 2191 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2192 | // packet number |
| 2193 | {"", |
| 2194 | {0x12, 0x34, 0x56, 0x78}}, |
| 2195 | // frame type (IETF_STREAM frame with LEN, FIN, and OFFSET bits set) |
| 2196 | {"", |
| 2197 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2198 | // stream id |
| 2199 | {"Unable to read stream_id.", |
| 2200 | {kVarInt62OneByte + 0x04}}, |
| 2201 | // offset |
| 2202 | {"Unable to read stream data offset.", |
| 2203 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2204 | 0x32, 0x10, 0x76, 0x54}}, |
| 2205 | // data length |
| 2206 | {"Unable to read stream data length.", |
| 2207 | {kVarInt62OneByte + 0x0c}}, |
| 2208 | // data |
| 2209 | {"Unable to read frame data.", |
| 2210 | { 'h', 'e', 'l', 'l', |
| 2211 | 'o', ' ', 'w', 'o', |
| 2212 | 'r', 'l', 'd', '!'}}, |
| 2213 | }; |
| 2214 | // clang-format on |
| 2215 | |
| 2216 | PacketFragments& fragments = |
| 2217 | framer_.transport_version() == QUIC_VERSION_99 |
| 2218 | ? packet99 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 2219 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2220 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2221 | AssemblePacketFromFragments(fragments)); |
| 2222 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2223 | |
| 2224 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2225 | ASSERT_TRUE(visitor_.header_.get()); |
| 2226 | EXPECT_TRUE(CheckDecryption( |
| 2227 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2228 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2229 | |
| 2230 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2231 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2232 | // Stream ID should be the last 1 byte of kStreamId. |
| 2233 | EXPECT_EQ(0x000000FF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2234 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2235 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2236 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2237 | |
| 2238 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2239 | } |
| 2240 | |
| 2241 | TEST_P(QuicFramerTest, StreamFrameWithVersion) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2242 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2243 | // clang-format off |
| 2244 | PacketFragments packet = { |
| 2245 | // public flags (version, 8 byte connection_id) |
| 2246 | {"", |
| 2247 | {0x29}}, |
| 2248 | // connection_id |
| 2249 | {"", |
| 2250 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2251 | // version tag |
| 2252 | {"", |
| 2253 | {QUIC_VERSION_BYTES}}, |
| 2254 | // packet number |
| 2255 | {"", |
| 2256 | {0x12, 0x34, 0x56, 0x78}}, |
| 2257 | // frame type (stream frame with fin) |
| 2258 | {"", |
| 2259 | {0xFE}}, |
| 2260 | // stream id |
| 2261 | {"Unable to read stream_id.", |
| 2262 | {0x02, 0x03, 0x04}}, |
| 2263 | // offset |
| 2264 | {"Unable to read offset.", |
| 2265 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2266 | 0x32, 0x10, 0x76, 0x54}}, |
| 2267 | {"Unable to read frame data.", |
| 2268 | { |
| 2269 | // data length |
| 2270 | 0x00, 0x0c, |
| 2271 | // data |
| 2272 | 'h', 'e', 'l', 'l', |
| 2273 | 'o', ' ', 'w', 'o', |
| 2274 | 'r', 'l', 'd', '!'}}, |
| 2275 | }; |
| 2276 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2277 | PacketFragments packet46 = { |
| 2278 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2279 | // 4-byte packet number) |
| 2280 | {"", |
| 2281 | {0xD3}}, |
| 2282 | // version tag |
| 2283 | {"", |
| 2284 | {QUIC_VERSION_BYTES}}, |
| 2285 | // connection_id length |
| 2286 | {"", |
| 2287 | {0x50}}, |
| 2288 | // connection_id |
| 2289 | {"", |
| 2290 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2291 | // packet number |
| 2292 | {"", |
| 2293 | {0x12, 0x34, 0x56, 0x78}}, |
| 2294 | // frame type (stream frame with fin) |
| 2295 | {"", |
| 2296 | {0xFE}}, |
| 2297 | // stream id |
| 2298 | {"Unable to read stream_id.", |
| 2299 | {0x02, 0x03, 0x04}}, |
| 2300 | // offset |
| 2301 | {"Unable to read offset.", |
| 2302 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2303 | 0x32, 0x10, 0x76, 0x54}}, |
| 2304 | {"Unable to read frame data.", |
| 2305 | { |
| 2306 | // data length |
| 2307 | 0x00, 0x0c, |
| 2308 | // data |
| 2309 | 'h', 'e', 'l', 'l', |
| 2310 | 'o', ' ', 'w', 'o', |
| 2311 | 'r', 'l', 'd', '!'}}, |
| 2312 | }; |
| 2313 | |
| 2314 | PacketFragments packet99 = { |
| 2315 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2316 | // 4-byte packet number) |
| 2317 | {"", |
| 2318 | {0xD3}}, |
| 2319 | // version tag |
| 2320 | {"", |
| 2321 | {QUIC_VERSION_BYTES}}, |
| 2322 | // connection_id length |
| 2323 | {"", |
| 2324 | {0x50}}, |
| 2325 | // connection_id |
| 2326 | {"", |
| 2327 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2328 | // long header packet length |
| 2329 | {"", |
| 2330 | {0x1E}}, |
| 2331 | // packet number |
| 2332 | {"", |
| 2333 | {0x12, 0x34, 0x56, 0x78}}, |
| 2334 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 2335 | {"", |
| 2336 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2337 | // stream id |
| 2338 | {"Long header payload length longer than packet.", |
| 2339 | {kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04}}, |
| 2340 | // offset |
| 2341 | {"Long header payload length longer than packet.", |
| 2342 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2343 | 0x32, 0x10, 0x76, 0x54}}, |
| 2344 | // data length |
| 2345 | {"Long header payload length longer than packet.", |
| 2346 | {kVarInt62OneByte + 0x0c}}, |
| 2347 | // data |
| 2348 | {"Long header payload length longer than packet.", |
| 2349 | { 'h', 'e', 'l', 'l', |
| 2350 | 'o', ' ', 'w', 'o', |
| 2351 | 'r', 'l', 'd', '!'}}, |
| 2352 | }; |
| 2353 | // clang-format on |
| 2354 | |
| 2355 | QuicVariableLengthIntegerLength retry_token_length_length = |
| 2356 | VARIABLE_LENGTH_INTEGER_LENGTH_0; |
| 2357 | size_t retry_token_length = 0; |
| 2358 | QuicVariableLengthIntegerLength length_length = |
| 2359 | QuicVersionHasLongHeaderLengths(framer_.transport_version()) |
| 2360 | ? VARIABLE_LENGTH_INTEGER_LENGTH_1 |
| 2361 | : VARIABLE_LENGTH_INTEGER_LENGTH_0; |
| 2362 | |
| 2363 | PacketFragments& fragments = |
| 2364 | framer_.transport_version() == QUIC_VERSION_99 |
| 2365 | ? packet99 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 2366 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2367 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2368 | AssemblePacketFromFragments(fragments)); |
| 2369 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2370 | |
| 2371 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2372 | ASSERT_TRUE(visitor_.header_.get()); |
| 2373 | EXPECT_TRUE(CheckDecryption( |
| 2374 | *encrypted, kIncludeVersion, !kIncludeDiversificationNonce, |
| 2375 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID, |
| 2376 | retry_token_length_length, retry_token_length, length_length)); |
| 2377 | |
| 2378 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2379 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2380 | // Stream ID should be the last 3 bytes of kStreamId. |
| 2381 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2382 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2383 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2384 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2385 | |
| 2386 | CheckFramingBoundaries(fragments, |
| 2387 | framer_.transport_version() == QUIC_VERSION_99 |
| 2388 | ? QUIC_INVALID_PACKET_HEADER |
| 2389 | : QUIC_INVALID_STREAM_DATA); |
| 2390 | } |
| 2391 | |
| 2392 | TEST_P(QuicFramerTest, RejectPacket) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2393 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2394 | visitor_.accept_packet_ = false; |
| 2395 | |
| 2396 | // clang-format off |
| 2397 | unsigned char packet[] = { |
| 2398 | // public flags (8 byte connection_id) |
| 2399 | 0x28, |
| 2400 | // connection_id |
| 2401 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2402 | // packet number |
| 2403 | 0x12, 0x34, 0x56, 0x78, |
| 2404 | |
| 2405 | // frame type (stream frame with fin) |
| 2406 | 0xFF, |
| 2407 | // stream id |
| 2408 | 0x01, 0x02, 0x03, 0x04, |
| 2409 | // offset |
| 2410 | 0x3A, 0x98, 0xFE, 0xDC, |
| 2411 | 0x32, 0x10, 0x76, 0x54, |
| 2412 | // data length |
| 2413 | 0x00, 0x0c, |
| 2414 | // data |
| 2415 | 'h', 'e', 'l', 'l', |
| 2416 | 'o', ' ', 'w', 'o', |
| 2417 | 'r', 'l', 'd', '!', |
| 2418 | }; |
| 2419 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2420 | unsigned char packet46[] = { |
| 2421 | // type (short header, 4 byte packet number) |
| 2422 | 0x43, |
| 2423 | // connection_id |
| 2424 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2425 | // packet number |
| 2426 | 0x12, 0x34, 0x56, 0x78, |
| 2427 | |
| 2428 | // frame type (STREAM Frame with FIN, LEN, and OFFSET bits set) |
| 2429 | 0x10 | 0x01 | 0x02 | 0x04, |
| 2430 | // stream id |
| 2431 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 2432 | // offset |
| 2433 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2434 | 0x32, 0x10, 0x76, 0x54, |
| 2435 | // data length |
| 2436 | kVarInt62OneByte + 0x0c, |
| 2437 | // data |
| 2438 | 'h', 'e', 'l', 'l', |
| 2439 | 'o', ' ', 'w', 'o', |
| 2440 | 'r', 'l', 'd', '!', |
| 2441 | }; |
| 2442 | // clang-format on |
| 2443 | |
| 2444 | unsigned char* p = packet; |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 2445 | if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2446 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2447 | } |
| 2448 | QuicEncryptedPacket encrypted(AsChars(p), |
| 2449 | framer_.transport_version() > QUIC_VERSION_43 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 2450 | ? QUIC_ARRAYSIZE(packet46) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2451 | : QUIC_ARRAYSIZE(packet), |
| 2452 | false); |
| 2453 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 2454 | |
| 2455 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2456 | ASSERT_TRUE(visitor_.header_.get()); |
| 2457 | EXPECT_TRUE(CheckDecryption( |
| 2458 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2459 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2460 | |
| 2461 | ASSERT_EQ(0u, visitor_.stream_frames_.size()); |
| 2462 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2463 | } |
| 2464 | |
| 2465 | TEST_P(QuicFramerTest, RejectPublicHeader) { |
| 2466 | visitor_.accept_public_header_ = false; |
| 2467 | |
| 2468 | // clang-format off |
| 2469 | unsigned char packet[] = { |
| 2470 | // public flags (8 byte connection_id) |
| 2471 | 0x28, |
| 2472 | // connection_id |
| 2473 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2474 | }; |
| 2475 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2476 | unsigned char packet46[] = { |
| 2477 | // type (short header, 1 byte packet number) |
| 2478 | 0x40, |
| 2479 | // connection_id |
| 2480 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2481 | // packet number |
| 2482 | 0x01, |
| 2483 | }; |
| 2484 | // clang-format on |
| 2485 | |
| 2486 | QuicEncryptedPacket encrypted( |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 2487 | framer_.transport_version() > QUIC_VERSION_43 ? AsChars(packet46) |
| 2488 | : AsChars(packet), |
| 2489 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet46) |
| 2490 | : QUIC_ARRAYSIZE(packet), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2491 | false); |
| 2492 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 2493 | |
| 2494 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2495 | ASSERT_TRUE(visitor_.header_.get()); |
| 2496 | EXPECT_FALSE(visitor_.header_->packet_number.IsInitialized()); |
| 2497 | } |
| 2498 | |
| 2499 | TEST_P(QuicFramerTest, AckFrameOneAckBlock) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2500 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2501 | // clang-format off |
| 2502 | PacketFragments packet = { |
| 2503 | // public flags (8 byte connection_id) |
| 2504 | {"", |
| 2505 | {0x2C}}, |
| 2506 | // connection_id |
| 2507 | {"", |
| 2508 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2509 | // packet number |
| 2510 | {"", |
| 2511 | {0x12, 0x34, 0x56, 0x78}}, |
| 2512 | // frame type (ack frame) |
| 2513 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2514 | {"", |
| 2515 | {0x45}}, |
| 2516 | // largest acked |
| 2517 | {"Unable to read largest acked.", |
| 2518 | {0x12, 0x34}}, |
| 2519 | // Zero delta time. |
| 2520 | {"Unable to read ack delay time.", |
| 2521 | {0x00, 0x00}}, |
| 2522 | // first ack block length. |
| 2523 | {"Unable to read first ack block length.", |
| 2524 | {0x12, 0x34}}, |
| 2525 | // num timestamps. |
| 2526 | {"Unable to read num received packets.", |
| 2527 | {0x00}} |
| 2528 | }; |
| 2529 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2530 | PacketFragments packet46 = { |
| 2531 | // type (short packet, 4 byte packet number) |
| 2532 | {"", |
| 2533 | {0x43}}, |
| 2534 | // connection_id |
| 2535 | {"", |
| 2536 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2537 | // packet number |
| 2538 | {"", |
| 2539 | {0x12, 0x34, 0x56, 0x78}}, |
| 2540 | // frame type (ack frame) |
| 2541 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2542 | {"", |
| 2543 | {0x45}}, |
| 2544 | // largest acked |
| 2545 | {"Unable to read largest acked.", |
| 2546 | {0x12, 0x34}}, |
| 2547 | // Zero delta time. |
| 2548 | {"Unable to read ack delay time.", |
| 2549 | {0x00, 0x00}}, |
| 2550 | // first ack block length. |
| 2551 | {"Unable to read first ack block length.", |
| 2552 | {0x12, 0x34}}, |
| 2553 | // num timestamps. |
| 2554 | {"Unable to read num received packets.", |
| 2555 | {0x00}} |
| 2556 | }; |
| 2557 | |
| 2558 | PacketFragments packet99 = { |
| 2559 | // type (short packet, 4 byte packet number) |
| 2560 | {"", |
| 2561 | {0x43}}, |
| 2562 | // connection_id |
| 2563 | {"", |
| 2564 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2565 | // packet number |
| 2566 | {"", |
| 2567 | {0x12, 0x34, 0x56, 0x78}}, |
| 2568 | // frame type (IETF_ACK) |
| 2569 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2570 | // IETF-Quic ignores the bit-fields in the ack type, all of |
| 2571 | // that information is encoded elsewhere in the frame. |
| 2572 | {"", |
| 2573 | {0x02}}, |
| 2574 | // largest acked |
| 2575 | {"Unable to read largest acked.", |
| 2576 | {kVarInt62TwoBytes + 0x12, 0x34}}, |
| 2577 | // Zero delta time. |
| 2578 | {"Unable to read ack delay time.", |
| 2579 | {kVarInt62OneByte + 0x00}}, |
| 2580 | // Ack block count (0 -- no blocks after the first) |
| 2581 | {"Unable to read ack block count.", |
| 2582 | {kVarInt62OneByte + 0x00}}, |
| 2583 | // first ack block length - 1. |
| 2584 | // IETF Quic defines the ack block's value as the "number of |
| 2585 | // packets that preceed the largest packet number in the block" |
| 2586 | // which for the 1st ack block is the largest acked field, |
| 2587 | // above. This means that if we are acking just packet 0x1234 |
| 2588 | // then the 1st ack block will be 0. |
| 2589 | {"Unable to read first ack block length.", |
| 2590 | {kVarInt62TwoBytes + 0x12, 0x33}} |
| 2591 | }; |
| 2592 | // clang-format on |
| 2593 | |
| 2594 | PacketFragments& fragments = |
| 2595 | framer_.transport_version() == QUIC_VERSION_99 |
| 2596 | ? packet99 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 2597 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2598 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2599 | AssemblePacketFromFragments(fragments)); |
| 2600 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2601 | |
| 2602 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2603 | ASSERT_TRUE(visitor_.header_.get()); |
| 2604 | EXPECT_TRUE(CheckDecryption( |
| 2605 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2606 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2607 | |
| 2608 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 2609 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 2610 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 2611 | EXPECT_EQ(kSmallLargestObserved, LargestAcked(frame)); |
| 2612 | ASSERT_EQ(4660u, frame.packets.NumPacketsSlow()); |
| 2613 | |
| 2614 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 2615 | } |
| 2616 | |
| 2617 | // This test checks that the ack frame processor correctly identifies |
| 2618 | // and handles the case where the first ack block is larger than the |
| 2619 | // largest_acked packet. |
| 2620 | TEST_P(QuicFramerTest, FirstAckFrameUnderflow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2621 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2622 | // clang-format off |
| 2623 | PacketFragments packet = { |
| 2624 | // public flags (8 byte connection_id) |
| 2625 | {"", |
| 2626 | {0x2C}}, |
| 2627 | // connection_id |
| 2628 | {"", |
| 2629 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2630 | // packet number |
| 2631 | {"", |
| 2632 | {0x12, 0x34, 0x56, 0x78}}, |
| 2633 | // frame type (ack frame) |
| 2634 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2635 | {"", |
| 2636 | {0x45}}, |
| 2637 | // largest acked |
| 2638 | {"Unable to read largest acked.", |
| 2639 | {0x12, 0x34}}, |
| 2640 | // Zero delta time. |
| 2641 | {"Unable to read ack delay time.", |
| 2642 | {0x00, 0x00}}, |
| 2643 | // first ack block length. |
| 2644 | {"Unable to read first ack block length.", |
| 2645 | {0x88, 0x88}}, |
| 2646 | // num timestamps. |
| 2647 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 2648 | {0x00}} |
| 2649 | }; |
| 2650 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2651 | PacketFragments packet46 = { |
| 2652 | // type (short header, 4 byte packet number) |
| 2653 | {"", |
| 2654 | {0x43}}, |
| 2655 | // connection_id |
| 2656 | {"", |
| 2657 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2658 | // packet number |
| 2659 | {"", |
| 2660 | {0x12, 0x34, 0x56, 0x78}}, |
| 2661 | // frame type (ack frame) |
| 2662 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2663 | {"", |
| 2664 | {0x45}}, |
| 2665 | // largest acked |
| 2666 | {"Unable to read largest acked.", |
| 2667 | {0x12, 0x34}}, |
| 2668 | // Zero delta time. |
| 2669 | {"Unable to read ack delay time.", |
| 2670 | {0x00, 0x00}}, |
| 2671 | // first ack block length. |
| 2672 | {"Unable to read first ack block length.", |
| 2673 | {0x88, 0x88}}, |
| 2674 | // num timestamps. |
| 2675 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 2676 | {0x00}} |
| 2677 | }; |
| 2678 | |
| 2679 | PacketFragments packet99 = { |
| 2680 | // type (short header, 4 byte packet number) |
| 2681 | {"", |
| 2682 | {0x43}}, |
| 2683 | // connection_id |
| 2684 | {"", |
| 2685 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2686 | // packet number |
| 2687 | {"", |
| 2688 | {0x12, 0x34, 0x56, 0x78}}, |
| 2689 | // frame type (IETF_ACK) |
| 2690 | {"", |
| 2691 | {0x02}}, |
| 2692 | // largest acked |
| 2693 | {"Unable to read largest acked.", |
| 2694 | {kVarInt62TwoBytes + 0x12, 0x34}}, |
| 2695 | // Zero delta time. |
| 2696 | {"Unable to read ack delay time.", |
| 2697 | {kVarInt62OneByte + 0x00}}, |
| 2698 | // Ack block count (0 -- no blocks after the first) |
| 2699 | {"Unable to read ack block count.", |
| 2700 | {kVarInt62OneByte + 0x00}}, |
| 2701 | // first ack block length. |
| 2702 | {"Unable to read first ack block length.", |
| 2703 | {kVarInt62TwoBytes + 0x28, 0x88}} |
| 2704 | }; |
| 2705 | // clang-format on |
| 2706 | |
| 2707 | PacketFragments& fragments = |
| 2708 | framer_.transport_version() == QUIC_VERSION_99 |
| 2709 | ? packet99 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 2710 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2711 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2712 | AssemblePacketFromFragments(fragments)); |
| 2713 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 2714 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 2715 | } |
| 2716 | |
| 2717 | // This test checks that the ack frame processor correctly identifies |
| 2718 | // and handles the case where the third ack block's gap is larger than the |
| 2719 | // available space in the ack range. |
| 2720 | TEST_P(QuicFramerTest, ThirdAckBlockUnderflowGap) { |
| 2721 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 2722 | // for now, only v99 |
| 2723 | return; |
| 2724 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2725 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2726 | // clang-format off |
| 2727 | PacketFragments packet99 = { |
| 2728 | // type (short header, 4 byte packet number) |
| 2729 | {"", |
| 2730 | {0x43}}, |
| 2731 | // connection_id |
| 2732 | {"", |
| 2733 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2734 | // packet number |
| 2735 | {"", |
| 2736 | {0x12, 0x34, 0x56, 0x78}}, |
| 2737 | // frame type (IETF_ACK frame) |
| 2738 | {"", |
| 2739 | {0x02}}, |
| 2740 | // largest acked |
| 2741 | {"Unable to read largest acked.", |
| 2742 | {kVarInt62OneByte + 63}}, |
| 2743 | // Zero delta time. |
| 2744 | {"Unable to read ack delay time.", |
| 2745 | {kVarInt62OneByte + 0x00}}, |
| 2746 | // Ack block count (2 -- 2 blocks after the first) |
| 2747 | {"Unable to read ack block count.", |
| 2748 | {kVarInt62OneByte + 0x02}}, |
| 2749 | // first ack block length. |
| 2750 | {"Unable to read first ack block length.", |
| 2751 | {kVarInt62OneByte + 13}}, // Ack 14 packets, range 50..63 (inclusive) |
| 2752 | |
| 2753 | {"Unable to read gap block value.", |
| 2754 | {kVarInt62OneByte + 9}}, // Gap 10 packets, 40..49 (inclusive) |
| 2755 | {"Unable to read ack block value.", |
| 2756 | {kVarInt62OneByte + 9}}, // Ack 10 packets, 30..39 (inclusive) |
| 2757 | {"Unable to read gap block value.", |
| 2758 | {kVarInt62OneByte + 29}}, // A gap of 30 packets (0..29 inclusive) |
| 2759 | // should be too big, leaving no room |
| 2760 | // for the ack. |
| 2761 | {"Underflow with gap block length 30 previous ack block start is 30.", |
| 2762 | {kVarInt62OneByte + 10}}, // Don't care |
| 2763 | }; |
| 2764 | // clang-format on |
| 2765 | |
| 2766 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2767 | AssemblePacketFromFragments(packet99)); |
| 2768 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 2769 | EXPECT_EQ( |
| 2770 | framer_.detailed_error(), |
| 2771 | "Underflow with gap block length 30 previous ack block start is 30."); |
| 2772 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 2773 | } |
| 2774 | |
| 2775 | // This test checks that the ack frame processor correctly identifies |
| 2776 | // and handles the case where the third ack block's length is larger than the |
| 2777 | // available space in the ack range. |
| 2778 | TEST_P(QuicFramerTest, ThirdAckBlockUnderflowAck) { |
| 2779 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 2780 | // for now, only v99 |
| 2781 | return; |
| 2782 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2783 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2784 | // clang-format off |
| 2785 | PacketFragments packet99 = { |
| 2786 | // type (short header, 4 byte packet number) |
| 2787 | {"", |
| 2788 | {0x43}}, |
| 2789 | // connection_id |
| 2790 | {"", |
| 2791 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2792 | // packet number |
| 2793 | {"", |
| 2794 | {0x12, 0x34, 0x56, 0x78}}, |
| 2795 | // frame type (IETF_ACK frame) |
| 2796 | {"", |
| 2797 | {0x02}}, |
| 2798 | // largest acked |
| 2799 | {"Unable to read largest acked.", |
| 2800 | {kVarInt62OneByte + 63}}, |
| 2801 | // Zero delta time. |
| 2802 | {"Unable to read ack delay time.", |
| 2803 | {kVarInt62OneByte + 0x00}}, |
| 2804 | // Ack block count (2 -- 2 blocks after the first) |
| 2805 | {"Unable to read ack block count.", |
| 2806 | {kVarInt62OneByte + 0x02}}, |
| 2807 | // first ack block length. |
| 2808 | {"Unable to read first ack block length.", |
| 2809 | {kVarInt62OneByte + 13}}, // only 50 packet numbers "left" |
| 2810 | |
| 2811 | {"Unable to read gap block value.", |
| 2812 | {kVarInt62OneByte + 10}}, // Only 40 packet numbers left |
| 2813 | {"Unable to read ack block value.", |
| 2814 | {kVarInt62OneByte + 10}}, // only 30 packet numbers left. |
| 2815 | {"Unable to read gap block value.", |
| 2816 | {kVarInt62OneByte + 1}}, // Gap is OK, 29 packet numbers left |
| 2817 | {"Unable to read ack block value.", |
| 2818 | {kVarInt62OneByte + 30}}, // Use up all 30, should be an error |
| 2819 | }; |
| 2820 | // clang-format on |
| 2821 | |
| 2822 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2823 | AssemblePacketFromFragments(packet99)); |
| 2824 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 2825 | EXPECT_EQ(framer_.detailed_error(), |
| 2826 | "Underflow with ack block length 31 latest ack block end is 25."); |
| 2827 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 2828 | } |
| 2829 | |
| 2830 | // Tests a variety of ack block wrap scenarios. For example, if the |
| 2831 | // N-1th block causes packet 0 to be acked, then a gap would wrap |
| 2832 | // around to 0x3fffffff ffffffff... Make sure we detect this |
| 2833 | // condition. |
| 2834 | TEST_P(QuicFramerTest, AckBlockUnderflowGapWrap) { |
| 2835 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 2836 | // for now, only v99 |
| 2837 | return; |
| 2838 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2839 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2840 | // clang-format off |
| 2841 | PacketFragments packet99 = { |
| 2842 | // type (short header, 4 byte packet number) |
| 2843 | {"", |
| 2844 | {0x43}}, |
| 2845 | // connection_id |
| 2846 | {"", |
| 2847 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2848 | // packet number |
| 2849 | {"", |
| 2850 | {0x12, 0x34, 0x56, 0x78}}, |
| 2851 | // frame type (IETF_ACK frame) |
| 2852 | {"", |
| 2853 | {0x02}}, |
| 2854 | // largest acked |
| 2855 | {"Unable to read largest acked.", |
| 2856 | {kVarInt62OneByte + 10}}, |
| 2857 | // Zero delta time. |
| 2858 | {"Unable to read ack delay time.", |
| 2859 | {kVarInt62OneByte + 0x00}}, |
| 2860 | // Ack block count (1 -- 1 blocks after the first) |
| 2861 | {"Unable to read ack block count.", |
| 2862 | {kVarInt62OneByte + 1}}, |
| 2863 | // first ack block length. |
| 2864 | {"Unable to read first ack block length.", |
| 2865 | {kVarInt62OneByte + 9}}, // Ack packets 1..10 (inclusive) |
| 2866 | |
| 2867 | {"Unable to read gap block value.", |
| 2868 | {kVarInt62OneByte + 1}}, // Gap of 2 packets (-1...0), should wrap |
| 2869 | {"Underflow with gap block length 2 previous ack block start is 1.", |
| 2870 | {kVarInt62OneByte + 9}}, // irrelevant |
| 2871 | }; |
| 2872 | // clang-format on |
| 2873 | |
| 2874 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2875 | AssemblePacketFromFragments(packet99)); |
| 2876 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 2877 | EXPECT_EQ(framer_.detailed_error(), |
| 2878 | "Underflow with gap block length 2 previous ack block start is 1."); |
| 2879 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 2880 | } |
| 2881 | |
| 2882 | // As AckBlockUnderflowGapWrap, but in this test, it's the ack |
| 2883 | // component of the ack-block that causes the wrap, not the gap. |
| 2884 | TEST_P(QuicFramerTest, AckBlockUnderflowAckWrap) { |
| 2885 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 2886 | // for now, only v99 |
| 2887 | return; |
| 2888 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2889 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2890 | // clang-format off |
| 2891 | PacketFragments packet99 = { |
| 2892 | // type (short header, 4 byte packet number) |
| 2893 | {"", |
| 2894 | {0x43}}, |
| 2895 | // connection_id |
| 2896 | {"", |
| 2897 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2898 | // packet number |
| 2899 | {"", |
| 2900 | {0x12, 0x34, 0x56, 0x78}}, |
| 2901 | // frame type (IETF_ACK frame) |
| 2902 | {"", |
| 2903 | {0x02}}, |
| 2904 | // largest acked |
| 2905 | {"Unable to read largest acked.", |
| 2906 | {kVarInt62OneByte + 10}}, |
| 2907 | // Zero delta time. |
| 2908 | {"Unable to read ack delay time.", |
| 2909 | {kVarInt62OneByte + 0x00}}, |
| 2910 | // Ack block count (1 -- 1 blocks after the first) |
| 2911 | {"Unable to read ack block count.", |
| 2912 | {kVarInt62OneByte + 1}}, |
| 2913 | // first ack block length. |
| 2914 | {"Unable to read first ack block length.", |
| 2915 | {kVarInt62OneByte + 6}}, // Ack packets 4..10 (inclusive) |
| 2916 | |
| 2917 | {"Unable to read gap block value.", |
| 2918 | {kVarInt62OneByte + 1}}, // Gap of 2 packets (2..3) |
| 2919 | {"Unable to read ack block value.", |
| 2920 | {kVarInt62OneByte + 9}}, // Should wrap. |
| 2921 | }; |
| 2922 | // clang-format on |
| 2923 | |
| 2924 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2925 | AssemblePacketFromFragments(packet99)); |
| 2926 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 2927 | EXPECT_EQ(framer_.detailed_error(), |
| 2928 | "Underflow with ack block length 10 latest ack block end is 1."); |
| 2929 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 2930 | } |
| 2931 | |
| 2932 | // An ack block that acks the entire range, 1...0x3fffffffffffffff |
| 2933 | TEST_P(QuicFramerTest, AckBlockAcksEverything) { |
| 2934 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 2935 | // for now, only v99 |
| 2936 | return; |
| 2937 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2938 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2939 | // clang-format off |
| 2940 | PacketFragments packet99 = { |
| 2941 | // type (short header, 4 byte packet number) |
| 2942 | {"", |
| 2943 | {0x43}}, |
| 2944 | // connection_id |
| 2945 | {"", |
| 2946 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2947 | // packet number |
| 2948 | {"", |
| 2949 | {0x12, 0x34, 0x56, 0x78}}, |
| 2950 | // frame type (IETF_ACK frame) |
| 2951 | {"", |
| 2952 | {0x02}}, |
| 2953 | // largest acked |
| 2954 | {"Unable to read largest acked.", |
| 2955 | {kVarInt62EightBytes + 0x3f, 0xff, 0xff, 0xff, |
| 2956 | 0xff, 0xff, 0xff, 0xff}}, |
| 2957 | // Zero delta time. |
| 2958 | {"Unable to read ack delay time.", |
| 2959 | {kVarInt62OneByte + 0x00}}, |
| 2960 | // Ack block count No additional blocks |
| 2961 | {"Unable to read ack block count.", |
| 2962 | {kVarInt62OneByte + 0}}, |
| 2963 | // first ack block length. |
| 2964 | {"Unable to read first ack block length.", |
| 2965 | {kVarInt62EightBytes + 0x3f, 0xff, 0xff, 0xff, |
| 2966 | 0xff, 0xff, 0xff, 0xfe}}, |
| 2967 | }; |
| 2968 | // clang-format on |
| 2969 | |
| 2970 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2971 | AssemblePacketFromFragments(packet99)); |
| 2972 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2973 | EXPECT_EQ(1u, visitor_.ack_frames_.size()); |
| 2974 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 2975 | EXPECT_EQ(1u, frame.packets.NumIntervals()); |
| 2976 | EXPECT_EQ(kLargestIetfLargestObserved, LargestAcked(frame)); |
| 2977 | EXPECT_EQ(kLargestIetfLargestObserved.ToUint64(), |
| 2978 | frame.packets.NumPacketsSlow()); |
| 2979 | } |
| 2980 | |
| 2981 | // This test looks for a malformed ack where |
| 2982 | // - There is a largest-acked value (that is, the frame is acking |
| 2983 | // something, |
| 2984 | // - But the length of the first ack block is 0 saying that no frames |
| 2985 | // are being acked with the largest-acked value or there are no |
| 2986 | // additional ack blocks. |
| 2987 | // |
| 2988 | TEST_P(QuicFramerTest, AckFrameFirstAckBlockLengthZero) { |
| 2989 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 2990 | // Not applicable to version 99 -- first ack block contains the |
| 2991 | // number of packets that preceed the largest_acked packet. |
| 2992 | // A value of 0 means no packets preceed --- that the block's |
| 2993 | // length is 1. Therefore the condition that this test checks can |
| 2994 | // not arise. |
| 2995 | return; |
| 2996 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 2997 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2998 | |
| 2999 | // clang-format off |
| 3000 | PacketFragments packet = { |
| 3001 | // public flags (8 byte connection_id) |
| 3002 | {"", |
| 3003 | { 0x2C }}, |
| 3004 | // connection_id |
| 3005 | {"", |
| 3006 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3007 | // packet number |
| 3008 | {"", |
| 3009 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3010 | |
| 3011 | // frame type (ack frame) |
| 3012 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3013 | {"", |
| 3014 | { 0x65 }}, |
| 3015 | // largest acked |
| 3016 | {"Unable to read largest acked.", |
| 3017 | { 0x12, 0x34 }}, |
| 3018 | // Zero delta time. |
| 3019 | {"Unable to read ack delay time.", |
| 3020 | { 0x00, 0x00 }}, |
| 3021 | // num ack blocks ranges. |
| 3022 | {"Unable to read num of ack blocks.", |
| 3023 | { 0x01 }}, |
| 3024 | // first ack block length. |
| 3025 | {"Unable to read first ack block length.", |
| 3026 | { 0x00, 0x00 }}, |
| 3027 | // gap to next block. |
| 3028 | { "First block length is zero.", |
| 3029 | { 0x01 }}, |
| 3030 | // ack block length. |
| 3031 | { "First block length is zero.", |
| 3032 | { 0x0e, 0xaf }}, |
| 3033 | // Number of timestamps. |
| 3034 | { "First block length is zero.", |
| 3035 | { 0x00 }}, |
| 3036 | }; |
| 3037 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3038 | PacketFragments packet46 = { |
| 3039 | // type (short header, 4 byte packet number) |
| 3040 | {"", |
| 3041 | { 0x43 }}, |
| 3042 | // connection_id |
| 3043 | {"", |
| 3044 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3045 | // packet number |
| 3046 | {"", |
| 3047 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3048 | |
| 3049 | // frame type (ack frame) |
| 3050 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3051 | {"", |
| 3052 | { 0x65 }}, |
| 3053 | // largest acked |
| 3054 | {"Unable to read largest acked.", |
| 3055 | { 0x12, 0x34 }}, |
| 3056 | // Zero delta time. |
| 3057 | {"Unable to read ack delay time.", |
| 3058 | { 0x00, 0x00 }}, |
| 3059 | // num ack blocks ranges. |
| 3060 | {"Unable to read num of ack blocks.", |
| 3061 | { 0x01 }}, |
| 3062 | // first ack block length. |
| 3063 | {"Unable to read first ack block length.", |
| 3064 | { 0x00, 0x00 }}, |
| 3065 | // gap to next block. |
| 3066 | { "First block length is zero.", |
| 3067 | { 0x01 }}, |
| 3068 | // ack block length. |
| 3069 | { "First block length is zero.", |
| 3070 | { 0x0e, 0xaf }}, |
| 3071 | // Number of timestamps. |
| 3072 | { "First block length is zero.", |
| 3073 | { 0x00 }}, |
| 3074 | }; |
| 3075 | |
| 3076 | // clang-format on |
| 3077 | PacketFragments& fragments = |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 3078 | framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3079 | |
| 3080 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3081 | AssemblePacketFromFragments(fragments)); |
| 3082 | |
| 3083 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3084 | EXPECT_EQ(QUIC_INVALID_ACK_DATA, framer_.error()); |
| 3085 | |
| 3086 | ASSERT_TRUE(visitor_.header_.get()); |
| 3087 | EXPECT_TRUE(CheckDecryption( |
| 3088 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3089 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3090 | |
| 3091 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3092 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3093 | |
| 3094 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3095 | } |
| 3096 | |
| 3097 | TEST_P(QuicFramerTest, AckFrameOneAckBlockMaxLength) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3098 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3099 | // clang-format off |
| 3100 | PacketFragments packet = { |
| 3101 | // public flags (8 byte connection_id) |
| 3102 | {"", |
| 3103 | {0x2C}}, |
| 3104 | // connection_id |
| 3105 | {"", |
| 3106 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3107 | // packet number |
| 3108 | {"", |
| 3109 | {0x12, 0x34, 0x56, 0x78}}, |
| 3110 | // frame type (ack frame) |
| 3111 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3112 | {"", |
| 3113 | {0x49}}, |
| 3114 | // largest acked |
| 3115 | {"Unable to read largest acked.", |
| 3116 | {0x12, 0x34, 0x56, 0x78}}, |
| 3117 | // Zero delta time. |
| 3118 | {"Unable to read ack delay time.", |
| 3119 | {0x00, 0x00}}, |
| 3120 | // first ack block length. |
| 3121 | {"Unable to read first ack block length.", |
| 3122 | {0x12, 0x34}}, |
| 3123 | // num timestamps. |
| 3124 | {"Unable to read num received packets.", |
| 3125 | {0x00}} |
| 3126 | }; |
| 3127 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3128 | PacketFragments packet46 = { |
| 3129 | // type (short header, 4 byte packet number) |
| 3130 | {"", |
| 3131 | {0x43}}, |
| 3132 | // connection_id |
| 3133 | {"", |
| 3134 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3135 | // packet number |
| 3136 | {"", |
| 3137 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3138 | // frame type (ack frame) |
| 3139 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3140 | {"", |
| 3141 | {0x49}}, |
| 3142 | // largest acked |
| 3143 | {"Unable to read largest acked.", |
| 3144 | {0x12, 0x34, 0x56, 0x78}}, |
| 3145 | // Zero delta time. |
| 3146 | {"Unable to read ack delay time.", |
| 3147 | {0x00, 0x00}}, |
| 3148 | // first ack block length. |
| 3149 | {"Unable to read first ack block length.", |
| 3150 | {0x12, 0x34}}, |
| 3151 | // num timestamps. |
| 3152 | {"Unable to read num received packets.", |
| 3153 | {0x00}} |
| 3154 | }; |
| 3155 | |
| 3156 | PacketFragments packet99 = { |
| 3157 | // type (short header, 4 byte packet number) |
| 3158 | {"", |
| 3159 | {0x43}}, |
| 3160 | // connection_id |
| 3161 | {"", |
| 3162 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3163 | // packet number |
| 3164 | {"", |
| 3165 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3166 | // frame type (IETF_ACK frame) |
| 3167 | {"", |
| 3168 | {0x02}}, |
| 3169 | // largest acked |
| 3170 | {"Unable to read largest acked.", |
| 3171 | {kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78}}, |
| 3172 | // Zero delta time. |
| 3173 | {"Unable to read ack delay time.", |
| 3174 | {kVarInt62OneByte + 0x00}}, |
| 3175 | // Number of ack blocks after first |
| 3176 | {"Unable to read ack block count.", |
| 3177 | {kVarInt62OneByte + 0x00}}, |
| 3178 | // first ack block length. |
| 3179 | {"Unable to read first ack block length.", |
| 3180 | {kVarInt62TwoBytes + 0x12, 0x33}} |
| 3181 | }; |
| 3182 | // clang-format on |
| 3183 | |
| 3184 | PacketFragments& fragments = |
| 3185 | framer_.transport_version() == QUIC_VERSION_99 |
| 3186 | ? packet99 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 3187 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3188 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3189 | AssemblePacketFromFragments(fragments)); |
| 3190 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3191 | |
| 3192 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 3193 | ASSERT_TRUE(visitor_.header_.get()); |
| 3194 | EXPECT_TRUE(CheckDecryption( |
| 3195 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3196 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3197 | |
| 3198 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3199 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3200 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3201 | EXPECT_EQ(kPacketNumber, LargestAcked(frame)); |
| 3202 | ASSERT_EQ(4660u, frame.packets.NumPacketsSlow()); |
| 3203 | |
| 3204 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3205 | } |
| 3206 | |
| 3207 | // Tests ability to handle multiple ackblocks after the first ack |
| 3208 | // block. Non-version-99 tests include multiple timestamps as well. |
| 3209 | TEST_P(QuicFramerTest, AckFrameTwoTimeStampsMultipleAckBlocks) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3210 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3211 | // clang-format off |
| 3212 | PacketFragments packet = { |
| 3213 | // public flags (8 byte connection_id) |
| 3214 | {"", |
| 3215 | { 0x2C }}, |
| 3216 | // connection_id |
| 3217 | {"", |
| 3218 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3219 | // packet number |
| 3220 | {"", |
| 3221 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3222 | |
| 3223 | // frame type (ack frame) |
| 3224 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3225 | {"", |
| 3226 | { 0x65 }}, |
| 3227 | // largest acked |
| 3228 | {"Unable to read largest acked.", |
| 3229 | { 0x12, 0x34 }}, |
| 3230 | // Zero delta time. |
| 3231 | {"Unable to read ack delay time.", |
| 3232 | { 0x00, 0x00 }}, |
| 3233 | // num ack blocks ranges. |
| 3234 | {"Unable to read num of ack blocks.", |
| 3235 | { 0x04 }}, |
| 3236 | // first ack block length. |
| 3237 | {"Unable to read first ack block length.", |
| 3238 | { 0x00, 0x01 }}, |
| 3239 | // gap to next block. |
| 3240 | { "Unable to read gap to next ack block.", |
| 3241 | { 0x01 }}, |
| 3242 | // ack block length. |
| 3243 | { "Unable to ack block length.", |
| 3244 | { 0x0e, 0xaf }}, |
| 3245 | // gap to next block. |
| 3246 | { "Unable to read gap to next ack block.", |
| 3247 | { 0xff }}, |
| 3248 | // ack block length. |
| 3249 | { "Unable to ack block length.", |
| 3250 | { 0x00, 0x00 }}, |
| 3251 | // gap to next block. |
| 3252 | { "Unable to read gap to next ack block.", |
| 3253 | { 0x91 }}, |
| 3254 | // ack block length. |
| 3255 | { "Unable to ack block length.", |
| 3256 | { 0x01, 0xea }}, |
| 3257 | // gap to next block. |
| 3258 | { "Unable to read gap to next ack block.", |
| 3259 | { 0x05 }}, |
| 3260 | // ack block length. |
| 3261 | { "Unable to ack block length.", |
| 3262 | { 0x00, 0x04 }}, |
| 3263 | // Number of timestamps. |
| 3264 | { "Unable to read num received packets.", |
| 3265 | { 0x02 }}, |
| 3266 | // Delta from largest observed. |
| 3267 | { "Unable to read sequence delta in received packets.", |
| 3268 | { 0x01 }}, |
| 3269 | // Delta time. |
| 3270 | { "Unable to read time delta in received packets.", |
| 3271 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3272 | // Delta from largest observed. |
| 3273 | { "Unable to read sequence delta in received packets.", |
| 3274 | { 0x02 }}, |
| 3275 | // Delta time. |
| 3276 | { "Unable to read incremental time delta in received packets.", |
| 3277 | { 0x32, 0x10 }}, |
| 3278 | }; |
| 3279 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3280 | PacketFragments packet46 = { |
| 3281 | // type (short header, 4 byte packet number) |
| 3282 | {"", |
| 3283 | { 0x43 }}, |
| 3284 | // connection_id |
| 3285 | {"", |
| 3286 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3287 | // packet number |
| 3288 | {"", |
| 3289 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3290 | |
| 3291 | // frame type (ack frame) |
| 3292 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3293 | {"", |
| 3294 | { 0x65 }}, |
| 3295 | // largest acked |
| 3296 | {"Unable to read largest acked.", |
| 3297 | { 0x12, 0x34 }}, |
| 3298 | // Zero delta time. |
| 3299 | {"Unable to read ack delay time.", |
| 3300 | { 0x00, 0x00 }}, |
| 3301 | // num ack blocks ranges. |
| 3302 | {"Unable to read num of ack blocks.", |
| 3303 | { 0x04 }}, |
| 3304 | // first ack block length. |
| 3305 | {"Unable to read first ack block length.", |
| 3306 | { 0x00, 0x01 }}, |
| 3307 | // gap to next block. |
| 3308 | { "Unable to read gap to next ack block.", |
| 3309 | { 0x01 }}, |
| 3310 | // ack block length. |
| 3311 | { "Unable to ack block length.", |
| 3312 | { 0x0e, 0xaf }}, |
| 3313 | // gap to next block. |
| 3314 | { "Unable to read gap to next ack block.", |
| 3315 | { 0xff }}, |
| 3316 | // ack block length. |
| 3317 | { "Unable to ack block length.", |
| 3318 | { 0x00, 0x00 }}, |
| 3319 | // gap to next block. |
| 3320 | { "Unable to read gap to next ack block.", |
| 3321 | { 0x91 }}, |
| 3322 | // ack block length. |
| 3323 | { "Unable to ack block length.", |
| 3324 | { 0x01, 0xea }}, |
| 3325 | // gap to next block. |
| 3326 | { "Unable to read gap to next ack block.", |
| 3327 | { 0x05 }}, |
| 3328 | // ack block length. |
| 3329 | { "Unable to ack block length.", |
| 3330 | { 0x00, 0x04 }}, |
| 3331 | // Number of timestamps. |
| 3332 | { "Unable to read num received packets.", |
| 3333 | { 0x02 }}, |
| 3334 | // Delta from largest observed. |
| 3335 | { "Unable to read sequence delta in received packets.", |
| 3336 | { 0x01 }}, |
| 3337 | // Delta time. |
| 3338 | { "Unable to read time delta in received packets.", |
| 3339 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3340 | // Delta from largest observed. |
| 3341 | { "Unable to read sequence delta in received packets.", |
| 3342 | { 0x02 }}, |
| 3343 | // Delta time. |
| 3344 | { "Unable to read incremental time delta in received packets.", |
| 3345 | { 0x32, 0x10 }}, |
| 3346 | }; |
| 3347 | |
| 3348 | PacketFragments packet99 = { |
| 3349 | // type (short header, 4 byte packet number) |
| 3350 | {"", |
| 3351 | { 0x43 }}, |
| 3352 | // connection_id |
| 3353 | {"", |
| 3354 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3355 | // packet number |
| 3356 | {"", |
| 3357 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3358 | |
| 3359 | // frame type (IETF_ACK frame) |
| 3360 | {"", |
| 3361 | { 0x02 }}, |
| 3362 | // largest acked |
| 3363 | {"Unable to read largest acked.", |
| 3364 | { kVarInt62TwoBytes + 0x12, 0x34 }}, // = 4660 |
| 3365 | // Zero delta time. |
| 3366 | {"Unable to read ack delay time.", |
| 3367 | { kVarInt62OneByte + 0x00 }}, |
| 3368 | // number of additional ack blocks |
| 3369 | {"Unable to read ack block count.", |
| 3370 | { kVarInt62OneByte + 0x03 }}, |
| 3371 | // first ack block length. |
| 3372 | {"Unable to read first ack block length.", |
| 3373 | { kVarInt62OneByte + 0x00 }}, // 1st block length = 1 |
| 3374 | |
| 3375 | // Additional ACK Block #1 |
| 3376 | // gap to next block. |
| 3377 | { "Unable to read gap block value.", |
| 3378 | { kVarInt62OneByte + 0x00 }}, // gap of 1 packet |
| 3379 | // ack block length. |
| 3380 | { "Unable to read ack block value.", |
| 3381 | { kVarInt62TwoBytes + 0x0e, 0xae }}, // 3759 |
| 3382 | |
| 3383 | // pre-version-99 test includes an ack block of 0 length. this |
| 3384 | // can not happen in version 99. ergo the second block is not |
| 3385 | // present in the v99 test and the gap length of the next block |
| 3386 | // is the sum of the two gaps in the pre-version-99 tests. |
| 3387 | // Additional ACK Block #2 |
| 3388 | // gap to next block. |
| 3389 | { "Unable to read gap block value.", |
| 3390 | { kVarInt62TwoBytes + 0x01, 0x8f }}, // Gap is 400 (0x190) pkts |
| 3391 | // ack block length. |
| 3392 | { "Unable to read ack block value.", |
| 3393 | { kVarInt62TwoBytes + 0x01, 0xe9 }}, // block is 389 (x1ea) pkts |
| 3394 | |
| 3395 | // Additional ACK Block #3 |
| 3396 | // gap to next block. |
| 3397 | { "Unable to read gap block value.", |
| 3398 | { kVarInt62OneByte + 0x04 }}, // Gap is 5 packets. |
| 3399 | // ack block length. |
| 3400 | { "Unable to read ack block value.", |
| 3401 | { kVarInt62OneByte + 0x03 }}, // block is 3 packets. |
| 3402 | }; |
| 3403 | |
| 3404 | // clang-format on |
| 3405 | PacketFragments& fragments = |
| 3406 | framer_.transport_version() == QUIC_VERSION_99 |
| 3407 | ? packet99 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 3408 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3409 | |
| 3410 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3411 | AssemblePacketFromFragments(fragments)); |
| 3412 | |
| 3413 | framer_.set_process_timestamps(true); |
| 3414 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3415 | |
| 3416 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 3417 | ASSERT_TRUE(visitor_.header_.get()); |
| 3418 | EXPECT_TRUE(CheckDecryption( |
| 3419 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3420 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3421 | |
| 3422 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3423 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3424 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3425 | EXPECT_EQ(kSmallLargestObserved, LargestAcked(frame)); |
| 3426 | ASSERT_EQ(4254u, frame.packets.NumPacketsSlow()); |
| 3427 | EXPECT_EQ(4u, frame.packets.NumIntervals()); |
| 3428 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 3429 | EXPECT_EQ(0u, frame.received_packet_times.size()); |
| 3430 | } else { |
| 3431 | EXPECT_EQ(2u, frame.received_packet_times.size()); |
| 3432 | } |
| 3433 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3434 | } |
| 3435 | |
| 3436 | TEST_P(QuicFramerTest, AckFrameTimeStampDeltaTooHigh) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 3437 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3438 | // clang-format off |
| 3439 | unsigned char packet[] = { |
| 3440 | // public flags (8 byte connection_id) |
| 3441 | 0x28, |
| 3442 | // connection_id |
| 3443 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3444 | // packet number |
| 3445 | 0x12, 0x34, 0x56, 0x78, |
| 3446 | |
| 3447 | // frame type (ack frame) |
| 3448 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3449 | 0x40, |
| 3450 | // largest acked |
| 3451 | 0x01, |
| 3452 | // Zero delta time. |
| 3453 | 0x00, 0x00, |
| 3454 | // first ack block length. |
| 3455 | 0x01, |
| 3456 | // num timestamps. |
| 3457 | 0x01, |
| 3458 | // Delta from largest observed. |
| 3459 | 0x01, |
| 3460 | // Delta time. |
| 3461 | 0x10, 0x32, 0x54, 0x76, |
| 3462 | }; |
| 3463 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3464 | unsigned char packet46[] = { |
| 3465 | // type (short header, 4 byte packet number) |
| 3466 | 0x43, |
| 3467 | // connection_id |
| 3468 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3469 | // packet number |
| 3470 | 0x12, 0x34, 0x56, 0x78, |
| 3471 | |
| 3472 | // frame type (ack frame) |
| 3473 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3474 | 0x40, |
| 3475 | // largest acked |
| 3476 | 0x01, |
| 3477 | // Zero delta time. |
| 3478 | 0x00, 0x00, |
| 3479 | // first ack block length. |
| 3480 | 0x01, |
| 3481 | // num timestamps. |
| 3482 | 0x01, |
| 3483 | // Delta from largest observed. |
| 3484 | 0x01, |
| 3485 | // Delta time. |
| 3486 | 0x10, 0x32, 0x54, 0x76, |
| 3487 | }; |
| 3488 | // clang-format on |
| 3489 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 3490 | return; |
| 3491 | } |
| 3492 | QuicEncryptedPacket encrypted( |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 3493 | AsChars(framer_.transport_version() > QUIC_VERSION_43 ? packet46 |
| 3494 | : packet), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3495 | QUIC_ARRAYSIZE(packet), false); |
| 3496 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 3497 | EXPECT_TRUE(QuicTextUtils::StartsWith( |
| 3498 | framer_.detailed_error(), "delta_from_largest_observed too high")); |
| 3499 | } |
| 3500 | |
| 3501 | TEST_P(QuicFramerTest, AckFrameTimeStampSecondDeltaTooHigh) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 3502 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3503 | // clang-format off |
| 3504 | unsigned char packet[] = { |
| 3505 | // public flags (8 byte connection_id) |
| 3506 | 0x28, |
| 3507 | // connection_id |
| 3508 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3509 | // packet number |
| 3510 | 0x12, 0x34, 0x56, 0x78, |
| 3511 | |
| 3512 | // frame type (ack frame) |
| 3513 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3514 | 0x40, |
| 3515 | // largest acked |
| 3516 | 0x03, |
| 3517 | // Zero delta time. |
| 3518 | 0x00, 0x00, |
| 3519 | // first ack block length. |
| 3520 | 0x03, |
| 3521 | // num timestamps. |
| 3522 | 0x02, |
| 3523 | // Delta from largest observed. |
| 3524 | 0x01, |
| 3525 | // Delta time. |
| 3526 | 0x10, 0x32, 0x54, 0x76, |
| 3527 | // Delta from largest observed. |
| 3528 | 0x03, |
| 3529 | // Delta time. |
| 3530 | 0x10, 0x32, |
| 3531 | }; |
| 3532 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3533 | unsigned char packet46[] = { |
| 3534 | // type (short header, 4 byte packet number) |
| 3535 | 0x43, |
| 3536 | // connection_id |
| 3537 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3538 | // packet number |
| 3539 | 0x12, 0x34, 0x56, 0x78, |
| 3540 | |
| 3541 | // frame type (ack frame) |
| 3542 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3543 | 0x40, |
| 3544 | // largest acked |
| 3545 | 0x03, |
| 3546 | // Zero delta time. |
| 3547 | 0x00, 0x00, |
| 3548 | // first ack block length. |
| 3549 | 0x03, |
| 3550 | // num timestamps. |
| 3551 | 0x02, |
| 3552 | // Delta from largest observed. |
| 3553 | 0x01, |
| 3554 | // Delta time. |
| 3555 | 0x10, 0x32, 0x54, 0x76, |
| 3556 | // Delta from largest observed. |
| 3557 | 0x03, |
| 3558 | // Delta time. |
| 3559 | 0x10, 0x32, |
| 3560 | }; |
| 3561 | // clang-format on |
| 3562 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 3563 | return; |
| 3564 | } |
| 3565 | QuicEncryptedPacket encrypted( |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 3566 | AsChars(framer_.transport_version() > QUIC_VERSION_43 ? packet46 |
| 3567 | : packet), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3568 | QUIC_ARRAYSIZE(packet), false); |
| 3569 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 3570 | EXPECT_TRUE(QuicTextUtils::StartsWith( |
| 3571 | framer_.detailed_error(), "delta_from_largest_observed too high")); |
| 3572 | } |
| 3573 | |
| 3574 | TEST_P(QuicFramerTest, NewStopWaitingFrame) { |
| 3575 | if (version_.transport_version == QUIC_VERSION_99) { |
| 3576 | return; |
| 3577 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 3578 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3579 | // clang-format off |
| 3580 | PacketFragments packet = { |
| 3581 | // public flags (8 byte connection_id) |
| 3582 | {"", |
| 3583 | {0x2C}}, |
| 3584 | // connection_id |
| 3585 | {"", |
| 3586 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3587 | // packet number |
| 3588 | {"", |
| 3589 | {0x12, 0x34, 0x56, 0x78}}, |
| 3590 | // frame type (stop waiting frame) |
| 3591 | {"", |
| 3592 | {0x06}}, |
| 3593 | // least packet number awaiting an ack, delta from packet number. |
| 3594 | {"Unable to read least unacked delta.", |
| 3595 | {0x00, 0x00, 0x00, 0x08}} |
| 3596 | }; |
| 3597 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3598 | PacketFragments packet46 = { |
| 3599 | // type (short header, 4 byte packet number) |
| 3600 | {"", |
| 3601 | {0x43}}, |
| 3602 | // connection_id |
| 3603 | {"", |
| 3604 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3605 | // packet number |
| 3606 | {"", |
| 3607 | {0x12, 0x34, 0x56, 0x78}}, |
| 3608 | // frame type (stop waiting frame) |
| 3609 | {"", |
| 3610 | {0x06}}, |
| 3611 | // least packet number awaiting an ack, delta from packet number. |
| 3612 | {"Unable to read least unacked delta.", |
| 3613 | {0x00, 0x00, 0x00, 0x08}} |
| 3614 | }; |
| 3615 | // clang-format on |
| 3616 | |
| 3617 | PacketFragments& fragments = |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 3618 | framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3619 | |
| 3620 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3621 | AssemblePacketFromFragments(fragments)); |
ianswett | 97b690b | 2019-05-02 15:12:43 -0700 | [diff] [blame] | 3622 | if (GetQuicReloadableFlag(quic_do_not_accept_stop_waiting) && |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 3623 | version_.transport_version > QUIC_VERSION_43) { |
ianswett | 97b690b | 2019-05-02 15:12:43 -0700 | [diff] [blame] | 3624 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3625 | EXPECT_EQ(QUIC_INVALID_STOP_WAITING_DATA, framer_.error()); |
| 3626 | EXPECT_EQ("STOP WAITING not supported in version 44+.", |
| 3627 | framer_.detailed_error()); |
| 3628 | return; |
| 3629 | } |
| 3630 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3631 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3632 | |
| 3633 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 3634 | ASSERT_TRUE(visitor_.header_.get()); |
| 3635 | EXPECT_TRUE(CheckDecryption( |
| 3636 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3637 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3638 | |
| 3639 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3640 | ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size()); |
| 3641 | const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0]; |
| 3642 | EXPECT_EQ(kLeastUnacked, frame.least_unacked); |
| 3643 | |
| 3644 | CheckFramingBoundaries(fragments, QUIC_INVALID_STOP_WAITING_DATA); |
| 3645 | } |
| 3646 | |
| 3647 | TEST_P(QuicFramerTest, InvalidNewStopWaitingFrame) { |
ianswett | 97b690b | 2019-05-02 15:12:43 -0700 | [diff] [blame] | 3648 | if (version_.transport_version == QUIC_VERSION_99 || |
| 3649 | (GetQuicReloadableFlag(quic_do_not_accept_stop_waiting) && |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 3650 | version_.transport_version > QUIC_VERSION_43)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3651 | return; |
| 3652 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 3653 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3654 | // clang-format off |
| 3655 | unsigned char packet[] = { |
| 3656 | // public flags (8 byte connection_id) |
| 3657 | 0x2C, |
| 3658 | // connection_id |
| 3659 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3660 | // packet number |
| 3661 | 0x12, 0x34, 0x56, 0x78, |
| 3662 | // frame type (stop waiting frame) |
| 3663 | 0x06, |
| 3664 | // least packet number awaiting an ack, delta from packet number. |
| 3665 | 0x13, 0x34, 0x56, 0x78, |
| 3666 | 0x9A, 0xA8, |
| 3667 | }; |
| 3668 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3669 | unsigned char packet46[] = { |
| 3670 | // type (short header, 4 byte packet number) |
| 3671 | 0x43, |
| 3672 | // connection_id |
| 3673 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3674 | // packet number |
| 3675 | 0x12, 0x34, 0x56, 0x78, |
| 3676 | // frame type (stop waiting frame) |
| 3677 | 0x06, |
| 3678 | // least packet number awaiting an ack, delta from packet number. |
| 3679 | 0x57, 0x78, 0x9A, 0xA8, |
| 3680 | }; |
| 3681 | // clang-format on |
| 3682 | |
| 3683 | QuicEncryptedPacket encrypted( |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 3684 | AsChars(framer_.transport_version() > QUIC_VERSION_43 ? packet46 |
| 3685 | : packet), |
| 3686 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet46) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3687 | : QUIC_ARRAYSIZE(packet), |
| 3688 | false); |
| 3689 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 3690 | EXPECT_EQ(QUIC_INVALID_STOP_WAITING_DATA, framer_.error()); |
| 3691 | EXPECT_EQ("Invalid unacked delta.", framer_.detailed_error()); |
| 3692 | } |
| 3693 | |
| 3694 | TEST_P(QuicFramerTest, RstStreamFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3695 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3696 | // clang-format off |
| 3697 | PacketFragments packet = { |
| 3698 | // public flags (8 byte connection_id) |
| 3699 | {"", |
| 3700 | {0x28}}, |
| 3701 | // connection_id |
| 3702 | {"", |
| 3703 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3704 | // packet number |
| 3705 | {"", |
| 3706 | {0x12, 0x34, 0x56, 0x78}}, |
| 3707 | // frame type (rst stream frame) |
| 3708 | {"", |
| 3709 | {0x01}}, |
| 3710 | // stream id |
| 3711 | {"Unable to read stream_id.", |
| 3712 | {0x01, 0x02, 0x03, 0x04}}, |
| 3713 | // sent byte offset |
| 3714 | {"Unable to read rst stream sent byte offset.", |
| 3715 | {0x3A, 0x98, 0xFE, 0xDC, |
| 3716 | 0x32, 0x10, 0x76, 0x54}}, |
| 3717 | // error code |
| 3718 | {"Unable to read rst stream error code.", |
| 3719 | {0x00, 0x00, 0x00, 0x01}} |
| 3720 | }; |
| 3721 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3722 | PacketFragments packet46 = { |
| 3723 | // type (short header, 4 byte packet number) |
| 3724 | {"", |
| 3725 | {0x43}}, |
| 3726 | // connection_id |
| 3727 | {"", |
| 3728 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3729 | // packet number |
| 3730 | {"", |
| 3731 | {0x12, 0x34, 0x56, 0x78}}, |
| 3732 | // frame type (rst stream frame) |
| 3733 | {"", |
| 3734 | {0x01}}, |
| 3735 | // stream id |
| 3736 | {"Unable to read stream_id.", |
| 3737 | {0x01, 0x02, 0x03, 0x04}}, |
| 3738 | // sent byte offset |
| 3739 | {"Unable to read rst stream sent byte offset.", |
| 3740 | {0x3A, 0x98, 0xFE, 0xDC, |
| 3741 | 0x32, 0x10, 0x76, 0x54}}, |
| 3742 | // error code |
| 3743 | {"Unable to read rst stream error code.", |
| 3744 | {0x00, 0x00, 0x00, 0x01}} |
| 3745 | }; |
| 3746 | |
| 3747 | PacketFragments packet99 = { |
| 3748 | // type (short header, 4 byte packet number) |
| 3749 | {"", |
| 3750 | {0x43}}, |
| 3751 | // connection_id |
| 3752 | {"", |
| 3753 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3754 | // packet number |
| 3755 | {"", |
| 3756 | {0x12, 0x34, 0x56, 0x78}}, |
| 3757 | // frame type (IETF_RST_STREAM frame) |
| 3758 | {"", |
| 3759 | {0x04}}, |
| 3760 | // stream id |
| 3761 | {"Unable to read rst stream stream id.", |
| 3762 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 3763 | // application error code |
| 3764 | {"Unable to read rst stream error code.", |
| 3765 | {0x00, 0x01}}, // Not varint62 encoded |
| 3766 | // Final Offset |
| 3767 | {"Unable to read rst stream sent byte offset.", |
| 3768 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}} |
| 3769 | }; |
| 3770 | // clang-format on |
| 3771 | |
| 3772 | PacketFragments& fragments = |
| 3773 | framer_.transport_version() == QUIC_VERSION_99 |
| 3774 | ? packet99 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 3775 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3776 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3777 | AssemblePacketFromFragments(fragments)); |
| 3778 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3779 | |
| 3780 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 3781 | ASSERT_TRUE(visitor_.header_.get()); |
| 3782 | EXPECT_TRUE(CheckDecryption( |
| 3783 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3784 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3785 | |
| 3786 | EXPECT_EQ(kStreamId, visitor_.rst_stream_frame_.stream_id); |
| 3787 | EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code); |
| 3788 | EXPECT_EQ(kStreamOffset, visitor_.rst_stream_frame_.byte_offset); |
| 3789 | CheckFramingBoundaries(fragments, QUIC_INVALID_RST_STREAM_DATA); |
| 3790 | } |
| 3791 | |
| 3792 | TEST_P(QuicFramerTest, ConnectionCloseFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3793 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3794 | // clang-format off |
| 3795 | PacketFragments packet = { |
| 3796 | // public flags (8 byte connection_id) |
| 3797 | {"", |
| 3798 | {0x28}}, |
| 3799 | // connection_id |
| 3800 | {"", |
| 3801 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3802 | // packet number |
| 3803 | {"", |
| 3804 | {0x12, 0x34, 0x56, 0x78}}, |
| 3805 | // frame type (connection close frame) |
| 3806 | {"", |
| 3807 | {0x02}}, |
| 3808 | // error code |
| 3809 | {"Unable to read connection close error code.", |
| 3810 | {0x00, 0x00, 0x00, 0x11}}, |
| 3811 | {"Unable to read connection close error details.", |
| 3812 | { |
| 3813 | // error details length |
| 3814 | 0x0, 0x0d, |
| 3815 | // error details |
| 3816 | 'b', 'e', 'c', 'a', |
| 3817 | 'u', 's', 'e', ' ', |
| 3818 | 'I', ' ', 'c', 'a', |
| 3819 | 'n'} |
| 3820 | } |
| 3821 | }; |
| 3822 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3823 | PacketFragments packet46 = { |
| 3824 | // type (short header, 4 byte packet number) |
| 3825 | {"", |
| 3826 | {0x43}}, |
| 3827 | // connection_id |
| 3828 | {"", |
| 3829 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3830 | // packet number |
| 3831 | {"", |
| 3832 | {0x12, 0x34, 0x56, 0x78}}, |
| 3833 | // frame type (connection close frame) |
| 3834 | {"", |
| 3835 | {0x02}}, |
| 3836 | // error code |
| 3837 | {"Unable to read connection close error code.", |
| 3838 | {0x00, 0x00, 0x00, 0x11}}, |
| 3839 | {"Unable to read connection close error details.", |
| 3840 | { |
| 3841 | // error details length |
| 3842 | 0x0, 0x0d, |
| 3843 | // error details |
| 3844 | 'b', 'e', 'c', 'a', |
| 3845 | 'u', 's', 'e', ' ', |
| 3846 | 'I', ' ', 'c', 'a', |
| 3847 | 'n'} |
| 3848 | } |
| 3849 | }; |
| 3850 | |
| 3851 | PacketFragments packet99 = { |
| 3852 | // type (short header, 4 byte packet number) |
| 3853 | {"", |
| 3854 | {0x43}}, |
| 3855 | // connection_id |
| 3856 | {"", |
| 3857 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3858 | // packet number |
| 3859 | {"", |
| 3860 | {0x12, 0x34, 0x56, 0x78}}, |
| 3861 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 3862 | {"", |
| 3863 | {0x1c}}, |
| 3864 | // error code |
| 3865 | {"Unable to read connection close error code.", |
| 3866 | {0x00, 0x11}}, |
| 3867 | {"Unable to read connection close frame type.", |
| 3868 | {kVarInt62TwoBytes + 0x12, 0x34 }}, |
| 3869 | {"Unable to read connection close error details.", |
| 3870 | { |
| 3871 | // error details length |
| 3872 | kVarInt62OneByte + 0x0d, |
| 3873 | // error details |
| 3874 | 'b', 'e', 'c', 'a', |
| 3875 | 'u', 's', 'e', ' ', |
| 3876 | 'I', ' ', 'c', 'a', |
| 3877 | 'n'} |
| 3878 | } |
| 3879 | }; |
| 3880 | // clang-format on |
| 3881 | |
| 3882 | PacketFragments& fragments = |
| 3883 | framer_.transport_version() == QUIC_VERSION_99 |
| 3884 | ? packet99 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 3885 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3886 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3887 | AssemblePacketFromFragments(fragments)); |
| 3888 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3889 | |
| 3890 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 3891 | ASSERT_TRUE(visitor_.header_.get()); |
| 3892 | EXPECT_TRUE(CheckDecryption( |
| 3893 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3894 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3895 | |
| 3896 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
zhongyi | ba6354a | 2019-04-10 16:49:25 -0700 | [diff] [blame] | 3897 | EXPECT_EQ(0x11u, static_cast<unsigned>( |
| 3898 | visitor_.connection_close_frame_.quic_error_code)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3899 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
| 3900 | if (framer_.transport_version() == QUIC_VERSION_99) { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 3901 | EXPECT_EQ(0x1234u, |
| 3902 | visitor_.connection_close_frame_.transport_close_frame_type); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3903 | } |
| 3904 | |
| 3905 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 3906 | |
| 3907 | CheckFramingBoundaries(fragments, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 3908 | } |
| 3909 | |
fkastenholz | 04bd4f3 | 2019-04-16 12:24:38 -0700 | [diff] [blame] | 3910 | // Test the CONNECTION_CLOSE/Application variant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3911 | TEST_P(QuicFramerTest, ApplicationCloseFrame) { |
| 3912 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 3913 | // This frame does not exist in versions other than 99. |
| 3914 | return; |
| 3915 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3916 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3917 | |
| 3918 | // clang-format off |
| 3919 | PacketFragments packet99 = { |
| 3920 | // type (short header, 4 byte packet number) |
| 3921 | {"", |
| 3922 | {0x43}}, |
| 3923 | // connection_id |
| 3924 | {"", |
| 3925 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3926 | // packet number |
| 3927 | {"", |
| 3928 | {0x12, 0x34, 0x56, 0x78}}, |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 3929 | // frame type (IETF_CONNECTION_CLOSE/Application frame) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3930 | {"", |
| 3931 | {0x1d}}, |
| 3932 | // error code |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 3933 | {"Unable to read connection close error code.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3934 | {0x00, 0x11}}, |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 3935 | {"Unable to read connection close error details.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3936 | { |
| 3937 | // error details length |
| 3938 | kVarInt62OneByte + 0x0d, |
| 3939 | // error details |
| 3940 | 'b', 'e', 'c', 'a', |
| 3941 | 'u', 's', 'e', ' ', |
| 3942 | 'I', ' ', 'c', 'a', |
| 3943 | 'n'} |
| 3944 | } |
| 3945 | }; |
| 3946 | // clang-format on |
| 3947 | |
| 3948 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3949 | AssemblePacketFromFragments(packet99)); |
| 3950 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3951 | |
| 3952 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 3953 | ASSERT_TRUE(visitor_.header_.get()); |
| 3954 | EXPECT_TRUE(CheckDecryption( |
| 3955 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3956 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3957 | |
| 3958 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3959 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 3960 | EXPECT_EQ(IETF_QUIC_APPLICATION_CONNECTION_CLOSE, |
| 3961 | visitor_.connection_close_frame_.close_type); |
| 3962 | EXPECT_EQ(122u, visitor_.connection_close_frame_.extracted_error_code); |
| 3963 | EXPECT_EQ(0x11, visitor_.connection_close_frame_.quic_error_code); |
| 3964 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3965 | |
| 3966 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 3967 | |
fkastenholz | 04bd4f3 | 2019-04-16 12:24:38 -0700 | [diff] [blame] | 3968 | CheckFramingBoundaries(packet99, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | TEST_P(QuicFramerTest, GoAwayFrame) { |
| 3972 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 3973 | // This frame is not supported in version 99. |
| 3974 | return; |
| 3975 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 3976 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3977 | // clang-format off |
| 3978 | PacketFragments packet = { |
| 3979 | // public flags (8 byte connection_id) |
| 3980 | {"", |
| 3981 | {0x28}}, |
| 3982 | // connection_id |
| 3983 | {"", |
| 3984 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3985 | // packet number |
| 3986 | {"", |
| 3987 | {0x12, 0x34, 0x56, 0x78}}, |
| 3988 | // frame type (go away frame) |
| 3989 | {"", |
| 3990 | {0x03}}, |
| 3991 | // error code |
| 3992 | {"Unable to read go away error code.", |
| 3993 | {0x00, 0x00, 0x00, 0x09}}, |
| 3994 | // stream id |
| 3995 | {"Unable to read last good stream id.", |
| 3996 | {0x01, 0x02, 0x03, 0x04}}, |
| 3997 | // stream id |
| 3998 | {"Unable to read goaway reason.", |
| 3999 | { |
| 4000 | // error details length |
| 4001 | 0x0, 0x0d, |
| 4002 | // error details |
| 4003 | 'b', 'e', 'c', 'a', |
| 4004 | 'u', 's', 'e', ' ', |
| 4005 | 'I', ' ', 'c', 'a', |
| 4006 | 'n'} |
| 4007 | } |
| 4008 | }; |
| 4009 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4010 | PacketFragments packet46 = { |
| 4011 | // type (short header, 4 byte packet number) |
| 4012 | {"", |
| 4013 | {0x43}}, |
| 4014 | // connection_id |
| 4015 | {"", |
| 4016 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4017 | // packet number |
| 4018 | {"", |
| 4019 | {0x12, 0x34, 0x56, 0x78}}, |
| 4020 | // frame type (go away frame) |
| 4021 | {"", |
| 4022 | {0x03}}, |
| 4023 | // error code |
| 4024 | {"Unable to read go away error code.", |
| 4025 | {0x00, 0x00, 0x00, 0x09}}, |
| 4026 | // stream id |
| 4027 | {"Unable to read last good stream id.", |
| 4028 | {0x01, 0x02, 0x03, 0x04}}, |
| 4029 | // stream id |
| 4030 | {"Unable to read goaway reason.", |
| 4031 | { |
| 4032 | // error details length |
| 4033 | 0x0, 0x0d, |
| 4034 | // error details |
| 4035 | 'b', 'e', 'c', 'a', |
| 4036 | 'u', 's', 'e', ' ', |
| 4037 | 'I', ' ', 'c', 'a', |
| 4038 | 'n'} |
| 4039 | } |
| 4040 | }; |
| 4041 | // clang-format on |
| 4042 | |
| 4043 | PacketFragments& fragments = |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4044 | framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4045 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4046 | AssemblePacketFromFragments(fragments)); |
| 4047 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4048 | |
| 4049 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4050 | ASSERT_TRUE(visitor_.header_.get()); |
| 4051 | EXPECT_TRUE(CheckDecryption( |
| 4052 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4053 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4054 | |
| 4055 | EXPECT_EQ(kStreamId, visitor_.goaway_frame_.last_good_stream_id); |
| 4056 | EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code); |
| 4057 | EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); |
| 4058 | |
| 4059 | CheckFramingBoundaries(fragments, QUIC_INVALID_GOAWAY_DATA); |
| 4060 | } |
| 4061 | |
| 4062 | TEST_P(QuicFramerTest, WindowUpdateFrame) { |
| 4063 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4064 | // This frame is not in version 99, see MaxDataFrame and MaxStreamDataFrame |
| 4065 | // for Version 99 equivalents. |
| 4066 | return; |
| 4067 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4068 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4069 | // clang-format off |
| 4070 | PacketFragments packet = { |
| 4071 | // public flags (8 byte connection_id) |
| 4072 | {"", |
| 4073 | {0x28}}, |
| 4074 | // connection_id |
| 4075 | {"", |
| 4076 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4077 | // packet number |
| 4078 | {"", |
| 4079 | {0x12, 0x34, 0x56, 0x78}}, |
| 4080 | // frame type (window update frame) |
| 4081 | {"", |
| 4082 | {0x04}}, |
| 4083 | // stream id |
| 4084 | {"Unable to read stream_id.", |
| 4085 | {0x01, 0x02, 0x03, 0x04}}, |
| 4086 | // byte offset |
| 4087 | {"Unable to read window byte_offset.", |
| 4088 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4089 | 0x32, 0x10, 0x76, 0x54}}, |
| 4090 | }; |
| 4091 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4092 | PacketFragments packet46 = { |
| 4093 | // type (short header, 4 byte packet number) |
| 4094 | {"", |
| 4095 | {0x43}}, |
| 4096 | // connection_id |
| 4097 | {"", |
| 4098 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4099 | // packet number |
| 4100 | {"", |
| 4101 | {0x12, 0x34, 0x56, 0x78}}, |
| 4102 | // frame type (window update frame) |
| 4103 | {"", |
| 4104 | {0x04}}, |
| 4105 | // stream id |
| 4106 | {"Unable to read stream_id.", |
| 4107 | {0x01, 0x02, 0x03, 0x04}}, |
| 4108 | // byte offset |
| 4109 | {"Unable to read window byte_offset.", |
| 4110 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4111 | 0x32, 0x10, 0x76, 0x54}}, |
| 4112 | }; |
| 4113 | |
| 4114 | // clang-format on |
| 4115 | |
| 4116 | PacketFragments& fragments = |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4117 | framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4118 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4119 | AssemblePacketFromFragments(fragments)); |
| 4120 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4121 | |
| 4122 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4123 | ASSERT_TRUE(visitor_.header_.get()); |
| 4124 | EXPECT_TRUE(CheckDecryption( |
| 4125 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4126 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4127 | |
| 4128 | EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); |
| 4129 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); |
| 4130 | |
| 4131 | CheckFramingBoundaries(fragments, QUIC_INVALID_WINDOW_UPDATE_DATA); |
| 4132 | } |
| 4133 | |
| 4134 | TEST_P(QuicFramerTest, MaxDataFrame) { |
| 4135 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 4136 | // This frame is available only in version 99. |
| 4137 | return; |
| 4138 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4139 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4140 | // clang-format off |
| 4141 | PacketFragments packet99 = { |
| 4142 | // type (short header, 4 byte packet number) |
| 4143 | {"", |
| 4144 | {0x43}}, |
| 4145 | // connection_id |
| 4146 | {"", |
| 4147 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4148 | // packet number |
| 4149 | {"", |
| 4150 | {0x12, 0x34, 0x56, 0x78}}, |
| 4151 | // frame type (IETF_MAX_DATA frame) |
| 4152 | {"", |
| 4153 | {0x10}}, |
| 4154 | // byte offset |
| 4155 | {"Can not read MAX_DATA byte-offset", |
| 4156 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 4157 | 0x32, 0x10, 0x76, 0x54}}, |
| 4158 | }; |
| 4159 | // clang-format on |
| 4160 | |
| 4161 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4162 | AssemblePacketFromFragments(packet99)); |
| 4163 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4164 | |
| 4165 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4166 | ASSERT_TRUE(visitor_.header_.get()); |
| 4167 | EXPECT_TRUE(CheckDecryption( |
| 4168 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4169 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4170 | |
| 4171 | EXPECT_EQ(QuicUtils::GetInvalidStreamId(framer_.transport_version()), |
| 4172 | visitor_.window_update_frame_.stream_id); |
| 4173 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); |
| 4174 | |
| 4175 | CheckFramingBoundaries(packet99, QUIC_INVALID_MAX_DATA_FRAME_DATA); |
| 4176 | } |
| 4177 | |
| 4178 | TEST_P(QuicFramerTest, MaxStreamDataFrame) { |
| 4179 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 4180 | // This frame available only in version 99. |
| 4181 | return; |
| 4182 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4183 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4184 | // clang-format off |
| 4185 | PacketFragments packet99 = { |
| 4186 | // type (short header, 4 byte packet number) |
| 4187 | {"", |
| 4188 | {0x43}}, |
| 4189 | // connection_id |
| 4190 | {"", |
| 4191 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4192 | // packet number |
| 4193 | {"", |
| 4194 | {0x12, 0x34, 0x56, 0x78}}, |
| 4195 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 4196 | {"", |
| 4197 | {0x11}}, |
| 4198 | // stream id |
| 4199 | {"Can not read MAX_STREAM_DATA stream id", |
| 4200 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 4201 | // byte offset |
| 4202 | {"Can not read MAX_STREAM_DATA byte-count", |
| 4203 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 4204 | 0x32, 0x10, 0x76, 0x54}}, |
| 4205 | }; |
| 4206 | // clang-format on |
| 4207 | |
| 4208 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4209 | AssemblePacketFromFragments(packet99)); |
| 4210 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4211 | |
| 4212 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4213 | ASSERT_TRUE(visitor_.header_.get()); |
| 4214 | EXPECT_TRUE(CheckDecryption( |
| 4215 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4216 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4217 | |
| 4218 | EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); |
| 4219 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); |
| 4220 | |
| 4221 | CheckFramingBoundaries(packet99, QUIC_INVALID_MAX_STREAM_DATA_FRAME_DATA); |
| 4222 | } |
| 4223 | |
| 4224 | TEST_P(QuicFramerTest, BlockedFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4225 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4226 | // clang-format off |
| 4227 | PacketFragments packet = { |
| 4228 | // public flags (8 byte connection_id) |
| 4229 | {"", |
| 4230 | {0x28}}, |
| 4231 | // connection_id |
| 4232 | {"", |
| 4233 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4234 | // packet number |
| 4235 | {"", |
| 4236 | {0x12, 0x34, 0x56, 0x78}}, |
| 4237 | // frame type (blocked frame) |
| 4238 | {"", |
| 4239 | {0x05}}, |
| 4240 | // stream id |
| 4241 | {"Unable to read stream_id.", |
| 4242 | {0x01, 0x02, 0x03, 0x04}}, |
| 4243 | }; |
| 4244 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4245 | PacketFragments packet46 = { |
| 4246 | // type (short header, 4 byte packet number) |
| 4247 | {"", |
| 4248 | {0x43}}, |
| 4249 | // connection_id |
| 4250 | {"", |
| 4251 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4252 | // packet number |
| 4253 | {"", |
| 4254 | {0x12, 0x34, 0x56, 0x78}}, |
| 4255 | // frame type (blocked frame) |
| 4256 | {"", |
| 4257 | {0x05}}, |
| 4258 | // stream id |
| 4259 | {"Unable to read stream_id.", |
| 4260 | {0x01, 0x02, 0x03, 0x04}}, |
| 4261 | }; |
| 4262 | |
| 4263 | PacketFragments packet99 = { |
| 4264 | // type (short header, 4 byte packet number) |
| 4265 | {"", |
| 4266 | {0x43}}, |
| 4267 | // connection_id |
| 4268 | {"", |
| 4269 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4270 | // packet number |
| 4271 | {"", |
| 4272 | {0x12, 0x34, 0x56, 0x78}}, |
| 4273 | // frame type (IETF_STREAM_BLOCKED frame) |
| 4274 | {"", |
| 4275 | {0x15}}, |
| 4276 | // stream id |
| 4277 | {"Can not read stream blocked stream id.", |
| 4278 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 4279 | // Offset |
| 4280 | {"Can not read stream blocked offset.", |
| 4281 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 4282 | }; |
| 4283 | // clang-format on |
| 4284 | |
| 4285 | PacketFragments& fragments = |
| 4286 | framer_.transport_version() == QUIC_VERSION_99 |
| 4287 | ? packet99 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4288 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4289 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4290 | AssemblePacketFromFragments(fragments)); |
| 4291 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4292 | |
| 4293 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4294 | ASSERT_TRUE(visitor_.header_.get()); |
| 4295 | EXPECT_TRUE(CheckDecryption( |
| 4296 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4297 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4298 | |
| 4299 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4300 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 4301 | } else { |
| 4302 | EXPECT_EQ(0u, visitor_.blocked_frame_.offset); |
| 4303 | } |
| 4304 | EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); |
| 4305 | |
| 4306 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4307 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_BLOCKED_DATA); |
| 4308 | } else { |
| 4309 | CheckFramingBoundaries(fragments, QUIC_INVALID_BLOCKED_DATA); |
| 4310 | } |
| 4311 | } |
| 4312 | |
| 4313 | TEST_P(QuicFramerTest, PingFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4314 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4315 | // clang-format off |
| 4316 | unsigned char packet[] = { |
| 4317 | // public flags (8 byte connection_id) |
| 4318 | 0x28, |
| 4319 | // connection_id |
| 4320 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4321 | // packet number |
| 4322 | 0x12, 0x34, 0x56, 0x78, |
| 4323 | |
| 4324 | // frame type (ping frame) |
| 4325 | 0x07, |
| 4326 | }; |
| 4327 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4328 | unsigned char packet46[] = { |
| 4329 | // type (short header, 4 byte packet number) |
| 4330 | 0x43, |
| 4331 | // connection_id |
| 4332 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4333 | // packet number |
| 4334 | 0x12, 0x34, 0x56, 0x78, |
| 4335 | |
| 4336 | // frame type |
| 4337 | 0x07, |
| 4338 | }; |
| 4339 | |
| 4340 | unsigned char packet99[] = { |
| 4341 | // type (short header, 4 byte packet number) |
| 4342 | 0x43, |
| 4343 | // connection_id |
| 4344 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4345 | // packet number |
| 4346 | 0x12, 0x34, 0x56, 0x78, |
| 4347 | |
| 4348 | // frame type (IETF_PING frame) |
| 4349 | 0x01, |
| 4350 | }; |
| 4351 | // clang-format on |
| 4352 | |
| 4353 | QuicEncryptedPacket encrypted( |
| 4354 | AsChars(framer_.transport_version() == QUIC_VERSION_99 |
| 4355 | ? packet99 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4356 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet46 |
| 4357 | : packet)), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4358 | framer_.transport_version() == QUIC_VERSION_99 |
| 4359 | ? QUIC_ARRAYSIZE(packet99) |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4360 | : (framer_.transport_version() > QUIC_VERSION_43 |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4361 | ? QUIC_ARRAYSIZE(packet46) |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4362 | : QUIC_ARRAYSIZE(packet)), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4363 | false); |
| 4364 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 4365 | |
| 4366 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4367 | ASSERT_TRUE(visitor_.header_.get()); |
| 4368 | EXPECT_TRUE(CheckDecryption( |
| 4369 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4370 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4371 | |
| 4372 | EXPECT_EQ(1u, visitor_.ping_frames_.size()); |
| 4373 | |
| 4374 | // No need to check the PING frame boundaries because it has no payload. |
| 4375 | } |
| 4376 | |
| 4377 | TEST_P(QuicFramerTest, MessageFrame) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4378 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4379 | return; |
| 4380 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4381 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4382 | // clang-format off |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4383 | PacketFragments packet46 = { |
| 4384 | // type (short header, 4 byte packet number) |
| 4385 | {"", |
| 4386 | {0x43}}, |
| 4387 | // connection_id |
| 4388 | {"", |
| 4389 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4390 | // packet number |
| 4391 | {"", |
| 4392 | {0x12, 0x34, 0x56, 0x78}}, |
| 4393 | // message frame type. |
| 4394 | {"", |
| 4395 | { 0x21 }}, |
| 4396 | // message length |
| 4397 | {"Unable to read message length", |
| 4398 | {0x07}}, |
| 4399 | // message data |
| 4400 | {"Unable to read message data", |
| 4401 | {'m', 'e', 's', 's', 'a', 'g', 'e'}}, |
| 4402 | // message frame no length. |
| 4403 | {"", |
| 4404 | { 0x20 }}, |
| 4405 | // message data |
| 4406 | {{}, |
| 4407 | {'m', 'e', 's', 's', 'a', 'g', 'e', '2'}}, |
| 4408 | }; |
| 4409 | // clang-format on |
| 4410 | |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4411 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4412 | AssemblePacketFromFragments(packet46)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4413 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4414 | |
| 4415 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4416 | ASSERT_TRUE(visitor_.header_.get()); |
| 4417 | EXPECT_TRUE(CheckDecryption( |
| 4418 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4419 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4420 | |
| 4421 | ASSERT_EQ(2u, visitor_.message_frames_.size()); |
| 4422 | EXPECT_EQ(7u, visitor_.message_frames_[0]->message_length); |
| 4423 | EXPECT_EQ(8u, visitor_.message_frames_[1]->message_length); |
| 4424 | |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4425 | CheckFramingBoundaries(packet46, QUIC_INVALID_MESSAGE_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4426 | } |
| 4427 | |
| 4428 | TEST_P(QuicFramerTest, PublicResetPacketV33) { |
| 4429 | // clang-format off |
| 4430 | PacketFragments packet = { |
| 4431 | // public flags (public reset, 8 byte connection_id) |
| 4432 | {"", |
| 4433 | {0x0A}}, |
| 4434 | // connection_id |
| 4435 | {"", |
| 4436 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4437 | {"Unable to read reset message.", |
| 4438 | { |
| 4439 | // message tag (kPRST) |
| 4440 | 'P', 'R', 'S', 'T', |
| 4441 | // num_entries (2) + padding |
| 4442 | 0x02, 0x00, 0x00, 0x00, |
| 4443 | // tag kRNON |
| 4444 | 'R', 'N', 'O', 'N', |
| 4445 | // end offset 8 |
| 4446 | 0x08, 0x00, 0x00, 0x00, |
| 4447 | // tag kRSEQ |
| 4448 | 'R', 'S', 'E', 'Q', |
| 4449 | // end offset 16 |
| 4450 | 0x10, 0x00, 0x00, 0x00, |
| 4451 | // nonce proof |
| 4452 | 0x89, 0x67, 0x45, 0x23, |
| 4453 | 0x01, 0xEF, 0xCD, 0xAB, |
| 4454 | // rejected packet number |
| 4455 | 0xBC, 0x9A, 0x78, 0x56, |
| 4456 | 0x34, 0x12, 0x00, 0x00, |
| 4457 | } |
| 4458 | } |
| 4459 | }; |
| 4460 | // clang-format on |
| 4461 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 4462 | return; |
| 4463 | } |
| 4464 | |
| 4465 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4466 | AssemblePacketFromFragments(packet)); |
| 4467 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4468 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4469 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 4470 | EXPECT_EQ(FramerTestConnectionId(), |
| 4471 | visitor_.public_reset_packet_->connection_id); |
| 4472 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 4473 | EXPECT_EQ( |
| 4474 | IpAddressFamily::IP_UNSPEC, |
| 4475 | visitor_.public_reset_packet_->client_address.host().address_family()); |
| 4476 | |
| 4477 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 4478 | } |
| 4479 | |
| 4480 | TEST_P(QuicFramerTest, PublicResetPacket) { |
| 4481 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 4482 | |
| 4483 | // clang-format off |
| 4484 | PacketFragments packet = { |
| 4485 | // public flags (public reset, 8 byte connection_id) |
| 4486 | {"", |
| 4487 | {0x0E}}, |
| 4488 | // connection_id |
| 4489 | {"", |
| 4490 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4491 | {"Unable to read reset message.", |
| 4492 | { |
| 4493 | // message tag (kPRST) |
| 4494 | 'P', 'R', 'S', 'T', |
| 4495 | // num_entries (2) + padding |
| 4496 | 0x02, 0x00, 0x00, 0x00, |
| 4497 | // tag kRNON |
| 4498 | 'R', 'N', 'O', 'N', |
| 4499 | // end offset 8 |
| 4500 | 0x08, 0x00, 0x00, 0x00, |
| 4501 | // tag kRSEQ |
| 4502 | 'R', 'S', 'E', 'Q', |
| 4503 | // end offset 16 |
| 4504 | 0x10, 0x00, 0x00, 0x00, |
| 4505 | // nonce proof |
| 4506 | 0x89, 0x67, 0x45, 0x23, |
| 4507 | 0x01, 0xEF, 0xCD, 0xAB, |
| 4508 | // rejected packet number |
| 4509 | 0xBC, 0x9A, 0x78, 0x56, |
| 4510 | 0x34, 0x12, 0x00, 0x00, |
| 4511 | } |
| 4512 | } |
| 4513 | }; |
| 4514 | // clang-format on |
| 4515 | |
| 4516 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 4517 | return; |
| 4518 | } |
| 4519 | |
| 4520 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4521 | AssemblePacketFromFragments(packet)); |
| 4522 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4523 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4524 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 4525 | EXPECT_EQ(FramerTestConnectionId(), |
| 4526 | visitor_.public_reset_packet_->connection_id); |
| 4527 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 4528 | EXPECT_EQ( |
| 4529 | IpAddressFamily::IP_UNSPEC, |
| 4530 | visitor_.public_reset_packet_->client_address.host().address_family()); |
| 4531 | |
| 4532 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 4533 | } |
| 4534 | |
| 4535 | TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) { |
| 4536 | // clang-format off |
| 4537 | unsigned char packet[] = { |
| 4538 | // public flags (public reset, 8 byte connection_id) |
| 4539 | 0x0A, |
| 4540 | // connection_id |
| 4541 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4542 | // message tag (kPRST) |
| 4543 | 'P', 'R', 'S', 'T', |
| 4544 | // num_entries (2) + padding |
| 4545 | 0x02, 0x00, 0x00, 0x00, |
| 4546 | // tag kRNON |
| 4547 | 'R', 'N', 'O', 'N', |
| 4548 | // end offset 8 |
| 4549 | 0x08, 0x00, 0x00, 0x00, |
| 4550 | // tag kRSEQ |
| 4551 | 'R', 'S', 'E', 'Q', |
| 4552 | // end offset 16 |
| 4553 | 0x10, 0x00, 0x00, 0x00, |
| 4554 | // nonce proof |
| 4555 | 0x89, 0x67, 0x45, 0x23, |
| 4556 | 0x01, 0xEF, 0xCD, 0xAB, |
| 4557 | // rejected packet number |
| 4558 | 0xBC, 0x9A, 0x78, 0x56, |
| 4559 | 0x34, 0x12, 0x00, 0x00, |
| 4560 | // trailing junk |
| 4561 | 'j', 'u', 'n', 'k', |
| 4562 | }; |
| 4563 | // clang-format on |
| 4564 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 4565 | return; |
| 4566 | } |
| 4567 | |
| 4568 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 4569 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 4570 | ASSERT_EQ(QUIC_INVALID_PUBLIC_RST_PACKET, framer_.error()); |
| 4571 | EXPECT_EQ("Unable to read reset message.", framer_.detailed_error()); |
| 4572 | } |
| 4573 | |
| 4574 | TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) { |
| 4575 | // clang-format off |
| 4576 | PacketFragments packet = { |
| 4577 | // public flags (public reset, 8 byte connection_id) |
| 4578 | {"", |
| 4579 | {0x0A}}, |
| 4580 | // connection_id |
| 4581 | {"", |
| 4582 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4583 | {"Unable to read reset message.", |
| 4584 | { |
| 4585 | // message tag (kPRST) |
| 4586 | 'P', 'R', 'S', 'T', |
| 4587 | // num_entries (2) + padding |
| 4588 | 0x03, 0x00, 0x00, 0x00, |
| 4589 | // tag kRNON |
| 4590 | 'R', 'N', 'O', 'N', |
| 4591 | // end offset 8 |
| 4592 | 0x08, 0x00, 0x00, 0x00, |
| 4593 | // tag kRSEQ |
| 4594 | 'R', 'S', 'E', 'Q', |
| 4595 | // end offset 16 |
| 4596 | 0x10, 0x00, 0x00, 0x00, |
| 4597 | // tag kCADR |
| 4598 | 'C', 'A', 'D', 'R', |
| 4599 | // end offset 24 |
| 4600 | 0x18, 0x00, 0x00, 0x00, |
| 4601 | // nonce proof |
| 4602 | 0x89, 0x67, 0x45, 0x23, |
| 4603 | 0x01, 0xEF, 0xCD, 0xAB, |
| 4604 | // rejected packet number |
| 4605 | 0xBC, 0x9A, 0x78, 0x56, |
| 4606 | 0x34, 0x12, 0x00, 0x00, |
| 4607 | // client address: 4.31.198.44:443 |
| 4608 | 0x02, 0x00, |
| 4609 | 0x04, 0x1F, 0xC6, 0x2C, |
| 4610 | 0xBB, 0x01, |
| 4611 | } |
| 4612 | } |
| 4613 | }; |
| 4614 | // clang-format on |
| 4615 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 4616 | return; |
| 4617 | } |
| 4618 | |
| 4619 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4620 | AssemblePacketFromFragments(packet)); |
| 4621 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4622 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4623 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 4624 | EXPECT_EQ(FramerTestConnectionId(), |
| 4625 | visitor_.public_reset_packet_->connection_id); |
| 4626 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 4627 | EXPECT_EQ("4.31.198.44", |
| 4628 | visitor_.public_reset_packet_->client_address.host().ToString()); |
| 4629 | EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); |
| 4630 | |
| 4631 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 4632 | } |
| 4633 | |
| 4634 | TEST_P(QuicFramerTest, IetfStatelessResetPacket) { |
| 4635 | // clang-format off |
| 4636 | unsigned char packet[] = { |
| 4637 | // type (short packet, 1 byte packet number) |
| 4638 | 0x50, |
| 4639 | // connection_id |
| 4640 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4641 | // Random bytes |
| 4642 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 4643 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 4644 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 4645 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 4646 | // stateless reset token |
| 4647 | 0xB5, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4648 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4649 | }; |
| 4650 | // clang-format on |
| 4651 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 4652 | return; |
| 4653 | } |
| 4654 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4655 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4656 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 4657 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, QuicMakeUnique<NullDecrypter>( |
| 4658 | Perspective::IS_CLIENT)); |
| 4659 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 4660 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 4661 | } else { |
| 4662 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 4663 | QuicMakeUnique<NullDecrypter>(Perspective::IS_CLIENT)); |
| 4664 | framer_.SetAlternativeDecrypter( |
| 4665 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 4666 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4667 | // This packet cannot be decrypted because diversification nonce is missing. |
| 4668 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 4669 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 4670 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4671 | ASSERT_TRUE(visitor_.stateless_reset_packet_.get()); |
| 4672 | EXPECT_EQ(kTestStatelessResetToken, |
| 4673 | visitor_.stateless_reset_packet_->stateless_reset_token); |
| 4674 | } |
| 4675 | |
| 4676 | TEST_P(QuicFramerTest, IetfStatelessResetPacketInvalidStatelessResetToken) { |
| 4677 | // clang-format off |
| 4678 | unsigned char packet[] = { |
| 4679 | // type (short packet, 1 byte packet number) |
| 4680 | 0x50, |
| 4681 | // connection_id |
| 4682 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4683 | // stateless reset token |
| 4684 | 0xB6, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4685 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4686 | }; |
| 4687 | // clang-format on |
| 4688 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 4689 | return; |
| 4690 | } |
| 4691 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4692 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4693 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 4694 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, QuicMakeUnique<NullDecrypter>( |
| 4695 | Perspective::IS_CLIENT)); |
| 4696 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 4697 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 4698 | } else { |
| 4699 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 4700 | QuicMakeUnique<NullDecrypter>(Perspective::IS_CLIENT)); |
| 4701 | framer_.SetAlternativeDecrypter( |
| 4702 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 4703 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4704 | // This packet cannot be decrypted because diversification nonce is missing. |
| 4705 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 4706 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 4707 | EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error()); |
| 4708 | ASSERT_FALSE(visitor_.stateless_reset_packet_); |
| 4709 | } |
| 4710 | |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 4711 | TEST_P(QuicFramerTest, VersionNegotiationPacketClient) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4712 | // clang-format off |
| 4713 | PacketFragments packet = { |
| 4714 | // public flags (version, 8 byte connection_id) |
| 4715 | {"", |
| 4716 | {0x29}}, |
| 4717 | // connection_id |
| 4718 | {"", |
| 4719 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4720 | // version tag |
| 4721 | {"Unable to read supported version in negotiation.", |
| 4722 | {QUIC_VERSION_BYTES, |
| 4723 | 'Q', '2', '.', '0'}}, |
| 4724 | }; |
| 4725 | |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4726 | PacketFragments ietf_packet = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4727 | // type (long header) |
| 4728 | {"", |
| 4729 | {0x8F}}, |
| 4730 | // version tag |
| 4731 | {"", |
| 4732 | {0x00, 0x00, 0x00, 0x00}}, |
| 4733 | {"", |
| 4734 | {0x05}}, |
| 4735 | // connection_id |
| 4736 | {"", |
| 4737 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4738 | // Supported versions |
| 4739 | {"Unable to read supported version in negotiation.", |
| 4740 | {QUIC_VERSION_BYTES, |
| 4741 | 'Q', '2', '.', '0'}}, |
| 4742 | }; |
| 4743 | // clang-format on |
| 4744 | |
| 4745 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 4746 | |
| 4747 | PacketFragments& fragments = |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4748 | framer_.transport_version() > QUIC_VERSION_43 ? ietf_packet : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4749 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4750 | AssemblePacketFromFragments(fragments)); |
| 4751 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4752 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4753 | ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); |
nharper | 4fd1105 | 2019-06-04 14:23:22 -0700 | [diff] [blame^] | 4754 | EXPECT_EQ(1u, visitor_.version_negotiation_packet_->versions.size()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4755 | EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); |
| 4756 | |
| 4757 | // Remove the last version from the packet so that every truncated |
| 4758 | // version of the packet is invalid, otherwise checking boundaries |
| 4759 | // is annoyingly complicated. |
| 4760 | for (size_t i = 0; i < 4; ++i) { |
| 4761 | fragments.back().fragment.pop_back(); |
| 4762 | } |
| 4763 | CheckFramingBoundaries(fragments, QUIC_INVALID_VERSION_NEGOTIATION_PACKET); |
| 4764 | } |
| 4765 | |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 4766 | TEST_P(QuicFramerTest, VersionNegotiationPacketServer) { |
| 4767 | if (!GetQuicRestartFlag(quic_server_drop_version_negotiation)) { |
| 4768 | return; |
| 4769 | } |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4770 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 4771 | return; |
| 4772 | } |
| 4773 | |
| 4774 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 4775 | // clang-format off |
| 4776 | unsigned char packet[] = { |
| 4777 | // public flags (long header with all ignored bits set) |
| 4778 | 0xFF, |
| 4779 | // version |
| 4780 | 0x00, 0x00, 0x00, 0x00, |
| 4781 | // connection ID lengths |
| 4782 | 0x50, |
| 4783 | // destination connection ID |
| 4784 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 4785 | // supported versions |
| 4786 | QUIC_VERSION_BYTES, |
| 4787 | 'Q', '2', '.', '0', |
| 4788 | }; |
| 4789 | // clang-format on |
| 4790 | |
| 4791 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 4792 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 4793 | EXPECT_EQ(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, framer_.error()); |
| 4794 | EXPECT_EQ("Server received version negotiation packet.", |
| 4795 | framer_.detailed_error()); |
| 4796 | EXPECT_FALSE(visitor_.version_negotiation_packet_.get()); |
| 4797 | } |
| 4798 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4799 | TEST_P(QuicFramerTest, OldVersionNegotiationPacket) { |
| 4800 | // clang-format off |
| 4801 | PacketFragments packet = { |
| 4802 | // public flags (version, 8 byte connection_id) |
| 4803 | {"", |
| 4804 | {0x2D}}, |
| 4805 | // connection_id |
| 4806 | {"", |
| 4807 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4808 | // version tag |
| 4809 | {"Unable to read supported version in negotiation.", |
| 4810 | {QUIC_VERSION_BYTES, |
| 4811 | 'Q', '2', '.', '0'}}, |
| 4812 | }; |
| 4813 | // clang-format on |
| 4814 | |
| 4815 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 4816 | return; |
| 4817 | } |
| 4818 | |
| 4819 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 4820 | |
| 4821 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4822 | AssemblePacketFromFragments(packet)); |
| 4823 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4824 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4825 | ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); |
nharper | 4fd1105 | 2019-06-04 14:23:22 -0700 | [diff] [blame^] | 4826 | EXPECT_EQ(1u, visitor_.version_negotiation_packet_->versions.size()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4827 | EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); |
| 4828 | |
| 4829 | // Remove the last version from the packet so that every truncated |
| 4830 | // version of the packet is invalid, otherwise checking boundaries |
| 4831 | // is annoyingly complicated. |
| 4832 | for (size_t i = 0; i < 4; ++i) { |
| 4833 | packet.back().fragment.pop_back(); |
| 4834 | } |
| 4835 | CheckFramingBoundaries(packet, QUIC_INVALID_VERSION_NEGOTIATION_PACKET); |
| 4836 | } |
| 4837 | |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 4838 | TEST_P(QuicFramerTest, ParseIetfRetryPacket) { |
| 4839 | if (!framer_.version().SupportsRetry()) { |
| 4840 | return; |
| 4841 | } |
| 4842 | // IETF RETRY is only sent from client to server. |
| 4843 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 4844 | // clang-format off |
| 4845 | unsigned char packet[] = { |
| 4846 | // public flags (long header with packet type RETRY and ODCIL=8) |
| 4847 | 0xF5, |
| 4848 | // version |
| 4849 | QUIC_VERSION_BYTES, |
| 4850 | // connection ID lengths |
| 4851 | 0x05, |
| 4852 | // source connection ID |
| 4853 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 4854 | // original destination connection ID |
| 4855 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4856 | // retry token |
| 4857 | 'H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'i', 's', |
| 4858 | ' ', 'i', 's', ' ', 'R', 'E', 'T', 'R', 'Y', '!', |
| 4859 | }; |
| 4860 | // clang-format on |
| 4861 | |
| 4862 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 4863 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 4864 | |
| 4865 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4866 | ASSERT_TRUE(visitor_.header_.get()); |
| 4867 | |
| 4868 | ASSERT_TRUE(visitor_.retry_original_connection_id_.get()); |
| 4869 | ASSERT_TRUE(visitor_.retry_new_connection_id_.get()); |
| 4870 | ASSERT_TRUE(visitor_.retry_token_.get()); |
| 4871 | |
| 4872 | EXPECT_EQ(FramerTestConnectionId(), |
| 4873 | *visitor_.retry_original_connection_id_.get()); |
| 4874 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), |
| 4875 | *visitor_.retry_new_connection_id_.get()); |
| 4876 | EXPECT_EQ("Hello this is RETRY!", *visitor_.retry_token_.get()); |
| 4877 | } |
| 4878 | |
| 4879 | TEST_P(QuicFramerTest, RejectIetfRetryPacketAsServer) { |
| 4880 | if (!framer_.version().SupportsRetry()) { |
| 4881 | return; |
| 4882 | } |
| 4883 | // IETF RETRY is only sent from client to server. |
| 4884 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 4885 | // clang-format off |
| 4886 | unsigned char packet[] = { |
| 4887 | // public flags (long header with packet type RETRY and ODCIL=8) |
| 4888 | 0xF5, |
| 4889 | // version |
| 4890 | QUIC_VERSION_BYTES, |
| 4891 | // connection ID lengths |
| 4892 | 0x05, |
| 4893 | // source connection ID |
| 4894 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 4895 | // original destination connection ID |
| 4896 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4897 | // retry token |
| 4898 | 'H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'i', 's', |
| 4899 | ' ', 'i', 's', ' ', 'R', 'E', 'T', 'R', 'Y', '!', |
| 4900 | }; |
| 4901 | // clang-format on |
| 4902 | |
| 4903 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 4904 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 4905 | |
| 4906 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
| 4907 | EXPECT_EQ("Client-initiated RETRY is invalid.", framer_.detailed_error()); |
| 4908 | } |
| 4909 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4910 | TEST_P(QuicFramerTest, BuildPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 4911 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4912 | QuicPacketHeader header; |
| 4913 | header.destination_connection_id = FramerTestConnectionId(); |
| 4914 | header.reset_flag = false; |
| 4915 | header.version_flag = false; |
| 4916 | header.packet_number = kPacketNumber; |
| 4917 | |
| 4918 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 4919 | |
| 4920 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 4921 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4922 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 4923 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4924 | // connection_id |
| 4925 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4926 | // packet number |
| 4927 | 0x12, 0x34, 0x56, 0x78, |
| 4928 | |
| 4929 | // frame type (padding frame) |
| 4930 | 0x00, |
| 4931 | 0x00, 0x00, 0x00, 0x00 |
| 4932 | }; |
| 4933 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 4934 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4935 | // type (short header, 4 byte packet number) |
| 4936 | 0x43, |
| 4937 | // connection_id |
| 4938 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4939 | // packet number |
| 4940 | 0x12, 0x34, 0x56, 0x78, |
| 4941 | |
| 4942 | // frame type (padding frame) |
| 4943 | 0x00, |
| 4944 | 0x00, 0x00, 0x00, 0x00 |
| 4945 | }; |
| 4946 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 4947 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4948 | // type (short header, 4 byte packet number) |
| 4949 | 0x43, |
| 4950 | // connection_id |
| 4951 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4952 | // packet number |
| 4953 | 0x12, 0x34, 0x56, 0x78, |
| 4954 | |
| 4955 | // frame type (padding frame) |
| 4956 | 0x00, |
| 4957 | 0x00, 0x00, 0x00, 0x00 |
| 4958 | }; |
| 4959 | // clang-format on |
| 4960 | |
| 4961 | unsigned char* p = packet; |
| 4962 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4963 | p = packet99; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4964 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4965 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4966 | } |
| 4967 | |
| 4968 | uint64_t header_size = GetPacketHeaderSize( |
| 4969 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 4970 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 4971 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 4972 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 4973 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4974 | |
| 4975 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 4976 | ASSERT_TRUE(data != nullptr); |
| 4977 | |
| 4978 | test::CompareCharArraysWithHexError( |
| 4979 | "constructed packet", data->data(), data->length(), AsChars(p), |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 4980 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet46) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4981 | : QUIC_ARRAYSIZE(packet)); |
| 4982 | } |
| 4983 | |
| 4984 | TEST_P(QuicFramerTest, BuildStreamFramePacketWithNewPaddingFrame) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 4985 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4986 | QuicPacketHeader header; |
| 4987 | header.destination_connection_id = FramerTestConnectionId(); |
| 4988 | header.reset_flag = false; |
| 4989 | header.version_flag = false; |
| 4990 | header.packet_number = kPacketNumber; |
| 4991 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
| 4992 | QuicStringPiece("hello world!")); |
| 4993 | QuicPaddingFrame padding_frame(2); |
| 4994 | QuicFrames frames = {QuicFrame(padding_frame), QuicFrame(stream_frame), |
| 4995 | QuicFrame(padding_frame)}; |
| 4996 | |
| 4997 | // clang-format off |
| 4998 | unsigned char packet[] = { |
| 4999 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5000 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5001 | // connection_id |
| 5002 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5003 | // packet number |
| 5004 | 0x12, 0x34, 0x56, 0x78, |
| 5005 | |
| 5006 | // paddings |
| 5007 | 0x00, 0x00, |
| 5008 | // frame type (stream frame with fin) |
| 5009 | 0xFF, |
| 5010 | // stream id |
| 5011 | 0x01, 0x02, 0x03, 0x04, |
| 5012 | // offset |
| 5013 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5014 | 0x32, 0x10, 0x76, 0x54, |
| 5015 | // data length |
| 5016 | 0x00, 0x0c, |
| 5017 | // data |
| 5018 | 'h', 'e', 'l', 'l', |
| 5019 | 'o', ' ', 'w', 'o', |
| 5020 | 'r', 'l', 'd', '!', |
| 5021 | // paddings |
| 5022 | 0x00, 0x00, |
| 5023 | }; |
| 5024 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5025 | unsigned char packet46[] = { |
| 5026 | // type (short header, 4 byte packet number) |
| 5027 | 0x43, |
| 5028 | // connection_id |
| 5029 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5030 | // packet number |
| 5031 | 0x12, 0x34, 0x56, 0x78, |
| 5032 | |
| 5033 | // paddings |
| 5034 | 0x00, 0x00, |
| 5035 | // frame type (stream frame with fin) |
| 5036 | 0xFF, |
| 5037 | // stream id |
| 5038 | 0x01, 0x02, 0x03, 0x04, |
| 5039 | // offset |
| 5040 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5041 | 0x32, 0x10, 0x76, 0x54, |
| 5042 | // data length |
| 5043 | 0x00, 0x0c, |
| 5044 | // data |
| 5045 | 'h', 'e', 'l', 'l', |
| 5046 | 'o', ' ', 'w', 'o', |
| 5047 | 'r', 'l', 'd', '!', |
| 5048 | // paddings |
| 5049 | 0x00, 0x00, |
| 5050 | }; |
| 5051 | |
| 5052 | unsigned char packet99[] = { |
| 5053 | // type (short header, 4 byte packet number) |
| 5054 | 0x43, |
| 5055 | // connection_id |
| 5056 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5057 | // packet number |
| 5058 | 0x12, 0x34, 0x56, 0x78, |
| 5059 | |
| 5060 | // paddings |
| 5061 | 0x00, 0x00, |
| 5062 | // frame type (IETF_STREAM with FIN, LEN, and OFFSET bits set) |
| 5063 | 0x08 | 0x01 | 0x02 | 0x04, |
| 5064 | // stream id |
| 5065 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 5066 | // offset |
| 5067 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 5068 | 0x32, 0x10, 0x76, 0x54, |
| 5069 | // data length |
| 5070 | kVarInt62OneByte + 0x0c, |
| 5071 | // data |
| 5072 | 'h', 'e', 'l', 'l', |
| 5073 | 'o', ' ', 'w', 'o', |
| 5074 | 'r', 'l', 'd', '!', |
| 5075 | // paddings |
| 5076 | 0x00, 0x00, |
| 5077 | }; |
| 5078 | // clang-format on |
| 5079 | |
| 5080 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5081 | ASSERT_TRUE(data != nullptr); |
| 5082 | |
| 5083 | unsigned char* p = packet; |
| 5084 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 5085 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5086 | p = packet99; |
| 5087 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5088 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5089 | p = packet46; |
| 5090 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5091 | } |
| 5092 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 5093 | |
| 5094 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 5095 | data->length(), AsChars(p), p_size); |
| 5096 | } |
| 5097 | |
| 5098 | TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5099 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5100 | QuicPacketHeader header; |
| 5101 | header.destination_connection_id = FramerTestConnectionId(); |
| 5102 | header.reset_flag = false; |
| 5103 | header.version_flag = false; |
| 5104 | header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; |
| 5105 | header.packet_number = kPacketNumber; |
| 5106 | |
| 5107 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5108 | |
| 5109 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5110 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5111 | // public flags (8 byte connection_id and 4 byte packet number) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5112 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5113 | // connection_id |
| 5114 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5115 | // packet number |
| 5116 | 0x12, 0x34, 0x56, 0x78, |
| 5117 | |
| 5118 | // frame type (padding frame) |
| 5119 | 0x00, |
| 5120 | 0x00, 0x00, 0x00, 0x00 |
| 5121 | }; |
| 5122 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5123 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5124 | // type (short header, 4 byte packet number) |
| 5125 | 0x43, |
| 5126 | // connection_id |
| 5127 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5128 | // packet number |
| 5129 | 0x12, 0x34, 0x56, 0x78, |
| 5130 | |
| 5131 | // frame type (padding frame) |
| 5132 | 0x00, |
| 5133 | 0x00, 0x00, 0x00, 0x00 |
| 5134 | }; |
| 5135 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5136 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5137 | // type (short header, 4 byte packet number) |
| 5138 | 0x43, |
| 5139 | // connection_id |
| 5140 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5141 | // packet number |
| 5142 | 0x12, 0x34, 0x56, 0x78, |
| 5143 | |
| 5144 | // frame type (padding frame) |
| 5145 | 0x00, |
| 5146 | 0x00, 0x00, 0x00, 0x00 |
| 5147 | }; |
| 5148 | // clang-format on |
| 5149 | |
| 5150 | unsigned char* p = packet; |
| 5151 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5152 | p = packet99; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5153 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5154 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5155 | } |
| 5156 | |
| 5157 | uint64_t header_size = GetPacketHeaderSize( |
| 5158 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 5159 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 5160 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 5161 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5162 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5163 | |
| 5164 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5165 | ASSERT_TRUE(data != nullptr); |
| 5166 | |
| 5167 | test::CompareCharArraysWithHexError( |
| 5168 | "constructed packet", data->data(), data->length(), AsChars(p), |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5169 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet46) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5170 | : QUIC_ARRAYSIZE(packet)); |
| 5171 | } |
| 5172 | |
| 5173 | TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5174 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5175 | QuicPacketHeader header; |
| 5176 | header.destination_connection_id = FramerTestConnectionId(); |
| 5177 | header.reset_flag = false; |
| 5178 | header.version_flag = false; |
| 5179 | header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; |
| 5180 | header.packet_number = kPacketNumber; |
| 5181 | |
| 5182 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5183 | |
| 5184 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5185 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5186 | // public flags (8 byte connection_id and 2 byte packet number) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5187 | 0x1C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5188 | // connection_id |
| 5189 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5190 | // packet number |
| 5191 | 0x56, 0x78, |
| 5192 | |
| 5193 | // frame type (padding frame) |
| 5194 | 0x00, |
| 5195 | 0x00, 0x00, 0x00, 0x00 |
| 5196 | }; |
| 5197 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5198 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5199 | // type (short header, 2 byte packet number) |
| 5200 | 0x41, |
| 5201 | // connection_id |
| 5202 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5203 | // packet number |
| 5204 | 0x56, 0x78, |
| 5205 | |
| 5206 | // frame type (padding frame) |
| 5207 | 0x00, |
| 5208 | 0x00, 0x00, 0x00, 0x00 |
| 5209 | }; |
| 5210 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5211 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5212 | // type (short header, 2 byte packet number) |
| 5213 | 0x41, |
| 5214 | // connection_id |
| 5215 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5216 | // packet number |
| 5217 | 0x56, 0x78, |
| 5218 | |
| 5219 | // frame type (padding frame) |
| 5220 | 0x00, |
| 5221 | 0x00, 0x00, 0x00, 0x00 |
| 5222 | }; |
| 5223 | // clang-format on |
| 5224 | |
| 5225 | unsigned char* p = packet; |
| 5226 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5227 | p = packet99; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5228 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5229 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | uint64_t header_size = GetPacketHeaderSize( |
| 5233 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 5234 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 5235 | !kIncludeDiversificationNonce, PACKET_2BYTE_PACKET_NUMBER, |
| 5236 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5237 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5238 | |
| 5239 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5240 | ASSERT_TRUE(data != nullptr); |
| 5241 | |
| 5242 | test::CompareCharArraysWithHexError( |
| 5243 | "constructed packet", data->data(), data->length(), AsChars(p), |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5244 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet46) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5245 | : QUIC_ARRAYSIZE(packet)); |
| 5246 | } |
| 5247 | |
| 5248 | TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5249 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5250 | QuicPacketHeader header; |
| 5251 | header.destination_connection_id = FramerTestConnectionId(); |
| 5252 | header.reset_flag = false; |
| 5253 | header.version_flag = false; |
| 5254 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 5255 | header.packet_number = kPacketNumber; |
| 5256 | |
| 5257 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5258 | |
| 5259 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5260 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5261 | // public flags (8 byte connection_id and 1 byte packet number) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5262 | 0x0C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5263 | // connection_id |
| 5264 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5265 | // packet number |
| 5266 | 0x78, |
| 5267 | |
| 5268 | // frame type (padding frame) |
| 5269 | 0x00, |
| 5270 | 0x00, 0x00, 0x00, 0x00 |
| 5271 | }; |
| 5272 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5273 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5274 | // type (short header, 1 byte packet number) |
| 5275 | 0x40, |
| 5276 | // connection_id |
| 5277 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5278 | // packet number |
| 5279 | 0x78, |
| 5280 | |
| 5281 | // frame type (padding frame) |
| 5282 | 0x00, |
| 5283 | 0x00, 0x00, 0x00, 0x00 |
| 5284 | }; |
| 5285 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5286 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5287 | // type (short header, 1 byte packet number) |
| 5288 | 0x40, |
| 5289 | // connection_id |
| 5290 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5291 | // packet number |
| 5292 | 0x78, |
| 5293 | |
| 5294 | // frame type (padding frame) |
| 5295 | 0x00, |
| 5296 | 0x00, 0x00, 0x00, 0x00 |
| 5297 | }; |
| 5298 | // clang-format on |
| 5299 | |
| 5300 | unsigned char* p = packet; |
| 5301 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5302 | p = packet99; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5303 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5304 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | uint64_t header_size = GetPacketHeaderSize( |
| 5308 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 5309 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 5310 | !kIncludeDiversificationNonce, PACKET_1BYTE_PACKET_NUMBER, |
| 5311 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5312 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5313 | |
| 5314 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5315 | ASSERT_TRUE(data != nullptr); |
| 5316 | |
| 5317 | test::CompareCharArraysWithHexError( |
| 5318 | "constructed packet", data->data(), data->length(), AsChars(p), |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5319 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet46) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5320 | : QUIC_ARRAYSIZE(packet)); |
| 5321 | } |
| 5322 | |
| 5323 | TEST_P(QuicFramerTest, BuildStreamFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5324 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5325 | QuicPacketHeader header; |
| 5326 | header.destination_connection_id = FramerTestConnectionId(); |
| 5327 | header.reset_flag = false; |
| 5328 | header.version_flag = false; |
| 5329 | header.packet_number = kPacketNumber; |
| 5330 | if (QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 5331 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 5332 | } |
| 5333 | |
| 5334 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
| 5335 | QuicStringPiece("hello world!")); |
| 5336 | |
| 5337 | QuicFrames frames = {QuicFrame(stream_frame)}; |
| 5338 | |
| 5339 | // clang-format off |
| 5340 | unsigned char packet[] = { |
| 5341 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5342 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5343 | // connection_id |
| 5344 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5345 | // packet number |
| 5346 | 0x12, 0x34, 0x56, 0x78, |
| 5347 | |
| 5348 | // frame type (stream frame with fin and no length) |
| 5349 | 0xDF, |
| 5350 | // stream id |
| 5351 | 0x01, 0x02, 0x03, 0x04, |
| 5352 | // offset |
| 5353 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5354 | 0x32, 0x10, 0x76, 0x54, |
| 5355 | // data |
| 5356 | 'h', 'e', 'l', 'l', |
| 5357 | 'o', ' ', 'w', 'o', |
| 5358 | 'r', 'l', 'd', '!', |
| 5359 | }; |
| 5360 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5361 | unsigned char packet46[] = { |
| 5362 | // type (short header, 4 byte packet number) |
| 5363 | 0x43, |
| 5364 | // connection_id |
| 5365 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5366 | // packet number |
| 5367 | 0x12, 0x34, 0x56, 0x78, |
| 5368 | |
| 5369 | // frame type (stream frame with fin and no length) |
| 5370 | 0xDF, |
| 5371 | // stream id |
| 5372 | 0x01, 0x02, 0x03, 0x04, |
| 5373 | // offset |
| 5374 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5375 | 0x32, 0x10, 0x76, 0x54, |
| 5376 | // data |
| 5377 | 'h', 'e', 'l', 'l', |
| 5378 | 'o', ' ', 'w', 'o', |
| 5379 | 'r', 'l', 'd', '!', |
| 5380 | }; |
| 5381 | |
| 5382 | unsigned char packet99[] = { |
| 5383 | // type (short header, 4 byte packet number) |
| 5384 | 0x43, |
| 5385 | // connection_id |
| 5386 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5387 | // packet number |
| 5388 | 0x12, 0x34, 0x56, 0x78, |
| 5389 | |
| 5390 | // frame type (IETF_STREAM frame with FIN and OFFSET, no length) |
| 5391 | 0x08 | 0x01 | 0x04, |
| 5392 | // stream id |
| 5393 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 5394 | // offset |
| 5395 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 5396 | 0x32, 0x10, 0x76, 0x54, |
| 5397 | // data |
| 5398 | 'h', 'e', 'l', 'l', |
| 5399 | 'o', ' ', 'w', 'o', |
| 5400 | 'r', 'l', 'd', '!', |
| 5401 | }; |
| 5402 | // clang-format on |
| 5403 | |
| 5404 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5405 | ASSERT_TRUE(data != nullptr); |
| 5406 | |
| 5407 | unsigned char* p = packet; |
| 5408 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 5409 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5410 | p = packet99; |
| 5411 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5412 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5413 | p = packet46; |
| 5414 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5415 | } |
| 5416 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 5417 | data->length(), AsChars(p), p_size); |
| 5418 | } |
| 5419 | |
| 5420 | TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) { |
| 5421 | QuicPacketHeader header; |
| 5422 | header.destination_connection_id = FramerTestConnectionId(); |
| 5423 | header.reset_flag = false; |
| 5424 | header.version_flag = true; |
| 5425 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5426 | header.long_packet_type = ZERO_RTT_PROTECTED; |
| 5427 | } |
| 5428 | header.packet_number = kPacketNumber; |
| 5429 | if (QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 5430 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 5431 | } |
| 5432 | |
| 5433 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
| 5434 | QuicStringPiece("hello world!")); |
| 5435 | QuicFrames frames = {QuicFrame(stream_frame)}; |
| 5436 | |
| 5437 | // clang-format off |
| 5438 | unsigned char packet[] = { |
| 5439 | // public flags (version, 8 byte connection_id) |
| 5440 | 0x2D, |
| 5441 | // connection_id |
| 5442 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5443 | // version tag |
| 5444 | QUIC_VERSION_BYTES, |
| 5445 | // packet number |
| 5446 | 0x12, 0x34, 0x56, 0x78, |
| 5447 | |
| 5448 | // frame type (stream frame with fin and no length) |
| 5449 | 0xDF, |
| 5450 | // stream id |
| 5451 | 0x01, 0x02, 0x03, 0x04, |
| 5452 | // offset |
| 5453 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 5454 | // data |
| 5455 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 5456 | }; |
| 5457 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5458 | unsigned char packet46[] = { |
| 5459 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 5460 | 0xD3, |
| 5461 | // version tag |
| 5462 | QUIC_VERSION_BYTES, |
| 5463 | // connection_id length |
| 5464 | 0x50, |
| 5465 | // connection_id |
| 5466 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5467 | // packet number |
| 5468 | 0x12, 0x34, 0x56, 0x78, |
| 5469 | |
| 5470 | // frame type (stream frame with fin and no length) |
| 5471 | 0xDF, |
| 5472 | // stream id |
| 5473 | 0x01, 0x02, 0x03, 0x04, |
| 5474 | // offset |
| 5475 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 5476 | // data |
| 5477 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 5478 | }; |
| 5479 | |
| 5480 | unsigned char packet99[] = { |
| 5481 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 5482 | 0xD3, |
| 5483 | // version tag |
| 5484 | QUIC_VERSION_BYTES, |
| 5485 | // connection_id length |
| 5486 | 0x50, |
| 5487 | // connection_id |
| 5488 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5489 | // length |
| 5490 | 0x40, 0x1D, |
| 5491 | // packet number |
| 5492 | 0x12, 0x34, 0x56, 0x78, |
| 5493 | |
| 5494 | // frame type (IETF_STREAM frame with fin and offset, no length) |
| 5495 | 0x08 | 0x01 | 0x04, |
| 5496 | // stream id |
| 5497 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 5498 | // offset |
| 5499 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 5500 | // data |
| 5501 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 5502 | }; |
| 5503 | // clang-format on |
| 5504 | |
| 5505 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5506 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5507 | ASSERT_TRUE(data != nullptr); |
| 5508 | |
| 5509 | unsigned char* p = packet; |
| 5510 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 5511 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5512 | p = packet99; |
| 5513 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5514 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5515 | p = packet46; |
| 5516 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5517 | } |
| 5518 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 5519 | data->length(), AsChars(p), p_size); |
| 5520 | } |
| 5521 | |
| 5522 | TEST_P(QuicFramerTest, BuildCryptoFramePacket) { |
| 5523 | if (framer_.transport_version() < QUIC_VERSION_99) { |
| 5524 | // CRYPTO frames aren't supported prior to v46. |
| 5525 | return; |
| 5526 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5527 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5528 | QuicPacketHeader header; |
| 5529 | header.destination_connection_id = FramerTestConnectionId(); |
| 5530 | header.reset_flag = false; |
| 5531 | header.version_flag = false; |
| 5532 | header.packet_number = kPacketNumber; |
| 5533 | |
| 5534 | SimpleDataProducer data_producer; |
| 5535 | framer_.set_data_producer(&data_producer); |
| 5536 | |
| 5537 | QuicStringPiece crypto_frame_contents("hello world!"); |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 5538 | QuicCryptoFrame crypto_frame(ENCRYPTION_INITIAL, kStreamOffset, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5539 | crypto_frame_contents.length()); |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 5540 | data_producer.SaveCryptoData(ENCRYPTION_INITIAL, kStreamOffset, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5541 | crypto_frame_contents); |
| 5542 | |
| 5543 | QuicFrames frames = {QuicFrame(&crypto_frame)}; |
| 5544 | |
| 5545 | // clang-format off |
| 5546 | unsigned char packet[] = { |
| 5547 | // type (short header, 4 byte packet number) |
| 5548 | 0x43, |
| 5549 | // connection_id |
| 5550 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5551 | // packet number |
| 5552 | 0x12, 0x34, 0x56, 0x78, |
| 5553 | |
| 5554 | // frame type (IETF_CRYPTO frame) |
| 5555 | 0x06, |
| 5556 | // offset |
| 5557 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 5558 | 0x32, 0x10, 0x76, 0x54, |
| 5559 | // length |
| 5560 | kVarInt62OneByte + 12, |
| 5561 | // data |
| 5562 | 'h', 'e', 'l', 'l', |
| 5563 | 'o', ' ', 'w', 'o', |
| 5564 | 'r', 'l', 'd', '!', |
| 5565 | }; |
| 5566 | // clang-format on |
| 5567 | |
| 5568 | size_t packet_size = QUIC_ARRAYSIZE(packet); |
| 5569 | |
| 5570 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5571 | ASSERT_TRUE(data != nullptr); |
| 5572 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 5573 | data->length(), AsChars(packet), |
| 5574 | packet_size); |
| 5575 | } |
| 5576 | |
| 5577 | TEST_P(QuicFramerTest, CryptoFrame) { |
| 5578 | if (framer_.transport_version() < QUIC_VERSION_99) { |
| 5579 | // CRYPTO frames aren't supported prior to v46. |
| 5580 | return; |
| 5581 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5582 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5583 | |
| 5584 | // clang-format off |
| 5585 | PacketFragments packet = { |
| 5586 | // type (short header, 4 byte packet number) |
| 5587 | {"", |
| 5588 | {0x43}}, |
| 5589 | // connection_id |
| 5590 | {"", |
| 5591 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5592 | // packet number |
| 5593 | {"", |
| 5594 | {0x12, 0x34, 0x56, 0x78}}, |
| 5595 | // frame type (IETF_CRYPTO frame) |
| 5596 | {"", |
| 5597 | {0x06}}, |
| 5598 | // offset |
| 5599 | {"", |
| 5600 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 5601 | 0x32, 0x10, 0x76, 0x54}}, |
| 5602 | // data length |
| 5603 | {"Invalid data length.", |
| 5604 | {kVarInt62OneByte + 12}}, |
| 5605 | // data |
| 5606 | {"Unable to read frame data.", |
| 5607 | {'h', 'e', 'l', 'l', |
| 5608 | 'o', ' ', 'w', 'o', |
| 5609 | 'r', 'l', 'd', '!'}}, |
| 5610 | }; |
| 5611 | // clang-format on |
| 5612 | |
| 5613 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5614 | AssemblePacketFromFragments(packet)); |
| 5615 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5616 | |
| 5617 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5618 | ASSERT_TRUE(visitor_.header_.get()); |
| 5619 | EXPECT_TRUE(CheckDecryption( |
| 5620 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5621 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5622 | ASSERT_EQ(1u, visitor_.crypto_frames_.size()); |
| 5623 | QuicCryptoFrame* frame = visitor_.crypto_frames_[0].get(); |
| 5624 | EXPECT_EQ(kStreamOffset, frame->offset); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 5625 | EXPECT_EQ("hello world!", |
| 5626 | std::string(frame->data_buffer, frame->data_length)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5627 | |
| 5628 | CheckFramingBoundaries(packet, QUIC_INVALID_FRAME_DATA); |
| 5629 | } |
| 5630 | |
| 5631 | TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { |
| 5632 | // clang-format off |
| 5633 | unsigned char packet[] = { |
| 5634 | // public flags (version, 8 byte connection_id) |
| 5635 | 0x0D, |
| 5636 | // connection_id |
| 5637 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5638 | // version tag |
| 5639 | QUIC_VERSION_BYTES, |
| 5640 | }; |
dschinazi | 9e92fb3 | 2019-05-08 14:47:24 -0700 | [diff] [blame] | 5641 | unsigned char type44 = 0x80; |
| 5642 | if (GetQuicReloadableFlag(quic_send_version_negotiation_fixed_bit)) { |
| 5643 | type44 = 0xC0; |
| 5644 | } |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5645 | unsigned char ietf_packet[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5646 | // type (long header) |
dschinazi | 9e92fb3 | 2019-05-08 14:47:24 -0700 | [diff] [blame] | 5647 | type44, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5648 | // version tag |
| 5649 | 0x00, 0x00, 0x00, 0x00, |
| 5650 | // connection_id length |
| 5651 | 0x05, |
| 5652 | // connection_id |
| 5653 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5654 | // version tag |
| 5655 | QUIC_VERSION_BYTES, |
| 5656 | }; |
| 5657 | // clang-format on |
| 5658 | unsigned char* p = packet; |
| 5659 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 5660 | if (framer_.transport_version() > QUIC_VERSION_43) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5661 | p = ietf_packet; |
| 5662 | p_size = QUIC_ARRAYSIZE(ietf_packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5663 | } |
| 5664 | |
| 5665 | QuicConnectionId connection_id = FramerTestConnectionId(); |
| 5666 | std::unique_ptr<QuicEncryptedPacket> data( |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 5667 | QuicFramer::BuildVersionNegotiationPacket( |
| 5668 | connection_id, EmptyQuicConnectionId(), |
| 5669 | framer_.transport_version() > QUIC_VERSION_43, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5670 | SupportedVersions(GetParam()))); |
| 5671 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 5672 | data->length(), AsChars(p), p_size); |
| 5673 | } |
| 5674 | |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 5675 | TEST_P(QuicFramerTest, BuildVersionNegotiationPacketWithClientConnectionId) { |
| 5676 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 5677 | // The GQUIC encoding does not support encoding client connection IDs. |
| 5678 | return; |
| 5679 | } |
| 5680 | |
| 5681 | // Client connection IDs cannot be used unless this flag is true. |
| 5682 | SetQuicRestartFlag(quic_do_not_override_connection_id, true); |
| 5683 | |
| 5684 | unsigned char type_byte = 0x80; |
| 5685 | if (GetQuicReloadableFlag(quic_send_version_negotiation_fixed_bit)) { |
| 5686 | type_byte = 0xC0; |
| 5687 | } |
| 5688 | // clang-format off |
| 5689 | unsigned char packet[] = { |
| 5690 | // type (long header) |
| 5691 | type_byte, |
| 5692 | // version tag |
| 5693 | 0x00, 0x00, 0x00, 0x00, |
| 5694 | // connection ID lengths |
| 5695 | 0x55, |
| 5696 | // client/destination connection ID |
| 5697 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 5698 | // server/source connection ID |
| 5699 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5700 | // version tag |
| 5701 | QUIC_VERSION_BYTES, |
| 5702 | }; |
| 5703 | // clang-format on |
| 5704 | |
| 5705 | QuicConnectionId server_connection_id = FramerTestConnectionId(); |
| 5706 | QuicConnectionId client_connection_id = FramerTestConnectionIdPlusOne(); |
| 5707 | std::unique_ptr<QuicEncryptedPacket> data( |
| 5708 | QuicFramer::BuildVersionNegotiationPacket(server_connection_id, |
| 5709 | client_connection_id, true, |
| 5710 | SupportedVersions(GetParam()))); |
| 5711 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 5712 | data->length(), AsChars(packet), |
| 5713 | QUIC_ARRAYSIZE(packet)); |
| 5714 | } |
| 5715 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5716 | TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlock) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5717 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5718 | QuicPacketHeader header; |
| 5719 | header.destination_connection_id = FramerTestConnectionId(); |
| 5720 | header.reset_flag = false; |
| 5721 | header.version_flag = false; |
| 5722 | header.packet_number = kPacketNumber; |
| 5723 | |
| 5724 | // Use kSmallLargestObserved to make this test finished in a short time. |
| 5725 | QuicAckFrame ack_frame = InitAckFrame(kSmallLargestObserved); |
| 5726 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 5727 | |
| 5728 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 5729 | |
| 5730 | // clang-format off |
| 5731 | unsigned char packet[] = { |
| 5732 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5733 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5734 | // connection_id |
| 5735 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5736 | // packet number |
| 5737 | 0x12, 0x34, 0x56, 0x78, |
| 5738 | |
| 5739 | // frame type (ack frame) |
| 5740 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 5741 | 0x45, |
| 5742 | // largest acked |
| 5743 | 0x12, 0x34, |
| 5744 | // Zero delta time. |
| 5745 | 0x00, 0x00, |
| 5746 | // first ack block length. |
| 5747 | 0x12, 0x34, |
| 5748 | // num timestamps. |
| 5749 | 0x00, |
| 5750 | }; |
| 5751 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5752 | unsigned char packet46[] = { |
| 5753 | // type (short header, 4 byte packet number) |
| 5754 | 0x43, |
| 5755 | // connection_id |
| 5756 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5757 | // packet number |
| 5758 | 0x12, 0x34, 0x56, 0x78, |
| 5759 | |
| 5760 | // frame type (ack frame) |
| 5761 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 5762 | 0x45, |
| 5763 | // largest acked |
| 5764 | 0x12, 0x34, |
| 5765 | // Zero delta time. |
| 5766 | 0x00, 0x00, |
| 5767 | // first ack block length. |
| 5768 | 0x12, 0x34, |
| 5769 | // num timestamps. |
| 5770 | 0x00, |
| 5771 | }; |
| 5772 | |
| 5773 | unsigned char packet99[] = { |
| 5774 | // type (short header, 4 byte packet number) |
| 5775 | 0x43, |
| 5776 | // connection_id |
| 5777 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5778 | // packet number |
| 5779 | 0x12, 0x34, 0x56, 0x78, |
| 5780 | |
| 5781 | // frame type (IETF_ACK frame) |
| 5782 | 0x02, |
| 5783 | // largest acked |
| 5784 | kVarInt62TwoBytes + 0x12, 0x34, |
| 5785 | // Zero delta time. |
| 5786 | kVarInt62OneByte + 0x00, |
| 5787 | // Number of additional ack blocks. |
| 5788 | kVarInt62OneByte + 0x00, |
| 5789 | // first ack block length. |
| 5790 | kVarInt62TwoBytes + 0x12, 0x33, |
| 5791 | }; |
| 5792 | // clang-format on |
| 5793 | unsigned char* p = packet; |
| 5794 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 5795 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5796 | p = packet99; |
| 5797 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5798 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5799 | p = packet46; |
| 5800 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5801 | } |
| 5802 | |
| 5803 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5804 | ASSERT_TRUE(data != nullptr); |
| 5805 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 5806 | data->length(), AsChars(p), p_size); |
| 5807 | } |
| 5808 | |
| 5809 | TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlockMaxLength) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5810 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5811 | QuicPacketHeader header; |
| 5812 | header.destination_connection_id = FramerTestConnectionId(); |
| 5813 | header.reset_flag = false; |
| 5814 | header.version_flag = false; |
| 5815 | header.packet_number = kPacketNumber; |
| 5816 | |
| 5817 | QuicAckFrame ack_frame = InitAckFrame(kPacketNumber); |
| 5818 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 5819 | |
| 5820 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 5821 | |
| 5822 | // clang-format off |
| 5823 | unsigned char packet[] = { |
| 5824 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5825 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5826 | // connection_id |
| 5827 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5828 | // packet number |
| 5829 | 0x12, 0x34, 0x56, 0x78, |
| 5830 | |
| 5831 | // frame type (ack frame) |
| 5832 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 5833 | 0x4A, |
| 5834 | // largest acked |
| 5835 | 0x12, 0x34, 0x56, 0x78, |
| 5836 | // Zero delta time. |
| 5837 | 0x00, 0x00, |
| 5838 | // first ack block length. |
| 5839 | 0x12, 0x34, 0x56, 0x78, |
| 5840 | // num timestamps. |
| 5841 | 0x00, |
| 5842 | }; |
| 5843 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5844 | unsigned char packet46[] = { |
| 5845 | // type (short header, 4 byte packet number) |
| 5846 | 0x43, |
| 5847 | // connection_id |
| 5848 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5849 | // packet number |
| 5850 | 0x12, 0x34, 0x56, 0x78, |
| 5851 | |
| 5852 | // frame type (ack frame) |
| 5853 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 5854 | 0x4A, |
| 5855 | // largest acked |
| 5856 | 0x12, 0x34, 0x56, 0x78, |
| 5857 | // Zero delta time. |
| 5858 | 0x00, 0x00, |
| 5859 | // first ack block length. |
| 5860 | 0x12, 0x34, 0x56, 0x78, |
| 5861 | // num timestamps. |
| 5862 | 0x00, |
| 5863 | }; |
| 5864 | |
| 5865 | |
| 5866 | unsigned char packet99[] = { |
| 5867 | // type (short header, 4 byte packet number) |
| 5868 | 0x43, |
| 5869 | // connection_id |
| 5870 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5871 | // packet number |
| 5872 | 0x12, 0x34, 0x56, 0x78, |
| 5873 | |
| 5874 | // frame type (IETF_ACK frame) |
| 5875 | 0x02, |
| 5876 | // largest acked |
| 5877 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 5878 | // Zero delta time. |
| 5879 | kVarInt62OneByte + 0x00, |
| 5880 | // Nr. of additional ack blocks |
| 5881 | kVarInt62OneByte + 0x00, |
| 5882 | // first ack block length. |
| 5883 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 5884 | }; |
| 5885 | // clang-format on |
| 5886 | unsigned char* p = packet; |
| 5887 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 5888 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5889 | p = packet99; |
| 5890 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5891 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5892 | p = packet46; |
| 5893 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5897 | ASSERT_TRUE(data != nullptr); |
| 5898 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 5899 | data->length(), AsChars(p), p_size); |
| 5900 | } |
| 5901 | |
| 5902 | TEST_P(QuicFramerTest, BuildAckFramePacketMultipleAckBlocks) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5903 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5904 | QuicPacketHeader header; |
| 5905 | header.destination_connection_id = FramerTestConnectionId(); |
| 5906 | header.reset_flag = false; |
| 5907 | header.version_flag = false; |
| 5908 | header.packet_number = kPacketNumber; |
| 5909 | |
| 5910 | // Use kSmallLargestObserved to make this test finished in a short time. |
| 5911 | QuicAckFrame ack_frame = |
| 5912 | InitAckFrame({{QuicPacketNumber(1), QuicPacketNumber(5)}, |
| 5913 | {QuicPacketNumber(10), QuicPacketNumber(500)}, |
| 5914 | {QuicPacketNumber(900), kSmallMissingPacket}, |
| 5915 | {kSmallMissingPacket + 1, kSmallLargestObserved + 1}}); |
| 5916 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 5917 | |
| 5918 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 5919 | |
| 5920 | // clang-format off |
| 5921 | unsigned char packet[] = { |
| 5922 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5923 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5924 | // connection_id |
| 5925 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5926 | // packet number |
| 5927 | 0x12, 0x34, 0x56, 0x78, |
| 5928 | |
| 5929 | // frame type (ack frame) |
| 5930 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 5931 | 0x65, |
| 5932 | // largest acked |
| 5933 | 0x12, 0x34, |
| 5934 | // Zero delta time. |
| 5935 | 0x00, 0x00, |
| 5936 | // num ack blocks ranges. |
| 5937 | 0x04, |
| 5938 | // first ack block length. |
| 5939 | 0x00, 0x01, |
| 5940 | // gap to next block. |
| 5941 | 0x01, |
| 5942 | // ack block length. |
| 5943 | 0x0e, 0xaf, |
| 5944 | // gap to next block. |
| 5945 | 0xff, |
| 5946 | // ack block length. |
| 5947 | 0x00, 0x00, |
| 5948 | // gap to next block. |
| 5949 | 0x91, |
| 5950 | // ack block length. |
| 5951 | 0x01, 0xea, |
| 5952 | // gap to next block. |
| 5953 | 0x05, |
| 5954 | // ack block length. |
| 5955 | 0x00, 0x04, |
| 5956 | // num timestamps. |
| 5957 | 0x00, |
| 5958 | }; |
| 5959 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5960 | unsigned char packet46[] = { |
| 5961 | // type (short header, 4 byte packet number) |
| 5962 | 0x43, |
| 5963 | // connection_id |
| 5964 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5965 | // packet number |
| 5966 | 0x12, 0x34, 0x56, 0x78, |
| 5967 | |
| 5968 | // frame type (ack frame) |
| 5969 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 5970 | 0x65, |
| 5971 | // largest acked |
| 5972 | 0x12, 0x34, |
| 5973 | // Zero delta time. |
| 5974 | 0x00, 0x00, |
| 5975 | // num ack blocks ranges. |
| 5976 | 0x04, |
| 5977 | // first ack block length. |
| 5978 | 0x00, 0x01, |
| 5979 | // gap to next block. |
| 5980 | 0x01, |
| 5981 | // ack block length. |
| 5982 | 0x0e, 0xaf, |
| 5983 | // gap to next block. |
| 5984 | 0xff, |
| 5985 | // ack block length. |
| 5986 | 0x00, 0x00, |
| 5987 | // gap to next block. |
| 5988 | 0x91, |
| 5989 | // ack block length. |
| 5990 | 0x01, 0xea, |
| 5991 | // gap to next block. |
| 5992 | 0x05, |
| 5993 | // ack block length. |
| 5994 | 0x00, 0x04, |
| 5995 | // num timestamps. |
| 5996 | 0x00, |
| 5997 | }; |
| 5998 | |
| 5999 | unsigned char packet99[] = { |
| 6000 | // type (short header, 4 byte packet number) |
| 6001 | 0x43, |
| 6002 | // connection_id |
| 6003 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6004 | // packet number |
| 6005 | 0x12, 0x34, 0x56, 0x78, |
| 6006 | |
| 6007 | // frame type (IETF_ACK frame) |
| 6008 | 0x02, |
| 6009 | // largest acked |
| 6010 | kVarInt62TwoBytes + 0x12, 0x34, |
| 6011 | // Zero delta time. |
| 6012 | kVarInt62OneByte + 0x00, |
| 6013 | // num additional ack blocks. |
| 6014 | kVarInt62OneByte + 0x03, |
| 6015 | // first ack block length. |
| 6016 | kVarInt62OneByte + 0x00, |
| 6017 | |
| 6018 | // gap to next block. |
| 6019 | kVarInt62OneByte + 0x00, |
| 6020 | // ack block length. |
| 6021 | kVarInt62TwoBytes + 0x0e, 0xae, |
| 6022 | |
| 6023 | // gap to next block. |
| 6024 | kVarInt62TwoBytes + 0x01, 0x8f, |
| 6025 | // ack block length. |
| 6026 | kVarInt62TwoBytes + 0x01, 0xe9, |
| 6027 | |
| 6028 | // gap to next block. |
| 6029 | kVarInt62OneByte + 0x04, |
| 6030 | // ack block length. |
| 6031 | kVarInt62OneByte + 0x03, |
| 6032 | }; |
| 6033 | // clang-format on |
| 6034 | unsigned char* p = packet; |
| 6035 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6036 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6037 | p = packet99; |
| 6038 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 6039 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6040 | p = packet46; |
| 6041 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6042 | } |
| 6043 | |
| 6044 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6045 | ASSERT_TRUE(data != nullptr); |
| 6046 | |
| 6047 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6048 | data->length(), AsChars(p), p_size); |
| 6049 | } |
| 6050 | |
| 6051 | TEST_P(QuicFramerTest, BuildAckFramePacketMaxAckBlocks) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6052 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6053 | QuicPacketHeader header; |
| 6054 | header.destination_connection_id = FramerTestConnectionId(); |
| 6055 | header.reset_flag = false; |
| 6056 | header.version_flag = false; |
| 6057 | header.packet_number = kPacketNumber; |
| 6058 | |
| 6059 | // Use kSmallLargestObservedto make this test finished in a short time. |
| 6060 | QuicAckFrame ack_frame; |
| 6061 | ack_frame.largest_acked = kSmallLargestObserved; |
| 6062 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6063 | // 300 ack blocks. |
| 6064 | for (size_t i = 2; i < 2 * 300; i += 2) { |
| 6065 | ack_frame.packets.Add(QuicPacketNumber(i)); |
| 6066 | } |
| 6067 | ack_frame.packets.AddRange(QuicPacketNumber(600), kSmallLargestObserved + 1); |
| 6068 | |
| 6069 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6070 | |
| 6071 | // clang-format off |
| 6072 | unsigned char packet[] = { |
| 6073 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6074 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6075 | // connection_id |
| 6076 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6077 | // packet number |
| 6078 | 0x12, 0x34, 0x56, 0x78, |
| 6079 | // frame type (ack frame) |
| 6080 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6081 | 0x65, |
| 6082 | // largest acked |
| 6083 | 0x12, 0x34, |
| 6084 | // Zero delta time. |
| 6085 | 0x00, 0x00, |
| 6086 | // num ack blocks ranges. |
| 6087 | 0xff, |
| 6088 | // first ack block length. |
| 6089 | 0x0f, 0xdd, |
| 6090 | // 255 = 4 * 63 + 3 |
| 6091 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6092 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6093 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6094 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6095 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6096 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6097 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6098 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6099 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6100 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6101 | |
| 6102 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6103 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6104 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6105 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6106 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6107 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6108 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6109 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6110 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6111 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6112 | |
| 6113 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6114 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6115 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6116 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6117 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6118 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6119 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6120 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6121 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6122 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6123 | |
| 6124 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6125 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6126 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6127 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6128 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6129 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6130 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6131 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6132 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6133 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6134 | |
| 6135 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6136 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6137 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6138 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6139 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6140 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6141 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6142 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6143 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6144 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6145 | |
| 6146 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6147 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6148 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6149 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6150 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6151 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6152 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6153 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6154 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6155 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6156 | |
| 6157 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6158 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6159 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6160 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6161 | // num timestamps. |
| 6162 | 0x00, |
| 6163 | }; |
| 6164 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6165 | unsigned char packet46[] = { |
| 6166 | // type (short header, 4 byte packet number) |
| 6167 | 0x43, |
| 6168 | // connection_id |
| 6169 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6170 | // packet number |
| 6171 | 0x12, 0x34, 0x56, 0x78, |
| 6172 | // frame type (ack frame) |
| 6173 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6174 | 0x65, |
| 6175 | // largest acked |
| 6176 | 0x12, 0x34, |
| 6177 | // Zero delta time. |
| 6178 | 0x00, 0x00, |
| 6179 | // num ack blocks ranges. |
| 6180 | 0xff, |
| 6181 | // first ack block length. |
| 6182 | 0x0f, 0xdd, |
| 6183 | // 255 = 4 * 63 + 3 |
| 6184 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6185 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6186 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6187 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6188 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6189 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6190 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6191 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6192 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6193 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6194 | |
| 6195 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6196 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6197 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6198 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6199 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6200 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6201 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6202 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6203 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6204 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6205 | |
| 6206 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6207 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6208 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6209 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6210 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6211 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6212 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6213 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6214 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6215 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6216 | |
| 6217 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6218 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6219 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6220 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6221 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6222 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6223 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6224 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6225 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6226 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6227 | |
| 6228 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6229 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6230 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6231 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6232 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6233 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6234 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6235 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6236 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6237 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6238 | |
| 6239 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6240 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6241 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6242 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6243 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6244 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6245 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6246 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6247 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6248 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6249 | |
| 6250 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6251 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6252 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6253 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6254 | // num timestamps. |
| 6255 | 0x00, |
| 6256 | }; |
| 6257 | |
| 6258 | unsigned char packet99[] = { |
| 6259 | // type (short header, 4 byte packet number) |
| 6260 | 0x43, |
| 6261 | // connection_id |
| 6262 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6263 | // packet number |
| 6264 | 0x12, 0x34, 0x56, 0x78, |
| 6265 | // frame type (IETF_ACK frame) |
| 6266 | 0x02, |
| 6267 | // largest acked |
| 6268 | kVarInt62TwoBytes + 0x12, 0x34, |
| 6269 | // Zero delta time. |
| 6270 | kVarInt62OneByte + 0x00, |
| 6271 | // num ack blocks ranges. |
| 6272 | kVarInt62TwoBytes + 0x01, 0x2b, |
| 6273 | // first ack block length. |
| 6274 | kVarInt62TwoBytes + 0x0f, 0xdc, |
| 6275 | // 255 added blocks of gap_size == 1, ack_size == 1 |
| 6276 | #define V99AddedBLOCK kVarInt62OneByte + 0x00, kVarInt62OneByte + 0x00 |
| 6277 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6278 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6279 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6280 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6281 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6282 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6283 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6284 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6285 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6286 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6287 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6288 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6289 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6290 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6291 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6292 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6293 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6294 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6295 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6296 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6297 | |
| 6298 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6299 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6300 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6301 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6302 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6303 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6304 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6305 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6306 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6307 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6308 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6309 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6310 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6311 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6312 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6313 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6314 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6315 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6316 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6317 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6318 | |
| 6319 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6320 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6321 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6322 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6323 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6324 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6325 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6326 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6327 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6328 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6329 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6330 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6331 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6332 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6333 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6334 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6335 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6336 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6337 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6338 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 6339 | |
| 6340 | #undef V99AddedBLOCK |
| 6341 | }; |
| 6342 | // clang-format on |
| 6343 | unsigned char* p = packet; |
| 6344 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6345 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6346 | p = packet99; |
| 6347 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 6348 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6349 | p = packet46; |
| 6350 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6351 | } |
| 6352 | |
| 6353 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6354 | ASSERT_TRUE(data != nullptr); |
| 6355 | |
| 6356 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6357 | data->length(), AsChars(p), p_size); |
| 6358 | } |
| 6359 | |
| 6360 | TEST_P(QuicFramerTest, BuildNewStopWaitingPacket) { |
| 6361 | if (version_.transport_version > QUIC_VERSION_43) { |
| 6362 | return; |
| 6363 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6364 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6365 | QuicPacketHeader header; |
| 6366 | header.destination_connection_id = FramerTestConnectionId(); |
| 6367 | header.reset_flag = false; |
| 6368 | header.version_flag = false; |
| 6369 | header.packet_number = kPacketNumber; |
| 6370 | |
| 6371 | QuicStopWaitingFrame stop_waiting_frame; |
| 6372 | stop_waiting_frame.least_unacked = kLeastUnacked; |
| 6373 | |
| 6374 | QuicFrames frames = {QuicFrame(stop_waiting_frame)}; |
| 6375 | |
| 6376 | // clang-format off |
| 6377 | unsigned char packet[] = { |
| 6378 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6379 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6380 | // connection_id |
| 6381 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6382 | // packet number |
| 6383 | 0x12, 0x34, 0x56, 0x78, |
| 6384 | |
| 6385 | // frame type (stop waiting frame) |
| 6386 | 0x06, |
| 6387 | // least packet number awaiting an ack, delta from packet number. |
| 6388 | 0x00, 0x00, 0x00, 0x08, |
| 6389 | }; |
| 6390 | |
| 6391 | // clang-format on |
| 6392 | |
| 6393 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6394 | ASSERT_TRUE(data != nullptr); |
| 6395 | |
| 6396 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6397 | data->length(), AsChars(packet), |
| 6398 | QUIC_ARRAYSIZE(packet)); |
| 6399 | } |
| 6400 | |
| 6401 | TEST_P(QuicFramerTest, BuildRstFramePacketQuic) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6402 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6403 | QuicPacketHeader header; |
| 6404 | header.destination_connection_id = FramerTestConnectionId(); |
| 6405 | header.reset_flag = false; |
| 6406 | header.version_flag = false; |
| 6407 | header.packet_number = kPacketNumber; |
| 6408 | |
| 6409 | QuicRstStreamFrame rst_frame; |
| 6410 | rst_frame.stream_id = kStreamId; |
| 6411 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6412 | rst_frame.ietf_error_code = 0x01; |
| 6413 | } else { |
| 6414 | rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708); |
| 6415 | } |
| 6416 | rst_frame.byte_offset = 0x0807060504030201; |
| 6417 | |
| 6418 | // clang-format off |
| 6419 | unsigned char packet[] = { |
| 6420 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6421 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6422 | // connection_id |
| 6423 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6424 | // packet number |
| 6425 | 0x12, 0x34, 0x56, 0x78, |
| 6426 | |
| 6427 | // frame type (rst stream frame) |
| 6428 | 0x01, |
| 6429 | // stream id |
| 6430 | 0x01, 0x02, 0x03, 0x04, |
| 6431 | // sent byte offset |
| 6432 | 0x08, 0x07, 0x06, 0x05, |
| 6433 | 0x04, 0x03, 0x02, 0x01, |
| 6434 | // error code |
| 6435 | 0x05, 0x06, 0x07, 0x08, |
| 6436 | }; |
| 6437 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6438 | unsigned char packet46[] = { |
| 6439 | // type (short packet, 4 byte packet number) |
| 6440 | 0x43, |
| 6441 | // connection_id |
| 6442 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6443 | // packet number |
| 6444 | 0x12, 0x34, 0x56, 0x78, |
| 6445 | |
| 6446 | // frame type (rst stream frame) |
| 6447 | 0x01, |
| 6448 | // stream id |
| 6449 | 0x01, 0x02, 0x03, 0x04, |
| 6450 | // sent byte offset |
| 6451 | 0x08, 0x07, 0x06, 0x05, |
| 6452 | 0x04, 0x03, 0x02, 0x01, |
| 6453 | // error code |
| 6454 | 0x05, 0x06, 0x07, 0x08, |
| 6455 | }; |
| 6456 | |
| 6457 | unsigned char packet99[] = { |
| 6458 | // type (short packet, 4 byte packet number) |
| 6459 | 0x43, |
| 6460 | // connection_id |
| 6461 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6462 | // packet number |
| 6463 | 0x12, 0x34, 0x56, 0x78, |
| 6464 | |
| 6465 | // frame type (IETF_RST_STREAM frame) |
| 6466 | 0x04, |
| 6467 | // stream id |
| 6468 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 6469 | // error code (not VarInt32 encoded) |
| 6470 | 0x00, 0x01, |
| 6471 | // sent byte offset |
| 6472 | kVarInt62EightBytes + 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 |
| 6473 | }; |
| 6474 | // clang-format on |
| 6475 | |
| 6476 | QuicFrames frames = {QuicFrame(&rst_frame)}; |
| 6477 | |
| 6478 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6479 | ASSERT_TRUE(data != nullptr); |
| 6480 | |
| 6481 | unsigned char* p = packet; |
| 6482 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6483 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6484 | p = packet99; |
| 6485 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 6486 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6487 | p = packet46; |
| 6488 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6489 | } |
| 6490 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 6491 | |
| 6492 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6493 | data->length(), AsChars(p), p_size); |
| 6494 | } |
| 6495 | |
| 6496 | TEST_P(QuicFramerTest, BuildCloseFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6497 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6498 | QuicPacketHeader header; |
| 6499 | header.destination_connection_id = FramerTestConnectionId(); |
| 6500 | header.reset_flag = false; |
| 6501 | header.version_flag = false; |
| 6502 | header.packet_number = kPacketNumber; |
| 6503 | |
| 6504 | QuicConnectionCloseFrame close_frame; |
| 6505 | if (framer_.transport_version() == QUIC_VERSION_99) { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 6506 | close_frame.transport_error_code = |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6507 | static_cast<QuicIetfTransportErrorCodes>(0x11); |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 6508 | close_frame.transport_close_frame_type = 0x05; |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 6509 | close_frame.close_type = IETF_QUIC_TRANSPORT_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6510 | } else { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 6511 | close_frame.quic_error_code = static_cast<QuicErrorCode>(0x05060708); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6512 | } |
| 6513 | close_frame.error_details = "because I can"; |
| 6514 | |
| 6515 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 6516 | |
| 6517 | // clang-format off |
| 6518 | unsigned char packet[] = { |
| 6519 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6520 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6521 | // connection_id |
| 6522 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6523 | // packet number |
| 6524 | 0x12, 0x34, 0x56, 0x78, |
| 6525 | |
| 6526 | // frame type (connection close frame) |
| 6527 | 0x02, |
| 6528 | // error code |
| 6529 | 0x05, 0x06, 0x07, 0x08, |
| 6530 | // error details length |
| 6531 | 0x00, 0x0d, |
| 6532 | // error details |
| 6533 | 'b', 'e', 'c', 'a', |
| 6534 | 'u', 's', 'e', ' ', |
| 6535 | 'I', ' ', 'c', 'a', |
| 6536 | 'n', |
| 6537 | }; |
| 6538 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6539 | unsigned char packet46[] = { |
| 6540 | // type (short header, 4 byte packet number) |
| 6541 | 0x43, |
| 6542 | // connection_id |
| 6543 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6544 | // packet number |
| 6545 | 0x12, 0x34, 0x56, 0x78, |
| 6546 | |
| 6547 | // frame type (connection close frame) |
| 6548 | 0x02, |
| 6549 | // error code |
| 6550 | 0x05, 0x06, 0x07, 0x08, |
| 6551 | // error details length |
| 6552 | 0x00, 0x0d, |
| 6553 | // error details |
| 6554 | 'b', 'e', 'c', 'a', |
| 6555 | 'u', 's', 'e', ' ', |
| 6556 | 'I', ' ', 'c', 'a', |
| 6557 | 'n', |
| 6558 | }; |
| 6559 | |
| 6560 | unsigned char packet99[] = { |
| 6561 | // type (short header, 4 byte packet number) |
| 6562 | 0x43, |
| 6563 | // connection_id |
| 6564 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6565 | // packet number |
| 6566 | 0x12, 0x34, 0x56, 0x78, |
| 6567 | |
| 6568 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 6569 | 0x1c, |
| 6570 | // error code |
| 6571 | 0x00, 0x11, |
| 6572 | // Frame type within the CONNECTION_CLOSE frame |
| 6573 | kVarInt62OneByte + 0x05, |
| 6574 | // error details length |
| 6575 | kVarInt62OneByte + 0x0d, |
| 6576 | // error details |
| 6577 | 'b', 'e', 'c', 'a', |
| 6578 | 'u', 's', 'e', ' ', |
| 6579 | 'I', ' ', 'c', 'a', |
| 6580 | 'n', |
| 6581 | }; |
| 6582 | // clang-format on |
| 6583 | |
| 6584 | unsigned char* p = packet; |
| 6585 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6586 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6587 | p = packet99; |
| 6588 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 6589 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6590 | p = packet46; |
| 6591 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6592 | } |
| 6593 | |
| 6594 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6595 | ASSERT_TRUE(data != nullptr); |
| 6596 | |
| 6597 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6598 | data->length(), AsChars(p), p_size); |
| 6599 | } |
| 6600 | |
| 6601 | TEST_P(QuicFramerTest, BuildTruncatedCloseFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6602 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6603 | QuicPacketHeader header; |
| 6604 | header.destination_connection_id = FramerTestConnectionId(); |
| 6605 | header.reset_flag = false; |
| 6606 | header.version_flag = false; |
| 6607 | header.packet_number = kPacketNumber; |
| 6608 | |
| 6609 | QuicConnectionCloseFrame close_frame; |
| 6610 | if (framer_.transport_version() == QUIC_VERSION_99) { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 6611 | close_frame.transport_error_code = PROTOCOL_VIOLATION; // value is 0x0a |
| 6612 | EXPECT_EQ(0u, close_frame.transport_close_frame_type); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 6613 | close_frame.close_type = IETF_QUIC_TRANSPORT_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6614 | } else { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 6615 | close_frame.quic_error_code = static_cast<QuicErrorCode>(0x05060708); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6616 | } |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 6617 | close_frame.error_details = std::string(2048, 'A'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6618 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 6619 | |
| 6620 | // clang-format off |
| 6621 | unsigned char packet[] = { |
| 6622 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6623 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6624 | // connection_id |
| 6625 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6626 | // packet number |
| 6627 | 0x12, 0x34, 0x56, 0x78, |
| 6628 | |
| 6629 | // frame type (connection close frame) |
| 6630 | 0x02, |
| 6631 | // error code |
| 6632 | 0x05, 0x06, 0x07, 0x08, |
| 6633 | // error details length |
| 6634 | 0x01, 0x00, |
| 6635 | // error details (truncated to 256 bytes) |
| 6636 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6637 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6638 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6639 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6640 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6641 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6642 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6643 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6644 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6645 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6646 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6647 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6648 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6649 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6650 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6651 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6652 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6653 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6654 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6655 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6656 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6657 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6658 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6659 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6660 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6661 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6662 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6663 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6664 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6665 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6666 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6667 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6668 | }; |
| 6669 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6670 | unsigned char packet46[] = { |
| 6671 | // type (short header, 4 byte packet number) |
| 6672 | 0x43, |
| 6673 | // connection_id |
| 6674 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6675 | // packet number |
| 6676 | 0x12, 0x34, 0x56, 0x78, |
| 6677 | |
| 6678 | // frame type (connection close frame) |
| 6679 | 0x02, |
| 6680 | // error code |
| 6681 | 0x05, 0x06, 0x07, 0x08, |
| 6682 | // error details length |
| 6683 | 0x01, 0x00, |
| 6684 | // error details (truncated to 256 bytes) |
| 6685 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6686 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6687 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6688 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6689 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6690 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6691 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6692 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6693 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6694 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6695 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6696 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6697 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6698 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6699 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6700 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6701 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6702 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6703 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6704 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6705 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6706 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6707 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6708 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6709 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6710 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6711 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6712 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6713 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6714 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6715 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6716 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6717 | }; |
| 6718 | |
| 6719 | unsigned char packet99[] = { |
| 6720 | // type (short header, 4 byte packet number) |
| 6721 | 0x43, |
| 6722 | // connection_id |
| 6723 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6724 | // packet number |
| 6725 | 0x12, 0x34, 0x56, 0x78, |
| 6726 | |
| 6727 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 6728 | 0x1c, |
| 6729 | // error code |
| 6730 | 0x00, 0x0a, |
| 6731 | // Frame type within the CONNECTION_CLOSE frame |
| 6732 | kVarInt62OneByte + 0x00, |
| 6733 | // error details length |
| 6734 | kVarInt62TwoBytes + 0x01, 0x00, |
| 6735 | // error details (truncated to 256 bytes) |
| 6736 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6737 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6738 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6739 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6740 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6741 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6742 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6743 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6744 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6745 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6746 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6747 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6748 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6749 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6750 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6751 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6752 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6753 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6754 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6755 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6756 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6757 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6758 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6759 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6760 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6761 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6762 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6763 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6764 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6765 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6766 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6767 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6768 | }; |
| 6769 | // clang-format on |
| 6770 | |
| 6771 | unsigned char* p = packet; |
| 6772 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6773 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6774 | p = packet99; |
| 6775 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 6776 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6777 | p = packet46; |
| 6778 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6782 | ASSERT_TRUE(data != nullptr); |
| 6783 | |
| 6784 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6785 | data->length(), AsChars(p), p_size); |
| 6786 | } |
| 6787 | |
| 6788 | TEST_P(QuicFramerTest, BuildApplicationCloseFramePacket) { |
| 6789 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 6790 | // Versions other than 99 do not have ApplicationClose |
| 6791 | return; |
| 6792 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6793 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6794 | QuicPacketHeader header; |
| 6795 | header.destination_connection_id = FramerTestConnectionId(); |
| 6796 | header.reset_flag = false; |
| 6797 | header.version_flag = false; |
| 6798 | header.packet_number = kPacketNumber; |
| 6799 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 6800 | QuicConnectionCloseFrame app_close_frame; |
| 6801 | app_close_frame.quic_error_code = static_cast<QuicErrorCode>(0x11); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6802 | app_close_frame.error_details = "because I can"; |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 6803 | app_close_frame.close_type = IETF_QUIC_APPLICATION_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6804 | |
| 6805 | QuicFrames frames = {QuicFrame(&app_close_frame)}; |
| 6806 | |
| 6807 | // clang-format off |
| 6808 | |
| 6809 | unsigned char packet99[] = { |
| 6810 | // type (short header, 4 byte packet number) |
| 6811 | 0x43, |
| 6812 | // connection_id |
| 6813 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6814 | // packet number |
| 6815 | 0x12, 0x34, 0x56, 0x78, |
| 6816 | |
| 6817 | // frame type (IETF_APPLICATION_CLOSE frame) |
| 6818 | 0x1d, |
| 6819 | // error code |
| 6820 | 0x00, 0x11, |
| 6821 | // error details length |
| 6822 | kVarInt62OneByte + 0x0d, |
| 6823 | // error details |
| 6824 | 'b', 'e', 'c', 'a', |
| 6825 | 'u', 's', 'e', ' ', |
| 6826 | 'I', ' ', 'c', 'a', |
| 6827 | 'n', |
| 6828 | }; |
| 6829 | // clang-format on |
| 6830 | |
| 6831 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6832 | ASSERT_TRUE(data != nullptr); |
| 6833 | |
| 6834 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6835 | data->length(), AsChars(packet99), |
| 6836 | QUIC_ARRAYSIZE(packet99)); |
| 6837 | } |
| 6838 | |
| 6839 | TEST_P(QuicFramerTest, BuildTruncatedApplicationCloseFramePacket) { |
| 6840 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 6841 | // Versions other than 99 do not have this frame. |
| 6842 | return; |
| 6843 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6844 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6845 | QuicPacketHeader header; |
| 6846 | header.destination_connection_id = FramerTestConnectionId(); |
| 6847 | header.reset_flag = false; |
| 6848 | header.version_flag = false; |
| 6849 | header.packet_number = kPacketNumber; |
| 6850 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 6851 | QuicConnectionCloseFrame app_close_frame; |
| 6852 | app_close_frame.quic_error_code = static_cast<QuicErrorCode>(0x11); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 6853 | app_close_frame.error_details = std::string(2048, 'A'); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 6854 | app_close_frame.close_type = IETF_QUIC_APPLICATION_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6855 | |
| 6856 | QuicFrames frames = {QuicFrame(&app_close_frame)}; |
| 6857 | |
| 6858 | // clang-format off |
| 6859 | unsigned char packet99[] = { |
| 6860 | // type (short header, 4 byte packet number) |
| 6861 | 0x43, |
| 6862 | // connection_id |
| 6863 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6864 | // packet number |
| 6865 | 0x12, 0x34, 0x56, 0x78, |
| 6866 | |
| 6867 | // frame type (IETF_APPLICATION_CLOSE frame) |
| 6868 | 0x1d, |
| 6869 | // error code |
| 6870 | 0x00, 0x11, |
| 6871 | // error details length |
| 6872 | kVarInt62TwoBytes + 0x01, 0x00, |
| 6873 | // error details (truncated to 256 bytes) |
| 6874 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6875 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6876 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6877 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6878 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6879 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6880 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6881 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6882 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6883 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6884 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6885 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6886 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6887 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6888 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6889 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6890 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6891 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6892 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6893 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6894 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6895 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6896 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6897 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6898 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6899 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6900 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6901 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6902 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6903 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6904 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6905 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 6906 | }; |
| 6907 | // clang-format on |
| 6908 | |
| 6909 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6910 | ASSERT_TRUE(data != nullptr); |
| 6911 | |
| 6912 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6913 | data->length(), AsChars(packet99), |
| 6914 | QUIC_ARRAYSIZE(packet99)); |
| 6915 | } |
| 6916 | |
| 6917 | TEST_P(QuicFramerTest, BuildGoAwayPacket) { |
| 6918 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6919 | // This frame type is not supported in version 99. |
| 6920 | return; |
| 6921 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6922 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6923 | QuicPacketHeader header; |
| 6924 | header.destination_connection_id = FramerTestConnectionId(); |
| 6925 | header.reset_flag = false; |
| 6926 | header.version_flag = false; |
| 6927 | header.packet_number = kPacketNumber; |
| 6928 | |
| 6929 | QuicGoAwayFrame goaway_frame; |
| 6930 | goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 6931 | goaway_frame.last_good_stream_id = kStreamId; |
| 6932 | goaway_frame.reason_phrase = "because I can"; |
| 6933 | |
| 6934 | QuicFrames frames = {QuicFrame(&goaway_frame)}; |
| 6935 | |
| 6936 | // clang-format off |
| 6937 | unsigned char packet[] = { |
| 6938 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6939 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6940 | // connection_id |
| 6941 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6942 | // packet number |
| 6943 | 0x12, 0x34, 0x56, 0x78, |
| 6944 | |
| 6945 | // frame type (go away frame) |
| 6946 | 0x03, |
| 6947 | // error code |
| 6948 | 0x05, 0x06, 0x07, 0x08, |
| 6949 | // stream id |
| 6950 | 0x01, 0x02, 0x03, 0x04, |
| 6951 | // error details length |
| 6952 | 0x00, 0x0d, |
| 6953 | // error details |
| 6954 | 'b', 'e', 'c', 'a', |
| 6955 | 'u', 's', 'e', ' ', |
| 6956 | 'I', ' ', 'c', 'a', |
| 6957 | 'n', |
| 6958 | }; |
| 6959 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6960 | unsigned char packet46[] = { |
| 6961 | // type (short header, 4 byte packet number) |
| 6962 | 0x43, |
| 6963 | // connection_id |
| 6964 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6965 | // packet number |
| 6966 | 0x12, 0x34, 0x56, 0x78, |
| 6967 | |
| 6968 | // frame type (go away frame) |
| 6969 | 0x03, |
| 6970 | // error code |
| 6971 | 0x05, 0x06, 0x07, 0x08, |
| 6972 | // stream id |
| 6973 | 0x01, 0x02, 0x03, 0x04, |
| 6974 | // error details length |
| 6975 | 0x00, 0x0d, |
| 6976 | // error details |
| 6977 | 'b', 'e', 'c', 'a', |
| 6978 | 'u', 's', 'e', ' ', |
| 6979 | 'I', ' ', 'c', 'a', |
| 6980 | 'n', |
| 6981 | }; |
| 6982 | |
| 6983 | // clang-format on |
| 6984 | |
| 6985 | unsigned char* p = packet; |
| 6986 | size_t p_size = QUIC_ARRAYSIZE(packet); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 6987 | if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6988 | p = packet46; |
| 6989 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6990 | } |
| 6991 | |
| 6992 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6993 | ASSERT_TRUE(data != nullptr); |
| 6994 | |
| 6995 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6996 | data->length(), AsChars(p), p_size); |
| 6997 | } |
| 6998 | |
| 6999 | TEST_P(QuicFramerTest, BuildTruncatedGoAwayPacket) { |
| 7000 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7001 | // This frame type is not supported in version 99. |
| 7002 | return; |
| 7003 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7004 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7005 | QuicPacketHeader header; |
| 7006 | header.destination_connection_id = FramerTestConnectionId(); |
| 7007 | header.reset_flag = false; |
| 7008 | header.version_flag = false; |
| 7009 | header.packet_number = kPacketNumber; |
| 7010 | |
| 7011 | QuicGoAwayFrame goaway_frame; |
| 7012 | goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 7013 | goaway_frame.last_good_stream_id = kStreamId; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 7014 | goaway_frame.reason_phrase = std::string(2048, 'A'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7015 | |
| 7016 | QuicFrames frames = {QuicFrame(&goaway_frame)}; |
| 7017 | |
| 7018 | // clang-format off |
| 7019 | unsigned char packet[] = { |
| 7020 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7021 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7022 | // connection_id |
| 7023 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7024 | // packet number |
| 7025 | 0x12, 0x34, 0x56, 0x78, |
| 7026 | |
| 7027 | // frame type (go away frame) |
| 7028 | 0x03, |
| 7029 | // error code |
| 7030 | 0x05, 0x06, 0x07, 0x08, |
| 7031 | // stream id |
| 7032 | 0x01, 0x02, 0x03, 0x04, |
| 7033 | // error details length |
| 7034 | 0x01, 0x00, |
| 7035 | // error details (truncated to 256 bytes) |
| 7036 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7037 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7038 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7039 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7040 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7041 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7042 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7043 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7044 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7045 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7046 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7047 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7048 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7049 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7050 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7051 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7052 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7053 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7054 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7055 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7056 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7057 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7058 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7059 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7060 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7061 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7062 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7063 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7064 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7065 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7066 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7067 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7068 | }; |
| 7069 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7070 | unsigned char packet46[] = { |
| 7071 | // type (short header, 4 byte packet number) |
| 7072 | 0x43, |
| 7073 | // connection_id |
| 7074 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7075 | // packet number |
| 7076 | 0x12, 0x34, 0x56, 0x78, |
| 7077 | |
| 7078 | // frame type (go away frame) |
| 7079 | 0x03, |
| 7080 | // error code |
| 7081 | 0x05, 0x06, 0x07, 0x08, |
| 7082 | // stream id |
| 7083 | 0x01, 0x02, 0x03, 0x04, |
| 7084 | // error details length |
| 7085 | 0x01, 0x00, |
| 7086 | // error details (truncated to 256 bytes) |
| 7087 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7088 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7089 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7090 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7091 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7092 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7093 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7094 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7095 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7096 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7097 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7098 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7099 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7100 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7101 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7102 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7103 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7104 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7105 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7106 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7107 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7108 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7109 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7110 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7111 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7112 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7113 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7114 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7115 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7116 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7117 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7118 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7119 | }; |
| 7120 | // clang-format on |
| 7121 | |
| 7122 | unsigned char* p = packet; |
| 7123 | size_t p_size = QUIC_ARRAYSIZE(packet); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 7124 | if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7125 | p = packet46; |
| 7126 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7127 | } |
| 7128 | |
| 7129 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7130 | ASSERT_TRUE(data != nullptr); |
| 7131 | |
| 7132 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7133 | data->length(), AsChars(p), p_size); |
| 7134 | } |
| 7135 | |
| 7136 | TEST_P(QuicFramerTest, BuildWindowUpdatePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7137 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7138 | QuicPacketHeader header; |
| 7139 | header.destination_connection_id = FramerTestConnectionId(); |
| 7140 | header.reset_flag = false; |
| 7141 | header.version_flag = false; |
| 7142 | header.packet_number = kPacketNumber; |
| 7143 | |
| 7144 | QuicWindowUpdateFrame window_update_frame; |
| 7145 | window_update_frame.stream_id = kStreamId; |
| 7146 | window_update_frame.byte_offset = 0x1122334455667788; |
| 7147 | |
| 7148 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 7149 | |
| 7150 | // clang-format off |
| 7151 | unsigned char packet[] = { |
| 7152 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7153 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7154 | // connection_id |
| 7155 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7156 | // packet number |
| 7157 | 0x12, 0x34, 0x56, 0x78, |
| 7158 | |
| 7159 | // frame type (window update frame) |
| 7160 | 0x04, |
| 7161 | // stream id |
| 7162 | 0x01, 0x02, 0x03, 0x04, |
| 7163 | // byte offset |
| 7164 | 0x11, 0x22, 0x33, 0x44, |
| 7165 | 0x55, 0x66, 0x77, 0x88, |
| 7166 | }; |
| 7167 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7168 | unsigned char packet46[] = { |
| 7169 | // type (short header, 4 byte packet number) |
| 7170 | 0x43, |
| 7171 | // connection_id |
| 7172 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7173 | // packet number |
| 7174 | 0x12, 0x34, 0x56, 0x78, |
| 7175 | |
| 7176 | // frame type (window update frame) |
| 7177 | 0x04, |
| 7178 | // stream id |
| 7179 | 0x01, 0x02, 0x03, 0x04, |
| 7180 | // byte offset |
| 7181 | 0x11, 0x22, 0x33, 0x44, |
| 7182 | 0x55, 0x66, 0x77, 0x88, |
| 7183 | }; |
| 7184 | |
| 7185 | unsigned char packet99[] = { |
| 7186 | // type (short header, 4 byte packet number) |
| 7187 | 0x43, |
| 7188 | // connection_id |
| 7189 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7190 | // packet number |
| 7191 | 0x12, 0x34, 0x56, 0x78, |
| 7192 | |
| 7193 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 7194 | 0x11, |
| 7195 | // stream id |
| 7196 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 7197 | // byte offset |
| 7198 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 7199 | 0x55, 0x66, 0x77, 0x88, |
| 7200 | }; |
| 7201 | // clang-format on |
| 7202 | |
| 7203 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7204 | ASSERT_TRUE(data != nullptr); |
| 7205 | |
| 7206 | unsigned char* p = packet; |
| 7207 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7208 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7209 | p = packet99; |
| 7210 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 7211 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7212 | p = packet46; |
| 7213 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7214 | } |
| 7215 | |
| 7216 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7217 | data->length(), AsChars(p), p_size); |
| 7218 | } |
| 7219 | |
| 7220 | TEST_P(QuicFramerTest, BuildMaxStreamDataPacket) { |
| 7221 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 7222 | // This frame is available only in this version. |
| 7223 | return; |
| 7224 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7225 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7226 | QuicPacketHeader header; |
| 7227 | header.destination_connection_id = FramerTestConnectionId(); |
| 7228 | header.reset_flag = false; |
| 7229 | header.version_flag = false; |
| 7230 | header.packet_number = kPacketNumber; |
| 7231 | |
| 7232 | QuicWindowUpdateFrame window_update_frame; |
| 7233 | window_update_frame.stream_id = kStreamId; |
| 7234 | window_update_frame.byte_offset = 0x1122334455667788; |
| 7235 | |
| 7236 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 7237 | |
| 7238 | // clang-format off |
| 7239 | unsigned char packet99[] = { |
| 7240 | // type (short header, 4 byte packet number) |
| 7241 | 0x43, |
| 7242 | // connection_id |
| 7243 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7244 | // packet number |
| 7245 | 0x12, 0x34, 0x56, 0x78, |
| 7246 | |
| 7247 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 7248 | 0x11, |
| 7249 | // stream id |
| 7250 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 7251 | // byte offset |
| 7252 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 7253 | 0x55, 0x66, 0x77, 0x88, |
| 7254 | }; |
| 7255 | // clang-format on |
| 7256 | |
| 7257 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7258 | ASSERT_TRUE(data != nullptr); |
| 7259 | |
| 7260 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7261 | data->length(), AsChars(packet99), |
| 7262 | QUIC_ARRAYSIZE(packet99)); |
| 7263 | } |
| 7264 | |
| 7265 | TEST_P(QuicFramerTest, BuildMaxDataPacket) { |
| 7266 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 7267 | // This frame is available only in this version. |
| 7268 | return; |
| 7269 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7270 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7271 | QuicPacketHeader header; |
| 7272 | header.destination_connection_id = FramerTestConnectionId(); |
| 7273 | header.reset_flag = false; |
| 7274 | header.version_flag = false; |
| 7275 | header.packet_number = kPacketNumber; |
| 7276 | |
| 7277 | QuicWindowUpdateFrame window_update_frame; |
| 7278 | window_update_frame.stream_id = |
| 7279 | QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 7280 | window_update_frame.byte_offset = 0x1122334455667788; |
| 7281 | |
| 7282 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 7283 | |
| 7284 | // clang-format off |
| 7285 | unsigned char packet99[] = { |
| 7286 | // type (short header, 4 byte packet number) |
| 7287 | 0x43, |
| 7288 | // connection_id |
| 7289 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7290 | // packet number |
| 7291 | 0x12, 0x34, 0x56, 0x78, |
| 7292 | |
| 7293 | // frame type (IETF_MAX_DATA frame) |
| 7294 | 0x10, |
| 7295 | // byte offset |
| 7296 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 7297 | 0x55, 0x66, 0x77, 0x88, |
| 7298 | }; |
| 7299 | // clang-format on |
| 7300 | |
| 7301 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7302 | ASSERT_TRUE(data != nullptr); |
| 7303 | |
| 7304 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7305 | data->length(), AsChars(packet99), |
| 7306 | QUIC_ARRAYSIZE(packet99)); |
| 7307 | } |
| 7308 | |
| 7309 | TEST_P(QuicFramerTest, BuildBlockedPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7310 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7311 | QuicPacketHeader header; |
| 7312 | header.destination_connection_id = FramerTestConnectionId(); |
| 7313 | header.reset_flag = false; |
| 7314 | header.version_flag = false; |
| 7315 | header.packet_number = kPacketNumber; |
| 7316 | |
| 7317 | QuicBlockedFrame blocked_frame; |
| 7318 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7319 | // For V99, the stream ID must be <invalid> for the frame |
| 7320 | // to be a BLOCKED frame. if it's valid, it will be a |
| 7321 | // STREAM_BLOCKED frame. |
| 7322 | blocked_frame.stream_id = |
| 7323 | QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 7324 | } else { |
| 7325 | blocked_frame.stream_id = kStreamId; |
| 7326 | } |
| 7327 | blocked_frame.offset = kStreamOffset; |
| 7328 | |
| 7329 | QuicFrames frames = {QuicFrame(&blocked_frame)}; |
| 7330 | |
| 7331 | // clang-format off |
| 7332 | unsigned char packet[] = { |
| 7333 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7334 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7335 | // connection_id |
| 7336 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7337 | // packet number |
| 7338 | 0x12, 0x34, 0x56, 0x78, |
| 7339 | |
| 7340 | // frame type (blocked frame) |
| 7341 | 0x05, |
| 7342 | // stream id |
| 7343 | 0x01, 0x02, 0x03, 0x04, |
| 7344 | }; |
| 7345 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7346 | unsigned char packet46[] = { |
| 7347 | // type (short packet, 4 byte packet number) |
| 7348 | 0x43, |
| 7349 | // connection_id |
| 7350 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7351 | // packet number |
| 7352 | 0x12, 0x34, 0x56, 0x78, |
| 7353 | |
| 7354 | // frame type (blocked frame) |
| 7355 | 0x05, |
| 7356 | // stream id |
| 7357 | 0x01, 0x02, 0x03, 0x04, |
| 7358 | }; |
| 7359 | |
| 7360 | unsigned char packet99[] = { |
| 7361 | // type (short packet, 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 | |
| 7368 | // frame type (IETF_BLOCKED frame) |
| 7369 | 0x14, |
| 7370 | // Offset |
| 7371 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 7372 | }; |
| 7373 | // clang-format on |
| 7374 | |
| 7375 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7376 | ASSERT_TRUE(data != nullptr); |
| 7377 | |
| 7378 | unsigned char* p = packet; |
| 7379 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7380 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7381 | p = packet99; |
| 7382 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 7383 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7384 | p = packet46; |
| 7385 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7386 | } |
| 7387 | |
| 7388 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7389 | data->length(), AsChars(p), p_size); |
| 7390 | } |
| 7391 | |
| 7392 | TEST_P(QuicFramerTest, BuildPingPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7393 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7394 | QuicPacketHeader header; |
| 7395 | header.destination_connection_id = FramerTestConnectionId(); |
| 7396 | header.reset_flag = false; |
| 7397 | header.version_flag = false; |
| 7398 | header.packet_number = kPacketNumber; |
| 7399 | |
| 7400 | QuicFrames frames = {QuicFrame(QuicPingFrame())}; |
| 7401 | |
| 7402 | // clang-format off |
| 7403 | unsigned char packet[] = { |
| 7404 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7405 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7406 | // connection_id |
| 7407 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7408 | // packet number |
| 7409 | 0x12, 0x34, 0x56, 0x78, |
| 7410 | |
| 7411 | // frame type (ping frame) |
| 7412 | 0x07, |
| 7413 | }; |
| 7414 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7415 | unsigned char packet46[] = { |
| 7416 | // type (short header, 4 byte packet number) |
| 7417 | 0x43, |
| 7418 | // connection_id |
| 7419 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7420 | // packet number |
| 7421 | 0x12, 0x34, 0x56, 0x78, |
| 7422 | |
| 7423 | // frame type |
| 7424 | 0x07, |
| 7425 | }; |
| 7426 | |
| 7427 | unsigned char packet99[] = { |
| 7428 | // type (short header, 4 byte packet number) |
| 7429 | 0x43, |
| 7430 | // connection_id |
| 7431 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7432 | // packet number |
| 7433 | 0x12, 0x34, 0x56, 0x78, |
| 7434 | |
| 7435 | // frame type (IETF_PING frame) |
| 7436 | 0x01, |
| 7437 | }; |
| 7438 | // clang-format on |
| 7439 | |
| 7440 | unsigned char* p = packet; |
| 7441 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7442 | p = packet99; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7443 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 7444 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7445 | } |
| 7446 | |
| 7447 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7448 | ASSERT_TRUE(data != nullptr); |
| 7449 | |
| 7450 | test::CompareCharArraysWithHexError( |
| 7451 | "constructed packet", data->data(), data->length(), AsChars(p), |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 7452 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet46) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7453 | : QUIC_ARRAYSIZE(packet)); |
| 7454 | } |
| 7455 | |
| 7456 | TEST_P(QuicFramerTest, BuildMessagePacket) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 7457 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7458 | return; |
| 7459 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7460 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7461 | QuicPacketHeader header; |
| 7462 | header.destination_connection_id = FramerTestConnectionId(); |
| 7463 | header.reset_flag = false; |
| 7464 | header.version_flag = false; |
| 7465 | header.packet_number = kPacketNumber; |
| 7466 | QuicMemSliceStorage storage(nullptr, 0, nullptr, 0); |
| 7467 | |
wub | 553a966 | 2019-03-28 20:13:23 -0700 | [diff] [blame] | 7468 | QuicMessageFrame frame(1, MakeSpan(&allocator_, "message", &storage)); |
| 7469 | QuicMessageFrame frame2(2, MakeSpan(&allocator_, "message2", &storage)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7470 | QuicFrames frames = {QuicFrame(&frame), QuicFrame(&frame2)}; |
| 7471 | |
| 7472 | // clang-format off |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7473 | unsigned char packet46[] = { |
| 7474 | // type (short header, 4 byte packet number) |
| 7475 | 0x43, |
| 7476 | // connection_id |
| 7477 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7478 | // packet number |
| 7479 | 0x12, 0x34, 0x56, 0x78, |
| 7480 | |
| 7481 | // frame type (message frame) |
| 7482 | 0x21, |
| 7483 | // Length |
| 7484 | 0x07, |
| 7485 | // Message Data |
| 7486 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 7487 | // frame type (message frame no length) |
| 7488 | 0x20, |
| 7489 | // Message Data |
| 7490 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 7491 | }; |
| 7492 | |
| 7493 | unsigned char packet99[] = { |
| 7494 | // type (short header, 4 byte packet number) |
| 7495 | 0x43, |
| 7496 | // connection_id |
| 7497 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7498 | // packet number |
| 7499 | 0x12, 0x34, 0x56, 0x78, |
| 7500 | |
| 7501 | // frame type (IETF_MESSAGE frame) |
| 7502 | 0x21, |
| 7503 | // Length |
| 7504 | 0x07, |
| 7505 | // Message Data |
| 7506 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 7507 | // frame type (message frame no length) |
| 7508 | 0x20, |
| 7509 | // Message Data |
| 7510 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 7511 | }; |
| 7512 | // clang-format on |
| 7513 | |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 7514 | unsigned char* p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7515 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7516 | p = packet99; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7517 | } |
| 7518 | |
| 7519 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7520 | ASSERT_TRUE(data != nullptr); |
| 7521 | |
| 7522 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7523 | data->length(), AsChars(p), |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 7524 | QUIC_ARRAYSIZE(packet46)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7525 | } |
| 7526 | |
| 7527 | // Test that the connectivity probing packet is serialized correctly as a |
| 7528 | // padded PING packet. |
| 7529 | TEST_P(QuicFramerTest, BuildConnectivityProbingPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7530 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7531 | QuicPacketHeader header; |
| 7532 | header.destination_connection_id = FramerTestConnectionId(); |
| 7533 | header.reset_flag = false; |
| 7534 | header.version_flag = false; |
| 7535 | header.packet_number = kPacketNumber; |
| 7536 | |
| 7537 | // clang-format off |
| 7538 | unsigned char packet[] = { |
| 7539 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7540 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7541 | // connection_id |
| 7542 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7543 | // packet number |
| 7544 | 0x12, 0x34, 0x56, 0x78, |
| 7545 | |
| 7546 | // frame type (ping frame) |
| 7547 | 0x07, |
| 7548 | // frame type (padding frame) |
| 7549 | 0x00, |
| 7550 | 0x00, 0x00, 0x00, 0x00 |
| 7551 | }; |
| 7552 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7553 | unsigned char packet46[] = { |
| 7554 | // type (short header, 4 byte packet number) |
| 7555 | 0x43, |
| 7556 | // connection_id |
| 7557 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7558 | // packet number |
| 7559 | 0x12, 0x34, 0x56, 0x78, |
| 7560 | |
| 7561 | // frame type |
| 7562 | 0x07, |
| 7563 | // frame type (padding frame) |
| 7564 | 0x00, |
| 7565 | 0x00, 0x00, 0x00, 0x00 |
| 7566 | }; |
| 7567 | |
| 7568 | unsigned char packet99[] = { |
| 7569 | // type (short header, 4 byte packet number) |
| 7570 | 0x43, |
| 7571 | // connection_id |
| 7572 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7573 | // packet number |
| 7574 | 0x12, 0x34, 0x56, 0x78, |
| 7575 | |
| 7576 | // frame type (IETF_PING frame) |
| 7577 | 0x01, |
| 7578 | // frame type (padding frame) |
| 7579 | 0x00, |
| 7580 | 0x00, 0x00, 0x00, 0x00 |
| 7581 | }; |
| 7582 | // clang-format on |
| 7583 | |
| 7584 | unsigned char* p = packet; |
| 7585 | size_t packet_size = QUIC_ARRAYSIZE(packet); |
| 7586 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7587 | p = packet99; |
| 7588 | packet_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 7589 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7590 | p = packet46; |
| 7591 | packet_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7592 | } |
| 7593 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 7594 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7595 | |
| 7596 | size_t length = framer_.BuildConnectivityProbingPacket( |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 7597 | header, buffer.get(), packet_size, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7598 | |
| 7599 | EXPECT_NE(0u, length); |
| 7600 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 7601 | header); |
| 7602 | |
| 7603 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 7604 | data.length(), AsChars(p), packet_size); |
| 7605 | } |
| 7606 | |
| 7607 | // Test that the path challenge connectivity probing packet is serialized |
| 7608 | // correctly as a padded PATH CHALLENGE packet. |
| 7609 | TEST_P(QuicFramerTest, BuildPaddedPathChallengePacket) { |
| 7610 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 7611 | return; |
| 7612 | } |
| 7613 | |
| 7614 | QuicPacketHeader header; |
| 7615 | header.destination_connection_id = FramerTestConnectionId(); |
| 7616 | header.reset_flag = false; |
| 7617 | header.version_flag = false; |
| 7618 | header.packet_number = kPacketNumber; |
| 7619 | QuicPathFrameBuffer payload; |
| 7620 | |
| 7621 | // clang-format off |
| 7622 | unsigned char packet[] = { |
| 7623 | // type (short header, 4 byte packet number) |
| 7624 | 0x43, |
| 7625 | // connection_id |
| 7626 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7627 | // packet number |
| 7628 | 0x12, 0x34, 0x56, 0x78, |
| 7629 | |
| 7630 | // Path Challenge Frame type (IETF_PATH_CHALLENGE) |
| 7631 | 0x1a, |
| 7632 | // 8 "random" bytes, MockRandom makes lots of r's |
| 7633 | 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', |
| 7634 | // frame type (padding frame) |
| 7635 | 0x00, |
| 7636 | 0x00, 0x00, 0x00, 0x00 |
| 7637 | }; |
| 7638 | // clang-format on |
| 7639 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 7640 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7641 | MockRandom randomizer; |
| 7642 | |
| 7643 | size_t length = framer_.BuildPaddedPathChallengePacket( |
| 7644 | header, buffer.get(), QUIC_ARRAYSIZE(packet), &payload, &randomizer, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 7645 | ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7646 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 7647 | |
| 7648 | // Payload has the random bytes that were generated. Copy them into packet, |
| 7649 | // above, before checking that the generated packet is correct. |
| 7650 | EXPECT_EQ(kQuicPathFrameBufferSize, payload.size()); |
| 7651 | |
| 7652 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 7653 | header); |
| 7654 | |
| 7655 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 7656 | data.length(), AsChars(packet), |
| 7657 | QUIC_ARRAYSIZE(packet)); |
| 7658 | } |
| 7659 | |
| 7660 | // Several tests that the path response connectivity probing packet is |
| 7661 | // serialized correctly as either a padded and unpadded PATH RESPONSE |
| 7662 | // packet. Also generates packets with 1 and 3 PATH_RESPONSES in them to |
| 7663 | // exercised the single- and multiple- payload cases. |
| 7664 | TEST_P(QuicFramerTest, BuildPathResponsePacket1ResponseUnpadded) { |
| 7665 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 7666 | return; |
| 7667 | } |
| 7668 | |
| 7669 | QuicPacketHeader header; |
| 7670 | header.destination_connection_id = FramerTestConnectionId(); |
| 7671 | header.reset_flag = false; |
| 7672 | header.version_flag = false; |
| 7673 | header.packet_number = kPacketNumber; |
| 7674 | QuicPathFrameBuffer payload0 = { |
| 7675 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 7676 | |
| 7677 | // Build 1 PATH RESPONSE, not padded |
| 7678 | // clang-format off |
| 7679 | unsigned char packet[] = { |
| 7680 | // type (short header, 4 byte packet number) |
| 7681 | 0x43, |
| 7682 | // connection_id |
| 7683 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7684 | // packet number |
| 7685 | 0x12, 0x34, 0x56, 0x78, |
| 7686 | |
| 7687 | // Path Response Frame type (IETF_PATH_RESPONSE) |
| 7688 | 0x1b, |
| 7689 | // 8 "random" bytes |
| 7690 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 7691 | }; |
| 7692 | // clang-format on |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 7693 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7694 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 7695 | payloads.push_back(payload0); |
| 7696 | size_t length = framer_.BuildPathResponsePacket( |
| 7697 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 7698 | /*is_padded=*/false, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7699 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 7700 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 7701 | header); |
| 7702 | |
| 7703 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 7704 | data.length(), AsChars(packet), |
| 7705 | QUIC_ARRAYSIZE(packet)); |
| 7706 | } |
| 7707 | |
| 7708 | TEST_P(QuicFramerTest, BuildPathResponsePacket1ResponsePadded) { |
| 7709 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 7710 | return; |
| 7711 | } |
| 7712 | |
| 7713 | QuicPacketHeader header; |
| 7714 | header.destination_connection_id = FramerTestConnectionId(); |
| 7715 | header.reset_flag = false; |
| 7716 | header.version_flag = false; |
| 7717 | header.packet_number = kPacketNumber; |
| 7718 | QuicPathFrameBuffer payload0 = { |
| 7719 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 7720 | |
| 7721 | // Build 1 PATH RESPONSE, padded |
| 7722 | // clang-format off |
| 7723 | unsigned char packet[] = { |
| 7724 | // type (short header, 4 byte packet number) |
| 7725 | 0x43, |
| 7726 | // connection_id |
| 7727 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7728 | // packet number |
| 7729 | 0x12, 0x34, 0x56, 0x78, |
| 7730 | |
| 7731 | // Path Response Frame type (IETF_PATH_RESPONSE) |
| 7732 | 0x1b, |
| 7733 | // 8 "random" bytes |
| 7734 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 7735 | // Padding type and pad |
| 7736 | 0x00, 0x00, 0x00, 0x00, 0x00 |
| 7737 | }; |
| 7738 | // clang-format on |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 7739 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7740 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 7741 | payloads.push_back(payload0); |
| 7742 | size_t length = framer_.BuildPathResponsePacket( |
| 7743 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 7744 | /*is_padded=*/true, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7745 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 7746 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 7747 | header); |
| 7748 | |
| 7749 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 7750 | data.length(), AsChars(packet), |
| 7751 | QUIC_ARRAYSIZE(packet)); |
| 7752 | } |
| 7753 | |
| 7754 | TEST_P(QuicFramerTest, BuildPathResponsePacket3ResponsesUnpadded) { |
| 7755 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 7756 | return; |
| 7757 | } |
| 7758 | |
| 7759 | QuicPacketHeader header; |
| 7760 | header.destination_connection_id = FramerTestConnectionId(); |
| 7761 | header.reset_flag = false; |
| 7762 | header.version_flag = false; |
| 7763 | header.packet_number = kPacketNumber; |
| 7764 | QuicPathFrameBuffer payload0 = { |
| 7765 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 7766 | QuicPathFrameBuffer payload1 = { |
| 7767 | {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}}; |
| 7768 | QuicPathFrameBuffer payload2 = { |
| 7769 | {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28}}; |
| 7770 | |
| 7771 | // Build one packet with 3 PATH RESPONSES, no padding |
| 7772 | // clang-format off |
| 7773 | unsigned char packet[] = { |
| 7774 | // type (short header, 4 byte packet number) |
| 7775 | 0x43, |
| 7776 | // connection_id |
| 7777 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7778 | // packet number |
| 7779 | 0x12, 0x34, 0x56, 0x78, |
| 7780 | |
| 7781 | // 3 path response frames (IETF_PATH_RESPONSE type byte and payload) |
| 7782 | 0x1b, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 7783 | 0x1b, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, |
| 7784 | 0x1b, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, |
| 7785 | }; |
| 7786 | // clang-format on |
| 7787 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 7788 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7789 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 7790 | payloads.push_back(payload0); |
| 7791 | payloads.push_back(payload1); |
| 7792 | payloads.push_back(payload2); |
| 7793 | size_t length = framer_.BuildPathResponsePacket( |
| 7794 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 7795 | /*is_padded=*/false, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7796 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 7797 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 7798 | header); |
| 7799 | |
| 7800 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 7801 | data.length(), AsChars(packet), |
| 7802 | QUIC_ARRAYSIZE(packet)); |
| 7803 | } |
| 7804 | |
| 7805 | TEST_P(QuicFramerTest, BuildPathResponsePacket3ResponsesPadded) { |
| 7806 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 7807 | return; |
| 7808 | } |
| 7809 | |
| 7810 | QuicPacketHeader header; |
| 7811 | header.destination_connection_id = FramerTestConnectionId(); |
| 7812 | header.reset_flag = false; |
| 7813 | header.version_flag = false; |
| 7814 | header.packet_number = kPacketNumber; |
| 7815 | QuicPathFrameBuffer payload0 = { |
| 7816 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 7817 | QuicPathFrameBuffer payload1 = { |
| 7818 | {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}}; |
| 7819 | QuicPathFrameBuffer payload2 = { |
| 7820 | {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28}}; |
| 7821 | |
| 7822 | // Build one packet with 3 PATH RESPONSES, with padding |
| 7823 | // clang-format off |
| 7824 | unsigned char packet[] = { |
| 7825 | // type (short header, 4 byte packet number) |
| 7826 | 0x43, |
| 7827 | // connection_id |
| 7828 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7829 | // packet number |
| 7830 | 0x12, 0x34, 0x56, 0x78, |
| 7831 | |
| 7832 | // 3 path response frames (IETF_PATH_RESPONSE byte and payload) |
| 7833 | 0x1b, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 7834 | 0x1b, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, |
| 7835 | 0x1b, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, |
| 7836 | // Padding |
| 7837 | 0x00, 0x00, 0x00, 0x00, 0x00 |
| 7838 | }; |
| 7839 | // clang-format on |
| 7840 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 7841 | std::unique_ptr<char[]> buffer(new char[kMaxOutgoingPacketSize]); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7842 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 7843 | payloads.push_back(payload0); |
| 7844 | payloads.push_back(payload1); |
| 7845 | payloads.push_back(payload2); |
| 7846 | size_t length = framer_.BuildPathResponsePacket( |
| 7847 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 7848 | /*is_padded=*/true, ENCRYPTION_INITIAL); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7849 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 7850 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 7851 | header); |
| 7852 | |
| 7853 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 7854 | data.length(), AsChars(packet), |
| 7855 | QUIC_ARRAYSIZE(packet)); |
| 7856 | } |
| 7857 | |
| 7858 | // Test that the MTU discovery packet is serialized correctly as a PING packet. |
| 7859 | TEST_P(QuicFramerTest, BuildMtuDiscoveryPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7860 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7861 | QuicPacketHeader header; |
| 7862 | header.destination_connection_id = FramerTestConnectionId(); |
| 7863 | header.reset_flag = false; |
| 7864 | header.version_flag = false; |
| 7865 | header.packet_number = kPacketNumber; |
| 7866 | |
| 7867 | QuicFrames frames = {QuicFrame(QuicMtuDiscoveryFrame())}; |
| 7868 | |
| 7869 | // clang-format off |
| 7870 | unsigned char packet[] = { |
| 7871 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7872 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7873 | // connection_id |
| 7874 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7875 | // packet number |
| 7876 | 0x12, 0x34, 0x56, 0x78, |
| 7877 | |
| 7878 | // frame type (ping frame) |
| 7879 | 0x07, |
| 7880 | }; |
| 7881 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7882 | unsigned char packet46[] = { |
| 7883 | // type (short header, 4 byte packet number) |
| 7884 | 0x43, |
| 7885 | // connection_id |
| 7886 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7887 | // packet number |
| 7888 | 0x12, 0x34, 0x56, 0x78, |
| 7889 | |
| 7890 | // frame type |
| 7891 | 0x07, |
| 7892 | }; |
| 7893 | |
| 7894 | unsigned char packet99[] = { |
| 7895 | // type (short header, 4 byte packet number) |
| 7896 | 0x43, |
| 7897 | // connection_id |
| 7898 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7899 | // packet number |
| 7900 | 0x12, 0x34, 0x56, 0x78, |
| 7901 | |
| 7902 | // frame type (IETF_PING frame) |
| 7903 | 0x01, |
| 7904 | }; |
| 7905 | // clang-format on |
| 7906 | |
| 7907 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7908 | ASSERT_TRUE(data != nullptr); |
| 7909 | |
| 7910 | unsigned char* p = packet; |
| 7911 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7912 | p = packet99; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7913 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 7914 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7915 | } |
| 7916 | |
| 7917 | test::CompareCharArraysWithHexError( |
| 7918 | "constructed packet", data->data(), data->length(), AsChars(p), |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 7919 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet46) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7920 | : QUIC_ARRAYSIZE(packet)); |
| 7921 | } |
| 7922 | |
| 7923 | TEST_P(QuicFramerTest, BuildPublicResetPacket) { |
| 7924 | QuicPublicResetPacket reset_packet; |
| 7925 | reset_packet.connection_id = FramerTestConnectionId(); |
| 7926 | reset_packet.nonce_proof = kNonceProof; |
| 7927 | |
| 7928 | // clang-format off |
| 7929 | unsigned char packet[] = { |
| 7930 | // public flags (public reset, 8 byte ConnectionId) |
| 7931 | 0x0E, |
| 7932 | // connection_id |
| 7933 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7934 | // message tag (kPRST) |
| 7935 | 'P', 'R', 'S', 'T', |
| 7936 | // num_entries (1) + padding |
| 7937 | 0x01, 0x00, 0x00, 0x00, |
| 7938 | // tag kRNON |
| 7939 | 'R', 'N', 'O', 'N', |
| 7940 | // end offset 8 |
| 7941 | 0x08, 0x00, 0x00, 0x00, |
| 7942 | // nonce proof |
| 7943 | 0x89, 0x67, 0x45, 0x23, |
| 7944 | 0x01, 0xEF, 0xCD, 0xAB, |
| 7945 | }; |
| 7946 | // clang-format on |
| 7947 | |
| 7948 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7949 | return; |
| 7950 | } |
| 7951 | |
| 7952 | std::unique_ptr<QuicEncryptedPacket> data( |
| 7953 | framer_.BuildPublicResetPacket(reset_packet)); |
| 7954 | ASSERT_TRUE(data != nullptr); |
| 7955 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7956 | data->length(), AsChars(packet), |
| 7957 | QUIC_ARRAYSIZE(packet)); |
| 7958 | } |
| 7959 | |
| 7960 | TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) { |
| 7961 | QuicPublicResetPacket reset_packet; |
| 7962 | reset_packet.connection_id = FramerTestConnectionId(); |
| 7963 | reset_packet.nonce_proof = kNonceProof; |
| 7964 | reset_packet.client_address = |
| 7965 | QuicSocketAddress(QuicIpAddress::Loopback4(), 0x1234); |
| 7966 | |
| 7967 | // clang-format off |
| 7968 | unsigned char packet[] = { |
| 7969 | // public flags (public reset, 8 byte ConnectionId) |
| 7970 | 0x0E, |
| 7971 | // connection_id |
| 7972 | 0xFE, 0xDC, 0xBA, 0x98, |
| 7973 | 0x76, 0x54, 0x32, 0x10, |
| 7974 | // message tag (kPRST) |
| 7975 | 'P', 'R', 'S', 'T', |
| 7976 | // num_entries (2) + padding |
| 7977 | 0x02, 0x00, 0x00, 0x00, |
| 7978 | // tag kRNON |
| 7979 | 'R', 'N', 'O', 'N', |
| 7980 | // end offset 8 |
| 7981 | 0x08, 0x00, 0x00, 0x00, |
| 7982 | // tag kCADR |
| 7983 | 'C', 'A', 'D', 'R', |
| 7984 | // end offset 16 |
| 7985 | 0x10, 0x00, 0x00, 0x00, |
| 7986 | // nonce proof |
| 7987 | 0x89, 0x67, 0x45, 0x23, |
| 7988 | 0x01, 0xEF, 0xCD, 0xAB, |
| 7989 | // client address |
| 7990 | 0x02, 0x00, |
| 7991 | 0x7F, 0x00, 0x00, 0x01, |
| 7992 | 0x34, 0x12, |
| 7993 | }; |
| 7994 | // clang-format on |
| 7995 | |
| 7996 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7997 | return; |
| 7998 | } |
| 7999 | |
| 8000 | std::unique_ptr<QuicEncryptedPacket> data( |
| 8001 | framer_.BuildPublicResetPacket(reset_packet)); |
| 8002 | ASSERT_TRUE(data != nullptr); |
| 8003 | |
| 8004 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8005 | data->length(), AsChars(packet), |
| 8006 | QUIC_ARRAYSIZE(packet)); |
| 8007 | } |
| 8008 | |
| 8009 | TEST_P(QuicFramerTest, BuildPublicResetPacketWithEndpointId) { |
| 8010 | QuicPublicResetPacket reset_packet; |
| 8011 | reset_packet.connection_id = FramerTestConnectionId(); |
| 8012 | reset_packet.nonce_proof = kNonceProof; |
| 8013 | reset_packet.endpoint_id = "FakeServerId"; |
| 8014 | |
| 8015 | // The tag value map in CryptoHandshakeMessage is a std::map, so the two tags |
| 8016 | // in the packet, kRNON and kEPID, have unspecified ordering w.r.t each other. |
| 8017 | // clang-format off |
| 8018 | unsigned char packet_variant1[] = { |
| 8019 | // public flags (public reset, 8 byte ConnectionId) |
| 8020 | 0x0E, |
| 8021 | // connection_id |
| 8022 | 0xFE, 0xDC, 0xBA, 0x98, |
| 8023 | 0x76, 0x54, 0x32, 0x10, |
| 8024 | // message tag (kPRST) |
| 8025 | 'P', 'R', 'S', 'T', |
| 8026 | // num_entries (2) + padding |
| 8027 | 0x02, 0x00, 0x00, 0x00, |
| 8028 | // tag kRNON |
| 8029 | 'R', 'N', 'O', 'N', |
| 8030 | // end offset 8 |
| 8031 | 0x08, 0x00, 0x00, 0x00, |
| 8032 | // tag kEPID |
| 8033 | 'E', 'P', 'I', 'D', |
| 8034 | // end offset 20 |
| 8035 | 0x14, 0x00, 0x00, 0x00, |
| 8036 | // nonce proof |
| 8037 | 0x89, 0x67, 0x45, 0x23, |
| 8038 | 0x01, 0xEF, 0xCD, 0xAB, |
| 8039 | // Endpoint ID |
| 8040 | 'F', 'a', 'k', 'e', 'S', 'e', 'r', 'v', 'e', 'r', 'I', 'd', |
| 8041 | }; |
| 8042 | unsigned char packet_variant2[] = { |
| 8043 | // public flags (public reset, 8 byte ConnectionId) |
| 8044 | 0x0E, |
| 8045 | // connection_id |
| 8046 | 0xFE, 0xDC, 0xBA, 0x98, |
| 8047 | 0x76, 0x54, 0x32, 0x10, |
| 8048 | // message tag (kPRST) |
| 8049 | 'P', 'R', 'S', 'T', |
| 8050 | // num_entries (2) + padding |
| 8051 | 0x02, 0x00, 0x00, 0x00, |
| 8052 | // tag kEPID |
| 8053 | 'E', 'P', 'I', 'D', |
| 8054 | // end offset 12 |
| 8055 | 0x0C, 0x00, 0x00, 0x00, |
| 8056 | // tag kRNON |
| 8057 | 'R', 'N', 'O', 'N', |
| 8058 | // end offset 20 |
| 8059 | 0x14, 0x00, 0x00, 0x00, |
| 8060 | // Endpoint ID |
| 8061 | 'F', 'a', 'k', 'e', 'S', 'e', 'r', 'v', 'e', 'r', 'I', 'd', |
| 8062 | // nonce proof |
| 8063 | 0x89, 0x67, 0x45, 0x23, |
| 8064 | 0x01, 0xEF, 0xCD, 0xAB, |
| 8065 | }; |
| 8066 | // clang-format on |
| 8067 | |
| 8068 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8069 | return; |
| 8070 | } |
| 8071 | |
| 8072 | std::unique_ptr<QuicEncryptedPacket> data( |
| 8073 | framer_.BuildPublicResetPacket(reset_packet)); |
| 8074 | ASSERT_TRUE(data != nullptr); |
| 8075 | |
| 8076 | // Variant 1 ends with char 'd'. Variant 1 ends with char 0xAB. |
| 8077 | if ('d' == data->data()[data->length() - 1]) { |
| 8078 | test::CompareCharArraysWithHexError( |
| 8079 | "constructed packet", data->data(), data->length(), |
| 8080 | AsChars(packet_variant1), QUIC_ARRAYSIZE(packet_variant1)); |
| 8081 | } else { |
| 8082 | test::CompareCharArraysWithHexError( |
| 8083 | "constructed packet", data->data(), data->length(), |
| 8084 | AsChars(packet_variant2), QUIC_ARRAYSIZE(packet_variant2)); |
| 8085 | } |
| 8086 | } |
| 8087 | |
| 8088 | TEST_P(QuicFramerTest, BuildIetfStatelessResetPacket) { |
| 8089 | // clang-format off |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 8090 | unsigned char packet[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8091 | // type (short header, 1 byte packet number) |
| 8092 | 0x70, |
| 8093 | // random packet number |
| 8094 | 0xFE, |
| 8095 | // stateless reset token |
| 8096 | 0xB5, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 8097 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 8098 | }; |
| 8099 | // clang-format on |
| 8100 | |
| 8101 | std::unique_ptr<QuicEncryptedPacket> data( |
| 8102 | framer_.BuildIetfStatelessResetPacket(FramerTestConnectionId(), |
| 8103 | kTestStatelessResetToken)); |
| 8104 | ASSERT_TRUE(data != nullptr); |
| 8105 | // Skip packet number byte which is random in stateless reset packet. |
| 8106 | test::CompareCharArraysWithHexError("constructed packet", data->data(), 1, |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 8107 | AsChars(packet), 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8108 | const size_t random_bytes_length = |
| 8109 | data->length() - kPacketHeaderTypeSize - sizeof(kTestStatelessResetToken); |
| 8110 | EXPECT_EQ(kMinRandomBytesLengthInStatelessReset, random_bytes_length); |
| 8111 | // Verify stateless reset token is correct. |
| 8112 | test::CompareCharArraysWithHexError( |
| 8113 | "constructed packet", |
| 8114 | data->data() + data->length() - sizeof(kTestStatelessResetToken), |
| 8115 | sizeof(kTestStatelessResetToken), |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 8116 | AsChars(packet) + QUIC_ARRAYSIZE(packet) - |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8117 | sizeof(kTestStatelessResetToken), |
| 8118 | sizeof(kTestStatelessResetToken)); |
| 8119 | } |
| 8120 | |
| 8121 | TEST_P(QuicFramerTest, EncryptPacket) { |
| 8122 | QuicPacketNumber packet_number = kPacketNumber; |
| 8123 | // clang-format off |
| 8124 | unsigned char packet[] = { |
| 8125 | // public flags (8 byte connection_id) |
| 8126 | 0x28, |
| 8127 | // connection_id |
| 8128 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8129 | // packet number |
| 8130 | 0x12, 0x34, 0x56, 0x78, |
| 8131 | |
| 8132 | // redundancy |
| 8133 | 'a', 'b', 'c', 'd', |
| 8134 | 'e', 'f', 'g', 'h', |
| 8135 | 'i', 'j', 'k', 'l', |
| 8136 | 'm', 'n', 'o', 'p', |
| 8137 | }; |
| 8138 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8139 | unsigned char packet46[] = { |
| 8140 | // type (short header, 4 byte packet number) |
| 8141 | 0x43, |
| 8142 | // connection_id |
| 8143 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8144 | // packet number |
| 8145 | 0x12, 0x34, 0x56, 0x78, |
| 8146 | |
| 8147 | // redundancy |
| 8148 | 'a', 'b', 'c', 'd', |
| 8149 | 'e', 'f', 'g', 'h', |
| 8150 | 'i', 'j', 'k', 'l', |
| 8151 | 'm', 'n', 'o', 'p', |
| 8152 | }; |
| 8153 | |
| 8154 | unsigned char packet99[] = { |
| 8155 | // type (short header, 4 byte packet number) |
| 8156 | 0x43, |
| 8157 | // connection_id |
| 8158 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8159 | // packet number |
| 8160 | 0x12, 0x34, 0x56, 0x78, |
| 8161 | |
| 8162 | // redundancy |
| 8163 | 'a', 'b', 'c', 'd', |
| 8164 | 'e', 'f', 'g', 'h', |
| 8165 | 'i', 'j', 'k', 'l', |
| 8166 | 'm', 'n', 'o', 'p', |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 8167 | 'q', 'r', 's', 't', |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8168 | }; |
| 8169 | // clang-format on |
| 8170 | |
| 8171 | unsigned char* p = packet; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 8172 | size_t p_size = QUIC_ARRAYSIZE(packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8173 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8174 | p = packet99; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 8175 | p_size = QUIC_ARRAYSIZE(packet99); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8176 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 8177 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8178 | } |
| 8179 | |
| 8180 | std::unique_ptr<QuicPacket> raw(new QuicPacket( |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 8181 | AsChars(p), p_size, false, PACKET_8BYTE_CONNECTION_ID, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8182 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 8183 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 8184 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0)); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8185 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8186 | size_t encrypted_length = framer_.EncryptPayload( |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8187 | ENCRYPTION_INITIAL, packet_number, *raw, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8188 | |
| 8189 | ASSERT_NE(0u, encrypted_length); |
| 8190 | EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); |
| 8191 | } |
| 8192 | |
| 8193 | TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 8194 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8195 | QuicPacketNumber packet_number = kPacketNumber; |
| 8196 | // clang-format off |
| 8197 | unsigned char packet[] = { |
| 8198 | // public flags (version, 8 byte connection_id) |
| 8199 | 0x29, |
| 8200 | // connection_id |
| 8201 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8202 | // version tag |
| 8203 | 'Q', '.', '1', '0', |
| 8204 | // packet number |
| 8205 | 0x12, 0x34, 0x56, 0x78, |
| 8206 | |
| 8207 | // redundancy |
| 8208 | 'a', 'b', 'c', 'd', |
| 8209 | 'e', 'f', 'g', 'h', |
| 8210 | 'i', 'j', 'k', 'l', |
| 8211 | 'm', 'n', 'o', 'p', |
| 8212 | }; |
| 8213 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8214 | unsigned char packet46[] = { |
| 8215 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 8216 | 0xD3, |
| 8217 | // version tag |
| 8218 | 'Q', '.', '1', '0', |
| 8219 | // connection_id length |
| 8220 | 0x50, |
| 8221 | // connection_id |
| 8222 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8223 | // packet number |
| 8224 | 0x12, 0x34, 0x56, 0x78, |
| 8225 | |
| 8226 | // redundancy |
| 8227 | 'a', 'b', 'c', 'd', |
| 8228 | 'e', 'f', 'g', 'h', |
| 8229 | 'i', 'j', 'k', 'l', |
| 8230 | 'm', 'n', 'o', 'p', |
| 8231 | }; |
| 8232 | |
| 8233 | unsigned char packet99[] = { |
| 8234 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 8235 | 0xD3, |
| 8236 | // version tag |
| 8237 | 'Q', '.', '1', '0', |
| 8238 | // connection_id length |
| 8239 | 0x50, |
| 8240 | // connection_id |
| 8241 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8242 | // packet number |
| 8243 | 0x12, 0x34, 0x56, 0x78, |
| 8244 | |
| 8245 | // redundancy |
| 8246 | 'a', 'b', 'c', 'd', |
| 8247 | 'e', 'f', 'g', 'h', |
| 8248 | 'i', 'j', 'k', 'l', |
| 8249 | 'm', 'n', 'o', 'p', |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 8250 | 'q', 'r', 's', 't', |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8251 | }; |
| 8252 | // clang-format on |
| 8253 | |
| 8254 | unsigned char* p = packet; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 8255 | size_t p_size = QUIC_ARRAYSIZE(packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8256 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8257 | p = packet99; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 8258 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 8259 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8260 | p = packet46; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 8261 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8262 | } |
| 8263 | |
| 8264 | std::unique_ptr<QuicPacket> raw(new QuicPacket( |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 8265 | AsChars(p), p_size, false, PACKET_8BYTE_CONNECTION_ID, |
| 8266 | PACKET_0BYTE_CONNECTION_ID, kIncludeVersion, |
| 8267 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 8268 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0)); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8269 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8270 | size_t encrypted_length = framer_.EncryptPayload( |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8271 | ENCRYPTION_INITIAL, packet_number, *raw, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8272 | |
| 8273 | ASSERT_NE(0u, encrypted_length); |
| 8274 | EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); |
| 8275 | } |
| 8276 | |
| 8277 | TEST_P(QuicFramerTest, AckTruncationLargePacket) { |
| 8278 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8279 | // This test is not applicable to this version; the range count is |
| 8280 | // effectively unlimited |
| 8281 | return; |
| 8282 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 8283 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8284 | |
| 8285 | QuicPacketHeader header; |
| 8286 | header.destination_connection_id = FramerTestConnectionId(); |
| 8287 | header.reset_flag = false; |
| 8288 | header.version_flag = false; |
| 8289 | header.packet_number = kPacketNumber; |
| 8290 | |
| 8291 | QuicAckFrame ack_frame; |
| 8292 | // Create a packet with just the ack. |
| 8293 | ack_frame = MakeAckFrameWithAckBlocks(300, 0u); |
| 8294 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 8295 | |
| 8296 | // Build an ack packet with truncation due to limit in number of nack ranges. |
| 8297 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 8298 | std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); |
| 8299 | ASSERT_TRUE(raw_ack_packet != nullptr); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8300 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8301 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 8302 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8303 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8304 | ASSERT_NE(0u, encrypted_length); |
| 8305 | // Now make sure we can turn our ack packet back into an ack frame. |
| 8306 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 8307 | ASSERT_TRUE(framer_.ProcessPacket( |
| 8308 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 8309 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 8310 | QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; |
| 8311 | EXPECT_EQ(QuicPacketNumber(600u), LargestAcked(processed_ack_frame)); |
| 8312 | ASSERT_EQ(256u, processed_ack_frame.packets.NumPacketsSlow()); |
| 8313 | EXPECT_EQ(QuicPacketNumber(90u), processed_ack_frame.packets.Min()); |
| 8314 | EXPECT_EQ(QuicPacketNumber(600u), processed_ack_frame.packets.Max()); |
| 8315 | } |
| 8316 | |
| 8317 | TEST_P(QuicFramerTest, AckTruncationSmallPacket) { |
| 8318 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8319 | // This test is not applicable to this version; the range count is |
| 8320 | // effectively unlimited |
| 8321 | return; |
| 8322 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 8323 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8324 | |
| 8325 | QuicPacketHeader header; |
| 8326 | header.destination_connection_id = FramerTestConnectionId(); |
| 8327 | header.reset_flag = false; |
| 8328 | header.version_flag = false; |
| 8329 | header.packet_number = kPacketNumber; |
| 8330 | |
| 8331 | // Create a packet with just the ack. |
| 8332 | QuicAckFrame ack_frame; |
| 8333 | ack_frame = MakeAckFrameWithAckBlocks(300, 0u); |
| 8334 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 8335 | |
| 8336 | // Build an ack packet with truncation due to limit in number of nack ranges. |
| 8337 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 8338 | std::unique_ptr<QuicPacket> raw_ack_packet( |
| 8339 | BuildDataPacket(header, frames, 500)); |
| 8340 | ASSERT_TRUE(raw_ack_packet != nullptr); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8341 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8342 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 8343 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8344 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8345 | ASSERT_NE(0u, encrypted_length); |
| 8346 | // Now make sure we can turn our ack packet back into an ack frame. |
| 8347 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 8348 | ASSERT_TRUE(framer_.ProcessPacket( |
| 8349 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 8350 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 8351 | QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; |
| 8352 | EXPECT_EQ(QuicPacketNumber(600u), LargestAcked(processed_ack_frame)); |
| 8353 | ASSERT_EQ(240u, processed_ack_frame.packets.NumPacketsSlow()); |
| 8354 | EXPECT_EQ(QuicPacketNumber(122u), processed_ack_frame.packets.Min()); |
| 8355 | EXPECT_EQ(QuicPacketNumber(600u), processed_ack_frame.packets.Max()); |
| 8356 | } |
| 8357 | |
| 8358 | TEST_P(QuicFramerTest, CleanTruncation) { |
| 8359 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8360 | // This test is not applicable to this version; the range count is |
| 8361 | // effectively unlimited |
| 8362 | return; |
| 8363 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 8364 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8365 | |
| 8366 | QuicPacketHeader header; |
| 8367 | header.destination_connection_id = FramerTestConnectionId(); |
| 8368 | header.reset_flag = false; |
| 8369 | header.version_flag = false; |
| 8370 | header.packet_number = kPacketNumber; |
| 8371 | |
| 8372 | QuicAckFrame ack_frame = InitAckFrame(201); |
| 8373 | |
| 8374 | // Create a packet with just the ack. |
| 8375 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 8376 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 8377 | std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); |
| 8378 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 8379 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8380 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8381 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 8382 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 8383 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8384 | ASSERT_NE(0u, encrypted_length); |
| 8385 | |
| 8386 | // Now make sure we can turn our ack packet back into an ack frame. |
| 8387 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 8388 | ASSERT_TRUE(framer_.ProcessPacket( |
| 8389 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 8390 | |
| 8391 | // Test for clean truncation of the ack by comparing the length of the |
| 8392 | // original packets to the re-serialized packets. |
| 8393 | frames.clear(); |
| 8394 | frames.push_back(QuicFrame(visitor_.ack_frames_[0].get())); |
| 8395 | |
| 8396 | size_t original_raw_length = raw_ack_packet->length(); |
| 8397 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 8398 | raw_ack_packet = BuildDataPacket(header, frames); |
| 8399 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 8400 | EXPECT_EQ(original_raw_length, raw_ack_packet->length()); |
| 8401 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 8402 | } |
| 8403 | |
| 8404 | TEST_P(QuicFramerTest, StopPacketProcessing) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 8405 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8406 | // clang-format off |
| 8407 | unsigned char packet[] = { |
| 8408 | // public flags (8 byte connection_id) |
| 8409 | 0x28, |
| 8410 | // connection_id |
| 8411 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8412 | // packet number |
| 8413 | 0x12, 0x34, 0x56, 0x78, |
| 8414 | |
| 8415 | // frame type (stream frame with fin) |
| 8416 | 0xFF, |
| 8417 | // stream id |
| 8418 | 0x01, 0x02, 0x03, 0x04, |
| 8419 | // offset |
| 8420 | 0x3A, 0x98, 0xFE, 0xDC, |
| 8421 | 0x32, 0x10, 0x76, 0x54, |
| 8422 | // data length |
| 8423 | 0x00, 0x0c, |
| 8424 | // data |
| 8425 | 'h', 'e', 'l', 'l', |
| 8426 | 'o', ' ', 'w', 'o', |
| 8427 | 'r', 'l', 'd', '!', |
| 8428 | |
| 8429 | // frame type (ack frame) |
| 8430 | 0x40, |
| 8431 | // least packet number awaiting an ack |
| 8432 | 0x12, 0x34, 0x56, 0x78, |
| 8433 | 0x9A, 0xA0, |
| 8434 | // largest observed packet number |
| 8435 | 0x12, 0x34, 0x56, 0x78, |
| 8436 | 0x9A, 0xBF, |
| 8437 | // num missing packets |
| 8438 | 0x01, |
| 8439 | // missing packet |
| 8440 | 0x12, 0x34, 0x56, 0x78, |
| 8441 | 0x9A, 0xBE, |
| 8442 | }; |
| 8443 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8444 | unsigned char packet46[] = { |
| 8445 | // type (short header, 4 byte packet number) |
| 8446 | 0x43, |
| 8447 | // connection_id |
| 8448 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8449 | // packet number |
| 8450 | 0x12, 0x34, 0x56, 0x78, |
| 8451 | |
| 8452 | // frame type (stream frame with fin) |
| 8453 | 0xFF, |
| 8454 | // stream id |
| 8455 | 0x01, 0x02, 0x03, 0x04, |
| 8456 | // offset |
| 8457 | 0x3A, 0x98, 0xFE, 0xDC, |
| 8458 | 0x32, 0x10, 0x76, 0x54, |
| 8459 | // data length |
| 8460 | 0x00, 0x0c, |
| 8461 | // data |
| 8462 | 'h', 'e', 'l', 'l', |
| 8463 | 'o', ' ', 'w', 'o', |
| 8464 | 'r', 'l', 'd', '!', |
| 8465 | |
| 8466 | // frame type (ack frame) |
| 8467 | 0x40, |
| 8468 | // least packet number awaiting an ack |
| 8469 | 0x12, 0x34, 0x56, 0x78, |
| 8470 | 0x9A, 0xA0, |
| 8471 | // largest observed packet number |
| 8472 | 0x12, 0x34, 0x56, 0x78, |
| 8473 | 0x9A, 0xBF, |
| 8474 | // num missing packets |
| 8475 | 0x01, |
| 8476 | // missing packet |
| 8477 | 0x12, 0x34, 0x56, 0x78, |
| 8478 | 0x9A, 0xBE, |
| 8479 | }; |
| 8480 | |
| 8481 | unsigned char packet99[] = { |
| 8482 | // type (short header, 4 byte packet number) |
| 8483 | 0x43, |
| 8484 | // connection_id |
| 8485 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8486 | // packet number |
| 8487 | 0x12, 0x34, 0x56, 0x78, |
| 8488 | |
| 8489 | // frame type (IETF_STREAM frame with fin, length, and offset bits set) |
| 8490 | 0x08 | 0x01 | 0x02 | 0x04, |
| 8491 | // stream id |
| 8492 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 8493 | // offset |
| 8494 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 8495 | 0x32, 0x10, 0x76, 0x54, |
| 8496 | // data length |
| 8497 | kVarInt62TwoBytes + 0x00, 0x0c, |
| 8498 | // data |
| 8499 | 'h', 'e', 'l', 'l', |
| 8500 | 'o', ' ', 'w', 'o', |
| 8501 | 'r', 'l', 'd', '!', |
| 8502 | |
| 8503 | // frame type (ack frame) |
| 8504 | 0x0d, |
| 8505 | // largest observed packet number |
| 8506 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 8507 | // Delta time |
| 8508 | kVarInt62OneByte + 0x00, |
| 8509 | // Ack Block count |
| 8510 | kVarInt62OneByte + 0x01, |
| 8511 | // First block size (one packet) |
| 8512 | kVarInt62OneByte + 0x00, |
| 8513 | |
| 8514 | // Next gap size & ack. Missing all preceding packets |
| 8515 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 8516 | kVarInt62OneByte + 0x00, |
| 8517 | }; |
| 8518 | // clang-format on |
| 8519 | |
| 8520 | MockFramerVisitor visitor; |
| 8521 | framer_.set_visitor(&visitor); |
| 8522 | EXPECT_CALL(visitor, OnPacket()); |
| 8523 | EXPECT_CALL(visitor, OnPacketHeader(_)); |
| 8524 | EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false)); |
| 8525 | EXPECT_CALL(visitor, OnPacketComplete()); |
| 8526 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); |
| 8527 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)).WillOnce(Return(true)); |
| 8528 | EXPECT_CALL(visitor, OnDecryptedPacket(_)); |
| 8529 | |
| 8530 | unsigned char* p = packet; |
| 8531 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 8532 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8533 | p = packet99; |
| 8534 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 8535 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8536 | p = packet46; |
| 8537 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8538 | } |
| 8539 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 8540 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 8541 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 8542 | } |
| 8543 | |
| 8544 | static char kTestString[] = "At least 20 characters."; |
| 8545 | static QuicStreamId kTestQuicStreamId = 1; |
| 8546 | static bool ExpectedStreamFrame(const QuicStreamFrame& frame) { |
| 8547 | return (frame.stream_id == kTestQuicStreamId || |
nharper | 46833c3 | 2019-05-15 21:33:05 -0700 | [diff] [blame] | 8548 | QuicUtils::IsCryptoStreamId(QUIC_VERSION_99, frame.stream_id)) && |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8549 | !frame.fin && frame.offset == 0 && |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 8550 | std::string(frame.data_buffer, frame.data_length) == kTestString; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8551 | // FIN is hard-coded false in ConstructEncryptedPacket. |
| 8552 | // Offset 0 is hard-coded in ConstructEncryptedPacket. |
| 8553 | } |
| 8554 | |
| 8555 | // Verify that the packet returned by ConstructEncryptedPacket() can be properly |
| 8556 | // parsed by the framer. |
| 8557 | TEST_P(QuicFramerTest, ConstructEncryptedPacket) { |
| 8558 | // Since we are using ConstructEncryptedPacket, we have to set the framer's |
| 8559 | // crypto to be Null. |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 8560 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 8561 | framer_.InstallDecrypter( |
| 8562 | ENCRYPTION_FORWARD_SECURE, |
| 8563 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
| 8564 | } else { |
| 8565 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 8566 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
| 8567 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8568 | ParsedQuicVersionVector versions; |
| 8569 | versions.push_back(framer_.version()); |
| 8570 | std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
| 8571 | TestConnectionId(), EmptyQuicConnectionId(), false, false, |
| 8572 | kTestQuicStreamId, kTestString, CONNECTION_ID_PRESENT, |
| 8573 | CONNECTION_ID_ABSENT, PACKET_4BYTE_PACKET_NUMBER, &versions)); |
| 8574 | |
| 8575 | MockFramerVisitor visitor; |
| 8576 | framer_.set_visitor(&visitor); |
| 8577 | EXPECT_CALL(visitor, OnPacket()).Times(1); |
| 8578 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) |
| 8579 | .Times(1) |
| 8580 | .WillOnce(Return(true)); |
| 8581 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) |
| 8582 | .Times(1) |
| 8583 | .WillOnce(Return(true)); |
| 8584 | EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1).WillOnce(Return(true)); |
| 8585 | EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); |
| 8586 | EXPECT_CALL(visitor, OnError(_)).Times(0); |
| 8587 | EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); |
QUICHE team | ea74008 | 2019-03-11 17:58:43 -0700 | [diff] [blame] | 8588 | if (!QuicVersionUsesCryptoFrames(framer_.version().transport_version)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8589 | EXPECT_CALL(visitor, OnStreamFrame(Truly(ExpectedStreamFrame))).Times(1); |
| 8590 | } else { |
| 8591 | EXPECT_CALL(visitor, OnCryptoFrame(_)).Times(1); |
| 8592 | } |
| 8593 | EXPECT_CALL(visitor, OnPacketComplete()).Times(1); |
| 8594 | |
| 8595 | EXPECT_TRUE(framer_.ProcessPacket(*packet)); |
| 8596 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 8597 | } |
| 8598 | |
| 8599 | // Verify that the packet returned by ConstructMisFramedEncryptedPacket() |
| 8600 | // does cause the framer to return an error. |
| 8601 | TEST_P(QuicFramerTest, ConstructMisFramedEncryptedPacket) { |
| 8602 | // Since we are using ConstructEncryptedPacket, we have to set the framer's |
| 8603 | // crypto to be Null. |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 8604 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 8605 | framer_.InstallDecrypter( |
| 8606 | ENCRYPTION_FORWARD_SECURE, |
| 8607 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 8608 | } else { |
| 8609 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 8610 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
| 8611 | } |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 8612 | framer_.SetEncrypter(ENCRYPTION_INITIAL, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8613 | QuicMakeUnique<NullEncrypter>(framer_.perspective())); |
| 8614 | ParsedQuicVersionVector versions; |
| 8615 | versions.push_back(framer_.version()); |
| 8616 | std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( |
| 8617 | TestConnectionId(), EmptyQuicConnectionId(), false, false, |
| 8618 | kTestQuicStreamId, kTestString, CONNECTION_ID_PRESENT, |
| 8619 | CONNECTION_ID_ABSENT, PACKET_4BYTE_PACKET_NUMBER, &versions, |
| 8620 | Perspective::IS_CLIENT)); |
| 8621 | |
| 8622 | MockFramerVisitor visitor; |
| 8623 | framer_.set_visitor(&visitor); |
| 8624 | EXPECT_CALL(visitor, OnPacket()).Times(1); |
| 8625 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) |
| 8626 | .Times(1) |
| 8627 | .WillOnce(Return(true)); |
| 8628 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) |
| 8629 | .Times(1) |
| 8630 | .WillOnce(Return(true)); |
| 8631 | EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1); |
| 8632 | EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); |
| 8633 | EXPECT_CALL(visitor, OnError(_)).Times(1); |
| 8634 | EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); |
| 8635 | EXPECT_CALL(visitor, OnPacketComplete()).Times(0); |
| 8636 | |
| 8637 | EXPECT_FALSE(framer_.ProcessPacket(*packet)); |
| 8638 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 8639 | } |
| 8640 | |
| 8641 | // Tests for fuzzing with Dr. Fuzz |
| 8642 | // Xref http://www.chromium.org/developers/testing/dr-fuzz for more details. |
| 8643 | #ifdef __cplusplus |
| 8644 | extern "C" { |
| 8645 | #endif |
| 8646 | |
| 8647 | // target function to be fuzzed by Dr. Fuzz |
| 8648 | void QuicFramerFuzzFunc(unsigned char* data, |
| 8649 | size_t size, |
| 8650 | const ParsedQuicVersion& version) { |
| 8651 | QuicFramer framer(AllSupportedVersions(), QuicTime::Zero(), |
| 8652 | Perspective::IS_SERVER, kQuicDefaultConnectionIdLength); |
| 8653 | ASSERT_EQ(GetQuicFlag(FLAGS_quic_supports_tls_handshake), true); |
| 8654 | const char* const packet_bytes = reinterpret_cast<const char*>(data); |
| 8655 | |
| 8656 | // Test the CryptoFramer. |
| 8657 | QuicStringPiece crypto_input(packet_bytes, size); |
| 8658 | std::unique_ptr<CryptoHandshakeMessage> handshake_message( |
| 8659 | CryptoFramer::ParseMessage(crypto_input)); |
| 8660 | |
| 8661 | // Test the regular QuicFramer with the same input. |
| 8662 | NoOpFramerVisitor visitor; |
| 8663 | framer.set_visitor(&visitor); |
| 8664 | framer.set_version(version); |
| 8665 | QuicEncryptedPacket packet(packet_bytes, size); |
| 8666 | framer.ProcessPacket(packet); |
| 8667 | } |
| 8668 | |
| 8669 | #ifdef __cplusplus |
| 8670 | } |
| 8671 | #endif |
| 8672 | |
| 8673 | TEST_P(QuicFramerTest, FramerFuzzTest) { |
| 8674 | // clang-format off |
| 8675 | unsigned char packet[] = { |
| 8676 | // public flags (8 byte connection_id) |
| 8677 | 0x2C, |
| 8678 | // connection_id |
| 8679 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8680 | // packet number |
| 8681 | 0x12, 0x34, 0x56, 0x78, |
| 8682 | // private flags |
| 8683 | 0x00, |
| 8684 | |
| 8685 | // frame type (stream frame with fin) |
| 8686 | 0xFF, |
| 8687 | // stream id |
| 8688 | 0x01, 0x02, 0x03, 0x04, |
| 8689 | // offset |
| 8690 | 0x3A, 0x98, 0xFE, 0xDC, |
| 8691 | 0x32, 0x10, 0x76, 0x54, |
| 8692 | // data length |
| 8693 | 0x00, 0x0c, |
| 8694 | // data |
| 8695 | 'h', 'e', 'l', 'l', |
| 8696 | 'o', ' ', 'w', 'o', |
| 8697 | 'r', 'l', 'd', '!', |
| 8698 | }; |
| 8699 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8700 | unsigned char packet46[] = { |
| 8701 | // type (short header, 4 byte packet number) |
| 8702 | 0x43, |
| 8703 | // packet number |
| 8704 | 0x12, 0x34, 0x56, 0x78, |
| 8705 | |
| 8706 | // frame type (stream frame with fin, length, and offset bits set) |
| 8707 | 0x10 | 0x01 | 0x02 | 0x04, |
| 8708 | // stream id |
| 8709 | 0x01, 0x02, 0x03, 0x04, |
| 8710 | // offset |
| 8711 | 0x3A, 0x98, 0xFE, 0xDC, |
| 8712 | 0x32, 0x10, 0x76, 0x54, |
| 8713 | // data length |
| 8714 | 0x00, 0x0c, |
| 8715 | // data |
| 8716 | 'h', 'e', 'l', 'l', |
| 8717 | 'o', ' ', 'w', 'o', |
| 8718 | 'r', 'l', 'd', '!', |
| 8719 | }; |
| 8720 | |
| 8721 | unsigned char packet99[] = { |
| 8722 | // type (short header, 4 byte packet number) |
| 8723 | 0x43, |
| 8724 | // packet number |
| 8725 | 0x12, 0x34, 0x56, 0x78, |
| 8726 | |
| 8727 | // frame type (IETF_STREAM frame with fin, length, and offset bits set) |
| 8728 | 0x08 | 0x01 | 0x02 | 0x04, |
| 8729 | // stream id |
| 8730 | 0x01, 0x02, 0x03, 0x04, |
| 8731 | // offset |
| 8732 | 0x3A, 0x98, 0xFE, 0xDC, |
| 8733 | 0x32, 0x10, 0x76, 0x54, |
| 8734 | // data length |
| 8735 | 0x00, 0x0c, |
| 8736 | // data |
| 8737 | 'h', 'e', 'l', 'l', |
| 8738 | 'o', ' ', 'w', 'o', |
| 8739 | 'r', 'l', 'd', '!', |
| 8740 | }; |
| 8741 | // clang-format on |
| 8742 | |
| 8743 | unsigned char* p = packet; |
| 8744 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8745 | p = packet99; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8746 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 8747 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8748 | } |
| 8749 | QuicFramerFuzzFunc(p, |
| 8750 | framer_.transport_version() > QUIC_VERSION_43 |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 8751 | ? QUIC_ARRAYSIZE(packet46) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8752 | : QUIC_ARRAYSIZE(packet), |
| 8753 | framer_.version()); |
| 8754 | } |
| 8755 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8756 | TEST_P(QuicFramerTest, IetfBlockedFrame) { |
| 8757 | // This test only for version 99. |
| 8758 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8759 | return; |
| 8760 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 8761 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8762 | |
| 8763 | // clang-format off |
| 8764 | PacketFragments packet99 = { |
| 8765 | // type (short header, 4 byte packet number) |
| 8766 | {"", |
| 8767 | {0x43}}, |
| 8768 | // connection_id |
| 8769 | {"", |
| 8770 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 8771 | // packet number |
| 8772 | {"", |
| 8773 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 8774 | // frame type (IETF_BLOCKED) |
| 8775 | {"", |
| 8776 | {0x14}}, |
| 8777 | // blocked offset |
| 8778 | {"Can not read blocked offset.", |
| 8779 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 8780 | }; |
| 8781 | // clang-format on |
| 8782 | |
| 8783 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 8784 | AssemblePacketFromFragments(packet99)); |
| 8785 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 8786 | |
| 8787 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 8788 | ASSERT_TRUE(visitor_.header_.get()); |
| 8789 | EXPECT_TRUE(CheckDecryption( |
| 8790 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 8791 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 8792 | |
| 8793 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 8794 | |
| 8795 | CheckFramingBoundaries(packet99, QUIC_INVALID_BLOCKED_DATA); |
| 8796 | } |
| 8797 | |
| 8798 | TEST_P(QuicFramerTest, BuildIetfBlockedPacket) { |
| 8799 | // This test only for version 99. |
| 8800 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8801 | return; |
| 8802 | } |
| 8803 | |
| 8804 | QuicPacketHeader header; |
| 8805 | header.destination_connection_id = FramerTestConnectionId(); |
| 8806 | header.reset_flag = false; |
| 8807 | header.version_flag = false; |
| 8808 | header.packet_number = kPacketNumber; |
| 8809 | |
| 8810 | QuicBlockedFrame frame; |
| 8811 | frame.stream_id = QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 8812 | frame.offset = kStreamOffset; |
| 8813 | QuicFrames frames = {QuicFrame(&frame)}; |
| 8814 | |
| 8815 | // clang-format off |
| 8816 | unsigned char packet99[] = { |
| 8817 | // type (short header, 4 byte packet number) |
| 8818 | 0x43, |
| 8819 | // connection_id |
| 8820 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8821 | // packet number |
| 8822 | 0x12, 0x34, 0x56, 0x78, |
| 8823 | |
| 8824 | // frame type (IETF_BLOCKED) |
| 8825 | 0x14, |
| 8826 | // Offset |
| 8827 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 8828 | }; |
| 8829 | // clang-format on |
| 8830 | |
| 8831 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8832 | ASSERT_TRUE(data != nullptr); |
| 8833 | |
| 8834 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8835 | data->length(), AsChars(packet99), |
| 8836 | QUIC_ARRAYSIZE(packet99)); |
| 8837 | } |
| 8838 | |
| 8839 | TEST_P(QuicFramerTest, IetfStreamBlockedFrame) { |
| 8840 | // This test only for version 99. |
| 8841 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8842 | return; |
| 8843 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 8844 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8845 | |
| 8846 | // clang-format off |
| 8847 | PacketFragments packet99 = { |
| 8848 | // type (short header, 4 byte packet number) |
| 8849 | {"", |
| 8850 | {0x43}}, |
| 8851 | // connection_id |
| 8852 | {"", |
| 8853 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 8854 | // packet number |
| 8855 | {"", |
| 8856 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 8857 | // frame type (IETF_STREAM_BLOCKED) |
| 8858 | {"", |
| 8859 | {0x15}}, |
| 8860 | // blocked offset |
| 8861 | {"Can not read stream blocked stream id.", |
| 8862 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 8863 | {"Can not read stream blocked offset.", |
| 8864 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 8865 | }; |
| 8866 | // clang-format on |
| 8867 | |
| 8868 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 8869 | AssemblePacketFromFragments(packet99)); |
| 8870 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 8871 | |
| 8872 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 8873 | ASSERT_TRUE(visitor_.header_.get()); |
| 8874 | EXPECT_TRUE(CheckDecryption( |
| 8875 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 8876 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 8877 | |
| 8878 | EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); |
| 8879 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 8880 | |
| 8881 | CheckFramingBoundaries(packet99, QUIC_INVALID_STREAM_BLOCKED_DATA); |
| 8882 | } |
| 8883 | |
| 8884 | TEST_P(QuicFramerTest, BuildIetfStreamBlockedPacket) { |
| 8885 | // This test only for version 99. |
| 8886 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8887 | return; |
| 8888 | } |
| 8889 | |
| 8890 | QuicPacketHeader header; |
| 8891 | header.destination_connection_id = FramerTestConnectionId(); |
| 8892 | header.reset_flag = false; |
| 8893 | header.version_flag = false; |
| 8894 | header.packet_number = kPacketNumber; |
| 8895 | |
| 8896 | QuicBlockedFrame frame; |
| 8897 | frame.stream_id = kStreamId; |
| 8898 | frame.offset = kStreamOffset; |
| 8899 | QuicFrames frames = {QuicFrame(&frame)}; |
| 8900 | |
| 8901 | // clang-format off |
| 8902 | unsigned char packet99[] = { |
| 8903 | // type (short header, 4 byte packet number) |
| 8904 | 0x43, |
| 8905 | // connection_id |
| 8906 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8907 | // packet number |
| 8908 | 0x12, 0x34, 0x56, 0x78, |
| 8909 | |
| 8910 | // frame type (IETF_STREAM_BLOCKED) |
| 8911 | 0x15, |
| 8912 | // Stream ID |
| 8913 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 8914 | // Offset |
| 8915 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 8916 | }; |
| 8917 | // clang-format on |
| 8918 | |
| 8919 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8920 | ASSERT_TRUE(data != nullptr); |
| 8921 | |
| 8922 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8923 | data->length(), AsChars(packet99), |
| 8924 | QUIC_ARRAYSIZE(packet99)); |
| 8925 | } |
| 8926 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 8927 | TEST_P(QuicFramerTest, BiDiMaxStreamsFrame) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8928 | // This test only for version 99. |
| 8929 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8930 | return; |
| 8931 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 8932 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8933 | |
| 8934 | // clang-format off |
| 8935 | PacketFragments packet99 = { |
| 8936 | // type (short header, 4 byte packet number) |
| 8937 | {"", |
| 8938 | {0x43}}, |
| 8939 | // connection_id |
| 8940 | {"", |
| 8941 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 8942 | // packet number |
| 8943 | {"", |
| 8944 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 8945 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 8946 | {"", |
| 8947 | {0x12}}, |
| 8948 | // max. streams |
| 8949 | {"Can not read MAX_STREAMS stream count.", |
| 8950 | {kVarInt62OneByte + 0x03}}, |
| 8951 | }; |
| 8952 | // clang-format on |
| 8953 | |
| 8954 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 8955 | AssemblePacketFromFragments(packet99)); |
| 8956 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 8957 | |
| 8958 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 8959 | ASSERT_TRUE(visitor_.header_.get()); |
| 8960 | EXPECT_TRUE(CheckDecryption( |
| 8961 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 8962 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 8963 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 8964 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 8965 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
| 8966 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8967 | } |
| 8968 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 8969 | TEST_P(QuicFramerTest, UniDiMaxStreamsFrame) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8970 | // This test only for version 99. |
| 8971 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8972 | return; |
| 8973 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 8974 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8975 | |
| 8976 | // clang-format off |
| 8977 | PacketFragments packet99 = { |
| 8978 | // type (short header, 4 byte packet number) |
| 8979 | {"", |
| 8980 | {0x43}}, |
| 8981 | // Test runs in client mode, no connection id |
| 8982 | // packet number |
| 8983 | {"", |
| 8984 | {0x12, 0x34, 0x9A, 0xBC}}, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 8985 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8986 | {"", |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 8987 | {0x13}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8988 | // max. streams |
| 8989 | {"Can not read MAX_STREAMS stream count.", |
| 8990 | {kVarInt62OneByte + 0x03}}, |
| 8991 | }; |
| 8992 | // clang-format on |
| 8993 | |
| 8994 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 8995 | AssemblePacketFromFragments(packet99)); |
| 8996 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 8997 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 8998 | |
| 8999 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9000 | ASSERT_TRUE(visitor_.header_.get()); |
| 9001 | EXPECT_TRUE(CheckDecryption( |
| 9002 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9003 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9004 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9005 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 9006 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 9007 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9008 | } |
| 9009 | |
| 9010 | TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrame) { |
| 9011 | // This test only for version 99. |
| 9012 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9013 | return; |
| 9014 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9015 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9016 | |
| 9017 | // clang-format off |
| 9018 | PacketFragments packet99 = { |
| 9019 | // type (short header, 4 byte packet number) |
| 9020 | {"", |
| 9021 | {0x43}}, |
| 9022 | // connection_id |
| 9023 | {"", |
| 9024 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9025 | // packet number |
| 9026 | {"", |
| 9027 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 9028 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 9029 | {"", |
| 9030 | {0x13}}, |
| 9031 | // max. streams |
| 9032 | {"Can not read MAX_STREAMS stream count.", |
| 9033 | {kVarInt62OneByte + 0x03}}, |
| 9034 | }; |
| 9035 | // clang-format on |
| 9036 | |
| 9037 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9038 | AssemblePacketFromFragments(packet99)); |
| 9039 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9040 | |
| 9041 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9042 | ASSERT_TRUE(visitor_.header_.get()); |
| 9043 | EXPECT_TRUE(CheckDecryption( |
| 9044 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9045 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9046 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9047 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 9048 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 9049 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9050 | } |
| 9051 | |
| 9052 | TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrame) { |
| 9053 | // This test only for version 99. |
| 9054 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9055 | return; |
| 9056 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9057 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9058 | |
| 9059 | // clang-format off |
| 9060 | PacketFragments packet99 = { |
| 9061 | // type (short header, 4 byte packet number) |
| 9062 | {"", |
| 9063 | {0x43}}, |
| 9064 | // Test runs in client mode, no connection id |
| 9065 | // packet number |
| 9066 | {"", |
| 9067 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 9068 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 9069 | {"", |
| 9070 | {0x13}}, |
| 9071 | // max. streams |
| 9072 | {"Can not read MAX_STREAMS stream count.", |
| 9073 | {kVarInt62OneByte + 0x03}}, |
| 9074 | }; |
| 9075 | // clang-format on |
| 9076 | |
| 9077 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9078 | AssemblePacketFromFragments(packet99)); |
| 9079 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9080 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9081 | |
| 9082 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9083 | ASSERT_TRUE(visitor_.header_.get()); |
| 9084 | EXPECT_TRUE(CheckDecryption( |
| 9085 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9086 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9087 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9088 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 9089 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 9090 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9091 | } |
| 9092 | |
| 9093 | // The following four tests ensure that the framer can deserialize a stream |
| 9094 | // count that is large enough to cause the resulting stream ID to exceed the |
| 9095 | // current implementation limit(32 bits). The intent is that when this happens, |
| 9096 | // the stream limit is pegged to the maximum supported value. There are four |
| 9097 | // tests, for the four combinations of uni- and bi-directional, server- and |
| 9098 | // client- initiated. |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9099 | TEST_P(QuicFramerTest, BiDiMaxStreamsFrameTooBig) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9100 | // This test only for version 99. |
| 9101 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9102 | return; |
| 9103 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9104 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9105 | |
| 9106 | // clang-format off |
| 9107 | unsigned char packet99[] = { |
| 9108 | // type (short header, 4 byte packet number) |
| 9109 | 0x43, |
| 9110 | // connection_id |
| 9111 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9112 | // packet number |
| 9113 | 0x12, 0x34, 0x9A, 0xBC, |
| 9114 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 9115 | 0x12, |
| 9116 | |
| 9117 | // max. streams. Max stream ID allowed is 0xffffffff |
| 9118 | // This encodes a count of 0x40000000, leading to stream |
| 9119 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 9120 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 9121 | }; |
| 9122 | // clang-format on |
| 9123 | |
| 9124 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 9125 | false); |
| 9126 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 9127 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9128 | ASSERT_TRUE(visitor_.header_.get()); |
| 9129 | EXPECT_TRUE(CheckDecryption( |
| 9130 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9131 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9132 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 9133 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9134 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9135 | } |
| 9136 | |
| 9137 | TEST_P(QuicFramerTest, ClientBiDiMaxStreamsFrameTooBig) { |
| 9138 | // This test only for version 99. |
| 9139 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9140 | return; |
| 9141 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9142 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9143 | |
| 9144 | // clang-format off |
| 9145 | unsigned char packet99[] = { |
| 9146 | // type (short header, 4 byte packet number) |
| 9147 | 0x43, |
| 9148 | // Test runs in client mode, no connection id |
| 9149 | // packet number |
| 9150 | 0x12, 0x34, 0x9A, 0xBC, |
| 9151 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 9152 | 0x12, |
| 9153 | |
| 9154 | // max. streams. Max stream ID allowed is 0xffffffff |
| 9155 | // This encodes a count of 0x40000000, leading to stream |
| 9156 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 9157 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 9158 | }; |
| 9159 | // clang-format on |
| 9160 | |
| 9161 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 9162 | false); |
| 9163 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9164 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 9165 | |
| 9166 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9167 | ASSERT_TRUE(visitor_.header_.get()); |
| 9168 | EXPECT_TRUE(CheckDecryption( |
| 9169 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9170 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9171 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 9172 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9173 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9174 | } |
| 9175 | |
| 9176 | TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrameTooBig) { |
| 9177 | // This test only for version 99. |
| 9178 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9179 | return; |
| 9180 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9181 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9182 | |
| 9183 | // clang-format off |
| 9184 | unsigned char packet99[] = { |
| 9185 | // type (short header, 4 byte packet number) |
| 9186 | 0x43, |
| 9187 | // connection_id |
| 9188 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9189 | // packet number |
| 9190 | 0x12, 0x34, 0x9A, 0xBC, |
| 9191 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 9192 | 0x13, |
| 9193 | |
| 9194 | // max. streams. Max stream ID allowed is 0xffffffff |
| 9195 | // This encodes a count of 0x40000000, leading to stream |
| 9196 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 9197 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 9198 | }; |
| 9199 | // clang-format on |
| 9200 | |
| 9201 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 9202 | false); |
| 9203 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 9204 | |
| 9205 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9206 | ASSERT_TRUE(visitor_.header_.get()); |
| 9207 | EXPECT_TRUE(CheckDecryption( |
| 9208 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9209 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9210 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 9211 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9212 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9213 | } |
| 9214 | |
| 9215 | TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrameTooBig) { |
| 9216 | // This test only for version 99. |
| 9217 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9218 | return; |
| 9219 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9220 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9221 | |
| 9222 | // clang-format off |
| 9223 | unsigned char packet99[] = { |
| 9224 | // type (short header, 4 byte packet number) |
| 9225 | 0x43, |
| 9226 | // Test runs in client mode, no connection id |
| 9227 | // packet number |
| 9228 | 0x12, 0x34, 0x9A, 0xBC, |
| 9229 | // frame type (IETF_MAX_STREAMS_UNDIRECTIONAL) |
| 9230 | 0x13, |
| 9231 | |
| 9232 | // max. streams. Max stream ID allowed is 0xffffffff |
| 9233 | // This encodes a count of 0x40000000, leading to stream |
| 9234 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 9235 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 9236 | }; |
| 9237 | // clang-format on |
| 9238 | |
| 9239 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 9240 | false); |
| 9241 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9242 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 9243 | |
| 9244 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9245 | ASSERT_TRUE(visitor_.header_.get()); |
| 9246 | EXPECT_TRUE(CheckDecryption( |
| 9247 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9248 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9249 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 9250 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9251 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9252 | } |
| 9253 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9254 | // Specifically test that count==0 is accepted. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9255 | TEST_P(QuicFramerTest, MaxStreamsFrameZeroCount) { |
| 9256 | // This test only for version 99. |
| 9257 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9258 | return; |
| 9259 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9260 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9261 | |
| 9262 | // clang-format off |
| 9263 | unsigned char packet99[] = { |
| 9264 | // type (short header, 4 byte packet number) |
| 9265 | 0x43, |
| 9266 | // connection_id |
| 9267 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9268 | // packet number |
| 9269 | 0x12, 0x34, 0x9A, 0xBC, |
| 9270 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 9271 | 0x12, |
| 9272 | // max. streams == 0. |
| 9273 | kVarInt62OneByte + 0x00 |
| 9274 | }; |
| 9275 | // clang-format on |
| 9276 | |
| 9277 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 9278 | false); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9279 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9280 | } |
| 9281 | |
| 9282 | TEST_P(QuicFramerTest, ServerBiDiStreamsBlockedFrame) { |
| 9283 | // This test only for version 99. |
| 9284 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9285 | return; |
| 9286 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9287 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9288 | |
| 9289 | // clang-format off |
| 9290 | PacketFragments packet99 = { |
| 9291 | // type (short header, 4 byte packet number) |
| 9292 | {"", |
| 9293 | {0x43}}, |
| 9294 | // connection_id |
| 9295 | {"", |
| 9296 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9297 | // packet number |
| 9298 | {"", |
| 9299 | {0x12, 0x34, 0x9A, 0xBC}}, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9300 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL frame) |
| 9301 | {"", |
| 9302 | {0x13}}, |
| 9303 | // stream count |
| 9304 | {"Can not read MAX_STREAMS stream count.", |
| 9305 | {kVarInt62OneByte + 0x00}}, |
| 9306 | }; |
| 9307 | // clang-format on |
| 9308 | |
| 9309 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9310 | AssemblePacketFromFragments(packet99)); |
| 9311 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9312 | |
| 9313 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9314 | ASSERT_TRUE(visitor_.header_.get()); |
| 9315 | EXPECT_TRUE(CheckDecryption( |
| 9316 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9317 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9318 | |
| 9319 | EXPECT_EQ(0u, visitor_.max_streams_frame_.stream_count); |
| 9320 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 9321 | |
| 9322 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
| 9323 | } |
| 9324 | |
| 9325 | TEST_P(QuicFramerTest, BiDiStreamsBlockedFrame) { |
| 9326 | // This test only for version 99. |
| 9327 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9328 | return; |
| 9329 | } |
| 9330 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 9331 | |
| 9332 | // clang-format off |
| 9333 | PacketFragments packet99 = { |
| 9334 | // type (short header, 4 byte packet number) |
| 9335 | {"", |
| 9336 | {0x43}}, |
| 9337 | // connection_id |
| 9338 | {"", |
| 9339 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9340 | // packet number |
| 9341 | {"", |
| 9342 | {0x12, 0x34, 0x9A, 0xBC}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9343 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 9344 | {"", |
| 9345 | {0x16}}, |
| 9346 | // stream id |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9347 | {"Can not read STREAMS_BLOCKED stream count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9348 | {kVarInt62OneByte + 0x03}}, |
| 9349 | }; |
| 9350 | // clang-format on |
| 9351 | |
| 9352 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9353 | AssemblePacketFromFragments(packet99)); |
| 9354 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9355 | |
| 9356 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9357 | ASSERT_TRUE(visitor_.header_.get()); |
| 9358 | EXPECT_TRUE(CheckDecryption( |
| 9359 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9360 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9361 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9362 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 9363 | EXPECT_FALSE(visitor_.streams_blocked_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9364 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9365 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9366 | } |
| 9367 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9368 | TEST_P(QuicFramerTest, UniDiStreamsBlockedFrame) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9369 | // This test only for version 99. |
| 9370 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9371 | return; |
| 9372 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9373 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9374 | |
| 9375 | // clang-format off |
| 9376 | PacketFragments packet99 = { |
| 9377 | // type (short header, 4 byte packet number) |
| 9378 | {"", |
| 9379 | {0x43}}, |
| 9380 | // connection_id |
| 9381 | {"", |
| 9382 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9383 | // packet number |
| 9384 | {"", |
| 9385 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 9386 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 9387 | {"", |
| 9388 | {0x17}}, |
| 9389 | // stream id |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9390 | {"Can not read STREAMS_BLOCKED stream count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9391 | {kVarInt62OneByte + 0x03}}, |
| 9392 | }; |
| 9393 | // clang-format on |
| 9394 | |
| 9395 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9396 | AssemblePacketFromFragments(packet99)); |
| 9397 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9398 | |
| 9399 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9400 | ASSERT_TRUE(visitor_.header_.get()); |
| 9401 | EXPECT_TRUE(CheckDecryption( |
| 9402 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9403 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9404 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9405 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 9406 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 9407 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9408 | } |
| 9409 | |
| 9410 | TEST_P(QuicFramerTest, ClientUniDiStreamsBlockedFrame) { |
| 9411 | // This test only for version 99. |
| 9412 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9413 | return; |
| 9414 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9415 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9416 | |
| 9417 | // clang-format off |
| 9418 | PacketFragments packet99 = { |
| 9419 | // type (short header, 4 byte packet number) |
| 9420 | {"", |
| 9421 | {0x43}}, |
| 9422 | // Test runs in client mode, no connection id |
| 9423 | // packet number |
| 9424 | {"", |
| 9425 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 9426 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 9427 | {"", |
| 9428 | {0x17}}, |
| 9429 | // stream id |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9430 | {"Can not read STREAMS_BLOCKED stream count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9431 | {kVarInt62OneByte + 0x03}}, |
| 9432 | }; |
| 9433 | // clang-format on |
| 9434 | |
| 9435 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9436 | AssemblePacketFromFragments(packet99)); |
| 9437 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9438 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9439 | |
| 9440 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9441 | ASSERT_TRUE(visitor_.header_.get()); |
| 9442 | EXPECT_TRUE(CheckDecryption( |
| 9443 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9444 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9445 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9446 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 9447 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 9448 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9449 | } |
| 9450 | |
| 9451 | // Check that when we get a STREAMS_BLOCKED frame that specifies too large |
| 9452 | // a stream count, we reject with an appropriate error. There is no need to |
| 9453 | // check for different combinations of Uni/Bi directional and client/server |
| 9454 | // initiated; the logic does not take these into account. |
| 9455 | TEST_P(QuicFramerTest, StreamsBlockedFrameTooBig) { |
| 9456 | // This test only for version 99. |
| 9457 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9458 | return; |
| 9459 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9460 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9461 | |
| 9462 | // clang-format off |
| 9463 | unsigned char packet99[] = { |
| 9464 | // type (short header, 4 byte packet number) |
| 9465 | 0x43, |
| 9466 | // Test runs in client mode, no connection id |
| 9467 | // packet number |
| 9468 | 0x12, 0x34, 0x9A, 0xBC, |
| 9469 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL) |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9470 | 0x16, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9471 | |
| 9472 | // max. streams. Max stream ID allowed is 0xffffffff |
| 9473 | // This encodes a count of 0x40000000, leading to stream |
| 9474 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 9475 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01 |
| 9476 | }; |
| 9477 | // clang-format on |
| 9478 | |
| 9479 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 9480 | false); |
| 9481 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9482 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 9483 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9484 | EXPECT_EQ(QUIC_STREAMS_BLOCKED_DATA, framer_.error()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9485 | EXPECT_EQ(framer_.detailed_error(), |
| 9486 | "STREAMS_BLOCKED stream count exceeds implementation limit."); |
| 9487 | } |
| 9488 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9489 | // Specifically test that count==0 is accepted. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9490 | TEST_P(QuicFramerTest, StreamsBlockedFrameZeroCount) { |
| 9491 | // This test only for version 99. |
| 9492 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9493 | return; |
| 9494 | } |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9495 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9496 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9497 | |
| 9498 | // clang-format off |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9499 | PacketFragments packet99 = { |
| 9500 | // type (short header, 4 byte packet number) |
| 9501 | {"", |
| 9502 | {0x43}}, |
| 9503 | // connection_id |
| 9504 | {"", |
| 9505 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9506 | // packet number |
| 9507 | {"", |
| 9508 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 9509 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 9510 | {"", |
| 9511 | {0x17}}, |
| 9512 | // stream id |
| 9513 | {"Can not read STREAMS_BLOCKED stream count.", |
| 9514 | {kVarInt62OneByte + 0x00}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9515 | }; |
| 9516 | // clang-format on |
| 9517 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9518 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9519 | AssemblePacketFromFragments(packet99)); |
| 9520 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9521 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9522 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9523 | ASSERT_TRUE(visitor_.header_.get()); |
| 9524 | EXPECT_TRUE(CheckDecryption( |
| 9525 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9526 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9527 | |
| 9528 | EXPECT_EQ(0u, visitor_.streams_blocked_frame_.stream_count); |
| 9529 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 9530 | |
| 9531 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9532 | } |
| 9533 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9534 | TEST_P(QuicFramerTest, BuildBiDiStreamsBlockedPacket) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9535 | // This test only for version 99. |
| 9536 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9537 | return; |
| 9538 | } |
| 9539 | |
| 9540 | QuicPacketHeader header; |
| 9541 | header.destination_connection_id = FramerTestConnectionId(); |
| 9542 | header.reset_flag = false; |
| 9543 | header.version_flag = false; |
| 9544 | header.packet_number = kPacketNumber; |
| 9545 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9546 | QuicStreamsBlockedFrame frame; |
| 9547 | frame.stream_count = 3; |
| 9548 | frame.unidirectional = false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9549 | |
| 9550 | QuicFrames frames = {QuicFrame(frame)}; |
| 9551 | |
| 9552 | // clang-format off |
| 9553 | unsigned char packet99[] = { |
| 9554 | // type (short header, 4 byte packet number) |
| 9555 | 0x43, |
| 9556 | // connection_id |
| 9557 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9558 | // packet number |
| 9559 | 0x12, 0x34, 0x56, 0x78, |
| 9560 | |
| 9561 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 9562 | 0x16, |
| 9563 | // Stream count |
| 9564 | kVarInt62OneByte + 0x03 |
| 9565 | }; |
| 9566 | // clang-format on |
| 9567 | |
| 9568 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 9569 | ASSERT_TRUE(data != nullptr); |
| 9570 | |
| 9571 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 9572 | data->length(), AsChars(packet99), |
| 9573 | QUIC_ARRAYSIZE(packet99)); |
| 9574 | } |
| 9575 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9576 | TEST_P(QuicFramerTest, BuildUniStreamsBlockedPacket) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9577 | // This test only for version 99. |
| 9578 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9579 | return; |
| 9580 | } |
| 9581 | |
| 9582 | QuicPacketHeader header; |
| 9583 | header.destination_connection_id = FramerTestConnectionId(); |
| 9584 | header.reset_flag = false; |
| 9585 | header.version_flag = false; |
| 9586 | header.packet_number = kPacketNumber; |
| 9587 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9588 | QuicStreamsBlockedFrame frame; |
| 9589 | frame.stream_count = 3; |
| 9590 | frame.unidirectional = true; |
| 9591 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9592 | QuicFrames frames = {QuicFrame(frame)}; |
| 9593 | |
| 9594 | // clang-format off |
| 9595 | unsigned char packet99[] = { |
| 9596 | // type (short header, 4 byte packet number) |
| 9597 | 0x43, |
| 9598 | // connection_id |
| 9599 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9600 | // packet number |
| 9601 | 0x12, 0x34, 0x56, 0x78, |
| 9602 | |
| 9603 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 9604 | 0x17, |
| 9605 | // Stream count |
| 9606 | kVarInt62OneByte + 0x03 |
| 9607 | }; |
| 9608 | // clang-format on |
| 9609 | |
| 9610 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 9611 | ASSERT_TRUE(data != nullptr); |
| 9612 | |
| 9613 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 9614 | data->length(), AsChars(packet99), |
| 9615 | QUIC_ARRAYSIZE(packet99)); |
| 9616 | } |
| 9617 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9618 | TEST_P(QuicFramerTest, BuildBiDiMaxStreamsPacket) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9619 | // This test only for version 99. |
| 9620 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9621 | return; |
| 9622 | } |
| 9623 | |
| 9624 | QuicPacketHeader header; |
| 9625 | header.destination_connection_id = FramerTestConnectionId(); |
| 9626 | header.reset_flag = false; |
| 9627 | header.version_flag = false; |
| 9628 | header.packet_number = kPacketNumber; |
| 9629 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9630 | QuicMaxStreamsFrame frame; |
| 9631 | frame.stream_count = 3; |
| 9632 | frame.unidirectional = false; |
| 9633 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9634 | QuicFrames frames = {QuicFrame(frame)}; |
| 9635 | |
| 9636 | // clang-format off |
| 9637 | unsigned char packet99[] = { |
| 9638 | // type (short header, 4 byte packet number) |
| 9639 | 0x43, |
| 9640 | // connection_id |
| 9641 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9642 | // packet number |
| 9643 | 0x12, 0x34, 0x56, 0x78, |
| 9644 | |
| 9645 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL frame) |
| 9646 | 0x12, |
| 9647 | // Stream count |
| 9648 | kVarInt62OneByte + 0x03 |
| 9649 | }; |
| 9650 | // clang-format on |
| 9651 | |
| 9652 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 9653 | ASSERT_TRUE(data != nullptr); |
| 9654 | |
| 9655 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 9656 | data->length(), AsChars(packet99), |
| 9657 | QUIC_ARRAYSIZE(packet99)); |
| 9658 | } |
| 9659 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9660 | TEST_P(QuicFramerTest, BuildUniDiMaxStreamsPacket) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9661 | // This test only for version 99. |
| 9662 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9663 | return; |
| 9664 | } |
| 9665 | |
| 9666 | // This test runs in client mode. |
| 9667 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9668 | |
| 9669 | QuicPacketHeader header; |
| 9670 | header.destination_connection_id = FramerTestConnectionId(); |
| 9671 | header.reset_flag = false; |
| 9672 | header.version_flag = false; |
| 9673 | header.packet_number = kPacketNumber; |
| 9674 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9675 | QuicMaxStreamsFrame frame; |
| 9676 | frame.stream_count = 3; |
| 9677 | frame.unidirectional = true; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9678 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9679 | QuicFrames frames = {QuicFrame(frame)}; |
| 9680 | |
| 9681 | // clang-format off |
| 9682 | unsigned char packet99[] = { |
| 9683 | // type (short header, 4 byte packet number) |
| 9684 | 0x43, |
| 9685 | // connection_id |
| 9686 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9687 | // packet number |
| 9688 | 0x12, 0x34, 0x56, 0x78, |
| 9689 | |
| 9690 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL frame) |
| 9691 | 0x13, |
| 9692 | // Stream count |
| 9693 | kVarInt62OneByte + 0x03 |
| 9694 | }; |
| 9695 | // clang-format on |
| 9696 | |
| 9697 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 9698 | ASSERT_TRUE(data != nullptr); |
| 9699 | |
| 9700 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 9701 | data->length(), AsChars(packet99), |
| 9702 | QUIC_ARRAYSIZE(packet99)); |
| 9703 | } |
| 9704 | |
| 9705 | TEST_P(QuicFramerTest, NewConnectionIdFrame) { |
| 9706 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9707 | // This frame is only for version 99. |
| 9708 | return; |
| 9709 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9710 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9711 | // clang-format off |
| 9712 | PacketFragments packet99 = { |
| 9713 | // type (short header, 4 byte packet number) |
| 9714 | {"", |
| 9715 | {0x43}}, |
| 9716 | // connection_id |
| 9717 | {"", |
| 9718 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9719 | // packet number |
| 9720 | {"", |
| 9721 | {0x12, 0x34, 0x56, 0x78}}, |
| 9722 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 9723 | {"", |
| 9724 | {0x18}}, |
| 9725 | // error code |
| 9726 | {"Unable to read new connection ID frame sequence number.", |
| 9727 | {kVarInt62OneByte + 0x11}}, |
| 9728 | {"Unable to read new connection ID frame connection id length.", |
| 9729 | {0x08}}, // connection ID length |
| 9730 | {"Unable to read new connection ID frame connection id.", |
| 9731 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11}}, |
| 9732 | {"Can not read new connection ID frame reset token.", |
| 9733 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 9734 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 9735 | }; |
| 9736 | // clang-format on |
| 9737 | |
| 9738 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9739 | AssemblePacketFromFragments(packet99)); |
| 9740 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9741 | |
| 9742 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9743 | ASSERT_TRUE(visitor_.header_.get()); |
| 9744 | EXPECT_TRUE(CheckDecryption( |
| 9745 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9746 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9747 | |
| 9748 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 9749 | |
| 9750 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), |
| 9751 | visitor_.new_connection_id_.connection_id); |
| 9752 | EXPECT_EQ(0x11u, visitor_.new_connection_id_.sequence_number); |
| 9753 | EXPECT_EQ(kTestStatelessResetToken, |
| 9754 | visitor_.new_connection_id_.stateless_reset_token); |
| 9755 | |
| 9756 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 9757 | |
| 9758 | CheckFramingBoundaries(packet99, QUIC_INVALID_NEW_CONNECTION_ID_DATA); |
| 9759 | } |
| 9760 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 9761 | TEST_P(QuicFramerTest, NewConnectionIdFrameVariableLength) { |
QUICHE team | 9b41c97 | 2019-03-21 11:22:48 -0700 | [diff] [blame] | 9762 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9763 | // This frame is only for version 99. |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 9764 | return; |
| 9765 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9766 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 9767 | // clang-format off |
| 9768 | PacketFragments packet99 = { |
| 9769 | // type (short header, 4 byte packet number) |
| 9770 | {"", |
| 9771 | {0x43}}, |
| 9772 | // connection_id |
| 9773 | {"", |
| 9774 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9775 | // packet number |
| 9776 | {"", |
| 9777 | {0x12, 0x34, 0x56, 0x78}}, |
| 9778 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 9779 | {"", |
| 9780 | {0x18}}, |
| 9781 | // error code |
| 9782 | {"Unable to read new connection ID frame sequence number.", |
| 9783 | {kVarInt62OneByte + 0x11}}, |
| 9784 | {"Unable to read new connection ID frame connection id length.", |
| 9785 | {0x09}}, // connection ID length |
| 9786 | {"Unable to read new connection ID frame connection id.", |
| 9787 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 9788 | {"Can not read new connection ID frame reset token.", |
| 9789 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 9790 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 9791 | }; |
| 9792 | // clang-format on |
| 9793 | |
| 9794 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9795 | AssemblePacketFromFragments(packet99)); |
| 9796 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9797 | |
| 9798 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9799 | ASSERT_TRUE(visitor_.header_.get()); |
| 9800 | EXPECT_TRUE(CheckDecryption( |
| 9801 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9802 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9803 | |
| 9804 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 9805 | |
| 9806 | EXPECT_EQ(FramerTestConnectionIdNineBytes(), |
| 9807 | visitor_.new_connection_id_.connection_id); |
| 9808 | EXPECT_EQ(0x11u, visitor_.new_connection_id_.sequence_number); |
| 9809 | EXPECT_EQ(kTestStatelessResetToken, |
| 9810 | visitor_.new_connection_id_.stateless_reset_token); |
| 9811 | |
| 9812 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 9813 | |
| 9814 | CheckFramingBoundaries(packet99, QUIC_INVALID_NEW_CONNECTION_ID_DATA); |
| 9815 | } |
| 9816 | |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 9817 | // Verifies that parsing a NEW_CONNECTION_ID frame with a length above the |
| 9818 | // specified maximum fails. |
| 9819 | TEST_P(QuicFramerTest, InvalidLongNewConnectionIdFrame) { |
| 9820 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9821 | // The NEW_CONNECTION_ID frame is only for version 99. |
| 9822 | return; |
| 9823 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9824 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 9825 | // clang-format off |
| 9826 | PacketFragments packet99 = { |
| 9827 | // type (short header, 4 byte packet number) |
| 9828 | {"", |
| 9829 | {0x43}}, |
| 9830 | // connection_id |
| 9831 | {"", |
| 9832 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9833 | // packet number |
| 9834 | {"", |
| 9835 | {0x12, 0x34, 0x56, 0x78}}, |
| 9836 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 9837 | {"", |
| 9838 | {0x18}}, |
| 9839 | // error code |
| 9840 | {"Unable to read new connection ID frame sequence number.", |
| 9841 | {kVarInt62OneByte + 0x11}}, |
| 9842 | {"Unable to read new connection ID frame connection id length.", |
| 9843 | {0x13}}, // connection ID length |
| 9844 | {"Unable to read new connection ID frame connection id.", |
| 9845 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9846 | 0xF0, 0xD2, 0xB4, 0x96, 0x78, 0x5A, 0x3C, 0x1E, |
| 9847 | 0x42, 0x33, 0x42}}, |
| 9848 | {"Can not read new connection ID frame reset token.", |
| 9849 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 9850 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 9851 | }; |
| 9852 | // clang-format on |
| 9853 | |
| 9854 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9855 | AssemblePacketFromFragments(packet99)); |
| 9856 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 9857 | EXPECT_EQ(QUIC_INVALID_NEW_CONNECTION_ID_DATA, framer_.error()); |
| 9858 | EXPECT_EQ("New connection ID length too high.", framer_.detailed_error()); |
| 9859 | } |
| 9860 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9861 | TEST_P(QuicFramerTest, BuildNewConnectionIdFramePacket) { |
| 9862 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9863 | // This frame is only for version 99. |
| 9864 | return; |
| 9865 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 9866 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9867 | QuicPacketHeader header; |
| 9868 | header.destination_connection_id = FramerTestConnectionId(); |
| 9869 | header.reset_flag = false; |
| 9870 | header.version_flag = false; |
| 9871 | header.packet_number = kPacketNumber; |
| 9872 | |
| 9873 | QuicNewConnectionIdFrame frame; |
| 9874 | frame.sequence_number = 0x11; |
| 9875 | // Use this value to force a 4-byte encoded variable length connection ID |
| 9876 | // in the frame. |
| 9877 | frame.connection_id = FramerTestConnectionIdPlusOne(); |
| 9878 | frame.stateless_reset_token = kTestStatelessResetToken; |
| 9879 | |
| 9880 | QuicFrames frames = {QuicFrame(&frame)}; |
| 9881 | |
| 9882 | // clang-format off |
| 9883 | unsigned char packet99[] = { |
| 9884 | // type (short header, 4 byte packet number) |
| 9885 | 0x43, |
| 9886 | // connection_id |
| 9887 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9888 | // packet number |
| 9889 | 0x12, 0x34, 0x56, 0x78, |
| 9890 | |
| 9891 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 9892 | 0x18, |
| 9893 | // sequence number |
| 9894 | kVarInt62OneByte + 0x11, |
| 9895 | // new connection id length |
| 9896 | 0x08, |
| 9897 | // new connection id |
| 9898 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 9899 | // stateless reset token |
| 9900 | 0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 9901 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 9902 | }; |
| 9903 | // clang-format on |
| 9904 | |
| 9905 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 9906 | ASSERT_TRUE(data != nullptr); |
| 9907 | |
| 9908 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 9909 | data->length(), AsChars(packet99), |
| 9910 | QUIC_ARRAYSIZE(packet99)); |
| 9911 | } |
| 9912 | |
| 9913 | TEST_P(QuicFramerTest, NewTokenFrame) { |
| 9914 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9915 | // This frame is only for version 99. |
| 9916 | return; |
| 9917 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9918 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9919 | // clang-format off |
| 9920 | PacketFragments packet = { |
| 9921 | // type (short header, 4 byte packet number) |
| 9922 | {"", |
| 9923 | {0x43}}, |
| 9924 | // connection_id |
| 9925 | {"", |
| 9926 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9927 | // packet number |
| 9928 | {"", |
| 9929 | {0x12, 0x34, 0x56, 0x78}}, |
| 9930 | // frame type (IETF_NEW_TOKEN frame) |
| 9931 | {"", |
| 9932 | {0x07}}, |
| 9933 | // Length |
| 9934 | {"Unable to read new token length.", |
| 9935 | {kVarInt62OneByte + 0x08}}, |
| 9936 | {"Unable to read new token data.", |
| 9937 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}} |
| 9938 | }; |
| 9939 | // clang-format on |
| 9940 | uint8_t expected_token_value[] = {0x00, 0x01, 0x02, 0x03, |
| 9941 | 0x04, 0x05, 0x06, 0x07}; |
| 9942 | |
| 9943 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9944 | AssemblePacketFromFragments(packet)); |
| 9945 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9946 | |
| 9947 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9948 | ASSERT_TRUE(visitor_.header_.get()); |
| 9949 | EXPECT_TRUE(CheckDecryption( |
| 9950 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9951 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9952 | |
| 9953 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 9954 | |
| 9955 | EXPECT_EQ(sizeof(expected_token_value), visitor_.new_token_.token.length()); |
| 9956 | EXPECT_EQ(0, memcmp(expected_token_value, visitor_.new_token_.token.data(), |
| 9957 | sizeof(expected_token_value))); |
| 9958 | |
| 9959 | CheckFramingBoundaries(packet, QUIC_INVALID_NEW_TOKEN); |
| 9960 | } |
| 9961 | |
| 9962 | TEST_P(QuicFramerTest, BuildNewTokenFramePacket) { |
| 9963 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9964 | // This frame is only for version 99. |
| 9965 | return; |
| 9966 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 9967 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9968 | QuicPacketHeader header; |
| 9969 | header.destination_connection_id = FramerTestConnectionId(); |
| 9970 | header.reset_flag = false; |
| 9971 | header.version_flag = false; |
| 9972 | header.packet_number = kPacketNumber; |
| 9973 | |
| 9974 | uint8_t expected_token_value[] = {0x00, 0x01, 0x02, 0x03, |
| 9975 | 0x04, 0x05, 0x06, 0x07}; |
| 9976 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 9977 | QuicNewTokenFrame frame(0, std::string((const char*)(expected_token_value), |
| 9978 | sizeof(expected_token_value))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9979 | |
| 9980 | QuicFrames frames = {QuicFrame(&frame)}; |
| 9981 | |
| 9982 | // clang-format off |
| 9983 | unsigned char packet[] = { |
| 9984 | // type (short header, 4 byte packet number) |
| 9985 | 0x43, |
| 9986 | // connection_id |
| 9987 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9988 | // packet number |
| 9989 | 0x12, 0x34, 0x56, 0x78, |
| 9990 | |
| 9991 | // frame type (IETF_NEW_TOKEN frame) |
| 9992 | 0x07, |
| 9993 | // Length and token |
| 9994 | kVarInt62OneByte + 0x08, |
| 9995 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 9996 | }; |
| 9997 | // clang-format on |
| 9998 | |
| 9999 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10000 | ASSERT_TRUE(data != nullptr); |
| 10001 | |
| 10002 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10003 | data->length(), AsChars(packet), |
| 10004 | QUIC_ARRAYSIZE(packet)); |
| 10005 | } |
| 10006 | |
| 10007 | TEST_P(QuicFramerTest, IetfStopSendingFrame) { |
| 10008 | // This test is only for version 99. |
| 10009 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10010 | return; |
| 10011 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10012 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10013 | |
| 10014 | // clang-format off |
| 10015 | PacketFragments packet99 = { |
| 10016 | // type (short header, 4 byte packet number) |
| 10017 | {"", |
| 10018 | {0x43}}, |
| 10019 | // connection_id |
| 10020 | {"", |
| 10021 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10022 | // packet number |
| 10023 | {"", |
| 10024 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10025 | // frame type (IETF_STOP_SENDING frame) |
| 10026 | {"", |
| 10027 | {0x05}}, |
| 10028 | // stream id |
| 10029 | {"Unable to read stop sending stream id.", |
| 10030 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 10031 | {"Unable to read stop sending application error code.", |
| 10032 | {0x76, 0x54}}, |
| 10033 | }; |
| 10034 | // clang-format on |
| 10035 | |
| 10036 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10037 | AssemblePacketFromFragments(packet99)); |
| 10038 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10039 | |
| 10040 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10041 | ASSERT_TRUE(visitor_.header_.get()); |
| 10042 | EXPECT_TRUE(CheckDecryption( |
| 10043 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10044 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10045 | |
| 10046 | EXPECT_EQ(kStreamId, visitor_.stop_sending_frame_.stream_id); |
| 10047 | EXPECT_EQ(0x7654, visitor_.stop_sending_frame_.application_error_code); |
| 10048 | |
| 10049 | CheckFramingBoundaries(packet99, QUIC_INVALID_STOP_SENDING_FRAME_DATA); |
| 10050 | } |
| 10051 | |
| 10052 | TEST_P(QuicFramerTest, BuildIetfStopSendingPacket) { |
| 10053 | // This test is only for version 99. |
| 10054 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10055 | return; |
| 10056 | } |
| 10057 | |
| 10058 | QuicPacketHeader header; |
| 10059 | header.destination_connection_id = FramerTestConnectionId(); |
| 10060 | header.reset_flag = false; |
| 10061 | header.version_flag = false; |
| 10062 | header.packet_number = kPacketNumber; |
| 10063 | |
| 10064 | QuicStopSendingFrame frame; |
| 10065 | frame.stream_id = kStreamId; |
| 10066 | frame.application_error_code = 0xffff; |
| 10067 | QuicFrames frames = {QuicFrame(&frame)}; |
| 10068 | |
| 10069 | // clang-format off |
| 10070 | unsigned char packet99[] = { |
| 10071 | // type (short header, 4 byte packet number) |
| 10072 | 0x43, |
| 10073 | // connection_id |
| 10074 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10075 | // packet number |
| 10076 | 0x12, 0x34, 0x56, 0x78, |
| 10077 | |
| 10078 | // frame type (IETF_STOP_SENDING frame) |
| 10079 | 0x05, |
| 10080 | // Stream ID |
| 10081 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 10082 | // Application error code |
| 10083 | 0xff, 0xff |
| 10084 | }; |
| 10085 | // clang-format on |
| 10086 | |
| 10087 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10088 | ASSERT_TRUE(data != nullptr); |
| 10089 | |
| 10090 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10091 | data->length(), AsChars(packet99), |
| 10092 | QUIC_ARRAYSIZE(packet99)); |
| 10093 | } |
| 10094 | |
| 10095 | TEST_P(QuicFramerTest, IetfPathChallengeFrame) { |
| 10096 | // This test only for version 99. |
| 10097 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10098 | return; |
| 10099 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10100 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10101 | |
| 10102 | // clang-format off |
| 10103 | PacketFragments packet99 = { |
| 10104 | // type (short header, 4 byte packet number) |
| 10105 | {"", |
| 10106 | {0x43}}, |
| 10107 | // connection_id |
| 10108 | {"", |
| 10109 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10110 | // packet number |
| 10111 | {"", |
| 10112 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10113 | // frame type (IETF_PATH_CHALLENGE) |
| 10114 | {"", |
| 10115 | {0x1a}}, |
| 10116 | // data |
| 10117 | {"Can not read path challenge data.", |
| 10118 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}}, |
| 10119 | }; |
| 10120 | // clang-format on |
| 10121 | |
| 10122 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10123 | AssemblePacketFromFragments(packet99)); |
| 10124 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10125 | |
| 10126 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10127 | ASSERT_TRUE(visitor_.header_.get()); |
| 10128 | EXPECT_TRUE(CheckDecryption( |
| 10129 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10130 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10131 | |
| 10132 | EXPECT_EQ(QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}), |
| 10133 | visitor_.path_challenge_frame_.data_buffer); |
| 10134 | |
| 10135 | CheckFramingBoundaries(packet99, QUIC_INVALID_PATH_CHALLENGE_DATA); |
| 10136 | } |
| 10137 | |
| 10138 | TEST_P(QuicFramerTest, BuildIetfPathChallengePacket) { |
| 10139 | // This test only for version 99. |
| 10140 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10141 | return; |
| 10142 | } |
| 10143 | |
| 10144 | QuicPacketHeader header; |
| 10145 | header.destination_connection_id = FramerTestConnectionId(); |
| 10146 | header.reset_flag = false; |
| 10147 | header.version_flag = false; |
| 10148 | header.packet_number = kPacketNumber; |
| 10149 | |
| 10150 | QuicPathChallengeFrame frame; |
| 10151 | frame.data_buffer = QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}); |
| 10152 | QuicFrames frames = {QuicFrame(&frame)}; |
| 10153 | |
| 10154 | // clang-format off |
| 10155 | unsigned char packet99[] = { |
| 10156 | // type (short header, 4 byte packet number) |
| 10157 | 0x43, |
| 10158 | // connection_id |
| 10159 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10160 | // packet number |
| 10161 | 0x12, 0x34, 0x56, 0x78, |
| 10162 | |
| 10163 | // frame type (IETF_PATH_CHALLENGE) |
| 10164 | 0x1a, |
| 10165 | // Data |
| 10166 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 10167 | }; |
| 10168 | // clang-format on |
| 10169 | |
| 10170 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10171 | ASSERT_TRUE(data != nullptr); |
| 10172 | |
| 10173 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10174 | data->length(), AsChars(packet99), |
| 10175 | QUIC_ARRAYSIZE(packet99)); |
| 10176 | } |
| 10177 | |
| 10178 | TEST_P(QuicFramerTest, IetfPathResponseFrame) { |
| 10179 | // This test only for version 99. |
| 10180 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10181 | return; |
| 10182 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10183 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10184 | |
| 10185 | // clang-format off |
| 10186 | PacketFragments packet99 = { |
| 10187 | // type (short header, 4 byte packet number) |
| 10188 | {"", |
| 10189 | {0x43}}, |
| 10190 | // connection_id |
| 10191 | {"", |
| 10192 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10193 | // packet number |
| 10194 | {"", |
| 10195 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10196 | // frame type (IETF_PATH_RESPONSE) |
| 10197 | {"", |
| 10198 | {0x1b}}, |
| 10199 | // data |
| 10200 | {"Can not read path response data.", |
| 10201 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}}, |
| 10202 | }; |
| 10203 | // clang-format on |
| 10204 | |
| 10205 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10206 | AssemblePacketFromFragments(packet99)); |
| 10207 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10208 | |
| 10209 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10210 | ASSERT_TRUE(visitor_.header_.get()); |
| 10211 | EXPECT_TRUE(CheckDecryption( |
| 10212 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10213 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10214 | |
| 10215 | EXPECT_EQ(QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}), |
| 10216 | visitor_.path_response_frame_.data_buffer); |
| 10217 | |
| 10218 | CheckFramingBoundaries(packet99, QUIC_INVALID_PATH_RESPONSE_DATA); |
| 10219 | } |
| 10220 | |
| 10221 | TEST_P(QuicFramerTest, BuildIetfPathResponsePacket) { |
| 10222 | // This test only for version 99. |
| 10223 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10224 | return; |
| 10225 | } |
| 10226 | |
| 10227 | QuicPacketHeader header; |
| 10228 | header.destination_connection_id = FramerTestConnectionId(); |
| 10229 | header.reset_flag = false; |
| 10230 | header.version_flag = false; |
| 10231 | header.packet_number = kPacketNumber; |
| 10232 | |
| 10233 | QuicPathResponseFrame frame; |
| 10234 | frame.data_buffer = QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}); |
| 10235 | QuicFrames frames = {QuicFrame(&frame)}; |
| 10236 | |
| 10237 | // clang-format off |
| 10238 | unsigned char packet99[] = { |
| 10239 | // type (short header, 4 byte packet number) |
| 10240 | 0x43, |
| 10241 | // connection_id |
| 10242 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10243 | // packet number |
| 10244 | 0x12, 0x34, 0x56, 0x78, |
| 10245 | |
| 10246 | // frame type (IETF_PATH_RESPONSE) |
| 10247 | 0x1b, |
| 10248 | // Data |
| 10249 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 10250 | }; |
| 10251 | // clang-format on |
| 10252 | |
| 10253 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10254 | ASSERT_TRUE(data != nullptr); |
| 10255 | |
| 10256 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10257 | data->length(), AsChars(packet99), |
| 10258 | QUIC_ARRAYSIZE(packet99)); |
| 10259 | } |
| 10260 | |
| 10261 | TEST_P(QuicFramerTest, GetRetransmittableControlFrameSize) { |
| 10262 | QuicRstStreamFrame rst_stream(1, 3, QUIC_STREAM_CANCELLED, 1024); |
| 10263 | EXPECT_EQ(QuicFramer::GetRstStreamFrameSize(framer_.transport_version(), |
| 10264 | rst_stream), |
| 10265 | QuicFramer::GetRetransmittableControlFrameSize( |
| 10266 | framer_.transport_version(), QuicFrame(&rst_stream))); |
| 10267 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 10268 | std::string error_detail(2048, 'e'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10269 | QuicConnectionCloseFrame connection_close(QUIC_NETWORK_IDLE_TIMEOUT, |
| 10270 | error_detail); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 10271 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 10272 | connection_close.close_type = IETF_QUIC_TRANSPORT_CONNECTION_CLOSE; |
| 10273 | } |
| 10274 | |
fkastenholz | a037b8b | 2019-05-07 06:00:05 -0700 | [diff] [blame] | 10275 | EXPECT_EQ(QuicFramer::GetConnectionCloseFrameSize(framer_.transport_version(), |
| 10276 | connection_close), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10277 | QuicFramer::GetRetransmittableControlFrameSize( |
| 10278 | framer_.transport_version(), QuicFrame(&connection_close))); |
| 10279 | |
| 10280 | QuicGoAwayFrame goaway(2, QUIC_PEER_GOING_AWAY, 3, error_detail); |
| 10281 | EXPECT_EQ(QuicFramer::GetMinGoAwayFrameSize() + 256, |
| 10282 | QuicFramer::GetRetransmittableControlFrameSize( |
| 10283 | framer_.transport_version(), QuicFrame(&goaway))); |
| 10284 | |
| 10285 | QuicWindowUpdateFrame window_update(3, 3, 1024); |
| 10286 | EXPECT_EQ(QuicFramer::GetWindowUpdateFrameSize(framer_.transport_version(), |
| 10287 | window_update), |
| 10288 | QuicFramer::GetRetransmittableControlFrameSize( |
| 10289 | framer_.transport_version(), QuicFrame(&window_update))); |
| 10290 | |
| 10291 | QuicBlockedFrame blocked(4, 3, 1024); |
| 10292 | EXPECT_EQ( |
| 10293 | QuicFramer::GetBlockedFrameSize(framer_.transport_version(), blocked), |
| 10294 | QuicFramer::GetRetransmittableControlFrameSize( |
| 10295 | framer_.transport_version(), QuicFrame(&blocked))); |
| 10296 | |
| 10297 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10298 | return; |
| 10299 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10300 | |
| 10301 | QuicNewConnectionIdFrame new_connection_id(5, TestConnectionId(), 1, 101111); |
| 10302 | EXPECT_EQ(QuicFramer::GetNewConnectionIdFrameSize(new_connection_id), |
| 10303 | QuicFramer::GetRetransmittableControlFrameSize( |
| 10304 | framer_.transport_version(), QuicFrame(&new_connection_id))); |
| 10305 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10306 | QuicMaxStreamsFrame max_streams(6, 3, /*unidirectional=*/false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10307 | EXPECT_EQ(QuicFramer::GetMaxStreamsFrameSize(framer_.transport_version(), |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10308 | max_streams), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10309 | QuicFramer::GetRetransmittableControlFrameSize( |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10310 | framer_.transport_version(), QuicFrame(max_streams))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10311 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10312 | QuicStreamsBlockedFrame streams_blocked(7, 3, /*unidirectional=*/false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10313 | EXPECT_EQ(QuicFramer::GetStreamsBlockedFrameSize(framer_.transport_version(), |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10314 | streams_blocked), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10315 | QuicFramer::GetRetransmittableControlFrameSize( |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10316 | framer_.transport_version(), QuicFrame(streams_blocked))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10317 | |
| 10318 | QuicPathFrameBuffer buffer = { |
| 10319 | {0x80, 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe5, 0xf7}}; |
| 10320 | QuicPathResponseFrame path_response_frame(8, buffer); |
| 10321 | EXPECT_EQ(QuicFramer::GetPathResponseFrameSize(path_response_frame), |
| 10322 | QuicFramer::GetRetransmittableControlFrameSize( |
| 10323 | framer_.transport_version(), QuicFrame(&path_response_frame))); |
| 10324 | |
| 10325 | QuicPathChallengeFrame path_challenge_frame(9, buffer); |
| 10326 | EXPECT_EQ(QuicFramer::GetPathChallengeFrameSize(path_challenge_frame), |
| 10327 | QuicFramer::GetRetransmittableControlFrameSize( |
| 10328 | framer_.transport_version(), QuicFrame(&path_challenge_frame))); |
| 10329 | |
| 10330 | QuicStopSendingFrame stop_sending_frame(10, 3, 20); |
| 10331 | EXPECT_EQ(QuicFramer::GetStopSendingFrameSize(stop_sending_frame), |
| 10332 | QuicFramer::GetRetransmittableControlFrameSize( |
| 10333 | framer_.transport_version(), QuicFrame(&stop_sending_frame))); |
| 10334 | } |
| 10335 | |
| 10336 | // A set of tests to ensure that bad frame-type encodings |
| 10337 | // are properly detected and handled. |
| 10338 | // First, four tests to see that unknown frame types generate |
| 10339 | // a QUIC_INVALID_FRAME_DATA error with detailed information |
| 10340 | // "Illegal frame type." This regardless of the encoding of the type |
| 10341 | // (1/2/4/8 bytes). |
| 10342 | // This only for version 99. |
| 10343 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown1Byte) { |
| 10344 | // This test only for version 99. |
| 10345 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10346 | return; |
| 10347 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10348 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10349 | // clang-format off |
| 10350 | PacketFragments packet = { |
| 10351 | // type (short header, 4 byte packet number) |
| 10352 | {"", |
| 10353 | {0x43}}, |
| 10354 | // connection_id |
| 10355 | {"", |
| 10356 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10357 | // packet number |
| 10358 | {"", |
| 10359 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10360 | // frame type (unknown value, single-byte encoding) |
| 10361 | {"", |
| 10362 | {0x38}} |
| 10363 | }; |
| 10364 | // clang-format on |
| 10365 | |
| 10366 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10367 | AssemblePacketFromFragments(packet)); |
| 10368 | |
| 10369 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 10370 | |
| 10371 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 10372 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 10373 | } |
| 10374 | |
| 10375 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown2Bytes) { |
| 10376 | // This test only for version 99. |
| 10377 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10378 | return; |
| 10379 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10380 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10381 | |
| 10382 | // clang-format off |
| 10383 | PacketFragments packet = { |
| 10384 | // type (short header, 4 byte packet number) |
| 10385 | {"", |
| 10386 | {0x43}}, |
| 10387 | // connection_id |
| 10388 | {"", |
| 10389 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10390 | // packet number |
| 10391 | {"", |
| 10392 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10393 | // frame type (unknown value, two-byte encoding) |
| 10394 | {"", |
| 10395 | {kVarInt62TwoBytes + 0x01, 0x38}} |
| 10396 | }; |
| 10397 | // clang-format on |
| 10398 | |
| 10399 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10400 | AssemblePacketFromFragments(packet)); |
| 10401 | |
| 10402 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 10403 | |
| 10404 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 10405 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 10406 | } |
| 10407 | |
| 10408 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown4Bytes) { |
| 10409 | // This test only for version 99. |
| 10410 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10411 | return; |
| 10412 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10413 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10414 | |
| 10415 | // clang-format off |
| 10416 | PacketFragments packet = { |
| 10417 | // type (short header, 4 byte packet number) |
| 10418 | {"", |
| 10419 | {0x43}}, |
| 10420 | // connection_id |
| 10421 | {"", |
| 10422 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10423 | // packet number |
| 10424 | {"", |
| 10425 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10426 | // frame type (unknown value, four-byte encoding) |
| 10427 | {"", |
| 10428 | {kVarInt62FourBytes + 0x01, 0x00, 0x00, 0x38}} |
| 10429 | }; |
| 10430 | // clang-format on |
| 10431 | |
| 10432 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10433 | AssemblePacketFromFragments(packet)); |
| 10434 | |
| 10435 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 10436 | |
| 10437 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 10438 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 10439 | } |
| 10440 | |
| 10441 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown8Bytes) { |
| 10442 | // This test only for version 99. |
| 10443 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10444 | return; |
| 10445 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10446 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10447 | // clang-format off |
| 10448 | PacketFragments packet = { |
| 10449 | // type (short header, 4 byte packet number) |
| 10450 | {"", |
| 10451 | {0x43}}, |
| 10452 | // connection_id |
| 10453 | {"", |
| 10454 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10455 | // packet number |
| 10456 | {"", |
| 10457 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10458 | // frame type (unknown value, eight-byte encoding) |
| 10459 | {"", |
| 10460 | {kVarInt62EightBytes + 0x01, 0x00, 0x00, 0x01, 0x02, 0x34, 0x56, 0x38}} |
| 10461 | }; |
| 10462 | // clang-format on |
| 10463 | |
| 10464 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10465 | AssemblePacketFromFragments(packet)); |
| 10466 | |
| 10467 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 10468 | |
| 10469 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 10470 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 10471 | } |
| 10472 | |
| 10473 | // Three tests to check that known frame types that are not minimally |
| 10474 | // encoded generate IETF_QUIC_PROTOCOL_VIOLATION errors with detailed |
| 10475 | // information "Frame type not minimally encoded." |
| 10476 | // Look at the frame-type encoded in 2, 4, and 8 bytes. |
| 10477 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2Bytes) { |
| 10478 | // This test only for version 99. |
| 10479 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10480 | return; |
| 10481 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10482 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10483 | |
| 10484 | // clang-format off |
| 10485 | PacketFragments packet = { |
| 10486 | // type (short header, 4 byte packet number) |
| 10487 | {"", |
| 10488 | {0x43}}, |
| 10489 | // connection_id |
| 10490 | {"", |
| 10491 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10492 | // packet number |
| 10493 | {"", |
| 10494 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10495 | // frame type (Blocked, two-byte encoding) |
| 10496 | {"", |
| 10497 | {kVarInt62TwoBytes + 0x00, 0x08}} |
| 10498 | }; |
| 10499 | // clang-format on |
| 10500 | |
| 10501 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10502 | AssemblePacketFromFragments(packet)); |
| 10503 | |
| 10504 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 10505 | |
| 10506 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 10507 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 10508 | } |
| 10509 | |
| 10510 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown4Bytes) { |
| 10511 | // This test only for version 99. |
| 10512 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10513 | return; |
| 10514 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10515 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10516 | |
| 10517 | // clang-format off |
| 10518 | PacketFragments packet = { |
| 10519 | // type (short header, 4 byte packet number) |
| 10520 | {"", |
| 10521 | {0x43}}, |
| 10522 | // connection_id |
| 10523 | {"", |
| 10524 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10525 | // packet number |
| 10526 | {"", |
| 10527 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10528 | // frame type (Blocked, four-byte encoding) |
| 10529 | {"", |
| 10530 | {kVarInt62FourBytes + 0x00, 0x00, 0x00, 0x08}} |
| 10531 | }; |
| 10532 | // clang-format on |
| 10533 | |
| 10534 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10535 | AssemblePacketFromFragments(packet)); |
| 10536 | |
| 10537 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 10538 | |
| 10539 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 10540 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 10541 | } |
| 10542 | |
| 10543 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown8Bytes) { |
| 10544 | // This test only for version 99. |
| 10545 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10546 | return; |
| 10547 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10548 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10549 | // clang-format off |
| 10550 | PacketFragments packet = { |
| 10551 | // type (short header, 4 byte packet number) |
| 10552 | {"", |
| 10553 | {0x43}}, |
| 10554 | // connection_id |
| 10555 | {"", |
| 10556 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10557 | // packet number |
| 10558 | {"", |
| 10559 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10560 | // frame type (Blocked, eight-byte encoding) |
| 10561 | {"", |
| 10562 | {kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08}} |
| 10563 | }; |
| 10564 | // clang-format on |
| 10565 | |
| 10566 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10567 | AssemblePacketFromFragments(packet)); |
| 10568 | |
| 10569 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 10570 | |
| 10571 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 10572 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 10573 | } |
| 10574 | |
| 10575 | // Tests to check that all known OETF frame types that are not minimally |
| 10576 | // encoded generate IETF_QUIC_PROTOCOL_VIOLATION errors with detailed |
| 10577 | // information "Frame type not minimally encoded." |
| 10578 | // Just look at 2-byte encoding. |
| 10579 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2BytesAllTypes) { |
| 10580 | // This test only for version 99. |
| 10581 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10582 | return; |
| 10583 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10584 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10585 | |
| 10586 | // clang-format off |
| 10587 | PacketFragments packets[] = { |
| 10588 | { |
| 10589 | // type (short header, 4 byte packet number) |
| 10590 | {"", |
| 10591 | {0x43}}, |
| 10592 | // connection_id |
| 10593 | {"", |
| 10594 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10595 | // packet number |
| 10596 | {"", |
| 10597 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10598 | // frame type (two-byte encoding) |
| 10599 | {"", |
| 10600 | {kVarInt62TwoBytes + 0x00, 0x00}} |
| 10601 | }, |
| 10602 | { |
| 10603 | // type (short header, 4 byte packet number) |
| 10604 | {"", |
| 10605 | {0x43}}, |
| 10606 | // connection_id |
| 10607 | {"", |
| 10608 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10609 | // packet number |
| 10610 | {"", |
| 10611 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10612 | // frame type (two-byte encoding) |
| 10613 | {"", |
| 10614 | {kVarInt62TwoBytes + 0x00, 0x01}} |
| 10615 | }, |
| 10616 | { |
| 10617 | // type (short header, 4 byte packet number) |
| 10618 | {"", |
| 10619 | {0x43}}, |
| 10620 | // connection_id |
| 10621 | {"", |
| 10622 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10623 | // packet number |
| 10624 | {"", |
| 10625 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10626 | // frame type (two-byte encoding) |
| 10627 | {"", |
| 10628 | {kVarInt62TwoBytes + 0x00, 0x02}} |
| 10629 | }, |
| 10630 | { |
| 10631 | // type (short header, 4 byte packet number) |
| 10632 | {"", |
| 10633 | {0x43}}, |
| 10634 | // connection_id |
| 10635 | {"", |
| 10636 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10637 | // packet number |
| 10638 | {"", |
| 10639 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10640 | // frame type (two-byte encoding) |
| 10641 | {"", |
| 10642 | {kVarInt62TwoBytes + 0x00, 0x03}} |
| 10643 | }, |
| 10644 | { |
| 10645 | // type (short header, 4 byte packet number) |
| 10646 | {"", |
| 10647 | {0x43}}, |
| 10648 | // connection_id |
| 10649 | {"", |
| 10650 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10651 | // packet number |
| 10652 | {"", |
| 10653 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10654 | // frame type (two-byte encoding) |
| 10655 | {"", |
| 10656 | {kVarInt62TwoBytes + 0x00, 0x04}} |
| 10657 | }, |
| 10658 | { |
| 10659 | // type (short header, 4 byte packet number) |
| 10660 | {"", |
| 10661 | {0x43}}, |
| 10662 | // connection_id |
| 10663 | {"", |
| 10664 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10665 | // packet number |
| 10666 | {"", |
| 10667 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10668 | // frame type (two-byte encoding) |
| 10669 | {"", |
| 10670 | {kVarInt62TwoBytes + 0x00, 0x05}} |
| 10671 | }, |
| 10672 | { |
| 10673 | // type (short header, 4 byte packet number) |
| 10674 | {"", |
| 10675 | {0x43}}, |
| 10676 | // connection_id |
| 10677 | {"", |
| 10678 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10679 | // packet number |
| 10680 | {"", |
| 10681 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10682 | // frame type (two-byte encoding) |
| 10683 | {"", |
| 10684 | {kVarInt62TwoBytes + 0x00, 0x06}} |
| 10685 | }, |
| 10686 | { |
| 10687 | // type (short header, 4 byte packet number) |
| 10688 | {"", |
| 10689 | {0x43}}, |
| 10690 | // connection_id |
| 10691 | {"", |
| 10692 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10693 | // packet number |
| 10694 | {"", |
| 10695 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10696 | // frame type (two-byte encoding) |
| 10697 | {"", |
| 10698 | {kVarInt62TwoBytes + 0x00, 0x07}} |
| 10699 | }, |
| 10700 | { |
| 10701 | // type (short header, 4 byte packet number) |
| 10702 | {"", |
| 10703 | {0x43}}, |
| 10704 | // connection_id |
| 10705 | {"", |
| 10706 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10707 | // packet number |
| 10708 | {"", |
| 10709 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10710 | // frame type (two-byte encoding) |
| 10711 | {"", |
| 10712 | {kVarInt62TwoBytes + 0x00, 0x08}} |
| 10713 | }, |
| 10714 | { |
| 10715 | // type (short header, 4 byte packet number) |
| 10716 | {"", |
| 10717 | {0x43}}, |
| 10718 | // connection_id |
| 10719 | {"", |
| 10720 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10721 | // packet number |
| 10722 | {"", |
| 10723 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10724 | // frame type (two-byte encoding) |
| 10725 | {"", |
| 10726 | {kVarInt62TwoBytes + 0x00, 0x09}} |
| 10727 | }, |
| 10728 | { |
| 10729 | // type (short header, 4 byte packet number) |
| 10730 | {"", |
| 10731 | {0x43}}, |
| 10732 | // connection_id |
| 10733 | {"", |
| 10734 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10735 | // packet number |
| 10736 | {"", |
| 10737 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10738 | // frame type (two-byte encoding) |
| 10739 | {"", |
| 10740 | {kVarInt62TwoBytes + 0x00, 0x0a}} |
| 10741 | }, |
| 10742 | { |
| 10743 | // type (short header, 4 byte packet number) |
| 10744 | {"", |
| 10745 | {0x43}}, |
| 10746 | // connection_id |
| 10747 | {"", |
| 10748 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10749 | // packet number |
| 10750 | {"", |
| 10751 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10752 | // frame type (two-byte encoding) |
| 10753 | {"", |
| 10754 | {kVarInt62TwoBytes + 0x00, 0x0b}} |
| 10755 | }, |
| 10756 | { |
| 10757 | // type (short header, 4 byte packet number) |
| 10758 | {"", |
| 10759 | {0x43}}, |
| 10760 | // connection_id |
| 10761 | {"", |
| 10762 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10763 | // packet number |
| 10764 | {"", |
| 10765 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10766 | // frame type (two-byte encoding) |
| 10767 | {"", |
| 10768 | {kVarInt62TwoBytes + 0x00, 0x0c}} |
| 10769 | }, |
| 10770 | { |
| 10771 | // type (short header, 4 byte packet number) |
| 10772 | {"", |
| 10773 | {0x43}}, |
| 10774 | // connection_id |
| 10775 | {"", |
| 10776 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10777 | // packet number |
| 10778 | {"", |
| 10779 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10780 | // frame type (two-byte encoding) |
| 10781 | {"", |
| 10782 | {kVarInt62TwoBytes + 0x00, 0x0d}} |
| 10783 | }, |
| 10784 | { |
| 10785 | // type (short header, 4 byte packet number) |
| 10786 | {"", |
| 10787 | {0x43}}, |
| 10788 | // connection_id |
| 10789 | {"", |
| 10790 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10791 | // packet number |
| 10792 | {"", |
| 10793 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10794 | // frame type (two-byte encoding) |
| 10795 | {"", |
| 10796 | {kVarInt62TwoBytes + 0x00, 0x0e}} |
| 10797 | }, |
| 10798 | { |
| 10799 | // type (short header, 4 byte packet number) |
| 10800 | {"", |
| 10801 | {0x43}}, |
| 10802 | // connection_id |
| 10803 | {"", |
| 10804 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10805 | // packet number |
| 10806 | {"", |
| 10807 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10808 | // frame type (two-byte encoding) |
| 10809 | {"", |
| 10810 | {kVarInt62TwoBytes + 0x00, 0x0f}} |
| 10811 | }, |
| 10812 | { |
| 10813 | // type (short header, 4 byte packet number) |
| 10814 | {"", |
| 10815 | {0x43}}, |
| 10816 | // connection_id |
| 10817 | {"", |
| 10818 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10819 | // packet number |
| 10820 | {"", |
| 10821 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10822 | // frame type (two-byte encoding) |
| 10823 | {"", |
| 10824 | {kVarInt62TwoBytes + 0x00, 0x10}} |
| 10825 | }, |
| 10826 | { |
| 10827 | // type (short header, 4 byte packet number) |
| 10828 | {"", |
| 10829 | {0x43}}, |
| 10830 | // connection_id |
| 10831 | {"", |
| 10832 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10833 | // packet number |
| 10834 | {"", |
| 10835 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10836 | // frame type (two-byte encoding) |
| 10837 | {"", |
| 10838 | {kVarInt62TwoBytes + 0x00, 0x11}} |
| 10839 | }, |
| 10840 | { |
| 10841 | // type (short header, 4 byte packet number) |
| 10842 | {"", |
| 10843 | {0x43}}, |
| 10844 | // connection_id |
| 10845 | {"", |
| 10846 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10847 | // packet number |
| 10848 | {"", |
| 10849 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10850 | // frame type (two-byte encoding) |
| 10851 | {"", |
| 10852 | {kVarInt62TwoBytes + 0x00, 0x12}} |
| 10853 | }, |
| 10854 | { |
| 10855 | // type (short header, 4 byte packet number) |
| 10856 | {"", |
| 10857 | {0x43}}, |
| 10858 | // connection_id |
| 10859 | {"", |
| 10860 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10861 | // packet number |
| 10862 | {"", |
| 10863 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10864 | // frame type (two-byte encoding) |
| 10865 | {"", |
| 10866 | {kVarInt62TwoBytes + 0x00, 0x13}} |
| 10867 | }, |
| 10868 | { |
| 10869 | // type (short header, 4 byte packet number) |
| 10870 | {"", |
| 10871 | {0x43}}, |
| 10872 | // connection_id |
| 10873 | {"", |
| 10874 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10875 | // packet number |
| 10876 | {"", |
| 10877 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10878 | // frame type (two-byte encoding) |
| 10879 | {"", |
| 10880 | {kVarInt62TwoBytes + 0x00, 0x14}} |
| 10881 | }, |
| 10882 | { |
| 10883 | // type (short header, 4 byte packet number) |
| 10884 | {"", |
| 10885 | {0x43}}, |
| 10886 | // connection_id |
| 10887 | {"", |
| 10888 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10889 | // packet number |
| 10890 | {"", |
| 10891 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10892 | // frame type (two-byte encoding) |
| 10893 | {"", |
| 10894 | {kVarInt62TwoBytes + 0x00, 0x15}} |
| 10895 | }, |
| 10896 | { |
| 10897 | // type (short header, 4 byte packet number) |
| 10898 | {"", |
| 10899 | {0x43}}, |
| 10900 | // connection_id |
| 10901 | {"", |
| 10902 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10903 | // packet number |
| 10904 | {"", |
| 10905 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10906 | // frame type (two-byte encoding) |
| 10907 | {"", |
| 10908 | {kVarInt62TwoBytes + 0x00, 0x16}} |
| 10909 | }, |
| 10910 | { |
| 10911 | // type (short header, 4 byte packet number) |
| 10912 | {"", |
| 10913 | {0x43}}, |
| 10914 | // connection_id |
| 10915 | {"", |
| 10916 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10917 | // packet number |
| 10918 | {"", |
| 10919 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10920 | // frame type (two-byte encoding) |
| 10921 | {"", |
| 10922 | {kVarInt62TwoBytes + 0x00, 0x17}} |
| 10923 | }, |
| 10924 | { |
| 10925 | // type (short header, 4 byte packet number) |
| 10926 | {"", |
| 10927 | {0x43}}, |
| 10928 | // connection_id |
| 10929 | {"", |
| 10930 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10931 | // packet number |
| 10932 | {"", |
| 10933 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10934 | // frame type (two-byte encoding) |
| 10935 | {"", |
| 10936 | {kVarInt62TwoBytes + 0x00, 0x18}} |
| 10937 | }, |
| 10938 | { |
| 10939 | // type (short header, 4 byte packet number) |
| 10940 | {"", |
| 10941 | {0x43}}, |
| 10942 | // connection_id |
| 10943 | {"", |
| 10944 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10945 | // packet number |
| 10946 | {"", |
| 10947 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10948 | // frame type (two-byte encoding) |
| 10949 | {"", |
| 10950 | {kVarInt62TwoBytes + 0x00, 0x20}} |
| 10951 | }, |
| 10952 | { |
| 10953 | // type (short header, 4 byte packet number) |
| 10954 | {"", |
| 10955 | {0x43}}, |
| 10956 | // connection_id |
| 10957 | {"", |
| 10958 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10959 | // packet number |
| 10960 | {"", |
| 10961 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10962 | // frame type (two-byte encoding) |
| 10963 | {"", |
| 10964 | {kVarInt62TwoBytes + 0x00, 0x21}} |
| 10965 | }, |
| 10966 | }; |
| 10967 | // clang-format on |
| 10968 | |
| 10969 | for (PacketFragments& packet : packets) { |
| 10970 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10971 | AssemblePacketFromFragments(packet)); |
| 10972 | |
| 10973 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 10974 | |
| 10975 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 10976 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 10977 | } |
| 10978 | } |
| 10979 | |
| 10980 | TEST_P(QuicFramerTest, RetireConnectionIdFrame) { |
| 10981 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10982 | // This frame is only for version 99. |
| 10983 | return; |
| 10984 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10985 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10986 | // clang-format off |
| 10987 | PacketFragments packet99 = { |
| 10988 | // type (short header, 4 byte packet number) |
| 10989 | {"", |
| 10990 | {0x43}}, |
| 10991 | // connection_id |
| 10992 | {"", |
| 10993 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10994 | // packet number |
| 10995 | {"", |
| 10996 | {0x12, 0x34, 0x56, 0x78}}, |
| 10997 | // frame type (IETF_RETIRE_CONNECTION_ID frame) |
| 10998 | {"", |
| 10999 | {0x19}}, |
| 11000 | // Sequence number |
| 11001 | {"Unable to read retire connection ID frame sequence number.", |
| 11002 | {kVarInt62TwoBytes + 0x11, 0x22}} |
| 11003 | }; |
| 11004 | // clang-format on |
| 11005 | |
| 11006 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11007 | AssemblePacketFromFragments(packet99)); |
| 11008 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11009 | |
| 11010 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11011 | ASSERT_TRUE(visitor_.header_.get()); |
| 11012 | EXPECT_TRUE(CheckDecryption( |
| 11013 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11014 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11015 | |
| 11016 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 11017 | |
| 11018 | EXPECT_EQ(0x1122u, visitor_.retire_connection_id_.sequence_number); |
| 11019 | |
| 11020 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 11021 | |
| 11022 | CheckFramingBoundaries(packet99, QUIC_INVALID_RETIRE_CONNECTION_ID_DATA); |
| 11023 | } |
| 11024 | |
| 11025 | TEST_P(QuicFramerTest, BuildRetireConnectionIdFramePacket) { |
| 11026 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11027 | // This frame is only for version 99. |
| 11028 | return; |
| 11029 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 11030 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11031 | QuicPacketHeader header; |
| 11032 | header.destination_connection_id = FramerTestConnectionId(); |
| 11033 | header.reset_flag = false; |
| 11034 | header.version_flag = false; |
| 11035 | header.packet_number = kPacketNumber; |
| 11036 | |
| 11037 | QuicRetireConnectionIdFrame frame; |
| 11038 | frame.sequence_number = 0x1122; |
| 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_RETIRE_CONNECTION_ID frame) |
| 11052 | 0x19, |
| 11053 | // sequence number |
| 11054 | kVarInt62TwoBytes + 0x11, 0x22 |
| 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 | |
| 11066 | TEST_P(QuicFramerTest, AckFrameWithInvalidLargestObserved) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11067 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11068 | // clang-format off |
| 11069 | unsigned char packet[] = { |
| 11070 | // public flags (8 byte connection_id) |
| 11071 | 0x2C, |
| 11072 | // connection_id |
| 11073 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11074 | // packet number |
| 11075 | 0x12, 0x34, 0x56, 0x78, |
| 11076 | |
| 11077 | // frame type (ack frame) |
| 11078 | 0x45, |
| 11079 | // largest observed |
| 11080 | 0x00, 0x00, |
| 11081 | // Zero delta time. |
| 11082 | 0x00, 0x00, |
| 11083 | // first ack block length. |
| 11084 | 0x00, 0x00, |
| 11085 | // num timestamps. |
| 11086 | 0x00 |
| 11087 | }; |
| 11088 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11089 | unsigned char packet46[] = { |
| 11090 | // type (short header, 4 byte packet number) |
| 11091 | 0x43, |
| 11092 | // connection_id |
| 11093 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11094 | // packet number |
| 11095 | 0x12, 0x34, 0x56, 0x78, |
| 11096 | |
| 11097 | // frame type (ack frame) |
| 11098 | 0x45, |
| 11099 | // largest observed |
| 11100 | 0x00, 0x00, |
| 11101 | // Zero delta time. |
| 11102 | 0x00, 0x00, |
| 11103 | // first ack block length. |
| 11104 | 0x00, 0x00, |
| 11105 | // num timestamps. |
| 11106 | 0x00 |
| 11107 | }; |
| 11108 | |
| 11109 | unsigned char packet99[] = { |
| 11110 | // type (short header, 4 byte packet number) |
| 11111 | 0x43, |
| 11112 | // connection_id |
| 11113 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11114 | // packet number |
| 11115 | 0x12, 0x34, 0x56, 0x78, |
| 11116 | |
| 11117 | // frame type (IETF_ACK frame) |
| 11118 | 0x02, |
| 11119 | // Largest acked |
| 11120 | kVarInt62OneByte + 0x00, |
| 11121 | // Zero delta time. |
| 11122 | kVarInt62OneByte + 0x00, |
| 11123 | // Ack block count 0 |
| 11124 | kVarInt62OneByte + 0x00, |
| 11125 | // First ack block length |
| 11126 | kVarInt62OneByte + 0x00, |
| 11127 | }; |
| 11128 | // clang-format on |
| 11129 | |
| 11130 | unsigned char* p = packet; |
| 11131 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 11132 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 11133 | p = packet99; |
| 11134 | p_size = QUIC_ARRAYSIZE(packet99); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11135 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 11136 | p = packet46; |
| 11137 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11138 | } |
| 11139 | |
| 11140 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 11141 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 11142 | EXPECT_EQ(framer_.detailed_error(), "Largest acked is 0."); |
| 11143 | } |
| 11144 | |
| 11145 | TEST_P(QuicFramerTest, FirstAckBlockJustUnderFlow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11146 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11147 | // clang-format off |
| 11148 | unsigned char packet[] = { |
| 11149 | // public flags (8 byte connection_id) |
| 11150 | 0x2C, |
| 11151 | // connection_id |
| 11152 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11153 | // packet number |
| 11154 | 0x12, 0x34, 0x56, 0x78, |
| 11155 | |
| 11156 | // frame type (ack frame) |
| 11157 | 0x45, |
| 11158 | // largest observed |
| 11159 | 0x00, 0x02, |
| 11160 | // Zero delta time. |
| 11161 | 0x00, 0x00, |
| 11162 | // first ack block length. |
| 11163 | 0x00, 0x03, |
| 11164 | // num timestamps. |
| 11165 | 0x00 |
| 11166 | }; |
| 11167 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11168 | unsigned char packet46[] = { |
| 11169 | // type (short header, 4 byte packet number) |
| 11170 | 0x43, |
| 11171 | // connection_id |
| 11172 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11173 | // packet number |
| 11174 | 0x12, 0x34, 0x56, 0x78, |
| 11175 | |
| 11176 | // frame type (ack frame) |
| 11177 | 0x45, |
| 11178 | // largest observed |
| 11179 | 0x00, 0x02, |
| 11180 | // Zero delta time. |
| 11181 | 0x00, 0x00, |
| 11182 | // first ack block length. |
| 11183 | 0x00, 0x03, |
| 11184 | // num timestamps. |
| 11185 | 0x00 |
| 11186 | }; |
| 11187 | |
| 11188 | unsigned char packet99[] = { |
| 11189 | // type (short header, 4 byte packet number) |
| 11190 | 0x43, |
| 11191 | // connection_id |
| 11192 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11193 | // packet number |
| 11194 | 0x12, 0x34, 0x56, 0x78, |
| 11195 | |
| 11196 | // frame type (IETF_ACK frame) |
| 11197 | 0x02, |
| 11198 | // Largest acked |
| 11199 | kVarInt62OneByte + 0x02, |
| 11200 | // Zero delta time. |
| 11201 | kVarInt62OneByte + 0x00, |
| 11202 | // Ack block count 0 |
| 11203 | kVarInt62OneByte + 0x00, |
| 11204 | // First ack block length |
| 11205 | kVarInt62OneByte + 0x02, |
| 11206 | }; |
| 11207 | // clang-format on |
| 11208 | |
| 11209 | unsigned char* p = packet; |
| 11210 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 11211 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 11212 | p = packet99; |
| 11213 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 11214 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11215 | p = packet46; |
| 11216 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11217 | } |
| 11218 | |
| 11219 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 11220 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 11221 | EXPECT_EQ(framer_.detailed_error(), |
| 11222 | "Underflow with first ack block length 3 largest acked is 2."); |
| 11223 | } |
| 11224 | |
| 11225 | TEST_P(QuicFramerTest, ThirdAckBlockJustUnderflow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11226 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11227 | // clang-format off |
| 11228 | unsigned char packet[] = { |
| 11229 | // public flags (8 byte connection_id) |
| 11230 | 0x2C, |
| 11231 | // connection_id |
| 11232 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11233 | // packet number |
| 11234 | 0x12, 0x34, 0x56, 0x78, |
| 11235 | |
| 11236 | // frame type (ack frame) |
| 11237 | 0x60, |
| 11238 | // largest observed |
| 11239 | 0x0A, |
| 11240 | // Zero delta time. |
| 11241 | 0x00, 0x00, |
| 11242 | // Num of ack blocks |
| 11243 | 0x02, |
| 11244 | // first ack block length. |
| 11245 | 0x02, |
| 11246 | // gap to next block |
| 11247 | 0x01, |
| 11248 | // ack block length |
| 11249 | 0x01, |
| 11250 | // gap to next block |
| 11251 | 0x01, |
| 11252 | // ack block length |
| 11253 | 0x06, |
| 11254 | // num timestamps. |
| 11255 | 0x00 |
| 11256 | }; |
| 11257 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11258 | unsigned char packet46[] = { |
| 11259 | // type (short header, 4 byte packet number) |
| 11260 | 0x43, |
| 11261 | // connection_id |
| 11262 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11263 | // packet number |
| 11264 | 0x12, 0x34, 0x56, 0x78, |
| 11265 | |
| 11266 | // frame type (ack frame) |
| 11267 | 0x60, |
| 11268 | // largest observed |
| 11269 | 0x0A, |
| 11270 | // Zero delta time. |
| 11271 | 0x00, 0x00, |
| 11272 | // Num of ack blocks |
| 11273 | 0x02, |
| 11274 | // first ack block length. |
| 11275 | 0x02, |
| 11276 | // gap to next block |
| 11277 | 0x01, |
| 11278 | // ack block length |
| 11279 | 0x01, |
| 11280 | // gap to next block |
| 11281 | 0x01, |
| 11282 | // ack block length |
| 11283 | 0x06, |
| 11284 | // num timestamps. |
| 11285 | 0x00 |
| 11286 | }; |
| 11287 | |
| 11288 | unsigned char packet99[] = { |
| 11289 | // type (short header, 4 byte packet number) |
| 11290 | 0x43, |
| 11291 | // connection_id |
| 11292 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11293 | // packet number |
| 11294 | 0x12, 0x34, 0x56, 0x78, |
| 11295 | |
| 11296 | // frame type (IETF_ACK frame) |
| 11297 | 0x02, |
| 11298 | // Largest acked |
| 11299 | kVarInt62OneByte + 0x0A, |
| 11300 | // Zero delta time. |
| 11301 | kVarInt62OneByte + 0x00, |
| 11302 | // Ack block count 2 |
| 11303 | kVarInt62OneByte + 0x02, |
| 11304 | // First ack block length |
| 11305 | kVarInt62OneByte + 0x01, |
| 11306 | // gap to next block length |
| 11307 | kVarInt62OneByte + 0x00, |
| 11308 | // ack block length |
| 11309 | kVarInt62OneByte + 0x00, |
| 11310 | // gap to next block length |
| 11311 | kVarInt62OneByte + 0x00, |
| 11312 | // ack block length |
| 11313 | kVarInt62OneByte + 0x05, |
| 11314 | }; |
| 11315 | // clang-format on |
| 11316 | |
| 11317 | unsigned char* p = packet; |
| 11318 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 11319 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 11320 | p = packet99; |
| 11321 | p_size = QUIC_ARRAYSIZE(packet99); |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 11322 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11323 | p = packet46; |
| 11324 | p_size = QUIC_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11325 | } |
| 11326 | |
| 11327 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 11328 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 11329 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 11330 | EXPECT_EQ(framer_.detailed_error(), |
| 11331 | "Underflow with ack block length 6 latest ack block end is 5."); |
| 11332 | } else { |
| 11333 | EXPECT_EQ(framer_.detailed_error(), |
| 11334 | "Underflow with ack block length 6, end of block is 6."); |
| 11335 | } |
| 11336 | } |
| 11337 | |
| 11338 | TEST_P(QuicFramerTest, CoalescedPacket) { |
| 11339 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 11340 | return; |
| 11341 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11342 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11343 | // clang-format off |
| 11344 | unsigned char packet[] = { |
| 11345 | // first coalesced packet |
| 11346 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 11347 | // 4-byte packet number) |
| 11348 | 0xD3, |
| 11349 | // version |
| 11350 | QUIC_VERSION_BYTES, |
| 11351 | // destination connection ID length |
| 11352 | 0x50, |
| 11353 | // destination connection ID |
| 11354 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11355 | // long header packet length |
| 11356 | 0x1E, |
| 11357 | // packet number |
| 11358 | 0x12, 0x34, 0x56, 0x78, |
| 11359 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 11360 | 0x08 | 0x01 | 0x02 | 0x04, |
| 11361 | // stream id |
| 11362 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 11363 | // offset |
| 11364 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 11365 | 0x32, 0x10, 0x76, 0x54, |
| 11366 | // data length |
| 11367 | kVarInt62OneByte + 0x0c, |
| 11368 | // data |
| 11369 | 'h', 'e', 'l', 'l', |
| 11370 | 'o', ' ', 'w', 'o', |
| 11371 | 'r', 'l', 'd', '!', |
| 11372 | // second coalesced packet |
| 11373 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 11374 | // 4-byte packet number) |
| 11375 | 0xD3, |
| 11376 | // version |
| 11377 | QUIC_VERSION_BYTES, |
| 11378 | // destination connection ID length |
| 11379 | 0x50, |
| 11380 | // destination connection ID |
| 11381 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11382 | // long header packet length |
| 11383 | 0x1E, |
| 11384 | // packet number |
| 11385 | 0x12, 0x34, 0x56, 0x79, |
| 11386 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 11387 | 0x08 | 0x01 | 0x02 | 0x04, |
| 11388 | // stream id |
| 11389 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 11390 | // offset |
| 11391 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 11392 | 0x32, 0x10, 0x76, 0x54, |
| 11393 | // data length |
| 11394 | kVarInt62OneByte + 0x0c, |
| 11395 | // data |
| 11396 | 'H', 'E', 'L', 'L', |
| 11397 | 'O', '_', 'W', 'O', |
| 11398 | 'R', 'L', 'D', '?', |
| 11399 | }; |
| 11400 | // clang-format on |
| 11401 | |
| 11402 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 11403 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 11404 | |
| 11405 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11406 | ASSERT_TRUE(visitor_.header_.get()); |
| 11407 | |
| 11408 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 11409 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 11410 | |
| 11411 | // Stream ID should be the last 3 bytes of kStreamId. |
| 11412 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 11413 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 11414 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 11415 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 11416 | |
| 11417 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 1u); |
| 11418 | EXPECT_TRUE(framer_.ProcessPacket(*visitor_.coalesced_packets_[0].get())); |
| 11419 | |
| 11420 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11421 | ASSERT_TRUE(visitor_.header_.get()); |
| 11422 | |
| 11423 | ASSERT_EQ(2u, visitor_.stream_frames_.size()); |
| 11424 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 11425 | |
| 11426 | // Stream ID should be the last 3 bytes of kStreamId. |
| 11427 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[1]->stream_id); |
| 11428 | EXPECT_TRUE(visitor_.stream_frames_[1]->fin); |
| 11429 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[1]->offset); |
| 11430 | CheckStreamFrameData("HELLO_WORLD?", visitor_.stream_frames_[1].get()); |
| 11431 | } |
| 11432 | |
| 11433 | TEST_P(QuicFramerTest, MismatchedCoalescedPacket) { |
| 11434 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 11435 | return; |
| 11436 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11437 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11438 | // clang-format off |
| 11439 | unsigned char packet[] = { |
| 11440 | // first coalesced packet |
| 11441 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 11442 | // 4-byte packet number) |
| 11443 | 0xD3, |
| 11444 | // version |
| 11445 | QUIC_VERSION_BYTES, |
| 11446 | // destination connection ID length |
| 11447 | 0x50, |
| 11448 | // destination connection ID |
| 11449 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11450 | // long header packet length |
| 11451 | 0x1E, |
| 11452 | // packet number |
| 11453 | 0x12, 0x34, 0x56, 0x78, |
| 11454 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 11455 | 0x08 | 0x01 | 0x02 | 0x04, |
| 11456 | // stream id |
| 11457 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 11458 | // offset |
| 11459 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 11460 | 0x32, 0x10, 0x76, 0x54, |
| 11461 | // data length |
| 11462 | kVarInt62OneByte + 0x0c, |
| 11463 | // data |
| 11464 | 'h', 'e', 'l', 'l', |
| 11465 | 'o', ' ', 'w', 'o', |
| 11466 | 'r', 'l', 'd', '!', |
| 11467 | // second coalesced packet |
| 11468 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 11469 | // 4-byte packet number) |
| 11470 | 0xD3, |
| 11471 | // version |
| 11472 | QUIC_VERSION_BYTES, |
| 11473 | // destination connection ID length |
| 11474 | 0x50, |
| 11475 | // destination connection ID |
| 11476 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 11477 | // long header packet length |
| 11478 | 0x1E, |
| 11479 | // packet number |
| 11480 | 0x12, 0x34, 0x56, 0x79, |
| 11481 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 11482 | 0x08 | 0x01 | 0x02 | 0x04, |
| 11483 | // stream id |
| 11484 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 11485 | // offset |
| 11486 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 11487 | 0x32, 0x10, 0x76, 0x54, |
| 11488 | // data length |
| 11489 | kVarInt62OneByte + 0x0c, |
| 11490 | // data |
| 11491 | 'H', 'E', 'L', 'L', |
| 11492 | 'O', '_', 'W', 'O', |
| 11493 | 'R', 'L', 'D', '?', |
| 11494 | }; |
| 11495 | // clang-format on |
| 11496 | |
| 11497 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 11498 | EXPECT_QUIC_PEER_BUG(EXPECT_TRUE(framer_.ProcessPacket(encrypted)), |
| 11499 | "Server: Received mismatched coalesced header.*"); |
| 11500 | |
| 11501 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11502 | ASSERT_TRUE(visitor_.header_.get()); |
| 11503 | |
| 11504 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 11505 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 11506 | |
| 11507 | // Stream ID should be the last 3 bytes of kStreamId. |
| 11508 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 11509 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 11510 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 11511 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 11512 | |
| 11513 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 0u); |
| 11514 | } |
| 11515 | |
| 11516 | TEST_P(QuicFramerTest, InvalidCoalescedPacket) { |
| 11517 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 11518 | return; |
| 11519 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11520 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11521 | // clang-format off |
| 11522 | unsigned char packet[] = { |
| 11523 | // first coalesced packet |
| 11524 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 11525 | // 4-byte packet number) |
| 11526 | 0xD3, |
| 11527 | // version |
| 11528 | QUIC_VERSION_BYTES, |
| 11529 | // destination connection ID length |
| 11530 | 0x50, |
| 11531 | // destination connection ID |
| 11532 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11533 | // long header packet length |
| 11534 | 0x1E, |
| 11535 | // packet number |
| 11536 | 0x12, 0x34, 0x56, 0x78, |
| 11537 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 11538 | 0x08 | 0x01 | 0x02 | 0x04, |
| 11539 | // stream id |
| 11540 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 11541 | // offset |
| 11542 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 11543 | 0x32, 0x10, 0x76, 0x54, |
| 11544 | // data length |
| 11545 | kVarInt62OneByte + 0x0c, |
| 11546 | // data |
| 11547 | 'h', 'e', 'l', 'l', |
| 11548 | 'o', ' ', 'w', 'o', |
| 11549 | 'r', 'l', 'd', '!', |
| 11550 | // second coalesced packet |
| 11551 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 11552 | // 4-byte packet number) |
| 11553 | 0xD3, |
| 11554 | // version would be here but we cut off the invalid coalesced header. |
| 11555 | }; |
| 11556 | // clang-format on |
| 11557 | |
| 11558 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 11559 | EXPECT_QUIC_PEER_BUG(EXPECT_TRUE(framer_.ProcessPacket(encrypted)), |
| 11560 | "Server: Failed to parse received coalesced header.*"); |
| 11561 | |
| 11562 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11563 | ASSERT_TRUE(visitor_.header_.get()); |
| 11564 | |
| 11565 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 11566 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 11567 | |
| 11568 | // Stream ID should be the last 3 bytes of kStreamId. |
| 11569 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 11570 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 11571 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 11572 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 11573 | |
| 11574 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 0u); |
| 11575 | } |
| 11576 | |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 11577 | // Some IETF implementations send an initial followed by zeroes instead of |
| 11578 | // padding inside the initial. We need to make sure that we still process |
| 11579 | // the initial correctly and ignore the zeroes. |
| 11580 | TEST_P(QuicFramerTest, CoalescedPacketWithZeroesRoundTrip) { |
| 11581 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 11582 | return; |
| 11583 | } |
| 11584 | ASSERT_TRUE(framer_.version().KnowsWhichDecrypterToUse()); |
| 11585 | QuicConnectionId connection_id = FramerTestConnectionId(); |
| 11586 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 11587 | |
| 11588 | CrypterPair client_crypters; |
| 11589 | CryptoUtils::CreateTlsInitialCrypters(Perspective::IS_CLIENT, |
| 11590 | framer_.transport_version(), |
| 11591 | connection_id, &client_crypters); |
| 11592 | framer_.SetEncrypter(ENCRYPTION_INITIAL, |
| 11593 | std::move(client_crypters.encrypter)); |
| 11594 | |
| 11595 | QuicPacketHeader header; |
| 11596 | header.destination_connection_id = connection_id; |
| 11597 | header.version_flag = true; |
| 11598 | header.packet_number = kPacketNumber; |
| 11599 | header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; |
| 11600 | header.long_packet_type = INITIAL; |
| 11601 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 11602 | header.retry_token_length_length = VARIABLE_LENGTH_INTEGER_LENGTH_1; |
| 11603 | QuicFrames frames = {QuicFrame(QuicPingFrame())}; |
| 11604 | |
| 11605 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11606 | ASSERT_NE(nullptr, data); |
| 11607 | |
| 11608 | // Add zeroes after the valid initial packet. |
| 11609 | unsigned char packet[kMaxOutgoingPacketSize] = {}; |
| 11610 | size_t encrypted_length = |
| 11611 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, *data, |
| 11612 | AsChars(packet), QUIC_ARRAYSIZE(packet)); |
| 11613 | ASSERT_NE(0u, encrypted_length); |
| 11614 | |
| 11615 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 11616 | CrypterPair server_crypters; |
| 11617 | CryptoUtils::CreateTlsInitialCrypters(Perspective::IS_SERVER, |
| 11618 | framer_.transport_version(), |
| 11619 | connection_id, &server_crypters); |
| 11620 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, |
| 11621 | std::move(server_crypters.decrypter)); |
| 11622 | |
| 11623 | // Make sure the first long header initial packet parses correctly. |
| 11624 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 11625 | |
| 11626 | // Make sure we discard the subsequent zeroes. |
| 11627 | EXPECT_QUIC_PEER_BUG(EXPECT_TRUE(framer_.ProcessPacket(encrypted)), |
| 11628 | "Server: Received mismatched coalesced header.*"); |
| 11629 | } |
| 11630 | |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 11631 | TEST_P(QuicFramerTest, ClientReceivesInvalidVersion) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 11632 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 11633 | return; |
| 11634 | } |
| 11635 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 11636 | |
| 11637 | // clang-format off |
| 11638 | unsigned char packet[] = { |
| 11639 | // public flags (long header with packet type INITIAL) |
| 11640 | 0xFF, |
| 11641 | // version that is different from the framer's version |
| 11642 | 'Q', '0', '4', '3', |
| 11643 | // connection ID lengths |
| 11644 | 0x05, |
| 11645 | // source connection ID |
| 11646 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11647 | // packet number |
| 11648 | 0x01, |
| 11649 | // padding frame |
| 11650 | 0x00, |
| 11651 | }; |
| 11652 | // clang-format on |
| 11653 | |
| 11654 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 11655 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 11656 | |
| 11657 | EXPECT_EQ(QUIC_INVALID_VERSION, framer_.error()); |
| 11658 | EXPECT_EQ("Client received unexpected version.", framer_.detailed_error()); |
| 11659 | } |
| 11660 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11661 | TEST_P(QuicFramerTest, PacketHeaderWithVariableLengthConnectionId) { |
| 11662 | if (framer_.transport_version() < QUIC_VERSION_46) { |
| 11663 | return; |
| 11664 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11665 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11666 | char connection_id_bytes[9] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, |
| 11667 | 0x54, 0x32, 0x10, 0x42}; |
| 11668 | QuicConnectionId connection_id(connection_id_bytes, |
| 11669 | sizeof(connection_id_bytes)); |
| 11670 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
dschinazi | 8ff7482 | 2019-05-28 16:37:20 -0700 | [diff] [blame] | 11671 | QuicFramerPeer::SetExpectedServerConnectionIDLength(&framer_, |
| 11672 | connection_id.length()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11673 | |
| 11674 | // clang-format off |
| 11675 | PacketFragments packet = { |
| 11676 | // type (8 byte connection_id and 1 byte packet number) |
| 11677 | {"Unable to read type.", |
| 11678 | {0x40}}, |
| 11679 | // connection_id |
| 11680 | {"Unable to read Destination ConnectionId.", |
| 11681 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 11682 | // packet number |
| 11683 | {"Unable to read packet number.", |
| 11684 | {0x78}}, |
| 11685 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 11686 | |
| 11687 | PacketFragments packet_with_padding = { |
| 11688 | // type (8 byte connection_id and 1 byte packet number) |
| 11689 | {"Unable to read type.", |
| 11690 | {0x40}}, |
| 11691 | // connection_id |
| 11692 | {"Unable to read Destination ConnectionId.", |
| 11693 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 11694 | // packet number |
| 11695 | {"", |
| 11696 | {0x78}}, |
| 11697 | // padding |
| 11698 | {"", {0x00, 0x00, 0x00}}, |
| 11699 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11700 | // clang-format on |
| 11701 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 11702 | PacketFragments& fragments = |
| 11703 | framer_.version().HasHeaderProtection() ? packet_with_padding : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11704 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 11705 | AssemblePacketFromFragments(fragments)); |
| 11706 | if (framer_.version().HasHeaderProtection()) { |
| 11707 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11708 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11709 | } else { |
| 11710 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11711 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 11712 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11713 | ASSERT_TRUE(visitor_.header_.get()); |
| 11714 | EXPECT_EQ(connection_id, visitor_.header_->destination_connection_id); |
| 11715 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 11716 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 11717 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 11718 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 11719 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 11720 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11721 | } |
| 11722 | |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 11723 | TEST_P(QuicFramerTest, UpdateExpectedConnectionIdLength) { |
| 11724 | if (framer_.transport_version() < QUIC_VERSION_46) { |
| 11725 | return; |
| 11726 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11727 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
dschinazi | 8ff7482 | 2019-05-28 16:37:20 -0700 | [diff] [blame] | 11728 | framer_.SetShouldUpdateExpectedServerConnectionIdLength(true); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 11729 | |
| 11730 | // clang-format off |
| 11731 | unsigned char long_header_packet[] = { |
| 11732 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 11733 | // 4-byte packet number) |
| 11734 | 0xD3, |
| 11735 | // version |
| 11736 | QUIC_VERSION_BYTES, |
| 11737 | // destination connection ID length |
| 11738 | 0x60, |
| 11739 | // destination connection ID |
| 11740 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 11741 | // packet number |
| 11742 | 0x12, 0x34, 0x56, 0x78, |
| 11743 | // padding frame |
| 11744 | 0x00, |
| 11745 | }; |
| 11746 | unsigned char long_header_packet99[] = { |
| 11747 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 11748 | // 4-byte packet number) |
| 11749 | 0xD3, |
| 11750 | // version |
| 11751 | QUIC_VERSION_BYTES, |
| 11752 | // destination connection ID length |
| 11753 | 0x60, |
| 11754 | // destination connection ID |
| 11755 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 11756 | // long header packet length |
| 11757 | 0x05, |
| 11758 | // packet number |
| 11759 | 0x12, 0x34, 0x56, 0x78, |
| 11760 | // padding frame |
| 11761 | 0x00, |
| 11762 | }; |
| 11763 | // clang-format on |
| 11764 | |
| 11765 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 11766 | EXPECT_TRUE(framer_.ProcessPacket( |
| 11767 | QuicEncryptedPacket(AsChars(long_header_packet), |
| 11768 | QUIC_ARRAYSIZE(long_header_packet), false))); |
| 11769 | } else { |
| 11770 | EXPECT_TRUE(framer_.ProcessPacket( |
| 11771 | QuicEncryptedPacket(AsChars(long_header_packet99), |
| 11772 | QUIC_ARRAYSIZE(long_header_packet99), false))); |
| 11773 | } |
| 11774 | |
| 11775 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11776 | ASSERT_TRUE(visitor_.header_.get()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 11777 | EXPECT_EQ(visitor_.header_.get()->destination_connection_id, |
| 11778 | FramerTestConnectionIdNineBytes()); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 11779 | EXPECT_EQ(visitor_.header_.get()->packet_number, |
| 11780 | QuicPacketNumber(UINT64_C(0x12345678))); |
| 11781 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11782 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 11783 | // clang-format off |
| 11784 | unsigned char short_header_packet[] = { |
| 11785 | // type (short header, 4 byte packet number) |
| 11786 | 0x43, |
| 11787 | // connection_id |
| 11788 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 11789 | // packet number |
| 11790 | 0x13, 0x37, 0x42, 0x33, |
| 11791 | // padding frame |
| 11792 | 0x00, |
| 11793 | }; |
| 11794 | // clang-format on |
| 11795 | |
| 11796 | QuicEncryptedPacket short_header_encrypted( |
| 11797 | AsChars(short_header_packet), QUIC_ARRAYSIZE(short_header_packet), false); |
| 11798 | EXPECT_TRUE(framer_.ProcessPacket(short_header_encrypted)); |
| 11799 | |
| 11800 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11801 | ASSERT_TRUE(visitor_.header_.get()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 11802 | EXPECT_EQ(visitor_.header_.get()->destination_connection_id, |
| 11803 | FramerTestConnectionIdNineBytes()); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 11804 | EXPECT_EQ(visitor_.header_.get()->packet_number, |
| 11805 | QuicPacketNumber(UINT64_C(0x13374233))); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 11806 | |
| 11807 | PacketHeaderFormat format; |
| 11808 | bool version_flag; |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 11809 | QuicConnectionId destination_connection_id, source_connection_id; |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 11810 | QuicVersionLabel version_label; |
| 11811 | std::string detailed_error; |
| 11812 | EXPECT_EQ(QUIC_NO_ERROR, |
| 11813 | QuicFramer::ProcessPacketDispatcher( |
| 11814 | QuicEncryptedPacket(AsChars(long_header_packet), |
| 11815 | QUIC_ARRAYSIZE(long_header_packet)), |
| 11816 | kQuicDefaultConnectionIdLength, &format, &version_flag, |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 11817 | &version_label, &destination_connection_id, |
| 11818 | &source_connection_id, &detailed_error)); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 11819 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 11820 | EXPECT_TRUE(version_flag); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 11821 | EXPECT_EQ(9, destination_connection_id.length()); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 11822 | EXPECT_EQ(FramerTestConnectionIdNineBytes(), destination_connection_id); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 11823 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 11824 | |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 11825 | EXPECT_EQ( |
| 11826 | QUIC_NO_ERROR, |
| 11827 | QuicFramer::ProcessPacketDispatcher( |
| 11828 | short_header_encrypted, 9, &format, &version_flag, &version_label, |
| 11829 | &destination_connection_id, &source_connection_id, &detailed_error)); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 11830 | EXPECT_EQ(IETF_QUIC_SHORT_HEADER_PACKET, format); |
| 11831 | EXPECT_FALSE(version_flag); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 11832 | EXPECT_EQ(9, destination_connection_id.length()); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 11833 | EXPECT_EQ(FramerTestConnectionIdNineBytes(), destination_connection_id); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 11834 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 11835 | } |
| 11836 | |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 11837 | TEST_P(QuicFramerTest, MultiplePacketNumberSpaces) { |
| 11838 | if (framer_.transport_version() < QUIC_VERSION_46) { |
| 11839 | return; |
| 11840 | } |
dschinazi | 8ff7482 | 2019-05-28 16:37:20 -0700 | [diff] [blame] | 11841 | framer_.SetShouldUpdateExpectedServerConnectionIdLength(true); |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 11842 | framer_.EnableMultiplePacketNumberSpacesSupport(); |
| 11843 | |
| 11844 | // clang-format off |
| 11845 | unsigned char long_header_packet[] = { |
| 11846 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 11847 | // 4-byte packet number) |
| 11848 | 0xD3, |
| 11849 | // version |
| 11850 | QUIC_VERSION_BYTES, |
| 11851 | // destination connection ID length |
| 11852 | 0x60, |
| 11853 | // destination connection ID |
| 11854 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 11855 | // packet number |
| 11856 | 0x12, 0x34, 0x56, 0x78, |
| 11857 | // padding frame |
| 11858 | 0x00, |
| 11859 | }; |
| 11860 | unsigned char long_header_packet99[] = { |
| 11861 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 11862 | // 4-byte packet number) |
| 11863 | 0xD3, |
| 11864 | // version |
| 11865 | QUIC_VERSION_BYTES, |
| 11866 | // destination connection ID length |
| 11867 | 0x60, |
| 11868 | // destination connection ID |
| 11869 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 11870 | // long header packet length |
| 11871 | 0x05, |
| 11872 | // packet number |
| 11873 | 0x12, 0x34, 0x56, 0x78, |
| 11874 | // padding frame |
| 11875 | 0x00, |
| 11876 | }; |
| 11877 | // clang-format on |
| 11878 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11879 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 11880 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 11881 | QuicMakeUnique<TestDecrypter>()); |
| 11882 | framer_.RemoveDecrypter(ENCRYPTION_INITIAL); |
| 11883 | } else { |
| 11884 | framer_.SetDecrypter(ENCRYPTION_ZERO_RTT, QuicMakeUnique<TestDecrypter>()); |
| 11885 | } |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 11886 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 11887 | EXPECT_TRUE(framer_.ProcessPacket( |
| 11888 | QuicEncryptedPacket(AsChars(long_header_packet), |
| 11889 | QUIC_ARRAYSIZE(long_header_packet), false))); |
| 11890 | } else { |
| 11891 | EXPECT_TRUE(framer_.ProcessPacket( |
| 11892 | QuicEncryptedPacket(AsChars(long_header_packet99), |
| 11893 | QUIC_ARRAYSIZE(long_header_packet99), false))); |
| 11894 | } |
| 11895 | |
| 11896 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11897 | EXPECT_FALSE( |
| 11898 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, INITIAL_DATA) |
| 11899 | .IsInitialized()); |
| 11900 | EXPECT_FALSE( |
| 11901 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, HANDSHAKE_DATA) |
| 11902 | .IsInitialized()); |
| 11903 | EXPECT_EQ(kPacketNumber, QuicFramerPeer::GetLargestDecryptedPacketNumber( |
| 11904 | &framer_, APPLICATION_DATA)); |
| 11905 | |
| 11906 | // clang-format off |
| 11907 | unsigned char short_header_packet[] = { |
| 11908 | // type (short header, 1 byte packet number) |
| 11909 | 0x40, |
| 11910 | // connection_id |
| 11911 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 11912 | // packet number |
| 11913 | 0x79, |
| 11914 | // padding frame |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 11915 | 0x00, 0x00, 0x00, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 11916 | }; |
| 11917 | // clang-format on |
| 11918 | |
| 11919 | QuicEncryptedPacket short_header_encrypted( |
| 11920 | AsChars(short_header_packet), QUIC_ARRAYSIZE(short_header_packet), false); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11921 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 11922 | framer_.InstallDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 11923 | QuicMakeUnique<TestDecrypter>()); |
| 11924 | framer_.RemoveDecrypter(ENCRYPTION_ZERO_RTT); |
| 11925 | } else { |
| 11926 | framer_.SetDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 11927 | QuicMakeUnique<TestDecrypter>()); |
| 11928 | } |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 11929 | EXPECT_TRUE(framer_.ProcessPacket(short_header_encrypted)); |
| 11930 | |
| 11931 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11932 | EXPECT_FALSE( |
| 11933 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, INITIAL_DATA) |
| 11934 | .IsInitialized()); |
| 11935 | EXPECT_FALSE( |
| 11936 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, HANDSHAKE_DATA) |
| 11937 | .IsInitialized()); |
| 11938 | EXPECT_EQ(kPacketNumber + 1, QuicFramerPeer::GetLargestDecryptedPacketNumber( |
| 11939 | &framer_, APPLICATION_DATA)); |
| 11940 | } |
| 11941 | |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 11942 | TEST_P(QuicFramerTest, IetfRetryPacketRejected) { |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 11943 | if (!framer_.version().KnowsWhichDecrypterToUse() || |
| 11944 | framer_.version().SupportsRetry()) { |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 11945 | return; |
| 11946 | } |
| 11947 | |
| 11948 | // clang-format off |
| 11949 | PacketFragments packet = { |
| 11950 | // public flags (IETF Retry packet, 0-length original destination CID) |
| 11951 | {"Unable to read type.", |
| 11952 | {0xf0}}, |
| 11953 | // version tag |
| 11954 | {"Unable to read protocol version.", |
| 11955 | {QUIC_VERSION_BYTES}}, |
| 11956 | // connection_id length |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 11957 | {"Illegal long header type value.", |
| 11958 | {0x00}}, |
| 11959 | }; |
| 11960 | // clang-format on |
| 11961 | |
| 11962 | // clang-format off |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 11963 | PacketFragments packet46 = { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 11964 | // public flags (IETF Retry packet, 0-length original destination CID) |
| 11965 | {"Unable to read type.", |
| 11966 | {0xf0}}, |
| 11967 | // version tag |
| 11968 | {"Unable to read protocol version.", |
| 11969 | {QUIC_VERSION_BYTES}}, |
| 11970 | // connection_id length |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 11971 | {"RETRY not supported in this version.", |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 11972 | {0x00}}, |
| 11973 | }; |
| 11974 | // clang-format on |
| 11975 | |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 11976 | PacketFragments& fragments = |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 11977 | framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet; |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 11978 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 11979 | AssemblePacketFromFragments(fragments)); |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 11980 | |
| 11981 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11982 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 11983 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 11984 | } |
| 11985 | |
| 11986 | TEST_P(QuicFramerTest, RetryPacketRejectedWithMultiplePacketNumberSpaces) { |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 11987 | if (framer_.transport_version() < QUIC_VERSION_46 || |
| 11988 | framer_.version().SupportsRetry()) { |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 11989 | return; |
| 11990 | } |
| 11991 | framer_.EnableMultiplePacketNumberSpacesSupport(); |
| 11992 | |
| 11993 | // clang-format off |
| 11994 | PacketFragments packet = { |
| 11995 | // public flags (IETF Retry packet, 0-length original destination CID) |
| 11996 | {"Unable to read type.", |
| 11997 | {0xf0}}, |
| 11998 | // version tag |
| 11999 | {"Unable to read protocol version.", |
| 12000 | {QUIC_VERSION_BYTES}}, |
| 12001 | // connection_id length |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 12002 | {"RETRY not supported in this version.", |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 12003 | {0x00}}, |
| 12004 | }; |
| 12005 | // clang-format on |
| 12006 | |
| 12007 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12008 | AssemblePacketFromFragments(packet)); |
| 12009 | |
| 12010 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 12011 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
| 12012 | CheckFramingBoundaries(packet, QUIC_INVALID_PACKET_HEADER); |
| 12013 | } |
| 12014 | |
nharper | a745e39 | 2019-04-19 12:05:15 -0700 | [diff] [blame] | 12015 | TEST_P(QuicFramerTest, ProcessPublicHeaderNoVersionInferredType) { |
| 12016 | // The framer needs to have Perspective::IS_SERVER and configured to infer the |
| 12017 | // packet header type from the packet (not the version). The framer's version |
| 12018 | // needs to be one that uses the IETF packet format. |
| 12019 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 12020 | return; |
| 12021 | } |
| 12022 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 12023 | |
| 12024 | // Prepare a packet that uses the Google QUIC packet header but has no version |
| 12025 | // field. |
| 12026 | |
| 12027 | // clang-format off |
| 12028 | PacketFragments packet = { |
| 12029 | // public flags (1-byte packet number, 8-byte connection_id, no version) |
| 12030 | {"Unable to read public flags.", |
| 12031 | {0x08}}, |
| 12032 | // connection_id |
| 12033 | {"Unable to read ConnectionId.", |
| 12034 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12035 | // packet number |
| 12036 | {"Unable to read packet number.", |
| 12037 | {0x01}}, |
| 12038 | // padding |
| 12039 | {"Invalid public header type for expected version.", |
| 12040 | {0x00}}, |
| 12041 | }; |
| 12042 | // clang-format on |
| 12043 | |
| 12044 | PacketFragments& fragments = packet; |
| 12045 | |
| 12046 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12047 | AssemblePacketFromFragments(fragments)); |
| 12048 | |
| 12049 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 12050 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
nharper | 8b6d63a | 2019-05-03 10:34:53 -0700 | [diff] [blame] | 12051 | EXPECT_EQ("Invalid public header type for expected version.", |
| 12052 | framer_.detailed_error()); |
nharper | a745e39 | 2019-04-19 12:05:15 -0700 | [diff] [blame] | 12053 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 12054 | } |
| 12055 | |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 12056 | TEST_P(QuicFramerTest, ProcessMismatchedHeaderVersion) { |
| 12057 | // The framer needs to have Perspective::IS_SERVER and configured to infer the |
| 12058 | // packet header type from the packet (not the version). The framer's version |
| 12059 | // needs to be one that uses the IETF packet format. |
| 12060 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 12061 | return; |
| 12062 | } |
| 12063 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 12064 | |
| 12065 | // clang-format off |
| 12066 | PacketFragments packet = { |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 12067 | // public flags (Google QUIC header with version present) |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 12068 | {"Unable to read public flags.", |
| 12069 | {0x09}}, |
| 12070 | // connection_id |
| 12071 | {"Unable to read ConnectionId.", |
| 12072 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12073 | // version tag |
| 12074 | {"Unable to read protocol version.", |
| 12075 | {QUIC_VERSION_BYTES}}, |
| 12076 | // packet number |
| 12077 | {"Unable to read packet number.", |
| 12078 | {0x01}}, |
| 12079 | }; |
| 12080 | // clang-format on |
| 12081 | |
| 12082 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12083 | AssemblePacketFromFragments(packet)); |
| 12084 | framer_.ProcessPacket(*encrypted); |
| 12085 | |
| 12086 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 12087 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
nharper | 8b6d63a | 2019-05-03 10:34:53 -0700 | [diff] [blame] | 12088 | EXPECT_EQ("Invalid public header type for expected version.", |
| 12089 | framer_.detailed_error()); |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 12090 | CheckFramingBoundaries(packet, QUIC_INVALID_PACKET_HEADER); |
| 12091 | } |
| 12092 | |
dschinazi | de0f6dc | 2019-05-15 16:10:11 -0700 | [diff] [blame] | 12093 | TEST_P(QuicFramerTest, WriteClientVersionNegotiationProbePacket) { |
| 12094 | // clang-format off |
| 12095 | static const char expected_packet[1200] = { |
| 12096 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 12097 | 0xc0, |
| 12098 | // Version, part of the IETF space reserved for negotiation. |
| 12099 | 0xca, 0xba, 0xda, 0xba, |
| 12100 | // Destination connection ID length 8, source connection ID length 0. |
| 12101 | 0x50, |
| 12102 | // 8-byte destination connection ID. |
| 12103 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 12104 | // 8 bytes of zeroes followed by 8 bytes of ones to ensure that this does |
| 12105 | // not parse with any known version. |
| 12106 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12107 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 12108 | // 2 bytes of zeroes to pad to 16 byte boundary. |
| 12109 | 0x00, 0x00, |
| 12110 | // A polite greeting in case a human sees this in tcpdump. |
| 12111 | 0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x63, |
| 12112 | 0x6b, 0x65, 0x74, 0x20, 0x6f, 0x6e, 0x6c, 0x79, |
| 12113 | 0x20, 0x65, 0x78, 0x69, 0x73, 0x74, 0x73, 0x20, |
| 12114 | 0x74, 0x6f, 0x20, 0x74, 0x72, 0x69, 0x67, 0x67, |
| 12115 | 0x65, 0x72, 0x20, 0x49, 0x45, 0x54, 0x46, 0x20, |
| 12116 | 0x51, 0x55, 0x49, 0x43, 0x20, 0x76, 0x65, 0x72, |
| 12117 | 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x65, 0x67, |
| 12118 | 0x6f, 0x74, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, |
| 12119 | 0x2e, 0x20, 0x50, 0x6c, 0x65, 0x61, 0x73, 0x65, |
| 12120 | 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, |
| 12121 | 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, |
| 12122 | 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, |
| 12123 | 0x4e, 0x65, 0x67, 0x6f, 0x74, 0x69, 0x61, 0x74, |
| 12124 | 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x63, 0x6b, |
| 12125 | 0x65, 0x74, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x63, |
| 12126 | 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x77, 0x68, |
| 12127 | 0x61, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, |
| 12128 | 0x6f, 0x6e, 0x73, 0x20, 0x79, 0x6f, 0x75, 0x20, |
| 12129 | 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2e, |
| 12130 | 0x20, 0x54, 0x68, 0x61, 0x6e, 0x6b, 0x20, 0x79, |
| 12131 | 0x6f, 0x75, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x68, |
| 12132 | 0x61, 0x76, 0x65, 0x20, 0x61, 0x20, 0x6e, 0x69, |
| 12133 | 0x63, 0x65, 0x20, 0x64, 0x61, 0x79, 0x2e, 0x00, |
| 12134 | }; |
| 12135 | // clang-format on |
| 12136 | char packet[1200]; |
| 12137 | char destination_connection_id_bytes[] = {0x56, 0x4e, 0x20, 0x70, |
| 12138 | 0x6c, 0x7a, 0x20, 0x21}; |
| 12139 | EXPECT_TRUE(QuicFramer::WriteClientVersionNegotiationProbePacket( |
| 12140 | packet, sizeof(packet), destination_connection_id_bytes, |
| 12141 | sizeof(destination_connection_id_bytes))); |
| 12142 | test::CompareCharArraysWithHexError("constructed packet", expected_packet, |
| 12143 | sizeof(expected_packet), packet, |
| 12144 | sizeof(packet)); |
| 12145 | QuicEncryptedPacket encrypted(reinterpret_cast<const char*>(packet), |
| 12146 | sizeof(packet), false); |
| 12147 | // Make sure we fail to parse this packet for the version under test. |
| 12148 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12149 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 12150 | // We can only parse the connection ID with an IETF parser. |
| 12151 | return; |
| 12152 | } |
| 12153 | ASSERT_TRUE(visitor_.header_.get()); |
| 12154 | QuicConnectionId probe_payload_connection_id( |
| 12155 | reinterpret_cast<const char*>(destination_connection_id_bytes), |
| 12156 | sizeof(destination_connection_id_bytes)); |
| 12157 | EXPECT_EQ(probe_payload_connection_id, |
| 12158 | visitor_.header_.get()->destination_connection_id); |
| 12159 | } |
| 12160 | |
| 12161 | TEST_P(QuicFramerTest, ParseServerVersionNegotiationProbeResponse) { |
| 12162 | // clang-format off |
| 12163 | const char packet[] = { |
| 12164 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 12165 | 0xc0, |
| 12166 | // Version of 0, indicating version negotiation. |
| 12167 | 0x00, 0x00, 0x00, 0x00, |
| 12168 | // Destination connection ID length 0, source connection ID length 8. |
| 12169 | 0x05, |
| 12170 | // 8-byte source connection ID. |
| 12171 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 12172 | // A few supported versions. |
| 12173 | 0xaa, 0xaa, 0xaa, 0xaa, |
| 12174 | QUIC_VERSION_BYTES, |
| 12175 | }; |
| 12176 | // clang-format on |
| 12177 | char probe_payload_bytes[] = {0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21}; |
| 12178 | char parsed_probe_payload_bytes[kQuicMaxConnectionIdLength] = {}; |
| 12179 | uint8_t parsed_probe_payload_length = 0; |
| 12180 | std::string parse_detailed_error = ""; |
| 12181 | EXPECT_TRUE(QuicFramer::ParseServerVersionNegotiationProbeResponse( |
| 12182 | reinterpret_cast<const char*>(packet), sizeof(packet), |
| 12183 | reinterpret_cast<char*>(parsed_probe_payload_bytes), |
| 12184 | &parsed_probe_payload_length, &parse_detailed_error)); |
| 12185 | EXPECT_EQ("", parse_detailed_error); |
| 12186 | test::CompareCharArraysWithHexError( |
| 12187 | "parsed probe", probe_payload_bytes, sizeof(probe_payload_bytes), |
| 12188 | parsed_probe_payload_bytes, parsed_probe_payload_length); |
| 12189 | } |
| 12190 | |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 12191 | TEST_P(QuicFramerTest, ClientConnectionIdNotSupportedYet) { |
| 12192 | if (GetQuicRestartFlag(quic_do_not_override_connection_id)) { |
| 12193 | // This check is currently only performed when this flag is disabled. |
| 12194 | return; |
| 12195 | } |
| 12196 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 12197 | // This test requires an IETF long header. |
| 12198 | return; |
| 12199 | } |
| 12200 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 12201 | // clang-format off |
| 12202 | unsigned char packet[] = { |
| 12203 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12204 | // 4-byte packet number) |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 12205 | 0xD3, |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 12206 | // version |
| 12207 | QUIC_VERSION_BYTES, |
| 12208 | // destination connection ID length |
| 12209 | 0x50, |
| 12210 | // destination connection ID |
| 12211 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12212 | // long header packet length |
| 12213 | 0x05, |
| 12214 | // packet number |
| 12215 | 0x12, 0x34, 0x56, 0x00, |
| 12216 | // padding frame |
| 12217 | 0x00, |
| 12218 | }; |
| 12219 | // clang-format on |
| 12220 | EXPECT_FALSE(framer_.ProcessPacket( |
| 12221 | QuicEncryptedPacket(AsChars(packet), QUIC_ARRAYSIZE(packet), false))); |
| 12222 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
| 12223 | if (!QuicUtils::VariableLengthConnectionIdAllowedForVersion( |
| 12224 | framer_.transport_version())) { |
| 12225 | EXPECT_EQ("Invalid ConnectionId length.", framer_.detailed_error()); |
| 12226 | } else { |
| 12227 | EXPECT_EQ("Client connection ID not supported yet.", |
| 12228 | framer_.detailed_error()); |
| 12229 | } |
| 12230 | } |
| 12231 | |
dschinazi | 334f023 | 2019-05-29 16:08:53 -0700 | [diff] [blame] | 12232 | TEST_P(QuicFramerTest, ProcessAndValidateIetfConnectionIdLengthClient) { |
| 12233 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 12234 | // This test requires an IETF long header. |
| 12235 | return; |
| 12236 | } |
| 12237 | char connection_id_lengths = 0x05; |
| 12238 | QuicDataReader reader(&connection_id_lengths, 1); |
| 12239 | |
| 12240 | bool should_update_expected_server_connection_id_length = false; |
| 12241 | uint8_t expected_server_connection_id_length = 8; |
| 12242 | uint8_t destination_connection_id_length = 0; |
| 12243 | uint8_t source_connection_id_length = 8; |
| 12244 | std::string detailed_error = ""; |
| 12245 | |
| 12246 | EXPECT_TRUE(QuicFramerPeer::ProcessAndValidateIetfConnectionIdLength( |
| 12247 | &reader, framer_.version(), Perspective::IS_CLIENT, |
| 12248 | should_update_expected_server_connection_id_length, |
| 12249 | &expected_server_connection_id_length, &destination_connection_id_length, |
| 12250 | &source_connection_id_length, &detailed_error)); |
| 12251 | EXPECT_EQ(8, expected_server_connection_id_length); |
| 12252 | EXPECT_EQ(0, destination_connection_id_length); |
| 12253 | EXPECT_EQ(8, source_connection_id_length); |
| 12254 | EXPECT_EQ("", detailed_error); |
| 12255 | |
| 12256 | QuicDataReader reader2(&connection_id_lengths, 1); |
| 12257 | should_update_expected_server_connection_id_length = true; |
| 12258 | expected_server_connection_id_length = 33; |
| 12259 | EXPECT_TRUE(QuicFramerPeer::ProcessAndValidateIetfConnectionIdLength( |
| 12260 | &reader2, framer_.version(), Perspective::IS_CLIENT, |
| 12261 | should_update_expected_server_connection_id_length, |
| 12262 | &expected_server_connection_id_length, &destination_connection_id_length, |
| 12263 | &source_connection_id_length, &detailed_error)); |
| 12264 | EXPECT_EQ(8, expected_server_connection_id_length); |
| 12265 | EXPECT_EQ(0, destination_connection_id_length); |
| 12266 | EXPECT_EQ(8, source_connection_id_length); |
| 12267 | EXPECT_EQ("", detailed_error); |
| 12268 | } |
| 12269 | |
| 12270 | TEST_P(QuicFramerTest, ProcessAndValidateIetfConnectionIdLengthServer) { |
| 12271 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 12272 | // This test requires an IETF long header. |
| 12273 | return; |
| 12274 | } |
| 12275 | char connection_id_lengths = 0x50; |
| 12276 | QuicDataReader reader(&connection_id_lengths, 1); |
| 12277 | |
| 12278 | bool should_update_expected_server_connection_id_length = false; |
| 12279 | uint8_t expected_server_connection_id_length = 8; |
| 12280 | uint8_t destination_connection_id_length = 8; |
| 12281 | uint8_t source_connection_id_length = 0; |
| 12282 | std::string detailed_error = ""; |
| 12283 | |
| 12284 | EXPECT_TRUE(QuicFramerPeer::ProcessAndValidateIetfConnectionIdLength( |
| 12285 | &reader, framer_.version(), Perspective::IS_SERVER, |
| 12286 | should_update_expected_server_connection_id_length, |
| 12287 | &expected_server_connection_id_length, &destination_connection_id_length, |
| 12288 | &source_connection_id_length, &detailed_error)); |
| 12289 | EXPECT_EQ(8, expected_server_connection_id_length); |
| 12290 | EXPECT_EQ(8, destination_connection_id_length); |
| 12291 | EXPECT_EQ(0, source_connection_id_length); |
| 12292 | EXPECT_EQ("", detailed_error); |
| 12293 | |
| 12294 | QuicDataReader reader2(&connection_id_lengths, 1); |
| 12295 | should_update_expected_server_connection_id_length = true; |
| 12296 | expected_server_connection_id_length = 33; |
| 12297 | EXPECT_TRUE(QuicFramerPeer::ProcessAndValidateIetfConnectionIdLength( |
| 12298 | &reader2, framer_.version(), Perspective::IS_SERVER, |
| 12299 | should_update_expected_server_connection_id_length, |
| 12300 | &expected_server_connection_id_length, &destination_connection_id_length, |
| 12301 | &source_connection_id_length, &detailed_error)); |
| 12302 | EXPECT_EQ(8, expected_server_connection_id_length); |
| 12303 | EXPECT_EQ(8, destination_connection_id_length); |
| 12304 | EXPECT_EQ(0, source_connection_id_length); |
| 12305 | EXPECT_EQ("", detailed_error); |
| 12306 | } |
| 12307 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12308 | } // namespace |
| 12309 | } // namespace test |
| 12310 | } // namespace quic |