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/stream/tls/ConfigSocketServer.h"
44#ifndef DOXYGEN_SHOULD_SKIP_THIS
46#include "log/Logger.h"
50#include <openssl/ssl.h>
57 template <
typename ConfigSocketServerBase>
60 , ConfigSocketServerBase(
this)
64 template <
typename ConfigSocketServerBase>
70 for (SSL_CTX* sniCtx :
sniCtxs) {
71 if (sniCtx !=
nullptr) {
77 template <
typename ConfigSocketServerBase>
100 sniCtxMap.insert(sslSans.begin(), sslSans.end());
102 for (
const auto& [sni, ctx] :
sniCtxMap) {
107 if (!domain.empty()) {
112 for (
const auto& [key, value] : sniCertConf) {
114 sslConfig
.cert = std::get<std::string>(value);
115 }
else if (key ==
"CertKey") {
116 sslConfig
.certKey = std::get<std::string>(value);
117 }
else if (key ==
"CertKeyPassword") {
118 sslConfig
.password = std::get<std::string>(value);
119 }
else if (key ==
"CaCert") {
120 sslConfig
.caCert = std::get<std::string>(value);
121 }
else if (key ==
"CaCertDir") {
122 sslConfig
.caCertDir = std::get<std::string>(value);
123 }
else if (key ==
"CaCertUseDefaultDir") {
125 }
else if (key ==
"CaCertAcceptUnknown") {
127 }
else if (key ==
"CipherList") {
128 sslConfig
.cipherList = std::get<std::string>(value);
129 }
else if (key ==
"SslOptions") {
130 sslConfig
.sslOptions = std::get<ssl_option_t>(value);
136 if (newCtx !=
nullptr) {
138 sniCtxMap.insert_or_assign(domain, newCtx);
153 for (
const auto& [sni, ctx] :
sniCtxMap) {
161 template <
typename ConfigSocketServerBase>
165 SSL_CTX* sniCtx =
nullptr;
167 std::map<std::string, SSL_CTX*>::iterator sniPairIt = std::find_if(
168 sniCtxMap.begin(),
sniCtxMap.end(), [&serverNameIndication,
this](
const std::pair<std::string, SSL_CTX*>& sniPair) ->
bool {
175 sniCtx = sniPairIt->second;
LogMessage(Level level, int verboseLevel=-1, bool withErrno=false)
const std::string & getInstanceName() const
const std::map< std::string, std::map< std::string, std::variant< std::string, bool, ssl_option_t > > > & getSniCerts() const
std::string getCaCertDir() const
std::string getCaCert() const
std::string getCipherList() const
ssl_option_t getSslOptions() const
bool getCaCertAcceptUnknown() const
bool getCaCertUseDefaultDir() const
std::string getCertKey() const
std::string getCert() const
std::string getCertKeyPassword() const
ConfigSocketServer(const std::string &name)
std::list< SSL_CTX * > sniCtxs
SSL_CTX * getSniCtx(const std::string &serverNameIndication)
std::map< std::string, SSL_CTX * > sniCtxMap
~ConfigSocketServer() override
ConfigSocketServer(const std::string &name)
~ConfigSocketServer() override
bool match(const char *first, const char *second)
void ssl_ctx_free(SSL_CTX *ctx)
std::map< std::string, SSL_CTX * > ssl_get_sans(SSL_CTX *sslCtx)
SSL_CTX * ssl_ctx_new(const SslConfig &sslConfig)