SNode.C
Loading...
Searching...
No Matches
core::socket::stream::tls::SocketConnection< PhysicalSocketT > Class Template Reference

#include <SocketConnection.h>

Inheritance diagram for core::socket::stream::tls::SocketConnection< PhysicalSocketT >:
Collaboration diagram for core::socket::stream::tls::SocketConnection< PhysicalSocketT >:

Public Types

using SocketAddress = typename Super::SocketAddress
 

Public Member Functions

 SocketConnection (const std::string &instanceName, PhysicalSocket &&physicalSocket, const std::function< void(SocketConnection *)> &onDisconnect, const std::string &configuredServer, const SocketAddress &localAddress, const SocketAddress &remoteAddress, const utils::Timeval &readTimeout, const utils::Timeval &writeTimeout, std::size_t readBlockSize, std::size_t writeBlockSize, const utils::Timeval &terminateTimeout)
 
SSL * getSSL () const
 

Private Types

using Super
 
using PhysicalSocket = PhysicalSocketT
 
using SocketReader = typename Super::SocketReader
 
using SocketWriter = typename Super::SocketWriter
 

Private Member Functions

SSL * startSSL (int fd, SSL_CTX *ctx, const utils::Timeval &sslInitTimeout, const utils::Timeval &sslShutdownTimeout, bool closeNotifyIsEOF)
 
void stopSSL ()
 
bool doSSLHandshake (const std::function< void()> &onSuccess, const std::function< void()> &onTimeout, const std::function< void(int)> &onStatus) final
 
void doSSLShutdown ()
 
void onReadShutdown () final
 
void doWriteShutdown (const std::function< void()> &onShutdown) final
 

Private Attributes

SSL * ssl = nullptr
 
utils::Timeval sslInitTimeout
 
utils::Timeval sslShutdownTimeout
 

Friends

template<typename PhysicalSocket , typename Config >
class SocketAcceptor
 
template<typename PhysicalSocket , typename Config >
class SocketConnector
 

Detailed Description

template<typename PhysicalSocketT>
class core::socket::stream::tls::SocketConnection< PhysicalSocketT >

Definition at line 49 of file SocketAcceptor.h.

Member Typedef Documentation

◆ PhysicalSocket

template<typename PhysicalSocketT >
using core::socket::stream::tls::SocketConnection< PhysicalSocketT >::PhysicalSocket = PhysicalSocketT
private

Definition at line 70 of file SocketConnection.h.

◆ SocketAddress

template<typename PhysicalSocketT >
using core::socket::stream::tls::SocketConnection< PhysicalSocketT >::SocketAddress = typename Super::SocketAddress

Definition at line 75 of file SocketConnection.h.

◆ SocketReader

template<typename PhysicalSocketT >
using core::socket::stream::tls::SocketConnection< PhysicalSocketT >::SocketReader = typename Super::SocketReader
private

Definition at line 71 of file SocketConnection.h.

◆ SocketWriter

template<typename PhysicalSocketT >
using core::socket::stream::tls::SocketConnection< PhysicalSocketT >::SocketWriter = typename Super::SocketWriter
private

Definition at line 72 of file SocketConnection.h.

◆ Super

template<typename PhysicalSocketT >
using core::socket::stream::tls::SocketConnection< PhysicalSocketT >::Super
private
Initial value:
core::socket::stream::
SocketConnectionT<PhysicalSocketT, core::socket::stream::tls::SocketReader, core::socket::stream::tls::SocketWriter>

Definition at line 67 of file SocketConnection.h.

Constructor & Destructor Documentation

◆ SocketConnection()

template<typename PhysicalSocket >
core::socket::stream::tls::SocketConnection< PhysicalSocket >::SocketConnection ( const std::string & instanceName,
PhysicalSocket && physicalSocket,
const std::function< void(SocketConnection< PhysicalSocketT > *)> & onDisconnect,
const std::string & configuredServer,
const SocketAddress & localAddress,
const SocketAddress & remoteAddress,
const utils::Timeval & readTimeout,
const utils::Timeval & writeTimeout,
std::size_t readBlockSize,
std::size_t writeBlockSize,
const utils::Timeval & terminateTimeout )

Definition at line 61 of file SocketConnection.hpp.

