Skip to content

Commit

Permalink
build: Add --disable-bip70 configure option
Browse files Browse the repository at this point in the history
This patch adds a --disable-bip70 configure option that disables BIP70
payment request support. When disabled, this removes the dependency of
the GUI on OpenSSL and Protobuf.
  • Loading branch information
laanwj authored and jameshilliard committed Oct 9, 2018
1 parent 1d14174 commit 9dcf6c0
Show file tree
Hide file tree
Showing 19 changed files with 185 additions and 13 deletions.
26 changes: 24 additions & 2 deletions configure.ac
Expand Up @@ -209,6 +209,11 @@ AC_ARG_ENABLE([zmq],
[disable ZMQ notifications])],
[use_zmq=$enableval],
[use_zmq=yes])
AC_ARG_ENABLE([bip70],
[AS_HELP_STRING([--disable-bip70],
[disable BIP70 (payment protocol) support in GUI (enabled by default)])],
[enable_bip70=$enableval],
[enable_bip70=yes])

AC_ARG_WITH([protoc-bindir],[AS_HELP_STRING([--with-protoc-bindir=BIN_DIR],[specify protoc bin path])], [protoc_bin_path=$withval], [])

Expand Down Expand Up @@ -1082,7 +1087,9 @@ if test x$use_pkgconfig = xyes; then
[
PKG_CHECK_MODULES([SSL], [libssl],, [AC_MSG_ERROR(openssl not found.)])
PKG_CHECK_MODULES([CRYPTO], [libcrypto],,[AC_MSG_ERROR(libcrypto not found.)])
BITCOIN_QT_CHECK([PKG_CHECK_MODULES([PROTOBUF], [protobuf], [have_protobuf=yes], [BITCOIN_QT_FAIL(libprotobuf not found)])])
if test x$enable_bip70 != xno; then
BITCOIN_QT_CHECK([PKG_CHECK_MODULES([PROTOBUF], [protobuf], [have_protobuf=yes], [BITCOIN_QT_FAIL(libprotobuf not found)])])
fi
if test x$use_qr != xno; then
BITCOIN_QT_CHECK([PKG_CHECK_MODULES([QR], [libqrencode], [have_qrencode=yes], [have_qrencode=no])])
fi
Expand Down Expand Up @@ -1142,7 +1149,9 @@ else
esac
fi

BITCOIN_QT_CHECK(AC_CHECK_LIB([protobuf] ,[main],[PROTOBUF_LIBS=-lprotobuf], BITCOIN_QT_FAIL(libprotobuf not found)))
if test x$enable_bip70 != xno; then
BITCOIN_QT_CHECK(AC_CHECK_LIB([protobuf] ,[main],[PROTOBUF_LIBS=-lprotobuf], BITCOIN_QT_FAIL(libprotobuf not found)))
fi
if test x$use_qr != xno; then
BITCOIN_QT_CHECK([AC_CHECK_LIB([qrencode], [main],[QR_LIBS=-lqrencode], [have_qrencode=no])])
BITCOIN_QT_CHECK([AC_CHECK_HEADER([qrencode.h],, have_qrencode=no)])
Expand Down Expand Up @@ -1220,7 +1229,9 @@ AM_CONDITIONAL([EMBEDDED_UNIVALUE],[test x$need_bundled_univalue = xyes])
AC_SUBST(UNIVALUE_CFLAGS)
AC_SUBST(UNIVALUE_LIBS)

if test x$enable_bip70 != xno; then
BITCOIN_QT_PATH_PROGS([PROTOC], [protoc],$protoc_bin_path)
fi

AC_MSG_CHECKING([whether to build bitcoind])
AM_CONDITIONAL([BUILD_BITCOIND], [test x$build_bitcoind = xyes])
Expand Down Expand Up @@ -1338,6 +1349,15 @@ if test x$bitcoin_enable_qt != xno; then
else
AC_MSG_RESULT([no])
fi

AC_MSG_CHECKING([whether to build BIP70 support])
if test x$enable_bip70 != xno; then
AC_DEFINE([ENABLE_BIP70],[1],[Define if BIP70 support should be compiled in])
enable_bip70=yes
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
fi

AM_CONDITIONAL([ENABLE_ZMQ], [test "x$use_zmq" = "xyes"])
Expand Down Expand Up @@ -1369,6 +1389,7 @@ AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])
AM_CONDITIONAL([ENABLE_QT_TESTS],[test x$BUILD_TEST_QT = xyes])
AM_CONDITIONAL([ENABLE_BIP70],[test x$enable_bip70 = xyes])
AM_CONDITIONAL([ENABLE_BENCH],[test x$use_bench = xyes])
AM_CONDITIONAL([USE_QRCODE], [test x$use_qr = xyes])
AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
Expand Down Expand Up @@ -1503,6 +1524,7 @@ echo "Options used to compile and link:"
echo " with wallet = $enable_wallet"
echo " with gui / qt = $bitcoin_enable_qt"
if test x$bitcoin_enable_qt != xno; then
echo " with bip70 = $enable_bip70"
echo " with qr = $use_qr"
fi
echo " with zmq = $use_zmq"
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Expand Up @@ -587,9 +587,11 @@ if HARDEN
$(AM_V_at) READELF=$(READELF) OBJDUMP=$(OBJDUMP) $(top_srcdir)/contrib/devtools/security-check.py < $(bin_PROGRAMS)
endif

