qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
listener.h
Go to the documentation of this file.
1
24
25#include "../listener.h"
26#include "socket.h"
27
28#ifndef QB_IO_TCP_SSL_LISTENER_H_
29#define QB_IO_TCP_SSL_LISTENER_H_
30
31namespace qb::io::tcp::ssl {
32
43class QB_API listener : public tcp::listener {
44 std::unique_ptr<SSL_CTX, void (*)(SSL_CTX *)>
45 _ctx;
46 mutable std::vector<unsigned char> _alpn_wire;
47public:
49 constexpr static bool is_secure() noexcept { return true; }
55 ~listener() noexcept;
56
62 listener() noexcept;
63
67 listener(listener const &) = delete;
68
72 listener(listener &&) = default;
73
78 listener &operator=(listener &&) = default;
79
87 void init(SSL_CTX *ctx) noexcept;
88
100 ssl::socket accept() const noexcept;
101
111 int accept(ssl::socket &socket) const noexcept;
112
118 [[nodiscard]] SSL_CTX *ssl_handle() const noexcept;
119
125 bool load_ca_certificates_for_client_auth(const std::string &ca_file_path);
126
132 bool load_ca_directory_for_client_auth(const std::string &ca_dir_path);
133
139 bool set_cipher_list(const std::string &ciphers);
140
146 bool set_ciphersuites_tls13(const std::string &ciphersuites);
147
154 bool set_tls_protocol_versions(int min_version, int max_version);
155
162 bool configure_mtls(const std::string &client_ca_file_path, int verification_mode = SSL_VERIFY_PEER);
163
170 bool set_alpn_selection_callback(SSL_CTX_alpn_select_cb_func callback, void *arg);
171
177 bool enable_session_caching(long cache_size = SSL_SESSION_CACHE_MAX_SIZE_DEFAULT);
178
185 bool set_custom_client_verify_callback(int (*callback)(int, X509_STORE_CTX *), int verification_mode);
186
193 bool set_ocsp_stapling_responder_callback(int (*callback)(SSL *s, void *arg), void *arg);
194
201 bool set_sni_selection_callback(int (*callback)(SSL *s, int *al, void *arg), void *arg);
202
208 bool set_keylog_callback(SSL_CTX_keylog_cb_func callback);
209
215 bool configure_dh_parameters(const std::string& dh_param_file_path);
216
222 bool configure_ecdh_curves(const std::string& curve_names_list);
223
229
237 bool set_supported_alpn_protocols(const std::vector<std::string>& protocols);
238
239 // --- Getters for SSL_CTX properties ---
240
246 int get_verify_mode() const;
248 int get_verify_depth() const;
253
254 // --- Other useful SSL_CTX configurations ---
255
261 long set_options(long options_to_set);
262
268 long clear_options(long options_to_clear);
269
275 long set_session_timeout(long seconds);
276
283 bool set_info_callback(void (*callback)(const SSL *ssl, int type, int val));
284
291 bool set_msg_callback(void (*callback)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg), void *arg);
292};
293
294} // namespace qb::io::tcp::ssl
295
296#endif // QB_IO_TCP_SSL_LISTENER_H_
Class implementing a TCP listener for accepting incoming connections.
Definition listener.h:42
listener() noexcept
Default constructor.
int get_verify_depth() const
Gets the current peer certificate verification depth.
bool configure_mtls(const std::string &client_ca_file_path, int verification_mode=SSL_VERIFY_PEER)
Configure client certificate authentication (mTLS) for this listener.
bool enable_session_caching(long cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT)
Enable and configure server-side SSL session caching for this listener.
bool set_tls_protocol_versions(int min_version, int max_version)
Set the minimum and maximum TLS protocol versions for this listener's context.
bool enable_post_handshake_auth()
Enable server-side support for TLS 1.3 Post-Handshake Authentication.
int get_min_protocol_version() const
Gets the minimum configured TLS protocol version.
bool set_ocsp_stapling_responder_callback(int(*callback)(SSL *s, void *arg), void *arg)
Set a callback for this listener's server to provide an OCSP response to be stapled.
long set_session_timeout(long seconds)
Set the session timeout for the listener's SSL_CTX.
static constexpr bool is_secure() noexcept
Indicates that this socket implementation is secure.
Definition listener.h:49
bool load_ca_directory_for_client_auth(const std::string &ca_dir_path)
Load CA certificates from a directory for client peer verification (mTLS).
SSL_CTX * ssl_handle() const noexcept
Get the raw OpenSSL SSL_CTX handle.
ssl::socket accept() const noexcept
Accept a new secure connection and return it as a new ssl::socket.
long set_options(long options_to_set)
Set specific SSL options on the listener's context.
long get_session_cache_mode() const
Gets the SSL session cache mode.
int get_verify_mode() const
Gets the current peer verification mode.
bool configure_ecdh_curves(const std::string &curve_names_list)
Configure preferred ECDH curves for this listener's context.
bool set_ciphersuites_tls13(const std::string &ciphersuites)
Set the preferred cipher suites for TLS 1.3 for this listener's context.
bool set_cipher_list(const std::string &ciphers)
Set the preferred cipher suites for TLS 1.2 and earlier for this listener's context.
int get_max_protocol_version() const
Gets the maximum configured TLS protocol version.
bool set_msg_callback(void(*callback)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg), void *arg)
Set a message callback for the listener's SSL_CTX for detailed protocol tracing.
bool set_keylog_callback(SSL_CTX_keylog_cb_func callback)
Set the SSL/TLS key log callback function for debugging.
long clear_options(long options_to_clear)
Clear specific SSL options on the listener's context.
bool set_sni_selection_callback(int(*callback)(SSL *s, int *al, void *arg), void *arg)
Set a callback for server-side SNI (Server Name Indication) handling.
bool load_ca_certificates_for_client_auth(const std::string &ca_file_path)
Load CA certificates from a file for client peer verification (mTLS).
bool configure_dh_parameters(const std::string &dh_param_file_path)
Configure Diffie-Hellman parameters for this listener's context.
bool set_custom_client_verify_callback(int(*callback)(int, X509_STORE_CTX *), int verification_mode)
Set a custom callback for X.509 client certificate verification.
void init(SSL_CTX *ctx) noexcept
Initialize the listener with a pre-configured SSL context.
bool set_supported_alpn_protocols(const std::vector< std::string > &protocols)
Set the list of ALPN protocols supported by the server listener.
bool set_info_callback(void(*callback)(const SSL *ssl, int type, int val))
Set an informational callback for the listener's SSL_CTX.
bool set_alpn_selection_callback(SSL_CTX_alpn_select_cb_func callback, void *arg)
Set the ALPN selection callback for this listener's context.
~listener() noexcept
Destructor.
long get_session_cache_size() const
Gets the SSL session cache size.
Class implementing secure SSL/TLS TCP socket functionality.
Definition socket.h:320
Template struct used for type identification in the event system.
Definition Event.h:53
Implementation of a TCP listener for the QB IO library.
Implementation of SSL/TLS sockets for secure TCP communication in the QB IO library.