From a681313f9af157b0958be9fec2d8dffa5dac842d Mon Sep 17 00:00:00 2001 From: tb Date: Sat, 31 Aug 2024 09:21:44 +0000 Subject: [PATCH] Make CONF_METHOD opaque Much of conf is designed in such a way that you really have to reach into its structs. This one piece can be hidden. It might even be removed soon. ok beck jsing --- lib/libcrypto/Makefile | 3 +- lib/libcrypto/conf/conf.h | 15 +------ lib/libcrypto/conf/conf_api.c | 4 +- lib/libcrypto/conf/conf_def.c | 3 +- lib/libcrypto/conf/conf_lib.c | 4 +- lib/libcrypto/conf/conf_local.h | 79 +++++++++++++++++++++++++++++++++ lib/libcrypto/x509/x509_conf.c | 3 +- 7 files changed, 92 insertions(+), 19 deletions(-) create mode 100644 lib/libcrypto/conf/conf_local.h diff --git a/lib/libcrypto/Makefile b/lib/libcrypto/Makefile index b4407d566c1..e71f8b4bf43 100644 --- a/lib/libcrypto/Makefile +++ b/lib/libcrypto/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.203 2024/08/28 07:15:04 tb Exp $ +# $OpenBSD: Makefile,v 1.204 2024/08/31 09:21:44 tb Exp $ LIB= crypto LIBREBUILD=y @@ -31,6 +31,7 @@ CFLAGS+= -I${LCRYPTO_SRC}/bio CFLAGS+= -I${LCRYPTO_SRC}/bn CFLAGS+= -I${LCRYPTO_SRC}/bn/arch/${MACHINE_CPU} CFLAGS+= -I${LCRYPTO_SRC}/bytestring +CFLAGS+= -I${LCRYPTO_SRC}/conf CFLAGS+= -I${LCRYPTO_SRC}/curve25519 CFLAGS+= -I${LCRYPTO_SRC}/dh CFLAGS+= -I${LCRYPTO_SRC}/dsa diff --git a/lib/libcrypto/conf/conf.h b/lib/libcrypto/conf/conf.h index 7b30ad453db..5129a259b32 100644 --- a/lib/libcrypto/conf/conf.h +++ b/lib/libcrypto/conf/conf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.h,v 1.17 2024/08/31 09:18:00 tb Exp $ */ +/* $OpenBSD: conf.h,v 1.18 2024/08/31 09:21:44 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -85,19 +85,6 @@ struct conf_st; struct conf_method_st; typedef struct conf_method_st CONF_METHOD; -struct conf_method_st { - const char *name; - CONF *(*create)(CONF_METHOD *meth); - int (*init)(CONF *conf); - int (*destroy)(CONF *conf); - int (*destroy_data)(CONF *conf); - int (*load_bio)(CONF *conf, BIO *bp, long *eline); - int (*dump)(const CONF *conf, BIO *bp); - int (*is_number)(const CONF *conf, char c); - int (*to_int)(const CONF *conf, char c); - int (*load)(CONF *conf, const char *name, long *eline); -}; - /* Module definitions */ typedef struct conf_imodule_st CONF_IMODULE; diff --git a/lib/libcrypto/conf/conf_api.c b/lib/libcrypto/conf/conf_api.c index a94e8c8be0c..348c4ff7443 100644 --- a/lib/libcrypto/conf/conf_api.c +++ b/lib/libcrypto/conf/conf_api.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf_api.c,v 1.19 2024/07/14 14:32:45 jsing Exp $ */ +/* $OpenBSD: conf_api.c,v 1.20 2024/08/31 09:21:44 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -69,6 +69,8 @@ #include #include +#include "conf_local.h" + static void value_free_hash_doall_arg(CONF_VALUE *a, LHASH_OF(CONF_VALUE) *conf); static void value_free_stack_doall(CONF_VALUE *a); diff --git a/lib/libcrypto/conf/conf_def.c b/lib/libcrypto/conf/conf_def.c index 07f6eceaf13..4c644055a23 100644 --- a/lib/libcrypto/conf/conf_def.c +++ b/lib/libcrypto/conf/conf_def.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf_def.c,v 1.37 2024/08/28 15:48:33 tb Exp $ */ +/* $OpenBSD: conf_def.c,v 1.38 2024/08/31 09:21:44 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -69,6 +69,7 @@ #include #include "conf_def.h" +#include "conf_local.h" #define MAX_CONF_VALUE_LENGTH 65536 diff --git a/lib/libcrypto/conf/conf_lib.c b/lib/libcrypto/conf/conf_lib.c index 01735906c05..fca7486de37 100644 --- a/lib/libcrypto/conf/conf_lib.c +++ b/lib/libcrypto/conf/conf_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf_lib.c,v 1.18 2024/08/31 09:18:00 tb Exp $ */ +/* $OpenBSD: conf_lib.c,v 1.19 2024/08/31 09:21:44 tb Exp $ */ /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL * project 2000. */ @@ -63,6 +63,8 @@ #include #include +#include "conf_local.h" + static CONF_METHOD *default_CONF_method = NULL; /* Init a 'CONF' structure from an old LHASH */ diff --git a/lib/libcrypto/conf/conf_local.h b/lib/libcrypto/conf/conf_local.h new file mode 100644 index 00000000000..dec0d3c0c16 --- /dev/null +++ b/lib/libcrypto/conf/conf_local.h @@ -0,0 +1,79 @@ +/* $OpenBSD: conf_local.h,v 1.1 2024/08/31 09:21:44 tb Exp $ */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_CONF_LOCAL_H +#define HEADER_CONF_LOCAL_H + +__BEGIN_HIDDEN_DECLS + +struct conf_method_st { + const char *name; + CONF *(*create)(CONF_METHOD *meth); + int (*init)(CONF *conf); + int (*destroy)(CONF *conf); + int (*destroy_data)(CONF *conf); + int (*load_bio)(CONF *conf, BIO *bp, long *eline); + int (*dump)(const CONF *conf, BIO *bp); + int (*is_number)(const CONF *conf, char c); + int (*to_int)(const CONF *conf, char c); + int (*load)(CONF *conf, const char *name, long *eline); +}; + +__END_HIDDEN_DECLS + +#endif /* HEADER_CONF_LOCAL_H */ diff --git a/lib/libcrypto/x509/x509_conf.c b/lib/libcrypto/x509/x509_conf.c index 25f0ad0b263..27f89072c81 100644 --- a/lib/libcrypto/x509/x509_conf.c +++ b/lib/libcrypto/x509/x509_conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_conf.c,v 1.22 2024/08/28 08:59:03 tb Exp $ */ +/* $OpenBSD: x509_conf.c,v 1.23 2024/08/31 09:21:44 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 1999. */ @@ -66,6 +66,7 @@ #include #include +#include "conf_local.h" #include "x509_local.h" static int v3_check_critical(const char **value); -- 2.20.1