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 }
127
128 ConfigTls& ConfigTls::setCert(const std::string& cert) {
129 certOpt //
130 ->default_val(cert)
131 ->clear();
132
133 return *this;
134 }
135
136 std::string ConfigTls::getCert() const {
137 return certOpt->as<std::string>();
138 }
139
140 ConfigTls& ConfigTls::setCertKey(const std::string& certKey) {
141 certKeyOpt //
142 ->default_val(certKey)
143 ->clear();
144
145 return *this;
146 }
147
148 std::string ConfigTls::getCertKey() const {
149 return certKeyOpt->as<std::string>();
150 }
151
152 ConfigTls& ConfigTls::setCertKeyPassword(const std::string& certKeyPassword) {
154 ->default_val(certKeyPassword)
155 ->clear();
156
157 return *this;
158 }
159
160 std::string ConfigTls::getCertKeyPassword() const {
161 return certKeyPasswordOpt->as<std::string>();
162 }
163
164 ConfigTls& ConfigTls::setCaCert(const std::string& caCert) {
165 caCertOpt //
166 ->default_val(caCert)
167 ->clear();
168
169 return *this;
170 }
171
172 std::string ConfigTls::getCaCert() const {
173 return caCertOpt->as<std::string>();
174 }
175
176 ConfigTls& ConfigTls::setCaCertDir(const std::string& caCertDir) {
177 caCertDirOpt //
178 ->default_val(caCertDir)
179 ->clear();
180
181 return *this;
182 }
183
184 std::string ConfigTls::getCaCertDir() const {
185 return caCertDirOpt->as<std::string>();
186 }
187
190 ->default_val(set ? "true" : "false")
191 ->clear();
192
193 return *this;
194 }
195
197 return caCertUseDefaultDirOpt->as<bool>();
198 }
199
202 ->default_val(set ? "true" : "false")
203 ->clear();
204
205 return *this;
206 }
207
209 return caCertAcceptUnknownOpt->as<bool>();
210 }
211
212 ConfigTls& ConfigTls::setCipherList(const std::string& cipherList) {
214 ->default_val(cipherList)
215 ->clear();
216
217 return *this;
218 }
219
220 std::string ConfigTls::getCipherList() const {
221 return cipherListOpt->as<std::string>();
222 }
223
224 ConfigTls& ConfigTls::setSslOptions(ssl_option_t sslOptions) {
226 ->default_val(sslOptions)
227 ->clear();
228
229 return *this;
230 }
231
232 ssl_option_t ConfigTls::getSslOptions() const {
233 return sslOptionsOpt->as<ssl_option_t>();
234 }
235
236 ConfigTls& ConfigTls::setNoCloseNotifyIsEOF(bool noCloseNotifyIsEOF) {
237 this->noCloseNotifyIsEOFOpt = noCloseNotifyIsEOF;
238
239 return *this;
240 }
241
244 }
245
246 ConfigTls& ConfigTls::setInitTimeout(const utils::Timeval& newInitTimeout) {
248 ->default_val(newInitTimeout)
249 ->clear();
250
251 return *this;
252 }
253
255 return initTimeoutOpt->as<utils::Timeval>();
256 }
257
258 ConfigTls& ConfigTls::setShutdownTimeout(const utils::Timeval& newShutdownTimeout) {
260 ->default_val(newShutdownTimeout)
261 ->clear();
262
263 return *this;
264 }
265
267 return shutdownTimeoutOpt //
268 ->as<utils::Timeval>();
269 }
270
271} // 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
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