Remove ASN.1 combining.
authorjsing <jsing@openbsd.org>
Tue, 10 May 2022 05:19:22 +0000 (05:19 +0000)
committerjsing <jsing@openbsd.org>
Tue, 10 May 2022 05:19:22 +0000 (05:19 +0000)
This was an option used to combine ASN.1 into a single structure, which was
only ever used by DSAPublicKey and X509_ATTRIBUTE. Since they no longer use
it we can mop this up and simplify all of the related code.

ok tb@

lib/libcrypto/asn1/asn1t.h
lib/libcrypto/asn1/tasn_dec.c
lib/libcrypto/asn1/tasn_fre.c
lib/libcrypto/asn1/tasn_new.c
lib/libcrypto/asn1/tasn_utl.c

index 892c8b7..2d38b0d 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: asn1t.h,v 1.19 2022/01/14 08:43:06 tb Exp $ */
+/* $OpenBSD: asn1t.h,v 1.20 2022/05/10 05:19:22 jsing Exp $ */
 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project 2000.
  */
@@ -352,11 +352,6 @@ extern "C" {
        (flags), (tag), offsetof(stname, field),\
        #field, ASN1_ITEM_ref(type) }
 
-/* used when the structure is combined with the parent */
-
-#define ASN1_EX_COMBINE(flags, tag, type) { \
-       (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) }
-
 /* implicit and explicit helper macros */
 
 #define ASN1_IMP_EX(stname, field, type, tag, ex) \
@@ -569,17 +564,6 @@ struct ASN1_ADB_TABLE_st {
 
 #define ASN1_TFLG_ADB_INT      (0x1<<9)
 
-/*
- * This flag means a parent structure is passed
- * instead of the field: this is useful is a
- * SEQUENCE is being combined with a CHOICE for
- * example. Since this means the structure and
- * item name will differ we need to use the
- * ASN1_CHOICE_END_name() macro for example.
- */
-
-#define ASN1_TFLG_COMBINE      (0x1<<10)
-
 /*
  * This flag when present in a SEQUENCE OF, SET OF
  * or EXPLICIT causes indefinite length constructed
index f9c5fa8..de0b819 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: tasn_dec.c,v 1.61 2022/05/07 15:50:25 jsing Exp $ */
+/* $OpenBSD: tasn_dec.c,v 1.62 2022/05/10 05:19:22 jsing Exp $ */
 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project 2000.
  */
@@ -132,10 +132,6 @@ asn1_item_ex_d2i_choice(ASN1_VALUE **pval, const unsigned char **in, long len,
        const unsigned char *p = NULL;
        int i;
        int ret = 0;
-       int combine;
-
-       combine = aclass & ASN1_TFLG_COMBINE;
-       aclass &= ~ASN1_TFLG_COMBINE;
 
        if (it->itype != ASN1_ITYPE_CHOICE)
                goto err;
@@ -211,8 +207,8 @@ asn1_item_ex_d2i_choice(ASN1_VALUE **pval, const unsigned char **in, long len,
  auxerr:
        ASN1error(ASN1_R_AUX_ERROR);
  err:
-       if (combine == 0)
-               ASN1_item_ex_free(pval, it);
+       ASN1_item_ex_free(pval, it);
+
        if (errtt)
                ERR_asprintf_error_data("Field=%s, Type=%s", errtt->field_name,
                    it->sname);
@@ -233,10 +229,6 @@ asn1_item_ex_d2i_sequence(ASN1_VALUE **pval, const unsigned char **in, long len,
        long tmplen;
        int i;
        int ret = 0;
-       int combine;
-
-       combine = aclass & ASN1_TFLG_COMBINE;
-       aclass &= ~ASN1_TFLG_COMBINE;
 
        if (it->itype != ASN1_ITYPE_NDEF_SEQUENCE &&
            it->itype != ASN1_ITYPE_SEQUENCE)
@@ -388,8 +380,8 @@ asn1_item_ex_d2i_sequence(ASN1_VALUE **pval, const unsigned char **in, long len,
  auxerr:
        ASN1error(ASN1_R_AUX_ERROR);
  err:
-       if (combine == 0)
-               ASN1_item_ex_free(pval, it);
+       ASN1_item_ex_free(pval, it);
+
        if (errtt)
                ERR_asprintf_error_data("Field=%s, Type=%s", errtt->field_name,
                    it->sname);
@@ -412,10 +404,6 @@ asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
        unsigned char oclass;
        int otag;
        int ret = 0;
-       int combine;
-
-       combine = aclass & ASN1_TFLG_COMBINE;
-       aclass &= ~ASN1_TFLG_COMBINE;
 
        if (!pval)
                return 0;
@@ -491,20 +479,19 @@ asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
 
        case ASN1_ITYPE_CHOICE:
                return asn1_item_ex_d2i_choice(pval, in, len, it, tag,
-                   aclass | combine, opt, depth);
+                   aclass, opt, depth);
 
        case ASN1_ITYPE_NDEF_SEQUENCE:
        case ASN1_ITYPE_SEQUENCE:
                return asn1_item_ex_d2i_sequence(pval, in, len, it, tag,
-                   aclass | combine, opt, depth);
+                   aclass, opt, depth);
 
        default:
                return 0;
        }
 
  err:
-       if (combine == 0)
-               ASN1_item_ex_free(pval, it);
+       ASN1_item_ex_free(pval, it);
 
        ERR_asprintf_error_data("Type=%s", it->sname);
 
@@ -691,8 +678,8 @@ asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
                        return -1;
        } else {
                /* Nothing special */
-               ret = asn1_item_ex_d2i(val, &p, len, tt->item,
-                   -1, tt->flags & ASN1_TFLG_COMBINE, opt, depth);
+               ret = asn1_item_ex_d2i(val, &p, len, tt->item, -1, 0,
+                   opt, depth);
                if (!ret) {
                        ASN1error(ERR_R_NESTED_ASN1_ERROR);
                        goto err;
index 64d3856..dbf6bf1 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: tasn_fre.c,v 1.18 2022/01/07 12:24:17 tb Exp $ */
+/* $OpenBSD: tasn_fre.c,v 1.19 2022/05/10 05:19:22 jsing Exp $ */
 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project 2000.
  */
 
 #include "asn1_locl.h"
 
-static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
-    int combine);
+static void asn1_item_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
 
 /* Free up an ASN1 structure */
 
 void
 ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
 {
-       asn1_item_combine_free(&val, it, 0);
+       asn1_item_free(&val, it);
 }
 
 void
 ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
-       asn1_item_combine_free(pval, it, 0);
+       asn1_item_free(pval, it);
 }
 
 static void
-asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
+asn1_item_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        const ASN1_TEMPLATE *tt = NULL, *seqtt;
        const ASN1_EXTERN_FUNCS *ef;
@@ -126,10 +125,8 @@ asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
                }
                if (asn1_cb)
                        asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
