[openssl-commits] [openssl] master update

Dr. Stephen Henson steve at openssl.org
Thu Sep 29 15:23:19 UTC 2016


The branch master has been updated
       via  b1b4f0a5807d0462067a39daf39eb8bccd3bca2b (commit)
       via  73a9f60dd127df9ca05bec7afd835ff7c9bee9ae (commit)
       via  adffae15d3c6713ecd15d55d51b159b4262c20e6 (commit)
       via  2171a071aa16780962071e93c5c24ff148195c98 (commit)
       via  5fb1005987d3d0bc749d935e5af4a69323824b48 (commit)
       via  56501ebd09316941a6deba111e33ccc166641b25 (commit)
      from  83ae4661315d3d0ad52ddaa8fa5c8f1055c6c6f6 (commit)


- Log -----------------------------------------------------------------
commit b1b4f0a5807d0462067a39daf39eb8bccd3bca2b
Author: Dr. Stephen Henson <steve at openssl.org>
Date:   Wed Sep 28 16:59:54 2016 +0100

    make update
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>

commit 73a9f60dd127df9ca05bec7afd835ff7c9bee9ae
Author: Dr. Stephen Henson <steve at openssl.org>
Date:   Wed Sep 28 15:18:58 2016 +0100

    Print <ABSENT> if a STACK is NULL.
    
    If a STACK (corresponding to SEQUENCE OF or SET OF) is NULL then the
    field is absent as opposed to empty (present but has zero elements).
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>

commit adffae15d3c6713ecd15d55d51b159b4262c20e6
Author: Dr. Stephen Henson <steve at openssl.org>
Date:   Wed Sep 28 00:24:58 2016 +0100

    add item list support to d2i_test
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>

commit 2171a071aa16780962071e93c5c24ff148195c98
Author: Dr. Stephen Henson <steve at openssl.org>
Date:   Tue Sep 27 22:39:12 2016 +0100

    ASN1_ITEM should use type name not structure name.
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>

commit 5fb1005987d3d0bc749d935e5af4a69323824b48
Author: Dr. Stephen Henson <steve at openssl.org>
Date:   Tue Sep 27 22:25:08 2016 +0100

    Add -item option to asn1parse
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>

commit 56501ebd09316941a6deba111e33ccc166641b25
Author: Dr. Stephen Henson <steve at openssl.org>
Date:   Tue Sep 27 21:15:57 2016 +0100

    Add ASN1_ITEM lookup and enumerate functions.
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>

-----------------------------------------------------------------------

Summary of changes:
 apps/asn1pars.c                             |  45 +++++++++--
 crypto/asn1/asn1_item_list.c                |  40 +++++++++
 fuzz/asn1.c => crypto/asn1/asn1_item_list.h | 121 +++++++---------------------
 crypto/asn1/build.info                      |   2 +-
 crypto/asn1/tasn_prn.c                      |   3 +-
 doc/apps/asn1parse.pod                      |   6 ++
 doc/crypto/ASN1_ITEM_lookup.pod             |  39 +++++++++
 include/openssl/asn1.h                      |   3 +
 include/openssl/asn1t.h                     |   4 +-
 test/d2i_test.c                             |  22 ++---
 util/libcrypto.num                          |   2 +
 11 files changed, 172 insertions(+), 115 deletions(-)
 create mode 100644 crypto/asn1/asn1_item_list.c
 copy fuzz/asn1.c => crypto/asn1/asn1_item_list.h (71%)
 create mode 100644 doc/crypto/ASN1_ITEM_lookup.pod

diff --git a/apps/asn1pars.c b/apps/asn1pars.c
index 1ac261c..0bc48e3 100644
--- a/apps/asn1pars.c
+++ b/apps/asn1pars.c
@@ -20,12 +20,14 @@
 #include <openssl/evp.h>
 #include <openssl/x509.h>
 #include <openssl/pem.h>
