diff --git a/Makefile b/Makefile
index ab09c1807e57387a9e8a884a7da5f628a6d5270a..ad004827a73a80861706aca4498c2986d8eeda7a 100644
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,7 @@ endif
 
 # Dependencies
 $(eval $(call find_lib,libknot))
+$(eval $(call find_lib,libknot-int))
 $(eval $(call find_lib,libuv))
 $(eval $(call find_lib,cmocka))
 $(eval $(call find_python))
@@ -24,4 +25,4 @@ CFLAGS += $(libknot_CFLAGS) $(libuv_CFLAGS) $(cmocka_CFLAGS) $(python_CFLAGS)
 include help.mk
 include lib/libkresolve.mk
 include daemon/kresolved.mk
-include tests/tests.mk
\ No newline at end of file
+include tests/tests.mk
diff --git a/help.mk b/help.mk
index 11cece62589603e9e430fc621b4d82e15f994f20..34c89aaaf24765d43879148f996d589fef394866 100644
--- a/help.mk
+++ b/help.mk
@@ -1,9 +1,8 @@
 info:
 	$(info )
 	$(info Target:     Knot DNS Resolver $(MAJOR).$(MINOR)-$(PLATFORM))
-	$(info Compiler:   $(CC))
-	$(info CFLAGS:     $(CFLAGS))
-	$(info LDFLAGS:    $(LDFLAGS))
+	$(info Compiler:   $(CC) $(CFLAGS))
+	$(info Linker:     $(LD) $(LDFLAGS))
 	$(info PREFIX:     $(PREFIX))
 	$(info BINDIR:     $(BINDIR))
 	$(info LIBDIR:     $(LIBDIR))
@@ -12,7 +11,8 @@ info:
 	$(info Features)
 	$(info --------)
 	$(info [$(HAS_libknot)] library (libknot))
+	$(info [$(HAS_libknot-int)] library (libknot-int))
 	$(info [$(HAS_libuv)] daemon (libuv))
 	$(info [$(HAS_cmocka)] unit tests (libcmocka))
 	$(info [$(HAS_python)] integration tests (libpython))
-	$(info )
\ No newline at end of file
+	$(info )
diff --git a/lib/cache.c b/lib/cache.c
index 1c2ef64e03f85a81f92c68c474d3c8026b45ee49..2ce91795c674d2be0f39cebcb5e632f7776dcf92 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -22,7 +22,6 @@
 
 #include <libknot/internal/mempattern.h>
 #include <libknot/internal/namedb/namedb_lmdb.h>
-#include <libknot/dnssec/random.h>
 #include <libknot/errcode.h>
 #include <libknot/descriptor.h>
 
diff --git a/lib/layer/iterate.c b/lib/layer/iterate.c
index 19c5434d6289f277f394a3cd9b217bc9d640893e..e839a2f4b495182b353dd3052f6a17fb56ca6b26 100644
--- a/lib/layer/iterate.c
+++ b/lib/layer/iterate.c
@@ -19,7 +19,7 @@
 #include <libknot/descriptor.h>
 #include <libknot/rrtype/rdname.h>
 #include <libknot/processing/requestor.h>
-#include <libknot/dnssec/random.h>
+#include <dnssec/random.h>
 
 #include "lib/layer/iterate.h"
 #include "lib/resolve.h"
@@ -287,7 +287,7 @@ static int prepare_query(knot_layer_t *ctx, knot_pkt_t *pkt)
 		return KNOT_NS_PROC_FAIL;
 	}
 
-	query->id = knot_random_uint16_t();
+	query->id = dnssec_random_uint16_t();
 	knot_wire_set_id(pkt->wire, query->id);
 	
 	/* Declare EDNS0 support. */
diff --git a/lib/resolve.c b/lib/resolve.c
index d6e8f761bbbd38133cd2953b39bc667d2a859fdc..a81171f10c34b0add705b4effb284530e61d33d3 100755
--- a/lib/resolve.c
+++ b/lib/resolve.c
@@ -19,7 +19,7 @@
 #include <libknot/internal/mempool.h>
 #include <libknot/processing/requestor.h>
 #include <libknot/descriptor.h>
-#include <libknot/dnssec/random.h>
+#include <dnssec/random.h>
 
 #include "lib/resolve.h"
 #include "lib/defines.h"
diff --git a/lib/zonecut.c b/lib/zonecut.c
index ae12857faf70e360b7417aeda0604e5d1970695c..0b0befa456ab3fc65708ecf638cd1795532b1099 100644
--- a/lib/zonecut.c
+++ b/lib/zonecut.c
@@ -14,7 +14,7 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <libknot/dnssec/random.h>
+#include <dnssec/random.h>
 #include <libknot/descriptor.h>
 #include <libknot/rrtype/rdname.h>
 #include <libknot/packet/wire.h>
