Skip to content

Commit 05b692d

Browse files
Merge pull request #6661 from julek-wolfssl/zd/16477
Recover when the client sends a 0-length session ID when using tickets
2 parents fbc6ed4 + dee3224 commit 05b692d

2 files changed

Lines changed: 88 additions & 9 deletions

File tree

src/internal.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16114,22 +16114,30 @@ static int DoHandShakeMsgType(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1611416114
case certificate_request:
1611516115
case server_hello_done:
1611616116
if (ssl->options.resuming) {
16117-
#ifdef WOLFSSL_WPAS
16117+
/* https://www.rfc-editor.org/rfc/rfc5077.html#section-3.4
16118+
* Alternatively, the client MAY include an empty Session ID
16119+
* in the ClientHello. In this case, the client ignores the
16120+
* Session ID sent in the ServerHello and determines if the
16121+
* server is resuming a session by the subsequent handshake
16122+
* messages.
16123+
*/
16124+
#ifndef WOLFSSL_WPAS
16125+
if (ssl->session->sessionIDSz != 0) {
16126+
/* Fatal error. Only try to send an alert. RFC 5246 does not
16127+
* allow for reverting back to a full handshake after the
16128+
* server has indicated the intention to do a resumption. */
16129+
(void)SendAlert(ssl, alert_fatal, unexpected_message);
16130+
WOLFSSL_ERROR_VERBOSE(OUT_OF_ORDER_E);
16131+
return OUT_OF_ORDER_E;
16132+
}
16133+
#endif
1611816134
/* This can occur when ssl->sessionSecretCb is set. EAP-FAST
1611916135
* (RFC 4851) allows for detecting server session resumption
1612016136
* based on the msg received after the ServerHello. */
1612116137
WOLFSSL_MSG("Not resuming as thought");
1612216138
ssl->options.resuming = 0;
1612316139
/* No longer resuming, reset peer authentication state. */
1612416140
ssl->options.peerAuthGood = 0;
16125-
#else
16126-
/* Fatal error. Only try to send an alert. RFC 5246 does not
16127-
* allow for reverting back to a full handshake after the
16128-
* server has indicated the intention to do a resumption. */
16129-
(void)SendAlert(ssl, alert_fatal, unexpected_message);
16130-
WOLFSSL_ERROR_VERBOSE(OUT_OF_ORDER_E);
16131-
return OUT_OF_ORDER_E;
16132-
#endif
1613316141
}
1613416142
}
1613516143
}

tests/api.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63172,6 +63172,76 @@ static int test_dtls_1_0_hvr_downgrade(void)
6317263172
}
6317363173
#endif
6317463174

63175+
#if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) && \
63176+
defined(HAVE_SESSION_TICKET)
63177+
63178+
static WOLFSSL_SESSION* test_session_ticket_no_id_session = NULL;
63179+
63180+
static void test_session_ticket_no_id_on_result(WOLFSSL* ssl)
63181+
{
63182+
test_session_ticket_no_id_session = wolfSSL_get1_session(ssl);
63183+
AssertNotNull(test_session_ticket_no_id_session);
63184+
}
63185+
63186+
static void test_session_ticket_no_id_ctx_ready(WOLFSSL_CTX* ctx)
63187+
{
63188+
AssertIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS);
63189+
}
63190+
63191+
static void test_session_ticket_no_id_ssl_ready(WOLFSSL* ssl)
63192+
{
63193+
test_session_ticket_no_id_session->sessionIDSz = 0;
63194+
AssertIntEQ(WOLFSSL_SUCCESS,
63195+
wolfSSL_set_session(ssl, test_session_ticket_no_id_session));
63196+
}
63197+
63198+
static int test_session_ticket_no_id(void)
63199+
{
63200+
/* We are testing an expired (invalid crypto context in out case since the
63201+
* ctx changes) session ticket being sent with the session ID being 0
63202+
* length. */
63203+
EXPECT_DECLS;
63204+
callback_functions func_cb_client;
63205+
callback_functions func_cb_server;
63206+
63207+
XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
63208+
XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
63209+
func_cb_client.method = wolfTLSv1_2_client_method;
63210+
func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
63211+
func_cb_client.on_result = test_session_ticket_no_id_on_result;
63212+
func_cb_server.method = wolfTLSv1_2_server_method;
63213+
func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
63214+
63215+
test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
63216+
63217+
ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
63218+
ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
63219+
63220+
XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
63221+
XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
63222+
func_cb_client.method = wolfTLSv1_2_client_method;
63223+
func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
63224+
func_cb_client.ssl_ready = test_session_ticket_no_id_ssl_ready;
63225+
func_cb_server.method = wolfTLSv1_2_server_method;
63226+
func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
63227+
63228+
test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
63229+
63230+
ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
63231+
ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
63232+
63233+
wolfSSL_SESSION_free(test_session_ticket_no_id_session);
63234+
63235+
return EXPECT_RESULT();
63236+
}
63237+
#else
63238+
static int test_session_ticket_no_id(void)
63239+
{
63240+
EXPECT_DECLS;
63241+
return EXPECT_RESULT();
63242+
}
63243+
#endif
63244+
6317563245
/*----------------------------------------------------------------------------*
6317663246
| Main
6317763247
*----------------------------------------------------------------------------*/
@@ -64425,6 +64495,7 @@ TEST_CASE testCases[] = {
6442564495
TEST_DECL(test_dtls_no_extensions),
6442664496
TEST_DECL(test_TLSX_CA_NAMES_bad_extension),
6442764497
TEST_DECL(test_dtls_1_0_hvr_downgrade),
64498+
TEST_DECL(test_session_ticket_no_id),
6442864499
/* This test needs to stay at the end to clean up any caches allocated. */
6442964500
TEST_DECL(test_wolfSSL_Cleanup)
6443064501
};

0 commit comments

Comments
 (0)