#include <algorithm>
#include <cstdint>
#include <memory>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#include "absl/base/macros.h"
#include "absl/strings/escaping.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "openssl/sha.h"
#include "quiche/quic/core/crypto/cert_compressor.h"
#include "quiche/quic/core/crypto/crypto_handshake.h"
#include "quiche/quic/core/crypto/crypto_utils.h"
#include "quiche/quic/core/crypto/proof_source.h"
#include "quiche/quic/core/crypto/quic_crypto_server_config.h"
#include "quiche/quic/core/crypto/quic_random.h"
#include "quiche/quic/core/proto/crypto_server_config_proto.h"
#include "quiche/quic/core/quic_socket_address_coder.h"
#include "quiche/quic/core/quic_utils.h"
#include "quiche/quic/platform/api/quic_flags.h"
#include "quiche/quic/platform/api/quic_test.h"
#include "quiche/quic/test_tools/crypto_test_utils.h"
#include "quiche/quic/test_tools/failing_proof_source.h"
#include "quiche/quic/test_tools/mock_clock.h"
#include "quiche/quic/test_tools/mock_random.h"
#include "quiche/quic/test_tools/quic_crypto_server_config_peer.h"
#include "quiche/quic/test_tools/quic_test_utils.h"
#include "quiche/common/quiche_endian.h"
namespace quic {
namespace test {
namespace {
class DummyProofVerifierCallback : public ProofVerifierCallback { … };
const char kOldConfigId[] = …;
}
struct TestParams { … };
std::string PrintToString(const TestParams& p) { … }
std::vector<TestParams> GetTestParams() { … }
class CryptoServerTest : public QuicTestWithParam<TestParams> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(CryptoServerTest, BadSNI) { … }
TEST_P(CryptoServerTest, DefaultCert) { … }
TEST_P(CryptoServerTest, RejectTooLarge) { … }
TEST_P(CryptoServerTest, RejectNotTooLarge) { … }
TEST_P(CryptoServerTest, RejectTooLargeButValidSTK) { … }
TEST_P(CryptoServerTest, BadSourceAddressToken) { … }
TEST_P(CryptoServerTest, BadClientNonce) { … }
TEST_P(CryptoServerTest, NoClientNonce) { … }
TEST_P(CryptoServerTest, DowngradeAttack) { … }
TEST_P(CryptoServerTest, CorruptServerConfig) { … }
TEST_P(CryptoServerTest, CorruptSourceAddressToken) { … }
TEST_P(CryptoServerTest, CorruptSourceAddressTokenIsStillAccepted) { … }
TEST_P(CryptoServerTest, CorruptClientNonceAndSourceAddressToken) { … }
TEST_P(CryptoServerTest, CorruptMultipleTags) { … }
TEST_P(CryptoServerTest, NoServerNonce) { … }
TEST_P(CryptoServerTest, ProofForSuppliedServerConfig) { … }
TEST_P(CryptoServerTest, RejectInvalidXlct) { … }
TEST_P(CryptoServerTest, ValidXlct) { … }
TEST_P(CryptoServerTest, NonceInSHLO) { … }
TEST_P(CryptoServerTest, ProofSourceFailure) { … }
TEST_P(CryptoServerTest, TwoRttServerDropCachedCerts) { … }
class CryptoServerConfigGenerationTest : public QuicTest { … };
TEST_F(CryptoServerConfigGenerationTest, Determinism) { … }
TEST_F(CryptoServerConfigGenerationTest, SCIDVaries) { … }
TEST_F(CryptoServerConfigGenerationTest, SCIDIsHashOfServerConfig) { … }
#if 0
class CryptoServerTestNoConfig : public CryptoServerTest {
public:
void SetUp() override {
}
};
INSTANTIATE_TEST_SUITE_P(CryptoServerTestsNoConfig,
CryptoServerTestNoConfig,
::testing::ValuesIn(GetTestParams()),
::testing::PrintToStringParamName());
TEST_P(CryptoServerTestNoConfig, DontCrash) {
CryptoHandshakeMessage msg = crypto_test_utils::CreateCHLO(
{{"PDMD", "X509"}, {"VER\0", client_version_string_}},
kClientHelloMinimumSize);
ShouldFailMentioning("No config", msg);
const HandshakeFailureReason kRejectReasons[] = {
SERVER_CONFIG_INCHOATE_HELLO_FAILURE};
CheckRejectReasons(kRejectReasons, ABSL_ARRAYSIZE(kRejectReasons));
}
class CryptoServerTestOldVersion : public CryptoServerTest {
public:
void SetUp() override {
client_version_ = supported_versions_.back();
client_version_string_ = ParsedQuicVersionToString(client_version_);
CryptoServerTest::SetUp();
}
};
INSTANTIATE_TEST_SUITE_P(CryptoServerTestsOldVersion,
CryptoServerTestOldVersion,
::testing::ValuesIn(GetTestParams()),
::testing::PrintToStringParamName());
TEST_P(CryptoServerTestOldVersion, ServerIgnoresXlct) {
CryptoHandshakeMessage msg =
crypto_test_utils::CreateCHLO({{"PDMD", "X509"},
{"AEAD", "AESG"},
{"KEXS", "C255"},
{"SCID", scid_hex_},
{"#004b5453", srct_hex_},
{"PUBS", pub_hex_},
{"NONC", nonce_hex_},
{"VER\0", client_version_string_},
{"XLCT", "#0100000000000000"}},
kClientHelloMinimumSize);
config_.set_replay_protection(false);
ShouldSucceed(msg);
EXPECT_EQ(kSHLO, out_.tag());
}
TEST_P(CryptoServerTestOldVersion, XlctNotRequired) {
CryptoHandshakeMessage msg =
crypto_test_utils::CreateCHLO({{"PDMD", "X509"},
{"AEAD", "AESG"},
{"KEXS", "C255"},
{"SCID", scid_hex_},
{"#004b5453", srct_hex_},
{"PUBS", pub_hex_},
{"NONC", nonce_hex_},
{"VER\0", client_version_string_}},
kClientHelloMinimumSize);
config_.set_replay_protection(false);
ShouldSucceed(msg);
EXPECT_EQ(kSHLO, out_.tag());
}
#endif
}
}