8000 Fix TLS server not throwing exception when a certificate or key file is not valid by emgre · Pull Request #443 · dnp3/opendnp3 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
now have an empty default implementation. See [#441](https://github.com/dnp3/opendnp3/pull/441).
* :beetle: Added extra log when closing a new connection based on `ServerAcceptMode::CloseNew`.
See [#442](https://github.com/dnp3/opendnp3/pull/442).
* :beetle: Fix TLS server not throwing exception when a certificate or key file
is not valid. See [#443](https://github.com/dnp3/opendnp3/pull/443).

### 3.1.1 ###
* :beetle: Fix static octet string serilazation bug.
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/tls/master/main.cpp
8000
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main(int argc, char* argv[])

// Connect via a TCPClient socket to a outstation
auto channel = manager.AddTLSClient(
"tls-client", logLevels, ChannelRetry::Default(), {IPEndpoint("127.0.0.1", 20001)}, "0.0.0.0",
"tlsclient", logLevels, ChannelRetry::Default(), {IPEndpoint("127.0.0.1", 20001)}, "0.0.0.0",
TLSConfig(peerCertificate, localCertificate, privateKey), PrintingChannelListener::Create());

// The master config object for a master. The default are
Expand Down
15 changes: 12 additions & 3 deletions cpp/examples/tls/outstation/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,18 @@ int main(int argc, char* argv[])
DNP3Manager manager(1, ConsoleLogger::Create());

// Create a TCP server (listener)
auto channel = manager.AddTLSServer("server", logLevels, ServerAcceptMode::CloseExisting, IPEndpoint("0.0.0.0", 20001),
TLSConfig(peerCertificate, localCertificate, privateKey),
PrintingChannelListener::Create());
auto channel = std::shared_ptr<IChannel>(nullptr);
try
{
channel = manager.AddTLSServer("tlsserver", logLevels, ServerAcceptMode::CloseExisting, IPEndpoint("0.0.0.0", 20001),
TLSConfig(peerCertificate, localCertificate, privateKey),
PrintingChannelListener::Create());
}
catch(const std::exception& e)
{
std::cerr << e.what() << '\n';
return -1;
}

// The main object for a outstation. The defaults are useable,
// but understanding the options are important.
Expand Down
26 changes: 18 additions & 8 deletions cpp/lib/src/channel/tls/TLSServerIOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ TLSServerIOHandler::TLSServerIOHandler(const Logger& logger,
std::shared_ptr<exe4cpp::StrandExecutor> executor,
IPEndpoint endpoint,
TLSConfig config,
std::error_code& /*ec*/)
std::error_code& ec)
: IOHandler(logger, mode == ServerAcceptMode::CloseExisting, listener),
executor(std::move(executor)),
endpoint(std::move(endpoint)),
config(std::move(config))
config(std::move(config)),
server(std::make_shared<Server>(this->logger, this->executor, this->endpoint, this->config, ec))
{
}

Expand All @@ -66,16 +67,25 @@ void TLSServerIOHandler::BeginChannelAccept()
this->OnNewChannel(channel);
};

std::error_code ec;
this->server = std::make_shared<Server>(this->logger, this->executor, this->endpoint, this->config, ec);

if (ec)
if (this->server)
{
SIMPLE_LOG_BLOCK(this->logger, flags::ERR, ec.message().c_str());
this->server->StartAcceptingConnection(callback);
}
else
{
this->server->StartAcceptingConnection(callback);
std::error_code ec;
this->server = std::make_shared<Server>(this->logger, this->executor, this->endpoint, this->config, ec);

if (ec)
{
SIMPLE_LOG_BLOCK(this->logger, flags::ERR, ec.message().c_str());

// TODO - should we retry?
}
else
{
this->server->StartAcceptingConnection(callback);
}
}
}

Expand Down
0