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

TLS 1.3: SRV: Implement mbedtls_ssl_read_early_data() #8692

Merged
merged 19 commits into from
Feb 2, 2024

Conversation

ronald-cron-arm
Copy link
Contributor

@ronald-cron-arm ronald-cron-arm commented Jan 10, 2024

Description

Fix #6341

Note for reviewers:
Following the work done in #6621, the implementation of mbedtls_ssl_read_early_data() started in #6541 with the function following a logic similar as the mbedtls_ssl_read() one with the function triggering an handshake sequence until some early data are found and returned to the caller. Working with that guideline I realized that the resulting function could also be used easily as a companion of the mbedtls_ssl_handshake/read/write() functions. These functions all trigger an handshake sequence and if as part of this sequence early data are detected, the functions return with an appropriate return value and then the caller can call mbedtls_ssl_read_early_data() to read the early data. That's convenient to adapt current mbedtls_ssl_handshake/read/write() workflows to read early data as well as I experienced when updating ssl_server2 to support early data. Thus now I am wondering if we should just keep the companion behavior of mbedtls_ssl_read_early_data() and thus practically remove from it the call to mbedtls_ssl_handshake(). This would narrow its scope and thus make it easier to apprehend and use I'd say. I would appreciate opinions, thoughts about that.

Opted for the simplest: mbedtls_ssl_read_early_data() does not trigger or resume the handshake (no call to mbedtls_ssl_handshake()). It just read early data that have been detected by a previous call to mbedtls_ssl_handshake(), mbedtls_ssl_handshake_step(), mbedtls_ssl_handshake_read() or mbedtls_ssl_handshake_write().

PR checklist

  • changelog not required yet
  • backport not required, new feature
  • tests provided

@ronald-cron-arm ronald-cron-arm requested a review from mpg January 10, 2024 09:32
@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 Jan 15, 2024
@tom-cosgrove-arm tom-cosgrove-arm self-requested a review January 22, 2024 15:57
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.

(Partial review so far.)

@tom-cosgrove-arm tom-cosgrove-arm added priority-high High priority - will be reviewed soon and removed needs-reviewer This PR needs someone to pick it up for review labels Jan 30, 2024
@ronald-cron-arm
Copy link
Contributor Author

@mpg I believe I have addressed your comments. Following our discussions, I have also added documentation to highlight that mbedtls_ssl_handshake(), mbedtls_ssl_write() may now return a new error code. I have also simplified the read API.

@ronald-cron-arm ronald-cron-arm force-pushed the read-early-data branch 2 times, most recently from 91b6694 to cc36a58 Compare January 31, 2024 10:47
@ronald-cron-arm
Copy link
Contributor Author

ronald-cron-arm commented Jan 31, 2024

I have some troubles with generate_ssl_debug_helpers.py (only on CI, not locally ...), trying to figure out the commit causing the problem. Sorry for the noise.

@ronald-cron-arm ronald-cron-arm force-pushed the read-early-data branch 3 times, most recently from fa45464 to 2614798 Compare February 1, 2024 08:30
@ronald-cron-arm
Copy link
Contributor Author

ronald-cron-arm commented Feb 1, 2024

CI all green but Windows-2013 not finished, I think this is ready for review.

@ronald-cron-arm ronald-cron-arm requested a review from mpg February 1, 2024 10:22
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.

Thanks for addressing my feedback! Looks almost all good to me, just one question and a few suggestions.

The question (about not checking ssl->early_data_state.srv) is the only reason I'm not approving now. The suggestions are minor and could be left to a follow-up in the interest of avoiding another round-trip.

Note about my review: at this point I'm not familiar enough with the spec and our code to be confident we're only accepting early data when we should (for example, I had completely missed the thing about HRR). So, I'm mostly assuming that negotiation of EarlyData is correct as it has been reviewed before, and also we'll have an opportunity to revisit that when adding negative testing.

ronald-cron-arm and others added 3 commits February 1, 2024 16:40
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
The main purpose is to know from the status
if early data can be received of not and
why.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
The function will be used by
mbedtls_ssl_read_early_data() as well.

Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
yuhaoth and others added 12 commits February 1, 2024 16:40
Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
MBEDTLS_SSL_EARLY_DATA implies
MBEDTLS_SSL_PROTO_TLS1_3 thus
MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_EARLY_DATA
is equivalent to MBEDTLS_SSL_EARLY_DATA.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Introduce early_data_state SSL context field to
distinguish better this internal state from
the status values defined for the
mbedtls_ssl_get_early_data_status() API.
Distinguish also between the client and
server states. Note that the client state
are going to be documented and reworked
as part of the implementation of
mbedtls_ssl_write_early_data().

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>
Do not progress the handshake in the API, just
read early data if some has been detected by
a previous call to mbedtls_ssl_handshake(),
mbedtls_ssl_handshake_step(),
mbedtls_ssl_read() or mbedtls_ssl_write().

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This reverts commit 0883b8b.
Due to the scope reduction of mbedtls_ssl_read_early_data()
it is not necessary anymore to refine the usage
of early_data_status/state rather the opposite.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Due to the scope reduction for
mbedtls_ssl_read_early_data(), on
server as early data state variable
we now only need a flag in the
handshake context indicating if
the server has accepted early data
or not.

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

ronald-cron-arm commented Feb 2, 2024

The question (about not checking ssl->early_data_state.srv) is the only reason I'm not approving now.

I have removed it.

Note about my review: at this point I'm not familiar enough with the spec and our code to be confident we're only accepting early data when we should (for example, I had completely missed the thing about HRR). So, I'm mostly assuming that negotiation of EarlyData is correct as it has been reviewed before, and also we'll have an opportunity to revisit that when adding negative testing.

I think that's kind of normal you did not spot the need for the change relative to the reception of an HRR while reviewing this PR. The change does not fit well in this PR (I probably should have done it in another PR, sorry about that). It is indeed something we missed when working on and reviewing ssl_tls13_update_early_data_status() (now ssl_tls13_is_early_data_accepted()). PR 8727 adds a test where an HRR is received and thus early data rejected.

Otherwise I had to rebase following the merge of #8711. There was only one conflict, that was easy to resolve.

@ronald-cron-arm ronald-cron-arm requested a review from mpg February 2, 2024 07:19
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.

Thanks for addressing my feedback - and more, I really like the simplification of state handling on the server.

I still have mostly the same question though, which I've tried to clarify. To be clear: I'm not saying there's something wrong, just that I can't convince myself I know what the code is doing, at this point.

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.

Thanks for answering my question. Looks all good to me now.

Copy link
Contributor

@tom-cosgrove-arm tom-cosgrove-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 approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, labels Feb 2, 2024
@ronald-cron-arm ronald-cron-arm added this pull request to the merge queue Feb 2, 2024
Merged via the queue into Mbed-TLS:development with commit b90e695 Feb 2, 2024
6 checks passed
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-tls13 enhancement priority-high High priority - will be reviewed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TLS 1.3 server: Add support for early data reading
4 participants