Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ servedocs: docs ## compile the docs watching for changes
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .

dist: clean ## builds source and wheel package
python setup.py sdist

./make/osx/build_wheels.sh

./make/manylinux1/build_wheels.sh

python setup.py sdist bdist_wheel
ls -l dist

release: ## package and upload a release
Expand Down
10 changes: 6 additions & 4 deletions wolfssl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
try:
from wolfssl._ffi import ffi as _ffi
from wolfssl._ffi import lib as _lib
except ImportError:
pass
except ImportError as e:
from wolfssl.utils import _FFIPlaceholder
_ffi = _FFIPlaceholder(e)
_lib = _FFIPlaceholder(e)

from wolfssl.utils import t2b

Expand Down Expand Up @@ -169,7 +171,7 @@ def __init__(self, protocol, server_side=None):
self.verify_mode = CERT_NONE

def __del__(self):
if getattr(self, 'native_object', _ffi.NULL) != _ffi.NULL:
if getattr(self, 'native_object', None) is not None and self.native_object != _ffi.NULL:
_lib.wolfSSL_CTX_free(self.native_object)

@property
Expand Down Expand Up @@ -474,7 +476,7 @@ def __del__(self):
self._release_native_object()

def _release_native_object(self):
if getattr(self, 'native_object', _ffi.NULL) != _ffi.NULL:
if getattr(self, 'native_object', None) is not None and self.native_object != _ffi.NULL:
_lib.wolfSSL_free(self.native_object)
self.native_object = _ffi.NULL

Expand Down
57 changes: 34 additions & 23 deletions wolfssl/_build_ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
from ctypes import cdll
from collections import namedtuple

libwolfssl_path = ""


def local_path(path):
""" Return path relative to the root of this project
"""
Expand Down Expand Up @@ -223,8 +220,13 @@ def build_wolfssl(ref, debug=False):


def make_optional_func_list(libwolfssl_path, funcs):
defined = []
sys.stderr.write("\nlibwolfssl Path: %s\n" % libwolfssl_path)
if libwolfssl_path.endswith(".so"):
if not libwolfssl_path or not os.path.exists(libwolfssl_path):
sys.stderr.write("WARNING: libwolfssl not found, skipping optional "
"function detection\n")
return []
if libwolfssl_path.endswith(".so") or libwolfssl_path.endswith(".dylib"):
libwolfssl = cdll.LoadLibrary(libwolfssl_path)
defined = []
for func in funcs:
Expand All @@ -244,16 +246,13 @@ def make_optional_func_list(libwolfssl_path, funcs):
return defined


def get_libwolfssl():
libwolfssl_path = os.path.join(wolfssl_lib_path(), "libwolfssl.a")
if not os.path.exists(libwolfssl_path):
libwolfssl_path = os.path.join(wolfssl_lib_path(), "libwolfssl.so")
if not os.path.exists(libwolfssl_path):
return 0
else:
return 1
else:
return 1
def get_libwolfssl_path():
lib_dir = wolfssl_lib_path()
for ext in (".so", ".dylib", ".a"):
path = os.path.join(lib_dir, "libwolfssl" + ext)
if os.path.exists(path):
return path
return None


def generate_libwolfssl():
Expand Down Expand Up @@ -282,6 +281,7 @@ def generate_libwolfssl():
raise RuntimeError("wolfSSL needs to be compiled with "
"--enable-opensslextra")
featureDetection = 1
libwolfssl_path = get_libwolfssl_path()
sys.stderr.write("\nDEBUG: Found <wolfssl/options.h>, attempting native "
"feature detection\n")

Expand All @@ -290,9 +290,10 @@ def generate_libwolfssl():
featureDetection = 0
sys.stderr.write("\nDEBUG: Skipping native feature detection, build not "
"using USE_LOCAL_WOLFSSL\n")
if get_libwolfssl() == 0:
libwolfssl_path = get_libwolfssl_path()
if libwolfssl_path is None:
generate_libwolfssl()
get_libwolfssl()
libwolfssl_path = get_libwolfssl_path()

# default values
OLDTLS_ENABLED = 0
Expand Down Expand Up @@ -328,13 +329,23 @@ def generate_libwolfssl():

ffi = FFI()

ffi.set_source(
"wolfssl._ffi",
ffi_source,
include_dirs=[wolfssl_inc_path()],
library_dirs=[wolfssl_lib_path()],
libraries=["wolfssl"],
)
if libwolfssl_path and libwolfssl_path.endswith(".a"):
# Static linking: pass the .a file directly via extra_objects
ffi.set_source(
"wolfssl._ffi",
ffi_source,
include_dirs=[wolfssl_inc_path()],
extra_objects=[libwolfssl_path],
)
else:
# Dynamic linking: use library_dirs + libraries
ffi.set_source(
"wolfssl._ffi",
ffi_source,
include_dirs=[wolfssl_inc_path()],
library_dirs=[wolfssl_lib_path()],
libraries=["wolfssl"],
)

cdef = """
/*
Expand Down
8 changes: 5 additions & 3 deletions wolfssl/_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
try:
from wolfssl._ffi import lib as _lib
from wolfssl._ffi import ffi as _ffi
except ImportError:
pass
except ImportError as e:
from wolfssl.utils import _FFIPlaceholder
_ffi = _FFIPlaceholder(e)
_lib = _FFIPlaceholder(e)


PROTOCOL_SSLv23 = 1
Expand Down Expand Up @@ -111,5 +113,5 @@ def __init__(self, protocol, server_side):
raise MemoryError("Cannot allocate method object")

def __del__(self):
if getattr(self, 'native_object', _ffi.NULL) != _ffi.NULL:
if getattr(self, 'native_object', None) is not None and self.native_object != _ffi.NULL:
_native_free(self.native_object, _DYNAMIC_TYPE_METHOD)
13 changes: 13 additions & 0 deletions wolfssl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@
_BINARY_TYPE = bytes if _PY3 else str


class _FFIPlaceholder:
def __init__(self, cause=None):
object.__setattr__(self, '_cause', cause)

def __getattr__(self, name):
raise ImportError(
"wolfssl._ffi is not available. The CFFI bindings have not been "
"compiled. If you installed wolfssl via pip, the build may have "
"failed silently. Try reinstalling with: "
"pip install --no-binary wolfssl wolfssl"
) from self._cause


def t2b(string):
"""
Converts text to binary.
Expand Down