Skip to content

Commit

Permalink
InfluxdbWriter: actually verify TLS server certificates
Browse files Browse the repository at this point in the history
And add a new option ssl_insecure_noverify to explicitly disable it if desired.
  • Loading branch information
julianbrost authored and Al2Klimov committed Aug 17, 2021
1 parent 037944a commit 8da90d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/09-object-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,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.
Expand Down
12 changes: 12 additions & 0 deletions lib/perfdata/influxdbwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,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);
Expand Down
3 changes: 3 additions & 0 deletions lib/perfdata/influxdbwriter.ti
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""; }}}
};
Expand Down

0 comments on commit 8da90d4

Please sign in to comment.