diff --git a/BUILDING.md b/BUILDING.md index 0f0a7aaf3..5978c840c 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -19,10 +19,9 @@ $ git submodule update --init --recursive --depth 1 The CMake library targets `libdatachannel` and `libdatachannel-static` respectively correspond to the shared and static libraries. The default target will build tests and examples. -The option `USE_GNUTLS` allows to switch between OpenSSL (default) and GnuTLS, and the option `USE_NICE` allows to switch between libjuice as submodule (default) and libnice. +Options `USE_GNUTLS` and `USE_MBEDTLS` allow to switch the cryptographic backend to GnuTLS and Mbed TLS respectively, otherwise OpenSSL is selected by default. The option `USE_NICE` allows to switch between libjuice as submodule (default) and libnice as system library. -The option `PREFER_SYSTEM_LIB` allow to link against the system library rather than building all the submodule. -Options `USE_SYSTEM_SRTP`, `USE_SYSTEM_JUICE`, `USE_SYSTEM_USRSCTP`, `USE_SYSTEM_PLOG` and `USE_SYSTEM_JSON` allow to do the same but per submodule, for libsrtp, libjuice, libusrsctp, Plog and Nlohmann JSON respectively. +The option `PREFER_SYSTEM_LIB` allows to link against the system library rather than building all the submodule. Options `USE_SYSTEM_SRTP`, `USE_SYSTEM_JUICE`, `USE_SYSTEM_USRSCTP`, `USE_SYSTEM_PLOG` and `USE_SYSTEM_JSON` allow to do the same but per submodule, for libsrtp, libjuice, libusrsctp, Plog and Nlohmann JSON respectively. If you only need Data Channels, the option `NO_MEDIA` allows to make the library lighter by removing media support. Similarly, `NO_WEBSOCKET` removes WebSocket support. @@ -78,7 +77,7 @@ $ nmake ## Build directly with Make (Linux only) -The option `USE_GNUTLS` allows to switch between OpenSSL (default) and GnuTLS, and the option `USE_NICE` allows to switch between libjuice as submodule (default) and libnice. +Options `USE_GNUTLS` and `USE_MBEDTLS` allow to switch the cryptographic backend to GnuTLS and Mbed TLS respectively, otherwise OpenSSL is selected by default. The option `USE_NICE` allows to switch between libjuice as submodule (default) and libnice as system library. If you only need Data Channels, the option `NO_MEDIA` removes media support. Similarly, `NO_WEBSOCKET` removes WebSocket support. diff --git a/CMakeLists.txt b/CMakeLists.txt index a843e868f..5760a4b7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,8 @@ set(PROJECT_DESCRIPTION "C/C++ WebRTC network library featuring Data Channels, M include(GNUInstallDirs) # Options -option(USE_MBEDTLS "Use Mbed TLS instead of OpenSSL" OFF) option(USE_GNUTLS "Use GnuTLS instead of OpenSSL" OFF) +option(USE_MBEDTLS "Use Mbed TLS instead of OpenSSL" OFF) option(USE_NICE "Use libnice instead of libjuice" OFF) option(PREFER_SYSTEM_LIB "Prefer system libraries over deps folder" OFF) option(USE_SYSTEM_SRTP "Use system libSRTP" ${PREFER_SYSTEM_LIB}) @@ -24,11 +24,10 @@ option(WARNINGS_AS_ERRORS "Treat warnings as errors" OFF) option(CAPI_STDCALL "Set calling convention of C API callbacks stdcall" OFF) option(SCTP_DEBUG "Enable SCTP debugging output to verbose log" OFF) -if (USE_MBEDTLS AND USE_GNUTLS) - message(FATAL_ERROR "Both USE_MBEDTLS and USE_GNUTLS can not be enabled at the same time") +if (USE_GNUTLS AND USE_MBEDTLS) + message(FATAL_ERROR "Both USE_MBEDTLS and USE_GNUTLS cannot be enabled at the same time") endif() - if(USE_GNUTLS) option(USE_NETTLE "Use Nettle in libjuice" ON) else() @@ -355,9 +354,8 @@ if (USE_GNUTLS) endif() elseif(USE_MBEDTLS) find_package(MbedTLS 3 REQUIRED) - - target_compile_definitions(datachannel PRIVATE USE_MBEDTLS) - target_compile_definitions(datachannel-static PRIVATE USE_MBEDTLS) + target_compile_definitions(datachannel PRIVATE USE_MBEDTLS=1) + target_compile_definitions(datachannel-static PRIVATE USE_MBEDTLS=1) target_link_libraries(datachannel PRIVATE MbedTLS::MbedTLS) target_link_libraries(datachannel-static PRIVATE MbedTLS::MbedTLS) else() diff --git a/Makefile b/Makefile index 77cc49d76..91365fb5b 100644 --- a/Makefile +++ b/Makefile @@ -19,11 +19,17 @@ INCLUDES=-Isrc -Iinclude/rtc -Iinclude -I$(PLOG_DIR)/include -I$(USRSCTP_DIR)/us LDLIBS= USE_GNUTLS ?= 0 +USE_MBEDTLS ?= 0 ifneq ($(USE_GNUTLS), 0) - CPPFLAGS+=-DUSE_GNUTLS=1 +ifneq ($(USE_MBEDTLS), 0) +$(error Both USE_MBEDTLS and USE_GNUTLS cannot be enabled at the same time) +endif + CPPFLAGS+=-DUSE_GNUTLS=1 LIBS+=gnutls +else ifneq ($(USE_MBEDTLS), 0) + CPPFLAGS+=-DUSE_MBEDTLS=1 + LIBS+=mbedtls else - CPPFLAGS+=-DUSE_GNUTLS=0 LIBS+=openssl SRTP_CONFIGURE_FLAGS+=--enable-openssl endif diff --git a/README.md b/README.md index a243691bb..793b33c85 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ libdatachannel is available on [AUR](https://aur.archlinux.org/packages/libdatac - [GnuTLS](https://www.gnutls.org/), [Mbed TLS](https://www.trustedfirmware.org/projects/mbed-tls/), or [OpenSSL](https://www.openssl.org/) - [usrsctp](https://github.com/sctplab/usrsctp) (as submodule by default) -- [Plog](https://github.com/SergiusTheBest/plog) (as submodule by default) +- [plog](https://github.com/SergiusTheBest/plog) (as submodule by default) - [libjuice](https://github.com/paullouisageneau/libjuice) (as submodule by default) or [libnice](https://nice.freedesktop.org/) as an ICE backend. - [libsrtp](https://github.com/cisco/libsrtp) (as submodule by default) required if compiled with media support. - [nlohmann JSON](https://github.com/nlohmann/json) (as submodule by default) required to build examples. diff --git a/examples/streamer/helpers.cpp b/examples/streamer/helpers.cpp index 36c76113c..7be76571e 100644 --- a/examples/streamer/helpers.cpp +++ b/examples/streamer/helpers.cpp @@ -38,7 +38,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) { x.LowPart = filetime.dwLowDateTime; x.HighPart = filetime.dwHighDateTime; usec = x.QuadPart / 10 - epoch_offset_us; - tv->tv_sec = time_t(usec / 1000000ULL); + tv->tv_sec = long(usec / 1000000ULL); tv->tv_usec = long(usec % 1000000ULL); } if (tz) { diff --git a/include/rtc/nalunit.hpp b/include/rtc/nalunit.hpp index b59c1bf79..8970fb87f 100644 --- a/include/rtc/nalunit.hpp +++ b/include/rtc/nalunit.hpp @@ -49,29 +49,29 @@ struct RTC_CPP_EXPORT NalUnitFragmentHeader { #pragma pack(pop) -typedef enum { +enum NalUnitStartSequenceMatch { NUSM_noMatch, NUSM_firstZero, NUSM_secondZero, NUSM_thirdZero, NUSM_shortMatch, NUSM_longMatch -} NalUnitStartSequenceMatch; +}; static const size_t H264_NAL_HEADER_SIZE = 1; static const size_t H265_NAL_HEADER_SIZE = 2; /// Nal unit struct RTC_CPP_EXPORT NalUnit : binary { - typedef enum { H264, H265 } Type; + enum class Type { H264, H265 }; NalUnit(const NalUnit &unit) = default; - NalUnit(size_t size, bool includingHeader = true, Type type = H264) + NalUnit(size_t size, bool includingHeader = true, Type type = Type::H264) : binary(size + (includingHeader ? 0 - : (type == H264 ? H264_NAL_HEADER_SIZE : H265_NAL_HEADER_SIZE))) {} + : (type == Type::H264 ? H264_NAL_HEADER_SIZE : H265_NAL_HEADER_SIZE))) {} NalUnit(binary &&data) : binary(std::move(data)) {} - NalUnit(Type type = H264) - : binary(type == H264 ? H264_NAL_HEADER_SIZE : H265_NAL_HEADER_SIZE) {} + NalUnit(Type type = Type::H264) + : binary(type == Type::H264 ? H264_NAL_HEADER_SIZE : H265_NAL_HEADER_SIZE) {} template NalUnit(Iterator begin_, Iterator end_) : binary(begin_, end_) {} bool forbiddenBit() const { return header()->forbiddenBit(); } diff --git a/pages/content/pages/index.md b/pages/content/pages/index.md index 9a215e000..58a6f6215 100644 --- a/pages/content/pages/index.md +++ b/pages/content/pages/index.md @@ -34,7 +34,7 @@ save_as: index.html

