SNode.C
Loading...
Searching...
No Matches
net::config::stream::tls::ConfigSocketServer< ConfigSocketServerBaseT > Class Template Reference

#include <ConfigSocketServer.h>

Inheritance diagram for net::config::stream::tls::ConfigSocketServer< ConfigSocketServerBaseT >:
Collaboration diagram for net::config::stream::tls::ConfigSocketServer< ConfigSocketServerBaseT >:

Public Types

using Instance = net::config::ConfigInstance
using Tls = net::config::ConfigTlsServer
Public Types inherited from net::config::ConfigInstance
enum class  Role { SERVER , CLIENT }
using Instance = ConfigInstance

Public Member Functions

SSL_CTX * getSslCtx ()
SSL_CTX * getSniCtx (const std::string &serverNameIndication)
Public Member Functions inherited from net::config::ConfigInstance
 ConfigInstance (ConfigInstance &)=delete
 ConfigInstance (ConfigInstance &&)=delete
ConfigInstanceoperator= (ConfigInstance &)=delete
ConfigInstanceoperator= (ConfigInstance &&)=delete
const std::string & getInstanceName () const
ConfigInstancesetInstanceName (const std::string &instanceName)
bool getDisabled () const
ConfigInstancesetDisabled (bool disabled=true)
ConfigInstanceconfigurable (bool configurable)
ConfigInstancesetOnDestroy (const std::function< void(ConfigInstance *)> &onDestroy)
Public Member Functions inherited from utils::SubCommand
 SubCommand (const SubCommand &)=delete
 SubCommand (SubCommand &&)=delete
SubCommandoperator= (const SubCommand &)=delete
SubCommandoperator= (SubCommand &&)=delete
virtual ~SubCommand ()
std::string getName () const
std::string version () const
CLI::Option * setConfig (const std::string &defaultConfigFile) const
CLI::Option * setLogFile (const std::string &defaultLogFile) const
CLI::Option * setVersionFlag (const std::string &version) const
bool hasParent () const
SubCommandgetParent () const
SubCommandallowExtras (bool allow=true)
SubCommandrequired (bool required=true, bool force=true)
SubCommandrequired (SubCommand *subCommand, bool required=true)
SubCommandrequired (CLI::Option *option, bool required=true)
bool getRequired () const
SubCommandneeds (SubCommand *subCommand, bool needs=true)
SubCommanddisabled (SubCommand *subCommand, bool disabled=true)
SubCommandsetRequireCallback (const std::function< void(void)> &callback)
SubCommandfinalCallback (const std::function< void()> &finalCallback)
std::string configToStr () const
std::string help (const CLI::App *helpApp, const CLI::AppFormatMode &mode) const
void addSubCommandApp (std::shared_ptr< utils::AppWithPtr > subCommand)
template<typename NewSubCommand, typename... Args>
NewSubCommand * newSubCommand (Args &&... args)
template<typename RequestedSubCommand>
RequestedSubCommand * getSubCommand ()
template<typename RequestedSubCommand>
RequestedSubCommand * getSubCommand () const
CLI::Option * getOption (const std::string &name) const
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &validator) const
template<typename ValueTypeT>
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &validator) const
template<typename ValueTypeT>
CLI::Option * addOptionVariable (const std::string &name, ValueTypeT &variable, const std::string &description, const std::string &typeName, const CLI::Validator &additionalValidator) const
template<typename ValueTypeT>
CLI::Option * addOptionVariable (const std::string &name, ValueTypeT &variable, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &additionalValidator) const
CLI::Option * addOptionFunction (const std::string &name, const std::function< void(const std::string &)> &callback, const std::string &description, const std::string &typeName, const CLI::Validator &validator) const
template<typename ValueTypeT>
CLI::Option * addOptionFunction (const std::string &name, const std::function< void(const std::string &)> &callback, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &validator) const
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &validator) const
template<typename ValueTypeT>
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &validator) const
CLI::Option * addFlagFunction (const std::string &name, const std::function< void()> &callback, const std::string &description, const std::string &typeName, const CLI::Validator &validator) const
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) const
Public Member Functions inherited from net::config::ConfigTlsServer
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 () const
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
Public Member Functions inherited from net::config::ConfigSection
template<typename T>
 ConfigSection (ConfigInstance *instance, T *sectionPtr, const std::string &group="Sections")
 ~ConfigSection () override
 ConfigSection (const ConfigSection &)=delete
 ConfigSection (ConfigSection &&)=delete
