diff --git a/common/include/dm_error_type.h b/common/include/dm_error_type.h index f731240cd1847039d6959f107418764e9b729c9d..753c754f23597329907bfd04f835913e3d8dc16c 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, - ERR_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/include/authentication_v2/dm_auth_state.h b/services/implementation/include/authentication_v2/dm_auth_state.h index d128017708d85f3cdcf2a5ad176b7ec7538f4967..8e948a6664f720607f6611b07713de1093c77010 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 c0a6e1a8ab08ce06129d46869b0ff71b9c4463f0..eff5dd6d6359f761c7fb0ccfa11facbb0a191aed 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) { @@ -278,13 +234,33 @@ 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()); } 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 == 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/auth_stages/auth_pin_auth.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_pin_auth.cpp index 0781403746899d115964b2c9e538f0f2022fde87..be3e377eac8a0cd5f067aafc25b6690c95b383b5 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 f9490cf3ca3ec2d9e45b886399b83d3fb882d7fd..9a0952c9cc4e44280e30b0020ce6c475e36674a6 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 }, + { 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 != DM_BIND_TRUST_TARGET) { // 根据凭据id 删除sink端多余的凭据 context->hiChainAuthConnector->DeleteCredential(context->accesser.userId, context->accesser.lnnCredentialId); @@ -806,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 diff --git a/services/implementation/src/authentication_v2/dm_negotiate_process.cpp b/services/implementation/src/authentication_v2/dm_negotiate_process.cpp index 1d0e5af647070204c3341df466a446acf01555a4..e6aa7a0e3c7949b183676a2de698b96a4f6aaf05 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)