Skip to content

Add Mbed TLS client session tickets - #88

Open
padelsbach wants to merge 4 commits into
wolfSSL:masterfrom
padelsbach:tickets
Open

padelsbach wants to merge 4 commits into
wolfSSL:masterfrom
padelsbach:tickets

Conversation

@padelsbach

Copy link
Copy Markdown
Contributor

Adds client session tickets for TLS 1.2 and 1.3, with MBEDTLS_SSL_SESSION_TICKETS:

  • mbedtls_ssl_conf_session_tickets, for TLS 1.2. Tickets are on by default. When off, the client sends no ticket, including one from a saved session
  • TLS 1.3: mbedtls_ssl_read returns MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET for each ticket, before the data after it, and mbedtls_ssl_get_session then has the ticket. A ticket with no lifetime is not signaled
  • mbedtls_ssl_conf_tls13_enable_signal_new_session_tickets, with WOLFPSA_MBEDTLS_3. As in Mbed TLS 3.6, mbedtls_ssl_config_defaults turns the signal off
  • mbedtls_ssl_conf_session_tickets_cb, mbedtls_ssl_conf_new_session_tickets and mbedtls_ssl_session_get_ticket_creation_time are placeholders so server code builds. A server sends no tickets until a follow-up PR adds server tickets

user_settings.h now defines HAVE_SESSION_TICKET, and HAVE_SYS_TIME_H for the ticket's age.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active issues allow buffered application data to bypass ticket notifications and can prevent TLS 1.2 session resumption when tickets are disabled during session import and re-enabled before the handshake.

2 open issues
What changed in this PR

Adds client session-ticket support to wolfPSA’s Mbed TLS compatibility layer for TLS 1.2 and TLS 1.3, while leaving server ticket support for a follow-up PR.

Changes:

  • Adds TLS 1.2 ticket controls and TLS 1.3 ticket notifications, including Mbed TLS 3.6’s disabled-by-default signaling.
  • Enables the required wolfSSL features and adds server API placeholders.
  • Adds ticket and resumption tests, adjusts suite helpers, and documents compatibility limits.
File Description
wolfpsa/​mbedtls_compat/​mbedtls/​ssl.h Declares ticket APIs, constants, state, and server placeholders.
user_settings.h Enables session tickets and ticket-age time support.
tools/​psa_want_probe.c Detects support for the session-ticket feature macro.
test/​mbedtls_compat/​ssl_test.c Tests ticket controls, notifications, saving, and resumption.
test/​mbedtls_compat/​ssl_suite/​ssl_helpers_port.c Excludes unsupported server-ticket helpers for wolfPSA.
test/​mbedtls_compat/​ssl_suite/​cases.txt Clarifies that the ticket limitation concerns server tickets.
test/​mbedtls_compat/​mbedtls3_test.c Tests Mbed TLS 3.6 signaling defaults and controls.
src/​mbedtls/​ssl.c Implements client ticket handling and server placeholders.
src/​mbedtls/​mbedtls3.c Implements the Mbed TLS 3.6 ticket-signaling setter.
README.md Narrows the outstanding ticket feature to server support.
docs/​mbedtls-compatibility.md Documents ticket requirements, APIs, and known differences.

Review effort: Balanced

