#include "quiche/quic/test_tools/quic_test_utils.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "absl/base/macros.h"
#include "absl/strings/string_view.h"
#include "openssl/chacha.h"
#include "openssl/sha.h"
#include "quiche/quic/core/crypto/crypto_framer.h"
#include "quiche/quic/core/crypto/crypto_handshake.h"
#include "quiche/quic/core/crypto/crypto_utils.h"
#include "quiche/quic/core/crypto/null_decrypter.h"
#include "quiche/quic/core/crypto/null_encrypter.h"
#include "quiche/quic/core/crypto/quic_decrypter.h"
#include "quiche/quic/core/crypto/quic_encrypter.h"
#include "quiche/quic/core/http/quic_spdy_client_session.h"
#include "quiche/quic/core/quic_config.h"
#include "quiche/quic/core/quic_data_writer.h"
#include "quiche/quic/core/quic_framer.h"
#include "quiche/quic/core/quic_packet_creator.h"
#include "quiche/quic/core/quic_packets.h"
#include "quiche/quic/core/quic_time.h"
#include "quiche/quic/core/quic_types.h"
#include "quiche/quic/core/quic_utils.h"
#include "quiche/quic/core/quic_versions.h"
#include "quiche/quic/platform/api/quic_flags.h"
#include "quiche/quic/platform/api/quic_logging.h"
#include "quiche/quic/test_tools/crypto_test_utils.h"
#include "quiche/quic/test_tools/quic_config_peer.h"
#include "quiche/quic/test_tools/quic_connection_peer.h"
#include "quiche/common/quiche_buffer_allocator.h"
#include "quiche/common/quiche_endian.h"
#include "quiche/common/simple_buffer_allocator.h"
#include "quiche/spdy/core/spdy_frame_builder.h"
_;
Invoke;
Return;
namespace quic {
namespace test {
QuicConnectionId TestConnectionId() { … }
QuicConnectionId TestConnectionId(uint64_t connection_number) { … }
QuicConnectionId TestConnectionIdNineBytesLong(uint64_t connection_number) { … }
uint64_t TestConnectionIdToUInt64(QuicConnectionId connection_id) { … }
std::vector<uint8_t> CreateStatelessResetTokenForTest() { … }
std::string TestHostname() { … }
QuicServerId TestServerId() { … }
QuicAckFrame InitAckFrame(const std::vector<QuicAckBlock>& ack_blocks) { … }
QuicAckFrame InitAckFrame(uint64_t largest_acked) { … }
QuicAckFrame InitAckFrame(QuicPacketNumber largest_acked) { … }
QuicAckFrame MakeAckFrameWithAckBlocks(size_t num_ack_blocks,
uint64_t least_unacked) { … }
QuicAckFrame MakeAckFrameWithGaps(uint64_t gap_size, size_t max_num_gaps,
uint64_t largest_acked) { … }
EncryptionLevel HeaderToEncryptionLevel(const QuicPacketHeader& header) { … }
std::unique_ptr<QuicPacket> BuildUnsizedDataPacket(
QuicFramer* framer, const QuicPacketHeader& header,
const QuicFrames& frames) { … }
std::unique_ptr<QuicPacket> BuildUnsizedDataPacket(
QuicFramer* framer, const QuicPacketHeader& header,
const QuicFrames& frames, size_t packet_size) { … }
std::string Sha1Hash(absl::string_view data) { … }
bool ClearControlFrame(const QuicFrame& frame) { … }
bool ClearControlFrameWithTransmissionType(const QuicFrame& frame,
TransmissionType ) { … }
uint64_t SimpleRandom::RandUint64() { … }
void SimpleRandom::RandBytes(void* data, size_t len) { … }
void SimpleRandom::InsecureRandBytes(void* data, size_t len) { … }
uint64_t SimpleRandom::InsecureRandUint64() { … }
void SimpleRandom::FillBuffer() { … }
void SimpleRandom::set_seed(uint64_t seed) { … }
MockFramerVisitor::MockFramerVisitor() { … }
MockFramerVisitor::~MockFramerVisitor() { … }
bool NoOpFramerVisitor::OnProtocolVersionMismatch(
ParsedQuicVersion ) { … }
bool NoOpFramerVisitor::OnUnauthenticatedPublicHeader(
const QuicPacketHeader& ) { … }
bool NoOpFramerVisitor::OnUnauthenticatedHeader(
const QuicPacketHeader& ) { … }
bool NoOpFramerVisitor::OnPacketHeader(const QuicPacketHeader& ) { … }
void NoOpFramerVisitor::OnCoalescedPacket(
const QuicEncryptedPacket& ) { … }
void NoOpFramerVisitor::OnUndecryptablePacket(
const QuicEncryptedPacket& , EncryptionLevel ,
bool ) { … }
bool NoOpFramerVisitor::OnStreamFrame(const QuicStreamFrame& ) { … }
bool NoOpFramerVisitor::OnCryptoFrame(const QuicCryptoFrame& ) { … }
bool NoOpFramerVisitor::OnAckFrameStart(QuicPacketNumber ,
QuicTime::Delta ) { … }
bool NoOpFramerVisitor::OnAckRange(QuicPacketNumber ,
QuicPacketNumber ) { … }
bool NoOpFramerVisitor::OnAckTimestamp(QuicPacketNumber ,
QuicTime ) { … }
bool NoOpFramerVisitor::OnAckFrameEnd(
QuicPacketNumber ,
const std::optional<QuicEcnCounts>& ) { … }
bool NoOpFramerVisitor::OnStopWaitingFrame(
const QuicStopWaitingFrame& ) { … }
bool NoOpFramerVisitor::OnPaddingFrame(const QuicPaddingFrame& ) { … }
bool NoOpFramerVisitor::OnPingFrame(const QuicPingFrame& ) { … }
bool NoOpFramerVisitor::OnRstStreamFrame(const QuicRstStreamFrame& ) { … }
bool NoOpFramerVisitor::OnConnectionCloseFrame(
const QuicConnectionCloseFrame& ) { … }
bool NoOpFramerVisitor::OnNewConnectionIdFrame(
const QuicNewConnectionIdFrame& ) { … }
bool NoOpFramerVisitor::OnRetireConnectionIdFrame(
const QuicRetireConnectionIdFrame& ) { … }
bool NoOpFramerVisitor::OnNewTokenFrame(const QuicNewTokenFrame& ) { … }
bool NoOpFramerVisitor::OnStopSendingFrame(
const QuicStopSendingFrame& ) { … }
bool NoOpFramerVisitor::OnPathChallengeFrame(
const QuicPathChallengeFrame& ) { … }
bool NoOpFramerVisitor::OnPathResponseFrame(
const QuicPathResponseFrame& ) { … }
bool NoOpFramerVisitor::OnGoAwayFrame(const QuicGoAwayFrame& ) { … }
bool NoOpFramerVisitor::OnMaxStreamsFrame(
const QuicMaxStreamsFrame& ) { … }
bool NoOpFramerVisitor::OnStreamsBlockedFrame(
const QuicStreamsBlockedFrame& ) { … }
bool NoOpFramerVisitor::OnWindowUpdateFrame(
const QuicWindowUpdateFrame& ) { … }
bool NoOpFramerVisitor::OnBlockedFrame(const QuicBlockedFrame& ) { … }
bool NoOpFramerVisitor::OnMessageFrame(const QuicMessageFrame& ) { … }
bool NoOpFramerVisitor::OnHandshakeDoneFrame(
const QuicHandshakeDoneFrame& ) { … }
bool NoOpFramerVisitor::OnAckFrequencyFrame(
const QuicAckFrequencyFrame& ) { … }
bool NoOpFramerVisitor::OnResetStreamAtFrame(
const QuicResetStreamAtFrame& ) { … }
bool NoOpFramerVisitor::IsValidStatelessResetToken(
const StatelessResetToken& ) const { … }
MockQuicConnectionVisitor::MockQuicConnectionVisitor() { … }
MockQuicConnectionVisitor::~MockQuicConnectionVisitor() { … }
MockQuicConnectionHelper::MockQuicConnectionHelper() { … }
MockQuicConnectionHelper::~MockQuicConnectionHelper() { … }
const MockClock* MockQuicConnectionHelper::GetClock() const { … }
MockClock* MockQuicConnectionHelper::GetClock() { … }
QuicRandom* MockQuicConnectionHelper::GetRandomGenerator() { … }
QuicAlarm* MockAlarmFactory::CreateAlarm(QuicAlarm::Delegate* delegate) { … }
QuicArenaScopedPtr<QuicAlarm> MockAlarmFactory::CreateAlarm(
QuicArenaScopedPtr<QuicAlarm::Delegate> delegate,
QuicConnectionArena* arena) { … }
quiche::QuicheBufferAllocator*
MockQuicConnectionHelper::GetStreamSendBufferAllocator() { … }
void MockQuicConnectionHelper::AdvanceTime(QuicTime::Delta delta) { … }
MockQuicConnection::MockQuicConnection(QuicConnectionHelperInterface* helper,
QuicAlarmFactory* alarm_factory,
Perspective perspective)
: … { … }
MockQuicConnection::MockQuicConnection(QuicSocketAddress address,
QuicConnectionHelperInterface* helper,
QuicAlarmFactory* alarm_factory,
Perspective perspective)
: … { … }
MockQuicConnection::MockQuicConnection(QuicConnectionId connection_id,
QuicConnectionHelperInterface* helper,
QuicAlarmFactory* alarm_factory,
Perspective perspective)
: … { … }
MockQuicConnection::MockQuicConnection(
QuicConnectionHelperInterface* helper, QuicAlarmFactory* alarm_factory,
Perspective perspective, const ParsedQuicVersionVector& supported_versions)
: … { … }
MockQuicConnection::MockQuicConnection(
QuicConnectionId connection_id, QuicSocketAddress initial_peer_address,
QuicConnectionHelperInterface* helper, QuicAlarmFactory* alarm_factory,
Perspective perspective, const ParsedQuicVersionVector& supported_versions)
: … { … }
MockQuicConnection::~MockQuicConnection() { … }
void MockQuicConnection::AdvanceTime(QuicTime::Delta delta) { … }
bool MockQuicConnection::OnProtocolVersionMismatch(
ParsedQuicVersion ) { … }
PacketSavingConnection::PacketSavingConnection(MockQuicConnectionHelper* helper,
QuicAlarmFactory* alarm_factory,
Perspective perspective)
: … { … }
PacketSavingConnection::PacketSavingConnection(
MockQuicConnectionHelper* helper, QuicAlarmFactory* alarm_factory,
Perspective perspective, const ParsedQuicVersionVector& supported_versions)
: … { … }
PacketSavingConnection::~PacketSavingConnection() { … }
SerializedPacketFate PacketSavingConnection::GetSerializedPacketFate(
bool , EncryptionLevel ) { … }
void PacketSavingConnection::SendOrQueuePacket(SerializedPacket packet) { … }
std::vector<const QuicEncryptedPacket*> PacketSavingConnection::GetPackets()
const { … }
void PacketSavingConnection::ClearPackets() { … }
MockQuicSession::MockQuicSession(QuicConnection* connection)
: … { … }
MockQuicSession::MockQuicSession(QuicConnection* connection,
bool create_mock_crypto_stream)
: … { … }
MockQuicSession::~MockQuicSession() { … }
QuicCryptoStream* MockQuicSession::GetMutableCryptoStream() { … }
const QuicCryptoStream* MockQuicSession::GetCryptoStream() const { … }
void MockQuicSession::SetCryptoStream(QuicCryptoStream* crypto_stream) { … }
QuicConsumedData MockQuicSession::ConsumeData(
QuicStreamId id, size_t write_length, QuicStreamOffset offset,
StreamSendingState state, TransmissionType ,
std::optional<EncryptionLevel> ) { … }
MockQuicCryptoStream::MockQuicCryptoStream(QuicSession* session)
: … { … }
MockQuicCryptoStream::~MockQuicCryptoStream() { … }
ssl_early_data_reason_t MockQuicCryptoStream::EarlyDataReason() const { … }
bool MockQuicCryptoStream::one_rtt_keys_available() const { … }
const QuicCryptoNegotiatedParameters&
MockQuicCryptoStream::crypto_negotiated_params() const { … }
CryptoMessageParser* MockQuicCryptoStream::crypto_message_parser() { … }
MockQuicSpdySession::MockQuicSpdySession(QuicConnection* connection)
: … { … }
MockQuicSpdySession::MockQuicSpdySession(QuicConnection* connection,
bool create_mock_crypto_stream)
: … { … }
MockQuicSpdySession::~MockQuicSpdySession() { … }
QuicCryptoStream* MockQuicSpdySession::GetMutableCryptoStream() { … }
const QuicCryptoStream* MockQuicSpdySession::GetCryptoStream() const { … }
void MockQuicSpdySession::SetCryptoStream(QuicCryptoStream* crypto_stream) { … }
QuicConsumedData MockQuicSpdySession::ConsumeData(
QuicStreamId id, size_t write_length, QuicStreamOffset offset,
StreamSendingState state, TransmissionType ,
std::optional<EncryptionLevel> ) { … }
TestQuicSpdyServerSession::TestQuicSpdyServerSession(
QuicConnection* connection, const QuicConfig& config,
const ParsedQuicVersionVector& supported_versions,
const QuicCryptoServerConfig* crypto_config,
QuicCompressedCertsCache* compressed_certs_cache)
: … { … }
TestQuicSpdyServerSession::~TestQuicSpdyServerSession() { … }
std::unique_ptr<QuicCryptoServerStreamBase>
TestQuicSpdyServerSession::CreateQuicCryptoServerStream(
const QuicCryptoServerConfig* crypto_config,
QuicCompressedCertsCache* compressed_certs_cache) { … }
QuicCryptoServerStreamBase*
TestQuicSpdyServerSession::GetMutableCryptoStream() { … }
const QuicCryptoServerStreamBase* TestQuicSpdyServerSession::GetCryptoStream()
const { … }
TestQuicSpdyClientSession::TestQuicSpdyClientSession(
QuicConnection* connection, const QuicConfig& config,
const ParsedQuicVersionVector& supported_versions,
const QuicServerId& server_id, QuicCryptoClientConfig* crypto_config,
std::optional<QuicSSLConfig> ssl_config)
: … { … }
TestQuicSpdyClientSession::~TestQuicSpdyClientSession() { … }
QuicCryptoClientStream* TestQuicSpdyClientSession::GetMutableCryptoStream() { … }
const QuicCryptoClientStream* TestQuicSpdyClientSession::GetCryptoStream()
const { … }
void TestQuicSpdyClientSession::RealOnConfigNegotiated() { … }
MockPacketWriter::MockPacketWriter() { … }
MockPacketWriter::~MockPacketWriter() { … }
MockSendAlgorithm::MockSendAlgorithm() { … }
MockSendAlgorithm::~MockSendAlgorithm() { … }
MockLossAlgorithm::MockLossAlgorithm() { … }
MockLossAlgorithm::~MockLossAlgorithm() { … }
MockAckListener::MockAckListener() { … }
MockAckListener::~MockAckListener() { … }
MockNetworkChangeVisitor::MockNetworkChangeVisitor() { … }
MockNetworkChangeVisitor::~MockNetworkChangeVisitor() { … }
QuicIpAddress TestPeerIPAddress() { … }
ParsedQuicVersion QuicVersionMax() { … }
ParsedQuicVersion QuicVersionMin() { … }
void DisableQuicVersionsWithTls() { … }
QuicEncryptedPacket* ConstructEncryptedPacket(
QuicConnectionId destination_connection_id,
QuicConnectionId source_connection_id, bool version_flag, bool reset_flag,
uint64_t packet_number, const std::string& data) { … }
QuicEncryptedPacket* ConstructEncryptedPacket(
QuicConnectionId destination_connection_id,
QuicConnectionId source_connection_id, bool version_flag, bool reset_flag,
uint64_t packet_number, const std::string& data,
QuicConnectionIdIncluded destination_connection_id_included,
QuicConnectionIdIncluded source_connection_id_included,
QuicPacketNumberLength packet_number_length) { … }
QuicEncryptedPacket* ConstructEncryptedPacket(
QuicConnectionId destination_connection_id,
QuicConnectionId source_connection_id, bool version_flag, bool reset_flag,
uint64_t packet_number, const std::string& data,
QuicConnectionIdIncluded destination_connection_id_included,
QuicConnectionIdIncluded source_connection_id_included,
QuicPacketNumberLength packet_number_length,
ParsedQuicVersionVector* versions) { … }
QuicEncryptedPacket* ConstructEncryptedPacket(
QuicConnectionId destination_connection_id,
QuicConnectionId source_connection_id, bool version_flag, bool reset_flag,
uint64_t packet_number, const std::string& data, bool full_padding,
QuicConnectionIdIncluded destination_connection_id_included,
QuicConnectionIdIncluded source_connection_id_included,
QuicPacketNumberLength packet_number_length,
ParsedQuicVersionVector* versions) { … }
QuicEncryptedPacket* ConstructEncryptedPacket(
QuicConnectionId destination_connection_id,
QuicConnectionId source_connection_id, bool version_flag, bool reset_flag,
uint64_t packet_number, const std::string& data, bool full_padding,
QuicConnectionIdIncluded destination_connection_id_included,
QuicConnectionIdIncluded source_connection_id_included,
QuicPacketNumberLength packet_number_length,
ParsedQuicVersionVector* versions, Perspective perspective) { … }
std::unique_ptr<QuicEncryptedPacket> GetUndecryptableEarlyPacket(
const ParsedQuicVersion& version,
const QuicConnectionId& server_connection_id) { … }
QuicReceivedPacket* ConstructReceivedPacket(
const QuicEncryptedPacket& encrypted_packet, QuicTime receipt_time) { … }
QuicReceivedPacket* ConstructReceivedPacket(
const QuicEncryptedPacket& encrypted_packet, QuicTime receipt_time,
QuicEcnCodepoint ecn) { … }
QuicEncryptedPacket* ConstructMisFramedEncryptedPacket(
QuicConnectionId destination_connection_id,
QuicConnectionId source_connection_id, bool version_flag, bool reset_flag,
uint64_t packet_number, const std::string& data,
QuicConnectionIdIncluded destination_connection_id_included,
QuicConnectionIdIncluded source_connection_id_included,
QuicPacketNumberLength packet_number_length, ParsedQuicVersion version,
Perspective perspective) { … }
QuicConfig DefaultQuicConfig() { … }
ParsedQuicVersionVector SupportedVersions(ParsedQuicVersion version) { … }
MockQuicConnectionDebugVisitor::MockQuicConnectionDebugVisitor() { … }
MockQuicConnectionDebugVisitor::~MockQuicConnectionDebugVisitor() { … }
MockReceivedPacketManager::MockReceivedPacketManager(QuicConnectionStats* stats)
: … { … }
MockReceivedPacketManager::~MockReceivedPacketManager() { … }
MockPacketCreatorDelegate::MockPacketCreatorDelegate() { … }
MockPacketCreatorDelegate::~MockPacketCreatorDelegate() { … }
MockSessionNotifier::MockSessionNotifier() { … }
MockSessionNotifier::~MockSessionNotifier() { … }
QuicCryptoClientStream::HandshakerInterface*
QuicCryptoClientStreamPeer::GetHandshaker(QuicCryptoClientStream* stream) { … }
void CreateClientSessionForTest(
QuicServerId server_id, QuicTime::Delta connection_start_time,
const ParsedQuicVersionVector& supported_versions,
MockQuicConnectionHelper* helper, QuicAlarmFactory* alarm_factory,
QuicCryptoClientConfig* crypto_client_config,
PacketSavingConnection** client_connection,
TestQuicSpdyClientSession** client_session) { … }
void CreateServerSessionForTest(
QuicServerId , QuicTime::Delta connection_start_time,
ParsedQuicVersionVector supported_versions,
MockQuicConnectionHelper* helper, QuicAlarmFactory* alarm_factory,
QuicCryptoServerConfig* server_crypto_config,
QuicCompressedCertsCache* compressed_certs_cache,
PacketSavingConnection** server_connection,
TestQuicSpdyServerSession** server_session) { … }
QuicStreamId GetNthClientInitiatedBidirectionalStreamId(
QuicTransportVersion version, int n) { … }
QuicStreamId GetNthServerInitiatedBidirectionalStreamId(
QuicTransportVersion version, int n) { … }
QuicStreamId GetNthServerInitiatedUnidirectionalStreamId(
QuicTransportVersion version, int n) { … }
QuicStreamId GetNthClientInitiatedUnidirectionalStreamId(
QuicTransportVersion version, int n) { … }
StreamType DetermineStreamType(QuicStreamId id, ParsedQuicVersion version,
Perspective perspective, bool is_incoming,
StreamType default_type) { … }
quiche::QuicheMemSlice MemSliceFromString(absl::string_view data) { … }
bool TaggingEncrypter::EncryptPacket(uint64_t ,
absl::string_view ,
absl::string_view plaintext, char* output,
size_t* output_length,
size_t max_output_length) { … }
bool TaggingDecrypter::DecryptPacket(uint64_t ,
absl::string_view ,
absl::string_view ciphertext, char* output,
size_t* output_length,
size_t ) { … }
bool TaggingDecrypter::CheckTag(absl::string_view ciphertext, uint8_t tag) { … }
TestPacketWriter::TestPacketWriter(ParsedQuicVersion version, MockClock* clock,
Perspective perspective)
: … { … }
TestPacketWriter::~TestPacketWriter() { … }
WriteResult TestPacketWriter::WritePacket(
const char* buffer, size_t buf_len, const QuicIpAddress& self_address,
const QuicSocketAddress& peer_address, PerPacketOptions* ,
const QuicPacketWriterParams& params) { … }
QuicPacketBuffer TestPacketWriter::GetNextWriteLocation(
const QuicIpAddress& ,
const QuicSocketAddress& ) { … }
WriteResult TestPacketWriter::Flush() { … }
char* TestPacketWriter::AllocPacketBuffer() { … }
void TestPacketWriter::FreePacketBuffer(const char* buffer) { … }
bool WriteServerVersionNegotiationProbeResponse(
char* packet_bytes, size_t* packet_length_out,
const char* source_connection_id_bytes,
uint8_t source_connection_id_length) { … }
bool ParseClientVersionNegotiationProbePacket(
const char* packet_bytes, size_t packet_length,
char* destination_connection_id_bytes,
uint8_t* destination_connection_id_length_out) { … }
}
}