mirror of
https://github.com/openharmony/security_deviceauth.git
synced 2026-07-20 19:04:51 -04:00
@@ -60,7 +60,6 @@ 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,
|
||||
@@ -86,7 +85,6 @@ 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,
|
||||
|
||||
@@ -97,7 +97,6 @@ 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;
|
||||
@@ -1288,86 +1287,6 @@ 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)
|
||||
{
|
||||
@@ -1884,7 +1803,6 @@ 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;
|
||||
|
||||
@@ -562,43 +562,6 @@ 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;
|
||||
@@ -1276,7 +1239,6 @@ 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);
|
||||
|
||||
@@ -169,8 +169,6 @@ typedef struct {
|
||||
int32_t (*getRegisterInfo)(char **returnRegisterInfo);
|
||||
int32_t (*getLocalConnectInfo)(char *returnInfo, int32_t bufLen);
|
||||
int32_t (*checkAccessToGroup)(const char *appId, const char *groupId);
|
||||
int32_t (*getPkInfoList)(const char *appId, const char *queryParams, char **returnInfoList,
|
||||
uint32_t *returnInfoNum);
|
||||
int32_t (*addGroupManager)(const char *appId, const char *groupId, const char *managerAppId);
|
||||
int32_t (*addGroupFriend)(const char *appId, const char *groupId, const char *friendAppId);
|
||||
int32_t (*deleteGroupManager)(const char *appId, const char *groupId, const char *managerAppId);
|
||||
|
||||
@@ -25,7 +25,6 @@ typedef struct DasAuthModuleT {
|
||||
int (*registerLocalIdentity)(const char *, const char *, Uint8Buff *, int);
|
||||
int (*unregisterLocalIdentity)(const char *, const char *, Uint8Buff *, int);
|
||||
int (*deletePeerAuthInfo)(const char *, const char *, Uint8Buff *, int);
|
||||
int (*getPublicKey)(const char *, const char *, Uint8Buff *, int, Uint8Buff *);
|
||||
} DasAuthModule;
|
||||
|
||||
bool IsDasSupported(void);
|
||||
|
||||
@@ -39,7 +39,5 @@ void DestroyDasProtocolEntities(void);
|
||||
int32_t RegisterLocalIdentityInTask(const char *pkgName, const char *serviceType, Uint8Buff *authId, int userType);
|
||||
int32_t UnregisterLocalIdentityInTask(const char *pkgName, const char *serviceType, Uint8Buff *authId, int userType);
|
||||
int32_t DeletePeerAuthInfoInTask(const char *pkgName, const char *serviceType, Uint8Buff *authIdPeer, int userTypePeer);
|
||||
int32_t GetPublicKeyInTask(const char *pkgName, const char *serviceType, Uint8Buff *authIdPeer, int userTypePeer,
|
||||
Uint8Buff *returnPk);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,7 +24,6 @@ typedef struct TokenManagerT {
|
||||
int (*unregisterLocalIdentity)(const char *, const char *, Uint8Buff *, int);
|
||||
int (*deletePeerAuthInfo)(const char *, const char *, Uint8Buff *, int);
|
||||
int (*computeAndSavePsk)(const PakeParams *);
|
||||
int (*getPublicKey)(const char *, const char *, Uint8Buff *, int, Uint8Buff *);
|
||||
} TokenManager;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -44,12 +44,6 @@ static int32_t DeleteDasPeerAuthInfo(const char *pkgName, const char *serviceTyp
|
||||
return DeletePeerAuthInfoInTask(pkgName, serviceType, authId, userType);
|
||||
}
|
||||
|
||||
static int32_t GetDasPublicKey(const char *pkgName, const char *serviceType, Uint8Buff *authId, int userType,
|
||||
Uint8Buff *returnPk)
|
||||
{
|
||||
return GetPublicKeyInTask(pkgName, serviceType, authId, userType, returnPk);
|
||||
}
|
||||
|
||||
bool IsDasMsgNeedIgnore(const CJson *in)
|
||||
{
|
||||
uint32_t message = 0;
|
||||
@@ -153,7 +147,6 @@ AuthModuleBase *CreateDasModule(void)
|
||||
g_dasModule.registerLocalIdentity = RegisterDasLocalIdentity;
|
||||
g_dasModule.unregisterLocalIdentity = UnregisterDasLocalIdentity;
|
||||
g_dasModule.deletePeerAuthInfo = DeleteDasPeerAuthInfo;
|
||||
g_dasModule.getPublicKey = GetDasPublicKey;
|
||||
g_taskInModuleVec = CREATE_HC_VECTOR(TaskInModuleVec)
|
||||
if (InitDasProtocolEntities() != HC_SUCCESS) {
|
||||
LOGE("Init das protocol entities failed.");
|
||||
|
||||
@@ -469,25 +469,6 @@ int32_t DeletePeerAuthInfoInTask(const char *pkgName, const char *serviceType, U
|
||||
return res;
|
||||
}
|
||||
|
||||
int32_t GetPublicKeyInTask(const char *pkgName, const char *serviceType, Uint8Buff *authIdPeer, int userTypePeer,
|
||||
Uint8Buff *returnPk)
|
||||
{
|
||||
uint32_t index;
|
||||
void **ptr = NULL;
|
||||
FOR_EACH_HC_VECTOR(g_protocolEntityVec, index, ptr) {
|
||||
if (ptr != NULL && (*ptr) != NULL) {
|
||||
DasProtocolEntity *temp = (DasProtocolEntity *)(*ptr);
|
||||
if ((temp->tokenManagerInstance == NULL) || (temp->tokenManagerInstance->getPublicKey == NULL)) {
|
||||
LOGD("Protocol type: %d, unsupported method!", temp->type);
|
||||
continue;
|
||||
}
|
||||
return temp->tokenManagerInstance->getPublicKey(pkgName, serviceType, authIdPeer, userTypePeer, returnPk);
|
||||
}
|
||||
}
|
||||
LOGE("Failed to find valid protocol!");
|
||||
return HC_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
static uint32_t GetPakeAlgInProtocol(int offset)
|
||||
{
|
||||
uint32_t algInProtocol = PSK_SPEKE;
|
||||
|
||||
-1
@@ -74,7 +74,6 @@ TokenManager g_symTokenManagerInstance = {
|
||||
.unregisterLocalIdentity = UnregisterLocalIdentity,
|
||||
.deletePeerAuthInfo = DeletePeerAuthInfo,
|
||||
.computeAndSavePsk = NULL,
|
||||
.getPublicKey = NULL
|
||||
};
|
||||
|
||||
const TokenManager *GetLiteTokenManagerInstance(void)
|
||||
|
||||
-31
@@ -166,42 +166,11 @@ static int32_t ComputeAndSavePsk(const PakeParams *params)
|
||||
return res;
|
||||
}
|
||||
|
||||
static int32_t GetPublicKey(const char *pkgName, const char *serviceType, Uint8Buff *authId, int userType,
|
||||
Uint8Buff *returnPk)
|
||||
{
|
||||
const AlgLoader *loader = GetLoaderInstance();
|
||||
Uint8Buff pkgNameBuff = { (uint8_t *)pkgName, strlen(pkgName) };
|
||||
Uint8Buff serviceTypeBuff = { (uint8_t *)serviceType, strlen(serviceType) };
|
||||
KeyAliasType keyType = userType;
|
||||
uint8_t keyAliasVal[PAKE_KEY_ALIAS_LEN] = { 0 };
|
||||
Uint8Buff keyAliasBuff = { keyAliasVal, PAKE_KEY_ALIAS_LEN };
|
||||
int32_t res = GenerateKeyAlias(&pkgNameBuff, &serviceTypeBuff, keyType, authId, &keyAliasBuff);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Failed to generate keyPair alias!");
|
||||
return res;
|
||||
}
|
||||
|
||||
res = loader->checkKeyExist(&keyAliasBuff);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Key pair is not exist!");
|
||||
return res;
|
||||
}
|
||||
|
||||
res = loader->exportPublicKey(&keyAliasBuff, returnPk);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Failed to export public key!");
|
||||
return res;
|
||||
}
|
||||
LOGI("Get public key successfully!");
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
TokenManager g_asyTokenManagerInstance = {
|
||||
.registerLocalIdentity = RegisterLocalIdentity,
|
||||
.unregisterLocalIdentity = UnregisterLocalIdentity,
|
||||
.deletePeerAuthInfo = DeletePeerAuthInfo,
|
||||
.computeAndSavePsk = ComputeAndSavePsk,
|
||||
.getPublicKey = GetPublicKey
|
||||
};
|
||||
|
||||
const TokenManager *GetStandardTokenManagerInstance()
|
||||
|
||||
@@ -281,7 +281,6 @@ DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance(void)
|
||||
g_groupManagerInstance->getRegisterInfo = GetRegisterInfo;
|
||||
g_groupManagerInstance->getLocalConnectInfo = NULL;
|
||||
g_groupManagerInstance->checkAccessToGroup = CheckAccessToGroupImpl;
|
||||
g_groupManagerInstance->getPkInfoList = GetPkInfoListImpl;
|
||||
g_groupManagerInstance->addGroupManager = AddGroupManagerImpl;
|
||||
g_groupManagerInstance->deleteGroupManager = DeleteGroupManagerImpl;
|
||||
g_groupManagerInstance->getGroupManagers = GetGroupManagersImpl;
|
||||
|
||||
@@ -46,8 +46,6 @@ int32_t UnregisterLocalIdentity(const char *pkgName, const char *serviceType, Ui
|
||||
int moduleType);
|
||||
int32_t DeletePeerAuthInfo(const char *pkgName, const char *serviceType, Uint8Buff *authId, int userType,
|
||||
int moduleType);
|
||||
int32_t GetPublicKey(const char *pkgName, const char *serviceType, Uint8Buff *authId, int userType,
|
||||
int moduleType, Uint8Buff *returnPk);
|
||||
|
||||
// for ACCOUNT
|
||||
int32_t ProcessCredentials(int credentialOpCode, const CJson *in, CJson *out, int moduleType);
|
||||
|
||||
@@ -146,27 +146,6 @@ int32_t DeletePeerAuthInfo(const char *pkgName, const char *serviceType, Uint8Bu
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t GetPublicKey(const char *pkgName, const char *serviceType, Uint8Buff *authId, int userType,
|
||||
int moduleType, Uint8Buff *returnPk)
|
||||
{
|
||||
if (!IsParamsForDasTokenManagerValid(pkgName, serviceType, authId, userType, moduleType) || returnPk == NULL) {
|
||||
LOGE("Params for GetPublicKey is invalid.");
|
||||
return HC_ERR_INVALID_PARAMS;
|
||||
}
|
||||
AuthModuleBase *module = GetModule(moduleType);
|
||||
if (module == NULL) {
|
||||
LOGE("Failed to get module for das.");
|
||||
return HC_ERR_MODULE_NOT_FOUNT;
|
||||
}
|
||||
DasAuthModule *dasModule = (DasAuthModule *)module;
|
||||
int32_t res = dasModule->getPublicKey(pkgName, serviceType, authId, userType, returnPk);
|
||||
if (res != HC_SUCCESS) {
|
||||
LOGE("Get public key failed, res: %d", res);
|
||||
return res;
|
||||
}
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ProcessTask(int taskId, const CJson *in, CJson *out, int *status, int moduleType)
|
||||
{
|
||||
if (in == NULL || out == NULL || status == NULL) {
|
||||
|
||||
@@ -47,7 +47,6 @@ int32_t RegListenerImpl(const char *appId, const DataChangeListener *listener);
|
||||
int32_t UnRegListenerImpl(const char *appId);
|
||||
|
||||
int32_t CheckAccessToGroupImpl(const char *appId, const char *groupId);
|
||||
int32_t GetPkInfoListImpl(const char *appId, const char *queryParams, char **returnInfoList, uint32_t *returnInfoNum);
|
||||
int32_t GetGroupInfoByIdImpl(const char *appId, const char *groupId, char **returnGroupInfo);
|
||||
int32_t GetGroupInfoImpl(const char *appId, const char *queryParams, char **returnGroupVec, uint32_t *groupNum);
|
||||
int32_t GetJoinedGroupsImpl(const char *appId, int groupType, char **returnGroupVec, uint32_t *groupNum);
|
||||
|
||||
@@ -41,8 +41,6 @@ typedef struct {
|
||||
int32_t (*regListener)(const char *appId, const DataChangeListener *listener);
|
||||
int32_t (*unRegListener)(const char *appId);
|
||||
int32_t (*checkAccessToGroup)(const char *appId, const char *groupId);
|
||||
int32_t (*getPkInfoList)(const char *appId, const char *queryParams, char **returnInfoList,
|
||||
uint32_t *returnInfoNum);
|
||||
int32_t (*getAccessibleGroupInfoById)(const char *appId, const char *groupId, char **returnGroupInfo);
|
||||
int32_t (*getAccessibleGroupInfo)(const char *appId, const char *queryParams, char **returnGroupVec,
|
||||
uint32_t *groupNum);
|
||||
|
||||
@@ -117,12 +117,6 @@ int32_t CheckAccessToGroupImpl(const char *appId, const char *groupId)
|
||||
return IsGroupSupport() ? GetGroupImplInstance()->checkAccessToGroup(appId, groupId) : HC_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int32_t GetPkInfoListImpl(const char *appId, const char *queryParams, char **returnInfoList, uint32_t *returnInfoNum)
|
||||
{
|
||||
return IsGroupSupport() ? GetGroupImplInstance()->getPkInfoList(appId, queryParams, returnInfoList,
|
||||
returnInfoNum) : HC_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int32_t GetGroupInfoByIdImpl(const char *appId, const char *groupId, char **returnGroupInfo)
|
||||
{
|
||||
return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleGroupInfoById(appId, groupId,
|
||||
|
||||
@@ -186,163 +186,6 @@ static bool IsQueryParamsValid(int groupType, const char *groupId, const char *g
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t QueryRelatedGroupsForGetPk(const char *udid, GroupInfoVec *groupInfoVec)
|
||||
{
|
||||
GroupQueryParams dbQueryParams = { 0 };
|
||||
dbQueryParams.visibility = GROUP_VISIBILITY_PUBLIC;
|
||||
dbQueryParams.type = PEER_TO_PEER_GROUP;
|
||||
dbQueryParams.udid = NULL;
|
||||
dbQueryParams.authId = NULL;
|
||||
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,
|
||||
int32_t returnPkHexStrLen)
|
||||
{
|
||||
/* Use the DeviceGroupManager package name. */
|
||||
const char *appId = GROUP_MANAGER_PACKAGE_NAME;
|
||||
int userType = deviceInfo->devType;
|
||||
const char *authId = StringGet(&deviceInfo->authId);
|
||||
if (authId == NULL) {
|
||||
LOGE("Failed to get authId from deviceInfo!");
|
||||
return HC_ERR_DB;
|
||||
}
|
||||
Uint8Buff authIdBuff = { 0, 0 };
|
||||
authIdBuff.length = HcStrlen(authId);
|
||||
authIdBuff.val = (uint8_t *)HcMalloc(authIdBuff.length, 0);
|
||||
if (authIdBuff.val == NULL) {
|
||||
LOGE("Failed to allocate authIdBuff memory!");
|
||||
return HC_ERR_ALLOC_MEMORY;
|
||||
}
|
||||
if (memcpy_s(authIdBuff.val, authIdBuff.length, authId, authIdBuff.length) != HC_SUCCESS) {
|
||||
LOGE("Failed to copy authId!");
|
||||
HcFree(authIdBuff.val);
|
||||
return HC_ERR_MEMORY_COPY;
|
||||
}
|
||||
uint8_t returnPkBytes[PUBLIC_KEY_MAX_LENGTH] = { 0 };
|
||||
Uint8Buff returnPkBuff = { 0, 0 };
|
||||
returnPkBuff.length = PUBLIC_KEY_MAX_LENGTH;
|
||||
returnPkBuff.val = returnPkBytes;
|
||||
int32_t res = GetPublicKey(appId, groupId, &authIdBuff, userType, DAS_MODULE, &returnPkBuff);
|
||||
HcFree(authIdBuff.val);
|
||||
if (res != HC_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
static int32_t GeneratePkInfo(const char *queryUdid, const char *groupId, CJson *pkInfo)
|
||||
{
|
||||
DeviceInfo *deviceInfo = CreateDeviceInfoStruct();
|
||||
if (deviceInfo == NULL) {
|
||||
LOGE("Failed to allocate deviceInfo memory!");
|
||||
return HC_ERR_ALLOC_MEMORY;
|
||||
}
|
||||
int32_t res = GetTrustedDevInfoById(queryUdid, true, groupId, deviceInfo);
|
||||
if (res != HC_SUCCESS) {
|
||||
DestroyDeviceInfoStruct(deviceInfo);
|
||||
return res;
|
||||
}
|
||||
char returnPkHexStr[SHA256_LEN * BYTE_TO_HEX_OPER_LENGTH + 1] = { 0 };
|
||||
res = GetPkByParams(groupId, deviceInfo, returnPkHexStr, sizeof(returnPkHexStr));
|
||||
DestroyDeviceInfoStruct(deviceInfo);
|
||||
if (res != HC_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
if (AddStringToJson(pkInfo, FIELD_GROUP_ID, groupId) != HC_SUCCESS) {
|
||||
LOGE("Failed to add groupId to pkInfo!");
|
||||
return HC_ERR_JSON_ADD;
|
||||
}
|
||||
if (AddStringToJson(pkInfo, FIELD_PUBLIC_KEY, returnPkHexStr) != HC_SUCCESS) {
|
||||
LOGE("Failed to add publicKey to pkInfo!");
|
||||
return HC_ERR_JSON_ADD;
|
||||
}
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
static void AddAllPkInfoToList(const char *queryUdid, const GroupInfoVec *groupInfoVec, CJson *pkInfoList)
|
||||
{
|
||||
uint32_t index;
|
||||
void **groupInfoPtr;
|
||||
FOR_EACH_HC_VECTOR(*groupInfoVec, index, groupInfoPtr) {
|
||||
if ((groupInfoPtr == NULL) || (*groupInfoPtr == NULL)) {
|
||||
continue;
|
||||
}
|
||||
GroupInfo *groupInfo = (GroupInfo *)*groupInfoPtr;
|
||||
const char *groupId = StringGet(&groupInfo->id);
|
||||
if (groupId == NULL) {
|
||||
LOGE("Failed to get groupId from groupInfo!");
|
||||
continue;
|
||||
}
|
||||
CJson *pkInfo = CreateJson();
|
||||
if (pkInfo == NULL) {
|
||||
LOGE("Failed to create json!");
|
||||
continue;
|
||||
}
|
||||
int32_t res = GeneratePkInfo(queryUdid, groupId, pkInfo);
|
||||
if (res != HC_SUCCESS) {
|
||||
FreeJson(pkInfo);
|
||||
continue;
|
||||
}
|
||||
if (AddObjToArray(pkInfoList, pkInfo) != HC_SUCCESS) {
|
||||
LOGE("Failed to add pkInfo to pkInfoList!");
|
||||
FreeJson(pkInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t GeneratePkInfoList(const char *appId, const CJson *params, CJson *pkInfoList)
|
||||
{
|
||||
const char *udid = GetStringFromJson(params, FIELD_UDID);
|
||||
if (udid == NULL) {
|
||||
LOGE("Failed to get udid from params!");
|
||||
return HC_ERR_JSON_GET;
|
||||
}
|
||||
bool isSelfPk = false;
|
||||
if (GetBoolFromJson(params, FIELD_IS_SELF_PK, &isSelfPk) != HC_SUCCESS) {
|
||||
LOGE("Failed to get isSelfPk from json!");
|
||||
return HC_ERR_JSON_GET;
|
||||
}
|
||||
GroupInfoVec groupInfoVec;
|
||||
CreateGroupInfoVecStruct(&groupInfoVec);
|
||||
int32_t res = QueryRelatedGroupsForGetPk(udid, &groupInfoVec);
|
||||
if (res != HC_SUCCESS) {
|
||||
DestroyGroupInfoVecStruct(&groupInfoVec);
|
||||
return res;
|
||||
}
|
||||
RemoveNoPermissionGroup(&groupInfoVec, appId);
|
||||
const char *queryUdid = isSelfPk ? GetLocalDevUdid() : udid;
|
||||
if (queryUdid == NULL) {
|
||||
LOGE("Failed to get local udid!");
|
||||
DestroyGroupInfoVecStruct(&groupInfoVec);
|
||||
return HC_ERR_DB;
|
||||
}
|
||||
AddAllPkInfoToList(queryUdid, &groupInfoVec, pkInfoList);
|
||||
DestroyGroupInfoVecStruct(&groupInfoVec);
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
static BaseGroup *GetGroupInstance(int32_t groupType)
|
||||
{
|
||||
if (!IsGroupTypeSupported(groupType)) {
|
||||
@@ -849,43 +692,6 @@ static int32_t CheckAccessToGroup(const char *appId, const char *groupId)
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t GetPkInfoList(const char *appId, const char *queryParams, char **returnInfoList, uint32_t *returnInfoNum)
|
||||
{
|
||||
LOGI("[Start]: start to get pk list!");
|
||||
if ((appId == NULL) || (queryParams == NULL) || (returnInfoList == NULL) || (returnInfoNum == NULL)) {
|
||||
LOGE("The input parameters contains NULL value!");
|
||||
return HC_ERR_INVALID_PARAMS;
|
||||
}
|
||||
CJson *params = CreateJsonFromString(queryParams);
|
||||
if (params == NULL) {
|
||||
LOGE("Failed to create json from string!");
|
||||
return HC_ERR_JSON_CREATE;
|
||||
}
|
||||
CJson *pkInfoList = CreateJsonArray();
|
||||
if (pkInfoList == NULL) {
|
||||
LOGE("Failed to create json array!");
|
||||
FreeJson(params);
|
||||
return HC_ERR_JSON_CREATE;
|
||||
}
|
||||
int32_t res = GeneratePkInfoList(appId, params, pkInfoList);
|
||||
FreeJson(params);
|
||||
if (res != HC_SUCCESS) {
|
||||
FreeJson(pkInfoList);
|
||||
return res;
|
||||
}
|
||||
int32_t pkInfoNum = GetItemNum(pkInfoList);
|
||||
char *pkInfoListStr = PackJsonToString(pkInfoList);
|
||||
FreeJson(pkInfoList);
|
||||
if (pkInfoListStr == NULL) {
|
||||
LOGE("Failed to convert json to string!");
|
||||
return HC_ERR_PACKAGE_JSON_TO_STRING_FAIL;
|
||||
}
|
||||
*returnInfoList = pkInfoListStr;
|
||||
*returnInfoNum = pkInfoNum;
|
||||
LOGI("[End]: Get pk list successfully!");
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t GetAccessibleGroupInfoById(const char *appId, const char *groupId, char **returnGroupInfo)
|
||||
{
|
||||
if ((appId == NULL) || (groupId == NULL) || (returnGroupInfo == NULL)) {
|
||||
@@ -1130,7 +936,6 @@ static const GroupImpl g_groupImplInstance = {
|
||||
.regListener = RegListener,
|
||||
.unRegListener = UnRegListener,
|
||||
.checkAccessToGroup = CheckAccessToGroup,
|
||||
.getPkInfoList = GetPkInfoList,
|
||||
.getAccessibleGroupInfoById = GetAccessibleGroupInfoById,
|
||||
.getAccessibleGroupInfo = GetAccessibleGroupInfo,
|
||||
.getAccessibleJoinedGroups = GetAccessibleJoinedGroups,
|
||||
|
||||
Reference in New Issue
Block a user