diff options
author | Jairus Christensen <christensenjairus@gmail.com> | 2023-02-27 09:36:15 -0700 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2023-06-02 05:46:46 +0200 |
commit | cee0628e0d53be82bd644ce258c3d3e90e64eced (patch) | |
tree | cec946b10eae236d4d425397a2512ab1cb25e8b6 /ssl | |
parent | fc570b2605b8eb18c3903543aaf0234b1f698c8e (diff) |
[feat] SSL RTT in both client and server statem. SSL_get_handshake_rtt makes it available
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/20248)
Diffstat (limited to 'ssl')
-rw-r--r-- | ssl/ssl_lib.c | 15 | ||||
-rw-r--r-- | ssl/ssl_local.h | 3 | ||||
-rw-r--r-- | ssl/statem/statem_clnt.c | 5 | ||||
-rw-r--r-- | ssl/statem/statem_srvr.c | 4 |
4 files changed, 27 insertions, 0 deletions
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 6848dbad7a..bad54e0955 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -4747,6 +4747,21 @@ const char *SSL_get_version(const SSL *s) return ssl_protocol_to_string(sc->version); } +__owur int SSL_get_handshake_rtt(const SSL *s, uint64_t *rtt) +{ + const SSL_CONNECTION *sc = SSL_CONNECTION_FROM_CONST_SSL(s); + + if (sc == NULL) + return -1; + if (sc->ts_msg_write.t <= 0 || sc->ts_msg_read.t <= 0) + return 0; /* data not (yet) available */ + if (sc->ts_msg_read.t < sc->ts_msg_write.t) + return -1; + + *rtt = ossl_time2us(ossl_time_subtract(sc->ts_msg_read, sc->ts_msg_write)); + return 1; +} + static int dup_ca_names(STACK_OF(X509_NAME) **dst, STACK_OF(X509_NAME) *src) { STACK_OF(X509_NAME) *sk; diff --git a/ssl/ssl_local.h b/ssl/ssl_local.h index 69a578dc5c..7ab84acc80 100644 --- a/ssl/ssl_local.h +++ b/ssl/ssl_local.h @@ -1249,6 +1249,9 @@ struct ssl_connection_st { int quiet_shutdown; /* we have shut things down, 0x01 sent, 0x02 for received */ int shutdown; + /* Timestamps used to calculate the handshake RTT */ + OSSL_TIME ts_msg_write; + OSSL_TIME ts_msg_read; /* where we are */ OSSL_STATEM statem; SSL_EARLY_DATA_STATE early_data_state; diff --git a/ssl/statem/statem_clnt.c b/ssl/statem/statem_clnt.c index e7a0d8ccfd..655b6ac17a 100644 --- a/ssl/statem/statem_clnt.c +++ b/ssl/statem/statem_clnt.c @@ -484,6 +484,8 @@ static WRITE_TRAN ossl_statem_client13_write_transition(SSL_CONNECTION *s) st->hand_state = TLS_ST_CW_COMP_CERT; else st->hand_state = TLS_ST_CW_CERT; + + s->ts_msg_read = ossl_time_now(); return WRITE_TRAN_CONTINUE; case TLS_ST_PENDING_EARLY_DATA_END: @@ -584,6 +586,7 @@ WRITE_TRAN ossl_statem_client_write_transition(SSL_CONNECTION *s) * No transition at the end of writing because we don't know what * we will be sent */ + s->ts_msg_write = ossl_time_now(); return WRITE_TRAN_FINISHED; case TLS_ST_CR_SRVR_HELLO: @@ -600,6 +603,7 @@ WRITE_TRAN ossl_statem_client_write_transition(SSL_CONNECTION *s) return WRITE_TRAN_CONTINUE; case TLS_ST_EARLY_DATA: + s->ts_msg_write = ossl_time_now(); return WRITE_TRAN_FINISHED; case DTLS_ST_CR_HELLO_VERIFY_REQUEST: @@ -607,6 +611,7 @@ WRITE_TRAN ossl_statem_client_write_transition(SSL_CONNECTION *s) return WRITE_TRAN_CONTINUE; case TLS_ST_CR_SRVR_DONE: + s->ts_msg_read = ossl_time_now(); if (s->s3.tmp.cert_req) st->hand_state = TLS_ST_CW_CERT; else diff --git a/ssl/statem/statem_srvr.c b/ssl/statem/statem_srvr.c index c33e8f64e9..6eb98040e8 100644 --- a/ssl/statem/statem_srvr.c +++ b/ssl/statem/statem_srvr.c @@ -547,12 +547,14 @@ static WRITE_TRAN ossl_statem_server13_write_transition(SSL_CONNECTION *s) case TLS_ST_SW_FINISHED: st->hand_state = TLS_ST_EARLY_DATA; + s->ts_msg_write = ossl_time_now(); return WRITE_TRAN_CONTINUE; case TLS_ST_EARLY_DATA: return WRITE_TRAN_FINISHED; case TLS_ST_SR_FINISHED: + s->ts_msg_read = ossl_time_now(); /* * Technically we have finished the handshake at this point, but we're * going to remain "in_init" for now and write out any session tickets @@ -702,9 +704,11 @@ WRITE_TRAN ossl_statem_server_write_transition(SSL_CONNECTION *s) return WRITE_TRAN_CONTINUE; case TLS_ST_SW_SRVR_DONE: + s->ts_msg_write = ossl_time_now(); return WRITE_TRAN_FINISHED; case TLS_ST_SR_FINISHED: + s->ts_msg_read = ossl_time_now(); if (s->hit) { st->hand_state = TLS_ST_OK; return WRITE_TRAN_CONTINUE; |