Browse Source

qml: actually do the x509 validation for bip70

as in other GUIs
master
SomberNight 3 years ago
parent
commit
02a2f02d02
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 23
      electrum/gui/qml/qeinvoice.py
  2. 1
      electrum/paymentrequest.py

23
electrum/gui/qml/qeinvoice.py

@ -1,5 +1,5 @@
import threading
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional
import asyncio
from urllib.parse import urlparse
@ -50,7 +50,7 @@ class QEInvoice(QObject):
def __init__(self, parent=None):
super().__init__(parent)
self._wallet = None
self._wallet = None # type: Optional[QEWallet]
self._canSave = False
self._canPay = False
self._key = None
@ -134,7 +134,7 @@ class QEInvoiceParser(QEInvoice):
lnurlRetrieved = pyqtSignal()
lnurlError = pyqtSignal([str,str], arguments=['code', 'message'])
_bip70PrResolvedSignal = pyqtSignal([PaymentRequest], arguments=['request'])
_bip70PrResolvedSignal = pyqtSignal([PaymentRequest], arguments=['pr'])
def __init__(self, parent=None):
super().__init__(parent)
@ -371,12 +371,19 @@ class QEInvoiceParser(QEInvoice):
URI=uri
)
def _bip70_payment_request_resolved(self, request: 'PaymentRequest'):
def _bip70_payment_request_resolved(self, pr: 'PaymentRequest'):
self._logger.debug('resolved payment request')
outputs = request.get_outputs()
invoice = self.create_onchain_invoice(outputs, None, request, None)
self.setValidOnchainInvoice(invoice)
self.validationSuccess.emit()
if pr.verify(self._wallet.wallet.contacts):
invoice = Invoice.from_bip70_payreq(pr, height=0)
if self._wallet.wallet.get_invoice_status(invoice) == PR_PAID:
self.validationError.emit('unknown', _('Invoice already paid'))
elif pr.has_expired():
self.validationError.emit('unknown', _('Payment request has expired'))
else:
self.setValidOnchainInvoice(invoice)
self.validationSuccess.emit()
else:
self.validationError.emit('unknown', f"invoice error:\n{pr.error}")
def validateRecipient(self, recipient):
if not recipient:

1
electrum/paymentrequest.py

@ -152,6 +152,7 @@ class PaymentRequest:
self.payment_url = self.details.payment_url
def verify(self, contacts):
# FIXME: we should enforce that this method was called before we attempt payment
if self.error:
return False
if not self.raw:

Loading…
Cancel
Save