Net module

SSLAdapter

Manages the OpenSSL context and BIO buffers for an SSL socket connection.

SSLAdapter

#include <icy/net/ssladapter.h>

Manages the OpenSSL context and BIO buffers for an SSL socket connection.

Public Methods

ReturnNameDescription
SSLAdapterConstructs the SSLAdapter and associates it with the given socket. The socket pointer must remain valid for the lifetime of this adapter.
SSLAdapterDeleted constructor.
SSLAdapterDeleted constructor.
voidinitClientInitializes the SSL context as a client.
voidinitServerInitializes the SSL context as a server.
boolinitialized constReturns true when SSL context has been initialized.
boolready constReturns true when the handshake is complete.
voidhandshakeStart/continue the SSL handshake process.
intavailable constReturns the number of bytes available in the SSL buffer for immediate reading.
voidshutdownIssues an orderly SSL shutdown.
voidflushFlushes the SSL read/write buffers.
voidsetHostnameSet the expected peer hostname for certificate verification. Must be called before initClient() to enable hostname verification.
voidaddIncomingDataFeeds encrypted data received from the network into the SSL read BIO. Triggers a flush, which drives the handshake or decrypts and delivers plaintext to the socket via onRecv().
voidaddOutgoingDataQueues plaintext data for encryption and transmission.
voidaddOutgoingDataQueues plaintext data for encryption and transmission.
voidaddOutgoingDataMoves plaintext data into the pending write buffer when possible.

SSLAdapter

SSLAdapter(net::SSLSocket * socket)

Constructs the SSLAdapter and associates it with the given socket. The socket pointer must remain valid for the lifetime of this adapter.

Parameters

  • socket The owning SSLSocket that sends and receives raw data.

SSLAdapter

SSLAdapter(const SSLAdapter &) = delete

Deleted constructor.


SSLAdapter

SSLAdapter(SSLAdapter &&) = delete

Deleted constructor.


initClient

void initClient()

Initializes the SSL context as a client.


initServer

void initServer()

Initializes the SSL context as a server.


initialized

const

bool initialized() const

Returns true when SSL context has been initialized.


ready

const

bool ready() const

Returns true when the handshake is complete.


handshake

void handshake()

Start/continue the SSL handshake process.


available

const

int available() const

Returns the number of bytes available in the SSL buffer for immediate reading.


shutdown

void shutdown()

Issues an orderly SSL shutdown.


flush

void flush()

Flushes the SSL read/write buffers.


setHostname

void setHostname(std::string_view hostname)

Set the expected peer hostname for certificate verification. Must be called before initClient() to enable hostname verification.


addIncomingData

void addIncomingData(const char * data, size_t len)

Feeds encrypted data received from the network into the SSL read BIO. Triggers a flush, which drives the handshake or decrypts and delivers plaintext to the socket via onRecv().

Parameters

  • data Pointer to the encrypted bytes.

  • len Number of bytes to feed.


addOutgoingData

void addOutgoingData(std::string_view data)

Queues plaintext data for encryption and transmission.

Parameters

  • data String view of the plaintext payload.

addOutgoingData

void addOutgoingData(const char * data, size_t len)

Queues plaintext data for encryption and transmission.

Parameters

  • data Pointer to the plaintext bytes.

  • len Number of bytes to queue.


addOutgoingData

void addOutgoingData(Buffer && data)

Moves plaintext data into the pending write buffer when possible.

Protected Attributes

ReturnNameDescription
net::SSLSocket *_socket
SSL *_ssl
BIO *_readBIOThe incoming buffer we write encrypted SSL data into.
BIO *_writeBIOThe outgoing buffer we write to the socket.
std::vector< char >_bufferOutThe outgoing payload to be encrypted and sent.
std::string_hostnameExpected peer hostname for verification.

_socket

net::SSLSocket * _socket

_ssl

SSL * _ssl

_readBIO

BIO * _readBIO

The incoming buffer we write encrypted SSL data into.


_writeBIO

BIO * _writeBIO

The outgoing buffer we write to the socket.


_bufferOut

std::vector< char > _bufferOut

The outgoing payload to be encrypted and sent.


_hostname

std::string _hostname

Expected peer hostname for verification.

Protected Methods

ReturnNameDescription
voidhandleError
voidflushReadBIO
voidflushWriteBIO

handleError

void handleError(int rc)

flushReadBIO

void flushReadBIO()

flushWriteBIO

void flushWriteBIO()