Skip to content

Commit ad7a7c0

Browse files
committed
TCP input TLS - Add certificate file path to configuration.
1 parent 3b12309 commit ad7a7c0

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/plugins/input/tcp/src/Config.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,22 @@ namespace tcp_in {
3030
* <params>
3131
* <localPort>...</localPort> <!-- optional -->
3232
* <localIPAddress>...</localIPAddress> <!-- optional, multiple times -->
33+
* <certificatePath>...</certificatePath> <!-- optional -->
3334
* </params>
3435
*/
3536

3637
enum ParamsXmlNodes {
3738
PARAM_PORT,
3839
PARAM_IPADDR,
40+
PARAM_CERTIFICATE,
3941
};
4042

4143
static const struct fds_xml_args args_params[] = {
4244
FDS_OPTS_ROOT("params"),
43-
FDS_OPTS_ELEM(PARAM_PORT , "localPort" , FDS_OPTS_T_UINT , FDS_OPTS_P_OPT),
44-
FDS_OPTS_ELEM(PARAM_IPADDR, "localIPAddress", FDS_OPTS_T_STRING, FDS_OPTS_P_OPT
45-
| FDS_OPTS_P_MULTI),
45+
FDS_OPTS_ELEM(PARAM_PORT , "localPort" , FDS_OPTS_T_UINT , FDS_OPTS_P_OPT),
46+
FDS_OPTS_ELEM(PARAM_IPADDR , "localIPAddress" , FDS_OPTS_T_STRING, FDS_OPTS_P_OPT
47+
| FDS_OPTS_P_MULTI),
48+
FDS_OPTS_ELEM(PARAM_CERTIFICATE, "certificateFile", FDS_OPTS_T_STRING, FDS_OPTS_P_OPT),
4649
FDS_OPTS_END,
4750
};
4851

@@ -69,6 +72,7 @@ Config::Config(ipx_ctx *ctx, const char *params) : local_port(DEFAULT_PORT), loc
6972
void Config::parse_params(ipx_ctx *ctx, fds_xml_ctx_t *params) {
7073
const struct fds_xml_cont *content;
7174
bool empty_address = false;
75+
bool empty_cert = false;
7276

7377
while (fds_xml_next(params, &content) != FDS_EOC) {
7478
switch (content->id) {
@@ -92,6 +96,15 @@ void Config::parse_params(ipx_ctx *ctx, fds_xml_ctx_t *params) {
9296
empty_address = true;
9397
}
9498
break;
99+
case PARAM_CERTIFICATE:
100+
assert(content->type == FDS_OPTS_T_STRING);
101+
// check if the string is not empty
102+
if (*content->ptr_string) {
103+
certificate_file = content->ptr_string;
104+
} else {
105+
empty_cert = true;
106+
}
107+
break;
95108
default:
96109
throw std::invalid_argument("Unexpected element within <params>.");
97110
}
@@ -104,6 +117,14 @@ void Config::parse_params(ipx_ctx *ctx, fds_xml_ctx_t *params) {
104117
"listen on all interfaces but only on the specified addresses."
105118
);
106119
}
120+
121+
if (empty_cert) {
122+
IPX_CTX_WARNING(
123+
ctx,
124+
"Empty certificate path in configuration ignored. Tcp plugin will "
125+
"NOT accept TLS connections."
126+
)
127+
}
107128
}
108129

109130
} // namespace tcp_in

src/plugins/input/tcp/src/Config.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
#pragma once
1212

13-
#include <vector> // std::vector
1413
#include <cstdint> // uint16_t
14+
#include <string>
15+
#include <vector> // std::vector
1516

1617
#include <libfds.h> // fds_xml_ctx_t
1718

@@ -25,6 +26,11 @@ namespace tcp_in {
2526
struct Config {
2627
uint16_t local_port;
2728
std::vector<IpAddress> local_addrs;
29+
/**
30+
* @brief Path to file in pem format which contains certificate and private key for TLS. If
31+
* empty TLS is not accepted.
32+
*/
33+
std::string certificate_file;
2834

2935
/**
3036
* @brief Parse configuration of the TCP plugin

0 commit comments

Comments
 (0)