store payment requests even if M2Crypto is not available

This commit is contained in:
ThomasV 2014-06-07 11:11:49 +02:00
parent 513f9c2d89
commit 14dfa6f5b0
1 changed files with 46 additions and 26 deletions

View File

@ -14,15 +14,15 @@ except:
print "protoc --proto_path=lib/ --python_out=lib/ lib/paymentrequest.proto" print "protoc --proto_path=lib/ --python_out=lib/ lib/paymentrequest.proto"
raise Exception() raise Exception()
try:
import requests
except ImportError:
sys.exit("Error: requests does not seem to be installed. Try 'sudo pip install requests'")
import urlparse import urlparse
import requests
from M2Crypto import X509
import bitcoin import bitcoin
from bitcoin import is_valid
import urlparse
import util import util
import transaction import transaction
@ -39,29 +39,40 @@ PR_PAID = 3 # send and propagated
ca_path = os.path.expanduser("~/.electrum/ca/ca-bundle.crt")
ca_list = {} ca_list = {}
try:
with open(ca_path, 'r') as ca_f: def load_certificates():
c = "" try:
for line in ca_f: from M2Crypto import X509
if line == "-----BEGIN CERTIFICATE-----\n": except:
c = line print_error("ERROR: Could not import M2Crypto")
else: return False
c += line
if line == "-----END CERTIFICATE-----\n": ca_path = os.path.expanduser("~/.electrum/ca/ca-bundle.crt")
x = X509.load_cert_string(c) try:
ca_list[x.get_fingerprint()] = x ca_f = open(ca_path, 'r')
except Exception: except Exception:
print "ERROR: Could not open %s"%ca_path print "ERROR: Could not open %s"%ca_path
print "ca-bundle.crt file should be placed in ~/.electrum/ca/ca-bundle.crt" print "ca-bundle.crt file should be placed in ~/.electrum/ca/ca-bundle.crt"
print "Documentation on how to download or create the file here: http://curl.haxx.se/docs/caextract.html" print "Documentation on how to download or create the file here: http://curl.haxx.se/docs/caextract.html"
print "Payment will continue with manual verification." print "Payment will continue with manual verification."
raise Exception() return False
c = ""
for line in ca_f:
if line == "-----BEGIN CERTIFICATE-----\n":
c = line
else:
c += line
if line == "-----END CERTIFICATE-----\n":
x = X509.load_cert_string(c)
ca_list[x.get_fingerprint()] = x
ca_f.close()
return True
load_certificates()
class PaymentRequest: class PaymentRequest:
def __init__(self, config): def __init__(self, config):
self.config = config self.config = config
self.outputs = [] self.outputs = []
@ -72,7 +83,6 @@ class PaymentRequest:
u = urlparse.urlparse(url) u = urlparse.urlparse(url)
self.domain = u.netloc self.domain = u.netloc
try: try:
connection = httplib.HTTPConnection(u.netloc) if u.scheme == 'http' else httplib.HTTPSConnection(u.netloc) connection = httplib.HTTPConnection(u.netloc) if u.scheme == 'http' else httplib.HTTPSConnection(u.netloc)
connection.request("GET",u.geturl(), headers=REQUEST_HEADERS) connection.request("GET",u.geturl(), headers=REQUEST_HEADERS)
@ -107,6 +117,16 @@ class PaymentRequest:
def verify(self): def verify(self):
try:
from M2Crypto import X509
except:
self.error = "cannot import M2Crypto"
return False
if not ca_list:
self.error = "Trusted certificate authorities list not found"
return False
paymntreq = self.data paymntreq = self.data
sig = paymntreq.signature sig = paymntreq.signature
if not sig: if not sig: