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 43 of file ConfigTlsServer.h.

Member Typedef Documentation

◆ Super

Definition at line 45 of file ConfigTlsServer.h.

◆ Tls

Constructor & Destructor Documentation

◆ ConfigTlsServer()

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

Definition at line 33 of file ConfigTlsServer.cpp.

34 : Super(instance) {
36 ->add_option("--sni-cert",
38 "Server Name Indication (SNI) Certificates:\n"
39 "sni = SNI of the virtual server\n"
40 "<key> = {\n"
41 " Cert -> value:PEM-FILE [\"\"]\n"
42 " CertKey -> value:PEM-FILE [\"\"]\n"
43 " CertKeyPassword -> value:TEXT [\"\"]\n"
44 " CaCert -> value:PEM-FILE [\"\"]\n"
45 " CaCertDir -> value:PEM-CONTAINER-DIR [\"\"]\n"
46 " CaCertUseDefaultDir -> value:BOOLEAN [false]\n"
47 " CipherList -> value:CIPHER [\"\"]\n"
48 " SslOptions -> value:UINT [0]\n"
49 "}") //
50 ->type_name("sni <key> value [<key> value] ... [%% sni <key> value [<key> value] ...]")
51 ->default_str("[\"\" \"\" \"\" \"\"]");
52 if (sniCertsOpt->get_configurable()) {
53 sniCertsOpt->group(section->get_formatter()->get_label("Persistent Options"));
54 }
55
56 sniCertsOpt->default_function([this]() -> std::string {
57 std::string defaultValue;
58
59 for (const auto& [domain, sniCertConf] : defaultSniCerts) {
60 defaultValue += (!defaultValue.empty() ? "\"%%\" \"" : "\"") + domain + "\" ";
61
62 for (const auto& [key, value] : sniCertConf) {
63 defaultValue += "\"" + key + "\" ";
64
65 if (key == "Cert") {
66 defaultValue += "\"" + std::get<std::string>(value) + "\" ";
67 } else if (key == "CertKey") {
68 defaultValue += "\"" + std::get<std::string>(value) + "\" ";
69 } else if (key == "CertKeyPassword") {
70 defaultValue += "\"" + std::get<std::string>(value) + "\" ";
71 } else if (key == "CaCert") {
72 defaultValue += "\"" + std::get<std::string>(value) + "\" ";
73 } else if (key == "CaCertDir") {
74 defaultValue += "\"" + std::get<std::string>(value) + "\" ";
75 } else if (key == "CaCertUseDefaultDir") {
76 defaultValue += std::get<bool>(value) ? "\"true\" " : "\"false\" ";
77 } else if (key == "CipherList") {
78 defaultValue += "\"" + std::get<std::string>(value) + "\" ";
79 } else if (key == "SslOptions") {
80 defaultValue += "\"" + std::to_string(std::get<ssl_option_t>(value)) + "\" ";
81 }
82 }
83 }
84
85 defaultValue.pop_back();
86
87 return "[" + defaultValue + " \"\"]";
88 });
89
91 "--force-sni{true}",
92 "Force using of the Server Name Indication",
93 "bool",
94 "false",
95 CLI::IsMember({"true", "false"}));
96
97 section->final_callback([this]() {
98 for (auto& [domain, sniMap] : configuredSniCerts) {
99 if (domain.empty()) {
100 sniCertsOpt //
101 ->clear();
102 sniMap.clear();
103 break;
104 }
105 for (auto& [key, value] : sniMap) {
106 if (key != "Cert" && //
107 key != "CertKey" && //
108 key != "CertKeyPassword" && //
109 key != "CaCert" && //
110 key != "CaCertDir" && //
111 key != "CaCertUseDefaultDir" && //
112 key != "CipherList" && //
113 key != "SslOptions") {
114 throw CLI::ConversionError("'" + key + "' of option '--" + section->get_parent()->get_name() + "." +
115 section->get_name() + ".sni-cert'",
116 "<key>");
117 }
118 }
119 }
120 });
121 }
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 143 of file ConfigTlsServer.cpp.

144 {
145 defaultSniCerts[domain] = sniCert;
146 sniCertsOpt->capture_default_str();
147
148 return *this;
149 }

◆ 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 135 of file ConfigTlsServer.cpp.

136 {
137 defaultSniCerts.insert(sniCerts.begin(), sniCerts.end());
138 sniCertsOpt->capture_default_str();
139
140 return *this;
141 }

◆ getForceSni()

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

Definition at line 131 of file ConfigTlsServer.cpp.

131 {
132 return forceSniOpt->as<bool>();
133 }

◆ 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 151 of file ConfigTlsServer.cpp.

151 {
153 }

◆ setForceSni()

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

Definition at line 123 of file ConfigTlsServer.cpp.

123 {
124 forceSniOpt //
125 ->default_val(forceSni ? "true" : "false")
126 ->clear();
127
128 return *this;
129 }

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 65 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 64 of file ConfigTlsServer.h.

◆ forceSniOpt

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

Definition at line 68 of file ConfigTlsServer.h.

◆ sniCertsOpt

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

Definition at line 67 of file ConfigTlsServer.h.


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