SNode.C
Loading...
Searching...
No Matches
ConfigTls.cpp
Go to the documentation of this file.
1/*
2 * SNode.C - A Slim Toolkit for Network Communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * MIT License
22 *
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to deal
25 * in the Software without restriction, including without limitation the rights
26 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 * copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
29 *
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
32 *
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 * THE SOFTWARE.
40 */
41
42#include "net/config/ConfigTls.h"
43
44#include "net/config/ConfigSection.hpp"
45
46#ifndef DOXYGEN_SHOULD_SKIP_THIS
47
48#endif /* DOXYGEN_SHOULD_SKIP_THIS */
49
50namespace net::config {
51
53 : ConfigSection(instance, "tls", "Configuration of SSL/TLS behavior") {
55 "--cert",
56 "Certificate chain file",
57 "filename:PEM-FILE",
58 "");
59
61 "--cert-key",
62 "Certificate key file",
63 "filename:PEM-FILE",
64 "");
65
67 "--cert-key-password",
68 "Password for the certificate key file",
69 "password",
70 "",
71 CLI::TypeValidator<std::string>());
72
74 "--ca-cert",
75 "CA-certificate file",
76 "filename:PEM-FILE",
77 "");
78
80 "--ca-cert-dir",
81 "CA-certificate directory",
82 "directory:PEM-CONTAINER-DIR",
83 "");
84
86 "--ca-cert-use-default-dir{true}",
87 "Use default CA-certificate directory",
88 "bool",
89 "false",
90 CLI::IsMember({"true", "false"}));
91
93 "--ca-cert-accept-unknown{true}",
94 "Accept unknown certificates (unsecure)",
95 "bool",
96 "false",
97 CLI::IsMember({"true", "false"}));
98
100 "--cipher-list",
101 "Cipher list (OpenSSL syntax)",
102 "cipher_list",
103 "",
104 CLI::TypeValidator<std::string>("CIPHER"));
105
107 "--ssl-options",
108 "OR combined SSL/TLS options (OpenSSL values)",
109 "options",
110 0,
111 CLI::TypeValidator<ssl_option_t>());
112
113 initTimeoutOpt = addOption( //
114 "--init-timeout",
115 "SSL/TLS initialization timeout in seconds",
116 "timeout",
117 TLS_INIT_TIMEOUT,
118 CLI::PositiveNumber);
119
120 shutdownTimeoutOpt = addOption( //
121 "--shutdown-timeout",
122 "SSL/TLS shutdown timeout in seconds",
123 "timeout",
124 TLS_SHUTDOWN_TIMEOUT,
125 CLI::PositiveNumber);
126
128 "--no-close-notify-is-eof{true}",
129 "Do not interpret a SSL/TLS close_notify alert as EOF",
130 "bool",
131 "false",
132 CLI::IsMember({"true", "false"}));
133 }
134
135 ConfigTls& ConfigTls::setCert(const std::string& cert) {
136 certOpt //
137 ->default_val(cert)
138 ->clear();
139
140 return *this;
141 }
142
143 std::string ConfigTls::getCert() const {
144 return certOpt->as<std::string>();
145 }
146
147 ConfigTls& ConfigTls::setCertKey(const std::string& certKey) {
148 certKeyOpt //
149 ->default_val(certKey)
150 ->clear();
151
152 return *this;
153 }
154
155 std::string ConfigTls::getCertKey() const {
156 return certKeyOpt->as<std::string>();
157 }
158
159 ConfigTls& ConfigTls::setCertKeyPassword(const std::string& certKeyPassword) {
161 ->default_val(certKeyPassword)
162 ->clear();
163
164 return *this;
165 }
166
167 std::string ConfigTls::getCertKeyPassword() const {
168 return certKeyPasswordOpt->as<std::string>();
169 }
170
171 ConfigTls& ConfigTls::setCaCert(const std::string& caCert) {
172 caCertOpt //
173 ->default_val(caCert)
174 ->clear();
175
176 return *this;
177 }
178
179 std::string ConfigTls::getCaCert() const {
180 return caCertOpt->as<std::string>();
181 }
182
183 ConfigTls& ConfigTls::setCaCertDir(const std::string& caCertDir) {
184 caCertDirOpt //
185 ->default_val(caCertDir)
186 ->clear();
187
188 return *this;
189 }
190
191 std::string ConfigTls::getCaCertDir() const {
192 return caCertDirOpt->as<std::string>();
193 }
194
197 ->default_val(set ? "true" : "false")
198 ->clear();
199
200 return *this;
201 }
202
204 return caCertUseDefaultDirOpt->as<bool>();
205 }
206
209 ->default_val(set ? "true" : "false")
210 ->clear();
211
212 return *this;
213 }
214
216 return caCertAcceptUnknownOpt->as<bool>();
217 }
218
219 ConfigTls& ConfigTls::setCipherList(const std::string& cipherList) {
221 ->default_val(cipherList)
222 ->clear();
223
224 return *this;
225 }
226
227 std::string ConfigTls::getCipherList() const {
228 return cipherListOpt->as<std::string>();
229 }
230
231 ConfigTls& ConfigTls::setSslOptions(ssl_option_t sslOptions) {
233 ->default_val(sslOptions)
234 ->clear();
235
236 return *this;
237 }
238
239 ssl_option_t ConfigTls::getSslOptions() const {
240 return sslOptionsOpt->as<ssl_option_t>();
241 }
242
243 ConfigTls& ConfigTls::setNoCloseNotifyIsEOF(bool closeNotifyIsEOF) {
245 ->default_val(closeNotifyIsEOF ? "true" : "false")
246 ->clear();
247 return *this;
248 }
249
251 return noCloseNotifyIsEOFOpt->as<bool>();
252 }
253
254 ConfigTls& ConfigTls::setInitTimeout(const utils::Timeval& newInitTimeout) {
256 ->default_val(newInitTimeout)
257 ->clear();
258
259 return *this;
260 }
261
263 return initTimeoutOpt->as<utils::Timeval>();
264 }
265
266 ConfigTls& ConfigTls::setShutdownTimeout(const utils::Timeval& newShutdownTimeout) {
268 ->default_val(newShutdownTimeout)
269 ->clear();
270
271 return *this;
272 }
273
275 return shutdownTimeoutOpt //
276 ->as<utils::Timeval>();
277 }
278
279} // namespace net::config
ConfigSection(ConfigInstance *instance, const std::string &name, const std::string &description)
CLI::Option * addOption(const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue)
CLI::Option * addOption(const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &additionalValidator)
CLI::Option * addFlag(const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &additionalValidator)
ConfigTls & setCaCert(const std::string &caCert)
CLI::Option * caCertUseDefaultDirOpt
Definition ConfigTls.h:112
CLI::Option * certOpt
Definition ConfigTls.h:107
CLI::Option * shutdownTimeoutOpt
Definition ConfigTls.h:117
CLI::Option * caCertDirOpt
Definition ConfigTls.h:111
CLI::Option * caCertAcceptUnknownOpt
Definition ConfigTls.h:113
utils::Timeval getShutdownTimeout() const
CLI::Option * caCertOpt
Definition ConfigTls.h:110
std::string getCaCertDir() const
CLI::Option * certKeyOpt
Definition ConfigTls.h:108
bool getNoCloseNotifyIsEOF() const
ConfigTls & setCert(const std::string &cert)
ConfigTls & setCaCertUseDefaultDir(bool set=true)
std::string getCaCert() const
ConfigTls & setCertKey(const std::string &certKey)
ConfigTls & setInitTimeout(const utils::Timeval &newInitTimeout)
CLI::Option * initTimeoutOpt
Definition ConfigTls.h:116
CLI::Option * sslOptionsOpt
Definition ConfigTls.h:115
std::string getCipherList() const
ssl_option_t getSslOptions() const
CLI::Option * noCloseNotifyIsEOFOpt
Definition ConfigTls.h:118
bool getCaCertAcceptUnknown() const
bool getCaCertUseDefaultDir() const
ConfigTls & setSslOptions(ssl_option_t sslOptions)
std::string getCertKey() const
ConfigTls & setCaCertAcceptUnknown(bool set=true)
CLI::Option * certKeyPasswordOpt
Definition ConfigTls.h:109
ConfigTls(ConfigInstance *instance)
Definition ConfigTls.cpp:52
ConfigTls & setNoCloseNotifyIsEOF(bool noCloseNotifyIsEOF=true)
ConfigTls & setCipherList(const std::string &cipherList)
ConfigTls & setCaCertDir(const std::string &caCertDir)
std::string getCert() const
CLI::Option * cipherListOpt
Definition ConfigTls.h:114
std::string getCertKeyPassword() const
ConfigTls & setShutdownTimeout(const utils::Timeval &newShutdownTimeout)
ConfigTls & setCertKeyPassword(const std::string &certKeyPassword)
utils::Timeval getInitTimeout() const