From 60258c9c75577496ef8026646f27d1e68e53275d Mon Sep 17 00:00:00 2001 From: "@shi-xiaoxiao-iris" Date: Mon, 4 Jul 2022 17:05:51 +0800 Subject: [PATCH 1/5] =?UTF-8?q?[=E9=9C=80=E6=B1=82]=E5=87=AD=E6=8D=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E8=BF=9C=E7=AB=AF=E5=8A=9F=E8=83=BD=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: @shi-xiaoxiao-iris --- common/include/dm_constants.h | 1 + .../credential/dm_credential_manager.h | 10 +- .../dependency/hichain/hichain_connector.h | 15 +- .../src/credential/dm_credential_manager.cpp | 208 +++++++++++++++++- .../dependency/hichain/hichain_connector.cpp | 96 ++++++++ 5 files changed, 326 insertions(+), 4 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 72ee5cbc..39988888 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -222,6 +222,7 @@ const std::string FIELD_PROCESS_TYPE = "processType"; const std::string FIELD_AUTH_TYPE = "authType"; const std::string FIELD_CREDENTIAL_DATA = "credentialData"; const std::string FIELD_CREDENTIAL_ID = "credentialId"; +const std::string FIELD_PEER_CREDENTIAL_INFO = "peerCredentialInfo"; const int32_t SAME_ACCOUNT_TYPE = 1; const int32_t CROSS_ACCOUNT_TYPE = 2; const int32_t PIN_CODE_NETWORK = 0; diff --git a/services/implementation/include/credential/dm_credential_manager.h b/services/implementation/include/credential/dm_credential_manager.h index 0cab7bad..845ff6bb 100644 --- a/services/implementation/include/credential/dm_credential_manager.h +++ b/services/implementation/include/credential/dm_credential_manager.h @@ -74,12 +74,19 @@ public: int32_t ImportLocalCredential(const std::string &credentialInfo); /** - * @tc.name: HiChainConnector::ImportRemoteCredential + * @tc.name: DmCredentialManager::ImportRemoteCredential * @tc.desc: Import Symmetry Credential Info of the DmCredential Manager * @tc.type: FUNC */ int32_t ImportRemoteCredential(const std::string &credentialInfo); + /** + * @tc.name: DmCredentialManager::DeleteRemoteCredential + * @tc.desc: delete Symmetry Credential Info of the DmCredential Manager + * @tc.type: FUNC + */ + int32_t DeleteRemoteCredential(const std::string &credentialInfo); + /** * @tc.name: HiChainConnector::DeleteCredential * @tc.desc: Delete Credential Info of the DmCredential Manager @@ -103,6 +110,7 @@ private: private: int32_t GetCredentialData(const std::string &credentialInfo, const CredentialData &inputCreData, nlohmann::json &jsonOutObj); + int32_t GetAddDeviceList(const nlohmann::json &jsonObject, nlohmann::json &jsonDeviceList); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/include/dependency/hichain/hichain_connector.h b/services/implementation/include/dependency/hichain/hichain_connector.h index 522f8377..c737fbf4 100644 --- a/services/implementation/include/dependency/hichain/hichain_connector.h +++ b/services/implementation/include/dependency/hichain/hichain_connector.h @@ -175,6 +175,19 @@ public: */ int32_t getRegisterInfo(const std::string &queryParams, std::string &returnJsonStr); + /** + * @tc.name: HiChainConnector::addMultiMembers + * @tc.desc: Get RegisterInfo Info of the HiChain Connector + * @tc.type: FUNC + */ + int32_t addMultiMembers(const int32_t groupType, const std::string userId, const nlohmann::json &jsonDeviceList); + + /** + * @tc.name: HiChainConnector::deleteMultiMembers + * @tc.desc: Get RegisterInfo Info of the HiChain Connector + * @tc.type: FUNC + */ + int32_t deleteMultiMembers(const int32_t groupType, const std::string userId, const nlohmann::json &jsonDeviceList); private: int64_t GenRequestId(); int32_t SyncGroups(std::string deviceId, std::vector &remoteGroupIdList); @@ -187,7 +200,7 @@ private: bool IsGroupInfoInvalid(GroupInfo &group); int32_t GetStrFieldByType(const std::string &reqJsonStr, const std::string &outField, int32_t type); int32_t GetNumsFieldByType(const std::string &reqJsonStr, int32_t &outField, int32_t type); - + int32_t GetGroupId(const std::string userId, const int32_t groupType, std::string &groupId); private: const DeviceGroupManager *deviceGroupManager_ = nullptr; DeviceAuthCallback deviceAuthCallback_; diff --git a/services/implementation/src/credential/dm_credential_manager.cpp b/services/implementation/src/credential/dm_credential_manager.cpp index b6b7a3b7..0601e1f3 100644 --- a/services/implementation/src/credential/dm_credential_manager.cpp +++ b/services/implementation/src/credential/dm_credential_manager.cpp @@ -24,6 +24,24 @@ namespace OHOS { namespace DistributedHardware { +struct CredentialDataInfo { + int32_t credentialType; + std::string credentailId; + std::string serverPk; + std::string pkInfoSignature; + std::string pkInfo; + std::string authCode; + std::string peerDeviceId; + std::string userId; + CredentialDataInfo() : credentialType(0) + { + } +}; + +struct PeerCredentialInfo { + std::string peerDeviceId; + std::string peerCredentialId; +}; void from_json(const nlohmann::json &jsonObject, CredentialData &credentialData) { if (!jsonObject.contains(FIELD_CREDENTIAL_TYPE) || !jsonObject.contains(FIELD_CREDENTIAL_ID) || @@ -100,7 +118,7 @@ int32_t DmCredentialManager::ImportCredential(const std::string &pkgName, const if (processType == LOCAL_CREDENTIAL_DEAL_TYPE) { return ImportLocalCredential(credentialInfo); } else if (processType == REMOTE_CREDENTIAL_DEAL_TYPE) { - return DM_OK; + return ImportRemoteCredential(credentialInfo); } else { LOGE("credential type error!"); } @@ -185,7 +203,7 @@ int32_t DmCredentialManager::DeleteCredential(const std::string &pkgName, const if (processType == LOCAL_CREDENTIAL_DEAL_TYPE) { return hiChainConnector_->DeleteGroup(requestId_, userId, authType); } else if (processType == REMOTE_CREDENTIAL_DEAL_TYPE) { - return DM_OK; + return DeleteRemoteCredential(deleteInfo); } else { LOGE("credential type error!"); } @@ -267,5 +285,191 @@ int32_t DmCredentialManager::GetCredentialData(const std::string &credentialInfo jsonOutObj = jsonCreObj; return DM_OK; } + +void from_json(const nlohmann::json &jsonObject, CredentialDataInfo &credentialDataInfo) +{ + if (!jsonObject.contains(FIELD_CREDENTIAL_TYPE)) { + LOGE("credentialType json key Not exist"); + return; + } + jsonObject[FIELD_CREDENTIAL_TYPE].get_to(credentialDataInfo.credentialType); + if (jsonObject.contains(FIELD_CREDENTIAL_ID)) { + jsonObject[FIELD_CREDENTIAL_ID].get_to(credentialDataInfo.credentailId); + } + if (credentialDataInfo.credentialType == NONSYMMETRY_CREDENTIAL_TYPE) { + if (jsonObject.contains(FIELD_SERVER_PK)) { + jsonObject[FIELD_SERVER_PK].get_to(credentialDataInfo.serverPk); + } + if (jsonObject.contains(FIELD_PKINFO_SIGNATURE)) { + jsonObject[FIELD_PKINFO_SIGNATURE].get_to(credentialDataInfo.pkInfoSignature); + } + if (jsonObject.contains(FIELD_PKINFO)) { + nlohmann::json jsonPkInfo = jsonObject[FIELD_PKINFO]; + credentialDataInfo.pkInfo = jsonPkInfo.dump().c_str(); + } + } else if (credentialDataInfo.credentialType == SYMMETRY_CREDENTIAL_TYPE) { + if (jsonObject.contains(FIELD_AUTH_CODE)) { + jsonObject[FIELD_AUTH_CODE].get_to(credentialDataInfo.authCode); + } + } + if (jsonObject.contains(FIELD_PEER_DEVICE_ID)) { + jsonObject[FIELD_PEER_DEVICE_ID].get_to(credentialDataInfo.peerDeviceId); + } +} + +void to_json(nlohmann::json &jsonObject, const CredentialDataInfo &credentialDataInfo) +{ + jsonObject[FIELD_DEVICE_ID] = credentialDataInfo.peerDeviceId; + jsonObject[FIELD_UDID] =credentialDataInfo.peerDeviceId; + jsonObject[FIELD_USER_ID] = credentialDataInfo.userId; + jsonObject[FIELD_CREDENTIAL_TYPE] = credentialDataInfo.credentialType; + jsonObject[FIELD_CREDENTIAL_ID] = atoi(credentialDataInfo.credentailId.c_str()); + if (credentialDataInfo.credentialType == NONSYMMETRY_CREDENTIAL_TYPE) { + jsonObject[FIELD_SERVER_PK] = credentialDataInfo.serverPk; + jsonObject[FIELD_PKINFO_SIGNATURE] = credentialDataInfo.pkInfoSignature; + jsonObject[FIELD_PKINFO] = credentialDataInfo.pkInfo; + } else if (credentialDataInfo.credentialType == SYMMETRY_CREDENTIAL_TYPE) { + jsonObject[FIELD_AUTH_CODE] = credentialDataInfo.authCode; + } +} + +int32_t DmCredentialManager::GetAddDeviceList(const nlohmann::json &jsonObject, nlohmann::json &jsonDeviceList) +{ + if (!jsonObject.contains(FIELD_CREDENTIAL_DATA) || !jsonObject.contains(FIELD_AUTH_TYPE)) { + LOGE("credentaildata or authType string key not exist!"); + return ERR_DM_FAILED; + } + nlohmann::json credentialJson = jsonObject[FIELD_CREDENTIAL_DATA]; + auto credentialDataList = credentialJson.get>(); + int32_t authType = jsonObject[FIELD_AUTH_TYPE]; + + for (auto &credentialData : credentialDataList) { + if (authType == SAME_ACCOUNT_TYPE) { + if (jsonObject.contains(FIELD_USER_ID)) { + credentialData.userId = jsonObject[FIELD_USER_ID]; + } + } else if (authType == CROSS_ACCOUNT_TYPE) { + if (jsonObject.contains(FIELD_PEER_USER_ID)) { + credentialData.userId = jsonObject[FIELD_PEER_USER_ID]; + } + } + } + for (size_t i = 0; i < credentialDataList.size(); i++) { + jsonDeviceList[FIELD_DEVICE_LIST][i] = credentialDataList.at(i); + } + return DM_OK; +} + +int32_t DmCredentialManager::ImportRemoteCredential(const std::string &credentialInfo) +{ + nlohmann::json jsonObject = nlohmann::json::parse(credentialInfo, nullptr, false); + if (jsonObject.is_discarded()) { + LOGE("credentialInfo string not a json type."); + return ERR_DM_FAILED; + } + if (!jsonObject.contains(FIELD_AUTH_TYPE) || !jsonObject.contains(FIELD_CREDENTIAL_DATA)) { + LOGE("auth type, credentialData string key not exist!"); + return ERR_DM_FAILED; + } + int32_t authType = jsonObject[FIELD_AUTH_TYPE]; + std::string userId; + int32_t groupType = 0; + if (authType == SAME_ACCOUNT_TYPE) { + groupType = IDENTICAL_ACCOUNT_GROUP; + if (!jsonObject.contains(FIELD_USER_ID)) { + LOGE("userId string key not exist!"); + return ERR_DM_FAILED; + } else { + userId = jsonObject[FIELD_USER_ID]; + } + } else if (authType == CROSS_ACCOUNT_TYPE) { + groupType = ACROSS_ACCOUNT_AUTHORIZE_GROUP; + if (!jsonObject.contains(FIELD_PEER_USER_ID)) { + LOGE("peerUserId string key not exist!"); + return ERR_DM_FAILED; + } else { + userId = jsonObject[FIELD_PEER_USER_ID]; + } + } + nlohmann::json jsonDeviceList; + if (GetAddDeviceList(jsonObject, jsonDeviceList) != DM_OK) { + LOGE("failed to get add DeviceList."); + return ERR_DM_FAILED; + } + if (hiChainConnector_->addMultiMembers(groupType, userId, jsonDeviceList) != DM_OK) { + LOGE("failed to add members to group."); + return ERR_DM_FAILED; + } + LOGI("ImportRemoteCredential complete!"); + return DM_OK; +} + +void from_json(const nlohmann::json &jsonObject, PeerCredentialInfo &peerCredentialInfo) +{ + if (jsonObject.contains(FIELD_PEER_USER_ID)) { + jsonObject[FIELD_PEER_USER_ID].get_to(peerCredentialInfo.peerDeviceId); + } +} + +void to_json( nlohmann::json &jsonObject, const PeerCredentialInfo &peerCredentialInfo) +{ + jsonObject[FIELD_DEVICE_ID] = peerCredentialInfo.peerDeviceId; +} + +int32_t GetDeleteDeviceList(const nlohmann::json &jsonObject, nlohmann::json &deviceList) +{ + if (!jsonObject.contains(FIELD_PEER_CREDENTIAL_INFO)) { + LOGE("devicelist string key not exist!"); + return ERR_DM_FAILED; + } + auto peerCredentialInfo = jsonObject[FIELD_PEER_CREDENTIAL_INFO].get>(); + for (size_t i = 0; i < peerCredentialInfo.size(); i++) { + deviceList[FIELD_DEVICE_LIST][i] = peerCredentialInfo[i]; + } + return DM_OK; +} + +int32_t DmCredentialManager::DeleteRemoteCredential(const std::string &deleteInfo) +{ + nlohmann::json jsonObject = nlohmann::json::parse(deleteInfo, nullptr, false); + if (jsonObject.is_discarded()) { + LOGE("credentialInfo string not a json type."); + return ERR_DM_FAILED; + } + if (!jsonObject.contains(FIELD_AUTH_TYPE) || !jsonObject.contains(FIELD_PEER_CREDENTIAL_INFO)) { + LOGE("authType, peerCredential or peerUserId string key not exist!"); + return ERR_DM_FAILED; + } + int32_t authType = jsonObject[FIELD_AUTH_TYPE]; + std::string userId; + int32_t groupType = 0; + if (authType == SAME_ACCOUNT_TYPE) { + if (!jsonObject.contains(FIELD_USER_ID)) { + LOGE("userId string key not exist."); + return ERR_DM_FAILED; + } else { + userId = jsonObject[FIELD_USER_ID]; + } + groupType = IDENTICAL_ACCOUNT_GROUP; + } else if (authType == CROSS_ACCOUNT_TYPE) { + if (!jsonObject.contains(FIELD_PEER_USER_ID)) { + LOGE("peerUserId string key not exist."); + return ERR_DM_FAILED; + } else { + userId = jsonObject[FIELD_PEER_USER_ID]; + } + groupType = ACROSS_ACCOUNT_AUTHORIZE_GROUP; + } + nlohmann::json jsonDeviceList; + if (GetDeleteDeviceList(jsonObject, jsonDeviceList) != DM_OK) { + LOGE("failed to get delete DeviceList."); + return ERR_DM_FAILED; + } + if (hiChainConnector_->deleteMultiMembers(groupType, userId, jsonDeviceList) != DM_OK) { + LOGE("failed to delete members from group."); + return ERR_DM_FAILED; + } + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/dependency/hichain/hichain_connector.cpp b/services/implementation/src/dependency/hichain/hichain_connector.cpp index 9be5f55c..4118fcfe 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -753,5 +753,101 @@ int32_t HiChainConnector::getRegisterInfo(const std::string &queryParams, std::s LOGI("request hichain device registerinfo successfully."); return DM_OK; } + +int32_t HiChainConnector::GetGroupId(const std::string userId, const int32_t groupType, std::string &groupId) +{ + nlohmann::json jsonObjGroup; + jsonObjGroup[FIELD_GROUP_TYPE] = groupType; + std::string queryParams = jsonObjGroup.dump(); + std::vector groupList; + + if (!GetGroupInfo(queryParams.c_str(), groupList)) { + LOGE("failed to get device join groups"); + return ERR_DM_FAILED; + } + for (auto &groupinfo : groupList) { + LOGI("groupinfo.groupId:%s", groupinfo.groupId.c_str()); + if (groupinfo.userId == userId) { + groupId = groupinfo.groupId; + break; + } + } + return DM_OK; +} + +int32_t HiChainConnector::addMultiMembers(const int32_t groupType, const std::string userId, + const nlohmann::json &jsonDeviceList) +{ + if (deviceGroupManager_ == nullptr) { + LOGE("HiChainConnector::deviceGroupManager_ is nullptr."); + return ERR_DM_INPUT_PARAMETER_EMPTY; + } + LOGI("addMultiMembers in!"); + if ( userId.empty() || !jsonDeviceList.contains(FIELD_DEVICE_LIST)) { + LOGE("userId or deviceList is empty"); + return ERR_DM_INPUT_PARAMETER_EMPTY; + } + std::string groupId; + LOGI("GetGroupId before!"); + if (GetGroupId(userId, groupType, groupId) != DM_OK) { + LOGE("failed to get groupid"); + return ERR_DM_FAILED; + } + LOGI("GetGroupId end!"); + std::string appId = DM_PKG_NAME; + nlohmann::json jsonObj; + jsonObj[FIELD_GROUP_ID] = groupId; + jsonObj[FIELD_GROUP_TYPE] = groupType; + jsonObj[FIELD_DEVICE_LIST] = jsonDeviceList[FIELD_DEVICE_LIST]; + std::string addParams = jsonObj.dump(); + int32_t osAccountUserId = MultipleUserConnector::GetCurrentAccountUserID(); + if (osAccountUserId < 0) { + LOGE("get current process account user id failed"); + return ERR_DM_FAILED; + } + int32_t ret = deviceGroupManager_->addMultiMembersToGroup(osAccountUserId, + appId.c_str(), addParams.c_str()); + if (ret!= DM_OK) { + LOGE("HiChainConnector::addMultiMemberstoGroup failure! ret=%d", ret); + return ret; + } + return DM_OK; +} + +int32_t HiChainConnector::deleteMultiMembers(const int32_t groupType, const std::string userId, + const nlohmann::json &jsonDeviceList) +{ + if (deviceGroupManager_ == nullptr) { + LOGE("HiChainConnector::deviceGroupManager_ is nullptr."); + return ERR_DM_INPUT_PARAMETER_EMPTY; + } + if (userId.empty() || !jsonDeviceList.contains(FIELD_DEVICE_LIST)) { + LOGE("jsonDeviceList userId or deleteInfo string is empty"); + return ERR_DM_INPUT_PARAMETER_EMPTY; + } + std::string groupId; + if (GetGroupId(userId, groupType, groupId) != DM_OK) { + LOGE("failed to get groupid"); + return ERR_DM_FAILED; + } + std::string appId = DM_PKG_NAME; + nlohmann::json jsonObj; + jsonObj[FIELD_GROUP_ID] = groupId; + jsonObj[FIELD_GROUP_TYPE] = groupType; + jsonObj[FIELD_DEVICE_LIST] = jsonDeviceList[FIELD_DEVICE_LIST]; + std::string deleteParams = jsonObj.dump(); + int32_t osAccountUserId = MultipleUserConnector::GetCurrentAccountUserID(); + if (osAccountUserId < 0) { + LOGE("get current process account user id failed"); + return ERR_DM_FAILED; + } + int32_t ret = deviceGroupManager_->delMultiMembersFromGroup(osAccountUserId, + appId.c_str(), deleteParams.c_str()); + if (ret != DM_OK) { + LOGE("HiChainConnector::deleteMultiMembers failure!, ret=%d", ret); + return ret; + } + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS From eda7ff709852cf2342ae93818150b1bd202c25fb Mon Sep 17 00:00:00 2001 From: "@shi-xiaoxiao-iris" Date: Mon, 4 Jul 2022 17:18:56 +0800 Subject: [PATCH 2/5] =?UTF-8?q?[=E9=9C=80=E6=B1=82]=E5=87=AD=E6=8D=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E8=BF=9C=E7=AB=AF=E5=8A=9F=E8=83=BD=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: @shi-xiaoxiao-iris --- .../src/credential/dm_credential_manager.cpp | 2 +- .../src/dependency/hichain/hichain_connector.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/implementation/src/credential/dm_credential_manager.cpp b/services/implementation/src/credential/dm_credential_manager.cpp index 0601e1f3..d9a75abf 100644 --- a/services/implementation/src/credential/dm_credential_manager.cpp +++ b/services/implementation/src/credential/dm_credential_manager.cpp @@ -411,7 +411,7 @@ void from_json(const nlohmann::json &jsonObject, PeerCredentialInfo &peerCredent } } -void to_json( nlohmann::json &jsonObject, const PeerCredentialInfo &peerCredentialInfo) +void to_json(nlohmann::json &jsonObject, const PeerCredentialInfo &peerCredentialInfo) { jsonObject[FIELD_DEVICE_ID] = peerCredentialInfo.peerDeviceId; } diff --git a/services/implementation/src/dependency/hichain/hichain_connector.cpp b/services/implementation/src/dependency/hichain/hichain_connector.cpp index 4118fcfe..ff76d5fa 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -783,7 +783,7 @@ int32_t HiChainConnector::addMultiMembers(const int32_t groupType, const std::st return ERR_DM_INPUT_PARAMETER_EMPTY; } LOGI("addMultiMembers in!"); - if ( userId.empty() || !jsonDeviceList.contains(FIELD_DEVICE_LIST)) { + if (userId.empty() || !jsonDeviceList.contains(FIELD_DEVICE_LIST)) { LOGE("userId or deviceList is empty"); return ERR_DM_INPUT_PARAMETER_EMPTY; } @@ -806,7 +806,7 @@ int32_t HiChainConnector::addMultiMembers(const int32_t groupType, const std::st return ERR_DM_FAILED; } int32_t ret = deviceGroupManager_->addMultiMembersToGroup(osAccountUserId, - appId.c_str(), addParams.c_str()); + appId.c_str(), addParams.c_str()); if (ret!= DM_OK) { LOGE("HiChainConnector::addMultiMemberstoGroup failure! ret=%d", ret); return ret; @@ -815,7 +815,7 @@ int32_t HiChainConnector::addMultiMembers(const int32_t groupType, const std::st } int32_t HiChainConnector::deleteMultiMembers(const int32_t groupType, const std::string userId, - const nlohmann::json &jsonDeviceList) + const nlohmann::json &jsonDeviceList) { if (deviceGroupManager_ == nullptr) { LOGE("HiChainConnector::deviceGroupManager_ is nullptr."); @@ -842,7 +842,7 @@ int32_t HiChainConnector::deleteMultiMembers(const int32_t groupType, const std: return ERR_DM_FAILED; } int32_t ret = deviceGroupManager_->delMultiMembersFromGroup(osAccountUserId, - appId.c_str(), deleteParams.c_str()); + appId.c_str(), deleteParams.c_str()); if (ret != DM_OK) { LOGE("HiChainConnector::deleteMultiMembers failure!, ret=%d", ret); return ret; From 0d9cf47d1c5ba7de0283a35ba209daa58b492119 Mon Sep 17 00:00:00 2001 From: "@shi-xiaoxiao-iris" Date: Mon, 4 Jul 2022 20:17:48 +0800 Subject: [PATCH 3/5] =?UTF-8?q?[=E9=9C=80=E6=B1=82]=E5=87=AD=E6=8D=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E8=BF=9C=E7=AB=AF=E5=8A=9F=E8=83=BD=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: @shi-xiaoxiao-iris --- test/unittest/mock/device_auth.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unittest/mock/device_auth.h b/test/unittest/mock/device_auth.h index 5ca6d5c5..3d1a6a44 100644 --- a/test/unittest/mock/device_auth.h +++ b/test/unittest/mock/device_auth.h @@ -67,6 +67,7 @@ #define FIELD_IS_DELETE_ALL "isDeleteAll" #define FIELD_BLE_CHALLENGE "bleChallenge" #define FIELD_OS_ACCOUNT_ID "osAccountId" +#define FIELD_DEVICE_LIST "deviceList" using OsAccountEnum = enum _OsAccountEnum : int32_t { DEFAULT_OS_ACCOUNT = 0, @@ -167,6 +168,8 @@ using DeviceGroupManager = struct _DeviceGroupManager { int32_t (*deleteMemberFromGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *deleteParams); int32_t (*processData)(int64_t requestId, const uint8_t *data, uint32_t dataLen); + int32_t (*addMultiMembersToGroup)(int32_t osAccountId, const char *appId, const char *addParams); + int32_t (*delMultiMembersFromGroup)(int32_t osAccountId, const char *appId, const char *deleteParams); int32_t (*confirmRequest)(int32_t osAccountId, int64_t requestId, const char *appId, const char *confirmParams); int32_t (*bindPeer)(int64_t requestId, const char *appId, const char *bindParams); int32_t (*unbindPeer)(int64_t requestId, const char *appId, const char *unbindParams); From ae2f487d13106794a25bdca4c292f19aadeb066e Mon Sep 17 00:00:00 2001 From: "@shi-xiaoxiao-iris" Date: Tue, 5 Jul 2022 10:35:03 +0800 Subject: [PATCH 4/5] =?UTF-8?q?[=E9=9C=80=E6=B1=82]=E5=87=AD=E6=8D=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E8=BF=9C=E7=AB=AF=E5=8A=9F=E8=83=BD=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: @shi-xiaoxiao-iris --- common/include/dm_constants.h | 1 + .../include/dependency/hichain/hichain_connector.h | 6 +++--- .../src/credential/dm_credential_manager.cpp | 8 +++++--- .../src/dependency/hichain/hichain_connector.cpp | 9 +++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 39988888..1ef1c554 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -152,6 +152,7 @@ const int32_t LOCAL_CREDENTIAL_DEAL_TYPE = 1; const int32_t REMOTE_CREDENTIAL_DEAL_TYPE = 2; const int32_t NONSYMMETRY_CREDENTIAL_TYPE = 2; const int32_t SYMMETRY_CREDENTIAL_TYPE = 1; +const int32_t UNKNOWN_CREDENTIAL_TYPE = 0; // Softbus const int32_t SOFTBUS_CHECK_INTERVAL = 100000; // 100ms const uint32_t SOFTBUS_SUBSCRIBE_ID_PREFIX_LEN = 16; diff --git a/services/implementation/include/dependency/hichain/hichain_connector.h b/services/implementation/include/dependency/hichain/hichain_connector.h index c737fbf4..f3dcd1e3 100644 --- a/services/implementation/include/dependency/hichain/hichain_connector.h +++ b/services/implementation/include/dependency/hichain/hichain_connector.h @@ -180,14 +180,14 @@ public: * @tc.desc: Get RegisterInfo Info of the HiChain Connector * @tc.type: FUNC */ - int32_t addMultiMembers(const int32_t groupType, const std::string userId, const nlohmann::json &jsonDeviceList); + int32_t addMultiMembers(const int32_t groupType, const std::string &userId, const nlohmann::json &jsonDeviceList); /** * @tc.name: HiChainConnector::deleteMultiMembers * @tc.desc: Get RegisterInfo Info of the HiChain Connector * @tc.type: FUNC */ - int32_t deleteMultiMembers(const int32_t groupType, const std::string userId, const nlohmann::json &jsonDeviceList); + int32_t deleteMultiMembers(const int32_t groupType, const std::string &userId, const nlohmann::json &jsonDeviceList); private: int64_t GenRequestId(); int32_t SyncGroups(std::string deviceId, std::vector &remoteGroupIdList); @@ -200,7 +200,7 @@ private: bool IsGroupInfoInvalid(GroupInfo &group); int32_t GetStrFieldByType(const std::string &reqJsonStr, const std::string &outField, int32_t type); int32_t GetNumsFieldByType(const std::string &reqJsonStr, int32_t &outField, int32_t type); - int32_t GetGroupId(const std::string userId, const int32_t groupType, std::string &groupId); + int32_t GetGroupId(const std::string &userId, const int32_t groupType, std::string &groupId); private: const DeviceGroupManager *deviceGroupManager_ = nullptr; DeviceAuthCallback deviceAuthCallback_; diff --git a/services/implementation/src/credential/dm_credential_manager.cpp b/services/implementation/src/credential/dm_credential_manager.cpp index d9a75abf..5c3b00d7 100644 --- a/services/implementation/src/credential/dm_credential_manager.cpp +++ b/services/implementation/src/credential/dm_credential_manager.cpp @@ -33,7 +33,7 @@ struct CredentialDataInfo { std::string authCode; std::string peerDeviceId; std::string userId; - CredentialDataInfo() : credentialType(0) + CredentialDataInfo() : credentialType(UNKNOWN_CREDENTIAL_TYPE) { } }; @@ -289,7 +289,7 @@ int32_t DmCredentialManager::GetCredentialData(const std::string &credentialInfo void from_json(const nlohmann::json &jsonObject, CredentialDataInfo &credentialDataInfo) { if (!jsonObject.contains(FIELD_CREDENTIAL_TYPE)) { - LOGE("credentialType json key Not exist"); + LOGE("credentialType json key not exist"); return; } jsonObject[FIELD_CREDENTIAL_TYPE].get_to(credentialDataInfo.credentialType); @@ -311,6 +311,9 @@ void from_json(const nlohmann::json &jsonObject, CredentialDataInfo &credentialD if (jsonObject.contains(FIELD_AUTH_CODE)) { jsonObject[FIELD_AUTH_CODE].get_to(credentialDataInfo.authCode); } + } eles { + LOGE("credentialType john key is unknown"); + return; } if (jsonObject.contains(FIELD_PEER_DEVICE_ID)) { jsonObject[FIELD_PEER_DEVICE_ID].get_to(credentialDataInfo.peerDeviceId); @@ -400,7 +403,6 @@ int32_t DmCredentialManager::ImportRemoteCredential(const std::string &credentia LOGE("failed to add members to group."); return ERR_DM_FAILED; } - LOGI("ImportRemoteCredential complete!"); return DM_OK; } diff --git a/services/implementation/src/dependency/hichain/hichain_connector.cpp b/services/implementation/src/dependency/hichain/hichain_connector.cpp index ff76d5fa..c84baca0 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -754,7 +754,7 @@ int32_t HiChainConnector::getRegisterInfo(const std::string &queryParams, std::s return DM_OK; } -int32_t HiChainConnector::GetGroupId(const std::string userId, const int32_t groupType, std::string &groupId) +int32_t HiChainConnector::GetGroupId(const std::string &userId, const int32_t groupType, std::string &groupId) { nlohmann::json jsonObjGroup; jsonObjGroup[FIELD_GROUP_TYPE] = groupType; @@ -775,25 +775,22 @@ int32_t HiChainConnector::GetGroupId(const std::string userId, const int32_t gro return DM_OK; } -int32_t HiChainConnector::addMultiMembers(const int32_t groupType, const std::string userId, +int32_t HiChainConnector::addMultiMembers(const int32_t groupType, const std::string &userId, const nlohmann::json &jsonDeviceList) { if (deviceGroupManager_ == nullptr) { LOGE("HiChainConnector::deviceGroupManager_ is nullptr."); return ERR_DM_INPUT_PARAMETER_EMPTY; } - LOGI("addMultiMembers in!"); if (userId.empty() || !jsonDeviceList.contains(FIELD_DEVICE_LIST)) { LOGE("userId or deviceList is empty"); return ERR_DM_INPUT_PARAMETER_EMPTY; } std::string groupId; - LOGI("GetGroupId before!"); if (GetGroupId(userId, groupType, groupId) != DM_OK) { LOGE("failed to get groupid"); return ERR_DM_FAILED; } - LOGI("GetGroupId end!"); std::string appId = DM_PKG_NAME; nlohmann::json jsonObj; jsonObj[FIELD_GROUP_ID] = groupId; @@ -814,7 +811,7 @@ int32_t HiChainConnector::addMultiMembers(const int32_t groupType, const std::st return DM_OK; } -int32_t HiChainConnector::deleteMultiMembers(const int32_t groupType, const std::string userId, +int32_t HiChainConnector::deleteMultiMembers(const int32_t groupType, const std::string &userId, const nlohmann::json &jsonDeviceList) { if (deviceGroupManager_ == nullptr) { From 5e34cb50209723988ae4c0fffb0ed91a030b4179 Mon Sep 17 00:00:00 2001 From: "@shi-xiaoxiao-iris" Date: Tue, 5 Jul 2022 10:44:16 +0800 Subject: [PATCH 5/5] =?UTF-8?q?[=E9=9C=80=E6=B1=82]=E5=87=AD=E6=8D=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E8=BF=9C=E7=AB=AF=E5=8A=9F=E8=83=BD=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: @shi-xiaoxiao-iris --- .../include/dependency/hichain/hichain_connector.h | 7 ++++--- .../src/credential/dm_credential_manager.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/services/implementation/include/dependency/hichain/hichain_connector.h b/services/implementation/include/dependency/hichain/hichain_connector.h index f3dcd1e3..d3d9213f 100644 --- a/services/implementation/include/dependency/hichain/hichain_connector.h +++ b/services/implementation/include/dependency/hichain/hichain_connector.h @@ -180,14 +180,15 @@ public: * @tc.desc: Get RegisterInfo Info of the HiChain Connector * @tc.type: FUNC */ - int32_t addMultiMembers(const int32_t groupType, const std::string &userId, const nlohmann::json &jsonDeviceList); - + int32_t addMultiMembers(const int32_t groupType, const std::string &userId, + const nlohmann::json &jsonDeviceList); /** * @tc.name: HiChainConnector::deleteMultiMembers * @tc.desc: Get RegisterInfo Info of the HiChain Connector * @tc.type: FUNC */ - int32_t deleteMultiMembers(const int32_t groupType, const std::string &userId, const nlohmann::json &jsonDeviceList); + int32_t deleteMultiMembers(const int32_t groupType, const std::string &userId, + const nlohmann::json &jsonDeviceList); private: int64_t GenRequestId(); int32_t SyncGroups(std::string deviceId, std::vector &remoteGroupIdList); diff --git a/services/implementation/src/credential/dm_credential_manager.cpp b/services/implementation/src/credential/dm_credential_manager.cpp index 5c3b00d7..b276ea20 100644 --- a/services/implementation/src/credential/dm_credential_manager.cpp +++ b/services/implementation/src/credential/dm_credential_manager.cpp @@ -311,7 +311,7 @@ void from_json(const nlohmann::json &jsonObject, CredentialDataInfo &credentialD if (jsonObject.contains(FIELD_AUTH_CODE)) { jsonObject[FIELD_AUTH_CODE].get_to(credentialDataInfo.authCode); } - } eles { + } else { LOGE("credentialType john key is unknown"); return; }