Skip to content

Commit b34b40f

Browse files
committed
Update wolfSSL to 5.1.1 and fix any issues
* Bumps to wolfSSL 5.1.1 * Fixup `make clean` * Move `wolfssl` src to root * Switch test from DigiCert to GlobalSign (`python.org` ditched DigiCert years ago) * Make SSLContext call `wolfSSL_Init()` which fixes a few issues * Make `setup.py` compile CFFI and wolfSSL C code * Fully enable SSLv3 support * Add TLSv1.3 support * Fix bug in `wolfSSL_Free()` usage * Update `tox.ini` to a currently supported platform
1 parent ace63e9 commit b34b40f

15 files changed

Lines changed: 76 additions & 43 deletions

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and
3030

3131

3232
clean-build: ## remove build artifacts
33+
rm -fr lib/
3334
rm -fr build/
3435
rm -fr dist/
3536
rm -fr .eggs/
37+
rm -fr wolfssl/_ffi*
3638
find . -name '*.egg-info' -exec rm -fr {} +
3739
find . -name '*.egg' -exec rm -f {} +
3840

@@ -81,7 +83,7 @@ servedocs: docs ## compile the docs watching for changes
8183

8284
dist: clean ## builds source and wheel package
8385
python setup.py sdist
84-
86+
8587
./make/osx/build_wheels.sh
8688

8789
./make/manylinux1/build_wheels.sh

README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ library targeted at IoT, embedded, and RTOS environments primarily because of
1313
its size, speed, and feature set. It works seamlessly in desktop, enterprise,
1414
and cloud environments as well.
1515

16+
Compiling
17+
=========
18+
19+
The `setup.py` file covers most things you will need to do to build and install from source. As pre-requisites you will need to install either from your OS repository or pip. You'll also need the Python development package for your Python version:
20+
21+
* `cffi`
22+
* `tox`
23+
* `pytest`
24+
25+
To build a source package run `python setup.py sdist`, to build a wheel package run `python setup.py bdist_wheel`. To test the build run `tox`. The `tox` tests rely on Python 3.9 being installed, if you do not have this version we recommend using `pyenv` to install it.
1626

1727
Installation
1828
============

certs/ca-digicert-ev.pem

Lines changed: 0 additions & 23 deletions
This file was deleted.

certs/ca-globalsign-r3.pem

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDXzCCAkegAwIBAgILBAAAAAABIVhTCKIwDQYJKoZIhvcNAQELBQAwTDEgMB4G
3+
A1UECxMXR2xvYmFsU2lnbiBSb290IENBIC0gUjMxEzARBgNVBAoTCkdsb2JhbFNp
4+
Z24xEzARBgNVBAMTCkdsb2JhbFNpZ24wHhcNMDkwMzE4MTAwMDAwWhcNMjkwMzE4
5+
MTAwMDAwWjBMMSAwHgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMzETMBEG
6+
A1UEChMKR2xvYmFsU2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjCCASIwDQYJKoZI
7+
hvcNAQEBBQADggEPADCCAQoCggEBAMwldpB5BngiFvXAg7aEyiie/QV2EcWtiHL8
8+
RgJDx7KKnQRfJMsuS+FggkbhUqsMgUdwbN1k0ev1LKMPgj0MK66X17YUhhB5uzsT
9+
gHeMCOFJ0mpiLx9e+pZo34knlTifBtc+ycsmWQ1z3rDI6SYOgxXG71uL0gRgykmm
10+
KPZpO/bLyCiR5Z2KYVc3rHQU3HTgOu5yLy6c+9C7v/U9AOEGM+iCK65TpjoWc4zd
11+
QQ4gOsC0p6Hpsk+QLjJg6VfLuQSSaGjlOCZgdbKfd/+RFO+uIEn8rUAVSNECMWEZ
12+
XriX7613t2Saer9fwRPvm2L7DWzgVGkWqQPabumDk3F2xmmFghcCAwEAAaNCMEAw
13+
DgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFI/wS3+o
14+
LkUkrk1Q+mOai97i3Ru8MA0GCSqGSIb3DQEBCwUAA4IBAQBLQNvAUKr+yAzv95ZU
15+
RUm7lgAJQayzE4aGKAczymvmdLm6AC2upArT9fHxD4q/c2dKg8dEe3jgr25sbwMp
16+
jjM5RcOO5LlXbKr8EpbsU8Yt5CRsuZRj+9xTaGdWPoO4zzUhw8lo/s7awlOqzJCK
17+
6fBdRoyV3XpYKBovHd7NADdBj+1EbddTKJd+82cEHhXXipa0095MJ6RMG3NzdvQX
18+
mcIfeg7jLQitChws/zyrVQ4PkX4268NXSb7hLi18YIvDQVETI53O9zJrlAGomecs
19+
Mx86OyXShkDOOyyGeMlhLxS67ttVb9+E7gUJTb0o2HLO02JQZR7rkpeDMdmztcpH
20+
WD9f
21+
-----END CERTIFICATE-----

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
# Adding src folder to the include path in order to import from wolfssl
31-
package_dir = os.path.join(os.path.dirname(__file__), "src")
31+
package_dir = os.path.dirname(__file__)
3232
sys.path.insert(0, package_dir)
3333

