-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -96,15 +96,16 @@ | |||||||
/* Error space gap */ | ||||||||
/** Processing of the Certificate handshake message failed. */ | ||||||||
#define MBEDTLS_ERR_SSL_BAD_CERTIFICATE -0x7A00 | ||||||||
/* Error space gap */ | ||||||||
/** | ||||||||
* Received NewSessionTicket Post Handshake Message. | ||||||||
* This error code is experimental and may be changed or removed without notice. | ||||||||
*/ | ||||||||
#define MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET -0x7B00 | ||||||||
/* Error space gap */ | ||||||||
/* Error space gap */ | ||||||||
/* Error space gap */ | ||||||||
/* Error space gap */ | ||||||||
/** Not possible to read early data */ | ||||||||
#define MBEDTLS_ERR_SSL_CANNOT_READ_EARLY_DATA -0x7B80 | ||||||||
/** Not possible to write early data */ | ||||||||
#define MBEDTLS_ERR_SSL_CANNOT_WRITE_EARLY_DATA -0x7C00 | ||||||||
/* Error space gap */ | ||||||||
/* Error space gap */ | ||||||||
/* Error space gap */ | ||||||||
|
@@ -806,14 +807,6 @@ typedef struct mbedtls_ssl_key_cert mbedtls_ssl_key_cert; | |||||||
typedef struct mbedtls_ssl_flight_item mbedtls_ssl_flight_item; | ||||||||
#endif | ||||||||
|
||||||||
#if defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_CLI_C) | ||||||||
#define MBEDTLS_SSL_EARLY_DATA_STATUS_UNKNOWN 0 | ||||||||
#define MBEDTLS_SSL_EARLY_DATA_STATUS_NOT_SENT 1 | ||||||||
#define MBEDTLS_SSL_EARLY_DATA_STATUS_INDICATION_SENT 2 | ||||||||
#define MBEDTLS_SSL_EARLY_DATA_STATUS_REJECTED 3 | ||||||||
#define MBEDTLS_SSL_EARLY_DATA_STATUS_ACCEPTED 4 | ||||||||
#endif | ||||||||
|
||||||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS) | ||||||||
typedef uint8_t mbedtls_ssl_tls13_ticket_flags; | ||||||||
|
||||||||
|
@@ -4897,6 +4890,151 @@ int mbedtls_ssl_send_alert_message( mbedtls_ssl_context *ssl, | |||||||
*/ | ||||||||
int mbedtls_ssl_close_notify( mbedtls_ssl_context *ssl ); | ||||||||
|
||||||||
#if defined(MBEDTLS_SSL_EARLY_DATA) | ||||||||
|
||||||||
#if defined(MBEDTLS_SSL_SRV_C) | ||||||||
/** | ||||||||
* \brief Read at most 'len' application data bytes while performing | ||||||||
* the handshake (early data). | ||||||||
* | ||||||||
* \note This function behaves mainly as mbedtls_ssl_read(). The | ||||||||
* specification of mbedtls_ssl_read() relevant to TLS 1.3 | ||||||||
* (thus not the parts specific to (D)TLS 1.2) applies to this | ||||||||
* function and the present documentation is restricted to the | ||||||||
* differences with mbedtls_ssl_read(). | ||||||||
* | ||||||||
* \param ssl SSL context | ||||||||
* \param buf buffer that will hold the data | ||||||||
* \param len maximum number of bytes to read | ||||||||
* | ||||||||
* \return One additional specific return value: | ||||||||
* #MBEDTLS_ERR_SSL_CANNOT_READ_EARLY_DATA. | ||||||||
* | ||||||||
* #MBEDTLS_ERR_SSL_CANNOT_READ_EARLY_DATA is returned when it | ||||||||
* is not possible to read early data for the SSL context | ||||||||
* \p ssl. | ||||||||
* | ||||||||
* It may have been possible and it is not possible | ||||||||
* anymore because the server received the End of Early Data | ||||||||
* message or the maximum number of allowed early data for the | ||||||||
* PSK in use has been reached. | ||||||||
* | ||||||||
* It may never have been possible and will never be possible | ||||||||
* for the SSL context \p ssl because the use of early data | ||||||||
* is disabled for that context or more generally the context | ||||||||
* is not suitably configured to enable early data or the | ||||||||
* client does not use early data or the first call to the | ||||||||
* function was done while the handshake was already too | ||||||||
* advanced to gather and accept early data. | ||||||||
* | ||||||||
* It is not possible to read early data for the SSL context | ||||||||
* \p ssl but this does not preclude for using it with | ||||||||
* mbedtls_ssl_write(), mbedtls_ssl_read() or | ||||||||
* mbedtls_ssl_handshake(). | ||||||||
* | ||||||||
* \note When a server wants to retrieve early data, it is expected | ||||||||
* that this function starts the handshake for the SSL context | ||||||||
* \p ssl. But this is not mandatory. | ||||||||
* | ||||||||
*/ | ||||||||
int mbedtls_ssl_read_early_data( mbedtls_ssl_context *ssl, | ||||||||
unsigned char *buf, size_t len ); | ||||||||
#endif /* MBEDTLS_SSL_SRV_C */ | ||||||||
|
||||||||
#if defined(MBEDTLS_SSL_CLI_C) | ||||||||
/** | ||||||||
* \brief Try to write exactly 'len' application data bytes while | ||||||||
* performing the handshake (early data). | ||||||||
* | ||||||||
* \note This function behaves mainly as mbedtls_ssl_write(). The | ||||||||
* specification of mbedtls_ssl_write() relevant to TLS 1.3 | ||||||||
* (thus not the parts specific to (D)TLS1.2) applies to this | ||||||||
* function and the present documentation is restricted to the | ||||||||
* differences with mbedtls_ssl_write(). | ||||||||
* | ||||||||
* \param ssl SSL context | ||||||||
* \param buf buffer holding the data | ||||||||
* \param len how many bytes must be written | ||||||||
* | ||||||||
* \return One additional specific return value: | ||||||||
* #MBEDTLS_ERR_SSL_CANNOT_WRITE_EARLY_DATA. | ||||||||
* | ||||||||
* #MBEDTLS_ERR_SSL_CANNOT_WRITE_EARLY_DATA is returned when it | ||||||||
* is not possible to write early data for the SSL context | ||||||||
* \p ssl. | ||||||||
* | ||||||||
* It may have been possible and it is not possible | ||||||||
* anymore because the client received the server Finished | ||||||||
* message, the server rejected early data or the maximum | ||||||||
* number of allowed early data for the PSK in use has been | ||||||||
* reached. | ||||||||
* | ||||||||
* It may never have been possible and will never be possible | ||||||||
* for the SSL context \p ssl because the use of early data | ||||||||
* is disabled for that context or more generally the context | ||||||||
* is not suitably configured to enable early data or the first | ||||||||
* call to the function was done while the handshake was | ||||||||
* already completed. | ||||||||
* | ||||||||
* It is not possible to write early data for the SSL context | ||||||||
* \p ssl but this does not preclude for using it with | ||||||||
* mbedtls_ssl_write(), mbedtls_ssl_read() or | ||||||||
* mbedtls_ssl_handshake(). | ||||||||
* | ||||||||
* \note This function may write early data only if the SSL context | ||||||||
* has been configured for the handshake with a PSK for which | ||||||||
* early data is allowed. | ||||||||
* | ||||||||
* \note To maximize the number of early data that can be written in | ||||||||
* the course of the handshake, it is expected that this | ||||||||
* function starts the handshake for the SSL context \p ssl. | ||||||||
* But this is not mandatory. | ||||||||
* | ||||||||
* \note This function does not provide any information on whether | ||||||||
* the server has accepted or will accept early data or not. | ||||||||
* When it returns a positive value, it just means that it | ||||||||
* has written early data to the server. To know whether the | ||||||||
* server has accepted early data or not, you should call | ||||||||
* mbedtls_ssl_get_early_data_status() with the handshake | ||||||||
* completed. | ||||||||
*/ | ||||||||
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 commentThe 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.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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
That's the plan like in There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 );
} |
||||||||
#define MBEDTLS_SSL_EARLY_DATA_STATUS_ACCEPTED 1 | ||||||||
#define MBEDTLS_SSL_EARLY_DATA_STATUS_REJECTED 2 | ||||||||
/** | ||||||||
* \brief Get the status of the negotiation of the use of early data. | ||||||||
* | ||||||||
* \param ssl The SSL context to query | ||||||||
* | ||||||||
* \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if this function is called | ||||||||
* from the server-side. | ||||||||
* | ||||||||
* \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if this function is called | ||||||||
* prior to completion of the handshake. | ||||||||
* | ||||||||
* \return #MBEDTLS_SSL_EARLY_DATA_STATUS_NOT_SENT if the client has | ||||||||
* not indicated the use of early data to the server. | ||||||||
yuhaoth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
* | ||||||||
* \return #MBEDTLS_SSL_EARLY_DATA_STATUS_ACCEPTED if the client has | ||||||||
* indicated the use of early data and the server has accepted | ||||||||
* it. | ||||||||
yuhaoth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
* | ||||||||
* \return #MBEDTLS_SSL_EARLY_DATA_STATUS_REJECTED if the client has | ||||||||
* indicated the use of early data but the server has rejected | ||||||||
* it. In this situation, the client may want to re-send the | ||||||||
* early data it may have tried to send by calling | ||||||||
* mbedtls_ssl_write_early_data() as ordinary post-handshake | ||||||||
* application data by calling mbedtls_ssl_write(). | ||||||||
yuhaoth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
* | ||||||||
*/ | ||||||||
int mbedtls_ssl_get_early_data_status( mbedtls_ssl_context *ssl ); | ||||||||
#endif /* MBEDTLS_SSL_CLI_C */ | ||||||||
|
||||||||
#endif /* MBEDTLS_SSL_EARLY_DATA */ | ||||||||
|
||||||||
/** | ||||||||
* \brief Free referenced items in an SSL context and clear memory | ||||||||
* | ||||||||
|
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 formbedtls_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 tombedtls_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
.