72 : Super(
73 instanceName,
74 std::move(physicalSocket),
75 [onDisconnect, this]() {
76 onDisconnect(this);
77 },
78 configuredServer,
79 localAddress,
80 remoteAddress,
81 readTimeout,
82 writeTimeout,
83 readBlockSize,
84 writeBlockSize,
85 terminateTimeout) {
86 }
core::socket::stream:: SocketConnectionT< PhysicalSocketT, core::socket::stream::tls::SocketReader, core::socket::stream::tls::SocketWriter > Super

References core::socket::stream::tls::SocketConnection< PhysicalSocketT >::SocketConnection().

Referenced by core::socket::stream::tls::SocketConnection< PhysicalSocketT >::SocketConnection().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ doSSLHandshake()

template<typename PhysicalSocket >
bool core::socket::stream::tls::SocketConnection< PhysicalSocket >::doSSLHandshake ( const std::function< void()> & onSuccess,
const std::function< void()> & onTimeout,
const std::function< void(int)> & onStatus )
finalprivate

Definition at line 131 of file SocketConnection.hpp.

133 {
134 if (ssl != nullptr) {
137 }
140 }
141
143 Super::getConnectionName(),
144 ssl,
145 [onSuccess, this]() { // onSuccess
147 onSuccess();
148 },
149 [onTimeout]() { // onTimeout
150 onTimeout();
151 },
152 [onStatus](int sslErr) { // onStatus
153 onStatus(sslErr);
154 },
156 }
157
158 return ssl != nullptr;
159 }
static void doHandshake(const std::string &instanceName, SSL *ssl, const std::function< void(void)> &onSuccess, const std::function< void(void)> &onTimeout, const std::function< void(int)> &onStatus, const utils::Timeval &timeout)

References core::socket::stream::tls::SocketConnection< PhysicalSocketT >::ssl.

◆ doSSLShutdown()

template<typename PhysicalSocket >
void core::socket::stream::tls::SocketConnection< PhysicalSocket >::doSSLShutdown ( )
private

Definition at line 162 of file SocketConnection.hpp.

162 {
163 bool resumeSocketReader = false;
164 bool resumeSocketWriter = false;
165
168 resumeSocketReader = true;
169 }
170
173 resumeSocketWriter = true;
174 }
175
177 Super::getConnectionName(),
178 ssl,
179 [this, resumeSocketReader, resumeSocketWriter]() { // onSuccess
180 if (resumeSocketReader) {
182 }
183 if (resumeSocketWriter) {
185 }
186 if (SSL_get_shutdown(ssl) == (SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN)) {
187 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Close_notify received and sent";
188 } else {
189 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Close_notify sent";
190
191 if (SSL_get_shutdown(ssl) == SSL_SENT_SHUTDOWN && SocketWriter::closeNotifyIsEOF) {
192 LOG(TRACE) << Super::getConnectionName() << " SSL/TLS: Close_notify is EOF: setting sslShutdownTimeout to "
193 << sslShutdownTimeout << " sec";
194 Super::setTimeout(sslShutdownTimeout);
195 }
196 }
197 },
198 [this, resumeSocketReader, resumeSocketWriter]() { // onTimeout
199 if (resumeSocketReader) {
201 }
202 if (resumeSocketWriter) {
204 }
205 LOG(ERROR) << Super::getConnectionName() << " SSL/TLS: Shutdown handshake timed out";
206 Super::doWriteShutdown([this]() {
208 });
209 },
210 [this, resumeSocketReader, resumeSocketWriter](int sslErr) { // onStatus
211 if (resumeSocketReader) {
213 }
214 if (resumeSocketWriter) {
216 }
217 ssl_log(Super::getConnectionName() + " SSL/TLS: Shutdown handshake failed", sslErr);
218 Super::doWriteShutdown([this]() {
220 });
221 },
223 }
static void doShutdown(const std::string &instanceName, SSL *ssl, const std::function< void(void)> &onSuccess, const std::function< void(void)> &onTimeout, const std::function< void(int)> &onStatus, const utils::Timeval &timeout)
void ssl_log(const std::string &message, int sslErr)

Referenced by core::socket::stream::tls::SocketConnection< PhysicalSocketT >::doWriteShutdown(), and core::socket::stream::tls::SocketConnection< PhysicalSocketT >::onReadShutdown().

Here is the caller graph for this function:

◆ doWriteShutdown()

template<typename PhysicalSocket >
void core::socket::stream::tls::SocketConnection< PhysicalSocket >::doWriteShutdown ( const std::function< void()> & onShutdown)
finalprivate

Definition at line 246 of file SocketConnection.hpp.

