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

Side by Side Diff: net/quic/crypto/crypto_framer_test.cc

Issue 14718011: Land Recent QUIC Changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/crypto/crypto_framer.cc ('k') | net/quic/crypto/crypto_protocol.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <map> 5 #include <map>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "net/quic/crypto/crypto_framer.h" 10 #include "net/quic/crypto/crypto_framer.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 message.set_tag(0xFFAA7733); 64 message.set_tag(0xFFAA7733);
65 message.SetStringPiece(0x12345678, "abcdef"); 65 message.SetStringPiece(0x12345678, "abcdef");
66 message.SetStringPiece(0x12345679, "ghijk"); 66 message.SetStringPiece(0x12345679, "ghijk");
67 message.SetStringPiece(0x1234567A, "lmnopqr"); 67 message.SetStringPiece(0x1234567A, "lmnopqr");
68 68
69 unsigned char packet[] = { 69 unsigned char packet[] = {
70 // tag 70 // tag
71 0x33, 0x77, 0xAA, 0xFF, 71 0x33, 0x77, 0xAA, 0xFF,
72 // num entries 72 // num entries
73 0x03, 0x00, 73 0x03, 0x00,
74 // padding
75 0x00, 0x00,
74 // tag 1 76 // tag 1
75 0x78, 0x56, 0x34, 0x12, 77 0x78, 0x56, 0x34, 0x12,
78 // end offset 1
79 0x06, 0x00, 0x00, 0x00,
76 // tag 2 80 // tag 2
77 0x79, 0x56, 0x34, 0x12, 81 0x79, 0x56, 0x34, 0x12,
82 // end offset 2
83 0x0b, 0x00, 0x00, 0x00,
78 // tag 3 84 // tag 3
79 0x7A, 0x56, 0x34, 0x12, 85 0x7A, 0x56, 0x34, 0x12,
80 // len 1 86 // end offset 3
81 0x06, 0x00, 87 0x12, 0x00, 0x00, 0x00,
82 // len 2
83 0x05, 0x00,
84 // len 3
85 0x07, 0x00,
86 // padding
87 0x00, 0x00,
88 // value 1 88 // value 1
89 'a', 'b', 'c', 'd', 89 'a', 'b', 'c', 'd',
90 'e', 'f', 90 'e', 'f',
91 // value 2 91 // value 2
92 'g', 'h', 'i', 'j', 92 'g', 'h', 'i', 'j',
93 'k', 93 'k',
94 // value 3 94 // value 3
95 'l', 'm', 'n', 'o', 95 'l', 'm', 'n', 'o',
96 'p', 'q', 'r', 96 'p', 'q', 'r',
97 }; 97 };
(...skipping 10 matching lines...) Expand all
108 CryptoHandshakeMessage message; 108 CryptoHandshakeMessage message;
109 message.set_tag(0xFFAA7733); 109 message.set_tag(0xFFAA7733);
110 message.SetStringPiece(0x12345678, "abcdef"); 110 message.SetStringPiece(0x12345678, "abcdef");
111 message.SetStringPiece(0x12345679, "ghijk"); 111 message.SetStringPiece(0x12345679, "ghijk");
112 112
113 unsigned char packet[] = { 113 unsigned char packet[] = {
114 // tag 114 // tag
115 0x33, 0x77, 0xAA, 0xFF, 115 0x33, 0x77, 0xAA, 0xFF,
116 // num entries 116 // num entries
117 0x02, 0x00, 117 0x02, 0x00,
118 // padding
119 0x00, 0x00,
118 // tag 1 120 // tag 1
119 0x78, 0x56, 0x34, 0x12, 121 0x78, 0x56, 0x34, 0x12,
122 // end offset 1
123 0x06, 0x00, 0x00, 0x00,
120 // tag 2 124 // tag 2
121 0x79, 0x56, 0x34, 0x12, 125 0x79, 0x56, 0x34, 0x12,
122 // len 1 126 // end offset 2
123 0x06, 0x00, 127 0x0b, 0x00, 0x00, 0x00,
124 // len 2
125 0x05, 0x00,
126 // value 1 128 // value 1
127 'a', 'b', 'c', 'd', 129 'a', 'b', 'c', 'd',
128 'e', 'f', 130 'e', 'f',
129 // value 2 131 // value 2
130 'g', 'h', 'i', 'j', 132 'g', 'h', 'i', 'j',
131 'k', 133 'k',
132 }; 134 };
133 135
134 CryptoFramer framer; 136 CryptoFramer framer;
135 scoped_ptr<QuicData> data(framer.ConstructHandshakeMessage(message)); 137 scoped_ptr<QuicData> data(framer.ConstructHandshakeMessage(message));
136 ASSERT_TRUE(data.get() != NULL); 138 ASSERT_TRUE(data.get() != NULL);
137 139
138 test::CompareCharArraysWithHexError("constructed packet", data->data(), 140 test::CompareCharArraysWithHexError("constructed packet", data->data(),
139 data->length(), AsChars(packet), 141 data->length(), AsChars(packet),
140 arraysize(packet)); 142 arraysize(packet));
141 } 143 }
142 144
143 TEST(CryptoFramerTest, ConstructHandshakeMessageZeroLength) { 145 TEST(CryptoFramerTest, ConstructHandshakeMessageZeroLength) {
144 CryptoHandshakeMessage message; 146 CryptoHandshakeMessage message;
145 message.set_tag(0xFFAA7733); 147 message.set_tag(0xFFAA7733);
146 message.SetStringPiece(0x12345678, ""); 148 message.SetStringPiece(0x12345678, "");
147 149
148 unsigned char packet[] = { 150 unsigned char packet[] = {
149 // tag 151 // tag
150 0x33, 0x77, 0xAA, 0xFF, 152 0x33, 0x77, 0xAA, 0xFF,
151 // num entries 153 // num entries
152 0x01, 0x00, 154 0x01, 0x00,
155 // padding
156 0x00, 0x00,
153 // tag 1 157 // tag 1
154 0x78, 0x56, 0x34, 0x12, 158 0x78, 0x56, 0x34, 0x12,
155 // len 1 159 // end offset 1
156 0x00, 0x00, 160 0x00, 0x00, 0x00, 0x00,
157 // padding
158 0x00, 0x00,
159 }; 161 };
160 162
161 CryptoFramer framer; 163 CryptoFramer framer;
162 scoped_ptr<QuicData> data(framer.ConstructHandshakeMessage(message)); 164 scoped_ptr<QuicData> data(framer.ConstructHandshakeMessage(message));
163 ASSERT_TRUE(data.get() != NULL); 165 ASSERT_TRUE(data.get() != NULL);
164 166
165 test::CompareCharArraysWithHexError("constructed packet", data->data(), 167 test::CompareCharArraysWithHexError("constructed packet", data->data(),
166 data->length(), AsChars(packet), 168 data->length(), AsChars(packet),
167 arraysize(packet)); 169 arraysize(packet));
168 } 170 }
(...skipping 13 matching lines...) Expand all
182 TEST(CryptoFramerTest, ProcessInput) { 184 TEST(CryptoFramerTest, ProcessInput) {
183 test::TestCryptoVisitor visitor; 185 test::TestCryptoVisitor visitor;
184 CryptoFramer framer; 186 CryptoFramer framer;
185 framer.set_visitor(&visitor); 187 framer.set_visitor(&visitor);
186 188
187 unsigned char input[] = { 189 unsigned char input[] = {
188 // tag 190 // tag
189 0x33, 0x77, 0xAA, 0xFF, 191 0x33, 0x77, 0xAA, 0xFF,
190 // num entries 192 // num entries
191 0x02, 0x00, 193 0x02, 0x00,
194 // padding
195 0x00, 0x00,
192 // tag 1 196 // tag 1
193 0x78, 0x56, 0x34, 0x12, 197 0x78, 0x56, 0x34, 0x12,
198 // end offset 1
199 0x06, 0x00, 0x00, 0x00,
194 // tag 2 200 // tag 2
195 0x79, 0x56, 0x34, 0x12, 201 0x79, 0x56, 0x34, 0x12,
196 // len 1 202 // end offset 2
197 0x06, 0x00, 203 0x0b, 0x00, 0x00, 0x00,
198 // len 2
199 0x05, 0x00,
200 // value 1 204 // value 1
201 'a', 'b', 'c', 'd', 205 'a', 'b', 'c', 'd',
202 'e', 'f', 206 'e', 'f',
203 // value 2 207 // value 2
204 'g', 'h', 'i', 'j', 208 'g', 'h', 'i', 'j',
205 'k', 209 'k',
206 }; 210 };
207 211
208 EXPECT_TRUE( 212 EXPECT_TRUE(
209 framer.ProcessInput(StringPiece(AsChars(input), arraysize(input)))); 213 framer.ProcessInput(StringPiece(AsChars(input), arraysize(input))));
210 EXPECT_EQ(0u, framer.InputBytesRemaining()); 214 EXPECT_EQ(0u, framer.InputBytesRemaining());
211 ASSERT_EQ(1u, visitor.messages_.size()); 215 ASSERT_EQ(1u, visitor.messages_.size());
212 const CryptoHandshakeMessage& message = visitor.messages_[0]; 216 const CryptoHandshakeMessage& message = visitor.messages_[0];
213 EXPECT_EQ(0xFFAA7733, message.tag()); 217 EXPECT_EQ(0xFFAA7733, message.tag());
214 EXPECT_EQ(2u, message.tag_value_map().size()); 218 EXPECT_EQ(2u, message.tag_value_map().size());
215 EXPECT_EQ("abcdef", CryptoTestUtils::GetValueForTag(message, 0x12345678)); 219 EXPECT_EQ("abcdef", CryptoTestUtils::GetValueForTag(message, 0x12345678));
216 EXPECT_EQ("ghijk", CryptoTestUtils::GetValueForTag(message, 0x12345679)); 220 EXPECT_EQ("ghijk", CryptoTestUtils::GetValueForTag(message, 0x12345679));
217 } 221 }
218 222
219 TEST(CryptoFramerTest, ProcessInputWithThreeKeys) { 223 TEST(CryptoFramerTest, ProcessInputWithThreeKeys) {
220 test::TestCryptoVisitor visitor; 224 test::TestCryptoVisitor visitor;
221 CryptoFramer framer; 225 CryptoFramer framer;
222 framer.set_visitor(&visitor); 226 framer.set_visitor(&visitor);
223 227
224 unsigned char input[] = { 228 unsigned char input[] = {
225 // tag 229 // tag
226 0x33, 0x77, 0xAA, 0xFF, 230 0x33, 0x77, 0xAA, 0xFF,
227 // num entries 231 // num entries
228 0x03, 0x00, 232 0x03, 0x00,
233 // padding
234 0x00, 0x00,
229 // tag 1 235 // tag 1
230 0x78, 0x56, 0x34, 0x12, 236 0x78, 0x56, 0x34, 0x12,
237 // end offset 1
238 0x06, 0x00, 0x00, 0x00,
231 // tag 2 239 // tag 2
232 0x79, 0x56, 0x34, 0x12, 240 0x79, 0x56, 0x34, 0x12,
241 // end offset 2
242 0x0b, 0x00, 0x00, 0x00,
233 // tag 3 243 // tag 3
234 0x7A, 0x56, 0x34, 0x12, 244 0x7A, 0x56, 0x34, 0x12,
235 // len 1 245 // end offset 3
236 0x06, 0x00, 246 0x12, 0x00, 0x00, 0x00,
237 // len 2
238 0x05, 0x00,
239 // len 3
240 0x07, 0x00,
241 // padding
242 0x00, 0x00,
243 // value 1 247 // value 1
244 'a', 'b', 'c', 'd', 248 'a', 'b', 'c', 'd',
245 'e', 'f', 249 'e', 'f',
246 // value 2 250 // value 2
247 'g', 'h', 'i', 'j', 251 'g', 'h', 'i', 'j',
248 'k', 252 'k',
249 // value 3 253 // value 3
250 'l', 'm', 'n', 'o', 254 'l', 'm', 'n', 'o',
251 'p', 'q', 'r', 255 'p', 'q', 'r',
252 }; 256 };
(...skipping 13 matching lines...) Expand all
266 TEST(CryptoFramerTest, ProcessInputIncrementally) { 270 TEST(CryptoFramerTest, ProcessInputIncrementally) {
267 test::TestCryptoVisitor visitor; 271 test::TestCryptoVisitor visitor;
268 CryptoFramer framer; 272 CryptoFramer framer;
269 framer.set_visitor(&visitor); 273 framer.set_visitor(&visitor);
270 274
271 unsigned char input[] = { 275 unsigned char input[] = {
272 // tag 276 // tag
273 0x33, 0x77, 0xAA, 0xFF, 277 0x33, 0x77, 0xAA, 0xFF,
274 // num entries 278 // num entries
275 0x02, 0x00, 279 0x02, 0x00,
280 // padding
281 0x00, 0x00,
276 // tag 1 282 // tag 1
277 0x78, 0x56, 0x34, 0x12, 283 0x78, 0x56, 0x34, 0x12,
284 // end offset 1
285 0x06, 0x00, 0x00, 0x00,
278 // tag 2 286 // tag 2
279 0x79, 0x56, 0x34, 0x12, 287 0x79, 0x56, 0x34, 0x12,
280 // len 1 288 // end offset 2
281 0x06, 0x00, 289 0x0b, 0x00, 0x00, 0x00,
282 // len 2
283 0x05, 0x00,
284 // value 1 290 // value 1
285 'a', 'b', 'c', 'd', 291 'a', 'b', 'c', 'd',
286 'e', 'f', 292 'e', 'f',
287 // value 2 293 // value 2
288 'g', 'h', 'i', 'j', 294 'g', 'h', 'i', 'j',
289 'k', 295 'k',
290 }; 296 };
291 297
292 for (size_t i = 0; i < arraysize(input); i++) { 298 for (size_t i = 0; i < arraysize(input); i++) {
293 EXPECT_TRUE(framer.ProcessInput(StringPiece(AsChars(input) + i, 1))); 299 EXPECT_TRUE(framer.ProcessInput(StringPiece(AsChars(input) + i, 1)));
(...skipping 10 matching lines...) Expand all
304 TEST(CryptoFramerTest, ProcessInputTagsOutOfOrder) { 310 TEST(CryptoFramerTest, ProcessInputTagsOutOfOrder) {
305 test::TestCryptoVisitor visitor; 311 test::TestCryptoVisitor visitor;
306 CryptoFramer framer; 312 CryptoFramer framer;
307 framer.set_visitor(&visitor); 313 framer.set_visitor(&visitor);
308 314
309 unsigned char input[] = { 315 unsigned char input[] = {
310 // tag 316 // tag
311 0x33, 0x77, 0xAA, 0xFF, 317 0x33, 0x77, 0xAA, 0xFF,
312 // num entries 318 // num entries
313 0x02, 0x00, 319 0x02, 0x00,
320 // padding
321 0x00, 0x00,
314 // tag 1 322 // tag 1
315 0x78, 0x56, 0x34, 0x13, 323 0x78, 0x56, 0x34, 0x13,
324 // end offset 1
325 0x01, 0x00, 0x00, 0x00,
316 // tag 2 326 // tag 2
317 0x79, 0x56, 0x34, 0x12, 327 0x79, 0x56, 0x34, 0x12,
328 // end offset 2
329 0x02, 0x00, 0x00, 0x00,
318 }; 330 };
319 331
320 EXPECT_FALSE( 332 EXPECT_FALSE(
321 framer.ProcessInput(StringPiece(AsChars(input), arraysize(input)))); 333 framer.ProcessInput(StringPiece(AsChars(input), arraysize(input))));
322 EXPECT_EQ(QUIC_CRYPTO_TAGS_OUT_OF_ORDER, framer.error()); 334 EXPECT_EQ(QUIC_CRYPTO_TAGS_OUT_OF_ORDER, framer.error());
323 } 335 }
324 336
325 TEST(CryptoFramerTest, ProcessInputTooManyEntries) { 337 TEST(CryptoFramerTest, ProcessEndOffsetsOutOfOrder) {
326 test::TestCryptoVisitor visitor; 338 test::TestCryptoVisitor visitor;
327 CryptoFramer framer; 339 CryptoFramer framer;
328 framer.set_visitor(&visitor); 340 framer.set_visitor(&visitor);
329 341
330 unsigned char input[] = { 342 unsigned char input[] = {
331 // tag 343 // tag
332 0x33, 0x77, 0xAA, 0xFF, 344 0x33, 0x77, 0xAA, 0xFF,
333 // num entries 345 // num entries
334 0xA0, 0x00, 346 0x02, 0x00,
347 // padding
348 0x00, 0x00,
349 // tag 1
350 0x79, 0x56, 0x34, 0x12,
351 // end offset 1
352 0x01, 0x00, 0x00, 0x00,
353 // tag 2
354 0x78, 0x56, 0x34, 0x13,
355 // end offset 2
356 0x00, 0x00, 0x00, 0x00,
335 }; 357 };
336 358
337 EXPECT_FALSE( 359 EXPECT_FALSE(framer.ProcessInput(StringPiece(AsChars(input),
338 framer.ProcessInput(StringPiece(AsChars(input), arraysize(input)))); 360 arraysize(input))));
339 EXPECT_EQ(QUIC_CRYPTO_TOO_MANY_ENTRIES, framer.error()); 361 EXPECT_EQ(QUIC_CRYPTO_TAGS_OUT_OF_ORDER, framer.error());
340 } 362 }
341 363
342 TEST(CryptoFramerTest, ProcessInputZeroLength) { 364 TEST(CryptoFramerTest, ProcessInputTooManyEntries) {
343 test::TestCryptoVisitor visitor; 365 test::TestCryptoVisitor visitor;
344 CryptoFramer framer; 366 CryptoFramer framer;
345 framer.set_visitor(&visitor); 367 framer.set_visitor(&visitor);
346 368
347 unsigned char input[] = { 369 unsigned char input[] = {
348 // tag 370 // tag
349 0x33, 0x77, 0xAA, 0xFF, 371 0x33, 0x77, 0xAA, 0xFF,
350 // num entries 372 // num entries
351 0x02, 0x00, 373 0xA0, 0x00,
352 // tag 1 374 // padding
353 0x78, 0x56, 0x34, 0x12,
354 // tag 2
355 0x79, 0x56, 0x34, 0x12,
356 // len 1
357 0x00, 0x00, 375 0x00, 0x00,
358 // len 2
359 0x05, 0x00,
360 }; 376 };
361 377
362 EXPECT_TRUE( 378 EXPECT_FALSE(framer.ProcessInput(StringPiece(AsChars(input),
363 framer.ProcessInput(StringPiece(AsChars(input), arraysize(input)))); 379 arraysize(input))));
380 EXPECT_EQ(QUIC_CRYPTO_TOO_MANY_ENTRIES, framer.error());
364 } 381 }
365 382
366 TEST(CryptoFramerTest, ProcessInputInvalidLengthPadding) { 383 TEST(CryptoFramerTest, ProcessInputZeroLength) {
367 test::TestCryptoVisitor visitor; 384 test::TestCryptoVisitor visitor;
368 CryptoFramer framer; 385 CryptoFramer framer;
369 framer.set_visitor(&visitor); 386 framer.set_visitor(&visitor);
370 387
371 unsigned char input[] = { 388 unsigned char input[] = {
372 // tag 389 // tag
373 0x33, 0x77, 0xAA, 0xFF, 390 0x33, 0x77, 0xAA, 0xFF,
374 // num entries 391 // num entries
375 0x01, 0x00, 392 0x02, 0x00,
393 // padding
394 0x00, 0x00,
376 // tag 1 395 // tag 1
377 0x78, 0x56, 0x34, 0x12, 396 0x78, 0x56, 0x34, 0x12,
378 // len 1 397 // end offset 1
379 0x05, 0x00, 398 0x00, 0x00, 0x00, 0x00,
380 // padding 399 // tag 2
381 0x05, 0x00, 400 0x79, 0x56, 0x34, 0x12,
401 // end offset 2
402 0x05, 0x00, 0x00, 0x00,
382 }; 403 };
383 404
384 EXPECT_FALSE( 405 EXPECT_TRUE(framer.ProcessInput(StringPiece(AsChars(input),
385 framer.ProcessInput(StringPiece(AsChars(input), arraysize(input)))); 406 arraysize(input))));
386 EXPECT_EQ(QUIC_CRYPTO_INVALID_VALUE_LENGTH, framer.error());
387 } 407 }
388 408
389 } // namespace test 409 } // namespace test
390 410
391 } // namespace net 411 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/crypto_framer.cc ('k') | net/quic/crypto/crypto_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698