From 395120b4a264fb5eaadb4e8296f4d6bec2216b6b Mon Sep 17 00:00:00 2001 From: jsing <> Date: Mon, 25 Feb 2019 16:46:17 +0000 Subject: Add a handshake action sent handler and use it for client finished. The write traffic key needs to be changed to the client application traffic key after the client finished message has been sent. The send handler generates the client finished message, however we cannot switch keys at this stage since the client finished message has not yet been protected by the record layer. ok tb@ --- src/lib/libssl/tls13_client.c | 23 ++++++++++++++--------- src/lib/libssl/tls13_handshake.c | 7 ++++++- src/lib/libssl/tls13_internal.h | 3 ++- 3 files changed, 22 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/lib/libssl/tls13_client.c b/src/lib/libssl/tls13_client.c index 5071507bbd..728d1a00c8 100644 --- a/src/lib/libssl/tls13_client.c +++ b/src/lib/libssl/tls13_client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_client.c,v 1.11 2019/02/25 16:39:14 jsing Exp $ */ +/* $OpenBSD: tls13_client.c,v 1.12 2019/02/25 16:46:17 jsing Exp $ */ /* * Copyright (c) 2018, 2019 Joel Sing * @@ -687,14 +687,6 @@ tls13_client_finished_send(struct tls13_ctx *ctx) if (!tls13_handshake_msg_finish(ctx->hs_msg)) goto err; - /* - * Any records following the client finished message must be encrypted - * using the client application traffic keys. - */ - if (!tls13_record_layer_set_write_traffic_key(ctx->rl, - &secrets->client_application_traffic)) - goto err; - ret = 1; err: @@ -702,3 +694,16 @@ tls13_client_finished_send(struct tls13_ctx *ctx) return ret; } + +int +tls13_client_finished_sent(struct tls13_ctx *ctx) +{ + struct tls13_secrets *secrets = ctx->hs->secrets; + + /* + * Any records following the client finished message must be encrypted + * using the client application traffic keys. + */ + return tls13_record_layer_set_write_traffic_key(ctx->rl, + &secrets->client_application_traffic); +} diff --git a/src/lib/libssl/tls13_handshake.c b/src/lib/libssl/tls13_handshake.c index aeb490f350..598a7c1666 100644 --- a/src/lib/libssl/tls13_handshake.c +++ b/src/lib/libssl/tls13_handshake.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_handshake.c,v 1.28 2019/02/14 18:06:35 jsing Exp $ */ +/* $OpenBSD: tls13_handshake.c,v 1.29 2019/02/25 16:46:17 jsing Exp $ */ /* * Copyright (c) 2018-2019 Theo Buehler * Copyright (c) 2019 Joel Sing @@ -36,6 +36,7 @@ struct tls13_handshake_action { uint8_t preserve_transcript_hash; int (*send)(struct tls13_ctx *ctx); + int (*sent)(struct tls13_ctx *ctx); int (*recv)(struct tls13_ctx *ctx); }; @@ -93,6 +94,7 @@ struct tls13_handshake_action state_machine[] = { .handshake_type = TLS13_MT_FINISHED, .sender = TLS13_HS_CLIENT, .send = tls13_client_finished_send, + .sent = tls13_client_finished_sent, .recv = tls13_client_finished_recv, }, [CLIENT_KEY_UPDATE] = { @@ -347,6 +349,9 @@ tls13_handshake_send_action(struct tls13_ctx *ctx, tls13_handshake_msg_free(ctx->hs_msg); ctx->hs_msg = NULL; + if (action->sent != NULL && !action->sent(ctx)) + return TLS13_IO_FAILURE; + return TLS13_IO_SUCCESS; } diff --git a/src/lib/libssl/tls13_internal.h b/src/lib/libssl/tls13_internal.h index 0e26d9c01c..b3b510c690 100644 --- a/src/lib/libssl/tls13_internal.h +++ b/src/lib/libssl/tls13_internal.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_internal.h,v 1.21 2019/02/25 14:36:25 inoguchi Exp $ */ +/* $OpenBSD: tls13_internal.h,v 1.22 2019/02/25 16:46:17 jsing Exp $ */ /* * Copyright (c) 2018 Bob Beck * Copyright (c) 2018 Theo Buehler @@ -244,6 +244,7 @@ int tls13_client_certificate_verify_send(struct tls13_ctx *ctx); int tls13_client_certificate_verify_recv(struct tls13_ctx *ctx); int tls13_client_finished_recv(struct tls13_ctx *ctx); int tls13_client_finished_send(struct tls13_ctx *ctx); +int tls13_client_finished_sent(struct tls13_ctx *ctx); int tls13_client_key_update_send(struct tls13_ctx *ctx); int tls13_client_key_update_recv(struct tls13_ctx *ctx); int tls13_server_hello_recv(struct tls13_ctx *ctx); -- cgit v1.2.3-55-g6feb