Skip to content

Commit bc8535b

Browse files
committed
Merge pull request #5467
6171e49 [Qt] Use identical strings for expired payment request message (Philip Kaufmann) 06087bd [Qt] minor comment updates in PaymentServer (Philip Kaufmann) 35d1595 [Qt] constify first parameter of processPaymentRequest() (Philip Kaufmann) 9b14aef [Qt] take care of a missing typecast in PaymentRequestPlus::getMerchant() (Philip Kaufmann) d19ae3c [Qt] remove unused PaymentRequestPlus::getPKIType function (Philip Kaufmann) 6e17a74 [Qt] paymentserver: better logging of invalid certs (Philip Kaufmann) 5a53d7c [Qt] paymentserver: do not log NULL certificates (Philip Kaufmann)
2 parents 9ab7cbf + 6171e49 commit bc8535b

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

src/qt/paymentrequestplus.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ bool PaymentRequestPlus::IsInitialized() const
5959
return paymentRequest.IsInitialized();
6060
}
6161

62-
QString PaymentRequestPlus::getPKIType() const
63-
{
64-
if (!IsInitialized()) return QString("none");
65-
return QString::fromStdString(paymentRequest.pki_type());
66-
}
67-
6862
bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) const
6963
{
7064
merchant.clear();
@@ -124,7 +118,7 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
124118
// The first cert is the signing cert, the rest are untrusted certs that chain
125119
// to a valid root authority. OpenSSL needs them separately.
126120
STACK_OF(X509) *chain = sk_X509_new_null();
127-
for (int i = certs.size()-1; i > 0; i--) {
121+
for (int i = certs.size() - 1; i > 0; i--) {
128122
sk_X509_push(chain, certs[i]);
129123
}
130124
X509 *signing_cert = certs[0];
@@ -172,9 +166,8 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
172166
EVP_MD_CTX_init(&ctx);
173167
if (!EVP_VerifyInit_ex(&ctx, digestAlgorithm, NULL) ||
174168
!EVP_VerifyUpdate(&ctx, data_to_verify.data(), data_to_verify.size()) ||
175-
!EVP_VerifyFinal(&ctx, (const unsigned char*)paymentRequest.signature().data(), paymentRequest.signature().size(), pubkey)) {
176-
177-
throw SSLVerifyError("Bad signature, invalid PaymentRequest.");
169+
!EVP_VerifyFinal(&ctx, (const unsigned char*)paymentRequest.signature().data(), (unsigned int)paymentRequest.signature().size(), pubkey)) {
170+
throw SSLVerifyError("Bad signature, invalid payment request.");
178171
}
179172

180173
// OpenSSL API for getting human printable strings from certs is baroque.

src/qt/paymentrequestplus.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class PaymentRequestPlus
2929
bool SerializeToString(std::string* output) const;
3030

3131
bool IsInitialized() const;
32-
QString getPKIType() const;
3332
// Returns true if merchant's identity is authenticated, and
3433
// returns human-readable merchant identity in merchant
3534
bool getMerchant(X509_STORE* certStore, QString& merchant) const;

src/qt/paymentserver.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ static QList<QString> savedPaymentRequests;
9797

9898
static void ReportInvalidCertificate(const QSslCertificate& cert)
9999
{
100-
qDebug() << "ReportInvalidCertificate: Payment server found an invalid certificate: " << cert.subjectInfo(QSslCertificate::CommonName);
100+
#if QT_VERSION < 0x050000
101+
qDebug() << QString("%1: Payment server found an invalid certificate: ").arg(__func__) << cert.serialNumber() << cert.subjectInfo(QSslCertificate::CommonName) << cert.subjectInfo(QSslCertificate::OrganizationalUnitName);
102+
#else
103+
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);
104+
#endif
101105
}
102106

103107
//
@@ -143,13 +147,20 @@ void PaymentServer::LoadRootCAs(X509_STORE* _store)
143147

144148
int nRootCerts = 0;
145149
const QDateTime currentTime = QDateTime::currentDateTime();
146-
foreach (const QSslCertificate& cert, certList)
147-
{
150+
151+
foreach (const QSslCertificate& cert, certList) {
152+
// Don't log NULL certificates
153+
if (cert.isNull())
154+
continue;
155+
156+
// Not yet active/valid, or expired certificate
148157
if (currentTime < cert.effectiveDate() || currentTime > cert.expiryDate()) {
149158
ReportInvalidCertificate(cert);
150159
continue;
151160
}
161+
152162
#if QT_VERSION >= 0x050000
163+
// Blacklisted certificate
153164
if (cert.isBlacklisted()) {
154165
ReportInvalidCertificate(cert);
155166
continue;
@@ -301,7 +312,7 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
301312

302313
// Install global event filter to catch QFileOpenEvents
303314
// on Mac: sent when you click bitcoin: links
304-
// other OSes: helpful when dealing with payment request files (in the future)
315+
// other OSes: helpful when dealing with payment request files
305316
if (parent)
306317
parent->installEventFilter(this);
307318

@@ -332,14 +343,13 @@ PaymentServer::~PaymentServer()
332343
}
333344

334345
//
335-
// OSX-specific way of handling bitcoin: URIs and
336-
// PaymentRequest mime types
346+
// OSX-specific way of handling bitcoin: URIs and PaymentRequest mime types.
347+
// Also used by paymentservertests.cpp and when opening a payment request file
348+
// via "Open URI..." menu entry.
337349
//
338350
bool PaymentServer::eventFilter(QObject *object, QEvent *event)
339351
{
340-
// clicking on bitcoin: URIs creates FileOpen events on the Mac
341-
if (event->type() == QEvent::FileOpen)
342-
{
352+
if (event->type() == QEvent::FileOpen) {
343353
QFileOpenEvent *fileEvent = static_cast<QFileOpenEvent*>(event);
344354
if (!fileEvent->file().isEmpty())
345355
handleURIOrFile(fileEvent->file());
@@ -515,7 +525,7 @@ bool PaymentServer::readPaymentRequestFromFile(const QString& filename, PaymentR
515525
return request.parse(data);
516526
}
517527

518-
bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient)
528+
bool PaymentServer::processPaymentRequest(const PaymentRequestPlus& request, SendCoinsRecipient& recipient)
519529
{
520530
if (!optionsModel)
521531
return false;
@@ -560,9 +570,9 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins
560570
addresses.append(QString::fromStdString(CBitcoinAddress(dest).ToString()));
561571
}
562572
else if (!recipient.authenticatedMerchant.isEmpty()) {
563-
// Insecure payments to custom bitcoin addresses are not supported
564-
// (there is no good way to tell the user where they are paying in a way
565-
// they'd have a chance of understanding).
573+
// Unauthenticated payment requests to custom bitcoin addresses are not supported
574+
// (there is no good way to tell the user where they are paying in a way they'd
575+
// have a chance of understanding).
566576
emit message(tr("Payment request rejected"),
567577
tr("Unverified payment requests to custom payment scripts are unsupported."),
568578
CClientUIInterface::MSG_ERROR);

src/qt/paymentserver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private slots:
131131
bool eventFilter(QObject *object, QEvent *event);
132132

133133
private:
134-
bool processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient);
134+
bool processPaymentRequest(const PaymentRequestPlus& request, SendCoinsRecipient& recipient);
135135
void fetchRequest(const QUrl& url);
136136

137137
// Setup networking

src/qt/sendcoinsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ void SendCoinsDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn
531531
msgParams.first = tr("A fee higher than %1 is considered an absurdly high fee.").arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), 10000000));
532532
break;
533533
case WalletModel::PaymentRequestExpired:
534-
msgParams.first = tr("Payment request expired!");
534+
msgParams.first = tr("Payment request expired.");
535535
msgParams.second = CClientUIInterface::MSG_ERROR;
536536
break;
537537
// included to prevent a compiler warning.

0 commit comments

Comments
 (0)