From 40ae7d6bc66d03e54ad7f33a82a1e22aa4b447ca Mon Sep 17 00:00:00 2001 From: joshua Date: Tue, 26 Mar 2024 08:54:48 +0000 Subject: [PATCH] Add TLS_ERROR_INVALID_CONTEXT error code to libtls ok jsing@ beck@ --- lib/libtls/tls.c | 6 +++--- lib/libtls/tls.h | 3 ++- lib/libtls/tls_client.c | 11 +++++++---- lib/libtls/tls_server.c | 7 ++++--- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/libtls/tls.c b/lib/libtls/tls.c index 8433f556bf0..a8b03f0d4a1 100644 --- a/lib/libtls/tls.c +++ b/lib/libtls/tls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls.c,v 1.101 2024/03/26 06:24:52 joshua Exp $ */ +/* $OpenBSD: tls.c,v 1.102 2024/03/26 08:54:48 joshua Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -821,7 +821,7 @@ tls_handshake(struct tls *ctx) tls_error_clear(&ctx->error); if ((ctx->flags & (TLS_CLIENT | TLS_SERVER_CONN)) == 0) { - tls_set_errorx(ctx, TLS_ERROR_UNKNOWN, + tls_set_errorx(ctx, TLS_ERROR_INVALID_CONTEXT, "invalid operation for context"); goto out; } @@ -924,7 +924,7 @@ tls_close(struct tls *ctx) tls_error_clear(&ctx->error); if ((ctx->flags & (TLS_CLIENT | TLS_SERVER_CONN)) == 0) { - tls_set_errorx(ctx, TLS_ERROR_UNKNOWN, + tls_set_errorx(ctx, TLS_ERROR_INVALID_CONTEXT, "invalid operation for context"); rv = -1; goto out; diff --git a/lib/libtls/tls.h b/lib/libtls/tls.h index 0113c1c67f0..b69c4af58c0 100644 --- a/lib/libtls/tls.h +++ b/lib/libtls/tls.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tls.h,v 1.64 2024/03/26 06:24:52 joshua Exp $ */ +/* $OpenBSD: tls.h,v 1.65 2024/03/26 08:54:48 joshua Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -80,6 +80,7 @@ extern "C" { #if defined(LIBRESSL_NEXT_API) || defined(LIBRESSL_INTERNAL) #define TLS_ERROR_UNKNOWN 0x0000 #define TLS_ERROR_OUT_OF_MEMORY 0x1000 +#define TLS_ERROR_INVALID_CONTEXT 0x2000 #endif struct tls; diff --git a/lib/libtls/tls_client.c b/lib/libtls/tls_client.c index 40ef9a02e21..97e1d402105 100644 --- a/lib/libtls/tls_client.c +++ b/lib/libtls/tls_client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls_client.c,v 1.50 2024/03/26 06:24:52 joshua Exp $ */ +/* $OpenBSD: tls_client.c,v 1.51 2024/03/26 08:54:48 joshua Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -66,7 +66,8 @@ tls_connect_servername(struct tls *ctx, const char *host, const char *port, int rv = -1, s = -1, ret; if ((ctx->flags & TLS_CLIENT) == 0) { - tls_set_errorx(ctx, TLS_ERROR_UNKNOWN, "not a client context"); + tls_set_errorx(ctx, TLS_ERROR_INVALID_CONTEXT, + "not a client context"); goto err; } @@ -292,7 +293,8 @@ tls_connect_common(struct tls *ctx, const char *servername) int rv = -1; if ((ctx->flags & TLS_CLIENT) == 0) { - tls_set_errorx(ctx, TLS_ERROR_UNKNOWN, "not a client context"); + tls_set_errorx(ctx, TLS_ERROR_INVALID_CONTEXT, + "not a client context"); goto err; } @@ -456,7 +458,8 @@ tls_handshake_client(struct tls *ctx) int rv = -1; if ((ctx->flags & TLS_CLIENT) == 0) { - tls_set_errorx(ctx, TLS_ERROR_UNKNOWN, "not a client context"); + tls_set_errorx(ctx, TLS_ERROR_INVALID_CONTEXT, + "not a client context"); goto err; } diff --git a/lib/libtls/tls_server.c b/lib/libtls/tls_server.c index a42985744b7..a94b4221ed6 100644 --- a/lib/libtls/tls_server.c +++ b/lib/libtls/tls_server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls_server.c,v 1.50 2024/03/26 06:24:52 joshua Exp $ */ +/* $OpenBSD: tls_server.c,v 1.51 2024/03/26 08:54:48 joshua Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -372,7 +372,8 @@ tls_accept_common(struct tls *ctx) struct tls *conn_ctx = NULL; if ((ctx->flags & TLS_SERVER) == 0) { - tls_set_errorx(ctx, TLS_ERROR_UNKNOWN, "not a server context"); + tls_set_errorx(ctx, TLS_ERROR_INVALID_CONTEXT, + "not a server context"); goto err; } @@ -461,7 +462,7 @@ tls_handshake_server(struct tls *ctx) int rv = -1; if ((ctx->flags & TLS_SERVER_CONN) == 0) { - tls_set_errorx(ctx, TLS_ERROR_UNKNOWN, + tls_set_errorx(ctx, TLS_ERROR_INVALID_CONTEXT, "not a server connection context"); goto err; } -- 2.20.1