Skip to content

Commit 06d81f7

Browse files
committed
Add a test case that negotiates tickets during another handshake
1 parent 7b29362 commit 06d81f7

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

tests/api.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5855,7 +5855,9 @@ static int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds,
58555855
}
58565856
while ((!handshake_complete) && (max_rounds > 0)) {
58575857
if (!hs_c) {
5858+
wolfSSL_SetLoggingPrefix("client");
58585859
ret = wolfSSL_connect(ctx->c_ssl);
5860+
wolfSSL_SetLoggingPrefix(NULL);
58595861
if (ret == WOLFSSL_SUCCESS) {
58605862
hs_c = 1;
58615863
}
@@ -5872,7 +5874,9 @@ static int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds,
58725874
}
58735875
}
58745876
if (!hs_s) {
5877+
wolfSSL_SetLoggingPrefix("server");
58755878
ret = wolfSSL_accept(ctx->s_ssl);
5879+
wolfSSL_SetLoggingPrefix(NULL);
58765880
if (ret == WOLFSSL_SUCCESS) {
58775881
hs_s = 1;
58785882
}
@@ -5921,15 +5925,19 @@ static int test_ssl_memio_read_write(test_ssl_memio_ctx* ctx)
59215925
msglen_s = ctx->s_msglen;
59225926
}
59235927

5928+
wolfSSL_SetLoggingPrefix("client");
59245929
ExpectIntEQ(wolfSSL_write(ctx->c_ssl, msg_c, msglen_c), msglen_c);
5930+
wolfSSL_SetLoggingPrefix("server");
59255931
ExpectIntGT(idx = wolfSSL_read(ctx->s_ssl, input, sizeof(input) - 1), 0);
59265932
if (idx >= 0) {
59275933
input[idx] = '\0';
59285934
}
59295935
ExpectIntGT(fprintf(stderr, "Client message: %s\n", input), 0);
59305936
ExpectIntEQ(wolfSSL_write(ctx->s_ssl, msg_s, msglen_s), msglen_s);
59315937
ctx->s_cb.return_code = EXPECT_RESULT();
5938+
wolfSSL_SetLoggingPrefix("client");
59325939
ExpectIntGT(idx = wolfSSL_read(ctx->c_ssl, input, sizeof(input) - 1), 0);
5940+
wolfSSL_SetLoggingPrefix(NULL);
59335941
if (idx >= 0) {
59345942
input[idx] = '\0';
59355943
}
@@ -64352,6 +64360,91 @@ static int test_session_ticket_no_id(void)
6435264360
}
6435364361
#endif
6435464362

