From: tb Date: Fri, 28 Jul 2023 09:58:30 +0000 (+0000) Subject: Make ASN.1 BIO internal X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=859caa332e6ddb5c421d0566d9cfa5e301f2801a;p=openbsd Make ASN.1 BIO internal With every bump we can remove a bit more of the ASN.1 BIO and the streaming interface. At some point enough will be internal so that we can rewrite it and bring it in a shape where mere mortals can follow all the twists and turns. This is the next step: BIO_f_asn1(3) goes away and takes BIO_asn1_{get,set}_{prefix,suffix}() with it, a bunch of functions helping along in a write-after-free recently. The getters go away, the setters stay for now. ok jsing --- diff --git a/lib/libcrypto/Symbols.list b/lib/libcrypto/Symbols.list index d0484a5d4ca..7dabfa1188b 100644 --- a/lib/libcrypto/Symbols.list +++ b/lib/libcrypto/Symbols.list @@ -253,10 +253,6 @@ BIGNUM_it BIO_CONNECT_free BIO_CONNECT_new BIO_accept -BIO_asn1_get_prefix -BIO_asn1_get_suffix -BIO_asn1_set_prefix -BIO_asn1_set_suffix BIO_callback_ctrl BIO_clear_flags BIO_copy_next_retry @@ -275,7 +271,6 @@ BIO_dump_indent BIO_dump_indent_cb BIO_dump_indent_fp BIO_dup_chain -BIO_f_asn1 BIO_f_base64 BIO_f_buffer BIO_f_cipher diff --git a/lib/libcrypto/Symbols.namespace b/lib/libcrypto/Symbols.namespace index b8ca3539ec6..d1afd92c081 100644 --- a/lib/libcrypto/Symbols.namespace +++ b/lib/libcrypto/Symbols.namespace @@ -1120,7 +1120,6 @@ _libre_ASN1_PCTX_get_oid_flags _libre_ASN1_PCTX_set_oid_flags _libre_ASN1_PCTX_get_str_flags _libre_ASN1_PCTX_set_str_flags -_libre_BIO_f_asn1 _libre_SMIME_crlf_copy _libre_SMIME_text _libre_ERR_load_ASN1_strings @@ -1164,10 +1163,6 @@ _libre_BIO_set_ex_data _libre_BIO_get_ex_data _libre_BIO_number_read _libre_BIO_number_written -_libre_BIO_asn1_set_prefix -_libre_BIO_asn1_get_prefix -_libre_BIO_asn1_set_suffix -_libre_BIO_asn1_get_suffix _libre_BIO_get_new_index _libre_BIO_s_file _libre_BIO_new_file diff --git a/lib/libcrypto/asn1/asn1.h b/lib/libcrypto/asn1/asn1.h index 5be4668be0a..fbc5d098d8b 100644 --- a/lib/libcrypto/asn1/asn1.h +++ b/lib/libcrypto/asn1/asn1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1.h,v 1.76 2023/04/25 19:08:30 tb Exp $ */ +/* $OpenBSD: asn1.h,v 1.77 2023/07/28 09:58:30 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -922,8 +922,6 @@ void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags); unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p); void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags); -const BIO_METHOD *BIO_f_asn1(void); - int SMIME_crlf_copy(BIO *in, BIO *out, int flags); int SMIME_text(BIO *in, BIO *out); diff --git a/lib/libcrypto/asn1/asn1_local.h b/lib/libcrypto/asn1/asn1_local.h index 52b8a46aebe..0ef5101fcbe 100644 --- a/lib/libcrypto/asn1/asn1_local.h +++ b/lib/libcrypto/asn1/asn1_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1_local.h,v 1.2 2023/04/25 19:08:30 tb Exp $ */ +/* $OpenBSD: asn1_local.h,v 1.3 2023/07/28 09:58:30 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -250,6 +250,8 @@ int asn1_time_tm_to_time_t(const struct tm *tm, time_t *out); int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it); +const BIO_METHOD *BIO_f_asn1(void); + BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it); int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, diff --git a/lib/libcrypto/asn1/bio_asn1.c b/lib/libcrypto/asn1/bio_asn1.c index e544bf9c9c2..b9f54cd4ef6 100644 --- a/lib/libcrypto/asn1/bio_asn1.c +++ b/lib/libcrypto/asn1/bio_asn1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bio_asn1.c,v 1.22 2023/07/05 21:23:36 beck Exp $ */ +/* $OpenBSD: bio_asn1.c,v 1.23 2023/07/28 09:58:30 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. */ @@ -69,6 +69,9 @@ #include "bio_local.h" +#define BIO_C_SET_PREFIX 149 +#define BIO_C_SET_SUFFIX 151 + /* Must be large enough for biggest tag+length */ #define DEFAULT_ASN1_BUF_SIZE 20 @@ -144,7 +147,6 @@ BIO_f_asn1(void) { return (&methods_asn1); } -LCRYPTO_ALIAS(BIO_f_asn1); static int asn1_bio_new(BIO *b) @@ -376,24 +378,12 @@ asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) ctx->prefix_free = ex_func->ex_free_func; break; - case BIO_C_GET_PREFIX: - ex_func = arg2; - ex_func->ex_func = ctx->prefix; - ex_func->ex_free_func = ctx->prefix_free; - break; - case BIO_C_SET_SUFFIX: ex_func = arg2; ctx->suffix = ex_func->ex_func; ctx->suffix_free = ex_func->ex_free_func; break; - case BIO_C_GET_SUFFIX: - ex_func = arg2; - ex_func->ex_func = ctx->suffix; - ex_func->ex_free_func = ctx->suffix_free; - break; - case BIO_C_SET_EX_ARG: ctx->ex_arg = arg2; break; @@ -450,46 +440,14 @@ asn1_bio_set_ex(BIO *b, int cmd, asn1_ps_func *ex_func, asn1_ps_func return BIO_ctrl(b, cmd, 0, &extmp); } -static int -asn1_bio_get_ex(BIO *b, int cmd, asn1_ps_func **ex_func, - asn1_ps_func **ex_free_func) -{ - BIO_ASN1_EX_FUNCS extmp; - int ret; - - if ((ret = BIO_ctrl(b, cmd, 0, &extmp)) <= 0) - return ret; - - *ex_func = extmp.ex_func; - *ex_free_func = extmp.ex_free_func; - - return ret; -} - int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free) { return asn1_bio_set_ex(b, BIO_C_SET_PREFIX, prefix, prefix_free); } -LCRYPTO_ALIAS(BIO_asn1_set_prefix); - -int -BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, asn1_ps_func **pprefix_free) -{ - return asn1_bio_get_ex(b, BIO_C_GET_PREFIX, pprefix, pprefix_free); -} -LCRYPTO_ALIAS(BIO_asn1_get_prefix); int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free) { return asn1_bio_set_ex(b, BIO_C_SET_SUFFIX, suffix, suffix_free); } -LCRYPTO_ALIAS(BIO_asn1_set_suffix); - -int -BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, asn1_ps_func **psuffix_free) -{ - return asn1_bio_get_ex(b, BIO_C_GET_SUFFIX, psuffix, psuffix_free); -} -LCRYPTO_ALIAS(BIO_asn1_get_suffix); diff --git a/lib/libcrypto/asn1/bio_ndef.c b/lib/libcrypto/asn1/bio_ndef.c index 11e51edade3..98bb1cd1975 100644 --- a/lib/libcrypto/asn1/bio_ndef.c +++ b/lib/libcrypto/asn1/bio_ndef.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bio_ndef.c,v 1.23 2023/07/09 19:22:43 tb Exp $ */ +/* $OpenBSD: bio_ndef.c,v 1.24 2023/07/28 09:58:30 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. */ @@ -61,6 +61,9 @@ #include "asn1_local.h" +int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free); +int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free); + /* Experimental NDEF ASN1 BIO support routines */ /* The usage is quite simple, initialize an ASN1 structure, diff --git a/lib/libcrypto/bio/bio.h b/lib/libcrypto/bio/bio.h index 124690b1ee5..8450780f69e 100644 --- a/lib/libcrypto/bio/bio.h +++ b/lib/libcrypto/bio/bio.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bio.h,v 1.58 2023/07/05 19:25:01 tb Exp $ */ +/* $OpenBSD: bio.h,v 1.59 2023/07/28 09:58:30 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -371,11 +371,6 @@ int BIO_meth_set_callback_ctrl(BIO_METHOD *biom, #define BIO_C_RESET_READ_REQUEST 147 #define BIO_C_SET_MD_CTX 148 -#define BIO_C_SET_PREFIX 149 -#define BIO_C_GET_PREFIX 150 -#define BIO_C_SET_SUFFIX 151 -#define BIO_C_GET_SUFFIX 152 - #define BIO_C_SET_EX_ARG 153 #define BIO_C_GET_EX_ARG 154 @@ -535,16 +530,6 @@ CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); unsigned long BIO_number_read(BIO *bio); unsigned long BIO_number_written(BIO *bio); -/* For BIO_f_asn1() */ -int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, -asn1_ps_func *prefix_free); -int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, -asn1_ps_func **pprefix_free); -int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, -asn1_ps_func *suffix_free); -int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, -asn1_ps_func **psuffix_free); - int BIO_get_new_index(void); const BIO_METHOD *BIO_s_file(void); BIO *BIO_new_file(const char *filename, const char *mode); diff --git a/lib/libcrypto/hidden/openssl/asn1.h b/lib/libcrypto/hidden/openssl/asn1.h index 7e41ec862c2..e3095e0631d 100644 --- a/lib/libcrypto/hidden/openssl/asn1.h +++ b/lib/libcrypto/hidden/openssl/asn1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1.h,v 1.2 2023/07/07 19:37:54 beck Exp $ */ +/* $OpenBSD: asn1.h,v 1.3 2023/07/28 09:58:30 tb Exp $ */ /* * Copyright (c) 2023 Bob Beck * @@ -250,7 +250,6 @@ LCRYPTO_USED(ASN1_PCTX_get_oid_flags); LCRYPTO_USED(ASN1_PCTX_set_oid_flags); LCRYPTO_USED(ASN1_PCTX_get_str_flags); LCRYPTO_USED(ASN1_PCTX_set_str_flags); -LCRYPTO_USED(BIO_f_asn1); LCRYPTO_USED(SMIME_crlf_copy); LCRYPTO_USED(SMIME_text); LCRYPTO_USED(ERR_load_ASN1_strings); diff --git a/lib/libcrypto/hidden/openssl/bio.h b/lib/libcrypto/hidden/openssl/bio.h index c04a0a447f4..46cbdf72fec 100644 --- a/lib/libcrypto/hidden/openssl/bio.h +++ b/lib/libcrypto/hidden/openssl/bio.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bio.h,v 1.2 2023/07/07 19:37:54 beck Exp $ */ +/* $OpenBSD: bio.h,v 1.3 2023/07/28 09:58:30 tb Exp $ */ /* * Copyright (c) 2023 Bob Beck * @@ -63,10 +63,6 @@ LCRYPTO_USED(BIO_set_ex_data); LCRYPTO_USED(BIO_get_ex_data); LCRYPTO_USED(BIO_number_read); LCRYPTO_USED(BIO_number_written); -LCRYPTO_USED(BIO_asn1_set_prefix); -LCRYPTO_USED(BIO_asn1_get_prefix); -LCRYPTO_USED(BIO_asn1_set_suffix); -LCRYPTO_USED(BIO_asn1_get_suffix); LCRYPTO_USED(BIO_get_new_index); LCRYPTO_USED(BIO_s_file); LCRYPTO_USED(BIO_new_file);