From 42f4a88ed1cb505550d1b26334ad1677024694f5 Mon Sep 17 00:00:00 2001 From: Robert Escriva Date: Thu, 3 Mar 2016 10:16:48 -0500 Subject: [PATCH] A test shim in testing that removes randomness This means that added caveats will be deterministic, and thus testable, without having to alter the underlying code. --- Makefile.am | 10 ++++++++-- port.c | 2 +- shim.c | 43 +++++++++++++++++++++++++++++++++++++++++++ test/env.sh | 1 + 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 shim.c diff --git a/Makefile.am b/Makefile.am index 578dbd5..4d7cdb5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (c) 2014, Robert Escriva +# Copyright (c) 2014-2016, Robert Escriva # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -65,9 +65,15 @@ EXTRA_DIST += test/python-hmac-sanity-check EXTRA_DIST += test/python-hmac-sanity-check.sh EXTRA_DIST += test/readme.sh +check_LTLIBRARIES = libmacaroons-shim.la + +libmacaroons_shim_la_SOURCES = shim.c +libmacaroons_shim_la_LIBADD = $(SODIUM_LIBS) +libmacaroons_shim_la_LDFLAGS = -module -avoid-version -rpath /evil/libtool/hack/to/force/shared/lib/creation + TESTS = TESTS += test/python-hmac-sanity-check.sh -#TESTS += test/readme.sh +TESTS += test/readme.sh #################################### Python #################################### diff --git a/port.c b/port.c index 4fef7fa..138682a 100644 --- a/port.c +++ b/port.c @@ -126,7 +126,7 @@ macaroon_secretbox_open(const unsigned char* enc_key, void macaroon_bin2hex(const unsigned char* bin, size_t bin_sz, char* hex) { - void* ptr = sodium_bin2hex(hex, bin_sz * 2, bin, bin_sz); + void* ptr = sodium_bin2hex(hex, bin_sz * 2 + 1, bin, bin_sz); assert(ptr == hex); } diff --git a/shim.c b/shim.c new file mode 100644 index 0000000..95cb9af --- /dev/null +++ b/shim.c @@ -0,0 +1,43 @@ +/* Copyright (c) 2016, Robert Escriva + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of this project nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* C */ +#include + +/* sodium */ +#include + +__attribute__ ((visibility ("default"))) +void randombytes_buf(void * const buf, const size_t size) +{ + sodium_memzero(buf, size); +} diff --git a/test/env.sh b/test/env.sh index 2b47c5d..3264020 100644 --- a/test/env.sh +++ b/test/env.sh @@ -2,4 +2,5 @@ export MACAROONS_SRCDIR="$1" export MACAROONS_BUILDDIR="$2" export MACAROONS_VERSION="$3" +export LD_PRELOAD="${MACAROONS_BUILDDIR}/.libs/libmacaroons-shim.so" export PYTHONPATH="${MACAROONS_BUILDDIR}"/bindings/python/.libs:${PYTHONPATH}