64363+
static int test_session_ticket_hs_update(void)
64364+
{
64365+
EXPECT_DECLS;
64366+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
64367+
defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
64368+
struct test_memio_ctx test_ctx;
64369+
struct test_memio_ctx test_ctx2;
64370+
struct test_memio_ctx test_ctx3;
64371+
WOLFSSL_CTX *ctx_c = NULL;
64372+
WOLFSSL_CTX *ctx_s = NULL;
64373+
WOLFSSL *ssl_c = NULL;
64374+
WOLFSSL *ssl_c2 = NULL;
64375+
WOLFSSL *ssl_c3 = NULL;
64376+
WOLFSSL *ssl_s = NULL;
64377+
WOLFSSL *ssl_s2 = NULL;
64378+
WOLFSSL *ssl_s3 = NULL;
64379+
WOLFSSL_SESSION *sess = NULL;
64380+
byte read_data[1];
64381+
64382+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
64383+
XMEMSET(&test_ctx2, 0, sizeof(test_ctx2));
64384+
XMEMSET(&test_ctx3, 0, sizeof(test_ctx3));
64385+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
64386+
wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
64387+
64388+
/* Generate tickets */
64389+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
64390+
wolfSSL_SetLoggingPrefix("client");
64391+
/* Read the ticket msg */
64392+
ExpectIntEQ(wolfSSL_read(ssl_c, read_data, sizeof(read_data)),
64393+
WOLFSSL_FATAL_ERROR);
64394+
ExpectIntEQ(wolfSSL_get_error(ssl_c, WOLFSSL_FATAL_ERROR),
64395+
WOLFSSL_ERROR_WANT_READ);
64396+
wolfSSL_SetLoggingPrefix(NULL);
64397+
64398+
ExpectIntEQ(test_memio_setup(&test_ctx2, &ctx_c, &ctx_s, &ssl_c2, &ssl_s2,
64399+
wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
64400+
ExpectIntEQ(test_memio_setup(&test_ctx3, &ctx_c, &ctx_s, &ssl_c3, &ssl_s3,
64401+
wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
64402+
64403+
ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
64404+
ExpectIntEQ(wolfSSL_set_session(ssl_c2, sess), WOLFSSL_SUCCESS);
64405+
ExpectIntEQ(wolfSSL_set_session(ssl_c3, sess), WOLFSSL_SUCCESS);
64406+
64407+
wolfSSL_SetLoggingPrefix("client");
64408+
/* Exchange intial flights for the second connection */
64409+
ExpectIntEQ(wolfSSL_connect(ssl_c2), WOLFSSL_FATAL_ERROR);
64410+
ExpectIntEQ(wolfSSL_get_error(ssl_c2, WOLFSSL_FATAL_ERROR),
64411+
WOLFSSL_ERROR_WANT_READ);
64412+
wolfSSL_SetLoggingPrefix(NULL);
64413+
wolfSSL_SetLoggingPrefix("server");
64414+
ExpectIntEQ(wolfSSL_accept(ssl_s2), WOLFSSL_FATAL_ERROR);
64415+
ExpectIntEQ(wolfSSL_get_error(ssl_s2, WOLFSSL_FATAL_ERROR),
64416+
WOLFSSL_ERROR_WANT_READ);
64417+
wolfSSL_SetLoggingPrefix(NULL);
64418+
64419+
/* Complete third connection so that new tickets are exchanged */
64420+
ExpectIntEQ(test_memio_do_handshake(ssl_c3, ssl_s3, 10, NULL), 0);
64421+
/* Read the ticket msg */
64422+
wolfSSL_SetLoggingPrefix("client");
64423+
ExpectIntEQ(wolfSSL_read(ssl_c3, read_data, sizeof(read_data)),
64424+
WOLFSSL_FATAL_ERROR);
64425+
ExpectIntEQ(wolfSSL_get_error(ssl_c3, WOLFSSL_FATAL_ERROR),
64426+
WOLFSSL_ERROR_WANT_READ);
64427+
wolfSSL_SetLoggingPrefix(NULL);
64428+
64429+
/* Complete second connection */
64430+
ExpectIntEQ(test_memio_do_handshake(ssl_c2, ssl_s2, 10, NULL), 0);
64431+
64432+
ExpectIntEQ(wolfSSL_session_reused(ssl_c2), 1);
64433+
ExpectIntEQ(wolfSSL_session_reused(ssl_c3), 1);
64434+
64435+
wolfSSL_free(ssl_c);
64436+
wolfSSL_free(ssl_c2);
64437+
wolfSSL_free(ssl_c3);
64438+
wolfSSL_free(ssl_s);
64439+
wolfSSL_free(ssl_s2);
64440+
wolfSSL_free(ssl_s3);
64441+
wolfSSL_CTX_free(ctx_c);
64442+
wolfSSL_CTX_free(ctx_s);
64443+
wolfSSL_SESSION_free(sess);
64444+
#endif
64445+
return EXPECT_RESULT();
64446+
}
64447+
6435564448
#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
6435664449
defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
6435764450
static void test_dtls_downgrade_scr_server_ctx_ready_server(WOLFSSL_CTX* ctx)
@@ -65733,6 +65826,7 @@ TEST_CASE testCases[] = {
6573365826
TEST_DECL(test_TLSX_CA_NAMES_bad_extension),
6573465827
TEST_DECL(test_dtls_1_0_hvr_downgrade),
6573565828
TEST_DECL(test_session_ticket_no_id),
65829+
TEST_DECL(test_session_ticket_hs_update),
6573665830
TEST_DECL(test_dtls_downgrade_scr_server),
6573765831
TEST_DECL(test_dtls_downgrade_scr),
6573865832
/* This test needs to stay at the end to clean up any caches allocated. */

tests/utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ int test_memio_do_handshake(WOLFSSL *ssl_c, WOLFSSL *ssl_s,
207207
*rounds = 0;
208208
while (!handshake_complete && max_rounds > 0) {
209209
if (!hs_c) {
210+
wolfSSL_SetLoggingPrefix("client");
210211
ret = wolfSSL_connect(ssl_c);
212+
wolfSSL_SetLoggingPrefix(NULL);
211213
if (ret == WOLFSSL_SUCCESS) {
212214
hs_c = 1;
213215
}
@@ -219,7 +221,9 @@ int test_memio_do_handshake(WOLFSSL *ssl_c, WOLFSSL *ssl_s,
219221
}
220222
}
221223
if (!hs_s) {
224+
wolfSSL_SetLoggingPrefix("server");
222225
ret = wolfSSL_accept(ssl_s);
226+
wolfSSL_SetLoggingPrefix(NULL);
223227
if (ret == WOLFSSL_SUCCESS) {
224228
hs_s = 1;
225229
}

0 commit comments

Comments
 (0)