From 6db8795ca4b6a853f49615279f068d4cf2b42087 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Tue, 17 Aug 2021 16:19:51 +0200 Subject: [PATCH] InfluxdbWriter: actually verify TLS server certificates And add a new option ssl_insecure_noverify to explicitly disable it if desired. --- doc/09-object-types.md | 1 + lib/perfdata/influxdbwriter.cpp | 12 ++++++++++++ lib/perfdata/influxdbwriter.ti | 3 +++ 3 files changed, 16 insertions(+) diff --git a/doc/09-object-types.md b/doc/09-object-types.md index 4208caee3..bd2821234 100644 --- a/doc/09-object-types.md +++ b/doc/09-object-types.md @@ -1640,6 +1640,7 @@ Configuration Attributes: username | String | **Optional.** InfluxDB user name. Defaults to `none`. password | String | **Optional.** InfluxDB user password. Defaults to `none`. ssl\_enable | Boolean | **Optional.** Whether to use a TLS stream. Defaults to `false`. + ssl\_insecure\_noverify | Boolean | **Optional.** Disable TLS peer verification. ssl\_ca\_cert | String | **Optional.** Path to CA certificate to validate the remote host. ssl\_cert | String | **Optional.** Path to host certificate to present to the remote host for mutual verification. ssl\_key | String | **Optional.** Path to host key to accompany the ssl\_cert. diff --git a/lib/perfdata/influxdbwriter.cpp b/lib/perfdata/influxdbwriter.cpp index 508fcff64..bcd5ba0e4 100644 --- a/lib/perfdata/influxdbwriter.cpp +++ b/lib/perfdata/influxdbwriter.cpp @@ -211,6 +211,18 @@ OptionalTlsStream InfluxdbWriter::Connect() << "TLS handshake with host '" << GetHost() << "' failed."; throw; } + + if (!GetSslInsecureNoverify()) { + if (!tlsStream.GetPeerCertificate()) { + BOOST_THROW_EXCEPTION(std::runtime_error("InfluxDB didn't present any TLS certificate.")); + } + + if (!tlsStream.IsVerifyOK()) { + BOOST_THROW_EXCEPTION(std::runtime_error( + "TLS certificate validation failed: " + std::string(tlsStream.GetVerifyError()) + )); + } + } } return std::move(stream); diff --git a/lib/perfdata/influxdbwriter.ti b/lib/perfdata/influxdbwriter.ti index 377c911ba..52c3c6802 100644 --- a/lib/perfdata/influxdbwriter.ti +++ b/lib/perfdata/influxdbwriter.ti @@ -29,6 +29,9 @@ class InfluxdbWriter : ConfigObject [config] bool ssl_enable { default {{{ return false; }}} }; + [config] bool ssl_insecure_noverify { + default {{{ return false; }}} + }; [config] String ssl_ca_cert { default {{{ return ""; }}} };