@@ -62,7 +62,7 @@ int kr_init_zone_cut(struct kr_zonecut *cut)
 		return KNOT_EINVAL;
 	}
 
-	const unsigned hint_id = knot_random_uint16_t() % HINT_COUNT;
+	const unsigned hint_id = dnssec_random_uint16_t() % HINT_COUNT;
 	const struct hint_info *hint = &SBELT[hint_id];
 
 	kr_set_zone_cut(cut, KR_DNAME_ROOT, hint->name);
diff --git a/scripts/Dockerfile b/scripts/Dockerfile
index 44d9ac0fcdff0c8f088eda932ac21f77da849aec..dbbe4d2539c3af10b5df162267edcaab182c78fb 100644
--- a/scripts/Dockerfile
+++ b/scripts/Dockerfile
@@ -3,8 +3,8 @@ MAINTAINER Marek Vavrusa <marek.vavrusa@nic.cz>
 
 # Environment
 ENV THREADS 4
-ENV BUILD_PKGS git-core make gcc libtool autoconf pkg-config libcmocka-dev libssl-dev liblmdb-dev
-ENV RUNTIME_PKGS libssl1.0.0 liblmdb0
+ENV BUILD_PKGS git-core make gcc libtool autoconf pkg-config libcmocka-dev libgnutls28-dev liblmdb-dev libjansson-dev
+ENV RUNTIME_PKGS libgnutls28 libjansson liblmdb0
 
 # Expose port
 EXPOSE 53
diff --git a/scripts/bootstrap-depends.sh b/scripts/bootstrap-depends.sh
index 8e5b9f919e2db5c1f86c929f69a81554db47a930..ae3c5d30a352b0f71d974ddb8558f25219dc8d53 100755
--- a/scripts/bootstrap-depends.sh
+++ b/scripts/bootstrap-depends.sh
@@ -2,74 +2,94 @@
 set -e
 
 CMOCKA_TAG="cmocka-0.4.1"
-URCU_TAG="v0.8.6"
+CMOCKA_URL="git://git.cryptomilk.org/projects/cmocka.git"
 LIBUV_TAG="v1.3.0"
+LIBUV_URL="https://github.com/libuv/libuv.git"
 KNOT_TAG="master"
+KNOT_URL="https://github.com/CZNIC-Labs/knot.git"
+GMP_TAG="6.0.0"
+GMP_URL="https://gmplib.org/download/gmp/gmp-${GMP_TAG}.tar.xz"
+JANSSON_TAG="2.7"
+JANSSON_URL="http://www.digip.org/jansson/releases/jansson-${JANSSON_TAG}.tar.gz"
+NETTLE_TAG="2.7.1"
+NETTLE_URL="https://ftp.gnu.org/gnu/nettle/nettle-${NETTLE_TAG}.tar.gz"
+GNUTLS_TAG="3.3.12"
+GNUTLS_URL="ftp://ftp.gnutls.org/gcrypt/gnutls/v3.3/gnutls-${GNUTLS_TAG}.tar.xz"
 
-# prepare build env
-PREFIX=${1}; [ -z ${PREFIX} ] && PREFIX="${HOME}/.local"
-PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
+# prepare install prefix
+PREFIX=${1}; [ -z ${PREFIX} ] && export PREFIX="${HOME}/.local"
 install -d ${PREFIX}/{lib,libexec,include,bin,sbin,man,share,etc,info,doc,var}
-[ ! -d .depend ] && mkdir .depend; cd .depend
 
