mirror of
https://github.com/openssl/openssl.git
synced 2025-03-13 19:47:47 +08:00
Let SSL_new_session_ticket() enter init immediately
The initial implementation always deferred the generation of the requested ticket(s) until the next application write, but this is not a great fit for what it actually does, architecturally wise. A request to send a session ticket means entering back into the handshake state machine (or "in init", as it's known in the implementation). The state machine transition is not something that only occurs at an application-data write, and in general could occur at any time. The only constraint is that we can't enter "init" while in the middle of writing application data. In such cases we will need to wait until the next TLS record boundary to enter the state machine, as is currently done. However, there is no reason why we cannot enter the handshake state machine immediately in SSL_new_session_ticket() if there are no application writes pending. Doing so provides a cleaner API surface to the application, as then calling SSL_do_handshake() suffices to drive the actual ticket generation. In the previous state of affairs a dummy zero-length SSL_write() would be needed to trigger the ticket generation, which is a logical mismatch in the type of operation being performed. This commit should only change whether SSL_do_handshake() vs zero-length SSL_write() is needed to immediately generate a ticket after the SSL_new_session_ticket() call -- the default behavior is still to defer the actual write until there is other application data to write, unless the application requests otherwise. Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14817)
This commit is contained in:
parent
e34e91d7e5
commit
7c73fefe38
@ -2327,10 +2327,14 @@ int SSL_renegotiate_pending(const SSL *s)
|
||||
|
||||
int SSL_new_session_ticket(SSL *s)
|
||||
{
|
||||
if (SSL_in_init(s) || SSL_IS_FIRST_HANDSHAKE(s) || !s->server
|
||||
/* If we are in init because we're sending tickets, okay to send more. */
|
||||
if ((SSL_in_init(s) && s->ext.extra_tickets_expected == 0)
|
||||
|| SSL_IS_FIRST_HANDSHAKE(s) || !s->server
|
||||
|| !SSL_IS_TLS13(s))
|
||||
return 0;
|
||||
s->ext.extra_tickets_expected++;
|
||||
if (s->rlayer.wbuf[0].left == 0 && !SSL_in_init(s))
|
||||
ossl_statem_set_in_init(s, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user