Skip to content

Commit db0cb33

Browse files
authored
Merge pull request #505 from uhle/wolfssl-support
Add support for WolfSSL as a GPLv2 compliant alternative to OpenSSL
2 parents 890be3b + 018e60a commit db0cb33

File tree

16 files changed

+286
-208
lines changed

16 files changed

+286
-208
lines changed

CMakeLists.txt

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,39 @@ if(NOT USE_PCAP)
8181
"${PROJECT_SOURCE_DIR}/src/send_packets.c")
8282
endif(NOT USE_PCAP)
8383

84+
find_package(PkgConfig QUIET) # import pkg_check_modules() and friends
8485
if(USE_SSL)
85-
add_definitions("-DUSE_TLS -DUSE_OPENSSL")
86+
if(PKG_CONFIG_FOUND)
87+
pkg_search_module(SSL openssl>=0.9.8 wolfssl>=3.15.0)
88+
endif()
89+
if(SSL_FOUND)
90+
if("${SSL_LIBRARIES}" MATCHES "wolfssl")
91+
set(WOLFSSL_FOUND True)
92+
else()
93+
set(OPENSSL_FOUND True)
94+
endif()
95+
else()
96+
find_library(OPENSSL_SSL_LIBRARY NAMES ssl)
97+
find_library(OPENSSL_CRYPTO_LIBRARY NAMES crypto)
98+
if(OPENSSL_SSL_LIBRARY AND OPENSSL_CRYPTO_LIBRARY)
99+
set(SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
100+
set(OPENSSL_FOUND True)
101+
else()
102+
find_library(WOLFSSL_LIBRARY NAMES wolfssl)
103+
if(WOLFSSL_LIBRARY)
104+
set(SSL_LIBRARIES ${WOLFSSL_LIBRARY})
105+
set(WOLFSSL_FOUND True)
106+
endif()
107+
endif()
108+
if(NOT OPENSSL_FOUND AND NOT WOLFSSL_FOUND)
109+
message(FATAL_ERROR "Neither OpenSSL nor WolfSSL was found; please install a devel package")
110+
endif()
111+
endif()
112+
if(OPENSSL_FOUND)
113+
add_definitions("-DUSE_TLS" "-DUSE_OPENSSL")
114+
elseif(WOLFSSL_FOUND)
115+
add_definitions("-DUSE_TLS" "-DUSE_WOLFSSL" "-DOPENSSL_ALL")
116+
endif()
86117
endif()
87118

88119
if(USE_PCAP)
@@ -134,7 +165,6 @@ if(BUILD_STATIC)
134165
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
135166
endif(BUILD_STATIC)
136167

137-
find_package(PkgConfig QUIET) # import pkg_check_modules() and friends
138168
if(PKG_CONFIG_FOUND)
139169
pkg_search_module(CURSES_LIBRARY ncursesw cursesw ncurses curses)
140170
if(CURSES_LIBRARY_FOUND)
@@ -187,10 +217,14 @@ if(USE_GSL AND GSL_LIBRARY)
187217
target_link_libraries(sipp_unittest gsl gslcblas)
188218
endif(USE_GSL AND GSL_LIBRARY)
189219

190-
if(USE_SSL)
191-
target_link_libraries(sipp crypto ssl)
192-
target_link_libraries(sipp_unittest crypto ssl)
193-
endif(USE_SSL)
220+
if(USE_SSL AND SSL_LIBRARIES)
221+
target_link_libraries(sipp ${SSL_LIBRARIES})
222+
target_link_libraries(sipp_unittest ${SSL_LIBRARIES})
223+
if(SSL_INCLUDE_DIRS)
224+
target_include_directories(sipp SYSTEM PUBLIC ${SSL_INCLUDE_DIRS})
225+
target_include_directories(sipp_unittest SYSTEM PUBLIC ${SSL_INCLUDE_DIRS})
226+
endif(SSL_INCLUDE_DIRS)
227+
endif(USE_SSL AND SSL_LIBRARIES)
194228

195229
if(USE_PCAP)
196230
target_link_libraries(sipp pcap)

docs/installation.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Installing SIPp
6363

6464
+ C++ Compiler
6565
+ curses or ncurses library
66-
+ For TLS support: OpenSSL >= 0.9.8
66+
+ For TLS support: OpenSSL >= 0.9.8 or WolfSSL >= 3.15.0
6767
+ For pcap play support: libpcap and libnet
6868
+ For SCTP support: lksctp-tools
6969
+ For distributed pauses: `Gnu Scientific Libraries`_
@@ -80,9 +80,9 @@ Installing SIPp
8080
make
8181

8282
+ With TLS support, you must have installed `OpenSSL library`_
83-
(>=0.9.8) (which may come with your system). Building SIPp
84-
consists only of adding the ``--with-openssl`` option to the
85-
configure command::
83+
(>=0.9.8) or `WolfSSL library`_ (>=3.15.0) (which may come with your
84+
system). Building SIPp consists only of adding the ``--with-openssl``
85+
option to the configure command::
8686

8787
tar -xvzf sipp-xxx.tar.gz
8888
cd sipp
@@ -130,3 +130,4 @@ Installing SIPp
130130
.. _hewlett-packard: https://www.hp.com/
131131
.. _SIPp's master tree: https://github.com/SIPp/sipp/tree/master
132132
.. _OpenSSL library: https://www.openssl.org/
133+
.. _WolfSSL library: https://www.wolfssl.com/

include/call.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ class call : virtual public task, virtual public listener, public virtual socket
199199
JLSRTP _rxUACVideo;
200200
JLSRTP _txUASVideo;
201201
JLSRTP _rxUASVideo;
202-
#ifdef USE_OPENSSL
202+
#ifdef USE_TLS
203203
char _pref_audio_cs_out[24];
204204
char _pref_video_cs_out[24];
205-
#endif // USE_OPENSSL
205+
#endif // USE_TLS
206206
#endif // RTP_STREAM
207207

208208
/* holds the auth header and if the challenge was 401 or 407 */
@@ -340,11 +340,11 @@ class call : virtual public task, virtual public listener, public virtual socket
340340

341341
#ifdef RTP_STREAM
342342
std::string extract_rtp_remote_addr(const char * message, int &ip_ver, int &audio_port, int &video_port);
343-
#ifdef USE_OPENSSL
343+
#ifdef USE_TLS
344344
int check_audio_ciphersuite_match(SrtpAudioInfoParams &pA);
345345
int check_video_ciphersuite_match(SrtpVideoInfoParams &pV);
346346
int extract_srtp_remote_info(const char * msg, SrtpAudioInfoParams &pA, SrtpVideoInfoParams &pV);
347-
#endif // USE_OPENSSL
347+
#endif // USE_TLS
348348
#endif // RTP_STREAM
349349

350350
bool lost(int index);
@@ -363,10 +363,10 @@ class call : virtual public task, virtual public listener, public virtual socket
363363
char *debugBuffer;
364364
int debugLength;
365365

366-
#ifdef USE_OPENSSL
366+
#ifdef USE_TLS
367367
FILE* _srtpctxdebugfile;
368368
int logSrtpInfo(const char *fmt, ...);
369-
#endif // USE_OPENSSL
369+
#endif // USE_TLS
370370

371371
SessionState _sessionStateCurrent;
372372
SessionState _sessionStateOld;

include/jlsrtp.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@
1919
#ifndef __JLSRTP__
2020
#define __JLSRTP__
2121

22-
#ifdef USE_OPENSSL
23-
22+
#if defined(USE_OPENSSL)
2423
#include <openssl/aes.h>
2524
#include <openssl/evp.h>
2625
#include <openssl/rand.h>
2726
#include <openssl/hmac.h>
27+
#elif defined(USE_WOLFSSL)
28+
#include <wolfssl/openssl/aes.h>
29+
#include <wolfssl/openssl/evp.h>
30+
#include <wolfssl/openssl/rand.h>
31+
#include <wolfssl/openssl/hmac.h>
32+
#endif
33+
34+
#if defined(USE_OPENSSL) || defined(USE_WOLFSSL)
35+
2836
#include <string>
2937
#include <vector>
3038

@@ -1166,7 +1174,7 @@ class JLSRTP
11661174

11671175
};
11681176

