Skip to content

Commit 9dcf6c0

Browse files
laanwjjameshilliard
authored andcommitted
build: Add --disable-bip70 configure option
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.
1 parent 1d14174 commit 9dcf6c0

19 files changed

+185
-13
lines changed

configure.ac

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ AC_ARG_ENABLE([zmq],
209209
[disable ZMQ notifications])],
210210
[use_zmq=$enableval],
211211
[use_zmq=yes])
212+
AC_ARG_ENABLE([bip70],
213+
[AS_HELP_STRING([--disable-bip70],
214+
[disable BIP70 (payment protocol) support in GUI (enabled by default)])],
215+
[enable_bip70=$enableval],
216+
[enable_bip70=yes])
212217

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

@@ -1082,7 +1087,9 @@ if test x$use_pkgconfig = xyes; then
10821087
[
10831088
PKG_CHECK_MODULES([SSL], [libssl],, [AC_MSG_ERROR(openssl not found.)])
10841089
PKG_CHECK_MODULES([CRYPTO], [libcrypto],,[AC_MSG_ERROR(libcrypto not found.)])
1085-
BITCOIN_QT_CHECK([PKG_CHECK_MODULES([PROTOBUF], [protobuf], [have_protobuf=yes], [BITCOIN_QT_FAIL(libprotobuf not found)])])
1090+
if test x$enable_bip70 != xno; then
1091+
BITCOIN_QT_CHECK([PKG_CHECK_MODULES([PROTOBUF], [protobuf], [have_protobuf=yes], [BITCOIN_QT_FAIL(libprotobuf not found)])])
1092+
fi
10861093
if test x$use_qr != xno; then
10871094
BITCOIN_QT_CHECK([PKG_CHECK_MODULES([QR], [libqrencode], [have_qrencode=yes], [have_qrencode=no])])
10881095
fi
@@ -1142,7 +1149,9 @@ else
11421149
esac
11431150
fi
11441151

1145-
BITCOIN_QT_CHECK(AC_CHECK_LIB([protobuf] ,[main],[PROTOBUF_LIBS=-lprotobuf], BITCOIN_QT_FAIL(libprotobuf not found)))
1152+
if test x$enable_bip70 != xno; then
1153+
BITCOIN_QT_CHECK(AC_CHECK_LIB([protobuf] ,[main],[PROTOBUF_LIBS=-lprotobuf], BITCOIN_QT_FAIL(libprotobuf not found)))
1154+
fi
11461155
if test x$use_qr != xno; then
11471156
BITCOIN_QT_CHECK([AC_CHECK_LIB([qrencode], [main],[QR_LIBS=-lqrencode], [have_qrencode=no])])
11481157
BITCOIN_QT_CHECK([AC_CHECK_HEADER([qrencode.h],, have_qrencode=no)])
@@ -1220,7 +1229,9 @@ AM_CONDITIONAL([EMBEDDED_UNIVALUE],[test x$need_bundled_univalue = xyes])
12201229
AC_SUBST(UNIVALUE_CFLAGS)
12211230
AC_SUBST(UNIVALUE_LIBS)
12221231

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

12251236
AC_MSG_CHECKING([whether to build bitcoind])
12261237
AM_CONDITIONAL([BUILD_BITCOIND], [test x$build_bitcoind = xyes])
@@ -1338,6 +1349,15 @@ if test x$bitcoin_enable_qt != xno; then
13381349
else
13391350
AC_MSG_RESULT([no])
13401351
fi
1352+
1353+
AC_MSG_CHECKING([whether to build BIP70 support])
1354+
if test x$enable_bip70 != xno; then
1355+
AC_DEFINE([ENABLE_BIP70],[1],[Define if BIP70 support should be compiled in])
1356+
enable_bip70=yes
1357+
AC_MSG_RESULT([yes])
1358+
else
1359+
AC_MSG_RESULT([no])
1360+
fi
13411361
fi
13421362

13431363
AM_CONDITIONAL([ENABLE_ZMQ], [test "x$use_zmq" = "xyes"])
@@ -1369,6 +1389,7 @@ AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
13691389
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
13701390
AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])
13711391
AM_CONDITIONAL([ENABLE_QT_TESTS],[test x$BUILD_TEST_QT = xyes])
1392+
AM_CONDITIONAL([ENABLE_BIP70],[test x$enable_bip70 = xyes])
13721393
AM_CONDITIONAL([ENABLE_BENCH],[test x$use_bench = xyes])
13731394
AM_CONDITIONAL([USE_QRCODE], [test x$use_qr = xyes])
13741395
AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
@@ -1503,6 +1524,7 @@ echo "Options used to compile and link:"
15031524
echo " with wallet = $enable_wallet"
15041525
echo " with gui / qt = $bitcoin_enable_qt"
15051526
if test x$bitcoin_enable_qt != xno; then
1527+
echo " with bip70 = $enable_bip70"
15061528
echo " with qr = $use_qr"
15071529
fi
15081530
echo " with zmq = $use_zmq"

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,11 @@ if HARDEN
587587
$(AM_V_at) READELF=$(READELF) OBJDUMP=$(OBJDUMP) $(top_srcdir)/contrib/devtools/security-check.py < $(bin_PROGRAMS)
588588
endif
589589

590+
if ENABLE_BIP70
590591
%.pb.cc %.pb.h: %.proto
591592
@test -f $(PROTOC)
592593
$(AM_V_GEN) $(PROTOC) --cpp_out=$(@D) --proto_path=$(<D) $<
594+
endif
593595

594596
if EMBEDDED_LEVELDB
595597
include Makefile.leveldb.include

src/Makefile.qt.include

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,15 @@ QT_QRC = qt/bitcoin.qrc
178178
QT_QRC_LOCALE_CPP = qt/qrc_bitcoin_locale.cpp
179179
QT_QRC_LOCALE = qt/bitcoin_locale.qrc
180180

181+
if ENABLE_BIP70
181182
PROTOBUF_CC = qt/paymentrequest.pb.cc
182183
PROTOBUF_H = qt/paymentrequest.pb.h
183184
PROTOBUF_PROTO = qt/paymentrequest.proto
185+
else
186+
PROTOBUF_CC =
187+
PROTOBUF_H =
188+
PROTOBUF_PROTO =
189+
endif
184190

185191
BITCOIN_QT_H = \
186192
qt/addressbookpage.h \
@@ -330,7 +336,6 @@ BITCOIN_QT_WALLET_CPP = \
330336
qt/editaddressdialog.cpp \
331337
qt/openuridialog.cpp \
332338
qt/overviewpage.cpp \
333-
qt/paymentrequestplus.cpp \
334339
qt/paymentserver.cpp \
335340
qt/receivecoinsdialog.cpp \
336341
qt/receiverequestdialog.cpp \
@@ -349,13 +354,19 @@ BITCOIN_QT_WALLET_CPP = \
349354
qt/walletmodeltransaction.cpp \
350355
qt/walletview.cpp
351356

357+
BITCOIN_QT_WALLET_BIP70_CPP = \
358+
qt/paymentrequestplus.cpp
359+
352360
BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP)
353361
if TARGET_WINDOWS
354362
BITCOIN_QT_CPP += $(BITCOIN_QT_WINDOWS_CPP)
355363
endif
356364
if ENABLE_WALLET
357365
BITCOIN_QT_CPP += $(BITCOIN_QT_WALLET_CPP)
358-
endif
366+
if ENABLE_BIP70
367+
BITCOIN_QT_CPP += $(BITCOIN_QT_WALLET_BIP70_CPP)
368+
endif # ENABLE_BIP70
369+
endif # ENABLE_WALLET
359370

360371
RES_IMAGES =
361372

src/Makefile.qttest.include

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ TEST_QT_MOC_CPP = \
1313
if ENABLE_WALLET
1414
TEST_QT_MOC_CPP += \
1515
qt/test/moc_addressbooktests.cpp \
16-
qt/test/moc_paymentservertests.cpp \
1716
qt/test/moc_wallettests.cpp
18-
endif
17+
if ENABLE_BIP70
18+
TEST_QT_MOC_CPP += \
19+
qt/test/moc_paymentservertests.cpp
20+
endif # ENABLE_BIP70
21+
endif # ENABLE_WALLET
1922

2023
TEST_QT_H = \
2124
qt/test/addressbooktests.h \
@@ -48,10 +51,13 @@ qt_test_test_bitcoin_qt_SOURCES = \
4851
if ENABLE_WALLET
4952
qt_test_test_bitcoin_qt_SOURCES += \
5053
qt/test/addressbooktests.cpp \
51-
qt/test/paymentservertests.cpp \
5254
qt/test/wallettests.cpp \
5355
wallet/test/wallet_test_fixture.cpp
54-
endif
56+
if ENABLE_BIP70
57+
qt_test_test_bitcoin_qt_SOURCES += \
58+
qt/test/paymentservertests.cpp
59+
endif # ENABLE_BIP70
60+
endif # ENABLE_WALLET
5561

5662
nodist_qt_test_test_bitcoin_qt_SOURCES = $(TEST_QT_MOC_CPP)
5763

src/qt/bitcoin.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,10 @@ void BitcoinApplication::addWallet(WalletModel* walletModel)
440440
window->setCurrentWallet(walletModel->getWalletName());
441441
}
442442

443+
#ifdef ENABLE_BIP70
443444
connect(walletModel, &WalletModel::coinsSent,
444445
paymentServer, &PaymentServer::fetchPaymentACK);
446+
#endif
445447
connect(walletModel, &WalletModel::unload, this, &BitcoinApplication::removeWallet);
446448

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

@@ -537,7 +541,7 @@ WId BitcoinApplication::getMainWinId() const
537541

538542
static void SetupUIArgs()
539543
{
540-
#ifdef ENABLE_WALLET
544+
#if defined(ENABLE_WALLET) && defined(ENABLE_BIP70)
541545
gArgs.AddArg("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS), true, OptionsCategory::GUI);
542546
#endif
543547
gArgs.AddArg("-choosedatadir", strprintf("Choose data directory on startup (default: %u)", DEFAULT_CHOOSE_DATADIR), false, OptionsCategory::GUI);

src/qt/coincontroldialog.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#if defined(HAVE_CONFIG_H)
6+
#include <config/bitcoin-config.h>
7+
#endif
8+
59
#include <qt/coincontroldialog.h>
610
#include <qt/forms/ui_coincontroldialog.h>
711

812
#include <qt/addresstablemodel.h>
13+
#include <base58.h>
914
#include <qt/bitcoinunits.h>
1015
#include <qt/guiutil.h>
1116
#include <qt/optionsmodel.h>

src/qt/paymentserver.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#if defined(HAVE_CONFIG_H)
6+
#include <config/bitcoin-config.h>
7+
#endif
8+
59
#include <qt/paymentserver.h>
610

711
#include <qt/bitcoinunits.h>
@@ -45,6 +49,7 @@
4549

4650
const int BITCOIN_IPC_CONNECT_TIMEOUT = 1000; // milliseconds
4751
const QString BITCOIN_IPC_PREFIX("bitcoin:");
52+
#ifdef ENABLE_BIP70
4853
// BIP70 payment protocol messages
4954
const char* BIP70_MESSAGE_PAYMENTACK = "PaymentACK";
5055
const char* BIP70_MESSAGE_PAYMENTREQUEST = "PaymentRequest";
@@ -67,6 +72,7 @@ namespace // Anon namespace
6772
{
6873
std::unique_ptr<X509_STORE, X509StoreDeleter> certStore;
6974
}
75+
#endif
7076

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

94100
static QList<QString> savedPaymentRequests;
95101

102+
#ifdef ENABLE_BIP70
96103
static void ReportInvalidCertificate(const QSslCertificate& cert)
97104
{
98105
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);
@@ -180,6 +187,7 @@ void PaymentServer::LoadRootCAs(X509_STORE* _store)
180187
// or use Qt's blacklist?
181188
// "certificate stapling" with server-side caching is more efficient
182189
}
190+
#endif
183191

184192
//
185193
// Sending to the server is done synchronously, at startup.
@@ -221,6 +229,7 @@ void PaymentServer::ipcParseCommandLine(interfaces::Node& node, int argc, char*
221229
}
222230
}
223231
}
232+
#ifdef ENABLE_BIP70
224233
else if (QFile::exists(arg)) // Filename
225234
{
226235
savedPaymentRequests.append(arg);
@@ -244,6 +253,7 @@ void PaymentServer::ipcParseCommandLine(interfaces::Node& node, int argc, char*
244253
// GUI hasn't started yet so we can't pop up a message box.
245254
qWarning() << "PaymentServer::ipcSendCommandLine: Payment request file does not exist: " << arg;
246255
}
256+
#endif
247257
}
248258
}
249259

@@ -290,12 +300,16 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
290300
QObject(parent),
291301
saveURIs(true),
292302
uriServer(0),
303+
#ifdef ENABLE_BIP70
293304
netManager(0),
305+
#endif
294306
optionsModel(0)
295307
{
308+
#ifdef ENABLE_BIP70
296309
// Verify that the version of the library that we linked against is
297310
// compatible with the version of the headers we compiled against.
298311
GOOGLE_PROTOBUF_VERIFY_VERSION;
312+
#endif
299313

300314
// Install global event filter to catch QFileOpenEvents
301315
// on Mac: sent when you click bitcoin: links
@@ -319,14 +333,18 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
319333
}
320334
else {
321335
connect(uriServer, &QLocalServer::newConnection, this, &PaymentServer::handleURIConnection);
336+
#ifdef ENABLE_BIP70
322337
connect(this, &PaymentServer::receivedPaymentACK, this, &PaymentServer::handlePaymentACK);
338+
#endif
323339
}
324340
}
325341
}
326342

327343
PaymentServer::~PaymentServer()
328344
{
345+
#ifdef ENABLE_BIP70
329346
google::protobuf::ShutdownProtobufLibrary();
347+
#endif
330348
}
331349

332350
//
@@ -349,6 +367,7 @@ bool PaymentServer::eventFilter(QObject *object, QEvent *event)
349367
return QObject::eventFilter(object, event);
350368
}
351369

370+
#ifdef ENABLE_BIP70
352371
void PaymentServer::initNetManager()
353372
{
354373
if (!optionsModel)
@@ -372,10 +391,13 @@ void PaymentServer::initNetManager()
372391
connect(netManager, &QNetworkAccessManager::finished, this, &PaymentServer::netRequestFinished);
373392
connect(netManager, &QNetworkAccessManager::sslErrors, this, &PaymentServer::reportSslErrors);
374393
}
394+
#endif
375395

376396
void PaymentServer::uiReady()
377397
{
398+
#ifdef ENABLE_BIP70
378399
initNetManager();
400+
#endif
379401

380402
saveURIs = false;
381403
for (const QString& s : savedPaymentRequests)
@@ -403,6 +425,7 @@ void PaymentServer::handleURIOrFile(const QString& s)
403425
QUrlQuery uri((QUrl(s)));
404426
if (uri.hasQueryItem("r")) // payment request URI
405427
{
428+
#ifdef ENABLE_BIP70
406429
QByteArray temp;
407430
temp.append(uri.queryItemValue("r"));
408431
QString decoded = QUrl::fromPercentEncoding(temp);
@@ -420,7 +443,11 @@ void PaymentServer::handleURIOrFile(const QString& s)
420443
tr("Payment request fetch URL is invalid: %1").arg(fetchUrl.toString()),
421444
CClientUIInterface::ICON_WARNING);
422445
}
423-
446+
#else
447+
Q_EMIT message(tr("URI handling"),
448+
tr("Cannot process payment request because BIP70 support was not compiled in."),
449+
CClientUIInterface::ICON_WARNING);
450+
#endif
424451
return;
425452
}
426453
else // normal URI
@@ -444,6 +471,7 @@ void PaymentServer::handleURIOrFile(const QString& s)
444471
}
445472
}
446473

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

460488
return;
461489
}
490+
#endif
462491
}
463492

464493
void PaymentServer::handleURIConnection()
@@ -481,6 +510,7 @@ void PaymentServer::handleURIConnection()
481510
handleURIOrFile(msg);
482511
}
483512

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

734765
void PaymentServer::setOptionsModel(OptionsModel *_optionsModel)
735766
{
736767
this->optionsModel = _optionsModel;
737768
}
738769

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

0 commit comments

Comments
 (0)