Skip to content

Commit 037944a

Browse files
julianbrostAl2Klimov
authored andcommitted
GelfWriter: actually verify TLS server certificates
And add a new option insecure_noverify to explicitly disable it if desired.
1 parent 78aa348 commit 037944a

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

doc/09-object-types.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,7 @@ Configuration Attributes:
13171317
enable\_send\_perfdata | Boolean | **Optional.** Enable performance data for 'CHECK RESULT' events.
13181318
enable\_ha | Boolean | **Optional.** Enable the high availability functionality. Only valid in a [cluster setup](06-distributed-monitoring.md#distributed-monitoring-high-availability-features). Defaults to `false`.
13191319
enable\_tls | Boolean | **Optional.** Whether to use a TLS stream. Defaults to `false`.
1320+
insecure\_noverify | Boolean | **Optional.** Disable TLS peer verification.
13201321
ca\_path | String | **Optional.** Path to CA certificate to validate the remote host. Requires `enable_tls` set to `true`.
13211322
cert\_path | String | **Optional.** Path to host certificate to present to the remote host for mutual verification. Requires `enable_tls` set to `true`.
13221323
key\_path | String | **Optional.** Path to host key to accompany the cert\_path. Requires `enable_tls` set to `true`.

lib/perfdata/gelfwriter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,18 @@ void GelfWriter::ReconnectInternal()
196196
<< "TLS handshake with host '" << GetHost() << " failed.'";
197197
throw;
198198
}
199+
200+
if (!GetInsecureNoverify()) {
201+
if (!tlsStream.GetPeerCertificate()) {
202+
BOOST_THROW_EXCEPTION(std::runtime_error("Graylog Gelf didn't present any TLS certificate."));
203+
}
204+
205+
if (!tlsStream.IsVerifyOK()) {
206+
BOOST_THROW_EXCEPTION(std::runtime_error(
207+
"TLS certificate validation failed: " + std::string(tlsStream.GetVerifyError())
208+
));
209+
}
210+
}
199211
}
200212

201213
SetConnected(true);

lib/perfdata/gelfwriter.ti

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class GelfWriter : ConfigObject
3434
[config] bool enable_tls {
3535
default {{{ return false; }}}
3636
};
37+
[config] bool insecure_noverify {
38+
default {{{ return false; }}}
39+
};
3740
[config] String ca_path;
3841
[config] String cert_path;
3942
[config] String key_path;

0 commit comments

Comments
 (0)