3434
import wolfssl
@@ -93,7 +93,7 @@ def build_extension(self, ext):
9393
package_dir={"":package_dir},
9494

9595
zip_safe=False,
96-
cffi_modules=["./src/wolfssl/_build_ffi.py:ffi"],
96+
cffi_modules=["./wolfssl/_build_ffi.py:ffi"],
9797

9898
keywords="wolfssl, wolfcrypt, security, cryptography",
9999
classifiers=[

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@
2727

2828
HOST = "www.python.org"
2929
PORT = 443
30-
CA_CERTS = "certs/ca-digicert-ev.pem"
30+
CA_CERTS = "certs/ca-globalsign-r3.pem"
3131

3232

3333
@pytest.fixture(
3434
params=["wrap_socket", "wrap_socket_with_ca",
3535
"wrap_socket_from_context", "ssl_socket"])
36+
3637
def secure_socket(request, ssl_provider, tcp_socket):
3738
sock = None
3839

@@ -64,7 +65,6 @@ def secure_socket(request, ssl_provider, tcp_socket):
6465
yield sock
6566
sock.close()
6667

67-
6868
def test_secure_connection(secure_socket):
6969
secure_socket.connect((HOST, PORT))
7070

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
2-
envlist = py27, py34, py35, py36
3-
skip_missing_interpreters = true
2+
envlist = py39, pep8
3+
skipsdist = True
44

55
[testenv]
66
setenv =
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
# When bumping the C library version, reset the POST count to 0
2828

29-
__wolfssl_version__ = "v4.8.1-stable"
29+
__wolfssl_version__ = "v5.1.1-stable"
3030

3131
# We're using implicit post releases [PEP 440] to bump package version
3232
# while maintaining the C library version intact for better reference.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class SSLContext(object):
138138
"""
139139

140140
def __init__(self, protocol, server_side=None):
141+
_lib.wolfSSL_Init()
141142
method = _WolfSSLMethod(protocol, server_side)
142143

143144
self.protocol = protocol
Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@
2424

2525
from distutils.util import get_platform
2626
from cffi import FFI
27-
from wolfssl._build_wolfssl import wolfssl_inc_path, wolfssl_lib_path
27+
from wolfssl._build_wolfssl import wolfssl_inc_path, wolfssl_lib_path, ensure_wolfssl_src, make, make_flags, local_path
28+
from wolfssl.__about__ import __wolfssl_version__ as version
2829
import wolfssl._openssl as openssl
2930
import subprocess
3031
import shlex
3132
import os
3233
from ctypes import cdll
3334
from collections import namedtuple
3435

36+
libwolfssl_path = ""
37+
3538
def make_optional_func_list(libwolfssl_path, funcs):
3639
if libwolfssl_path.endswith(".so"):
3740
libwolfssl = cdll.LoadLibrary(libwolfssl_path)
@@ -52,12 +55,26 @@ def make_optional_func_list(libwolfssl_path, funcs):
5255

5356
return defined
5457

55-
libwolfssl_path = os.path.join(wolfssl_lib_path(), "libwolfssl.a")
56-
if not os.path.exists(libwolfssl_path):
57-
libwolfssl_path = os.path.join(wolfssl_lib_path(), "libwolfssl.so")
58+
def get_libwolfssl():
59+
libwolfssl_path = os.path.join(wolfssl_lib_path(), "libwolfssl.a")
5860
if not os.path.exists(libwolfssl_path):
59-
err = "Couldn't find libwolfssl under {}.".format(wolfssl_lib_path())
60-
raise Exception(err)
61+
libwolfssl_path = os.path.join(wolfssl_lib_path(), "libwolfssl.so")
62+
if not os.path.exists(libwolfssl_path):
63+
return 0
64+
else:
65+
return 1
66+
else:
67+
return 1
68+
69+
def generate_libwolfssl():
70+
ensure_wolfssl_src(version)
71+
prefix = local_path("lib/wolfssl/{}/{}".format(
72+
get_platform(), version))
73+
make(make_flags(prefix, False))
74+
75+
if get_libwolfssl() == 0:
76+
generate_libwolfssl()
77+
get_libwolfssl()
6178

6279
WolfFunction = namedtuple("WolfFunction", ["name", "native_sig", "ossl_sig"])
6380
# Depending on how wolfSSL was configured, the functions below may or may not be
@@ -175,6 +192,7 @@ def make_optional_func_list(libwolfssl_path, funcs):
175192
/**
176193
* SSL/TLS Session functions
177194
*/
195+
void wolfSSL_Init();
178196
WOLFSSL* wolfSSL_new(WOLFSSL_CTX*);
179197
void wolfSSL_free(WOLFSSL*);
180198
@@ -276,5 +294,4 @@ def make_optional_func_list(libwolfssl_path, funcs):
276294
ffi_cdef = cdef + openssl.construct_cdef(optional_funcs)
277295
ffi.cdef(ffi_cdef)
278296

279-
if __name__ == "__main__":
280-
ffi.compile(verbose=True)
297+
ffi.compile(verbose=True)

0 commit comments

Comments
 (0)