Fix sslcrypto thread safety (#2454)
* Use sslcrypto instead of pyelliptic and pybitcointools * Fix CryptMessage * Support Python 3.4 * Fix user creation * Get rid of pyelliptic and pybitcointools * Fix typo * Delete test file * Add sslcrypto to tree * Update sslcrypto * Add pyaes to src/lib * Fix typo in tests * Update sslcrypto version * Use privatekey_bin instead of privatekey for bytes objects * Fix sslcrypto * Fix Benchmark plugin * Don't calculate the same thing twice * Only import sslcrypto once * Handle fallback sslcrypto implementation during tests * Fix sslcrypto fallback implementation selection * Fix thread safety * Add derivation * Bring split back * Fix typo * v3.3 * Fix custom OpenSSL discovery
This commit is contained in:
parent
7ba2c9344d
commit
296e4aab57
57 changed files with 3781 additions and 7306 deletions
39
src/util/Electrum.py
Normal file
39
src/util/Electrum.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import hashlib
|
||||
import struct
|
||||
|
||||
|
||||
# Electrum, the heck?!
|
||||
|
||||
def bchr(i):
|
||||
return struct.pack("B", i)
|
||||
|
||||
def encode(val, base, minlen=0):
|
||||
base, minlen = int(base), int(minlen)
|
||||
code_string = b"".join([bchr(x) for x in range(256)])
|
||||
result = b""
|
||||
while val > 0:
|
||||
index = val % base
|
||||
result = code_string[index:index + 1] + result
|
||||
val //= base
|
||||
return code_string[0:1] * max(minlen - len(result), 0) + result
|
||||
|
||||
def insane_int(x):
|
||||
x = int(x)
|
||||
if x < 253:
|
||||
return bchr(x)
|
||||
elif x < 65536:
|
||||
return bchr(253) + encode(x, 256, 2)[::-1]
|
||||
elif x < 4294967296:
|
||||
return bchr(254) + encode(x, 256, 4)[::-1]
|
||||
else:
|
||||
return bchr(255) + encode(x, 256, 8)[::-1]
|
||||
|
||||
|
||||
def magic(message):
|
||||
return b"\x18Bitcoin Signed Message:\n" + insane_int(len(message)) + message
|
||||
|
||||
def format(message):
|
||||
return hashlib.sha256(magic(message)).digest()
|
||||
|
||||
def dbl_format(message):
|
||||
return hashlib.sha256(format(message)).digest()
|
|
@ -1,13 +1,11 @@
|
|||
import logging
|
||||
import os
|
||||
import sys
|
||||
import ctypes
|
||||
import ctypes.util
|
||||
from ctypes.util import find_library
|
||||
from lib.sslcrypto.openssl import discovery
|
||||
|
||||
from Config import config
|
||||
|
||||
find_library_original = ctypes.util.find_library
|
||||
|
||||
|
||||
def getOpensslPath():
|
||||
if config.openssl_lib_file:
|
||||
|
@ -49,29 +47,11 @@ def getOpensslPath():
|
|||
logging.debug("OpenSSL lib not found in: %s (%s)" % (path, err))
|
||||
|
||||
lib_path = (
|
||||
find_library_original('ssl.so') or find_library_original('ssl') or
|
||||
find_library_original('crypto') or find_library_original('libcrypto') or 'libeay32'
|
||||
find_library('ssl.so') or find_library('ssl') or
|
||||
find_library('crypto') or find_library('libcrypto') or 'libeay32'
|
||||
)
|
||||
|
||||
return lib_path
|
||||
|
||||
|
||||
def patchCtypesOpensslFindLibrary():
|
||||
def findLibraryPatched(name):
|
||||
if name in ("ssl", "crypto", "libeay32"):
|
||||
lib_path = getOpensslPath()
|
||||
return lib_path
|
||||
else:
|
||||
return find_library_original(name)
|
||||
|
||||
ctypes.util.find_library = findLibraryPatched
|
||||
|
||||
|
||||
patchCtypesOpensslFindLibrary()
|
||||
|
||||
|
||||
def openLibrary():
|
||||
lib_path = getOpensslPath()
|
||||
logging.debug("Opening %s..." % lib_path)
|
||||
ssl_lib = ctypes.CDLL(lib_path, ctypes.RTLD_GLOBAL)
|
||||
return ssl_lib
|
||||
discovery.discover = getOpensslPath
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue