Skip to content

Commit e024b05

Browse files
Disable BIP-70 payment server by default
This commit adds a configuration option, `enable-bip70`, to enable this feature. Only enable this if you know what you're doing. Please note that BIP-21 payment links continue to work. Co-authored-by: Old Dip Tracker <[email protected]>
1 parent 2e71121 commit e024b05

File tree

5 files changed

+66
-16
lines changed

5 files changed

+66
-16
lines changed

Diff for: src/init.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ std::string HelpMessage(HelpMessageMode mode)
373373
strUsage += HelpMessageOpt("-discover", _("Discover own IP addresses (default: 1 when listening and no -externalip or -proxy)"));
374374
strUsage += HelpMessageOpt("-dns", _("Allow DNS lookups for -addnode, -seednode and -connect") + " " + strprintf(_("(default: %u)"), DEFAULT_NAME_LOOKUP));
375375
strUsage += HelpMessageOpt("-dnsseed", _("Query for peer addresses via DNS lookup, if low on addresses (default: 1 unless -connect/-noconnect)"));
376+
strUsage += HelpMessageOpt("-enable-bip70", _("Enable BIP-70 PaymentServer (default: 0)"));
376377
strUsage += HelpMessageOpt("-externalip=<ip>", _("Specify your own public address"));
377378
strUsage += HelpMessageOpt("-forcednsseed", strprintf(_("Always query for peer addresses via DNS lookup (default: %u)"), DEFAULT_FORCEDNSSEED));
378379
strUsage += HelpMessageOpt("-listen", _("Accept connections from outside (default: 1 if no -proxy or -connect/-noconnect)"));

Diff for: src/qt/bitcoin.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ BitcoinApplication::~BitcoinApplication()
368368
#ifdef ENABLE_WALLET
369369
void BitcoinApplication::createPaymentServer()
370370
{
371-
paymentServer = new PaymentServer(this);
371+
paymentServer = new PaymentServer(this, true, GetBoolArg("-enable-bip70", false));
372372
}
373373
#endif
374374

@@ -466,10 +466,6 @@ void BitcoinApplication::initializeResult(int retval)
466466
{
467467
// Log this only after AppInit2 finishes, as then logging setup is guaranteed complete
468468
qWarning() << "Platform customization:" << platformStyle->getName();
469-
#ifdef ENABLE_WALLET
470-
PaymentServer::LoadRootCAs();
471-
paymentServer->setOptionsModel(optionsModel);
472-
#endif
473469

474470
clientModel = new ClientModel(optionsModel);
475471
window->setClientModel(clientModel);
@@ -481,9 +477,6 @@ void BitcoinApplication::initializeResult(int retval)
481477

482478
window->addWallet(BitcoinGUI::DEFAULT_WALLET, walletModel);
483479
window->setCurrentWallet(BitcoinGUI::DEFAULT_WALLET);
484-
485-
connect(walletModel, SIGNAL(coinsSent(CWallet*,SendCoinsRecipient,QByteArray)),
486-
paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray)));
487480
}
488481
#endif
489482

@@ -499,10 +492,21 @@ void BitcoinApplication::initializeResult(int retval)
499492
Q_EMIT splashFinished(window);
500493

501494
#ifdef ENABLE_WALLET
495+
paymentServer->setOptionsModel(optionsModel);
496+
497+
if(GetBoolArg("-enable-bip70", false))
498+
{
499+
PaymentServer::LoadRootCAs();
500+
if(pwalletMain)
501+
connect(walletModel, SIGNAL(coinsSent(CWallet*,SendCoinsRecipient,QByteArray)),
502+
paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray)));
503+
}
504+
502505
// Now that initialization/startup is done, process any command-line
503-
// bitcoin: URIs or payment requests:
506+
// payment requests:
504507
connect(paymentServer, SIGNAL(receivedPaymentRequest(SendCoinsRecipient)),
505-
window, SLOT(handlePaymentRequest(SendCoinsRecipient)));
508+
window, SLOT(handlePaymentRequest(SendCoinsRecipient)));
509+
// Now that initialization/startup is done, process any command-line bitcoin: URIs
506510
connect(window, SIGNAL(receivedURI(QString)),
507511
paymentServer, SLOT(handleURIOrFile(QString)));
508512
connect(paymentServer, SIGNAL(message(QString,QString,unsigned int)),

Diff for: src/qt/paymentserver.cpp

+46-4
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,11 @@ bool PaymentServer::ipcSendCommandLine()
298298
return fResult;
299299
}
300300

