Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/socket/stream/SocketClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ namespace core::socket::stream {
config);
}
} else {
log.critical("{} required", config->getInstanceName());
log.critical("required");
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/core/socket/stream/SocketServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ namespace core::socket::stream {
config);
}
} else {
log.critical("{} required", config->getInstanceName());
log.critical("required");
}
});

Expand Down
24 changes: 9 additions & 15 deletions src/core/socket/stream/tls/SocketAcceptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,21 @@ namespace core::socket::stream::tls {
}
},
[socketContextFactory, onConnected](SocketConnection* socketConnection) { // on Connected
static_cast<core::socket::stream::SocketConnection*>(socketConnection)
->log()
.trace("{} SSL/TLS: Start handshake", socketConnection->getConnectionName());
static_cast<core::socket::stream::SocketConnection*>(socketConnection)->log().trace("SSL/TLS: Start handshake");
if (!socketConnection->doSSLHandshake(
[socketContextFactory,
onConnected,
socketConnection,
log = static_cast<core::socket::stream::SocketConnection*>(socketConnection)->log(),
connectionName = socketConnection->getConnectionName()]() { // onSuccess
log.debug("{} SSL/TLS: Handshake success", connectionName);
log = static_cast<core::socket::stream::SocketConnection*>(socketConnection)->log()]() { // onSuccess
log.debug("SSL/TLS: Handshake success");

onConnected(socketConnection);

socketConnection->setSocketContext(socketContextFactory);
},
[socketConnection,
log = static_cast<core::socket::stream::SocketConnection*>(socketConnection)->log(),
connectionName = socketConnection->getConnectionName()]() { // onTimeout
log.error("{}SSL/TLS: Handshake timed out", connectionName);
log = static_cast<core::socket::stream::SocketConnection*>(socketConnection)->log()]() { // onTimeout
log.error("SSL/TLS: Handshake timed out");

socketConnection->close();
},
Expand All @@ -102,9 +98,7 @@ namespace core::socket::stream::tls {

socketConnection->close();
})) {
static_cast<core::socket::stream::SocketConnection*>(socketConnection)
->log()
.error("{} SSL/TLS: Handshake failed", socketConnection->getConnectionName());
static_cast<core::socket::stream::SocketConnection*>(socketConnection)->log().error("SSL/TLS: Handshake failed");

socketConnection->close();
}
Expand Down Expand Up @@ -141,17 +135,17 @@ namespace core::socket::stream::tls {
template <typename PhysicalSocketServer, typename Config>
void SocketAcceptor<PhysicalSocketServer, Config>::init() {
if (core::eventLoopState() == core::State::RUNNING && !config->getDisabled()) {
this->log().trace("{} SSL/TLS: SSL_CTX creating ...", config->getInstanceName());
this->log().trace("SSL/TLS: SSL_CTX creating ...");
SSL_CTX* sslCtx = config->getSslCtx();

if (sslCtx != nullptr) {
this->log().debug("{} SSL/TLS: SSL_CTX created", config->getInstanceName());
this->log().debug("SSL/TLS: SSL_CTX created");

SSL_CTX_set_client_hello_cb(sslCtx, clientHelloCallback, nullptr);

Super::init();
} else {
this->log().error("{} SSL/TLS: SSL/TLS creation failed", config->getInstanceName());
this->log().error("SSL/TLS: SSL/TLS creation failed");

Super::onStatus(Super::config->Local::getSocketAddress(), core::socket::STATE_ERROR);
Super::destruct();
Expand Down
17 changes: 7 additions & 10 deletions src/core/socket/stream/tls/SocketConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,9 @@ namespace core::socket::stream::tls {
SocketWriter::resume();
}
if (SSL_get_shutdown(ssl) == (SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN)) {
core::socket::stream::SocketConnection::log().debug("{} SSL/TLS: Passive close_notify received and sent",
Super::getConnectionName());
core::socket::stream::SocketConnection::log().debug("SSL/TLS: Passive close_notify received and sent");
} else {
core::socket::stream::SocketConnection::log().debug("{} SSL/TLS: Active close_notify sent", Super::getConnectionName());
core::socket::stream::SocketConnection::log().debug("SSL/TLS: Active close_notify sent");
}
},
[this, resumeSocketReader, resumeSocketWriter]() { // onTimeout
Expand All @@ -179,7 +178,7 @@ namespace core::socket::stream::tls {
if (resumeSocketWriter) {
SocketWriter::resume();
}
core::socket::stream::SocketConnection::log().error("{} SSL/TLS: Shutdown handshake timed out", Super::getConnectionName());
core::socket::stream::SocketConnection::log().error("SSL/TLS: Shutdown handshake timed out");
Super::doWriteShutdown([this]() {
SocketConnection::close();
});
Expand All @@ -203,21 +202,19 @@ namespace core::socket::stream::tls {
void SocketConnection<PhysicalSocket, Config>::onReadShutdown() {
if ((SSL_get_shutdown(ssl) & SSL_RECEIVED_SHUTDOWN) != 0) {
if ((SSL_get_shutdown(ssl) & SSL_SENT_SHUTDOWN) != 0) {
core::socket::stream::SocketConnection::log().debug("{} SSL/TLS: Active close_notify sent and received",
Super::getConnectionName());
core::socket::stream::SocketConnection::log().debug("SSL/TLS: Active close_notify sent and received");
SocketWriter::shutdownInProgress = false;

if (closeNotifyIsEOF) {
this->onReadError(0);
}
} else {
core::socket::stream::SocketConnection::log().debug(
"{} SSL/TLS: Passive close_notify received, answering with close_notify", Super::getConnectionName());
core::socket::stream::SocketConnection::log().debug("SSL/TLS: Passive close_notify received, answering with close_notify");

doSSLShutdown();
}
} else {
core::socket::stream::SocketConnection::log().error("{} SSL/TLS: Unexpected EOF error", Super::getConnectionName());
core::socket::stream::SocketConnection::log().error("SSL/TLS: Unexpected EOF error");

SocketWriter::shutdownInProgress = false;
SSL_set_shutdown(ssl, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
Expand All @@ -227,7 +224,7 @@ namespace core::socket::stream::tls {
template <typename PhysicalSocket, typename Config>
void SocketConnection<PhysicalSocket, Config>::doWriteShutdown(const std::function<void()>& onShutdown) {
if ((SSL_get_shutdown(ssl) & SSL_SENT_SHUTDOWN) == 0) {
core::socket::stream::SocketConnection::log().debug("{} SSL/TLS: Active send close_notify", Super::getConnectionName());
core::socket::stream::SocketConnection::log().debug("SSL/TLS: Active send close_notify");

doSSLShutdown();
} else {
Expand Down
24 changes: 9 additions & 15 deletions src/core/socket/stream/tls/SocketConnector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,21 @@ namespace core::socket::stream::tls {
}
},
[socketContextFactory, onConnected](SocketConnection* socketConnection) { // onConnected
static_cast<core::socket::stream::SocketConnection*>(socketConnection)
->log()
.trace("{} SSL/TLS: Start handshake", socketConnection->getConnectionName());
static_cast<core::socket::stream::SocketConnection*>(socketConnection)->log().trace("SSL/TLS: Start handshake");
if (!socketConnection->doSSLHandshake(
[socketContextFactory,
onConnected,
socketConnection,
log = static_cast<core::socket::stream::SocketConnection*>(socketConnection)->log(),
connectionName = socketConnection->getConnectionName()]() { // onSuccess
log.debug("{} SSL/TLS: Handshake success", connectionName);
log = static_cast<core::socket::stream::SocketConnection*>(socketConnection)->log()]() { // onSuccess
log.debug("SSL/TLS: Handshake success");

onConnected(socketConnection);

socketConnection->setSocketContext(socketContextFactory);
},
[socketConnection,
log = static_cast<core::socket::stream::SocketConnection*>(socketConnection)->log(),
connectionName = socketConnection->getConnectionName()]() { // onTimeout
log.error("{} SSL/TLS: Handshake timed out", connectionName);
log = static_cast<core::socket::stream::SocketConnection*>(socketConnection)->log()]() { // onTimeout
log.error("SSL/TLS: Handshake timed out");

socketConnection->close();
},
Expand All @@ -105,9 +101,7 @@ namespace core::socket::stream::tls {

socketConnection->close();
})) {
static_cast<core::socket::stream::SocketConnection*>(socketConnection)
->log()
.error("{} SSL/TLS: Handshake failed", socketConnection->getConnectionName());
static_cast<core::socket::stream::SocketConnection*>(socketConnection)->log().error("SSL/TLS: Handshake failed");

socketConnection->close();
}
Expand Down Expand Up @@ -144,14 +138,14 @@ namespace core::socket::stream::tls {
template <typename PhysicalSocketClient, typename Config>
void SocketConnector<PhysicalSocketClient, Config>::init() {
if (core::eventLoopState() == core::State::RUNNING && !config->getDisabled()) {
this->log().trace("{} SSL/TLS: SSL_CTX creating ...", config->getInstanceName());
this->log().trace("SSL/TLS: SSL_CTX creating ...");

if (config->getSslCtx() != nullptr) {
this->log().debug("{} SSL/TLS: SSL_CTX created", config->getInstanceName());
this->log().debug("SSL/TLS: SSL_CTX created");

Super::init();
} else {
this->log().error("{} SSL/TLS: SSL_CTX creation failed", config->getInstanceName());
this->log().error("SSL/TLS: SSL_CTX creation failed");

Super::onStatus(config->Remote::getSocketAddress(), core::socket::STATE_FATAL);
Super::destruct();
Expand Down
Loading