diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 70c6dd645dc2f9ab652cb9b9d8e92eb3df6c8341..b95a6bbc426339f09f883184ed29e572ee087812 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 18610d61cd3b926b9fa37b272636d3d2b38cb84b..32a4af56ae4b88d57d810049b0d9988bbc1557c5 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 = { @@ -1312,6 +1313,15 @@ void DmAuthManager::AuthenticateFinish() if (timer_ != nullptr) { timer_->DeleteAll(); } + if (sessionKey_ != nullptr) { + delete[] sessionKey_; + sessionKey_ = nullptr; + } + + if (authsessionKey_ != nullptr) { + delete[] authsessionKey_; + authsessionKey_ = nullptr; + } isFinishOfLocal_ = true; authResponseContext_ = nullptr; authMessageProcessor_ = nullptr; @@ -2110,11 +2120,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; } - sessionKey_ = sessionKey; + 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_; sessionKeyLen_ = sessionKeyLen; }