Skip to content

Commit 9588b78

Browse files
committed
simple_http: Convert to WolfSSL
Fully convert to WolfSSL as recent version of WolfSSL dropped the support shims for CyaSSL. Signed-off-by: Christian Marangi <[email protected]>
1 parent d7b9a21 commit 9588b78

File tree

2 files changed

+81
-86
lines changed

2 files changed

+81
-86
lines changed

configure.in

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,48 +85,45 @@ AC_SUBST(enable_latex_docs)
8585
# Acutally perform the doxygen check
8686
BB_ENABLE_DOXYGEN
8787

88-
# Enable cyassl?
89-
AC_DEFUN([BB_CYASSL],
88+
# Enable wolfssl?
89+
AC_DEFUN([BB_WOLFSSL],
9090
[
91-
AC_ARG_ENABLE(cyassl, [ --enable-cyassl enable TLS support for auth server communication (no)], [], [enable_cyassl=no])
92-
if test "x$enable_cyassl" = xyes; then
93-
# CyaSSL has been renamed wolfSSL. Old method names are still available
94-
# via cyassl/ssl.h, which maps old methods to new methods via macros.
95-
# To find the proper lib to link against (cyassl or wolfssl), we do have
96-
# the use the new naming scheme below as cyassl/ssl.h is not available for
97-
# AC_SEARCH_LIBS
98-
AC_CHECK_HEADERS(cyassl/ssl.h)
99-
AC_SEARCH_LIBS([CyaTLSv1_client_method], [cyassl], [], [
100-
AC_SEARCH_LIBS([wolfTLSv1_client_method], [wolfssl], [], [
101-
AC_MSG_ERROR([unable to locate SSL lib: either wolfSSL or CyaSSL needed.])
102-
])
91+
AC_ARG_ENABLE(wolfssl, [ --enable-wolfssl enable TLS support for auth server communication (no)], [], [enable_wolfssl=no])
92+
if test "x$enable_wolfssl" = xyes; then
93+
AC_CHECK_HEADERS(wolfssl/ssl.h, [], [],
94+
[
95+
#include <wolfssl/options.h>
96+
])
97+
AC_SEARCH_LIBS([wolfTLSv1_client_method], [wolfssl], [], [
98+
AC_MSG_ERROR([unable to locate SSL lib: wolfSSL needed.])
10399
])
104100
105-
AC_MSG_CHECKING([for the CyaSSL SNI enabled])
101+
AC_MSG_CHECKING([for the Wolfssl SNI enabled])
106102
AC_LINK_IFELSE([AC_LANG_PROGRAM(
107103
[[
108104
#define HAVE_SNI
109-
#include <cyassl/ssl.h>
105+
#include <wolfssl/options.h>
106+
#include <wolfssl/ssl.h>
110107
]], [[
111-
CYASSL_CTX *ctx;
112-
CyaSSL_Init();
113-
ctx = CyaSSL_CTX_new(CyaTLSv1_client_method());
114-
CyaSSL_CTX_UseSNI(ctx, CYASSL_SNI_HOST_NAME, "wifidog.org", 11);
108+
WOLFSSL_CTX *ctx;
109+
wolfSSL_Init();
110+
ctx = wolfSSL_CTX_new(wolfTLSv1_client_method());
111+
wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME, "wifidog.org", 11);
115112
]])], [enabled_sni=yes], [enabled_sni=no])
116113
117114
if test "x$enabled_sni" = xyes; then
118115
AC_MSG_RESULT([yes])
119-
AC_DEFINE([HAVE_SNI],, "Compile with CyaSSL SNI support")
116+
AC_DEFINE([HAVE_SNI],, "Compile with wolfssl SNI support")
120117
else
121118
AC_MSG_RESULT([no])
122119
fi
123120
124-
AC_DEFINE(USE_CYASSL,, "Compile with CyaSSL support")
121+
AC_DEFINE(USE_WOLFSSL,, "Compile with wolfssl support")
125122
fi
126123
])
127124

128-
# Actually perform the cyassl check
129-
BB_CYASSL
125+
# Actually perform the wolfssl check
126+
BB_WOLFSSL
130127

131128

132129

src/simple_http.c

Lines changed: 60 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <arpa/inet.h>
2929
#include <errno.h>
3030
#include <unistd.h>
31+
#include <pthread.h>
3132
#include <string.h>
3233
#include <syslog.h>
3334

@@ -36,17 +37,14 @@
3637
#include "debug.h"
3738
#include "pstring.h"
3839

39-
#ifdef USE_CYASSL
40-
#include <cyassl/ssl.h>
40+
#ifdef USE_WOLFSSL
41+
#include <wolfssl/options.h>
42+
#include <wolfssl/ssl.h>
4143
#include "conf.h"
42-
/* For CYASSL_MAX_ERROR_SZ */
43-
#include <cyassl/ctaocrypt/types.h>
44-
/* For COMPRESS_E */
45-
#include <cyassl/ctaocrypt/error-crypt.h>
4644
#endif
4745

48-
#ifdef USE_CYASSL
49-
static CYASSL_CTX *get_cyassl_ctx(const char *hostname);
46+
#ifdef USE_WOLFSSL
47+
static WOLFSSL_CTX *get_wolfssl_ctx(const char *hostname);
5048
#endif
5149

5250
/**
@@ -133,48 +131,48 @@ http_get(const int sockfd, const char *req)
133131
return NULL;
134132
}
135133

136-
#ifdef USE_CYASSL
134+
#ifdef USE_WOLFSSL
137135

138-
static CYASSL_CTX *cyassl_ctx = NULL;
139-
static pthread_mutex_t cyassl_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
136+
static WOLFSSL_CTX *wolfssl_ctx = NULL;
137+
static pthread_mutex_t wolfssl_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
140138

141-
#define LOCK_CYASSL_CTX() do { \
142-
debug(LOG_DEBUG, "Locking CyaSSL Context"); \
143-
pthread_mutex_lock(&cyassl_ctx_mutex); \
144-
debug(LOG_DEBUG, "CyaSSL Context locked"); \
139+
#define LOCK_WOLFSSL_CTX() do { \
140+
debug(LOG_DEBUG, "Locking WolfSSL Context"); \
141+
pthread_mutex_lock(&wolfssl_ctx_mutex); \
142+
debug(LOG_DEBUG, "WolfSSL Context locked"); \
145143
} while (0)
146144

147-
#define UNLOCK_CYASSL_CTX() do { \
148-
debug(LOG_DEBUG, "Unlocking CyaSSL Context"); \
149-
pthread_mutex_unlock(&cyassl_ctx_mutex); \
150-
debug(LOG_DEBUG, "CyaSSL Context unlocked"); \
145+
#define UNLOCK_WOLFSSL_CTX() do { \
146+
debug(LOG_DEBUG, "Unlocking WolfSSL Context"); \
147+
pthread_mutex_unlock(&wolfssl_ctx_mutex); \
148+
debug(LOG_DEBUG, "WolfSSL Context unlocked"); \
151149
} while (0)
152150

153-
static CYASSL_CTX *
154-
get_cyassl_ctx(const char *hostname)
151+
static WOLFSSL_CTX *
152+
get_wolfssl_ctx(const char *hostname)
155153
{
156154
int err;
157-
CYASSL_CTX *ret;
155+
WOLFSSL_CTX *ret;
158156
s_config *config = config_get_config();
159157

160-
LOCK_CYASSL_CTX();
158+
LOCK_WOLFSSL_CTX();
161159

162-
if (NULL == cyassl_ctx) {
163-
CyaSSL_Init();
164-
/* Create the CYASSL_CTX */
160+
if (NULL == wolfssl_ctx) {
161+
wolfSSL_Init();
162+
/* Create the WOLFSSL_CTX */
165163
/* Allow TLSv1.0 up to TLSv1.2 */
166-
if ((cyassl_ctx = CyaSSL_CTX_new(CyaTLSv1_client_method())) == NULL) {
167-
debug(LOG_ERR, "Could not create CYASSL context.");
168-
UNLOCK_CYASSL_CTX();
164+
if ((wolfssl_ctx = wolfSSL_CTX_new(wolfTLSv1_client_method())) == NULL) {
165+
debug(LOG_ERR, "Could not create WOLFSSL context.");
166+
UNLOCK_WOLFSSL_CTX();
169167
return NULL;
170168
}
171169

172170
if (config->ssl_cipher_list) {
173171
debug(LOG_INFO, "Setting SSL cipher list to [%s]", config->ssl_cipher_list);
174-
err = CyaSSL_CTX_set_cipher_list(cyassl_ctx, config->ssl_cipher_list);
172+
err = wolfSSL_CTX_set_cipher_list(wolfssl_ctx, config->ssl_cipher_list);
175173
if (SSL_SUCCESS != err) {
176174
debug(LOG_ERR, "Could not load SSL cipher list (error %d)", err);
177-
UNLOCK_CYASSL_CTX();
175+
UNLOCK_WOLFSSL_CTX();
178176
return NULL;
179177
}
180178
}
@@ -183,41 +181,41 @@ get_cyassl_ctx(const char *hostname)
183181
if (config->ssl_use_sni) {
184182
debug(LOG_INFO, "Setting SSL using SNI for hostname %s",
185183
hostname);
186-
err = CyaSSL_CTX_UseSNI(cyassl_ctx, CYASSL_SNI_HOST_NAME, hostname,
184+
err = wolfSSL_CTX_UseSNI(wolfssl_ctx, WOLFSSL_SNI_HOST_NAME, hostname,
187185
strlen(hostname));
188186
if (SSL_SUCCESS != err) {
189187
debug(LOG_ERR, "Could not setup SSL using SNI for hostname %s",
190188
hostname);
191-
UNLOCK_CYASSL_CTX();
189+
UNLOCK_WOLFSSL_CTX();
192190
return NULL;
193191
}
194192
}
195193
#endif
196194

197195
if (config->ssl_verify) {
198196
/* Use trusted certs */
199-
/* Note: CyaSSL requires that the certificates are named by their hash values */
197+
/* Note: WolfSSL requires that the certificates are named by their hash values */
200198
debug(LOG_INFO, "Loading SSL certificates from %s", config->ssl_certs);
201-
err = CyaSSL_CTX_load_verify_locations(cyassl_ctx, NULL, config->ssl_certs);
199+
err = wolfSSL_CTX_load_verify_locations(wolfssl_ctx, NULL, config->ssl_certs);
202200
if (err != SSL_SUCCESS) {
203201
debug(LOG_ERR, "Could not load SSL certificates (error %d)", err);
204202
if (err == ASN_UNKNOWN_OID_E) {
205-
debug(LOG_ERR, "Error is ASN_UNKNOWN_OID_E - try compiling cyassl/wolfssl with --enable-ecc");
203+
debug(LOG_ERR, "Error is ASN_UNKNOWN_OID_E - try compiling wolfssl/wolfssl with --enable-ecc");
206204
} else {
207205
debug(LOG_ERR, "Make sure that SSLCertPath points to the correct path in the config file");
208206
debug(LOG_ERR, "Or disable certificate loading with 'SSLPeerVerification No'.");
209207
}
210-
UNLOCK_CYASSL_CTX();
208+
UNLOCK_WOLFSSL_CTX();
211209
return NULL;
212210
}
213211
} else {
214-
CyaSSL_CTX_set_verify(cyassl_ctx, SSL_VERIFY_NONE, 0);
212+
wolfSSL_CTX_set_verify(wolfssl_ctx, SSL_VERIFY_NONE, 0);
215213
debug(LOG_INFO, "Disabling SSL certificate verification!");
216214
}
217215
}
218216

219-
ret = cyassl_ctx;
220-
UNLOCK_CYASSL_CTX();
217+
ret = wolfssl_ctx;
218+
UNLOCK_WOLFSSL_CTX();
221219
return ret;
222220
}
223221

@@ -237,20 +235,20 @@ https_get(const int sockfd, const char *req, const char *hostname)
237235
fd_set readfds;
238236
struct timeval timeout;
239237
unsigned long sslerr;
240-
char sslerrmsg[CYASSL_MAX_ERROR_SZ];
238+
char sslerrmsg[WOLFSSL_MAX_ERROR_SZ];
241239
size_t reqlen = strlen(req);
242240
char readbuf[MAX_BUF];
243241
char *retval;
244242
pstr_t *response = pstr_new();
245-
CYASSL *ssl = NULL;
246-
CYASSL_CTX *ctx = NULL;
243+
WOLFSSL *ssl = NULL;
244+
WOLFSSL_CTX *ctx = NULL;
247245

248246
s_config *config;
249247
config = config_get_config();
250248

251-
ctx = get_cyassl_ctx(hostname);
249+
ctx = get_wolfssl_ctx(hostname);
252250
if (NULL == ctx) {
253-
debug(LOG_ERR, "Could not get CyaSSL Context!");
251+
debug(LOG_ERR, "Could not get WolfSSL Context!");
254252
goto error;
255253
}
256254

@@ -260,28 +258,28 @@ https_get(const int sockfd, const char *req, const char *hostname)
260258
goto error;
261259
}
262260

263-
/* Create CYASSL object */
264-
if ((ssl = CyaSSL_new(ctx)) == NULL) {
265-
debug(LOG_ERR, "Could not create CyaSSL context.");
261+
/* Create WOLFSSL object */
262+
if ((ssl = wolfSSL_new(ctx)) == NULL) {
263+
debug(LOG_ERR, "Could not create WolfSSL context.");
266264
goto error;
267265
}
268266
if (config->ssl_verify) {
269267
// Turn on domain name check
270268
// Loading of CA certificates and verification of remote host name
271269
// go hand in hand - one is useless without the other.
272-
CyaSSL_check_domain_name(ssl, hostname);
270+
wolfSSL_check_domain_name(ssl, hostname);
273271
}
274-
CyaSSL_set_fd(ssl, sockfd);
272+
wolfSSL_set_fd(ssl, sockfd);
275273

276274
debug(LOG_DEBUG, "Sending HTTPS request to auth server: [%s]\n", req);
277-
numbytes = CyaSSL_send(ssl, req, (int)reqlen, 0);
275+
numbytes = wolfSSL_send(ssl, req, (int)reqlen, 0);
278276
if (numbytes <= 0) {
279-
sslerr = (unsigned long)CyaSSL_get_error(ssl, numbytes);
280-
CyaSSL_ERR_error_string(sslerr, sslerrmsg);
281-
debug(LOG_ERR, "CyaSSL_send failed: %s", sslerrmsg);
277+
sslerr = (unsigned long)wolfSSL_get_error(ssl, numbytes);
278+
wolfSSL_ERR_error_string(sslerr, sslerrmsg);
279+
debug(LOG_ERR, "WolfSSL_send failed: %s", sslerrmsg);
282280
goto error;
283281
} else if ((size_t) numbytes != reqlen) {
284-
debug(LOG_ERR, "CyaSSL_send failed: only %d bytes out of %d bytes sent!", numbytes, reqlen);
282+
debug(LOG_ERR, "WolfSSL_send failed: only %d bytes out of %d bytes sent!", numbytes, reqlen);
285283
goto error;
286284
}
287285

@@ -300,14 +298,14 @@ https_get(const int sockfd, const char *req, const char *hostname)
300298
/** We don't have to use FD_ISSET() because there
301299
* was only one fd. */
302300
memset(readbuf, 0, MAX_BUF);
303-
numbytes = CyaSSL_read(ssl, readbuf, MAX_BUF - 1);
301+
numbytes = wolfSSL_read(ssl, readbuf, MAX_BUF - 1);
304302
if (numbytes < 0) {
305-
sslerr = (unsigned long)CyaSSL_get_error(ssl, numbytes);
306-
CyaSSL_ERR_error_string(sslerr, sslerrmsg);
303+
sslerr = (unsigned long)wolfSSL_get_error(ssl, numbytes);
304+
wolfSSL_ERR_error_string(sslerr, sslerrmsg);
307305
debug(LOG_ERR, "An error occurred while reading from server: %s", sslerrmsg);
308306
goto error;
309307
} else if (numbytes == 0) {
310-
/* CyaSSL_read returns 0 on a clean shutdown or if the peer closed the
308+
/* WolfSSL_read returns 0 on a clean shutdown or if the peer closed the
311309
connection. We can't distinguish between these cases right now. */
312310
done = 1;
313311
} else {
@@ -326,15 +324,15 @@ https_get(const int sockfd, const char *req, const char *hostname)
326324

327325
close(sockfd);
328326

329-
CyaSSL_free(ssl);
327+
wolfSSL_free(ssl);
330328

331329
retval = pstr_to_string(response);
332330
debug(LOG_DEBUG, "HTTPS Response from Server: [%s]", retval);
333331
return retval;
334332

335333
error:
336334
if (ssl) {
337-
CyaSSL_free(ssl);
335+
wolfSSL_free(ssl);
338336
}
339337
if (sockfd >= 0) {
340338
close(sockfd);
@@ -344,4 +342,4 @@ https_get(const int sockfd, const char *req, const char *hostname)
344342
return NULL;
345343
}
346344

347-
#endif /* USE_CYASSL */
345+
#endif /* USE_WOLFSSL */

0 commit comments

Comments
 (0)