1169-
#else // !USE_OPENSSL
1177+
#else // !USE_OPENSSL && !USE_WOLFSSL
11701178

11711179
class JLSRTP
11721180
{
@@ -1187,7 +1195,7 @@ class JLSRTP
11871195
~JLSRTP();
11881196
};
11891197

1190-
#endif // USE_OPENSSL
1198+
#endif // USE_OPENSSL || USE_WOLFSSL
11911199

11921200
#endif // __JLSRTP__
11931201

include/message.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ typedef enum {
9191
,
9292
E_Message_RTPStream_Audio_Port,
9393
E_Message_RTPStream_Video_Port,
94-
#ifdef USE_OPENSSL
94+
#ifdef USE_TLS
9595
E_Message_CryptoTag1Audio,
9696
E_Message_CryptoTag2Audio,
9797
E_Message_CryptoSuiteAesCm128Sha1801Audio,
@@ -124,7 +124,7 @@ typedef enum {
124124
E_Message_UEAesCm128Sha1802Video,
125125
E_Message_UEAesCm128Sha1321Video,
126126
E_Message_UEAesCm128Sha1322Video,
127-
#endif // USE_OPENSSL
127+
#endif // USE_TLS
128128
#endif // RTP_STREAM
129129
} MessageCompType;
130130

include/rtpstream.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define RTPECHO_MAX_FILENAMELEN 256
2929
#define RTPECHO_MAX_PAYLOADNAME 256
3030

31-
#ifdef USE_OPENSSL
31+
#ifdef USE_TLS
3232
typedef struct _SrtpAudioInfoParams
3333
{
3434
bool audio_found;
@@ -54,7 +54,7 @@ typedef struct _SrtpVideoInfoParams
5454
bool primary_unencrypted_video_srtp;
5555
bool secondary_unencrypted_video_srtp;
5656
} SrtpVideoInfoParams;
57-
#endif // USE_OPENSSL
57+
#endif // USE_TLS
5858

5959
struct threaddata_t;
6060
struct taskentry_t;
@@ -123,11 +123,11 @@ struct taskentry_t
123123
int video_rtp_socket;
124124
int video_rtcp_socket;
125125

126-
#ifdef USE_OPENSSL
126+
#ifdef USE_TLS
127127
/* audio/video SRTP echo activity indicators */
128128
int audio_srtp_echo_active;
129129
int video_srtp_echo_active;
130-
#endif // USE_OPENSSL
130+
#endif // USE_TLS
131131

132132
/* rtp peer address structures */
133133
struct sockaddr_storage remote_audio_rtp_addr;
@@ -147,12 +147,12 @@ struct taskentry_t
147147
int audio_active;
148148
int video_active;
149149

150-
#ifdef USE_OPENSSL
150+
#ifdef USE_TLS
151151
SrtpAudioInfoParams local_srtp_audio_params;
152152
SrtpAudioInfoParams remote_srtp_audio_params;
153153
SrtpVideoInfoParams local_srtp_video_params;
154154
SrtpVideoInfoParams remote_srtp_video_params;
155-
#endif // USE_OPENSSL
155+
#endif // USE_TLS
156156
};
157157

