2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#include "net/config/ConfigTlsServer.h"
44#include "net/config/ConfigSection.hpp"
46#ifndef DOXYGEN_SHOULD_SKIP_THIS
53namespace net::config {
58 ->add_option(
"--sni-cert",
60 "Server Name Indication (SNI) Certificates:\n"
61 "sni = SNI of the virtual server\n"
63 " Cert -> value:PEM-FILE [\"\"]\n"
64 " CertKey -> value:PEM-FILE [\"\"]\n"
65 " CertKeyPassword -> value:TEXT [\"\"]\n"
66 " CaCert -> value:PEM-FILE [\"\"]\n"
67 " CaCertDir -> value:PEM-CONTAINER-DIR [\"\"]\n"
68 " CaCertUseDefaultDir -> value:BOOLEAN [false]\n"
69 " CipherList -> value:CIPHER [\"\"]\n"
70 " SslOptions -> value:UINT [0]\n"
72 ->type_name(
"sni <key> value [<key> value] ... [%% sni <key> value [<key> value] ...]")
73 ->default_str(
"[\"\" \"\" \"\" \"\"]");
78 sniCertsOpt->default_function([
this]() -> std::string {
79 std::string defaultValue;
82 defaultValue += (!defaultValue.empty() ?
"\"%%\" \"" :
"\"") + domain +
"\" ";
84 for (
const auto& [key, value] : sniCertConf) {
85 defaultValue +=
"\"" + key +
"\" ";
88 defaultValue +=
"\"" + std::get<std::string>(value) +
"\" ";
89 }
else if (key ==
"CertKey") {
90 defaultValue +=
"\"" + std::get<std::string>(value) +
"\" ";
91 }
else if (key ==
"CertKeyPassword") {
92 defaultValue +=
"\"" + std::get<std::string>(value) +
"\" ";
93 }
else if (key ==
"CaCert") {
94 defaultValue +=
"\"" + std::get<std::string>(value) +
"\" ";
95 }
else if (key ==
"CaCertDir") {
96 defaultValue +=
"\"" + std::get<std::string>(value) +
"\" ";
97 }
else if (key ==
"CaCertUseDefaultDir") {
98 defaultValue += std::get<
bool>(value) ?
"\"true\" " :
"\"false\" ";
99 }
else if (key ==
"CipherList") {
100 defaultValue +=
"\"" + std::get<std::string>(value) +
"\" ";
101 }
else if (key ==
"SslOptions") {
102 defaultValue +=
"\"" + std::to_string(std::get<ssl_option_t>(value)) +
"\" ";
107 defaultValue.pop_back();
109 return "[" + defaultValue +
" \"\"]";
114 "Force using of the Server Name Indication",
117 CLI::IsMember({
"true",
"false"})
);
119 section->final_callback([
this]() {
121 if (domain.empty()) {
127 for (
auto& [key, value] : sniMap) {
130 key !=
"CertKeyPassword" &&
132 key !=
"CaCertDir" &&
133 key !=
"CaCertUseDefaultDir" &&
134 key !=
"CipherList" &&
135 key !=
"SslOptions") {
136 throw CLI::ConversionError(
"'" + key +
"' of option '--" +
section->get_parent()->get_name() +
"." +
137 section->get_name() +
".sni-cert'",
147 ->default_val(forceSni ?
"true" :
"false")
158 const std::map<std::string, std::map<std::string, std::variant<std::string,
bool, ssl_option_t>>>& sniCerts) {
166 const std::map<std::string, std::variant<std::string,
bool, ssl_option_t>>& sniCert) {
CLI::Option * addFlag(const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &additionalValidator)
std::map< std::string, std::map< std::string, std::variant< std::string, bool, ssl_option_t > > > configuredSniCerts
ConfigTlsServer & addSniCerts(const std::map< std::string, std::map< std::string, std::variant< std::string, bool, ssl_option_t > > > &sniCerts)
ConfigTlsServer(ConfigInstance *instance)
ConfigTlsServer & setForceSni(bool forceSni=true)
std::map< std::string, std::map< std::string, std::variant< std::string, bool, ssl_option_t > > > defaultSniCerts
CLI::Option * sniCertsOpt
CLI::Option * forceSniOpt
ConfigTlsServer & addSniCert(const std::string &domain, const std::map< std::string, std::variant< std::string, bool, ssl_option_t > > &sniCert)
const std::map< std::string, std::map< std::string, std::variant< std::string, bool, ssl_option_t > > > & getSniCerts()
ConfigTls(ConfigInstance *instance)