Skip to content

Commit

Permalink
A test shim in testing that removes randomness
Browse files Browse the repository at this point in the history
This means that added caveats will be deterministic, and thus testable, without
having to alter the underlying code.
  • Loading branch information
rescrv committed Mar 3, 2016
1 parent 1558d06 commit 42f4a88
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
10 changes: 8 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 ####################################

Expand Down
2 changes: 1 addition & 1 deletion port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
43 changes: 43 additions & 0 deletions shim.c
Original file line number Diff line number Diff line change
@@ -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 <stdlib.h>

/* sodium */
#include <sodium/utils.h>

__attribute__ ((visibility ("default")))
void randombytes_buf(void * const buf, const size_t size)
{
sodium_memzero(buf, size);
}
1 change: 1 addition & 0 deletions test/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit 42f4a88

Please sign in to comment.