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

Tls13 add early data indication #6486

Merged

Conversation

xkqian
Copy link
Contributor

@xkqian xkqian commented Oct 26, 2022

Add fields to mbedtls_ssl_context
Add write early data indication function
Add early data option to ssl_client2
Add test cases for early data

Part of adding early data support in TLS 1.3. No need for a change log.

@xkqian xkqian linked an issue Oct 26, 2022 that may be closed by this pull request
2 tasks
@xkqian xkqian force-pushed the tls13_add_early_data_indication branch 6 times, most recently from 9233497 to 039504b Compare October 27, 2022 10:42
@daverodgman daverodgman added the priority-high High priority - will be reviewed soon label Oct 27, 2022
Copy link
Contributor

@ronald-cron-arm ronald-cron-arm left a comment

Choose a reason for hiding this comment

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

Some early feedback. At that point no need to evolve the PR by adding new commits. Please just rewrite a clean commit history.

include/mbedtls/ssl.h Outdated Show resolved Hide resolved
include/mbedtls/build_info.h Outdated Show resolved Hide resolved
include/mbedtls/ssl.h Outdated Show resolved Hide resolved
include/mbedtls/ssl.h Outdated Show resolved Hide resolved
library/ssl_tls13_generic.c Outdated Show resolved Hide resolved
library/ssl_tls13_generic.c Outdated Show resolved Hide resolved
Copy link
Contributor

@ronald-cron-arm ronald-cron-arm left a comment

Choose a reason for hiding this comment

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

Some additional comments. I haven't look at the changes in ssl-opt.sh yet.

include/mbedtls/ssl.h Outdated Show resolved Hide resolved
library/ssl_misc.h Outdated Show resolved Hide resolved
library/ssl_tls13_client.c Outdated Show resolved Hide resolved
library/ssl_tls13_client.c Outdated Show resolved Hide resolved
library/ssl_tls13_generic.c Outdated Show resolved Hide resolved
@xkqian xkqian force-pushed the tls13_add_early_data_indication branch from b29afc8 to fb91dc8 Compare October 31, 2022 10:38
@xkqian xkqian requested a review from yuhaoth November 1, 2022 10:53
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.

We should provide a parameter to input early data. Also some improvements.

include/mbedtls/ssl.h Outdated Show resolved Hide resolved
include/mbedtls/ssl.h Outdated Show resolved Hide resolved
library/ssl_misc.h Outdated Show resolved Hide resolved
library/ssl_tls13_client.c Outdated Show resolved Hide resolved
library/ssl_tls13_client.c Outdated Show resolved Hide resolved
library/ssl_tls13_generic.c Outdated Show resolved Hide resolved
tests/ssl-opt.sh Outdated Show resolved Hide resolved
tests/ssl-opt.sh Outdated Show resolved Hide resolved
library/ssl_tls13_generic.c Outdated Show resolved Hide resolved
programs/ssl/ssl_client2.c Show resolved Hide resolved
@xkqian xkqian force-pushed the tls13_add_early_data_indication branch 2 times, most recently from 45ade6f to f99b5a5 Compare November 3, 2022 06:43
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.

Some improvement and reply.

library/ssl_tls13_client.c Outdated Show resolved Hide resolved
library/ssl_tls13_client.c Show resolved Hide resolved
library/ssl_tls13_client.c Outdated Show resolved Hide resolved
library/ssl_tls13_client.c Outdated Show resolved Hide resolved
library/ssl_tls13_client.c Outdated Show resolved Hide resolved
include/mbedtls/ssl.h Outdated Show resolved Hide resolved
include/mbedtls/ssl.h Outdated Show resolved Hide resolved
library/ssl_tls13_client.c Show resolved Hide resolved
library/ssl_tls13_client.c Outdated Show resolved Hide resolved
library/ssl_tls13_client.c Show resolved Hide resolved
library/ssl_tls13_client.c Outdated Show resolved Hide resolved
library/ssl_tls13_client.c Outdated Show resolved Hide resolved
library/ssl_tls13_client.c Outdated Show resolved Hide resolved
Copy link
Contributor

