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

Side by Side Diff: net/quic/test_tools/crypto_test_utils.cc

Issue 1904213002: QUIC: support diversified keys with version 33. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hkdf
Patch Set: Rebase Created 4 years, 8 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
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.h ('k') | net/quic/test_tools/quic_config_peer.cc » ('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 "net/quic/test_tools/crypto_test_utils.h" 5 #include "net/quic/test_tools/crypto_test_utils.h"
6 6
7 #include <openssl/bn.h> 7 #include <openssl/bn.h>
8 #include <openssl/ec.h> 8 #include <openssl/ec.h>
9 #include <openssl/ecdsa.h> 9 #include <openssl/ecdsa.h>
10 #include <openssl/evp.h> 10 #include <openssl/evp.h>
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 const FakeServerOptions& fake_options) { 367 const FakeServerOptions& fake_options) {
368 QuicCryptoServerConfig::ConfigOptions options; 368 QuicCryptoServerConfig::ConfigOptions options;
369 options.channel_id_enabled = true; 369 options.channel_id_enabled = true;
370 options.token_binding_enabled = fake_options.token_binding_enabled; 370 options.token_binding_enabled = fake_options.token_binding_enabled;
371 std::unique_ptr<CryptoHandshakeMessage> scfg( 371 std::unique_ptr<CryptoHandshakeMessage> scfg(
372 crypto_config->AddDefaultConfig(rand, clock, options)); 372 crypto_config->AddDefaultConfig(rand, clock, options));
373 } 373 }
374 374
375 // static 375 // static
376 void CryptoTestUtils::CommunicateHandshakeMessages( 376 void CryptoTestUtils::CommunicateHandshakeMessages(
377 PacketSavingConnection* a_conn, 377 PacketSavingConnection* client_conn,
378 QuicCryptoStream* a, 378 QuicCryptoStream* client,
379 PacketSavingConnection* b_conn, 379 PacketSavingConnection* server_conn,
380 QuicCryptoStream* b) { 380 QuicCryptoStream* server) {
381 CommunicateHandshakeMessagesAndRunCallbacks(a_conn, a, b_conn, b, nullptr); 381 CommunicateHandshakeMessagesAndRunCallbacks(client_conn, client, server_conn,
382 server, nullptr);
382 } 383 }
383 384
384 // static 385 // static
385 void CryptoTestUtils::CommunicateHandshakeMessagesAndRunCallbacks( 386 void CryptoTestUtils::CommunicateHandshakeMessagesAndRunCallbacks(
386 PacketSavingConnection* a_conn, 387 PacketSavingConnection* client_conn,
387 QuicCryptoStream* a, 388 QuicCryptoStream* client,
388 PacketSavingConnection* b_conn, 389 PacketSavingConnection* server_conn,
389 QuicCryptoStream* b, 390 QuicCryptoStream* server,
390 CallbackSource* callback_source) { 391 CallbackSource* callback_source) {
391 size_t a_i = 0, b_i = 0; 392 size_t client_i = 0, server_i = 0;
392 while (!a->handshake_confirmed()) { 393 while (!client->handshake_confirmed()) {
393 ASSERT_GT(a_conn->encrypted_packets_.size(), a_i); 394 ASSERT_GT(client_conn->encrypted_packets_.size(), client_i);
394 VLOG(1) << "Processing " << a_conn->encrypted_packets_.size() - a_i 395 VLOG(1) << "Processing "
395 << " packets a->b"; 396 << client_conn->encrypted_packets_.size() - client_i
396 MovePackets(a_conn, &a_i, b, b_conn); 397 << " packets client->server";
398 MovePackets(client_conn, &client_i, server, server_conn,
399 Perspective::IS_SERVER);
397 if (callback_source) { 400 if (callback_source) {
398 callback_source->RunPendingCallbacks(); 401 callback_source->RunPendingCallbacks();
399 } 402 }
400 403
401 ASSERT_GT(b_conn->encrypted_packets_.size(), b_i); 404 ASSERT_GT(server_conn->encrypted_packets_.size(), server_i);
402 VLOG(1) << "Processing " << b_conn->encrypted_packets_.size() - b_i 405 VLOG(1) << "Processing "
403 << " packets b->a"; 406 << server_conn->encrypted_packets_.size() - server_i
404 MovePackets(b_conn, &b_i, a, a_conn); 407 << " packets server->client";
408 MovePackets(server_conn, &server_i, client, client_conn,
409 Perspective::IS_CLIENT);
405 if (callback_source) { 410 if (callback_source) {
406 callback_source->RunPendingCallbacks(); 411 callback_source->RunPendingCallbacks();
407 } 412 }
408 } 413 }
409 } 414 }
410 415
411 // static 416 // static
412 pair<size_t, size_t> CryptoTestUtils::AdvanceHandshake( 417 pair<size_t, size_t> CryptoTestUtils::AdvanceHandshake(
413 PacketSavingConnection* a_conn, 418 PacketSavingConnection* client_conn,
414 QuicCryptoStream* a, 419 QuicCryptoStream* client,
415 size_t a_i, 420 size_t client_i,
416 PacketSavingConnection* b_conn, 421 PacketSavingConnection* server_conn,
417 QuicCryptoStream* b, 422 QuicCryptoStream* server,
418 size_t b_i) { 423 size_t server_i) {
419 VLOG(1) << "Processing " << a_conn->encrypted_packets_.size() - a_i 424 VLOG(1) << "Processing " << client_conn->encrypted_packets_.size() - client_i
420 << " packets a->b"; 425 << " packets client->server";
421 MovePackets(a_conn, &a_i, b, b_conn); 426 MovePackets(client_conn, &client_i, server, server_conn,
427 Perspective::IS_SERVER);
422 428
423 VLOG(1) << "Processing " << b_conn->encrypted_packets_.size() - b_i 429 VLOG(1) << "Processing " << server_conn->encrypted_packets_.size() - server_i
424 << " packets b->a"; 430 << " packets server->client";
425 if (b_conn->encrypted_packets_.size() - b_i == 2) { 431 if (server_conn->encrypted_packets_.size() - server_i == 2) {
426 VLOG(1) << "here"; 432 VLOG(1) << "here";
427 } 433 }
428 MovePackets(b_conn, &b_i, a, a_conn); 434 MovePackets(server_conn, &server_i, client, client_conn,
435 Perspective::IS_CLIENT);
429 436
430 return std::make_pair(a_i, b_i); 437 return std::make_pair(client_i, server_i);
431 } 438 }
432 439
433 // static 440 // static
434 string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message, 441 string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message,
435 QuicTag tag) { 442 QuicTag tag) {
436 QuicTagValueMap::const_iterator it = message.tag_value_map().find(tag); 443 QuicTagValueMap::const_iterator it = message.tag_value_map().find(tag);
437 if (it == message.tag_value_map().end()) { 444 if (it == message.tag_value_map().end()) {
438 return string(); 445 return string();
439 } 446 }
440 return it->second; 447 return it->second;
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 760
754 // static 761 // static
755 ChannelIDSource* CryptoTestUtils::ChannelIDSourceForTesting() { 762 ChannelIDSource* CryptoTestUtils::ChannelIDSourceForTesting() {
756 return new TestChannelIDSource(); 763 return new TestChannelIDSource();
757 } 764 }
758 765
759 // static 766 // static
760 void CryptoTestUtils::MovePackets(PacketSavingConnection* source_conn, 767 void CryptoTestUtils::MovePackets(PacketSavingConnection* source_conn,
761 size_t* inout_packet_index, 768 size_t* inout_packet_index,
762 QuicCryptoStream* dest_stream, 769 QuicCryptoStream* dest_stream,
763 PacketSavingConnection* dest_conn) { 770 PacketSavingConnection* dest_conn,
764 SimpleQuicFramer framer(source_conn->supported_versions()); 771 Perspective dest_perspective) {
772 SimpleQuicFramer framer(source_conn->supported_versions(), dest_perspective);
765 CryptoFramer crypto_framer; 773 CryptoFramer crypto_framer;
766 CryptoFramerVisitor crypto_visitor; 774 CryptoFramerVisitor crypto_visitor;
767 775
768 // In order to properly test the code we need to perform encryption and 776 // In order to properly test the code we need to perform encryption and
769 // decryption so that the crypters latch when expected. The crypters are in 777 // decryption so that the crypters latch when expected. The crypters are in
770 // |dest_conn|, but we don't want to try and use them there. Instead we swap 778 // |dest_conn|, but we don't want to try and use them there. Instead we swap
771 // them into |framer|, perform the decryption with them, and then swap ther 779 // them into |framer|, perform the decryption with them, and then swap ther
772 // back. 780 // back.
773 QuicConnectionPeer::SwapCrypters(dest_conn, framer.framer()); 781 QuicConnectionPeer::SwapCrypters(dest_conn, framer.framer());
774 782
(...skipping 19 matching lines...) Expand all
794 802
795 ASSERT_EQ(0u, crypto_framer.InputBytesRemaining()); 803 ASSERT_EQ(0u, crypto_framer.InputBytesRemaining());
796 804
797 for (const CryptoHandshakeMessage& message : crypto_visitor.messages()) { 805 for (const CryptoHandshakeMessage& message : crypto_visitor.messages()) {
798 dest_stream->OnHandshakeMessage(message); 806 dest_stream->OnHandshakeMessage(message);
799 } 807 }
800 } 808 }
801 809
802 } // namespace test 810 } // namespace test
803 } // namespace net 811 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.h ('k') | net/quic/test_tools/quic_config_peer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698