246 {
247 if ((SSL_get_shutdown(ssl) & SSL_SENT_SHUTDOWN) == 0) {
248 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Send close_notify";
249
251 } else {
252 Super::doWriteShutdown(onShutdown);
253 }
254 }

References core::socket::stream::tls::SocketConnection< PhysicalSocketT >::doSSLShutdown(), and core::socket::stream::tls::SocketConnection< PhysicalSocketT >::ssl.

Here is the call graph for this function:

◆ getSSL()

template<typename PhysicalSocket >
SSL * core::socket::stream::tls::SocketConnection< PhysicalSocket >::getSSL ( ) const

Definition at line 89 of file SocketConnection.hpp.

89 {
90 return ssl;
91 }

References core::socket::stream::tls::SocketConnection< PhysicalSocketT >::ssl.

◆ onReadShutdown()

template<typename PhysicalSocket >
void core::socket::stream::tls::SocketConnection< PhysicalSocket >::onReadShutdown ( )
finalprivate

Definition at line 226 of file SocketConnection.hpp.

226 {
227 if ((SSL_get_shutdown(ssl) & SSL_RECEIVED_SHUTDOWN) != 0) {
228 if ((SSL_get_shutdown(ssl) & SSL_SENT_SHUTDOWN) != 0) {
229 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Close_notify sent and received";
230
232 } else {
233 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Close_notify received";
234
236 }
237 } else {
238 LOG(ERROR) << Super::getConnectionName() << " SSL/TLS: Unexpected EOF error";
239
241 SSL_set_shutdown(ssl, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
242 }
243 }

References core::socket::stream::tls::SocketConnection< PhysicalSocketT >::doSSLShutdown(), and core::socket::stream::tls::SocketConnection< PhysicalSocketT >::ssl.

Here is the call graph for this function:

◆ startSSL()

template<typename PhysicalSocket >
SSL * core::socket::stream::tls::SocketConnection< PhysicalSocket >::startSSL ( int fd,
SSL_CTX * ctx,
const utils::Timeval & sslInitTimeout,
const utils::Timeval & sslShutdownTimeout,
bool closeNotifyIsEOF )
private

Definition at line 94 of file SocketConnection.hpp.

95 {
96 this->sslInitTimeout = sslInitTimeout;
97 this->sslShutdownTimeout = sslShutdownTimeout;
98 if (ctx != nullptr) {
99 ssl = SSL_new(ctx);
100
101 if (ssl != nullptr) {
102 SSL_set_ex_data(ssl, 0, const_cast<std::string*>(&Super::getConnectionName()));
103
104 if (SSL_set_fd(ssl, fd) == 1) {
107 SocketReader::closeNotifyIsEOF = closeNotifyIsEOF;
108 SocketWriter::closeNotifyIsEOF = closeNotifyIsEOF;
109 } else {
110 SSL_free(ssl);
111 ssl = nullptr;
112 }
113 }
114 }
115
116 return ssl;
117 }

References core::socket::stream::tls::SocketConnection< PhysicalSocketT >::ssl.

◆ stopSSL()

template<typename PhysicalSocket >
void core::socket::stream::tls::SocketConnection< PhysicalSocket >::stopSSL ( )
private

Definition at line 120 of file SocketConnection.hpp.

120 {
121 if (ssl != nullptr) {
122 SSL_free(ssl);
123
124 ssl = nullptr;
125 SocketReader::ssl = nullptr;
126 SocketWriter::ssl = nullptr;
127 }
128 }

References core::socket::stream::tls::SocketConnection< PhysicalSocketT >::ssl.

Friends And Related Symbol Documentation

◆ SocketAcceptor

template<typename PhysicalSocketT >
template<typename PhysicalSocket , typename Config >
friend class SocketAcceptor
friend

Definition at line 113 of file SocketConnection.h.

◆ SocketConnector

template<typename PhysicalSocketT >
template<typename PhysicalSocket , typename Config >
friend class SocketConnector
friend

Definition at line 116 of file SocketConnection.h.

Member Data Documentation

◆ ssl

◆ sslInitTimeout

template<typename PhysicalSocketT >
utils::Timeval core::socket::stream::tls::SocketConnection< PhysicalSocketT >::sslInitTimeout
private

Definition at line 109 of file SocketConnection.h.

◆ sslShutdownTimeout

template<typename PhysicalSocketT >
utils::Timeval core::socket::stream::tls::SocketConnection< PhysicalSocketT >::sslShutdownTimeout
private

Definition at line 110 of file SocketConnection.h.


The documentation for this class was generated from the following files: