SNode.C
Loading...
Searching...
No Matches
ConfigSocketServer.hpp
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "net/config/stream/tls/ConfigSocketServer.h"
21
22#ifndef DOXYGEN_SHOULD_SKIP_THIS
23
24#include "log/Logger.h"
25
26#include <algorithm>
27#include <list>
28#include <openssl/ssl.h>
29#include <variant>
30
31#endif // DOXYGEN_SHOULD_SKIP_THIS
32
33namespace net::config::stream::tls {
34
35 template <typename ConfigSocketServerBase>
41
42 template <typename ConfigSocketServerBase>
44 if (sslCtx != nullptr) {
46 }
49 if (sniCtx != nullptr) {
51 }
52 }
53 }
54
55 template <typename ConfigSocketServerBase>
57 if (sslCtx == nullptr) {
59
61
71
73 }
74
75 if (sniCtxMap.empty()) {
77
79
80 for (const auto& [sni, ctx] : sniCtxMap) {
81 LOG(TRACE) << getInstanceName() << " SSL/TLS: SSL_CTX (M) sni for '" << sni << "' from master certificate installed";
82 }
83
84 for (const auto& [domain, sniCertConf] : getSniCerts()) {
85 if (!domain.empty()) {
87
89
90 for (const auto& [key, value] : sniCertConf) {
91 if (key == "Cert") {
93 } else if (key == "CertKey") {
95 } else if (key == "CertKeyPassword") {
97 } else if (key == "CaCert") {
99 } else if (key == "CaCertDir") {
101 } else if (key == "CaCertUseDefaultDir") {
103 } else if (key == "CaCertAcceptUnknown") {
105 } else if (key == "CipherList") {
107 } else if (key == "SslOptions") {
109 }
110 }
111
113
114 if (newCtx != nullptr) {
117
118 LOG(TRACE) << getInstanceName() << " SSL/TLS: SSL_CTX (E) sni for '" << domain << "' explicitly installed";
119
120 for (const auto& [san, ctx] : core::socket::stream::tls::ssl_get_sans(newCtx)) {
122
123 LOG(TRACE) << getInstanceName() << " SSL/TLS: SSL_CTX (S) sni for '" << san << "' from SAN installed";
124 }
125 } else {
126 LOG(WARNING) << getInstanceName() << " SSL/TLS: Can not create SNI_SSL_CTX for domain '" << domain << "'";
127 }
128 }
129 }
130 LOG(TRACE) << getInstanceName() << " SSL/TLS: SNI list result:";
131 for (const auto& [sni, ctx] : sniCtxMap) {
132 LOG(TRACE) << " " << sni;
133 }
134 }
135
136 return sslCtx;
137 }
138
139 template <typename ConfigSocketServerBase>
141 LOG(TRACE) << getInstanceName() << " SSL/TLS SNI: Lookup for sni='" << serverNameIndication << "' in sni certificates";
142
143 SSL_CTX* sniCtx = nullptr;
144
146 sniCtxMap.begin(), sniCtxMap.end(), [&serverNameIndication, this](const std::pair<std::string, SSL_CTX*>& sniPair) -> bool {
147 LOG(TRACE) << getInstanceName() << " SSL/TLS SNI: .. " << sniPair.first.c_str();
149 });
150
151 if (sniPairIt != sniCtxMap.end()) {
152 LOG(TRACE) << getInstanceName() << " SSL/TLS SNI: found for " << serverNameIndication << " -> '" << sniPairIt->first << "'";
154 } else {
155 LOG(WARNING) << getInstanceName() << " SSL/TL SNI: not found for " << serverNameIndication;
156 }
157
158 return sniCtx;
159 }
160
161} // namespace net::config::stream::tls