Skip to content

Commit b1c5c37

Browse files
committed
bearssl
BearSSL just doesn't address DTLS. Otherwise it should be a full client-server TLS implementation.
1 parent 7d80570 commit b1c5c37

50 files changed

Lines changed: 3614 additions & 274 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.sai.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@
116116
"cmake": "-DLWS_WITH_GNUTLS=1",
117117
"platforms": "none, rocky9/aarch64-a72a55-rk3588/gcc"
118118
},
119+
"bearssl": {
120+
"cmake": "-DLWS_WITH_BEARSSL=1 -DLWS_BEARSSL_INCLUDE_DIRS=/opt/BearSSL/inc -DLWS_BEARSSL_LIBRARIES=/opt/BearSSL/build/libbearssl.so",
121+
"platforms": "none, rocky9/aarch64-a72a55-rk3588/gcc"
122+
},
119123
"default-examples-awslc": {
120124
"cmake": "-DLWS_WITH_AWSLC=1 -DLWS_OPENSSL_INCLUDE_DIRS=\"/usr/aws-lc/include\" -DLWS_OPENSSL_LIBRARIES=\"/usr/aws-lc/lib64/libssl.so;/usr/aws-lc/lib64/libcrypto.so\" -DLWS_WITH_MINIMAL_EXAMPLES=1",
121125
"platforms": "none, rocky9/aarch64-a72a55-rk3588/gcc"

CMakeLists-implied-options.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if(IOS)
2727
set(LWS_DETECTED_PLAT_IOS 1)
2828
endif()
2929

30-
if (LWS_WITH_SCHANNEL OR LWS_WITH_GNUTLS OR LWS_WITH_MBEDTLS)
30+
if (LWS_WITH_SCHANNEL OR LWS_WITH_GNUTLS OR LWS_WITH_MBEDTLS OR LWS_WITH_BEARSSL)
3131
set(LWS_WITH_SSL 1)
3232
endif()
3333

@@ -170,12 +170,16 @@ if (LWS_WITH_TRANSPORT_SEQUENCER)
170170
set(LWS_WITH_LWS_DSH 1)
171171
endif()
172172

173-
if (LWS_WITH_WEBRTC)
174-
set(LWS_WITH_UDP 1)
175-
set(LWS_WITH_DTLS 1)
173+
if (LWS_WITH_WEBRTC_MIXER)
174+
set(LWS_WITH_WEBRTC 1)
176175
set(LWS_WITH_ALSA 1 CACHE BOOL "Enable alsa audio example" FORCE)
177176
set(LWS_WITH_OPUS 1 CACHE BOOL "Enable opus audio codec" FORCE)
178177
set(LWS_WITH_GSTREAMER 1 CACHE BOOL "Enable gstreamer" FORCE)
178+
endif()
179+
180+
if (LWS_WITH_WEBRTC)
181+
set(LWS_WITH_UDP 1)
182+
set(LWS_WITH_DTLS 1)
179183
set(LWS_WITH_PLUGINS 1 CACHE BOOL "Enable plugins" FORCE)
180184
set(LWS_WITH_V4L2 1)
181185
set(LWS_WITH_LIBV4L2 1)
@@ -479,7 +483,7 @@ if (LWS_SSL_SERVER_WITH_ECDH_CERT)
479483
endif()
480484

481485
# LWS_OPENSSL_SUPPORT deprecated... use LWS_WITH_TLS
482-
if (LWS_WITH_SSL OR LWS_WITH_MBEDTLS)
486+
if (LWS_WITH_SSL OR LWS_WITH_MBEDTLS OR LWS_WITH_BEARSSL)
483487
set(LWS_OPENSSL_SUPPORT 1)
484488
set(LWS_WITH_TLS 1)
485489
endif()

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ option(LWS_WITH_GZINFLATE "Enable internal minimal gzip inflator" ON)
194194
option(LWS_WITH_JPEG "Enable stateful JPEG stream decoder" ON)
195195
option(LWS_WITH_DLO "Enable Display List Objects" ON)
196196
option(LWS_WITH_WEBRTC "Enable WebRTC" OFF)
197+
option(LWS_WITH_WEBRTC_MIXER "Enable WebRTC mixer (gstreamer)" OFF)
197198
option(LWS_WITH_TRANSCODE "Enable video transcoding support (requires ffmpeg)" OFF)
198199
option(LWS_WITH_V4L2 "Enable V4L2 support (Linux only)" OFF)
199200
option(LWS_WITH_LIBV4L2 "Link against libv4l2 if available" OFF)
@@ -232,6 +233,8 @@ option(LWS_CTEST_INTERNET_AVAILABLE "CTest will performs tests that need the Int
232233
#
233234
option(LWS_WITH_SSL "Include SSL support (defaults to OpenSSL or similar, mbedTLS if LWS_WITH_MBEDTLS is set)" ON)
234235
option(LWS_WITH_MBEDTLS "Use mbedTLS (>=2.0) replacement for OpenSSL. When setting this, you also may need to specify LWS_MBEDTLS_LIBRARIES and LWS_MBEDTLS_INCLUDE_DIRS" OFF)
236+
option(LWS_WITH_BEARSSL "Use BearSSL replacement for OpenSSL. When setting this, you also may need to specify LWS_BEARSSL_LIBRARIES and LWS_BEARSSL_INCLUDE_DIRS" OFF)
237+
set(LWS_BEARSSL_PROFILE "full" CACHE STRING "BearSSL profile to use (e.g. full, client, minimal)")
235238
option(LWS_WITH_SCHANNEL "Use Windows SChannel for SSL" OFF)
236239
option(LWS_WITH_BORINGSSL "Use BoringSSL replacement for OpenSSL" OFF)
237240
option(LWS_WITH_GNUTLS "Use GnuTLS for SSL" OFF)

READMEs/README.build-windows.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ additional CMake options on lws:
122122
-DLWS_WITH_MBEDTLS=TRUE
123123
```
124124

125+
### Alternative: BearSSL (or OpenSSL/MbedTLS, see above)
126+
127+
BearSSL is a highly optimized, minimalistic alternative to OpenSSL and MbedTLS. It is easily cross-compiled or built on Windows. Note that BearSSL currently does not support DTLS. To use it, simply provide the include and library paths:
128+
129+
```
130+
-DLWS_WITH_BEARSSL=TRUE
131+
-DLWS_BEARSSL_INCLUDE_DIRS=C:/path/to/bearssl/inc
132+
-DLWS_BEARSSL_LIBRARIES=C:/path/to/bearssl/build/bearssl.lib
133+
```
134+
125135
### Powershell
126136

127137
CMake wants it and the version that comes with windows is too old to have pwsh.exe.

READMEs/README.build.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ plugins and lwsws.
334334
- If you are really restricted on memory, code size, or don't care about TLS
335335
speed, mbedTLS is a good choice: `cmake .. -DLWS_WITH_MBEDTLS=1`
336336

337+
- If you want an extremely lightweight, highly optimized TLS library with a minimal memory footprint and fast execution speed, BearSSL is a strong alternative: `cmake .. -DLWS_WITH_BEARSSL=1`. Note that BearSSL currently does not support DTLS.
338+
337339
- If cpu and memory is not super restricted and you care about TLS speed,
338340
OpenSSL or a directly compatible variant like Boring SSL is a good choice.
339341

@@ -354,12 +356,18 @@ Lws supports both almost the same, so instead of taking my word for it you are
354356
invited to try it both ways and see which the results (including, eg, binary
355357
size and memory usage as well as speed) suggest you use.
356358

357-
NOTE: one major difference with mbedTLS is it does not load the system trust
358-
store by default. That has advantages and disadvantages, but the disadvantage
359-
is you must provide the CA cert to lws built against mbedTLS for it to be able
360-
to validate it, ie, use -A with the test client. The minimal test clients
361-
have the CA cert for warmcat.com and libwebsockets.org and use it if they see
362-
they were built with mbedTLS.
359+
NOTE: one major difference with mbedTLS and BearSSL is they do not natively load the OS trust
360+
store by default in the same way OpenSSL does.
361+
362+
For mbedTLS, you must provide the CA cert to lws for it to be able
363+
to validate it, ie, use `-A` with the test client.
364+
365+
For BearSSL, LWS implements a multi-cert PEM parser and fallback sequence to emulate OpenSSL's behavior:
366+
1. It checks the `SSL_CERT_FILE` and `SSL_CERT_DIR` environment variables for runtime overrides.
367+
2. It falls back to probing standard OS locations (e.g. `/etc/ssl/certs/ca-certificates.crt`).
368+
3. It defaults to the CMake-configured `LWS_OPENSSL_CLIENT_CERTS` if all else fails.
369+
370+
This allows BearSSL to validate most system certificates out of the box on Linux. The minimal test clients also automatically include the CA cert for warmcat.com if they see they were built with mbedTLS or BearSSL.
363371

364372
@section optee Building for OP-TEE
365373

READMEs/README.plugin-webrtc-mixer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The WebRTC mixer plugin relies heavily on `protocol_lws_webrtc`. While `protocol
1111
Video decoding, composition, and encoding (H.264/AV1) are handled entirely by GStreamer. This enables hardware-accelerated media pipelines that drastically reduce CPU usage and memory footprint compared to software-based transcoding.
1212

1313
### Build Requirements
14-
To compile the mixer plugin, you must enable `LWS_WITH_GSTREAMER=ON` in CMake and install the GStreamer development headers:
14+
To compile the mixer plugin, you must enable `LWS_WITH_WEBRTC_MIXER=ON` in CMake and install the GStreamer development headers:
1515
- **Debian/Ubuntu**: `sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev`
1616
- **Fedora/RHEL**: `sudo dnf install gstreamer1-devel gstreamer1-plugins-base-devel`
1717

cmake/lws_config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@
208208
#cmakedefine LWS_WITH_LWSAC
209209
#cmakedefine LWS_LOGS_TIMESTAMP
210210
#cmakedefine LWS_WITH_MBEDTLS
211+
#cmakedefine LWS_WITH_BEARSSL
211212
#cmakedefine LWS_WITH_SCHANNEL
212213
#cmakedefine LWS_WITH_GNUTLS
213214
#cmakedefine LWS_WITH_MINIZ

include/libwebsockets.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,9 @@ lws_fx_string(const lws_fx_t *a, char *buf, size_t size);
907907
#include <mbedtls/sha256.h>
908908
#include <mbedtls/sha512.h>
909909
#endif
910+
#if defined(LWS_WITH_BEARSSL)
911+
#include <bearssl.h>
912+
#endif
910913

911914
#include <libwebsockets/lws-genhash.h>
912915
#include <libwebsockets/lws-genrsa.h>

include/libwebsockets/lws-context-vhost.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ struct lws_context_creation_info {
597597

598598
#endif
599599

600-
#if !defined(LWS_WITH_MBEDTLS)
600+
#if !defined(LWS_WITH_MBEDTLS) && !defined(LWS_WITH_BEARSSL)
601601
SSL_CTX *provided_client_ssl_ctx;
602602
/**< CONTEXT: If non-null, swap out libwebsockets ssl
603603
* implementation for the one provided by provided_ssl_ctx.

include/libwebsockets/lws-genaes.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ struct lws_genaes_ctx {
9191
#elif defined(LWS_WITH_GNUTLS)
9292
gnutls_cipher_hd_t ctx;
9393
int gnutls_gcm_initialized;
94+
#elif defined(LWS_WITH_BEARSSL)
95+
union {
96+
br_aes_ct_cbcenc_keys cbcenc;
97+
br_aes_ct_cbcdec_keys cbcdec;
98+
br_aes_ct_ctr_keys ctr;
99+
} u;
100+
br_gcm_context gcm;
101+
const br_block_cbcenc_class *cbcenc_vtable;
102+
const br_block_cbcdec_class *cbcdec_vtable;
103+
const br_block_ctr_class *ctr_vtable;
94104
#else
95105
EVP_CIPHER_CTX *ctx;
96106
const EVP_CIPHER *cipher;

0 commit comments

Comments
 (0)