Merge pull request #257 from fa08c/master
Searching libcrypto.so in more locations
This commit is contained in:
commit
1becc9362d
3 changed files with 27 additions and 6 deletions
|
@ -45,9 +45,29 @@ def load_openssl():
|
||||||
if libcrypto_path:
|
if libcrypto_path:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
# We may get here when find_library fails because, for example,
|
||||||
|
# the user does not have sufficient privileges to access those
|
||||||
|
# tools underlying find_library on linux.
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
for libcrypto_path in glob.glob('/usr/lib/libcrypto.*'):
|
import sys
|
||||||
pass
|
|
||||||
|
patterns = ['/usr/lib/libcrypto.*']
|
||||||
|
|
||||||
|
# Some linux distros may store so in alternative locations
|
||||||
|
if sys.maxsize > 2 ** 32:
|
||||||
|
# Python is 64-bit
|
||||||
|
patterns.extend(['/usr/lib64/libcrypto.*'])
|
||||||
|
else:
|
||||||
|
# Python is 32-bit
|
||||||
|
patterns.extend(['/usr/lib32/libcrypto.*'])
|
||||||
|
|
||||||
|
for pat in patterns:
|
||||||
|
files = glob.glob(pat)
|
||||||
|
if files:
|
||||||
|
libcrypto_path = files[0]
|
||||||
|
break
|
||||||
|
|
||||||
if libcrypto_path is None:
|
if libcrypto_path is None:
|
||||||
raise Exception('libcrypto(OpenSSL) not found')
|
raise Exception('libcrypto(OpenSSL) not found')
|
||||||
logging.info('loading libcrypto from %s', libcrypto_path)
|
logging.info('loading libcrypto from %s', libcrypto_path)
|
||||||
|
@ -83,9 +103,9 @@ def load_cipher(cipher_name):
|
||||||
|
|
||||||
class CtypesCrypto(object):
|
class CtypesCrypto(object):
|
||||||
def __init__(self, cipher_name, key, iv, op):
|
def __init__(self, cipher_name, key, iv, op):
|
||||||
|
self._ctx = None
|
||||||
if not loaded:
|
if not loaded:
|
||||||
load_openssl()
|
load_openssl()
|
||||||
self._ctx = None
|
|
||||||
cipher = libcrypto.EVP_get_cipherbyname(cipher_name)
|
cipher = libcrypto.EVP_get_cipherbyname(cipher_name)
|
||||||
if not cipher:
|
if not cipher:
|
||||||
cipher = load_cipher(cipher_name)
|
cipher = load_cipher(cipher_name)
|
||||||
|
|
|
@ -39,7 +39,7 @@ def create_cipher(alg, key, iv, op, key_as_bytes=0, d=None, salt=None,
|
||||||
try:
|
try:
|
||||||
from shadowsocks.crypto import ctypes_openssl
|
from shadowsocks.crypto import ctypes_openssl
|
||||||
return ctypes_openssl.CtypesCrypto(b'rc4', rc4_key, b'', op)
|
return ctypes_openssl.CtypesCrypto(b'rc4', rc4_key, b'', op)
|
||||||
except:
|
except Exception:
|
||||||
import M2Crypto.EVP
|
import M2Crypto.EVP
|
||||||
return M2Crypto.EVP.Cipher(b'rc4', rc4_key, b'', op,
|
return M2Crypto.EVP.Cipher(b'rc4', rc4_key, b'', op,
|
||||||
key_as_bytes=0, d='md5', salt=None, i=1,
|
key_as_bytes=0, d='md5', salt=None, i=1,
|
||||||
|
|
|
@ -232,6 +232,7 @@ class EventLoop(object):
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
if self._handlers_to_remove:
|
||||||
for handler in self._handlers_to_remove:
|
for handler in self._handlers_to_remove:
|
||||||
self._handlers.remove(handler)
|
self._handlers.remove(handler)
|
||||||
self._handlers_to_remove = []
|
self._handlers_to_remove = []
|
||||||
|
|
Loading…
Reference in a new issue