summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2019-01-21 10:44:08 +0000
committerjsing <>2019-01-21 10:44:08 +0000
commitdacdef0bd14d3205fd8b9a76fa9f8f2d56946ce4 (patch)
tree2d62fadb51ad002be7e5cba46dd5f6f31c36c111 /src/lib
parent99fe8b99380227d1dceddd13bd867d7abb47184e (diff)
downloadopenbsd-dacdef0bd14d3205fd8b9a76fa9f8f2d56946ce4.tar.gz
openbsd-dacdef0bd14d3205fd8b9a76fa9f8f2d56946ce4.tar.bz2
openbsd-dacdef0bd14d3205fd8b9a76fa9f8f2d56946ce4.zip
The main handshake loop can be shared between client and server.
Pull the shared code up into a function and call it from tls13_connect() and tls13_accept() instead of duplicating it. "Yes, please!" tb@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libssl/tls13_handshake.c40
-rw-r--r--src/lib/libssl/tls13_internal.h4
2 files changed, 15 insertions, 29 deletions
diff --git a/src/lib/libssl/tls13_handshake.c b/src/lib/libssl/tls13_handshake.c
index 92780bb2f2..9e17fd1351 100644
--- a/src/lib/libssl/tls13_handshake.c
+++ b/src/lib/libssl/tls13_handshake.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_handshake.c,v 1.15 2019/01/21 06:58:44 jsing Exp $ */ 1/* $OpenBSD: tls13_handshake.c,v 1.16 2019/01/21 10:44:08 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2018-2019 Theo Buehler <tb@openbsd.org> 3 * Copyright (c) 2018-2019 Theo Buehler <tb@openbsd.org>
4 * Copyright (c) 2019 Joel Sing <jsing@openbsd.org> 4 * Copyright (c) 2019 Joel Sing <jsing@openbsd.org>
@@ -286,13 +286,11 @@ tls13_handshake_advance_state_machine(struct tls13_ctx *ctx)
286} 286}
287 287
288int 288int
289tls13_connect(struct tls13_ctx *ctx) 289tls13_handshake_perform(struct tls13_ctx *ctx)
290{ 290{
291 struct tls13_handshake_action *action; 291 struct tls13_handshake_action *action;
292 int ret; 292 int ret;
293 293
294 ctx->mode = TLS13_HS_CLIENT;
295
296 for (;;) { 294 for (;;) {
297 if ((action = tls13_handshake_active_action(ctx)) == NULL) 295 if ((action = tls13_handshake_active_action(ctx)) == NULL)
298 return TLS13_IO_FAILURE; 296 return TLS13_IO_FAILURE;
@@ -300,7 +298,7 @@ tls13_connect(struct tls13_ctx *ctx)
300 if (action->handshake_complete) 298 if (action->handshake_complete)
301 return TLS13_IO_SUCCESS; 299 return TLS13_IO_SUCCESS;
302 300
303 if (action->sender == TLS13_HS_CLIENT) { 301 if (action->sender == ctx->mode) {
304 if ((ret = tls13_handshake_send_action(ctx, action)) <= 0) 302 if ((ret = tls13_handshake_send_action(ctx, action)) <= 0)
305 return ret; 303 return ret;
306 } else { 304 } else {
@@ -314,33 +312,19 @@ tls13_connect(struct tls13_ctx *ctx)
314} 312}
315 313
316int 314int
317tls13_accept(struct tls13_ctx *ctx) 315tls13_connect(struct tls13_ctx *ctx)
318{ 316{
319 struct tls13_handshake_action *action; 317 ctx->mode = TLS13_HS_CLIENT;
320 int ret;
321
322 ctx->mode = TLS13_HS_SERVER;
323
324 for (;;) {
325 if ((action = tls13_handshake_active_action(ctx)) == NULL)
326 return TLS13_IO_FAILURE;
327
328 if (action->handshake_complete)
329 return TLS13_IO_SUCCESS;
330 318
331 if (action->sender == TLS13_HS_SERVER) { 319 return tls13_handshake_perform(ctx);
332 if ((ret = tls13_handshake_send_action(ctx, action)) <= 0) 320}
333 return ret;
334 } else {
335 if ((ret = tls13_handshake_recv_action(ctx, action)) <= 0)
336 return ret;
337 }
338 321
339 if (!tls13_handshake_advance_state_machine(ctx)) 322int
340 return TLS13_IO_FAILURE; 323tls13_accept(struct tls13_ctx *ctx)
341 } 324{
325 ctx->mode = TLS13_HS_SERVER;
342 326
343 return 1; 327 return tls13_handshake_perform(ctx);
344} 328}
345 329
346int 330int
diff --git a/src/lib/libssl/tls13_internal.h b/src/lib/libssl/tls13_internal.h
index 03fdab7e53..03de0fc40e 100644
--- a/src/lib/libssl/tls13_internal.h
+++ b/src/lib/libssl/tls13_internal.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_internal.h,v 1.12 2019/01/21 09:10:58 jsing Exp $ */ 1/* $OpenBSD: tls13_internal.h,v 1.13 2019/01/21 10:44:08 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2018 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2018 Bob Beck <beck@openbsd.org>
4 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> 4 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
@@ -186,6 +186,8 @@ int tls13_legacy_write_bytes(SSL *ssl, int type, const void *buf, int len);
186#define TLS13_MT_KEY_UPDATE 24 186#define TLS13_MT_KEY_UPDATE 24
187#define TLS13_MT_MESSAGE_HASH 254 187#define TLS13_MT_MESSAGE_HASH 254
188 188
189int tls13_handshake_perform(struct tls13_ctx *ctx);
190
189int tls13_client_hello_send(struct tls13_ctx *ctx); 191int tls13_client_hello_send(struct tls13_ctx *ctx);
190int tls13_client_hello_recv(struct tls13_ctx *ctx); 192int tls13_client_hello_recv(struct tls13_ctx *ctx);
191int tls13_client_hello_retry_send(struct tls13_ctx *ctx); 193int tls13_client_hello_retry_send(struct tls13_ctx *ctx);