5
5
#include " paymentserver.h"
6
6
7
7
#include " bitcoinunits.h"
8
- #include " guiconstants.h"
9
8
#include " guiutil.h"
10
9
#include " optionsmodel.h"
11
10
19
18
20
19
#include < openssl/x509.h>
21
20
#include < openssl/x509_vfy.h>
21
+
22
22
#include < QApplication>
23
23
#include < QByteArray>
24
24
#include < QDataStream>
@@ -51,9 +51,15 @@ using namespace boost;
51
51
52
52
const int BITCOIN_IPC_CONNECT_TIMEOUT = 1000 ; // milliseconds
53
53
const QString BITCOIN_IPC_PREFIX (" bitcoin:" );
54
- const char * BITCOIN_REQUEST_MIMETYPE = " application/bitcoin-paymentrequest" ;
55
- const char * BITCOIN_PAYMENTACK_MIMETYPE = " application/bitcoin-paymentack" ;
56
- const char * BITCOIN_PAYMENTACK_CONTENTTYPE = " application/bitcoin-payment" ;
54
+ // BIP70 payment protocol messages
55
+ const char * BIP70_MESSAGE_PAYMENTACK = " PaymentACK" ;
56
+ const char * BIP70_MESSAGE_PAYMENTREQUEST = " PaymentRequest" ;
57
+ // BIP71 payment protocol media types
58
+ const char * BIP71_MIMETYPE_PAYMENT = " application/bitcoin-payment" ;
59
+ const char * BIP71_MIMETYPE_PAYMENTACK = " application/bitcoin-paymentack" ;
60
+ const char * BIP71_MIMETYPE_PAYMENTREQUEST = " application/bitcoin-paymentrequest" ;
61
+ // BIP70 max payment request size in bytes (DoS protection)
62
+ const qint64 BIP70_MAX_PAYMENTREQUEST_SIZE = 50000 ;
57
63
58
64
X509_STORE* PaymentServer::certStore = NULL ;
59
65
void PaymentServer::freeCertStore ()
@@ -486,7 +492,7 @@ bool PaymentServer::readPaymentRequest(const QString& filename, PaymentRequestPl
486
492
return false ;
487
493
}
488
494
489
- if (f.size () > MAX_PAYMENT_REQUEST_SIZE )
495
+ if (f.size () > BIP70_MAX_PAYMENTREQUEST_SIZE )
490
496
{
491
497
qWarning () << " PaymentServer::readPaymentRequest : " << filename << " too large" ;
492
498
return false ;
@@ -583,10 +589,10 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins
583
589
void PaymentServer::fetchRequest (const QUrl& url)
584
590
{
585
591
QNetworkRequest netRequest;
586
- netRequest.setAttribute (QNetworkRequest::User, " PaymentRequest " );
592
+ netRequest.setAttribute (QNetworkRequest::User, BIP70_MESSAGE_PAYMENTREQUEST );
587
593
netRequest.setUrl (url);
588
594
netRequest.setRawHeader (" User-Agent" , CLIENT_NAME.c_str ());
589
- netRequest.setRawHeader (" Accept" , BITCOIN_REQUEST_MIMETYPE );
595
+ netRequest.setRawHeader (" Accept" , BIP71_MIMETYPE_PAYMENTREQUEST );
590
596
netManager->get (netRequest);
591
597
}
592
598
@@ -597,11 +603,11 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipien
597
603
return ;
598
604
599
605
QNetworkRequest netRequest;
600
- netRequest.setAttribute (QNetworkRequest::User, " PaymentACK " );
606
+ netRequest.setAttribute (QNetworkRequest::User, BIP70_MESSAGE_PAYMENTACK );
601
607
netRequest.setUrl (QString::fromStdString (details.payment_url ()));
602
- netRequest.setHeader (QNetworkRequest::ContentTypeHeader, BITCOIN_PAYMENTACK_CONTENTTYPE );
608
+ netRequest.setHeader (QNetworkRequest::ContentTypeHeader, BIP71_MIMETYPE_PAYMENT );
603
609
netRequest.setRawHeader (" User-Agent" , CLIENT_NAME.c_str ());
604
- netRequest.setRawHeader (" Accept" , BITCOIN_PAYMENTACK_MIMETYPE );
610
+ netRequest.setRawHeader (" Accept" , BIP71_MIMETYPE_PAYMENTACK );
605
611
606
612
payments::Payment payment;
607
613
payment.set_merchant_data (details.merchant_data ());
@@ -663,7 +669,7 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
663
669
QByteArray data = reply->readAll ();
664
670
665
671
QString requestType = reply->request ().attribute (QNetworkRequest::User).toString ();
666
- if (requestType == " PaymentRequest " )
672
+ if (requestType == BIP70_MESSAGE_PAYMENTREQUEST )
667
673
{
668
674
PaymentRequestPlus request;
669
675
SendCoinsRecipient recipient;
@@ -679,7 +685,7 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
679
685
680
686
return ;
681
687
}
682
- else if (requestType == " PaymentACK " )
688
+ else if (requestType == BIP70_MESSAGE_PAYMENTACK )
683
689
{
684
690
payments::PaymentACK paymentACK;
685
691
if (!paymentACK.ParseFromArray (data.data (), data.size ()))
0 commit comments