1515#include < string> // string
1616#include < cassert> // assert
1717#include < cstdint> // UINT16_MAX
18+ #include < cstring>
1819
1920#include < libfds.h> // fds_*, FDS_*
2021
@@ -30,19 +31,24 @@ namespace tcp_in {
3031 * <params>
3132 * <localPort>...</localPort> <!-- optional -->
3233 * <localIPAddress>...</localIPAddress> <!-- optional, multiple times -->
34+ * <certificatePath>...</certificatePath> <!-- optional -->
3335 * </params>
3436 */
3537
3638enum ParamsXmlNodes {
3739 PARAM_PORT,
3840 PARAM_IPADDR,
41+ PARAM_CERTIFICATE,
42+ PARAM_TLS_VERIFY_PEER,
3943};
4044
4145static const struct fds_xml_args args_params[] = {
4246 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),
47+ FDS_OPTS_ELEM (PARAM_PORT , " localPort" , FDS_OPTS_T_UINT , FDS_OPTS_P_OPT),
48+ FDS_OPTS_ELEM (PARAM_IPADDR , " localIPAddress" , FDS_OPTS_T_STRING, FDS_OPTS_P_OPT
49+ | FDS_OPTS_P_MULTI),
50+ FDS_OPTS_ELEM (PARAM_CERTIFICATE , " certificateFile" , FDS_OPTS_T_STRING, FDS_OPTS_P_OPT),
51+ FDS_OPTS_ELEM (PARAM_TLS_VERIFY_PEER, " tlsVerifyPeer" , FDS_OPTS_T_BOOL , FDS_OPTS_P_OPT),
4652 FDS_OPTS_END,
4753};
4854
@@ -69,6 +75,8 @@ Config::Config(ipx_ctx *ctx, const char *params) : local_port(DEFAULT_PORT), loc
6975void Config::parse_params (ipx_ctx *ctx, fds_xml_ctx_t *params) {
7076 const struct fds_xml_cont *content;
7177 bool empty_address = false ;
78+ bool empty_cert = false ;
79+ bool verify_set = false ;
7280
7381 while (fds_xml_next (params, &content) != FDS_EOC) {
7482 switch (content->id ) {
@@ -85,13 +93,27 @@ void Config::parse_params(ipx_ctx *ctx, fds_xml_ctx_t *params) {
8593 break ;
8694 case PARAM_IPADDR:
8795 assert (content->type == FDS_OPTS_T_STRING);
88- // check if the string is not empty
89- if (*content->ptr_string ) {
96+ // check if the string is empty
97+ if (std::strcmp (content->ptr_string , " " ) == 0 ) {
98+ empty_address = true ;
99+ } else {
90100 local_addrs.push_back (IpAddress (content->ptr_string ));
101+ }
102+ break ;
103+ case PARAM_CERTIFICATE:
104+ assert (content->type == FDS_OPTS_T_STRING);
105+ // check if the string is empty
106+ if (std::strcmp (content->ptr_string , " " ) == 0 ) {
107+ empty_cert = true ;
91108 } else {
92- empty_address = true ;
109+ certificate_file = content-> ptr_string ;
93110 }
94111 break ;
112+ case PARAM_TLS_VERIFY_PEER:
113+ assert (content->type == FDS_OPTS_T_BOOL);
114+ verify_peer = content->val_bool ;
115+ verify_set = true ;
116+ break ;
95117 default :
96118 throw std::invalid_argument (" Unexpected element within <params>." );
97119 }
@@ -100,10 +122,26 @@ void Config::parse_params(ipx_ctx *ctx, fds_xml_ctx_t *params) {
100122 if (empty_address && local_addrs.size () != 0 ) {
101123 IPX_CTX_WARNING (
102124 ctx,
103- " Empty address in configuration ignored. Tcp plugin will NOT "
125+ " Empty address in configuration ignored. TCP plugin will NOT "
104126 " listen on all interfaces but only on the specified addresses."
105127 );
106128 }
129+
130+ if (empty_cert) {
131+ IPX_CTX_WARNING (
132+ ctx,
133+ " Empty certificate path in configuration ignored. TCP plugin will "
134+ " NOT accept TLS connections."
135+ )
136+ }
137+
138+ if (verify_set && certificate_file.empty ()) {
139+ IPX_CTX_WARNING (
140+ ctx,
141+ " TLS peer verification enabled, but TLS certificate is missing. "
142+ " TCP plugin will NOT accept TLS connections."
143+ );
144+ }
107145}
108146
109147} // namespace tcp_in
0 commit comments