28
28
#include <arpa/inet.h>
29
29
#include <errno.h>
30
30
#include <unistd.h>
31
+ #include <pthread.h>
31
32
#include <string.h>
32
33
#include <syslog.h>
33
34
36
37
#include "debug.h"
37
38
#include "pstring.h"
38
39
39
- #ifdef USE_CYASSL
40
- #include <cyassl/ssl.h>
40
+ #ifdef USE_WOLFSSL
41
+ #include <wolfssl/options.h>
42
+ #include <wolfssl/ssl.h>
41
43
#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>
46
44
#endif
47
45
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 );
50
48
#endif
51
49
52
50
/**
@@ -133,48 +131,48 @@ http_get(const int sockfd, const char *req)
133
131
return NULL ;
134
132
}
135
133
136
- #ifdef USE_CYASSL
134
+ #ifdef USE_WOLFSSL
137
135
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 ;
140
138
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"); \
145
143
} while (0)
146
144
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"); \
151
149
} while (0)
152
150
153
- static CYASSL_CTX *
154
- get_cyassl_ctx (const char * hostname )
151
+ static WOLFSSL_CTX *
152
+ get_wolfssl_ctx (const char * hostname )
155
153
{
156
154
int err ;
157
- CYASSL_CTX * ret ;
155
+ WOLFSSL_CTX * ret ;
158
156
s_config * config = config_get_config ();
159
157
160
- LOCK_CYASSL_CTX ();
158
+ LOCK_WOLFSSL_CTX ();
161
159
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 */
165
163
/* 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 ();
169
167
return NULL ;
170
168
}
171
169
172
170
if (config -> ssl_cipher_list ) {
173
171
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 );
175
173
if (SSL_SUCCESS != err ) {
176
174
debug (LOG_ERR , "Could not load SSL cipher list (error %d)" , err );
177
- UNLOCK_CYASSL_CTX ();
175
+ UNLOCK_WOLFSSL_CTX ();
178
176
return NULL ;
179
177
}
180
178
}
@@ -183,41 +181,41 @@ get_cyassl_ctx(const char *hostname)
183
181
if (config -> ssl_use_sni ) {
184
182
debug (LOG_INFO , "Setting SSL using SNI for hostname %s" ,
185
183
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 ,
187
185
strlen (hostname ));
188
186
if (SSL_SUCCESS != err ) {
189
187
debug (LOG_ERR , "Could not setup SSL using SNI for hostname %s" ,
190
188
hostname );
191
- UNLOCK_CYASSL_CTX ();
189
+ UNLOCK_WOLFSSL_CTX ();
192
190
return NULL ;
193
191
}
194
192
}
195
193
#endif
196
194
197
195
if (config -> ssl_verify ) {
198
196
/* 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 */
200
198
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 );
202
200
if (err != SSL_SUCCESS ) {
203
201
debug (LOG_ERR , "Could not load SSL certificates (error %d)" , err );
204
202
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" );
206
204
} else {
207
205
debug (LOG_ERR , "Make sure that SSLCertPath points to the correct path in the config file" );
208
206
debug (LOG_ERR , "Or disable certificate loading with 'SSLPeerVerification No'." );
209
207
}
210
- UNLOCK_CYASSL_CTX ();
208
+ UNLOCK_WOLFSSL_CTX ();
211
209
return NULL ;
212
210
}
213
211
} else {
214
- CyaSSL_CTX_set_verify ( cyassl_ctx , SSL_VERIFY_NONE , 0 );
212
+ wolfSSL_CTX_set_verify ( wolfssl_ctx , SSL_VERIFY_NONE , 0 );
215
213
debug (LOG_INFO , "Disabling SSL certificate verification!" );
216
214
}
217
215
}
218
216
219
- ret = cyassl_ctx ;
220
- UNLOCK_CYASSL_CTX ();
217
+ ret = wolfssl_ctx ;
218
+ UNLOCK_WOLFSSL_CTX ();
221
219
return ret ;
222
220
}
223
221
@@ -237,20 +235,20 @@ https_get(const int sockfd, const char *req, const char *hostname)
237
235
fd_set readfds ;
238
236
struct timeval timeout ;
239
237
unsigned long sslerr ;
240
- char sslerrmsg [CYASSL_MAX_ERROR_SZ ];
238
+ char sslerrmsg [WOLFSSL_MAX_ERROR_SZ ];
241
239
size_t reqlen = strlen (req );
242
240
char readbuf [MAX_BUF ];
243
241
char * retval ;
244
242
pstr_t * response = pstr_new ();
245
- CYASSL * ssl = NULL ;
246
- CYASSL_CTX * ctx = NULL ;
243
+ WOLFSSL * ssl = NULL ;
244
+ WOLFSSL_CTX * ctx = NULL ;
247
245
248
246
s_config * config ;
249
247
config = config_get_config ();
250
248
251
- ctx = get_cyassl_ctx (hostname );
249
+ ctx = get_wolfssl_ctx (hostname );
252
250
if (NULL == ctx ) {
253
- debug (LOG_ERR , "Could not get CyaSSL Context!" );
251
+ debug (LOG_ERR , "Could not get WolfSSL Context!" );
254
252
goto error ;
255
253
}
256
254
@@ -260,28 +258,28 @@ https_get(const int sockfd, const char *req, const char *hostname)
260
258
goto error ;
261
259
}
262
260
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." );
266
264
goto error ;
267
265
}
268
266
if (config -> ssl_verify ) {
269
267
// Turn on domain name check
270
268
// Loading of CA certificates and verification of remote host name
271
269
// go hand in hand - one is useless without the other.
272
- CyaSSL_check_domain_name (ssl , hostname );
270
+ wolfSSL_check_domain_name (ssl , hostname );
273
271
}
274
- CyaSSL_set_fd (ssl , sockfd );
272
+ wolfSSL_set_fd (ssl , sockfd );
275
273
276
274
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 );
278
276
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 );
282
280
goto error ;
283
281
} 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 );
285
283
goto error ;
286
284
}
287
285
@@ -300,14 +298,14 @@ https_get(const int sockfd, const char *req, const char *hostname)
300
298
/** We don't have to use FD_ISSET() because there
301
299
* was only one fd. */
302
300
memset (readbuf , 0 , MAX_BUF );
303
- numbytes = CyaSSL_read (ssl , readbuf , MAX_BUF - 1 );
301
+ numbytes = wolfSSL_read (ssl , readbuf , MAX_BUF - 1 );
304
302
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 );
307
305
debug (LOG_ERR , "An error occurred while reading from server: %s" , sslerrmsg );
308
306
goto error ;
309
307
} 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
311
309
connection. We can't distinguish between these cases right now. */
312
310
done = 1 ;
313
311
} else {
@@ -326,15 +324,15 @@ https_get(const int sockfd, const char *req, const char *hostname)
326
324
327
325
close (sockfd );
328
326
329
- CyaSSL_free (ssl );
327
+ wolfSSL_free (ssl );
330
328
331
329
retval = pstr_to_string (response );
332
330
debug (LOG_DEBUG , "HTTPS Response from Server: [%s]" , retval );
333
331
return retval ;
334
332
335
333
error :
336
334
if (ssl ) {
337
- CyaSSL_free (ssl );
335
+ wolfSSL_free (ssl );
338
336
}
339
337
if (sockfd >= 0 ) {
340
338
close (sockfd );
@@ -344,4 +342,4 @@ https_get(const int sockfd, const char *req, const char *hostname)
344
342
return NULL ;
345
343
}
346
344
347
- #endif /* USE_CYASSL */
345
+ #endif /* USE_WOLFSSL */
0 commit comments