From 6a3d21ee5897c9a30ee70d2761440d723f0d4fa4 Mon Sep 17 00:00:00 2001 From: jsing Date: Sun, 17 Jul 2022 15:49:20 +0000 Subject: [PATCH] Pass SSL pointer to tls13_ctx_new(). struct tls13_ctx already knows about SSL's and this way tls13_ctx_new() can set up various pointers, rather than duplicating this in tls13_legacy_accept() and tls13_legacy_connect(). ok tb@ --- lib/libssl/tls13_internal.h | 4 ++-- lib/libssl/tls13_legacy.c | 14 +++----------- lib/libssl/tls13_lib.c | 8 ++++++-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/libssl/tls13_internal.h b/lib/libssl/tls13_internal.h index 75e13ac15df..555dd4262e5 100644 --- a/lib/libssl/tls13_internal.h +++ b/lib/libssl/tls13_internal.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_internal.h,v 1.97 2022/06/03 13:11:04 tb Exp $ */ +/* $OpenBSD: tls13_internal.h,v 1.98 2022/07/17 15:49:20 jsing Exp $ */ /* * Copyright (c) 2018 Bob Beck * Copyright (c) 2018 Theo Buehler @@ -292,7 +292,7 @@ struct tls13_ctx { #define TLS13_PHH_LIMIT 100 #endif -struct tls13_ctx *tls13_ctx_new(int mode); +struct tls13_ctx *tls13_ctx_new(int mode, SSL *ssl); void tls13_ctx_free(struct tls13_ctx *ctx); const EVP_AEAD *tls13_cipher_aead(const SSL_CIPHER *cipher); diff --git a/lib/libssl/tls13_legacy.c b/lib/libssl/tls13_legacy.c index 27e030fa772..545f2cd9783 100644 --- a/lib/libssl/tls13_legacy.c +++ b/lib/libssl/tls13_legacy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_legacy.c,v 1.37 2022/02/06 16:08:14 jsing Exp $ */ +/* $OpenBSD: tls13_legacy.c,v 1.38 2022/07/17 15:49:20 jsing Exp $ */ /* * Copyright (c) 2018, 2019 Joel Sing * @@ -414,14 +414,10 @@ tls13_legacy_accept(SSL *ssl) int ret; if (ctx == NULL) { - if ((ctx = tls13_ctx_new(TLS13_HS_SERVER)) == NULL) { + if ((ctx = tls13_ctx_new(TLS13_HS_SERVER, ssl)) == NULL) { SSLerror(ssl, ERR_R_INTERNAL_ERROR); /* XXX */ return -1; } - ssl->internal->tls13 = ctx; - ctx->ssl = ssl; - ctx->hs = &ssl->s3->hs; - if (!tls13_server_init(ctx)) { if (ERR_peek_error() == 0) SSLerror(ssl, ERR_R_INTERNAL_ERROR); /* XXX */ @@ -450,14 +446,10 @@ tls13_legacy_connect(SSL *ssl) int ret; if (ctx == NULL) { - if ((ctx = tls13_ctx_new(TLS13_HS_CLIENT)) == NULL) { + if ((ctx = tls13_ctx_new(TLS13_HS_CLIENT, ssl)) == NULL) { SSLerror(ssl, ERR_R_INTERNAL_ERROR); /* XXX */ return -1; } - ssl->internal->tls13 = ctx; - ctx->ssl = ssl; - ctx->hs = &ssl->s3->hs; - if (!tls13_client_init(ctx)) { if (ERR_peek_error() == 0) SSLerror(ssl, ERR_R_INTERNAL_ERROR); /* XXX */ diff --git a/lib/libssl/tls13_lib.c b/lib/libssl/tls13_lib.c index 20d3a38412b..8b8ea7f01b0 100644 --- a/lib/libssl/tls13_lib.c +++ b/lib/libssl/tls13_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_lib.c,v 1.63 2022/02/05 14:54:10 jsing Exp $ */ +/* $OpenBSD: tls13_lib.c,v 1.64 2022/07/17 15:49:20 jsing Exp $ */ /* * Copyright (c) 2018, 2019 Joel Sing * Copyright (c) 2019 Bob Beck @@ -382,14 +382,16 @@ static const struct tls13_record_layer_callbacks rl_callbacks = { }; struct tls13_ctx * -tls13_ctx_new(int mode) +tls13_ctx_new(int mode, SSL *ssl) { struct tls13_ctx *ctx = NULL; if ((ctx = calloc(sizeof(struct tls13_ctx), 1)) == NULL) goto err; + ctx->hs = &ssl->s3->hs; ctx->mode = mode; + ctx->ssl = ssl; if ((ctx->rl = tls13_record_layer_new(&rl_callbacks, ctx)) == NULL) goto err; @@ -401,6 +403,8 @@ tls13_ctx_new(int mode) ctx->middlebox_compat = 1; + ssl->internal->tls13 = ctx; + return ctx; err: -- 2.20.1