Loading src/crypto/tls.cpp +6 −8 Changes for src/crypto/tls.cpp: 6 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -216,21 +216,19 @@ namespace netplus { std::string snihostname; if (extractSNIFromClientHello(ch, snihostname)) { requested_hostname = snihostname; // Suche das Zertifikat in der Map auto it = cert_map.find(snihostname); if (it != cert_map.end()) { if (cert_map) { auto it = cert_map->find(snihostname); if (it != cert_map->end()) { selected_cert_bundle = const_cast<CertificateBundle*>(&it->second); // ✅ Use bundle's cert directly - no need to copy to _cert SSL_LOG("[SNI] Selected cert for domain: " << snihostname); } else { SSL_LOG("[SNI] No cert found for domain: " << snihostname << ", using default"); // Fallback: Verwende das erste Zertifikat if (!cert_map.empty()) { selected_cert_bundle = const_cast<CertificateBundle*>(&cert_map.begin()->second); // ✅ Use bundle's cert directly if (!cert_map->empty()) { selected_cert_bundle = const_cast<CertificateBundle*>(&cert_map->begin()->second); SSL_LOG("[SNI] Switched to default cert"); } } } } else { SSL_LOG("[SNI] SNI extension not found in ClientHello, using default cert"); } Loading src/crypto/tls.h +1 −1 Changes for src/crypto/tls.h: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -414,7 +414,7 @@ namespace netplus { uint16_t selected_group = 0; // Named group for key share // --- SNI (Server Name Indication) Support --- std::map<std::string, CertificateBundle> cert_map; std::shared_ptr<const std::map<std::string, CertificateBundle>> cert_map; std::string requested_hostname; CertificateBundle* selected_cert_bundle = nullptr; Loading src/event/epoll.cpp +1 −2 Changes for src/event/epoll.cpp: 1 added line, 2 removed lines. Original line number Diff line number Diff line Loading @@ -212,8 +212,7 @@ namespace netplus { ccon->csock = std::make_unique<tcp>(-1); else if (_ServerSocket->_Type == sockettype::SSL) { ssl* srv = static_cast<ssl*>(_ServerSocket); // ✅ Pass the certificate bundle map (SNI will select appropriate cert per connection) ccon->csock = std::make_unique<ssl>(srv->_tls.cert_map, -1); ccon->csock = std::make_unique<ssl>(*srv->_tls.cert_map, -1); } else if (_ServerSocket->_Type == sockettype::QUIC) { // QUIC: Process ONE UDP datagram per epoll event. // The server socket uses level-triggered EPOLLIN, Loading src/socket.h +1 −0 Changes for src/socket.h: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -430,6 +430,7 @@ namespace netplus { const tls& getTls() const { return _tls; } private: ssl(std::shared_ptr<const std::map<std::string, CertificateBundle>> shared_certs); tls _tls; FramingCallback _framing_cb; std::atomic<bool> _pendingIocpWrite{false}; Loading src/ssl.cpp +16 −20 Changes for src/ssl.cpp: 16 added lines, 20 removed lines. Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <iostream> #include <cstring> #include <vector> Loading @@ -39,18 +38,18 @@ namespace netplus { // ============================================================================ ssl::ssl(const std::map<std::string, CertificateBundle>& certs) : tcp() { _tls.cert_map = certs; _tls.cert_map = std::make_shared<const std::map<std::string, CertificateBundle>>(certs); if (!certs.empty()) { _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&certs.begin()->second); _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&_tls.cert_map->begin()->second); } _tls.setSocket(this); _Type = sockettype::SSL; } ssl::ssl(const std::map<std::string, CertificateBundle>& certs, int sock) : tcp(sock) { _tls.cert_map = certs; _tls.cert_map = std::make_shared<const std::map<std::string, CertificateBundle>>(certs); if (!certs.empty()) { _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&certs.begin()->second); _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&_tls.cert_map->begin()->second); } _tls.setSocket(this); _Type = sockettype::SSL; Loading @@ -59,9 +58,18 @@ ssl::ssl(const std::map<std::string, CertificateBundle>& certs, int sock) : tcp( ssl::ssl(const std::map<std::string, CertificateBundle>& certs, const std::string& addr, int port, int maxconnections, int sockopts) : tcp(addr, port, maxconnections, sockopts) { _tls.cert_map = certs; _tls.cert_map = std::make_shared<const std::map<std::string, CertificateBundle>>(certs); if (!certs.empty()) { _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&certs.begin()->second); _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&_tls.cert_map->begin()->second); } _tls.setSocket(this); _Type = sockettype::SSL; } ssl::ssl(std::shared_ptr<const std::map<std::string, CertificateBundle>> shared_certs) : tcp() { _tls.cert_map = std::move(shared_certs); if (_tls.cert_map && !_tls.cert_map->empty()) { _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&_tls.cert_map->begin()->second); } _tls.setSocket(this); _Type = sockettype::SSL; Loading @@ -72,19 +80,11 @@ ssl::ssl(const std::map<std::string, CertificateBundle>& certs, // ============================================================================ void ssl::accept(std::unique_ptr<socket>& csock, bool nonblock) { // Create child SSL socket // Share cert_map with child — no deep copy auto cssock = std::make_unique<ssl>(_tls.cert_map); // Accept TCP connection tcp::accept(reinterpret_cast<std::unique_ptr<socket>&>(cssock), nonblock); // Set accepted socket to non-blocking mode for TLS processing // Copy certificate map and set socket reference cssock->_tls.cert_map = _tls.cert_map; if (!_tls.cert_map.empty()) { cssock->_tls.selected_cert_bundle = const_cast<CertificateBundle*>(&_tls.cert_map.begin()->second); } // Propagate ALPN select callback and framing callback to child socket cssock->_tls.alpn_select_cb = _tls.alpn_select_cb; cssock->_framing_cb = _framing_cb; Loading Loading @@ -165,10 +165,6 @@ void ssl::accept(LPFN_ACCEPTEX lpfnAcceptEx, std::unique_ptr<socket>& csock) { tcp::accept(lpfnAcceptEx, reinterpret_cast<std::unique_ptr<socket>&>(cssock)); cssock->_tls.cert_map = _tls.cert_map; if (!_tls.cert_map.empty()) { cssock->_tls.selected_cert_bundle = const_cast<CertificateBundle*>(&_tls.cert_map.begin()->second); } cssock->_tls.setSocket(cssock.get()); cssock->_Type = sockettype::SSL; Loading Loading
src/crypto/tls.cpp +6 −8 Changes for src/crypto/tls.cpp: 6 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -216,21 +216,19 @@ namespace netplus { std::string snihostname; if (extractSNIFromClientHello(ch, snihostname)) { requested_hostname = snihostname; // Suche das Zertifikat in der Map auto it = cert_map.find(snihostname); if (it != cert_map.end()) { if (cert_map) { auto it = cert_map->find(snihostname); if (it != cert_map->end()) { selected_cert_bundle = const_cast<CertificateBundle*>(&it->second); // ✅ Use bundle's cert directly - no need to copy to _cert SSL_LOG("[SNI] Selected cert for domain: " << snihostname); } else { SSL_LOG("[SNI] No cert found for domain: " << snihostname << ", using default"); // Fallback: Verwende das erste Zertifikat if (!cert_map.empty()) { selected_cert_bundle = const_cast<CertificateBundle*>(&cert_map.begin()->second); // ✅ Use bundle's cert directly if (!cert_map->empty()) { selected_cert_bundle = const_cast<CertificateBundle*>(&cert_map->begin()->second); SSL_LOG("[SNI] Switched to default cert"); } } } } else { SSL_LOG("[SNI] SNI extension not found in ClientHello, using default cert"); } Loading
src/crypto/tls.h +1 −1 Changes for src/crypto/tls.h: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -414,7 +414,7 @@ namespace netplus { uint16_t selected_group = 0; // Named group for key share // --- SNI (Server Name Indication) Support --- std::map<std::string, CertificateBundle> cert_map; std::shared_ptr<const std::map<std::string, CertificateBundle>> cert_map; std::string requested_hostname; CertificateBundle* selected_cert_bundle = nullptr; Loading
src/event/epoll.cpp +1 −2 Changes for src/event/epoll.cpp: 1 added line, 2 removed lines. Original line number Diff line number Diff line Loading @@ -212,8 +212,7 @@ namespace netplus { ccon->csock = std::make_unique<tcp>(-1); else if (_ServerSocket->_Type == sockettype::SSL) { ssl* srv = static_cast<ssl*>(_ServerSocket); // ✅ Pass the certificate bundle map (SNI will select appropriate cert per connection) ccon->csock = std::make_unique<ssl>(srv->_tls.cert_map, -1); ccon->csock = std::make_unique<ssl>(*srv->_tls.cert_map, -1); } else if (_ServerSocket->_Type == sockettype::QUIC) { // QUIC: Process ONE UDP datagram per epoll event. // The server socket uses level-triggered EPOLLIN, Loading
src/socket.h +1 −0 Changes for src/socket.h: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -430,6 +430,7 @@ namespace netplus { const tls& getTls() const { return _tls; } private: ssl(std::shared_ptr<const std::map<std::string, CertificateBundle>> shared_certs); tls _tls; FramingCallback _framing_cb; std::atomic<bool> _pendingIocpWrite{false}; Loading
src/ssl.cpp +16 −20 Changes for src/ssl.cpp: 16 added lines, 20 removed lines. Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <iostream> #include <cstring> #include <vector> Loading @@ -39,18 +38,18 @@ namespace netplus { // ============================================================================ ssl::ssl(const std::map<std::string, CertificateBundle>& certs) : tcp() { _tls.cert_map = certs; _tls.cert_map = std::make_shared<const std::map<std::string, CertificateBundle>>(certs); if (!certs.empty()) { _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&certs.begin()->second); _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&_tls.cert_map->begin()->second); } _tls.setSocket(this); _Type = sockettype::SSL; } ssl::ssl(const std::map<std::string, CertificateBundle>& certs, int sock) : tcp(sock) { _tls.cert_map = certs; _tls.cert_map = std::make_shared<const std::map<std::string, CertificateBundle>>(certs); if (!certs.empty()) { _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&certs.begin()->second); _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&_tls.cert_map->begin()->second); } _tls.setSocket(this); _Type = sockettype::SSL; Loading @@ -59,9 +58,18 @@ ssl::ssl(const std::map<std::string, CertificateBundle>& certs, int sock) : tcp( ssl::ssl(const std::map<std::string, CertificateBundle>& certs, const std::string& addr, int port, int maxconnections, int sockopts) : tcp(addr, port, maxconnections, sockopts) { _tls.cert_map = certs; _tls.cert_map = std::make_shared<const std::map<std::string, CertificateBundle>>(certs); if (!certs.empty()) { _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&certs.begin()->second); _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&_tls.cert_map->begin()->second); } _tls.setSocket(this); _Type = sockettype::SSL; } ssl::ssl(std::shared_ptr<const std::map<std::string, CertificateBundle>> shared_certs) : tcp() { _tls.cert_map = std::move(shared_certs); if (_tls.cert_map && !_tls.cert_map->empty()) { _tls.selected_cert_bundle = const_cast<CertificateBundle*>(&_tls.cert_map->begin()->second); } _tls.setSocket(this); _Type = sockettype::SSL; Loading @@ -72,19 +80,11 @@ ssl::ssl(const std::map<std::string, CertificateBundle>& certs, // ============================================================================ void ssl::accept(std::unique_ptr<socket>& csock, bool nonblock) { // Create child SSL socket // Share cert_map with child — no deep copy auto cssock = std::make_unique<ssl>(_tls.cert_map); // Accept TCP connection tcp::accept(reinterpret_cast<std::unique_ptr<socket>&>(cssock), nonblock); // Set accepted socket to non-blocking mode for TLS processing // Copy certificate map and set socket reference cssock->_tls.cert_map = _tls.cert_map; if (!_tls.cert_map.empty()) { cssock->_tls.selected_cert_bundle = const_cast<CertificateBundle*>(&_tls.cert_map.begin()->second); } // Propagate ALPN select callback and framing callback to child socket cssock->_tls.alpn_select_cb = _tls.alpn_select_cb; cssock->_framing_cb = _framing_cb; Loading Loading @@ -165,10 +165,6 @@ void ssl::accept(LPFN_ACCEPTEX lpfnAcceptEx, std::unique_ptr<socket>& csock) { tcp::accept(lpfnAcceptEx, reinterpret_cast<std::unique_ptr<socket>&>(cssock)); cssock->_tls.cert_map = _tls.cert_map; if (!_tls.cert_map.empty()) { cssock->_tls.selected_cert_bundle = const_cast<CertificateBundle*>(&_tls.cert_map.begin()->second); } cssock->_tls.setSocket(cssock.get()); cssock->_Type = sockettype::SSL; Loading