diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 64533caa197df44e02c1f3721e24f21699ffb3fb..c76a26e5f0fe7ebe3898bb86f744b6aa3c75aeb6 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -90,6 +90,7 @@ typedef struct DmOfflineParam { uint32_t bindType; std::vector processVec; int32_t leftAclNumber; + int32_t peerUserId; } DmOfflineParam; namespace OHOS { @@ -146,7 +147,7 @@ public: const std::string &deviceId); EXPORT bool CheckSinkDevIdInAclForDevBind(const std::string &pkgName, const std::string &deviceId); - EXPORT uint32_t DeleteTimeOutAcl(const std::string &deviceId); + EXPORT uint32_t DeleteTimeOutAcl(const std::string &deviceId, int32_t peerUserId); EXPORT int32_t GetTrustNumber(const std::string &deviceId); bool CheckDevIdInAclForDevBind(const std::string &pkgName, const std::string &deviceId); std::vector CompareBindType(std::vector profiles, @@ -166,9 +167,9 @@ public: const std::string &remoteUdid, const std::string &localUdid); EXPORT int32_t HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, const std::string &localUdid); - EXPORT OHOS::DistributedHardware::ProcessInfo HandleAppUnBindEvent( + EXPORT DmOfflineParam HandleAppUnBindEvent( int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid); - EXPORT OHOS::DistributedHardware::ProcessInfo HandleAppUnBindEvent( + EXPORT DmOfflineParam HandleAppUnBindEvent( int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid, int32_t peerTokenId); EXPORT std::vector @@ -183,8 +184,7 @@ public: const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); EXPORT void HandleUserSwitched( const std::vector &activeProfiles, - const std::vector &inActiveProfiles, - const std::vector &delActiveProfiles); + const std::vector &inActiveProfiles); EXPORT void HandleSyncForegroundUserIdEvent( const std::vector &remoteUserIds, const std::string &remoteUdid, const std::vector &localUserIds, std::string &localUdid); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 1146f3e8eae80b9674f554360edbf98d69a111f9..676ffae9860d01a8e5757aa276ac3617586724ae 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -662,6 +662,7 @@ void DeviceProfileConnector::DeleteAppBindLevel(DmOfflineParam &offlineParam, co processInfo.pkgName = item.GetAccesser().GetAccesserBundleName(); processInfo.userId = item.GetAccesser().GetAccesserUserId(); offlineParam.processVec.push_back(processInfo); + offlineParam.peerUserId = item.GetAccessee().GetAccesseeUserId(); LOGI("Src delete acl pkgName %{public}s, bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s", pkgName.c_str(), item.GetBindType(), GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str()); @@ -677,6 +678,7 @@ void DeviceProfileConnector::DeleteAppBindLevel(DmOfflineParam &offlineParam, co processInfo.pkgName = item.GetAccessee().GetAccesseeBundleName(); processInfo.userId = item.GetAccessee().GetAccesseeUserId(); offlineParam.processVec.push_back(processInfo); + offlineParam.peerUserId = item.GetAccesser().GetAccesserUserId(); LOGI("Sink delete acl pkgName %{public}s, bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s", pkgName.c_str(), item.GetBindType(), GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str()); @@ -711,6 +713,7 @@ void DeviceProfileConnector::DeleteAppBindLevel(DmOfflineParam &offlineParam, co processInfo.pkgName = item.GetAccesser().GetAccesserBundleName(); processInfo.userId = item.GetAccesser().GetAccesserUserId(); offlineParam.processVec.push_back(processInfo); + offlineParam.peerUserId = item.GetAccessee().GetAccesseeUserId(); LOGI("Src delete acl pkgName %{public}s, bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s", pkgName.c_str(), item.GetBindType(), GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str()); @@ -727,6 +730,7 @@ void DeviceProfileConnector::DeleteAppBindLevel(DmOfflineParam &offlineParam, co processInfo.pkgName = item.GetAccessee().GetAccesseeBundleName(); processInfo.userId = item.GetAccessee().GetAccesseeUserId(); offlineParam.processVec.push_back(processInfo); + offlineParam.peerUserId = item.GetAccesser().GetAccesserUserId(); LOGI("Sink delete acl pkgName %{public}s, bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s", pkgName.c_str(), item.GetBindType(), GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str()); @@ -865,11 +869,15 @@ bool DeviceProfileConnector::CheckDevIdInAclForDevBind(const std::string &pkgNam return (CheckSinkDevIdInAclForDevBind(pkgName, deviceId) || CheckSrcDevIdInAclForDevBind(pkgName, deviceId)); } -EXPORT uint32_t DeviceProfileConnector::DeleteTimeOutAcl(const std::string &deviceId) +EXPORT uint32_t DeviceProfileConnector::DeleteTimeOutAcl(const std::string &deviceId, int32_t &peerUserId) { std::vector profiles = GetAccessControlProfile(); LOGI("AccessControlProfile size is %{public}zu", profiles.size()); uint32_t res = 0; + int32_t currentUserId = MultipleUserConnector::GetCurrentAccountUserID(); + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + std::string localUdid = std::string(localDeviceId); for (auto &item : profiles) { if (item.GetTrustDeviceId() != deviceId || item.GetStatus() != ACTIVE) { continue; @@ -878,6 +886,16 @@ EXPORT uint32_t DeviceProfileConnector::DeleteTimeOutAcl(const std::string &devi if (item.GetAuthenticationType() == ALLOW_AUTH_ONCE) { res--; DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); + if (item.GetAccesser().GetAccesserUserId() == currentUserId && + item.GetAccesser().GetAccesserDeviceId() == localUdid && + item.GetAccessee().GetAccesseeDeviceId() == deviceId) { + peerUserId = item.GetAccessee().GetAccesseeUserId(); + } + if (item.GetAccessee().GetAccesseeUserId() == currentUserId && + item.GetAccessee().GetAccesseeDeviceId() == localUdid && + item.GetAccesser().GetAccesserDeviceId() == deviceId) { + peerUserId = item.GetAccesser().GetAccesserUserId(); + } } } return res; @@ -1225,26 +1243,33 @@ EXPORT int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUserId return bindType; } -EXPORT OHOS::DistributedHardware::ProcessInfo DeviceProfileConnector::HandleAppUnBindEvent( +EXPORT DmOfflineParam DeviceProfileConnector::HandleAppUnBindEvent( int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid) { LOGI("RemoteUserId %{public}d, remoteUdid %{public}s, tokenId %{public}d, localUdid %{public}s.", remoteUserId, GetAnonyString(remoteUdid).c_str(), tokenId, GetAnonyString(localUdid).c_str()); std::vector profiles = GetAccessControlProfile(); - ProcessInfo processInfo; + DmOfflineParam offlineParam; + int32_t bindNums = 0; + int32_t deleteNums = 0; for (const auto &item : profiles) { if (item.GetTrustDeviceId() != remoteUdid || item.GetBindType() == DM_IDENTICAL_ACCOUNT || item.GetBindLevel() != APP) { continue; } + bindNums++; if (item.GetAccesser().GetAccesserUserId() == remoteUserId && item.GetAccesser().GetAccesserDeviceId() == remoteUdid && static_cast(item.GetAccesser().GetAccesserTokenId()) == tokenId && item.GetAccessee().GetAccesseeDeviceId() == localUdid) { LOGI("Src device unbind."); DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); + deleteNums++; + offlineParam.bindType = APP; + ProcessInfo processInfo; processInfo.pkgName = item.GetAccessee().GetAccesseeBundleName(); processInfo.userId = item.GetAccessee().GetAccesseeUserId(); + offlineParam.processVec.push_back(processInfo); continue; } if (item.GetAccessee().GetAccesseeUserId() == remoteUserId && @@ -1253,27 +1278,35 @@ EXPORT OHOS::DistributedHardware::ProcessInfo DeviceProfileConnector::HandleAppU item.GetAccesser().GetAccesserDeviceId() == localUdid) { LOGI("Sink device unbind."); DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); + deleteNums++; + offlineParam.bindType = APP; + ProcessInfo processInfo; processInfo.pkgName = item.GetAccesser().GetAccesserBundleName(); processInfo.userId = item.GetAccesser().GetAccesserUserId(); + offlineParam.processVec.push_back(processInfo); continue; } } - return processInfo; + offlineParam.leftAclNumber = bindNums - deleteNums; + return offlineParam; } -EXPORT OHOS::DistributedHardware::ProcessInfo DeviceProfileConnector::HandleAppUnBindEvent( +EXPORT DmOfflineParam DeviceProfileConnector::HandleAppUnBindEvent( int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid, int32_t peerTokenId) { LOGI("RemoteUserId %{public}d, remoteUdid %{public}s, tokenId %{public}d, localUdid %{public}s.", remoteUserId, GetAnonyString(remoteUdid).c_str(), tokenId, GetAnonyString(localUdid).c_str()); std::vector profiles = GetAccessControlProfile(); - ProcessInfo processInfo; + DmOfflineParam offlineParam; + int32_t bindNums = 0; + int32_t deleteNums = 0; for (const auto &item : profiles) { if (item.GetTrustDeviceId() != remoteUdid || item.GetBindType() == DM_IDENTICAL_ACCOUNT || item.GetBindLevel() != APP) { continue; } + bindNums++; if (item.GetAccesser().GetAccesserUserId() == remoteUserId && item.GetAccesser().GetAccesserDeviceId() == remoteUdid && static_cast(item.GetAccesser().GetAccesserTokenId()) == tokenId && @@ -1281,8 +1314,13 @@ EXPORT OHOS::DistributedHardware::ProcessInfo DeviceProfileConnector::HandleAppU item.GetAccessee().GetAccesseeDeviceId() == localUdid) { LOGI("Src device unbind."); DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); + deleteNums++; + offlineParam.bindType = APP; + ProcessInfo processInfo; + //TODO 校验是否delete Credentianl processInfo.pkgName = item.GetAccessee().GetAccesseeBundleName(); processInfo.userId = item.GetAccessee().GetAccesseeUserId(); + offlineParam.processVec.push_back(processInfo); continue; } if (item.GetAccessee().GetAccesseeUserId() == remoteUserId && @@ -1292,12 +1330,18 @@ EXPORT OHOS::DistributedHardware::ProcessInfo DeviceProfileConnector::HandleAppU item.GetAccesser().GetAccesserDeviceId() == localUdid) { LOGI("Sink device unbind."); DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); + deleteNums++; + offlineParam.bindType = APP; + ProcessInfo processInfo; + //TODO 校验是否delete Credentianl processInfo.pkgName = item.GetAccesser().GetAccesserBundleName(); processInfo.userId = item.GetAccesser().GetAccesserUserId(); + offlineParam.processVec.push_back(processInfo); continue; } } - return processInfo; + offlineParam.leftAclNumber = bindNums - deleteNums; + return offlineParam; } EXPORT std::vector DeviceProfileConnector::GetAllAccessControlProfile() @@ -1326,7 +1370,6 @@ EXPORT int32_t DeviceProfileConnector::HandleUserSwitched( std::vector profiles = GetAllAccessControlProfile(); std::vector activeProfiles; std::vector inActiveProfiles; - std::vector delActiveProfiles; for (auto &item : profiles) { if (std::find(deviceVec.begin(), deviceVec.end(), item.GetTrustDeviceId()) == deviceVec.end()) { continue; @@ -1339,9 +1382,7 @@ EXPORT int32_t DeviceProfileConnector::HandleUserSwitched( item.SetStatus(INACTIVE); inActiveProfiles.push_back(item); } - if (item.GetBindType() != DM_IDENTICAL_ACCOUNT) { - delActiveProfiles.push_back(item); - } + continue; } if ((item.GetAccesser().GetAccesserDeviceId() == localUdid && @@ -1353,21 +1394,17 @@ EXPORT int32_t DeviceProfileConnector::HandleUserSwitched( continue; } } - HandleUserSwitched(activeProfiles, inActiveProfiles, delActiveProfiles); + HandleUserSwitched(activeProfiles, inActiveProfiles); return DM_OK; } EXPORT void DeviceProfileConnector::HandleUserSwitched( const std::vector &activeProfiles, - const std::vector &inActiveProfiles, - const std::vector &delActiveProfiles) + const std::vector &inActiveProfiles) { for (auto &item : inActiveProfiles) { DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(item); } - for (auto &item : delActiveProfiles) { - DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); - } for (auto &item : activeProfiles) { DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(item); } @@ -1648,9 +1685,6 @@ EXPORT void DeviceProfileConnector::HandleSyncBackgroundUserIdEvent( item.SetStatus(INACTIVE); DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(item); } - if (item.GetBindType() != DM_IDENTICAL_ACCOUNT) { - DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); - } } else if ((accesseeDeviceId == localUdid && accesserDeviceId == remoteUdid) && (find(remoteUserIds.begin(), remoteUserIds.end(), accesserUserId) != remoteUserIds.end() || find(localUserIds.begin(), localUserIds.end(), accesseeUserId) == localUserIds.end())) { @@ -1658,9 +1692,6 @@ EXPORT void DeviceProfileConnector::HandleSyncBackgroundUserIdEvent( item.SetStatus(INACTIVE); DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(item); } - if (item.GetBindType() != DM_IDENTICAL_ACCOUNT) { - DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); - } } } } @@ -1894,7 +1925,6 @@ EXPORT int32_t DeviceProfileConnector::HandleUserSwitched( std::vector profiles = GetAllAccessControlProfile(); std::vector activeProfiles; std::vector inActiveProfiles; - std::vector delActiveProfiles; for (auto &item : profiles) { if (std::find(deviceVec.begin(), deviceVec.end(), item.GetTrustDeviceId()) == deviceVec.end()) { continue; @@ -1909,9 +1939,6 @@ EXPORT int32_t DeviceProfileConnector::HandleUserSwitched( item.SetStatus(INACTIVE); inActiveProfiles.push_back(item); } - if (item.GetBindType() != DM_IDENTICAL_ACCOUNT) { - delActiveProfiles.push_back(item); - } continue; } if ((item.GetAccesser().GetAccesserDeviceId() == localUdid && @@ -1925,7 +1952,7 @@ EXPORT int32_t DeviceProfileConnector::HandleUserSwitched( continue; } } - HandleUserSwitched(activeProfiles, inActiveProfiles, delActiveProfiles); + HandleUserSwitched(activeProfiles, inActiveProfiles); return DM_OK; } diff --git a/services/implementation/include/dependency/hichain/hichain_auth_connector.h b/services/implementation/include/dependency/hichain/hichain_auth_connector.h index 460a4094d749c6dd2d1cced847902e4406239851..f6caeeb9f406b498f3eb1abe628b0e78fab18a2d 100644 --- a/services/implementation/include/dependency/hichain/hichain_auth_connector.h +++ b/services/implementation/include/dependency/hichain/hichain_auth_connector.h @@ -53,8 +53,8 @@ public: int32_t ProcessAuthData(int64_t requestId, std::string authData, int32_t osAccountId); int32_t GenerateCredential(std::string &localUdid, int32_t osAccountId, std::string &publicKey); bool QueryCredential(std::string &localUdid, int32_t osAccountId); - int32_t ImportCredential(int32_t osAccountId, std::string deviceId, std::string publicKey); - int32_t DeleteCredential(const std::string &deviceId, int32_t userId); + int32_t ImportCredential(int32_t osAccountId, int32_t peerOsAccountId, std::string deviceId, std::string publicKey); + int32_t DeleteCredential(const std::string &deviceId, int32_t userId, int32_t peerUserId); int32_t RegisterHiChainAuthCallback(std::shared_ptr callback); int32_t GetCredential(std::string &localUdid, int32_t osAccountId, std::string &publicKey); private: diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 9a93051e499f0ddf43cec7313248df728d6ae909..cfdf1038884985d4cc49609162f28d59b8578b71 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -525,7 +525,8 @@ int32_t DmAuthManager::DeleteAcl(const std::string &pkgName, const std::string & if (offlineParam.leftAclNumber == 0) { LOGI("The pkgName unbind app-level type leftAclNumber is zero."); softbusConnector_->SetProcessInfoVec(offlineParam.processVec); - hiChainAuthConnector_->DeleteCredential(remoteUdid, MultipleUserConnector::GetCurrentAccountUserID()); + hiChainAuthConnector_->DeleteCredential(remoteUdid, MultipleUserConnector::GetCurrentAccountUserID(), + offlineParam.peerUserId); return DM_OK; } } @@ -535,7 +536,8 @@ int32_t DmAuthManager::DeleteAcl(const std::string &pkgName, const std::string & } if (static_cast(bindLevel) == DEVICE && offlineParam.leftAclNumber == 0) { LOGI("Unbind deivce-level, retain null."); - hiChainAuthConnector_->DeleteCredential(remoteUdid, MultipleUserConnector::GetCurrentAccountUserID()); + hiChainAuthConnector_->DeleteCredential(remoteUdid, MultipleUserConnector::GetCurrentAccountUserID(), + offlineParam.peerUserId); return DM_OK; } return ERR_DM_FAILED; @@ -2295,9 +2297,26 @@ void DmAuthManager::RequestCredentialDone() int32_t DmAuthManager::ImportCredential(std::string &deviceId, std::string &publicKey) { - LOGI("DmAuthManager::ImportCredential"); + LOGI("DmAuthManager::ImportCredential, deviceId %{public}s", GetAnonyString(deviceId).c_str()); int32_t osAccountId = MultipleUserConnector::GetCurrentAccountUserID(); - return hiChainAuthConnector_->ImportCredential(osAccountId, deviceId, publicKey); + if ((authRequestState_ != nullptr) && (authResponseState_ == nullptr)) { + // Source Import Credential + CHECK_NULL_VOID(authRequestContext_); + CHECK_NULL_VOID(hiChainAuthConnector_); + LOGI("Source Import Credential remoteUserId: %{public}d", authRequestContext_->remoteUserId); + return hiChainAuthConnector_->ImportCredential(osAccountId, authRequestContext_->remoteUserId, deviceId, + publicKey); + } else if ((authResponseState_ != nullptr) && (authRequestState_ == nullptr)) { + // Sink Import Credential + CHECK_NULL_VOID(authResponseContext_); + CHECK_NULL_VOID(hiChainAuthConnector_); + LOGI("Source Import Credential remoteUserId: %{public}d", authResponseContext_->remoteUserId); + return hiChainAuthConnector_->ImportCredential(osAccountId, authResponseContext_->remoteUserId, deviceId, + publicKey); + } else { + LOGE("DmAuthManager::ImportCredential failed, authRequestState_ or authResponseState_ is invalid."); + return ERR_DM_AUTH_FAILED; + } } void DmAuthManager::ResponseCredential() diff --git a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp index e18cbf08bb5fe9b82792961a4148de55fb77024a..226646e5ebd20903eb5578c52a64dcc8e554c6ab 100644 --- a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp @@ -185,15 +185,10 @@ int32_t HiChainAuthConnector::GenerateCredential(std::string &localUdid, int32_t LOGE("Decode generate return data jsonStr error."); return ERR_DM_FAILED; } - if (!IsInt32(jsonObject, "result") || !IsString(jsonObject, "publicKey") || - jsonObject["result"].Get() != HC_SUCCESS) { + if (!IsString(jsonObject, "publicKey")) { LOGE("Hichain generate public key jsonObject invalied."); return ERR_DM_FAILED; } - if (jsonObject["result"].Get() != 0) { - LOGE("Hichain generate public key failed"); - return ERR_DM_FAILED; - } publicKey = jsonObject["publicKey"].Get(); return DM_OK; } @@ -220,11 +215,7 @@ bool HiChainAuthConnector::QueryCredential(std::string &localUdid, int32_t osAcc LOGE("Decode query return data jsonStr error."); return false; } - if (!IsInt32(jsonObject, "result") || jsonObject["result"].Get() == -1) { - LOGE("Hichain generate public key failed."); - return false; - } - if (!IsString(jsonObject, "publicKey") || jsonObject["result"].Get() == 1) { + if (!IsString(jsonObject, "publicKey")) { LOGI("Credential not exist."); return false; } @@ -253,11 +244,7 @@ int32_t HiChainAuthConnector::GetCredential(std::string &localUdid, int32_t osAc LOGE("Decode query return data jsonStr error."); return ERR_DM_FAILED; } - if (!IsInt32(jsonObject, "result") || jsonObject["result"].Get() == -1) { - LOGE("Hichain generate public key failed."); - return ERR_DM_FAILED; - } - if (!IsString(jsonObject, "publicKey") || jsonObject["result"].Get() == 1) { + if (!IsString(jsonObject, "publicKey")) { LOGI("Credential not exist."); return ERR_DM_FAILED; } @@ -265,11 +252,14 @@ int32_t HiChainAuthConnector::GetCredential(std::string &localUdid, int32_t osAc return DM_OK; } -int32_t HiChainAuthConnector::ImportCredential(int32_t osAccountId, std::string deviceId, std::string publicKey) +int32_t HiChainAuthConnector::ImportCredential(int32_t osAccountId, int32_t peerOsAccountId, std::string deviceId, + std::string publicKey) { - LOGI("HiChainAuthConnector::ImportCredential"); + LOGI("ImportCredential start, deviceId: %{public}s, peerOsAccountId: %{public}d", + GetAnonyString(deviceId).c_str(), peerOsAccountId); JsonObject jsonObj; jsonObj["osAccountId"] = osAccountId; + jsonObj["peerOsAccountId"] = peerOsAccountId; jsonObj["deviceId"] = deviceId; jsonObj["acquireType"] = AcquireType::P2P_BIND; jsonObj["publicKey"] = publicKey; @@ -280,32 +270,19 @@ int32_t HiChainAuthConnector::ImportCredential(int32_t osAccountId, std::string FreeJsonString(returnData); return ERR_DM_FAILED; } - std::string returnDataStr = static_cast(returnData); FreeJsonString(returnData); - JsonObject jsonObject(returnDataStr); - if (jsonObject.IsDiscarded()) { - LOGE("Decode import return data jsonStr error."); - return ERR_DM_FAILED; - } - if (!IsInt32(jsonObject, "result")) { - LOGI("Hichain import public key jsonObject invalied."); - return ERR_DM_FAILED; - } - int32_t result = jsonObject["result"].Get(); - if (result != 0) { - LOGE("Hichain import public key result is %{public}d.", result); - return ERR_DM_FAILED; - } return DM_OK; } -int32_t HiChainAuthConnector::DeleteCredential(const std::string &deviceId, int32_t userId) +int32_t HiChainAuthConnector::DeleteCredential(const std::string &deviceId, int32_t userId, int32_t peerUserId) { - LOGI("DeleteCredential start."); + LOGI("DeleteCredential start, deviceId: %{public}s, peerUserId: %{public}d", + GetAnonyString(deviceId).c_str(), peerUserId); JsonObject jsonObj; jsonObj["deviceId"] = deviceId; jsonObj["acquireType"] = AcquireType::P2P_BIND; jsonObj["osAccountId"] = userId; + jsonObj["peerOsAccountId"] = peerUserId; std::string requestParam = SafetyDump(jsonObj); char *returnData = nullptr; if (ProcessCredential(CRED_OP_DELETE, requestParam.c_str(), &returnData) != HC_SUCCESS) { @@ -313,18 +290,8 @@ int32_t HiChainAuthConnector::DeleteCredential(const std::string &deviceId, int3 FreeJsonString(returnData); return false; } - std::string returnDataStr = static_cast(returnData); FreeJsonString(returnData); - JsonObject jsonObject(returnDataStr); - if (jsonObject.IsDiscarded()) { - LOGE("Decode import return data jsonStr error."); - return false; - } - if (!IsInt32(jsonObject, "result")) { - LOGI("Hichain delete credential result json key is invalid."); - return ERR_DM_FAILED; - } - return jsonObject["result"].Get(); + return DM_OK; } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 54e5840c1a690821611b6a3611e0e84e5bd7f113..fb9551035425961a5c7e6c596082878e0f28a4b8 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -685,6 +685,10 @@ void DeviceManagerServiceImpl::HandleIdentAccountLogout(const std::string &local processInfo.userId = localUserId; CHECK_NULL_VOID(softbusConnector_); softbusConnector_->SetProcessInfo(processInfo); + CHECK_NULL_VOID(hiChainConnector_); + hiChainConnector_->DeleteAllGroup(localUserId); + CHECK_NULL_VOID(hiChainAuthConnector_); + hiChainAuthConnector_->DeleteCredential(peerUdid, localUserId, peerUserId); CHECK_NULL_VOID(deviceStateMgr_); deviceStateMgr_->OnDeviceOffline(peerUdid); } @@ -726,8 +730,6 @@ void DeviceManagerServiceImpl::HandleUserSwitched(const std::vector GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); std::string localUdid = static_cast(localDeviceId); DeviceProfileConnector::GetInstance().HandleUserSwitched(localUdid, deviceVec, currentUserId, beforeUserId); - CHECK_NULL_VOID(hiChainConnector_); - hiChainConnector_->DeleteAllGroup(beforeUserId); } void DeviceManagerServiceImpl::ScreenCommonEventCallback(std::string commonEventType) @@ -864,15 +866,25 @@ void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); std::string localUdid = std::string(localUdidTemp); - ProcessInfo processInfo = + DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, localUdid); - if (processInfo.pkgName.empty()) { - LOGE("Pkgname is empty."); + + if (offlineParam.leftAclNumber != 0) { + LOGI("The sessionName unbind app-level type leftAclNumber not zero."); + CHECK_NULL_VOID(softbusConnector_); + softbusConnector_->SetProcessInfoVec(offlineParam.processVec); + softbusConnector_->HandleDeviceOffline(remoteUdid); + return; + } + if (offlineParam.leftAclNumber == 0) { + LOGI("The sessionName unbind app-level type leftAclNumber is zero."); + CHECK_NULL_VOID(softbusConnector_); + softbusConnector_->SetProcessInfoVec(offlineParam.processVec); + CHECK_NULL_VOID(hiChainAuthConnector_); + hiChainAuthConnector_->DeleteCredential(remoteUdid, MultipleUserConnector::GetCurrentAccountUserID(), + remoteUserId); return; } - CHECK_NULL_VOID(softbusConnector_); - softbusConnector_->SetProcessInfo(processInfo); - softbusConnector_->HandleDeviceOffline(remoteUdid); } void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, @@ -882,16 +894,27 @@ void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); std::string localUdid = std::string(localUdidTemp); - ProcessInfo processInfo = + //TODO app_unbind + DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, localUdid, peerTokenId); - if (processInfo.pkgName.empty()) { - LOGE("Pkgname is empty."); + + if (offlineParam.leftAclNumber != 0) { + LOGI("The sessionName unbind app-level type leftAclNumber not zero."); + CHECK_NULL_VOID(softbusConnector_); + softbusConnector_->SetProcessInfoVec(offlineParam.processVec); + softbusConnector_->HandleDeviceOffline(remoteUdid); + return; + } + if (offlineParam.leftAclNumber == 0) { + LOGI("The sessionName unbind app-level type leftAclNumber is zero."); + CHECK_NULL_VOID(softbusConnector_); + softbusConnector_->SetProcessInfoVec(offlineParam.processVec); + CHECK_NULL_VOID(hiChainAuthConnector_); + hiChainAuthConnector_->DeleteCredential(remoteUdid, MultipleUserConnector::GetCurrentAccountUserID(), + remoteUserId); return; } - CHECK_NULL_VOID(softbusConnector_); - softbusConnector_->SetProcessInfo(processInfo); - softbusConnector_->HandleDeviceOffline(remoteUdid); } void DeviceManagerServiceImpl::HandleSyncUserIdEvent(const std::vector &foregroundUserIds, @@ -1040,21 +1063,34 @@ void DeviceManagerServiceImpl::DeleteAlwaysAllowTimeOut() std::vector profiles = DeviceProfileConnector::GetInstance().GetAllAccessControlProfile(); std::string remoteUdid = ""; + int32_t remoteUserId = -1; int64_t currentTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + int32_t currentUserId = MultipleUserConnector::GetCurrentAccountUserID(); + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + std::string localUdid = std::string(localDeviceId); for (auto &item : profiles) { if (item.GetBindType() == DM_IDENTICAL_ACCOUNT) { continue; } if ((currentTime - item.GetLastAuthTime()) > MAX_ALWAYS_ALLOW_SECONDS && item.GetLastAuthTime() > 0) { DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); + if (item.GetAccesser().GetAccesserUserId() == currentUserId && + item.GetAccesser().GetAccesserDeviceId() == localUdid) { + remoteUserId = item.GetAccessee().GetAccesseeUserId(); + } + if (item.GetAccessee().GetAccesseeUserId() == currentUserId && + item.GetAccessee().GetAccesseeDeviceId() == localUdid) { + remoteUserId = item.GetAccesser().GetAccesserUserId(); + } remoteUdid = item.GetTrustDeviceId(); - CheckDeleteCredential(remoteUdid); + CheckDeleteCredential(remoteUdid, remoteUserId); } } } -void DeviceManagerServiceImpl::CheckDeleteCredential(const std::string &remoteUdid) +void DeviceManagerServiceImpl::CheckDeleteCredential(const std::string &remoteUdid, int32_t remoteUserId) { std::vector profiles = DeviceProfileConnector::GetInstance().GetAllAccessControlProfile(); @@ -1066,7 +1102,8 @@ void DeviceManagerServiceImpl::CheckDeleteCredential(const std::string &remoteUd } if (!leftAcl) { LOGI("CheckDeleteCredential delete credential"); - hiChainAuthConnector_->DeleteCredential(remoteUdid, MultipleUserConnector::GetCurrentAccountUserID()); + hiChainAuthConnector_->DeleteCredential(remoteUdid, MultipleUserConnector::GetCurrentAccountUserID(), + remoteUserId); } } diff --git a/services/implementation/src/devicestate/dm_device_state_manager.cpp b/services/implementation/src/devicestate/dm_device_state_manager.cpp index 736c75c9dc073558fb88dad4dfb26a720cce4bdb..d88646d7c854b2ba978559e1f926d070eb21eae8 100644 --- a/services/implementation/src/devicestate/dm_device_state_manager.cpp +++ b/services/implementation/src/devicestate/dm_device_state_manager.cpp @@ -306,10 +306,11 @@ void DmDeviceStateManager::DeleteTimeOutGroup(std::string name) hiChainConnector_->DeleteTimeOutGroup((idIter->second).c_str()); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) DeleteGroupByDP(idIter->second); - uint32_t res = DeviceProfileConnector::GetInstance().DeleteTimeOutAcl(idIter->second); + int32_t peerUserId = -1; + uint32_t res = DeviceProfileConnector::GetInstance().DeleteTimeOutAcl(idIter->second, peerUserId); if (res == 0) { hiChainAuthConnector_->DeleteCredential(idIter->second, - MultipleUserConnector::GetCurrentAccountUserID()); + MultipleUserConnector::GetCurrentAccountUserID(), peerUserId); } #endif stateTimerInfoMap_.erase(iter); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 7a7e913d38eb06bad7e34b8a5b47c0cd05e156ab..83e3db5a65b2744f272656d2d6156bfe26198bb8 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2065,9 +2065,6 @@ void DeviceManagerService::UpdateAclAndDeleteGroup(const std::string &localUdid, } discoveryMgr_->GetCommonDependencyObj()->HandleUserSwitched(localUdid, deviceVec, foregroundUserIds, backgroundUserIds); - //delete group - CHECK_NULL_VOID(hichainListener_); - hichainListener_->DeleteAllGroup(localUdid, backgroundUserIds); } #endif diff --git a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp index 01a64b6723649cd6fa12b21627f7e295a564f09f..7047624ffed3b3b56a9dd3fec040fa6ff77b20fe 100644 --- a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp +++ b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp @@ -225,7 +225,7 @@ void DMCommTool::ProcessReceiveUserIdsEvent(const std::shared_ptr } RspLocalFrontOrBackUserIds(commMsg->remoteNetworkId, foregroundUserIdsU32, backgroundUserIdsU32, commMsg->socketId); - + if (userIdsMsg.foregroundUserIds.empty()) { LOGE("Parse but get none remote foreground userids"); } else { diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 5861cef0c062f08661510ada333742b6a6da41a8..b40e3cf32cffedb563ed04300de526477d6e7738 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -1297,7 +1297,7 @@ int32_t SoftbusListener::GetAllTrustedDeviceList(const std::string &pkgName, con std::vector allProfile = DeviceProfileConnector::GetInstance().GetAllAccessControlProfile(); for (DistributedDeviceProfile::AccessControlProfile profile : allProfile) { - if (profile.GetBindType() == GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP) { + if (profile.GetBindType() == GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP || profile.GetStatus() == INACTIVE) { continue; } DistributedDeviceProfile::Accesser acer = profile.GetAccesser(); diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index 06a5ba958a7b03f60edd09bb48141147e1aa60c0..f7a63ff8bcf023a50a445044439e05ae47ffafc0 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -778,7 +778,7 @@ HWTEST_F(DmAuthManagerTest, ImportCredential001, testing::ext::TestSize.Level1) { std::string deviceId = "deviceId"; std::string publicKey = "publicKey"; - EXPECT_CALL(*hiChainAuthConnectorMock_, ImportCredential(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); + EXPECT_CALL(*hiChainAuthConnectorMock_, ImportCredential(_, _, _, _)).WillOnce(Return(ERR_DM_FAILED)); int32_t ret = authManager_->ImportCredential(deviceId, publicKey); ASSERT_EQ(ret, ERR_DM_FAILED); } @@ -789,13 +789,13 @@ HWTEST_F(DmAuthManagerTest, ResponseCredential001, testing::ext::TestSize.Level1 ASSERT_EQ(authManager_->isAuthDevice_, false); authManager_->authResponseContext_->publicKey = "publicKey"; - EXPECT_CALL(*hiChainAuthConnectorMock_, ImportCredential(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); + EXPECT_CALL(*hiChainAuthConnectorMock_, ImportCredential(_, _, _, _)).WillOnce(Return(ERR_DM_FAILED)); authManager_->ResponseCredential(); ASSERT_EQ(authManager_->isAuthDevice_, false); authManager_->authMessageProcessor_ = std::make_shared(authManager_); authManager_->authMessageProcessor_->authResponseContext_ = std::make_shared(); - EXPECT_CALL(*hiChainAuthConnectorMock_, ImportCredential(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*hiChainAuthConnectorMock_, ImportCredential(_, _, _, _)).WillOnce(Return(DM_OK)); authManager_->ResponseCredential(); ASSERT_EQ(authManager_->isAuthDevice_, false); } @@ -1832,7 +1832,7 @@ HWTEST_F(DmAuthManagerTest, RequestCredentialDone_003, testing::ext::TestSize.Le ASSERT_EQ(authManager_->isAuthDevice_, false); authManager_->authResponseContext_->publicKey = "publicKey"; - EXPECT_CALL(*hiChainAuthConnectorMock_, ImportCredential(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); + EXPECT_CALL(*hiChainAuthConnectorMock_, ImportCredential(_, _, _, _)).WillOnce(Return(ERR_DM_FAILED)); authManager_->RequestCredentialDone(); ASSERT_EQ(authManager_->isAuthDevice_, false); } diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index 52821ab12be7bb930257816bd2861c5e8fa66347..b36a14b0c14a3c6625ed69ef4327545d13ef97c1 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -1084,7 +1084,8 @@ HWTEST_F(DeviceProfileConnectorTest, CheckDevIdInAclForDevBind_001, testing::ext HWTEST_F(DeviceProfileConnectorTest, DeleteTimeOutAcl_001, testing::ext::TestSize.Level1) { std::string deviceId; - uint32_t ret = DeviceProfileConnector::GetInstance().DeleteTimeOutAcl(deviceId); + int32_t peerUserId = -1; + uint32_t ret = DeviceProfileConnector::GetInstance().DeleteTimeOutAcl(deviceId, peerUserId); EXPECT_EQ(ret, 0); } @@ -1204,15 +1205,14 @@ HWTEST_F(DeviceProfileConnectorTest, HandleAppUnBindEvent_001, testing::ext::Tes std::string remoteUdid = "remoteDeviceId"; std::string localUdid = "localDeviceId"; std::string pkgName = ""; - ProcessInfo res; - - res = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, localUdid); - EXPECT_EQ(pkgName, res.pkgName); + DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, + remoteUdid, tokenId, localUdid); + EXPECT_EQ(offlineParam.leftAclNumber, 0); int32_t peerTokenId = 1; - res = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, localUdid, - peerTokenId); - EXPECT_EQ(pkgName, res.pkgName); + offlineParam = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, + localUdid, peerTokenId); + EXPECT_EQ(offlineParam.leftAclNumber, 0); } HWTEST_F(DeviceProfileConnectorTest, SingleUserProcess_001, testing::ext::TestSize.Level1) @@ -1339,7 +1339,8 @@ HWTEST_F(DeviceProfileConnectorTest, CheckSrcDevIdInAclForDevBind_004, testing:: HWTEST_F(DeviceProfileConnectorTest, DeleteTimeOutAcl_002, testing::ext::TestSize.Level1) { std::string deviceId = "remoteDeviceId"; - uint32_t ret = DeviceProfileConnector::GetInstance().DeleteTimeOutAcl(deviceId); + int32_t peerUserId = 0; + uint32_t ret = DeviceProfileConnector::GetInstance().DeleteTimeOutAcl(deviceId, peerUserId); EXPECT_EQ(ret, 0); } @@ -1544,13 +1545,15 @@ HWTEST_F(DeviceProfileConnectorTest, HandleUserSwitched_001, testing::ext::TestS std::string localUdid = "deviceId"; int32_t beforeUserId = 123456; std::vector deviceVec; + std::map peerUserIdMap; int32_t ret = DeviceProfileConnector::GetInstance().HandleUserSwitched(localUdid, deviceVec, currentUserId, - beforeUserId); + beforeUserId, peerUserIdMap); EXPECT_EQ(ret, DM_OK); beforeUserId = 1234; currentUserId = 123456; - ret = DeviceProfileConnector::GetInstance().HandleUserSwitched(localUdid, deviceVec, currentUserId, beforeUserId); + ret = DeviceProfileConnector::GetInstance().HandleUserSwitched(localUdid, deviceVec, currentUserId, beforeUserId, + peerUserIdMap); EXPECT_EQ(ret, DM_OK); std::vector remoteUserIds; @@ -1863,23 +1866,25 @@ HWTEST_F(DeviceProfileConnectorTest, HandleAppUnBindEvent_002, testing::ext::Tes std::string remoteUdid = "localDeviceId"; std::string localUdid = "remoteDeviceId"; std::string pkgName = ""; - ProcessInfo res; - res = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, localUdid); - EXPECT_EQ("bundleName", res.pkgName); + DmOfflineParam offlineParam; + offlineParam = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, + localUdid); + EXPECT_EQ(offlineParam.leftAclNumber, 0); int32_t peerTokenId = 1001; - res = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, localUdid, - peerTokenId); - EXPECT_EQ("bundleName", res.pkgName); + offlineParam = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, + localUdid, peerTokenId); + EXPECT_EQ(offlineParam.leftAclNumber, 0); tokenId = 1002; peerTokenId = tokenId; - res = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, localUdid); - EXPECT_EQ("bundleName", res.pkgName); + offlineParam = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, + localUdid); + EXPECT_EQ(offlineParam.leftAclNumber, 0); - res = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, localUdid, - peerTokenId); - EXPECT_EQ("bundleName", res.pkgName); + offlineParam = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, + localUdid, peerTokenId); + EXPECT_EQ(offlineParam.leftAclNumber, 0); } HWTEST_F(DeviceProfileConnectorTest, HandleAppUnBindEvent_003, testing::ext::TestSize.Level1) @@ -1890,10 +1895,9 @@ HWTEST_F(DeviceProfileConnectorTest, HandleAppUnBindEvent_003, testing::ext::Tes std::string localUdid = "localDeviceId"; std::string pkgName = ""; int32_t peerTokenId = 1001; - ProcessInfo res; - res = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, + DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, localUdid, peerTokenId); - EXPECT_EQ(pkgName, res.pkgName); + EXPECT_EQ(offlineParam.leftAclNumber, 0); } HWTEST_F(DeviceProfileConnectorTest, HandleAppUnBindEvent_004, testing::ext::TestSize.Level1) @@ -1904,10 +1908,9 @@ HWTEST_F(DeviceProfileConnectorTest, HandleAppUnBindEvent_004, testing::ext::Tes std::string localUdid = "localDeviceId"; std::string pkgName = ""; int32_t peerTokenId = 1001; - ProcessInfo res; - res = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, + DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, localUdid, peerTokenId); - EXPECT_EQ("bundleName", res.pkgName); + EXPECT_EQ(offlineParam.leftAclNumber, 0); } HWTEST_F(DeviceProfileConnectorTest, GetTokenIdByNameAndDeviceId_002, testing::ext::TestSize.Level1) diff --git a/test/commonunittest/UTTest_hichain_auth_connector.cpp b/test/commonunittest/UTTest_hichain_auth_connector.cpp index a33d4b17b58f9f55bcb6b8d2f5e2cf78a6e43894..823602de96bd26e1918683fffb0cb246f6d0ade3 100644 --- a/test/commonunittest/UTTest_hichain_auth_connector.cpp +++ b/test/commonunittest/UTTest_hichain_auth_connector.cpp @@ -488,7 +488,8 @@ HWTEST_F(HiChainAuthConnectorTest, ImportCredential_001, testing::ext::TestSize. int32_t localUdid = 0; std::string deviceId; std::string publicKey; - int32_t ret = hiChain_->ImportCredential(localUdid, deviceId, publicKey); + int32_t peerUserId = 0; + int32_t ret = hiChain_->ImportCredential(localUdid, peerUserId, deviceId, publicKey); EXPECT_NE(ret, DM_OK); } @@ -497,7 +498,8 @@ HWTEST_F(HiChainAuthConnectorTest, ImportCredential_002, testing::ext::TestSize. int32_t localUdid = 0; std::string deviceId = "4513541351"; std::string publicKey = "42125143613"; - int32_t ret = hiChain_->ImportCredential(localUdid, deviceId, publicKey); + int32_t peerUserId = 0; + int32_t ret = hiChain_->ImportCredential(localUdid, peerUserId, deviceId, publicKey); EXPECT_NE(ret, DM_OK); } @@ -508,7 +510,8 @@ HWTEST_F(HiChainAuthConnectorTest, ImportCredential_003, testing::ext::TestSize. std::string publicKey = "test"; g_processCredentialResultCode = HC_SUCCESS; g_processCredentialReturnDataStr = "{invalid_json}"; - int32_t ret = hiChain_->ImportCredential(localUdid, deviceId, publicKey); + int32_t peerUserId = 0; + int32_t ret = hiChain_->ImportCredential(localUdid, peerUserId, deviceId, publicKey); EXPECT_EQ(ret, ERR_DM_FAILED); } @@ -519,7 +522,8 @@ HWTEST_F(HiChainAuthConnectorTest, ImportCredential_004, testing::ext::TestSize. std::string publicKey = "test"; g_processCredentialResultCode = HC_SUCCESS; g_processCredentialReturnDataStr = R"({"result": "not_an_int"})"; - int32_t ret = hiChain_->ImportCredential(localUdid, deviceId, publicKey); + int32_t peerUserId = 0; + int32_t ret = hiChain_->ImportCredential(localUdid, peerUserId, deviceId, publicKey); EXPECT_EQ(ret, ERR_DM_FAILED); } @@ -530,7 +534,8 @@ HWTEST_F(HiChainAuthConnectorTest, ImportCredential_005, testing::ext::TestSize. std::string publicKey = "test"; g_processCredentialResultCode = HC_SUCCESS; g_processCredentialReturnDataStr = R"({"result": -1})"; - int32_t ret = hiChain_->ImportCredential(localUdid, deviceId, publicKey); + int32_t peerUserId = 0; + int32_t ret = hiChain_->ImportCredential(localUdid, peerUserId, deviceId, publicKey); EXPECT_EQ(ret, ERR_DM_FAILED); } @@ -541,7 +546,8 @@ HWTEST_F(HiChainAuthConnectorTest, ImportCredential_006, testing::ext::TestSize. std::string publicKey = "test"; g_processCredentialResultCode = HC_SUCCESS; g_processCredentialReturnDataStr = R"({"result": 0})"; - int32_t ret = hiChain_->ImportCredential(localUdid, deviceId, publicKey); + int32_t peerUserId = 0; + int32_t ret = hiChain_->ImportCredential(localUdid, peerUserId, deviceId, publicKey); EXPECT_EQ(ret, DM_OK); } @@ -549,7 +555,8 @@ HWTEST_F(HiChainAuthConnectorTest, DeleteCredential_001, testing::ext::TestSize. { std::string deviceId; int32_t userId = 0; - int32_t ret = hiChain_->DeleteCredential(deviceId, userId); + int32_t peerUserId = 0; + int32_t ret = hiChain_->DeleteCredential(deviceId, userId, peerUserId); EXPECT_EQ(ret, DM_OK); } @@ -557,7 +564,8 @@ HWTEST_F(HiChainAuthConnectorTest, DeleteCredential_002, testing::ext::TestSize. { std::string deviceId = "864513535"; int32_t userId = 0; - int32_t ret = hiChain_->DeleteCredential(deviceId, userId); + int32_t peerUserId = 0; + int32_t ret = hiChain_->DeleteCredential(deviceId, userId, peerUserId); EXPECT_EQ(ret, DM_OK); } @@ -567,7 +575,8 @@ HWTEST_F(HiChainAuthConnectorTest, DeleteCredential_003, testing::ext::TestSize. int32_t userId = 0; g_processCredentialResultCode = HC_SUCCESS; g_processCredentialReturnDataStr = "{invalid_json}"; - int32_t ret = hiChain_->DeleteCredential(deviceId, userId); + int32_t peerUserId = 0; + int32_t ret = hiChain_->DeleteCredential(deviceId, userId, peerUserId); EXPECT_EQ(ret, 0); } @@ -577,7 +586,8 @@ HWTEST_F(HiChainAuthConnectorTest, DeleteCredential_004, testing::ext::TestSize. int32_t userId = 0; g_processCredentialResultCode = HC_SUCCESS; g_processCredentialReturnDataStr = R"({"result": "not_an_int"})"; - int32_t ret = hiChain_->DeleteCredential(deviceId, userId); + int32_t peerUserId = 0; + int32_t ret = hiChain_->DeleteCredential(deviceId, userId, peerUserId); EXPECT_EQ(ret, ERR_DM_FAILED); } @@ -587,7 +597,8 @@ HWTEST_F(HiChainAuthConnectorTest, DeleteCredential_005, testing::ext::TestSize. int32_t userId = 0; g_processCredentialResultCode = HC_SUCCESS; g_processCredentialReturnDataStr = R"({"result": 100})"; - int32_t ret = hiChain_->DeleteCredential(deviceId, userId); + int32_t peerUserId = 0; + int32_t ret = hiChain_->DeleteCredential(deviceId, userId, peerUserId); EXPECT_EQ(ret, 100); } } // namespace DistributedHardware diff --git a/test/servicesfuzztest/deviceprofileconnector_fuzzer/device_profile_connector_fuzzer.cpp b/test/servicesfuzztest/deviceprofileconnector_fuzzer/device_profile_connector_fuzzer.cpp index c7875807c9ff81f52e3cf37edc222dbb06ecaaea..fb5dd1d3246fa657f05de547400f17bb86c5beaa 100644 --- a/test/servicesfuzztest/deviceprofileconnector_fuzzer/device_profile_connector_fuzzer.cpp +++ b/test/servicesfuzztest/deviceprofileconnector_fuzzer/device_profile_connector_fuzzer.cpp @@ -63,7 +63,7 @@ void DeviceProfileConnectorFuzzTest(const uint8_t* data, size_t size) DeviceProfileConnector::GetInstance().UpdateAccessControlList(userId, accountId, accountId); DeviceProfileConnector::GetInstance().CheckIdenticalAccount(userId, accountId); DeviceProfileConnector::GetInstance().CheckDevIdInAclForDevBind(pkgName, localDeviceId); - DeviceProfileConnector::GetInstance().DeleteTimeOutAcl(localDeviceId); + DeviceProfileConnector::GetInstance().DeleteTimeOutAcl(localDeviceId, userId); DeviceProfileConnector::GetInstance().GetTrustNumber(localDeviceId); } } diff --git a/test/unittest/mock/hichain_auth_connector_mock.cpp b/test/unittest/mock/hichain_auth_connector_mock.cpp index e6c8451c821d2dfa79ce1b1212eb2d4b5c2b7740..f63aa36bcc3d7c1ee5bfa8ae34d63902585d4613 100644 --- a/test/unittest/mock/hichain_auth_connector_mock.cpp +++ b/test/unittest/mock/hichain_auth_connector_mock.cpp @@ -29,9 +29,11 @@ int32_t HiChainAuthConnector::AuthDevice(int32_t pinCode, int32_t osAccountId, s return DmHiChainAuthConnector::dmHiChainAuthConnector->AuthDevice(pinCode, osAccountId, udid, requestId); } -int32_t HiChainAuthConnector::ImportCredential(int32_t osAccountId, std::string deviceId, std::string publicKey) +int32_t HiChainAuthConnector::ImportCredential(int32_t osAccountId, int32_t peerOsAccountId, std::string deviceId, + std::string publicKey) { - return DmHiChainAuthConnector::dmHiChainAuthConnector->ImportCredential(osAccountId, deviceId, publicKey); + return DmHiChainAuthConnector::dmHiChainAuthConnector->ImportCredential(osAccountId, peerOsAccountId, deviceId, + publicKey); } } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/hichain_auth_connector_mock.h b/test/unittest/mock/hichain_auth_connector_mock.h index 174867f64715fdb4b00c866237243b4026413797..1c82b073a00a42183c026336a52fc057632624a8 100644 --- a/test/unittest/mock/hichain_auth_connector_mock.h +++ b/test/unittest/mock/hichain_auth_connector_mock.h @@ -27,9 +27,9 @@ public: virtual ~DmHiChainAuthConnector() = default; public: virtual bool QueryCredential(std::string &localUdid, int32_t osAccountId) = 0; - virtual int32_t AuthDevice(int32_t pinCode, int32_t osAccountId, - std::string udid, int64_t requestId) = 0; - virtual int32_t ImportCredential(int32_t osAccountId, std::string deviceId, std::string publicKey) = 0; + virtual int32_t AuthDevice(int32_t pinCode, int32_t osAccountId, std::string udid, int64_t requestId) = 0; + virtual int32_t ImportCredential(int32_t osAccountId, int32_t peerOsAccountId, std::string deviceId, + std::string publicKey) = 0; public: static inline std::shared_ptr dmHiChainAuthConnector = nullptr; };