Skip to content

Commit 0954240

Browse files
committed
Add wolfSSL support
- Add WITH_WOLFSSL option to cmake - Gate out functions with potential missing wolfSSL API - Update github action to test wolfSSL
1 parent b44665c commit 0954240

5 files changed

Lines changed: 74 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on: [push, pull_request]
55
jobs:
66
build:
77
strategy:
8+
fail-fast: false
89
matrix:
910
os:
1011
- ubuntu-latest
@@ -14,6 +15,7 @@ jobs:
1415
- "-DWITH_OPENSSL=ON -DWITH_GNUTLS=OFF -DWITH_GCRYPT=OFF" # build with OpenSSL
1516
- "-DWITH_OPENSSL=OFF -DWITH_GNUTLS=ON -DWITH_GCRYPT=ON" # build with GnuTLS and Libgrypt
1617
- "-DWITH_OPENSSL=OFF -DWITH_GNUTLS=OFF -DWITH_GCRYPT=OFF" # build without external encryption libraries
18+
- "-DWITH_OPENSSL=OFF -DWITH_GNUTLS=OFF -DWITH_GCRYPT=OFF -DWITH_WOLFSSL=ON" # build with wolfSSL
1719
- "-DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-mingw32-linux.cmake" # crosscompile with MinGW toolchain
1820
include:
1921
- os: macos-latest
@@ -31,29 +33,29 @@ jobs:
3133
cmake_options: "-DWITH_OPENSSL=OFF -DWITH_GNUTLS=ON -DWITH_GCRYPT=ON" # don't have GnuTLS and libgcrypt on Windows (yet)
3234
runs-on: ${{ matrix.os }}
3335
steps:
34-
- uses: actions/checkout@v3
36+
- uses: actions/checkout@v4
3537
- name: Install Ubuntu Build Dependencies
3638
if: ${{ matrix.os == 'ubuntu-latest' }}
3739
run: |
3840
sudo apt update
39-
sudo apt install libsdl2-dev liblzo2-dev libssl-dev gnutls-dev libgcrypt-dev mingw-w64-x86-64-dev binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64 wine
41+
sudo apt install libsdl2-dev liblzo2-dev libssl-dev gnutls-dev libgcrypt-dev libwolfssl-dev mingw-w64-x86-64-dev binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64 wine
4042
- name: Install MacOS Build Dependencies
4143
if: ${{ matrix.os == 'macos-latest' }}
4244
run: |
4345
unset HOMEBREW_NO_INSTALL_FROM_API
4446
brew untap homebrew/core homebrew/cask
4547
brew update
46-
brew install sdl2 lzo
48+
brew install sdl2 lzo wolfssl
4749
- name: Install Windows Build Dependencies
4850
if: ${{ matrix.os == 'windows-latest' }}
4951
run: |
50-
vcpkg install zlib libjpeg-turbo libpng --triplet=x64-windows # could install more but should use run-vcpkg with caching for this
52+
vcpkg install zlib libjpeg-turbo libpng pkgconf wolfssl --triplet=x64-windows # could install more but should use run-vcpkg with caching for this
5153
- name: Build
5254
run: |
5355
mkdir build
5456
cd build
5557
cmake ${{ matrix.cmake_options }} ${{ matrix.macos_cmake_options }} ${{ matrix.windows_cmake_options }} ..
56-
cmake --build .
58+
cmake --build . --verbose
5759
- name: Prepare Test
5860
if: ${{ matrix.os == 'ubuntu-latest' }} # only ubuntu does crosscompile with MinGW toolchain
5961
run: |

CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ option(WITH_THREADS "Search for a threading library to build with multithreading
6464
option(PREFER_WIN32THREADS "When searching for a threading library, prefer win32 threads if they are found" OFF)
6565
option(WITH_GNUTLS "Search for the GnuTLS secure communications library to support TLS" ON)
6666
option(WITH_OPENSSL "Search for the OpenSSL cryptography library to support TLS and use as crypto backend" ON)
67+
option(WITH_WOLFSSL "Search for the wolfSSL cryptography library to support TLS and use as crypto backend" OFF)
6768
option(WITH_SYSTEMD "Search for libsystemd to build with systemd socket activation support" ON)
6869
option(WITH_GCRYPT "Search for Libgcrypt to use as crypto backend" ON)
6970
option(WITH_FFMPEG "Search for FFMPEG to build an example VNC to MPEG encoder" ON)
@@ -182,6 +183,14 @@ if(WITH_OPENSSL)
182183
find_package(OpenSSL)
183184
endif(WITH_OPENSSL)
184185

186+
if(WITH_WOLFSSL)
187+
find_package(PkgConfig)
188+
pkg_check_modules(WOLFSSL "wolfssl")
189+
if(WOLFSSL_FOUND)
190+
link_directories(${WOLFSSL_LIBRARY_DIRS})
191+
endif(WOLFSSL_FOUND)
192+
endif(WITH_WOLFSSL)
193+
185194

186195
if(WITH_SYSTEMD AND NOT ANDROID AND NOT WIN32)
187196
find_package(PkgConfig)
@@ -275,6 +284,9 @@ endif(PNG_FOUND)
275284
if(NOT OPENSSL_FOUND)
276285
unset(OPENSSL_LIBRARIES) # would otherwise contain -NOTFOUND, confusing target_link_libraries()
277286
endif()
287+
if(NOT WOLFSSL_FOUND)
288+
unset(WOLFSSL_LIBRARIES) # would otherwise contain -NOTFOUND, confusing target_link_libraries()
289+
endif()
278290
if(SYSTEMD_FOUND)
279291
add_definitions(-DLIBVNCSERVER_WITH_SYSTEMD)
280292
include_directories(${SYSTEMD_INCLUDE_DIRS})
@@ -290,6 +302,10 @@ elseif(OPENSSL_FOUND)
290302
message(STATUS "Building crypto with OpenSSL")
291303
set(CRYPTO_LIBRARIES ${OPENSSL_LIBRARIES})
292304
set(CRYPTO_SOURCES ${COMMON_DIR}/crypto_openssl.c)
305+
elseif(WOLFSSL_FOUND)
306+
message(STATUS "Building crypto with wolfSSL")
307+
set(CRYPTO_LIBRARIES ${WOLFSSL_LIBRARIES})
308+
set(CRYPTO_SOURCES ${COMMON_DIR}/crypto_openssl.c)
293309
else()
294310
message(STATUS "Building crypto with builtin functions, only including SHA1 and D3DES")
295311
set(CRYPTO_SOURCES ${COMMON_DIR}/crypto_included.c ${COMMON_DIR}/sha1.c ${COMMON_DIR}/d3des.c)
@@ -312,6 +328,13 @@ if(OPENSSL_FOUND)
312328
set(LIBVNCSERVER_HAVE_LIBSSL 1)
313329
endif(OPENSSL_FOUND)
314330

331+
if(WOLFSSL_FOUND)
332+
include_directories("${WOLFSSL_INCLUDE_DIRS}" "${WOLFSSL_INCLUDEDIR}/wolfssl")
333+
set(LIBVNCSERVER_HAVE_LIBWOLFSSL 1)
334+
set(LIBVNCSERVER_HAVE_LIBSSL 1)
335+
add_definitions(-DEXTERNAL_OPTS_OPENVPN -DOPENSSL_VERSION_NUMBER=0x10001040L)
336+
endif(WOLFSSL_FOUND)
337+
315338
if(WITH_IPv6)
316339
if(WIN32 AND LIBVNCSERVER_HAVE_WS2TCPIP_H AND LIBVNCSERVER_HAVE_VPRINTF)
317340
set(LIBVNCSERVER_IPv6 1)
@@ -448,6 +471,17 @@ elseif(OPENSSL_FOUND)
448471
${LIBVNCSERVER_DIR}/rfbssl_openssl.c
449472
)
450473
include_directories(${OPENSSL_INCLUDE_DIR})
474+
elseif(WOLFSSL_FOUND)
475+
message(STATUS "Building TLS with wolfSSL")
476+
set(LIBVNCCLIENT_SOURCES
477+
${LIBVNCCLIENT_SOURCES}
478+
${LIBVNCCLIENT_DIR}/tls_openssl.c
479+
)
480+
set(LIBVNCSERVER_SOURCES
481+
${LIBVNCSERVER_SOURCES}
482+
${LIBVNCSERVER_DIR}/rfbssl_openssl.c
483+
)
484+
include_directories("${WOLFSSL_INCLUDE_DIRS}" "${WOLFSSL_INCLUDEDIR}/wolfssl")
451485
else()
452486
message(STATUS "Building without TLS")
453487
set(LIBVNCCLIENT_SOURCES
@@ -548,6 +582,7 @@ target_link_libraries(vncclient
548582
${CRYPTO_LIBRARIES}
549583
${GNUTLS_LIBRARIES}
550584
${OPENSSL_LIBRARIES}
585+
${WOLFSSL_LIBRARIES}
551586
)
552587
target_link_libraries(vncserver
553588
${ADDITIONAL_LIBS}
@@ -558,6 +593,7 @@ target_link_libraries(vncserver
558593
${CRYPTO_LIBRARIES}
559594
${GNUTLS_LIBRARIES}
560595
${OPENSSL_LIBRARIES}
596+
${WOLFSSL_LIBRARIES}
561597
)
562598

563599
SET_TARGET_PROPERTIES(vncclient vncserver

include/rfb/rfbconfig.h.cmakein

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@
160160
/* Define to 1 if OpenSSL is present */
161161
#cmakedefine LIBVNCSERVER_HAVE_LIBSSL 1
162162

163+
/* Define to 1 if wolfSSL is present */
164+
#cmakedefine LIBVNCSERVER_HAVE_LIBWOLFSSL 1
165+
163166
/* Define to 1 if Cyrus SASL is present */
164167
#cmakedefine LIBVNCSERVER_HAVE_SASL 1
165168

src/common/crypto_openssl.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ static unsigned char reverseByte(unsigned char b) {
4242

4343
int hash_md5(void *out, const void *in, const size_t in_len)
4444
{
45+
#if defined(LIBVNCSERVER_HAVE_LIBWOLFSSL) && defined(NO_MD5)
46+
/* wolfSSL in MacOS brew doesn't have md5 enabled */
47+
return 0;
48+
#else
4549
MD5_CTX md5;
4650
if(!MD5_Init(&md5))
4751
return 0;
@@ -50,6 +54,7 @@ int hash_md5(void *out, const void *in, const size_t in_len)
5054
if(!MD5_Final(out, &md5))
5155
return 0;
5256
return 1;
57+
#endif
5358
}
5459

5560
int hash_sha1(void *out, const void *in, const size_t in_len)
@@ -71,6 +76,10 @@ void random_bytes(void *out, size_t len)
7176

7277
int encrypt_rfbdes(void *out, int *out_len, const unsigned char key[8], const void *in, const size_t in_len)
7378
{
79+
#if defined(LIBVNCSERVER_HAVE_LIBWOLFSSL) && (defined(NO_DES3) || !defined(WOLFSSL_DES_ECB))
80+
/* wolfSSL in MacOS brew doesn't have des enabled */
81+
return 0;
82+
#else
7483
int result = 0;
7584
EVP_CIPHER_CTX *des = NULL;
7685
unsigned char mungedkey[8];
@@ -110,10 +119,15 @@ int encrypt_rfbdes(void *out, int *out_len, const unsigned char key[8], const vo
110119
OSSL_PROVIDER_unload(providerDefault);
111120
#endif
112121
return result;
122+
#endif
113123
}
114124

115125
int decrypt_rfbdes(void *out, int *out_len, const unsigned char key[8], const void *in, const size_t in_len)
116126
{
127+
#if defined(LIBVNCSERVER_HAVE_LIBWOLFSSL) && (defined(NO_DES3) || !defined(WOLFSSL_DES_ECB))
128+
/* wolfSSL in MacOS brew doesn't have des enabled */
129+
return 0;
130+
#else
117131
int result = 0;
118132
EVP_CIPHER_CTX *des = NULL;
119133
unsigned char mungedkey[8];
@@ -155,10 +169,15 @@ int decrypt_rfbdes(void *out, int *out_len, const unsigned char key[8], const vo
155169
OSSL_PROVIDER_unload(providerDefault);
156170
#endif
157171
return result;
172+
#endif
158173
}
159174

160175
int encrypt_aes128ecb(void *out, int *out_len, const unsigned char key[16], const void *in, const size_t in_len)
161176
{
177+
#if defined(LIBVNCSERVER_HAVE_LIBWOLFSSL) && (!defined(HAVE_AES_ECB) || !defined(WOLFSSL_AES_128))
178+
/* wolfSSL in MacOS brew doesn't have aes-ecb enabled */
179+
return 0;
180+
#else
162181
int result = 0;
163182
EVP_CIPHER_CTX *aes;
164183

@@ -175,6 +194,7 @@ int encrypt_aes128ecb(void *out, int *out_len, const unsigned char key[16], cons
175194
out:
176195
EVP_CIPHER_CTX_free(aes);
177196
return result;
197+
#endif
178198
}
179199

180200
static void pad_leading_zeros(uint8_t *out, const size_t current_len, const size_t expected_len) {

src/libvncclient/tls_openssl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ static int wait_for_data(SSL *ssl, int ret, int timeout)
212212
static rfbBool
213213
load_crls_from_file(char *file, SSL_CTX *ssl_ctx)
214214
{
215+
#if defined(LIBVNCSERVER_HAVE_LIBWOLFSSL) && (!defined(OPENSSL_ALL) || defined(NO_BIO))
216+
/* wolfSSL in Windows vcpkg is missing API */
217+
return 0;
218+
#else
215219
X509_STORE *st;
216220
int i;
217221
int count = 0;
@@ -245,6 +249,7 @@ load_crls_from_file(char *file, SSL_CTX *ssl_ctx)
245249
return TRUE;
246250
else
247251
return FALSE;
252+
#endif
248253
}
249254

250255
static SSL *
@@ -350,7 +355,10 @@ open_ssl_connection (rfbClient *client, int sockfd, rfbBool anonTLS, rfbCredenti
350355
}
351356

352357
SSL_set_fd (ssl, sockfd);
358+
#if !defined(LIBVNCSERVER_HAVE_LIBWOLFSSL) || defined(OPENSSL_ALL)
359+
/* wolfSSL in Windows vcpkg is missing API */
353360
SSL_CTX_set_app_data (ssl_ctx, client);
361+
#endif
354362

355363
do
356364
{

0 commit comments

Comments
 (0)