-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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: Add definition of mbedtls_ssl_{write,read}_early_data #6621
TLS 1.3: Add definition of mbedtls_ssl_{write,read}_early_data #6621
Conversation
4ca0c89
to
6ce46d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nitpick comments. Very details :)
int mbedtls_ssl_write_early_data( mbedtls_ssl_context *ssl, | ||
const unsigned char *buf, size_t len ); | ||
|
||
#define MBEDTLS_SSL_EARLY_DATA_STATUS_NOT_SENT 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MBEDTLS_SSL_EARLY_DATA_STATUS_CAN_DO means SSL context allow early data, any negative value means not allow.
MBEDTLS_SSL_EARLY_DATA_STATUS_ALLOW_SEND, I am not sure if it should be expose to user. that means mbedtls_ssl_write_early_data
can called without error report. If not expose that, we should call mbedtls_ssl_handshake_step
inside mbedtls_ssl_write_early_data
#define MBEDTLS_SSL_EARLY_DATA_STATUS_NOT_SENT 0 | |
#define MBEDTLS_SSL_EARLY_DATA_STATUS_CAN_DO 0 | |
#define MBEDTLS_SSL_EARLY_DATA_STATUS_ALLOW_SEND 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SSL context is set-up by the application and if it wants to send early data it has to set it up with a proper PSK, enabling early data with mbedtls_ssl_tls13_conf_early_data()
... Thus the application is aware if the SSL context potentially allow early data or not. That's why there is currently no API to tell it so.
Setting-up the SSL context is not trivial though thus we should at least have clear debug logs when early data have been enabled through mbedtls_ssl_tls13_conf_early_data()
but eventually early data cannot be sent.
If not expose that, we should call mbedtls_ssl_handshake_step inside mbedtls_ssl_write_early_data
That's the plan like in mbedtls_ssl_write()
to call mbedtls_ssl_handshake()
in mbedtls_ssl_write_early_data()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more question. Is below code expected ?
int mbedtls_ssl_get_early_data_status( mbedtls_ssl_context *ssl )
{
if( is_server || handshake_is_not_over )
return( BAD_INPUT_DATA );
return( ssl->early_data_status );
}
int mbedtls_ssl_read_early_data( mbedtls_ssl_context *ssl, | ||
unsigned char *buf, size_t len ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a internal buffer for early data, before it is called, early data should be saved.
In this case, should we change mbedtls_ssl_read
? If early data buffer is not empty, we should return early data .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plan is for mbedtls_ssl_read_early_data()
to be called when the handshake is not started and for mbedtls_ssl_read_early_data()
to initiate it. Thus when we receive early data while the handshake is on-going we have a buffer (the buffer passed to mbedtls_ssl_read_early_data()
) to store the early data. See the pseudo-code I have added in tls13-support.md.
Otherwise mbedtls_ssl_read
does not and cannot return early data as it reads data when the handshake is over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the early data buffer is not empty when handshake is over, we should free it , right? it must be read by mbedtls_ssl_read_early_data
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There are still two questions to confirm the exactly meaning in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure whether I have fully understood it or not.
I think we need one internal buffer and internal API like mbedtls_ssl_set_early_data() to copy the early data to it.
Our ssl_client2 is one single thread, I think we only have chance to write the early data in the first flight of handshake, which is between early key generated and end of early data received. And at this time, we are during the handshake step. and application will have no chance to transfer the data buffer to it.
Maybe this will be realted with the change of the application, anyway, I am something confused, can you help me? thanks.
Do you want to change something in this PRs? As the discussion in this PR, |
one conflic happens, I will approve it after it's resovled. |
I don't want to change anything, just want to learn more about it and talk abou the application desgin here, seems it's not a right place here. |
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
6ce46d4
to
4a8c9e2
Compare
That's the right place, I just haven't found the time to answer yet. I will try to have a look tomorrow morning. |
Did you have a look to the documentation I added in tls13-support.md which is about how an application would use As mentioned by @yuhaoth in https://github.com/hannestschofenig/mbedtls/blob/3a50d364a977a61914c0d34d560c207eb71734d9/library/ssl_msg.c you can find an implementation of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Understand. Thanks for you and Jerry's explanation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Add definition of mbedtls_ssl_{write,read}_early_data to write and read early data.
Fix #4902
Fix #6310
Gatekeeper checklist