ConfigSectionoperator= (const ConfigSection &)=delete

Protected Member Functions

 ConfigSocketServer (const std::string &name)
 ~ConfigSocketServer () override
Protected Member Functions inherited from net::config::ConfigInstance
 ConfigInstance (const std::string &instanceName, Role role)
 ~ConfigInstance () override
Protected Member Functions inherited from utils::SubCommand
 SubCommand (SubCommand *parent, std::shared_ptr< utils::AppWithPtr > appWithPtr, const std::string &group, bool final=false)
template<typename ConcretSubCommand>
 SubCommand (SubCommand *parent, ConcretSubCommand *concretSubCommand, const std::string &group, bool final=false)
void parse (int argc, char *argv[]) const
SubCommanddescription (const std::string &description)
SubCommandfooter (const std::string &footer)
void removeSubCommand ()
template<typename ValueTypeT>
CLI::Option * setDefaultValue (CLI::Option *option, const ValueTypeT &value, bool clear=true) const
CLI::Option * setConfigurable (CLI::Option *option, bool configurable) const
Protected Member Functions inherited from net::config::ConfigTlsServer
 ConfigTlsServer (ConfigInstance *instance)
 ~ConfigTlsServer () override
Protected Member Functions inherited from net::config::ConfigTls
template<typename ConcretConfigTls>
 ConfigTls (ConfigInstance *instance, ConcretConfigTls section)
 ~ConfigTls () override

Static Private Member Functions

static int clientHelloCallback (SSL *ssl, int *al, void *arg)

Private Attributes

SSL_CTX * sslCtx = nullptr
std::list< SSL_CTX * > sniCtxs
std::map< std::string, SSL_CTX * > sniCtxMap

Additional Inherited Members

Static Public Member Functions inherited from net::config::ConfigInstance
static CLI::App * getHelpTriggerApp ()
static CLI::App * getShowConfigTriggerApp ()
static CLI::App * extracted ()
static CLI::App * getCommandlineTriggerApp ()
Static Public Attributes inherited from net::config::ConfigTls
static constexpr std::string_view NAME {"tls"}
static constexpr std::string_view DESCRIPTION {"Configuration of SSL/TLS behavior"}
Static Protected Member Functions inherited from utils::SubCommand
static CLI::App * getHelpTriggerApp ()
static CLI::App * getShowConfigTriggerApp ()
static CLI::App * getCommandlineTriggerApp ()
Protected Attributes inherited from utils::SubCommand
CLI::Option * helpOpt = nullptr
Static Protected Attributes inherited from utils::SubCommand
static std::shared_ptr< CLI::Formatter > sectionFormatter = makeSectionFormatter()
static std::map< std::string, std::string > aliases
static CLI::App * helpTriggerApp = nullptr
static CLI::App * showConfigTriggerApp = nullptr
static CLI::App * commandlineTriggerApp = nullptr

Detailed Description

template<typename ConfigSocketServerBaseT>
class net::config::stream::tls::ConfigSocketServer< ConfigSocketServerBaseT >

Definition at line 59 of file ConfigSocketServer.h.

Member Typedef Documentation

◆ Instance

template<typename ConfigSocketServerBaseT>
using net::config::stream::tls::ConfigSocketServer< ConfigSocketServerBaseT >::Instance = net::config::ConfigInstance

Definition at line 69 of file ConfigSocketServer.h.

◆ Tls

template<typename ConfigSocketServerBaseT>
using net::config::stream::tls::ConfigSocketServer< ConfigSocketServerBaseT >::Tls = net::config::ConfigTlsServer

Definition at line 70 of file ConfigSocketServer.h.

Constructor & Destructor Documentation

◆ ConfigSocketServer()

◆ ~ConfigSocketServer()

template<typename ConfigSocketServerBase>
net::config::stream::tls::ConfigSocketServer< ConfigSocketServerBase >::~ConfigSocketServer ( )
overrideprotected

Definition at line 65 of file ConfigSocketServer.hpp.

Member Function Documentation

◆ clientHelloCallback()

template<typename ConfigSocketServerBaseT>
int net::config::stream::tls::ConfigSocketServer< ConfigSocketServerBaseT >::clientHelloCallback ( SSL * ssl,
int * al,
void * arg )
staticprivate

◆ getSniCtx()

template<typename ConfigSocketServerBase>
SSL_CTX * net::config::stream::tls::ConfigSocketServer< ConfigSocketServerBase >::getSniCtx ( const std::string & serverNameIndication)

Definition at line 162 of file ConfigSocketServer.hpp.

162 {
163 LOG(TRACE) << getInstanceName() << " SSL/TLS SNI: Lookup for sni='" << serverNameIndication << "' in sni certificates";
164
165 SSL_CTX* sniCtx = nullptr;
166
168 sniCtxMap.begin(), sniCtxMap.end(), [&serverNameIndication, this](const std::pair<std::string, SSL_CTX*>& sniPair) -> bool {
169 LOG(TRACE) << getInstanceName() << " SSL/TLS SNI: .. " << sniPair.first.c_str();
170 return core::socket::stream::tls::match(sniPair.first.c_str(), serverNameIndication.c_str());
171 });
172
173 if (sniPairIt != sniCtxMap.end()) {
174 LOG(TRACE) << getInstanceName() << " SSL/TLS SNI: found for " << serverNameIndication << " -> '" << sniPairIt->first << "'";
175 sniCtx = sniPairIt->second;
176 } else {
177 LOG(WARNING) << getInstanceName() << " SSL/TL SNI: not found for " << serverNameIndication;
178 }
179
180 return sniCtx;
181 }
#define LOG(level)
Definition Logger.h:148
const std::string & getInstanceName() const
std::map< std::string, SSL_CTX * > sniCtxMap

References net::config::ConfigInstance::getInstanceName(), logger::LogMessage::LogMessage(), core::socket::stream::tls::match(), sniCtxMap, logger::TRACE, and logger::WARNING.

Here is the call graph for this function:

◆ getSslCtx()

template<typename ConfigSocketServerBase>
SSL_CTX * net::config::stream::tls::ConfigSocketServer< ConfigSocketServerBase >::getSslCtx ( )

Definition at line 78 of file ConfigSocketServer.hpp.

78 {
79 if (sslCtx == nullptr) {
81
83
84 sslConfig.cert = getCert();
85 sslConfig.certKey = getCertKey();
86 sslConfig.password = getCertKeyPassword();
87 sslConfig.caCert = getCaCert();
88 sslConfig.caCertDir = getCaCertDir();
89 sslConfig.cipherList = getCipherList();
90 sslConfig.sslOptions = getSslOptions();
91 sslConfig.caCertUseDefaultDir = getCaCertUseDefaultDir();
92 sslConfig.caCertAcceptUnknown = getCaCertAcceptUnknown();
93
95 }
96
97 if (sniCtxMap.empty()) {
99
100 sniCtxMap.insert(sslSans.begin(), sslSans.end());
101
102 for (const auto& [sni, ctx] : sniCtxMap) {
103 LOG(TRACE) << getInstanceName() << " SSL/TLS: SSL_CTX (M) sni for '" << sni << "' from master certificate installed";
104 }
105
106 for (const auto& [domain, sniCertConf] : getSniCerts()) {
107 if (!domain.empty()) {
109
111
112 for (const auto& [key, value] : sniCertConf) {
113 if (key == "Cert") {
115 } else if (key == "CertKey") {
117 } else if (key == "CertKeyPassword") {
119 } else if (key == "CaCert") {
121 } else if (key == "CaCertDir") {
123 } else if (key == "CaCertUseDefaultDir") {
124 sslConfig.caCertUseDefaultDir = std::get<bool>(value);
125 } else if (key == "CaCertAcceptUnknown") {
126 sslConfig.caCertAcceptUnknown = std::get<bool>(value);
127 } else if (key == "CipherList") {
129 } else if (key == "SslOptions") {
131 }
132 }
133
135
136 if (newCtx != nullptr) {
137 sniCtxs.push_back(newCtx);
138 sniCtxMap.insert_or_assign(domain, newCtx);
139
140 LOG(TRACE) << getInstanceName() << " SSL/TLS: SSL_CTX (E) sni for '" << domain << "' explicitly installed";
141
142 for (const auto& [san, ctx] : core::socket::stream::tls::ssl_get_sans(newCtx)) {
143 sniCtxMap.insert_or_assign(san, ctx);
144
145 LOG(TRACE) << getInstanceName() << " SSL/TLS: SSL_CTX (S) sni for '" << san << "' from SAN installed";
146 }
147 } else {
148 LOG(WARNING) << getInstanceName() << " SSL/TLS: Can not create SNI_SSL_CTX for domain '" << domain << "'";
149 }
150 }
151 }
152 LOG(TRACE) << getInstanceName() << " SSL/TLS: SNI list result:";
153 for (const auto& [sni, ctx] : sniCtxMap) {
154 LOG(TRACE) << " " << sni;
155 }
156 }
157
158 return sslCtx;
159 }
const std::map< std::string, std::map< std::string, std::variant< std::string, bool, ssl_option_t > > > & getSniCerts() const
std::string getCaCertDir() const
Definition ConfigTls.cpp:99
std::string getCaCert() const
Definition ConfigTls.cpp:89
std::string getCipherList() const
ssl_option_t getSslOptions() const
bool getCaCertAcceptUnknown() const
bool getCaCertUseDefaultDir() const
std::string getCertKey() const
Definition ConfigTls.cpp:69
std::string getCert() const
Definition ConfigTls.cpp:59
std::string getCertKeyPassword() const
Definition ConfigTls.cpp:79
std::map< std::string, SSL_CTX * > ssl_get_sans(SSL_CTX *sslCtx)
SSL_CTX * ssl_ctx_new(const SslConfig &sslConfig)

