diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 5d67e55181dabb722dc8697d3a92c9527282ce7e..af342d6cd3a5b9e3e123937e1a792159d494f867 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -249,11 +249,16 @@ int32_t DeviceProfileConnector::GetAuthForm(DistributedDeviceProfile::AccessCont std::vector DeviceProfileConnector::GetBindTypeByPkgName(std::string pkgName, std::string requestDeviceId, std::string trustUdid) { - LOGI("Start."); + LOGI("Start requestDeviceId %{public}s, trustUdid %{public}s.", GetAnonyString(requestDeviceId).c_str(), + GetAnonyString(trustUdid).c_str()); + std::vector bindTypeVec; + if (requestDeviceId.empty() || trustUdid.empty() || requestDeviceId == trustUdid) { + LOGE("Input udid param invalied."); + return bindTypeVec; + } std::vector profiles = GetAccessControlProfileByUserId(MultipleUserConnector::GetFirstForegroundUserId()); LOGI("AccessControlProfile size is %{public}zu", profiles.size()); - std::vector bindTypeVec; for (auto &item : profiles) { if (trustUdid != item.GetTrustDeviceId() || item.GetStatus() != ACTIVE) { continue; @@ -282,41 +287,40 @@ uint64_t DeviceProfileConnector::GetTokenIdByNameAndDeviceId(std::string pkgName return peerTokenId; } -void DeviceProfileConnector::GetParamBindTypeVec(AccessControlProfile profiles, std::string requestDeviceId, +void DeviceProfileConnector::GetParamBindTypeVec(AccessControlProfile profile, std::string requestDeviceId, std::vector &bindTypeVec, std::string trustUdid) { - if (profiles.GetBindType() == DM_IDENTICAL_ACCOUNT) { - bindTypeVec.push_back(IDENTICAL_ACCOUNT_TYPE); + if (!(profile.GetAccesser().GetAccesserDeviceId() == trustUdid && + profile.GetAccessee().GetAccesseeDeviceId() == requestDeviceId) && + !(profile.GetAccessee().GetAccesseeDeviceId() == trustUdid && + profile.GetAccesser().GetAccesserDeviceId() == requestDeviceId)) { + LOGE("input udid param invalied."); + return; } - if (profiles.GetBindType() == DM_POINT_TO_POINT) { - if (profiles.GetBindLevel() == DEVICE) { - bindTypeVec.push_back(DEVICE_PEER_TO_PEER_TYPE); - } - if (profiles.GetBindLevel() == APP) { - if (profiles.GetAccesser().GetAccesserDeviceId() == trustUdid && - profiles.GetAccessee().GetAccesseeDeviceId() == requestDeviceId) { - bindTypeVec.push_back(APP_PEER_TO_PEER_TYPE); + uint32_t bindType = profile.GetBindType(); + switch (bindType) { + case DM_IDENTICAL_ACCOUNT: + bindTypeVec.push_back(IDENTICAL_ACCOUNT_TYPE); + break; + case DM_POINT_TO_POINT: + if (profile.GetBindLevel() == DEVICE) { + bindTypeVec.push_back(DEVICE_PEER_TO_PEER_TYPE); } - if (profiles.GetAccessee().GetAccesseeDeviceId() == trustUdid && - profiles.GetAccesser().GetAccesserDeviceId() == requestDeviceId) { + if (profile.GetBindLevel() == APP) { bindTypeVec.push_back(APP_PEER_TO_PEER_TYPE); } - } - } - if (profiles.GetBindType() == DM_ACROSS_ACCOUNT) { - if (profiles.GetBindLevel() == DEVICE) { - bindTypeVec.push_back(DEVICE_ACROSS_ACCOUNT_TYPE); - } - if (profiles.GetBindLevel() == APP) { - if (profiles.GetAccesser().GetAccesserDeviceId() == trustUdid && - profiles.GetAccessee().GetAccesseeDeviceId() == requestDeviceId) { - bindTypeVec.push_back(APP_ACROSS_ACCOUNT_TYPE); + break; + case DM_ACROSS_ACCOUNT: + if (profile.GetBindLevel() == DEVICE) { + bindTypeVec.push_back(DEVICE_ACROSS_ACCOUNT_TYPE); } - if (profiles.GetAccessee().GetAccesseeDeviceId() == trustUdid && - profiles.GetAccesser().GetAccesserDeviceId() == requestDeviceId) { + if (profile.GetBindLevel() == APP) { bindTypeVec.push_back(APP_ACROSS_ACCOUNT_TYPE); } - } + break; + default: + LOGE("unknown bind type %{public}d.", bindType); + break; } } diff --git a/interfaces/kits/js4.0/src/dm_native_util.cpp b/interfaces/kits/js4.0/src/dm_native_util.cpp index 8b08c668a1d786f0b71cc9f4ef85c5d12ca1cbbe..711ebe4c5f1a0d81bdb2ae4b1819a4f6e25a4ed7 100644 --- a/interfaces/kits/js4.0/src/dm_native_util.cpp +++ b/interfaces/kits/js4.0/src/dm_native_util.cpp @@ -327,8 +327,6 @@ void JsToBindParam(const napi_env &env, const napi_value &object, std::string &b JsObjectToString(env, object, "targetPkgName", targetPkgName, sizeof(targetPkgName)); char metaType[DM_NAPI_BUF_LENGTH] = ""; JsObjectToString(env, object, "metaType", metaType, sizeof(metaType)); - char peerBundleName[DM_NAPI_BUF_LENGTH] = ""; - JsObjectToString(env, object, "peerBundleName", peerBundleName, sizeof(peerBundleName)); std::string metaTypeStr = metaType; isMetaType = !metaTypeStr.empty(); @@ -356,7 +354,6 @@ void JsToBindParam(const napi_env &env, const napi_value &object, std::string &b jsonObj[CUSTOM_DESCRIPTION] = std::string(customDescription); jsonObj[PARAM_KEY_TARGET_PKG_NAME] = std::string(targetPkgName); jsonObj[PARAM_KEY_META_TYPE] = metaTypeStr; - jsonObj[PARAM_KEY_PEER_BUNDLE_NAME] = std::string(peerBundleName); jsonObj[PARAM_KEY_PIN_CODE] = std::string(pinCode); jsonObj[PARAM_KEY_AUTH_TOKEN] = std::string(authToken); jsonObj[PARAM_KEY_IS_SHOW_TRUST_DIALOG] = std::string(isShowTrustDialog); diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index b67246a0b4afb00059c8509d13377ccd84db51e2..dd1aa32fe221d3d16e5b291cd99886e6b51ca0de 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -401,6 +401,8 @@ void AuthMessageProcessor::ParseResponseFinishMessage(nlohmann::json &json) void AuthMessageProcessor::GetAuthReqMessage(nlohmann::json &json) { + authResponseContext_->localDeviceId = ""; + authResponseContext_->deviceId = ""; if (IsInt32(json, TAG_AUTH_TYPE)) { authResponseContext_->authType = json[TAG_AUTH_TYPE].get(); } diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 1d284dab319c86f50b0c62a9c70aea1ca5dca597..31312c494dac9f479cc9a32f216900f892315353 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -104,6 +104,7 @@ constexpr const char* DM_VERSION_4_1_5_1 = "4.1.5.1"; constexpr const char* DM_VERSION_5_0_1 = "5.0.1"; constexpr const char* DM_VERSION_5_0_2 = "5.0.2"; constexpr const char* DM_VERSION_5_0_3 = "5.0.3"; +constexpr const char* DM_VERSION_5_0_4 = "5.0.4"; std::mutex g_authFinishLock; DmAuthManager::DmAuthManager(std::shared_ptr softbusConnector, @@ -119,7 +120,7 @@ DmAuthManager::DmAuthManager(std::shared_ptr softbusConnector, authUiStateMgr_ = std::make_shared(listener_); authenticationMap_[AUTH_TYPE_IMPORT_AUTH_CODE] = nullptr; authenticationMap_[AUTH_TYPE_CRE] = nullptr; - dmVersion_ = DM_VERSION_5_0_3; + dmVersion_ = DM_VERSION_5_0_4; } DmAuthManager::~DmAuthManager() @@ -230,7 +231,7 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, authRequestContext_->localDeviceId = localUdid; authRequestContext_->deviceId = deviceId; authRequestContext_->addr = deviceId; - authRequestContext_->dmVersion = DM_VERSION_5_0_3; + authRequestContext_->dmVersion = DM_VERSION_5_0_4; uint32_t tokenId = 0 ; MultipleUserConnector::GetTokenIdAndForegroundUserId(tokenId, authRequestContext_->localUserId); authRequestContext_->tokenId = static_cast(tokenId); @@ -861,7 +862,7 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId) authResponseContext_->localAccountId = authRequestContext_->localAccountId; authResponseContext_->localUserId = authRequestContext_->localUserId; authResponseContext_->isIdenticalAccount = false; - authResponseContext_->edition = DM_VERSION_5_0_3; + authResponseContext_->edition = DM_VERSION_5_0_4; authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_NEGOTIATE); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); @@ -885,7 +886,8 @@ void DmAuthManager::AbilityNegotiate() CompatiblePutAcl(); } authResponseContext_->reply = ERR_DM_AUTH_PEER_REJECT; - if (authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && !importAuthCode_.empty()) { + 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 { @@ -1043,7 +1045,8 @@ void DmAuthManager::GetAuthRequestContext() void DmAuthManager::ProcessAuthRequestExt(const int32_t &sessionId) { LOGI("ProcessAuthRequestExt start."); - if (authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && + if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_3)) && + authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && !authResponseContext_->importAuthCode.empty() && !importAuthCode_.empty()) { if (authResponseContext_->importAuthCode != Crypto::Sha256(importAuthCode_)) { SetReasonAndFinish(ERR_DM_AUTH_CODE_INCORRECT, AuthState::AUTH_REQUEST_FINISH); @@ -1056,7 +1059,8 @@ void DmAuthManager::ProcessAuthRequestExt(const int32_t &sessionId) DeviceProfileConnector::GetInstance().SyncAclByBindType(authResponseContext_->hostPkgName, authResponseContext_->bindType, authResponseContext_->localDeviceId, authResponseContext_->deviceId); authResponseContext_->authed = !bindType.empty(); - if (authResponseContext_->isOnline && authResponseContext_->authed && + if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_3)) && + authResponseContext_->isOnline && authResponseContext_->authed && authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && (authResponseContext_->importAuthCode.empty() || importAuthCode_.empty())) { SetReasonAndFinish(ERR_DM_AUTH_CODE_INCORRECT, AuthState::AUTH_REQUEST_FINISH); @@ -2326,7 +2330,7 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) authResponseContext_->localDeviceId, authResponseContext_->deviceId); authResponseContext_->authed = !authResponseContext_->bindType.empty(); if (authResponseContext_->authed && authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && - !importAuthCode_.empty()) { + !importAuthCode_.empty() && !CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_3))) { authResponseContext_->importAuthCode = Crypto::Sha256(importAuthCode_); } @@ -2821,14 +2825,14 @@ void DmAuthManager::ConverToFinish() void DmAuthManager::RequestReCheckMsg() { - LOGI("dmVersion %{public}s.", DM_VERSION_5_0_3); + LOGI("dmVersion %{public}s.", DM_VERSION_5_0_4); char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); uint32_t tokenId = 0; int32_t localUserId = 0; MultipleUserConnector::GetTokenIdAndForegroundUserId(tokenId, localUserId); std::string localAccountId = MultipleUserConnector::GetOhosAccountIdByUserId(localUserId); - authResponseContext_->edition = DM_VERSION_5_0_3; + authResponseContext_->edition = DM_VERSION_5_0_4; authResponseContext_->localDeviceId = static_cast(localDeviceId); authResponseContext_->localUserId = localUserId; authResponseContext_->localAccountId = localAccountId; @@ -2855,7 +2859,7 @@ void DmAuthManager::ResponseReCheckMsg() } char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - authResponseContext_->edition = DM_VERSION_5_0_3; + authResponseContext_->edition = DM_VERSION_5_0_4; authResponseContext_->localDeviceId = std::string(localDeviceId); authResponseContext_->localUserId = MultipleUserConnector::GetFirstForegroundUserId(); authResponseContext_->localAccountId =