158158
struct rtpstream_callinfo_t
@@ -209,12 +209,12 @@ int rtpstream_get_local_videoport(rtpstream_callinfo_t *callinfo);
209209
void rtpstream_set_remote(rtpstream_callinfo_t* callinfo, int ip_ver, const char* ip_addr,
210210
int audio_port, int video_port);
211211

212-
#ifdef USE_OPENSSL
212+
#ifdef USE_TLS
213213
int rtpstream_set_srtp_audio_local(rtpstream_callinfo_t *callinfo, SrtpAudioInfoParams &p);
214214
int rtpstream_set_srtp_audio_remote(rtpstream_callinfo_t *callinfo, SrtpAudioInfoParams &p);
215215
int rtpstream_set_srtp_video_local(rtpstream_callinfo_t *callinfo, SrtpVideoInfoParams &p);
216216
int rtpstream_set_srtp_video_remote(rtpstream_callinfo_t *callinfo, SrtpVideoInfoParams &p);
217-
#endif // USE_OPENSSL
217+
#endif // USE_TLS
218218

219219
int rtpstream_cache_file(char *filename,
220220
int mode /* 0: FILE - 1: PATTERN */,

include/sipp.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
/* Std C includes */
2424
#include "config.h"
25+
#include "defines.h"
2526
#include <stdio.h>
2627
#include <stdlib.h>
2728
#include <string.h>
@@ -141,10 +142,10 @@
141142
#define MAX_PEER_SIZE 4096 /* 3pcc extended mode: max size of peer names */
142143
#define MAX_LOCAL_TWIN_SOCKETS 10 /*3pcc extended mode:max number of peers from which
143144
cmd messages are received */
144-
#ifdef USE_OPENSSL
145+
#ifdef USE_TLS
145146
#define DEFAULT_PREFERRED_AUDIO_CRYPTOSUITE ((char*)"AES_CM_128_HMAC_SHA1_80")
146147
#define DEFAULT_PREFERRED_VIDEO_CRYPTOSUITE ((char*)"AES_CM_128_HMAC_SHA1_80")
147-
#endif // USE_OPENSSL
148+
#endif // USE_TLS
148149

149150
/******************** Default parameters ***********************/
150151

@@ -263,9 +264,9 @@ MAYBE_EXTERN int rtp_default_payload DEFVAL(DEFAULT_RTP_PAYLO
263264
MAYBE_EXTERN int rtp_tasks_per_thread DEFVAL(DEFAULT_RTP_THREADTASKS);
264265
MAYBE_EXTERN int rtp_buffsize DEFVAL(65535);
265266
MAYBE_EXTERN bool rtpcheck_debug DEFVAL(0);
266-
#ifdef USE_OPENSSL
267+
#ifdef USE_TLS
267268
MAYBE_EXTERN bool srtpcheck_debug DEFVAL(0);
268-
#endif // USE_OPENSSL
269+
#endif // USE_TLS
269270
MAYBE_EXTERN double audiotolerance DEFVAL(1.0);
270271
MAYBE_EXTERN double videotolerance DEFVAL(1.0);
271272
#endif // RTP_STREAM

include/socket.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#ifndef __SIPP_SOCKET_H__
2121
#define __SIPP_SOCKET_H__
2222

23-
#ifdef USE_OPENSSL
23+
#ifdef USE_TLS
2424
#include "sslsocket.hpp"
2525
#endif
2626

@@ -129,7 +129,7 @@ class SIPpSocket {
129129

130130
bool ss_call_socket; /* Is this a call socket? */
131131

132-
#ifdef USE_OPENSSL
132+
#if defined(USE_OPENSSL) || defined(USE_WOLFSSL)
133133
SSL *ss_ssl; /* The underlying SSL descriptor for this socket. */
134134
BIO *ss_bio; /* The underlying BIO descriptor for this socket. */
135135
#endif
@@ -155,7 +155,7 @@ bool reconnect_allowed();
155155
/********************** Network Interfaces ********************/
156156

157157
int send_message(int s, void ** comp_state, char * msg);
158-
#ifdef USE_OPENSSL
158+
#if defined(USE_OPENSSL) || defined(USE_WOLFSSL)
159159
int send_message_tls(SSL *s, void ** comp_state, char * msg);
160160
#endif
161161

include/sslsocket.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@
1919
#ifndef __SSLSOCKET__
2020
#define __SSLSOCKET__
2121

22-
#ifdef USE_OPENSSL
22+
#if defined(USE_OPENSSL)
2323
#include <openssl/bio.h>
2424
#include <openssl/err.h>
2525
#include <openssl/rand.h>
2626
#include <openssl/ssl.h>
2727
#include <openssl/x509v3.h>
2828
#include <pthread.h>
29+
#elif defined(USE_WOLFSSL)
30+
#include <wolfssl/openssl/bio.h>
31+
#include <wolfssl/openssl/err.h>
32+
#include <wolfssl/openssl/rand.h>
33+
#include <wolfssl/openssl/ssl.h>
34+
#include <wolfssl/openssl/x509v3.h>
2935
#endif
3036

3137
/* Initialises an SSL context and makes the lib thread safe */
@@ -41,7 +47,7 @@ enum tls_init_status TLS_init_context(void);
4147

4248
/* Helpers for OpenSSL */
4349

44-
#ifdef USE_OPENSSL
50+
#if defined(USE_OPENSSL) || defined(USE_WOLFSSL)
4551
SSL* SSL_new_client();
4652
SSL* SSL_new_server();
4753
const char *SSL_error_string(int ssl_error, int orig_ret);

0 commit comments

Comments
 (0)