From fa83d446c9fe3931bf03f34647261f413725d2e9 Mon Sep 17 00:00:00 2001 From: Viacheslau Kalenikau Date: Tue, 24 Nov 2026 16:04:32 +0100 Subject: [PATCH 1/3] Document the TLS channel in the README --- README.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/README.md b/README.md index 6c827bd..f0efa0b 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,71 @@ The native streaming sends via the wire the same data packages as they are send cmake --preset gcc/debug cmake --build build/gcc/debug ``` + +## TLS + +Connections can be encrypted with TLS 1.2 or later. The TLS channel is optional: it is the only part of the +library that needs OpenSSL (1.1.1 or later), and it is compiled in only with the CMake option +`NATIVE_STREAMING_ENABLE_TLS`, which is `OFF` by default: + +``` +cmake --preset gcc/debug -DNATIVE_STREAMING_ENABLE_TLS=ON +cmake --build build/gcc/debug +``` + +With the option on, OpenSSL is linked publicly and the installed package config finds it for consumers. The +compile definition `NATIVE_STREAMING_ENABLE_TLS` is public too, so code using the TLS API guards it with +`#if NATIVE_STREAMING_ENABLE_TLS`. With the option off, the TLS API is compiled out and `tls.hpp` is not +installed. + +Certificates and keys are passed as paths to PEM files, and the library builds the SSL contexts from them. + +### Server + +`Server::startTls()` listens for TLS connections, alongside `start()` on another port or instead of it: + +```cpp +server->start(plainPort); +server->startTls(tlsPort, "server.crt", "server.key", "client-ca.crt"); +``` + +The CA file is optional. If it is given, mutual TLS is enabled: clients must present a certificate signed by +that authority. A missing or malformed file is reported through the returned error code rather than thrown, +and so is a port the server already listens on (`address_in_use`). + +### Client + +A client connects over TLS when it is constructed with a `ClientTlsConfig`: + +```cpp +ClientTlsConfig tlsConfig; +tlsConfig.caFile = "ca.crt"; +tlsConfig.certFile = "client.crt"; // mutual TLS only +tlsConfig.keyFile = "client.key"; // mutual TLS only + +auto client = std::make_shared(host, port, path, authentication, + onNewSession, onResolveFail, onConnectFail, onHandshakeFail, + ioContext, logCallback, + tlsConfig, onTlsHandshakeFail); +``` + +The constructor reads the files. It throws `std::invalid_argument` if the configuration is inconsistent, for +example a certificate without a key, and `boost::system::system_error` if a file is missing or malformed. + +`onTlsHandshakeFail` is optional. It is called when the TLS layer rejects the connection: the server was +reached, but the two sides do not trust each other, so retrying with the same files is pointless. Without it, +such failures are reported through `onHandshakeFail`. + +### Modes + +| Mode | Server | Client | +|---|---|---| +| Server authentication | `startTls(port, cert, key)` | `caFile` | +| Mutual TLS | `startTls(port, cert, key, clientCa)` | `caFile`, `certFile`, `keyFile` | +| Encryption without server authentication | `startTls(port, cert, key)` | `verifyServer = false` | + +The server certificate is verified against the CA only; its host name is not checked. Without server +authentication any certificate the server presents is accepted, which leaves no protection against an active +man-in-the-middle: use it only where the server is trusted by other means. + +The certificates under `test/secrets` are for the tests only. From 8b45bec62763d9d6bd531728a3a9e39d2796aa95 Mon Sep 17 00:00:00 2001 From: Viacheslau Kalenikau Date: Tue, 24 Nov 2026 16:04:38 +0100 Subject: [PATCH 2/3] Add the changelog entries for v1.0.21 to v1.0.23 and the TLS channel --- changelog | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/changelog b/changelog index 16aa170..33c7022 100644 --- a/changelog +++ b/changelog @@ -54,4 +54,21 @@ ## v1.0.20 - Bump boost version to 1.90.0 + +## v1.0.21 - Add precompiled headers and unity builds through opendaq-cmake-utils v1.1.0; CI moved to the openDAQ-CI reusable workflow + +## v1.0.22 + - Read the upgrade request of each connection into its own buffer, so a malformed request no longer breaks the next connection + - Accept further connections without waiting for the upgrade request of the current one + - Disconnect a client that sends no upgrade request within 5 s + +## v1.0.23 + - Close a connection attempt still in flight when the client is destroyed + +## Unreleased + - Add an optional TLS channel behind the CMake option NATIVE_STREAMING_ENABLE_TLS (OFF by default, requires OpenSSL 1.1.1 or later) + - Add Server::startTls() to listen for TLS connections alongside or instead of plaintext ones, with optional mutual TLS + - Add a Client constructor taking a ClientTlsConfig, with an optional callback for TLS handshake failures + - Make the Session constructor take the transport-neutral IWsStream instead of WebsocketStream + - Return address_in_use when the server is asked to listen on a port it already listens on From 20f42e2af33a7e595d8867e23031d7620941fe12 Mon Sep 17 00:00:00 2001 From: Viacheslau Kalenikau Date: Tue, 24 Nov 2026 16:13:04 +0100 Subject: [PATCH 3/3] Bump version to v1.0.24 --- CMakeLists.txt | 2 +- changelog | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index abcac15..55d0ea2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ set(CMAKE_POLICY_VERSION_MINIMUM 3.5) cmake_minimum_required(VERSION 3.24) -project(native_streaming VERSION 1.0.23 LANGUAGES CXX) +project(native_streaming VERSION 1.0.24 LANGUAGES CXX) if (NOT CMAKE_MESSAGE_CONTEXT) set(CMAKE_MESSAGE_CONTEXT ${PROJECT_NAME}) diff --git a/changelog b/changelog index 33c7022..715e3f8 100644 --- a/changelog +++ b/changelog @@ -66,7 +66,7 @@ ## v1.0.23 - Close a connection attempt still in flight when the client is destroyed -## Unreleased +## v1.0.24 - Add an optional TLS channel behind the CMake option NATIVE_STREAMING_ENABLE_TLS (OFF by default, requires OpenSSL 1.1.1 or later) - Add Server::startTls() to listen for TLS connections alongside or instead of plaintext ones, with optional mutual TLS - Add a Client constructor taking a ClientTlsConfig, with an optional callback for TLS handshake failures