Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bdd4a5b
Cover both allocation failures in TLS DH parameter copying
danielinux Nov 27, 2026
4139704
Exercise TLS ChaCha and Poly1305 key allocation failures
danielinux Nov 27, 2026
9e078d4
Verify TLS DH parameter ownership across copies and failures
danielinux Nov 27, 2026
223c5d6
Exercise Extended Master Secret key derivation decisions
danielinux Nov 27, 2026
62e486c
Exercise TLS suite and handshake key ownership guards
danielinux Nov 27, 2026
1b1fe73
Exercise TLS reads after deterministic transport errors
danielinux Nov 27, 2026
221e021
Cover TLS protocol classifiers and fatal alert errors
danielinux Nov 27, 2026
a80ed8a
Cover TLS signature constraints, hash copy and DTLS sequence limits
danielinux Nov 27, 2026
9fbcca5
Cover TLS hash output guards and retained transcript copies
danielinux Nov 27, 2026
05664da
Cover TLS signature scheme encoding and DTLS message lists
danielinux Nov 27, 2026
28f469a
Exercise TLS FFDHE helper argument and capacity checks
danielinux Nov 27, 2026
6ba7455
Cover TLS ECC signature digest length bounds
danielinux Nov 27, 2026
03e493b
Exercise cleanup ownership for X25519 and X448 keys
danielinux Nov 27, 2026
959fd91
Cover TLS hostname and wildcard policy decisions
danielinux Nov 27, 2026
6d15a9d
Exercise TLS suite credentials and context ownership checks
danielinux Nov 27, 2026
5e04774
Exercise TLS RSA signature algorithm dispatch
danielinux Nov 27, 2026
cd2d0bf
Verify TLS handshake transcript copying and error propagation
danielinux Nov 27, 2026
939329f
Sweep allocation failures during native TLS handshakes
danielinux Nov 27, 2026
b009dc5
Test native TLS transport retry and buffer retention
danielinux Nov 27, 2026
8b0fa2e
Cover native peer key decoding and minimum size policy
danielinux Nov 27, 2026
599e4ac
Cover TLS RSA signature selection and PSS parameter policy
danielinux Nov 27, 2026
d137eed
Cover TLS key exchange and transcript preconditions
danielinux Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions tests/api/test_ssl_cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -6874,6 +6874,90 @@ int test_wolfSSL_alloc_failure_sweep(void)
return EXPECT_RESULT();
}

#if defined(WOLFSSL_MCDC_ALLOC_SWEEP) && defined(USE_WOLFSSL_MEMORY) && \
defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_RSA) && \
!defined(NO_TLS) && !defined(WOLFSSL_NO_TLS12) && \
!defined(WOLFSSL_STATIC_MEMORY) && \
!defined(WOLFSSL_DEBUG_MEMORY) && !defined(HAVE_FIPS) && \
!defined(HAVE_SELFTEST)
static int fi_handshake_attempt(method_provider client, method_provider server,
int failAt)
{
struct test_memio_ctx io;
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
int ret;

XMEMSET(&io, 0, sizeof(io));
fi_failAt = -1;
ret = test_memio_setup(&io, &ctx_c, &ctx_s, &ssl_c, &ssl_s, client,
server);
fi_count = 0;
fi_failed = 0;
if (ret == 0) {
fi_failAt = failAt;
ret = test_memio_do_handshake(ssl_c, ssl_s, 12, NULL);
fi_failAt = -1;
}

wolfSSL_free(ssl_s);
wolfSSL_free(ssl_c);
wolfSSL_CTX_free(ctx_s);
wolfSSL_CTX_free(ctx_c);
return ret;
}

static int fi_run_handshake_sweep(method_provider client, method_provider server)
{
int total, i;
int injected = 0;

if (fi_handshake_attempt(client, server, -1) != 0)
return 1;
total = fi_count;
for (i = 0; i < total; i++) {
(void)fi_handshake_attempt(client, server, i);
if (fi_failed)
injected++;
}
if (injected == 0 || fi_handshake_attempt(client, server, -1) != 0)
return 1;
return 0;
}
#endif

int test_wolfSSL_handshake_alloc_failure_sweep(void)
{
EXPECT_DECLS;
#if defined(WOLFSSL_MCDC_ALLOC_SWEEP) && defined(USE_WOLFSSL_MEMORY) && \
defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_RSA) && \
!defined(NO_TLS) && !defined(WOLFSSL_NO_TLS12) && \
!defined(WOLFSSL_STATIC_MEMORY) && \
!defined(WOLFSSL_DEBUG_MEMORY) && !defined(HAVE_FIPS) && \
!defined(HAVE_SELFTEST)
wolfSSL_Malloc_cb previousMalloc = NULL;
wolfSSL_Free_cb previousFree = NULL;
wolfSSL_Realloc_cb previousRealloc = NULL;
int failed;

(void)wolfSSL_GetAllocators(&previousMalloc, &previousFree, &previousRealloc);
if (wolfSSL_SetAllocators(fi_malloc, fi_free, fi_realloc) != 0)
return EXPECT_RESULT();

failed = fi_run_handshake_sweep(wolfTLSv1_2_client_method,
wolfTLSv1_2_server_method);
#ifdef WOLFSSL_TLS13
failed |= fi_run_handshake_sweep(wolfTLSv1_3_client_method,
wolfTLSv1_3_server_method);
#endif

fi_failAt = -1;
(void)wolfSSL_SetAllocators(previousMalloc, previousFree, previousRealloc);
ExpectIntEQ(failed, 0);
#endif
return EXPECT_RESULT();
}

/* ---------------------------------------------------------------------------
* DTLS API argument guards, on a DTLS object.
*
Expand Down
2 changes: 2 additions & 0 deletions tests/api/test_ssl_cert.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ int test_wolfSSL_load_pathological_files(void);
int test_wolfSSL_load_from_fifo(void);
int test_wolfSSL_dtls_api_more_guards(void);
int test_wolfSSL_alloc_failure_sweep(void);
int test_wolfSSL_handshake_alloc_failure_sweep(void);

int test_wolfSSL_get_verify_mode(void);
int test_wolfSSL_CTX_get_verify_mode(void);
Expand Down Expand Up @@ -165,6 +166,7 @@ int test_wolfSSL_SESSION_get0_peer_full_chain(void);
TEST_DECL_GROUP("ssl_cert", test_wolfSSL_load_from_fifo), \
TEST_DECL_GROUP("ssl_cert", test_wolfSSL_dtls_api_more_guards), \
TEST_DECL_GROUP("ssl_cert", test_wolfSSL_alloc_failure_sweep), \
TEST_DECL_GROUP("ssl_cert", test_wolfSSL_handshake_alloc_failure_sweep), \
TEST_DECL_GROUP("ssl_cert", test_ssl_cert_decision_coverage)

#endif /* TESTS_API_SSL_CERT_H */
103 changes: 103 additions & 0 deletions tests/api/test_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,63 @@
#include <wolfssl/ssl.h>


#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
!defined(NO_TLS) && !defined(WOLFSSL_NO_TLS12)
static int test_tls_recv_transport_error(WOLFSSL* ssl, char* buf, int sz,
void* ctx)
{
(void)ssl;
(void)buf;
(void)sz;
return *(const int*)ctx;
}
#endif

