Implements an SSL/TLS layer on top of an underlying connection. More...
#include <ssl.hpp>
Public Types | |
using | TPoller = typename TSocket::TPoller |
Public Member Functions | |
TSslSocket (TSocket &&socket, TSslContext &ctx) | |
Constructs a TSslSocket from an underlying socket and an SSL context. | |
TSslSocket (TSslSocket &&other) | |
TSslSocket & | operator= (TSslSocket &&other) |
TSslSocket (const TSslSocket &)=delete | |
TSslSocket & | operator= (const TSslSocket &)=delete |
~TSslSocket () | |
Destructor. | |
void | SslSetTlsExtHostName (const std::string &host) |
Sets the TLS SNI (Server Name Indication) extension host name. | |
TFuture< TSslSocket< TSocket > > | Accept () |
Asynchronously accepts an incoming SSL connection. | |
TFuture< void > | AcceptHandshake () |
Performs the server-side SSL handshake. | |
TFuture< void > | Connect (const TAddress &address, TTime deadline=TTime::max()) |
Initiates the client-side SSL handshake. | |
TFuture< ssize_t > | ReadSome (void *data, size_t size) |
Asynchronously reads data from the SSL connection. | |
TFuture< ssize_t > | WriteSome (const void *data, size_t size) |
Asynchronously writes data to the SSL connection. | |
auto | Poller () |
Returns the underlying poller. | |
Implements an SSL/TLS layer on top of an underlying connection.
TSslSocket wraps an existing connection (of type TSocket
) with SSL/TLS functionality. It creates a new SSL instance (via SSL_new()
) using the provided TSslContext, and sets up memory BIOs for reading (Rbio) and writing (Wbio).
The class provides asynchronous operations for both server and client handshakes:
Once the handshake is complete, TSslSocket exposes asynchronous read and write methods (ReadSome() and WriteSome()) that perform SSL_read() and SSL_write(), using an internal I/O loop (via DoIO() and DoHandshake()).
Additionally, TSslSocket allows setting the TLS SNI (via SslSetTlsExtHostName).
TSocket | The underlying socket type over which SSL/TLS is layered. |
|
inline |
Constructs a TSslSocket from an underlying socket and an SSL context.
Creates a new SSL instance using the provided context, sets up memory BIOs for I/O, and configures SSL for partial writes.
socket | An rvalue reference to the underlying connection handle. |
ctx | Reference to the TSslContext to use. |
|
inline |
Destructor.
Frees the SSL instance (and associated BIOs) and destroys any active handshake task.
|
inline |
Asynchronously accepts an incoming SSL connection.
Waits for an incoming connection on the underlying socket, wraps it in a TSslSocket, and performs the handshake.
|
inline |
Performs the server-side SSL handshake.
Configures the SSL state to accept a connection, then performs the handshake asynchronously.
|
inline |
Initiates the client-side SSL handshake.
Connects to the remote address, sets the SSL state to connect, and performs the handshake.
address | The remote address to connect to. |
deadline | Optional timeout for the connection attempt. |
|
inline |
Returns the underlying poller.
|
inline |
Asynchronously reads data from the SSL connection.
Performs SSL_read() and, if needed, loops using asynchronous I/O via DoIO() until data is available.
data | Pointer to the buffer. |
size | Maximum number of bytes to read. |
|
inline |
Sets the TLS SNI (Server Name Indication) extension host name.
This is useful for virtual hosting when connecting to servers that rely on SNI.
host | The server host name. |
|
inline |
Asynchronously writes data to the SSL connection.
Writes the full buffer in a loop using SSL_write() and asynchronous I/O until completion.
data | Pointer to the data. |
size | The number of bytes to write. |