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

Change early data flag to input file #8596

Merged

Conversation

xkqian
Copy link
Contributor

@xkqian xkqian commented Dec 4, 2023

Description

Originally we have one input option to control whether enable early data or not. Currently we need one extra parameter to input various length of early data. This pr will integrate them together.

This is part of #6542

PR checklist

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

  • changelog provided, or not required
  • backport done, or not required
  • tests provided , or not required

@xkqian xkqian added needs-ci Needs to pass CI tests component-tls13 priority-high High priority - will be reviewed soon labels Dec 4, 2023
@xkqian xkqian force-pushed the tls13_early_data_input_file branch from 0c8d22f to 4c909e6 Compare December 4, 2023 08:58
@xkqian xkqian requested a review from yuhaoth December 4, 2023 08:58
@xkqian xkqian linked an issue Dec 4, 2023 that may be closed by this pull request
1 task
@xkqian xkqian force-pushed the tls13_early_data_input_file branch from 4c909e6 to 0183914 Compare December 4, 2023 09:04
@tom-cosgrove-arm
Copy link
Contributor

@xkqian Should this PR be part of the Early Data epic?

@xkqian xkqian added needs-review Every commit must be reviewed by at least two team members, and removed needs-review Every commit must be reviewed by at least two team members, labels Dec 4, 2023
@xkqian
Copy link
Contributor Author

xkqian commented Dec 4, 2023

@xkqian Should this PR be part of the Early Data epic?

Yes, sure, this is part of #6542 I just want to split it into several small PRs to accelerate the review, and this is the the first one.

Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
@xkqian xkqian force-pushed the tls13_early_data_input_file branch from 0183914 to 70fbdcf Compare December 5, 2023 05:51
@xkqian xkqian added the needs-review Every commit must be reviewed by at least two team members, label Dec 5, 2023
@xkqian xkqian mentioned this pull request Dec 5, 2023
3 tasks
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.

This looks almost good to me, just some minor suggestions.

Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
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 comments. I think the implementation looks too complex and miss some features for tests.

Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
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 new comments. And previous early_data option feedback is not addressed

Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
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 minor comments

Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
@ronald-cron-arm
Copy link
Contributor

I am fine with the two options solution. I put a comment in one of Jerry's suggestion.

Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
@xkqian xkqian requested a review from yuhaoth December 7, 2023 09:51
yuhaoth
yuhaoth previously approved these changes Dec 7, 2023
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

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.

While thinking about what option to add to ssl_client2 for early data testing I think we have lost (at least that's my case) sight of its scope. It is mainly about testing the various TLS options and the compatibility with GnuTLS and OpenSSL. Negative and edge cases testing is not really in scope.

Thus I'd say let's keep things simple, for the time being at least:
one option early_data_file whose default value is "". If a valid file path is set to early_data_file, we enable early data on the client and in the reconnection case, before to call mbedtls_ssl_handshake() to reconnect we call mbedtls_ssl_write_early_data() that tries to write the early_data_file file data.

When we add more testing for early data we will see if they best fit in ssl-opt.sh or test_suite_ssl and we need to add other options in ssl_client2.

@yuhaoth
Copy link
Contributor

yuhaoth commented Dec 8, 2023

While thinking about what option to add to ssl_client2 for early data testing I think we have lost (at least that's my case) sight of its scope. It is mainly about testing the various TLS options and the compatibility with GnuTLS and OpenSSL. Negative and edge cases testing is not really in scope.

Thus I'd say let's keep things simple, for the time being at least: one option early_data_file whose default value is "". If a valid file path is set to early_data_file, we enable early data on the client and in the reconnection case, before to call mbedtls_ssl_handshake() to reconnect we call mbedtls_ssl_write_early_data() that tries to write the early_data_file file data.

My target is to simple this PR. Let's make final decision in next PRs .
But if only one option, we have to do more things in this PR. early_data option come from development, it must be removed. I do not thinks we should remove or change it in this PR. That make things complex.

For the two options from your previous comments, I do not think empty file and invalid file are same. If they are same, we have to check the file length before call mbedtls_ssl_{handshake, write_early_data}() and reduce possible test case. And I do not mean we MUST add the test in ssl-opt.sh. But the amount of code is less and the test coverage is more, why not do like that?

When we add more testing for early data we will see if they best fit in ssl-opt.sh or test_suite_ssl and we need to add other options in ssl_client2.

Agree.
I think this PR just do two things enough.

  • add early_data_file option
  • add a empty function for writing early data in next PRs .

@xkqian
Copy link
Contributor Author

xkqian commented Dec 8, 2023

Thus I'd say let's keep things simple, for the time being at least:
one option early_data_file whose default value is "". If a valid file path is set to early_data_file, we enable early data on the client and in the reconnection case, before to call mbedtls_ssl_handshake() to reconnect we call mbedtls_ssl_write_early_data() that tries to write the early_data_file file data.

Seems this is the first way which only provide one option, am I right? if yes, then the code before this commit: 57db590 can satisfy the requirements, of course, need addressing some comments.

My target is to simple this PR. Let's make final decision in next PRs . But if only one option, we have to do more things in this PR. early_data option come from development, it must be removed. I do not thinks we should remove or change it in this PR. That make things complex.

This comment prefer to reserve the early_data option and introduce another option named "early_data_file" as the source file read early data from. The latest code is trying to satisfy this requirement.

Seems we should agree with each other that which way we should take. and then I will revert code or keep the code accordingly.
(my original plan is: one option is enough for this case, but I am fine with two options. )

Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
@xkqian
Copy link
Contributor Author

xkqian commented Dec 8, 2023

I just revert the code to use the one option, which uses early_data as the input early data file.
In this PR, we can only replace the option, and in next PR, we can add the test code including: ssl_write_early_data(), and how to call it.
I think we can review it base one current version.

ronald-cron-arm
ronald-cron-arm previously approved these changes Dec 8, 2023
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.

If with this changes you have what you need for your coming PRs implementing mbedtls_ssl_write_early_data() this is good enough to me.

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.

It has got CI failure
One change request and one nitpick comments.

Comment on lines +1969 to +1976
if (strlen(opt.early_data) > 0) {
if ((early_data_fp = fopen(opt.early_data, "rb")) == NULL) {
mbedtls_printf("failed\n ! Cannot open '%s' for reading.\n",
opt.early_data);
goto exit;
}
early_data_enabled = MBEDTLS_SSL_EARLY_DATA_ENABLED;
}
Copy link
Contributor

@yuhaoth yuhaoth Dec 8, 2023

Choose a reason for hiding this comment

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

To fix the CI failure

Suggested change
if (strlen(opt.early_data) > 0) {
if ((early_data_fp = fopen(opt.early_data, "rb")) == NULL) {
mbedtls_printf("failed\n ! Cannot open '%s' for reading.\n",
opt.early_data);
goto exit;
}
early_data_enabled = MBEDTLS_SSL_EARLY_DATA_ENABLED;
}
if (opt.early_data) {
if ((early_data_fp = fopen(opt.early_data, "rb")) == NULL) {
mbedtls_printf("failed\n ! Cannot open '%s' for reading.\n",
opt.early_data);
goto exit;
}
early_data_enabled = MBEDTLS_SSL_EARLY_DATA_ENABLED;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CI failure is caused by the uninitialized file pointer early_data_fp.
opt.early_data will be default to "", this check maybe useless...

Comment on lines +1969 to +1976
if (strlen(opt.early_data) > 0) {
if ((early_data_fp = fopen(opt.early_data, "rb")) == NULL) {
mbedtls_printf("failed\n ! Cannot open '%s' for reading.\n",
opt.early_data);
goto exit;
}
early_data_enabled = MBEDTLS_SSL_EARLY_DATA_ENABLED;
}
Copy link
Contributor

@yuhaoth yuhaoth Dec 8, 2023

Choose a reason for hiding this comment

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

Nitpick comment : move it to option check like previous version

Suggested change
if (strlen(opt.early_data) > 0) {
if ((early_data_fp = fopen(opt.early_data, "rb")) == NULL) {
mbedtls_printf("failed\n ! Cannot open '%s' for reading.\n",
opt.early_data);
goto exit;
}
early_data_enabled = MBEDTLS_SSL_EARLY_DATA_ENABLED;
}
mbedtls_ssl_conf_early_data(&conf, early_data_fp ?MBEDTLS_SSL_EARLY_DATA_ENABLE: MBEDTLS_SSL_EARLY_DATA_DISABLE);

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 see there are file processings like context_file, will treat it like what I have done, so I prefer that way.

Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
@tom-cosgrove-arm
Copy link
Contributor

@yuhaoth are you happy with this now, too?

}
early_data_enabled = MBEDTLS_SSL_EARLY_DATA_ENABLED;
}
mbedtls_ssl_conf_early_data(&conf, early_data_enabled);
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit) presumably early data defaults to disabled, so we could move this into the if() and remove the variable?

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 Dec 11, 2023
@gilles-peskine-arm gilles-peskine-arm added this pull request to the merge queue Dec 11, 2023
Merged via the queue into Mbed-TLS:development with commit a211bb7 Dec 11, 2023
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 needs-ci Needs to pass CI tests priority-high High priority - will be reviewed soon
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

TLS 1.3 client: Add support for early data writing
5 participants