int test_tls_read_transport_errors(void)
{
EXPECT_DECLS;
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
!defined(NO_TLS) && !defined(WOLFSSL_NO_TLS12)
static const struct {
int status;
int readResult;
int error;
} cases[] = {
{WOLFSSL_CBIO_ERR_GENERAL, WOLFSSL_FATAL_ERROR, SOCKET_ERROR_E},
{WOLFSSL_CBIO_ERR_CONN_RST, 0, SOCKET_PEER_CLOSED_E},
{WOLFSSL_CBIO_ERR_CONN_CLOSE, 0, SOCKET_PEER_CLOSED_E},
};
size_t i;

for (i = 0; i < XELEM_CNT(cases); i++) {
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
struct test_memio_ctx testCtx;
byte out;
int status = cases[i].status;

XMEMSET(&testCtx, 0, sizeof(testCtx));
ExpectIntEQ(test_memio_setup(&testCtx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);

if (EXPECT_SUCCESS()) {
wolfSSL_SSLSetIORecv(ssl_c, test_tls_recv_transport_error);
wolfSSL_SetIOReadCtx(ssl_c, &status);
ExpectIntEQ(wolfSSL_read(ssl_c, &out, sizeof(out)),
cases[i].readResult);
ExpectIntEQ(ssl_c->error, cases[i].error);
}

wolfSSL_free(ssl_c);
wolfSSL_free(ssl_s);
wolfSSL_CTX_free(ctx_c);
wolfSSL_CTX_free(ctx_s);
}
#endif
return EXPECT_RESULT();
}

int test_utils_memio_move_message(void)
{
EXPECT_DECLS;
Expand Down Expand Up @@ -7947,6 +8004,19 @@ static unsigned int test_dhe_psk_max_server_cb(WOLFSSL* ssl,

return MAX_PSK_KEY_LEN;
}
#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
static unsigned int test_dhe_psk_invalid_key_cb(WOLFSSL* ssl, const char* hint,
char* id, unsigned int id_max, unsigned char* key, unsigned int key_max)
{
const int* oversized = (const int*)wolfSSL_get_psk_callback_ctx(ssl);
(void)hint;
(void)id;
(void)id_max;
(void)key;
return oversized != NULL && *oversized ? key_max + 1 : 0;
}
#endif

#endif

/* A DHE-PSK exchange fills the pre-master secret buffer with a two byte
Expand All @@ -7973,6 +8043,9 @@ int test_dhe_psk_max_premaster(void)
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
struct test_memio_ctx test_ctx;
int groups[1] = { WOLFSSL_ECC_SECP256R1 };
#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
int oversized;
#endif

/* Both lengths, the largest secret the peer can pick and the longest key
* have to fit. */
Expand Down Expand Up @@ -8005,6 +8078,36 @@ int test_dhe_psk_max_premaster(void)
wolfSSL_free(ssl_s);
wolfSSL_CTX_free(ctx_c);
wolfSSL_CTX_free(ctx_s);

#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
for (oversized = 0; oversized <= 1 && EXPECT_SUCCESS(); oversized++) {
ctx_c = ctx_s = NULL;
ssl_c = ssl_s = NULL;
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, "DHE-PSK-AES128-GCM-SHA256"),
WOLFSSL_SUCCESS);
ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, "DHE-PSK-AES128-GCM-SHA256"),
WOLFSSL_SUCCESS);
ExpectIntEQ(wolfSSL_set_psk_callback_ctx(ssl_c, &oversized),
WOLFSSL_SUCCESS);
if (EXPECT_SUCCESS()) {
wolfSSL_set_psk_client_callback(ssl_c, test_dhe_psk_invalid_key_cb);
wolfSSL_set_psk_server_callback(ssl_s, test_dhe_psk_max_server_cb);
}
ExpectIntEQ(wolfSSL_SetTmpDH_file(ssl_s, TEST_DHE_PSK_MAX_DH_FILE,
WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
ExpectIntEQ(wolfSSL_set_groups(ssl_c, groups, 1), WOLFSSL_SUCCESS);
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), -1);
ExpectIntEQ(wolfSSL_get_error(ssl_c, WOLFSSL_FATAL_ERROR),
WC_NO_ERR_TRACE(PSK_KEY_ERROR));
wolfSSL_free(ssl_c);
wolfSSL_free(ssl_s);
wolfSSL_CTX_free(ctx_c);
wolfSSL_CTX_free(ctx_s);
}
#endif
#endif
return EXPECT_RESULT();
}
Expand Down
2 changes: 2 additions & 0 deletions tests/api/test_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ int test_tls_get_peer_tmp_key(void);
int test_tls_get_negotiated_group(void);
int test_tls_alert_info_cb(void);
int test_tls_shutdown_in_init(void);
int test_tls_read_transport_errors(void);
int test_tls_unknown_record_type_alert(void);
int test_tls12_curve_intersection(void);
int test_tls12_dhe_rsa_pss_sigalg(void);
Expand Down Expand Up @@ -152,6 +153,7 @@ int test_tls_unset_fd_no_stdin_io(void);
TEST_DECL_GROUP("tls", test_tls_get_peer_tmp_key), \
TEST_DECL_GROUP("tls", test_tls_get_negotiated_group), \
TEST_DECL_GROUP("tls", test_tls_alert_info_cb), \
TEST_DECL_GROUP("tls", test_tls_read_transport_errors), \
TEST_DECL_GROUP("tls", test_tls_shutdown_in_init), \
TEST_DECL_GROUP("tls", test_tls_unknown_record_type_alert), \
TEST_DECL_GROUP("tls", test_tls12_curve_intersection), \
Expand Down
Loading
Loading