From 38b57497b9d394d3fbe7bb3a8bdea26bca4e85d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 27 May 2019 20:24:03 +0300 Subject: [PATCH] MXS-2486: Move to_string into SSLProvider The functionality is more a part of the provider than the context so it should be defined in it. It also doesn't use any parts of the SSLContext which makes it somewhat more clear that it doesn't belong there. --- include/maxscale/ssl.hh | 15 +++++--- server/core/server.cc | 4 +- server/core/ssl.cc | 43 ++++++++-------------- server/modules/routing/binlogrouter/blr.cc | 12 ++---- 4 files changed, 30 insertions(+), 44 deletions(-) diff --git a/include/maxscale/ssl.hh b/include/maxscale/ssl.hh index 04c060e26..f929f6d88 100644 --- a/include/maxscale/ssl.hh +++ b/include/maxscale/ssl.hh @@ -117,12 +117,6 @@ public: return m_cfg; } - // Convert to JSON representation - json_t* to_json() const; - - // Convert to human readable string representation - std::string to_string() const; - ~SSLContext(); private: @@ -144,12 +138,21 @@ public: SSLProvider(std::unique_ptr context); + // Return true if SSL is enabled + bool enabled() const + { + return m_context.get(); + } + // Current configuration const mxs::SSLConfig& config() const; // The context or nullptr if no context is set mxs::SSLContext* context() const; + // Convert to human readable string representation + std::string to_string() const; + // Set the context, argument must not be null void set_context(std::unique_ptr ssl); diff --git a/server/core/server.cc b/server/core/server.cc index b0e2d0a80..613fb8eed 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -524,9 +524,9 @@ void Server::print_to_dcb(DCB* dcb) const + server->stats.n_from_pool + 1); dcb_printf(dcb, "\tPool availability: %0.2lf%%\n", d * 100.0); } - if (server->ssl().context()) + if (server->ssl().enabled()) { - dcb_printf(dcb, "%s", server->ssl().context()->to_string().c_str()); + dcb_printf(dcb, "%s", server->ssl().to_string().c_str()); } if (server->proxy_protocol) { diff --git a/server/core/ssl.cc b/server/core/ssl.cc index b57df3f2a..89fa43d52 100644 --- a/server/core/ssl.cc +++ b/server/core/ssl.cc @@ -358,34 +358,6 @@ bool SSLContext::init() return true; } -json_t* SSLContext::to_json() const -{ - json_t* ssl = json_object(); - const char* ssl_method = ssl_method_type_to_string(m_cfg.version); - - json_object_set_new(ssl, "ssl_version", json_string(ssl_method)); - json_object_set_new(ssl, "ssl_cert", json_string(m_cfg.cert.c_str())); - json_object_set_new(ssl, "ssl_ca_cert", json_string(m_cfg.ca.c_str())); - json_object_set_new(ssl, "ssl_key", json_string(m_cfg.key.c_str())); - - return ssl; -} - -std::string SSLContext::to_string() const -{ - std::ostringstream ss; - - ss << "\tSSL initialized: yes\n" - << "\tSSL method type: " << ssl_method_type_to_string(m_cfg.version) << "\n" - << "\tSSL certificate verification depth: " << m_cfg.verify_depth << "\n" - << "\tSSL peer verification : " << (m_cfg.verify_peer ? "true" : "false") << "\n" - << "\tSSL certificate: " << m_cfg.cert << "\n" - << "\tSSL key: " << m_cfg.key << "\n" - << "\tSSL CA certificate: " << m_cfg.ca << "\n"; - - return ss.str(); -} - SSLContext::~SSLContext() { SSL_CTX_free(m_ctx); @@ -413,4 +385,19 @@ void SSLProvider::set_context(std::unique_ptr ssl) m_context = std::move(ssl); m_config = m_context->config(); } + +std::string SSLProvider::to_string() const +{ + std::ostringstream ss; + + ss << "\tSSL initialized: yes\n" + << "\tSSL method type: " << ssl_method_type_to_string(m_config.version) << "\n" + << "\tSSL certificate verification depth: " << m_config.verify_depth << "\n" + << "\tSSL peer verification : " << (m_config.verify_peer ? "true" : "false") << "\n" + << "\tSSL certificate: " << m_config.cert << "\n" + << "\tSSL key: " << m_config.key << "\n" + << "\tSSL CA certificate: " << m_config.ca << "\n"; + + return ss.str(); +} } diff --git a/server/modules/routing/binlogrouter/blr.cc b/server/modules/routing/binlogrouter/blr.cc index d8a81efd6..ee528328d 100644 --- a/server/modules/routing/binlogrouter/blr.cc +++ b/server/modules/routing/binlogrouter/blr.cc @@ -1477,9 +1477,11 @@ static void diagnostics(MXS_ROUTER* router, DCB* dcb) } /* SSL options */ - if (auto ssl = router_inst->service->dbref->server->ssl().context()) + const auto& ssl = router_inst->service->dbref->server->ssl(); + + if (ssl.enabled()) { - dcb_printf(dcb, "%s", ssl->to_string().c_str()); + dcb_printf(dcb, "%s", ssl.to_string().c_str()); } /* Binlog Encryption options */ @@ -1953,12 +1955,6 @@ static json_t* diagnostics_json(const MXS_ROUTER* router) min10 /= 10.0; min5 /= 5.0; - /* SSL options */ - if (auto ssl = router_inst->service->dbref->server->ssl().context()) - { - json_object_set_new(rval, "master_ssl", ssl->to_json()); - } - /* Binlog Encryption options */ if (router_inst->encryption.enabled) {