diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2016-11-14 14:26:58 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2016-11-14 17:19:52 +0100 |
commit | e02c2254b7de50c6d00192a516b543919c437fa0 (patch) | |
tree | 9dbe21bf81a5bf539fe7f8cd9b98bc5cf8227638 | |
parent | 290b1586daac15c7c07c105a4969f25b5f4ff426 (diff) | |
download | gnutls-tmp-afl.tar.gz |
tests: added a PKCS#8 encrypted key parsing test suite based on AFL [ci skip]tmp-afl
Relates #148
-rw-r--r-- | tests/suite/afl/Makefile.am | 8 | ||||
-rw-r--r-- | tests/suite/afl/afl-pkcs8-decode.c | 82 | ||||
-rw-r--r-- | tests/suite/afl/afl-pkcs8.in/key1.der | bin | 0 -> 735 bytes | |||
-rw-r--r-- | tests/suite/afl/afl-pkcs8.in/key2.der | bin | 0 -> 678 bytes | |||
-rw-r--r-- | tests/suite/afl/afl-pkcs8.in/key3.der | bin | 0 -> 724 bytes | |||
-rw-r--r-- | tests/suite/afl/afl-pkcs8.in/key4.der | bin | 0 -> 674 bytes | |||
-rwxr-xr-x | tests/suite/afl/afl-pkcs8.sh | 29 |
7 files changed, 116 insertions, 3 deletions
diff --git a/tests/suite/afl/Makefile.am b/tests/suite/afl/Makefile.am index 6e9030c522..ca66b4b2bf 100644 --- a/tests/suite/afl/Makefile.am +++ b/tests/suite/afl/Makefile.am @@ -20,7 +20,9 @@ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. EXTRA_DIST = afl-dn.in/dn1.der afl-dn.in/dn2.der afl-dn.in/dn3.der afl-dn.in/dn4.der \ - afl-cert.in/cert1.der af-cert.in/cert2.der af-cert.in/cert3.der + afl-cert.in/cert1.der af-cert.in/cert2.der af-cert.in/cert3.der \ + afl-pkcs8.in/key1.der afl-pkcs8.in/key2.der afl-pkcs8.in/key3.der \ + afl-pkcs8.in/key4.der AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS) AM_CPPFLAGS = \ @@ -38,7 +40,7 @@ LDADD = ../../../lib/libgnutls.la \ ../../../gl/libgnu.la \ $(LIBSOCKET) $(INET_NTOP_LIB) $(INET_PTON_LIB) -noinst_SCRIPTS = afl-dn.sh afl-cert.sh +noinst_SCRIPTS = afl-dn.sh afl-cert.sh afl-pkcs8.sh -noinst_PROGRAMS = afl-dn-decode afl-cert-decode +noinst_PROGRAMS = afl-dn-decode afl-cert-decode afl-pkcs8-decode diff --git a/tests/suite/afl/afl-pkcs8-decode.c b/tests/suite/afl/afl-pkcs8-decode.c new file mode 100644 index 0000000000..2eebda5f63 --- /dev/null +++ b/tests/suite/afl/afl-pkcs8-decode.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2016 Red Hat, Inc. + * + * Author: Nikos Mavrogiannopoulos + * + * This file is part of GnuTLS. + * + * GnuTLS is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GnuTLS is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GnuTLS; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* This checks the low level DN encoding and decoding routines */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> + +#include <string.h> +#include <gnutls/gnutls.h> +#include <gnutls/abstract.h> + +static void decode(const gnutls_datum_t *raw) +{ + int ret; + gnutls_datum_t out; + gnutls_x509_privkey_t key; + + ret = gnutls_x509_privkey_init(&key); + if (ret < 0) { + fprintf(stderr, "%s\n", gnutls_strerror(ret)); + return; + } + + ret = gnutls_x509_privkey_import_pkcs8(key, raw, GNUTLS_X509_FMT_DER, "1234", 0); + if (ret < 0) { + fprintf(stderr, "%s\n", gnutls_strerror(ret)); + return; + } + + ret = gnutls_x509_privkey_export2(key, GNUTLS_X509_FMT_DER, &out); + if (ret < 0) { + fprintf(stderr, "%s\n", gnutls_strerror(ret)); + return; + } + + gnutls_free(out.data); + gnutls_x509_privkey_deinit(key); + + return; +} + +int main(int argc, char **argv) +{ + int ret; + unsigned char buf[64*1024]; + gnutls_datum_t raw; + + ret = fread(buf, 1, sizeof(buf), stdin); + if (ret <= 0) + return 0; + + raw.data = buf; + raw.size = ret; + decode(&raw); + + return 0; +} + diff --git a/tests/suite/afl/afl-pkcs8.in/key1.der b/tests/suite/afl/afl-pkcs8.in/key1.der Binary files differnew file mode 100644 index 0000000000..4babed5dd4 --- /dev/null +++ b/tests/suite/afl/afl-pkcs8.in/key1.der diff --git a/tests/suite/afl/afl-pkcs8.in/key2.der b/tests/suite/afl/afl-pkcs8.in/key2.der Binary files differnew file mode 100644 index 0000000000..726ed0fdfb --- /dev/null +++ b/tests/suite/afl/afl-pkcs8.in/key2.der diff --git a/tests/suite/afl/afl-pkcs8.in/key3.der b/tests/suite/afl/afl-pkcs8.in/key3.der Binary files differnew file mode 100644 index 0000000000..436a0cea8c --- /dev/null +++ b/tests/suite/afl/afl-pkcs8.in/key3.der diff --git a/tests/suite/afl/afl-pkcs8.in/key4.der b/tests/suite/afl/afl-pkcs8.in/key4.der Binary files differnew file mode 100644 index 0000000000..d2be2f5463 --- /dev/null +++ b/tests/suite/afl/afl-pkcs8.in/key4.der diff --git a/tests/suite/afl/afl-pkcs8.sh b/tests/suite/afl/afl-pkcs8.sh new file mode 100755 index 0000000000..ffd78aec6c --- /dev/null +++ b/tests/suite/afl/afl-pkcs8.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# Copyright (C) 2015-2016 Red Hat, Inc. +# +# This file is part of GnuTLS. +# +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this file; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +srcdir="${srcdir:-.}" +INNAME=afl-pkcs8.in +OUTNAME=afl-pkcs8.out + +export LD_LIBRARY_PATH=${srcdir}/../../../lib/.libs/ +rm -rf $OUTNAME +mkdir -p $OUTNAME +afl-fuzz -i $INNAME -o $OUTNAME -- .libs/afl-pkcs8-decode + +exit $? |