if ENABLE_BIP70
%.pb.cc %.pb.h: %.proto
@test -f $(PROTOC)
$(AM_V_GEN) $(PROTOC) --cpp_out=$(@D) --proto_path=$(<D) $<
endif

if EMBEDDED_LEVELDB
include Makefile.leveldb.include
Expand Down
15 changes: 13 additions & 2 deletions src/Makefile.qt.include
Expand Up @@ -178,9 +178,15 @@ QT_QRC = qt/bitcoin.qrc
QT_QRC_LOCALE_CPP = qt/qrc_bitcoin_locale.cpp
QT_QRC_LOCALE = qt/bitcoin_locale.qrc

if ENABLE_BIP70
PROTOBUF_CC = qt/paymentrequest.pb.cc
PROTOBUF_H = qt/paymentrequest.pb.h
PROTOBUF_PROTO = qt/paymentrequest.proto
else
PROTOBUF_CC =
PROTOBUF_H =
PROTOBUF_PROTO =
endif

BITCOIN_QT_H = \
qt/addressbookpage.h \
Expand Down Expand Up @@ -330,7 +336,6 @@ BITCOIN_QT_WALLET_CPP = \
qt/editaddressdialog.cpp \
qt/openuridialog.cpp \
qt/overviewpage.cpp \
qt/paymentrequestplus.cpp \
qt/paymentserver.cpp \
qt/receivecoinsdialog.cpp \
qt/receiverequestdialog.cpp \
Expand All @@ -349,13 +354,19 @@ BITCOIN_QT_WALLET_CPP = \
qt/walletmodeltransaction.cpp \
qt/walletview.cpp

BITCOIN_QT_WALLET_BIP70_CPP = \
qt/paymentrequestplus.cpp

BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP)
if TARGET_WINDOWS
BITCOIN_QT_CPP += $(BITCOIN_QT_WINDOWS_CPP)
endif
if ENABLE_WALLET
BITCOIN_QT_CPP += $(BITCOIN_QT_WALLET_CPP)
endif
if ENABLE_BIP70
BITCOIN_QT_CPP += $(BITCOIN_QT_WALLET_BIP70_CPP)
endif # ENABLE_BIP70
endif # ENABLE_WALLET

RES_IMAGES =

Expand Down
14 changes: 10 additions & 4 deletions src/Makefile.qttest.include
Expand Up @@ -13,9 +13,12 @@ TEST_QT_MOC_CPP = \
if ENABLE_WALLET
TEST_QT_MOC_CPP += \
qt/test/moc_addressbooktests.cpp \
qt/test/moc_paymentservertests.cpp \
qt/test/moc_wallettests.cpp
endif
if ENABLE_BIP70
TEST_QT_MOC_CPP += \
qt/test/moc_paymentservertests.cpp
endif # ENABLE_BIP70
endif # ENABLE_WALLET

TEST_QT_H = \
qt/test/addressbooktests.h \
Expand Down Expand Up @@ -48,10 +51,13 @@ qt_test_test_bitcoin_qt_SOURCES = \
if ENABLE_WALLET
qt_test_test_bitcoin_qt_SOURCES += \
qt/test/addressbooktests.cpp \
qt/test/paymentservertests.cpp \
qt/test/wallettests.cpp \
wallet/test/wallet_test_fixture.cpp
endif
if ENABLE_BIP70
qt_test_test_bitcoin_qt_SOURCES += \
qt/test/paymentservertests.cpp
endif # ENABLE_BIP70
endif # ENABLE_WALLET

nodist_qt_test_test_bitcoin_qt_SOURCES = $(TEST_QT_MOC_CPP)

Expand Down
6 changes: 5 additions & 1 deletion src/qt/bitcoin.cpp
Expand Up @@ -440,8 +440,10 @@ void BitcoinApplication::addWallet(WalletModel* walletModel)
window->setCurrentWallet(walletModel->getWalletName());
}

#ifdef ENABLE_BIP70
connect(walletModel, &WalletModel::coinsSent,
paymentServer, &PaymentServer::fetchPaymentACK);
#endif
connect(walletModel, &WalletModel::unload, this, &BitcoinApplication::removeWallet);

m_wallet_models.push_back(walletModel);
Expand All @@ -468,7 +470,9 @@ void BitcoinApplication::initializeResult(bool success)
// Log this only after AppInitMain finishes, as then logging setup is guaranteed complete
qWarning() << "Platform customization:" << platformStyle->getName();
#ifdef ENABLE_WALLET
#ifdef ENABLE_BIP70
PaymentServer::LoadRootCAs();
#endif
paymentServer->setOptionsModel(optionsModel);
#endif

Expand Down Expand Up @@ -537,7 +541,7 @@ WId BitcoinApplication::getMainWinId() const

static void SetupUIArgs()
{
#ifdef ENABLE_WALLET
#if defined(ENABLE_WALLET) && defined(ENABLE_BIP70)
gArgs.AddArg("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS), true, OptionsCategory::GUI);
#endif
gArgs.AddArg("-choosedatadir", strprintf("Choose data directory on startup (default: %u)", DEFAULT_CHOOSE_DATADIR), false, OptionsCategory::GUI);
Expand Down
5 changes: 5 additions & 0 deletions src/qt/coincontroldialog.cpp
Expand Up @@ -2,10 +2,15 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif

#include <qt/coincontroldialog.h>
#include <qt/forms/ui_coincontroldialog.h>

#include <qt/addresstablemodel.h>
#include <base58.h>
#include <qt/bitcoinunits.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
Expand Down
35 changes: 34 additions & 1 deletion src/qt/paymentserver.cpp
Expand Up @@ -2,6 +2,10 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif

#include <qt/paymentserver.h>

#include <qt/bitcoinunits.h>
Expand Down Expand Up @@ -45,6 +49,7 @@

const int BITCOIN_IPC_CONNECT_TIMEOUT = 1000; // milliseconds
const QString BITCOIN_IPC_PREFIX("bitcoin:");
#ifdef ENABLE_BIP70
// BIP70 payment protocol messages
const char* BIP70_MESSAGE_PAYMENTACK = "PaymentACK";
const char* BIP70_MESSAGE_PAYMENTREQUEST = "PaymentRequest";
Expand All @@ -67,6 +72,7 @@ namespace // Anon namespace
{
std::unique_ptr<X509_STORE, X509StoreDeleter> certStore;
}
#endif

//
// Create a name that is unique for:
Expand All @@ -93,6 +99,7 @@ static QString ipcServerName()

static QList<QString> savedPaymentRequests;

#ifdef ENABLE_BIP70
static void ReportInvalidCertificate(const QSslCertificate& cert)
{
qDebug() << QString("%1: Payment server found an invalid certificate: ").arg(__func__) << cert.serialNumber() << cert.subjectInfo(QSslCertificate::CommonName) << cert.subjectInfo(QSslCertificate::DistinguishedNameQualifier) << cert.subjectInfo(QSslCertificate::OrganizationalUnitName);
Expand Down Expand Up @@ -180,6 +187,7 @@ void PaymentServer::LoadRootCAs(X509_STORE* _store)
// or use Qt's blacklist?
// "certificate stapling" with server-side caching is more efficient
}
#endif

//
// Sending to the server is done synchronously, at startup.
Expand Down Expand Up @@ -221,6 +229,7 @@ void PaymentServer::ipcParseCommandLine(interfaces::Node& node, int argc, char*
}
}
}
#ifdef ENABLE_BIP70
else if (QFile::exists(arg)) // Filename
{
savedPaymentRequests.append(arg);
Expand All @@ -244,6 +253,7 @@ void PaymentServer::ipcParseCommandLine(interfaces::Node& node, int argc, char*
// GUI hasn't started yet so we can't pop up a message box.
qWarning() << "PaymentServer::ipcSendCommandLine: Payment request file does not exist: " << arg;
}
#endif
}
}

