From dc8f7e21f38bca78b76ba9d64d1e3ae20eb14285 Mon Sep 17 00:00:00 2001 From: jxw Date: Wed, 9 Jul 2025 13:37:32 +0000 Subject: [PATCH 1/3] update frameworks/js/napi/websocket/async_context/include/connect_context.h. Signed-off-by: jxw --- .../js/napi/websocket/async_context/include/connect_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/js/napi/websocket/async_context/include/connect_context.h b/frameworks/js/napi/websocket/async_context/include/connect_context.h index f6f77da9e..4614fd5b2 100755 --- a/frameworks/js/napi/websocket/async_context/include/connect_context.h +++ b/frameworks/js/napi/websocket/async_context/include/connect_context.h @@ -75,7 +75,7 @@ public: std::string clientCert_; - bool skipServerCertVerification_; + bool skipServerCertVerification_ = false; Secure::SecureChar clientKey_; -- Gitee From ee71ca9a36af539bf770f6f35f003c3bfefd555e Mon Sep 17 00:00:00 2001 From: jxw Date: Wed, 9 Jul 2025 13:39:04 +0000 Subject: [PATCH 2/3] update frameworks/js/napi/websocket/websocket_exec/src/websocket_exec.cpp. Signed-off-by: jxw --- .../websocket_exec/src/websocket_exec.cpp | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/frameworks/js/napi/websocket/websocket_exec/src/websocket_exec.cpp b/frameworks/js/napi/websocket/websocket_exec/src/websocket_exec.cpp index 959ee7b21..d8707298b 100644 --- a/frameworks/js/napi/websocket/websocket_exec/src/websocket_exec.cpp +++ b/frameworks/js/napi/websocket/websocket_exec/src/websocket_exec.cpp @@ -526,6 +526,18 @@ void WebSocketExec::FillContextInfo(ConnectContext *context, lws_context_creatio } } +static bool WebSocketConnect(lws_client_connect_info &connectInfo, const std::shared_ptr &manager, + ConnectContext *context) +{ + if (lws_client_connect_via_info(&connectInfo) == nullptr) { + NETSTACK_LOGI("ExecConnect websocket connect failed"); + context->SetErrorCode(-1); + OnConnectError(manager.get(), COMMON_ERROR_CODE, 0); + return false; + } + return true; +} + bool WebSocketExec::CreatConnectInfo(ConnectContext *context, lws_context *lwsContext, const std::shared_ptr &manager) { @@ -549,30 +561,31 @@ bool WebSocketExec::CreatConnectInfo(ConnectContext *context, lws_context *lwsCo if (strcpy_s(customizedProtocol, context->GetProtocol().length() + 1, context->GetProtocol().c_str()) != EOK) { NETSTACK_LOGE("memory copy failed"); } - + connectInfo.context = lwsContext; connectInfo.port = port; connectInfo.address = address.c_str(); + if (std::strlen(path.c_str()) != path.length()) { + NETSTACK_LOGE("c_str() length does not match path length."); + return false; + } connectInfo.path = path.c_str(); connectInfo.host = tempHost.c_str(); connectInfo.origin = address.c_str(); connectInfo.protocol = customizedProtocol; - + if (protocol == PREFIX_HTTPS || protocol == PREFIX_WSS) { connectInfo.ssl_connection = LCCSCF_USE_SSL | LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK | LCCSCF_ALLOW_SELFSIGNED; } if (context->skipServerCertVerification_) { NETSTACK_LOGI("ExecConnect skip server cert verify"); - connectInfo.ssl_connection |= LCCSCF_ALLOW_INSECURE; + connectInfo.ssl_connection = ((unsigned int)connectInfo.ssl_connection) | LCCSCF_ALLOW_INSECURE; } lws *wsi = nullptr; connectInfo.pwsi = &wsi; connectInfo.retry_and_idle_policy = &RETRY; connectInfo.userdata = manager.get(); - if (lws_client_connect_via_info(&connectInfo) == nullptr) { - NETSTACK_LOGI("ExecConnect websocket connect failed"); - context->SetErrorCode(-1); - OnConnectError(manager.get(), COMMON_ERROR_CODE, 0); + if (!WebSocketConnect(connectInfo, manager, context)) { return false; } return true; -- Gitee From 387b96e26ba8a068a96d63979de1a3502ab7b8ca Mon Sep 17 00:00:00 2001 From: jxw Date: Wed, 9 Jul 2025 13:40:57 +0000 Subject: [PATCH 3/3] update frameworks/js/napi/websocket/websocket_module/src/websocket_client.cpp. Signed-off-by: jxw --- .../napi/websocket/websocket_module/src/websocket_client.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frameworks/js/napi/websocket/websocket_module/src/websocket_client.cpp b/frameworks/js/napi/websocket/websocket_module/src/websocket_client.cpp index 53276d5f1..91eee44cb 100644 --- a/frameworks/js/napi/websocket/websocket_module/src/websocket_client.cpp +++ b/frameworks/js/napi/websocket/websocket_module/src/websocket_client.cpp @@ -405,6 +405,10 @@ int CreatConnectInfo(const std::string url, lws_context *lwsContext, WebSocketCl connectInfo.context = lwsContext; connectInfo.address = address; connectInfo.port = port; + if (std::strlen(path.c_str()) != path.length()) { + NETSTACK_LOGE("c_str() length does not match path length."); + return -1; + } connectInfo.path = path.c_str(); connectInfo.host = tempHost.c_str(); connectInfo.origin = address; -- Gitee