#include "quiche/quic/test_tools/crypto_test_utils.h"
#include <algorithm>
#include <cstddef>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "quiche/quic/core/crypto/certificate_view.h"
#include "quiche/quic/core/crypto/crypto_handshake.h"
#include "quiche/quic/core/crypto/crypto_utils.h"
#include "quiche/quic/core/crypto/proof_source_x509.h"
#include "quiche/quic/core/crypto/quic_crypto_server_config.h"
#include "quiche/quic/core/crypto/quic_decrypter.h"
#include "quiche/quic/core/crypto/quic_encrypter.h"
#include "quiche/quic/core/crypto/quic_random.h"
#include "quiche/quic/core/proto/crypto_server_config_proto.h"
#include "quiche/quic/core/quic_clock.h"
#include "quiche/quic/core/quic_connection.h"
#include "quiche/quic/core/quic_crypto_client_stream.h"
#include "quiche/quic/core/quic_crypto_server_stream_base.h"
#include "quiche/quic/core/quic_crypto_stream.h"
#include "quiche/quic/core/quic_packets.h"
#include "quiche/quic/core/quic_server_id.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_hostname_utils.h"
#include "quiche/quic/platform/api/quic_logging.h"
#include "quiche/quic/platform/api/quic_socket_address.h"
#include "quiche/quic/platform/api/quic_test.h"
#include "quiche/quic/test_tools/quic_connection_peer.h"
#include "quiche/quic/test_tools/quic_framer_peer.h"
#include "quiche/quic/test_tools/quic_stream_peer.h"
#include "quiche/quic/test_tools/quic_test_utils.h"
#include "quiche/quic/test_tools/simple_quic_framer.h"
#include "quiche/quic/test_tools/test_certificates.h"
#include "quiche/common/platform/api/quiche_logging.h"
#include "quiche/common/quiche_callbacks.h"
#include "quiche/common/test_tools/quiche_test_utils.h"
namespace quic {
namespace test {
namespace crypto_test_utils {
namespace {
_;
class CryptoFramerVisitor : public CryptoFramerVisitorInterface { … };
bool HexChar(char c, uint8_t* value) { … }
void MovePackets(const QuicConnection& source_conn,
absl::Span<const QuicEncryptedPacket* const> packets,
QuicCryptoStream& dest_stream, QuicConnection& dest_conn,
Perspective dest_perspective, bool process_stream_data) { … }
}
FakeClientOptions::FakeClientOptions() { … }
FakeClientOptions::~FakeClientOptions() { … }
namespace {
class FullChloGenerator { … };
}
std::unique_ptr<QuicCryptoServerConfig> CryptoServerConfigForTesting() { … }
int HandshakeWithFakeServer(QuicConfig* server_quic_config,
QuicCryptoServerConfig* crypto_config,
MockQuicConnectionHelper* helper,
MockAlarmFactory* alarm_factory,
PacketSavingConnection* client_conn,
QuicCryptoClientStreamBase* client,
std::string alpn) { … }
int HandshakeWithFakeClient(MockQuicConnectionHelper* helper,
MockAlarmFactory* alarm_factory,
PacketSavingConnection* server_conn,
QuicCryptoServerStreamBase* server,
const QuicServerId& server_id,
const FakeClientOptions& options,
std::string alpn) { … }
void SetupCryptoServerConfigForTest(const QuicClock* clock, QuicRandom* rand,
QuicCryptoServerConfig* crypto_config) { … }
void SendHandshakeMessageToStream(QuicCryptoStream* stream,
const CryptoHandshakeMessage& message,
Perspective ) { … }
void CommunicateHandshakeMessages(PacketSavingConnection* client_conn,
QuicCryptoStream* client,
PacketSavingConnection* server_conn,
QuicCryptoStream* server) { … }
void CommunicateHandshakeMessages(QuicConnection& client_conn,
QuicCryptoStream& client,
QuicConnection& server_conn,
QuicCryptoStream& server,
PacketProvider& packets_from_client,
PacketProvider& packets_from_server) { … }
bool CommunicateHandshakeMessagesUntil(
PacketSavingConnection* client_conn, QuicCryptoStream* client,
quiche::UnretainedCallback<bool()> client_condition,
PacketSavingConnection* server_conn, QuicCryptoStream* server,
quiche::UnretainedCallback<bool()> server_condition,
bool process_stream_data) { … }
bool CommunicateHandshakeMessagesUntil(
QuicConnection& client_conn, QuicCryptoStream& client,
quiche::UnretainedCallback<bool()> client_condition,
QuicConnection& server_conn, QuicCryptoStream& server,
quiche::UnretainedCallback<bool()> server_condition,
bool process_stream_data, PacketProvider& packets_from_client,
PacketProvider& packets_from_server) { … }
std::pair<size_t, size_t> AdvanceHandshake(PacketSavingConnection* client_conn,
QuicCryptoStream* client,
size_t client_i,
PacketSavingConnection* server_conn,
QuicCryptoStream* server,
size_t server_i) { … }
void AdvanceHandshake(
absl::Span<const QuicEncryptedPacket* const> packets_from_client,
QuicConnection& client_conn, QuicCryptoStream& client,
absl::Span<const QuicEncryptedPacket* const> packets_from_server,
QuicConnection& server_conn, QuicCryptoStream& server) { … }
std::string GetValueForTag(const CryptoHandshakeMessage& message, QuicTag tag) { … }
uint64_t LeafCertHashForTesting() { … }
void FillInDummyReject(CryptoHandshakeMessage* rej) { … }
namespace {
#define RETURN_STRING_LITERAL(x) …
std::string EncryptionLevelString(EncryptionLevel level) { … }
void CompareCrypters(const QuicEncrypter* encrypter,
const QuicDecrypter* decrypter, std::string label) { … }
}
void CompareClientAndServerKeys(QuicCryptoClientStreamBase* client,
QuicCryptoServerStreamBase* server) { … }
QuicTag ParseTag(const char* tagstr) { … }
CryptoHandshakeMessage CreateCHLO(
std::vector<std::pair<std::string, std::string>> tags_and_values) { … }
CryptoHandshakeMessage CreateCHLO(
std::vector<std::pair<std::string, std::string>> tags_and_values,
int minimum_size_bytes) { … }
CryptoHandshakeMessage GenerateDefaultInchoateCHLO(
const QuicClock* clock, QuicTransportVersion version,
QuicCryptoServerConfig* crypto_config) { … }
std::string GenerateClientNonceHex(const QuicClock* clock,
QuicCryptoServerConfig* crypto_config) { … }
std::string GenerateClientPublicValuesHex() { … }
void GenerateFullCHLO(
const CryptoHandshakeMessage& inchoate_chlo,
QuicCryptoServerConfig* crypto_config, QuicSocketAddress server_addr,
QuicSocketAddress client_addr, QuicTransportVersion transport_version,
const QuicClock* clock,
quiche::QuicheReferenceCountedPointer<QuicSignedServerConfig> signed_config,
QuicCompressedCertsCache* compressed_certs_cache,
CryptoHandshakeMessage* out) { … }
namespace {
constexpr char kTestProofHostname[] = …;
class TestProofSource : public ProofSourceX509 { … };
class TestProofVerifier : public ProofVerifier { … };
}
std::unique_ptr<ProofSource> ProofSourceForTesting() { … }
std::unique_ptr<ProofVerifier> ProofVerifierForTesting() { … }
std::string CertificateHostnameForTesting() { … }
std::unique_ptr<ProofVerifyContext> ProofVerifyContextForTesting() { … }
}
}
}