Expand Down Expand Up @@ -290,12 +300,16 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
QObject(parent),
saveURIs(true),
uriServer(0),
#ifdef ENABLE_BIP70
netManager(0),
#endif
optionsModel(0)
{
#ifdef ENABLE_BIP70
// Verify that the version of the library that we linked against is
// compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION;
#endif

// Install global event filter to catch QFileOpenEvents
// on Mac: sent when you click bitcoin: links
Expand All @@ -319,14 +333,18 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
}
else {
connect(uriServer, &QLocalServer::newConnection, this, &PaymentServer::handleURIConnection);
#ifdef ENABLE_BIP70
connect(this, &PaymentServer::receivedPaymentACK, this, &PaymentServer::handlePaymentACK);
#endif
}
}
}

PaymentServer::~PaymentServer()
{
#ifdef ENABLE_BIP70
google::protobuf::ShutdownProtobufLibrary();
#endif
}

//
Expand All @@ -349,6 +367,7 @@ bool PaymentServer::eventFilter(QObject *object, QEvent *event)
return QObject::eventFilter(object, event);
}

#ifdef ENABLE_BIP70
void PaymentServer::initNetManager()
{
if (!optionsModel)
Expand All @@ -372,10 +391,13 @@ void PaymentServer::initNetManager()
connect(netManager, &QNetworkAccessManager::finished, this, &PaymentServer::netRequestFinished);
connect(netManager, &QNetworkAccessManager::sslErrors, this, &PaymentServer::reportSslErrors);
}
#endif

void PaymentServer::uiReady()
{
#ifdef ENABLE_BIP70
initNetManager();
#endif

saveURIs = false;
for (const QString& s : savedPaymentRequests)
Expand Down Expand Up @@ -403,6 +425,7 @@ void PaymentServer::handleURIOrFile(const QString& s)
QUrlQuery uri((QUrl(s)));
if (uri.hasQueryItem("r")) // payment request URI
{
#ifdef ENABLE_BIP70
QByteArray temp;
temp.append(uri.queryItemValue("r"));
QString decoded = QUrl::fromPercentEncoding(temp);
Expand All @@ -420,7 +443,11 @@ void PaymentServer::handleURIOrFile(const QString& s)
tr("Payment request fetch URL is invalid: %1").arg(fetchUrl.toString()),
CClientUIInterface::ICON_WARNING);
}

#else
Q_EMIT message(tr("URI handling"),
tr("Cannot process payment request because BIP70 support was not compiled in."),
CClientUIInterface::ICON_WARNING);
#endif
return;
}
else // normal URI
Expand All @@ -444,6 +471,7 @@ void PaymentServer::handleURIOrFile(const QString& s)
}
}

#ifdef ENABLE_BIP70
if (QFile::exists(s)) // payment request file
{
PaymentRequestPlus request;
Expand All @@ -459,6 +487,7 @@ void PaymentServer::handleURIOrFile(const QString& s)

return;
}
#endif
}

void PaymentServer::handleURIConnection()
Expand All @@ -481,6 +510,7 @@ void PaymentServer::handleURIConnection()
handleURIOrFile(msg);
}

#ifdef ENABLE_BIP70
//
// Warning: readPaymentRequestFromFile() is used in ipcSendCommandLine()
// so don't use "Q_EMIT message()", but "QMessageBox::"!
Expand Down Expand Up @@ -730,12 +760,14 @@ void PaymentServer::reportSslErrors(QNetworkReply* reply, const QList<QSslError>
}
Q_EMIT message(tr("Network request error"), errString, CClientUIInterface::MSG_ERROR);
}
#endif

void PaymentServer::setOptionsModel(OptionsModel *_optionsModel)
{
this->optionsModel = _optionsModel;
}

#ifdef ENABLE_BIP70
void PaymentServer::handlePaymentACK(const QString& paymentACKMsg)
{
// currently we don't further process or store the paymentACK message
Expand Down Expand Up @@ -794,3 +826,4 @@ X509_STORE* PaymentServer::getCertStore()
{
return certStore.get();
}
#endif

0 comments on commit 9dcf6c0

Please sign in to comment.