301-
void PaymentServer::initializeServer(QObject* parent, QString ipcServerName, bool startLocalServer) {
301+
void PaymentServer::initializeServer(QObject* parent, QString ipcServerName, bool startLocalServer, bool enableBip70) {
302302
// Verify that the version of the library that we linked against is
303303
// compatible with the version of the headers we compiled against.
304304
GOOGLE_PROTOBUF_VERIFY_VERSION;
305+
this->enableBip70 = enableBip70;
305306

306307
// Install global event filter to catch QFileOpenEvents
307308
// on Mac: sent when you click bitcoin: links
@@ -332,7 +333,18 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
332333
netManager(0),
333334
optionsModel(0)
334335
{
335-
this->initializeServer(parent, ipcServerName(), startLocalServer);
336+
this->initializeServer(parent, ipcServerName(), startLocalServer, false);
337+
}
338+
339+
340+
PaymentServer::PaymentServer(QObject* parent, bool startLocalServer, bool enableBip70) :
341+
QObject(parent),
342+
saveURIs(true),
343+
uriServer(0),
344+
netManager(0),
345+
optionsModel(0)
346+
{
347+
this->initializeServer(parent, ipcServerName(), startLocalServer, enableBip70);
336348
}
337349

338350

@@ -343,7 +355,18 @@ PaymentServer::PaymentServer(QObject* parent, QString ipcServerName, bool startL
343355
netManager(0),
344356
optionsModel(0)
345357
{
346-
this->initializeServer(parent, ipcServerName, startLocalServer);
358+
this->initializeServer(parent, ipcServerName, startLocalServer, false);
359+
}
360+
361+
362+
PaymentServer::PaymentServer(QObject* parent, QString ipcServerName, bool startLocalServer, bool enableBip70Flag) :
363+
QObject(parent),
364+
saveURIs(true),
365+
uriServer(0),
366+
netManager(0),
367+
optionsModel(0)
368+
{
369+
this->initializeServer(parent, ipcServerName, startLocalServer, enableBip70Flag);
347370
}
348371

349372
PaymentServer::~PaymentServer()
@@ -427,6 +450,15 @@ void PaymentServer::handleURIOrFile(const QString& s)
427450
#endif
428451
if (uri.hasQueryItem("r")) // payment request URI
429452
{
453+
if (!enableBip70) {
454+
qDebug() << "PaymentServer::handleURIOrFile: 'r' item supplied but BIP70 disabled.";
455+
Q_EMIT message(tr("URI handling"), tr(
456+
"BIP70 payment requests are deprecated and disabled by default."
457+
"Restart with -enable-bip70 if you absolutely have to use this functionality.\n\n"
458+
"Use this functionality with extreme caution."),
459+
CClientUIInterface::MSG_ERROR);
460+
return;
461+
}
430462
QByteArray temp;
431463
temp.append(uri.queryItemValue("r"));
432464
QString decoded = QUrl::fromPercentEncoding(temp);
@@ -469,7 +501,17 @@ void PaymentServer::handleURIOrFile(const QString& s)
469501
}
470502
}
471503

472-
if (QFile::exists(s)) // payment request file
504+
// payment request file
505+
if (!enableBip70) {
506+
Q_EMIT message(tr("Payment request file handling"), tr(
507+
"Payment request file handling is disabled by default."
508+
"Restart with -enable-bip70 if you absolutely have to use this functionality.\n\n"
509+
"Use this functionality with extreme caution."),
510+
CClientUIInterface::MSG_ERROR);
511+
return;
512+
}
513+
514+
if (QFile::exists(s))
473515
{
474516
PaymentRequestPlus request;
475517
SendCoinsRecipient recipient;

Diff for: src/qt/paymentserver.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ class PaymentServer : public QObject
7373

7474
// parent should be QApplication object
7575
PaymentServer(QObject* parent, bool startLocalServer = true);
76+
PaymentServer(QObject* parent, bool startLocalServer = true, bool enableBip70Flag = false);
7677
PaymentServer(QObject* parent, QString ipcServerName, bool startLocalServer = true);
78+
PaymentServer(QObject* parent, QString ipcServerName, bool startLocalServer = true, bool enableBip70Flag = false);
7779
~PaymentServer();
7880

7981
// Load root certificate authorities. Pass NULL (default)
@@ -140,7 +142,8 @@ private Q_SLOTS:
140142

141143
bool saveURIs; // true during startup
142144

143-
void initializeServer(QObject* parent, QString ipcServerName, bool startLocalServer);
145+
void initializeServer(QObject* parent, QString ipcServerName, bool startLocalServer, bool enableBip70Flag);
146+
bool enableBip70; // false by default
144147
QLocalServer* uriServer;
145148

146149
QNetworkAccessManager* netManager; // Used to fetch payment requests

Diff for: src/qt/test/paymentservertests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void PaymentServerTests::paymentServerTests()
6767
{
6868
SelectParams(CBaseChainParams::MAIN);
6969
OptionsModel optionsModel;
70-
PaymentServer* server = new PaymentServer(NULL, QString("testIPCServer"), false);
70+
PaymentServer* server = new PaymentServer(NULL, QString("testIPCServer"), false, true);
7171
X509_STORE* caStore = X509_STORE_new();
7272
X509_STORE_add_cert(caStore, parse_b64der_cert(caCert1_BASE64));
7373
PaymentServer::LoadRootCAs(caStore);

0 commit comments

Comments
 (0)