Rev2130, Use SslPatch to load openssl library, Fix Android 6 openssl loading
This commit is contained in:
parent
ebbe19131b
commit
f30b2b6fc2
4 changed files with 43 additions and 49 deletions
|
@ -10,7 +10,7 @@ class Config(object):
|
|||
|
||||
def __init__(self, argv):
|
||||
self.version = "0.5.6"
|
||||
self.rev = 2128
|
||||
self.rev = 2130
|
||||
self.argv = argv
|
||||
self.action = None
|
||||
self.config_file = "zeronet.conf"
|
||||
|
|
|
@ -194,24 +194,15 @@ ssl = None
|
|||
|
||||
def openLibrary():
|
||||
global ssl
|
||||
try:
|
||||
if sys.platform.startswith("win"):
|
||||
dll_path = os.path.dirname(os.path.abspath(__file__)) + "/" + "libeay32.dll"
|
||||
elif sys.platform == "cygwin":
|
||||
dll_path = "/bin/cygcrypto-1.0.0.dll"
|
||||
elif os.path.isfile("../lib/libcrypto.so"): # ZeroBundle OSX
|
||||
dll_path = "../lib/libcrypto.so"
|
||||
elif os.path.isfile("/opt/lib/libcrypto.so.1.0.0"): # For optware and entware
|
||||
dll_path = "/opt/lib/libcrypto.so.1.0.0"
|
||||
else:
|
||||
dll_path = "/usr/local/ssl/lib/libcrypto.so"
|
||||
ssl = _OpenSSL(dll_path)
|
||||
assert ssl
|
||||
except Exception, err:
|
||||
ssl = _OpenSSL(ctypes.util.find_library('ssl.so.1.0') or ctypes.util.find_library('ssl') or ctypes.util.find_library('crypto') or ctypes.util.find_library('libcrypto') or 'libeay32')
|
||||
import util.SslPatch
|
||||
ssl = _OpenSSL(util.SslPatch.getLibraryPath())
|
||||
logging.debug("opensslVerify loaded: %s", ssl._lib)
|
||||
|
||||
openLibrary()
|
||||
if __name__ == "__main__":
|
||||
ssl = _OpenSSL(sys.argv[1])
|
||||
else:
|
||||
openLibrary()
|
||||
|
||||
openssl_version = "%.9X" % ssl._lib.SSLeay()
|
||||
|
||||
NID_secp256k1 = 714
|
||||
|
@ -461,4 +452,4 @@ if __name__ == "__main__":
|
|||
for i in range(1000):
|
||||
pubkey = getMessagePubkey("hello", sign)
|
||||
verified = btctools.pubkey_to_address(pubkey) == address
|
||||
print "100x Verified", verified, time.time() - s
|
||||
print "1000x Verified", verified, time.time() - s
|
||||
|
|
|
@ -496,21 +496,9 @@ class _OpenSSL:
|
|||
|
||||
def loadOpenSSL():
|
||||
import logging
|
||||
import util.SslPatch
|
||||
global OpenSSL
|
||||
try:
|
||||
if sys.platform.startswith("win"):
|
||||
dll_path = os.path.normpath(os.path.dirname(__file__) + "/../opensslVerify/" + "libeay32.dll")
|
||||
elif sys.platform == "cygwin":
|
||||
dll_path = "/bin/cygcrypto-1.0.0.dll"
|
||||
elif os.path.isfile("../lib/libcrypto.so"): # ZeroBundle OSX
|
||||
dll_path = "../lib/libcrypto.so"
|
||||
else:
|
||||
dll_path = "/usr/local/ssl/lib/libcrypto.so"
|
||||
ssl = _OpenSSL(dll_path)
|
||||
assert ssl
|
||||
except Exception, err:
|
||||
ssl = _OpenSSL(ctypes.util.find_library('ssl.so.1.0') or ctypes.util.find_library('ssl') or ctypes.util.find_library('crypto') or ctypes.util.find_library('libcrypto') or 'libeay32')
|
||||
OpenSSL = ssl
|
||||
logging.debug("pyelliptic loaded: %s", ssl._lib)
|
||||
OpenSSL = _OpenSSL(util.SslPatch.getLibraryPath())
|
||||
logging.debug("pyelliptic loaded: %s", OpenSSL._lib)
|
||||
|
||||
loadOpenSSL()
|
||||
|
|
|
@ -4,31 +4,46 @@
|
|||
import logging
|
||||
import os
|
||||
import sys
|
||||
import ctypes
|
||||
import ctypes.util
|
||||
|
||||
from Config import config
|
||||
|
||||
|
||||
def openLibrary():
|
||||
import ctypes
|
||||
import ctypes.util
|
||||
try:
|
||||
def getLibraryPath():
|
||||
if sys.platform.startswith("win"):
|
||||
dll_path = "src/lib/opensslVerify/libeay32.dll"
|
||||
lib_path = os.path.dirname(os.path.abspath(__file__)) + "/../lib/opensslVerify/libeay32.dll"
|
||||
elif sys.platform == "cygwin":
|
||||
dll_path = "/bin/cygcrypto-1.0.0.dll"
|
||||
lib_path = "/bin/cygcrypto-1.0.0.dll"
|
||||
elif os.path.isfile("../lib/libcrypto.so"): # ZeroBundle OSX
|
||||
lib_path = "../lib/libcrypto.so"
|
||||
elif os.path.isfile("/opt/lib/libcrypto.so.1.0.0"): # For optware and entware
|
||||
lib_path = "/opt/lib/libcrypto.so.1.0.0"
|
||||
else:
|
||||
dll_path = "/usr/local/ssl/lib/libcrypto.so"
|
||||
ssl_lib = ctypes.CDLL(dll_path, ctypes.RTLD_GLOBAL)
|
||||
assert ssl_lib
|
||||
except:
|
||||
dll_path = ctypes.util.find_library('ssl.so.1.0') or ctypes.util.find_library('ssl') or ctypes.util.find_library('crypto') or ctypes.util.find_library('libcrypto')
|
||||
ssl_lib = ctypes.CDLL(dll_path or 'libeay32', ctypes.RTLD_GLOBAL)
|
||||
lib_path = "/usr/local/ssl/lib/libcrypto.so"
|
||||
|
||||
if os.path.isfile(lib_path):
|
||||
return lib_path
|
||||
|
||||
if "ANDROID_APP_PATH" in os.environ:
|
||||
try:
|
||||
lib_dir = os.environ["ANDROID_APP_PATH"] + "/../../lib"
|
||||
return [lib for lib in os.listdir(lib_dir) if "crypto" in lib][0]
|
||||
except Exception, err:
|
||||
logging.debug("OpenSSL lib not found in: %s (%s)" % (lib_dir, err))
|
||||
|
||||
return (ctypes.util.find_library('ssl.so.1.0') or ctypes.util.find_library('ssl') or ctypes.util.find_library('crypto') or ctypes.util.find_library('libcrypto') or 'libeay32')
|
||||
|
||||
|
||||
|
||||
def openLibrary():
|
||||
lib_path = getLibraryPath() or "libeay32"
|
||||
logging.debug("Opening %s..." % lib_path)
|
||||
ssl_lib = ctypes.CDLL(lib_path, ctypes.RTLD_GLOBAL)
|
||||
return ssl_lib
|
||||
|
||||
|
||||
def disableSSLCompression():
|
||||
import ctypes
|
||||
import ctypes.util
|
||||
try:
|
||||
openssl = openLibrary()
|
||||
openssl.SSL_COMP_get_compression_methods.restype = ctypes.c_void_p
|
||||
|
|
Loading…
Reference in a new issue