From 887340c04dea4e9b6552ee57467783bec667c11a Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Fri, 18 Jan 2019 16:12:38 +0100 Subject: [PATCH] Generalized fuzzing script --- tests/Makefile.am | 1 + tests/test-fuzzing-pkcs15-tool-dump.sh | 33 ----------------- tests/test-fuzzing.sh | 51 ++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 33 deletions(-) delete mode 100644 tests/test-fuzzing-pkcs15-tool-dump.sh create mode 100755 tests/test-fuzzing.sh diff --git a/tests/Makefile.am b/tests/Makefile.am index e88620a0..66323e9d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,7 @@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in dist_noinst_SCRIPTS = test-manpage.sh \ + test-fuzzing.sh \ test-pkcs11-tool-sign-verify.sh TESTS = test-manpage.sh \ diff --git a/tests/test-fuzzing-pkcs15-tool-dump.sh b/tests/test-fuzzing-pkcs15-tool-dump.sh deleted file mode 100644 index 574c7f2c..00000000 --- a/tests/test-fuzzing-pkcs15-tool-dump.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -if [ ! -d x41-smartcard-fuzzing ]; -then - git clone https://github.com/x41sec/x41-smartcard-fuzzing -fi - -gcc -shared -fPIC -o x41-smartcard-fuzzing/scard_override/libsccard_override.so x41-smartcard-fuzzing/scard_override/scard_override.c -ldl -I/usr/include/PCSC/ - -if [ ! -f configure ]; -then - autoreconf -vis -fi - -if [ ! -f Makefile ]; -then - make clean -fi - -#export AFL_USE_ASAN=1 -./configure CC=afl-gcc CFLAGS="-O0" LDFLAGS="-ldl" --disable-shared --disable-notify --with-pcsc-provider=$PWD/x41-smartcard-fuzzing/scard_override/libsccard_override.so -make - -if [ ! -d tests/fuzzing-testcases ] -then - mkdir -p tests/fuzzing-testcases - echo -ne "$(printf '\\x90\\x00')" > tests/fuzzing-testcases/9000 - IN=tests/fuzzing-testcases -else - IN=- -fi - -FUZZ_FILE=input.apdu afl-fuzz -i $IN -o out -f input.apdu src/tools/pkcs15-tool -D diff --git a/tests/test-fuzzing.sh b/tests/test-fuzzing.sh new file mode 100755 index 00000000..2f24f57c --- /dev/null +++ b/tests/test-fuzzing.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +set -ex + +case "$1" in + "pkcs11-tool") + CMD="src/tools/pkcs11-tool --test --login --pin 123456" + ;; + "pkcs15-tool") + CMD="src/tools/pkcs15-tool --dump" + ;; + "eidenv") + CMD="src/tools/eidenv" + ;; + *) + echo "Unknown fuzzing target" + exit 1 + ;; +esac + +IN=tests/fuzzing-testcases +if [ ! -d "$IN" ] +then + mkdir -p "$IN" + echo -ne "$(printf '\\x90\\x00')" > "$IN"/9000 +fi + +# reuse output directory if possible +OUT="out-$1" +if [ -d "$OUT" ] +then + IN=- +fi + +if [ ! -d x41-smartcard-fuzzing ]; +then + git clone https://github.com/x41sec/x41-smartcard-fuzzing +fi + +gcc -shared -fPIC -o x41-smartcard-fuzzing/scard_override/libsccard_override.so x41-smartcard-fuzzing/scard_override/scard_override.c -ldl -I/usr/include/PCSC/ + +if [ ! -f configure ]; +then + autoreconf -vis +fi + +#export AFL_USE_ASAN=1 +./configure CC=afl-gcc CFLAGS="-O0" --disable-shared --disable-notify --with-pcsc-provider=$PWD/x41-smartcard-fuzzing/scard_override/libsccard_override.so +make + +FUZZ_FILE=input.apdu afl-fuzz -i "$IN" -o "$OUT" -f input.apdu $CMD