!116 add GetPkInfoList interface

Merge pull request !116 from 符子坤/master
This commit is contained in:
openharmony_ci
2021-12-07 07:30:12 +00:00
committed by Gitee
5 changed files with 146 additions and 6 deletions
+2
View File
@@ -60,6 +60,7 @@ extern "C" {
#define PARAM_TYPE_DEVICE_INFO 29
#define PARAM_TYPE_AUTH_PARAMS 30
#define PARAM_TYPE_CB_OBJECT 31
#define PARAM_TYPE_RETURN_DATA 32
enum {
IPC_CALL_ID_REG_CB = 1,
@@ -85,6 +86,7 @@ enum {
IPC_CALL_ID_GET_GROUP_FRIEND,
IPC_CALL_ID_GET_GROUP_INFO,
IPC_CALL_ID_SEARCH_GROUPS,
IPC_CALL_ID_GET_PK_INFO_LIST,
IPC_CALL_ID_GET_JOINED_GROUPS,
IPC_CALL_ID_GET_RELATED_GROUPS,
IPC_CALL_ID_GET_DEV_INFO_BY_ID,
+82
View File
@@ -97,6 +97,7 @@ static void GetIpcReplyByType(const IpcDataInfo *ipcData,
case PARAM_TYPE_FRIEND_APPID:
case PARAM_TYPE_DEVICE_INFO:
case PARAM_TYPE_GROUP_INFO:
case PARAM_TYPE_RETURN_DATA:
*(uint8_t **)outCache = ipcData[i].val;
if (cacheLen != NULL) {
*cacheLen = ipcData[i].valSz;
@@ -1287,6 +1288,86 @@ static int32_t IpcGmGetGroupInfoById(const char *appId, const char *groupId, cha
return ret;
}
static int32_t ParseReturnResult(const IpcDataInfo *replies,
int32_t cacheNum, char **returnData, uint32_t *returnNum)
{
int32_t ret;
int32_t inOutLen;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) {
return HC_ERR_IPC_OUT_DATA_NUM;
}
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_RETURN_DATA, (uint8_t *)returnData, NULL);
if (*returnData == NULL) {
return HC_ERR_IPC_OUT_DATA;
}
*returnData = strdup(*returnData);
if (*returnData == NULL) {
return HC_ERR_ALLOC_MEMORY;
}
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)returnNum, &inOutLen);
return HC_SUCCESS;
}
static int32_t IpcGmGetPkInfoList(const char *appId, const char *queryParams, char **returnInfoList,
uint32_t *returnInfoNum)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache[IPC_DATA_CACHES_4] = {{0}};
LOGI("starting ...");
if (!IS_STRING_VALID(queryParams) || !IS_STRING_VALID(appId) ||
(returnInfoList == NULL) || (returnInfoNum == NULL)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_QUERY_PARAMS,
(const uint8_t *)queryParams, strlen(queryParams) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_QUERY_PARAMS);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_PK_INFO_LIST, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
if (ret != HC_SUCCESS) {
DestroyCallCtx(&callCtx, NULL);
return ret;
}
ret = ParseReturnResult(replyCache, REPLAY_CACHE_NUM(replyCache), returnInfoList, returnInfoNum);
LOGI("proc result done, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return ret;
}
static int32_t SearchGroupsIpcResult(const IpcDataInfo *replies,
int32_t cacheNum, char **outGroupVec, uint32_t *groupNum)
{
@@ -1803,6 +1884,7 @@ static void InitIpcGmMethods(DeviceGroupManager *gmMethodObj)
gmMethodObj->getDeviceInfoById = IpcGmGetDeviceInfoById;
gmMethodObj->getTrustedDevices = IpcGmGetTrustedDevices;
gmMethodObj->checkAccessToGroup = IpcGmCheckAccessToGroup;
gmMethodObj->getPkInfoList = IpcGmGetPkInfoList;
gmMethodObj->isDeviceInGroup = IpcGmIsDeviceInGroup;
gmMethodObj->destroyInfo = IpcGmDestroyInfo;
gmMethodObj->authKeyAgree = IpcGmAuthKeyAgree;
+38
View File
@@ -562,6 +562,43 @@ static int32_t IpcServiceGmApplyRegisterInfo(const IpcDataInfo *ipcParams, int32
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGmGetPkInfoList(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const char *queryParams = NULL;
char *returnInfoList = NULL;
uint32_t returnInfoNum = 0;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((appId == NULL) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return HC_ERR_IPC_BAD_PARAM;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_QUERY_PARAMS, (uint8_t *)&queryParams, NULL);
if ((queryParams == NULL) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_QUERY_PARAMS);
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.getPkInfoList(appId, queryParams, &returnInfoList, &returnInfoNum);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
(const uint8_t *)&g_ipcResultNum2, sizeof(int32_t));
if (returnInfoList != NULL) {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)returnInfoList,
strlen(returnInfoList) + 1);
} else {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0);
}
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&returnInfoNum, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
g_devGroupMgrMethod.destroyInfo(&returnInfoList);
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGmAddGroupManager(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
@@ -1239,6 +1276,7 @@ static int32_t AddMethodMap(uintptr_t ipcInstance)
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetDeviceInfoById, IPC_CALL_ID_GET_DEV_INFO_BY_ID);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetTrustedDevices, IPC_CALL_ID_GET_TRUST_DEVICES);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmIsDeviceInGroup, IPC_CALL_ID_IS_DEV_IN_GROUP);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetPkInfoList, IPC_CALL_ID_GET_PK_INFO_LIST);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGaProcessData, IPC_CALL_ID_GA_PROC_DATA);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGaQueryTrustedDeviceNum, IPC_CALL_ID_QUERY_TRUST_DEV_NUM);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGaIsTrustedDevice, IPC_CALL_ID_IS_TRUST_DEVICE);
@@ -97,6 +97,7 @@ static void DoOnChannelOpened(HcTaskBase *baseTask)
LOGE("The input task is NULL!");
return;
}
LOGI("[Start]: DoOnChannelOpened!");
SoftBusTask *task = (SoftBusTask *)baseTask;
OnChannelOpened(task->requestId, task->channelId);
}
@@ -15,6 +15,7 @@
#include "group_operation.h"
#include "alg_defs.h"
#include "broadcast_manager.h"
#include "callback_manager.h"
#include "database_manager.h"
@@ -187,13 +188,28 @@ static bool IsQueryParamsValid(int groupType, const char *groupId, const char *g
static int32_t QueryRelatedGroupsForGetPk(const char *udid, GroupInfoVec *groupInfoVec)
{
(void)udid;
GroupQueryParams dbQueryParams = { 0 };
dbQueryParams.visibility = GROUP_VISIBILITY_PUBLIC;
dbQueryParams.type = PEER_TO_PEER_GROUP;
dbQueryParams.udid = NULL;
dbQueryParams.authId = NULL;
return GetJoinedGroupInfoVecByDevId(&dbQueryParams, groupInfoVec);
if (udid != NULL) {
uint32_t peerUdidLen = HcStrlen(udid) + 1;
dbQueryParams.udid = (char *)HcMalloc(peerUdidLen, 0);
if (dbQueryParams.udid == NULL) {
LOGE("Failed to allocate memory for queryParams of udid!");
return HC_ERR_ALLOC_MEMORY;
}
if (strcpy_s(dbQueryParams.udid, peerUdidLen, udid) != EOK) {
LOGE("Failed to copy udid for queryParams!");
HcFree(dbQueryParams.udid);
dbQueryParams.udid = NULL;
return HC_ERR_MEMORY_COPY;
}
}
int32_t result = GetJoinedGroupInfoVecByDevId(&dbQueryParams, groupInfoVec);
HcFree(dbQueryParams.udid);
return result;
}
static int32_t GetPkByParams(const char *groupId, const DeviceInfo *deviceInfo, char *returnPkHexStr,
@@ -228,9 +244,10 @@ static int32_t GetPkByParams(const char *groupId, const DeviceInfo *deviceInfo,
if (res != HC_SUCCESS) {
return res;
}
if (ByteToHexString(returnPkBuff.val, returnPkBuff.length, returnPkHexStr, returnPkHexStrLen) != HC_SUCCESS) {
LOGE("Failed to convert bytes to string!");
return HC_ERR_CONVERT_FAILED;
res = GetHashResult(returnPkBuff.val, returnPkBuff.length, returnPkHexStr, returnPkHexStrLen);
if (res != HC_SUCCESS) {
LOGE("Failed to get hash for pk!");
return HC_ERR_HASH_FAIL;
}
return HC_SUCCESS;
}
@@ -247,7 +264,7 @@ static int32_t GeneratePkInfo(const char *queryUdid, const char *groupId, CJson
DestroyDeviceInfoStruct(deviceInfo);
return res;
}
char returnPkHexStr[BYTE_TO_HEX_OPER_LENGTH * PUBLIC_KEY_MAX_LENGTH + 1] = { 0 };
char returnPkHexStr[SHA256_LEN * BYTE_TO_HEX_OPER_LENGTH + 1] = { 0 };
res = GetPkByParams(groupId, deviceInfo, returnPkHexStr, sizeof(returnPkHexStr));
DestroyDeviceInfoStruct(deviceInfo);
if (res != HC_SUCCESS) {