#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <algorithm>
#include <limits>
#include <string>
#include <utility>
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <openssl/aead.h>
#include <openssl/base64.h>
#include <openssl/bytestring.h>
#include <openssl/bio.h>
#include <openssl/cipher.h>
#include <openssl/crypto.h>
#include <openssl/curve25519.h>
#include <openssl/err.h>
#include <openssl/hmac.h>
#include <openssl/hpke.h>
#include <openssl/pem.h>
#include <openssl/sha.h>
#include <openssl/ssl.h>
#include <openssl/rand.h>
#include <openssl/x509.h>
#include "internal.h"
#include "../crypto/internal.h"
#include "../crypto/test/file_util.h"
#include "../crypto/test/test_util.h"
#if defined(OPENSSL_WINDOWS)
OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <winsock2.h>
OPENSSL_MSVC_PRAGMA(warning(pop))
#else
#include <sys/time.h>
#endif
#if defined(OPENSSL_THREADS)
#include <thread>
#endif
ElementsAre;
Key;
BSSL_NAMESPACE_BEGIN
namespace {
#define TRACED_CALL(code) …
struct VersionParam { … };
static const size_t kTicketKeyLen = …;
static const VersionParam kAllVersions[] = …;
struct ExpectedCipher { … };
struct CipherTest { … };
struct CurveTest { … };
template <typename T>
class UnownedSSLExData { … };
static const CipherTest kCipherTests[] = …;
static const char *kBadRules[] = …;
static const char *kMustNotIncludeDeprecated[] = …;
static const char* kShouldIncludeCBCSHA256[] = …;
static const CurveTest kCurveTests[] = …;
static const char *kBadCurvesLists[] = …;
static std::string CipherListToString(SSL_CTX *ctx) { … }
static bool CipherListsEqual(SSL_CTX *ctx,
const std::vector<ExpectedCipher> &expected) { … }
TEST(GrowableArrayTest, Resize) { … }
TEST(GrowableArrayTest, MoveConstructor) { … }
TEST(GrowableArrayTest, GrowableArrayContainingGrowableArrays) { … }
TEST(ReconstructSeqnumTest, Increment) { … }
TEST(ReconstructSeqnumTest, Decrement) { … }
TEST(ReconstructSeqnumTest, Halfway) { … }
TEST(SSLTest, CipherRules) { … }
TEST(SSLTest, CurveRules) { … }
static const char kOpenSSLSession[] = …;
static const char kCustomSession[] = …;
static const char kBoringSSLSession[] = …;
static const char kBadSessionExtraField[] = …;
static const char kBadSessionVersion[] = …;
static const char kBadSessionTrailingData[] = …;
static bool DecodeBase64(std::vector<uint8_t> *out, const char *in) { … }
static bool DecodeLowerHex(std::vector<uint8_t> *out,
bssl::Span<const char> in) { … }
TEST(SSLTest, SessionEncoding) { … }
static void ExpectDefaultVersion(uint16_t min_version, uint16_t max_version,
const SSL_METHOD *(*method)(void)) { … }
TEST(SSLTest, DefaultVersion) { … }
TEST(SSLTest, CipherProperties) { … }
static bssl::UniquePtr<SSL_SESSION> CreateSessionWithTicket(uint16_t version,
size_t ticket_len) { … }
static bool GetClientHello(SSL *ssl, std::vector<uint8_t> *out) { … }
static size_t GetClientHelloLen(uint16_t max_version, uint16_t session_version,
size_t ticket_len) { … }
TEST(SSLTest, Padding) { … }
static bssl::UniquePtr<X509> CertFromPEM(const char *pem) { … }
static bssl::UniquePtr<EVP_PKEY> KeyFromPEM(const char *pem) { … }
static bssl::UniquePtr<CRYPTO_BUFFER> BufferFromPEM(const char *pem) { … }
static bssl::UniquePtr<X509> X509FromBuffer(
bssl::UniquePtr<CRYPTO_BUFFER> buffer) { … }
static bssl::UniquePtr<X509> GetTestCertificate() { … }
static bssl::UniquePtr<EVP_PKEY> GetTestKey() { … }
static bssl::UniquePtr<SSL_CTX> CreateContextWithTestCertificate(
const SSL_METHOD *method) { … }
static bssl::UniquePtr<CRYPTO_BUFFER> GetECDSATestCertificateBuffer() { … }
static bssl::UniquePtr<X509> GetECDSATestCertificate() { … }
static bssl::UniquePtr<EVP_PKEY> GetECDSATestKey() { … }
static bssl::UniquePtr<CRYPTO_BUFFER> GetChainTestCertificateBuffer() { … }
static bssl::UniquePtr<X509> GetChainTestCertificate() { … }
static bssl::UniquePtr<CRYPTO_BUFFER> GetChainTestIntermediateBuffer() { … }
static bssl::UniquePtr<X509> GetChainTestIntermediate() { … }
static bssl::UniquePtr<EVP_PKEY> GetChainTestKey() { … }
static bool CompleteHandshakes(SSL *client, SSL *server) { … }
static bool FlushNewSessionTickets(SSL *client, SSL *server) { … }
static bool CreateClientAndServer(bssl::UniquePtr<SSL> *out_client,
bssl::UniquePtr<SSL> *out_server,
SSL_CTX *client_ctx, SSL_CTX *server_ctx) { … }
struct ClientConfig { … };
static bool ConnectClientAndServer(bssl::UniquePtr<SSL> *out_client,
bssl::UniquePtr<SSL> *out_server,
SSL_CTX *client_ctx, SSL_CTX *server_ctx,
const ClientConfig &config = ClientConfig(),
bool shed_handshake_config = true) { … }
static bssl::UniquePtr<SSL_SESSION> g_last_session;
static int SaveLastSession(SSL *ssl, SSL_SESSION *session) { … }
static bssl::UniquePtr<SSL_SESSION> CreateClientSession(
SSL_CTX *client_ctx, SSL_CTX *server_ctx,
const ClientConfig &config = ClientConfig()) { … }
static void SetUpExpectedNewCodePoint(SSL_CTX *ctx) { … }
static void SetUpExpectedOldCodePoint(SSL_CTX *ctx) { … }
TEST(SSLTest, ClientCAList) { … }
TEST(SSLTest, AddClientCA) { … }
struct ECHConfigParams { … };
bool MakeECHConfig(std::vector<uint8_t> *out,
const ECHConfigParams ¶ms) { … }
static bssl::UniquePtr<SSL_ECH_KEYS> MakeTestECHKeys(uint8_t config_id = 1) { … }
static bool InstallECHConfigList(SSL *client, const SSL_ECH_KEYS *keys) { … }
TEST(SSLTest, MarshalECHConfig) { … }
TEST(SSLTest, ECHHasDuplicateConfigID) { … }
TEST(SSLTest, ECHKeyConsistency) { … }
TEST(SSLTest, ECHServerConfigsWithoutRetryConfigs) { … }
TEST(SSLTest, UnsupportedECHConfig) { … }
TEST(SSLTest, ECHClientRandomsMatch) { … }
static bool GetECHLength(SSL_CTX *ctx, size_t *out_client_hello_len,
size_t *out_ech_len, size_t max_name_len,
const char *name) { … }
TEST(SSLTest, ECHPadding) { … }
TEST(SSLTest, ECHPublicName) { … }
TEST(SSLTest, ECHBuiltinVerifier) { … }
#if defined(OPENSSL_THREADS)
TEST(SSLTest, ECHThreads) { … }
#endif
TEST(SSLTest, TLS13ExporterAvailability) { … }
static void AppendSession(SSL_SESSION *session, void *arg) { … }
static bool CacheEquals(SSL_CTX *ctx,
const std::vector<SSL_SESSION*> &expected) { … }
static bssl::UniquePtr<SSL_SESSION> CreateTestSession(uint32_t number) { … }
TEST(SSLTest, InternalSessionCache) { … }
static uint16_t EpochFromSequence(uint64_t seq) { … }
static const uint8_t kTestName[] = …;
class SSLVersionTest : public ::testing::TestWithParam<VersionParam> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(SSLVersionTest, SequenceNumber) { … }
TEST_P(SSLVersionTest, OneSidedShutdown) { … }
TEST_P(SSLVersionTest, WriteAfterShutdown) { … }
TEST_P(SSLVersionTest, WriteAfterReadSentFatalAlert) { … }
TEST_P(SSLVersionTest, WriteAfterHandshakeSentFatalAlert) { … }
TEST(SSLTest, WriteAfterWrongVersionOnEarlyData) { … }
TEST(SSLTest, SessionDuplication) { … }
static void ExpectFDs(const SSL *ssl, int rfd, int wfd) { … }
TEST(SSLTest, SetFD) { … }
TEST(SSLTest, SetBIO) { … }
static int VerifySucceed(X509_STORE_CTX *store_ctx, void *arg) { … }
TEST_P(SSLVersionTest, GetPeerCertificate) { … }
TEST_P(SSLVersionTest, NoPeerCertificate) { … }
TEST_P(SSLVersionTest, RetainOnlySHA256OfCerts) { … }
TEST(SSLTest, ClientHello) { … }
static void ExpectSessionReused(SSL_CTX *client_ctx, SSL_CTX *server_ctx,
SSL_SESSION *session, bool want_reused) { … }
static bssl::UniquePtr<SSL_SESSION> ExpectSessionRenewed(SSL_CTX *client_ctx,
SSL_CTX *server_ctx,
SSL_SESSION *session) { … }
static void ExpectTicketKeyChanged(SSL_CTX *ctx, uint8_t *inout_key,
bool changed) { … }
static int SwitchSessionIDContextSNI(SSL *ssl, int *out_alert, void *arg) { … }
TEST_P(SSLVersionTest, SessionIDContext) { … }
static timeval g_current_time;
static void CurrentTimeCallback(const SSL *ssl, timeval *out_clock) { … }
static void FrozenTimeCallback(const SSL *ssl, timeval *out_clock) { … }
static int RenewTicketCallback(SSL *ssl, uint8_t *key_name, uint8_t *iv,
EVP_CIPHER_CTX *ctx, HMAC_CTX *hmac_ctx,
int encrypt) { … }
static bool GetServerTicketTime(long *out, const SSL_SESSION *session) { … }
TEST_P(SSLVersionTest, SessionTimeout) { … }
TEST_P(SSLVersionTest, DefaultTicketKeyInitialization) { … }
TEST_P(SSLVersionTest, DefaultTicketKeyRotation) { … }
static int SwitchContext(SSL *ssl, int *out_alert, void *arg) { … }
TEST_P(SSLVersionTest, SNICallback) { … }
TEST(SSLTest, EarlyCallbackVersionSwitch) { … }
TEST(SSLTest, SetVersion) { … }
static const char *GetVersionName(uint16_t version) { … }
TEST_P(SSLVersionTest, Version) { … }
TEST_P(SSLVersionTest, ALPNCipherAvailable) { … }
TEST_P(SSLVersionTest, SSLClearSessionResumption) { … }
TEST_P(SSLVersionTest, SSLClearFailsWithShedding) { … }
static bool ChainsEqual(const STACK_OF(X509) *chain,
const std::vector<X509 *> &expected) { … }
static bool BuffersEqual(const STACK_OF(CRYPTO_BUFFER) *chain,
const std::vector<CRYPTO_BUFFER *> &expected) { … }
TEST_P(SSLVersionTest, AutoChain) { … }
static bool ExpectSingleError(int lib, int reason) { … }
TEST_P(SSLVersionTest, SSLWriteRetry) { … }
TEST_P(SSLVersionTest, RecordCallback) { … }
TEST_P(SSLVersionTest, GetServerName) { … }
TEST_P(SSLVersionTest, ClientSessionCacheMode) { … }
TEST_P(SSLVersionTest, SmallBuffer) { … }
TEST(SSLTest, AddChainCertHack) { … }
TEST(SSLTest, GetCertificate) { … }
TEST(SSLTest, SetChainAndKeyMismatch) { … }
TEST(SSLTest, CertThenKeyMismatch) { … }
TEST(SSLTest, KeyThenCertMismatch) { … }
TEST(SSLTest, OverrideCertAndKey) { … }
TEST(SSLTest, OverrideKeyMethodWithKey) { … }
TEST(SSLTest, OverrideChain) { … }
TEST(SSLTest, OverrideChainAndKey) { … }
TEST(SSLTest, OverrideCredentialChain) { … }
TEST(SSLTest, SetChainAndKeyCtx) { … }
TEST(SSLTest, SetChainAndKeySSL) { … }
TEST(SSLTest, BuffersFailWithoutCustomVerify) { … }
TEST(SSLTest, CustomVerify) { … }
TEST(SSLTest, ClientCABuffers) { … }
TEST(SSLTest, EmptyCipherList) { … }
enum ssl_test_ticket_aead_failure_mode { … };
struct ssl_test_ticket_aead_state { … };
static int ssl_test_ticket_aead_ex_index_dup(CRYPTO_EX_DATA *to,
const CRYPTO_EX_DATA *from,
void **from_d, int index,
long argl, void *argp) { … }
static void ssl_test_ticket_aead_ex_index_free(void *parent, void *ptr,
CRYPTO_EX_DATA *ad, int index,
long argl, void *argp) { … }
static CRYPTO_once_t g_ssl_test_ticket_aead_ex_index_once = …;
static int g_ssl_test_ticket_aead_ex_index;
static int ssl_test_ticket_aead_get_ex_index() { … }
static size_t ssl_test_ticket_aead_max_overhead(SSL *ssl) { … }
static int ssl_test_ticket_aead_seal(SSL *ssl, uint8_t *out, size_t *out_len,
size_t max_out_len, const uint8_t *in,
size_t in_len) { … }
static ssl_ticket_aead_result_t ssl_test_ticket_aead_open(
SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out_len,
const uint8_t *in, size_t in_len) { … }
static const SSL_TICKET_AEAD_METHOD kSSLTestTicketMethod = …;
static void ConnectClientAndServerWithTicketMethod(
bssl::UniquePtr<SSL> *out_client, bssl::UniquePtr<SSL> *out_server,
SSL_CTX *client_ctx, SSL_CTX *server_ctx, unsigned retry_count,
ssl_test_ticket_aead_failure_mode failure_mode, SSL_SESSION *session) { … }
TicketAEADMethodParam;
class TicketAEADMethodTest
: public ::testing::TestWithParam<TicketAEADMethodParam> { … };
TEST_P(TicketAEADMethodTest, Resume) { … }
std::string TicketAEADMethodParamToString(
const testing::TestParamInfo<TicketAEADMethodParam> ¶ms) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST(SSLTest, SelectNextProto) { … }
TEST(SSLTest, NoCiphersAvailable) { … }
TEST_P(SSLVersionTest, SessionVersion) { … }
TEST_P(SSLVersionTest, SSLPending) { … }
TEST(SSLTest, ShutdownIgnoresTickets) { … }
TEST(SSLTest, SignatureAlgorithmProperties) { … }
static int XORCompressFunc(SSL *ssl, CBB *out, const uint8_t *in,
size_t in_len) { … }
static int XORDecompressFunc(SSL *ssl, CRYPTO_BUFFER **out,
size_t uncompressed_len, const uint8_t *in,
size_t in_len) { … }
TEST(SSLTest, CertCompression) { … }
void MoveBIOs(SSL *dest, SSL *src) { … }
void VerifyHandoff(bool use_new_alps_codepoint) { … }
TEST(SSLTest, Handoff) { … }
TEST(SSLTest, HandoffDeclined) { … }
static std::string SigAlgsToString(Span<const uint16_t> sigalgs) { … }
void ExpectSigAlgsEqual(Span<const uint16_t> expected,
Span<const uint16_t> actual) { … }
TEST(SSLTest, SigAlgs) { … }
TEST(SSLTest, SigAlgsList) { … }
TEST(SSLTest, ApplyHandoffRemovesUnsupportedCiphers) { … }
TEST(SSLTest, ApplyHandoffRemovesUnsupportedCurves) { … }
TEST(SSLTest, ZeroSizedWiteFlushesHandshakeMessages) { … }
TEST_P(SSLVersionTest, VerifyBeforeCertRequest) { … }
TEST_P(SSLVersionTest, FakeIDsForTickets) { … }
#if defined(OPENSSL_THREADS)
TEST_P(SSLVersionTest, SessionCacheThreads) { … }
TEST_P(SSLVersionTest, SessionTicketThreads) { … }
TEST(SSLTest, GetCertificateThreads) { … }
TEST_P(SSLVersionTest, SessionPropertiesThreads) { … }
static void SetValueOnFree(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
int index, long argl, void *argp) { … }
TEST(SSLTest, ExDataThreads) { … }
#endif
constexpr size_t kNumQUICLevels = …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
const char *LevelToString(ssl_encryption_level_t level) { … }
class MockQUICTransport { … };
class MockQUICTransportPair { … };
class QUICMethodTest : public testing::Test { … };
UnownedSSLExData<MockQUICTransport> QUICMethodTest::ex_data_;
TEST_F(QUICMethodTest, Basic) { … }
TEST_F(QUICMethodTest, HelloRetryRequest) { … }
TEST_F(QUICMethodTest, NoLegacySessionId) { … }
TEST_F(QUICMethodTest, HalfRTTKeys) { … }
TEST_F(QUICMethodTest, ZeroRTTAccept) { … }
TEST_F(QUICMethodTest, ZeroRTTRejectMismatchedParameters) { … }
TEST_F(QUICMethodTest, NoZeroRTTTicketWithoutEarlyDataContext) { … }
TEST_F(QUICMethodTest, ZeroRTTReject) { … }
TEST_F(QUICMethodTest, NoZeroRTTKeysBeforeReverify) { … }
TEST_F(QUICMethodTest, Async) { … }
TEST_F(QUICMethodTest, Buffered) { … }
TEST_F(QUICMethodTest, ExcessProvidedData) { … }
TEST_F(QUICMethodTest, ProvideWrongLevel) { … }
TEST_F(QUICMethodTest, TooMuchData) { … }
TEST_F(QUICMethodTest, BadPostHandshake) { … }
static void ExpectReceivedTransportParamsEqual(const SSL *ssl,
Span<const uint8_t> expected) { … }
TEST_F(QUICMethodTest, SetTransportParameters) { … }
TEST_F(QUICMethodTest, SetTransportParamsInCallback) { … }
TEST_F(QUICMethodTest, ForbidCrossProtocolResumptionClient) { … }
TEST_F(QUICMethodTest, ForbidCrossProtocolResumptionServer) { … }
TEST_F(QUICMethodTest, ClientRejectsMissingTransportParams) { … }
TEST_F(QUICMethodTest, ServerRejectsMissingTransportParams) { … }
TEST_F(QUICMethodTest, QuicLegacyCodepointEnabled) { … }
TEST_F(QUICMethodTest, QuicLegacyCodepointDisabled) { … }
TEST_F(QUICMethodTest, QuicLegacyCodepointClientOnly) { … }
TEST_F(QUICMethodTest, QuicLegacyCodepointServerOnly) { … }
TEST_F(QUICMethodTest, QuicCodePointDefault) { … }
extern "C" {
int BORINGSSL_enum_c_type_test(void);
}
TEST(SSLTest, EnumTypes) { … }
TEST_P(SSLVersionTest, DoubleSSLError) { … }
TEST_P(SSLVersionTest, SameKeyResume) { … }
TEST_P(SSLVersionTest, DifferentKeyNoResume) { … }
TEST_P(SSLVersionTest, UnrelatedServerNoResume) { … }
Span<const uint8_t> SessionIDOf(const SSL* ssl) { … }
TEST_P(SSLVersionTest, TicketSessionIDsMatch) { … }
static void WriteHelloRequest(SSL *server) { … }
TEST(SSLTest, WriteWhileExplicitRenegotiate) { … }
TEST(SSLTest, ConnectionPropertiesDuringRenegotiate) { … }
TEST(SSLTest, CopyWithoutEarlyData) { … }
TEST(SSLTest, ProcessTLS13NewSessionTicket) { … }
TEST(SSLTest, BIO) { … }
TEST(SSLTest, ALPNConfig) { … }
class AlpsNewCodepointTest : public testing::Test { … };
TEST_F(AlpsNewCodepointTest, Enabled) { … }
TEST_F(AlpsNewCodepointTest, Disabled) { … }
TEST_F(AlpsNewCodepointTest, ClientOnly) { … }
TEST_F(AlpsNewCodepointTest, ServerOnly) { … }
TEST(SSLTest, KeyUsageWithUIDs) { … }
TEST(SSLTest, CanReleasePrivateKey) { … }
static bool GetExtensionOrder(SSL_CTX *client_ctx, std::vector<uint16_t> *out,
SSL_ECH_KEYS *ech_keys, bool decrypt_ech) { … }
TEST(SSLTest, PermuteExtensions) { … }
TEST(SSLTest, HostMatching) { … }
TEST(SSLTest, NumTickets) { … }
TEST(SSLTest, CertSubjectsToStack) { … }
TEST(SSLTest, EmptyClientCAList) { … }
TEST(SSLTest, EmptyWriteBlockedOnHandshakeData) { … }
TEST(SSLTest, ErrorSyscallAfterCloseNotify) { … }
TEST(SSLTest, QuietShutdown) { … }
TEST(SSLTest, InvalidSignatureAlgorithm) { … }
TEST(SSLTest, InvalidGroups) { … }
TEST(SSLTest, NameLists) { … }
TEST(SSLTest, MixContextAndConnection) { … }
TEST_P(SSLVersionTest, NoCertOrKey) { … }
TEST_P(SSLVersionTest, KeyLog) { … }
}
BSSL_NAMESPACE_END