Comment thread src/mbedtls/ssl.c
Comment on lines +247 to +249
/* Ends the read for mbedtls_ssl_read() to return the ticket */
if (s->reading && s->new_ticket) {
return WOLFSSL_CBIO_ERR_WANT_READ;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read ahead requires WOLFSSL_TLS_READ_AHEAD and a call to wolfSSL_CTX_set_read_ahead. So this feature is not available to an application.

Comment thread src/mbedtls/ssl.c Outdated
Comment on lines +1289 to +1292
if (ret == WOLFSSL_SUCCESS &&
conf->session_tickets == MBEDTLS_SSL_SESSION_TICKETS_DISABLED &&
!IsAtLeastTLSv1_3(ssl->session->version)) {
ret = wolfSSL_set_SessionTicket(ssl, NULL, 0);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Fixed.

For future reference, this is the problematic sequence:

  1. A connection with tickets on saves a session that has a ticket.
  2. The client turns tickets off, then calls mbedtls_ssl_set_session() with that session.
  3. The client turns tickets back on.
  4. The handshake should resume with the ticket, but it does a full handshake.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #88

Scan targets checked: wolfpsa-src, wolfpsa-bugs
Not reviewed (no scan target covers them): README.md, docs/mbedtls-compatibility.md, test/mbedtls_compat/ssl_suite/cases.txt, tools/psa_want_probe.c, user_settings.h
Coverage: 6 of 6 in-scope changed file(s) opened by the reviewer

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Max

Comment thread test/mbedtls_compat/ssl_test.c Outdated
mbedtls_ssl_conf_session_tickets(&cli.conf,
MBEDTLS_SSL_SESSION_TICKETS_DISABLED);
}
ok = ok && Reconnect(&session) == (first && second);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tls12TicketOff passes even if MbedSetTickets ignores MBEDTLS_SSL_SESSION_TICKETS_DISABLED · Weak or missing assertions

With first == 0, tickets stay disabled through Reconnect, so MbedSetSession deletes any ticket in the saved session, and the server cache is off. The test passes even if MbedSetTickets still requests a ticket in the first handshake, so the disabled branch goes untested.

Suggested fix: Add a case that disables tickets for the first handshake and re-enables them before Reconnect, expecting no resumption.
Basis: Mbed TLS ssl.h, mbedtls_ssl_conf_session_tickets(): enables or disables TLS 1.2 session tickets on the client, so a session from a handshake with tickets disabled holds no ticket to resume with.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case added

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three small points below, the first optional.

Comment thread src/mbedtls/ssl.c
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
if (ssl->session_set && ssl->conf->session_tickets ==
MBEDTLS_SSL_SESSION_TICKETS_DISABLED &&
!IsAtLeastTLSv1_3(ssl->ssl->session->version)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: no test runs TLS 1.3 with mbedtls_ssl_conf_session_tickets() off, so dropping this version check would still pass. A Tls13Ticket case with tickets disabled that still expects the signal and Reconnect() == 1 would cover it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case added

Comment thread wolfpsa/mbedtls_compat/mbedtls/ssl.h Outdated
{
(void)session;
(void)ticket_creation_time;
#ifdef WOLFPSA_MBEDTLS_3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MBEDTLS_ERR_SSL_BAD_INPUT_DATA is PSA_ERROR_INVALID_ARGUMENT in every build (line 205), so both branches return the same value; drop the #ifdef and return it once.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread src/mbedtls/ssl.c

if (s->conf->signal_tickets &&
wolfSSL_version(ssl) == MBEDTLS_SSL_VERSION_TLS1_3 &&
wolfSSL_SESSION_get_ticket_lifetime_hint(session) > 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A ticket with zero lifetime isn't signaled, but wolfSSL has already stored it over the previous ticket, so mbedtls_ssl_get_session() then returns a session that can't resume. Mbed TLS discards such a ticket; keep the earlier one or list this under the known differences.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe MbedTLS and wolfPSA both discard the previous ticket and return failure until the next ticket. Docs updated with this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, Mbed TLS frees the earlier ticket in ssl_tls13_parse_new_session_ticket too; the new doc note covers the difference.

@padelsbach padelsbach removed their assignment Dec 2, 2026

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #88

Scan targets checked: wolfpsa-src, wolfpsa-bugs
Not reviewed (no scan target covers them): README.md, docs/mbedtls-compatibility.md, test/mbedtls_compat/ssl_suite/cases.txt, tools/psa_want_probe.c, user_settings.h
Coverage: 2 of 3 in-scope changed file(s) opened by the reviewer; not opened: wolfpsa/mbedtls_compat/mbedtls/ssl.h

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed their stale review December 2, 2026 18:27

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

@Frauschi Frauschi closed this Dec 3, 2026
@Frauschi Frauschi reopened this Dec 3, 2026

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three comments resolved; verified locally, including the new TLS 1.3 tickets-off test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants