├── THANKS ├── src ├── versioninfo.rc.in ├── ksba.pc.in ├── asn1-constants.h ├── shared.h ├── mkerrors ├── ber-decoder.h ├── writer.h ├── der-builder.h ├── reader.h ├── convert.h ├── crl.h ├── der-encoder.h ├── gen-help.c ├── certreq.h ├── ksba-config.in ├── keyinfo.h ├── gen-help.h ├── cert.h ├── sexp-parse.h ├── ber-dump.c ├── version.c ├── stringbuf.h ├── util.h ├── ocsp.h ├── Makefile.am ├── time.c ├── ber-help.h ├── cms.h ├── libksba.vers ├── asn1-func2.c └── asn1-func.h ├── tests ├── samples │ ├── bull.crt │ ├── betsy.crt │ ├── authority.crt │ ├── ov-server.crt │ ├── ov-server.p12 │ ├── ov-user.crt │ ├── ov-user.p12 │ ├── ov2-user.crt │ ├── ov-test-crl.crl │ ├── ov-userrev.crt │ ├── ov-userrev.p12 │ ├── ov2-userrev.crt │ ├── rsa-sample1.p7m │ ├── rsa-sample1.p7s │ ├── cert_dfn_pca01.der │ ├── cert_dfn_pca15.der │ ├── detached-sig.cms │ ├── ecdh-sample1.p7m │ ├── ecdsa-sample1.p7s │ ├── ed25519-ossl-1.crt │ ├── ed25519-ossl-1.key │ ├── ed448-ossl-1.crt │ ├── ed448-ossl-1.key │ ├── ov-ocsp-server.crt │ ├── ov-serverrev.crt │ ├── ov-serverrev.p12 │ ├── ed25519-rfc8410.crt │ ├── ed25519-rfc8410.key │ ├── ov-root-ca-cert.crt │ ├── ov2-ocsp-server.crt │ ├── ov2-root-ca-cert.crt │ ├── cert_g10code_test1.der │ ├── crl_testpki_testpca.der │ ├── secp256r1-sha384_cert.crt │ ├── secp256r1-sha512_cert.crt │ ├── secp384r1-sha512_cert.crt │ ├── openssl-secp256r1ca.cert.crt │ ├── README │ ├── ecdh-sample1.p7m.asn │ └── rsa-sample1.p7m.asn ├── extra │ ├── dsig-with-id-aa-encrypKeyPref-1.cms │ └── README ├── mkoidtbl.awk ├── Makefile.am ├── t-oid.c ├── t-reader.c ├── t-dnparser.c └── t-common.h ├── m4 ├── Makefile.am ├── ltversion.m4 ├── autobuild.m4 ├── ax_prog_bison.m4 ├── ax_cc_for_build.m4 ├── ltsugar.m4 └── lt~obsolete.m4 ├── gl ├── dummyobj.c ├── m4 │ ├── gnulib.m4 │ ├── valgrind-tests.m4 │ └── alloca.m4 ├── Makefile.am └── alloca_.h ├── COPYING ├── .gitignore ├── autogen.rc ├── ChangeLog ├── doc ├── HACKING ├── Makefile.am └── ChangeLog-2011 ├── README ├── ksba.txt ├── announce.txt ├── TODO ├── README.GIT ├── mkinstalldirs ├── AUTHORS └── Makefile.am /THANKS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/THANKS -------------------------------------------------------------------------------- /src/versioninfo.rc.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/src/versioninfo.rc.in -------------------------------------------------------------------------------- /tests/samples/bull.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/bull.crt -------------------------------------------------------------------------------- /tests/samples/betsy.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/betsy.crt -------------------------------------------------------------------------------- /tests/samples/authority.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/authority.crt -------------------------------------------------------------------------------- /tests/samples/ov-server.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov-server.crt -------------------------------------------------------------------------------- /tests/samples/ov-server.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov-server.p12 -------------------------------------------------------------------------------- /tests/samples/ov-user.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov-user.crt -------------------------------------------------------------------------------- /tests/samples/ov-user.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov-user.p12 -------------------------------------------------------------------------------- /tests/samples/ov2-user.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov2-user.crt -------------------------------------------------------------------------------- /tests/samples/ov-test-crl.crl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov-test-crl.crl -------------------------------------------------------------------------------- /tests/samples/ov-userrev.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov-userrev.crt -------------------------------------------------------------------------------- /tests/samples/ov-userrev.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov-userrev.p12 -------------------------------------------------------------------------------- /tests/samples/ov2-userrev.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov2-userrev.crt -------------------------------------------------------------------------------- /tests/samples/rsa-sample1.p7m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/rsa-sample1.p7m -------------------------------------------------------------------------------- /tests/samples/rsa-sample1.p7s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/rsa-sample1.p7s -------------------------------------------------------------------------------- /tests/samples/cert_dfn_pca01.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/cert_dfn_pca01.der -------------------------------------------------------------------------------- /tests/samples/cert_dfn_pca15.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/cert_dfn_pca15.der -------------------------------------------------------------------------------- /tests/samples/detached-sig.cms: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/detached-sig.cms -------------------------------------------------------------------------------- /tests/samples/ecdh-sample1.p7m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ecdh-sample1.p7m -------------------------------------------------------------------------------- /tests/samples/ecdsa-sample1.p7s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ecdsa-sample1.p7s -------------------------------------------------------------------------------- /tests/samples/ed25519-ossl-1.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ed25519-ossl-1.crt -------------------------------------------------------------------------------- /tests/samples/ed25519-ossl-1.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ed25519-ossl-1.key -------------------------------------------------------------------------------- /tests/samples/ed448-ossl-1.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ed448-ossl-1.crt -------------------------------------------------------------------------------- /tests/samples/ed448-ossl-1.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ed448-ossl-1.key -------------------------------------------------------------------------------- /tests/samples/ov-ocsp-server.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov-ocsp-server.crt -------------------------------------------------------------------------------- /tests/samples/ov-serverrev.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov-serverrev.crt -------------------------------------------------------------------------------- /tests/samples/ov-serverrev.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov-serverrev.p12 -------------------------------------------------------------------------------- /tests/samples/ed25519-rfc8410.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ed25519-rfc8410.crt -------------------------------------------------------------------------------- /tests/samples/ed25519-rfc8410.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ed25519-rfc8410.key -------------------------------------------------------------------------------- /tests/samples/ov-root-ca-cert.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov-root-ca-cert.crt -------------------------------------------------------------------------------- /tests/samples/ov2-ocsp-server.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov2-ocsp-server.crt -------------------------------------------------------------------------------- /tests/samples/ov2-root-ca-cert.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/ov2-root-ca-cert.crt -------------------------------------------------------------------------------- /tests/samples/cert_g10code_test1.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/cert_g10code_test1.der -------------------------------------------------------------------------------- /tests/samples/crl_testpki_testpca.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/crl_testpki_testpca.der -------------------------------------------------------------------------------- /tests/samples/secp256r1-sha384_cert.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/secp256r1-sha384_cert.crt -------------------------------------------------------------------------------- /tests/samples/secp256r1-sha512_cert.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/secp256r1-sha512_cert.crt -------------------------------------------------------------------------------- /tests/samples/secp384r1-sha512_cert.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/secp384r1-sha512_cert.crt -------------------------------------------------------------------------------- /m4/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST = autobuild.m4 gpg-error.m4 libtool.m4 \ 3 | ax_prog_bison.m4 ax_cc_for_build.m4 4 | -------------------------------------------------------------------------------- /tests/samples/openssl-secp256r1ca.cert.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/samples/openssl-secp256r1ca.cert.crt -------------------------------------------------------------------------------- /tests/extra/dsig-with-id-aa-encrypKeyPref-1.cms: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/libksba/master/tests/extra/dsig-with-id-aa-encrypKeyPref-1.cms -------------------------------------------------------------------------------- /gl/dummyobj.c: -------------------------------------------------------------------------------- 1 | /* dummyobj.c -- Dummy to help libtool with a broken ar(1) */ 2 | 3 | int 4 | _ksba_dummyobj_for_broken_ar (int foo) 5 | { 6 | return foo; 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | KSBA is distributed under mixed GPL and LGPL licenses. Please see the 2 | file AUTHOR for details. The text of the used licenses can be found in 3 | the files: 4 | 5 | COPYING.LGPLv3 6 | COPYING.GPLv3 7 | COPYING.GPLv2 8 | -------------------------------------------------------------------------------- /tests/extra/README: -------------------------------------------------------------------------------- 1 | These are extra tests we don't want to distribute or even put into the 2 | CVS for confidentiality reasons. 3 | 4 | dsig-with-id-aa-encrypKeyPref-1.cms 5 | 6 | Detached signature with a signedAttribute that starts with a conetxt 7 | tag. This is to check for the bug fixed 2002-12-03. 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/ksba.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | includedir=@includedir@ 4 | libdir=@libdir@ 5 | host=@KSBA_CONFIG_HOST@ 6 | api_version=@KSBA_CONFIG_API_VERSION@ 7 | 8 | Name: ksba 9 | Description: X.509 and CMS support library 10 | Requires: gpg-error 11 | Version: @PACKAGE_VERSION@ 12 | Cflags: -I${includedir} @KSBA_CONFIG_CFLAGS@ 13 | Libs: -L${libdir} @KSBA_CONFIG_LIBS@ 14 | URL: https://www.gnupg.org/related_software/libksba/ 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.lo 2 | *.o 3 | .deps/ 4 | .libs/ 5 | /aclocal.m4 6 | /autom4te.cache 7 | /config.h.in 8 | /config.h 9 | /config.log 10 | /config.status 11 | /configure 12 | /libtool 13 | /stamp-h1 14 | /Makefile.in 15 | /Makefile 16 | /aclocal.m4 17 | /config.h.in 18 | /configure 19 | /doc/stamp-vti 20 | /doc/version.texi 21 | /gl/Makefile.in 22 | /m4/Makefile.in 23 | /src/Makefile.in 24 | /doc/Makefile.in 25 | /doc/ksba.info 26 | /tests/Makefile.in 27 | /src/asn1-parse.c 28 | /VERSION 29 | -------------------------------------------------------------------------------- /autogen.rc: -------------------------------------------------------------------------------- 1 | # autogen.sh configuration for GnuPG -*- sh -*- 2 | 3 | case "$myhost:$myhostsub" in 4 | w32:ce) 5 | extraoptions= 6 | ;; 7 | w32:) 8 | extraoptions= 9 | ;; 10 | esac 11 | 12 | case "$myhost" in 13 | w32) 14 | configure_opts="" 15 | ;; 16 | 17 | amd64) 18 | configure_opts="" 19 | ;; 20 | esac 21 | 22 | 23 | extra_aclocal_flags="-I gl/m4" 24 | 25 | final_info="./configure --enable-maintainer-mode && make" 26 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | No more ChangeLog files 2 | ======================== 3 | 4 | Do not modify any of the ChangeLog files in Libksba. Starting on 5 | December 1st, 2011 we put change information only in the GIT commit 6 | log, and generate a top-level ChangeLog file from logs at "make dist" 7 | time. As such, there are strict requirements on the form of the 8 | commit log messages. See doc/HACKING for details. The old ChangeLog 9 | files have all be renamed to ChangeLog-2011. 10 | 11 | 12 | 13 | Local Variables: 14 | buffer-read-only: t 15 | mode: text 16 | End: 17 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 3337 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.2]) 16 | m4_define([LT_PACKAGE_REVISION], [1.3337]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.2' 20 | macro_revision='1.3337' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /doc/HACKING: -------------------------------------------------------------------------------- 1 | # HACKING -*- org -*- 2 | #+TITLE: Hacking notes for Libksba 3 | #+STARTUP: showall 4 | 5 | * No more ChangeLog files 6 | 7 | Do not modify any of the ChangeLog files in Libksba. Starting 8 | on December 1st, 2011 we put change information only in the GIT 9 | commit log, and generate a top-level ChangeLog file from logs at 10 | "make dist" time. As such, there are strict requirements on the 11 | form of the commit log messages. The old ChangeLog files have all 12 | be renamed to ChangeLog-2011 13 | 14 | 15 | * Commit log requirements 16 | 17 | Your commit log should always start with a one-line summary, the 18 | second line should be blank, and the remaining lines are usually 19 | ChangeLog-style entries for all affected files. However, it's fine 20 | -- even recommended -- to write a few lines of prose describing the 21 | change, when the summary and ChangeLog entries don't give enough of 22 | the big picture. Omit the leading TABs that you're used to seeing 23 | in a "real" ChangeLog file, but keep the maximum line length at 72 24 | or smaller, so that the generated ChangeLog lines, each with its 25 | leading TAB, will not exceed 80 columns. 26 | -------------------------------------------------------------------------------- /gl/m4/gnulib.m4: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2004 Free Software Foundation, Inc. 2 | # This file is free software, distributed under the terms of the GNU 3 | # General Public License. As a special exception to the GNU General 4 | # Public License, this file may be distributed as part of a program 5 | # that contains a configuration script generated by Autoconf, under 6 | # the same distribution terms as the rest of that program. 7 | # 8 | # Generated by gnulib-tool. 9 | # 10 | # Invoked as: gnulib-tool --import 11 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --aux-dir=. --libtool alloca alloca-opt 12 | 13 | AC_DEFUN([gl_EARLY], 14 | [ 15 | ]) 16 | 17 | AC_DEFUN([gl_INIT], 18 | [ 19 | changequote(,)dnl 20 | LTALLOCA=`echo "$ALLOCA" | sed 's/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'` 21 | changequote([, ])dnl 22 | AC_SUBST(LTALLOCA) 23 | gl_FUNC_ALLOCA 24 | gl_VALGRIND_TESTS 25 | ]) 26 | 27 | dnl Usage: gl_MODULES(module1 module2 ...) 28 | AC_DEFUN([gl_MODULES], []) 29 | 30 | dnl Usage: gl_SOURCE_BASE(DIR) 31 | AC_DEFUN([gl_SOURCE_BASE], []) 32 | 33 | dnl Usage: gl_M4_BASE(DIR) 34 | AC_DEFUN([gl_M4_BASE], []) 35 | 36 | dnl Usage: gl_LIB(LIBNAME) 37 | AC_DEFUN([gl_LIB], []) 38 | 39 | dnl Usage: gl_LGPL 40 | AC_DEFUN([gl_LGPL], []) 41 | 42 | # gnulib.m4 ends here 43 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | # doc - Automake template 2 | # Copyright (C) 2002 g10 Code GmbH 3 | # 4 | # This file is part of KSBA. 5 | # 6 | # KSBA is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # KSBA is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, see . 18 | 19 | ## Process this file with automake to produce Makefile.in 20 | 21 | DISTCLEANFILES = ksba.cps 22 | 23 | EXTRA_DIST = HACKING 24 | 25 | 26 | info_TEXINFOS = ksba.texi 27 | ksba_TEXINFOS = gpl.texi 28 | 29 | online: ksba.html ksba.pdf 30 | set -e; \ 31 | echo "Uploading current manuals to www.gnupg.org ..."; \ 32 | user=werner ; \ 33 | (cd ksba.html && rsync -vr --exclude='.svn' . \ 34 | $${user}@cvs.gnupg.org:webspace/manuals/ksba/ ); \ 35 | rsync -v ksba.pdf $${user}@cvs.gnupg.org:webspace/manuals/ 36 | -------------------------------------------------------------------------------- /m4/autobuild.m4: -------------------------------------------------------------------------------- 1 | # autobuild.m4 serial 2 (autobuild-3.3) 2 | # Copyright (C) 2004 Simon Josefsson 3 | # 4 | # This file is free software, distributed under the terms of the GNU 5 | # General Public License. As a special exception to the GNU General 6 | # Public License, this file may be distributed as part of a program 7 | # that contains a configuration script generated by Autoconf, under 8 | # the same distribution terms as the rest of that program. 9 | # 10 | # This file can can be used in projects which are not available under 11 | # the GNU General Public License or the GNU Library General Public 12 | # License but which still want to provide support for Autobuild. 13 | 14 | # Usage: AB_INIT([MODE]). 15 | AC_DEFUN([AB_INIT], 16 | [ 17 | AC_REQUIRE([AC_CANONICAL_BUILD]) 18 | AC_REQUIRE([AC_CANONICAL_HOST]) 19 | 20 | AC_MSG_NOTICE([autobuild project... ${PACKAGE_NAME:-$PACKAGE}]) 21 | AC_MSG_NOTICE([autobuild revision... ${PACKAGE_VERSION:-$VERSION}]) 22 | hostname=`hostname` 23 | if test "$hostname"; then 24 | AC_MSG_NOTICE([autobuild hostname... $hostname]) 25 | fi 26 | ifelse([$1],[],,[AC_MSG_NOTICE([autobuild mode... $1])]) 27 | date=`date +%Y%m%d-%H%M%S` 28 | if test "$?" != 0; then 29 | date=`date` 30 | fi 31 | if test "$date"; then 32 | AC_MSG_NOTICE([autobuild timestamp... $date]) 33 | fi 34 | ]) 35 | -------------------------------------------------------------------------------- /gl/m4/valgrind-tests.m4: -------------------------------------------------------------------------------- 1 | # valgrind-tests.m4 serial 3 2 | dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Simon Josefsson 8 | 9 | # gl_VALGRIND_TESTS() 10 | # ------------------- 11 | # Check if valgrind is available, and set VALGRIND to it if available. 12 | AC_DEFUN([gl_VALGRIND_TESTS], 13 | [ 14 | AC_ARG_ENABLE(valgrind-tests, 15 | AS_HELP_STRING([--enable-valgrind-tests], 16 | [run self tests under valgrind]), 17 | [opt_valgrind_tests=$enableval], [opt_valgrind_tests=yes]) 18 | 19 | # Run self-tests under valgrind? 20 | if test "$opt_valgrind_tests" = "yes" && test "$cross_compiling" = no; then 21 | AC_CHECK_PROGS(VALGRIND, valgrind) 22 | fi 23 | 24 | OPTS="-q --error-exitcode=1 --leak-check=full" 25 | 26 | if test -n "$VALGRIND" \ 27 | && $VALGRIND $OPTS $SHELL -c 'exit 0' > /dev/null 2>&1; then 28 | opt_valgrind_tests=yes 29 | VALGRIND="$VALGRIND $OPTS" 30 | else 31 | opt_valgrind_tests=no 32 | VALGRIND= 33 | fi 34 | 35 | AC_MSG_CHECKING([whether self tests are run under valgrind]) 36 | AC_MSG_RESULT($opt_valgrind_tests) 37 | ]) 38 | -------------------------------------------------------------------------------- /gl/m4/alloca.m4: -------------------------------------------------------------------------------- 1 | # alloca.m4 serial 5 2 | dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | AC_DEFUN([gl_FUNC_ALLOCA], 8 | [ 9 | dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57. 10 | AC_REQUIRE([AC_PROG_CPP]) 11 | AC_REQUIRE([AC_PROG_EGREP]) 12 | 13 | AC_REQUIRE([AC_FUNC_ALLOCA]) 14 | if test $ac_cv_func_alloca_works = no; then 15 | gl_PREREQ_ALLOCA 16 | fi 17 | 18 | # Define an additional variable used in the Makefile substitution. 19 | if test $ac_cv_working_alloca_h = yes; then 20 | AC_EGREP_CPP([Need own alloca], [ 21 | #if defined __GNUC__ || defined _AIX || defined _MSC_VER 22 | Need own alloca 23 | #endif 24 | ], 25 | [AC_DEFINE(HAVE_ALLOCA, 1, 26 | [Define to 1 if you have `alloca' after including , 27 | a header that may be supplied by this distribution.]) 28 | ALLOCA_H=alloca.h], 29 | [ALLOCA_H=]) 30 | else 31 | ALLOCA_H=alloca.h 32 | fi 33 | AC_SUBST([ALLOCA_H]) 34 | 35 | AC_DEFINE(HAVE_ALLOCA_H, 1, 36 | [Define HAVE_ALLOCA_H for backward compatibility with older code 37 | that includes only if HAVE_ALLOCA_H is defined.]) 38 | ]) 39 | 40 | # Prerequisites of lib/alloca.c. 41 | # STACK_DIRECTION is already handled by AC_FUNC_ALLOCA. 42 | AC_DEFUN([gl_PREREQ_ALLOCA], [:]) 43 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | LIBKSBA 2 | --------- 3 | 4 | Copyright (C) 2001-2006, 2010-2015, 2018-2023 g10 Code GmbH 5 | 6 | This file is free software; as a special exception the author gives 7 | unlimited permission to copy and/or distribute it, with or without 8 | modifications, as long as this notice is preserved. 9 | 10 | This file is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 12 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 13 | PURPOSE. 14 | 15 | Libksba itself is distributed under the terms of the GNU General 16 | Public License, see the file AUTHORS for details. 17 | 18 | 19 | KSBA Overview 20 | ------------- 21 | 22 | KSBA (pronounced Kasbah) is a library to make X.509 certificates as 23 | well as the CMS easily accessible by other applications. Both 24 | specifications are building blocks of S/MIME and TLS. 25 | 26 | KSBA is made available as a standard shared library and reserves 27 | identifiers starting with "ksba" and "_ksba" (also uppercase and mixed 28 | case). It does not rely on another cryptographic library. 29 | 30 | 31 | Documentation 32 | ------------- 33 | 34 | A standard info format reference manual is included. However the OCSP 35 | feature has not yet been documented. See the comments in src/ocsp.c 36 | and the example tests/t-ocsp.c. The GnuPG's dirmngr module makes 37 | extensive use of the OCSP feature and may be used as another example. 38 | -------------------------------------------------------------------------------- /gl/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in. 2 | # Copyright (C) 2004 Free Software Foundation, Inc. 3 | # 4 | # This file is free software, distributed under the terms of the GNU 5 | # General Public License. As a special exception to the GNU General 6 | # Public License, this file may be distributed as part of a program 7 | # that contains a configuration script generated by Automake, under 8 | # the same distribution terms as the rest of that program. 9 | # 10 | # Generated by gnulib-tool. 11 | # Invoked as: gnulib-tool --import 12 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --aux-dir=. --libtool alloca alloca-opt valgrind-tests 13 | 14 | AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies 15 | 16 | noinst_LTLIBRARIES = libgnu.la 17 | 18 | libgnu_la_SOURCES = dummyobj.c 19 | libgnu_la_LIBADD = @LTLIBOBJS@ 20 | EXTRA_DIST = 21 | BUILT_SOURCES = 22 | SUFFIXES = 23 | MOSTLYCLEANFILES = 24 | CLEANFILES = 25 | DISTCLEANFILES = 26 | MAINTAINERCLEANFILES = 27 | 28 | ## begin gnulib module alloca 29 | 30 | 31 | libgnu_la_LIBADD += @LTALLOCA@ 32 | ## end gnulib module alloca 33 | 34 | ## begin gnulib module alloca-opt 35 | 36 | BUILT_SOURCES += $(ALLOCA_H) 37 | EXTRA_DIST += alloca_.h 38 | 39 | # We need the following in order to create an when the system 40 | # doesn't have one that works with the given compiler. 41 | all-local $(libgnu_la_OBJECTS): $(ALLOCA_H) 42 | alloca.h: alloca_.h 43 | cp $(srcdir)/alloca_.h $@-t 44 | mv $@-t $@ 45 | MOSTLYCLEANFILES += alloca.h alloca.h-t 46 | 47 | ## end gnulib module alloca-opt 48 | 49 | 50 | # Makefile.am ends here 51 | -------------------------------------------------------------------------------- /src/asn1-constants.h: -------------------------------------------------------------------------------- 1 | /* asn1-constants.h 2 | * Copyright (C) 2020 g10 Code GmbH 3 | * 4 | * This file is free software; the authors give unlimited permission 5 | * to copy, distribute and modify it. 6 | * 7 | * SPDX-License-Identifier: FSFUL 8 | */ 9 | 10 | #ifndef ASN1_CONSTANTS_H 11 | #define ASN1_CONSTANTS_H 12 | 13 | typedef enum { 14 | TYPE_NONE = 0, 15 | TYPE_BOOLEAN = 1, 16 | TYPE_INTEGER = 2, 17 | TYPE_BIT_STRING = 3, 18 | TYPE_OCTET_STRING = 4, 19 | TYPE_NULL = 5, 20 | TYPE_OBJECT_ID = 6, 21 | TYPE_OBJECT_DESCRIPTOR = 7, 22 | TYPE_EXTERNAL = 8, 23 | TYPE_REAL = 9, 24 | TYPE_ENUMERATED = 10, 25 | TYPE_EMBEDDED_PDV = 11, 26 | TYPE_UTF8_STRING = 12, 27 | TYPE_REALTIVE_OID = 13, 28 | TYPE_SEQUENCE = 16, 29 | TYPE_SET = 17, 30 | TYPE_NUMERIC_STRING = 18, 31 | TYPE_PRINTABLE_STRING = 19, 32 | TYPE_TELETEX_STRING = 20, 33 | TYPE_VIDEOTEX_STRING = 21, 34 | TYPE_IA5_STRING = 22, 35 | TYPE_UTC_TIME = 23, 36 | TYPE_GENERALIZED_TIME = 24, 37 | TYPE_GRAPHIC_STRING = 25, 38 | TYPE_VISIBLE_STRING = 26, 39 | TYPE_GENERAL_STRING = 27, 40 | TYPE_UNIVERSAL_STRING = 28, 41 | TYPE_CHARACTER_STRING = 29, 42 | TYPE_BMP_STRING = 30, 43 | /* the following values do not correspond to an Universal tag */ 44 | TYPE_CONSTANT = 128, 45 | TYPE_IDENTIFIER, 46 | TYPE_TAG, 47 | TYPE_DEFAULT, 48 | TYPE_SIZE, 49 | TYPE_SEQUENCE_OF, 50 | TYPE_ANY, 51 | TYPE_SET_OF, 52 | TYPE_DEFINITIONS, 53 | TYPE_CHOICE, 54 | TYPE_IMPORTS, 55 | TYPE_PRE_SEQUENCE /* premanufactured Seqences as used by the DER encoder. */ 56 | } node_type_t; 57 | 58 | 59 | enum tag_class { 60 | CLASS_UNIVERSAL = 0, 61 | CLASS_APPLICATION = 1, 62 | CLASS_CONTEXT = 2, 63 | CLASS_PRIVATE =3 64 | }; 65 | 66 | #endif /*ASN1_CONSTANTS_H*/ 67 | -------------------------------------------------------------------------------- /src/shared.h: -------------------------------------------------------------------------------- 1 | /* shared.h - values shared with other software 2 | * Copyright (C) 2001, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef SHARED_H 32 | #define SHARED_H 33 | 34 | #ifdef GCRYPT_VERSION 35 | /* It is pretty useless to use this file if we would link this library 36 | to Libgcrypt anyway */ 37 | #error please make shure that gcrypt.h is not included 38 | #endif 39 | 40 | enum gcry_md_algos { 41 | GCRY_MD_NONE = 0, 42 | GCRY_MD_MD5 = 1, 43 | GCRY_MD_SHA1 = 2, 44 | GCRY_MD_RMD160 = 3, 45 | GCRY_MD_TIGER = 6, 46 | GCRY_MD_SHA256 = 8, 47 | GCRY_MD_SHA384 = 9, 48 | GCRY_MD_SHA512 = 10, 49 | GCRY_MD_SHA224 = 11 50 | }; 51 | 52 | 53 | 54 | #endif /*SHARED_H*/ 55 | -------------------------------------------------------------------------------- /gl/alloca_.h: -------------------------------------------------------------------------------- 1 | /* Memory allocation on the stack. 2 | 3 | Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004 Free Software 4 | Foundation, Inc. 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published 8 | by the Free Software Foundation; either version 3, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public 17 | License along with this program; if not, see . 18 | */ 19 | 20 | /* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H 21 | means there is a real alloca function. */ 22 | #ifndef _GNULIB_ALLOCA_H 23 | # define _GNULIB_ALLOCA_H 24 | 25 | /* alloca (N) returns a pointer to N bytes of memory 26 | allocated on the stack, which will last until the function returns. 27 | Use of alloca should be avoided: 28 | - inside arguments of function calls - undefined behaviour, 29 | - in inline functions - the allocation may actually last until the 30 | calling function returns, 31 | - for huge N (say, N >= 65536) - you never know how large (or small) 32 | the stack is, and when the stack cannot fulfill the memory allocation 33 | request, the program just crashes. 34 | */ 35 | 36 | #ifdef __GNUC__ 37 | # define alloca __builtin_alloca 38 | #elif defined _AIX 39 | # define alloca __alloca 40 | #elif defined _MSC_VER 41 | # include 42 | # define alloca _alloca 43 | #else 44 | # include 45 | # ifdef __cplusplus 46 | extern "C" 47 | # endif 48 | void *alloca (size_t); 49 | #endif 50 | 51 | #endif /* _GNULIB_ALLOCA_H */ 52 | -------------------------------------------------------------------------------- /src/mkerrors: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # mkerrors - Extract error strings from ksba.h 3 | # and create C source for ksba_strerror 4 | # Copyright (C) 2001 g10 Code GmbH 5 | # 6 | # This file is part of KSBA. 7 | # 8 | # KSBA is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation; either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # KSBA is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program; if not, see . 20 | 21 | 22 | cat < 27 | #include "ksba.h" 28 | 29 | /** 30 | * ksba_strerror: 31 | * @err: Error code 32 | * 33 | * This function returns a textual representaion of the given 34 | * errocode. If this is an unknown value, a string with the value 35 | * is returned (which is hold in a static buffer). 36 | * 37 | * Return value: String with the error description. 38 | **/ 39 | const char * 40 | ksba_strerror (KsbaError err) 41 | { 42 | const char *s; 43 | static char buf[25]; 44 | 45 | switch (err) 46 | { 47 | case -1: s="EOF"; break; 48 | EOF 49 | 50 | awk ' 51 | /KSBA_No_Error/ { okay=1 } 52 | !okay {next} 53 | /}/ { exit 0 } 54 | /KSBA_[A-Za-z_]*/ { print_code($1) } 55 | 56 | 57 | function print_code( s ) 58 | { 59 | printf " case %s: s=\"", s ; 60 | gsub(/_/, " ", s ); 61 | printf "%s\"; break;\n", substr(s,6); 62 | } 63 | ' 64 | 65 | cat < 24 | 25 | %%updated: ??????? 26 | 27 | %%keywords: encryption, digital signature, GnuPG, X.509, S/MIME, CMS 28 | 29 | %%interface: 30 | 31 | %%programs: 32 | 33 | %%GNU: no 34 | 35 | %%web-page: http://www.gnupg.org/gpgme.html 36 | 37 | %%support: paid extension/consulting from http://www.g10code.com 38 | 39 | %%doc: English programmer reference in Texinfo, Postscript, HTML included 40 | 41 | %%developers: Werner Koch . 42 | 43 | %%contributors: 44 | 45 | %%sponsors: 46 | 47 | %%source: 48 | 49 | %%debian: 50 | 51 | %%redhat: 52 | 53 | %%repository: See http://www.gnupg.org/cvs-access.html 54 | 55 | %%related: 56 | 57 | %%source-language: C 58 | 59 | %%supported-languages: C, C++ 60 | 61 | %%use-requirements: 62 | 63 | %%build-prerequisites: 64 | 65 | %%weak-prerequisites: 66 | 67 | %%source-prerequisites: 68 | 69 | %%version: not released 70 | 71 | %%announce-list: announce@gnupg.org announce-request@gnupg.org 72 | 73 | %%announce-news: 74 | 75 | %%help-list: 76 | 77 | %%help-news: 78 | 79 | %%dev-list: gnupg-devel@gnupg.org gnupg-devel-request@gnupg.org 80 | 81 | %%dev-news: 82 | 83 | %%bug-list: 84 | 85 | %%bug-database: 86 | 87 | %%entry written by: Werner Koch 88 | -------------------------------------------------------------------------------- /announce.txt: -------------------------------------------------------------------------------- 1 | Hello! 2 | 3 | We are pleased to announce version 1.0.4 of Libksba. 4 | 5 | Libksba is an X.509 and CMS (PKCS#7) library. It is for example 6 | required to build the S/MIME part of GnuPG-2 (gpgsm). The only build 7 | requirement for Libksba itself is the libgpg-error package. There are 8 | no other dependencies; actual cryptographic operations need to be done 9 | by the user. Libksba is distributed under the GPLv3+. There are no 10 | user tools accompanying this software, thus it is mostly relevant to 11 | developers. 12 | 13 | This is a maintenance release. 14 | 15 | You may download the library and its OpenPGP signature from: 16 | 17 | ftp://ftp.gnupg.org/gcrypt/libksba/libksba-1.0.4.tar.bz2 (553k) 18 | ftp://ftp.gnupg.org/gcrypt/libksba/libksba-1.0.4.tar.bz2.sig 19 | 20 | As an alternative you may use a patch file to upgrade the previous 21 | version of the library: 22 | 23 | ftp://ftp.gnupg.org/gcrypt/libksba/libksba-1.0.3-1.0.4.diff.bz2 (144k) 24 | 25 | (the reason for the large patch file is due to newer version of files 26 | from the build systems) or from any mirror of that server 27 | (http://www.gnupg.org/mirrors.html). 28 | 29 | SHA-1 checksums are: 30 | 31 | 05d0b803bac34b53e07619ca52425452be535792 libksba-1.0.4.tar.bz2 32 | 51249c45ea74c61325c1f2462045ba5a4148bf38 libksba-1.0.3-1.0.4.diff.bz2 33 | 34 | 35 | Noteworthy changes in version 1.0.4 (2008-09-22) 36 | ------------------------------------------------ 37 | 38 | * Write smimeCapabilities according to RFC3851 to help Mozilla. 39 | 40 | * Support DSA. 41 | 42 | * The visibility attribute is now used if supported by the toolchain. 43 | 44 | 45 | Commercial support contracts for Libksba are available, and they help 46 | finance continued maintenance. g10 Code, a Duesseldorf based company 47 | owned and headed by Libksba's principal author, is currently funding 48 | its development. We are always looking for interesting development 49 | projects. See also http://www.gnupg.org/service.html . 50 | 51 | 52 | Happy hacking, 53 | 54 | Werner 55 | -------------------------------------------------------------------------------- /tests/mkoidtbl.awk: -------------------------------------------------------------------------------- 1 | # mkoidtbl.awk - Create OID table from Peter Gutmann's dumpasn1.cfg 2 | # Copyright (C) 2004 g10 Code GmbH 3 | # 4 | # This file is free software; as a special exception the author gives 5 | # unlimited permission to copy and/or distribute it, with or without 6 | # modifications, as long as this notice is preserved. 7 | # 8 | # This file is distributed in the hope that it will be useful, but 9 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 10 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 | # 12 | 13 | # This file takes a list of OID description in a format like 14 | # 15 | # # Comment line, the next line identifies a new record 16 | # OID = 06 05 02 82 06 01 0A 17 | # Comment = Deutsche Telekom 18 | # Description = Telesec (0 2 262 1 10) 19 | # 20 | # And creates a new table in IETF notation with lines like 21 | # 0.2.262.1.10 Telesec Deutsche Telekom 22 | # comment lines may also occur in the output. 23 | # 24 | 25 | 26 | BEGIN { 27 | print "static struct { char *oid, *desc, *comment; } oidtranstbl[] = {" 28 | } 29 | 30 | /^[ \t]*#/ { next } 31 | /^OID/ { flush() 32 | oid = substr($0, index($0, "=") + 2) 33 | gsub (/[ \t]+/, ".", oid) 34 | } 35 | /^Comment/ { comment = substr($0, index($0, "=") + 2 ) 36 | gsub(/\r/, "", comment) 37 | gsub (/\\/, "\\\\", comment) 38 | gsub (/"/, "\\\"", comment) 39 | gsub (/\(\?\?\?\)/, "(?)", comment) 40 | } 41 | /^Description/ { 42 | desc = substr($0, index($0, "=") + 2) 43 | gsub(/\r/, "", desc) 44 | if (match (desc, /\([0-9 \t]+\)/) > 2) { 45 | oid = substr(desc, RSTART+1, RLENGTH-2 ) 46 | desc = substr(desc, 1, RSTART-1); 47 | } 48 | gsub (/[ \t]+/, ".", oid) 49 | gsub (/\\/, "\\\\", desc) 50 | gsub (/"/, "\\\"", desc) 51 | sub (/[ \t]*$/, "", desc) 52 | } 53 | 54 | END { flush(); print " { NULL, NULL, NULL }\n};" } 55 | 56 | function flush() { 57 | if(oid && desc) 58 | printf " { \"%s\", \"%s\", \"%s\" },\n", oid, desc, comment 59 | oid = desc = comment = "" 60 | } 61 | -------------------------------------------------------------------------------- /src/ber-decoder.h: -------------------------------------------------------------------------------- 1 | /* ber-decoder.h - Definitions for the Basic Encoding Rules Decoder 2 | * Copyright (C) 2001, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef BER_DECODER_H 32 | #define BER_DECODER_H 1 33 | 34 | #include "asn1-func.h" 35 | 36 | struct ber_decoder_s; 37 | typedef struct ber_decoder_s *BerDecoder; 38 | 39 | BerDecoder _ksba_ber_decoder_new (void); 40 | void _ksba_ber_decoder_release (BerDecoder d); 41 | 42 | gpg_error_t _ksba_ber_decoder_set_module (BerDecoder d, ksba_asn_tree_t module); 43 | gpg_error_t _ksba_ber_decoder_set_reader (BerDecoder d, ksba_reader_t r); 44 | 45 | gpg_error_t _ksba_ber_decoder_dump (BerDecoder d, FILE *fp); 46 | gpg_error_t _ksba_ber_decoder_decode (BerDecoder d, const char *start_name, 47 | unsigned int flags, 48 | AsnNode *r_root, 49 | unsigned char **r_image, 50 | size_t *r_imagelen); 51 | 52 | #define BER_DECODER_FLAG_FAST_STOP 1 53 | 54 | 55 | #endif /*BER_DECODER_H*/ 56 | -------------------------------------------------------------------------------- /src/writer.h: -------------------------------------------------------------------------------- 1 | /* writer.h - internal definitions for the writer object. 2 | * Copyright (C) 2001, 2010, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef WRITER_H 32 | #define WRITER_H 1 33 | 34 | #include 35 | 36 | enum writer_type { 37 | WRITER_TYPE_NONE = 0, 38 | WRITER_TYPE_FD, 39 | WRITER_TYPE_FILE, 40 | WRITER_TYPE_CB, 41 | WRITER_TYPE_MEM 42 | }; 43 | 44 | 45 | struct ksba_writer_s { 46 | int error; 47 | unsigned long nwritten; 48 | enum writer_type type; 49 | int ndef_is_open; 50 | 51 | gpg_error_t (*filter)(void*, 52 | const void *,size_t, size_t *, 53 | void *, size_t, size_t *); 54 | void *filter_arg; 55 | 56 | union { 57 | int fd; /* for WRITER_TYPE_FD */ 58 | FILE *file; /* for WRITER_TYPE_FILE */ 59 | struct { 60 | int (*fnc)(void*,const void *,size_t); 61 | void *value; 62 | } cb; /* for WRITER_TYPE_CB */ 63 | struct { 64 | unsigned char *buffer; 65 | size_t size; 66 | } mem; /* for WRITER_TYPE_MEM */ 67 | } u; 68 | void (*notify_cb)(void*,ksba_writer_t); 69 | void *notify_cb_value; 70 | }; 71 | 72 | 73 | 74 | 75 | #endif /*WRITER_H*/ 76 | -------------------------------------------------------------------------------- /src/der-builder.h: -------------------------------------------------------------------------------- 1 | /* der-builder.h - Straightforward DER object builder 2 | * Copyright (C) 2020 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * This file is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This file is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #ifndef DER_BUILDER_H 22 | #define DER_BUILDER_H 1 23 | 24 | /* A generic release function. If we add a DER parser we will use the 25 | * same object and then it does not make sense to have several release 26 | * functions. */ 27 | void _ksba_der_release (ksba_der_t hd); 28 | 29 | /* Create a new builder context. */ 30 | ksba_der_t _ksba_der_builder_new (unsigned int nitems); 31 | /* Reset a builder context. */ 32 | void _ksba_der_builder_reset (ksba_der_t d); 33 | 34 | void _ksba_der_add_ptr (ksba_der_t d, int class, int tag, 35 | void *value, size_t valuelen); 36 | void _ksba_der_add_val (ksba_der_t d, int class, int tag, 37 | const void *value, size_t valuelen); 38 | void _ksba_der_add_oid (ksba_der_t d, const char *oidstr); 39 | void _ksba_der_add_bts (ksba_der_t d, const void *value, size_t valuelen, 40 | unsigned int unusedbits); 41 | void _ksba_der_add_int (ksba_der_t d, const void *value, size_t valuelen, 42 | int force_positive); 43 | void _ksba_der_add_der (ksba_der_t d, const void *der, size_t derlen); 44 | void _ksba_der_add_tag (ksba_der_t d, int class, int tag); 45 | void _ksba_der_add_end (ksba_der_t d); 46 | 47 | gpg_error_t _ksba_der_builder_get (ksba_der_t d, 48 | unsigned char **r_obj, size_t *r_objlen); 49 | 50 | 51 | #endif /*DER_BUILDER_H*/ 52 | -------------------------------------------------------------------------------- /src/reader.h: -------------------------------------------------------------------------------- 1 | /* reader.h - internl definitions for the reder object. 2 | * Copyright (C) 2001, 2010, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef READER_H 32 | #define READER_H 1 33 | 34 | #include 35 | 36 | enum reader_type { 37 | READER_TYPE_NONE = 0, 38 | READER_TYPE_MEM, 39 | READER_TYPE_FD, 40 | READER_TYPE_FILE, 41 | READER_TYPE_CB 42 | }; 43 | 44 | 45 | struct ksba_reader_s { 46 | int eof; 47 | int error; /* If an error occured, takes the value of errno. */ 48 | unsigned long nread; 49 | struct { 50 | unsigned char *buf; 51 | size_t size; /* allocated size */ 52 | size_t length; /* used size */ 53 | size_t readpos; /* offset where to start the next read */ 54 | } unread; 55 | enum reader_type type; 56 | union { 57 | struct { 58 | unsigned char *buffer; 59 | size_t size; 60 | size_t readpos; 61 | } mem; /* for READER_TYPE_MEM */ 62 | int fd; /* for READER_TYPE_FD */ 63 | FILE *file; /* for READER_TYPE_FILE */ 64 | struct { 65 | int (*fnc)(void*,char *,size_t,size_t*); 66 | void *value; 67 | } cb; /* for READER_TYPE_CB */ 68 | } u; 69 | void (*notify_cb)(void*,ksba_reader_t); 70 | void *notify_cb_value; 71 | }; 72 | 73 | 74 | 75 | 76 | #endif /*READER_H*/ 77 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | -*- outline -*- 2 | 3 | * src/dn.c: 4 | 5 | ** Check that error handling of bad utf-8 encoding is correct 6 | ** There is an ambiguity in rfc2253. 7 | This is related to the handling of spaces around delimiters. At one 8 | place it talks about whitespace and few lines later it talks about 9 | just the space characters which must be ignored. How should that be 10 | solved? This is only related to spaces at the beginning or end of a 11 | name part when old style quoting is not used. 12 | 13 | * src/der-decoder.c: 14 | 15 | ** should work on a stripped down parse tree 16 | 17 | ** Allow to specify the desired top element. 18 | Or a list so that it can detect the needed tree itself 19 | 20 | * src/der-encoder.c 21 | ** Setting default values is missing 22 | ** Tags > 31 are not supported. 23 | 24 | * src/asn1-* 25 | ** Cleanup the used data structures and remove unneeded functions. 26 | ** Think about a public API to the Asn functions. 27 | 28 | * src/cms* 29 | ** split some stuff from cms.c into a new cms-build.c 30 | ** can't handle CRL infos in certificates 31 | This is not a problem within the Aegypten project as CRL aren't be 32 | retrieved by online means. 33 | ** cant't handle unprotected attributes 34 | e.g. for counter signatures. Not needed in Aegypten. 35 | 36 | 37 | * src/keyinfo.c 38 | ** Do we need to support BER encoded stuff? 39 | 40 | * src/time.c 41 | ** Allow for other timezones 42 | 43 | * src/reader.c 44 | ** ksba_reader_unread limited to 100 bytes 45 | Actually the reader is limited to 100 bytes over the first unread 46 | size. Easy to fix. 47 | 48 | * General 49 | ** The ASN.1 parse tree is not released in all places 50 | ** Some memory is not released in case of errors. 51 | 52 | * src/crl.c 53 | ** certificateIssuer not supported 54 | To support this we need to have an extended ksba_crl_get_item 55 | function to either return the issuer or at least set a flag to 56 | indicate that such an extension is available. If this new API is 57 | used we will move detection of the critical certificateIssuer 58 | extension into the old ksba_crl_get_item and bail out only there. 59 | If the new version of that function is used there won't be a need to 60 | bail out. Example of a CRL using this extension: 61 | http://pks.telesec.de/telesec/servlet/download_cr (2006-09-04). 62 | 63 | ** Allow fetching of all entry extensions. 64 | -------------------------------------------------------------------------------- /README.GIT: -------------------------------------------------------------------------------- 1 | If you are building from GIT, run the script 2 | 3 | ./autogen.sh 4 | 5 | first, to make sure that you have all the necessary maintainer tools 6 | are installed and to build the actual configuration files. If you 7 | have just checked out from GIT, you should add the option "--force" to 8 | autogen.sh so that meta data is noticed by autom4te.cache. Then run 9 | 10 | ./configure --enable-maintainer-mode 11 | 12 | followed by the usual make. 13 | 14 | If autogen.sh complains about insufficient versions of the required 15 | tools, or the tools are not installed, you may use environment 16 | variables to override the default tool names: 17 | 18 | AUTOMAKE_SUFFIX is used as a suffix for all tools from the automake 19 | package. For example 20 | AUTOMAKE_SUFFIX="-1.7" ./autogen.sh 21 | uses "automake-1.7" and "aclocal-1.7. 22 | AUTOMAKE_PREFIX is used as a prefix for all tools from the automake 23 | page and may be combined with AUTOMAKE_SUFFIX. e.g.: 24 | AUTOMAKE_PREFIX=/usr/foo/bin ./autogen.sh 25 | uses "automake" and "aclocal" in the /usr/foo/bin 26 | directory. 27 | AUTOCONF_SUFFIX is used as a suffix for all tools from the automake 28 | package 29 | AUTOCONF_PREFIX is used as a prefix for all tools from the automake 30 | package 31 | GETTEXT_SUFFIX is used as a suffix for all tools from the gettext 32 | package 33 | GETTEXT_PREFIX is used as a prefix for all tools from the gettext 34 | package 35 | 36 | It is also possible to use the variable name AUTOMAKE, AUTOCONF, 37 | ACLOCAL, AUTOHEADER, GETTEXT and MSGMERGE to directly specify the name 38 | of the programs to run. It is however better to use the suffix and 39 | prefix forms as described above because that does not require 40 | knowledge about the actual tools used by autogen.sh. 41 | 42 | 43 | Please don't use autopoint, libtoolize or autoreconf unless you are 44 | the current maintainer and want to update the standard configuration 45 | files. All those files should be in GIT and only updated manually 46 | if the maintainer decides that newer versions are required. The 47 | maintainer should also make sure that the required version of automake 48 | et al. are properly indicated at the top of configure.ac and take care 49 | to copy the files and not merely use symlinks. 50 | -------------------------------------------------------------------------------- /doc/ChangeLog-2011: -------------------------------------------------------------------------------- 1 | 2011-12-01 Werner Koch 2 | 3 | NB: ChangeLog files are no longer manually maintained. Starting 4 | on December 1st, 2011 we put change information only in the GIT 5 | commit log, and generate a top-level ChangeLog file from logs at 6 | "make dist". See doc/HACKING for details. 7 | 8 | 2008-11-12 Marcus Brinkmann 9 | 10 | * ksba.texi: Clear up wording on reference counting. 11 | 12 | 2007-07-04 Werner Koch 13 | 14 | Changed license to GPLv3. 15 | 16 | * gpl.texi: Changed text to GPLv3. 17 | 18 | 2006-11-03 Werner Koch 19 | 20 | * ksba.texi (ksba_cert_get_key_usage): Add list of attributes. 21 | Provided by Brad Hards. 22 | (ksba_cert_get_key_ext_usage): New. 23 | 24 | 2006-07-03 Werner Koch 25 | 26 | * ksba.texi (DNs): New section 27 | 28 | 2006-03-30 Brad Hards (wk) 29 | 30 | * ksba.texi: Fixed typos and other errors. 31 | 32 | 2005-04-15 Werner Koch 33 | 34 | * ksba.texi: Added a new function. Markup improvements. 35 | 36 | 2005-02-08 Werner Koch 37 | 38 | * ksba.texi: Fixed direntry. 39 | 40 | 2004-03-23 Werner Koch 41 | 42 | * ksba.texi: Added 2 more functions. Minor other updates. 43 | 44 | 2004-01-28 Werner Koch 45 | 46 | * ksba.info (components): Add a table of used labels. 47 | 48 | 2003-12-08 Werner Koch 49 | 50 | * Makefile.am (ksba_TEXINFOS): Removed fdl.texi. 51 | 52 | 2003-12-01 Werner Koch 53 | 54 | * ksba.texi: Changed license to GPL. 55 | * fdl.texi: Removed 56 | 57 | 2002-11-13 Werner Koch 58 | 59 | * ksba.texi: Sanitized the wording of fixmes and added pointers to 60 | example code. 61 | 62 | 2002-06-19 Werner Koch 63 | 64 | * ksba.texi: Fixed the direntry. Noted by Thomas Koester. 65 | 66 | 2002-04-15 Werner Koch 67 | 68 | * ksba.texi: Add new functions. 69 | 70 | Copyright 2002, 2003, 2004, 2005 g10 Code GmbH 71 | 72 | This file is free software; as a special exception the author gives 73 | unlimited permission to copy and/or distribute it, with or without 74 | modifications, as long as this notice is preserved. 75 | 76 | This file is distributed in the hope that it will be useful, but 77 | WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 78 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 79 | -------------------------------------------------------------------------------- /src/convert.h: -------------------------------------------------------------------------------- 1 | /* convert.h 2 | * Copyright (C) 2001, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef CONVERT_H 32 | #define CONVERT_H 33 | 34 | #include "asn1-func.h" 35 | 36 | /*-- time.c --*/ 37 | gpg_error_t _ksba_asntime_to_iso (const char *buffer, size_t length, 38 | int is_utctime, ksba_isotime_t timebuf); 39 | gpg_error_t _ksba_assert_time_format (const ksba_isotime_t atime); 40 | void _ksba_copy_time (ksba_isotime_t d, const ksba_isotime_t s); 41 | int _ksba_cmp_time (const ksba_isotime_t a, const ksba_isotime_t b); 42 | int _ksba_current_time (ksba_isotime_t timebuf); 43 | 44 | 45 | /*-- dn.c --*/ 46 | gpg_error_t _ksba_dn_to_str (const unsigned char *image, AsnNode node, 47 | char **r_string); 48 | gpg_error_t _ksba_derdn_to_str (const unsigned char *der, size_t derlen, 49 | char **r_string); 50 | gpg_error_t _ksba_dn_from_str (const char *string, char **rbuf, size_t *rlength); 51 | 52 | /*-- oid.c --*/ 53 | char *_ksba_oid_node_to_str (const unsigned char *image, AsnNode node); 54 | gpg_error_t _ksba_oid_from_buf (const void *buffer, size_t buflen, 55 | unsigned char **rbuf, size_t *rlength); 56 | 57 | 58 | /*-- name.c --*/ 59 | gpg_error_t _ksba_name_new_from_der (ksba_name_t *r_name, 60 | const unsigned char *image, 61 | size_t imagelen); 62 | 63 | 64 | #endif /*CONVERT_H*/ 65 | -------------------------------------------------------------------------------- /src/crl.h: -------------------------------------------------------------------------------- 1 | /* crl.h - Internal definitions for the CRL Parser 2 | * Copyright (C) 2002, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef CRL_H 32 | #define CRL_H 1 33 | 34 | #include "ksba.h" 35 | 36 | #ifndef HAVE_TYPEDEFD_ASNNODE 37 | typedef struct asn_node_struct *AsnNode; /* FIXME: should not go here */ 38 | #define HAVE_TYPEDEFD_ASNNODE 39 | #endif 40 | 41 | 42 | struct crl_extn_s { 43 | struct crl_extn_s *next; 44 | char *oid; 45 | int critical; 46 | size_t derlen; 47 | unsigned char der[1]; 48 | }; 49 | typedef struct crl_extn_s *crl_extn_t; 50 | 51 | struct ksba_crl_s { 52 | gpg_error_t last_error; 53 | 54 | ksba_reader_t reader; 55 | int any_parse_done; 56 | 57 | void (*hash_fnc)(void *, const void *, size_t); 58 | void *hash_fnc_arg; 59 | 60 | struct { 61 | struct tag_info ti; 62 | unsigned long outer_len, tbs_len, seqseq_len; 63 | int outer_ndef, tbs_ndef, seqseq_ndef; 64 | int have_seqseq; 65 | } state; 66 | 67 | int crl_version; 68 | struct { 69 | char *oid; 70 | char *parm; 71 | size_t parmlen; 72 | } algo; 73 | struct { 74 | AsnNode root; /* root of the tree with the values */ 75 | unsigned char *image; 76 | size_t imagelen; 77 | } issuer; 78 | ksba_isotime_t this_update; 79 | ksba_isotime_t next_update; 80 | 81 | struct { 82 | ksba_sexp_t serial; 83 | ksba_crl_reason_t reason; 84 | ksba_isotime_t revocation_date; 85 | } item; 86 | 87 | crl_extn_t extension_list; 88 | ksba_sexp_t sigval; 89 | 90 | struct { 91 | int used; 92 | char buffer[8192]; 93 | } hashbuf; 94 | 95 | }; 96 | 97 | 98 | /*-- crl.c --*/ 99 | 100 | 101 | #endif /*CRL_H*/ 102 | -------------------------------------------------------------------------------- /src/der-encoder.h: -------------------------------------------------------------------------------- 1 | /* der-encoder.h - Definitions for the Distinguished Encoding Rules Encoder 2 | * Copyright (C) 2001, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef DER_ENCODER_H 32 | #define DER_ENCODER_H 1 33 | 34 | #include "asn1-func.h" 35 | 36 | struct der_encoder_s; 37 | typedef struct der_encoder_s *DerEncoder; 38 | 39 | DerEncoder _ksba_der_encoder_new (void); 40 | void _ksba_der_encoder_release (DerEncoder d); 41 | 42 | gpg_error_t _ksba_der_encoder_set_module (DerEncoder d, ksba_asn_tree_t module); 43 | gpg_error_t _ksba_der_encoder_set_writer (DerEncoder d, ksba_writer_t w); 44 | 45 | 46 | gpg_error_t _ksba_der_write_integer (ksba_writer_t w, 47 | const unsigned char *value); 48 | gpg_error_t _ksba_der_write_algorithm_identifier ( 49 | ksba_writer_t w, const char *oid, const void *parm, size_t parmlen); 50 | 51 | 52 | 53 | gpg_error_t _ksba_der_copy_tree (AsnNode dst, 54 | AsnNode src, const unsigned char *srcimage); 55 | 56 | 57 | 58 | gpg_error_t _ksba_der_store_time (AsnNode node, const ksba_isotime_t atime); 59 | gpg_error_t _ksba_der_store_string (AsnNode node, const char *string); 60 | gpg_error_t _ksba_der_store_integer (AsnNode node, const unsigned char *value); 61 | gpg_error_t _ksba_der_store_oid (AsnNode node, const char *oid); 62 | gpg_error_t _ksba_der_store_octet_string (AsnNode node, 63 | const char *buf, size_t len); 64 | gpg_error_t _ksba_der_store_sequence (AsnNode node, 65 | const unsigned char *buf, size_t len); 66 | gpg_error_t _ksba_der_store_null (AsnNode node); 67 | 68 | 69 | gpg_error_t _ksba_der_encode_tree (AsnNode root, 70 | unsigned char **r_image, size_t *r_imagelen); 71 | 72 | 73 | 74 | #endif /*DER_ENCODER_H*/ 75 | -------------------------------------------------------------------------------- /src/gen-help.c: -------------------------------------------------------------------------------- 1 | /* gen-help.c - Helper functions used by build time tools 2 | * Copyright (C) 2010 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Fountion; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * KSBA is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | /* No config.h - this file needs to build as plain ISO-C. */ 21 | #include 22 | #include 23 | #include 24 | 25 | #include "gen-help.h" 26 | 27 | 28 | static void 29 | out_of_core(void) 30 | { 31 | fputs ("\nfatal: out of memory\n", stderr); 32 | exit (2); 33 | } 34 | 35 | 36 | 37 | /* Implementation of the common xfoo() memory allocation functions */ 38 | void * 39 | xmalloc (size_t n ) 40 | { 41 | void *p = malloc (n); 42 | if (!p) 43 | out_of_core (); 44 | return p; 45 | } 46 | 47 | void * 48 | xcalloc (size_t n, size_t m) 49 | { 50 | void *p = calloc (n, m); 51 | if (!p) 52 | out_of_core (); 53 | return p; 54 | } 55 | 56 | void * 57 | xrealloc (void *mem, size_t n) 58 | { 59 | void *p = realloc (mem, n); 60 | if (!p) 61 | out_of_core (); 62 | return p; 63 | } 64 | 65 | 66 | char * 67 | xstrdup (const char *str) 68 | { 69 | char *p = strdup (str); 70 | if (!p) 71 | out_of_core (); 72 | return p; 73 | } 74 | 75 | void 76 | xfree (void *a) 77 | { 78 | if (a) 79 | free (a); 80 | } 81 | 82 | 83 | /* Our version of stpcpy to avoid conflicts with already availabale 84 | implementations. */ 85 | char * 86 | gen_help_stpcpy (char *a, const char *b) 87 | { 88 | while (*b) 89 | *a++ = *b++; 90 | *a = 0; 91 | 92 | return a; 93 | } 94 | 95 | 96 | /* Simple replacement function to avoid the need for a build libgpg-error */ 97 | const char * 98 | gpg_strerror (int err) 99 | { 100 | switch (err) 101 | { 102 | case 0: return "Success"; 103 | case GPG_ERR_GENERAL: return "General error"; 104 | case GPG_ERR_SYNTAX: return "Syntax error"; 105 | case GPG_ERR_INV_VALUE: return "Invalid value"; 106 | case GPG_ERR_BUG: return "Bug"; 107 | case GPG_ERR_ELEMENT_NOT_FOUND: return "Not found"; 108 | case GPG_ERR_IDENTIFIER_NOT_FOUND: return "Identifier not found"; 109 | default: return "Unknown error"; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /m4/ax_prog_bison.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_prog_bison.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_PROG_BISON(ACTION-IF-TRUE,ACTION-IF-FALSE) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether bison is the parser generator. Run ACTION-IF-TRUE if 12 | # successful, ACTION-IF-FALSE otherwise 13 | # 14 | # LICENSE 15 | # 16 | # Copyright (c) 2009 Francesco Salvestrini 17 | # Copyright (c) 2010 Diego Elio Petteno` 18 | # 19 | # This program is free software; you can redistribute it and/or modify it 20 | # under the terms of the GNU General Public License as published by the 21 | # Free Software Foundation; either version 2 of the License, or (at your 22 | # option) any later version. 23 | # 24 | # This program is distributed in the hope that it will be useful, but 25 | # WITHOUT ANY WARRANTY; without even the implied warranty of 26 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 27 | # Public License for more details. 28 | # 29 | # You should have received a copy of the GNU General Public License along 30 | # with this program. If not, see . 31 | # 32 | # As a special exception, the respective Autoconf Macro's copyright owner 33 | # gives unlimited permission to copy, distribute and modify the configure 34 | # scripts that are the output of Autoconf when processing the Macro. You 35 | # need not follow the terms of the GNU General Public License when using 36 | # or distributing such scripts, even though portions of the text of the 37 | # Macro appear in them. The GNU General Public License (GPL) does govern 38 | # all other use of the material that constitutes the Autoconf Macro. 39 | # 40 | # This special exception to the GPL applies to versions of the Autoconf 41 | # Macro released by the Autoconf Archive. When you make and distribute a 42 | # modified version of the Autoconf Macro, you may extend this special 43 | # exception to the GPL to apply to your modified version as well. 44 | 45 | #serial 9 46 | 47 | AC_DEFUN([AX_PROG_BISON], [ 48 | AC_REQUIRE([AC_PROG_YACC]) 49 | AC_REQUIRE([AC_PROG_EGREP]) 50 | 51 | AC_CACHE_CHECK([if bison is the parser generator],[ax_cv_prog_bison],[ 52 | AS_IF([$YACC --version 2>/dev/null | $EGREP -q '^bison '], 53 | [ax_cv_prog_bison=yes], [ax_cv_prog_bison=no]) 54 | ]) 55 | AS_IF([test "$ax_cv_prog_bison" = "yes"], [ 56 | dnl replace the yacc-compatible compiler with the real bison, as 57 | dnl otherwise autoconf limits us to the POSIX yacc. 58 | dnl We also change the generated filename to the old one, so that 59 | dnl automake's ylwrap can deal with it. 60 | YACC="${YACC% -y} -o y.tab.c" 61 | ] m4_ifnblank([$1], [[$1]]), 62 | m4_ifnblank([$2], [[$2]]) 63 | ) 64 | ]) 65 | -------------------------------------------------------------------------------- /tests/samples/README: -------------------------------------------------------------------------------- 1 | Sample data used for the initial development: 2 | 3 | cert_dfn_pca01.der 4 | cert_dfn_pca15.der 5 | cert_g10code_test1.der 6 | crl_testpki_testpca.der 7 | detached_sig.cms 8 | 9 | Certificates downloaded from http://www.magmacom.com/~mbartel/iso/\ 10 | certificates/samples/sample_certificates.html on 2003-11-20: 11 | 12 | authority.crt A root certificate 13 | betsy.crt An "everyday" certificate. 14 | bull.crt Same but includes a BMPString. 15 | 16 | Note, that these certs use MD2. 17 | 18 | 19 | Certificates downloaded from 20 | http://www.openvalidation.org/download/downloadrootcertsCA1.htm and 21 | on 2003-11-20 and prefixed with "ov-": 22 | 23 | ov-root-ca-cert.crt Root certificate 24 | ov-ocsp-server.crt The certificate of the OCSP responder 25 | ov-user.crt User certificate 26 | ov-userrev.crt A user certificate revoked by OCSP 27 | ov-server.crt A server (SSL) certificate 28 | ov-serverrev.crt A server certificate revoked by OCSP 29 | 30 | ov-user.p12 Private keys for the above certificates, 31 | ov-userrev.p12 passphrase is "start". 32 | ov-server.p12 33 | ov-serverrev.p12 34 | 35 | ov-test-crl.crl The current CRL 36 | 37 | The responder adress is http://ocsp.openvalidation.org 38 | 39 | Certificates downloaded from http://www.openvalidation.org/en/test/ca2.html 40 | on 2006-08-30 and prefixed with "ov2-": 41 | 42 | ov2-root-ca-cert.crt Root certificate 43 | ov2-ocsp-server.crt The certificate of the OCSP responder 44 | ov2-user.crt User certificate 45 | ov2-userrev.crt A user certificate revoked by OCSP 46 | 47 | Certificates downloaded on 2007-04-05 from 48 | http://dev.experimentalstuff.com:8082/CIC_sample-certs_2006-06-22.zip 49 | and converted to binary format. These are signed with 50 | ECDSA-P256-SHA384, ECDSA-P256-SHA512, and ECDSA-P384-SHA512. 51 | 52 | secp256r1-sha384_cert.crt 53 | secp256r1-sha512_cert.crt 54 | secp384r1-sha512_cert.crt 55 | 56 | From http://dev.experimentalstuff.com:8082/certs/secp256r1ca.cert.pem 57 | 58 | openssl-secp256r1ca.cert.crt 59 | 60 | ECDH sample enveloped data from the Mozilla bug tracker: 61 | 62 | ecdh-sample1.p7m 63 | ecdh-sample1.p7m.asn Commented dump. 64 | 65 | RSA sample enveloped data created with gpgsm 66 | 67 | rsa-sample1.p7m 68 | rsa-sample1.p7m.asn Commented dump 69 | 70 | RSA sample signature created with gpgsm 71 | 72 | rsa-sample1.p7s 73 | rsa-sample1.p7s.asn Commented dump 74 | 75 | ECDSA sample signature created with Governikus Signer 76 | 77 | ecdsa-sample1.p7s signed data is hitchhiker.txt 78 | ecdsa-sample1.p7s.asn Commented dump 79 | 80 | ED25519 sample self-signed certificates 81 | 82 | ed25519-rfc8410.crt from RFC8410 83 | ed25519-rfc8410.key 84 | ed25519-ossl-1.crt generated with OpenSSL 85 | ed25519-ossl-1.key 86 | 87 | ED448 sample self-signed certificate 88 | 89 | ed448-ossl-1.crt generated with OpenSSL 90 | ed448-ossl-1.key generated with OpenSSL 91 | -------------------------------------------------------------------------------- /m4/ax_cc_for_build.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_cc_for_build.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CC_FOR_BUILD 8 | # 9 | # DESCRIPTION 10 | # 11 | # Find a build-time compiler. Sets CC_FOR_BUILD and EXEEXT_FOR_BUILD. 12 | # 13 | # LICENSE 14 | # 15 | # Copyright (c) 2010 Reuben Thomas 16 | # Copyright (c) 1999 Richard Henderson 17 | # 18 | # This program is free software: you can redistribute it and/or modify it 19 | # under the terms of the GNU General Public License as published by the 20 | # Free Software Foundation, either version 3 of the License, or (at your 21 | # option) any later version. 22 | # 23 | # This program is distributed in the hope that it will be useful, but 24 | # WITHOUT ANY WARRANTY; without even the implied warranty of 25 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 26 | # Public License for more details. 27 | # 28 | # You should have received a copy of the GNU General Public License along 29 | # with this program. If not, see . 30 | # 31 | # As a special exception, the respective Autoconf Macro's copyright owner 32 | # gives unlimited permission to copy, distribute and modify the configure 33 | # scripts that are the output of Autoconf when processing the Macro. You 34 | # need not follow the terms of the GNU General Public License when using 35 | # or distributing such scripts, even though portions of the text of the 36 | # Macro appear in them. The GNU General Public License (GPL) does govern 37 | # all other use of the material that constitutes the Autoconf Macro. 38 | # 39 | # This special exception to the GPL applies to versions of the Autoconf 40 | # Macro released by the Autoconf Archive. When you make and distribute a 41 | # modified version of the Autoconf Macro, you may extend this special 42 | # exception to the GPL to apply to your modified version as well. 43 | 44 | #serial 3 45 | 46 | dnl Get a default for CC_FOR_BUILD to put into Makefile. 47 | AC_DEFUN([AX_CC_FOR_BUILD], 48 | [# Put a plausible default for CC_FOR_BUILD in Makefile. 49 | if test -z "$CC_FOR_BUILD"; then 50 | if test "x$cross_compiling" = "xno"; then 51 | CC_FOR_BUILD='$(CC)' 52 | else 53 | CC_FOR_BUILD=gcc 54 | fi 55 | fi 56 | AC_SUBST(CC_FOR_BUILD) 57 | # Also set EXEEXT_FOR_BUILD. 58 | if test "x$cross_compiling" = "xno"; then 59 | EXEEXT_FOR_BUILD='$(EXEEXT)' 60 | else 61 | AC_CACHE_CHECK([for build system executable suffix], bfd_cv_build_exeext, 62 | [rm -f conftest* 63 | echo 'int main () { return 0; }' > conftest.c 64 | bfd_cv_build_exeext= 65 | ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5 66 | for file in conftest.*; do 67 | case $file in 68 | *.c | *.o | *.obj | *.ilk | *.pdb) ;; 69 | *) bfd_cv_build_exeext=`echo $file | sed -e s/conftest//` ;; 70 | esac 71 | done 72 | rm -f conftest* 73 | test x"${bfd_cv_build_exeext}" = x && bfd_cv_build_exeext=no]) 74 | EXEEXT_FOR_BUILD="" 75 | test x"${bfd_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${bfd_cv_build_exeext} 76 | fi 77 | AC_SUBST(EXEEXT_FOR_BUILD)])dnl 78 | -------------------------------------------------------------------------------- /src/certreq.h: -------------------------------------------------------------------------------- 1 | /* certreq.h - Internal definitions for pkcs-10 objects 2 | * Copyright (C) 2002, 2005, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef CERTREQ_H 32 | #define CERTREQ_H 1 33 | 34 | #include "ksba.h" 35 | 36 | #ifndef HAVE_TYPEDEFD_ASNNODE 37 | typedef struct asn_node_struct *AsnNode; /* FIXME: should not go here */ 38 | #define HAVE_TYPEDEFD_ASNNODE 39 | #endif 40 | 41 | struct extn_list_s 42 | { 43 | struct extn_list_s *next; 44 | const char *oid; 45 | int critical; 46 | int derlen; 47 | unsigned char der[1]; 48 | }; 49 | 50 | 51 | /* Object to collect information for building a GeneralNames. */ 52 | struct general_names_s 53 | { 54 | struct general_names_s *next; 55 | int tag; /* The GeneralName CHOICE. Only certain values are 56 | supported. This is not strictly required because DATA 57 | below has already been prefixed with the DER encoded 58 | tag. */ 59 | size_t datalen; /* Length of the data. */ 60 | char data[1]; /* The actual data: encoded tag, llength and value. */ 61 | }; 62 | 63 | 64 | struct ksba_certreq_s 65 | { 66 | gpg_error_t last_error; 67 | 68 | ksba_writer_t writer; 69 | 70 | void (*hash_fnc)(void *, const void *, size_t); 71 | void *hash_fnc_arg; 72 | 73 | int any_build_done; 74 | 75 | struct { 76 | struct { 77 | char *der; /* Malloced serialno; if this is set we want to 78 | build a real X.509 certificate. */ 79 | size_t derlen; 80 | } serial; 81 | struct { 82 | char *der; 83 | size_t derlen; 84 | } issuer; 85 | ksba_isotime_t not_before; 86 | ksba_isotime_t not_after; 87 | struct { 88 | unsigned char *der; 89 | size_t derlen; 90 | } siginfo; 91 | } x509; 92 | 93 | struct { 94 | char *der; 95 | size_t derlen; 96 | } subject; 97 | 98 | struct { 99 | unsigned char *der; 100 | size_t derlen; 101 | } key; 102 | 103 | struct general_names_s *subject_alt_names; 104 | 105 | struct extn_list_s *extn_list; 106 | 107 | struct { 108 | unsigned char *der; 109 | size_t derlen; 110 | } cri; 111 | 112 | struct { 113 | char *algo; 114 | int is_ecc; /* 1 = plain ecc, 2 = EdDSA */ 115 | unsigned char *value; 116 | size_t valuelen; 117 | } sig_val; 118 | 119 | 120 | 121 | }; 122 | 123 | 124 | 125 | #endif /*CERTREQ_H*/ 126 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | # Makefile.am - for the KSBA regression tests 2 | # Copyright (C) 2001, 2003 g10 Code GmbH 3 | # 4 | # This file is part of KSBA. 5 | # 6 | # KSBA is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # KSBA is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, see . 18 | 19 | ## Process this file with automake to produce Makefile.in 20 | 21 | TESTS_ENVIRONMENT = 22 | 23 | test_certs = samples/cert_dfn_pca01.der samples/cert_dfn_pca15.der \ 24 | samples/cert_g10code_test1.der samples/crl_testpki_testpca.der \ 25 | samples/authority.crt samples/betsy.crt samples/bull.crt \ 26 | samples/ov-ocsp-server.crt samples/ov-userrev.crt \ 27 | samples/ov-root-ca-cert.crt samples/ov-serverrev.crt \ 28 | samples/ov-user.crt samples/ov-server.crt \ 29 | samples/ov2-root-ca-cert.crt samples/ov2-ocsp-server.crt \ 30 | samples/ov2-user.crt samples/ov2-userrev.crt \ 31 | samples/secp256r1-sha384_cert.crt \ 32 | samples/secp256r1-sha512_cert.crt \ 33 | samples/secp384r1-sha512_cert.crt \ 34 | samples/openssl-secp256r1ca.cert.crt \ 35 | samples/ed25519-rfc8410.crt \ 36 | samples/ed25519-ossl-1.crt \ 37 | samples/ed448-ossl-1.crt 38 | 39 | 40 | test_crls = samples/ov-test-crl.crl 41 | 42 | test_keys = samples/ov-server.p12 samples/ov-userrev.p12 \ 43 | samples/ov-serverrev.p12 samples/ov-user.p12 44 | 45 | EXTRA_DIST = $(test_certs) mkoidtbl.awk \ 46 | samples/README \ 47 | samples/detached-sig.cms \ 48 | samples/rsa-sample1.p7m samples/rsa-sample1.p7m \ 49 | samples/rsa-sample1.p7s samples/rsa-sample1.p7s \ 50 | samples/ecdh-sample1.p7m samples/ecdh-sample1.p7m.asn \ 51 | samples/ecdsa-sample1.p7s samples/ecdsa-sample1.p7s.asn 52 | 53 | 54 | BUILT_SOURCES = oidtranstbl.h 55 | CLEANFILES = oidtranstbl.h 56 | 57 | TESTS = cert-basic t-crl-parser t-dnparser t-oid t-reader t-cms-parser \ 58 | t-der-builder 59 | 60 | AM_CFLAGS = $(GPG_ERROR_CFLAGS) $(COVERAGE_CFLAGS) 61 | if HAVE_W32_SYSTEM 62 | AM_LDFLAGS = -no-fast-install $(COVERAGE_LDFLAGS) 63 | else 64 | AM_LDFLAGS = -no-install $(COVERAGE_LDFLAGS) 65 | endif 66 | 67 | noinst_HEADERS = t-common.h 68 | noinst_PROGRAMS = $(TESTS) t-ocsp 69 | LDADD = ../src/libksba.la $(GPG_ERROR_LIBS) @LDADD_FOR_TESTS_KLUDGE@ 70 | 71 | t_ocsp_SOURCES = t-ocsp.c sha1.c 72 | 73 | # Build the OID table: Note that the binary includes data from an 74 | # another program and we may not be allowed to distribute this. This 75 | # ain't no problem as the programs using this generated data are not 76 | # installed and thus not distributed. 77 | oidtranstbl.h: Makefile mkoidtbl.awk 78 | set -e; f="/dev/null"; \ 79 | for i in /etc/dumpasn1 /usr/local/bin /usr/local/share /usr/bin \ 80 | /usr/share ; do \ 81 | if test -f $$i/dumpasn1.cfg; then f=$$i/dumpasn1.cfg; break; fi; \ 82 | done; tr -d '\r' <$$f | $(AWK) -f $(srcdir)/mkoidtbl.awk >$@ 83 | 84 | LOG_COMPILER = $(VALGRIND) 85 | -------------------------------------------------------------------------------- /src/ksba-config.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (C) 1999, 2002, 2011 Free Software Foundation, Inc. 3 | # 4 | # This file is free software; as a special exception the author gives 5 | # unlimited permission to copy and/or distribute it, with or without 6 | # modifications, as long as this notice is preserved. 7 | # 8 | # This file is distributed in the hope that it will be useful, but 9 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 10 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 | 12 | PGM=ksba-config 13 | libs="@KSBA_CONFIG_LIBS@ @GPG_ERROR_LIBS@" 14 | cflags="@KSBA_CONFIG_CFLAGS@ @GPG_ERROR_CFLAGS@" 15 | prefix=@prefix@ 16 | exec_prefix=@exec_prefix@ 17 | api_version="@KSBA_CONFIG_API_VERSION@" 18 | my_host="@KSBA_CONFIG_HOST@" 19 | 20 | includes="" 21 | libdirs="" 22 | exec_prefix_set=no 23 | echo_libs=no 24 | echo_cflags=no 25 | echo_prefix=no 26 | echo_exec_prefix=no 27 | echo_api_version=no 28 | echo_host=no 29 | 30 | 31 | usage() 32 | { 33 | cat <&2 49 | fi 50 | 51 | while test $# -gt 0; do 52 | case "$1" in 53 | -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; 54 | *) optarg= ;; 55 | esac 56 | 57 | case $1 in 58 | --prefix=*) 59 | prefix=$optarg 60 | if test $exec_prefix_set = no ; then 61 | exec_prefix=$optarg 62 | fi 63 | ;; 64 | --prefix) 65 | echo_prefix=yes 66 | ;; 67 | --exec-prefix=*) 68 | exec_prefix=$optarg 69 | exec_prefix_set=yes 70 | ;; 71 | --exec-prefix) 72 | echo_exec_prefix=yes 73 | ;; 74 | --variable=*) 75 | case "${1#*=}" in 76 | prefix) echo "$prefix" ;; 77 | exec_prefix) echo "$exec_prefix" ;; 78 | host) echo "$my_host" ;; 79 | api_version) echo "$api_version" ;; 80 | esac 81 | exit 0 82 | ;; 83 | --modversion|--version) 84 | echo "@PACKAGE_VERSION@" 85 | exit 0 86 | ;; 87 | --api-version) 88 | echo_api_version=yes 89 | ;; 90 | --cflags) 91 | echo_cflags=yes 92 | ;; 93 | --libs) 94 | echo_libs=yes 95 | ;; 96 | --host) 97 | echo_host=yes 98 | ;; 99 | *) 100 | usage 1 1>&2 101 | ;; 102 | esac 103 | shift 104 | done 105 | 106 | if test "$echo_prefix" = "yes"; then 107 | echo $prefix 108 | fi 109 | 110 | if test "$echo_exec_prefix" = "yes"; then 111 | echo $exec_prefix 112 | fi 113 | 114 | if test "$echo_api_version" = "yes"; then 115 | echo "$api_version" 116 | fi 117 | 118 | if test "$echo_host" = "yes"; then 119 | echo "$my_host" 120 | fi 121 | 122 | if test "$echo_cflags" = "yes"; then 123 | includes="" 124 | if test "@includedir@" != "/usr/include" ; then 125 | includes="-I@includedir@" 126 | fi 127 | tmp="" 128 | for i in $includes $cflags; do 129 | if echo "$tmp" | fgrep -v -- "$i" >/dev/null; then 130 | tmp="$tmp $i" 131 | fi 132 | done 133 | echo $tmp 134 | fi 135 | 136 | if test "$echo_libs" = "yes"; then 137 | libdirs="" 138 | if test "@libdir@" != "/usr/lib" ; then 139 | libdirs="-L@libdir@" 140 | fi 141 | tmp="" 142 | for i in $libdirs $libs; do 143 | if echo "$tmp" | fgrep -v -- "$i" >/dev/null; then 144 | tmp="$tmp $i" 145 | fi 146 | done 147 | echo $tmp 148 | fi 149 | -------------------------------------------------------------------------------- /src/keyinfo.h: -------------------------------------------------------------------------------- 1 | /* keyinfo.h - Parse and build a keyInfo structure 2 | * Copyright (C) 2001, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef KEYINFO_H 32 | #define KEYINFO_H 33 | 34 | #include "asn1-func.h" 35 | 36 | 37 | gpg_error_t 38 | _ksba_parse_algorithm_identifier (const unsigned char *der, 39 | size_t derlen, 40 | size_t *r_nread, 41 | char **r_oid); 42 | gpg_error_t 43 | _ksba_parse_algorithm_identifier2 (const unsigned char *der, size_t derlen, 44 | size_t *r_nread, char **r_oid, 45 | char **r_parm, size_t *r_parmlen); 46 | 47 | gpg_error_t 48 | _ksba_parse_algorithm_identifier3 (const unsigned char *der, size_t derlen, 49 | int firsttag, 50 | size_t *r_nread, char **r_oid, 51 | char **r_parm, size_t *r_parmlen, 52 | int *r_parmtype); 53 | 54 | 55 | gpg_error_t _ksba_keyinfo_to_sexp (const unsigned char *der, size_t derlen, 56 | ksba_sexp_t *r_string) 57 | _KSBA_VISIBILITY_DEFAULT; 58 | 59 | gpg_error_t _ksba_keyinfo_from_sexp (ksba_const_sexp_t sexp, int algoinfomode, 60 | unsigned char **r_der, size_t *r_derlen) 61 | _KSBA_VISIBILITY_DEFAULT; 62 | 63 | gpg_error_t _ksba_algoinfo_from_sexp (ksba_const_sexp_t sexp, 64 | unsigned char **r_der, size_t *r_derlen); 65 | 66 | gpg_error_t _ksba_keyinfo_get_pss_info (const unsigned char *der, 67 | size_t derlen, 68 | char **r_psshash, 69 | unsigned int *r_saltlen); 70 | 71 | gpg_error_t _ksba_sigval_to_sexp (const unsigned char *der, size_t derlen, 72 | ksba_sexp_t *r_string); 73 | gpg_error_t _ksba_encval_to_sexp (const unsigned char *der, size_t derlen, 74 | ksba_sexp_t *r_string); 75 | gpg_error_t _ksba_encval_kari_to_sexp (const unsigned char *der, size_t derlen, 76 | const char *keyencralgo, 77 | const char *keywrapalgo, 78 | const void *enckey, size_t enckeylen, 79 | ksba_sexp_t *r_string); 80 | 81 | int _ksba_node_with_oid_to_digest_algo (const unsigned char *image, 82 | AsnNode node); 83 | 84 | 85 | 86 | #endif /*KEYINFO_H*/ 87 | -------------------------------------------------------------------------------- /src/gen-help.h: -------------------------------------------------------------------------------- 1 | /* gen-help.c - Helper functions used by build time tools 2 | * Copyright (C) 2010 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Fountion; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * KSBA is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | /* This header has definitions used by programs which are only run on 21 | the build platform as part of the build process. They need to be 22 | plain ISO C and don't make use of any information gathered from the 23 | configure run. */ 24 | 25 | #ifndef GEN_HELP_H 26 | #define GEN_HELP_H 27 | 28 | #ifndef BUILD_GENTOOLS 29 | #error file may only be used for build time tools 30 | #endif 31 | 32 | 33 | void *xmalloc (size_t n); 34 | void *xcalloc (size_t n, size_t m); 35 | void *xrealloc (void *mem, size_t n); 36 | char *xstrdup (const char *str); 37 | void xfree (void *a); 38 | #define xtrymalloc(a) malloc ((a)) 39 | 40 | char *gen_help_stpcpy (char *a, const char *b); 41 | #define stpcpy(a, b) gen_help_stpcpy ((a), (b)) 42 | 43 | 44 | 45 | 46 | #define DIM(v) (sizeof(v)/sizeof((v)[0])) 47 | #define DIMof(type,member) DIM(((type *)0)->member) 48 | #ifndef STR 49 | # define STR(v) #v 50 | #endif 51 | #ifndef STR2 52 | # define STR2(v) STR(v) 53 | #endif 54 | 55 | #define return_if_fail(expr) do { \ 56 | if (!(expr)) { \ 57 | fprintf (stderr, "%s:%d: assertion `%s' failed\n", \ 58 | __FILE__, __LINE__, #expr ); \ 59 | return; \ 60 | } } while (0) 61 | #define return_null_if_fail(expr) do { \ 62 | if (!(expr)) { \ 63 | fprintf (stderr, "%s:%d: assertion `%s' failed\n", \ 64 | __FILE__, __LINE__, #expr ); \ 65 | return NULL; \ 66 | } } while (0) 67 | #define return_val_if_fail(expr,val) do { \ 68 | if (!(expr)) { \ 69 | fprintf (stderr, "%s:%d: assertion `%s' failed\n", \ 70 | __FILE__, __LINE__, #expr ); \ 71 | return (val); \ 72 | } } while (0) 73 | #define never_reached() do { \ 74 | fprintf (stderr, "%s:%d: oops; should never get here\n", \ 75 | __FILE__, __LINE__ ); \ 76 | } while (0) 77 | 78 | 79 | /* Replacement for gpg_error.h stuff. */ 80 | #define GPG_ERR_GENERAL 1 81 | #define GPG_ERR_SYNTAX 29 82 | #define GPG_ERR_INV_VALUE 55 83 | #define GPG_ERR_BUG 59 84 | #define GPG_ERR_ELEMENT_NOT_FOUND 136 85 | #define GPG_ERR_IDENTIFIER_NOT_FOUND 137 86 | 87 | #define gpg_error(a) (a) 88 | #define gpg_error_from_syserror() (GPG_ERR_GENERAL); 89 | const char *gpg_strerror (int err); 90 | 91 | /* Duplicated type definitions from ksba.h. */ 92 | typedef struct ksba_asn_tree_s *ksba_asn_tree_t; 93 | int ksba_asn_parse_file (const char *filename, ksba_asn_tree_t *result, 94 | int debug); 95 | void ksba_asn_tree_dump (ksba_asn_tree_t tree, const char *name, FILE *fp); 96 | 97 | #endif /*GEN_HELP_H*/ 98 | -------------------------------------------------------------------------------- /mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | 4 | scriptversion=2006-05-11.19 5 | 6 | # Original author: Noah Friedman 7 | # Created: 1993-05-16 8 | # Public domain. 9 | # 10 | # This file is maintained in Automake, please report 11 | # bugs to or send patches to 12 | # . 13 | 14 | nl=' 15 | ' 16 | IFS=" "" $nl" 17 | errstatus=0 18 | dirmode= 19 | 20 | usage="\ 21 | Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ... 22 | 23 | Create each directory DIR (with mode MODE, if specified), including all 24 | leading file name components. 25 | 26 | Report bugs to ." 27 | 28 | # process command line arguments 29 | while test $# -gt 0 ; do 30 | case $1 in 31 | -h | --help | --h*) # -h for help 32 | echo "$usage" 33 | exit $? 34 | ;; 35 | -m) # -m PERM arg 36 | shift 37 | test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } 38 | dirmode=$1 39 | shift 40 | ;; 41 | --version) 42 | echo "$0 $scriptversion" 43 | exit $? 44 | ;; 45 | --) # stop option processing 46 | shift 47 | break 48 | ;; 49 | -*) # unknown option 50 | echo "$usage" 1>&2 51 | exit 1 52 | ;; 53 | *) # first non-opt arg 54 | break 55 | ;; 56 | esac 57 | done 58 | 59 | for file 60 | do 61 | if test -d "$file"; then 62 | shift 63 | else 64 | break 65 | fi 66 | done 67 | 68 | case $# in 69 | 0) exit 0 ;; 70 | esac 71 | 72 | # Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and 73 | # mkdir -p a/c at the same time, both will detect that a is missing, 74 | # one will create a, then the other will try to create a and die with 75 | # a "File exists" error. This is a problem when calling mkinstalldirs 76 | # from a parallel make. We use --version in the probe to restrict 77 | # ourselves to GNU mkdir, which is thread-safe. 78 | case $dirmode in 79 | '') 80 | if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then 81 | echo "mkdir -p -- $*" 82 | exec mkdir -p -- "$@" 83 | else 84 | # On NextStep and OpenStep, the `mkdir' command does not 85 | # recognize any option. It will interpret all options as 86 | # directories to create, and then abort because `.' already 87 | # exists. 88 | test -d ./-p && rmdir ./-p 89 | test -d ./--version && rmdir ./--version 90 | fi 91 | ;; 92 | *) 93 | if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 && 94 | test ! -d ./--version; then 95 | echo "mkdir -m $dirmode -p -- $*" 96 | exec mkdir -m "$dirmode" -p -- "$@" 97 | else 98 | # Clean up after NextStep and OpenStep mkdir. 99 | for d in ./-m ./-p ./--version "./$dirmode"; 100 | do 101 | test -d $d && rmdir $d 102 | done 103 | fi 104 | ;; 105 | esac 106 | 107 | for file 108 | do 109 | case $file in 110 | /*) pathcomp=/ ;; 111 | *) pathcomp= ;; 112 | esac 113 | oIFS=$IFS 114 | IFS=/ 115 | set fnord $file 116 | shift 117 | IFS=$oIFS 118 | 119 | for d 120 | do 121 | test "x$d" = x && continue 122 | 123 | pathcomp=$pathcomp$d 124 | case $pathcomp in 125 | -*) pathcomp=./$pathcomp ;; 126 | esac 127 | 128 | if test ! -d "$pathcomp"; then 129 | echo "mkdir $pathcomp" 130 | 131 | mkdir "$pathcomp" || lasterr=$? 132 | 133 | if test ! -d "$pathcomp"; then 134 | errstatus=$lasterr 135 | else 136 | if test ! -z "$dirmode"; then 137 | echo "chmod $dirmode $pathcomp" 138 | lasterr= 139 | chmod "$dirmode" "$pathcomp" || lasterr=$? 140 | 141 | if test ! -z "$lasterr"; then 142 | errstatus=$lasterr 143 | fi 144 | fi 145 | fi 146 | fi 147 | 148 | pathcomp=$pathcomp/ 149 | done 150 | done 151 | 152 | exit $errstatus 153 | 154 | # Local Variables: 155 | # mode: shell-script 156 | # sh-indentation: 2 157 | # eval: (add-hook 'write-file-hooks 'time-stamp) 158 | # time-stamp-start: "scriptversion=" 159 | # time-stamp-format: "%:y-%02m-%02d.%02H" 160 | # time-stamp-end: "$" 161 | # End: 162 | -------------------------------------------------------------------------------- /src/cert.h: -------------------------------------------------------------------------------- 1 | /* cert.h - Internal definitions for cert.c 2 | * Copyright (C) 2001, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef CERT_H 32 | #define CERT_H 1 33 | 34 | #include "asn1-func.h" 35 | 36 | /* An object to keep parsed information about an extension. */ 37 | struct cert_extn_info 38 | { 39 | char *oid; 40 | int crit; 41 | int off, len; 42 | }; 43 | 44 | 45 | /* An object to store user supplied data to be associated with a 46 | certificates. This is implemented as a linked list with the 47 | constrained that a given key may only occur once. */ 48 | struct cert_user_data 49 | { 50 | struct cert_user_data *next; /* Link to next item. */ 51 | 52 | /* The length of the data store at DATA. */ 53 | size_t datalen; 54 | 55 | /* The stored data. This is either malloced storage or points to 56 | DATABUF below. If it is NULL, no data is actually stored under 57 | the key. */ 58 | void *data; 59 | 60 | /* Often we need to store only a few bytes as data. By providing a 61 | fixed buffer we are able to avoid an extra malloc in this case. */ 62 | char databuf[sizeof (int)]; 63 | 64 | /* The key used to store the data object. Dynamically allocated at 65 | object creation time. */ 66 | char key[1]; 67 | }; 68 | 69 | 70 | /* The internal certificate object. */ 71 | struct ksba_cert_s 72 | { 73 | /* Certificate objects often play a central role and applications 74 | might want to associate other data with the certificate to avoid 75 | wrapping the certificate object into an own object. This UDATA 76 | linked list provides the means to do that. It gets accessed by 77 | ksba_cert_set_user_data and ksba_cert_get_user_data. */ 78 | struct cert_user_data *udata; 79 | 80 | /* This object has been initialized with an actual certificate. 81 | Note that UDATA may be used even without an initialized 82 | certificate. */ 83 | int initialized; 84 | 85 | /* Because we often need to pass certificate objects to other 86 | functions, we use reference counting to keep resource overhead 87 | low. Note, that this object usually gets only read and not 88 | modified. */ 89 | int ref_count; 90 | 91 | ksba_asn_tree_t asn_tree; 92 | AsnNode root; /* Root of the tree with the values */ 93 | 94 | unsigned char *image; 95 | size_t imagelen; 96 | 97 | gpg_error_t last_error; 98 | struct { 99 | char *digest_algo; 100 | int extns_valid; 101 | int n_extns; 102 | struct cert_extn_info *extns; 103 | } cache; 104 | }; 105 | 106 | 107 | /*** Internal functions ***/ 108 | 109 | int _ksba_cert_cmp (ksba_cert_t a, ksba_cert_t b); 110 | 111 | gpg_error_t _ksba_cert_get_serial_ptr (ksba_cert_t cert, 112 | unsigned char const **ptr, 113 | size_t *length); 114 | gpg_error_t _ksba_cert_get_issuer_dn_ptr (ksba_cert_t cert, 115 | unsigned char const **ptr, 116 | size_t *length); 117 | gpg_error_t _ksba_cert_get_subject_dn_ptr (ksba_cert_t cert, 118 | unsigned char const **ptr, 119 | size_t *length); 120 | gpg_error_t _ksba_cert_get_public_key_ptr (ksba_cert_t cert, 121 | unsigned char const **ptr, 122 | size_t *length); 123 | 124 | 125 | #endif /*CERT_H*/ 126 | -------------------------------------------------------------------------------- /src/sexp-parse.h: -------------------------------------------------------------------------------- 1 | /* sexp-parse.h - S-expression helper functions for canonical encodings. 2 | * Copyright (C) 2002, 2003, 2007 Free Software Foundation, Inc. 3 | * Copyright (C) 2012 g10 Code GmbH 4 | * 5 | * This file is part of KSBA. 6 | * 7 | * KSBA is free software; you can redistribute it and/or modify 8 | * it under the terms of either 9 | * 10 | * - the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 3 of the License, or (at 12 | * your option) any later version. 13 | * 14 | * or 15 | * 16 | * - the GNU General Public License as published by the Free 17 | * Software Foundation; either version 2 of the License, or (at 18 | * your option) any later version. 19 | * 20 | * or both in parallel, as here. 21 | * 22 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 23 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 24 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 25 | * License for more details. 26 | * 27 | * You should have received a copies of the GNU General Public License 28 | * and the GNU Lesser General Public License along with this program; 29 | * if not, see . 30 | */ 31 | 32 | #ifndef SEXP_PARSE_H 33 | #define SEXP_PARSE_H 34 | 35 | #include 36 | 37 | /* Return the length of the next S-Exp part and update the pointer to 38 | the first data byte. 0 is returned on error */ 39 | static inline size_t 40 | snext (unsigned char const **buf) 41 | { 42 | const unsigned char *s; 43 | int n; 44 | 45 | s = *buf; 46 | for (n=0; *s && *s != ':' && (*s >= '0' && *s <= '9'); s++) 47 | n = n*10 + (*s - '0'); 48 | if (!n || *s != ':') 49 | return 0; /* we don't allow empty lengths */ 50 | *buf = s+1; 51 | return n; 52 | } 53 | 54 | /* Skip over the S-Expression BUF points to and update BUF to point to 55 | the byte right behind. DEPTH gives the initial number of open 56 | lists and may be passed as a positive number to skip over the 57 | remainder of an S-Expression if the current position is somewhere 58 | in an S-Expression. The function may return an error code if it 59 | encounters an impossible conditions */ 60 | static inline gpg_error_t 61 | sskip (unsigned char const **buf, int *depth) 62 | { 63 | const unsigned char *s = *buf; 64 | size_t n; 65 | int d = *depth; 66 | 67 | while (d > 0) 68 | { 69 | if (*s == '(') 70 | { 71 | d++; 72 | s++; 73 | } 74 | else if (*s == ')') 75 | { 76 | d--; 77 | s++; 78 | } 79 | else 80 | { 81 | if (!d) 82 | return gpg_error (GPG_ERR_INV_SEXP); 83 | n = snext (&s); 84 | if (!n) 85 | return gpg_error (GPG_ERR_INV_SEXP); 86 | s += n; 87 | } 88 | } 89 | *buf = s; 90 | *depth = d; 91 | return 0; 92 | } 93 | 94 | 95 | /* Check whether the the string at the address BUF points to matches 96 | the token. Return true on match and update BUF to point behind the 97 | token. Return false and do not update the buffer if it does not 98 | match. */ 99 | static inline int 100 | smatch (unsigned char const **buf, size_t buflen, const char *token) 101 | { 102 | size_t toklen = strlen (token); 103 | 104 | if (buflen != toklen || memcmp (*buf, token, toklen)) 105 | return 0; 106 | *buf += toklen; 107 | return 1; 108 | } 109 | 110 | 111 | /* Format VALUE for use as the length indicatior of an S-expression. 112 | The caller needs to provide a buffer HELP_BUFFER with a length of 113 | HELP_BUFLEN. The return value is a pointer into HELP_BUFFER with 114 | the formatted length string. The colon and a trailing nul are 115 | appended. HELP_BUFLEN must be at least 3 - a more useful value is 116 | 15. If LENGTH is not NULL, the LENGTH of the resulting string 117 | (excluding the terminating nul) is stored at that address. */ 118 | static inline char * 119 | smklen (char *help_buffer, size_t help_buflen, size_t value, size_t *length) 120 | { 121 | char *p = help_buffer + help_buflen; 122 | 123 | if (help_buflen >= 3) 124 | { 125 | *--p = 0; 126 | *--p = ':'; 127 | do 128 | { 129 | *--p = '0' + (value % 10); 130 | value /= 10; 131 | } 132 | while (value && p > help_buffer); 133 | } 134 | 135 | if (length) 136 | *length = (help_buffer + help_buflen) - p; 137 | return p; 138 | } 139 | 140 | #endif /*SEXP_PARSE_H*/ 141 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Program: Libksba 2 | Download: https://gnupg.org/ftp/gcrypt/libksba/ 3 | Repository: git://git.gnupg.org/libksba.git 4 | Maintainer: Werner Koch 5 | Bug reports: https://bugs.gnupg.org 6 | Security related bug reports: 7 | License (library): LGPLv3+/GPLv2+ 8 | License (tools, manual): GPLv3+ 9 | 10 | 11 | Libksba is free software. See the files COPYING.* for detailed 12 | copying conditions, and this file for notices about a few 13 | contributions that require these additional notices to be distributed. 14 | License copyright years may be listed using range notation, e.g., 15 | 2000-2013, indicating that every year in the range, inclusive, is a 16 | copyrightable year that would otherwise be listed individually. 17 | 18 | 19 | List of Authors 20 | =============== 21 | 22 | g10 Code GmbH 23 | Design and most stuff. 24 | 25 | 26 | GNUTLS Fabio Fiorina 2001-06-19 27 | [According to CVS log of August 5, 2001 @ 11:38: "renamed cert_* to 28 | x509_*" , further more, the original names must have been changed from 29 | Fabio's orginal ones to cert_* when he commited them to CVS] As of 30 | now the following files contain some of this code: 31 | (asn1-parse.y, asn1-func.[ch]) 32 | 33 | 34 | Copyright 35 | ========= 36 | 37 | Copyright (C) 2001-2006, 2010-2015, 2018-2023 g10 Code GmbH 38 | Copyright (C) 2001-2003, 2007 Free Software Foundation, Inc. 39 | Copyright (C) 2000, 2001 Fabio Fiorina 40 | 41 | The library and the header files are distributed under the following 42 | terms (LGPLv3+/GPLv2+): 43 | 44 | KSBA is free software; you can redistribute it and/or modify 45 | it under the terms of either 46 | 47 | - the GNU Lesser General Public License as published by the Free 48 | Software Foundation; either version 3 of the License, or (at 49 | your option) any later version. 50 | 51 | or 52 | 53 | - the GNU General Public License as published by the Free 54 | Software Foundation; either version 2 of the License, or (at 55 | your option) any later version. 56 | 57 | or both in parallel, as here. 58 | 59 | KSBA is distributed in the hope that it will be useful, but WITHOUT 60 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 61 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 62 | License for more details. 63 | 64 | The other parts (e.g. manual, build system, tests) are distributed 65 | under the following terms (GPLv3): 66 | 67 | KSBA is free software; you can redistribute it and/or modify 68 | it under the terms of the GNU General Public License as published by 69 | the Free Software Foundation; either version 3 of the License, or 70 | (at your option) any later version. 71 | 72 | KSBA is distributed in the hope that it will be useful, 73 | but WITHOUT ANY WARRANTY; without even the implied warranty of 74 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 75 | GNU General Public License for more details. 76 | 77 | The ASN.1 definition for CMS is based on a specification published 78 | under the following terms (see src/cms.asn): 79 | 80 | Copyright (C) The Internet Society (1999). All Rights Reserved. 81 | 82 | This document and translations of it may be copied and furnished to 83 | others, and derivative works that comment on or otherwise explain it 84 | or assist in its implementation may be prepared, copied, published 85 | and distributed, in whole or in part, without restriction of any 86 | kind, provided that the above copyright notice and this paragraph are 87 | included on all such copies and derivative works. However, this 88 | document itself may not be modified in any way, such as by removing 89 | the copyright notice or references to the Internet Society or other 90 | Internet organizations, except as needed for the purpose of 91 | developing Internet standards in which case the procedures for 92 | copyrights defined in the Internet Standards process must be 93 | followed, or as required to translate it into languages other than 94 | English. 95 | 96 | The limited permissions granted above are perpetual and will not be 97 | revoked by the Internet Society or its successors or assigns. 98 | 99 | This document and the information contained herein is provided on an 100 | "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING 101 | TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING 102 | BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION 103 | HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF 104 | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 105 | -------------------------------------------------------------------------------- /src/ber-dump.c: -------------------------------------------------------------------------------- 1 | /* ber-dump.c - Tool to dump BER encoded data 2 | * Copyright (C) 2001 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * KSBA is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "visibility.h" 28 | #include "ksba.h" 29 | #include "ber-decoder.h" 30 | 31 | #define PGMNAME "ber-dump" 32 | 33 | #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )) 34 | # define ATTR_PRINTF(a,b) __attribute__ ((format (printf,a,b))) 35 | #else 36 | # define ATTR_PRINTF(a,b) 37 | #endif 38 | 39 | /* keep track of parsing error */ 40 | static int error_counter; 41 | 42 | 43 | static void print_error (const char *fmt, ... ) ATTR_PRINTF(1,2); 44 | 45 | 46 | 47 | static void 48 | print_error (const char *fmt, ... ) 49 | { 50 | va_list arg_ptr ; 51 | 52 | va_start (arg_ptr, fmt); 53 | fputs (PGMNAME ": ", stderr); 54 | vfprintf (stderr, fmt, arg_ptr); 55 | va_end (arg_ptr); 56 | error_counter++; 57 | } 58 | 59 | static void 60 | fatal (const char *fmt, ... ) 61 | { 62 | va_list arg_ptr ; 63 | 64 | va_start (arg_ptr, fmt); 65 | fputs (PGMNAME ": fatal: ", stderr); 66 | vfprintf (stderr, fmt, arg_ptr); 67 | va_end (arg_ptr); 68 | exit (1); 69 | } 70 | 71 | 72 | static void 73 | one_file (FILE *fp, const char *fname, ksba_asn_tree_t asn_tree) 74 | { 75 | gpg_error_t err; 76 | ksba_reader_t r; 77 | BerDecoder d; 78 | 79 | (void)fname; /* Not yet used in error messages. */ 80 | 81 | err = ksba_reader_new (&r); 82 | if (err) 83 | fatal ("out of core\n"); 84 | err = ksba_reader_set_file (r, fp); 85 | if (err) 86 | fatal ("ksba_reader_set_file failed: rc=%d\n", err); 87 | 88 | d = _ksba_ber_decoder_new (); 89 | if (!d) 90 | fatal ("out of core\n"); 91 | err = _ksba_ber_decoder_set_reader (d, r); 92 | if (err) 93 | fatal ("ksba_ber_decoder_set_reader failed: rc=%d\n", err); 94 | 95 | if (asn_tree) 96 | { 97 | err = _ksba_ber_decoder_set_module (d, asn_tree); 98 | if (err) 99 | fatal ("ksba_ber_decoder_set_module failed: rc=%d\n", err); 100 | } 101 | 102 | err = _ksba_ber_decoder_dump (d, stdout); 103 | if (err) 104 | print_error ("ksba_ber_decoder_dump failed: rc=%d\n", err); 105 | 106 | _ksba_ber_decoder_release (d); 107 | ksba_reader_release (r); 108 | } 109 | 110 | 111 | static void 112 | usage (int exitcode) 113 | { 114 | fputs ("usage: ber-dump [--module asnfile] [files]\n", stderr); 115 | exit (exitcode); 116 | } 117 | 118 | int 119 | main (int argc, char **argv) 120 | { 121 | const char *asnfile = NULL; 122 | ksba_asn_tree_t asn_tree = NULL; 123 | int rc; 124 | 125 | if (!argc || (argc > 1 && 126 | (!strcmp (argv[1],"--help") || !strcmp (argv[1],"-h"))) ) 127 | usage (0); 128 | 129 | argc--; argv++; 130 | if (argc && !strcmp (*argv,"--module")) 131 | { 132 | argc--; argv++; 133 | if (!argc) 134 | usage (1); 135 | asnfile = *argv; 136 | argc--; argv++; 137 | } 138 | 139 | if (asnfile) 140 | { 141 | rc = ksba_asn_parse_file (asnfile, &asn_tree, 0); 142 | if (rc) 143 | { 144 | print_error ("parsing `%s' failed: rc=%d\n", asnfile, rc); 145 | exit (1); 146 | } 147 | } 148 | 149 | 150 | if (!argc) 151 | one_file (stdin, "-", asn_tree); 152 | else 153 | { 154 | for (; argc; argc--, argv++) 155 | { 156 | FILE *fp; 157 | 158 | fp = fopen (*argv, "r"); 159 | if (!fp) 160 | print_error ("can't open `%s': %s\n", *argv, strerror (errno)); 161 | else 162 | { 163 | one_file (fp, *argv, asn_tree); 164 | fclose (fp); 165 | } 166 | } 167 | } 168 | 169 | ksba_asn_tree_release (asn_tree); 170 | 171 | return error_counter? 1:0; 172 | } 173 | -------------------------------------------------------------------------------- /src/version.c: -------------------------------------------------------------------------------- 1 | /* version.c - Version checking 2 | * Copyright (C) 2001, 2002, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "util.h" 37 | 38 | static const char* 39 | parse_version_number (const char *s, int *number) 40 | { 41 | int val = 0; 42 | 43 | if (*s == '0' && digitp (s+1)) 44 | return NULL; /* Leading zeros are not allowed. */ 45 | for (; digitp (s); s++) 46 | { 47 | val *= 10; 48 | val += *s - '0'; 49 | } 50 | *number = val; 51 | return val < 0 ? NULL : s; 52 | } 53 | 54 | static const char * 55 | parse_version_string (const char *s, int *major, int *minor, int *micro) 56 | { 57 | s = parse_version_number (s, major); 58 | if (!s || *s != '.') 59 | return NULL; 60 | s++; 61 | s = parse_version_number (s, minor); 62 | if (!s || *s != '.') 63 | return NULL; 64 | s++; 65 | s = parse_version_number (s, micro); 66 | if (!s) 67 | return NULL; 68 | return s; /* Patchlevel. */ 69 | } 70 | 71 | static const char * 72 | compare_versions (const char *my_version, const char *req_version) 73 | { 74 | int my_major, my_minor, my_micro; 75 | int rq_major, rq_minor, rq_micro; 76 | const char *my_plvl, *rq_plvl; 77 | 78 | if (!req_version) 79 | return my_version; 80 | if (!my_version) 81 | return NULL; 82 | 83 | my_plvl = parse_version_string (my_version, &my_major, &my_minor, &my_micro); 84 | if (!my_plvl) 85 | return NULL; /* Very strange: our own version is bogus. */ 86 | rq_plvl = parse_version_string(req_version, 87 | &rq_major, &rq_minor, &rq_micro); 88 | if (!rq_plvl) 89 | return NULL; /* Requested version string is invalid. */ 90 | 91 | if (my_major > rq_major 92 | || (my_major == rq_major && my_minor > rq_minor) 93 | || (my_major == rq_major && my_minor == rq_minor 94 | && my_micro > rq_micro) 95 | || (my_major == rq_major && my_minor == rq_minor 96 | && my_micro == rq_micro)) 97 | { 98 | return my_version; 99 | } 100 | return NULL; 101 | } 102 | 103 | /* This is actually a dummy function to make sure that is module is 104 | not empty. Some compilers barf on empty modules. */ 105 | static const char * 106 | cright_blurb (void) 107 | { 108 | static const char blurb[] = 109 | "\n\n" 110 | "This is Libksba " PACKAGE_VERSION " - An X.509 and CMS Library\n" 111 | "Copyright 2001-2006,2010-2015,2018-2021 g10 Code GmbH\n" 112 | "\n" 113 | "SPDX-License-Identifier: LGPL-3.0-or-later OR GPL-2.0-or-later\n" 114 | "(" BUILD_REVISION " " BUILD_TIMESTAMP ")\n" 115 | "\n\n"; 116 | return blurb; 117 | } 118 | 119 | 120 | /** 121 | * ksba_check_version: 122 | * @req_version: A string with a version 123 | * 124 | * Check that the the version of the library is at minimum the requested one 125 | * and return the version string; return NULL if the condition is not 126 | * met. If a NULL is passed to this function, no check is done and 127 | * the version string is simply returned. It is a pretty good idea to 128 | * run this function as soon as possible, because it also intializes 129 | * some subsystems. In a multithreaded environment if should be called 130 | * before the first thread is created. 131 | * 132 | * Return value: The version string or NULL 133 | **/ 134 | const char * 135 | ksba_check_version (const char *req_version) 136 | { 137 | /* fixme: if we need global initializations. 138 | Note that the malloc hook might not have been run yet */ 139 | if (req_version && req_version[0] == 1 && req_version[1] == 1) 140 | return cright_blurb (); 141 | return compare_versions (VERSION, req_version); 142 | } 143 | -------------------------------------------------------------------------------- /src/stringbuf.h: -------------------------------------------------------------------------------- 1 | /* stringbuf.h - Inline functions for building strings. 2 | * Copyright (C) 2001, 2002, 2007, 2008, 2012, 2020 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef STRINGBUF_H 32 | #define STRINGBUF_H 1 33 | 34 | #include "util.h" 35 | #include "errno.h" 36 | 37 | struct stringbuf 38 | { 39 | size_t len; 40 | size_t size; 41 | char *buf; 42 | gpg_error_t out_of_core; 43 | }; 44 | 45 | 46 | static inline void 47 | init_stringbuf (struct stringbuf *sb, int initiallen) 48 | { 49 | sb->len = 0; 50 | sb->size = initiallen; 51 | sb->out_of_core = 0; 52 | /* allocate one more, so that get_stringbuf can append a nul */ 53 | sb->buf = xtrymalloc (initiallen+1); 54 | if (!sb->buf) 55 | sb->out_of_core = errno? errno : ENOMEM; 56 | } 57 | 58 | 59 | static inline void 60 | deinit_stringbuf (struct stringbuf *sb) 61 | { 62 | xfree (sb->buf); 63 | sb->buf = NULL; 64 | sb->out_of_core = ENOMEM; /* make sure the caller does an init before reuse */ 65 | } 66 | 67 | 68 | static inline void 69 | put_stringbuf_mem (struct stringbuf *sb, const char *text, size_t n) 70 | { 71 | if (sb->out_of_core) 72 | return; 73 | 74 | if (sb->len + n >= sb->size) 75 | { 76 | char *p; 77 | 78 | sb->size += n + 100; 79 | p = xtryrealloc (sb->buf, sb->size + 1); 80 | if (!p) 81 | { 82 | sb->out_of_core = errno? errno : ENOMEM; 83 | return; 84 | } 85 | sb->buf = p; 86 | } 87 | memcpy (sb->buf+sb->len, text, n); 88 | sb->len += n; 89 | } 90 | 91 | 92 | static inline void 93 | put_stringbuf_mem_skip (struct stringbuf *sb, const char *text, size_t n, 94 | int skip) 95 | { 96 | char *p; 97 | 98 | if (!skip) 99 | { 100 | put_stringbuf_mem (sb, text, n); 101 | return; 102 | } 103 | if (sb->out_of_core) 104 | return; 105 | 106 | if (sb->len + n >= sb->size) 107 | { 108 | /* Note: we allocate too much here, but we don't care. */ 109 | sb->size += n + 100; 110 | p = xtryrealloc (sb->buf, sb->size + 1); 111 | if ( !p) 112 | { 113 | sb->out_of_core = errno? errno : ENOMEM; 114 | return; 115 | } 116 | sb->buf = p; 117 | } 118 | p = sb->buf+sb->len; 119 | while (n > skip) 120 | { 121 | text += skip; 122 | n -= skip; 123 | *p++ = *text++; 124 | n--; 125 | sb->len++; 126 | } 127 | } 128 | 129 | 130 | static inline void 131 | put_stringbuf (struct stringbuf *sb, const char *text) 132 | { 133 | put_stringbuf_mem (sb, text,strlen (text)); 134 | } 135 | 136 | 137 | static inline void 138 | put_stringbuf_mem_sexp (struct stringbuf *sb, const char *text, size_t length) 139 | { 140 | char buf[20]; 141 | sprintf (buf,"%u:", (unsigned int)length); 142 | put_stringbuf (sb, buf); 143 | put_stringbuf_mem (sb, text, length); 144 | } 145 | 146 | 147 | static inline void 148 | put_stringbuf_sexp (struct stringbuf *sb, const char *text) 149 | { 150 | put_stringbuf_mem_sexp (sb, text, strlen (text)); 151 | } 152 | 153 | 154 | static inline void 155 | put_stringbuf_uint (struct stringbuf *sb, unsigned int value) 156 | { 157 | char buf[35]; 158 | snprintf (buf, sizeof buf, "%u", (unsigned int)value); 159 | put_stringbuf_sexp (sb, buf); 160 | } 161 | 162 | 163 | static inline char * 164 | get_stringbuf (struct stringbuf *sb) 165 | { 166 | char *p; 167 | 168 | if (sb->out_of_core) 169 | { 170 | xfree (sb->buf); sb->buf = NULL; 171 | gpg_err_set_errno (sb->out_of_core); 172 | return NULL; 173 | } 174 | 175 | sb->buf[sb->len] = 0; 176 | p = sb->buf; 177 | sb->buf = NULL; 178 | sb->out_of_core = ENOMEM; /* make sure the caller does an init before reuse */ 179 | return p; 180 | } 181 | 182 | 183 | #endif /*STRINGBUF_H*/ 184 | -------------------------------------------------------------------------------- /tests/samples/ecdh-sample1.p7m.asn: -------------------------------------------------------------------------------- 1 | 0 443: SEQUENCE { 2 | 4 9: OBJECT IDENTIFIER envelopedData (1 2 840 113549 1 7 3) 3 | 15 428: [0] { -- content 4 | 19 424: SEQUENCE { 5 | 23 1: INTEGER 2 6 | 26 323: SET { 7 | 30 319: [1] { -- kari 8 | 34 1: INTEGER 3 9 | 37 113: [0] { -- originator 10 | 39 111: [1] { -- choice originatorKey 11 | 41 9: SEQUENCE { -- algorithm 12 | 43 7: OBJECT IDENTIFIER ecPublicKey (1 2 840 10045 2 1) 13 | : } 14 | 52 98: BIT STRING -- publicKey (ephemeral public key) 15 | : 04 A8 21 3B BD A2 18 85 63 B2 FA D1 46 94 05 3F 16 | : EF 1F B0 47 29 69 69 B5 F4 50 B2 34 E1 3C AB EE 17 | : EA E2 30 EB 46 E3 DD 4A 2B 15 B7 9D EF 3C 39 E1 18 | : 36 39 0D E9 66 AE 18 59 E3 05 CC F0 42 0F 3F EC 19 | : 51 8F 0C BB 0B DE 51 19 CE 06 4D BF 97 61 CF BF 20 | : 24 BF BF F7 B2 54 7C EC 0C 65 41 DD 10 FE 95 B5 21 | : A4 22 | : } 23 | : } -- end originator 24 | 152 21: SEQUENCE { -- keyEncryptionAlgorithm 25 | 154 6: OBJECT IDENTIFIER '1 3 132 1 11 1' -- (certicom) 26 | -- 11.1 := dhSinglePass-stdDH-sha256kdf-scheme 27 | -- 11.2 := dhSinglePass-stdDH-sha384kdf-scheme 28 | -- 11.3 := dhSinglePass-stdDH-sha512kdf-scheme 29 | 162 11: SEQUENCE { -- keyWrapAlgorithm 30 | 164 9: OBJECT IDENTIFIER aes128-wrap (2 16 840 1 101 3 4 1 5) 31 | -- 1.5 := aes128-wrap 32 | -- 1.25 := aes192-wrap 33 | -- 1.45 := aes256-wrap 34 | : } 35 | : } 36 | 175 175: SEQUENCE { -- recipientEncryptedKeys 37 | 178 172: SEQUENCE { -- recipientEncryptedKey 38 | 181 143: SEQUENCE { -- rid.issuerAndSerialNumber 39 | 184 119: SEQUENCE { 40 | 186 11: SET { 41 | 188 9: SEQUENCE { 42 | 190 3: OBJECT IDENTIFIER countryName (2 5 4 6) 43 | 195 2: PrintableString 'US' 44 | : } 45 | : } 46 | 199 19: SET { 47 | 201 17: SEQUENCE { 48 | 203 3: OBJECT IDENTIFIER stateOrProvinceName (2 5 4 8) 49 | 208 10: PrintableString 'California' 50 | : } 51 | : } 52 | 220 22: SET { 53 | 222 20: SEQUENCE { 54 | 224 3: OBJECT IDENTIFIER localityName (2 5 4 7) 55 | 229 13: PrintableString 'Mountain View' 56 | : } 57 | : } 58 | 244 18: SET { 59 | 246 16: SEQUENCE { 60 | 248 3: OBJECT IDENTIFIER organizationName (2 5 4 10) 61 | 253 9: PrintableString 'BOGUS NSS' 62 | : } 63 | : } 64 | 264 39: SET { 65 | 266 37: SEQUENCE { 66 | 268 3: OBJECT IDENTIFIER commonName (2 5 4 3) 67 | 273 30: PrintableString 'NSS Pregenerated Test CA (ECC)' 68 | : } 69 | : } 70 | : } 71 | 305 20: INTEGER 72 | : 74 5D C1 8C 19 D4 40 13 83 BE FC 5F 6E D2 BA D1 73 | : BE AE F5 09 74 | : } -- end rid.issuerAndSerialNumber 75 | 327 24: OCTET STRING -- encryptedKey 76 | : 80 0F 02 BC 0A 4A 52 EB 8A FF 51 B7 4E 88 DA 52 77 | : F7 EF AA 29 B0 26 13 E0 78 | : } -- end recipientEncryptedKey 79 | : } -- end recipientEncryptedKeys 80 | : } -- end kari 81 | : } -- end set 82 | 353 92: SEQUENCE { -- encryptedContentInfo 83 | 355 9: OBJECT IDENTIFIER data (1 2 840 113549 1 7 1) --type 84 | 366 29: SEQUENCE { -- contentEncryptionAlgorithm 85 | 368 9: OBJECT IDENTIFIER aes128-CBC (2 16 840 1 101 3 4 1 2) 86 | 379 16: OCTET STRING B1 55 96 AD B3 05 C8 64 69 4F 55 C8 9C 37 3A DF 87 | : } 88 | 397 48: [0] -- encryptedContent 89 | : 39 C9 BE CA 2C 99 58 ED F6 66 8F 96 A2 69 C8 58 90 | : 32 FC 84 67 7C 79 B6 F4 05 9E 35 C7 CC 4A 79 6E 91 | : 89 97 94 CF 9E 30 EE E1 AC DF A1 D9 C2 EC 72 9C 92 | : } 93 | : } 94 | : } 95 | : } 96 | -------------------------------------------------------------------------------- /src/util.h: -------------------------------------------------------------------------------- 1 | /* util.h 2 | * Copyright (C) 2001, 2009, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef UTIL_H 32 | #define UTIL_H 33 | 34 | #ifdef BUILD_GENTOOLS 35 | #error file may not be be used for build time tools 36 | #endif 37 | 38 | 39 | #include "visibility.h" 40 | 41 | 42 | gpg_error_t _ksba_hash_buffer (const char *oid, 43 | const void *buffer, size_t length, 44 | size_t resultsize, 45 | unsigned char *result, size_t *resultlen); 46 | 47 | void *_ksba_reallocarray (void *a, size_t oldnmemb, size_t nmemb, size_t size); 48 | 49 | void *_ksba_xmalloc (size_t n ); 50 | void *_ksba_xcalloc (size_t n, size_t m ); 51 | void *_ksba_xrealloc (void *p, size_t n); 52 | char *_ksba_xstrdup (const char *p); 53 | 54 | #define xtrymalloc(a) ksba_malloc((a)) 55 | #define xtrycalloc(a,b) ksba_calloc((a),(b)) 56 | #define xtryrealloc(a,b) ksba_realloc((a),(b)) 57 | #define xtrystrdup(a) ksba_strdup((a)) 58 | #define xfree(a) ksba_free((a)) 59 | 60 | #define xmalloc(a) _ksba_xmalloc((a)) 61 | #define xcalloc(a,b) _ksba_xcalloc((a),(b)) 62 | #define xrealloc(a,b) _ksba_xrealloc((a),(b)) 63 | #define xstrdup(a) _ksba_xstrdup((a)) 64 | 65 | 66 | #define DIM(v) (sizeof(v)/sizeof((v)[0])) 67 | #define DIMof(type,member) DIM(((type *)0)->member) 68 | #ifndef STR 69 | # define STR(v) #v 70 | #endif 71 | #ifndef STR2 72 | # define STR2(v) STR(v) 73 | #endif 74 | 75 | #define return_if_fail(expr) do { \ 76 | if (!(expr)) { \ 77 | fprintf (stderr, "%s:%d: assertion `%s' failed\n", \ 78 | __FILE__, __LINE__, #expr ); \ 79 | return; \ 80 | } } while (0) 81 | #define return_null_if_fail(expr) do { \ 82 | if (!(expr)) { \ 83 | fprintf (stderr, "%s:%d: assertion `%s' failed\n", \ 84 | __FILE__, __LINE__, #expr ); \ 85 | return NULL; \ 86 | } } while (0) 87 | #define return_val_if_fail(expr,val) do { \ 88 | if (!(expr)) { \ 89 | fprintf (stderr, "%s:%d: assertion `%s' failed\n", \ 90 | __FILE__, __LINE__, #expr ); \ 91 | return (val); \ 92 | } } while (0) 93 | #define never_reached() do { \ 94 | fprintf (stderr, "%s:%d: oops; should never get here\n", \ 95 | __FILE__, __LINE__ ); \ 96 | } while (0) 97 | 98 | 99 | #ifndef HAVE_STPCPY 100 | char *_ksba_stpcpy (char *a, const char *b); 101 | #define stpcpy(a,b) _ksba_stpcpy ((a), (b)) 102 | #endif 103 | 104 | int _ksba_ascii_memcasecmp (const void *a_arg, const void *b_arg, size_t n); 105 | #define ascii_memcasecmp(a,b,n) _ksba_ascii_memcasecmp ((a),(b),(n)) 106 | 107 | /* some macros to replace ctype ones and avoid locale problems */ 108 | #define spacep(p) (*(p) == ' ' || *(p) == '\t') 109 | #define digitp(p) (*(p) >= '0' && *(p) <= '9') 110 | #define hexdigitp(a) (digitp (a) \ 111 | || (*(a) >= 'A' && *(a) <= 'F') \ 112 | || (*(a) >= 'a' && *(a) <= 'f')) 113 | /* the atoi macros assume that the buffer has only valid digits */ 114 | #define atoi_1(p) (*(p) - '0' ) 115 | #define atoi_2(p) ((atoi_1(p) * 10) + atoi_1((p)+1)) 116 | #define atoi_4(p) ((atoi_2(p) * 100) + atoi_2((p)+2)) 117 | #define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \ 118 | *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10)) 119 | #define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1)) 120 | 121 | #endif /* UTIL_H */ 122 | -------------------------------------------------------------------------------- /m4/ltsugar.m4: -------------------------------------------------------------------------------- 1 | # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. 4 | # Written by Gary V. Vaughan, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 6 ltsugar.m4 11 | 12 | # This is to help aclocal find these macros, as it can't see m4_define. 13 | AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) 14 | 15 | 16 | # lt_join(SEP, ARG1, [ARG2...]) 17 | # ----------------------------- 18 | # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their 19 | # associated separator. 20 | # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier 21 | # versions in m4sugar had bugs. 22 | m4_define([lt_join], 23 | [m4_if([$#], [1], [], 24 | [$#], [2], [[$2]], 25 | [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) 26 | m4_define([_lt_join], 27 | [m4_if([$#$2], [2], [], 28 | [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) 29 | 30 | 31 | # lt_car(LIST) 32 | # lt_cdr(LIST) 33 | # ------------ 34 | # Manipulate m4 lists. 35 | # These macros are necessary as long as will still need to support 36 | # Autoconf-2.59 which quotes differently. 37 | m4_define([lt_car], [[$1]]) 38 | m4_define([lt_cdr], 39 | [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], 40 | [$#], 1, [], 41 | [m4_dquote(m4_shift($@))])]) 42 | m4_define([lt_unquote], $1) 43 | 44 | 45 | # lt_append(MACRO-NAME, STRING, [SEPARATOR]) 46 | # ------------------------------------------ 47 | # Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'. 48 | # Note that neither SEPARATOR nor STRING are expanded; they are appended 49 | # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). 50 | # No SEPARATOR is output if MACRO-NAME was previously undefined (different 51 | # than defined and empty). 52 | # 53 | # This macro is needed until we can rely on Autoconf 2.62, since earlier 54 | # versions of m4sugar mistakenly expanded SEPARATOR but not STRING. 55 | m4_define([lt_append], 56 | [m4_define([$1], 57 | m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) 58 | 59 | 60 | 61 | # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) 62 | # ---------------------------------------------------------- 63 | # Produce a SEP delimited list of all paired combinations of elements of 64 | # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list 65 | # has the form PREFIXmINFIXSUFFIXn. 66 | # Needed until we can rely on m4_combine added in Autoconf 2.62. 67 | m4_define([lt_combine], 68 | [m4_if(m4_eval([$# > 3]), [1], 69 | [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl 70 | [[m4_foreach([_Lt_prefix], [$2], 71 | [m4_foreach([_Lt_suffix], 72 | ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, 73 | [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) 74 | 75 | 76 | # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) 77 | # ----------------------------------------------------------------------- 78 | # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited 79 | # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. 80 | m4_define([lt_if_append_uniq], 81 | [m4_ifdef([$1], 82 | [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], 83 | [lt_append([$1], [$2], [$3])$4], 84 | [$5])], 85 | [lt_append([$1], [$2], [$3])$4])]) 86 | 87 | 88 | # lt_dict_add(DICT, KEY, VALUE) 89 | # ----------------------------- 90 | m4_define([lt_dict_add], 91 | [m4_define([$1($2)], [$3])]) 92 | 93 | 94 | # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) 95 | # -------------------------------------------- 96 | m4_define([lt_dict_add_subkey], 97 | [m4_define([$1($2:$3)], [$4])]) 98 | 99 | 100 | # lt_dict_fetch(DICT, KEY, [SUBKEY]) 101 | # ---------------------------------- 102 | m4_define([lt_dict_fetch], 103 | [m4_ifval([$3], 104 | m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), 105 | m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) 106 | 107 | 108 | # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) 109 | # ----------------------------------------------------------------- 110 | m4_define([lt_if_dict_fetch], 111 | [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], 112 | [$5], 113 | [$6])]) 114 | 115 | 116 | # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) 117 | # -------------------------------------------------------------- 118 | m4_define([lt_dict_filter], 119 | [m4_if([$5], [], [], 120 | [lt_join(m4_quote(m4_default([$4], [[, ]])), 121 | lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), 122 | [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl 123 | ]) 124 | -------------------------------------------------------------------------------- /src/ocsp.h: -------------------------------------------------------------------------------- 1 | /* ocsp.h - OCSP (rfc2560) 2 | * Copyright (C) 2003, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef OCSP_H 32 | #define OCSP_H 1 33 | 34 | #include "ksba.h" 35 | 36 | 37 | 38 | /* A structure to store certificates read from a response. */ 39 | struct ocsp_certlist_s { 40 | struct ocsp_certlist_s *next; 41 | ksba_cert_t cert; 42 | }; 43 | 44 | /* A structre to save a way extensions. */ 45 | struct ocsp_extension_s 46 | { 47 | struct ocsp_extension_s *next; 48 | size_t off; /* Offset into DATA to the content of the octet string. */ 49 | size_t len; /* Length of the octet string. */ 50 | int crit; /* IsCritical flag. */ 51 | char data[1]; /* This is made up of the OID string followed by the 52 | actual DER data of the extension. */ 53 | }; 54 | 55 | 56 | /* A structure to keep a information about a single status request. */ 57 | struct ocsp_reqitem_s { 58 | struct ocsp_reqitem_s *next; 59 | 60 | ksba_cert_t cert; /* The target certificate for the request. */ 61 | ksba_cert_t issuer_cert; /* And the certificate of the issuer. */ 62 | 63 | /* The next 4 fields are used to match a response with a request. */ 64 | unsigned char issuer_name_hash[32]; /* The hash as used by the request. */ 65 | unsigned char issuer_key_hash[32]; /* The hash as used by the request. */ 66 | unsigned char *serialno; /* A malloced copy of the serial number. */ 67 | size_t serialnolen; /* and its length. */ 68 | 69 | /* The actual status as parsed from the response. */ 70 | ksba_isotime_t this_update; /* The thisUpdate value from the response. */ 71 | ksba_isotime_t next_update; /* The nextUpdate value from the response. */ 72 | ksba_status_t status; /* Set to the status of the target. */ 73 | ksba_isotime_t revocation_time; /* The indicated revocation time. */ 74 | ksba_crl_reason_t revocation_reason; /* The reason given for revocation. */ 75 | struct ocsp_extension_s *single_extensions; /* List of extensions. */ 76 | }; 77 | 78 | /* A structure used as context for the ocsp subsystem. */ 79 | struct ksba_ocsp_s { 80 | char *digest_oid; /* The OID of the digest algorithm to be 81 | used for a request. */ 82 | 83 | struct ocsp_reqitem_s *requestlist; /* The list of request items. */ 84 | 85 | size_t noncelen; /* 0 if no nonce was sent. */ 86 | unsigned char nonce[16]; /* The random nonce we sent; actual length 87 | is NONCELEN. Warning: If its length is 88 | increased, check that the created 89 | request will still be valid as we use a 90 | hacked implementation. */ 91 | 92 | unsigned int sha256_certid; /* If set SHA256 will be used for the CERTID. */ 93 | 94 | unsigned char *request_buffer; /* Internal buffer to build the request. */ 95 | size_t request_buflen; 96 | 97 | size_t hash_offset; /* What area of the response is to be */ 98 | size_t hash_length; /* hashed. */ 99 | 100 | ksba_ocsp_response_status_t response_status; /* Status of the response. */ 101 | ksba_sexp_t sigval; /* The signature value. */ 102 | ksba_isotime_t produced_at; /* The time the response was signed. */ 103 | struct ocsp_certlist_s *received_certs; /* Certificates received in 104 | the response. */ 105 | struct ocsp_extension_s *response_extensions; /* List of extensions. */ 106 | int bad_nonce; /* The nonce does not match the request. */ 107 | struct { 108 | char *name; /* Allocated DN. */ 109 | char *keyid; /* Allocated key ID. */ 110 | size_t keyidlen; /* length of the KeyID. */ 111 | } responder_id; /* The reponder ID from the response. */ 112 | }; 113 | 114 | 115 | #endif /*OCSP_H*/ 116 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | # Makefile.am - for the KSBA ASN.1 and X.509 library 2 | # Copyright (C) 2001, 2002, 2004, 2005, 2007 g10 Code GmbH 3 | # 4 | # This file is part of KSBA. 5 | # 6 | # KSBA is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # KSBA is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, see . 18 | 19 | ## Process this file with automake to produce Makefile.in 20 | 21 | pkgconfigdir = $(libdir)/pkgconfig 22 | pkgconfig_DATA = ksba.pc 23 | 24 | asn1_modules = tmttv2.asn cms.asn 25 | 26 | buildtool_src = asn1-gentables.c gen-help.c gen-help.h 27 | EXTRA_DIST = ksba.h.in ksba-config.in $(asn1_modules) ksba.m4 \ 28 | libksba.vers libksba.def \ 29 | asn1-parse.c asn1-tables.c $(buildtool_src) ksba.pc.in 30 | BUILT_SOURCES = asn1-parse.c asn1-tables.c 31 | if USE_GPGRT_CONFIG 32 | noinst_SCRIPTS = ksba-config 33 | else 34 | bin_SCRIPTS = ksba-config 35 | endif 36 | nodist_include_HEADERS = ksba.h 37 | lib_LTLIBRARIES = libksba.la 38 | noinst_PROGRAMS = ber-dump 39 | 40 | m4datadir = $(datadir)/aclocal 41 | m4data_DATA = ksba.m4 42 | 43 | CLEANFILES = asn1-gentables 44 | DISTCLEANFILES = asn1-tables.c 45 | 46 | AM_CPPFLAGS = -I$(top_builddir)/gl -I$(top_srcdir)/gl 47 | AM_CFLAGS = $(GPG_ERROR_CFLAGS) $(COVERAGE_CFLAGS) 48 | 49 | 50 | if HAVE_LD_VERSION_SCRIPT 51 | libksba_version_script_cmd = -Wl,--version-script=$(srcdir)/libksba.vers 52 | else 53 | libksba_version_script_cmd = 54 | endif 55 | 56 | 57 | if HAVE_W32_SYSTEM 58 | RCCOMPILE = $(RC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 59 | $(libksba_la_CPPFLAGS) $(AM_CPPFLAGS) $(CPPFLAGS) 60 | LTRCCOMPILE = $(LIBTOOL) --mode=compile --tag=RC $(RCCOMPILE) 61 | 62 | SUFFIXES = .rc .lo 63 | 64 | .rc.lo: 65 | $(LTRCCOMPILE) -i "$<" -o "$@" 66 | 67 | ksba_res = versioninfo.lo 68 | no_undefined = -no-undefined 69 | export_symbols = -export-symbols $(srcdir)/libksba.def 70 | extra_ltoptions = -XCClinker -static-libgcc 71 | 72 | uninstall-def-file: 73 | -rm $(DESTDIR)$(libdir)/libksba.def 74 | 75 | ksba_deps = $(ksba_res) libksba.def 76 | ksbadefdir = $(libdir) 77 | ksbadef_DATA = libksba.def 78 | 79 | else !HAVE_W32_SYSTEM 80 | ksba_res = 81 | no_undefined = 82 | export_symbols = 83 | extra_ltoptions = 84 | ksba_deps = 85 | uninstall-def-file: 86 | endif !HAVE_W32_SYSTEM 87 | 88 | 89 | libksba_la_LDFLAGS = $(no_undefined) $(export_symbols) $(extra_ltoptions) \ 90 | $(libksba_version_script_cmd) -version-info \ 91 | @LIBKSBA_LT_CURRENT@:@LIBKSBA_LT_REVISION@:@LIBKSBA_LT_AGE@ \ 92 | $(COVERAGE_LDFLAGS) 93 | libksba_la_INCLUDES = -I$(top_srcdir)/lib 94 | libksba_la_DEPENDENCIES = $(srcdir)/libksba.vers $(ksba_deps) 95 | libksba_la_LIBADD = $(ksba_res) @LTLIBOBJS@ @GPG_ERROR_LIBS@ 96 | 97 | 98 | libksba_la_SOURCES = \ 99 | ksba.h \ 100 | visibility.c visibility.h \ 101 | reader.c reader.h \ 102 | writer.c writer.h \ 103 | asn1-parse.y \ 104 | asn1-func.c asn1-func2.c asn1-func.h asn1-constants.h \ 105 | ber-help.c ber-help.h \ 106 | ber-decoder.c ber-decoder.h \ 107 | der-encoder.c der-encoder.h \ 108 | der-builder.c der-builder.h \ 109 | cert.c cert.h \ 110 | cms.c cms.h cms-parser.c \ 111 | crl.c crl.h \ 112 | certreq.c certreq.h \ 113 | ocsp.c ocsp.h \ 114 | keyinfo.c keyinfo.h \ 115 | oid.c name.c dn.c time.c convert.h stringbuf.h \ 116 | version.c util.c util.h shared.h \ 117 | sexp-parse.h \ 118 | asn1-tables.c 119 | 120 | ber_dump_SOURCES = ber-dump.c \ 121 | ber-decoder.c ber-help.c reader.c writer.c asn1-parse.c \ 122 | asn1-func.c oid.c time.c util.c 123 | ber_dump_LDADD = $(GPG_ERROR_LIBS) ../gl/libgnu.la 124 | ber_dump_CFLAGS = $(AM_CFLAGS) 125 | 126 | asn1-parse.c : asn1-func.h gen-help.h 127 | 128 | asn1-gentables$(EXEEXT_FOR_BUILD): asn1-gentables.c asn1-parse.c asn1-func.c \ 129 | gen-help.c gen-help.h 130 | $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) \ 131 | $(CPPFLAGS_FOR_BUILD) -I$(srcdir) -DBUILD_GENTOOLS -o $@ \ 132 | $(srcdir)/asn1-gentables.c \ 133 | `test -f 'asn1-parse.c' || echo '$(srcdir)/'`asn1-parse.c \ 134 | $(srcdir)/asn1-func.c \ 135 | $(srcdir)/gen-help.c 136 | 137 | asn1-tables.c : $(asn1_modules) asn1-gentables$(EXEEXT_FOR_BUILD) 138 | @set -e; list=""; \ 139 | for file in $(asn1_modules); do list="$$list $(srcdir)/$$file";done;\ 140 | ./asn1-gentables$(EXEEXT_FOR_BUILD) $$list > asn1-tables.c 141 | 142 | 143 | uninstall-local: uninstall-def-file 144 | -------------------------------------------------------------------------------- /src/time.c: -------------------------------------------------------------------------------- 1 | /* time.c - UTCTime and GeneralizedTime helper 2 | * Copyright (C) 2001, 2003, 2005, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "util.h" 39 | #include "convert.h" 40 | 41 | 42 | /* Converts an UTCTime or GeneralizedTime to ISO format. Sets the 43 | returns string to empty on error and returns the error code. The 44 | function figures automagically the right format. fixme: Currently 45 | we only zupport Zulu time and no timezone which is sufficient for 46 | DER encoding. It IS_UTCTIME is true, the function assumes that the 47 | time is in UTCTime and thus allows to parse UTCTimes without 48 | seconds (which is legal ASN.1; however Gutmann claims that the 49 | rules changed in 1996 to always require seconds; OTOH, Dubuisson's 50 | reference book from 2001 doesn't say so). */ 51 | gpg_error_t 52 | _ksba_asntime_to_iso (const char *buffer, size_t length, int is_utctime, 53 | ksba_isotime_t timebuf) 54 | { 55 | const char *s; 56 | size_t n; 57 | int year; 58 | 59 | *timebuf = 0; 60 | for (s=buffer, n=0; n < length && digitp (s); n++, s++) 61 | ; 62 | if (is_utctime) 63 | { 64 | if ((n != 10 && n != 12) || *s != 'Z') 65 | return gpg_error (GPG_ERR_INV_TIME); 66 | } 67 | else if ((n != 12 && n != 14) || *s != 'Z') 68 | return gpg_error (GPG_ERR_INV_TIME); 69 | 70 | s = buffer; 71 | if (n==12 || n == 10 ) /* UTCTime with or without seconds. */ 72 | { 73 | year = atoi_2 (s); 74 | timebuf[0] = year < 50? '2': '1'; 75 | timebuf[1] = year < 50? '0': '9'; 76 | memcpy (timebuf+2, s, 6); 77 | s += 6; 78 | } 79 | else 80 | { 81 | memcpy (timebuf, s, 8); 82 | s += 8; 83 | } 84 | timebuf[8] = 'T'; 85 | if (n == 10) /* UTCTime w/0 seconds. */ 86 | { 87 | memcpy (timebuf+9, s, 4); 88 | timebuf[13] = timebuf[14] = '0'; 89 | } 90 | else 91 | { 92 | memcpy (timebuf+9, s, 6); 93 | } 94 | timebuf[15] = 0; 95 | 96 | return 0; 97 | } 98 | 99 | 100 | /* Return 0 if ATIME has the proper format (e.g. "19660205T131415"). */ 101 | gpg_error_t 102 | _ksba_assert_time_format (const ksba_isotime_t atime) 103 | { 104 | int i; 105 | const char *s; 106 | 107 | if (!*atime) 108 | return gpg_error (GPG_ERR_NO_VALUE); 109 | 110 | for (s=atime, i=0; i < 8; i++, s++) 111 | if (!digitp (s)) 112 | return gpg_error (GPG_ERR_BUG); 113 | if (*s != 'T') 114 | return gpg_error (GPG_ERR_BUG); 115 | for (s++, i=9; i < 15; i++, s++) 116 | if (!digitp (s)) 117 | return gpg_error (GPG_ERR_BUG); 118 | if (*s) 119 | return gpg_error (GPG_ERR_BUG); 120 | return 0; 121 | } 122 | 123 | 124 | /* Copy ISO time S to D. This is a function so that we can detect 125 | faulty time formats. */ 126 | void 127 | _ksba_copy_time (ksba_isotime_t d, const ksba_isotime_t s) 128 | { 129 | if (!*s) 130 | memset (d, 0, 16); 131 | else if ( _ksba_assert_time_format (s) ) 132 | { 133 | fprintf (stderr, "BUG: invalid isotime buffer\n"); 134 | abort (); 135 | } 136 | else 137 | strcpy (d, s); 138 | } 139 | 140 | 141 | /* Compare the time strings A and B. Return 0 if they show the very 142 | same time, return 1 if A is newer than B and -1 if A is older than 143 | B. */ 144 | int 145 | _ksba_cmp_time (const ksba_isotime_t a, const ksba_isotime_t b) 146 | { 147 | return strcmp (a, b); 148 | } 149 | 150 | /* Fill the TIMEBUF with the current time (UTC of course). */ 151 | int 152 | _ksba_current_time (ksba_isotime_t timebuf) 153 | { 154 | time_t epoch = time (NULL); 155 | struct tm *tp; 156 | #ifdef HAVE_GMTIME_R 157 | struct tm tmbuf; 158 | 159 | tp = gmtime_r ( &epoch, &tmbuf); 160 | #else 161 | tp = gmtime ( &epoch ); 162 | #endif 163 | return snprintf (timebuf, sizeof (ksba_isotime_t), 164 | "%04d%02d%02dT%02d%02d%02d", 165 | 1900 + tp->tm_year, tp->tm_mon+1, tp->tm_mday, 166 | tp->tm_hour, tp->tm_min, tp->tm_sec); 167 | } 168 | -------------------------------------------------------------------------------- /src/ber-help.h: -------------------------------------------------------------------------------- 1 | /* ber-help.h - Basic Encoding Rules helpers 2 | * Copyright (C) 2001, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef BER_HELP_H 32 | #define BER_HELP_H 1 33 | 34 | 35 | struct tag_info { 36 | enum tag_class class; 37 | int is_constructed; 38 | unsigned long tag; 39 | unsigned long length; /* length part of the TLV */ 40 | int ndef; /* It is an indefinite length */ 41 | size_t nhdr; /* number of bytes in the TL */ 42 | unsigned char buf[10]; /* buffer for the TL */ 43 | const char *err_string; 44 | int non_der; 45 | }; 46 | 47 | 48 | gpg_error_t _ksba_ber_read_tl (ksba_reader_t reader, struct tag_info *ti); 49 | gpg_error_t _ksba_ber_parse_tl (unsigned char const **buffer, size_t *size, 50 | struct tag_info *ti); 51 | gpg_error_t _ksba_ber_write_tl (ksba_writer_t writer, 52 | unsigned long tag, 53 | enum tag_class class, 54 | int constructed, 55 | unsigned long length); 56 | size_t _ksba_ber_encode_tl (unsigned char *buffer, 57 | unsigned long tag, 58 | enum tag_class class, 59 | int constructed, 60 | unsigned long length); 61 | size_t _ksba_ber_count_tl (unsigned long tag, 62 | enum tag_class class, 63 | int constructed, 64 | unsigned long length); 65 | 66 | 67 | static inline void 68 | parse_skip (unsigned char const **buf, size_t *len, struct tag_info *ti) 69 | { 70 | if (ti->length) 71 | { 72 | assert (ti->length <= *len); 73 | *len -= ti->length; 74 | *buf += ti->length; 75 | } 76 | } 77 | 78 | gpg_error_t _ksba_parse_sequence (unsigned char const **buf, size_t *len, 79 | struct tag_info *ti); 80 | #define parse_sequence(buf,len,ti) \ 81 | _ksba_parse_sequence ((buf),(len),(ti)) 82 | 83 | gpg_error_t _ksba_parse_context_tag (unsigned char const **buf, size_t *len, 84 | struct tag_info *ti, int tag); 85 | #define parse_context_tag(buf,len,ti,tag) \ 86 | _ksba_parse_context_tag ((buf),(len),(ti),(tag)) 87 | 88 | gpg_error_t _ksba_parse_enumerated (unsigned char const **buf, size_t *len, 89 | struct tag_info *ti, size_t maxlen); 90 | #define parse_enumerated(buf,len,ti,maxlen) \ 91 | _ksba_parse_enumerated ((buf),(len),(ti),(maxlen)) 92 | 93 | gpg_error_t _ksba_parse_integer (unsigned char const **buf, size_t *len, 94 | struct tag_info *ti); 95 | #define parse_integer(buf,len,ti) \ 96 | _ksba_parse_integer ((buf),(len),(ti)) 97 | 98 | gpg_error_t _ksba_parse_octet_string (unsigned char const **buf, size_t *len, 99 | struct tag_info *ti); 100 | #define parse_octet_string(buf,len,ti) \ 101 | _ksba_parse_octet_string ((buf),(len),(ti)) 102 | 103 | gpg_error_t _ksba_parse_optional_boolean (unsigned char const **buf, 104 | size_t *len, int *r_bool); 105 | #define parse_optional_boolean(buf,len,r_bool) \ 106 | _ksba_parse_optional_boolean ((buf),(len),(r_bool)) 107 | 108 | gpg_error_t _ksba_parse_optional_null (unsigned char const **buf, size_t *len, 109 | int *r_seen); 110 | #define parse_optional_null(buf,len,r_seen) \ 111 | _ksba_parse_optional_null ((buf),(len),(r_seen)) 112 | 113 | gpg_error_t _ksba_parse_object_id_into_str (unsigned char const **buf, 114 | size_t *len, char **oid); 115 | #define parse_object_id_into_str(buf,len,r_oid) \ 116 | _ksba_parse_object_id_into_str ((buf),(len),(r_oid)) 117 | 118 | 119 | gpg_error_t _ksba_parse_asntime_into_isotime (unsigned char const **buf, 120 | size_t *len, 121 | ksba_isotime_t isotime); 122 | #define parse_asntime_into_isotime(buf,len,isotime) \ 123 | _ksba_parse_asntime_into_isotime ((buf),(len),(isotime)) 124 | 125 | 126 | 127 | #endif /*BER_HELP_H*/ 128 | -------------------------------------------------------------------------------- /tests/samples/rsa-sample1.p7m.asn: -------------------------------------------------------------------------------- 1 | 0 NDEF: SEQUENCE { 2 | 2 9: OBJECT IDENTIFIER envelopedData (1 2 840 113549 1 7 3) 3 | 13 NDEF: [0] { -- content 4 | 15 NDEF: SEQUENCE { 5 | 17 1: INTEGER 0 -- version CMSVersion 6 | 20 538: SET { -- recipientInfos 7 | 24 534: SEQUENCE { -- ktri 8 | 28 1: INTEGER 0 -- version 9 | 31 126: SEQUENCE { -- rid.issuerAndSerialNumber 10 | 33 120: SEQUENCE { 11 | 35 11: SET { 12 | 37 9: SEQUENCE { 13 | 39 3: OBJECT IDENTIFIER countryName (2 5 4 6) 14 | 44 2: PrintableString 'DE' 15 | : } 16 | : } 17 | 48 22: SET { 18 | 50 20: SEQUENCE { 19 | 52 3: OBJECT IDENTIFIER organizationName (2 5 4 10) 20 | 57 13: PrintableString 'g10 Code GmbH' 21 | : } 22 | : } 23 | 72 16: SET { 24 | 74 14: SEQUENCE { 25 | 76 3: OBJECT IDENTIFIER organizationalUnitName (2 5 4 11) 26 | 81 7: PrintableString 'Testlab' 27 | : } 28 | : } 29 | 90 30: SET { 30 | 92 28: SEQUENCE { 31 | 94 3: OBJECT IDENTIFIER commonName (2 5 4 3) 32 | 99 21: PrintableString 'g10 Code TEST CA 2019' 33 | : } 34 | : } 35 | 122 31: SET { 36 | 124 29: SEQUENCE { 37 | 126 9: OBJECT IDENTIFIER 38 | : emailAddress (1 2 840 113549 1 9 1) 39 | 137 16: IA5String 'info@g10code.com' 40 | : } 41 | : } 42 | : } 43 | 155 2: INTEGER 6660 44 | : } -- end rid.issuerAndSerialNumber 45 | 159 13: SEQUENCE { -- keyEncryptionAlgorithm 46 | 161 9: OBJECT IDENTIFIER rsaEncryption (1 2 840 113549 1 1 1) 47 | 172 0: NULL 48 | : } 49 | 174 384: OCTET STRING -- encryptedKey 50 | : 4F E8 F7 AF BD 6D 0A C0 96 69 A6 51 27 9A E9 D8 51 | : D4 95 FA E2 88 7B FF 72 09 89 56 E5 57 17 EA 31 52 | : 65 8D 14 14 06 3A 30 05 C5 46 3F 47 F3 D0 14 8B 53 | : D9 9B 4B EA 09 26 F8 3E 6B 8B A5 EC 97 FE 77 9A 54 | : 43 BC 6D 16 0C 5F 6E AA 1D 12 A8 C9 5F 41 A0 D6 55 | : 65 19 CF EA 4C BE 9C 15 D4 B6 90 93 96 31 99 03 56 | : 85 EF 43 0E 6E 4E 07 C7 F9 46 B4 22 81 B2 52 73 57 | : C8 0B 90 E7 F4 6D 15 61 79 0B D2 AA A2 F4 29 45 58 | : 67 10 0E 39 E3 6B 5F BF 3A F3 E8 39 66 87 1A 49 59 | : 12 1E 03 24 BF F6 26 7F 81 04 DC 52 DE 44 E5 5F 60 | : 73 FA 7C 22 9E 55 D4 E3 EA 74 71 7F E0 07 EE 10 61 | : CF 35 7F 7D DE 64 6B A6 43 33 2A 74 96 23 D0 46 62 | : D3 F6 05 61 55 84 8C 98 EC FA 53 21 83 6E FE 6A 63 | : 2A 2C 91 81 FD 4C 9A C5 C5 AB 55 89 98 64 54 33 64 | : CF A2 9B 1D FB 5A DE D6 B5 2A 11 5D 47 9C B5 37 65 | : AE 22 49 97 3B F4 9F E7 F7 5C 57 27 42 39 35 0B 66 | : 3B 23 59 01 90 58 70 C0 06 FB DB 11 AE 57 9E AE 67 | : 5F 1B 9B 2C 8C 9A EE 31 EB 69 F0 AE A4 68 54 18 68 | : 68 4B 69 6A 7A 86 9E 60 86 80 20 51 A0 EC 8C 7D 69 | : 18 7B FA 44 64 E9 4E D7 6A FA C0 AB 90 7A B3 E3 70 | : 02 B9 FF 45 6F 6F B5 0C E3 D1 F2 F9 6E 05 BD E0 71 | : D7 A9 BB 10 DF A9 A4 13 65 3D DB 42 F3 04 7F 9E 72 | : 62 6B 75 BE 89 6E 85 04 EF 38 DB 64 44 09 5C 64 73 | : 79 73 99 F3 DD EB 16 BA 06 C2 92 84 A8 6B 7B 86 74 | : } -- end ktri 75 | : } -- end recipientInfos 76 | 562 NDEF: SEQUENCE { --encryptedContentInfo 77 | 564 9: OBJECT IDENTIFIER data (1 2 840 113549 1 7 1) 78 | 575 29: SEQUENCE { -- contentEncryptionAlgorithm 79 | 577 9: OBJECT IDENTIFIER aes128-CBC (2 16 840 1 101 3 4 1 2) 80 | 588 16: OCTET STRING A1 53 A3 8D A7 3A 23 5F 1D 46 10 8D 56 00 BC 3C 81 | : } 82 | 606 NDEF: [0] { -- encryptedContent 83 | 608 112: OCTET STRING 84 | : DA 9F 04 37 3F C5 7F 47 45 88 D6 04 AE 28 8E 98 85 | : 99 14 DD C1 DC 0A A9 18 38 BC 96 6D 05 AA 6F 82 86 | : BB 10 06 55 CF 43 0D 97 AB 6C 30 9A 70 1F BE D2 87 | : 35 A5 2E 96 F2 BC 4F 57 12 2F 2A FD 72 7A 79 CA 88 | : 9E 76 A5 05 62 47 0B 36 25 59 EE 1C 9F 7F 82 39 89 | : F6 58 91 3C 3B 97 A1 3E 5B A4 FA 6D 54 75 AF D8 90 | : 68 3F 24 52 56 C1 3D 88 39 53 0E 68 DD F8 5A 38 91 | 722 16: OCTET STRING F4 3A D1 CC 9A 64 31 C8 B7 3E ED F7 B9 FF 8F DC 92 | : } 93 | : } 94 | : } 95 | : } 96 | : } 97 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # Makefile.am - main makefile for libksba 2 | # Copyright (C) 2001, 2002 g10 Code GmbH 3 | # 4 | # This file is part of KSBA. 5 | # 6 | # KSBA is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # KSBA is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, see . 18 | 19 | ## Process this file with automake to produce Makefile.in 20 | 21 | # Location of the released tarball archives. This is prefixed by 22 | # the variable RELEASE_ARCHIVE in ~/.gnupg-autogen.rc. For example: 23 | # RELEASE_ARCHIVE=wk@somehost:archive/tarballs 24 | RELEASE_ARCHIVE_SUFFIX = libksba 25 | 26 | ACLOCAL_AMFLAGS = -I m4 -I gl/m4 27 | DISTCHECK_CONFIGURE_FLAGS = --enable-doc 28 | 29 | # (A suitable gitlog-to-changelog script can be found in GnuPG master.) 30 | GITLOG_TO_CHANGELOG=gitlog-to-changelog 31 | 32 | EXTRA_DIST = autogen.sh autogen.rc \ 33 | COPYING.GPLv2 COPYING.GPLv3 COPYING.LGPLv3 \ 34 | ChangeLog-2011 doc/ChangeLog-2011 src/ChangeLog-2011 \ 35 | tests/ChangeLog-2011 \ 36 | build-aux/libtool-patch.sed \ 37 | build-aux/git-log-footer build-aux/git-log-fix 38 | 39 | 40 | if CROSS_COMPILING 41 | tests = 42 | else 43 | tests = tests 44 | endif 45 | 46 | if BUILD_DOC 47 | doc = doc 48 | else 49 | doc = 50 | endif 51 | 52 | SUBDIRS = m4 gl src $(tests) $(doc) 53 | 54 | dist-hook: gen-ChangeLog 55 | 56 | distcheck-hook: 57 | set -e; ( \ 58 | pref="#+macro: $$(echo $(PACKAGE_NAME)|tr '-' '_')_" ;\ 59 | reldate="$$(date -u +%Y-%m-%d)" ;\ 60 | echo "$${pref}ver $(PACKAGE_VERSION)" ;\ 61 | echo "$${pref}date $${reldate}" ;\ 62 | list='$(DIST_ARCHIVES)'; for i in $$list; do \ 63 | case "$$i" in *.tar.bz2) \ 64 | echo "$${pref}size $$(wc -c <$$i|awk '{print int($$1/1024)}')k" ;\ 65 | echo "$${pref}sha1 $$(sha1sum <$$i|cut -d' ' -f1)" ;\ 66 | echo "$${pref}sha2 $$(sha256sum <$$i|cut -d' ' -f1)" ;;\ 67 | esac;\ 68 | done ) | tee $(distdir).swdb 69 | 70 | 71 | gen_start_date = 2011-12-01T00:00:00 72 | gen-ChangeLog: 73 | if test -d $(top_srcdir)/.git; then \ 74 | (cd $(top_srcdir) && \ 75 | $(GITLOG_TO_CHANGELOG) --append-dot --tear-off \ 76 | --amend=build-aux/git-log-fix \ 77 | --since=$(gen_start_date) ) > $(distdir)/cl-t; \ 78 | cat $(top_srcdir)/build-aux/git-log-footer >> $(distdir)/cl-t;\ 79 | rm -f $(distdir)/ChangeLog; \ 80 | mv $(distdir)/cl-t $(distdir)/ChangeLog; \ 81 | fi 82 | 83 | 84 | 85 | stowinstall: 86 | $(MAKE) $(AM_MAKEFLAGS) install prefix=/usr/local/stow/libksba 87 | 88 | 89 | 90 | .PHONY: gen-ChangeLog clean-coverage coverage-html release sign-release 91 | 92 | # Macro to help the release target. 93 | RELEASE_NAME = $(PACKAGE_TARNAME)-$(PACKAGE_VERSION) 94 | 95 | release: 96 | +(set -e;\ 97 | if [ "$(abs_top_builddir)" = "$(abs_top_srcdir)" ]; then \ 98 | echo "error: build directory must not be the source directory" >&2;\ 99 | exit 2;\ 100 | fi ;\ 101 | echo "/* Build started at $$(date -uIseconds) */" ;\ 102 | cd $(top_srcdir); \ 103 | ./autogen.sh --force; \ 104 | cd $(abs_top_builddir); \ 105 | rm -rf dist; mkdir dist ; cd dist ; \ 106 | $(abs_top_srcdir)/configure --enable-maintainer-mode; \ 107 | $(MAKE) distcheck; \ 108 | echo "/* Build finished at $$(date -uIseconds) */" ;\ 109 | echo "/*" ;\ 110 | echo " * Please run the final step interactivly:" ;\ 111 | echo " * make sign-release" ;\ 112 | echo " */" ;\ 113 | ) 2>&1 | tee "$(RELEASE_NAME).buildlog" 114 | 115 | sign-release: 116 | +(set -e; \ 117 | test $$(pwd | sed 's,.*/,,') = dist || cd dist; \ 118 | x=$$(grep '^RELEASE_ARCHIVE=' $$HOME/.gnupg-autogen.rc|cut -d= -f2);\ 119 | if [ -z "$$x" ]; then \ 120 | echo "error: RELEASE_ARCHIVE missing in ~/.gnupg-autogen.rc">&2; \ 121 | exit 2;\ 122 | fi;\ 123 | myarchive="$$x/$(RELEASE_ARCHIVE_SUFFIX)";\ 124 | x=$$(grep '^RELEASE_SIGNKEY=' $$HOME/.gnupg-autogen.rc|cut -d= -f2);\ 125 | if [ -z "$$x" ]; then \ 126 | echo "error: RELEASE_SIGNKEY missing in ~/.gnupg-autogen.rc">&2; \ 127 | exit 2;\ 128 | fi;\ 129 | mysignkey="$$x";\ 130 | files1="$(RELEASE_NAME).tar.bz2" ; \ 131 | files2="$(RELEASE_NAME).tar.bz2.sig \ 132 | $(RELEASE_NAME).swdb \ 133 | $(RELEASE_NAME).buildlog" ;\ 134 | echo "/* Signing the source tarball ..." ;\ 135 | gpg -sbu $$mysignkey $(RELEASE_NAME).tar.bz2 ;\ 136 | cat $(RELEASE_NAME).swdb >swdb.snippet;\ 137 | echo >>swdb.snippet ;\ 138 | sha1sum $${files1} >>swdb.snippet ;\ 139 | cat "../$(RELEASE_NAME).buildlog" swdb.snippet \ 140 | | gzip >$(RELEASE_NAME).buildlog ;\ 141 | echo "Copying to archive $$myarchive ..." ;\ 142 | scp -p $${files1} $${files2} $${myarchive}/ || true;\ 143 | echo '/*' ;\ 144 | echo ' * All done; for checksums see dist/swdb.snippet' ;\ 145 | echo ' */' ;\ 146 | ) 147 | -------------------------------------------------------------------------------- /src/cms.h: -------------------------------------------------------------------------------- 1 | /* cms.h - Internal definitions for the CMS functions 2 | * Copyright (C) 2001, 2012 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of either 8 | * 9 | * - the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 3 of the License, or (at 11 | * your option) any later version. 12 | * 13 | * or 14 | * 15 | * - the GNU General Public License as published by the Free 16 | * Software Foundation; either version 2 of the License, or (at 17 | * your option) any later version. 18 | * 19 | * or both in parallel, as here. 20 | * 21 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | * License for more details. 25 | * 26 | * You should have received a copies of the GNU General Public License 27 | * and the GNU Lesser General Public License along with this program; 28 | * if not, see . 29 | */ 30 | 31 | #ifndef CMS_H 32 | #define CMS_H 1 33 | 34 | #include "ksba.h" 35 | 36 | #ifndef HAVE_TYPEDEFD_ASNNODE 37 | typedef struct asn_node_struct *AsnNode; /* FIXME: should not go here */ 38 | #define HAVE_TYPEDEFD_ASNNODE 39 | #endif 40 | 41 | 42 | /* This structure is used to store the results of a BER parser run. */ 43 | struct value_tree_s { 44 | struct value_tree_s *next; 45 | AsnNode root; /* root of the tree with the values */ 46 | unsigned char *image; 47 | size_t imagelen; 48 | }; 49 | 50 | 51 | struct enc_val_s { 52 | char *algo; 53 | unsigned char *value; /* RSA's "a" or ECDH's "s". (malloced) */ 54 | size_t valuelen; 55 | struct { 56 | unsigned char *e; /* Malloced buffer. */ 57 | size_t elen; /* Length of E. */ 58 | char *encr_algo; /* Malloced OID string. */ 59 | char *wrap_algo; /* Malloced OID string. */ 60 | } ecdh; 61 | }; 62 | 63 | 64 | struct oidlist_s { 65 | struct oidlist_s *next; 66 | char *oid; 67 | }; 68 | 69 | /* A structure to store an OID and a parameter. */ 70 | struct oidparmlist_s { 71 | struct oidparmlist_s *next; 72 | char *oid; 73 | size_t parmlen; 74 | unsigned char parm[1]; 75 | }; 76 | 77 | 78 | struct certlist_s { 79 | struct certlist_s *next; 80 | ksba_cert_t cert; 81 | int msg_digest_len; /* used length of .. */ 82 | char msg_digest[64]; /* enough space to store a SHA-512 hash */ 83 | ksba_isotime_t signing_time; 84 | struct { 85 | AsnNode root; 86 | unsigned char *image; 87 | } sa; 88 | struct enc_val_s enc_val; /* used for creating enveloped data */ 89 | }; 90 | 91 | 92 | struct signer_info_s { 93 | struct signer_info_s *next; 94 | AsnNode root; /* root of the tree with the values */ 95 | unsigned char *image; 96 | size_t imagelen; 97 | struct { 98 | char *digest_algo; 99 | } cache; 100 | }; 101 | 102 | struct sig_val_s { 103 | struct sig_val_s *next; 104 | char *algo; 105 | unsigned char *value; /* Malloced buffer for parameter "s". */ 106 | size_t valuelen; /* Used length of VALUE. */ 107 | struct { 108 | unsigned char *r; /* Malloced buffer for parameter "r". */ 109 | size_t rlen; /* Length of R. */ 110 | } ecc; 111 | }; 112 | 113 | 114 | struct ksba_cms_s { 115 | gpg_error_t last_error; 116 | 117 | ksba_reader_t reader; 118 | ksba_writer_t writer; 119 | 120 | void (*hash_fnc)(void *, const void *, size_t); 121 | void *hash_fnc_arg; 122 | 123 | ksba_stop_reason_t stop_reason; 124 | 125 | struct { 126 | char *oid; 127 | unsigned long length; 128 | int ndef; 129 | ksba_content_type_t ct; 130 | gpg_error_t (*handler)(ksba_cms_t); 131 | } content; 132 | 133 | /* Data used with auth enveloped data. */ 134 | struct { 135 | unsigned char *mac; /* The MAC (authtag) */ 136 | int mac_len; 137 | unsigned char *attr; /* DER encoded authAttr. */ 138 | int attr_len; 139 | } authdata; 140 | 141 | int cms_version; 142 | 143 | struct oidlist_s *digest_algos; 144 | struct certlist_s *cert_list; 145 | char *inner_cont_oid; /* Encapsulated or Encrypted 146 | ContentInfo.contentType as string */ 147 | unsigned long inner_cont_len; 148 | int inner_cont_ndef; 149 | int detached_data; /* no actual data */ 150 | char *encr_algo_oid; 151 | char *encr_iv; 152 | size_t encr_ivlen; 153 | 154 | struct certlist_s *cert_info_list; /* A list with certificates intended 155 | to be send with a signed message */ 156 | 157 | struct oidparmlist_s *capability_list; /* A list of S/MIME capabilities. */ 158 | 159 | struct signer_info_s *signer_info; 160 | 161 | struct value_tree_s *recp_info; 162 | 163 | struct sig_val_s *sig_val; 164 | 165 | struct enc_val_s *enc_val; 166 | }; 167 | 168 | 169 | /*-- cms.c --*/ 170 | 171 | 172 | /*-- cms-parser.c --*/ 173 | gpg_error_t _ksba_cms_parse_content_info (ksba_cms_t cms); 174 | gpg_error_t _ksba_cms_parse_signed_data_part_1 (ksba_cms_t cms); 175 | gpg_error_t _ksba_cms_parse_signed_data_part_2 (ksba_cms_t cms); 176 | gpg_error_t _ksba_cms_parse_enveloped_data_part_1 (ksba_cms_t cms); 177 | gpg_error_t _ksba_cms_parse_enveloped_data_part_2 (ksba_cms_t cms); 178 | 179 | 180 | 181 | #endif /*CMS_H*/ 182 | -------------------------------------------------------------------------------- /tests/t-oid.c: -------------------------------------------------------------------------------- 1 | /* t-oid.c - Test utility for the OID functions 2 | * Copyright (C) 2009 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * KSBA is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "../src/ksba.h" 29 | 30 | #define PGM "t-oid" 31 | #define BADOID "1.3.6.1.4.1.11591.2.12242973" 32 | 33 | 34 | static void * 35 | read_into_buffer (FILE *fp, size_t *r_length) 36 | { 37 | char *buffer; 38 | size_t buflen; 39 | size_t nread, bufsize = 0; 40 | 41 | *r_length = 0; 42 | #define NCHUNK 8192 43 | #ifdef HAVE_W32_SYSTEM 44 | setmode (fileno(fp), O_BINARY); 45 | #endif 46 | buffer = NULL; 47 | buflen = 0; 48 | do 49 | { 50 | bufsize += NCHUNK; 51 | buffer = realloc (buffer, bufsize); 52 | if (!buffer) 53 | { 54 | perror ("realloc failed"); 55 | exit (1); 56 | } 57 | 58 | nread = fread (buffer + buflen, 1, NCHUNK, fp); 59 | if (nread < NCHUNK && ferror (fp)) 60 | { 61 | perror ("fread failed"); 62 | exit (1); 63 | } 64 | buflen += nread; 65 | } 66 | while (nread == NCHUNK); 67 | #undef NCHUNK 68 | 69 | *r_length = buflen; 70 | return buffer; 71 | } 72 | 73 | 74 | static void 75 | test_oid_to_str (void) 76 | { 77 | struct { 78 | unsigned int binlen; 79 | unsigned char *bin; 80 | char *str; 81 | } tests[] = { 82 | 83 | { 7, "\x02\x82\x06\x01\x0A\x0C\x00", 84 | "0.2.262.1.10.12.0" 85 | }, 86 | { 7, "\x02\x82\x06\x01\x0A\x0C\x01", 87 | "0.2.262.1.10.12.1" 88 | }, 89 | { 7, "\x2A\x86\x48\xCE\x38\x04\x01", 90 | "1.2.840.10040.4.1" 91 | }, 92 | { 7, "\x2A\x86\x48\xCE\x38\x04\x03", 93 | "1.2.840.10040.4.3" 94 | }, 95 | { 10, "\x2B\x06\x01\x04\x01\xDA\x47\x02\x01\x01", 96 | "1.3.6.1.4.1.11591.2.1.1" 97 | }, 98 | { 3, "\x55\x1D\x0E", 99 | "2.5.29.14" 100 | }, 101 | { 9, "\x80\x02\x70\x50\x25\x46\xfd\x0c\xc0", 102 | BADOID 103 | }, 104 | { 1, "\x80", 105 | BADOID 106 | }, 107 | { 2, "\x81\x00", 108 | "2.48" 109 | }, 110 | { 2, "\x81\x01", 111 | "2.49" 112 | }, 113 | { 2, "\x81\x7f", 114 | "2.175" 115 | }, 116 | { 2, "\x81\x80", /* legal encoding? */ 117 | "2.48" 118 | }, 119 | { 2, "\x81\x81\x01", /* legal encoding? */ 120 | "2.49" 121 | }, 122 | { 0, "", 123 | "" 124 | }, 125 | 126 | { 0, NULL, NULL } 127 | }; 128 | int tidx; 129 | char *str; 130 | 131 | for (tidx=0; tests[tidx].bin; tidx++) 132 | { 133 | str = ksba_oid_to_str (tests[tidx].bin, tests[tidx].binlen); 134 | if (!str) 135 | { 136 | perror ("ksba_oid_to_str failed"); 137 | exit (1); 138 | } 139 | if (strcmp (tests[tidx].str, str)) 140 | { 141 | fprintf (stderr, "ksba_oid_to_str test %d failed\n", tidx); 142 | fprintf (stderr, " got=%s\n", str); 143 | fprintf (stderr, " want=%s\n", tests[tidx].str); 144 | exit (1); 145 | } 146 | ksba_free (str); 147 | } 148 | } 149 | 150 | 151 | int 152 | main (int argc, char **argv) 153 | { 154 | gpg_error_t err; 155 | 156 | if (argc) 157 | { 158 | argc--; 159 | argv++; 160 | } 161 | 162 | 163 | if (!argc) 164 | { 165 | test_oid_to_str (); 166 | } 167 | else if (!strcmp (*argv, "--from-str")) 168 | { 169 | unsigned char *buffer; 170 | size_t n, buflen; 171 | 172 | for (argv++,argc-- ; argc; argc--, argv++) 173 | { 174 | err = ksba_oid_from_str (*argv, &buffer, &buflen); 175 | if (err) 176 | { 177 | fprintf (stderr, "can't convert `%s': %s\n", 178 | *argv, gpg_strerror (err)); 179 | return 1; 180 | } 181 | printf ("%s ->", *argv); 182 | for (n=0; n < buflen; n++) 183 | printf (" %02X", buffer[n]); 184 | putchar ('\n'); 185 | free (buffer); 186 | buffer = NULL; 187 | } 188 | } 189 | else if (!strcmp (*argv, "--to-str")) 190 | { 191 | char *buffer; 192 | size_t buflen; 193 | char *result; 194 | 195 | argv++;argc--; 196 | 197 | buffer = read_into_buffer (stdin, &buflen); 198 | result = ksba_oid_to_str (buffer, buflen); 199 | free (buffer); 200 | printf ("%s\n", result? result:"[malloc failed]"); 201 | free (result); 202 | } 203 | else 204 | { 205 | fputs ("usage: "PGM" [--from-str|--to-str]\n", stderr); 206 | return 1; 207 | } 208 | 209 | return 0; 210 | } 211 | -------------------------------------------------------------------------------- /tests/t-reader.c: -------------------------------------------------------------------------------- 1 | /* t-reader.c - basic tests for the reader object 2 | * Copyright (C) 2017 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * KSBA is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "../src/ksba.h" 34 | #include "t-common.h" 35 | 36 | void 37 | test_fd(const char* path) 38 | { 39 | int fd = open (path, O_RDONLY); 40 | gpg_error_t err = 0; 41 | ksba_reader_t reader; 42 | ksba_cert_t cert; 43 | 44 | if (fd < 0) 45 | { 46 | perror ("open() failed"); 47 | exit (1); 48 | } 49 | 50 | if ((err = ksba_reader_new (&reader))) 51 | { 52 | fprintf (stderr, "ksba_reader_new() failed: %s\n", gpg_strerror (err)); 53 | exit (1); 54 | } 55 | 56 | if ((err = ksba_reader_set_fd (reader, fd))) 57 | { 58 | fprintf (stderr, "ksba_reader_set_fd() failed: %s\n", gpg_strerror (err)); 59 | exit (1); 60 | } 61 | 62 | if ((err = ksba_cert_new (&cert))) 63 | { 64 | fprintf (stderr, "ksba_cert_new() failed: %s\n", gpg_strerror (err)); 65 | exit (1); 66 | } 67 | 68 | if ((err = ksba_cert_read_der (cert, reader))) 69 | { 70 | fprintf(stderr, "ksba_cert_read_der() failed: %s\n", gpg_strerror (err)); 71 | exit (1); 72 | } 73 | 74 | ksba_cert_release (cert); 75 | ksba_reader_release (reader); 76 | close (fd); 77 | } 78 | 79 | void 80 | test_file(const char* path) 81 | { 82 | FILE* fp = fopen (path, "r"); 83 | gpg_error_t err = 0; 84 | ksba_reader_t reader; 85 | ksba_cert_t cert; 86 | 87 | if (!fp) 88 | { 89 | perror ("fopen() failed"); 90 | exit (1); 91 | } 92 | 93 | if ((err = ksba_reader_new (&reader))) 94 | { 95 | fprintf (stderr, "ksba_reader_new() failed: %s\n", gpg_strerror (err)); 96 | exit (1); 97 | } 98 | 99 | if ((err = ksba_reader_set_file (reader, fp))) 100 | { 101 | fprintf (stderr, "ksba_reader_set_fd() failed: %s\n", gpg_strerror (err)); 102 | exit (1); 103 | } 104 | 105 | if ((err = ksba_cert_new (&cert))) 106 | { 107 | fprintf (stderr, "ksba_cert_new() failed: %s\n", gpg_strerror (err)); 108 | exit (1); 109 | } 110 | 111 | if ((err = ksba_cert_read_der (cert, reader))) 112 | { 113 | fprintf(stderr, "ksba_cert_read_der() failed: %s\n", gpg_strerror (err)); 114 | exit (1); 115 | } 116 | 117 | ksba_cert_release (cert); 118 | ksba_reader_release (reader); 119 | fclose (fp); 120 | } 121 | 122 | void 123 | test_mem(const char* path) 124 | { 125 | int fd = open (path, O_RDONLY); 126 | gpg_error_t err = 0; 127 | ksba_reader_t reader; 128 | ksba_cert_t cert; 129 | char *mem = NULL; 130 | ssize_t ret = 0; 131 | size_t p = 0; 132 | struct stat st; 133 | 134 | if (fd < 0) 135 | { 136 | perror ("fopen() failed"); 137 | exit (1); 138 | } 139 | 140 | if (fstat (fd, &st)) 141 | { 142 | fprintf (stderr, "fstat() failed: %s\n", gpg_strerror (err)); 143 | exit (1); 144 | } 145 | 146 | mem = xmalloc(st.st_size); 147 | 148 | while (p < st.st_size && (ret = read(fd, mem + p, st.st_size - p))) 149 | { 150 | if (ret < 0) 151 | { 152 | fprintf (stderr, "read() failed: %s\n", gpg_strerror (err)); 153 | exit (1); 154 | } 155 | p += ret; 156 | } 157 | 158 | if ((err = ksba_reader_new (&reader))) 159 | { 160 | exit (1); 161 | } 162 | 163 | if ((err = ksba_reader_set_mem (reader, mem, st.st_size))) 164 | { 165 | fprintf (stderr, "ksba_reader_set_mem() failed: %s\n", gpg_strerror (err)); 166 | exit (1); 167 | } 168 | 169 | if ((err = ksba_cert_new (&cert))) 170 | { 171 | fprintf (stderr, "ksba_cert_new() failed: %s\n", gpg_strerror (err)); 172 | exit (1); 173 | } 174 | 175 | if ((err = ksba_cert_read_der (cert, reader))) 176 | { 177 | fprintf(stderr, "ksba_cert_read_der() failed: %s\n", gpg_strerror (err)); 178 | exit (1); 179 | } 180 | 181 | ksba_cert_release (cert); 182 | ksba_reader_release (reader); 183 | xfree (mem); 184 | close (fd); 185 | } 186 | 187 | int 188 | main (int argc, char **argv) 189 | { 190 | if (argc == 1) 191 | { 192 | char *fname = prepend_srcdir ("samples/cert_g10code_test1.der"); 193 | 194 | test_fd (fname); 195 | test_file (fname); 196 | test_mem (fname); 197 | free(fname); 198 | } 199 | else 200 | { 201 | int i; 202 | for (i = 1; i < argc; ++i) 203 | { 204 | test_fd (argv[i]); 205 | test_file (argv[i]); 206 | test_mem (argv[i]); 207 | } 208 | } 209 | 210 | return 0; 211 | } 212 | -------------------------------------------------------------------------------- /src/libksba.vers: -------------------------------------------------------------------------------- 1 | # libksba.vers - What symbols to export 2 | # Copyright (C) 2004 g10 Code GmbH 3 | # 4 | # This file is part of KSBA. 5 | # 6 | # KSBA is free software; you can redistribute it and/or modify 7 | # it under the terms of either 8 | # 9 | # - the GNU Lesser General Public License as published by the Free 10 | # Software Foundation; either version 3 of the License, or (at 11 | # your option) any later version. 12 | # 13 | # or 14 | # 15 | # - the GNU General Public License as published by the Free 16 | # Software Foundation; either version 2 of the License, or (at 17 | # your option) any later version. 18 | # 19 | # or both in parallel, as here. 20 | # 21 | # KSBA is distributed in the hope that it will be useful, but WITHOUT 22 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 23 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 24 | # License for more details. 25 | # 26 | # You should have received a copies of the GNU General Public License 27 | # and the GNU Lesser General Public License along with this program; 28 | # if not, see . 29 | 30 | 31 | KSBA_0.9 { 32 | global: 33 | ksba_check_version; ksba_set_hash_buffer_function; 34 | 35 | ksba_set_malloc_hooks; 36 | ksba_free; ksba_malloc; ksba_calloc; ksba_realloc; ksba_strdup; 37 | 38 | ksba_asn_create_tree; ksba_asn_delete_structure; ksba_asn_parse_file; 39 | ksba_asn_tree_dump; ksba_asn_tree_release; 40 | 41 | ksba_cert_get_auth_key_id; ksba_cert_get_cert_policies; 42 | ksba_cert_get_crl_dist_point; ksba_cert_get_digest_algo; 43 | ksba_cert_get_ext_key_usages; ksba_cert_get_extension; 44 | ksba_cert_get_image; ksba_cert_get_issuer; ksba_cert_get_key_usage; 45 | ksba_cert_get_public_key; ksba_cert_get_serial; ksba_cert_get_sig_val; 46 | ksba_cert_get_subject; ksba_cert_get_validity; ksba_cert_hash; 47 | ksba_cert_init_from_mem; ksba_cert_is_ca; ksba_cert_new; 48 | ksba_cert_read_der; ksba_cert_ref; ksba_cert_release; 49 | ksba_cert_get_authority_info_access; ksba_cert_get_subject_info_access; 50 | ksba_cert_get_subj_key_id; 51 | ksba_cert_set_user_data; ksba_cert_get_user_data; 52 | 53 | ksba_certreq_add_subject; ksba_certreq_build; ksba_certreq_new; 54 | ksba_certreq_release; ksba_certreq_set_hash_function; 55 | ksba_certreq_set_public_key; ksba_certreq_set_sig_val; 56 | ksba_certreq_set_writer; 57 | ksba_certreq_add_extension; 58 | ksba_certreq_set_serial; 59 | ksba_certreq_set_issuer; 60 | ksba_certreq_set_validity; 61 | ksba_certreq_set_siginfo; 62 | 63 | ksba_cms_add_cert; ksba_cms_add_digest_algo; ksba_cms_add_recipient; 64 | ksba_cms_add_signer; ksba_cms_build; ksba_cms_get_cert; 65 | ksba_cms_get_content_enc_iv; ksba_cms_get_content_oid; 66 | ksba_cms_get_content_type; ksba_cms_get_digest_algo; 67 | ksba_cms_get_digest_algo_list; ksba_cms_get_enc_val; 68 | ksba_cms_get_issuer_serial; ksba_cms_get_message_digest; 69 | ksba_cms_get_sig_val; ksba_cms_get_sigattr_oids; 70 | ksba_cms_get_signing_time; ksba_cms_hash_signed_attrs; 71 | ksba_cms_identify; ksba_cms_new; ksba_cms_parse; ksba_cms_release; 72 | ksba_cms_set_content_enc_algo; ksba_cms_set_content_type; 73 | ksba_cms_set_enc_val; ksba_cms_set_hash_function; 74 | ksba_cms_set_message_digest; ksba_cms_set_reader_writer; 75 | ksba_cms_set_sig_val; ksba_cms_set_signing_time; 76 | ksba_cms_add_smime_capability; 77 | 78 | ksba_crl_get_digest_algo; ksba_crl_get_issuer; ksba_crl_get_item; 79 | ksba_crl_get_sig_val; ksba_crl_get_update_times; ksba_crl_new; 80 | ksba_crl_parse; ksba_crl_release; ksba_crl_set_hash_function; 81 | ksba_crl_set_reader; 82 | ksba_crl_get_extension; ksba_crl_get_auth_key_id; 83 | ksba_crl_get_crl_number; 84 | 85 | ksba_name_enum; ksba_name_get_uri; ksba_name_new; ksba_name_ref; 86 | ksba_name_release; 87 | 88 | ksba_ocsp_add_cert; ksba_ocsp_add_target; ksba_ocsp_build_request; 89 | ksba_ocsp_get_cert; ksba_ocsp_get_digest_algo; 90 | ksba_ocsp_get_responder_id; ksba_ocsp_get_sig_val; 91 | ksba_ocsp_get_status; ksba_ocsp_hash_request; ksba_ocsp_hash_response; 92 | ksba_ocsp_new; ksba_ocsp_parse_response; ksba_ocsp_prepare_request; 93 | ksba_ocsp_release; ksba_ocsp_set_digest_algo; ksba_ocsp_set_nonce; 94 | ksba_ocsp_set_requestor; ksba_ocsp_set_sig_val; ksba_ocsp_get_extension; 95 | 96 | ksba_oid_from_str; ksba_oid_to_str; 97 | 98 | ksba_dn_der2str; ksba_dn_str2der; ksba_dn_teststr; 99 | 100 | ksba_reader_clear; ksba_reader_error; ksba_reader_new; 101 | ksba_reader_read; ksba_reader_release; ksba_reader_set_cb; 102 | ksba_reader_set_fd; ksba_reader_set_file; ksba_reader_set_mem; 103 | ksba_reader_tell; ksba_reader_unread; ksba_reader_set_release_notify; 104 | 105 | ksba_writer_error; ksba_writer_get_mem; ksba_writer_new; 106 | ksba_writer_release; ksba_writer_set_cb; ksba_writer_set_fd; 107 | ksba_writer_set_file; ksba_writer_set_filter; ksba_writer_set_mem; 108 | ksba_writer_snatch_mem; ksba_writer_tell; ksba_writer_write; 109 | ksba_writer_write_octet_string; ksba_writer_set_release_notify; 110 | 111 | ksba_der_release; ksba_der_builder_new; ksba_der_builder_reset; 112 | ksba_der_add_ptr; ksba_der_add_val; ksba_der_add_int; 113 | ksba_der_add_oid; ksba_der_add_bts; ksba_der_add_der; 114 | ksba_der_add_tag; ksba_der_add_end; 115 | ksba_der_builder_get; 116 | 117 | local: 118 | *; 119 | }; 120 | 121 | 122 | # We need to export a couple of symbols for our regression tests. 123 | KSBA_PRIVATE_TESTS { 124 | global: 125 | _ksba_keyinfo_from_sexp; _ksba_keyinfo_to_sexp; 126 | 127 | } KSBA_0.9; 128 | -------------------------------------------------------------------------------- /tests/t-dnparser.c: -------------------------------------------------------------------------------- 1 | /* t-dnparser.c - basic test for the DN parser 2 | * Copyright (C) 2002, 2006 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * KSBA is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "../src/ksba.h" 28 | #include "t-common.h" 29 | 30 | static int quiet; 31 | static int verbose; 32 | 33 | 34 | static void 35 | test_0 (void) 36 | { 37 | static char *good_strings[] = { 38 | "C=de,O=g10 Code,OU=qa,CN=Pépé le Moko", 39 | "C= de, O=g10 Code , OU=qa ,CN=Pépé le Moko", 40 | "CN=www.gnupg.org", 41 | " CN=www.gnupg.org ", 42 | "C=fr,L=Paris,CN=Julien Duvivier,EMAIL=julien@example.org", 43 | NULL 44 | }; 45 | gpg_error_t err; 46 | int i; 47 | unsigned char *buf; 48 | size_t off, len; 49 | 50 | for (i=0; good_strings[i]; i++) 51 | { 52 | err = ksba_dn_str2der (good_strings[i], &buf, &len); 53 | if (err) 54 | { 55 | fprintf (stderr, "%s:%d: ksba_dn_str2der failed for `%s': %s\n", 56 | __FILE__,__LINE__, good_strings[i], gpg_strerror (err)); 57 | exit (1); 58 | } 59 | err = ksba_dn_teststr (good_strings[i], 0, &off, &len); 60 | if (err) 61 | { 62 | fprintf (stderr, "%s:%d: ksba_dn_teststr failed for `%s': %s\n", 63 | __FILE__,__LINE__, good_strings[i], gpg_strerror (err)); 64 | exit (1); 65 | } 66 | xfree (buf); 67 | } 68 | } 69 | 70 | 71 | static void 72 | test_1 (void) 73 | { 74 | static char *empty_elements[] = { 75 | "C=de,O=foo,OU=,CN=joe", 76 | "C=de,O=foo,OU= ,CN=joe", 77 | "C=de,O=foo,OU=\"\" ,CN=joe", 78 | "C=de,O=foo,OU=", 79 | "C=de,O=foo,OU= ", 80 | "C=,O=foo,OU=bar ", 81 | "C = ,O=foo,OU=bar ", 82 | "C=", 83 | NULL 84 | }; 85 | gpg_error_t err; 86 | int i; 87 | unsigned char *buf; 88 | size_t off, len; 89 | 90 | for (i=0; empty_elements[i]; i++) 91 | { 92 | err = ksba_dn_str2der (empty_elements[i], &buf, &len); 93 | if (gpg_err_code (err) != GPG_ERR_SYNTAX) 94 | fail ("empty element not detected"); 95 | err = ksba_dn_teststr (empty_elements[i], 0, &off, &len); 96 | if (!err) 97 | fail ("ksba_dn_teststr returned no error"); 98 | if (!quiet) 99 | printf ("string ->%s<- error at %lu.%lu (%.*s)\n", 100 | empty_elements[i], (unsigned long)off, (unsigned long)len, 101 | (int)len, empty_elements[i]+off); 102 | xfree (buf); 103 | } 104 | } 105 | 106 | static void 107 | test_2 (void) 108 | { 109 | static char *invalid_labels[] = { 110 | "C=de,FOO=something,O=bar", 111 | "Y=foo, C=baz", 112 | NULL 113 | }; 114 | gpg_error_t err; 115 | int i; 116 | unsigned char *buf; 117 | size_t off, len; 118 | 119 | for (i=0; invalid_labels[i]; i++) 120 | { 121 | err = ksba_dn_str2der (invalid_labels[i], &buf, &len); 122 | if (gpg_err_code (err) != GPG_ERR_UNKNOWN_NAME) 123 | fail ("invalid label not detected"); 124 | err = ksba_dn_teststr (invalid_labels[i], 0, &off, &len); 125 | if (!err) 126 | fail ("ksba_dn_test_str returned no error"); 127 | if (!quiet) 128 | printf ("string ->%s<- error at %lu.%lu (%.*s)\n", 129 | invalid_labels[i], (unsigned long)off, (unsigned long)len, 130 | (int)len, invalid_labels[i]+off); 131 | xfree (buf); 132 | } 133 | } 134 | 135 | 136 | 137 | int 138 | main (int argc, char **argv) 139 | { 140 | char inputbuf[4096]; 141 | unsigned char *buf; 142 | size_t len; 143 | gpg_error_t err; 144 | char *string; 145 | 146 | if (argc) 147 | { 148 | argc--; argv++; 149 | } 150 | if (argc && !strcmp (*argv, "--verbose")) 151 | { 152 | verbose = 1; 153 | argc--; argv++; 154 | } 155 | 156 | if (argc == 1 && !strcmp (argv[0], "--to-str") ) 157 | { /* Read the DER encoded DN from stdin write the string to stdout */ 158 | len = fread (inputbuf, 1, sizeof inputbuf, stdin); 159 | if (!feof (stdin)) 160 | fail ("read error or input too large"); 161 | 162 | err = ksba_dn_der2str (inputbuf, len, &string); 163 | fail_if_err (err); 164 | fputs (string, stdout); 165 | ksba_free (string); 166 | } 167 | else if (argc == 1 && !strcmp (argv[0], "--to-der") ) 168 | { /* Read the String from stdin write the DER encoding to stdout */ 169 | len = fread (inputbuf, 1, sizeof inputbuf, stdin); 170 | if (!feof (stdin)) 171 | fail ("read error or input too large"); 172 | 173 | err = ksba_dn_str2der (inputbuf, &buf, &len); 174 | fail_if_err (err); 175 | fwrite (buf, len, 1, stdout); 176 | } 177 | else if (!argc) 178 | { 179 | if (!verbose) 180 | quiet = 1; 181 | test_0 (); 182 | test_1 (); 183 | test_2 (); 184 | } 185 | else 186 | { 187 | fprintf (stderr, "usage: t-dnparser [--to-str|--to-der]\n"); 188 | return 1; 189 | } 190 | 191 | return 0; 192 | } 193 | -------------------------------------------------------------------------------- /src/asn1-func2.c: -------------------------------------------------------------------------------- 1 | /* asn1-func2.c - More ASN.1 definitions 2 | * Copyright (C) 2000, 2001 Fabio Fiorina 3 | * Copyright (C) 2001 Free Software Foundation, Inc. 4 | * Copyright (C) 2008, 2012 g10 Code GmbH 5 | * 6 | * This file is part of KSBA. 7 | * 8 | * KSBA is free software; you can redistribute it and/or modify 9 | * it under the terms of either 10 | * 11 | * - the GNU Lesser General Public License as published by the Free 12 | * Software Foundation; either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * or 16 | * 17 | * - the GNU General Public License as published by the Free 18 | * Software Foundation; either version 2 of the License, or (at 19 | * your option) any later version. 20 | * 21 | * or both in parallel, as here. 22 | * 23 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 24 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 25 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 26 | * License for more details. 27 | * 28 | * You should have received a copies of the GNU General Public License 29 | * and the GNU Lesser General Public License along with this program; 30 | * if not, see . 31 | */ 32 | 33 | /* 34 | This file has functions which rely on on the asn1-gentables created 35 | asn1-tables.c - we can't put this into asn1-func.c because this one 36 | is needed by asn1-gentables ;-) 37 | */ 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "util.h" 47 | #include "ksba.h" 48 | #include "asn1-func.h" 49 | 50 | 51 | static AsnNode 52 | set_right (AsnNode node, AsnNode right) 53 | { 54 | if (node == NULL) 55 | return node; 56 | 57 | node->right = right; 58 | if (right) 59 | right->left = node; 60 | return node; 61 | } 62 | 63 | 64 | static AsnNode 65 | set_down (AsnNode node, AsnNode down) 66 | { 67 | if (node == NULL) 68 | return node; 69 | 70 | node->down = down; 71 | if (down) 72 | down->left = node; 73 | return node; 74 | } 75 | 76 | 77 | static AsnNode 78 | find_up (AsnNode node) 79 | { 80 | AsnNode p; 81 | 82 | if (node == NULL) 83 | return NULL; 84 | 85 | p = node; 86 | while ((p->left != NULL) && (p->left->right == p)) 87 | p = p->left; 88 | 89 | return p->left; 90 | } 91 | 92 | 93 | 94 | 95 | /** 96 | * Creates the structures needed to manage the ASN1 definitions. ROOT is 97 | * a vector created by the asn1-gentable tool. 98 | * 99 | * Input Parameter: 100 | * 101 | * Name of the module 102 | * 103 | * Output Parameter: 104 | * 105 | * KsbaAsntree *result : return the pointer to an object to be used 106 | * with other functions. 107 | * 108 | * Return Value: 109 | * 0: structure created correctly. 110 | * GPG_ERR_GENERAL: an error occured while structure creation. 111 | * GPG_ERR_MODULE_NOT_FOUND: No such module NAME 112 | */ 113 | gpg_error_t 114 | ksba_asn_create_tree (const char *mod_name, ksba_asn_tree_t *result) 115 | { 116 | enum { DOWN, UP, RIGHT } move; 117 | const static_asn *root; 118 | const char *strgtbl; 119 | AsnNode pointer; 120 | AsnNode p = NULL; 121 | AsnNode p_last = NULL; 122 | unsigned long k; 123 | int rc; 124 | AsnNode link_next = NULL; 125 | 126 | if (!result) 127 | return gpg_error (GPG_ERR_INV_VALUE); 128 | *result = NULL; 129 | 130 | if (!mod_name) 131 | return gpg_error (GPG_ERR_INV_VALUE); 132 | root = _ksba_asn_lookup_table (mod_name, &strgtbl); 133 | if (!root) 134 | return gpg_error (GPG_ERR_MODULE_NOT_FOUND); 135 | 136 | pointer = NULL; 137 | move = UP; 138 | 139 | k = 0; 140 | while (root[k].stringvalue_off || root[k].type || root[k].name_off) 141 | { 142 | p = _ksba_asn_new_node (root[k].type); 143 | p->flags = root[k].flags; 144 | p->flags.help_down = 0; 145 | p->link_next = link_next; 146 | link_next = p; 147 | 148 | if (root[k].name_off) 149 | _ksba_asn_set_name (p, strgtbl + root[k].name_off); 150 | if (root[k].stringvalue_off) 151 | { 152 | if (root[k].type == TYPE_TAG) 153 | { 154 | unsigned long val; 155 | val = strtoul (strgtbl+root[k].stringvalue_off, NULL, 10); 156 | _ksba_asn_set_value (p, VALTYPE_ULONG, &val, sizeof(val)); 157 | } 158 | else 159 | _ksba_asn_set_value (p, VALTYPE_CSTR, 160 | strgtbl+root[k].stringvalue_off, 0); 161 | } 162 | 163 | if (!pointer) 164 | pointer = p; 165 | 166 | if (move == DOWN) 167 | set_down (p_last, p); 168 | else if (move == RIGHT) 169 | set_right (p_last, p); 170 | 171 | p_last = p; 172 | 173 | if (root[k].flags.help_down) 174 | move = DOWN; 175 | else if (root[k].flags.help_right) 176 | move = RIGHT; 177 | else 178 | { 179 | while (1) 180 | { 181 | if (p_last == pointer) 182 | break; 183 | 184 | p_last = find_up (p_last); 185 | 186 | if (p_last == NULL) 187 | break; 188 | 189 | if (p_last->flags.help_right) 190 | { 191 | p_last->flags.help_right = 0; 192 | move = RIGHT; 193 | break; 194 | } 195 | } 196 | } 197 | k++; 198 | } 199 | 200 | if (p_last == pointer) 201 | { 202 | ksba_asn_tree_t tree; 203 | 204 | _ksba_asn_change_integer_value (pointer); 205 | _ksba_asn_expand_object_id (pointer); 206 | tree = xtrymalloc (sizeof *tree + strlen (mod_name)); 207 | if (!tree) 208 | rc = gpg_error (GPG_ERR_ENOMEM); 209 | else 210 | { 211 | tree->parse_tree = pointer; 212 | tree->node_list = p; 213 | strcpy (tree->filename, mod_name); 214 | *result = tree; 215 | rc = 0; 216 | } 217 | } 218 | else 219 | rc = gpg_error (GPG_ERR_GENERAL); 220 | 221 | if (rc) 222 | _ksba_asn_delete_structure (pointer); 223 | 224 | return rc; 225 | } 226 | -------------------------------------------------------------------------------- /src/asn1-func.h: -------------------------------------------------------------------------------- 1 | /* asn1-func.h - definitions for asn1-func.c 2 | * Copyright (C) 2000,2001 Fabio Fiorina 3 | * Copyright (C) 2001 Free Software Foundation, Inc. 4 | * Copyright (C) 2002, 2003, 2006, 2007, 2010, 2012 g10 Code GmbH 5 | * 6 | * This file is part of KSBA. 7 | * 8 | * KSBA is free software; you can redistribute it and/or modify 9 | * it under the terms of either 10 | * 11 | * - the GNU Lesser General Public License as published by the Free 12 | * Software Foundation; either version 3 of the License, or (at 13 | * your option) any later version. 14 | * 15 | * or 16 | * 17 | * - the GNU General Public License as published by the Free 18 | * Software Foundation; either version 2 of the License, or (at 19 | * your option) any later version. 20 | * 21 | * or both in parallel, as here. 22 | * 23 | * KSBA is distributed in the hope that it will be useful, but WITHOUT 24 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 25 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 26 | * License for more details. 27 | * 28 | * You should have received a copies of the GNU General Public License 29 | * and the GNU Lesser General Public License along with this program; 30 | * if not, see . 31 | */ 32 | 33 | #ifndef ASN1_FUNC_H 34 | #define ASN1_FUNC_H 35 | 36 | #include "asn1-constants.h" 37 | 38 | /* Important: this must match the code in asn1-gentables.c */ 39 | struct node_flag_s { 40 | enum tag_class class; 41 | unsigned int explicit:1; 42 | unsigned int implicit:1; 43 | unsigned int has_imports:1; 44 | unsigned int assignment:1; /* node is an assignment */ 45 | unsigned int one_param:1; 46 | unsigned int has_tag:1; 47 | unsigned int has_size:1; 48 | unsigned int has_list:1; 49 | unsigned int has_min_max:1; 50 | unsigned int has_defined_by:1; 51 | unsigned int is_false:1; 52 | unsigned int is_true:1; 53 | unsigned int has_default:1; /* node has a default value (fixme:needed???)*/ 54 | unsigned int is_optional:1; 55 | unsigned int is_implicit:1; 56 | unsigned int in_set:1; 57 | unsigned int in_choice:1; 58 | unsigned int in_array:1; 59 | unsigned int is_any:1; /* The der-encoder must change any to a real type 60 | but still be aware that it actually is any */ 61 | unsigned int not_used:1; 62 | unsigned int help_down:1; /* helper for create_tree */ 63 | unsigned int help_right:1; /* helper for create_tree */ 64 | unsigned int tag_seen:1; 65 | unsigned int skip_this:1; /* helper */ 66 | }; 67 | 68 | enum asn_value_type { 69 | VALTYPE_NULL = 0, 70 | VALTYPE_BOOL, 71 | VALTYPE_CSTR, 72 | VALTYPE_MEM, 73 | VALTYPE_LONG, 74 | VALTYPE_ULONG 75 | }; 76 | 77 | union asn_value_u { 78 | int v_bool; 79 | char *v_cstr; 80 | struct { 81 | size_t len; 82 | unsigned char *buf; 83 | } v_mem; 84 | long v_long; 85 | unsigned long v_ulong; 86 | }; 87 | 88 | 89 | /* 90 | * Structure definition used for the node of the tree that represents 91 | * an ASN.1 DEFINITION. 92 | */ 93 | #ifndef HAVE_TYPEDEFD_ASNNODE 94 | typedef struct asn_node_struct *AsnNode; 95 | typedef struct asn_node_struct *asn_node_t; 96 | #define HAVE_TYPEDEFD_ASNNODE 97 | #endif 98 | struct asn_node_struct { 99 | char *name; /* Node name */ 100 | node_type_t type; 101 | struct node_flag_s flags; 102 | 103 | enum asn_value_type valuetype; 104 | union asn_value_u value; 105 | int off; /* offset of this TLV */ 106 | int nhdr; /* length of the header */ 107 | int len; /* length part of the TLV */ 108 | node_type_t actual_type; /* ugly helper to overcome TYPE_ANY probs*/ 109 | 110 | AsnNode down; /* Pointer to the son node */ 111 | AsnNode right; /* Pointer to the brother node */ 112 | AsnNode left; /* Pointer to the next list element */ 113 | AsnNode link_next; /* to keep track of all nodes in a tree */ 114 | }; 115 | 116 | /* Structure to keep an entire ASN.1 parse tree and associated information */ 117 | struct ksba_asn_tree_s { 118 | AsnNode parse_tree; 119 | AsnNode node_list; /* for easier release of all nodes */ 120 | char filename[1]; 121 | }; 122 | 123 | 124 | typedef struct static_struct_asn { 125 | unsigned int name_off; /* Node name */ 126 | node_type_t type; /* Node type */ 127 | struct node_flag_s flags; 128 | unsigned int stringvalue_off; 129 | } static_asn; 130 | 131 | 132 | /*-- asn1-parse.y --*/ 133 | void _ksba_asn_release_nodes (AsnNode node); 134 | 135 | 136 | /*-- asn1-func.c --*/ 137 | void _ksba_asn_set_value (AsnNode node, enum asn_value_type vtype, 138 | const void *value, size_t len); 139 | void _ksba_asn_set_name (AsnNode node, const char *name); 140 | AsnNode _ksba_asn_walk_tree (AsnNode root, AsnNode node); 141 | AsnNode _ksba_asn_walk_tree_up_right (AsnNode root, AsnNode node); 142 | AsnNode _ksba_asn_find_node(AsnNode pointer,const char *name); 143 | int _ksba_asn_check_identifier(AsnNode node); 144 | int _ksba_asn_change_integer_value(AsnNode node); 145 | int _ksba_asn_delete_not_used(AsnNode node); 146 | int _ksba_asn_expand_object_id(AsnNode node); 147 | void _ksba_asn_set_default_tag (AsnNode node); 148 | void _ksba_asn_type_set_config (AsnNode node); 149 | AsnNode _ksba_asn_expand_tree (AsnNode parse_tree, const char *name); 150 | AsnNode _ksba_asn_insert_copy (AsnNode node); 151 | 152 | int _ksba_asn_is_primitive (node_type_t type); 153 | AsnNode _ksba_asn_new_node (node_type_t type); 154 | void _ksba_asn_node_dump (AsnNode p, FILE *fp); 155 | void _ksba_asn_node_dump_all (AsnNode root, FILE *fp); 156 | 157 | AsnNode _ksba_asn_find_type_value (const unsigned char *image, 158 | AsnNode root, int idx, 159 | const void *oidbuf, size_t oidlen); 160 | 161 | 162 | int _ksba_asn_delete_structure (AsnNode root); 163 | 164 | /*-- asn2-func.c --*/ 165 | /*(functions are all declared in ksba.h)*/ 166 | 167 | /*-- asn1-tables.c (generated) --*/ 168 | const static_asn *_ksba_asn_lookup_table (const char *name, 169 | const char **stringtbl); 170 | 171 | 172 | 173 | #endif /*ASN1_FUNC_H*/ 174 | -------------------------------------------------------------------------------- /m4/lt~obsolete.m4: -------------------------------------------------------------------------------- 1 | # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004. 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 5 lt~obsolete.m4 11 | 12 | # These exist entirely to fool aclocal when bootstrapping libtool. 13 | # 14 | # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN) 15 | # which have later been changed to m4_define as they aren't part of the 16 | # exported API, or moved to Autoconf or Automake where they belong. 17 | # 18 | # The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN 19 | # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us 20 | # using a macro with the same name in our local m4/libtool.m4 it'll 21 | # pull the old libtool.m4 in (it doesn't see our shiny new m4_define 22 | # and doesn't know about Autoconf macros at all.) 23 | # 24 | # So we provide this file, which has a silly filename so it's always 25 | # included after everything else. This provides aclocal with the 26 | # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything 27 | # because those macros already exist, or will be overwritten later. 28 | # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 29 | # 30 | # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. 31 | # Yes, that means every name once taken will need to remain here until 32 | # we give up compatibility with versions before 1.7, at which point 33 | # we need to keep only those names which we still refer to. 34 | 35 | # This is to help aclocal find these macros, as it can't see m4_define. 36 | AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) 37 | 38 | m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) 39 | m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) 40 | m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) 41 | m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) 42 | m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) 43 | m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) 44 | m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) 45 | m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) 46 | m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) 47 | m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) 48 | m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) 49 | m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) 50 | m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) 51 | m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) 52 | m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) 53 | m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) 54 | m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) 55 | m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) 56 | m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) 57 | m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) 58 | m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) 59 | m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) 60 | m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) 61 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) 62 | m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) 63 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) 64 | m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) 65 | m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) 66 | m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) 67 | m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) 68 | m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) 69 | m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) 70 | m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) 71 | m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) 72 | m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) 73 | m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) 74 | m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) 75 | m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) 76 | m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) 77 | m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) 78 | m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) 79 | m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) 80 | m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) 81 | m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) 82 | m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) 83 | m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) 84 | m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) 85 | m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) 86 | m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) 87 | m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) 88 | m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) 89 | m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) 90 | m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) 91 | m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) 92 | m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])]) 93 | m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])]) 94 | m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])]) 95 | m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])]) 96 | m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])]) 97 | m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])]) 98 | m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])]) 99 | -------------------------------------------------------------------------------- /tests/t-common.h: -------------------------------------------------------------------------------- 1 | /* t-common.h - Common functions for the tests. 2 | * Copyright (C) 2002, 2003 g10 Code GmbH 3 | * 4 | * This file is part of KSBA. 5 | * 6 | * KSBA is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * KSBA is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | /*-- sha1.c --*/ 21 | void sha1_hash_buffer (char *outbuf, const char *buffer, size_t length); 22 | void sha256_hash_buffer (char *outbuf, const char *buffer, size_t length); 23 | 24 | 25 | 26 | #define digitp(p) (*(p) >= '0' && *(p) <= '9') 27 | 28 | #define fail_if_err(a) do { if(a) { \ 29 | fprintf (stderr, "%s:%d: KSBA error: %s\n", \ 30 | __FILE__, __LINE__, gpg_strerror(a)); \ 31 | exit (1); } \ 32 | } while(0) 33 | 34 | 35 | #define fail_if_err2(f, a) do { if(a) {\ 36 | fprintf (stderr, "%s:%d: KSBA error on file `%s': %s\n", \ 37 | __FILE__, __LINE__, (f), gpg_strerror(a)); \ 38 | exit (1); } \ 39 | } while(0) 40 | 41 | #define fail(s) do { fprintf (stderr, "%s:%d: %s\n", __FILE__,__LINE__, (s));\ 42 | exit (1); } while(0) 43 | 44 | #define xfree(a) ksba_free (a) 45 | 46 | 47 | void * 48 | xmalloc (size_t n) 49 | { 50 | char *p = ksba_malloc (n); 51 | if (!p) 52 | { 53 | fprintf (stderr, "out of core\n"); 54 | exit (1); 55 | } 56 | return p; 57 | } 58 | 59 | 60 | /* Prepend FNAME with the srcdir environment variable's value and 61 | retrun an allocated filename. */ 62 | char * 63 | prepend_srcdir (const char *fname) 64 | { 65 | static const char *srcdir; 66 | char *result; 67 | 68 | if (!srcdir) 69 | if(!(srcdir = getenv ("srcdir"))) 70 | srcdir = "."; 71 | 72 | result = xmalloc (strlen (srcdir) + 1 + strlen (fname) + 1); 73 | strcpy (result, srcdir); 74 | strcat (result, "/"); 75 | strcat (result, fname); 76 | return result; 77 | } 78 | 79 | 80 | 81 | void 82 | print_hex (const unsigned char *p, size_t n) 83 | { 84 | if (!p) 85 | fputs ("none", stdout); 86 | else 87 | { 88 | for (; n; n--, p++) 89 | printf ("%02X", *p); 90 | } 91 | } 92 | 93 | 94 | void 95 | print_sexp (ksba_const_sexp_t p) 96 | { 97 | int level = 0; 98 | 99 | if (!p) 100 | fputs ("[none]", stdout); 101 | else 102 | { 103 | for (;;) 104 | { 105 | if (*p == '(') 106 | { 107 | putchar (*p); 108 | p++; 109 | level++; 110 | } 111 | else if (*p == ')') 112 | { 113 | putchar (*p); 114 | p++; 115 | if (--level <= 0 ) 116 | return; 117 | } 118 | else if (!digitp (p)) 119 | { 120 | fputs ("[invalid s-exp]", stdout); 121 | return; 122 | } 123 | else 124 | { 125 | char *endp; 126 | const unsigned char *s; 127 | unsigned long len, n; 128 | 129 | len = strtoul (p, &endp, 10); 130 | p = endp; 131 | if (*p != ':') 132 | { 133 | fputs ("[invalid s-exp]", stdout); 134 | return; 135 | } 136 | p++; 137 | for (s=p,n=0; n < len; n++, s++) 138 | if ( !((*s >= 'a' && *s <= 'z') 139 | || (*s >= 'A' && *s <= 'Z') 140 | || (*s >= '0' && *s <= '9') 141 | || *s == '-' || *s == '.')) 142 | break; 143 | if (n < len) 144 | { 145 | putchar('#'); 146 | for (n=0; n < len; n++, p++) 147 | printf ("%02X", *p); 148 | putchar('#'); 149 | } 150 | else 151 | { 152 | for (n=0; n < len; n++, p++) 153 | putchar (*p); 154 | } 155 | } 156 | } 157 | } 158 | } 159 | 160 | /* Variant of print_sexp which forces printing the values in hex. */ 161 | void 162 | print_sexp_hex (ksba_const_sexp_t p) 163 | { 164 | int level = 0; 165 | 166 | if (!p) 167 | fputs ("[none]", stdout); 168 | else 169 | { 170 | for (;;) 171 | { 172 | if (*p == '(') 173 | { 174 | putchar (*p); 175 | p++; 176 | level++; 177 | } 178 | else if (*p == ')') 179 | { 180 | putchar (*p); 181 | p++; 182 | if (--level <= 0 ) 183 | return; 184 | } 185 | else if (!digitp (p)) 186 | { 187 | fputs ("[invalid s-exp]", stdout); 188 | return; 189 | } 190 | else 191 | { 192 | char *endp; 193 | unsigned long len, n; 194 | 195 | len = strtoul (p, &endp, 10); 196 | p = endp; 197 | if (*p != ':') 198 | { 199 | fputs ("[invalid s-exp]", stdout); 200 | return; 201 | } 202 | p++; 203 | putchar('#'); 204 | for (n=0; n < len; n++, p++) 205 | printf ("%02X", *p); 206 | putchar('#'); 207 | } 208 | } 209 | } 210 | } 211 | 212 | 213 | void 214 | print_dn (char *p) 215 | { 216 | if (!p) 217 | fputs ("error", stdout); 218 | else 219 | printf ("`%s'", p); 220 | } 221 | 222 | 223 | void 224 | print_time (ksba_isotime_t t) 225 | { 226 | if (!t || !*t) 227 | fputs ("none", stdout); 228 | else 229 | printf ("%.4s-%.2s-%.2s %.2s:%.2s:%s", t, t+4, t+6, t+9, t+11, t+13); 230 | } 231 | --------------------------------------------------------------------------------