Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ AC_ARG_WITH([system-univalue],
[system_univalue=$withval],
[system_univalue=no]
)

AC_ARG_WITH([openssl],
[AS_HELP_STRING([--with-openssl],
[enable openssl (default is yes if OpenSSL is found)])],
[use_openssl=$withval],
[use_openssl=yes])

AC_ARG_ENABLE([zmq],
[AS_HELP_STRING([--disable-zmq],
[disable ZMQ notifications])],
Expand Down Expand Up @@ -654,12 +661,14 @@ case $host in
dnl It's safe to add these paths even if the functionality is disabled by
dnl the user (--without-wallet or --without-gui for example).

openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
bdb_prefix=`$BREW --prefix berkeley-db4 2>/dev/null`
qt5_prefix=`$BREW --prefix qt5 2>/dev/null`
if test x$openssl_prefix != x; then
PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
export PKG_CONFIG_PATH
if test x$use_openssl != xno; then
openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
if test x$openssl_prefix != x; then
PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
export PKG_CONFIG_PATH
fi
fi
if test x$bdb_prefix != x; then
CPPFLAGS="$CPPFLAGS -I$bdb_prefix/include"
Expand Down Expand Up @@ -1171,6 +1180,7 @@ if test "x$enable_fuzz" = "xyes"; then
bitcoin_enable_qt_dbus=no
enable_wallet=no
use_bench=no
use_openssl=no
use_upnp=no
use_zmq=no
else
Expand Down Expand Up @@ -1358,8 +1368,10 @@ if test x$use_pkgconfig = xyes; then
m4_ifdef(
[PKG_CHECK_MODULES],
[
PKG_CHECK_MODULES([SSL], [libssl],, [AC_MSG_ERROR(openssl not found.)])
PKG_CHECK_MODULES([CRYPTO], [libcrypto],,[AC_MSG_ERROR(libcrypto not found.)])
if test x$use_openssl != xno; then
PKG_CHECK_MODULES([SSL], [libssl],, [use_openssl=no])
PKG_CHECK_MODULES([CRYPTO], [libcrypto],, [use_openssl=no])
fi
if test x$enable_bip70 != xno; then
BITCOIN_QT_CHECK([PKG_CHECK_MODULES([PROTOBUF], [protobuf], [have_protobuf=yes], [have_protobuf=no])])
fi
Expand All @@ -1385,11 +1397,13 @@ if test x$use_pkgconfig = xyes; then
]
)
else
AC_CHECK_HEADER([openssl/crypto.h],,AC_MSG_ERROR(libcrypto headers missing))
AC_CHECK_LIB([crypto], [main],CRYPTO_LIBS=-lcrypto, AC_MSG_ERROR(libcrypto missing))
if test x$use_openssl != xno; then
AC_CHECK_HEADER([openssl/crypto.h],,[use_openssl=no])
AC_CHECK_LIB([crypto], [main],CRYPTO_LIBS=-lcrypto, [use_openssl=no])

AC_CHECK_HEADER([openssl/ssl.h],, AC_MSG_ERROR(libssl headers missing),)
AC_CHECK_LIB([ssl], [main],SSL_LIBS=-lssl, AC_MSG_ERROR(libssl missing))
AC_CHECK_HEADER([openssl/ssl.h],, [use_openssl=no])
AC_CHECK_LIB([ssl], [main],SSL_LIBS=-lssl, [use_openssl=no])
fi

if test x$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests != xnononono; then
AC_CHECK_HEADER([event2/event.h],, AC_MSG_ERROR(libevent headers missing),)
Expand Down Expand Up @@ -1627,6 +1641,12 @@ if test x$bitcoin_enable_qt != xno; then
fi
enable_bip70=no
AC_MSG_RESULT(no)
elif test x$use_openssl = xno; then
if test x$enable_bip70 = xyes; then
AC_MSG_ERROR(OpenSSL missing)
fi
enable_bip70=no
AC_MSG_RESULT(no)
else
if test x$enable_bip70 != xno; then
AC_DEFINE([ENABLE_BIP70],[1],[Define if BIP70 support should be compiled in])
Expand All @@ -1638,6 +1658,10 @@ if test x$bitcoin_enable_qt != xno; then
fi
fi

if test x$use_openssl = xyes; then
AC_DEFINE([USE_OPENSSL],[1],[Define to 1 to use OpenSSL])
fi

AM_CONDITIONAL([ENABLE_ZMQ], [test "x$use_zmq" = "xyes"])

AC_MSG_CHECKING([whether to build test_dash])
Expand Down Expand Up @@ -1819,6 +1843,7 @@ if test x$bitcoin_enable_qt != xno; then
echo " with bip70 = $enable_bip70"
echo " with qr = $use_qr"
fi
echo " with openssl = $use_openssl"
echo " with zmq = $use_zmq"
echo " with test = $use_tests"
echo " with bench = $use_bench"
Expand Down
6 changes: 6 additions & 0 deletions depends/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ BASE_CACHE ?= $(BASEDIR)/built
SDK_PATH ?= $(BASEDIR)/SDKs
NO_QT ?=
NO_PROTOBUF ?=
NO_OPENSSL ?=
NO_WALLET ?=
NO_ZMQ ?=
NO_UPNP ?=
Expand Down Expand Up @@ -136,6 +137,7 @@ upnp_packages_$(NO_UPNP) = $(upnp_packages)
zmq_packages_$(NO_ZMQ) = $(zmq_packages)

protobuf_packages_$(NO_PROTOBUF) = $(protobuf_packages)
openssl_packages_$(NO_OPENSSL) = $(openssl_packages)

packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(qt_packages_) $(wallet_packages_) $(upnp_packages_)
native_packages += $($(host_arch)_$(host_os)_native_packages) $($(host_os)_native_packages)
Expand All @@ -145,6 +147,10 @@ native_packages += $(protobuf_native_packages)
packages += $(protobuf_packages)
endif

ifneq ($(openssl_packages_),)
packages += $(openssl_packages)
endif

ifneq ($(zmq_packages_),)
packages += $(zmq_packages)
endif
Expand Down
4 changes: 3 additions & 1 deletion depends/packages/packages.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
packages:=boost openssl libevent gmp bls-dash backtrace cmake immer
packages:=boost libevent gmp bls-dash backtrace cmake immer

protobuf_native_packages = native_protobuf
protobuf_packages = protobuf

openssl_packages = openssl

qt_packages = qrencode zlib

qt_linux_packages:=qt expat dbus libxcb xcb_proto libXau xproto freetype fontconfig
Expand Down
7 changes: 6 additions & 1 deletion depends/packages/qt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ $(package)_download_path=https://download.qt.io/archive/qt/5.9/$($(package)_vers
$(package)_suffix=opensource-src-$($(package)_version).tar.xz
$(package)_file_name=qtbase-$($(package)_suffix)
$(package)_sha256_hash=9b9dec1f67df1f94bce2955c5604de992d529dde72050239154c56352da0907d
$(package)_dependencies=openssl zlib
$(package)_dependencies=zlib
ifeq ($(NO_OPENSSL),)
$(package)_dependencies+= openssl
endif
$(package)_linux_dependencies=freetype fontconfig libxcb
$(package)_qt_libs=corelib network widgets gui plugins testlib
$(package)_patches=fix_qt_pkgconfig.patch mac-qmake.conf fix_configure_mac.patch fix_no_printer.patch fix_riscv64_arch.patch
Expand Down Expand Up @@ -62,7 +65,9 @@ $(package)_config_opts += -no-xinput2
$(package)_config_opts += -nomake examples
$(package)_config_opts += -nomake tests
$(package)_config_opts += -opensource
ifeq ($(NO_OPENSSL),)
$(package)_config_opts += -openssl-linked
endif
$(package)_config_opts += -optimized-tools
$(package)_config_opts += -pch
$(package)_config_opts += -pkg-config
Expand Down
2 changes: 2 additions & 0 deletions src/qt/paymentserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#include <cstdlib>
#include <memory>

#if USE_OPENSSL
#include <openssl/x509_vfy.h>
#endif

#include <QApplication>
#include <QByteArray>
Expand Down
2 changes: 2 additions & 0 deletions src/qt/test/paymentservertests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
#include <test/setup_common.h>
#include <util/strencodings.h>

#if USE_OPENSSL
#include <openssl/x509.h>
#include <openssl/x509_vfy.h>
#endif

#include <QFileOpenEvent>
#include <QTemporaryFile>
Expand Down
4 changes: 4 additions & 0 deletions src/qt/test/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#include <QObject>
#include <QTest>

#if USE_OPENSSL
#include <openssl/ssl.h>
#endif

#if defined(QT_STATICPLUGIN)
#include <QtPlugin>
Expand Down Expand Up @@ -75,7 +77,9 @@ int main(int argc, char *argv[])
BitcoinApplication app(*node);
app.setApplicationName("Dash-Qt-test");

#if USE_OPENSSL
SSL_library_init();
#endif

AppTests app_tests(app);
if (QTest::qExec(&app_tests) != 0) {
Expand Down
16 changes: 16 additions & 0 deletions src/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
#include <cpuid.h>
#endif

#if USE_OPENSSL
#include <openssl/rand.h>
#include <openssl/conf.h>
#endif

[[noreturn]] static void RandFailure()
{
Expand Down Expand Up @@ -400,7 +402,9 @@ void GetOSRand(unsigned char *ent32)
#endif
}

#if USE_OPENSSL
void LockingCallbackOpenSSL(int mode, int i, const char* file, int line);
#endif

namespace {

Expand All @@ -424,6 +428,7 @@ class RNGState {
{
InitHardwareRand();

#if USE_OPENSSL
// Init OpenSSL library multithreading support
m_mutex_openssl.reset(new Mutex[CRYPTO_num_locks()]);
CRYPTO_set_locking_callback(LockingCallbackOpenSSL);
Expand All @@ -434,14 +439,17 @@ class RNGState {
// or corrupt. Explicitly tell OpenSSL not to try to load the file. The result for our libs will be
// that the config appears to have been loaded and there are no modules/engines available.
OPENSSL_no_config();
#endif
}

~RNGState()
{
#if USE_OPENSSL
// Securely erase the memory used by the OpenSSL PRNG
RAND_cleanup();
// Shutdown OpenSSL library multithreading support
CRYPTO_set_locking_callback(nullptr);
#endif
}

/** Extract up to 32 bytes of entropy from the RNG state, mixing in new entropy from hasher.
Expand Down Expand Up @@ -478,7 +486,9 @@ class RNGState {
return ret;
}

#if USE_OPENSSL
Mutex& GetOpenSSLMutex(int i) { return m_mutex_openssl[i]; }
#endif
};

RNGState& GetRNGState() noexcept
Expand All @@ -490,6 +500,7 @@ RNGState& GetRNGState() noexcept
}
}

#if USE_OPENSSL
void LockingCallbackOpenSSL(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS
{
RNGState& rng = GetRNGState();
Expand All @@ -500,6 +511,7 @@ void LockingCallbackOpenSSL(int mode, int i, const char* file, int line) NO_THRE
rng.GetOpenSSLMutex(i).unlock();
}
}
#endif

/* A note on the use of noexcept in the seeding functions below:
*
Expand Down Expand Up @@ -538,9 +550,11 @@ static void SeedSlow(CSHA512& hasher) noexcept
GetOSRand(buffer);
hasher.Write(buffer, sizeof(buffer));

#if USE_OPENSSL
// OpenSSL RNG (for now)
RAND_bytes(buffer, sizeof(buffer));
hasher.Write(buffer, sizeof(buffer));
#endif

// High-precision timestamp.
//
Expand Down Expand Up @@ -635,13 +649,15 @@ static void ProcRand(unsigned char* out, int num, RNGLevel level)
rng.MixExtract(out, num, std::move(startup_hasher), true);
}

#if USE_OPENSSL
// For anything but the 'fast' level, feed the resulting RNG output (after an additional hashing step) back into OpenSSL.
if (level != RNGLevel::FAST) {
unsigned char buf[64];
CSHA512().Write(out, num).Finalize(buf);
RAND_add(buf, sizeof(buf), num);
memory_cleanse(buf, 64);
}
#endif
}

std::chrono::microseconds GetRandMicros(std::chrono::microseconds duration_max) noexcept
Expand Down