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

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

Issue 2222393002: Make QuicDispatcher to queue packets for new connections while waiting for CHLOs. Flag protected by… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@129318081
Patch Set: add new files Created 4 years, 4 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
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>
11 #include <openssl/obj_mac.h> 11 #include <openssl/obj_mac.h>
12 #include <openssl/sha.h> 12 #include <openssl/sha.h>
13 13
14 #include <memory> 14 #include <memory>
15 15
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "crypto/openssl_util.h" 17 #include "crypto/openssl_util.h"
18 #include "crypto/scoped_openssl_types.h" 18 #include "crypto/scoped_openssl_types.h"
19 #include "crypto/secure_hash.h" 19 #include "crypto/secure_hash.h"
20 #include "net/quic/core/crypto/channel_id.h" 20 #include "net/quic/core/crypto/channel_id.h"
21 #include "net/quic/core/crypto/common_cert_set.h" 21 #include "net/quic/core/crypto/common_cert_set.h"
22 #include "net/quic/core/crypto/crypto_handshake.h" 22 #include "net/quic/core/crypto/crypto_handshake.h"
23 #include "net/quic/core/crypto/crypto_server_config_protobuf.h"
23 #include "net/quic/core/crypto/quic_crypto_server_config.h" 24 #include "net/quic/core/crypto/quic_crypto_server_config.h"
24 #include "net/quic/core/crypto/quic_decrypter.h" 25 #include "net/quic/core/crypto/quic_decrypter.h"
25 #include "net/quic/core/crypto/quic_encrypter.h" 26 #include "net/quic/core/crypto/quic_encrypter.h"
26 #include "net/quic/core/crypto/quic_random.h" 27 #include "net/quic/core/crypto/quic_random.h"
27 #include "net/quic/core/quic_clock.h" 28 #include "net/quic/core/quic_clock.h"
28 #include "net/quic/core/quic_crypto_client_stream.h" 29 #include "net/quic/core/quic_crypto_client_stream.h"
29 #include "net/quic/core/quic_crypto_server_stream.h" 30 #include "net/quic/core/quic_crypto_server_stream.h"
30 #include "net/quic/core/quic_crypto_stream.h" 31 #include "net/quic/core/quic_crypto_stream.h"
31 #include "net/quic/core/quic_server_id.h" 32 #include "net/quic/core/quic_server_id.h"
32 #include "net/quic/core/quic_utils.h" 33 #include "net/quic/core/quic_utils.h"
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 QuicConnectionPeer::SwapCrypters(dest_conn, framer.framer()); 893 QuicConnectionPeer::SwapCrypters(dest_conn, framer.framer());
893 894
894 ASSERT_EQ(0u, crypto_framer.InputBytesRemaining()); 895 ASSERT_EQ(0u, crypto_framer.InputBytesRemaining());
895 896
896 for (const CryptoHandshakeMessage& message : crypto_visitor.messages()) { 897 for (const CryptoHandshakeMessage& message : crypto_visitor.messages()) {
897 dest_stream->OnHandshakeMessage(message); 898 dest_stream->OnHandshakeMessage(message);
898 } 899 }
899 QuicConnectionPeer::SetCurrentPacket(dest_conn, StringPiece(nullptr, 0)); 900 QuicConnectionPeer::SetCurrentPacket(dest_conn, StringPiece(nullptr, 0));
900 } 901 }
901 902
903 CryptoHandshakeMessage CryptoTestUtils::GenerateDefaultInchoateCHLO(
904 const QuicClock* clock,
905 QuicVersion version,
906 QuicCryptoServerConfig* crypto_config) {
907 // clang-format off
908 return CryptoTestUtils::Message(
909 "CHLO",
910 "PDMD", "X509",
911 "AEAD", "AESG",
912 "KEXS", "C255",
913 "PUBS", CryptoTestUtils::GenerateClientPublicValuesHex().c_str(),
914 "NONC", CryptoTestUtils::GenerateClientNonceHex(clock,
915 crypto_config).c_str(),
916 "VER\0", QuicUtils::TagToString(
917 QuicVersionToQuicTag(version)).c_str(),
918 "$padding", static_cast<int>(kClientHelloMinimumSize),
919 nullptr);
920 // clang-format on
921 }
922
923 string CryptoTestUtils::GenerateClientNonceHex(
924 const QuicClock* clock,
925 QuicCryptoServerConfig* crypto_config) {
926 net::QuicCryptoServerConfig::ConfigOptions old_config_options;
927 net::QuicCryptoServerConfig::ConfigOptions new_config_options;
928 old_config_options.id = "old-config-id";
929 delete crypto_config->AddDefaultConfig(net::QuicRandom::GetInstance(), clock,
930 old_config_options);
931 std::unique_ptr<QuicServerConfigProtobuf> primary_config(
932 crypto_config->GenerateConfig(net::QuicRandom::GetInstance(), clock,
933 new_config_options));
934 primary_config->set_primary_time(clock->WallNow().ToUNIXSeconds());
935 std::unique_ptr<net::CryptoHandshakeMessage> msg(
936 crypto_config->AddConfig(primary_config.get(), clock->WallNow()));
937 StringPiece orbit;
938 CHECK(msg->GetStringPiece(net::kORBT, &orbit));
939 string nonce;
940 net::CryptoUtils::GenerateNonce(
941 clock->WallNow(), net::QuicRandom::GetInstance(),
942 StringPiece(reinterpret_cast<const char*>(orbit.data()),
943 sizeof(orbit.size())),
944 &nonce);
945 return ("#" + net::QuicUtils::HexEncode(nonce));
946 }
947
948 string CryptoTestUtils::GenerateClientPublicValuesHex() {
949 char public_value[32];
950 memset(public_value, 42, sizeof(public_value));
951 return ("#" + net::QuicUtils::HexEncode(public_value, sizeof(public_value)));
952 }
953
902 // static 954 // static
903 void CryptoTestUtils::GenerateFullCHLO( 955 void CryptoTestUtils::GenerateFullCHLO(
904 const CryptoHandshakeMessage& inchoate_chlo, 956 const CryptoHandshakeMessage& inchoate_chlo,
905 QuicCryptoServerConfig* crypto_config, 957 QuicCryptoServerConfig* crypto_config,
906 IPAddress server_ip, 958 IPAddress server_ip,
907 IPEndPoint client_addr, 959 IPEndPoint client_addr,
908 QuicVersion version, 960 QuicVersion version,
909 const QuicClock* clock, 961 const QuicClock* clock,
910 QuicCryptoProof* proof, 962 QuicCryptoProof* proof,
911 QuicCompressedCertsCache* compressed_certs_cache, 963 QuicCompressedCertsCache* compressed_certs_cache,
912 CryptoHandshakeMessage* out) { 964 CryptoHandshakeMessage* out) {
913 // Pass a inchoate CHLO. 965 // Pass a inchoate CHLO.
914 crypto_config->ValidateClientHello( 966 crypto_config->ValidateClientHello(
915 inchoate_chlo, client_addr.address(), server_ip, version, clock, proof, 967 inchoate_chlo, client_addr.address(), server_ip, version, clock, proof,
916 new FullChloGenerator(crypto_config, server_ip, client_addr, clock, proof, 968 new FullChloGenerator(crypto_config, server_ip, client_addr, clock, proof,
917 compressed_certs_cache, out)); 969 compressed_certs_cache, out));
918 } 970 }
919 971
920 } // namespace test 972 } // namespace test
921 } // namespace net 973 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.h ('k') | net/quic/test_tools/quic_buffered_packet_store_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698