Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and align ticket age check in ssl_ticket.c for TLS 1.2 and TLS 1.3 #8574

Merged
merged 16 commits into from
Feb 21, 2024

Conversation

ronald-cron-arm
Copy link
Contributor

@ronald-cron-arm ronald-cron-arm commented Nov 28, 2023

Description

Fix and align ticket age check in ssl_ticket.c for TLS 1.2 and TLS 1.3
Follow-up of #6788, partially supersede #8525

Fixes #7795

PR checklist

Please tick as appropriate and edit the reasons (e.g.: "backport: not needed because this is a new feature")

  • changelog not required, internal changes to the TLS implementation only
  • backport not required
  • tests provided

Copy link
Contributor

@yuhaoth yuhaoth left a comment

Choose a reason for hiding this comment

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

Just take a quick look.

* session, the ticket creation time may need to be saved for the ticket
* module to be able to check the ticket age when the ticket is used.
* That's the purpose of this field.
* Before to create a new ticket, an Mbed TLS server set this field with
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: before creating a new ticket

@ronald-cron-arm ronald-cron-arm linked an issue Dec 19, 2023 that may be closed by this pull request
Disable ticket module if either the TLS
server or the support for session tickets
is not enabled at build time as in that
case the ticket module is not used by the
TLS library.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
ssl_ticket.c is a server module.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
The ticket module is removed from the build
if the TLS server is not in the build now
thus no need for the guard.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
When calculating the ticket age, remove the check
that the endpoint is a server. The module is
supposed to be used only server side. Furthermore,
if such check was necessary, it should be at the
beginning of all ssl_ticket.c APIs. As there is no
such protection in any API, just remove the check.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Take into account that the lifetime of
tickets can be changed through the
mbedtls_ssl_ticket_rotate() API.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
The endpoint field is needed to serialize/deserialize
a session in TLS 1.2 the same way it is needed in the
TLS 1.3 case: client specific fields that should not
be in the serialized version on server side if both
TLS client and server are enabled in the TLS library.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
The purpose of this change is to eventually base
the calculation in ssl_ticket.c of the ticket age
when parsing a ticket on the ticket creation time
both in TLS 1.2 and TLS 1.3 case.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Move the save/load of session endpoint and
ciphersuite that are common to TLS 1.2 and
TLS 1.3 serialized data from the
specialized ssl_{tls12,tls13}_session_{save,load}
functions to ssl__session_{save,load}.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
@ronald-cron-arm
Copy link
Contributor Author

I've rebased and addressed the comments.

@ronald-cron-arm ronald-cron-arm requested a review from mpg January 15, 2024 09:34
@ronald-cron-arm ronald-cron-arm added needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review and removed needs-ci Needs to pass CI tests labels Feb 6, 2024
@gilles-peskine-arm gilles-peskine-arm self-requested a review February 6, 2024 15:13
@gilles-peskine-arm gilles-peskine-arm removed the needs-reviewer This PR needs someone to pick it up for review label Feb 6, 2024
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

This mostly looks good to me, with a doubt about partly preexisting design and a few minor change requests.

Comment on lines +1237 to +1240
* Before creating a new ticket, an Mbed TLS server set this field with
* its current time in milliseconds. This time may then be saved in the
* session ticket data by the session ticket writing function and
* recovered by the ticket parsing function later when the ticket is used.
Copy link
Contributor

Choose a reason for hiding this comment

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

Info: why do it this way, rather than letting the ticket writing function query the current time if it wants? That would seem more natural to me.

If this was a session creation time used for multiple purposes, this approach would be necessary, since there would have to be a single point where the official session creation time is decided. But for the ticket creation time, the (single) ticket writing function is the natural place.

(I realize that this is not new from this pull request: it's from #6788, which isn't released yet, and which AFAICT wasn't part of the public API until this PR which exposes it via mbedtls_ssl_session_get_ticket_creation_time.)

Copy link
Contributor Author

@ronald-cron-arm ronald-cron-arm Feb 7, 2024

Choose a reason for hiding this comment

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

First, thanks for the review.

Info: why do it this way, rather than letting the ticket writing function query the current time if it wants?

One important point is that when using the ticket the TLS 1.3 server needs the ticket_creation_time, it cannot be only a ticket module data. Thus it means that the ticket_creation_time needs to be in the ticket data.
In our implementation of mbedtls_ssl_ticket_write_t (and it is expected to be so in third party ones) the creation of the ticket data is based on mbedtls_ssl_session_save() thus when mbedtls_ssl_session_save() is called the
ticket_creation_time of the mbedtls_ssl_session structure must be set.

We could do it in mbedtls_ssl_ticket_write() but it is not straightforward as the session input parameter is a const: const mbedtls_ssl_session *session (we would need to copy the session ...). And if we do it that way with another implementation of mbedtls_ssl_ticket_write_t based on mbedtls_ssl_session_save() we would not add the ticket_creation_time in the ticket data.

@gilles-peskine-arm gilles-peskine-arm added needs-work and removed needs-review Every commit must be reviewed by at least two team members, labels Feb 6, 2024
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
@ronald-cron-arm ronald-cron-arm added needs-ci Needs to pass CI tests needs-review Every commit must be reviewed by at least two team members, and removed needs-work needs-ci Needs to pass CI tests labels Feb 9, 2024
@ronald-cron-arm
Copy link
Contributor Author

@gilles-peskine-arm the CI is green (but ABI-API check as expected) and I believe I have addressed your comment now, please have another look, thanks.

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

LGTM

@tom-cosgrove-arm tom-cosgrove-arm added needs-reviewer This PR needs someone to pick it up for review and removed needs-reviewer This PR needs someone to pick it up for review labels Feb 20, 2024
@tom-cosgrove-arm
Copy link
Contributor

@mpg doing second review on this

Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

LGTM!

@mpg mpg removed the needs-review Every commit must be reviewed by at least two team members, label Feb 21, 2024
@mpg mpg added this pull request to the merge queue Feb 21, 2024
@mpg mpg added the approved Design and code approved - may be waiting for CI or backports label Feb 21, 2024
@mpg
Copy link
Contributor

mpg commented Feb 21, 2024

partially supersede #8525

Was it really partial? Or can #8525 be closed now?

@ronald-cron-arm
Copy link
Contributor Author

partially supersede #8525

Was it really partial? Or can #8525 be closed now?

I have to check but yes I think there is still some work to do.

Merged via the queue into Mbed-TLS:development with commit 0ecb5fd Feb 21, 2024
4 of 6 checks passed
ronald-cron-arm added a commit to ronald-cron-arm/mbedtls that referenced this pull request Mar 11, 2024
Since the merge of Mbed-TLS#8574 it is not the case
anymore that the lifetime of keys is twice
the lifetime of tickets.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports component-tls component-tls13 enhancement priority-high High priority - will be reviewed soon
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Rare intermittent failure of a TLS 1.3 session resumption test
5 participants