@@ -509,12 +509,7 @@ bool PaymentServer::readPaymentRequestFromFile(const QString& filename, PaymentR
509
509
}
510
510
511
511
// BIP70 DoS protection
512
- if (f.size () > BIP70_MAX_PAYMENTREQUEST_SIZE) {
513
- qWarning () << QString (" PaymentServer::%1: Payment request %2 is too large (%3 bytes, allowed %4 bytes)." )
514
- .arg (__func__)
515
- .arg (filename)
516
- .arg (f.size ())
517
- .arg (BIP70_MAX_PAYMENTREQUEST_SIZE);
512
+ if (!verifySize (f.size ())) {
518
513
return false ;
519
514
}
520
515
@@ -685,14 +680,13 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
685
680
reply->deleteLater ();
686
681
687
682
// BIP70 DoS protection
688
- if (reply->size () > BIP70_MAX_PAYMENTREQUEST_SIZE) {
689
- QString msg = tr (" Payment request %1 is too large (%2 bytes, allowed %3 bytes)." )
690
- .arg (reply->request ().url ().toString ())
691
- .arg (reply->size ())
692
- .arg (BIP70_MAX_PAYMENTREQUEST_SIZE);
693
-
694
- qWarning () << QString (" PaymentServer::%1:" ).arg (__func__) << msg;
695
- Q_EMIT message (tr (" Payment request DoS protection" ), msg, CClientUIInterface::MSG_ERROR);
683
+ if (!verifySize (reply->size ())) {
684
+ Q_EMIT message (tr (" Payment request rejected" ),
685
+ tr (" Payment request %1 is too large (%2 bytes, allowed %3 bytes)." )
686
+ .arg (reply->request ().url ().toString ())
687
+ .arg (reply->size ())
688
+ .arg (BIP70_MAX_PAYMENTREQUEST_SIZE),
689
+ CClientUIInterface::MSG_ERROR);
696
690
return ;
697
691
}
698
692
@@ -790,6 +784,18 @@ bool PaymentServer::verifyExpired(const payments::PaymentDetails& requestDetails
790
784
return fVerified ;
791
785
}
792
786
787
+ bool PaymentServer::verifySize (qint64 requestSize)
788
+ {
789
+ bool fVerified = (requestSize <= BIP70_MAX_PAYMENTREQUEST_SIZE);
790
+ if (!fVerified ) {
791
+ qWarning () << QString (" PaymentServer::%1: Payment request too large (%2 bytes, allowed %3 bytes)." )
792
+ .arg (__func__)
793
+ .arg (requestSize)
794
+ .arg (BIP70_MAX_PAYMENTREQUEST_SIZE);
795
+ }
796
+ return fVerified ;
797
+ }
798
+
793
799
bool PaymentServer::verifyAmount (const CAmount& requestAmount)
794
800
{
795
801
bool fVerified = MoneyRange (requestAmount);
0 commit comments