Add negative tolerance window
If `now == session->start` or the timer of
client is faster than server, client age might
be bigger than server.
Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
diff --git a/library/ssl_tls13_server.c b/library/ssl_tls13_server.c
index 67d685b..55cb670 100644
--- a/library/ssl_tls13_server.c
+++ b/library/ssl_tls13_server.c
@@ -136,7 +136,8 @@
unsigned char *ticket_buffer;
#if defined(MBEDTLS_HAVE_TIME)
mbedtls_time_t now;
- uint64_t age_in_s, age_in_ms, client_age_in_ms;
+ uint64_t age_in_s;
+ int64_t diff_in_ms;
#endif
((void) obfuscated_ticket_age);
@@ -220,15 +221,14 @@
* ticket_age_add from PskIdentity.obfuscated_ticket_age modulo 2^32) is
* within a small tolerance of the time since the ticket was issued.
*/
- age_in_ms = age_in_s * 1000;
- client_age_in_ms = obfuscated_ticket_age - session->ticket_age_add;
- if( age_in_ms < client_age_in_ms ||
- ( age_in_ms - client_age_in_ms ) > MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE )
+ diff_in_ms = age_in_s * 1000;
+ diff_in_ms -= ( obfuscated_ticket_age - session->ticket_age_add );
+ diff_in_ms += MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE / 2;
+ if( diff_in_ms < 0 || diff_in_ms > MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE )
{
MBEDTLS_SSL_DEBUG_MSG(
3, ( "Ticket expired: Ticket age outside tolerance window "
- "( diff=%d )",
- (int)(age_in_ms - client_age_in_ms ) ) );
+ "( diff=%d )", (int)diff_in_ms ) );
goto exit;
}