@@ -7,26 +7,19 @@ Upstream-Status: Submitted [https://github.com/openssl/openssl/pull/22481]
77
88Signed-off-by: William Lyu <
[email protected] >
99---
10- test/helpers/handshake.c | 139 +++++++++++++++++++++++++++++----------
10+ test/helpers/handshake.c | 137 +++++++++++++++++++++++++++++----------
1111 test/helpers/handshake.h | 70 +++++++++++++++++++-
1212 test/ssl_test.c | 44 +++++++++++++
13- 3 files changed, 218 insertions(+), 35 deletions(-)
13+ 3 files changed, 217 insertions(+), 34 deletions(-)
1414
1515diff --git a/test/helpers/handshake.c b/test/helpers/handshake.c
16- index e0422469e4..ae2ad59dd4 100644
16+ index f611b3a..5703b48 100644
1717--- a/test/helpers/handshake.c
1818+++ b/test/helpers/handshake.c
19- @@ -1,5 +1,5 @@
20- /*
21- - * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22- + * Copyright 2016-2023 The OpenSSL Project Authors. All Rights Reserved.
23- *
24- * Licensed under the Apache License 2.0 (the "License"). You may not use
25- * this file except in compliance with the License. You can obtain a copy
2619@@ -24,6 +24,102 @@
2720 #include <netinet/sctp.h>
2821 #endif
29-
22+
3023+ /* Shamelessly copied from test/helpers/ssl_test_ctx.c */
3124+ /* Maps string names to various enumeration type */
3225+ typedef struct {
@@ -126,10 +119,10 @@ index e0422469e4..ae2ad59dd4 100644
126119 HANDSHAKE_RESULT *HANDSHAKE_RESULT_new(void)
127120 {
128121 HANDSHAKE_RESULT *ret;
129- @@ -719 ,15 +815 ,6 @@ static void configure_handshake_ssl(SSL *server, SSL *client,
122+ @@ -725 ,15 +821 ,6 @@ static void configure_handshake_ssl(SSL *server, SSL *client,
130123 SSL_set_post_handshake_auth(client, 1);
131124 }
132-
125+
133126- /* The status for each connection phase. */
134127- typedef enum {
135128- PEER_SUCCESS,
@@ -142,10 +135,10 @@ index e0422469e4..ae2ad59dd4 100644
142135 /* An SSL object and associated read-write buffers. */
143136 typedef struct peer_st {
144137 SSL *ssl;
145- @@ -1074 ,17 +1161 ,6 @@ static void do_shutdown_step(PEER *peer)
138+ @@ -1080 ,17 +1167 ,6 @@ static void do_shutdown_step(PEER *peer)
146139 }
147140 }
148-
141+
149142- typedef enum {
150143- HANDSHAKE,
151144- RENEG_APPLICATION_DATA,
@@ -160,10 +153,10 @@ index e0422469e4..ae2ad59dd4 100644
160153 static int renegotiate_op(const SSL_TEST_CTX *test_ctx)
161154 {
162155 switch (test_ctx->handshake_mode) {
163- @@ -1162 ,19 +1238 ,6 @@ static void do_connect_step(const SSL_TEST_CTX *test_ctx, PEER *peer,
156+ @@ -1168 ,19 +1244 ,6 @@ static void do_connect_step(const SSL_TEST_CTX *test_ctx, PEER *peer,
164157 }
165158 }
166-
159+
167160- typedef enum {
168161- /* Both parties succeeded. */
169162- HANDSHAKE_SUCCESS,
@@ -180,21 +173,21 @@ index e0422469e4..ae2ad59dd4 100644
180173 /*
181174 * Determine the handshake outcome.
182175 * last_status: the status of the peer to have acted last.
183- @@ -1539 ,6 +1602 ,10 @@ static HANDSHAKE_RESULT *do_handshake_internal(
184-
176+ @@ -1545 ,6 +1608 ,10 @@ static HANDSHAKE_RESULT *do_handshake_internal(
177+
185178 start = time(NULL);
186-
179+
187180+ save_loop_history(&(ret->history),
188181+ phase, status, server.status, client.status,
189182+ client_turn_count, client_turn);
190183+
191184 /*
192185 * Half-duplex handshake loop.
193186 * Client and server speak to each other synchronously in the same process.
194- @@ -1560 ,6 +1627 ,10 @@ static HANDSHAKE_RESULT *do_handshake_internal(
187+ @@ -1566 ,6 +1633 ,10 @@ static HANDSHAKE_RESULT *do_handshake_internal(
195188 0 /* server went last */);
196189 }
197-
190+
198191+ save_loop_history(&(ret->history),
199192+ phase, status, server.status, client.status,
200193+ client_turn_count, client_turn);
@@ -203,7 +196,7 @@ index e0422469e4..ae2ad59dd4 100644
203196 case HANDSHAKE_SUCCESS:
204197 client_turn_count = 0;
205198diff --git a/test/helpers/handshake.h b/test/helpers/handshake.h
206- index 78b03f9f4b..b9967c2623 100644
199+ index 78b03f9..b9967c2 100644
207200--- a/test/helpers/handshake.h
208201+++ b/test/helpers/handshake.h
209202@@ -1,5 +1,5 @@
@@ -214,9 +207,9 @@ index 78b03f9f4b..b9967c2623 100644
214207 * Licensed under the Apache License 2.0 (the "License"). You may not use
215208 * this file except in compliance with the License. You can obtain a copy
216209@@ -12,6 +12,11 @@
217-
210+
218211 #include "ssl_test_ctx.h"
219-
212+
220213+ #define MAX_HANDSHAKE_HISTORY_ENTRY_BIT 4
221214+ #define MAX_HANDSHAKE_HISTORY_ENTRY (1 << MAX_HANDSHAKE_HISTORY_ENTRY_BIT)
222215+ #define MAX_HANDSHAKE_HISTORY_ENTRY_IDX_MASK \
@@ -228,7 +221,7 @@ index 78b03f9f4b..b9967c2623 100644
228221@@ -22,6 +27,63 @@ typedef struct ctx_data_st {
229222 char *session_ticket_app_data;
230223 } CTX_DATA;
231-
224+
232225+ typedef enum {
233226+ HANDSHAKE,
234227+ RENEG_APPLICATION_DATA,
@@ -296,25 +289,25 @@ index 78b03f9f4b..b9967c2623 100644
296289+ /* handshake loop history */
297290+ HANDSHAKE_HISTORY history;
298291 } HANDSHAKE_RESULT;
299-
292+
300293 HANDSHAKE_RESULT *HANDSHAKE_RESULT_new(void);
301294@@ -95,4 +159,8 @@ int configure_handshake_ctx_for_srp(SSL_CTX *server_ctx, SSL_CTX *server2_ctx,
302295 CTX_DATA *server2_ctx_data,
303296 CTX_DATA *client_ctx_data);
304-
297+
305298+ const char *handshake_connect_phase_name(connect_phase_t phase);
306299+ const char *handshake_status_name(handshake_status_t handshake_status);
307300+ const char *handshake_peer_status_name(peer_status_t peer_status);
308301+
309302 #endif /* OSSL_TEST_HANDSHAKE_HELPER_H */
310303diff --git a/test/ssl_test.c b/test/ssl_test.c
311- index ea608518f9..9d6b093c81 100644
304+ index ea60851..9d6b093 100644
312305--- a/test/ssl_test.c
313306+++ b/test/ssl_test.c
314307@@ -26,6 +26,44 @@ static OSSL_LIB_CTX *libctx = NULL;
315308 /* Currently the section names are of the form test-<number>, e.g. test-15. */
316309 #define MAX_TESTCASE_NAME_LENGTH 100
317-
310+
318311+ static void print_handshake_history(const HANDSHAKE_HISTORY *history)
319312+ {
320313+ size_t first_idx;
0 commit comments