-               if (!combine) {
-                       free(*pval);
-                       *pval = NULL;
-               }
+               free(*pval);
+               *pval = NULL;
                break;
 
        case ASN1_ITYPE_EXTERN:
@@ -164,10 +161,8 @@ asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
                }
                if (asn1_cb)
                        asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
-               if (!combine) {
-                       free(*pval);
-                       *pval = NULL;
-               }
+               free(*pval);
+               *pval = NULL;
                break;
        }
 }
@@ -181,14 +176,12 @@ ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
                for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
                        ASN1_VALUE *vtmp;
                        vtmp = sk_ASN1_VALUE_value(sk, i);
-                       asn1_item_combine_free(&vtmp, tt->item,
-                           0);
+                       asn1_item_free(&vtmp, tt->item);
                }
                sk_ASN1_VALUE_free(sk);
                *pval = NULL;
        } else
-               asn1_item_combine_free(pval, tt->item,
-                   tt->flags & ASN1_TFLG_COMBINE);
+               asn1_item_free(pval, tt->item);
 }
 
 void
index 1f17f17..83b0fce 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: tasn_new.c,v 1.21 2022/01/07 12:24:17 tb Exp $ */
+/* $OpenBSD: tasn_new.c,v 1.22 2022/05/10 05:19:22 jsing Exp $ */
 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project 2000.
  */
@@ -66,8 +66,7 @@
 
 #include "asn1_locl.h"
 
-static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
-    int combine);
+static int asn1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
 static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
 static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
 static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
@@ -86,11 +85,11 @@ ASN1_item_new(const ASN1_ITEM *it)
 int
 ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
-       return asn1_item_ex_combine_new(pval, it, 0);
+       return asn1_item_ex_new(pval, it);
 }
 
 static int
-asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
+asn1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        const ASN1_TEMPLATE *tt = NULL;
        const ASN1_EXTERN_FUNCS *ef;
@@ -102,9 +101,7 @@ asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
        if (aux != NULL && aux->asn1_cb != NULL)
                asn1_cb = aux->asn1_cb;
 
-       if (!combine)
-               *pval = NULL;
-
+       *pval = NULL;
 
        switch (it->itype) {
        case ASN1_ITYPE_EXTERN:
@@ -137,11 +134,9 @@ asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
                                return 1;
                        }
                }
-               if (!combine) {
-                       *pval = calloc(1, it->size);
-                       if (!*pval)
-                               goto memerr;
-               }
+               *pval = calloc(1, it->size);
+               if (!*pval)
+                       goto memerr;
                asn1_set_choice_selector(pval, -1, it);
                if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
                        goto auxerr;
@@ -157,13 +152,11 @@ asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
                                return 1;
                        }
                }
-               if (!combine) {
-                       *pval = calloc(1, it->size);
-                       if (!*pval)
-                               goto memerr;
-                       asn1_do_lock(pval, 0, it);
-                       asn1_enc_init(pval, it);
-               }
+               *pval = calloc(1, it->size);
+               if (!*pval)
+                       goto memerr;
+               asn1_do_lock(pval, 0, it);
+               asn1_enc_init(pval, it);
                for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
                        pseqval = asn1_get_field_ptr(pval, tt);
                        if (!ASN1_template_new(pseqval, tt))
@@ -249,7 +242,7 @@ ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
                goto done;
        }
        /* Otherwise pass it back to the item routine */
-       ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
+       ret = asn1_item_ex_new(pval, it);
  done:
        return ret;
 }
index e64bbe1..4ef4232 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: tasn_utl.c,v 1.13 2021/12/25 13:17:48 jsing Exp $ */
+/* $OpenBSD: tasn_utl.c,v 1.14 2022/05/10 05:19:23 jsing Exp $ */
 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project 2000.
  */
@@ -205,8 +205,6 @@ asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
 {
        ASN1_VALUE **pvaltmp;
 
-       if (tt->flags & ASN1_TFLG_COMBINE)
-               return pval;
        pvaltmp = offset2ptr(*pval, tt->offset);
        /* NOTE for BOOLEAN types the field is just a plain
         * int so we can't return int **, so settle for