@ronald-cron-arm ronald-cron-arm left a comment

Choose a reason for hiding this comment

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

A few final minor issues.

library/ssl_tls13_client.c Outdated Show resolved Hide resolved
library/ssl_misc.h Outdated Show resolved Hide resolved
library/ssl_tls13_client.c Outdated Show resolved Hide resolved
tests/ssl-opt.sh Outdated Show resolved Hide resolved
tests/ssl-opt.sh Outdated Show resolved Hide resolved
tests/ssl-opt.sh Outdated Show resolved Hide resolved
include/mbedtls/build_info.h Outdated Show resolved Hide resolved
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.

Some minor improvement

library/ssl_tls13_client.c Outdated Show resolved Hide resolved
include/mbedtls/ssl.h Outdated Show resolved Hide resolved
include/mbedtls/ssl.h Show resolved Hide resolved
include/mbedtls/ssl.h Show resolved Hide resolved
library/ssl_debug_helpers.h Outdated Show resolved Hide resolved
library/ssl_misc.h Outdated Show resolved Hide resolved
tests/ssl-opt.sh Outdated Show resolved Hide resolved
tests/ssl-opt.sh Outdated Show resolved Hide resolved
Define the ALLOW_PSK_RESUMPTION and ALLOW_PSK_EPHEMERAL_RESUMPTION
to the key exchange mode EXCHANGE_MODE_PSK and
EXCHANGE_MODE_PSK_EPHEMERAL to facilate later check.
Since they are 1( 1u<<0 ) and 4( 1u<<2 ), so define
ALLOW_EARLY_DATA to 8( 1u<<3 ).

Signed-off-by: Xiaokang Qian <[email protected]>
@xkqian xkqian requested a review from yuhaoth November 16, 2022 08:53
@xkqian xkqian force-pushed the tls13_add_early_data_indication branch from 802e2c8 to e7bab00 Compare November 16, 2022 10:07
yuhaoth
yuhaoth previously approved these changes Nov 16, 2022
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.

LGTM

lpy4105 added a commit to lpy4105/mbedtls that referenced this pull request Nov 17, 2022
The code is based PR Mbed-TLS#6486. This commit might be adapted after
PR Mbed-TLS#6486 merged.

Signed-off-by: Pengyu Lv <[email protected]>
lpy4105 added a commit to lpy4105/mbedtls that referenced this pull request Nov 17, 2022
The code is based PR Mbed-TLS#6486. This commit might be adapted after
PR Mbed-TLS#6486 merged.

Signed-off-by: Pengyu Lv <[email protected]>
Copy link
Contributor

@ronald-cron-arm ronald-cron-arm left a comment

Choose a reason for hiding this comment

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

Just some comments about the tests. Otherwise, this looks good to me.

tests/opt-testcases/tls13-misc.sh Outdated Show resolved Hide resolved
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
run_test "TLS 1.3 m->G: EarlyData: basic check, good" \
"$G_NEXT_SRV -d 10 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:+ECDHE-PSK:+PSK --earlydata --disable-client-cert" \
"$P_CLI debug_level=4 force_version=tls13 early_data=1 reco_mode=1 reconnect=1 reco_delay=2" \
Copy link
Contributor

Choose a reason for hiding this comment

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

We try usually to force the TLS 1.3 version only on the server side thus like in the following test. That way when both TLS 1.2 and TLS 1.3 are enabled in the build the "hybrid" test is run and when only TLS 1.3 is enabled the test corresponding to TLS 1.3 being forced on the client side is run. Thus, I think we should just remove this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just remember in kex exchange mode tests, we remove the force_version=tls13 in client side. To keep aligned, I prefer to remove this case. How about your opinion? @yuhaoth

Copy link
Contributor

Choose a reason for hiding this comment

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

For this PR, it is okay to remove it for me.
It should be added in Write APP data

https://datatracker.ietf.org/doc/html/rfc8446#appendix-A.2 shows early data can be sent after ClientHello. It is Okay for TLS1.3 only. But for hybrid mode, it might cause problem. That's why suggest add hybrid tests.

And I do not think we should postpone write app data like prototype, it does not match RFC. This point has been raised in GnuTLS https://gitlab.com/gnutls/gnutls/-/issues/1146.

Copy link
Contributor Author

@xkqian xkqian Nov 17, 2022

Choose a reason for hiding this comment

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

For this PR, it is okay to remove it for me. It should be added in Write APP data

So I will remove the test case with -force_version=tls13, and only leave the test case which you said "hibrid case" as basic case.

https://datatracker.ietf.org/doc/html/rfc8446#appendix-A.2 shows early data can be sent after ClientHello. It is Okay for TLS1.3 only. But for hybrid mode, it might cause problem. That's why suggest add hybrid tests.

We will leave the "hibrid case" there. Can you eleborate the problems?

And I do not think we should postpone write app data like prototype, it does not match RFC. This point has been raised in GnuTLS https://gitlab.com/gnutls/gnutls/-/issues/1146.

Seems it's related with wrte early data, can we leave the comment to this PR #6542

Copy link
Contributor

Choose a reason for hiding this comment

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

So I will remove the test case with -force_version=tls13, and only leave the test case which you said "hibrid case" as basic case.

Okay.

Seems it's related with wrte early data, can we leave the comment to this PR #6542

Sure.

We will leave the "hibrid case". Can you eleborate the problems?

From RFC 8446, we should send early data after ClientHello immediately. So we must switch outbound traffic after ClientHello ASAP.

If switch in CLIENT_HELLO and send early data, it match RFC. But if the server select TLS 1.2, I am not sure what will happen.

To avoid the issue, I think we should postpone the traffic switch, just after TLS 1.3 is selected at this moment. And in ClientHello, we should only switch traffic if it is configured as tls1.3 only.

For the test side, we should have tls1.3 only and hybrid mode test to cover the cases.

Copy link
Contributor Author

@xkqian xkqian Nov 17, 2022

Choose a reason for hiding this comment

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

From RFC 8446, we should send early data after ClientHello immediately. So we must switch outbound traffic after ClientHello ASAP.

If switch in CLIENT_HELLO and send early data, it match RFC. But if the server select TLS 1.2, I am not sure what will happen.

To avoid the issue, I think we should postpone the traffic switch, just after TLS 1.3 is selected at this moment. And in ClientHello, we should only switch traffic if it is configured as tls1.3 only.

For the test side, we should have tls1.3 only and hybrid mode test to cover the cases.

Seems it's one issue we should trade off when and in which case to change transform key.
Currently we only support session tikets psk, which means we only send out early data in resumption with tickets, maybe weI can make use of the tls_version in seriealized session to detect whether we only send out tls13 version, and then server will only have one tls13 choice. I am not sure whether the design work or not, maybe we can solve it in some ways.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes that's a key point. A TLS 1.3 handshake proposing early data can only be done with a PSK (external or obtained through a ticket) which is TLS 1.3 specific. Thus in that case we are not going to propose TLS 1.2 to the server: "TLS 1.3 only ClientHello".

tests/opt-testcases/tls13-misc.sh Outdated Show resolved Hide resolved
Copy link
Contributor

@ronald-cron-arm ronald-cron-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, @yuhaoth please have another look.

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.

LGTM

@ronald-cron-arm
Copy link
Contributor

LGTM

It seems you selected "Request changes" instead of "Approve".

@yuhaoth yuhaoth mentioned this pull request Nov 17, 2022
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.

LGTM

@ronald-cron-arm ronald-cron-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, needs-ci Needs to pass CI tests labels Nov 17, 2022
@ronald-cron-arm ronald-cron-arm merged commit d12922a into Mbed-TLS:development Nov 17, 2022
lpy4105 added a commit to lpy4105/mbedtls that referenced this pull request Nov 22, 2022
The code is based PR Mbed-TLS#6486. This commit might be adapted after
PR Mbed-TLS#6486 merged.

Signed-off-by: Pengyu Lv <[email protected]>
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 priority-high High priority - will be reviewed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TLS 1.3 client: Writing of the early data indication extension
4 participants