From 733e1494c9a6ba3bcbe0eb4802d09cb171e1363c Mon Sep 17 00:00:00 2001 From: fuzikun Date: Thu, 7 Jul 2022 10:39:54 +0800 Subject: [PATCH 1/2] only not local device can be added Signed-off-by: fuzikun --- .../inc/group_operation_common.h | 1 + .../across_account_group.c | 17 ++++++++++++++- .../group_operation/group_operation_common.c | 19 +++++++++++++++++ .../identical_account_group.c | 17 ++++++++++++++- .../peer_to_peer_group/peer_to_peer_group.c | 21 +------------------ 5 files changed, 53 insertions(+), 22 deletions(-) diff --git a/services/group_manager/inc/group_operation_common.h b/services/group_manager/inc/group_operation_common.h index abe4c285..f365e712 100644 --- a/services/group_manager/inc/group_operation_common.h +++ b/services/group_manager/inc/group_operation_common.h @@ -40,6 +40,7 @@ int32_t AssertUserIdExist(const CJson *jsonParams); int32_t AssertSharedUserIdExist(const CJson *jsonParams); int32_t AssertGroupTypeMatch(int32_t inputType, int32_t targetType); int32_t AssertSameGroupNotExist(int32_t osAccountId, const char *groupId); +int32_t AssertPeerDeviceNotSelf(const char *peerUdid); int32_t CheckGroupExist(int32_t osAccountId, const char *groupId); int32_t CheckGroupNumLimit(int32_t osAccountId, int32_t groupType, const char *appId); int32_t CheckDeviceNumLimit(int32_t osAccountId, const char *groupId, const char *peerUdid); diff --git a/services/group_manager/src/group_operation/across_account_group/across_account_group.c b/services/group_manager/src/group_operation/across_account_group/across_account_group.c index e8e0d39b..f31cd190 100644 --- a/services/group_manager/src/group_operation/across_account_group/across_account_group.c +++ b/services/group_manager/src/group_operation/across_account_group/across_account_group.c @@ -366,8 +366,23 @@ static int32_t GenerateTrustedDevParams(const CJson *jsonParams, const char *gro return HC_SUCCESS; } +static int32_t CheckPeerDeviceNotSelf(const CJson *jsonParams) +{ + const char *udid = GetStringFromJson(jsonParams, FIELD_UDID); + if (udid == NULL) { + LOGE("Failed to get udid from json!"); + return HC_ERR_JSON_GET; + } + return AssertPeerDeviceNotSelf(udid); +} + static int32_t AddDeviceAndToken(int32_t osAccountId, CJson *jsonParams, CJson *deviceInfo) { + int32_t res = CheckPeerDeviceNotSelf(jsonParams); + if (res != HC_SUCCESS) { + LOGE("The peer device udid is equals to the local udid!"); + return res; + } const char *groupId = GetStringFromJson(jsonParams, FIELD_GROUP_ID); if (groupId == NULL) { LOGE("Failed to get groupId from json!"); @@ -378,7 +393,7 @@ static int32_t AddDeviceAndToken(int32_t osAccountId, CJson *jsonParams, CJson * LOGE("Failed to get credential from json!"); return HC_ERR_JSON_GET; } - int32_t res = GenerateAddTokenParams(deviceInfo, credential); + res = GenerateAddTokenParams(deviceInfo, credential); if (res != HC_SUCCESS) { return res; } diff --git a/services/group_manager/src/group_operation/group_operation_common.c b/services/group_manager/src/group_operation/group_operation_common.c index 913ba38d..e817f790 100644 --- a/services/group_manager/src/group_operation/group_operation_common.c +++ b/services/group_manager/src/group_operation/group_operation_common.c @@ -869,6 +869,25 @@ int32_t AssertSameGroupNotExist(int32_t osAccountId, const char *groupId) return HC_SUCCESS; } +int32_t AssertPeerDeviceNotSelf(const char *peerUdid) +{ + if (peerUdid == NULL) { + LOGE("The input peerUdid is NULL!"); + return HC_ERR_NULL_PTR; + } + char udid[INPUT_UDID_LEN] = { 0 }; + int32_t res = HcGetUdid((uint8_t *)udid, INPUT_UDID_LEN); + if (res != HC_SUCCESS) { + LOGE("Failed to get local udid! res: %d", res); + return HC_ERR_DB; + } + if (strcmp(peerUdid, udid) == 0) { + LOGE("You are not allowed to delete yourself!"); + return HC_ERR_INVALID_PARAMS; + } + return HC_SUCCESS; +} + int32_t CheckGroupExist(int32_t osAccountId, const char *groupId) { if (groupId == NULL) { diff --git a/services/group_manager/src/group_operation/identical_account_group/identical_account_group.c b/services/group_manager/src/group_operation/identical_account_group/identical_account_group.c index 7910ab55..723196bd 100644 --- a/services/group_manager/src/group_operation/identical_account_group/identical_account_group.c +++ b/services/group_manager/src/group_operation/identical_account_group/identical_account_group.c @@ -354,8 +354,23 @@ static int32_t GenerateTrustedDevParams(const CJson *jsonParams, const char *gro return HC_SUCCESS; } +static int32_t CheckPeerDeviceNotSelf(const CJson *jsonParams) +{ + const char *udid = GetStringFromJson(jsonParams, FIELD_UDID); + if (udid == NULL) { + LOGE("Failed to get udid from json!"); + return HC_ERR_JSON_GET; + } + return AssertPeerDeviceNotSelf(udid); +} + static int32_t AddDeviceAndToken(int32_t osAccountId, CJson *jsonParams, CJson *deviceInfo) { + int32_t res = CheckPeerDeviceNotSelf(jsonParams); + if (res != HC_SUCCESS) { + LOGE("The peer device udid is equals to the local udid!"); + return res; + } const char *groupId = GetStringFromJson(jsonParams, FIELD_GROUP_ID); if (groupId == NULL) { LOGE("Failed to get groupId from json!"); @@ -366,7 +381,7 @@ static int32_t AddDeviceAndToken(int32_t osAccountId, CJson *jsonParams, CJson * LOGE("Failed to get credential from json!"); return HC_ERR_JSON_GET; } - int32_t res = GenerateAddTokenParams(deviceInfo, credential); + res = GenerateAddTokenParams(deviceInfo, credential); if (res != HC_SUCCESS) { return res; } diff --git a/services/group_manager/src/group_operation/peer_to_peer_group/peer_to_peer_group.c b/services/group_manager/src/group_operation/peer_to_peer_group/peer_to_peer_group.c index e33cf591..9d3f5846 100644 --- a/services/group_manager/src/group_operation/peer_to_peer_group/peer_to_peer_group.c +++ b/services/group_manager/src/group_operation/peer_to_peer_group/peer_to_peer_group.c @@ -360,25 +360,6 @@ static int32_t HandleLocalUnbind(int64_t requestId, const CJson *jsonParams, return HC_SUCCESS; } -static int32_t IsPeerDeviceNotSelf(const char *peerUdid) -{ - if (peerUdid == NULL) { - LOGE("The input peerUdid is NULL!"); - return HC_ERR_NULL_PTR; - } - char udid[INPUT_UDID_LEN] = { 0 }; - int32_t res = HcGetUdid((uint8_t *)udid, INPUT_UDID_LEN); - if (res != HC_SUCCESS) { - LOGE("Failed to get local udid! res: %d", res); - return HC_ERR_DB; - } - if (strcmp(peerUdid, udid) == 0) { - LOGE("You are not allowed to delete yourself!"); - return HC_ERR_INVALID_PARAMS; - } - return HC_SUCCESS; -} - static int32_t CheckPeerDeviceStatus(int32_t osAccountId, const char *groupId, const CJson *jsonParams) { const char *peerAuthId = GetStringFromJson(jsonParams, FIELD_DELETE_ID); @@ -397,7 +378,7 @@ static int32_t CheckPeerDeviceStatus(int32_t osAccountId, const char *groupId, c DestroyDeviceEntry(deviceInfo); return result; } - result = IsPeerDeviceNotSelf(StringGet(&deviceInfo->udid)); + result = AssertPeerDeviceNotSelf(StringGet(&deviceInfo->udid)); DestroyDeviceEntry(deviceInfo); return result; } -- Gitee From d435438a543ea710baa159c52ef8273d5969b4e8 Mon Sep 17 00:00:00 2001 From: fuzikun Date: Thu, 7 Jul 2022 20:03:21 +0800 Subject: [PATCH 2/2] ensure that the peerUserId is inconsistent with the local userId Signed-off-by: fuzikun --- .../inc/group_operation_common.h | 1 - .../across_account_group.c | 21 ++++++++++++++++++- .../group_operation/group_operation_common.c | 10 --------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/services/group_manager/inc/group_operation_common.h b/services/group_manager/inc/group_operation_common.h index f365e712..3af6e244 100644 --- a/services/group_manager/inc/group_operation_common.h +++ b/services/group_manager/inc/group_operation_common.h @@ -37,7 +37,6 @@ int32_t ProcessKeyPair(int action, const CJson *jsonParams, const char *groupId) int32_t GetHashMessage(const Uint8Buff *first, const Uint8Buff *second, uint8_t **hashMessage, uint32_t *messageSize); int32_t AssertUserIdExist(const CJson *jsonParams); -int32_t AssertSharedUserIdExist(const CJson *jsonParams); int32_t AssertGroupTypeMatch(int32_t inputType, int32_t targetType); int32_t AssertSameGroupNotExist(int32_t osAccountId, const char *groupId); int32_t AssertPeerDeviceNotSelf(const char *peerUdid); diff --git a/services/group_manager/src/group_operation/across_account_group/across_account_group.c b/services/group_manager/src/group_operation/across_account_group/across_account_group.c index f31cd190..d22dbccb 100644 --- a/services/group_manager/src/group_operation/across_account_group/across_account_group.c +++ b/services/group_manager/src/group_operation/across_account_group/across_account_group.c @@ -218,6 +218,25 @@ static int32_t AssertIdenticalGroupExist(int32_t osAccountId, const CJson *jsonP return HC_SUCCESS; } +static int32_t AssertSharedUserIdValid(const CJson *jsonParams) +{ + const char *userId = GetStringFromJson(jsonParams, FIELD_USER_ID); + if (userId == NULL) { + LOGE("Failed to get userId from jsonParams!"); + return HC_ERR_JSON_GET; + } + const char *sharedUserId = GetStringFromJson(jsonParams, FIELD_PEER_USER_ID); + if (sharedUserId == NULL) { + LOGE("Failed to get sharedUserId from jsonParams!"); + return HC_ERR_JSON_GET; + } + if (strcmp(sharedUserId, userId) == 0) { + LOGE("The input peerUserId is the same as the local userId!"); + return HC_ERR_INVALID_PARAMS; + } + return HC_SUCCESS; +} + static int32_t CheckCreateParams(int32_t osAccountId, const CJson *jsonParams) { const char *appId = GetStringFromJson(jsonParams, FIELD_APP_ID); @@ -230,7 +249,7 @@ static int32_t CheckCreateParams(int32_t osAccountId, const CJson *jsonParams) ((result = CheckGroupVisibilityIfExist(jsonParams)) != HC_SUCCESS) || ((result = CheckExpireTimeIfExist(jsonParams)) != HC_SUCCESS) || ((result = AssertUserIdExist(jsonParams)) != HC_SUCCESS) || - ((result = AssertSharedUserIdExist(jsonParams)) != HC_SUCCESS) || + ((result = AssertSharedUserIdValid(jsonParams)) != HC_SUCCESS) || ((result = AssertIdenticalGroupExist(osAccountId, jsonParams)) != HC_SUCCESS)) { return result; } diff --git a/services/group_manager/src/group_operation/group_operation_common.c b/services/group_manager/src/group_operation/group_operation_common.c index e817f790..b3c94ee6 100644 --- a/services/group_manager/src/group_operation/group_operation_common.c +++ b/services/group_manager/src/group_operation/group_operation_common.c @@ -850,16 +850,6 @@ int32_t AssertUserIdExist(const CJson *jsonParams) return HC_SUCCESS; } -int32_t AssertSharedUserIdExist(const CJson *jsonParams) -{ - const char *sharedUserId = GetStringFromJson(jsonParams, FIELD_PEER_USER_ID); - if (sharedUserId == NULL) { - LOGE("Failed to get sharedUserId from jsonParams!"); - return HC_ERR_JSON_GET; - } - return HC_SUCCESS; -} - int32_t AssertSameGroupNotExist(int32_t osAccountId, const char *groupId) { if (IsGroupExistByGroupId(osAccountId, groupId)) { -- Gitee