References core::socket::stream::tls::SslConfig::caCert, core::socket::stream::tls::SslConfig::caCertAcceptUnknown, core::socket::stream::tls::SslConfig::caCertDir, core::socket::stream::tls::SslConfig::caCertUseDefaultDir, core::socket::stream::tls::SslConfig::cert, core::socket::stream::tls::SslConfig::certKey, core::socket::stream::tls::SslConfig::cipherList, net::config::ConfigTls::getCaCert(), net::config::ConfigTls::getCaCertAcceptUnknown(), net::config::ConfigTls::getCaCertDir(), net::config::ConfigTls::getCaCertUseDefaultDir(), net::config::ConfigTls::getCert(), net::config::ConfigTls::getCertKey(), net::config::ConfigTls::getCertKeyPassword(), net::config::ConfigTls::getCipherList(), net::config::ConfigInstance::getInstanceName(), net::config::ConfigTlsServer::getSniCerts(), net::config::ConfigTls::getSslOptions(), core::socket::stream::tls::SslConfig::instanceName, logger::LogMessage::LogMessage(), core::socket::stream::tls::SslConfig::password, sniCtxMap, sniCtxs, core::socket::stream::tls::ssl_ctx_new(), core::socket::stream::tls::ssl_get_sans(), core::socket::stream::tls::SslConfig::SslConfig(), sslCtx, core::socket::stream::tls::SslConfig::sslOptions, logger::TRACE, and logger::WARNING.

Here is the call graph for this function:

Member Data Documentation

◆ sniCtxMap

template<typename ConfigSocketServerBaseT>
std::map<std::string, SSL_CTX*> net::config::stream::tls::ConfigSocketServer< ConfigSocketServerBaseT >::sniCtxMap
private

Definition at line 80 of file ConfigSocketServer.h.

Referenced by getSniCtx(), and getSslCtx().

◆ sniCtxs

template<typename ConfigSocketServerBaseT>
std::list<SSL_CTX*> net::config::stream::tls::ConfigSocketServer< ConfigSocketServerBaseT >::sniCtxs
private

Definition at line 79 of file ConfigSocketServer.h.

Referenced by getSslCtx().

◆ sslCtx

template<typename ConfigSocketServerBaseT>
SSL_CTX* net::config::stream::tls::ConfigSocketServer< ConfigSocketServerBaseT >::sslCtx = nullptr
private

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