+#include <openssl/asn1t.h>
 
 typedef enum OPTION_choice {
     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
     OPT_INFORM, OPT_IN, OPT_OUT, OPT_INDENT, OPT_NOOUT,
     OPT_OID, OPT_OFFSET, OPT_LENGTH, OPT_DUMP, OPT_DLIMIT,
-    OPT_STRPARSE, OPT_GENSTR, OPT_GENCONF, OPT_STRICTPEM
+    OPT_STRPARSE, OPT_GENSTR, OPT_GENCONF, OPT_STRICTPEM,
+    OPT_ITEM
 } OPTION_CHOICE;
 
 OPTIONS asn1parse_options[] = {
@@ -49,6 +51,7 @@ OPTIONS asn1parse_options[] = {
     {OPT_MORE_STR, 0, 0, "(-inform  will be ignored)"},
     {"strictpem", OPT_STRICTPEM, 0,
      "do not attempt base64 decode outside PEM markers"},
+    {"item", OPT_ITEM, 's', "item to parse and print"},
     {NULL}
 };
 
@@ -71,6 +74,7 @@ int asn1parse_main(int argc, char **argv)
     unsigned char *tmpbuf;
     unsigned int length = 0;
     OPTION_CHOICE o;
+    const ASN1_ITEM *it = NULL;
 
     prog = opt_init(argc, argv, asn1parse_options);
 
@@ -134,6 +138,22 @@ int asn1parse_main(int argc, char **argv)
             strictpem = 1;
             informat = FORMAT_PEM;
             break;
+        case OPT_ITEM:
+            it = ASN1_ITEM_lookup(opt_arg());
+            if (it == NULL) {
+                size_t tmp;
+
+                BIO_printf(bio_err, "Unknown item name %s\n", opt_arg());
+                BIO_puts(bio_err, "Supported types:\n");
+                for (tmp = 0;; tmp++) {
+                    it = ASN1_ITEM_get(tmp);
+                    if (it == NULL)
+                        break;
+                    BIO_printf(bio_err, "    %s\n", it->sname);
+                }
+                goto end;
+            }
+            break;
         }
     }
     argc = opt_num_rest();
@@ -260,11 +280,24 @@ int asn1parse_main(int argc, char **argv)
             goto end;
         }
     }
