Forking what is left of ZeroNet and hopefully adding an AT Proto Frontend/Proxy
1import logging
2import os
3import sys
4import ctypes.util
5
6from Config import config
7
8find_library_original = ctypes.util.find_library
9
10
11def getOpensslPath():
12 if config.openssl_lib_file:
13 return config.openssl_lib_file
14
15 if sys.platform.startswith("win"):
16 lib_paths = [
17 os.path.join(os.getcwd(), "tools/openssl/libeay32.dll"), # ZeroBundle Windows
18 os.path.join(os.path.dirname(sys.executable), "DLLs/libcrypto-1_1-x64.dll"),
19 os.path.join(os.path.dirname(sys.executable), "DLLs/libcrypto-1_1.dll")
20 ]
21 elif sys.platform == "cygwin":
22 lib_paths = ["/bin/cygcrypto-1.0.0.dll"]
23 else:
24 lib_paths = [
25 "../runtime/lib/libcrypto.so.1.1", # ZeroBundle Linux
26 "../../Frameworks/libcrypto.1.1.dylib", # ZeroBundle macOS
27 "/opt/lib/libcrypto.so.1.0.0", # For optware and entware
28 "/usr/local/ssl/lib/libcrypto.so"
29 ]
30
31 for lib_path in lib_paths:
32 if os.path.isfile(lib_path):
33 return lib_path
34
35 if "ANDROID_APP_PATH" in os.environ:
36 try:
37 lib_dir = os.environ["ANDROID_APP_PATH"] + "/../../lib"
38 return [lib for lib in os.listdir(lib_dir) if "crypto" in lib][0]
39 except Exception as err:
40 logging.debug("OpenSSL lib not found in: %s (%s)" % (lib_dir, err))
41
42 if "LD_LIBRARY_PATH" in os.environ:
43 lib_dir_paths = os.environ["LD_LIBRARY_PATH"].split(":")
44 for path in lib_dir_paths:
45 try:
46 return [lib for lib in os.listdir(path) if "libcrypto.so" in lib][0]
47 except Exception as err:
48 logging.debug("OpenSSL lib not found in: %s (%s)" % (path, err))
49
50 lib_path = (
51 find_library_original('ssl.so') or find_library_original('ssl') or
52 find_library_original('crypto') or find_library_original('libcrypto') or 'libeay32'
53 )
54
55 return lib_path
56
57
58def patchCtypesOpensslFindLibrary():
59 def findLibraryPatched(name):
60 if name in ("ssl", "crypto", "libeay32"):
61 lib_path = getOpensslPath()
62 return lib_path
63 else:
64 return find_library_original(name)
65
66 ctypes.util.find_library = findLibraryPatched
67
68
69patchCtypesOpensslFindLibrary()