From 677bcbc985c3971d5ebb96fe571ba69ee0d3876f Mon Sep 17 00:00:00 2001 From: yangwei_814916 Date: Tue, 22 Apr 2025 12:05:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=8F=E5=90=8C?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E7=99=BD=E5=90=8D=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangwei_814916 --- .../authentication/auth_message_processor.cpp | 4 --- .../src/authentication/dm_auth_manager.cpp | 34 ++++++++++--------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index 44294f3b0..c6dd61e5c 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -634,8 +634,6 @@ void AuthMessageProcessor::ParseNegotiateMessage(const JsonObject &json) } if (IsString(json, TAG_ACCOUNT_GROUPID)) { authResponseContext_->accountGroupIdHash = json[TAG_ACCOUNT_GROUPID].Get(); - } else { - authResponseContext_->accountGroupIdHash = OLD_VERSION_ACCOUNT; } if (IsString(json, TAG_HOST)) { authResponseContext_->hostPkgName = json[TAG_HOST].Get(); @@ -673,8 +671,6 @@ void AuthMessageProcessor::ParseRespNegotiateMessage(const JsonObject &json) } if (IsString(json, TAG_ACCOUNT_GROUPID)) { authResponseContext_->accountGroupIdHash = json[TAG_ACCOUNT_GROUPID].Get(); - } else { - authResponseContext_->accountGroupIdHash = OLD_VERSION_ACCOUNT; } if (IsString(json, TAG_NET_ID)) { authResponseContext_->networkId = json[TAG_NET_ID].Get(); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 5660934f7..d5bd6f222 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -984,14 +984,17 @@ void DmAuthManager::AbilityNegotiate() authResponseContext_->remoteAccountId = authResponseContext_->localAccountId; authResponseContext_->remoteUserId = authResponseContext_->localUserId; GetBinderInfo(); - bool ret = hiChainConnector_->IsDevicesInP2PGroup(authResponseContext_->localDeviceId, localDeviceId); - if (ret) { + if (hiChainConnector_->IsDevicesInP2PGroup(authResponseContext_->localDeviceId, localDeviceId) != DM_OK) { LOGE("DmAuthManager::EstablishAuthChannel device is in group"); if (!DeviceProfileConnector::GetInstance().CheckSinkDevIdInAclForDevBind(authResponseContext_->hostPkgName, authResponseContext_->localDeviceId)) { CompatiblePutAcl(); } authResponseContext_->reply = ERR_DM_AUTH_PEER_REJECT; + if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_3)) && + authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && !importAuthCode_.empty()) { + authResponseContext_->importAuthCode = Crypto::Sha256(importAuthCode_); + } } else { authResponseContext_->reply = ERR_DM_AUTH_REJECT; } @@ -1970,10 +1973,6 @@ bool DmAuthManager::IsIdenticalAccount() LOGE("authResponseContext_ is nullptr."); return false; } - if (authResponseContext_->accountGroupIdHash == OLD_VERSION_ACCOUNT) { - LOGI("The old version."); - return true; - } JsonObject jsonPeerGroupIdObj(authResponseContext_->accountGroupIdHash); if (jsonPeerGroupIdObj.IsDiscarded()) { LOGE("accountGroupIdHash string not a json type."); @@ -2636,7 +2635,10 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) DeviceProfileConnector::GetInstance().GetBindTypeByPkgName(authResponseContext_->hostPkgName, authResponseContext_->localDeviceId, authResponseContext_->deviceId); authResponseContext_->authed = !authResponseContext_->bindType.empty(); - + if (authResponseContext_->authed && authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && + !importAuthCode_.empty() && !CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_3))) { + authResponseContext_->importAuthCode = Crypto::Sha256(importAuthCode_); + } authResponseContext_->isIdenticalAccount = false; if (authResponseContext_->localAccountId == authResponseContext_->remoteAccountId && authResponseContext_->localAccountId != "ohosAnonymousUid" && authResponseContext_->authed) { @@ -2682,6 +2684,12 @@ void DmAuthManager::ProcRespNegotiate(const int32_t &sessionId) softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); return; } + if (IsIdenticalAccount()) { + jsonObject[TAG_IDENTICAL_ACCOUNT] = true; + if (authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && !importAuthCode_.empty()) { + jsonObject[TAG_IMPORT_AUTH_CODE] = Crypto::Sha256(importAuthCode_); + } + } jsonObject[TAG_ACCOUNT_GROUPID] = GetAccountGroupIdHash(); authResponseContext_ = authResponseState_->GetAuthContext(); if (jsonObject[TAG_CRYPTO_SUPPORT].Get() == true && authResponseContext_->cryptoSupport) { @@ -2870,12 +2878,9 @@ void DmAuthManager::HandleSessionHeartbeat(std::string name) int32_t DmAuthManager::CheckTrustState() { - bool isSameGroup = false; - if (authResponseContext_->reply == ERR_DM_AUTH_PEER_REJECT && + bool isSameGroup = (authResponseContext_->reply == ERR_DM_AUTH_PEER_REJECT && hiChainConnector_->IsDevicesInP2PGroup(authResponseContext_->localDeviceId, - authRequestContext_->localDeviceId)) { - isSameGroup = true; - } + authRequestContext_->localDeviceId)); if (isSameGroup && authResponseContext_->isOnline && authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE) { authResponseContext_->isFinish = true; SetReasonAndFinish(DM_OK, AuthState::AUTH_REQUEST_FINISH); @@ -3098,12 +3103,9 @@ int32_t DmAuthManager::GetBinderInfo() } ret = AppManager::GetInstance().GetHapTokenIdByName(authResponseContext_->localUserId, authResponseContext_->peerBundleName, 0, authResponseContext_->tokenId); -#ifndef DEVICE_MANAGER_COMMON_FLAG - if (ret == DM_OK && static_cast(authResponseContext_->bindLevel) != APP) { + if (ret == DM_OK) { LOGI("get tokenId by bundleName failed %{public}s", GetAnonyString(authResponseContext_->bundleName).c_str()); - return ERR_DM_FAILED; } -#endif return ret; } -- Gitee From 4df0c6ee61e6fc34b1c4dcb48440876e0d5d6792 Mon Sep 17 00:00:00 2001 From: yangwei_814916 Date: Tue, 22 Apr 2025 12:07:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=8F=E5=90=8C?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E7=99=BD=E5=90=8D=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangwei_814916 --- .../implementation/src/authentication/dm_auth_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index d5bd6f222..04af5ce3e 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -3103,8 +3103,8 @@ int32_t DmAuthManager::GetBinderInfo() } ret = AppManager::GetInstance().GetHapTokenIdByName(authResponseContext_->localUserId, authResponseContext_->peerBundleName, 0, authResponseContext_->tokenId); - if (ret == DM_OK) { - LOGI("get tokenId by bundleName failed %{public}s", GetAnonyString(authResponseContext_->bundleName).c_str()); + if (ret != DM_OK) { + LOGE("get tokenId by bundleName failed %{public}s", GetAnonyString(authResponseContext_->bundleName).c_str()); } return ret; } -- Gitee