-    if (!noout &&
-        !ASN1_parse_dump(bio_out, &(str[offset]), length,
-                         indent, dump)) {
-        ERR_print_errors(bio_err);
-        goto end;
+    if (!noout) {
+        const unsigned char *p = str + offset;
+
+        if (it != NULL) {
+            ASN1_VALUE *value = ASN1_item_d2i(NULL, &p, length, it);
+            if (value == NULL) {
+                BIO_printf(bio_err, "Error parsing item %s\n", it->sname);
+                ERR_print_errors(bio_err);
+                goto end;
+            }
+            ASN1_item_print(bio_out, value, 0, it, NULL);
+            ASN1_item_free(value, it);
+        } else {
+            if (!ASN1_parse_dump(bio_out, p, length, indent, dump)) {
+                ERR_print_errors(bio_err);
+                goto end;
+            }
+        }
     }
     ret = 0;
  end:
diff --git a/crypto/asn1/asn1_item_list.c b/crypto/asn1/asn1_item_list.c
new file mode 100644
index 0000000..eaeb34f
--- /dev/null
+++ b/crypto/asn1/asn1_item_list.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include <stdio.h>
+#include "internal/cryptlib.h"
+#include <openssl/asn1.h>
+#include <openssl/asn1t.h>
+#include <openssl/cms.h>
+#include <openssl/ocsp.h>
+#include <openssl/pkcs7.h>
+#include <openssl/pkcs12.h>
+#include <openssl/x509v3.h>
+
+#include "asn1_item_list.h"
+
+const ASN1_ITEM *ASN1_ITEM_lookup(const char *name)
+{
+    size_t i;
+
+    for (i = 0; i < OSSL_NELEM(asn1_item_list); i++) {
+        const ASN1_ITEM *it = ASN1_ITEM_ptr(asn1_item_list[i]);
+
+        if (strcmp(it->sname, name) == 0)
+            return it;
+    }
+    return NULL;
+}
+
+const ASN1_ITEM *ASN1_ITEM_get(size_t i)
+{
+    if (i >= OSSL_NELEM(asn1_item_list))
+        return NULL;
+    return ASN1_ITEM_ptr(asn1_item_list[i]);
+}
diff --git a/fuzz/asn1.c b/crypto/asn1/asn1_item_list.h
similarity index 71%
copy from fuzz/asn1.c
copy to crypto/asn1/asn1_item_list.h
index 5125f36..909ea3e 100644
--- a/fuzz/asn1.c
+++ b/crypto/asn1/asn1_item_list.h
@@ -1,40 +1,19 @@
 /*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
  *
- * Licensed under the OpenSSL licenses, (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the OpenSSL license (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
  * https://www.openssl.org/source/license.html
- * or in the file LICENSE in the source distribution.
  */
 
-/*
- * Fuzz ASN.1 parsing for various data structures. Specify which on the
- * command line:
- *
- * asn1 <data structure>
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <openssl/asn1.h>
-#include <openssl/asn1t.h>
-#include <openssl/dh.h>
-#include <openssl/ec.h>
-#include <openssl/ocsp.h>
-#include <openssl/pkcs12.h>
-#include <openssl/rsa.h>
-#include <openssl/ts.h>
-#include <openssl/x509v3.h>
-#include <openssl/cms.h>
-#include "fuzzer.h"
+static ASN1_ITEM_EXP *asn1_item_list[] = {
 
-static ASN1_ITEM_EXP *item_type[] = {
     ASN1_ITEM_ref(ACCESS_DESCRIPTION),
 #ifndef OPENSSL_NO_RFC3779
+    ASN1_ITEM_ref(ASIdOrRange),
     ASN1_ITEM_ref(ASIdentifierChoice),
     ASN1_ITEM_ref(ASIdentifiers),
-    ASN1_ITEM_ref(ASIdOrRange),
 #endif
     ASN1_ITEM_ref(ASN1_ANY),
     ASN1_ITEM_ref(ASN1_BIT_STRING),
@@ -48,12 +27,12 @@ static ASN1_ITEM_EXP *item_type[] = {
     ASN1_ITEM_ref(ASN1_INTEGER),
     ASN1_ITEM_ref(ASN1_NULL),
     ASN1_ITEM_ref(ASN1_OBJECT),
-    ASN1_ITEM_ref(ASN1_OCTET_STRING),
     ASN1_ITEM_ref(ASN1_OCTET_STRING_NDEF),
-    ASN1_ITEM_ref(ASN1_PRINTABLE),
+    ASN1_ITEM_ref(ASN1_OCTET_STRING),
     ASN1_ITEM_ref(ASN1_PRINTABLESTRING),
-    ASN1_ITEM_ref(ASN1_SEQUENCE),
+    ASN1_ITEM_ref(ASN1_PRINTABLE),
     ASN1_ITEM_ref(ASN1_SEQUENCE_ANY),
+    ASN1_ITEM_ref(ASN1_SEQUENCE),
     ASN1_ITEM_ref(ASN1_SET_ANY),
     ASN1_ITEM_ref(ASN1_T61STRING),
     ASN1_ITEM_ref(ASN1_TBOOLEAN),
@@ -74,23 +53,23 @@ static ASN1_ITEM_EXP *item_type[] = {
 #ifndef OPENSSL_NO_CMS
     ASN1_ITEM_ref(CMS_ContentInfo),
     ASN1_ITEM_ref(CMS_ReceiptRequest),
-    ASN1_ITEM_ref(CRL_DIST_POINTS),
 #endif
+    ASN1_ITEM_ref(CRL_DIST_POINTS),
 #ifndef OPENSSL_NO_DH
     ASN1_ITEM_ref(DHparams),
 #endif
     ASN1_ITEM_ref(DIRECTORYSTRING),
     ASN1_ITEM_ref(DISPLAYTEXT),
-    ASN1_ITEM_ref(DIST_POINT),
     ASN1_ITEM_ref(DIST_POINT_NAME),
+    ASN1_ITEM_ref(DIST_POINT),
 #ifndef OPENSSL_NO_EC
     ASN1_ITEM_ref(ECPARAMETERS),
     ASN1_ITEM_ref(ECPKPARAMETERS),
 #endif
     ASN1_ITEM_ref(EDIPARTYNAME),
     ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
-    ASN1_ITEM_ref(GENERAL_NAME),
     ASN1_ITEM_ref(GENERAL_NAMES),
+    ASN1_ITEM_ref(GENERAL_NAME),
     ASN1_ITEM_ref(GENERAL_SUBTREE),
 #ifndef OPENSSL_NO_RFC3779
     ASN1_ITEM_ref(IPAddressChoice),
@@ -126,97 +105,59 @@ static ASN1_ITEM_EXP *item_type[] = {
     ASN1_ITEM_ref(PBE2PARAM),
     ASN1_ITEM_ref(PBEPARAM),
     ASN1_ITEM_ref(PBKDF2PARAM),
-    ASN1_ITEM_ref(PKCS12),
     ASN1_ITEM_ref(PKCS12_AUTHSAFES),
     ASN1_ITEM_ref(PKCS12_BAGS),
     ASN1_ITEM_ref(PKCS12_MAC_DATA),
-    ASN1_ITEM_ref(PKCS12_SAFEBAG),
     ASN1_ITEM_ref(PKCS12_SAFEBAGS),
-    ASN1_ITEM_ref(PKCS7),
+    ASN1_ITEM_ref(PKCS12_SAFEBAG),
+    ASN1_ITEM_ref(PKCS12),
     ASN1_ITEM_ref(PKCS7_ATTR_SIGN),
     ASN1_ITEM_ref(PKCS7_ATTR_VERIFY),
     ASN1_ITEM_ref(PKCS7_DIGEST),
-    ASN1_ITEM_ref(PKCS7_ENC_CONTENT),
     ASN1_ITEM_ref(PKCS7_ENCRYPT),
+    ASN1_ITEM_ref(PKCS7_ENC_CONTENT),
     ASN1_ITEM_ref(PKCS7_ENVELOPE),
     ASN1_ITEM_ref(PKCS7_ISSUER_AND_SERIAL),
     ASN1_ITEM_ref(PKCS7_RECIP_INFO),
     ASN1_ITEM_ref(PKCS7_SIGNED),
-    ASN1_ITEM_ref(PKCS7_SIGN_ENVELOPE),
     ASN1_ITEM_ref(PKCS7_SIGNER_INFO),
+    ASN1_ITEM_ref(PKCS7_SIGN_ENVELOPE),
+    ASN1_ITEM_ref(PKCS7),
     ASN1_ITEM_ref(PKCS8_PRIV_KEY_INFO),
     ASN1_ITEM_ref(PKEY_USAGE_PERIOD),
-    ASN1_ITEM_ref(POLICY_CONSTRAINTS),
     ASN1_ITEM_ref(POLICYINFO),
-    ASN1_ITEM_ref(POLICY_MAPPING),
-    ASN1_ITEM_ref(POLICY_MAPPINGS),
     ASN1_ITEM_ref(POLICYQUALINFO),
+    ASN1_ITEM_ref(POLICY_CONSTRAINTS),
+    ASN1_ITEM_ref(POLICY_MAPPINGS),
+    ASN1_ITEM_ref(POLICY_MAPPING),
     ASN1_ITEM_ref(PROXY_CERT_INFO_EXTENSION),
     ASN1_ITEM_ref(PROXY_POLICY),
-    ASN1_ITEM_ref(RSA_OAEP_PARAMS),
+#ifndef OPENSSL_NO_RSA
     ASN1_ITEM_ref(RSAPrivateKey),
-    ASN1_ITEM_ref(RSA_PSS_PARAMS),
     ASN1_ITEM_ref(RSAPublicKey),
-    ASN1_ITEM_ref(SXNET),
+    ASN1_ITEM_ref(RSA_OAEP_PARAMS),
+    ASN1_ITEM_ref(RSA_PSS_PARAMS),
+#endif
     ASN1_ITEM_ref(SXNETID),
-    /*ASN1_ITEM_ref(TS_RESP),  want to do this, but type is hidden, however d2i exists... */
+    ASN1_ITEM_ref(SXNET),
     ASN1_ITEM_ref(USERNOTICE),
-    ASN1_ITEM_ref(X509),
-    ASN1_ITEM_ref(X509_ALGOR),
     ASN1_ITEM_ref(X509_ALGORS),
+    ASN1_ITEM_ref(X509_ALGOR),
     ASN1_ITEM_ref(X509_ATTRIBUTE),
     ASN1_ITEM_ref(X509_CERT_AUX),
     ASN1_ITEM_ref(X509_CINF),
-    ASN1_ITEM_ref(X509_CRL),
     ASN1_ITEM_ref(X509_CRL_INFO),
-    ASN1_ITEM_ref(X509_EXTENSION),
+    ASN1_ITEM_ref(X509_CRL),
     ASN1_ITEM_ref(X509_EXTENSIONS),
-    ASN1_ITEM_ref(X509_NAME),
+    ASN1_ITEM_ref(X509_EXTENSION),
     ASN1_ITEM_ref(X509_NAME_ENTRY),
+    ASN1_ITEM_ref(X509_NAME),
     ASN1_ITEM_ref(X509_PUBKEY),
-    ASN1_ITEM_ref(X509_REQ),
     ASN1_ITEM_ref(X509_REQ_INFO),
+    ASN1_ITEM_ref(X509_REQ),
     ASN1_ITEM_ref(X509_REVOKED),
     ASN1_ITEM_ref(X509_SIG),
     ASN1_ITEM_ref(X509_VAL),
+    ASN1_ITEM_ref(X509),
     ASN1_ITEM_ref(ZLONG),
-    NULL
 };