-# platform-specific
-DEPEND_CACHE="https://dl.dropboxusercontent.com/u/2255176/resolver-${TRAVIS_OS_NAME}-cache.tgz"
-PIP_PKGS="${TRAVIS_BUILD_DIR}/tests/pydnstest/requirements.txt cpp-coveralls"
-if [ "${TRAVIS_OS_NAME}" == "osx" ]; then
-	if curl "${DEPEND_CACHE}" > cache.tgz; then
-		echo "extracting prebuilt dependencies from ${DEPEND_CACHE}"
-		tar -xz -C ${HOME} -f cache.tgz || true
+# prepare build env
+export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
+export BUILD_DIR="$(pwd)/.build-depend"
+export LOG=$(pwd)/build.log
+[ ! -e ${BUILD_DIR} ] && mkdir ${BUILD_DIR}; cd ${BUILD_DIR}
+echo "building in ${BUILD_DIR} log ${LOG}" | tee ${LOG}
+
+function fetch_pkg {
+	if [ "${2##*.}" == git ]; then
+		[ ! -e $1 ] && git clone -b $3 "$2" $1 &> /dev/null
+	else
+		[ ! -f $1.tar.${2##*.} ] && curl "$2" > $1.tar.${2##*.}
+		tar xf $1.tar.${2##*.}
 	fi
-	brew install --force makedepend
-	brew install --force python
-	brew link --overwrite python
-	pip install --upgrade pip
-	pip install -r ${PIP_PKGS}
-fi
-if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
-	pip install --user ${USER} -r ${PIP_PKGS}
-fi
+	cd $1
+}
 
-# liburcu
-if [ ! -e ${PREFIX}/include/urcu.h ]; then
-	git clone -b ${URCU_TAG} git://git.urcu.so/userspace-rcu.git || true
-	cd userspace-rcu
-	./bootstrap
-	./configure --prefix=${PREFIX} --disable-dependency-tracking --disable-rpath
-	( make ${MAKEOPTS} ; make install ) || true
-	cd ..
-fi
+function build_pkg {
+	if [ -f CMakeLists.txt ]; then
+		[ -e cmake-build ] && rm -r cmake-build; mkdir cmake-build; cd cmake-build
+		cmake -DCMAKE_INSTALL_PREFIX=${PREFIX} ..
+	else
+		if [ ! -e ./configure ]; then
+			[ -e autogen.sh ] && sh autogen.sh || autoreconf -if
+		fi
+		./configure --prefix=${PREFIX} --enable-shared --disable-static $*
+	fi
+	make ${MAKEOPTS}
+	make install
+}
 
-# libknot
-if [ ! -e ${PREFIX}/include/libknot ]; then
-	git clone -b ${KNOT_TAG} https://github.com/CZNIC-Labs/knot.git || true
-	cd knot
-	autoreconf -i
-	if [ $(uname) == "Darwin" ]; then # Workaround for crypto version check on OS X
-		export libcrypto_CFLAGS="-I /usr/local/opt/openssl/include"
-		export libcrypto_LIBS="-L/usr/local/opt/openssl/lib -lcrypto"
+function pkg {
+	if [ ! -e ${PREFIX}/$4 ]; then
+		cd ${BUILD_DIR}
+		echo "[x] fetching $1-$3"
+		fetch_pkg "$1-$3" "$2" $3 >> ${LOG}
+		echo "[x] building $1-$3"
+		shift 4
+		(build_pkg $*) >> ${LOG} 2>&1
 	fi
-	./configure --prefix=${PREFIX} --with-lmdb=no --disable-fastparser --disable-dependency-tracking
-	make ${MAKEOPTS} && make install
-	cd ..
-fi
+}
 
+# gnutls + dependencies
+pkg gmp ${GMP_URL} ${GMP_TAG} include/gmp.h
+pkg nettle ${NETTLE_URL} ${NETTLE_TAG} include/nettle \
+	--disable-documentation --with-lib-path=${PREFIX}/lib --with-include-path=${PREFIX}/include
+export GMP_CFLAGS="-I${PREFIX}/include"
+export GMP_LIBS="-L${PREFIX}/lib -lgmp"
+pkg gnutls ${GNUTLS_URL} ${GNUTLS_TAG} include/gnutls \
+	--disable-tests --disable-doc --disable-valgrind-tests
+# jansson
+pkg jansson ${JANSSON_URL} ${JANSSON_TAG} include/jansson.h
+# libknot
+pkg libknot ${KNOT_URL} ${KNOT_TAG} include/libknot \
+	--with-lmdb=no --disable-fastparser --disable-daemon --disable-utilities --disable-documentation
 # cmocka
-if [ ! -e ${PREFIX}/include/cmocka.h ]; then
-	git clone -b ${CMOCKA_TAG} git://git.cryptomilk.org/projects/cmocka.git || true
-	cd cmocka
-	mkdir build
-	cd build
-	cmake -DCMAKE_INSTALL_PREFIX=${PREFIX} ..
-	make ${MAKEOPTS} && make install
-	cd ../..
-fi
-
+pkg cmocka ${CMOCKA_URL} ${CMOCKA_TAG} 
 # libuv
-if [ ! -e ${PREFIX}/include/uv.h ]; then
-	git clone -b ${LIBUV_TAG} https://github.com/libuv/libuv.git || true
-	cd libuv
-	sh autogen.sh
-	./configure --prefix=${PREFIX} --disable-dependency-tracking
-	make ${MAKEOPTS} && make install
+pkg libuv ${LIBUV_URL} ${LIBUV_TAG} include/uv.h
+
+# travis-specific
+PIP_PKGS="${TRAVIS_BUILD_DIR}/tests/pydnstest/requirements.txt cpp-coveralls"
+if [ "${TRAVIS_OS_NAME}" == "osx" ]; then
+	DEPEND_CACHE="https://dl.dropboxusercontent.com/u/2255176/resolver-${TRAVIS_OS_NAME}-cache.tar.gz"
+	curl "${DEPEND_CACHE}" > cache.tar.gz && tar -xz -C ${HOME} -f cache.tar.gz || true
+	brew install --force makedepend python
+	brew link --overwrite python
+	pip install --upgrade pip
+	pip install -r ${PIP_PKGS}
 fi
+if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
+	pip install --user ${USER} -r ${PIP_PKGS}
+fi
\ No newline at end of file