2 * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 * We need access to the deprecated low level HMAC APIs for legacy purposes
12 * when the deprecated calls are not hidden
14 #ifndef OPENSSL_NO_DEPRECATED_3_0
15 # define OPENSSL_SUPPRESS_DEPRECATED
21 #include <openssl/opensslconf.h>
22 #include <openssl/bio.h>
23 #include <openssl/crypto.h>
24 #include <openssl/ssl.h>
25 #include <openssl/engine.h>
27 #include "helpers/ssltestlib.h"
29 #include "testutil/output.h"
30 #include "internal/ktls.h"
31 #include "../ssl/ssl_local.h"
32 #include "../ssl/statem/statem_local.h"
34 static OSSL_LIB_CTX *libctx = NULL;
35 static char *cert = NULL;
36 static char *privkey = NULL;
39 * Test 0: Clientside handshake RTT (TLSv1.2)
40 * Test 1: Serverside handshake RTT (TLSv1.2)
41 * Test 2: Clientside handshake RTT (TLSv1.3)
42 * Test 3: Serverside handshake RTT (TLSv1.3)
43 * Test 4: Clientside handshake RTT with Early Data (TLSv1.3)
45 static int test_handshake_rtt(int tst)
47 SSL_CTX *cctx = NULL, *sctx = NULL;
48 SSL *clientssl = NULL, *serverssl = NULL;
50 SSL_CONNECTION *s = NULL;
51 OSSL_STATEM *st = NULL;
54 #ifdef OPENSSL_NO_TLS1_2
58 #ifdef OSSL_NO_USABLE_TLS1_3
63 if (!TEST_true(create_ssl_ctx_pair(libctx, TLS_server_method(),
66 (tst <= 1) ? TLS1_2_VERSION
68 &sctx, &cctx, cert, privkey))
69 || !TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
73 s = SSL_CONNECTION_FROM_SSL(tst % 2 == 0 ? clientssl : serverssl);
74 if (!TEST_ptr(s) || !TEST_ptr(st = &s->statem))
77 /* implicitly set handshake rtt with a delay */
80 st->hand_state = TLS_ST_CW_CLNT_HELLO;
81 ossl_statem_client_write_transition(s);
83 st->hand_state = TLS_ST_CR_SRVR_DONE;
84 ossl_statem_client_write_transition(s);
87 st->hand_state = TLS_ST_SW_SRVR_DONE;
88 ossl_statem_server_write_transition(s);
90 st->hand_state = TLS_ST_SR_FINISHED;
91 ossl_statem_server_write_transition(s);
94 st->hand_state = TLS_ST_CW_CLNT_HELLO;
95 ossl_statem_client_write_transition(s);
97 st->hand_state = TLS_ST_CR_SRVR_DONE;
98 ossl_statem_client_write_transition(s);
101 st->hand_state = TLS_ST_SW_SRVR_DONE;
102 ossl_statem_server_write_transition(s);
104 st->hand_state = TLS_ST_SR_FINISHED;
105 ossl_statem_server_write_transition(s);
108 st->hand_state = TLS_ST_EARLY_DATA;
109 ossl_statem_client_write_transition(s);
111 st->hand_state = TLS_ST_CR_SRVR_DONE;
112 ossl_statem_client_write_transition(s);
116 if (!TEST_int_gt(SSL_get_handshake_rtt(SSL_CONNECTION_GET_SSL(s), &rtt), 0))
118 /* 1 millisec is the absolute minimum it could be given the delay */
119 if (!TEST_uint64_t_ge(rtt, 1000))
133 int setup_tests(void)
135 ADD_ALL_TESTS(test_handshake_rtt, 5);