-
-int FuzzerInitialize(int *argc, char ***argv) {
-    return 1;
-}
-
-int FuzzerTestOneInput(const uint8_t *buf, size_t len) {
-    int n;
-
-    ASN1_PCTX *pctx = ASN1_PCTX_new();
-
-    ASN1_PCTX_set_flags(pctx, ASN1_PCTX_FLAGS_SHOW_ABSENT |
-        ASN1_PCTX_FLAGS_SHOW_SEQUENCE | ASN1_PCTX_FLAGS_SHOW_SSOF |
-        ASN1_PCTX_FLAGS_SHOW_TYPE | ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME);
-    ASN1_PCTX_set_str_flags(pctx, ASN1_STRFLGS_UTF8_CONVERT |
-        ASN1_STRFLGS_SHOW_TYPE | ASN1_STRFLGS_DUMP_ALL);
-
-    for (n = 0; item_type[n] != NULL; ++n) {
-        const uint8_t *b = buf;
-        unsigned char *der = NULL;
-        const ASN1_ITEM *i = ASN1_ITEM_ptr(item_type[n]);
-        ASN1_VALUE *o = ASN1_item_d2i(NULL, &b, len, i);
-
-        if (o != NULL) {
-            BIO *bio = BIO_new(BIO_s_null());
-            ASN1_item_print(bio, o, 4, i, pctx);
-            BIO_free(bio);
-
-            ASN1_item_i2d(o, &der, i);
-            OPENSSL_free(der);
-
-            ASN1_item_free(o, i);
-        }
-    }
-
-    ASN1_PCTX_free(pctx);
-
-    return 0;
-}
diff --git a/crypto/asn1/build.info b/crypto/asn1/build.info
index 02d1120..242dbb7 100644
--- a/crypto/asn1/build.info
+++ b/crypto/asn1/build.info
@@ -13,4 +13,4 @@ SOURCE[../../libcrypto]=\
         x_pkey.c bio_asn1.c bio_ndef.c asn_mime.c \
         asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_strnid.c \
         evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p5_scrypt.c p8_pkey.c \
