44#include <asio/ssl.hpp>
182 bool wait_for_stop(std::chrono::milliseconds timeout = std::chrono::milliseconds(5000));
318 const std::string& session_id,
319 std::span<const uint8_t> data)>;
345 bool start_server(uint16_t port,
int backlog = 128);
354 bool start_server(std::string_view address, uint16_t port,
int backlog = 128);
366 bool wait_for_stop(std::chrono::milliseconds timeout = std::chrono::milliseconds(5000));
374 bool send_to(std::string_view session_id, std::span<const uint8_t> data);
380 void broadcast(std::span<const uint8_t> data);
386 void disconnect(std::string_view session_id);
398 size_t client_count() const noexcept;
404 std::string_view server_id() const noexcept;
589 const std::string& session_id,
590 std::span<const uint8_t> data)>;
615 bool start_server(uint16_t port);
623 bool start_server(std::string_view address, uint16_t port);
636 bool send_to(std::string_view session_id, std::span<const uint8_t> data);
648 size_t session_count() const noexcept;
654 std::string_view server_id() const noexcept;
660 void set_session_connected_callback(std::function<
void(const std::
string&)> callback);
666 void set_session_disconnected_callback(std::function<
void(const std::
string&)> callback);
A secure client for establishing TLS/SSL encrypted TCP connections to a server.
auto send_packet(std::vector< uint8_t > &&data) -> VoidResult
Sends data to the connected server.
auto client_id() const -> const std::string &
Returns the client identifier.
connection_state get_state() const noexcept
Get the current connection state.
auto stop_client() -> VoidResult
Stops the client and disconnects from the server.
std::string get_cipher_suite() const
Get the negotiated cipher suite.
auto wait_for_stop() -> void
Blocks until stop_client() is called.
void set_disconnection_callback(disconnection_callback callback)
Set disconnection callback.
void set_connection_callback(connection_callback callback)
Set connection callback (called after TLS handshake)
secure_messaging_client(std::string_view client_id, const ssl_config &config={})
Construct a secure client with SSL configuration.
auto is_running() const noexcept -> bool
Checks if the client is currently running.
std::string get_protocol_version() const
Get the negotiated TLS protocol version.
auto set_error_callback(error_callback_t callback) -> void
Sets the callback for errors.
virtual ~secure_messaging_client() noexcept
Destructor.
auto start_client(std::string_view host, unsigned short port) -> VoidResult
Starts the client and connects to the specified host and port.
void set_data_callback(data_callback callback)
Set data received callback.
auto is_connected() const noexcept -> bool
Checks if the client is connected to the server.
std::optional< std::string > get_peer_certificate_subject() const
Get peer certificate information.
std::unique_ptr< impl > pimpl_
A secure server class that manages incoming TLS/SSL encrypted TCP connections, creating secure_sessio...
secure_messaging_server(std::string_view server_id, const ssl_config &config)
Construct a secure server with SSL configuration.
std::function< void(const std::string &session_id)> client_disconnected_callback
Callback type for client disconnection events.
std::function< void( const std::string &session_id, std::span< const uint8_t > data)> client_data_callback
Callback type for client data events.
std::function< void(const std::string &session_id)> client_connected_callback
Callback type for secure client connection events.
virtual ~secure_messaging_server() noexcept
Destructor.
A secure UDP client using DTLS (Datagram TLS) for encrypted communication.
virtual ~secure_messaging_udp_client() noexcept
Destructor.
secure_messaging_udp_client(std::string_view client_id, const ssl_config &config={})
Construct a secure UDP client with DTLS configuration.
A secure UDP server using DTLS (Datagram TLS) for encrypted communication.
secure_messaging_udp_server(std::string_view server_id, const ssl_config &config)
Construct a secure UDP server with DTLS configuration.
std::function< void( const std::string &session_id, std::span< const uint8_t > data)> dtls_data_callback
Callback type for DTLS data reception.
virtual ~secure_messaging_udp_server() noexcept
Destructor.
ssl_protocol
SSL/TLS protocol version enumeration.
@ dtls_1_2
DTLS 1.2 for UDP.
@ dtls_1_3
DTLS 1.3 for UDP.
@ tls_1_3
TLS 1.3 (recommended)
std::function< void()> disconnection_callback
std::function< void()> connection_callback
Callback type aliases for messaging.
ssl_verify_mode
SSL verification mode.
@ client_once
Request client certificate once.
@ fail_if_no_peer_cert
Fail if no peer certificate.
@ peer
Verify peer certificate.
std::function< void(const std::string &)> error_callback
connection_state
Connection state enumeration.
std::function< void(std::span< const uint8_t >)> data_callback
SSL/TLS configuration structure.
ssl_verify_mode verify_mode
Verification mode.
std::filesystem::path private_key_path
Path to private key file (PEM format)
std::string server_name
Server name for SNI (Server Name Indication)
bool enable_ocsp_stapling
Enable OCSP stapling.
bool enable_session_resumption
Enable session resumption.
std::filesystem::path certificate_path
Path to certificate file (PEM format)
std::string cipher_list
Cipher list (OpenSSL format, empty for default)
ssl_protocol protocol
SSL protocol version.
std::string private_key_password
Password for encrypted private key (empty if not encrypted)
std::filesystem::path ca_certificate_path
Path to CA certificate file for verification (PEM format)