Füge Unterstützung für SSL/TLS in den WebSocket-Server hinzu. Aktualisiere die Konfigurationsdatei, um SSL-Optionen zu ermöglichen, und passe die WebSocketServer-Klasse an, um Zertifikat- und Schlüsselpfade zu akzeptieren. Verbessere die Serverstartlogik, um SSL korrekt zu initialisieren und entsprechende Meldungen auszugeben.
This commit is contained in:
committed by
Torsten (PC)
parent
92e17a9f43
commit
8212e906a3
@@ -18,8 +18,9 @@ struct lws_protocols WebSocketServer::protocols[] = {
|
||||
{ nullptr, nullptr, 0, 0 }
|
||||
};
|
||||
|
||||
WebSocketServer::WebSocketServer(int port, ConnectionPool &pool, MessageBroker &broker)
|
||||
: port(port), pool(pool), broker(broker) {}
|
||||
WebSocketServer::WebSocketServer(int port, ConnectionPool &pool, MessageBroker &broker,
|
||||
bool useSSL, const std::string& certPath, const std::string& keyPath)
|
||||
: port(port), pool(pool), broker(broker), useSSL(useSSL), certPath(certPath), keyPath(keyPath) {}
|
||||
|
||||
WebSocketServer::~WebSocketServer() {
|
||||
stop();
|
||||
@@ -57,8 +58,21 @@ void WebSocketServer::startServer() {
|
||||
info.port = port;
|
||||
info.protocols = protocols;
|
||||
|
||||
// SSL/TLS Konfiguration
|
||||
if (useSSL) {
|
||||
if (certPath.empty() || keyPath.empty()) {
|
||||
throw std::runtime_error("SSL enabled but certificate or key path not provided");
|
||||
}
|
||||
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||
info.ssl_cert_filepath = certPath.c_str();
|
||||
info.ssl_private_key_filepath = keyPath.c_str();
|
||||
std::cout << "WebSocket SSL Server starting on port " << port << " with certificates: "
|
||||
<< certPath << " / " << keyPath << std::endl;
|
||||
} else {
|
||||
std::cout << "WebSocket Server starting on port " << port << " (no SSL)" << std::endl;
|
||||
}
|
||||
|
||||
// Reduziere Log-Level um weniger Debug-Ausgaben zu haben
|
||||
// Setze Umgebungsvariable für Log-Level
|
||||
setenv("LWS_LOG_LEVEL", "0", 1); // 0 = nur Fehler
|
||||
|
||||
context = lws_create_context(&info);
|
||||
|
||||
Reference in New Issue
Block a user