-        asn_moid.c asn_mstbl.c
+        asn_moid.c asn_mstbl.c asn1_item_list.c
diff --git a/crypto/asn1/tasn_prn.c b/crypto/asn1/tasn_prn.c
index f53e905..b569806 100644
--- a/crypto/asn1/tasn_prn.c
+++ b/crypto/asn1/tasn_prn.c
@@ -315,7 +315,8 @@ static int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                                      pctx))
                 return 0;
         }
-        if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0)
+        if (i == 0 && BIO_printf(out, "%*s<%s>\n", indent + 2, "",
+                                 stack == NULL ? "ABSENT" : "EMPTY") <= 0)
             return 0;
         if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
             if (BIO_printf(out, "%*s}\n", indent, "") <= 0)
diff --git a/doc/apps/asn1parse.pod b/doc/apps/asn1parse.pod
index 10a5aba..ee09a83 100644
--- a/doc/apps/asn1parse.pod
+++ b/doc/apps/asn1parse.pod
@@ -22,6 +22,7 @@ B<openssl> B<asn1parse>
 [B<-genstr string>]
 [B<-genconf file>]
 [B<-strictpem>]
+[B<-item name>]
 
 =head1 DESCRIPTION
 
@@ -102,6 +103,11 @@ processed whether it has the normal PEM BEGIN and END markers or not. This
 option will ignore any data prior to the start of the BEGIN marker, or after an
 END marker in a PEM file.
 
