From d13728f319fe74101df57dfabe16907c5d517d28 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Wed, 20 Aug 2014 09:53:10 +0200 Subject: Added another BER-encoded PKCS #12 file to test indefinite decoding --- tests/Makefile.am | 4 +++- tests/Test_indefinite.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index d28656d..a400af7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -23,7 +23,8 @@ AM_LDFLAGS = -no-install LDADD = ../lib/libtasn1.la ../gl/libgnu.la EXTRA_DIST = Test_parser.asn Test_tree.asn Test_tree_asn1_tab.c \ - Test_encoding.asn pkix.asn TestIndef.p12 choice.asn + Test_encoding.asn pkix.asn TestIndef.p12 choice.asn \ + TestIndef2.p12 # For crlf. EXTRA_DIST += crlf.cer crl.der @@ -48,6 +49,7 @@ TESTS_ENVIRONMENT = \ ASN1PKIX=$(srcdir)/pkix.asn \ ASN1CRLDER=$(srcdir)/crl.der \ ASN1INDEF=$(srcdir)/TestIndef.p12 \ + ASN1INDEF2=$(srcdir)/TestIndef2.p12 \ ASN1ENCODING=$(srcdir)/Test_encoding.asn \ THREADSAFETY_FILES=`find $(top_srcdir)/lib -name \*.c` \ EXEEXT=$(EXEEXT) \ diff --git a/tests/Test_indefinite.c b/tests/Test_indefinite.c index c1613ef..b1a435a 100644 --- a/tests/Test_indefinite.c +++ b/tests/Test_indefinite.c @@ -48,6 +48,7 @@ main (int argc, char *argv[]) ssize_t size; const char *treefile = getenv ("ASN1PKIX"); const char *indeffile = getenv ("ASN1INDEF"); + const char *indeffile2 = getenv ("ASN1INDEF2"); int verbose = 0; if (argc > 1) @@ -59,6 +60,9 @@ main (int argc, char *argv[]) if (!indeffile) indeffile = "TestIndef.p12"; + if (!indeffile2) + indeffile = "TestIndef2.p12"; + if (verbose) { printf ("\n\n/****************************************/\n"); @@ -110,13 +114,49 @@ main (int argc, char *argv[]) if (result != ASN1_SUCCESS) { asn1_perror (result); - printf ("Cannot decode BER data (size %ld)\n", (long) size); + printf ("Cannot decode BER data (size %ld) in %s\n", (long) size, indeffile); + exit (1); + } + + asn1_delete_structure (&asn1_element); + + /* second test */ + fd = fopen (indeffile2, "rb"); + if (fd == NULL) + { + printf ("Cannot read file %s\n", indeffile); + exit (1); + } + size = fread (buffer, 1, sizeof (buffer), fd); + if (size <= 0) + { + printf ("Cannot read from file %s\n", indeffile); + exit (1); + } + + fclose (fd); + + result = + asn1_create_element (definitions, "PKIX1.pkcs-12-PFX", &asn1_element); + if (result != ASN1_SUCCESS) + { + asn1_perror (result); + printf ("Cannot create PKCS12 element\n"); + exit (1); + } + + result = asn1_der_decoding (&asn1_element, buffer, size, errorDescription); + if (result != ASN1_SUCCESS) + { + asn1_perror (result); + printf ("Cannot decode BER data (size %ld) in %s\n", (long) size, indeffile2); exit (1); } + asn1_delete_structure (&asn1_element); + /* Clear the definition structures */ asn1_delete_structure (&definitions); - asn1_delete_structure (&asn1_element); if (out != stdout) fclose (out); -- cgit v1.2.1