mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 17:01:34 +00:00
parse PEM list using tlslite
This commit is contained in:
parent
b973d31a67
commit
58d2e90fa5
2 changed files with 20 additions and 36 deletions
|
@ -43,42 +43,8 @@ import x509
|
||||||
REQUEST_HEADERS = {'Accept': 'application/bitcoin-paymentrequest', 'User-Agent': 'Electrum'}
|
REQUEST_HEADERS = {'Accept': 'application/bitcoin-paymentrequest', 'User-Agent': 'Electrum'}
|
||||||
ACK_HEADERS = {'Content-Type':'application/bitcoin-payment','Accept':'application/bitcoin-paymentack','User-Agent':'Electrum'}
|
ACK_HEADERS = {'Content-Type':'application/bitcoin-payment','Accept':'application/bitcoin-paymentack','User-Agent':'Electrum'}
|
||||||
|
|
||||||
|
|
||||||
ca_list = {}
|
|
||||||
ca_path = requests.certs.where()
|
ca_path = requests.certs.where()
|
||||||
|
ca_list = x509.load_certificates(ca_path)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def load_certificates():
|
|
||||||
try:
|
|
||||||
ca_f = open(ca_path, 'r')
|
|
||||||
except Exception:
|
|
||||||
print "ERROR: Could not open %s"%ca_path
|
|
||||||
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 "Payment will continue with manual verification."
|
|
||||||
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.X509()
|
|
||||||
try:
|
|
||||||
x.parse(c)
|
|
||||||
except Exception as e:
|
|
||||||
util.print_error("cannot parse cert:", e)
|
|
||||||
continue
|
|
||||||
ca_list[x.getFingerprint()] = x
|
|
||||||
ca_f.close()
|
|
||||||
util.print_error("%d certificates"%len(ca_list))
|
|
||||||
return True
|
|
||||||
|
|
||||||
load_certificates()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PaymentRequest:
|
class PaymentRequest:
|
||||||
|
@ -325,7 +291,6 @@ class PaymentRequest:
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
util.set_verbosity(True)
|
util.set_verbosity(True)
|
||||||
load_certificates()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
uri = sys.argv[1]
|
uri = sys.argv[1]
|
||||||
|
|
19
lib/x509.py
19
lib/x509.py
|
@ -23,6 +23,7 @@ import sys
|
||||||
import pyasn1
|
import pyasn1
|
||||||
import pyasn1_modules
|
import pyasn1_modules
|
||||||
import tlslite
|
import tlslite
|
||||||
|
import util
|
||||||
|
|
||||||
# workaround https://github.com/trevp/tlslite/issues/15
|
# workaround https://github.com/trevp/tlslite/issues/15
|
||||||
tlslite.utils.cryptomath.pycryptoLoaded = False
|
tlslite.utils.cryptomath.pycryptoLoaded = False
|
||||||
|
@ -224,3 +225,21 @@ class X509(tlslite.X509):
|
||||||
|
|
||||||
class X509CertChain(tlslite.X509CertChain):
|
class X509CertChain(tlslite.X509CertChain):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def load_certificates(ca_path):
|
||||||
|
ca_list = {}
|
||||||
|
with open(ca_path, 'r') as f:
|
||||||
|
s = f.read()
|
||||||
|
bList = tlslite.utils.pem.dePemList(s, "CERTIFICATE")
|
||||||
|
for b in bList:
|
||||||
|
x = X509()
|
||||||
|
try:
|
||||||
|
x.parseBinary(b)
|
||||||
|
except Exception as e:
|
||||||
|
util.print_error("cannot parse cert:", e)
|
||||||
|
continue
|
||||||
|
ca_list[x.getFingerprint()] = x
|
||||||
|
return ca_list
|
||||||
|
|
Loading…
Add table
Reference in a new issue