SSLSocket
SSLSocket
#include <icy/net/sslsocket.h>Inherits:
TCPSocket
SSL socket implementation.
Public Methods
| Return | Name | Description |
|---|---|---|
SSLSocket | Constructs an SSLSocket that acquires its context from SSLManager on first use. | |
SSLSocket | Constructs an SSLSocket with an explicit SSL context. | |
SSLSocket | Constructs an SSLSocket with an explicit context and a prior session for resumption. | |
void | connect virtual | Initialize the SSLSocket with the given SSLContext. |
void | connect virtual | Resolves host and initiates a secure connection. |
void | bind virtual | Binds the socket to address for server-side use. Throws std::logic_error if the context is not a server context. |
void | listen virtual | Starts listening for incoming connections. Throws std::logic_error if the context is not a server context. |
bool | shutdown virtual | Shuts down the connection by attempting an orderly SSL shutdown, then actually shutting down the TCP connection. |
void | close virtual | Closes the socket forcefully. |
ssize_t | send virtual | Encrypts and sends len bytes to the connected peer. |
ssize_t | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
ssize_t | send virtual | Encrypts and sends len bytes, ignoring peerAddress (TCP is connected). |
ssize_t | sendOwned virtual | |
void | setHostname | Set the expected peer hostname for certificate verification and SNI. Must be called before connect() to enable hostname verification. |
void | useContext | Use the given SSL context for this socket. |
SSLContext::Ptr | context const | Returns the SSL context used for this socket. |
void | useSession | Sets the SSL session to use for the next connection. Setting a previously saved Session object is necessary to enable session caching. |
SSLSession::Ptr | currentSession | Returns the SSL session of the current connection, for reuse in a future connection (if session caching is enabled). |
bool | sessionWasReused | Returns true if a reused session was negotiated during the handshake. |
int | available const | Returns the number of bytes available from the SSL buffer for immediate reading. |
X509 * | peerCertificate const | Returns the peer's X.509 certificate, or nullptr if no certificate was presented. |
net::TransportType | transport virtual const | Returns the SSLTCP transport protocol identifier. |
void | acceptConnection virtual | Accepts a pending client connection, initializes the server-side SSL context on the new socket, and fires the AcceptConnection signal. |
void | onConnect virtual | Called when the TCP connection is established; starts reading and initiates the client-side SSL handshake. |
void | onRead virtual | Feeds raw encrypted bytes from the network into the SSL adapter. Called by the stream layer when ciphertext arrives from the peer. |
SSLSocket
SSLSocket(uv::Loop * loop)Constructs an SSLSocket that acquires its context from SSLManager on first use.
Parameters
loopEvent loop to use; defaults to the default loop.
SSLSocket
SSLSocket(SSLContext::Ptr sslContext, uv::Loop * loop)Constructs an SSLSocket with an explicit SSL context.
Parameters
sslContextThe SSL context to use for this connection.loopEvent loop to use; defaults to the default loop.
SSLSocket
SSLSocket(SSLContext::Ptr sslContext, SSLSession::Ptr session, uv::Loop * loop)Constructs an SSLSocket with an explicit context and a prior session for resumption.
Parameters
sslContextThe SSL context to use for this connection.sessionA previously saved session to attempt resumption with.loopEvent loop to use; defaults to the default loop.
connect
virtual
virtual void connect(const Address & peerAddress)Initialize the SSLSocket with the given SSLContext.
Initiates a secure connection to the peer at the given address.
The SSL handshake begins automatically once the TCP connection is established.
Parameters
peerAddressThe remote address to connect to.
connect
virtual
virtual void connect(std::string_view host, uint16_t port)Resolves host and initiates a secure connection.
Sets the hostname on the SSL adapter for SNI and certificate verification before resolving and connecting.
Parameters
hostHostname or IP address string.portDestination port.
bind
virtual
virtual void bind(const net::Address & address, unsigned flags)Binds the socket to address for server-side use. Throws std::logic_error if the context is not a server context.
Parameters
addressLocal address to bind to.flagsOptional bind flags (passed to uv_tcp_bind).
listen
virtual
virtual void listen(int backlog)Starts listening for incoming connections. Throws std::logic_error if the context is not a server context.
Parameters
backlogMaximum number of pending connections.
shutdown
virtual
virtual bool shutdown()Shuts down the connection by attempting an orderly SSL shutdown, then actually shutting down the TCP connection.
close
virtual
virtual void close()Closes the socket forcefully.
send
virtual
virtual ssize_t send(const char * data, size_t len, int flags)Encrypts and sends len bytes to the connected peer.
Parameters
dataPointer to the plaintext payload.lenNumber of bytes to send.flagsReserved; currently unused.
Returns
Number of plaintext bytes accepted, or -1 on error.
sendOwned
virtual
virtual ssize_t sendOwned(Buffer && buffer, int flags)Sends an owned payload buffer to the connected peer.
send
virtual
virtual ssize_t send(const char * data, size_t len, const net::Address & peerAddress, int flags)Encrypts and sends len bytes, ignoring peerAddress (TCP is connected).
Parameters
dataPointer to the plaintext payload.lenNumber of bytes to send.peerAddressIgnored for SSL/TCP; present for interface conformance.flagsReserved; currently unused.
Returns
Number of plaintext bytes accepted, or -1 on error.
sendOwned
virtual
virtual ssize_t sendOwned(Buffer && buffer, const net::Address & peerAddress, int flags)setHostname
void setHostname(std::string_view hostname)Set the expected peer hostname for certificate verification and SNI. Must be called before connect() to enable hostname verification.
useContext
void useContext(SSLContext::Ptr context)Use the given SSL context for this socket.
context
const
SSLContext::Ptr context() constReturns the SSL context used for this socket.
useSession
void useSession(SSLSession::Ptr session)Sets the SSL session to use for the next connection. Setting a previously saved Session object is necessary to enable session caching.
To remove the currently set session, a nullptr pointer can be given.
Must be called before connect() to be effective.
currentSession
SSLSession::Ptr currentSession()Returns the SSL session of the current connection, for reuse in a future connection (if session caching is enabled).
If no connection is established, returns nullptr.
sessionWasReused
bool sessionWasReused()Returns true if a reused session was negotiated during the handshake.
available
const
int available() constReturns the number of bytes available from the SSL buffer for immediate reading.
peerCertificate
const
X509 * peerCertificate() constReturns the peer's X.509 certificate, or nullptr if no certificate was presented.
transport
virtual const
virtual net::TransportType transport() constReturns the SSLTCP transport protocol identifier.
acceptConnection
virtual
virtual void acceptConnection()Accepts a pending client connection, initializes the server-side SSL context on the new socket, and fires the AcceptConnection signal.
onConnect
virtual
virtual void onConnect()Called when the TCP connection is established; starts reading and initiates the client-side SSL handshake.
onRead
virtual
virtual void onRead(const char * data, size_t len)Feeds raw encrypted bytes from the network into the SSL adapter. Called by the stream layer when ciphertext arrives from the peer.
Parameters
dataPointer to the encrypted bytes.lenNumber of bytes received.
Protected Attributes
| Return | Name | Description |
|---|---|---|
net::SSLContext::Ptr | _sslContext | |
net::SSLSession::Ptr | _sslSession | |
net::SSLAdapter | _sslAdapter |
_sslContext
net::SSLContext::Ptr _sslContext_sslSession
net::SSLSession::Ptr _sslSession_sslAdapter
net::SSLAdapter _sslAdapterPublic Types
Ptr
std::shared_ptr< SSLSocket > Ptr()Vec
std::vector< Ptr > Vec()