From 10059a1661dad4221795e56206bdfd87ac504db7 Mon Sep 17 00:00:00 2001 From: AssemblyJohn Date: Thu, 5 Dec 2024 13:50:25 +0200 Subject: [PATCH] Fixed logic error on connection initialization Signed-off-by: AssemblyJohn --- .../websocket/websocket_libwebsockets.cpp | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/ocpp/common/websocket/websocket_libwebsockets.cpp b/lib/ocpp/common/websocket/websocket_libwebsockets.cpp index 2e6378fed..9c38ca94b 100644 --- a/lib/ocpp/common/websocket/websocket_libwebsockets.cpp +++ b/lib/ocpp/common/websocket/websocket_libwebsockets.cpp @@ -179,7 +179,7 @@ struct ConnectionData { } } - void init_connection_context(lws_context* lws_ctx) { + void init_connection_context(lws_context* lws_ctx, SSL_CTX* ssl_ctx) { std::lock_guard lock(this->mutex); if (this->lws_ctx || this->sec_context) { @@ -188,16 +188,10 @@ struct ConnectionData { // Causes a deadlock in callback_minimal if not reset this->lws_ctx = std::unique_ptr(lws_ctx); - } - - void init_security_context(SSL_CTX* ssl_ctx) { - std::lock_guard lock(this->mutex); - if (this->lws_ctx || this->sec_context) { - EVLOG_AND_THROW(std::runtime_error("Cleanup must be called before re-initing a connection!")); + if (ssl_ctx) { + this->sec_context = std::unique_ptr(ssl_ctx); } - - this->sec_context = std::unique_ptr(ssl_ctx); } void init_connection(lws* lws) { @@ -611,6 +605,7 @@ bool WebsocketLibwebsockets::initialize_connection_options(std::shared_ptr private_key_password; + SSL_CTX* ssl_ctx = nullptr; if (this->connection_options.security_profile == 2 || this->connection_options.security_profile == 3) { // Setup context - need to know the key type first @@ -642,7 +637,6 @@ bool WebsocketLibwebsockets::initialize_connection_options(std::shared_ptrinit_security_context(ssl_ctx); } lws_context* lws_ctx = lws_create_context(&info); @@ -691,8 +682,8 @@ bool WebsocketLibwebsockets::initialize_connection_options(std::shared_ptrinit_connection_context(lws_ctx); + // Conn acquire the lws context and security context + local_data->init_connection_context(lws_ctx, ssl_ctx); return true; }