summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2019-01-20 02:57:16 +0000
committerjsing <>2019-01-20 02:57:16 +0000
commitb05e94746a653cd4b83bc444092de90f90e0ea88 (patch)
tree898b24ffa901db1a0e40faebcccb781d740463e0
parent3b92b80575a2a6534616ef86463ebb3c68dc1f62 (diff)
downloadopenbsd-b05e94746a653cd4b83bc444092de90f90e0ea88.tar.gz
openbsd-b05e94746a653cd4b83bc444092de90f90e0ea88.tar.bz2
openbsd-b05e94746a653cd4b83bc444092de90f90e0ea88.zip
Add some internal consistency checks to the handshake state handling.
Fix the tls13_handshake_advance_state_machine() return value, which inadvertantly got flipped in an earlier commit. Also move this function to a more suitable location. ok tb@
-rw-r--r--src/lib/libssl/tls13_handshake.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/lib/libssl/tls13_handshake.c b/src/lib/libssl/tls13_handshake.c
index 7798093def..9110c601c6 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.11 2019/01/20 02:08:05 tb Exp $ */ 1/* $OpenBSD: tls13_handshake.c,v 1.12 2019/01/20 02:57:16 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>
@@ -30,7 +30,7 @@
30/* Indexing into the state machine */ 30/* Indexing into the state machine */
31struct tls13_handshake { 31struct tls13_handshake {
32 uint8_t hs_type; 32 uint8_t hs_type;
33 int message_number; 33 uint8_t message_number;
34}; 34};
35 35
36struct tls13_ctx { 36struct tls13_ctx {
@@ -259,10 +259,18 @@ static enum tls13_message_type handshakes[][TLS13_NUM_MESSAGE_TYPES] = {
259 }, 259 },
260}; 260};
261 261
262#define NUM_HANDSHAKES (sizeof(handshakes) / sizeof(handshakes[0]))
263
262enum tls13_message_type 264enum tls13_message_type
263tls13_handshake_active_state(struct tls13_ctx *ctx) 265tls13_handshake_active_state(struct tls13_ctx *ctx)
264{ 266{
265 struct tls13_handshake hs = ctx->handshake; 267 struct tls13_handshake hs = ctx->handshake;
268
269 if (hs.hs_type >= NUM_HANDSHAKES)
270 return INVALID;
271 if (hs.message_number >= TLS13_NUM_MESSAGE_TYPES)
272 return INVALID;
273
266 return handshakes[hs.hs_type][hs.message_number]; 274 return handshakes[hs.hs_type][hs.message_number];
267} 275}
268 276
@@ -270,10 +278,23 @@ struct tls13_handshake_action *
270tls13_handshake_active_action(struct tls13_ctx *ctx) 278tls13_handshake_active_action(struct tls13_ctx *ctx)
271{ 279{
272 enum tls13_message_type mt = tls13_handshake_active_state(ctx); 280 enum tls13_message_type mt = tls13_handshake_active_state(ctx);
281
282 if (mt == INVALID)
283 return NULL;
284
273 return &state_machine[mt]; 285 return &state_machine[mt];
274} 286}
275 287
276int 288int
289tls13_handshake_advance_state_machine(struct tls13_ctx *ctx)
290{
291 if (++ctx->handshake.message_number >= TLS13_NUM_MESSAGE_TYPES)
292 return 0;
293
294 return 1;
295}
296
297int
277tls13_connect(struct tls13_ctx *ctx) 298tls13_connect(struct tls13_ctx *ctx)
278{ 299{
279 struct tls13_handshake_action *action; 300 struct tls13_handshake_action *action;
@@ -332,13 +353,6 @@ tls13_accept(struct tls13_ctx *ctx)
332} 353}
333 354
334int 355int
335tls13_handshake_advance_state_machine(struct tls13_ctx *ctx)
336{
337 ctx->handshake.message_number++;
338 return 0;
339}
340
341int
342tls13_handshake_send_action(struct tls13_ctx *ctx, 356tls13_handshake_send_action(struct tls13_ctx *ctx,
343 struct tls13_handshake_action *action) 357 struct tls13_handshake_action *action)
344{ 358{