|
|
@ -1,4 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import _ssl
|
|
|
|
import ctypes
|
|
|
|
import ctypes
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import random
|
|
|
@ -13,21 +14,29 @@ import testlib
|
|
|
|
import plain_old_module
|
|
|
|
import plain_old_module
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IS_64BIT = struct.calcsize('P') == 8
|
|
|
|
def _find_ssl_linux():
|
|
|
|
PLATFORM_TO_PATH = {
|
|
|
|
s = testlib.subprocess__check_output(['ldd', _ssl.__file__])
|
|
|
|
('darwin', False): '/usr/lib/libssl.dylib',
|
|
|
|
for line in s.splitlines():
|
|
|
|
('darwin', True): '/usr/lib/libssl.dylib',
|
|
|
|
bits = line.split()
|
|
|
|
('linux2', False): '/usr/lib/libssl.so',
|
|
|
|
if bits[0].startswith('libssl'):
|
|
|
|
('linux2', True): '/usr/lib/x86_64-linux-gnu/libssl.so',
|
|
|
|
return bits[2]
|
|
|
|
# Python 2.6
|
|
|
|
|
|
|
|
('linux3', False): '/usr/lib/libssl.so',
|
|
|
|
def _find_ssl_darwin():
|
|
|
|
('linux3', True): '/usr/lib/x86_64-linux-gnu/libssl.so',
|
|
|
|
s = testlib.subprocess__check_output(['otool', '-l', _ssl.__file__])
|
|
|
|
# Python 3
|
|
|
|
for line in s.splitlines():
|
|
|
|
('linux', False): '/usr/lib/libssl.so',
|
|
|
|
bits = line.split()
|
|
|
|
('linux', True): '/usr/lib/x86_64-linux-gnu/libssl.so',
|
|
|
|
if bits[0] == 'name' and 'libssl' in bits[1]:
|
|
|
|
}
|
|
|
|
return bits[1]
|
|
|
|
|
|
|
|
|
|
|
|
c_ssl = ctypes.CDLL(PLATFORM_TO_PATH[sys.platform, IS_64BIT])
|
|
|
|
|
|
|
|
|
|
|
|
if sys.platform.startswith('linux'):
|
|
|
|
|
|
|
|
LIBSSL_PATH = _find_ssl_linux()
|
|
|
|
|
|
|
|
elif sys.platform == 'darwin':
|
|
|
|
|
|
|
|
LIBSSL_PATH = _find_ssl_darwin()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
assert 0, "Don't know how to find libssl on this platform"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c_ssl = ctypes.CDLL(LIBSSL_PATH)
|
|
|
|
c_ssl.RAND_pseudo_bytes.argtypes = [ctypes.c_char_p, ctypes.c_int]
|
|
|
|
c_ssl.RAND_pseudo_bytes.argtypes = [ctypes.c_char_p, ctypes.c_int]
|
|
|
|
c_ssl.RAND_pseudo_bytes.restype = ctypes.c_int
|
|
|
|
c_ssl.RAND_pseudo_bytes.restype = ctypes.c_int
|
|
|
|
|
|
|
|
|
|
|
|