+=item B<-item name>
+
+attempt to decode and print the data as B<ASN1_ITEM name>. This can be used to
+print out the fields of any supported ASN.1 structure if the type is known.
+
 =back
 
 =head2 Output
diff --git a/doc/crypto/ASN1_ITEM_lookup.pod b/doc/crypto/ASN1_ITEM_lookup.pod
new file mode 100644
index 0000000..9ba69c9d
--- /dev/null
+++ b/doc/crypto/ASN1_ITEM_lookup.pod
@@ -0,0 +1,39 @@
+=pod
+
+=head1 NAME
+
+ASN1_ITEM_lookup, ASN1_ITEM_get - lookup ASN.1 structures
+
+=head1 SYNOPSIS
+
+ #include <openssl/asn1.h>
+
+ const ASN1_ITEM *ASN1_ITEM_lookup(const char *name);
+ const ASN1_ITEM *ASN1_ITEM_get(size_t i);
+
+=head1 DESCRIPTION
+
+ASN1_ITEM_lookup() returns the B<ASN1_ITEM name>.
+
+ASN1_ITEM_get() returns the B<ASN1_ITEM> with index B<i>. This function
+returns B<NULL> if the index B<i> is out of range.
+
+=head1 RETURN VALUES
+
+ASN1_ITEM_lookup() and ASN1_ITEM_get() return a valid B<ASN1_ITEM> structure
+or B<NULL> if an error occurred.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)>
+
+=head1 COPYRIGHT
+
+Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+
+Licensed under the OpenSSL license (the "License").  You may not use
+this file except in compliance with the License.  You can obtain a copy
+in the file LICENSE in the source distribution or at
+L<https://www.openssl.org/source/license.html>.
+
+=cut
diff --git a/include/openssl/asn1.h b/include/openssl/asn1.h
index 7cf6116..665b952 100644
--- a/include/openssl/asn1.h
+++ b/include/openssl/asn1.h
@@ -870,6 +870,9 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it);
 int SMIME_crlf_copy(BIO *in, BIO *out, int flags);
 int SMIME_text(BIO *in, BIO *out);
 
+const ASN1_ITEM *ASN1_ITEM_lookup(const char *name);
+const ASN1_ITEM *ASN1_ITEM_get(size_t i);
+
 /* BEGIN ERROR CODES */
 /*
  * The following lines are auto generated by the script mkerr.pl. Any changes
diff --git a/include/openssl/asn1t.h b/include/openssl/asn1t.h
index 8eedfb3..0a7e375 100644
--- a/include/openssl/asn1t.h
+++ b/include/openssl/asn1t.h
@@ -130,7 +130,7 @@ extern "C" {
                 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
                 NULL,\
                 sizeof(stname),\
-                #stname \
+                #tname \
         ASN1_ITEM_end(tname)
 
 # define static_ASN1_SEQUENCE_END_name(stname, tname) \
@@ -208,7 +208,7 @@ extern "C" {
                 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
                 &tname##_aux,\
                 sizeof(stname),\
-                #stname \
+                #tname \
         ASN1_ITEM_end(tname)
 # define static_ASN1_SEQUENCE_END_ref(stname, tname) \
         ;\
diff --git a/test/d2i_test.c b/test/d2i_test.c
index 8c99087..b173cc5 100644
--- a/test/d2i_test.c
+++ b/test/d2i_test.c
@@ -144,12 +144,6 @@ int main(int argc, char **argv)
     const char *expected_error_string;
 
     size_t i;
-    static ASN1_ITEM_EXP *items[] = {
-        ASN1_ITEM_ref(ASN1_ANY),
-        ASN1_ITEM_ref(X509),
-        ASN1_ITEM_ref(GENERAL_NAME),
-        ASN1_ITEM_ref(ASN1_INTEGER)
-    };
 
     static error_enum expected_errors[] = {
         {"OK", ASN1_OK},
@@ -169,18 +163,16 @@ int main(int argc, char **argv)
     expected_error_string = argv[2];
     test_file = argv[3];
 
-    for (i = 0; i < OSSL_NELEM(items); i++) {
-        const ASN1_ITEM *it = ASN1_ITEM_ptr(items[i]);
-        if (strcmp(test_type_name, it->sname) == 0) {
-            item_type = it;
-            break;
-        }
-    }
+    item_type = ASN1_ITEM_lookup(test_type_name);
+
     if (item_type == NULL) {
         fprintf(stderr, "Unknown type %s\n", test_type_name);
         fprintf(stderr, "Supported types:\n");
-        for (i = 0; i < OSSL_NELEM(items); i++) {
-            const ASN1_ITEM *it = ASN1_ITEM_ptr(items[i]);
+        for (i = 0;; i++) {
+            const ASN1_ITEM *it = ASN1_ITEM_get(i);
+
+            if (it == NULL)
+                break;
             fprintf(stderr, "\t%s\n", it->sname);
         }
         return 1;
diff --git a/util/libcrypto.num b/util/libcrypto.num
index db6732e..21d46d2 100644
--- a/util/libcrypto.num
+++ b/util/libcrypto.num
@@ -4206,3 +4206,5 @@ ECPARAMETERS_new                        4156	1_1_0	EXIST::FUNCTION:EC
 OCSP_RESPID_set_by_name                 4157	1_1_0a	EXIST::FUNCTION:OCSP
 OCSP_RESPID_set_by_key                  4158	1_1_0a	EXIST::FUNCTION:OCSP
 OCSP_RESPID_match                       4159	1_1_0a	EXIST::FUNCTION:OCSP
+ASN1_ITEM_lookup                        4160	1_1_1	EXIST::FUNCTION:
+ASN1_ITEM_get                           4161	1_1_1	EXIST::FUNCTION:


More information about the openssl-commits mailing list