From 2b53386fbcc6b5cb3d30e1ddc5f35afb82c709de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Thu, 3 Jul 2025 16:30:41 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../auth_stages/auth_acl.cpp | 20 +++++++++++++++++++ .../src/authentication_v2/dm_auth_state.cpp | 6 ++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp index c0a6e1a8a..bff62e063 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp @@ -285,6 +285,26 @@ int32_t AuthSrcFinishState::Action(std::shared_ptr context) } context->isNeedJoinLnn = true; SourceFinish(context); + std::string peerDeviceId = ""; + GetPeerDeviceId(context, peerDeviceId); + bool isNeedJoinLnn = context->softbusConnector->CheckIsNeedJoinLnn(peerDeviceId, context->accessee.addr); + // Trigger networking + if (context->reason = ERR_DM_BIND_TRUST_TARGET && (!context->accesser.isOnline || isNeedJoinLnn)) { + if (context->connSessionType == CONN_SESSION_TYPE_HML) { + context->softbusConnector->JoinLnnByHml(context->sessionId, context->accesser.transmitSessionKeyId, + context->accessee.transmitSessionKeyId); + } else { + char udidHashTmp[DM_MAX_DEVICE_ID_LEN] = {0}; + if (Crypto::GetUdidHash(context->accessee.deviceId, reinterpret_cast(udidHashTmp)) != DM_OK) { + LOGE("AuthSrcDataSyncState joinLnn get udidhash by udid: %{public}s failed", + GetAnonyString(context->accessee.deviceId).c_str()); + return ERR_DM_FAILED; + } + std::string peerUdidHash = std::string(udidHashTmp); + context->softbusConnector->JoinLNNBySkId(context->sessionId, context->accesser.transmitSessionKeyId, + context->accessee.transmitSessionKeyId, context->accessee.addr, peerUdidHash); + } + } LOGI("AuthSrcFinishState::Action ok"); std::shared_ptr tempContext = context; auto taskFunc = [this, tempContext]() { diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index f9490cf3c..eb0cdd712 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -75,7 +75,8 @@ const std::map NEW_AND_OLD_STATE_MAPPING = { const std::map NEW_AND_OLD_REPLAY_MAPPING = { { DM_ALREADY_AUTHED, SOFTBUS_OK }, - { SOFTBUS_OK, SOFTBUS_OK } + { SOFTBUS_OK, SOFTBUS_OK }, + { ERR_DM_BIND_TRUST_TARGET, DM_OK } }; int32_t DmAuthState::GetTaskTimeout(std::shared_ptr context, const char* taskName, int32_t taskTimeOut) @@ -119,7 +120,8 @@ void DmAuthState::SourceFinish(std::shared_ptr context) GetOutputState(context->state), GenerateBindResultContent(context)); context->successFinished = true; - if (context->reason != DM_OK && context->reason != DM_ALREADY_AUTHED && context->reUseCreId.empty()) { + if (context->reason != DM_OK && context->reason != DM_ALREADY_AUTHED && context->reUseCreId.empty() && + context->reason != ERR_DM_BIND_TRUST_TARGET) { // 根据凭据id 删除sink端多余的凭据 context->hiChainAuthConnector->DeleteCredential(context->accesser.userId, context->accesser.lnnCredentialId); -- Gitee From 9c9618d3714300b51704df94d3396d5a351650b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Thu, 3 Jul 2025 16:50:22 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- common/include/dm_error_type.h | 2 +- .../src/authentication_v2/auth_stages/auth_acl.cpp | 2 +- .../src/authentication_v2/auth_stages/auth_pin_auth.cpp | 2 +- .../implementation/src/authentication_v2/dm_auth_state.cpp | 4 ++-- .../src/authentication_v2/dm_negotiate_process.cpp | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/include/dm_error_type.h b/common/include/dm_error_type.h index f731240cd..2825c666f 100644 --- a/common/include/dm_error_type.h +++ b/common/include/dm_error_type.h @@ -129,7 +129,7 @@ enum { ERR_DM_SESSION_CLOSED = 96929840, ERR_DM_GET_LOCAL_USERID_FAILED = 969298341, ERR_DM_CAPABILITY_NEGOTIATE_FAILED = 969298342, - ERR_DM_BIND_TRUST_TARGET = 969298343, + DM_BIND_TRUST_TARGET = 969298343, ERR_DM_BINDTARGET_SCREEN_LOCK = 969298344, ERR_DM_NO_REPLAY = 969298345, ERR_DM_GET_TOKENID_FAILED = 969298346, diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp index bff62e063..a9f68d548 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp @@ -289,7 +289,7 @@ int32_t AuthSrcFinishState::Action(std::shared_ptr context) GetPeerDeviceId(context, peerDeviceId); bool isNeedJoinLnn = context->softbusConnector->CheckIsNeedJoinLnn(peerDeviceId, context->accessee.addr); // Trigger networking - if (context->reason = ERR_DM_BIND_TRUST_TARGET && (!context->accesser.isOnline || isNeedJoinLnn)) { + if (context->reason = DM_BIND_TRUST_TARGET && (!context->accesser.isOnline || isNeedJoinLnn)) { if (context->connSessionType == CONN_SESSION_TYPE_HML) { context->softbusConnector->JoinLnnByHml(context->sessionId, context->accesser.transmitSessionKeyId, context->accessee.transmitSessionKeyId); diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_pin_auth.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_pin_auth.cpp index 078140374..be3e377ea 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_pin_auth.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_pin_auth.cpp @@ -403,7 +403,7 @@ int32_t AuthSrcPinNegotiateStartState::Action(std::shared_ptr con return ProcessPinBind(context); } if (!IsNeedBind(context) && !IsNeedAgreeCredential(context) && !IsNeedAuth(context)) { - context->reason = ERR_DM_BIND_TRUST_TARGET; + context->reason = DM_BIND_TRUST_TARGET; context->authStateMachine->TransitionTo(std::make_shared()); return DM_OK; } diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index eb0cdd712..1593e5a5a 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -76,7 +76,7 @@ const std::map NEW_AND_OLD_STATE_MAPPING = { const std::map NEW_AND_OLD_REPLAY_MAPPING = { { DM_ALREADY_AUTHED, SOFTBUS_OK }, { SOFTBUS_OK, SOFTBUS_OK }, - { ERR_DM_BIND_TRUST_TARGET, DM_OK } + { DM_BIND_TRUST_TARGET, DM_OK } }; int32_t DmAuthState::GetTaskTimeout(std::shared_ptr context, const char* taskName, int32_t taskTimeOut) @@ -121,7 +121,7 @@ void DmAuthState::SourceFinish(std::shared_ptr context) context->successFinished = true; if (context->reason != DM_OK && context->reason != DM_ALREADY_AUTHED && context->reUseCreId.empty() && - context->reason != ERR_DM_BIND_TRUST_TARGET) { + context->reason != DM_BIND_TRUST_TARGET) { // 根据凭据id 删除sink端多余的凭据 context->hiChainAuthConnector->DeleteCredential(context->accesser.userId, context->accesser.lnnCredentialId); diff --git a/services/implementation/src/authentication_v2/dm_negotiate_process.cpp b/services/implementation/src/authentication_v2/dm_negotiate_process.cpp index 1d0e5af64..e6aa7a0e3 100644 --- a/services/implementation/src/authentication_v2/dm_negotiate_process.cpp +++ b/services/implementation/src/authentication_v2/dm_negotiate_process.cpp @@ -34,8 +34,8 @@ int32_t EndBind(std::shared_ptr context) context->needBind = false; context->needAgreeCredential = false; context->needAuth = false; - context->reason = ERR_DM_BIND_TRUST_TARGET; - return ERR_DM_BIND_TRUST_TARGET; + context->reason = DM_BIND_TRUST_TARGET; + return DM_BIND_TRUST_TARGET; } int32_t OnlyCredAuth(std::shared_ptr context) -- Gitee From 29f5adb5b3042aa1ed3e45ae6d976dc3fd25d078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Thu, 3 Jul 2025 17:44:51 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../include/authentication_v2/dm_auth_state.h | 2 +- .../auth_stages/auth_acl.cpp | 46 +------------------ .../src/authentication_v2/dm_auth_state.cpp | 44 ++++++++++++++++++ 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/services/implementation/include/authentication_v2/dm_auth_state.h b/services/implementation/include/authentication_v2/dm_auth_state.h index d12801770..8e948a666 100644 --- a/services/implementation/include/authentication_v2/dm_auth_state.h +++ b/services/implementation/include/authentication_v2/dm_auth_state.h @@ -174,6 +174,7 @@ public: const JsonItemObject &credInfo); static void DeleteAclAndSk(std::shared_ptr context, const DistributedDeviceProfile::AccessControlProfile &profile); + void GetPeerDeviceId(std::shared_ptr context, std::string &peerDeviceId); protected: bool NeedReqUserConfirm(std::shared_ptr context); bool NeedAgreeAcl(std::shared_ptr context); @@ -538,7 +539,6 @@ public: virtual ~AuthSrcDataSyncState() {}; DmAuthStateType GetStateType() override; int32_t Action(std::shared_ptr context) override; - void GetPeerDeviceId(std::shared_ptr context, std::string &peerDeviceId); }; class AuthSinkFinishState : public DmAuthState { diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp index a9f68d548..c1ca9ec0e 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp @@ -200,50 +200,6 @@ DmAuthStateType AuthSrcDataSyncState::GetStateType() return DmAuthStateType::AUTH_SRC_DATA_SYNC_STATE; } -void AuthSrcDataSyncState::GetPeerDeviceId(std::shared_ptr context, std::string &peerDeviceId) -{ - CHECK_NULL_VOID(context); - if (context->accesser.aclProfiles.find(DM_IDENTICAL_ACCOUNT) != context->accesser.aclProfiles.end()) { - peerDeviceId = context->accesser.aclProfiles[DM_IDENTICAL_ACCOUNT].GetAccessee().GetAccesseeDeviceId(); - if (!peerDeviceId.empty()) { - return; - } - } - if (context->accesser.aclProfiles.find(DM_SHARE) != context->accesser.aclProfiles.end()) { - peerDeviceId = context->accesser.aclProfiles[DM_SHARE].GetAccessee().GetAccesseeDeviceId(); - if (peerDeviceId == context->accesser.deviceId) { - peerDeviceId = context->accesser.aclProfiles[DM_SHARE].GetAccesser().GetAccesserDeviceId(); - } - if (!peerDeviceId.empty()) { - return; - } - } - if (context->accesser.aclProfiles.find(DM_POINT_TO_POINT) != context->accesser.aclProfiles.end()) { - peerDeviceId = context->accesser.aclProfiles[DM_POINT_TO_POINT].GetAccessee().GetAccesseeDeviceId(); - if (peerDeviceId == context->accesser.deviceId) { - peerDeviceId = context->accesser.aclProfiles[DM_POINT_TO_POINT].GetAccesser().GetAccesserDeviceId(); - } - if (!peerDeviceId.empty()) { - return; - } - } - if (!context->IsProxyBind || context->subjectProxyOnes.empty()) { - return; - } - for (auto &app : context->subjectProxyOnes) { - if (app.proxyAccesser.aclProfiles.find(DM_POINT_TO_POINT) != app.proxyAccesser.aclProfiles.end()) { - peerDeviceId = app.proxyAccesser.aclProfiles[DM_POINT_TO_POINT].GetAccessee().GetAccesseeDeviceId(); - if (peerDeviceId == context->accesser.deviceId) { - peerDeviceId = app.proxyAccesser.aclProfiles[DM_POINT_TO_POINT].GetAccesser().GetAccesserDeviceId(); - } - if (!peerDeviceId.empty()) { - return; - } - } - } - LOGE("failed"); -} - // Received 200 end message, send 201 int32_t AuthSinkFinishState::Action(std::shared_ptr context) { @@ -289,7 +245,7 @@ int32_t AuthSrcFinishState::Action(std::shared_ptr context) GetPeerDeviceId(context, peerDeviceId); bool isNeedJoinLnn = context->softbusConnector->CheckIsNeedJoinLnn(peerDeviceId, context->accessee.addr); // Trigger networking - if (context->reason = DM_BIND_TRUST_TARGET && (!context->accesser.isOnline || isNeedJoinLnn)) { + if (context->reason == DM_BIND_TRUST_TARGET && (!context->accesser.isOnline || isNeedJoinLnn)) { if (context->connSessionType == CONN_SESSION_TYPE_HML) { context->softbusConnector->JoinLnnByHml(context->sessionId, context->accesser.transmitSessionKeyId, context->accessee.transmitSessionKeyId); diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index 1593e5a5a..9a0952c9c 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -808,5 +808,49 @@ void DmAuthState::DeleteAclAndSk(std::shared_ptr context, context->authMessageProcessor->DeleteSessionKeyToDP(userId, sessionKeyId); DeviceProfileConnector::GetInstance().DeleteAccessControlById(profile.GetAccessControlId()); } + +void DmAuthState::GetPeerDeviceId(std::shared_ptr context, std::string &peerDeviceId) +{ + CHECK_NULL_VOID(context); + if (context->accesser.aclProfiles.find(DM_IDENTICAL_ACCOUNT) != context->accesser.aclProfiles.end()) { + peerDeviceId = context->accesser.aclProfiles[DM_IDENTICAL_ACCOUNT].GetAccessee().GetAccesseeDeviceId(); + if (!peerDeviceId.empty()) { + return; + } + } + if (context->accesser.aclProfiles.find(DM_SHARE) != context->accesser.aclProfiles.end()) { + peerDeviceId = context->accesser.aclProfiles[DM_SHARE].GetAccessee().GetAccesseeDeviceId(); + if (peerDeviceId == context->accesser.deviceId) { + peerDeviceId = context->accesser.aclProfiles[DM_SHARE].GetAccesser().GetAccesserDeviceId(); + } + if (!peerDeviceId.empty()) { + return; + } + } + if (context->accesser.aclProfiles.find(DM_POINT_TO_POINT) != context->accesser.aclProfiles.end()) { + peerDeviceId = context->accesser.aclProfiles[DM_POINT_TO_POINT].GetAccessee().GetAccesseeDeviceId(); + if (peerDeviceId == context->accesser.deviceId) { + peerDeviceId = context->accesser.aclProfiles[DM_POINT_TO_POINT].GetAccesser().GetAccesserDeviceId(); + } + if (!peerDeviceId.empty()) { + return; + } + } + if (!context->IsProxyBind || context->subjectProxyOnes.empty()) { + return; + } + for (auto &app : context->subjectProxyOnes) { + if (app.proxyAccesser.aclProfiles.find(DM_POINT_TO_POINT) != app.proxyAccesser.aclProfiles.end()) { + peerDeviceId = app.proxyAccesser.aclProfiles[DM_POINT_TO_POINT].GetAccessee().GetAccesseeDeviceId(); + if (peerDeviceId == context->accesser.deviceId) { + peerDeviceId = app.proxyAccesser.aclProfiles[DM_POINT_TO_POINT].GetAccesser().GetAccesserDeviceId(); + } + if (!peerDeviceId.empty()) { + return; + } + } + } + LOGE("failed"); +} } // namespace DistributedHardware } // namespace OHOS -- Gitee From 01dd8653e1b17211767918a0bf92c9754082a264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Fri, 4 Jul 2025 09:23:47 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- common/include/dm_error_type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/include/dm_error_type.h b/common/include/dm_error_type.h index 2825c666f..753c754f2 100644 --- a/common/include/dm_error_type.h +++ b/common/include/dm_error_type.h @@ -23,6 +23,7 @@ enum { SOFTBUS_OK = 0, STOP_BIND = 1, DM_ALREADY_AUTHED = 2, + DM_BIND_TRUST_TARGET = 969298343, /* Transfer to the other end device, not define specification error code */ ERR_DM_NOT_SYSTEM_APP = 202, ERR_DM_TIME_OUT = -20001, @@ -129,7 +130,6 @@ enum { ERR_DM_SESSION_CLOSED = 96929840, ERR_DM_GET_LOCAL_USERID_FAILED = 969298341, ERR_DM_CAPABILITY_NEGOTIATE_FAILED = 969298342, - DM_BIND_TRUST_TARGET = 969298343, ERR_DM_BINDTARGET_SCREEN_LOCK = 969298344, ERR_DM_NO_REPLAY = 969298345, ERR_DM_GET_TOKENID_FAILED = 969298346, -- Gitee From 16a91f9295621f5880fc15d2c91d0c3cf2a5e0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Fri, 4 Jul 2025 10:21:25 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../src/authentication_v2/auth_stages/auth_acl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp index c1ca9ec0e..eff5dd6d6 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp @@ -234,7 +234,7 @@ DmAuthStateType AuthSinkFinishState::GetStateType() int32_t AuthSrcFinishState::Action(std::shared_ptr context) { LOGI("AuthSrcFinishState::Action start"); - if (context->reason != DM_OK) { + if (context->reason != DM_OK && context->reason != DM_BIND_TRUST_TARGET) { context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_AUTH_REQ_FINISH, context); } else { context->state = static_cast(GetStateType()); -- Gitee