Skip to content

Commit 4333e26

Browse files
author
Philip Kaufmann
committed
[Qt] add BIP70 DoS protection test
- this test required to make readPaymentRequestFromFile() public in order to be able to is it in paymentservertests.cpp
1 parent 31f8494 commit 4333e26

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/qt/paymentserver.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ QT_END_NAMESPACE
5252

5353
class CWallet;
5454

55+
// BIP70 max payment request size in bytes (DoS protection)
56+
extern const qint64 BIP70_MAX_PAYMENTREQUEST_SIZE;
57+
5558
class PaymentServer : public QObject
5659
{
5760
Q_OBJECT
@@ -85,6 +88,9 @@ class PaymentServer : public QObject
8588
// OptionsModel is used for getting proxy settings and display unit
8689
void setOptionsModel(OptionsModel *optionsModel);
8790

91+
// This is now public, because we use it in paymentservertests.cpp
92+
static bool readPaymentRequestFromFile(const QString& filename, PaymentRequestPlus& request);
93+
8894
signals:
8995
// Fired when a valid payment request is received
9096
void receivedPaymentRequest(SendCoinsRecipient);
@@ -118,7 +124,6 @@ private slots:
118124
bool eventFilter(QObject *object, QEvent *event);
119125

120126
private:
121-
static bool readPaymentRequestFromFile(const QString& filename, PaymentRequestPlus& request);
122127
bool processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient);
123128
void fetchRequest(const QUrl& url);
124129

src/qt/test/paymentservertests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "optionsmodel.h"
88
#include "paymentrequestdata.h"
99

10+
#include "random.h"
1011
#include "util.h"
1112
#include "utilstrencodings.h"
1213

@@ -108,6 +109,17 @@ void PaymentServerTests::paymentServerTests()
108109
r.paymentRequest.getMerchant(caStore, merchant);
109110
QCOMPARE(merchant, QString(""));
110111

112+
// Just get some random data big enough to trigger BIP70 DoS protection
113+
unsigned char randData[BIP70_MAX_PAYMENTREQUEST_SIZE + 1];
114+
GetRandBytes(randData, sizeof(randData));
115+
// Write data to a temp file:
116+
QTemporaryFile tempFile;
117+
tempFile.open();
118+
tempFile.write((const char*)randData, sizeof(randData));
119+
tempFile.close();
120+
// Trigger BIP70 DoS protection
121+
QCOMPARE(PaymentServer::readPaymentRequestFromFile(tempFile.fileName(), r.paymentRequest), false);
122+
111123
delete server;
112124
}
113125

0 commit comments

Comments
 (0)