diff options
author | Dariusz Michaluk <d.michaluk@samsung.com> | 2018-06-15 11:11:52 +0200 |
---|---|---|
committer | Dariusz Michaluk <d.michaluk@samsung.com> | 2018-06-15 11:11:52 +0200 |
commit | 9ec7943e548cce0a73bdd3805933248fcb0ee67c (patch) | |
tree | 3d2dddcfb0dcb05fb0b7e5a8247f75e6b430c257 /tests | |
parent | a39386a3afe2d7e0cc717a49f970f53d974fda53 (diff) | |
download | libtasn1-9ec7943e548cce0a73bdd3805933248fcb0ee67c.tar.gz libtasn1-9ec7943e548cce0a73bdd3805933248fcb0ee67c.tar.bz2 libtasn1-9ec7943e548cce0a73bdd3805933248fcb0ee67c.zip |
Imported Upstream version 4.9upstream/4.9
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 4 | ||||
-rw-r--r-- | tests/Makefile.in | 48 | ||||
-rw-r--r-- | tests/coding-long-oid.c | 205 | ||||
-rw-r--r-- | tests/object-id-decoding.c | 89 |
4 files changed, 338 insertions, 8 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index d637ce0..379525e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -54,13 +54,13 @@ MOSTLYCLEANFILES = Test_parser_ERROR.asn check_PROGRAMS = Test_parser Test_tree Test_encoding Test_indefinite \ Test_errors Test_simple Test_overflow Test_strings Test_choice \ Test_encdec copynode coding-decoding2 strict-der Test_choice_ocsp \ - ocsp-basic-response octet-string + ocsp-basic-response octet-string coding-long-oid object-id-decoding TESTS = Test_parser Test_tree Test_encoding Test_indefinite \ Test_errors Test_simple Test_overflow crlf threadsafety \ Test_strings Test_choice Test_encdec copynode coding-decoding2 \ strict-der Test_choice_ocsp decoding decoding-invalid-x509 \ - ocsp-basic-response octet-string + ocsp-basic-response octet-string coding-long-oid object-id-decoding TESTS_ENVIRONMENT = \ ASN1PARSER=$(srcdir)/Test_parser.asn \ diff --git a/tests/Makefile.in b/tests/Makefile.in index c1ad745..f51866d 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -111,7 +111,8 @@ check_PROGRAMS = Test_parser$(EXEEXT) Test_tree$(EXEEXT) \ Test_choice$(EXEEXT) Test_encdec$(EXEEXT) copynode$(EXEEXT) \ coding-decoding2$(EXEEXT) strict-der$(EXEEXT) \ Test_choice_ocsp$(EXEEXT) ocsp-basic-response$(EXEEXT) \ - octet-string$(EXEEXT) + octet-string$(EXEEXT) coding-long-oid$(EXEEXT) \ + object-id-decoding$(EXEEXT) TESTS = Test_parser$(EXEEXT) Test_tree$(EXEEXT) Test_encoding$(EXEEXT) \ Test_indefinite$(EXEEXT) Test_errors$(EXEEXT) \ Test_simple$(EXEEXT) Test_overflow$(EXEEXT) crlf threadsafety \ @@ -119,7 +120,8 @@ TESTS = Test_parser$(EXEEXT) Test_tree$(EXEEXT) Test_encoding$(EXEEXT) \ Test_encdec$(EXEEXT) copynode$(EXEEXT) \ coding-decoding2$(EXEEXT) strict-der$(EXEEXT) \ Test_choice_ocsp$(EXEEXT) decoding decoding-invalid-x509 \ - ocsp-basic-response$(EXEEXT) octet-string$(EXEEXT) + ocsp-basic-response$(EXEEXT) octet-string$(EXEEXT) \ + coding-long-oid$(EXEEXT) object-id-decoding$(EXEEXT) subdir = tests ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/lib/glm4/gnulib-comp.m4 \ @@ -231,10 +233,18 @@ coding_decoding2_SOURCES = coding-decoding2.c coding_decoding2_OBJECTS = coding-decoding2.$(OBJEXT) coding_decoding2_LDADD = $(LDADD) coding_decoding2_DEPENDENCIES = ../lib/libtasn1.la ../gl/libgnu.la +coding_long_oid_SOURCES = coding-long-oid.c +coding_long_oid_OBJECTS = coding-long-oid.$(OBJEXT) +coding_long_oid_LDADD = $(LDADD) +coding_long_oid_DEPENDENCIES = ../lib/libtasn1.la ../gl/libgnu.la copynode_SOURCES = copynode.c copynode_OBJECTS = copynode.$(OBJEXT) copynode_LDADD = $(LDADD) copynode_DEPENDENCIES = ../lib/libtasn1.la ../gl/libgnu.la +object_id_decoding_SOURCES = object-id-decoding.c +object_id_decoding_OBJECTS = object-id-decoding.$(OBJEXT) +object_id_decoding_LDADD = $(LDADD) +object_id_decoding_DEPENDENCIES = ../lib/libtasn1.la ../gl/libgnu.la ocsp_basic_response_SOURCES = ocsp-basic-response.c ocsp_basic_response_OBJECTS = ocsp-basic-response.$(OBJEXT) ocsp_basic_response_LDADD = $(LDADD) @@ -284,13 +294,15 @@ am__v_CCLD_1 = SOURCES = Test_choice.c Test_choice_ocsp.c Test_encdec.c \ Test_encoding.c Test_errors.c Test_indefinite.c \ Test_overflow.c Test_parser.c Test_simple.c Test_strings.c \ - Test_tree.c coding-decoding2.c copynode.c \ - ocsp-basic-response.c octet-string.c strict-der.c + Test_tree.c coding-decoding2.c coding-long-oid.c copynode.c \ + object-id-decoding.c ocsp-basic-response.c octet-string.c \ + strict-der.c DIST_SOURCES = Test_choice.c Test_choice_ocsp.c Test_encdec.c \ Test_encoding.c Test_errors.c Test_indefinite.c \ Test_overflow.c Test_parser.c Test_simple.c Test_strings.c \ - Test_tree.c coding-decoding2.c copynode.c \ - ocsp-basic-response.c octet-string.c strict-der.c + Test_tree.c coding-decoding2.c coding-long-oid.c copynode.c \ + object-id-decoding.c ocsp-basic-response.c octet-string.c \ + strict-der.c am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -1312,10 +1324,18 @@ coding-decoding2$(EXEEXT): $(coding_decoding2_OBJECTS) $(coding_decoding2_DEPEND @rm -f coding-decoding2$(EXEEXT) $(AM_V_CCLD)$(LINK) $(coding_decoding2_OBJECTS) $(coding_decoding2_LDADD) $(LIBS) +coding-long-oid$(EXEEXT): $(coding_long_oid_OBJECTS) $(coding_long_oid_DEPENDENCIES) $(EXTRA_coding_long_oid_DEPENDENCIES) + @rm -f coding-long-oid$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(coding_long_oid_OBJECTS) $(coding_long_oid_LDADD) $(LIBS) + copynode$(EXEEXT): $(copynode_OBJECTS) $(copynode_DEPENDENCIES) $(EXTRA_copynode_DEPENDENCIES) @rm -f copynode$(EXEEXT) $(AM_V_CCLD)$(LINK) $(copynode_OBJECTS) $(copynode_LDADD) $(LIBS) +object-id-decoding$(EXEEXT): $(object_id_decoding_OBJECTS) $(object_id_decoding_DEPENDENCIES) $(EXTRA_object_id_decoding_DEPENDENCIES) + @rm -f object-id-decoding$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(object_id_decoding_OBJECTS) $(object_id_decoding_LDADD) $(LIBS) + ocsp-basic-response$(EXEEXT): $(ocsp_basic_response_OBJECTS) $(ocsp_basic_response_DEPENDENCIES) $(EXTRA_ocsp_basic_response_DEPENDENCIES) @rm -f ocsp-basic-response$(EXEEXT) $(AM_V_CCLD)$(LINK) $(ocsp_basic_response_OBJECTS) $(ocsp_basic_response_LDADD) $(LIBS) @@ -1346,7 +1366,9 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Test_strings.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Test_tree.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/coding-decoding2.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/coding-long-oid.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/copynode.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/object-id-decoding.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ocsp-basic-response.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/octet-string.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strict-der.Po@am__quote@ @@ -1711,6 +1733,20 @@ octet-string.log: octet-string$(EXEEXT) --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) +coding-long-oid.log: coding-long-oid$(EXEEXT) + @p='coding-long-oid$(EXEEXT)'; \ + b='coding-long-oid'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +object-id-decoding.log: object-id-decoding$(EXEEXT) + @p='object-id-decoding$(EXEEXT)'; \ + b='object-id-decoding'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) .test.log: @p='$<'; \ $(am__set_b); \ diff --git a/tests/coding-long-oid.c b/tests/coding-long-oid.c new file mode 100644 index 0000000..bc2cd56 --- /dev/null +++ b/tests/coding-long-oid.c @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2016 Free Software Foundation, Inc. + * + * This file is part of LIBTASN1. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <libtasn1.h> + +/* This checks the decoding and re-encoding of OIDs which contain elements + * >= 2^32 bits. + */ + +const unsigned char der_data[] = + "\x30\x82\x06\xdc\x30\x82\x05\xc4\xa0\x03\x02\x01\x02\x02\x08\x35" + "\x73\x8c\xaf\x21\xea\xbd\x2d\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7" + "\x0d\x01\x01\x05\x05\x00\x30\x81\x8e\x31\x0b\x30\x09\x06\x03\x55" + "\x04\x06\x13\x02\x55\x53\x31\x17\x30\x15\x06\x03\x55\x04\x08\x13" + "\x0e\x4e\x6f\x72\x74\x68\x20\x43\x61\x72\x6f\x6c\x69\x6e\x61\x31" + "\x10\x30\x0e\x06\x03\x55\x04\x07\x13\x07\x52\x61\x6c\x65\x69\x67" + "\x68\x31\x10\x30\x0e\x06\x03\x55\x04\x0a\x13\x07\x4b\x61\x74\x65" + "\x6c\x6c\x6f\x31\x14\x30\x12\x06\x03\x55\x04\x0b\x13\x0b\x53\x6f" + "\x6d\x65\x4f\x72\x67\x55\x6e\x69\x74\x31\x2c\x30\x2a\x06\x03\x55" + "\x04\x03\x13\x23\x73\x61\x74\x2d\x72\x32\x32\x30\x2d\x31\x30\x2e" + "\x6c\x61\x62\x2e\x65\x6e\x67\x2e\x72\x64\x75\x32\x2e\x72\x65\x64" + "\x68\x61\x74\x2e\x63\x6f\x6d\x30\x1e\x17\x0d\x31\x36\x30\x37\x30" + "\x31\x31\x38\x35\x34\x31\x37\x5a\x17\x0d\x34\x39\x31\x32\x30\x31" + "\x31\x33\x30\x30\x30\x30\x5a\x30\x2b\x31\x29\x30\x27\x06\x03\x55" + "\x04\x03\x13\x20\x38\x61\x38\x38\x38\x30\x31\x37\x35\x35\x61\x37" + "\x63\x39\x30\x37\x30\x31\x35\x35\x61\x37\x63\x66\x62\x65\x33\x36" + "\x30\x30\x30\x34\x30\x82\x01\x22\x30\x0d\x06\x09\x2a\x86\x48\x86" + "\xf7\x0d\x01\x01\x01\x05\x00\x03\x82\x01\x0f\x00\x30\x82\x01\x0a" + "\x02\x82\x01\x01\x00\xdc\x70\x8b\x9c\x84\xe9\x3e\x79\x8f\x03\xe5" + "\x5f\x21\xf0\x29\x9e\xd9\x94\x4e\x0f\x37\x45\x47\x42\xda\x2a\xe0" + "\xda\xf5\x8b\xfa\xe1\xf8\x62\x51\x14\x9d\x9e\xe0\xc7\x69\xd0\x3d" + "\xfc\x25\x2f\xb6\x10\x45\xbd\x0d\xbc\x92\x86\x54\xbb\x4e\x7d\xd4" + "\x92\x75\x65\xba\x48\xa4\x64\xa1\xeb\xf7\xe7\xdc\xc0\xd7\x0a\x5e" + "\x36\x13\x0e\x4e\x35\xcc\x2c\xc6\xf3\xe7\xe7\xe5\x32\x8a\x0c\xf7" + "\x47\x28\x7a\x02\xc2\x68\x66\x19\x3a\xba\xca\x31\xe2\xdd\x43\xbe" + "\x26\x4c\x80\x12\x0c\xae\x44\x40\xeb\x69\x7d\x9e\x58\xd3\xab\xaf" + "\x69\xe6\x54\xae\x7d\x80\xee\x2c\x10\xe9\xbb\x5e\x6b\x89\x15\x2e" + "\x2c\x72\x26\xba\x7f\xe5\xa3\x66\xc5\x98\xc6\x57\xbf\x05\x1e\x55" + "\x93\xa6\x16\x83\xa6\x88\x79\x8f\x4e\xb5\x7e\x70\xeb\xf0\xa9\xa6" + "\xd5\xf9\x1f\xe6\xab\x70\x06\x43\xe0\xde\x82\xad\x0e\x04\x17\x2b" + "\x69\x82\x40\x98\x84\x14\x00\x2a\xa2\xda\x61\x7b\x35\xac\x71\x05" + "\x43\x6f\x55\x3a\x28\x4b\xd1\xa4\xeb\x3b\xf5\x03\xc2\xf8\x3c\xfd" + "\x0a\xc4\x99\x1d\xa7\x7d\x08\x5c\xd1\x15\x70\x73\xb9\xdc\x5c\xf2" + "\xfe\x2c\xc6\x21\x8a\xbe\xbd\x52\x37\x64\x04\xe5\x06\x3e\xc6\x62" + "\xa1\xe9\x8e\xcb\xc1\x02\x03\x01\x00\x01\xa3\x82\x03\x9e\x30\x82" + "\x03\x9a\x30\x11\x06\x09\x60\x86\x48\x01\x86\xf8\x42\x01\x01\x04" + "\x04\x03\x02\x05\xa0\x30\x0b\x06\x03\x55\x1d\x0f\x04\x04\x03\x02" + "\x04\xb0\x30\x81\xc3\x06\x03\x55\x1d\x23\x04\x81\xbb\x30\x81\xb8" + "\x80\x14\xca\xca\x62\x86\x04\x05\xf0\xf5\x9b\x38\xd2\x2c\x3c\x8c" + "\x65\x0f\xc6\xba\xa5\x3c\xa1\x81\x94\xa4\x81\x91\x30\x81\x8e\x31" + "\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x55\x53\x31\x17\x30\x15" + "\x06\x03\x55\x04\x08\x13\x0e\x4e\x6f\x72\x74\x68\x20\x43\x61\x72" + "\x6f\x6c\x69\x6e\x61\x31\x10\x30\x0e\x06\x03\x55\x04\x07\x13\x07" + "\x52\x61\x6c\x65\x69\x67\x68\x31\x10\x30\x0e\x06\x03\x55\x04\x0a" + "\x13\x07\x4b\x61\x74\x65\x6c\x6c\x6f\x31\x14\x30\x12\x06\x03\x55" + "\x04\x0b\x13\x0b\x53\x6f\x6d\x65\x4f\x72\x67\x55\x6e\x69\x74\x31" + "\x2c\x30\x2a\x06\x03\x55\x04\x03\x13\x23\x73\x61\x74\x2d\x72\x32" + "\x32\x30\x2d\x31\x30\x2e\x6c\x61\x62\x2e\x65\x6e\x67\x2e\x72\x64" + "\x75\x32\x2e\x72\x65\x64\x68\x61\x74\x2e\x63\x6f\x6d\x82\x09\x00" + "\xa4\xe7\xca\xeb\xbe\x43\x5d\xcc\x30\x1d\x06\x03\x55\x1d\x0e\x04" + "\x16\x04\x14\x0e\x8d\x7b\x53\xba\x5a\x9e\x92\x44\xe5\x64\x58\xa1" + "\xdb\x83\x47\x05\x3e\x32\xd3\x30\x13\x06\x03\x55\x1d\x25\x04\x0c" + "\x30\x0a\x06\x08\x2b\x06\x01\x05\x05\x07\x03\x02\x30\x2a\x06\x10" + "\x2b\x06\x01\x04\x01\x92\x08\x09\x01\xaa\xda\xbe\xbe\xfa\x5b\x01" + "\x04\x16\x0c\x14\x6d\x6f\x72\x64\x6f\x72\x5f\x75\x65\x62\x65\x72" + "\x5f\x70\x72\x6f\x64\x75\x63\x74\x30\x16\x06\x10\x2b\x06\x01\x04" + "\x01\x92\x08\x09\x01\xaa\xda\xbe\xbe\xfa\x5b\x03\x04\x02\x0c\x00" + "\x30\x16\x06\x10\x2b\x06\x01\x04\x01\x92\x08\x09\x01\xaa\xda\xbe" + "\xbe\xfa\x5b\x02\x04\x02\x0c\x00\x30\x16\x06\x10\x2b\x06\x01\x04" + "\x01\x92\x08\x09\x01\xaa\xda\xbe\xbe\xfa\x5b\x05\x04\x02\x0c\x00" + "\x30\x19\x06\x10\x2b\x06\x01\x04\x01\x92\x08\x09\x02\xaa\xda\xbe" + "\xbe\xfa\x72\x01\x04\x05\x0c\x03\x79\x75\x6d\x30\x24\x06\x11\x2b" + "\x06\x01\x04\x01\x92\x08\x09\x02\xaa\xda\xbe\xbe\xfa\x72\x01\x01" + "\x04\x0f\x0c\x0d\x75\x65\x62\x65\x72\x5f\x63\x6f\x6e\x74\x65\x6e" + "\x74\x30\x32\x06\x11\x2b\x06\x01\x04\x01\x92\x08\x09\x02\xaa\xda" + "\xbe\xbe\xfa\x72\x01\x02\x04\x1d\x0c\x1b\x31\x34\x36\x37\x33\x39" + "\x39\x32\x35\x37\x34\x33\x35\x5f\x75\x65\x62\x65\x72\x5f\x63\x6f" + "\x6e\x74\x65\x6e\x74\x30\x1d\x06\x11\x2b\x06\x01\x04\x01\x92\x08" + "\x09\x02\xaa\xda\xbe\xbe\xfa\x72\x01\x05\x04\x08\x0c\x06\x43\x75" + "\x73\x74\x6f\x6d\x30\x1e\x06\x11\x2b\x06\x01\x04\x01\x92\x08\x09" + "\x02\xaa\xda\xbe\xbe\xfa\x72\x01\x06\x04\x09\x0c\x07\x2f\x6d\x6f" + "\x72\x64\x6f\x72\x30\x17\x06\x11\x2b\x06\x01\x04\x01\x92\x08\x09" + "\x02\xaa\xda\xbe\xbe\xfa\x72\x01\x07\x04\x02\x0c\x00\x30\x18\x06" + "\x11\x2b\x06\x01\x04\x01\x92\x08\x09\x02\xaa\xda\xbe\xbe\xfa\x72" + "\x01\x08\x04\x03\x0c\x01\x31\x30\x24\x06\x0a\x2b\x06\x01\x04\x01" + "\x92\x08\x09\x04\x01\x04\x16\x0c\x14\x6d\x6f\x72\x64\x6f\x72\x5f" + "\x75\x65\x62\x65\x72\x5f\x70\x72\x6f\x64\x75\x63\x74\x30\x10\x06" + "\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x04\x02\x04\x02\x0c\x00\x30" + "\x1d\x06\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x04\x03\x04\x0f\x0c" + "\x0d\x31\x34\x36\x37\x33\x39\x39\x32\x35\x37\x34\x33\x35\x30\x11" + "\x06\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x04\x05\x04\x03\x0c\x01" + "\x31\x30\x24\x06\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x04\x06\x04" + "\x16\x0c\x14\x32\x30\x31\x36\x2d\x30\x37\x2d\x30\x31\x54\x31\x38" + "\x3a\x35\x34\x3a\x31\x37\x5a\x30\x24\x06\x0a\x2b\x06\x01\x04\x01" + "\x92\x08\x09\x04\x07\x04\x16\x0c\x14\x32\x30\x34\x39\x2d\x31\x32" + "\x2d\x30\x31\x54\x31\x33\x3a\x30\x30\x3a\x30\x30\x5a\x30\x11\x06" + "\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x04\x0c\x04\x03\x0c\x01\x30" + "\x30\x11\x06\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x04\x0e\x04\x03" + "\x0c\x01\x30\x30\x11\x06\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x04" + "\x0b\x04\x03\x0c\x01\x31\x30\x34\x06\x0a\x2b\x06\x01\x04\x01\x92" + "\x08\x09\x05\x01\x04\x26\x0c\x24\x39\x34\x35\x33\x66\x38\x65\x36" + "\x2d\x38\x34\x62\x32\x2d\x34\x38\x32\x65\x2d\x61\x33\x65\x61\x2d" + "\x30\x31\x63\x33\x62\x33\x65\x32\x36\x36\x61\x35\x30\x0d\x06\x09" + "\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00\x03\x82\x01\x01\x00" + "\xf7\x4d\xf3\x30\x53\xcd\x35\xbf\x49\x07\x29\x9b\xf0\x7a\xaa\x49" + "\x60\xda\xce\x14\x45\xb5\x32\x8f\xda\xc3\xce\x6b\xec\xbf\x20\xc0" + "\x05\xa3\x3a\x89\xc4\x7d\x66\x34\xfc\xf3\x16\xb8\xf3\x03\xda\xfc" + "\x82\x4a\xb8\x97\xf8\x67\x3d\xc2\x8c\x78\xb4\x6d\xb8\xbb\x18\xec" + "\x36\xee\xc4\x28\x79\xda\xfe\xa1\x1f\xaf\x0b\x3f\xe4\x75\xde\x83" + "\xff\x6b\xf9\x11\x60\x09\x57\xea\x85\x34\xed\x60\xe2\x94\x8b\xd6" + "\xf2\x21\x9b\xda\x97\x99\xf3\x0d\xa9\x0f\xb5\x3b\x3a\x8f\x96\x8d" + "\x0b\xdf\x30\x17\x03\xe6\x47\xc3\x71\x32\x09\x18\xbc\xc0\xa9\x83" + "\x7e\xb7\x5f\x5c\xbb\xeb\x0a\x18\x3f\xa9\x40\x98\xae\x57\xab\x99" + "\x3d\x47\x1b\x98\x8a\xdc\x6e\x85\xa2\xea\x5e\x21\x80\xa9\xb5\x48" + "\xc9\x1d\x63\xc1\x1b\xe6\x01\xa1\xbd\x84\x38\x7f\x1a\x43\xa5\xd4" + "\x7f\x41\x5b\xf6\x88\x33\xb0\xf1\xb8\x8f\xe1\x39\x69\x6f\x60\x13" + "\xd3\x5d\x70\xde\x95\x0d\x2f\xa9\x89\x6c\xd4\x3a\xeb\x22\x59\xe6" + "\x31\x67\x71\xa5\xed\xfb\xcb\x20\x11\x0c\x31\x2e\xe0\x98\x9a\x3b" + "\x9c\x7b\xa2\x74\x6f\x87\x97\xa1\xd9\x82\x7f\x7d\x62\x6b\x45\x6c" + "\x0b\x5e\x25\x43\x8a\x20\x16\x7d\xe5\x84\x18\x3f\x7c\xda\xfc\xf9"; + +int der_data_size = sizeof(der_data)-1; + +char new_data[4*1024]; + +int +main (int argc, char** argv) +{ + int result = 0; + asn1_node definitions = NULL, node1 = NULL; + char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; + const char *pkixfile = getenv ("ASN1PKIX"); + int new_data_size; + + if (!pkixfile) + pkixfile = "pkix.asn"; + + /* Encode */ + result = asn1_parser2tree (pkixfile, &definitions, errorDescription); + if (result != ASN1_SUCCESS) + { + printf ("error in %d\n", __LINE__); + exit (1); + } + + result = asn1_create_element (definitions, "PKIX1.Certificate", &node1); + if (result != ASN1_SUCCESS) + { + printf ("error in %d\n", __LINE__); + exit (1); + } + + result = asn1_der_decoding (&node1, der_data, der_data_size, errorDescription); + if (result != ASN1_SUCCESS) + { + printf ("error in %d: %s\n", __LINE__, errorDescription); + exit (1); + } + + new_data_size = sizeof(new_data); + result = asn1_der_coding (node1, "", new_data, &new_data_size, errorDescription); + if (result != ASN1_SUCCESS) + { + printf ("error in %d\n", __LINE__); + exit (1); + } + + if (new_data_size != der_data_size) + { + printf ("error in %d\n", __LINE__); + printf ("new_size is %d, expected: %d\n", new_data_size, der_data_size); + exit (1); + } + + if (memcmp(new_data, der_data, der_data_size) != 0) + { + printf ("error in %d\n", __LINE__); + exit (1); + } + + asn1_delete_structure (&node1); + asn1_delete_structure (&definitions); + + return 0; +} diff --git a/tests/object-id-decoding.c b/tests/object-id-decoding.c new file mode 100644 index 0000000..e3e9669 --- /dev/null +++ b/tests/object-id-decoding.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2016 Red Hat, Inc. + * + * This file is part of LIBTASN1. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#include "libtasn1.h" + +struct tv +{ + int der_len; + const unsigned char *der_str; + const char *oid; + int expected_error; +}; + +static const struct tv tv[] = { + {.der_len = 12, + .der_str = (void *) "\x06\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x05\x01", + .oid = "1.3.6.1.4.1.2312.9.5.1", + .expected_error = ASN1_SUCCESS}, + {.der_len = 19, + .der_str = + (void *) + "\x06\x11\x2b\x06\x01\x04\x01\x92\x08\x09\x02\xaa\xda\xbe\xbe\xfa\x72\x01\x07", + .oid = "1.3.6.1.4.1.2312.9.2.1467399257458.1.7", + .expected_error = ASN1_SUCCESS}, +}; + +int +main (int argc, char *argv[]) +{ + char str[128]; + int ret, ret_len; + size_t i; + + for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++) + { + /* decode */ + ret = + asn1_get_object_id_der (tv[i].der_str+1, + tv[i].der_len-1, &ret_len, str, + sizeof (str)); + if (ret != tv[i].expected_error) + { + fprintf (stderr, + "%d: asn1_get_object_id_der iter %lu: got %d expected %d\n", + __LINE__, (unsigned long) i, ret, tv[i].expected_error); + return 1; + } + + if (ret_len != tv[i].der_len-1) + { + fprintf (stderr, + "%d: iter %lu: error in DER, length returned is %d, had %d\n", + __LINE__, (unsigned long)i, ret_len, tv[i].der_len-1); + return 1; + } + + if (strcmp (tv[i].oid, str) != 0) + { + fprintf (stderr, + "%d: strcmp iter %lu: got invalid OID: %s, expected: %s\n", + __LINE__, (unsigned long) i, str, tv[i].oid); + return 1; + } + + } + + return 0; +} |