SNode.C
Loading...
Searching...
No Matches
net::config::ConfigTlsServer Class Reference

#include <ConfigTlsServer.h>

Inheritance diagram for net::config::ConfigTlsServer:
Collaboration diagram for net::config::ConfigTlsServer:

Public Types

using Tls = ConfigTlsServer
 

Public Member Functions

ConfigTlsServersetForceSni (bool forceSni=true)
 
bool getForceSni () const
 
ConfigTlsServeraddSniCerts (const std::map< std::string, std::map< std::string, std::variant< std::string, bool, ssl_option_t > > > &sniCerts)
 
ConfigTlsServeraddSniCert (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 ()
 
- Public Member Functions inherited from net::config::ConfigTls
ConfigTlssetInitTimeout (const utils::Timeval &newInitTimeout)
 
utils::Timeval getInitTimeout () const
 
ConfigTlssetShutdownTimeout (const utils::Timeval &newShutdownTimeout)
 
utils::Timeval getShutdownTimeout () const
 
ConfigTlssetCert (const std::string &cert)
 
std::string getCert () const
 
ConfigTlssetCertKey (const std::string &certKey)
 
std::string getCertKey () const
 
ConfigTlssetCertKeyPassword (const std::string &certKeyPassword)
 
std::string getCertKeyPassword () const
 
ConfigTlssetCaCert (const std::string &caCert)
 
std::string getCaCert () const
 
ConfigTlssetCaCertDir (const std::string &caCertDir)
 
std::string getCaCertDir () const
 
ConfigTlssetCaCertUseDefaultDir (bool set=true)
 
bool getCaCertUseDefaultDir () const
 
ConfigTlssetCaCertAcceptUnknown (bool set=true)
 
bool getCaCertAcceptUnknown () const
 
ConfigTlssetCipherList (const std::string &cipherList)
 
std::string getCipherList () const
 
ConfigTlssetSslOptions (ssl_option_t sslOptions)
 
ssl_option_t getSslOptions () const
 
ConfigTlssetNoCloseNotifyIsEOF (bool noCloseNotifyIsEOF=true)
 
bool getNoCloseNotifyIsEOF () const
 

Protected Member Functions

 ConfigTlsServer (ConfigInstance *instance)
 
- Protected Member Functions inherited from net::config::ConfigTls
 ConfigTls (ConfigInstance *instance)
 
- Protected Member Functions inherited from net::config::ConfigSection
 ConfigSection (ConfigInstance *instance, const std::string &name, const std::string &description)
 
 ConfigSection (const ConfigSection &)=delete
 
 ConfigSection (ConfigSection &&)=delete
 
ConfigSectionoperator= (const ConfigSection &)=delete
 
ConfigSectionoperator= (ConfigSection &&)=delete
 
CLI::Option * addOption (const std::string &name, const std::string &description)
 
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName)
 
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &additionalValidator)
 
template<typename ValueTypeT >
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue)
 
template<typename ValueTypeT >
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)
 
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &additionalValidator)
 
template<typename ValueTypeT >
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue)
 
template<typename ValueTypeT >
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &additionalValidator)
 
CLI::Option * addFlagFunction (const std::string &name, const std::function< void()> &callback, const std::string &description, const std::string &typeName, const std::string &defaultValue)
 
CLI::Option * addFlagFunction (const std::string &name, const std::function< void()> &callback, const std::string &description, const std::string &typeName, const std::string &defaultValue, const CLI::Validator &validator)
 
void required (CLI::Option *opt, bool req=true)
 
bool required () const
 
template<typename ValueType >
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, ValueType defaultValue)
 
template<typename ValueType >
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, ValueType defaultValue, const CLI::Validator &additionalValidator)
 
template<typename ValueType >
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueType defaultValue)
 
template<typename ValueType >
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueType defaultValue, const CLI::Validator &additionalValidator)
 

Private Types

using Super = ConfigTls
 

Private Attributes

std::map< std::string, std::map< std::string, std::variant< std::string, bool, ssl_option_t > > > defaultSniCerts
 
std::map< std::string, std::map< std::string, std::variant< std::string, bool, ssl_option_t > > > configuredSniCerts
 
CLI::Option * sniCertsOpt = nullptr
 
CLI::Option * forceSniOpt = nullptr
 

Additional Inherited Members

- Protected Attributes inherited from net::config::ConfigSection
CLI::App * section = nullptr
 

Detailed Description

Definition at line 65 of file ConfigTlsServer.h.

Member Typedef Documentation

◆ Super

Definition at line 67 of file ConfigTlsServer.h.

◆ Tls

Constructor & Destructor Documentation

◆ ConfigTlsServer()

net::config::ConfigTlsServer::ConfigTlsServer ( ConfigInstance * instance)
explicitprotected

Definition at line 55 of file ConfigTlsServer.cpp.

56 : Super(instance) {
58 ->add_option("--sni-cert",
60 "Server Name Indication (SNI) Certificates:\n"
61 "sni = SNI of the virtual server\n"
62 "<key> = {\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"
71 "}") //
72 ->type_name("sni <key> value [<key> value] ... [%% sni <key> value [<key> value] ...]")
73 ->default_str("[\"\" \"\" \"\" \"\"]");
74 if (sniCertsOpt->get_configurable()) {
75 sniCertsOpt->group(section->get_formatter()->get_label("Persistent Options"));
76 }
77
78 sniCertsOpt->default_function([this]() -> std::string {
79 std::string defaultValue;
80
81 for (const auto& [domain, sniCertConf] : defaultSniCerts) {
82 defaultValue += (!defaultValue.empty() ? "\"%%\" \"" : "\"") + domain + "\" ";
83
84 for (const auto& [key, value] : sniCertConf) {
85 defaultValue += "\"" + key + "\" ";
86
87 if (key == "Cert") {
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)) + "\" ";
103 }
104 }
105 }
106
107 defaultValue.pop_back();
108
109 return "[" + defaultValue + " \"\"]";
110 });
111
112 forceSniOpt = addFlag( //
113 "--force-sni{true}",
114 "Force using of the Server Name Indication",
115 "bool",
116 "false",
117 CLI::IsMember({"true", "false"}));
118
119 section->final_callback([this]() {
120 for (auto& [domain, sniMap] : configuredSniCerts) {
121 if (domain.empty()) {
122 sniCertsOpt //
123 ->clear();
124 sniMap.clear();
125 break;
126 }
127 for (auto& [key, value] : sniMap) {
128 if (key != "Cert" && //
129 key != "CertKey" && //
130 key != "CertKeyPassword" && //
131 key != "CaCert" && //
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'",
138 "<key>");
139 }
140 }
141 }
142 });
143 }
CLI::Option * addFlag(const std::string &name, const std::string &description, const std::string &typeName)
std::map< std::string, std::map< std::string, std::variant< std::string, bool, ssl_option_t > > > configuredSniCerts
std::map< std::string, std::map< std::string, std::variant< std::string, bool, ssl_option_t > > > defaultSniCerts

Member Function Documentation

◆ addSniCert()

ConfigTlsServer & net::config::ConfigTlsServer::addSniCert ( const std::string & domain,
const std::map< std::string, std::variant< std::string, bool, ssl_option_t > > & sniCert )

Definition at line 165 of file ConfigTlsServer.cpp.

166 {
167 defaultSniCerts[domain] = sniCert;
168 sniCertsOpt->capture_default_str();
169
170 return *this;
171 }

◆ addSniCerts()

ConfigTlsServer & net::config::ConfigTlsServer::addSniCerts ( const std::map< std::string, std::map< std::string, std::variant< std::string, bool, ssl_option_t > > > & sniCerts)

Definition at line 157 of file ConfigTlsServer.cpp.

158 {
159 defaultSniCerts.insert(sniCerts.begin(), sniCerts.end());
160 sniCertsOpt->capture_default_str();
161
162 return *this;
163 }

◆ getForceSni()

bool net::config::ConfigTlsServer::getForceSni ( ) const

Definition at line 153 of file ConfigTlsServer.cpp.

153 {
154 return forceSniOpt->as<bool>();
155 }

◆ getSniCerts()

const std::map< std::string, std::map< std::string, std::variant< std::string, bool, ssl_option_t > > > & net::config::ConfigTlsServer::getSniCerts ( )

Definition at line 173 of file ConfigTlsServer.cpp.

173 {
175 }

◆ setForceSni()

ConfigTlsServer & net::config::ConfigTlsServer::setForceSni ( bool forceSni = true)

Definition at line 145 of file ConfigTlsServer.cpp.

145 {
146 forceSniOpt //
147 ->default_val(forceSni ? "true" : "false")
148 ->clear();
149
150 return *this;
151 }

Member Data Documentation

◆ configuredSniCerts

std::map<std::string, std::map<std::string, std::variant<std::string, bool, ssl_option_t> > > net::config::ConfigTlsServer::configuredSniCerts
private

Definition at line 87 of file ConfigTlsServer.h.

◆ defaultSniCerts

std::map<std::string, std::map<std::string, std::variant<std::string, bool, ssl_option_t> > > net::config::ConfigTlsServer::defaultSniCerts
private

Definition at line 86 of file ConfigTlsServer.h.

◆ forceSniOpt

CLI::Option* net::config::ConfigTlsServer::forceSniOpt = nullptr
private

Definition at line 90 of file ConfigTlsServer.h.

◆ sniCertsOpt

CLI::Option* net::config::ConfigTlsServer::sniCertsOpt = nullptr
private

Definition at line 89 of file ConfigTlsServer.h.


The documentation for this class was generated from the following files: