1 From: Gert Doering <gert@greenie.muc.de>
3 Support for wolfSSL in OpenVPN
5 This patch adds support for wolfSSL in OpenVPN. Support is added by using
6 wolfSSL's OpenSSL compatibility layer. Function calls are left unchanged
7 and instead the OpenSSL includes point to wolfSSL headers and OpenVPN is
8 linked against the wolfSSL library. The wolfSSL installation directory is
9 detected using pkg-config.
11 As requested by OpenVPN maintainers, this patch does not include
12 wolfssl/options.h on its own. By defining the macro EXTERNAL_OPTS_OPENVPN
13 in the configure script wolfSSL will include wolfssl/options.h on its own
14 (change added in wolfSSL/wolfssl#2825). The patch
15 adds an option '--disable-wolfssl-options-h' in case the user would like
16 to supply their own settings file for wolfSSL.
19 Support added in: wolfSSL/wolfssl#2503
21 git clone https://github.com/wolfSSL/wolfssl.git
24 ./configure --enable-openvpn
31 ./configure --with-crypto-library=wolfssl
36 Signed-off-by: Juliusz Sosinowicz <juliusz@wolfssl.com>
37 Acked-by: Arne Schwabe <arne@rfc2549.org>
38 Message-Id: <20210317181153.83716-1-juliusz@wolfssl.com>
39 URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg21686.html
40 Signed-off-by: Gert Doering <gert@greenie.muc.de>
42 configure.ac | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
43 src/openvpn/syshead.h | 3 ++-
44 2 files changed, 110 insertions(+), 3 deletions(-)
47 @@ -271,16 +271,23 @@ AC_ARG_WITH(
51 - [AS_HELP_STRING([--with-crypto-library=library], [build with the given crypto library, TYPE=openssl|mbedtls @<:@default=openssl@:>@])],
52 + [AS_HELP_STRING([--with-crypto-library=library], [build with the given crypto library, TYPE=openssl|mbedtls|wolfssl @<:@default=openssl@:>@])],
56 + openssl|mbedtls|wolfssl) ;;
57 *) AC_MSG_ERROR([bad value ${withval} for --with-crypto-library]) ;;
60 [with_crypto_library="openssl"]
64 + [wolfssl-options-h],
65 + [AS_HELP_STRING([--disable-wolfssl-options-h], [Disable including options.h in wolfSSL @<:@default=yes@:>@])],
67 + [enable_wolfssl_options_h="yes"]
70 AC_ARG_VAR([PLUGINDIR], [Path of plug-in directory @<:@default=LIBDIR/openvpn/plugins@:>@])
71 if test -n "${PLUGINDIR}"; then
72 plugindir="${PLUGINDIR}"
73 @@ -1026,6 +1033,105 @@ elif test "${with_crypto_library}" = "mb
74 AC_DEFINE([ENABLE_CRYPTO_MBEDTLS], [1], [Use mbed TLS library])
75 CRYPTO_CFLAGS="${MBEDTLS_CFLAGS}"
76 CRYPTO_LIBS="${MBEDTLS_LIBS}"
78 +elif test "${with_crypto_library}" = "wolfssl"; then
79 + AC_ARG_VAR([WOLFSSL_CFLAGS], [C compiler flags for wolfssl. The include directory should
80 + contain the regular wolfSSL header files but also the
81 + wolfSSL OpenSSL header files. Ex: -I/usr/local/include
82 + -I/usr/local/include/wolfssl])
83 + AC_ARG_VAR([WOLFSSL_LIBS], [linker flags for wolfssl])
85 + saved_CFLAGS="${CFLAGS}"
86 + saved_LIBS="${LIBS}"
88 + if test -z "${WOLFSSL_CFLAGS}" -a -z "${WOLFSSL_LIBS}"; then
89 + # if the user did not explicitly specify flags, try to autodetect
94 + [AC_MSG_ERROR([Could not find wolfSSL.])]
97 + [WOLFSSL_INCLUDEDIR],
101 + [AC_MSG_ERROR([Could not find wolfSSL includedir variable.])]
103 + WOLFSSL_CFLAGS="${WOLFSSL_CFLAGS} -I${WOLFSSL_INCLUDEDIR}/wolfssl"
105 + saved_CFLAGS="${CFLAGS}"
106 + saved_LIBS="${LIBS}"
107 + CFLAGS="${CFLAGS} ${WOLFSSL_CFLAGS}"
108 + LIBS="${LIBS} ${WOLFSSL_LIBS}"
114 + [AC_MSG_ERROR([Could not link wolfSSL library.])]
116 + AC_CHECK_HEADER([wolfssl/options.h],,[AC_MSG_ERROR([wolfSSL header wolfssl/options.h not found!])])
118 + # wolfSSL signal EKM support
119 + have_export_keying_material="yes"
121 + AC_DEFINE([HAVE_HMAC_CTX_NEW], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
122 + AC_DEFINE([HAVE_HMAC_CTX_FREE], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
123 + AC_DEFINE([HAVE_HMAC_CTX_RESET], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
124 + AC_DEFINE([HAVE_EVP_MD_CTX_NEW], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
125 + AC_DEFINE([HAVE_EVP_MD_CTX_FREE], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
126 + AC_DEFINE([HAVE_EVP_MD_CTX_RESET], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
127 + AC_DEFINE([HAVE_EVP_CIPHER_CTX_RESET], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
128 + AC_DEFINE([HAVE_OPENSSL_VERSION], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
129 + AC_DEFINE([HAVE_SSL_CTX_GET_DEFAULT_PASSWD_CB], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
130 + AC_DEFINE([HAVE_SSL_CTX_GET_DEFAULT_PASSWD_CB_USERDATA], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
131 + AC_DEFINE([HAVE_SSL_CTX_SET_SECURITY_LEVEL], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
132 + AC_DEFINE([HAVE_X509_GET0_NOTBEFORE], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
133 + AC_DEFINE([HAVE_X509_GET0_NOTAFTER], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
134 + AC_DEFINE([HAVE_X509_GET0_PUBKEY], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
135 + AC_DEFINE([HAVE_X509_STORE_GET0_OBJECTS], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
136 + AC_DEFINE([HAVE_X509_OBJECT_FREE], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
137 + AC_DEFINE([HAVE_X509_OBJECT_GET_TYPE], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
138 + AC_DEFINE([HAVE_EVP_PKEY_ID], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
139 + AC_DEFINE([HAVE_EVP_PKEY_GET0_RSA], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
140 + AC_DEFINE([HAVE_EVP_PKEY_GET0_DSA], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
141 + AC_DEFINE([HAVE_EVP_PKEY_GET0_EC_KEY], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
142 + AC_DEFINE([HAVE_RSA_SET_FLAGS], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
143 + AC_DEFINE([HAVE_RSA_BITS], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
144 + AC_DEFINE([HAVE_RSA_GET0_KEY], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
145 + AC_DEFINE([HAVE_RSA_SET0_KEY], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
146 + AC_DEFINE([HAVE_DSA_GET0_PQG], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
147 + AC_DEFINE([HAVE_DSA_BITS], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
148 + AC_DEFINE([HAVE_RSA_METH_NEW], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
149 + AC_DEFINE([HAVE_RSA_METH_FREE], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
150 + AC_DEFINE([HAVE_RSA_METH_SET_PUB_ENC], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
151 + AC_DEFINE([HAVE_RSA_METH_SET_PUB_DEC], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
152 + AC_DEFINE([HAVE_RSA_METH_SET_PRIV_ENC], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
153 + AC_DEFINE([HAVE_RSA_METH_SET_PRIV_DEC], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
154 + AC_DEFINE([HAVE_RSA_METH_SET_INIT], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
155 + AC_DEFINE([HAVE_RSA_METH_SET_SIGN], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
156 + AC_DEFINE([HAVE_RSA_METH_SET_FINISH], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
157 + AC_DEFINE([HAVE_RSA_METH_SET0_APP_DATA], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
158 + AC_DEFINE([HAVE_RSA_METH_GET0_APP_DATA], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
159 + AC_DEFINE([HAVE_EC_GROUP_ORDER_BITS], [1], [Emulate AC_CHECK_FUNCS since these are defined as macros])
161 + if test "${enable_wolfssl_options_h}" = "yes"; then
162 + AC_DEFINE([EXTERNAL_OPTS_OPENVPN], [1], [Include options.h from wolfSSL library])
164 + AC_DEFINE([WOLFSSL_USER_SETTINGS], [1], [Use custom user_settings.h file for wolfSSL library])
167 + have_export_keying_material="yes"
169 + CFLAGS="${saved_CFLAGS}"
170 + LIBS="${saved_LIBS}"
172 + AC_DEFINE([ENABLE_CRYPTO_WOLFSSL], [1], [Use wolfSSL crypto library])
173 + AC_DEFINE([ENABLE_CRYPTO_OPENSSL], [1], [Use wolfSSL openssl compatibility layer])
174 + CRYPTO_CFLAGS="${WOLFSSL_CFLAGS}"
175 + CRYPTO_LIBS="${WOLFSSL_LIBS}"
177 AC_MSG_ERROR([Invalid crypto library: ${with_crypto_library}])
179 --- a/src/openvpn/syshead.h
180 +++ b/src/openvpn/syshead.h
181 @@ -582,7 +582,8 @@ socket_defined(const socket_descriptor_t
183 * Do we have CryptoAPI capability?
185 -#if defined(_WIN32) && defined(ENABLE_CRYPTO_OPENSSL)
186 +#if defined(_WIN32) && defined(ENABLE_CRYPTO_OPENSSL) && \
187 + !defined(ENABLE_CRYPTO_WOLFSSL)
188 #define ENABLE_CRYPTOAPI