Portable

diff --git a/src/impl/dtlstransport.cpp b/src/impl/dtlstransport.cpp index aa5182411..2f6c38ccd 100644 --- a/src/impl/dtlstransport.cpp +++ b/src/impl/dtlstransport.cpp @@ -766,7 +766,6 @@ DtlsTransport::DtlsTransport(shared_ptr lower, certificate_ptr cer auto ecdh = unique_ptr( EC_KEY_new_by_curve_name(NID_X9_62_prime256v1), EC_KEY_free); SSL_CTX_set_tmp_ecdh(mCtx, ecdh.get()); - SSL_CTX_set_options(mCtx, SSL_OP_SINGLE_ECDH_USE); #endif auto [x509, pkey] = mCertificate->credentials(); diff --git a/src/impl/tlstransport.cpp b/src/impl/tlstransport.cpp index e04d0736c..bf95250e3 100644 --- a/src/impl/tlstransport.cpp +++ b/src/impl/tlstransport.cpp @@ -589,7 +589,6 @@ TlsTransport::TlsTransport(variant, shared_ptr( EC_KEY_new_by_curve_name(NID_X9_62_prime256v1), EC_KEY_free); SSL_CTX_set_tmp_ecdh(mCtx, ecdh.get()); - SSL_CTX_set_options(mCtx, SSL_OP_SINGLE_ECDH_USE); #endif if(mIsClient) {