From db54ceeee9afbc285ddd5413fe9a4c7f8c8958c8 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Thu, 19 Dec 2024 15:08:11 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=8E=92=E6=9F=A5dm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84hichain=E5=9B=9E=E8=B0=83=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../src/authentication/dm_auth_manager.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 18610d61c..81aeb72aa 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1312,6 +1312,10 @@ void DmAuthManager::AuthenticateFinish() if (timer_ != nullptr) { timer_->DeleteAll(); } + if (sessionKey_ != nullptr) { + delete[] sessionKey_; + sessionKey_ = nullptr; + } isFinishOfLocal_ = true; authResponseContext_ = nullptr; authMessageProcessor_ = nullptr; @@ -2114,7 +2118,14 @@ void DmAuthManager::AuthDeviceSessionKey(int64_t requestId, const uint8_t *sessi LOGE("DmAuthManager::onTransmit requestId %{public}" PRId64 "is error.", requestId); return; } - sessionKey_ = sessionKey; + if (sessionKey_ == nullptr) { + sessionKey_ = new uint64_t[sessionKeyLen + 1]; + } + + if (memcpy_s(sessionKey_, sessionKeyLen, sessionKey, sessionKeyLen) != DM_OK) { + LOGI("DmAuthManager::AuthDeviceSessionKey memcpy_s failed."); + return; + } sessionKeyLen_ = sessionKeyLen; } -- Gitee From 7200fb3d35f59d24264d2aa37557f4078f0fd18e Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 20 Dec 2024 17:37:45 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=8E=92=E6=9F=A5dm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84hichain=E5=9B=9E=E8=B0=83=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../src/authentication/dm_auth_manager.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 81aeb72aa..2a6a410f6 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -78,6 +78,7 @@ const int32_t AUTH_DEVICE_TIMEOUT = 10; const int32_t SESSION_HEARTBEAT_TIMEOUT = 50; const int32_t ALREADY_BIND = 1; const int32_t STRTOLL_BASE_10 = 10; +const int32_t DM_SESSION_KEY_LEN = 128; // clone task timeout map const std::map TASK_TIME_OUT_MAP = { @@ -2114,18 +2115,16 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) void DmAuthManager::AuthDeviceSessionKey(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen) { LOGI("DmAuthManager::AuthDeviceSessionKey start."); - if (requestId != authResponseContext_->requestId) { + if (requestId != authResponseContext_->requestId || sessionKeyLen > DM_SESSION_KEY_LEN) { LOGE("DmAuthManager::onTransmit requestId %{public}" PRId64 "is error.", requestId); return; } - if (sessionKey_ == nullptr) { - sessionKey_ = new uint64_t[sessionKeyLen + 1]; - } - - if (memcpy_s(sessionKey_, sessionKeyLen, sessionKey, sessionKeyLen) != DM_OK) { + uint8_t authsessionKey[] = new uint8_t[sessionKeyLen + 1]; + if (memcpy_s(authsessionKey, DM_SESSION_KEY_LEN, sessionKey, sessionKeyLen) != DM_OK) { LOGI("DmAuthManager::AuthDeviceSessionKey memcpy_s failed."); return; } + sessionKey_ = authsessionKey; sessionKeyLen_ = sessionKeyLen; } -- Gitee From a337d13ac14cb21c9de124721308141708bf94a4 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 20 Dec 2024 18:34:32 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=8E=92=E6=9F=A5dm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84hichain=E5=9B=9E=E8=B0=83=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../include/authentication/dm_auth_manager.h | 1 + .../src/authentication/dm_auth_manager.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 70c6dd645..b95a6bbc4 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -561,6 +561,7 @@ private: std::string importAuthCode_ = ""; PeerTargetId peerTargetId_; const uint8_t *sessionKey_ = nullptr; + uint8_t* authsessionKey_ = nullptr; uint32_t sessionKeyLen_ = 0; std::string remoteDeviceId_ = ""; std::string dmVersion_ = ""; diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 2a6a410f6..bee54de16 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1317,6 +1317,11 @@ void DmAuthManager::AuthenticateFinish() delete[] sessionKey_; sessionKey_ = nullptr; } + + if (authsessionKey_ != nullptr) { + delete[] authsessionKey_; + authsessionKey_ = nullptr; + } isFinishOfLocal_ = true; authResponseContext_ = nullptr; authMessageProcessor_ = nullptr; @@ -2119,12 +2124,12 @@ void DmAuthManager::AuthDeviceSessionKey(int64_t requestId, const uint8_t *sessi LOGE("DmAuthManager::onTransmit requestId %{public}" PRId64 "is error.", requestId); return; } - uint8_t authsessionKey[] = new uint8_t[sessionKeyLen + 1]; - if (memcpy_s(authsessionKey, DM_SESSION_KEY_LEN, sessionKey, sessionKeyLen) != DM_OK) { + authsessionKey_ = new uint8_t[DM_SESSION_KEY_LEN + 1]; + if (memcpy_s(authsessionKey, DM_SESSION_KEY_LEN + 1, sessionKey, sessionKeyLen) != DM_OK) { LOGI("DmAuthManager::AuthDeviceSessionKey memcpy_s failed."); return; } - sessionKey_ = authsessionKey; + sessionKey_ = authsessionKey_; sessionKeyLen_ = sessionKeyLen; } -- Gitee From 8a3137b69fda5c28e81b980bdb45fcaeb71a1d3f Mon Sep 17 00:00:00 2001 From: l60055366 Date: Sat, 21 Dec 2024 10:53:33 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=8E=92=E6=9F=A5dm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84hichain=E5=9B=9E=E8=B0=83=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- services/implementation/src/authentication/dm_auth_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index bee54de16..32a4af56a 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -2125,7 +2125,7 @@ void DmAuthManager::AuthDeviceSessionKey(int64_t requestId, const uint8_t *sessi return; } authsessionKey_ = new uint8_t[DM_SESSION_KEY_LEN + 1]; - if (memcpy_s(authsessionKey, DM_SESSION_KEY_LEN + 1, sessionKey, sessionKeyLen) != DM_OK) { + if (memcpy_s(authsessionKey_, DM_SESSION_KEY_LEN + 1, sessionKey, sessionKeyLen) != DM_OK) { LOGI("DmAuthManager::AuthDeviceSessionKey memcpy_s failed."); return; } -- Gitee