From 4221b198bb1bc3e4b7cea0239715958159a20841 Mon Sep 17 00:00:00 2001 From: loonycyborg Date: Sat, 20 Mar 2021 18:32:24 +0300 Subject: [PATCH] Added methods to check if connection is using TLS --- src/network_asio.hpp | 8 ++++++++ src/wesnothd_connection.hpp | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/network_asio.hpp b/src/network_asio.hpp index 3482daecd735..d8709807a57f 100644 --- a/src/network_asio.hpp +++ b/src/network_asio.hpp @@ -102,6 +102,14 @@ class connection return done_; } + /** True if connection is currently using TLS and thus is allowed to send cleartext passwords or auth tokens */ + bool using_tls() const + { + // Calling this function before connection is ready may return wrong result + assert(done_); + return utils::holds_alternative(socket_); + } + std::size_t bytes_to_write() const { return bytes_to_write_; diff --git a/src/wesnothd_connection.hpp b/src/wesnothd_connection.hpp index 14333ed175be..6be6e2833d85 100644 --- a/src/wesnothd_connection.hpp +++ b/src/wesnothd_connection.hpp @@ -98,6 +98,12 @@ class wesnothd_connection /** Waits until the server handshake is complete. */ void wait_for_handshake(); + /** True if connection is currently using TLS and thus is allowed to send cleartext passwords or auth tokens */ + bool using_tls() const + { + return utils::holds_alternative(socket_); + } + void cancel(); void stop();