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):
|
def __init__(self, argv):
|
||||||
self.version = "0.5.6"
|
self.version = "0.5.6"
|
||||||
self.rev = 2128
|
self.rev = 2130
|
||||||
self.argv = argv
|
self.argv = argv
|
||||||
self.action = None
|
self.action = None
|
||||||
self.config_file = "zeronet.conf"
|
self.config_file = "zeronet.conf"
|
||||||
|
|
|
@ -194,24 +194,15 @@ ssl = None
|
||||||
|
|
||||||
def openLibrary():
|
def openLibrary():
|
||||||
global ssl
|
global ssl
|
||||||
try:
|
import util.SslPatch
|
||||||
if sys.platform.startswith("win"):
|
ssl = _OpenSSL(util.SslPatch.getLibraryPath())
|
||||||
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')
|
|
||||||
logging.debug("opensslVerify loaded: %s", ssl._lib)
|
logging.debug("opensslVerify loaded: %s", ssl._lib)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
ssl = _OpenSSL(sys.argv[1])
|
||||||
|
else:
|
||||||
openLibrary()
|
openLibrary()
|
||||||
|
|
||||||
openssl_version = "%.9X" % ssl._lib.SSLeay()
|
openssl_version = "%.9X" % ssl._lib.SSLeay()
|
||||||
|
|
||||||
NID_secp256k1 = 714
|
NID_secp256k1 = 714
|
||||||
|
@ -461,4 +452,4 @@ if __name__ == "__main__":
|
||||||
for i in range(1000):
|
for i in range(1000):
|
||||||
pubkey = getMessagePubkey("hello", sign)
|
pubkey = getMessagePubkey("hello", sign)
|
||||||
verified = btctools.pubkey_to_address(pubkey) == address
|
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():
|
def loadOpenSSL():
|
||||||
import logging
|
import logging
|
||||||
|
import util.SslPatch
|
||||||
global OpenSSL
|
global OpenSSL
|
||||||
try:
|
OpenSSL = _OpenSSL(util.SslPatch.getLibraryPath())
|
||||||
if sys.platform.startswith("win"):
|
logging.debug("pyelliptic loaded: %s", OpenSSL._lib)
|
||||||
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)
|
|
||||||
|
|
||||||
loadOpenSSL()
|
loadOpenSSL()
|
||||||
|
|
|
@ -4,31 +4,46 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import ctypes
|
||||||
|
import ctypes.util
|
||||||
|
|
||||||
from Config import config
|
from Config import config
|
||||||
|
|
||||||
|
|
||||||
def openLibrary():
|
def getLibraryPath():
|
||||||
import ctypes
|
|
||||||
import ctypes.util
|
|
||||||
try:
|
|
||||||
if sys.platform.startswith("win"):
|
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":
|
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:
|
else:
|
||||||
dll_path = "/usr/local/ssl/lib/libcrypto.so"
|
lib_path = "/usr/local/ssl/lib/libcrypto.so"
|
||||||
ssl_lib = ctypes.CDLL(dll_path, ctypes.RTLD_GLOBAL)
|
|
||||||
assert ssl_lib
|
if os.path.isfile(lib_path):
|
||||||
except:
|
return lib_path
|
||||||
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)
|
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
|
return ssl_lib
|
||||||
|
|
||||||
|
|
||||||
def disableSSLCompression():
|
def disableSSLCompression():
|
||||||
import ctypes
|
|
||||||
import ctypes.util
|
|
||||||
try:
|
try:
|
||||||
openssl = openLibrary()
|
openssl = openLibrary()
|
||||||
openssl.SSL_COMP_get_compression_methods.restype = ctypes.c_void_p
|
openssl.SSL_COMP_get_compression_methods.restype = ctypes.c_void_p
|
||||||
|
|
Loading…
Reference in a new issue