fit multi-user

Signed-off-by: fuzikun <fuzikun@huawei.com>
This commit is contained in:
fuzikun 2022-02-10 21:33:31 +08:00
parent 493f294956
commit 7836ba76ae
83 changed files with 4296 additions and 2183 deletions

View File

@ -0,0 +1,33 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "hc_string_vector.h"
IMPLEMENT_HC_VECTOR(StringVector, HcString, 1)
StringVector CreateStrVector(void)
{
return CreateStringVector();
}
void DestroyStrVector(StringVector *vec)
{
uint32_t index;
HcString *strItemPtr = NULL;
FOR_EACH_HC_VECTOR(*vec, index, strItemPtr) {
DeleteString(strItemPtr);
}
DESTROY_HC_VECTOR(StringVector, vec);
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HC_STRING_VECTOR_H
#define HC_STRING_VECTOR_H
#include "hc_string.h"
#include "hc_vector.h"
#ifdef __cplusplus
extern "C" {
#endif
DECLARE_HC_VECTOR(StringVector, HcString)
StringVector CreateStrVector(void);
void DestroyStrVector(StringVector *vec);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -156,8 +156,8 @@ void Destroy##ClassName(ClassName* obj) \
}
/* Use these two macros to create and destroy vector */
#define CREATE_HC_VECTOR(classname) Create##classname();
#define DESTROY_HC_VECTOR(classname, obj) Destroy##classname(obj);
#define CREATE_HC_VECTOR(classname) Create##classname()
#define DESTROY_HC_VECTOR(classname, obj) Destroy##classname(obj)
#define FOR_EACH_HC_VECTOR(vec, index, iter) for (index = 0; index < (vec).size(&(vec)) && \
(iter = (vec).getp(&(vec), index)); ++index)

View File

@ -38,6 +38,7 @@ hal_common_files = [
"${common_lib_path}/impl/src/clib_types.c",
"${common_lib_path}/impl/src/hc_parcel.c",
"${common_lib_path}/impl/src/hc_string.c",
"${common_lib_path}/impl/src/hc_string_vector.c",
"${common_lib_path}/impl/src/hc_tlv_parser.c",
"${common_lib_path}/impl/src/json_utils.c",
"${common_lib_path}/impl/src/string_util.c",

View File

@ -84,7 +84,7 @@ static int32_t InitHks(void)
LOGD("Hks: The local hks file needs to be refreshed!");
LOGI("Start to delete local database file!");
HcFileRemove(FILE_ID_GROUP);
HcFileRemove(GetStoragePath());
LOGI("Delete local database file successfully!");
res = HksRefreshKeyInfo();
if (res != HKS_SUCCESS) {

View File

@ -21,6 +21,14 @@
#include "hks_type.h"
#include "string_util.h"
#define BASE_IMPORT_PARAMS_LEN 7
#define EXT_IMPORT_PARAMS_LEN 2
static enum HksKeyPurpose g_purposeToHksKeyPurpose[] = {
HKS_KEY_PURPOSE_MAC,
HKS_KEY_PURPOSE_DERIVE
};
static enum HksKeyAlg g_algToHksAlgorithm[] = {
HKS_ALG_ED25519,
HKS_ALG_X25519,
@ -1121,13 +1129,106 @@ static bool CheckDlPublicKey(const Uint8Buff *key, const char *primeHex)
return true;
}
static int32_t CheckImportSymmetricKeyParam(const Uint8Buff *keyAlias, const Uint8Buff *authToken)
{
const Uint8Buff *inParams[] = { keyAlias, authToken };
const char *paramTags[] = { "keyAlias", "authToken" };
return BaseCheckParams(inParams, paramTags, CAL_ARRAY_SIZE(inParams));
}
static int32_t ConstructImportSymmetricKeyParam(struct HksParamSet **paramSet, uint32_t keyLen, KeyPurpose purpose,
const ExtraInfo *exInfo)
{
struct HksParam *importParam = NULL;
struct HksBlob authIdBlob = { 0, NULL };
union KeyRoleInfoUnion roleInfoUnion;
(void)memset_s(&roleInfoUnion, sizeof(roleInfoUnion), 0, sizeof(roleInfoUnion));
uint32_t idx = 0;
if (exInfo != NULL) {
CHECK_PTR_RETURN_HAL_ERROR_CODE(exInfo->authId.val, "authId");
CHECK_LEN_ZERO_RETURN_ERROR_CODE(exInfo->authId.length, "authId");
CHECK_LEN_HIGHER_RETURN(exInfo->pairType, PAIR_TYPE_END - 1, "pairType");
importParam = (struct HksParam *)HcMalloc(sizeof(struct HksParam) *
(BASE_IMPORT_PARAMS_LEN + EXT_IMPORT_PARAMS_LEN), 0);
if (importParam == NULL) {
LOGE("Malloc for importParam failed.");
return HAL_ERR_BAD_ALLOC;
}
authIdBlob.size = exInfo->authId.length;
authIdBlob.data = exInfo->authId.val;
roleInfoUnion.roleInfoStruct.userType = (uint8_t)exInfo->userType;
roleInfoUnion.roleInfoStruct.pairType = (uint8_t)exInfo->pairType;
importParam[idx].tag = HKS_TAG_KEY_AUTH_ID;
importParam[idx++].blob = authIdBlob;
importParam[idx].tag = HKS_TAG_KEY_ROLE;
importParam[idx++].uint32Param = roleInfoUnion.roleInfo;
} else {
importParam = (struct HksParam *)HcMalloc(sizeof(struct HksParam) * BASE_IMPORT_PARAMS_LEN, 0);
if (importParam == NULL) {
LOGE("Malloc for importParam failed.");
return HAL_ERR_BAD_ALLOC;
}
}
importParam[idx].tag = HKS_TAG_ALGORITHM;
importParam[idx++].uint32Param = HKS_ALG_AES;
importParam[idx].tag = HKS_TAG_KEY_SIZE;
importParam[idx++].uint32Param = keyLen * BITS_PER_BYTE;
importParam[idx].tag = HKS_TAG_PADDING;
importParam[idx++].uint32Param = HKS_PADDING_NONE;
importParam[idx].tag = HKS_TAG_IS_ALLOWED_WRAP;
importParam[idx++].boolParam = false;
importParam[idx].tag = HKS_TAG_PURPOSE;
importParam[idx++].uint32Param = g_purposeToHksKeyPurpose[purpose];
importParam[idx].tag = HKS_TAG_BLOCK_MODE;
importParam[idx++].uint32Param = HKS_MODE_GCM;
importParam[idx].tag = HKS_TAG_DIGEST;
importParam[idx++].uint32Param = HKS_DIGEST_SHA256;
int ret = ConstructParamSet(paramSet, importParam, idx);
if (ret != HAL_SUCCESS) {
LOGE("Construct decrypt param set failed, ret = %d.", ret);
}
HcFree(importParam);
return ret;
}
static int32_t ImportSymmetricKey(const Uint8Buff *keyAlias, const Uint8Buff *authToken, KeyPurpose purpose,
const ExtraInfo *exInfo)
{
int32_t ret = CheckImportSymmetricKeyParam(keyAlias, authToken);
if (ret != HAL_SUCCESS) {
return ret;
}
struct HksBlob keyAliasBlob = { keyAlias->length, keyAlias->val };
struct HksBlob symKeyBlob = { authToken->length, authToken->val };
struct HksParamSet *paramSet = NULL;
ret = ConstructImportSymmetricKeyParam(&paramSet, authToken->length, purpose, exInfo);
if (ret != HAL_SUCCESS) {
LOGE("construct param set failed, ret = %d", ret);
return ret;
}
ret = HksImportKey(&keyAliasBlob, paramSet, &symKeyBlob);
if (ret != HKS_SUCCESS) {
LOGE("HksImportKey failed, ret: %d", ret);
HksFreeParamSet(&paramSet);
return ret;
}
HksFreeParamSet(&paramSet);
return HAL_SUCCESS;
}
static const AlgLoader g_huksLoader = {
.initAlg = InitHks,
.sha256 = Sha256,
.generateRandom = GenerateRandom,
.computeHmac = ComputeHmac,
.computeHkdf = ComputeHkdf,
.importSymmetricKey = NULL,
.importSymmetricKey = ImportSymmetricKey,
.checkKeyExist = CheckKeyExist,
.deleteKey = DeleteKey,
.aesGcmEncrypt = AesGcmEncrypt,

View File

@ -14,9 +14,10 @@
*/
#include "hc_file.h"
#include <dirent.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "securec.h"
#include "hc_log.h"
@ -29,29 +30,6 @@ extern "C" {
#define MAX_FILE_PATH_SIZE 256
#define MAX_FOLDER_NAME_SIZE 128
typedef struct {
FileIdEnum fileId;
const char *filePath;
} FileDefInfo;
static char g_groupPath[MAX_FILE_PATH_SIZE] = { 0 };
static FileDefInfo g_fileDefInfo[FILE_ID_LAST] = {
{ FILE_ID_GROUP, "/data/data/deviceauth/hcgroup.dat" },
{ FILE_ID_CRED_DATA, "" }
};
void SetFilePath(FileIdEnum fileId, const char *path)
{
if (path == NULL) {
LOGE("Invalid path param");
return;
}
if (sprintf_s(g_groupPath, MAX_FILE_PATH_SIZE, "%s", path) != -1) {
g_fileDefInfo[fileId].filePath = g_groupPath;
}
}
static int32_t CreateDirectory(const char *filePath)
{
int32_t ret;
@ -84,15 +62,13 @@ static int32_t CreateDirectory(const char *filePath)
return 0;
}
static FILE *HcFileOpenRead(int fileId, const char *path)
static FILE *HcFileOpenRead(const char *path)
{
(void)fileId;
return fopen(path, "rb");
}
static FILE *HcFileOpenWrite(int32_t fileId, const char *path)
static FILE *HcFileOpenWrite(const char *path)
{
(void)fileId;
if (access(path, F_OK) != 0) {
int32_t ret = CreateDirectory(path);
if (ret != 0) {
@ -102,15 +78,15 @@ static FILE *HcFileOpenWrite(int32_t fileId, const char *path)
return fopen(path, "w+");
}
int HcFileOpen(int fileId, int mode, FileHandle *file)
int HcFileOpen(const char *path, int mode, FileHandle *file)
{
if (fileId < 0 || fileId >= FILE_ID_LAST || file == NULL) {
if (path == NULL || file == NULL) {
return -1;
}
if (mode == MODE_FILE_READ) {
file->pfd = HcFileOpenRead(fileId, g_fileDefInfo[fileId].filePath);
file->pfd = HcFileOpenRead(path);
} else {
file->pfd = HcFileOpenWrite(fileId, g_fileDefInfo[fileId].filePath);
file->pfd = HcFileOpenWrite(path);
}
if (file->pfd == NULL) {
return -1;
@ -185,16 +161,41 @@ void HcFileClose(FileHandle file)
return;
}
fclose(fp);
(void)fclose(fp);
}
void HcFileRemove(int fileId)
void HcFileRemove(const char *path)
{
if (fileId >= FILE_ID_LAST) {
LOGE("Invalid fileId:%d", fileId);
if (path == NULL) {
LOGE("Invalid file path");
return;
}
unlink(g_fileDefInfo[fileId].filePath);
(void)remove(path);
}
void HcFileGetSubFileName(const char *path, StringVector *nameVec)
{
DIR *dir = NULL;
struct dirent *entry = NULL;
if ((dir = opendir(path)) == NULL) {
LOGI("opendir failed!");
return;
}
while ((entry = readdir(dir)) != NULL) {
if ((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)) {
continue;
}
HcString subFileName = CreateString();
if (!StringSetPointer(&subFileName, entry->d_name)) {
LOGE("Failed to copy subFileName!");
DeleteString(&subFileName);
continue;
}
if (nameVec->pushBackT(nameVec, subFileName) == NULL) {
LOGE("Failed to push path to pathVec!");
DeleteString(&subFileName);
}
}
}
#ifdef __cplusplus

View File

@ -1,216 +0,0 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "hc_file.h"
#include <errno.h>
#include <fcntl.h>
#include <securec.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include "common_defs.h"
#include "hal_error.h"
#include "hc_log.h"
#define MAX_FILE_PATH_SIZE 256
#define MAX_FOLDER_NAME_SIZE 128
#define GET_FOLDER_OK 0
#define GET_FOLDER_FAILED (-1)
#define GET_FILE_OK 1
#define DEFAULT_FILE_PERMISSION 0666
typedef struct {
FileIdEnum fileId;
const char* filePath;
} FileDefInfo;
static FileDefInfo g_fileDefInfo[FILE_ID_LAST] = {
{ FILE_ID_GROUP, "user/Hichain/hcgroup.dat" },
{ FILE_ID_CRED_DATA, "" }
};
static char g_groupPath[MAX_FILE_PATH_SIZE] = { 0 };
void SetFilePath(FileIdEnum fileId, const char *path)
{
if (path == NULL) {
LOGE("Invalid path param");
return;
}
if (sprintf_s(g_groupPath, MAX_FILE_PATH_SIZE, "%s", path) != -1) {
g_fileDefInfo[fileId].filePath = g_groupPath;
}
}
int GetNextFolder(const char *filePath, int *beginPos, char *dst, int size)
{
int pos = (*beginPos);
while (1) {
char c = filePath[pos++];
if (c == '\0') {
if (memcpy_s(dst, size, filePath, pos - 1) != EOK) {
return GET_FOLDER_FAILED;
}
dst[pos - 1] = '\0';
(*beginPos) = pos;
return GET_FILE_OK;
} else if (c == '/') {
if (memcpy_s(dst, size, filePath, pos - 1) != EOK) {
return GET_FOLDER_FAILED;
}
dst[pos - 1] = '\0';
(*beginPos) = pos;
return GET_FOLDER_OK;
} else {
if (pos >= size) {
(*beginPos) = pos;
return GET_FOLDER_FAILED;
}
}
}
}
int HcFileOpenRead(const char *path)
{
return open(path, O_RDONLY);
}
static int IsFileValid(const char *path)
{
struct stat fileStat;
int32_t ret = stat(path, &fileStat);
if (ret == -1) {
if (errno == ENOENT) {
return HAL_ERR_FILE_NOT_EXIST;
} else {
LOGE("file stat failed, errno = 0x%x", errno);
return HAL_ERR_FILE;
}
}
return 0;
}
int HcFileOpenWrite(const char *path)
{
char filePath[MAX_FOLDER_NAME_SIZE + 1];
int beginPos = 0;
while (1) {
int ret = GetNextFolder(path, &beginPos, filePath, sizeof(filePath));
if (ret == GET_FOLDER_OK) {
if (IsFileValid(filePath) == 0) {
continue;
}
if (mkdir(filePath, DEFAULT_FILE_PERMISSION) != 0) {
return -1;
}
} else if (ret == GET_FOLDER_FAILED) {
return -1;
} else {
int fd = open(filePath, O_RDWR | O_CREAT);
if (fd == -1) {
LOGE("file stat failed, errno = 0x%x", errno);
}
return fd;
}
}
}
int HcFileOpen(int fileId, int mode, FileHandle *file)
{
if (fileId < 0 || fileId >= FILE_ID_LAST || file == NULL) {
return -1;
}
if (mode == MODE_FILE_READ) {
file->fileHandle.fd = HcFileOpenRead(g_fileDefInfo[fileId].filePath);
} else {
file->fileHandle.fd = HcFileOpenWrite(g_fileDefInfo[fileId].filePath);
}
if (file->fileHandle.fd == -1) {
return -1;
}
return 0;
}
int HcFileSize(FileHandle file)
{
int fp = file.fileHandle.fd;
int size = lseek(fp, 0, SEEK_END);
(void)lseek(fp, 0, SEEK_SET);
return size;
}
int HcFileRead(FileHandle file, void *dst, int dstSize)
{
int fp = file.fileHandle.fd;
if (fp == -1 || dstSize < 0 || dst == NULL) {
return -1;
}
char *dstBuffer = (char *)dst;
int total = 0;
while (total < dstSize) {
int readCount = read(fp, dstBuffer + total, dstSize - total);
if (readCount < 0 || readCount > (dstSize - total)) {
LOGE("read errno :%x", errno);
return -1;
}
if (readCount == 0) {
LOGE("read errno :%x", errno);
return total;
}
total += readCount;
}
return total;
}
int HcFileWrite(FileHandle file, const void *src, int srcSize)
{
int fp = file.fileHandle.fd;
if (fp == -1 || srcSize < 0 || src == NULL) {
return -1;
}
const char *srcBuffer = (const char *)src;
int total = 0;
while (total < srcSize) {
int writeCount = write(fp, srcBuffer + total, srcSize - total);
if (writeCount < 0 || writeCount > (srcSize - total)) {
return -1;
}
total += writeCount;
}
return total;
}
void HcFileClose(FileHandle file)
{
int fp = file.fileHandle.fd;
if (fp == 0) {
return;
}
close(fp);
}
void HcFileRemove(int fileId)
{
if (fileId >= FILE_ID_LAST) {
LOGE("Invalid fileId:%d", fileId);
return;
}
unlink(g_fileDefInfo[fileId].filePath);
}

View File

@ -14,67 +14,49 @@
*/
#include "hc_file.h"
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <securec.h>
#include <stdio.h>
#include <unistd.h>
#include "hal_error.h"
#include "hc_log.h"
#include "utils_file.h"
#define MAX_FILE_PATH_SIZE 64
#define MAX_FOLDER_NAME_SIZE 128
#define GET_FOLDER_OK 0
#define GET_FOLDER_FAILED (-1)
#define GET_FILE_OK 1
#define DEFAULT_FILE_PERMISSION 0666
typedef struct {
FileIdEnum fileId;
char filePath[MAX_FILE_PATH_SIZE];
} FileDefInfo;
static FileDefInfo g_fileDefInfo[FILE_ID_LAST] = {
{ FILE_ID_GROUP, "/data/hcgroup.dat" },
{ FILE_ID_CRED_DATA, "" }
};
void SetFilePath(FileIdEnum fileId, const char *path)
{
if (fileId < 0 || fileId >= FILE_ID_LAST || path == NULL) {
LOGE("Invalid path param");
return;
}
if (sprintf_s(g_fileDefInfo[fileId].filePath, MAX_FILE_PATH_SIZE, "%s", path) == HAL_FAILED) {
LOGE("Set file path failed fileId:%d", fileId);
}
}
int HcFileOpenRead(const char *path)
static int HcFileOpenRead(const char *path)
{
int ret = UtilsFileOpen(path, O_RDONLY, 0);
LOGI("ret = %d", ret);
return ret;
}
int HcFileOpenWrite(const char *path)
static int HcFileOpenWrite(const char *path)
{
int ret = UtilsFileOpen(path, O_RDWR_FS | O_CREAT_FS | O_TRUNC_FS, 0);
LOGI("ret = %d", ret);
return ret;
}
int HcFileOpen(int fileId, int mode, FileHandle *file)
int HcFileOpen(const char *path, int mode, FileHandle *file)
{
if (fileId < 0 || fileId >= FILE_ID_LAST || file == NULL) {
if (path == NULL || file == NULL) {
return -1;
}
if (strcpy_s(file->filePath, MAX_FILE_PATH_SIZE, path) != EOK) {
LOGE("Failed to copy filePath!");
return HAL_FAILED;
}
if (mode == MODE_FILE_READ) {
file->fileHandle.fd = HcFileOpenRead(g_fileDefInfo[fileId].filePath);
file->filePath = g_fileDefInfo[fileId].filePath;
file->fileHandle.fd = HcFileOpenRead(path);
} else {
file->fileHandle.fd = HcFileOpenWrite(g_fileDefInfo[fileId].filePath);
file->filePath = g_fileDefInfo[fileId].filePath;
file->fileHandle.fd = HcFileOpenWrite(path);
}
if (file->fileHandle.fd == HAL_FAILED) {
return HAL_FAILED;
@ -89,8 +71,6 @@ int HcFileSize(FileHandle file)
LOGI("ret = %d, fileSize = %d\n", ret, fileSize);
if (ret == HAL_SUCCESS) {
return fileSize;
} else {
return HAL_FAILED;
}
return HAL_FAILED;
}
@ -127,12 +107,37 @@ void HcFileClose(FileHandle file)
LOGI("ret = %d", ret);
}
void HcFileRemove(int fileId)
void HcFileRemove(const char *path)
{
if (fileId >= FILE_ID_LAST) {
LOGE("Invalid fileId:%d", fileId);
if (path == NULL) {
LOGE("Invalid file path");
return;
}
int ret = UtilsFileDelete(g_fileDefInfo[fileId].filePath);
int ret = UtilsFileDelete(path);
LOGI("File delete result:%d", ret);
}
void HcFileGetSubFileName(const char *path, StringVector *nameVec)
{
DIR *dir = NULL;
struct dirent *entry = NULL;
if ((dir = opendir(path)) == NULL) {
LOGI("opendir failed!");
return;
}
while ((entry = readdir(dir)) != NULL) {
if ((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)) {
continue;
}
HcString subFileName = CreateString();
if (!StringSetPointer(&subFileName, entry->d_name)) {
LOGE("Failed to copy subFileName!");
DeleteString(&subFileName);
continue;
}
if (nameVec->pushBackT(nameVec, subFileName) == NULL) {
LOGE("Failed to push path to pathVec!");
DeleteString(&subFileName);
}
}
}

View File

@ -16,6 +16,8 @@
#ifndef HC_FILE_H
#define HC_FILE_H
#include "hc_string_vector.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -25,24 +27,18 @@ typedef union {
int fd;
} FileHandle;
typedef enum FileIdEnumT {
FILE_ID_GROUP = 0,
FILE_ID_CRED_DATA,
FILE_ID_LAST,
} FileIdEnum;
#define MODE_FILE_READ 0
#define MODE_FILE_WRITE 1
// 0 indicates success
// -1 indicates fail
int HcFileOpen(int fileId, int mode, FileHandle *file);
int HcFileOpen(const char *path, int mode, FileHandle *file);
int HcFileSize(FileHandle file);
int HcFileRead(FileHandle file, void *dst, int dstSize);
int HcFileWrite(FileHandle file, const void *src, int srcSize);
void HcFileClose(FileHandle file);
void HcFileRemove(int fileId);
void SetFilePath(FileIdEnum fileId, const char *path);
void HcFileRemove(const char *path);
void HcFileGetSubFileName(const char *path, StringVector *nameVec);
#ifdef __cplusplus
}

View File

@ -16,30 +16,35 @@
#ifndef HC_FILE_H
#define HC_FILE_H
#include "hc_string_vector.h"
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_FILE_PATH_SIZE 64
typedef struct {
union {
void *pfd;
int fd;
} fileHandle;
const char *filePath;
char filePath[MAX_FILE_PATH_SIZE];
} FileHandle;
typedef enum FileIdEnumT {
FILE_ID_GROUP = 0,
FILE_ID_CRED_DATA,
FILE_ID_LAST,
} FileIdEnum;
#define MODE_FILE_READ 0
#define MODE_FILE_WRITE 1
/* 0 indicates success, -1 indicates fail */
int HcFileOpen(int fileId, int mode, FileHandle *file);
int HcFileOpen(const char *path, int mode, FileHandle *file);
int HcFileSize(FileHandle file);
int HcFileRead(FileHandle file, void *dst, int dstSize);
int HcFileWrite(FileHandle file, const void *src, int srcSize);
void HcFileClose(FileHandle file);
void HcFileRemove(int fileId);
void SetFilePath(FileIdEnum fileId, const char *path);
void HcFileRemove(const char *path);
void HcFileGetSubFileName(const char *path, StringVector *nameVec);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -60,6 +60,8 @@ extern "C" {
#define PARAM_TYPE_DEVICE_INFO 29
#define PARAM_TYPE_AUTH_PARAMS 30
#define PARAM_TYPE_CB_OBJECT 31
#define PARAM_TYPE_OS_ACCOUNT_ID 32
#define PARAM_TYPE_RETURN_DATA 33
enum {
IPC_CALL_ID_REG_CB = 1,
@ -96,7 +98,9 @@ enum {
IPC_CALL_ID_IS_TRUST_DEVICE,
IPC_CALL_ID_GET_AUTH_STATE,
IPC_CALL_ID_AUTH_DEVICE,
IPC_CALL_ID_INFORM_DEV_DISCONN
IPC_CALL_ID_INFORM_DEV_DISCONN,
IPC_CALL_ID_CHECK_ACCESS_TO_GROUP,
IPC_CALL_ID_GET_PK_INFO_LIST,
};
#ifdef __cplusplus

View File

@ -29,8 +29,8 @@ typedef struct {
IpcServiceCall method;
int32_t methodId;
} IpcServiceCallMap;
#define MAX_CALLMAP_SIZE 32
#define MAX_CBSTUB_SIZE 32
#define MAX_CALLMAP_SIZE 64
#define MAX_CBSTUB_SIZE 64
typedef LiteIpcCallService DevAuthService;

View File

@ -25,8 +25,8 @@ typedef struct {
IpcServiceCall method;
int32_t methodId;
} IpcServiceCallMap;
const int32_t MAX_CALLMAP_SIZE = 32;
const int32_t MAX_CBSTUB_SIZE = 32;
const int32_t MAX_CALLMAP_SIZE = 64;
const int32_t MAX_CBSTUB_SIZE = 64;
class ServiceDevAuth : public IRemoteStub<IMethodsIpcCall> {
public:

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;
@ -275,7 +276,7 @@ static int32_t IpcGmUnRegDataChangeListener(const char *appId)
return HC_SUCCESS;
}
static int32_t IpcGmCreateGroup(int64_t requestId, const char *appid, const char *createParams)
static int32_t IpcGmCreateGroup(int32_t osAccountId, int64_t requestId, const char *appid, const char *createParams)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -295,7 +296,13 @@ static int32_t IpcGmCreateGroup(int64_t requestId, const char *appid, const char
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
@ -330,7 +337,7 @@ static int32_t IpcGmCreateGroup(int64_t requestId, const char *appid, const char
return ret;
}
static int32_t IpcGmDelGroup(int64_t requestId, const char *appId, const char *delParams)
static int32_t IpcGmDelGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *delParams)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -351,6 +358,13 @@ static int32_t IpcGmDelGroup(int64_t requestId, const char *appId, const char *d
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
@ -384,7 +398,7 @@ static int32_t IpcGmDelGroup(int64_t requestId, const char *appId, const char *d
return ret;
}
static int32_t IpcGmAddMemberToGroup(int64_t requestId, const char *appId, const char *addParams)
static int32_t IpcGmAddMemberToGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -404,7 +418,13 @@ static int32_t IpcGmAddMemberToGroup(int64_t requestId, const char *appId, const
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
@ -438,7 +458,7 @@ static int32_t IpcGmAddMemberToGroup(int64_t requestId, const char *appId, const
return ret;
}
static int32_t IpcGmDelMemberFromGroup(int64_t requestId, const char *appId, const char *delParams)
static int32_t IpcGmDelMemberFromGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *delParams)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -458,7 +478,13 @@ static int32_t IpcGmDelMemberFromGroup(int64_t requestId, const char *appId, con
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
@ -512,14 +538,12 @@ static int32_t IpcGmProcessData(int64_t requestId, const uint8_t *data, uint32_t
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_COMM_DATA, data, dataLen);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_COMM_DATA);
@ -541,7 +565,7 @@ static int32_t IpcGmProcessData(int64_t requestId, const uint8_t *data, uint32_t
return ret;
}
static int32_t IpcGmConfirmRequest(int64_t requestId, const char *appId, const char *cfmParams)
static int32_t IpcGmConfirmRequest(int32_t osAccountId, int64_t requestId, const char *appId, const char *cfmParams)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -561,7 +585,13 @@ static int32_t IpcGmConfirmRequest(int64_t requestId, const char *appId, const c
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
@ -833,17 +863,62 @@ static int32_t IpcGmGetLocalConnectInfo(char *returnInfo, int32_t bufLen)
return HC_ERR_NOT_SUPPORT;
}
static int32_t IpcGmCheckAccessToGroup(const char *appId, const char *groupId)
static int32_t IpcGmCheckAccessToGroup(int32_t osAccountId, const char *appId, const char *groupId)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if ((appId == NULL) || (groupId == NULL)) {
if (!IS_STRING_VALID(appId) || !IS_STRING_VALID(groupId)) {
return HC_ERR_INVALID_PARAMS;
}
return HC_ERR_NOT_SUPPORT;
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_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_CHECK_ACCESS_TO_GROUP, 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);
DestroyCallCtx(&callCtx, NULL);
return ret;
}
static int32_t IpcGmAddGroupManager(const char *appId, const char *groupId, const char *managerAppId)
static int32_t IpcGmAddGroupManager(int32_t osAccountId, const char *appId, const char *groupId,
const char *managerAppId)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -863,6 +938,13 @@ static int32_t IpcGmAddGroupManager(const char *appId, const char *groupId, cons
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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);
@ -897,7 +979,7 @@ static int32_t IpcGmAddGroupManager(const char *appId, const char *groupId, cons
return ret;
}
static int32_t IpcGmAddGroupFriend(const char *appId, const char *groupId, const char *friendAppId)
static int32_t IpcGmAddGroupFriend(int32_t osAccountId, const char *appId, const char *groupId, const char *friendAppId)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -917,6 +999,13 @@ static int32_t IpcGmAddGroupFriend(const char *appId, const char *groupId, const
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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);
@ -951,7 +1040,7 @@ static int32_t IpcGmAddGroupFriend(const char *appId, const char *groupId, const
return ret;
}
static int32_t IpcGmDelGroupManager(const char *appId, const char *groupId, const char *managerAppId)
static int32_t IpcGmDelGroupManager(int32_t osAccountId, const char *appId, const char *groupId, const char *managerAppId)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -971,6 +1060,13 @@ static int32_t IpcGmDelGroupManager(const char *appId, const char *groupId, cons
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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);
@ -1005,7 +1101,7 @@ static int32_t IpcGmDelGroupManager(const char *appId, const char *groupId, cons
return ret;
}
static int32_t IpcGmDelGroupFriend(const char *appId, const char *groupId, const char *friendAppId)
static int32_t IpcGmDelGroupFriend(int32_t osAccountId, const char *appId, const char *groupId, const char *friendAppId)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -1025,6 +1121,13 @@ static int32_t IpcGmDelGroupFriend(const char *appId, const char *groupId, const
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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);
@ -1060,7 +1163,7 @@ static int32_t IpcGmDelGroupFriend(const char *appId, const char *groupId, const
}
static int32_t GetGroupManagersIpcResult(const IpcDataInfo *replies, int32_t cacheNum,
char **outManagers, uint32_t *outSize)
char **outManagers, uint32_t *outSize)
{
int32_t inOutLen;
int32_t ret;
@ -1083,7 +1186,8 @@ static int32_t GetGroupManagersIpcResult(const IpcDataInfo *replies, int32_t cac
return HC_SUCCESS;
}
static int32_t IpcGmGetGroupManagers(const char *appId, const char *groupId, char **outManagers, uint32_t *outSize)
static int32_t IpcGmGetGroupManagers(int32_t osAccountId, const char *appId, const char *groupId,
char **outManagers, uint32_t *outSize)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -1103,6 +1207,13 @@ static int32_t IpcGmGetGroupManagers(const char *appId, const char *groupId, cha
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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);
@ -1160,7 +1271,8 @@ static int32_t GetGroupFriendsIpcResult(const IpcDataInfo *replies,
return HC_SUCCESS;
}
static int32_t IpcGmGetGroupFriends(const char *appId, const char *groupId, char **outFriends, uint32_t *outSize)
static int32_t IpcGmGetGroupFriends(int32_t osAccountId, const char *appId, const char *groupId,
char **outFriends, uint32_t *outSize)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -1180,6 +1292,13 @@ static int32_t IpcGmGetGroupFriends(const char *appId, const char *groupId, char
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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);
@ -1234,7 +1353,7 @@ static int32_t GroupInfoIpcResult(const IpcDataInfo *replies, int32_t cacheNum,
return HC_SUCCESS;
}
static int32_t IpcGmGetGroupInfoById(const char *appId, const char *groupId, char **outGroupInfo)
static int32_t IpcGmGetGroupInfoById(int32_t osAccountId, const char *appId, const char *groupId, char **outGroupInfo)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -1254,6 +1373,13 @@ static int32_t IpcGmGetGroupInfoById(const char *appId, const char *groupId, cha
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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);
@ -1287,6 +1413,92 @@ 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(int32_t osAccountId, 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(appId) || !IS_STRING_VALID(queryParams) ||
(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_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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)
{
@ -1311,7 +1523,8 @@ static int32_t SearchGroupsIpcResult(const IpcDataInfo *replies,
return HC_SUCCESS;
}
static int32_t IpcGmGetGroupInfo(const char *appId, const char *queryParams, char **outGroupVec, uint32_t *groupNum)
static int32_t IpcGmGetGroupInfo(int32_t osAccountId, const char *appId, const char *queryParams,
char **outGroupVec, uint32_t *groupNum)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -1331,6 +1544,13 @@ static int32_t IpcGmGetGroupInfo(const char *appId, const char *queryParams, cha
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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);
@ -1389,7 +1609,8 @@ static int32_t JoinedGroupsIpcResult(const IpcDataInfo *replies,
return HC_SUCCESS;
}
static int32_t IpcGmGetJoinedGroups(const char *appId, int32_t groupType, char **outGroupVec, uint32_t *groupNum)
static int32_t IpcGmGetJoinedGroups(int32_t osAccountId, const char *appId, int32_t groupType,
char **outGroupVec, uint32_t *groupNum)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -1397,8 +1618,7 @@ static int32_t IpcGmGetJoinedGroups(const char *appId, int32_t groupType, char *
IpcDataInfo replyCache[IPC_DATA_CACHES_4] = {{0}};
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || (outGroupVec == NULL) ||
(groupNum == NULL) || (groupType != ACROSS_ACCOUNT_AUTHORIZE_GROUP)) {
if (!IS_STRING_VALID(appId) || (outGroupVec == NULL) || (groupNum == NULL)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
@ -1410,6 +1630,13 @@ static int32_t IpcGmGetJoinedGroups(const char *appId, int32_t groupType, char *
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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);
@ -1467,7 +1694,8 @@ static int32_t RelatedGroupsIpcResult(const IpcDataInfo *replies,
return HC_SUCCESS;
}
static int32_t IpcGmGetRelatedGroups(const char *appId, const char *peerUdid, char **outGroupVec, uint32_t *groupNum)
static int32_t IpcGmGetRelatedGroups(int32_t osAccountId, const char *appId, const char *peerUdid,
char **outGroupVec, uint32_t *groupNum)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -1487,6 +1715,13 @@ static int32_t IpcGmGetRelatedGroups(const char *appId, const char *peerUdid, ch
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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);
@ -1541,10 +1776,17 @@ static int32_t DevInfoByIdIpcResult(const IpcDataInfo *replies, int32_t cacheNum
return HC_SUCCESS;
}
static int32_t FormParamsForGettingDeviceInfo(const char *appId,
static int32_t FormParamsForGettingDeviceInfo(int32_t osAccountId, const char *appId,
const char *peerUdid, const char *groupId, uintptr_t callCtx)
{
int32_t ret;
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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);
@ -1563,7 +1805,8 @@ static int32_t FormParamsForGettingDeviceInfo(const char *appId,
return HC_SUCCESS;
}
static int32_t IpcGmGetDeviceInfoById(const char *appId, const char *peerUdid, const char *groupId, char **outDevInfo)
static int32_t IpcGmGetDeviceInfoById(int32_t osAccountId, const char *appId, const char *peerUdid, const char *groupId,
char **outDevInfo)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -1583,7 +1826,7 @@ static int32_t IpcGmGetDeviceInfoById(const char *appId, const char *peerUdid, c
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = FormParamsForGettingDeviceInfo(appId, peerUdid, groupId, callCtx);
ret = FormParamsForGettingDeviceInfo(osAccountId, appId, peerUdid, groupId, callCtx);
if (ret != HC_SUCCESS) {
DestroyCallCtx(&callCtx, NULL);
return ret;
@ -1632,7 +1875,7 @@ static int32_t TrustedDevIpcResult(const IpcDataInfo *replies, int32_t cacheNum,
return HC_SUCCESS;
}
static int32_t IpcGmGetTrustedDevices(const char *appId,
static int32_t IpcGmGetTrustedDevices(int32_t osAccountId, const char *appId,
const char *groupId, char **outDevInfoVec, uint32_t *deviceNum)
{
uintptr_t callCtx = 0x0;
@ -1654,6 +1897,13 @@ static int32_t IpcGmGetTrustedDevices(const char *appId,
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
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);
@ -1687,7 +1937,7 @@ static int32_t IpcGmGetTrustedDevices(const char *appId,
return ret;
}
static bool IpcGmIsDeviceInGroup(const char *appId, const char *groupId, const char *udid)
static bool IpcGmIsDeviceInGroup(int32_t osAccountId, const char *appId, const char *groupId, const char *udid)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -1696,40 +1946,47 @@ static bool IpcGmIsDeviceInGroup(const char *appId, const char *groupId, const c
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || !IS_STRING_VALID(groupId) || !IS_STRING_VALID(udid)) {
return HC_ERR_INVALID_PARAMS;
return false;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
return false;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
return false;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return false;
}
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;
return false;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
return false;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)udid, strlen(udid) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_UDID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
return false;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_IS_DEV_IN_GROUP, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
return false;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLY;
@ -1804,6 +2061,7 @@ static void InitIpcGmMethods(DeviceGroupManager *gmMethodObj)
gmMethodObj->getTrustedDevices = IpcGmGetTrustedDevices;
gmMethodObj->checkAccessToGroup = IpcGmCheckAccessToGroup;
gmMethodObj->isDeviceInGroup = IpcGmIsDeviceInGroup;
gmMethodObj->getPkInfoList = IpcGmGetPkInfoList;
gmMethodObj->destroyInfo = IpcGmDestroyInfo;
gmMethodObj->authKeyAgree = IpcGmAuthKeyAgree;
gmMethodObj->processKeyAgreeData = IpcGmProcessKeyAgreeData;
@ -2013,7 +2271,8 @@ static int32_t IpcGaGetAuthState(int64_t authReqId, const char *groupId,
return ret;
}
static int32_t IpcGaAuthDevice(int64_t authReqId, const char *authParams, const DeviceAuthCallback *callback)
static int32_t IpcGaAuthDevice(int32_t osAccountId, int64_t authReqId, const char *authParams,
const DeviceAuthCallback *callback)
{
uintptr_t callCtx = 0x0;
int32_t ret;
@ -2034,7 +2293,13 @@ static int32_t IpcGaAuthDevice(int64_t authReqId, const char *authParams, const
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
sizeof(osAccountId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&authReqId), sizeof(authReqId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID);

View File

@ -200,12 +200,19 @@ static int32_t IpcServiceGmCreateGroup(const IpcDataInfo *ipcParams, int32_t par
{
int32_t callRet;
int32_t ret;
int32_t osAccountId;
int64_t requestId = 0;
int32_t inOutLen;
const char *createParams = NULL;
const char *appId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
@ -227,7 +234,7 @@ static int32_t IpcServiceGmCreateGroup(const IpcDataInfo *ipcParams, int32_t par
LOGE("bind request id by app id failed");
return ret;
}
callRet = g_devGroupMgrMethod.createGroup(requestId, appId, createParams);
callRet = g_devGroupMgrMethod.createGroup(osAccountId, requestId, appId, createParams);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
@ -237,12 +244,19 @@ static int32_t IpcServiceGmDelGroup(const IpcDataInfo *ipcParams, int32_t paramN
{
int32_t callRet;
int32_t ret;
int32_t osAccountId;
int64_t requestId = 0;
int32_t inOutLen;
const char *appId = NULL;
const char *delParams = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
@ -259,8 +273,12 @@ static int32_t IpcServiceGmDelGroup(const IpcDataInfo *ipcParams, int32_t paramN
LOGE("get param error, type %d", PARAM_TYPE_DEL_PARAMS);
return ret;
}
callRet = g_devGroupMgrMethod.deleteGroup(requestId, appId, delParams);
ret = AddReqIdByAppId(appId, requestId);
if (ret != 0) {
LOGE("bind request id by app id failed");
return ret;
}
callRet = g_devGroupMgrMethod.deleteGroup(osAccountId, requestId, appId, delParams);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
@ -271,11 +289,18 @@ static int32_t IpcServiceGmAddMemberToGroup(const IpcDataInfo *ipcParams, int32_
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
int64_t requestId = 0;
const char *addParams = NULL;
const char *appId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
@ -296,8 +321,7 @@ static int32_t IpcServiceGmAddMemberToGroup(const IpcDataInfo *ipcParams, int32_
if (ret != HC_SUCCESS) {
return ret;
}
callRet = g_devGroupMgrMethod.addMemberToGroup(requestId, appId, addParams);
callRet = g_devGroupMgrMethod.addMemberToGroup(osAccountId, requestId, appId, addParams);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
@ -308,11 +332,18 @@ static int32_t IpcServiceGmDelMemberFromGroup(const IpcDataInfo *ipcParams, int3
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
int64_t requestId = 0;
const char *delParams = NULL;
const char *appId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
@ -329,8 +360,12 @@ static int32_t IpcServiceGmDelMemberFromGroup(const IpcDataInfo *ipcParams, int3
LOGE("get param error, type %d", PARAM_TYPE_DEL_PARAMS);
return ret;
}
callRet = g_devGroupMgrMethod.deleteMemberFromGroup(requestId, appId, delParams);
ret = AddReqIdByAppId(appId, requestId);
if (ret != 0) {
LOGE("bind request id by app id failed");
return ret;
}
callRet = g_devGroupMgrMethod.deleteMemberFromGroup(osAccountId, requestId, appId, delParams);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
@ -374,29 +409,31 @@ static int32_t IpcServiceGmConfirmRequest(const IpcDataInfo *ipcParams, int32_t
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
int64_t requestId = 0;
const char *cfmParams = NULL;
const char *appId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_REQID);
return HC_ERR_IPC_BAD_PARAM;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&cfmParams, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQ_CFM, (uint8_t *)&cfmParams, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_REQ_CFM);
return ret;
}
callRet = g_devGroupMgrMethod.confirmRequest(requestId, appId, cfmParams);
callRet = g_devGroupMgrMethod.confirmRequest(osAccountId, requestId, appId, cfmParams);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
@ -562,15 +599,101 @@ static int32_t IpcServiceGmApplyRegisterInfo(const IpcDataInfo *ipcParams, int32
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGmCheckAccessToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
const char *groupId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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_GROUPID, (uint8_t *)&groupId, NULL);
if ((groupId == NULL) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.checkAccessToGroup(osAccountId, appId, groupId);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmGetPkInfoList(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
const char *queryParams = NULL;
char *returnInfoList = NULL;
uint32_t returnInfoNum = 0;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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(osAccountId, 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;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
const char *groupId = NULL;
const char *managerAppId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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);
@ -586,7 +709,7 @@ static int32_t IpcServiceGmAddGroupManager(const IpcDataInfo *ipcParams, int32_t
LOGE("get param error, type %d", PARAM_TYPE_MGR_APPID);
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.addGroupManager(appId, groupId, managerAppId);
callRet = g_devGroupMgrMethod.addGroupManager(osAccountId, appId, groupId, managerAppId);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
@ -596,11 +719,19 @@ static int32_t IpcServiceGmAddGroupFriend(const IpcDataInfo *ipcParams, int32_t
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
const char *groupId = NULL;
const char *friendAppId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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);
@ -616,7 +747,7 @@ static int32_t IpcServiceGmAddGroupFriend(const IpcDataInfo *ipcParams, int32_t
LOGE("get param error, type %d", PARAM_TYPE_FRIEND_APPID);
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.addGroupFriend(appId, groupId, friendAppId);
callRet = g_devGroupMgrMethod.addGroupFriend(osAccountId, appId, groupId, friendAppId);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
@ -626,11 +757,19 @@ static int32_t IpcServiceGmDelGroupManager(const IpcDataInfo *ipcParams, int32_t
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
const char *groupId = NULL;
const char *managerAppId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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);
@ -646,7 +785,7 @@ static int32_t IpcServiceGmDelGroupManager(const IpcDataInfo *ipcParams, int32_t
LOGE("get param error, type %d", PARAM_TYPE_MGR_APPID);
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.deleteGroupManager(appId, groupId, managerAppId);
callRet = g_devGroupMgrMethod.deleteGroupManager(osAccountId, appId, groupId, managerAppId);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
@ -656,11 +795,19 @@ static int32_t IpcServiceGmDelGroupFriend(const IpcDataInfo *ipcParams, int32_t
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
const char *groupId = NULL;
const char *friendAppId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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);
@ -676,7 +823,7 @@ static int32_t IpcServiceGmDelGroupFriend(const IpcDataInfo *ipcParams, int32_t
LOGE("get param error, type %d", PARAM_TYPE_FRIEND_APPID);
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.deleteGroupFriend(appId, groupId, friendAppId);
callRet = g_devGroupMgrMethod.deleteGroupFriend(osAccountId, appId, groupId, friendAppId);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
@ -686,12 +833,20 @@ static int32_t IpcServiceGmGetGroupManagers(const IpcDataInfo *ipcParams, int32_
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
const char *groupId = NULL;
char *managers = NULL;
uint32_t managersNum = 0;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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);
@ -703,7 +858,7 @@ static int32_t IpcServiceGmGetGroupManagers(const IpcDataInfo *ipcParams, int32_
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.getGroupManagers(appId, groupId, &managers, &managersNum);
callRet = g_devGroupMgrMethod.getGroupManagers(osAccountId, appId, groupId, &managers, &managersNum);
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));
@ -722,12 +877,20 @@ static int32_t IpcServiceGmGetGroupFriends(const IpcDataInfo *ipcParams, int32_t
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
const char *groupId = NULL;
char *friends = NULL;
uint32_t friendsNum = 0;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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);
@ -739,7 +902,7 @@ static int32_t IpcServiceGmGetGroupFriends(const IpcDataInfo *ipcParams, int32_t
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.getGroupFriends(appId, groupId, &friends, &friendsNum);
callRet = g_devGroupMgrMethod.getGroupFriends(osAccountId, appId, groupId, &friends, &friendsNum);
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));
@ -758,11 +921,19 @@ static int32_t IpcServiceGmGetGroupInfoById(const IpcDataInfo *ipcParams, int32_
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
const char *groupId = NULL;
char *groupInfo = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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);
@ -774,7 +945,7 @@ static int32_t IpcServiceGmGetGroupInfoById(const IpcDataInfo *ipcParams, int32_
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.getGroupInfoById(appId, groupId, &groupInfo);
callRet = g_devGroupMgrMethod.getGroupInfoById(osAccountId, appId, groupId, &groupInfo);
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_ipcResultNum1, sizeof(int32_t));
@ -792,12 +963,20 @@ static int32_t IpcServiceGmGetGroupInfo(const IpcDataInfo *ipcParams, int32_t pa
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
const char *queryParams = NULL;
char *outGroups = NULL;
uint32_t groupNum = 0;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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);
@ -809,7 +988,7 @@ static int32_t IpcServiceGmGetGroupInfo(const IpcDataInfo *ipcParams, int32_t pa
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.getGroupInfo(appId, queryParams, &outGroups, &groupNum);
callRet = g_devGroupMgrMethod.getGroupInfo(osAccountId, appId, queryParams, &outGroups, &groupNum);
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));
@ -829,12 +1008,19 @@ static int32_t IpcServiceGmGetJoinedGroups(const IpcDataInfo *ipcParams, int32_t
int32_t callRet;
int32_t ret;
int32_t groupType = 0;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
char *outGroups = NULL;
uint32_t groupNum = 0;
int32_t inOutLen;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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);
@ -847,7 +1033,7 @@ static int32_t IpcServiceGmGetJoinedGroups(const IpcDataInfo *ipcParams, int32_t
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.getJoinedGroups(appId, groupType, &outGroups, &groupNum);
callRet = g_devGroupMgrMethod.getJoinedGroups(osAccountId, appId, groupType, &outGroups, &groupNum);
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));
@ -866,12 +1052,20 @@ static int32_t IpcServiceGmGetRelatedGroups(const IpcDataInfo *ipcParams, int32_
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
const char *peerUdid = NULL;
char *outGroups = NULL;
uint32_t groupNum = 0;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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);
@ -883,7 +1077,7 @@ static int32_t IpcServiceGmGetRelatedGroups(const IpcDataInfo *ipcParams, int32_
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.getRelatedGroups(appId, peerUdid, &outGroups, &groupNum);
callRet = g_devGroupMgrMethod.getRelatedGroups(osAccountId, appId, peerUdid, &outGroups, &groupNum);
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));
@ -902,12 +1096,20 @@ static int32_t IpcServiceGmGetDeviceInfoById(const IpcDataInfo *ipcParams, int32
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
const char *peerUdid = NULL;
const char *groupId = NULL;
char *outDevInfo = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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);
@ -924,7 +1126,7 @@ static int32_t IpcServiceGmGetDeviceInfoById(const IpcDataInfo *ipcParams, int32
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.getDeviceInfoById(appId, peerUdid, groupId, &outDevInfo);
callRet = g_devGroupMgrMethod.getDeviceInfoById(osAccountId, appId, peerUdid, groupId, &outDevInfo);
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_ipcResultNum1, sizeof(int32_t));
@ -943,12 +1145,20 @@ static int32_t IpcServiceGmGetTrustedDevices(const IpcDataInfo *ipcParams, int32
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
const char *appId = NULL;
const char *groupId = NULL;
char *outDevInfo = NULL;
uint32_t outDevNum = 0;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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);
@ -960,7 +1170,7 @@ static int32_t IpcServiceGmGetTrustedDevices(const IpcDataInfo *ipcParams, int32
return HC_ERR_IPC_BAD_PARAM;
}
callRet = g_devGroupMgrMethod.getTrustedDevices(appId, groupId, &outDevInfo, &outDevNum);
callRet = g_devGroupMgrMethod.getTrustedDevices(osAccountId, appId, groupId, &outDevInfo, &outDevNum);
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));
@ -980,12 +1190,20 @@ static int32_t IpcServiceGmIsDeviceInGroup(const IpcDataInfo *ipcParams, int32_t
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int32_t osAccountId;
bool bRet = false;
const char *appId = NULL;
const char *udid = NULL;
const char *groupId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
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);
@ -1002,7 +1220,7 @@ static int32_t IpcServiceGmIsDeviceInGroup(const IpcDataInfo *ipcParams, int32_t
return HC_ERR_IPC_BAD_PARAM;
}
bRet = g_devGroupMgrMethod.isDeviceInGroup(appId, groupId, udid);
bRet = g_devGroupMgrMethod.isDeviceInGroup(osAccountId, appId, groupId, udid);
callRet = ((bRet == true) ? HC_SUCCESS : HC_ERROR);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
@ -1139,12 +1357,19 @@ static int32_t IpcServiceGaAuthDevice(const IpcDataInfo *ipcParams, int32_t para
int32_t callRet;
int32_t ret;
DeviceAuthCallback *gaCallback = NULL;
int32_t osAccountId;
int64_t authReqId = 0;
const char *authParams = NULL;
int32_t inOutLen;
int32_t cbObjIdx = -1;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
return HC_ERR_IPC_BAD_PARAM;
}
inOutLen = sizeof(authReqId);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&authReqId, &inOutLen);
if ((inOutLen != sizeof(authReqId)) || (ret != HC_SUCCESS)) {
@ -1178,7 +1403,7 @@ static int32_t IpcServiceGaAuthDevice(const IpcDataInfo *ipcParams, int32_t para
}
AddIpcCbObjByReqId(authReqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH);
callRet = g_groupAuthMgrMethod.authDevice(authReqId, authParams, &g_authCbAdt);
callRet = g_groupAuthMgrMethod.authDevice(osAccountId, authReqId, authParams, &g_authCbAdt);
if (callRet != HC_SUCCESS) {
DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
}
@ -1226,6 +1451,7 @@ static int32_t AddMethodMap(uintptr_t ipcInstance)
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmProcessLiteData, IPC_CALL_ID_PROC_LIGHT_DATA);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmSaveCredential, IPC_CALL_ID_SAVE_CREDENTIAL);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmApplyRegisterInfo, IPC_CALL_ID_APPLY_REG_INFO);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmCheckAccessToGroup, IPC_CALL_ID_CHECK_ACCESS_TO_GROUP);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmAddGroupManager, IPC_CALL_ID_ADD_GROUP_MGR);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmAddGroupFriend, IPC_CALL_ID_ADD_GROUP_FRIEND);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmDelGroupManager, IPC_CALL_ID_DEL_GROUP_MGR);
@ -1239,6 +1465,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);

View File

@ -1535,7 +1535,7 @@ static bool IsTypeForSettingPtr(int32_t type)
static bool IsTypeForCpyData(int32_t type)
{
int32_t typeList[] = {
PARAM_TYPE_REQID, PARAM_TYPE_GROUP_TYPE, PARAM_TYPE_OPCODE, PARAM_TYPE_ERRCODE
PARAM_TYPE_REQID, PARAM_TYPE_GROUP_TYPE, PARAM_TYPE_OPCODE, PARAM_TYPE_ERRCODE, PARAM_TYPE_OS_ACCOUNT_ID
};
int32_t i;
int32_t n = sizeof(typeList) / sizeof(typeList[0]);

View File

@ -129,6 +129,7 @@ void ResetIpcCallBackNodeByNodeId(int32_t nodeIdx)
return;
}
ResetIpcCallBackNode(g_ipcCallBackList.ctx[nodeIdx]);
g_ipcCallBackList.nodeCnt--;
LOGI("done, index %d", nodeIdx);
return;
}
@ -354,7 +355,7 @@ int32_t AddIpcCallBackByReqId(int64_t reqId, const uint8_t *cbPtr, int32_t cbSz,
ServiceDevAuth::ResetRemoteObject(node->proxyId);
node->proxyId = -1;
}
LOGI("callback added success, request id %lld, type %d", (long long)reqId, type);
LOGI("callback replaced success, request id %lld, type %d", (long long)reqId, type);
return HC_SUCCESS;
}
@ -1442,7 +1443,7 @@ static bool IsTypeForSettingPtr(int32_t type)
static bool IsTypeForCpyData(int32_t type)
{
int32_t typeList[] = {
PARAM_TYPE_REQID, PARAM_TYPE_GROUP_TYPE, PARAM_TYPE_OPCODE, PARAM_TYPE_ERRCODE
PARAM_TYPE_REQID, PARAM_TYPE_GROUP_TYPE, PARAM_TYPE_OPCODE, PARAM_TYPE_ERRCODE, PARAM_TYPE_OS_ACCOUNT_ID
};
int32_t i;
int32_t n = sizeof(typeList) / sizeof(typeList[0]);

View File

@ -67,6 +67,13 @@
#define FIELD_EXPIRE_TIME "expireTime"
#define FIELD_IS_DELETE_ALL "isDeleteAll"
#define FIELD_BLE_CHALLENGE "bleChallenge"
#define FIELD_OS_ACCOUNT_ID "osAccountId"
typedef enum {
DEFAULT_OS_ACCOUNT = 0,
INVALID_OS_ACCOUNT = -1,
ANY_OS_ACCOUNT = -2,
} OsAccountEnum;
typedef enum {
ALL_GROUP = 0,
@ -145,7 +152,8 @@ typedef struct {
bool (*isTrustedDevice)(const char *udid);
int32_t (*getAuthState)(int64_t authReqId, const char *groupId, const char *peerUdid,
uint8_t *out, uint32_t *outLen);
int32_t (*authDevice)(int64_t authReqId, const char *authParams, const DeviceAuthCallback *gaCallback);
int32_t (*authDevice)(int32_t osAccountId, int64_t authReqId, const char *authParams,
const DeviceAuthCallback *gaCallback);
void (*informDeviceDisconnection)(const char *udid);
} GroupAuthManager;
@ -154,12 +162,13 @@ typedef struct {
int32_t (*unRegCallback)(const char *appId);
int32_t (*regDataChangeListener)(const char *appId, const DataChangeListener *listener);
int32_t (*unRegDataChangeListener)(const char *appId);
int32_t (*createGroup)(int64_t requestId, const char *appId, const char *createParams);
int32_t (*deleteGroup)(int64_t requestId, const char *appId, const char *disbandParams);
int32_t (*addMemberToGroup)(int64_t requestId, const char *appId, const char *addParams);
int32_t (*deleteMemberFromGroup)(int64_t requestId, const char *appId, const char *deleteParams);
int32_t (*createGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams);
int32_t (*deleteGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *disbandParams);
int32_t (*addMemberToGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams);
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 (*confirmRequest)(int64_t requestId, const char *appId, const char *confirmParams);
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);
int32_t (*processLiteData)(int64_t requestId, const char *appId, const uint8_t *data, uint32_t dataLen);
@ -168,21 +177,30 @@ typedef struct {
int32_t (*processCredential)(int operationCode, const char *reqJsonStr, char **returnJsonStr);
int32_t (*getRegisterInfo)(char **returnRegisterInfo);
int32_t (*getLocalConnectInfo)(char *returnInfo, int32_t bufLen);
int32_t (*checkAccessToGroup)(const char *appId, const char *groupId);
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);
int32_t (*deleteGroupFriend)(const char *appId, const char *groupId, const char *friendAppId);
int32_t (*getGroupManagers)(const char *appId, const char *groupId, char **returnManagers, uint32_t *returnSize);
int32_t (*getGroupFriends)(const char *appId, const char *groupId, char **returnFriends, uint32_t *returnSize);
int32_t (*getGroupInfoById)(const char *appId, const char *groupId, char **returnGroupInfo);
int32_t (*getGroupInfo)(const char *appId, const char *queryParams, char **returnGroupVec, uint32_t *groupNum);
int32_t (*getJoinedGroups)(const char *appId, int groupType, char **returnGroupVec, uint32_t *groupNum);
int32_t (*getRelatedGroups)(const char *appId, const char *peerDeviceId, char **returnGroupVec, uint32_t *groupNum);
int32_t (*getDeviceInfoById)(const char *appId, const char *deviceId, const char *groupId,
int32_t (*checkAccessToGroup)(int32_t osAccountId, const char *appId, const char *groupId);
int32_t (*getPkInfoList)(int32_t osAccountId, const char *appId, const char *queryParams, char **returnInfoList,
uint32_t *returnInfoNum);
int32_t (*addGroupManager)(int32_t osAccountId, const char *appId, const char *groupId, const char *managerAppId);
int32_t (*addGroupFriend)(int32_t osAccountId, const char *appId, const char *groupId, const char *friendAppId);
int32_t (*deleteGroupManager)(int32_t osAccountId, const char *appId, const char *groupId,
const char *managerAppId);
int32_t (*deleteGroupFriend)(int32_t osAccountId, const char *appId, const char *groupId, const char *friendAppId);
int32_t (*getGroupManagers)(int32_t osAccountId, const char *appId, const char *groupId, char **returnManagers,
uint32_t *returnSize);
int32_t (*getGroupFriends)(int32_t osAccountId, const char *appId, const char *groupId,
char **returnFriends, uint32_t *returnSize);
int32_t (*getGroupInfoById)(int32_t osAccountId, const char *appId, const char *groupId, char **returnGroupInfo);
int32_t (*getGroupInfo)(int32_t osAccountId, const char *appId, const char *queryParams,
char **returnGroupVec, uint32_t *groupNum);
int32_t (*getJoinedGroups)(int32_t osAccountId, const char *appId, int groupType,
char **returnGroupVec, uint32_t *groupNum);
int32_t (*getRelatedGroups)(int32_t osAccountId, const char *appId, const char *peerDeviceId,
char **returnGroupVec, uint32_t *groupNum);
int32_t (*getDeviceInfoById)(int32_t osAccountId, const char *appId, const char *deviceId, const char *groupId,
char **returnDeviceInfo);
int32_t (*getTrustedDevices)(const char *appId, const char *groupId, char **returnDevInfoVec, uint32_t *deviceNum);
bool (*isDeviceInGroup)(const char *appId, const char *groupId, const char *deviceId);
int32_t (*getTrustedDevices)(int32_t osAccountId, const char *appId, const char *groupId,
char **returnDevInfoVec, uint32_t *deviceNum);
bool (*isDeviceInGroup)(int32_t osAccountId, const char *appId, const char *groupId, const char *deviceId);
void (*destroyInfo)(char **returnInfo);
} DeviceGroupManager;

View File

@ -139,6 +139,8 @@ if (defined(ohos_lite)) {
"//foundation/communication/dsoftbus/interfaces/kits/common",
"//foundation/communication/dsoftbus/interfaces/kits/transport",
"//foundation/communication/dsoftbus/interfaces/inner_kits/transport",
"//third_party/json/include",
"//base/account/os_account/interfaces/innerkits/osaccount/native/include",
]
sources = deviceauth_files
@ -158,6 +160,7 @@ if (defined(ohos_lite)) {
external_deps = [
"dsoftbus_standard:softbus_client",
"hiviewdfx_hilog_native:libhilog",
"os_account_standard:os_account_innerkits",
]
}

View File

@ -24,7 +24,8 @@ typedef struct DasAuthModuleT {
AuthModuleBase moduleBase;
int32_t (*registerLocalIdentity)(const char *, const char *, Uint8Buff *, int);
int32_t (*unregisterLocalIdentity)(const char *, const char *, Uint8Buff *, int);
int32_t (*deletePeerAuthInfo)(const char *, const char *, Uint8Buff *, int);
int32_t (*deletePeerAuthInfo)(const char *, const char *, Uint8Buff *, int);
int32_t (*getPublicKey)(const char *, const char *, Uint8Buff *, int, Uint8Buff *);
} DasAuthModule;
bool IsDasSupported(void);

View File

@ -39,5 +39,7 @@ 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

View File

@ -20,10 +20,11 @@
#include "pake_base_cur_task.h"
typedef struct TokenManagerT {
int (*registerLocalIdentity)(const char *, const char *, Uint8Buff *, int);
int32_t (*registerLocalIdentity)(const char *, const char *, Uint8Buff *, int);
int32_t (*unregisterLocalIdentity)(const char *, const char *, Uint8Buff *, int);
int32_t (*deletePeerAuthInfo)(const char *, const char *, Uint8Buff *, int);
int (*computeAndSavePsk)(const PakeParams *);
int32_t (*computeAndSavePsk)(const PakeParams *);
int32_t (*getPublicKey)(const char *, const char *, Uint8Buff *, int, Uint8Buff *);
} TokenManager;
#endif

View File

@ -23,7 +23,7 @@
#define DAS_CLIENT_STEP_MASK 0xF00F
#define DAS_CLIENT_FIRST_MESSAGE 0x0001
DECLARE_HC_VECTOR(TaskInModuleVec, void *)
DECLARE_HC_VECTOR(TaskInModuleVec, void *);
IMPLEMENT_HC_VECTOR(TaskInModuleVec, void *, 1)
TaskInModuleVec g_taskInModuleVec;
@ -44,6 +44,12 @@ 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)
{
int32_t message = 0;
@ -87,7 +93,7 @@ static void DestroyDasModule(AuthModuleBase *module)
((Task *)(*ptr))->destroyTask((Task *)(*ptr));
}
}
DESTROY_HC_VECTOR(TaskInModuleVec, &g_taskInModuleVec)
DESTROY_HC_VECTOR(TaskInModuleVec, &g_taskInModuleVec);
DestroyDasProtocolEntities();
if (module != NULL) {
(void)memset_s(module, sizeof(DasAuthModule), 0, sizeof(DasAuthModule));
@ -147,7 +153,8 @@ AuthModuleBase *CreateDasModule(void)
g_dasModule.registerLocalIdentity = RegisterDasLocalIdentity;
g_dasModule.unregisterLocalIdentity = UnregisterDasLocalIdentity;
g_dasModule.deletePeerAuthInfo = DeleteDasPeerAuthInfo;
g_taskInModuleVec = CREATE_HC_VECTOR(TaskInModuleVec)
g_dasModule.getPublicKey = GetDasPublicKey;
g_taskInModuleVec = CREATE_HC_VECTOR(TaskInModuleVec);
if (InitDasProtocolEntities() != HC_SUCCESS) {
LOGE("Init das protocol entities failed.");
DestroyDasModule((AuthModuleBase *)&g_dasModule);

View File

@ -35,7 +35,7 @@ typedef struct DasProtocolEntityT {
} DasProtocolEntity;
IMPLEMENT_HC_VECTOR(SubTaskVec, void *, 1)
DECLARE_HC_VECTOR(DasProtocolEntityVec, void *)
DECLARE_HC_VECTOR(DasProtocolEntityVec, void *);
IMPLEMENT_HC_VECTOR(DasProtocolEntityVec, void *, 1)
DasProtocolEntityVec g_protocolEntityVec;
@ -123,7 +123,7 @@ static void DestroyTaskT(Task *task)
((SubTaskBase *)(*ptr))->destroyTask((SubTaskBase *)(*ptr));
}
}
DESTROY_HC_VECTOR(SubTaskVec, &(task->vec))
DESTROY_HC_VECTOR(SubTaskVec, &(task->vec));
HcFree(task);
}
@ -367,7 +367,7 @@ Task *CreateTaskT(int32_t *taskId, const CJson *in, CJson *out)
res = HC_ERR_ALLOC_MEMORY;
goto ERR;
}
task->vec = CREATE_HC_VECTOR(SubTaskVec)
task->vec = CREATE_HC_VECTOR(SubTaskVec);
task->destroyTask = DestroyTaskT;
task->processTask = ProcessTaskT;
@ -469,6 +469,25 @@ 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;
@ -484,7 +503,7 @@ static uint32_t GetPakeAlgInProtocol(int offset)
int32_t InitDasProtocolEntities(void)
{
g_protocolEntityVec = CREATE_HC_VECTOR(DasProtocolEntityVec)
g_protocolEntityVec = CREATE_HC_VECTOR(DasProtocolEntityVec);
DasProtocolEntity *protocol = NULL;
if (IsIsoSupported()) {
protocol = (DasProtocolEntity *)HcMalloc(sizeof(DasProtocolEntity), 0);
@ -538,5 +557,5 @@ void DestroyDasProtocolEntities(void)
*ptr = NULL;
}
}
DESTROY_HC_VECTOR(DasProtocolEntityVec, &g_protocolEntityVec)
DESTROY_HC_VECTOR(DasProtocolEntityVec, &g_protocolEntityVec);
}

View File

@ -74,6 +74,7 @@ TokenManager g_symTokenManagerInstance = {
.unregisterLocalIdentity = UnregisterLocalIdentity,
.deletePeerAuthInfo = DeletePeerAuthInfo,
.computeAndSavePsk = NULL,
.getPublicKey = NULL,
};
const TokenManager *GetLiteTokenManagerInstance(void)

View File

@ -166,11 +166,42 @@ 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()

View File

@ -0,0 +1,106 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DATA_MANAGER_H
#define DATA_MANAGER_H
#include <stdbool.h>
#include "hc_string.h"
#include "hc_string_vector.h"
#include "hc_tlv_parser.h"
#include "hc_vector.h"
#define MAX_STRING_LEN 256
#define MAX_EXPIRE_TIME 90
#define HC_TRUST_DEV_ENTRY_MAX_NUM 101
#define HC_TRUST_GROUP_ENTRY_MAX_NUM 100
typedef struct {
HcString name; /* group name */
HcString id; /* group id */
int32_t type; /* including identical account group(1), peer to peer group(256), across account group(1282) */
int32_t visibility; /* visibility of the group */
int32_t expireTime; /* the time of group expired, unit day, user config */
HcString userIdHash; /* hash result of the user account id */
StringVector sharedUserIdHashVec; /* vector of hash results for shared user account id */
StringVector managers; /* group manager vector, group manager can add and delete members, index 0 is the owner */
StringVector friends; /* group friend vector, group friend can query group information */
} TrustedGroupEntry;
DECLARE_HC_VECTOR(GroupEntryVec, TrustedGroupEntry*)
typedef struct {
TrustedGroupEntry *groupEntry;
HcString groupId;
HcString udid; /* unique device id */
HcString authId; /* id by service defined for authentication */
HcString serviceType; /* compatible with previous versions, the value is the same as groupId */
HcParcel ext; /* for caching extern data, user data */
uint8_t credential; /* 1 - asymmetrical, 2 - symmetrical */
uint8_t devType; /* 0 - accessory, 1 - controller, 2 - proxy */
HcString userIdHash; /* hash result of the user account id */
uint64_t lastTm; /* accessed time of the device of the auth information, absolute time */
} TrustedDeviceEntry;
DECLARE_HC_VECTOR(DeviceEntryVec, TrustedDeviceEntry*)
typedef struct {
const char *groupId;
const char *groupName;
const char *ownerName;
int32_t groupType;
int32_t groupVisibility;
} QueryGroupParams;
typedef struct {
const char *groupId;
const char *udid;
const char *authId;
} QueryDeviceParams;
#ifdef __cplusplus
extern "C" {
#endif
int32_t InitDatabase(void);
void DestroyDatabase(void);
int32_t AddGroup(int32_t osAccountId, const TrustedGroupEntry *groupEntry);
int32_t DelGroup(int32_t osAccountId, const QueryGroupParams *params);
int32_t AddTrustedDevice(int32_t osAccountId, const TrustedDeviceEntry *deviceEntry);
int32_t DelTrustedDevice(int32_t osAccountId, const QueryDeviceParams *params);
int32_t QueryGroups(int32_t osAccountId, const QueryGroupParams *params, GroupEntryVec *vec);
int32_t QueryDevices(int32_t osAccountId, const QueryDeviceParams *params, DeviceEntryVec *vec);
int32_t SaveOsAccountDb(int32_t osAccountId);
bool GenerateGroupEntryFromEntry(const TrustedGroupEntry *entry, TrustedGroupEntry *returnEntry);
bool GenerateDeviceEntryFromEntry(const TrustedDeviceEntry *entry, TrustedDeviceEntry *returnEntry);
TrustedGroupEntry *DeepCopyGroupEntry(const TrustedGroupEntry *entry);
TrustedDeviceEntry *DeepCopyDeviceEntry(const TrustedDeviceEntry *entry);
QueryGroupParams InitQueryGroupParams(void);
QueryDeviceParams InitQueryDeviceParams(void);
TrustedGroupEntry *CreateGroupEntry(void);
TrustedDeviceEntry *CreateDeviceEntry(void);
void DestroyGroupEntry(TrustedGroupEntry *groupEntry);
void DestroyDeviceEntry(TrustedDeviceEntry *groupEntry);
GroupEntryVec CreateGroupEntryVec(void);
DeviceEntryVec CreateDeviceEntryVec(void);
void ClearGroupEntryVec(GroupEntryVec *vec);
void ClearDeviceEntryVec(DeviceEntryVec *vec);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,123 +0,0 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DATABASE_H
#define DATABASE_H
#include "common_defs.h"
#include "hc_string.h"
#include "hc_tlv_parser.h"
#include "hc_vector.h"
#define MAX_STRING_LEN 256
#define MAX_EXPIRE_TIME 90
typedef int32_t (*GenGroupIdFunc)(const char *userIdHash, const char *sharedUserIdHash, char **returnGroupId);
typedef struct {
HcString name; /* group name */
HcString id; /* group id */
int32_t type; /* including identical account group(1), peer to peer group(256), across account group(1282) */
int32_t visibility; /* visibility of the group */
int32_t expireTime; /* the time of group expired, unit day, user config */
HcString userIdHash; /* hash result of the user account id */
StringVector sharedUserIdHashVec; /* vector of hash results for shared user account id */
StringVector managers; /* group manager vector, group manager can add and delete members, index 0 is the owner */
StringVector friends; /* group friend vector, group friend can query group information */
} TrustedGroupEntry;
DECLARE_HC_VECTOR(TrustedGroupTable, TrustedGroupEntry*)
typedef struct {
TrustedGroupEntry *groupEntry;
HcString udid; /* unique device id */
HcString authId; /* id by service defined for authentication */
HcString serviceType; /* compatible with previous versions, the value is the same as groupId */
HcParcel ext; /* for caching extern data, user data */
uint8_t credential; /* 1 - asymmetrical, 2 - symmetrical */
uint8_t devType; /* 0 - accessory, 1 - controller, 2 - proxy */
HcString userIdHash; /* hash result of the user account id */
uint64_t lastTm; /* accessed time of the device of the auth information, absolute time */
} TrustedDeviceEntry;
DECLARE_HC_VECTOR(TrustedDeviceTable, TrustedDeviceEntry)
typedef struct {
DECLARE_TLV_STRUCT(9)
TlvString name;
TlvString id;
TlvUint32 type;
TlvInt32 visibility;
TlvInt32 expireTime;
TlvString userIdHash;
TlvBuffer sharedUserIdHashVec;
TlvBuffer managers;
TlvBuffer friends;
} TlvGroupElement;
DECLEAR_INIT_FUNC(TlvGroupElement)
DECLARE_TLV_VECTOR(TlvGroupVec, TlvGroupElement)
typedef struct {
uint8_t credential;
uint8_t devType;
int64_t userId;
uint64_t lastTm;
} DevAuthFixedLenInfo;
DECLARE_TLV_FIX_LENGTH_TYPE(TlvDevAuthFixedLenInfo, DevAuthFixedLenInfo)
DECLEAR_INIT_FUNC(TlvDevAuthFixedLenInfo)
typedef struct {
DECLARE_TLV_STRUCT(7)
TlvString groupId;
TlvString udid;
TlvString authId;
TlvString serviceType;
TlvBuffer ext;
TlvDevAuthFixedLenInfo info;
TlvString userIdHash;
} TlvDevAuthElement;
DECLEAR_INIT_FUNC(TlvDevAuthElement)
DECLARE_TLV_VECTOR(TlvDevAuthVec, TlvDevAuthElement)
typedef struct {
DECLARE_TLV_STRUCT(3)
TlvInt32 version;
TlvGroupVec groups;
TlvDevAuthVec devices;
} HCDataBaseV1;
DECLEAR_INIT_FUNC(HCDataBaseV1)
typedef struct {
HcString name; /* group name */
HcString id; /* group id */
HcString ownerName; /* group owner name */
int32_t type; /* group type, 0 - invalid, 1 - the same account, 2 - different account, 3 - none account(p2p) */
int32_t visibility; /* visibility of the group */
int32_t expireTime; /* the time of group expired, unit day, user config */
HcString userIdHash; /* hash result of the user account id */
HcString sharedUserIdHash; /* shared user account id */
} GroupInfo;
DECLARE_HC_VECTOR(GroupInfoVec, void *)
typedef struct {
HcString udid; /* unique device id */
HcString authId; /* id by service defined for authentication */
uint8_t credential; /* 1 - asymmetrical, 2 - symmetrical */
uint8_t devType; /* 0 - accessory, 1 - controller, 2 - proxy */
HcString userIdHash; /* hash result of the user account id */
HcString groupId; /* map the device authentication data for group */
HcString serviceType; /* compatible with previous versions, the value is the same as groupId */
} DeviceInfo;
DECLARE_HC_VECTOR(DeviceInfoVec, void *)
#endif

View File

@ -1,101 +0,0 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DATABASE_MANAGER_H
#define DATABASE_MANAGER_H
#include "common_defs.h"
#include "string_util.h"
#include "database.h"
#define HC_TRUST_DEV_ENTRY_MAX_NUM 101
#define HC_TRUST_GROUP_ENTRY_MAX_NUM 100
typedef struct {
int32_t type; /* group type */
int32_t visibility; /* group visibility */
char *udid; /* unique device id */
char *authId; /* id by service defined for authentication */
} GroupQueryParams;
typedef enum {
GROUP_MANAGER = 1,
GROUP_FRIEND = 2
} GroupRole;
#ifdef __cplusplus
extern "C" {
#endif
int32_t InitDatabase(void);
void DestroyDatabase(void);
StringVector CreateStrVector(void);
void DestroyStrVector(StringVector *obj);
int32_t AddGroup(const GroupInfo *addParams);
int32_t DelGroupByGroupId(const char *groupId);
int32_t AddTrustedDevice(const DeviceInfo *deviceInfo, const Uint8Buff *ext);
int32_t DelTrustedDevice(const char *deviceId, bool isUdid, const char *groupId);
int32_t DeleteUserIdExpiredGroups(const char *curUserIdHash);
int32_t DeleteAllAccountGroup(void);
int32_t OnlyAddSharedUserIdVec(const StringVector *sharedUserIdHashVec, CJson *groupIdList);
int32_t ChangeSharedUserIdVec(const StringVector *sharedUserIdHashVec);
const char *GetLocalDevUdid(void);
void RegGenerateGroupIdFunc(GenGroupIdFunc func);
void DeregGenerateGroupIdFunc(void);
int32_t GetTrustedDevNumber(void);
int32_t GetGroupInfoById(const char *groupId, GroupInfo *returnGroupInfo);
int32_t GetGroupInfoIfDevExist(const char *groupId, const char *udid, GroupInfo *returnGroupInfo);
int32_t GetTrustedDevInfoById(const char *deviceId, bool isUdid, const char *groupId, DeviceInfo *deviceInfo);
int32_t GetJoinedGroupInfoVecByDevId(const GroupQueryParams *params, GroupInfoVec *vec);
int32_t GetGroupNumByOwner(const char *ownerName);
int32_t GetCurDeviceNumByGroupId(const char *groupId);
int32_t CompareVisibility(const char *groupId, int groupVisibility);
bool IsGroupOwner(const char *groupId, const char *appId);
bool IsGroupAccessible(const char *groupId, const char *appId);
bool IsGroupEditAllowed(const char *groupId, const char *appId);
bool IsSameNameGroupExist(const char *ownerName, const char *groupName);
bool IsIdenticalGroupExist(void);
bool IsAcrossAccountGroupExist(void);
bool IsGroupExistByGroupId(const char *groupId);
bool IsTrustedDeviceExist(const char *udid);
bool IsTrustedDeviceInGroup(const char *groupId, const char *deviceId, bool isUdid);
int32_t GetJoinedGroups(int groupType, GroupInfoVec *groupInfoVec);
int32_t GetGroupInfo(int groupType, const char *groupId, const char *groupName, const char *groupOwner,
GroupInfoVec *groupInfoVec);
int32_t GetRelatedGroups(const char *peerDeviceId, bool isUdid, GroupInfoVec *groupInfoVec);
int32_t GetTrustedDevices(const char *groupId, DeviceInfoVec *deviceInfoVec);
int32_t AddGroupRole(const char *groupId, GroupRole roleType, const char *appId);
int32_t RemoveGroupRole(const char *groupId, GroupRole roleType, const char *appId);
int32_t GetGroupRoles(const char *groupId, GroupRole roleType, CJson *returnRoles);
GroupInfo *CreateGroupInfoStruct(void);
DeviceInfo *CreateDeviceInfoStruct(void);
void DestroyGroupInfoStruct(GroupInfo *groupInfo);
void DestroyDeviceInfoStruct(DeviceInfo *deviceInfo);
void CreateGroupInfoVecStruct(GroupInfoVec *vec);
void DestroyGroupInfoVecStruct(GroupInfoVec *vec);
void CreateDeviceInfoVecStruct(DeviceInfoVec *vec);
void DestroyDeviceInfoVecStruct(DeviceInfoVec *vec);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,77 +0,0 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DATABASE_UTIL_H
#define DATABASE_UTIL_H
#include "database.h"
#ifdef __cplusplus
extern "C" {
#endif
bool SetGroupElement(TlvGroupElement *element, TrustedGroupEntry **entry);
bool SetDeviceElement(TlvDevAuthElement *element, TrustedDeviceEntry *entry);
void RegGenerateGroupIdFunc(GenGroupIdFunc func);
void DeregGenerateGroupIdFunc(void);
bool LoadStringVectorFromParcel(StringVector *vec, HcParcel *parcel);
bool SaveStringVectorToParcel(const StringVector *vec, HcParcel *parcel);
StringVector CreateStrVector(void);
void DestroyStrVector(StringVector *vec);
GroupInfo *CreateGroupInfoStruct(void);
void DestroyGroupInfoStruct(GroupInfo *groupInfo);
DeviceInfo *CreateDeviceInfoStruct(void);
void DestroyDeviceInfoStruct(DeviceInfo *deviceInfo);
TrustedGroupEntry *CreateGroupEntryStruct(void);
void DestroyGroupEntryStruct(TrustedGroupEntry *groupEntry);
void DestroyDeviceEntryStruct(TrustedDeviceEntry *deviceEntry);
int32_t GenerateGroupInfoByEntry(const TrustedGroupEntry *groupEntry, const char *groupId,
const char *sharedUserIdHash, GroupInfo *returnGroupInfo);
int32_t GenerateDeviceInfoByEntry(const TrustedDeviceEntry *deviceEntry, const char *groupId,
DeviceInfo *returnDeviceInfo);
int32_t GetSharedUserIdFromVecByGroupId(const TrustedGroupEntry *groupEntry, const char *groupId,
const char **returnUserIdHash);
void AddNewSharedUserId(const StringVector *sharedUserIdHashList, TrustedGroupEntry *entry, CJson *groupIdList);
void DeleteExpiredSharedUserId(const StringVector *sharedUserIdHashList, TrustedGroupEntry *entry);
bool CompareGroupTypeInGroupEntryOrAll(const TrustedGroupEntry *groupEntry, int32_t groupType);
bool CompareDevIdInDeviceEntryOrNull(const TrustedDeviceEntry *deviceEntry, const char *devId, bool isUdid);
bool CompareGroupIdInDeviceEntryOrNull(const TrustedDeviceEntry *deviceEntry, const char *groupId);
bool CompareSearchParams(int32_t groupType, const char *groupId, const char *groupName, const char *groupOwner,
const TrustedGroupEntry *entry);
bool IsGroupIdEquals(const TrustedGroupEntry *groupEntry, const char *groupId);
bool IsGroupNameEquals(const TrustedGroupEntry *groupEntry, const char *groupName);
bool IsGroupManager(const char *appId, const TrustedGroupEntry *entry);
bool IsGroupFriend(const char *appId, const TrustedGroupEntry *entry);
bool SatisfyType(int32_t type, int32_t standardType);
bool SatisfyVisibility(int32_t visibility, int32_t standardVisibility);
void NotifyGroupCreated(const TrustedGroupEntry *groupEntry, const char *sharedUserIdHash);
void NotifyGroupDeleted(const TrustedGroupEntry *groupEntry, const char *sharedUserIdHash);
void NotifyDeviceBound(const TrustedDeviceEntry *deviceEntry);
void NotifyDeviceUnBound(const TrustedDeviceEntry *deviceEntry);
void NotifyDeviceNotTrusted(const char *peerUdid);
void NotifyLastGroupDeleted(const char *peerUdid, int groupType);
void NotifyTrustedDeviceNumChanged(int trustedDeviceNum);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "database_manager.h"
#include "data_manager.h"
#include "database_util.h"
#include "device_auth.h"
@ -441,7 +441,7 @@ static int32_t GenerateGroupEntryByInfo(const GroupInfo *groupInfo, TrustedGroup
return HC_SUCCESS;
}
static int32_t GenerateDeviceEntryByInfo(const DeviceInfo *deviceInfo, const Uint8Buff *ext,
static int32_t GenerateDeviceEntryByInfo(const TrustedDeviceEntry *deviceInfo, const Uint8Buff *ext,
TrustedDeviceEntry *deviceEntry)
{
deviceEntry->udid = CreateString();
@ -747,7 +747,7 @@ static int32_t PushGroupInfoToVec(const TrustedGroupEntry *entry, const char *gr
static int32_t PushDevInfoToVec(const TrustedDeviceEntry *entry, const char *groupId, DeviceInfoVec *deviceInfoVec)
{
DeviceInfo *deviceInfo = CreateDeviceInfoStruct();
TrustedDeviceEntry *deviceInfo = CreateDeviceInfoStruct();
if (deviceInfo == NULL) {
LOGE("[DB]: Failed to allocate deviceInfo memory!");
return HC_ERR_ALLOC_MEMORY;
@ -839,7 +839,7 @@ int32_t DelGroupByGroupId(const char *groupId)
return HC_SUCCESS;
}
int32_t AddTrustedDevice(const DeviceInfo *deviceInfo, const Uint8Buff *ext)
int32_t AddTrustedDevice(const TrustedDeviceEntry *deviceInfo, const Uint8Buff *ext)
{
LOGI("[DB]: Start to add a trusted device to database!");
if (deviceInfo == NULL) {
@ -1253,7 +1253,7 @@ bool IsGroupExistByGroupId(const char *groupId)
return isExists;
}
int32_t GetTrustedDevInfoById(const char *deviceId, bool isUdid, const char *groupId, DeviceInfo *deviceInfo)
int32_t GetTrustedDevInfoById(const char *deviceId, bool isUdid, const char *groupId, TrustedDeviceEntry *deviceInfo)
{
if ((deviceId == NULL) || (groupId == NULL) || (deviceInfo == NULL)) {
LOGE("[DB]: The input parameters contains NULL value!");
@ -1343,7 +1343,7 @@ void CreateGroupInfoVecStruct(GroupInfoVec *vec)
if (vec == NULL) {
return;
}
*vec = CREATE_HC_VECTOR(GroupInfoVec)
*vec = CREATE_HC_VECTOR(GroupInfoVec);
}
void DestroyGroupInfoVecStruct(GroupInfoVec *vec)
@ -1355,7 +1355,7 @@ void DestroyGroupInfoVecStruct(GroupInfoVec *vec)
DestroyGroupInfoStruct(*entry);
}
}
DESTROY_HC_VECTOR(GroupInfoVec, vec)
DESTROY_HC_VECTOR(GroupInfoVec, vec);
}
void CreateDeviceInfoVecStruct(DeviceInfoVec *vec)
@ -1363,7 +1363,7 @@ void CreateDeviceInfoVecStruct(DeviceInfoVec *vec)
if (vec == NULL) {
return;
}
*vec = CREATE_HC_VECTOR(DeviceInfoVec)
*vec = CREATE_HC_VECTOR(DeviceInfoVec);
}
void DestroyDeviceInfoVecStruct(DeviceInfoVec *vec)
@ -1375,7 +1375,7 @@ void DestroyDeviceInfoVecStruct(DeviceInfoVec *vec)
DestroyDeviceInfoStruct(*entry);
}
}
DESTROY_HC_VECTOR(DeviceInfoVec, vec)
DESTROY_HC_VECTOR(DeviceInfoVec, vec);
}
int32_t GetJoinedGroupInfoVecByDevId(const GroupQueryParams *params, GroupInfoVec *vec)

View File

@ -123,7 +123,7 @@ static int32_t GenerateAcrossAccountGroupInfoByUserIdHash(const TrustedGroupEntr
return GenerateGroupInfoSharedUserIdHash(sharedUserIdHash, returnGroupInfo);
}
static int32_t GenerateDeviceInfoCommonByEntry(const TrustedDeviceEntry *entry, DeviceInfo *returnDeviceInfo)
static int32_t GenerateDeviceInfoCommonByEntry(const TrustedDeviceEntry *entry, TrustedDeviceEntry *returnDeviceInfo)
{
if (!StringSet(&returnDeviceInfo->udid, entry->udid)) {
LOGE("[DB]: Failed to copy udid!");
@ -146,7 +146,7 @@ static int32_t GenerateDeviceInfoCommonByEntry(const TrustedDeviceEntry *entry,
return HC_SUCCESS;
}
static int32_t GenerateDeviceInfoId(const char *groupId, DeviceInfo *returnDeviceInfo)
static int32_t GenerateDeviceInfoId(const char *groupId, TrustedDeviceEntry *returnDeviceInfo)
{
if (!StringSetPointer(&(returnDeviceInfo->groupId), groupId)) {
LOGE("[DB]: Failed to copy groupId!");
@ -240,7 +240,7 @@ void DestroyStrVector(StringVector *vec)
FOR_EACH_HC_VECTOR(*vec, index, strItemPtr) {
DeleteString(strItemPtr);
}
DESTROY_HC_VECTOR(StringVector, vec)
DESTROY_HC_VECTOR(StringVector, vec);
}
GroupInfo *CreateGroupInfoStruct(void)
@ -271,9 +271,9 @@ void DestroyGroupInfoStruct(GroupInfo *groupInfo)
HcFree(groupInfo);
}
DeviceInfo *CreateDeviceInfoStruct(void)
TrustedDeviceEntry *CreateDeviceInfoStruct(void)
{
DeviceInfo *deviceInfo = (DeviceInfo *)HcMalloc(sizeof(DeviceInfo), 0);
TrustedDeviceEntry *deviceInfo = (TrustedDeviceEntry *)HcMalloc(sizeof(DeviceInfo), 0);
if (deviceInfo == NULL) {
LOGE("[DB]: Failed to allocate deviceInfo memory!");
return NULL;
@ -286,7 +286,7 @@ DeviceInfo *CreateDeviceInfoStruct(void)
return deviceInfo;
}
void DestroyDeviceInfoStruct(DeviceInfo *deviceInfo)
void DestroyDeviceInfoStruct(TrustedDeviceEntry *deviceInfo)
{
if (deviceInfo == NULL) {
return;
@ -358,7 +358,7 @@ int32_t GenerateGroupInfoByEntry(const TrustedGroupEntry *groupEntry, const char
}
int32_t GenerateDeviceInfoByEntry(const TrustedDeviceEntry *deviceEntry, const char *groupId,
DeviceInfo *returnDeviceInfo)
TrustedDeviceEntry *returnDeviceInfo)
{
int32_t result = GenerateDeviceInfoCommonByEntry(deviceEntry, returnDeviceInfo);
if (result != HC_SUCCESS) {

View File

@ -26,6 +26,7 @@
#include "hc_log.h"
#include "json_utils.h"
#include "lcm_adapter.h"
#include "os_account_adapter.h"
#include "session_manager.h"
#include "task_manager.h"
@ -38,7 +39,7 @@ static void DestroyGroupAuthTask(HcTaskBase *task)
FreeJson(realTask->authParams);
}
static bool InitAuthDeviceTask(AuthDeviceTask *task, int64_t authReqId, CJson *authParams,
static bool InitAuthDeviceTask(int32_t osAccountId, AuthDeviceTask *task, int64_t authReqId, CJson *authParams,
const DeviceAuthCallback *gaCallback)
{
task->base.doAction = DoAuthDevice;
@ -48,6 +49,10 @@ static bool InitAuthDeviceTask(AuthDeviceTask *task, int64_t authReqId, CJson *a
LOGE("Failed to add requestId to json!");
return false;
}
if (AddIntToJson(authParams, FIELD_OS_ACCOUNT_ID, osAccountId) != HC_SUCCESS) {
LOGE("Failed to add os accountId to json for auth device!");
return false;
}
task->authParams = authParams;
task->callback = gaCallback;
if (task->callback == NULL) {
@ -57,8 +62,8 @@ static bool InitAuthDeviceTask(AuthDeviceTask *task, int64_t authReqId, CJson *a
return true;
}
static bool InitProcessDataTask(AuthDeviceTask *task, int64_t authReqId, CJson *receivedData,
const DeviceAuthCallback *gaCallback)
static bool InitProcessDataTask(AuthDeviceTask *task, int64_t authReqId,
CJson *receivedData, const DeviceAuthCallback *gaCallback)
{
task->base.doAction = DoProcessAuthData;
task->base.destroy = DestroyGroupAuthTask;
@ -80,9 +85,11 @@ static bool InitProcessDataTask(AuthDeviceTask *task, int64_t authReqId, CJson *
return true;
}
static int32_t AuthDevice(int64_t authReqId, const char *authParams, const DeviceAuthCallback *gaCallback)
static int32_t AuthDevice(int32_t osAccountId, int64_t authReqId, const char *authParams,
const DeviceAuthCallback *gaCallback)
{
LOGI("Begin AuthDevice.");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if (authParams == NULL) {
LOGE("The input auth params is null!");
return HC_ERR_INVALID_PARAMS;
@ -98,7 +105,7 @@ static int32_t AuthDevice(int64_t authReqId, const char *authParams, const Devic
LOGE("Failed to allocate memory for task!");
return HC_ERR_ALLOC_MEMORY;
}
if (!InitAuthDeviceTask(task, authReqId, jsonParams, gaCallback)) {
if (!InitAuthDeviceTask(osAccountId, task, authReqId, jsonParams, gaCallback)) {
LOGE("Failed to init task!");
FreeJson(jsonParams);
HcFree(task);
@ -296,6 +303,7 @@ DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance(void)
g_groupManagerInstance->getDeviceInfoById = GetDeviceInfoByIdImpl;
g_groupManagerInstance->getTrustedDevices = GetTrustedDevicesImpl;
g_groupManagerInstance->isDeviceInGroup = IsDeviceInGroupImpl;
g_groupManagerInstance->getPkInfoList = GetPkInfoListImpl;
g_groupManagerInstance->destroyInfo = DestroyInfoImpl;
return g_groupManagerInstance;
}

View File

@ -47,6 +47,7 @@ inc_path = [
"${dev_frameworks_path}/inc/",
"${dev_frameworks_path}/inc/module",
"${dev_frameworks_path}/inc/session",
"${dev_frameworks_path}/inc/os_account_adapter",
"${dev_frameworks_path}/inc/task_manager",
"${authenticators_path}/inc/account_related",
"${authenticators_path}/inc/account_unrelated",
@ -89,7 +90,13 @@ dev_frameworks_files = [
"${dev_frameworks_path}/src/task_manager/task_manager.c",
]
os_account_adapter_files =
[ "${dev_frameworks_path}/src/os_account_adapter/os_account_adapter.cpp" ]
os_account_adapter_lite_files = [ "${dev_frameworks_path}/src/os_account_adapter_mock/os_account_adapter_mock.cpp" ]
group_auth_files = [
"${group_auth_path}/src/group_auth_manager/group_auth_data_operation.c",
"${group_auth_path}/src/group_auth_manager/group_auth_manager.c",
"${group_auth_path}/src/session/auth_session/auth_session_client.c",
"${group_auth_path}/src/session/auth_session/auth_session_common.c",
@ -111,8 +118,9 @@ group_auth_account_unrelated_mock_files = [ "${group_auth_path}/src/group_auth_m
group_auth_account_related_mock_files = [ "${group_auth_path}/src/group_auth_manager/account_related_group_auth_mock/account_related_group_auth_mock.c" ]
database_manager_files = [
"${data_manager_path}/src/database_manager.c",
"${data_manager_path}/src/database_util.c",
# "${data_manager_path}/src/database_manager.c",
# "${data_manager_path}/src/database_util.c",
"${data_manager_path}/src/data_manager.c",
]
database_manager_lite_files = []
@ -304,6 +312,12 @@ if (enable_broadcast == true) {
deviceauth_files += broadcast_manager_mock_files
}
if (defined(ohos_lite)) {
deviceauth_files += os_account_adapter_lite_files
} else {
deviceauth_files += os_account_adapter_files
}
#build_flags = [ "-Wrestrict" ]
build_flags = [ "-Werror" ]

View File

@ -71,6 +71,7 @@
#define FIELD_NONCE "nonce"
#define FIELD_OPERATION_CODE "operationCode"
#define FIELD_OPERATION_PARAMS "operationParams"
#define FIELD_OS_ACCOUNT_ID "osAccountId"
#define FIELD_OWNER_ID "ownerId"
#define FIELD_OWNER_NAME "ownerName"
#define FIELD_PERMISSION "Permission"
@ -220,6 +221,4 @@ typedef enum {
SECURE_CLONE = 8,
} OperationCode;
DECLARE_HC_VECTOR(StringVector, HcString)
#endif

View File

@ -31,6 +31,13 @@ typedef struct AuthModuleBaseT {
void (*destroyModule)(struct AuthModuleBaseT *module);
} AuthModuleBase;
typedef struct {
const char *pkgName;
const char *serviceType;
Uint8Buff *authId;
int userType;
} AuthModuleParams;
int32_t InitModules(void);
void DestroyModules(void);
@ -46,6 +53,7 @@ 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(int moduleType, AuthModuleParams *params, Uint8Buff *returnPk);
// for ACCOUNT
int32_t ProcessCredentials(int credentialOpCode, const CJson *in, CJson *out, int moduleType);

View File

@ -0,0 +1,30 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OS_ACCOUNT_ADAPTER_H
#define OS_ACCOUNT_ADAPTER_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
int32_t DevAuthGetRealOsAccountLocalId(int32_t inputId);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -21,7 +21,7 @@
#include "account_module.h"
#include "version_util.h"
DECLARE_HC_VECTOR(AuthModuleVec, void *)
DECLARE_HC_VECTOR(AuthModuleVec, void *);
IMPLEMENT_HC_VECTOR(AuthModuleVec, void *, 1)
static AuthModuleVec g_authModuleVec;
@ -146,6 +146,29 @@ int32_t DeletePeerAuthInfo(const char *pkgName, const char *serviceType, Uint8Bu
return HC_SUCCESS;
}
int32_t GetPublicKey(int moduleType, AuthModuleParams *params, Uint8Buff *returnPk)
{
if (params == NULL || returnPk == NULL ||
!IsParamsForDasTokenManagerValid(params->pkgName, params->serviceType,
params->authId, params->userType, moduleType)) {
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(params->pkgName, params->serviceType,
params->authId, params->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, int32_t *status, int moduleType)
{
if (in == NULL || out == NULL || status == NULL) {
@ -236,7 +259,7 @@ static int32_t InitAccountModule(void)
int32_t InitModules(void)
{
g_authModuleVec = CREATE_HC_VECTOR(AuthModuleVec)
g_authModuleVec = CREATE_HC_VECTOR(AuthModuleVec);
InitGroupAndModuleVersion(&g_version);
int res;
if (IsDasSupported()) {
@ -270,7 +293,7 @@ void DestroyModules(void)
((AuthModuleBase *)(*module))->destroyModule((AuthModuleBase *)*module);
}
}
DESTROY_HC_VECTOR(AuthModuleVec, &g_authModuleVec)
DESTROY_HC_VECTOR(AuthModuleVec, &g_authModuleVec);
(void)memset_s(&g_version, sizeof(VersionStruct), 0, sizeof(VersionStruct));
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "os_account_adapter.h"
#include <vector>
#include "device_auth.h"
#include "hc_log.h"
#include "os_account_manager.h"
int32_t DevAuthGetRealOsAccountLocalId(int32_t inputId)
{
if (inputId == ANY_OS_ACCOUNT) {
std::vector<int> activatedOsAccountIds;
LOGI("[OsAccountManager][In]: QueryActiveOsAccountIds!");
OHOS::ErrCode res = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activatedOsAccountIds);
LOGI("[OsAccountManager][Out]: QueryActiveOsAccountIds! res: %d", res);
if ((res != OHOS::ERR_OK) || (activatedOsAccountIds.size() <= 0)) {
LOGE("[Account]: QueryActiveOsAccountIds fail! res: %d", res);
return INVALID_OS_ACCOUNT;
}
int osAccountId = activatedOsAccountIds[0];
LOGI("[Account]: Use activated os account! [Id]: %d", osAccountId);
return osAccountId;
} else if (inputId >= 0) {
LOGI("[Account]: Use input os account! [Id]: %d", inputId);
return inputId;
} else {
LOGE("[Account]: The input os account is invalid! [Id]: %d", inputId);
return INVALID_OS_ACCOUNT;
}
}

View File

@ -0,0 +1,23 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "os_account_adapter.h"
#include "device_auth.h"
int32_t DevAuthGetRealOsAccountLocalId(int32_t inputId)
{
(void)inputId;
return DEFAULT_OS_ACCOUNT;
}

View File

@ -38,10 +38,10 @@ typedef struct {
int64_t sessionId;
} RequestInfo;
DECLARE_HC_VECTOR(SessionManagerVec, void *)
DECLARE_HC_VECTOR(SessionManagerVec, void *);
IMPLEMENT_HC_VECTOR(SessionManagerVec, void *, 1)
DECLARE_HC_VECTOR(RequestInfoVec, RequestInfo)
DECLARE_HC_VECTOR(RequestInfoVec, RequestInfo);
IMPLEMENT_HC_VECTOR(RequestInfoVec, RequestInfo, 1)
static SessionManagerVec g_sessionManagerVec;
@ -113,8 +113,8 @@ static void DestroyRequest(int64_t requestId)
void InitSessionManager(void)
{
g_sessionManagerVec = CREATE_HC_VECTOR(SessionManagerVec)
g_requestVec = CREATE_HC_VECTOR(RequestInfoVec)
g_sessionManagerVec = CREATE_HC_VECTOR(SessionManagerVec);
g_requestVec = CREATE_HC_VECTOR(RequestInfoVec);
}
void DestroySessionManager(void)
@ -127,8 +127,8 @@ void DestroySessionManager(void)
temp->destroy(temp);
}
}
DESTROY_HC_VECTOR(SessionManagerVec, &g_sessionManagerVec)
DESTROY_HC_VECTOR(RequestInfoVec, &g_requestVec)
DESTROY_HC_VECTOR(SessionManagerVec, &g_sessionManagerVec);
DESTROY_HC_VECTOR(RequestInfoVec, &g_requestVec);
}
bool IsRequestExist(int64_t requestId)

View File

@ -18,10 +18,10 @@
#include <stdint.h>
#include "base_group_auth.h"
#include "database_manager.h"
#include "data_manager.h"
typedef void (*GetAccountCandidateGroupFunc)(const CJson *param, const GroupQueryParams *queryParams,
GroupInfoVec *vec);
typedef void (*GetAccountCandidateGroupFunc)(const CJson *param, const QueryGroupParams *queryParams,
GroupEntryVec *vec);
typedef struct {
BaseGroupAuth base;

View File

@ -18,14 +18,15 @@
#include <stdint.h>
#include "auth_session_common_defines.h"
#include "database_manager.h"
#include "data_manager.h"
#include "device_auth.h"
#include "json_utils.h"
typedef struct {
void (*onFinish)(int64_t requestId, const CJson *authParam, const CJson *out, const DeviceAuthCallback *callback);
void (*onError)(int64_t requestId, const AuthSession *session, int errorCode);
int32_t (*fillDeviceAuthInfo)(const GroupInfo *entry, const DeviceInfo *localAuthInfo, CJson *paramsData);
int32_t (*fillDeviceAuthInfo)(int32_t osAccountId, const TrustedGroupEntry *entry,
const TrustedDeviceEntry *localAuthInfo, CJson *paramsData);
int32_t (*getAuthParamForServer)(const CJson *dataFromClient, ParamsVec *authParamsVec);
int32_t (*getReqParams)(const CJson *receiveData, CJson *reqParam);
int32_t (*combineServerConfirmParams)(const CJson *confirmationJson, CJson *dataFromClient);

View File

@ -0,0 +1,34 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GROUP_AUTH_DATA_OPERATION_H
#define GROUP_AUTH_DATA_OPERATION_H
#include "data_manager.h"
#ifdef __cplusplus
extern "C" {
#endif
bool GaIsGroupAccessible(int32_t osAccountId, const char *groupId, const char *appId);
int32_t GaGetTrustedDeviceEntryById(int32_t osAccountId, const char *deviceId,
bool isUdid, const char *groupId, TrustedDeviceEntry *returnDeviceEntry);
bool GaIsDeviceInGroup(int32_t groupType, int32_t osAccountId, const char *peerUdid, const char *peerAuthId,
const char *groupId);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -25,7 +25,7 @@ extern "C" {
void InformLocalAuthError(const CJson *param, const DeviceAuthCallback *callback);
void InformPeerAuthError(const CJson *param, const DeviceAuthCallback *callback);
int32_t InformAuthError(AuthSession *session, const CJson *out, int errorCode);
int32_t GetAuthParamsList(const CJson *param, ParamsVec *authParamsVec);
int32_t GetAuthParamsList(int32_t osAccountId, const CJson *param, ParamsVec *authParamsVec);
int32_t ProcessTaskStatusForAuth(const AuthSession *session, const CJson *param, CJson *out, int32_t status);
int32_t CreateAndProcessTask(AuthSession *session, CJson *paramInSession, CJson *out, int32_t *status);
void ProcessDeviceLevel(const CJson *receiveData, CJson *authParam);

View File

@ -24,10 +24,13 @@
#ifdef __cplusplus
extern "C" {
#endif
BaseGroupAuth *GetGroupAuth(int32_t groupAuthType);
int32_t GetAuthModuleType(const CJson *in);
int32_t GetInfoHash(const uint8_t *info, uint32_t infoLen, char *str, uint32_t strLen);
bool IsBleAuthForAcrossAccount(const CJson *authParam);
int32_t GroupTypeToAuthForm(int32_t groupType);
#ifdef __cplusplus
}
#endif

View File

@ -18,13 +18,16 @@
#include "auth_session_common_util.h"
#include "common_defs.h"
#include "device_auth_defines.h"
#include "group_auth_data_operation.h"
#include "hc_log.h"
#include "hc_types.h"
#include "json_utils.h"
#include "os_account_adapter.h"
static void OnDasFinish(int64_t requestId, const CJson *authParam, const CJson *out,
const DeviceAuthCallback *callback);
static int32_t FillNonAccountAuthInfo(const GroupInfo *entry, const DeviceInfo *localAuthInfo, CJson *paramsData);
static int32_t FillNonAccountAuthInfo(int32_t osAccountId, const TrustedGroupEntry *entry,
const TrustedDeviceEntry *localAuthInfo, CJson *paramsData);
static void OnDasError(int64_t requestId, const AuthSession *session, int errorCode);
static int32_t GetDasAuthParamForServer(const CJson *dataFromClient, ParamsVec *authParamsVec);
static int32_t GetDasReqParams(const CJson *receiveData, CJson *reqParam);
@ -228,26 +231,34 @@ static int32_t DasOnFinishToSelf(int64_t requestId, const CJson *authParam, cons
return res;
}
static int32_t AddNonAccountPkgName(const GroupInfo *entry, CJson *paramsData)
static int32_t AddNonAccountPkgName(const TrustedGroupEntry *entry, CJson *paramsData)
{
int32_t res = HC_SUCCESS;
int32_t groupType = entry->type;
if (groupType == COMPATIBLE_GROUP) {
if (AddStringToJson(paramsData, FIELD_SERVICE_PKG_NAME, StringGet(&entry->ownerName))
!= HC_SUCCESS) {
if ((entry->managers).size(&(entry->managers)) == 0) {
LOGE("The manager size is 0!");
return HC_ERR_DB;
}
HcString ownerName = (entry->managers).get(&(entry->managers), 0);
const char *ownerNameStr = StringGet(&ownerName);
if (ownerNameStr == NULL) {
LOGE("Failed to get ownerName!");
return HC_ERR_DB;
}
if (AddStringToJson(paramsData, FIELD_SERVICE_PKG_NAME, ownerNameStr) != HC_SUCCESS) {
LOGE("Failed to add ownerName to json!");
res = HC_ERR_JSON_FAIL;
return HC_ERR_JSON_FAIL;
}
} else {
if (AddStringToJson(paramsData, FIELD_SERVICE_PKG_NAME, GROUP_MANAGER_PACKAGE_NAME) != HC_SUCCESS) {
LOGE("Failed to add group manager name to json!");
res = HC_ERR_JSON_FAIL;
return HC_ERR_JSON_FAIL;
}
}
return res;
return HC_SUCCESS;
}
static int32_t AddNonAccountAuthInfo(const DeviceInfo *localAuthInfo, const DeviceInfo *peerAuthInfo,
static int32_t AddNonAccountAuthInfo(const TrustedDeviceEntry *localAuthInfo, const TrustedDeviceEntry *peerAuthInfo,
CJson *paramsData)
{
int32_t keyLen = DEFAULT_RETURN_KEY_LENGTH;
@ -327,11 +338,12 @@ static void OnDasError(int64_t requestId, const AuthSession *session, int errorC
FreeJsonString(returnStr);
}
static int32_t FillNonAccountAuthInfo(const GroupInfo *entry, const DeviceInfo *localAuthInfo, CJson *paramsData)
static int32_t FillNonAccountAuthInfo(int32_t osAccountId, const TrustedGroupEntry *entry,
const TrustedDeviceEntry *localAuthInfo, CJson *paramsData)
{
int32_t res;
const char *groupId = StringGet(&entry->id);
DeviceInfo *peerAuthInfo = CreateDeviceInfoStruct();
TrustedDeviceEntry *peerAuthInfo = CreateDeviceEntry();
if (peerAuthInfo == NULL) {
LOGE("Failed to allocate devEntry memory for peerAuthInfo!");
return HC_ERR_ALLOC_MEMORY;
@ -339,9 +351,9 @@ static int32_t FillNonAccountAuthInfo(const GroupInfo *entry, const DeviceInfo *
const char *peerUdid = GetStringFromJson(paramsData, FIELD_PEER_CONN_DEVICE_ID);
const char *peeAuthId = GetStringFromJson(paramsData, FIELD_PEER_AUTH_ID);
if (peerUdid != NULL) {
res = GetTrustedDevInfoById(peerUdid, true, groupId, peerAuthInfo);
res = GaGetTrustedDeviceEntryById(osAccountId, peerUdid, true, groupId, peerAuthInfo);
} else if (peeAuthId != NULL) {
res = GetTrustedDevInfoById(peeAuthId, false, groupId, peerAuthInfo);
res = GaGetTrustedDeviceEntryById(osAccountId, peeAuthId, false, groupId, peerAuthInfo);
} else {
LOGE("Invalid input, both peer udid and peer authId are null!");
res = HC_ERR_NULL_PTR;
@ -362,7 +374,7 @@ static int32_t FillNonAccountAuthInfo(const GroupInfo *entry, const DeviceInfo *
break;
}
} while (0);
DestroyDeviceInfoStruct(peerAuthInfo);
DestroyDeviceEntry(peerAuthInfo);
return res;
}
@ -424,7 +436,12 @@ static int32_t CombineDasServerConfirmParams(const CJson *confirmationJson, CJso
static int32_t GetDasAuthParamForServer(const CJson *dataFromClient, ParamsVec *authParamsVec)
{
LOGI("Begin get non-account auth params for server.");
int32_t res = GetAuthParamsList(dataFromClient, authParamsVec);
int32_t osAccountId = ANY_OS_ACCOUNT;
if (GetIntFromJson(dataFromClient, FIELD_OS_ACCOUNT_ID, &osAccountId) != HC_SUCCESS) {
LOGE("Failed to get os accountId from dataFromClient!");
return HC_ERR_JSON_GET;
}
int32_t res = GetAuthParamsList(osAccountId, dataFromClient, authParamsVec);
if (res != HC_SUCCESS) {
LOGE("Failed to get non-account auth params!");
}

View File

@ -0,0 +1,238 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "group_auth_data_operation.h"
#include "auth_session_util.h"
#include "common_defs.h"
#include "device_auth.h"
#include "device_auth_defines.h"
#include "hc_log.h"
#include "hc_string.h"
#include "hc_vector.h"
static bool GaDeepCopyDeviceEntry(const TrustedDeviceEntry *entry, TrustedDeviceEntry *returnEntry)
{
returnEntry->groupEntry = NULL;
if (!StringSet(&returnEntry->groupId, entry->groupId)) {
LOGE("[GA]: Failed to copy udid!");
return false;
}
if (!StringSet(&returnEntry->udid, entry->udid)) {
LOGE("[GA]: Failed to copy udid!");
return false;
}
if (!StringSet(&returnEntry->authId, entry->authId)) {
LOGE("[GA]: Failed to copy authId!");
return false;
}
if (!StringSet(&returnEntry->serviceType, entry->serviceType)) {
LOGE("[GA]: Failed to copy serviceType!");
return false;
}
if (!StringSet(&returnEntry->userIdHash, entry->userIdHash)) {
LOGE("[GA]: Failed to copy userIdHash!");
return false;
}
returnEntry->credential = entry->credential;
returnEntry->devType = entry->devType;
returnEntry->lastTm = entry->lastTm;
return true;
}
static bool GaDeepCopyGroupEntry(const TrustedGroupEntry *entry, TrustedGroupEntry *returnEntry)
{
if (HC_VECTOR_SIZE(&entry->managers) <= 0) {
LOGE("[GA]: The group owner is lost!");
return false;
}
HcString entryOwner = HC_VECTOR_GET(&entry->managers, 0);
if (!StringSet(&returnEntry->name, entry->name)) {
LOGE("[GA]: Failed to copy groupName!");
return false;
}
if (!StringSet(&returnEntry->id, entry->id)) {
LOGE("[GA]: Failed to copy groupId!");
return false;
}
if (!StringSet(&returnEntry->userIdHash, entry->userIdHash)) {
LOGE("[GA]: Failed to copy userIdHash!");
return false;
}
returnEntry->type = entry->type;
returnEntry->visibility = entry->visibility;
returnEntry->expireTime = entry->expireTime;
HcString ownerName = CreateString();
if (!StringSet(&ownerName, entryOwner)) {
LOGE("[GA]: Failed to copy groupOwner!");
DeleteString(&ownerName);
return false;
}
if (returnEntry->managers.pushBack(&returnEntry->managers, &ownerName) == NULL) {
LOGE("[GA]: Failed to push groupOwner to managers!");
DeleteString(&ownerName);
return false;
}
return true;
}
static bool GaIsGroupManager(const char *appId, const TrustedGroupEntry *entry)
{
uint32_t index;
HcString *manager = NULL;
const char *managerStr = NULL;
FOR_EACH_HC_VECTOR(entry->managers, index, manager) {
managerStr = StringGet(manager);
if ((managerStr != NULL) && (strcmp(managerStr, appId) == 0)) {
return true;
}
}
return false;
}
static bool GaIsGroupFriend(const char *appId, const TrustedGroupEntry *entry)
{
uint32_t index;
HcString *trustedFriend = NULL;
const char *friendStr = NULL;
FOR_EACH_HC_VECTOR(entry->friends, index, trustedFriend) {
friendStr = StringGet(trustedFriend);
if ((friendStr != NULL) && (strcmp(friendStr, appId) == 0)) {
return true;
}
}
return false;
}
static int32_t GetGroupEntryById(int32_t osAccountId, const char *groupId, TrustedGroupEntry *returnEntry)
{
if (returnEntry == NULL) {
LOGE("The input returnEntry is NULL!");
return HC_ERR_INVALID_PARAMS;
}
uint32_t groupIndex;
TrustedGroupEntry **entry = NULL;
GroupEntryVec groupEntryVec = CreateGroupEntryVec();
QueryGroupParams groupParams = InitQueryGroupParams();
groupParams.groupId = groupId;
if (QueryGroups(osAccountId, &groupParams, &groupEntryVec) != HC_SUCCESS) {
LOGE("query groups failed!");
ClearGroupEntryVec(&groupEntryVec);
return HC_ERR_GROUP_NOT_EXIST;
}
FOR_EACH_HC_VECTOR(groupEntryVec, groupIndex, entry) {
if ((entry != NULL) && (*entry != NULL)) {
if (!GaDeepCopyGroupEntry(*entry, returnEntry)) {
ClearGroupEntryVec(&groupEntryVec);
return HC_ERR_GROUP_NOT_EXIST;
}
ClearGroupEntryVec(&groupEntryVec);
return HC_SUCCESS;
}
}
ClearGroupEntryVec(&groupEntryVec);
return HC_ERR_GROUP_NOT_EXIST;
}
bool GaIsGroupAccessible(int32_t osAccountId, const char *groupId, const char *appId)
{
if ((groupId == NULL) || (appId == NULL)) {
LOGE("The input groupId or appId is NULL!");
return false;
}
TrustedGroupEntry *entry = CreateGroupEntry();
if (entry == NULL) {
LOGE("Failed to create group entry!");
return false;
}
int32_t res = GetGroupEntryById(osAccountId, groupId, entry);
if (res != HC_SUCCESS) {
LOGE("Failed to get group entry by groupId!");
DestroyGroupEntry(entry);
return false;
}
if ((entry->visibility == GROUP_VISIBILITY_PUBLIC) ||
(GaIsGroupManager(appId, entry)) ||
(GaIsGroupFriend(appId, entry))) {
DestroyGroupEntry(entry);
return true;
}
DestroyGroupEntry(entry);
return false;
}
int32_t GaGetTrustedDeviceEntryById(int32_t osAccountId, const char *deviceId,
bool isUdid, const char *groupId, TrustedDeviceEntry *returnDeviceEntry)
{
if (returnDeviceEntry == NULL) {
LOGE("The input returnEntry is NULL!");
return HC_ERR_INVALID_PARAMS;
}
uint32_t index;
TrustedDeviceEntry **deviceEntry = NULL;
DeviceEntryVec deviceEntryVec = CREATE_HC_VECTOR(DeviceEntryVec);
QueryDeviceParams params = InitQueryDeviceParams();
params.groupId = groupId;
if (isUdid) {
params.udid = deviceId;
} else {
params.authId = deviceId;
}
if (QueryDevices(osAccountId, &params, &deviceEntryVec) != HC_SUCCESS) {
LOGE("query trusted devices failed!");
ClearDeviceEntryVec(&deviceEntryVec);
return HC_ERR_DEVICE_NOT_EXIST;
}
FOR_EACH_HC_VECTOR(deviceEntryVec, index, deviceEntry) {
if ((deviceEntry != NULL) && (*deviceEntry != NULL)) {
if (!GaDeepCopyDeviceEntry(*deviceEntry, returnDeviceEntry)) {
ClearDeviceEntryVec(&deviceEntryVec);
return HC_ERR_GROUP_NOT_EXIST;
}
ClearDeviceEntryVec(&deviceEntryVec);
return HC_SUCCESS;
}
}
ClearDeviceEntryVec(&deviceEntryVec);
return HC_ERR_DEVICE_NOT_EXIST;
}
bool GaIsDeviceInGroup(int32_t groupType, int32_t osAccountId, const char *peerUdid, const char *peerAuthId,
const char *groupId)
{
int32_t res;
int32_t authForm = GroupTypeToAuthForm(groupType);
if ((authForm == AUTH_FORM_ACROSS_ACCOUNT) || (authForm == AUTH_FORM_IDENTICAL_ACCOUNT)) {
LOGD("Auth for account related type.");
return true; /* Do not check whether account related devices is in account. */
}
TrustedDeviceEntry *deviceEntry = CreateDeviceEntry();
if (deviceEntry == NULL) {
LOGE("Failed to allocate memory for deviceEntry!");
return false;
}
if (peerUdid != NULL) {
res = GaGetTrustedDeviceEntryById(osAccountId, peerUdid, true, groupId, deviceEntry);
} else if (peerAuthId != NULL) {
res = GaGetTrustedDeviceEntryById(osAccountId, peerAuthId, false, groupId, deviceEntry);
} else {
LOGE("Both the input udid and authId is null!");
res = HC_ERROR;
}
DestroyDeviceEntry(deviceEntry);
if (res != HC_SUCCESS) {
return false;
}
return true;
}

View File

@ -15,7 +15,6 @@
#include "group_auth_manager.h"
#include "common_defs.h"
#include "database_manager.h"
#include "dev_auth_module_manager.h"
#include "device_auth_defines.h"
#include "hc_log.h"
@ -59,12 +58,14 @@ bool IsTrustedDevice(const char *udid)
LOGE("Invalid params in IsTrustedDevice");
return false;
}
return IsTrustedDeviceExist(udid);
LOGE("Group auth do not support func currently: %s!", __func__);
return false;
}
int32_t QueryTrustedDeviceNum(void)
{
return GetTrustedDevNumber();
LOGE("Group auth do not support func currently: %s!", __func__);
return HC_ERR_NOT_SUPPORT;
}
void DoAuthDevice(HcTaskBase *task)

View File

@ -21,6 +21,7 @@
#include "hc_types.h"
#include "json_utils.h"
#include "session_common.h"
#include "string_util.h"
static int32_t ProcessClientAuthSession(Session *session, CJson *in);
@ -106,6 +107,20 @@ int32_t CheckClientGroupAuthMsg(AuthSession *session, const CJson *in)
return HC_ERR_PEER_ERROR;
}
static void PrintErrorInputInfo(const CJson *param)
{
const char *peerUdid = GetStringFromJson(param, FIELD_PEER_CONN_DEVICE_ID);
const char *peerAuthId = GetStringFromJson(param, FIELD_PEER_AUTH_ID);
char *anonyPeerUdid = NULL;
char *anonyPeerAuthId = NULL;
ConvertToAnonymousStr(peerUdid, &anonyPeerUdid);
ConvertToAnonymousStr(peerAuthId, &anonyPeerAuthId);
LOGE("[PrintErrorInputInfo] [peerUdid]: %s", ((anonyPeerUdid == NULL) ? "NULL" : anonyPeerUdid));
LOGE("[PrintErrorInputInfo] [peerAuthId]: %s", ((anonyPeerAuthId == NULL) ? "NULL" : anonyPeerAuthId));
HcFree(anonyPeerUdid);
HcFree(anonyPeerAuthId);
}
static int32_t ProcessClientAuthSession(Session *session, CJson *in)
{
LOGI("Begin process client authSession.");
@ -141,15 +156,16 @@ static int32_t ProcessClientAuthSession(Session *session, CJson *in)
return res;
}
static Session *CreateClientAuthSessionInner(CJson *param, const DeviceAuthCallback *callback)
static Session *CreateClientAuthSessionInner(int32_t osAccountId, CJson *param, const DeviceAuthCallback *callback)
{
ParamsVec authParamsVec;
CreateAuthParamsVec(&authParamsVec);
int32_t res = GetAuthParamsList(param, &authParamsVec);
int32_t res = GetAuthParamsList(osAccountId, param, &authParamsVec);
if ((res != HC_SUCCESS) || (authParamsVec.size(&authParamsVec) == 0)) {
LOGE("Failed to get auth param list, candidate group = %u!", authParamsVec.size(&authParamsVec));
DestroyAuthParamsVec(&authParamsVec);
InformLocalAuthError(param, callback);
PrintErrorInputInfo(param);
return NULL;
}
@ -195,7 +211,13 @@ Session *CreateClientAuthSession(CJson *param, const DeviceAuthCallback *callbac
InformLocalAuthError(param, callback);
return NULL;
}
session = CreateClientAuthSessionInner(param, callback);
int32_t osAccountId = INVALID_OS_ACCOUNT;
if (GetIntFromJson(param, FIELD_OS_ACCOUNT_ID, &osAccountId) != HC_SUCCESS) {
LOGE("Failed to get osAccountId for create client session!");
InformLocalAuthError(param, callback);
return NULL;
}
session = CreateClientAuthSessionInner(osAccountId, param, callback);
if (session == NULL) {
LOGE("Failed to create client auth session!");
return NULL;

View File

@ -20,8 +20,10 @@
#include "auth_session_util.h"
#include "common_defs.h"
#include "string_util.h"
#include "database_manager.h"
#include "data_manager.h"
#include "dev_auth_module_manager.h"
#include "group_auth_data_operation.h"
#include "hc_dev_info.h"
#include "hc_log.h"
#include "json_utils.h"
@ -83,40 +85,16 @@ static int32_t UnifyOldFormatParams(const CJson *param, ParamsVec *paramsVec)
return res;
}
static bool IsGroupAvailable(const char *groupId, const char *pkgName)
static bool IsGroupAvailable(int32_t osAccountId, const char *groupId, const char *pkgName)
{
if (IsGroupAccessible(groupId, pkgName)) {
if (GaIsGroupAccessible(osAccountId, groupId, pkgName)) {
return true;
}
LOGD("%s don't have enough right for group: %s!", pkgName, groupId);
LOGD("%s don't have enough right in group: %s, os account:%d!", pkgName, groupId, osAccountId);
return false;
}
static int32_t GroupTypeToAuthForm(int32_t groupType)
{
int32_t authForm;
switch (groupType) {
case PEER_TO_PEER_GROUP:
authForm = AUTH_FORM_ACCOUNT_UNRELATED;
break;
case COMPATIBLE_GROUP:
authForm = AUTH_FORM_ACCOUNT_UNRELATED;
break;
case IDENTICAL_ACCOUNT_GROUP:
authForm = AUTH_FORM_IDENTICAL_ACCOUNT;
break;
case ACROSS_ACCOUNT_AUTHORIZE_GROUP:
authForm = AUTH_FORM_ACROSS_ACCOUNT;
break;
default:
LOGE("Invalid group type!");
authForm = AUTH_FORM_INVALID_TYPE;
break;
}
return authForm;
}
static int32_t AddGeneralParams(const char *groupId, int32_t groupType, const DeviceInfo *localAuthInfo,
static int32_t AddGeneralParams(const char *groupId, int32_t groupType, const TrustedDeviceEntry *localAuthInfo,
CJson *paramsData)
{
int32_t authForm = GroupTypeToAuthForm(groupType);
@ -141,25 +119,34 @@ static int32_t AddGeneralParams(const char *groupId, int32_t groupType, const De
return HC_SUCCESS;
}
static int32_t GetLocalDeviceInfoFromDatabase(const char *groupId, DeviceInfo *localAuthInfo)
static int32_t GetLocalDeviceInfoFromDatabase(int32_t osAccountId, const char *groupId,
TrustedDeviceEntry *localAuthInfo)
{
int32_t res;
const char *localUdidStr = GetLocalDevUdid();
if (localUdidStr == NULL) {
LOGE("Failed to get local udid!");
return HC_ERR_DB;
char *localUdid = (char *)HcMalloc(INPUT_UDID_LEN, 0);
if (localUdid == NULL) {
LOGE("Failed to malloc for local udid!");
return HC_ERR_ALLOC_MEMORY;
}
res = GetTrustedDevInfoById(localUdidStr, true, groupId, localAuthInfo);
int32_t res = HcGetUdid((uint8_t *)localUdid, INPUT_UDID_LEN);
if (res != HC_SUCCESS) {
LOGE("[DB]: Failed to get local udid! res: %d", res);
HcFree(localUdid);
return res;
}
res = GaGetTrustedDeviceEntryById(osAccountId, localUdid, true, groupId, localAuthInfo);
HcFree(localUdid);
if (res != HC_SUCCESS) {
LOGE("Failed to get local device info from database!");
}
return res;
}
static int32_t ExtractAndAddParams(const char *groupId, const GroupInfo *groupInfo, CJson *paramsData)
static int32_t ExtractAndAddParams(int32_t osAccountId, const char *groupId,
const TrustedGroupEntry *groupInfo, CJson *paramsData)
{
int32_t res;
DeviceInfo *localAuthInfo = CreateDeviceInfoStruct();
TrustedDeviceEntry *localAuthInfo = CreateDeviceEntry();
if (localAuthInfo == NULL) {
LOGE("Failed to allocate memory for localAuthInfo!");
return HC_ERR_ALLOC_MEMORY;
@ -167,7 +154,7 @@ static int32_t ExtractAndAddParams(const char *groupId, const GroupInfo *groupIn
int32_t groupType = groupInfo->type;
int32_t authForm = GroupTypeToAuthForm(groupType);
do {
res = GetLocalDeviceInfoFromDatabase(groupId, localAuthInfo);
res = GetLocalDeviceInfoFromDatabase(osAccountId, groupId, localAuthInfo);
if (res != HC_SUCCESS) {
break;
}
@ -181,35 +168,41 @@ static int32_t ExtractAndAddParams(const char *groupId, const GroupInfo *groupIn
LOGE("Failed to get group auth handle!");
break;
}
res = groupAuth->fillDeviceAuthInfo(groupInfo, localAuthInfo, paramsData);
res = groupAuth->fillDeviceAuthInfo(osAccountId, groupInfo, localAuthInfo, paramsData);
if (res != HC_SUCCESS) {
LOGE("Failed to fill device auth info!");
break;
}
} while (0);
DestroyDeviceInfoStruct(localAuthInfo);
DestroyDeviceEntry(localAuthInfo);
return res;
}
static int32_t FillAuthParams(const CJson *param, const GroupInfoVec *vec, ParamsVec *paramsVec)
static int32_t FillAuthParams(int32_t osAccountId, const CJson *param,
const GroupEntryVec *vec, ParamsVec *paramsVec)
{
const char *peerUdid = GetStringFromJson(param, FIELD_PEER_CONN_DEVICE_ID);
const char *peerAuthId = GetStringFromJson(param, FIELD_PEER_AUTH_ID);
const char *pkgName = GetStringFromJson(param, FIELD_SERVICE_PKG_NAME);
if (pkgName == NULL) {
LOGE("Pkg name is null, can't extract params from db!");
return HC_ERR_NULL_PTR;
}
uint32_t index;
void **ptr = NULL;
TrustedGroupEntry **ptr = NULL;
FOR_EACH_HC_VECTOR(*vec, index, ptr) {
if ((ptr == NULL) || (*ptr == NULL)) {
continue;
}
const GroupInfo *groupInfo = (GroupInfo *)(*ptr);
const TrustedGroupEntry *groupInfo = (TrustedGroupEntry *)(*ptr);
const char *groupId = StringGet(&(groupInfo->id));
if (groupId == NULL) {
continue;
}
if (!IsGroupAvailable(groupId, pkgName)) {
if (!IsGroupAvailable(osAccountId, groupId, pkgName)) {
continue;
}
if (!GaIsDeviceInGroup(groupInfo->type, osAccountId, peerUdid, peerAuthId, groupId)) {
continue;
}
CJson *paramsData = DuplicateJson(param);
@ -217,7 +210,7 @@ static int32_t FillAuthParams(const CJson *param, const GroupInfoVec *vec, Param
LOGE("Failed to duplicate auth param data!");
return HC_ERR_JSON_FAIL;
}
int32_t res = ExtractAndAddParams(groupId, groupInfo, paramsData);
int32_t res = ExtractAndAddParams(osAccountId, groupId, groupInfo, paramsData);
if (res != HC_SUCCESS) {
LOGE("Failed to extract and add param!");
FreeJson(paramsData);
@ -228,73 +221,25 @@ static int32_t FillAuthParams(const CJson *param, const GroupInfoVec *vec, Param
return HC_SUCCESS;
}
static void GetCandidateGroupByOrder(const CJson *param, GroupQueryParams *queryParams, GroupInfoVec *vec)
static void GetCandidateGroupByOrder(int32_t osAccountId, const CJson *param,
QueryGroupParams *queryParams, GroupEntryVec *vec)
{
BaseGroupAuth *groupAuth = GetGroupAuth(ACCOUNT_RELATED_GROUP_AUTH_TYPE);
if (groupAuth != NULL) {
AccountRelatedGroupAuth *realGroupAuth = (AccountRelatedGroupAuth *)groupAuth;
realGroupAuth->getAccountCandidateGroup(param, queryParams, vec);
}
queryParams->type = PEER_TO_PEER_GROUP;
if (GetJoinedGroupInfoVecByDevId(queryParams, vec) != HC_SUCCESS) {
queryParams->groupType = PEER_TO_PEER_GROUP;
if (QueryGroups(osAccountId, queryParams, vec) != HC_SUCCESS) {
LOGD("No peer to peer group in db.");
}
queryParams->type = COMPATIBLE_GROUP;
if (GetJoinedGroupInfoVecByDevId(queryParams, vec) != HC_SUCCESS) {
queryParams->groupType = COMPATIBLE_GROUP;
if (QueryGroups(osAccountId, queryParams, vec) != HC_SUCCESS) {
LOGD("No compatible group in db.");
}
}
static int32_t InitGroupQueryParams(const char *peerUdid, const char *peerAuthId, GroupQueryParams *queryParams)
{
uint32_t peerUdidLen = HcStrlen(peerUdid) + 1;
uint32_t peerAuthIdLen = HcStrlen(peerAuthId) + 1;
queryParams->type = ALL_GROUP;
queryParams->visibility = ALL_GROUP_VISIBILITY;
queryParams->udid = NULL;
queryParams->authId = NULL;
if (peerUdid != NULL) {
queryParams->udid = (char *)HcMalloc(peerUdidLen, 0);
if (queryParams->udid == NULL) {
LOGE("Failed to allocate memory for queryParams of udid!");
return HC_ERR_ALLOC_MEMORY;
}
if (strcpy_s(queryParams->udid, peerUdidLen, peerUdid) != EOK) {
LOGE("Failed to copy udid for queryParams!");
HcFree(queryParams->udid);
queryParams->udid = NULL;
return HC_ERR_MEMORY_COPY;
}
} else if (peerAuthId != NULL) {
queryParams->authId = (char *)HcMalloc(peerAuthIdLen, 0);
if (queryParams->authId == NULL) {
LOGE("Failed to allocate memory for queryParams of authId!");
return HC_ERR_ALLOC_MEMORY;
}
if (strcpy_s(queryParams->authId, peerAuthIdLen, peerAuthId) != EOK) {
LOGE("Failed to copy authId for queryParams!");
HcFree(queryParams->authId);
queryParams->authId = NULL;
return HC_ERR_MEMORY_COPY;
}
}
return HC_SUCCESS;
}
static void DestroyGroupQueryParams(GroupQueryParams *queryParams)
{
if (queryParams->udid != NULL) {
HcFree(queryParams->udid);
queryParams->udid = NULL;
}
if (queryParams->authId != NULL) {
HcFree(queryParams->authId);
queryParams->authId = NULL;
}
}
static void GetCandidateGroupInfo(const CJson *param, const char *peerUdid,
const char *peerAuthId, GroupInfoVec *vec)
static void GetCandidateGroupInfo(int32_t osAccountId, const CJson *param, GroupEntryVec *vec)
{
LOGI("No input of groupId, extract group info without groupId.");
bool deviceLevelFlag = false;
@ -304,40 +249,27 @@ static void GetCandidateGroupInfo(const CJson *param, const char *peerUdid,
LOGE("Failed to get the value: isClient!");
return;
}
GroupQueryParams queryParams = { 0 };
if (InitGroupQueryParams(peerUdid, peerAuthId, &queryParams) != HC_SUCCESS) {
LOGE("Failed to init group query params!");
return;
}
QueryGroupParams queryParams = InitQueryGroupParams();
if (deviceLevelFlag && isClient) {
LOGI("Try to get device-level candidate groups for auth.");
} else {
queryParams.visibility = GROUP_VISIBILITY_PUBLIC;
queryParams.groupVisibility = GROUP_VISIBILITY_PUBLIC;
}
GetCandidateGroupByOrder(param, &queryParams, vec);
DestroyGroupQueryParams(&queryParams);
GetCandidateGroupByOrder(osAccountId, param, &queryParams, vec);
}
static void GetGroupInfoByGroupId(const char *groupId, const char *peerUdid, const char *peerAuthId, GroupInfoVec *vec)
static void GetGroupInfoByGroupId(int32_t osAccountId, const char *groupId,
GroupEntryVec *groupEntryVec)
{
GroupInfo *entry = CreateGroupInfoStruct();
if (entry == NULL) {
LOGE("Failed to create entry struct!");
if (groupId == NULL) {
LOGE("GroupId is null!");
return;
}
int32_t res = HC_SUCCESS;
if (peerUdid != NULL) {
res = GetGroupInfoIfDevExist(groupId, peerUdid, entry);
} else {
if (IsTrustedDeviceInGroup(groupId, peerAuthId, false)) {
res = GetGroupInfoById(groupId, entry);
}
}
if (res == HC_SUCCESS) {
vec->pushBackT(vec, (void *)entry);
} else {
LOGE("Failed to get group entry!");
DestroyGroupInfoStruct(entry);
QueryGroupParams queryParams = InitQueryGroupParams();
queryParams.groupId = groupId;
if (QueryGroups(osAccountId, &queryParams, groupEntryVec) != HC_SUCCESS) {
LOGE("Failed to query groups for groupId %s!", groupId);
return;
}
}
@ -357,36 +289,22 @@ static int32_t GetBleGroupInfoAndAuthParams(const CJson *param, ParamsVec *param
return HC_SUCCESS;
}
static int32_t GetCandidateAuthInfo(const char *groupId, const CJson *param, ParamsVec *authParamsVec)
static int32_t GetCandidateAuthInfo(int32_t osAccountId, const char *groupId,
const CJson *param, ParamsVec *authParamsVec)
{
const char *peerUdid = GetStringFromJson(param, FIELD_PEER_CONN_DEVICE_ID);
const char *peerAuthId = GetStringFromJson(param, FIELD_PEER_AUTH_ID);
GroupInfoVec vec;
CreateGroupInfoVecStruct(&vec);
GroupEntryVec vec = CreateGroupEntryVec();
if (groupId == NULL) {
GetCandidateGroupInfo(param, peerUdid, peerAuthId, &vec);
GetCandidateGroupInfo(osAccountId, param, &vec);
} else {
GetGroupInfoByGroupId(groupId, peerUdid, peerAuthId, &vec);
GetGroupInfoByGroupId(osAccountId, groupId, &vec);
}
if (vec.size(&vec) == 0) {
LOGE("No satisfied candidate group!");
DestroyGroupInfoVecStruct(&vec);
char *anonyPeerUdid = NULL;
char *anonyPeerAuthId = NULL;
ConvertToAnonymousStr(peerUdid, &anonyPeerUdid);
ConvertToAnonymousStr(peerAuthId, &anonyPeerAuthId);
LOGE("[GetCandidateAuthInfo] [peerUdid]: %s", ((anonyPeerUdid == NULL) ? "NULL" : anonyPeerUdid));
LOGE("[GetCandidateAuthInfo] [peerAuthId]: %s", ((anonyPeerAuthId == NULL) ? "NULL" : anonyPeerAuthId));
HcFree(anonyPeerUdid);
HcFree(anonyPeerAuthId);
if (peerUdid != NULL) {
LOGE("[GetCandidateAuthInfo] peerUdid-IsTrustedDeviceExist = %s",
(IsTrustedDeviceExist(peerUdid) == true) ? "true" : "false");
}
ClearGroupEntryVec(&vec);
return HC_ERR_NO_CANDIDATE_GROUP;
}
int32_t res = FillAuthParams(param, &vec, authParamsVec);
DestroyGroupInfoVecStruct(&vec);
int32_t res = FillAuthParams(osAccountId, param, &vec, authParamsVec);
ClearGroupEntryVec(&vec);
return res;
}
@ -471,7 +389,7 @@ static int32_t ReturnTransmitData(const AuthSession *session, CJson *out)
return ret;
}
int32_t GetAuthParamsList(const CJson *param, ParamsVec *authParamsVec)
int32_t GetAuthParamsList(int32_t osAccountId, const CJson *param, ParamsVec *authParamsVec)
{
int32_t ret;
const char *groupId = GetStringFromJson(param, FIELD_GROUP_ID);
@ -485,7 +403,7 @@ int32_t GetAuthParamsList(const CJson *param, ParamsVec *authParamsVec)
LOGD("This is across-account auth for ble device.");
ret = GetBleGroupInfoAndAuthParams(param, authParamsVec);
} else {
ret = GetCandidateAuthInfo(groupId, param, authParamsVec);
ret = GetCandidateAuthInfo(osAccountId, groupId, param, authParamsVec);
}
return ret;
}
@ -921,17 +839,17 @@ void DestroyAuthSession(Session *session)
FreeJson((CJson *)*paramsData);
}
}
DESTROY_HC_VECTOR(ParamsVec, &(realSession->paramsList))
DESTROY_HC_VECTOR(ParamsVec, &(realSession->paramsList));
HcFree(realSession);
realSession = NULL;
}
void CreateAuthParamsVec(ParamsVec *vec)
{
*vec = CREATE_HC_VECTOR(ParamsVec)
*vec = CREATE_HC_VECTOR(ParamsVec);
}
void DestroyAuthParamsVec(ParamsVec *vec)
{
DESTROY_HC_VECTOR(ParamsVec, vec)
DESTROY_HC_VECTOR(ParamsVec, vec);
}

View File

@ -23,6 +23,7 @@
#include "device_auth_defines.h"
#include "hc_log.h"
#include "hc_types.h"
#include "os_account_adapter.h"
#include "session_common.h"
static int32_t ProcessServerAuthSession(Session *session, CJson *in);
@ -34,6 +35,16 @@ static int32_t CombineServerParams(const CJson *confirmationJson, CJson *dataFro
LOGE("Failed to get auth form in data sent by client for the first time!");
return HC_ERR_JSON_GET;
}
int32_t osAccountId = ANY_OS_ACCOUNT;
(void)GetIntFromJson(confirmationJson, FIELD_OS_ACCOUNT_ID, &osAccountId);
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if (osAccountId == INVALID_OS_ACCOUNT) {
return HC_ERR_INVALID_PARAMS;
}
if (AddIntToJson(dataFromClient, FIELD_OS_ACCOUNT_ID, osAccountId) != HC_SUCCESS) {
LOGE("Failed to add os accountId for server in onRequest confirm!");
return HC_ERR_JSON_ADD;
}
int32_t groupAuthType = GetGroupAuthType(authForm);
BaseGroupAuth *groupAuthHandle = GetGroupAuth(groupAuthType);
if (groupAuthHandle == NULL) {

View File

@ -112,4 +112,28 @@ int32_t GetInfoHash(const uint8_t *info, uint32_t infoLen, char *str, uint32_t s
HcFree(infoHash.val);
infoHash.val = NULL;
return res;
}
int32_t GroupTypeToAuthForm(int32_t groupType)
{
int32_t authForm;
switch (groupType) {
case PEER_TO_PEER_GROUP:
authForm = AUTH_FORM_ACCOUNT_UNRELATED;
break;
case COMPATIBLE_GROUP:
authForm = AUTH_FORM_ACCOUNT_UNRELATED;
break;
case IDENTICAL_ACCOUNT_GROUP:
authForm = AUTH_FORM_IDENTICAL_ACCOUNT;
break;
case ACROSS_ACCOUNT_AUTHORIZE_GROUP:
authForm = AUTH_FORM_ACROSS_ACCOUNT;
break;
default:
LOGE("Invalid group type!");
authForm = AUTH_FORM_INVALID_TYPE;
break;
}
return authForm;
}

View File

@ -21,8 +21,8 @@
typedef struct {
int type;
int32_t (*createGroup)(CJson *jsonParams, char **returnJsonStr);
int32_t (*deleteGroup)(CJson *jsonParams, char **returnJsonStr);
int32_t (*createGroup)(int32_t osAccountId, CJson *jsonParams, char **returnJsonStr);
int32_t (*deleteGroup)(int32_t osAccountId, CJson *jsonParams, char **returnJsonStr);
} BaseGroup;
#endif

View File

@ -23,9 +23,18 @@
typedef struct {
HcTaskBase base;
int64_t reqId;
int32_t osAccountId;
int32_t opCode;
CJson *params;
const DeviceAuthCallback *cb;
} GroupManagerTask;
typedef struct {
int64_t reqId;
int32_t osAccountId;
int32_t opCode;
CJson *params;
const DeviceAuthCallback *cb;
} GMTaskParams;
#endif

View File

@ -16,7 +16,7 @@
#ifndef BROADCAST_MANAGER_H
#define BROADCAST_MANAGER_H
#include "database.h"
#include "data_manager.h"
#include "device_auth.h"
#ifdef __cplusplus
@ -24,10 +24,10 @@ extern "C" {
#endif
typedef struct {
void (*postOnGroupCreated)(const GroupInfo *groupInfo);
void (*postOnGroupDeleted)(const GroupInfo *groupInfo);
void (*postOnDeviceBound)(const char *peerUdid, const GroupInfo *groupInfo);
void (*postOnDeviceUnBound)(const char *peerUdid, const GroupInfo *groupInfo);
void (*postOnGroupCreated)(const TrustedGroupEntry *groupEntry);
void (*postOnGroupDeleted)(const TrustedGroupEntry *groupEntry);
void (*postOnDeviceBound)(const char *peerUdid, const TrustedGroupEntry *groupEntry);
void (*postOnDeviceUnBound)(const char *peerUdid, const TrustedGroupEntry *groupEntry);
void (*postOnDeviceNotTrusted)(const char *peerUdid);
void (*postOnLastGroupDeleted)(const char *peerUdid, int groupType);
void (*postOnTrustedDeviceNumChanged)(int curTrustedDeviceNum);

View File

@ -26,34 +26,43 @@ extern "C" {
int32_t InitGroupManager(void);
void DestroyGroupManager(void);
int32_t CreateGroupImpl(int64_t requestId, const char *appId, const char *createParams);
int32_t DeleteGroupImpl(int64_t requestId, const char *appId, const char *disbandParams);
int32_t AddMemberToGroupImpl(int64_t requestId, const char *appId, const char *addParams);
int32_t DeleteMemberFromGroupImpl(int64_t requestId, const char *appId, const char *deleteParams);
int32_t CreateGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams);
int32_t DeleteGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *disbandParams);
int32_t AddMemberToGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams);
int32_t DeleteMemberFromGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *deleteParams);
int32_t ProcessBindDataImpl(int64_t requestId, const uint8_t *data, uint32_t dataLen);
int32_t ConfirmRequestImpl(int64_t requestId, const char *appId, const char *confirmParams);
int32_t ConfirmRequestImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *confirmParams);
int32_t GenerateAccountGroupIdImpl(int32_t groupType, const char *userIdHash, const char *sharedUserIdHash,
char **returnGroupId);
int32_t SyncAcrossAccountGroupImpl(const char *appId, const char *userIdHash, const char *deviceId,
const CJson *sharedUserIdHashList);
int32_t AddGroupManagerImpl(const char *appId, const char *groupId, const char *managerAppId);
int32_t AddGroupFriendImpl(const char *appId, const char *groupId, const char *friendAppId);
int32_t DeleteGroupManagerImpl(const char *appId, const char *groupId, const char *managerAppId);
int32_t DeleteGroupFriendImpl(const char *appId, const char *groupId, const char *friendAppId);
int32_t GetGroupManagersImpl(const char *appId, const char *groupId, char **returnManagers, uint32_t *returnSize);
int32_t GetGroupFriendsImpl(const char *appId, const char *groupId, char **returnFriends, uint32_t *returnSize);
int32_t AddGroupManagerImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *managerAppId);
int32_t AddGroupFriendImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *friendAppId);
int32_t DeleteGroupManagerImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *managerAppId);
int32_t DeleteGroupFriendImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *friendAppId);
int32_t GetGroupManagersImpl(int32_t osAccountId, const char *appId, const char *groupId,
char **returnManagers, uint32_t *returnSize);
int32_t GetGroupFriendsImpl(int32_t osAccountId, const char *appId, const char *groupId,
char **returnFriends, uint32_t *returnSize);
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 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);
int32_t GetRelatedGroupsImpl(const char *appId, const char *peerDeviceId, char **returnGroupVec, uint32_t *groupNum);
int32_t GetDeviceInfoByIdImpl(const char *appId, const char *deviceId, const char *groupId, char **returnDeviceInfo);
int32_t GetTrustedDevicesImpl(const char *appId, const char *groupId, char **returnDevInfoVec, uint32_t *deviceNum);
bool IsDeviceInGroupImpl(const char *appId, const char *groupId, const char *deviceId);
int32_t CheckAccessToGroupImpl(int32_t osAccountId, const char *appId, const char *groupId);
int32_t GetGroupInfoByIdImpl(int32_t osAccountId, const char *appId, const char *groupId, char **returnGroupInfo);
int32_t GetGroupInfoImpl(int32_t osAccountId, const char *appId, const char *queryParams,
char **returnGroupVec, uint32_t *groupNum);
int32_t GetJoinedGroupsImpl(int32_t osAccountId, const char *appId, int groupType,
char **returnGroupVec, uint32_t *groupNum);
int32_t GetRelatedGroupsImpl(int32_t osAccountId, const char *appId, const char *peerDeviceId,
char **returnGroupVec, uint32_t *groupNum);
int32_t GetDeviceInfoByIdImpl(int32_t osAccountId, const char *appId, const char *deviceId, const char *groupId,
char **returnDeviceInfo);
int32_t GetTrustedDevicesImpl(int32_t osAccountId, const char *appId, const char *groupId,
char **returnDevInfoVec, uint32_t *deviceNum);
bool IsDeviceInGroupImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *deviceId);
int32_t GetPkInfoListImpl(int32_t osAccountId, const char *appId, const char *queryParams,
char **returnInfoList, uint32_t *returnInfoNum);
void DestroyInfoImpl(char **returnInfo);
int32_t BindPeerImpl(int64_t requestId, const char *appId, const char *bindParams);

View File

@ -29,7 +29,7 @@ void DestroyGroupManagerTask(HcTaskBase *task);
int32_t BindCallbackToTask(GroupManagerTask *task, const CJson *jsonParams);
int32_t AddReqInfoToJson(int64_t requestId, const char *appId, CJson *jsonParams);
int32_t AddBindParamsToJson(int operationCode, int64_t requestId, const char *appId, CJson *jsonParams);
int32_t InitAndPushGMTask(int32_t opCode, int64_t reqId, CJson *params, TaskFunc func);
int32_t InitAndPushGMTask(int32_t osAccountId, int32_t opCode, int64_t reqId, CJson *params, TaskFunc func);
#ifdef __cplusplus
}

View File

@ -24,34 +24,41 @@ extern "C" {
#endif
typedef struct {
int32_t (*createGroup)(int64_t requestId, const char *appId, const char *createParams);
int32_t (*deleteGroup)(int64_t requestId, const char *appId, const char *disbandParams);
int32_t (*addMember)(int64_t requestId, const char *appId, const char *addParams);
int32_t (*deleteMember)(int64_t requestId, const char *appId, const char *deleteParams);
int32_t (*createGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams);
int32_t (*deleteGroup)(int32_t osAccountId, int64_t requestId, const char *appId, const char *disbandParams);
int32_t (*addMember)(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams);
int32_t (*deleteMember)(int32_t osAccountId, int64_t requestId, const char *appId, const char *deleteParams);
int32_t (*processBindData)(int64_t requestId, const uint8_t *data, uint32_t dataLen);
int32_t (*confirmRequest)(int64_t requestId, const char *appId, const char *confirmParams);
int32_t (*confirmRequest)(int32_t osAccountId, int64_t requestId, const char *appId, const char *confirmParams);
int32_t (*generateAccountGroupId)(int32_t groupType, const char *userIdHash, const char *sharedUserIdHash,
char **returnGroupId);
int32_t (*syncAcrossAccountGroup)(const char *appId, const char *userIdHash, const char *deviceId,
const CJson *sharedUserIdHashList);
int32_t (*addGroupRole)(bool isManager, const char *appId, const char *groupId, const char *roleAppId);
int32_t (*deleteGroupRole)(bool isManager, const char *appId, const char *groupId, const char *roleAppId);
int32_t (*getGroupRoles)(bool isManager, const char *appId, const char *groupId, char **returnJsonStr,
uint32_t *returnSize);
int32_t (*addGroupRole)(int32_t osAccountId, bool isManager, const char *appId, const char *groupId,
const char *roleAppId);
int32_t (*deleteGroupRole)(int32_t osAccountId, bool isManager, const char *appId, const char *groupId,
const char *roleAppId);
int32_t (*getGroupRoles)(int32_t osAccuntId, bool isManager, const char *appId, const char *groupId,
char **returnJsonStr, uint32_t *returnSize);
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 (*getAccessibleGroupInfoById)(const char *appId, const char *groupId, char **returnGroupInfo);
int32_t (*getAccessibleGroupInfo)(const char *appId, const char *queryParams, char **returnGroupVec,
uint32_t *groupNum);
int32_t (*getAccessibleJoinedGroups)(const char *appId, int groupType, char **returnGroupVec, uint32_t *groupNum);
int32_t (*getAccessibleRelatedGroups)(const char *appId, const char *peerDeviceId, bool isUdid,
int32_t (*checkAccessToGroup)(int32_t osAccountId, const char *appId, const char *groupId);
int32_t (*getAccessibleGroupInfoById)(int32_t osAccountId, const char *appId, const char *groupId,
char **returnGroupInfo);
int32_t (*getAccessibleGroupInfo)(int32_t osAccountId, const char *appId, const char *queryParams,
char **returnGroupVec, uint32_t *groupNum);
int32_t (*getAccessibleDeviceInfoById)(const char *appId, const char *deviceId, bool isUdid,
int32_t (*getAccessibleJoinedGroups)(int32_t osAccountId, const char *appId, int groupType,
char **returnGroupVec, uint32_t *groupNum);
int32_t (*getAccessibleRelatedGroups)(int32_t osAccountId, const char *appId, const char *peerDeviceId, bool isUdid,
char **returnGroupVec, uint32_t *groupNum);
int32_t (*getAccessibleDeviceInfoById)(int32_t osAccountId, const char *appId, const char *deviceId, bool isUdid,
const char *groupId, char **returnDeviceInfo);
int32_t (*getAccessibleTrustedDevices)(const char *appId, const char *groupId,
int32_t (*getAccessibleTrustedDevices)(int32_t osAccountId, const char *appId, const char *groupId,
char **returnDevInfoVec, uint32_t *deviceNum);
bool (*isDeviceInAccessibleGroup)(const char *appId, const char *groupId, const char *deviceId, bool isUdid);
bool (*isDeviceInAccessibleGroup)(int32_t osAccountId, const char *appId, const char *groupId,
const char *deviceId, bool isUdid);
int32_t (*getPkInfoList)(int32_t osAccountId, const char *appId, const char *queryParams, char **returnInfoList,
uint32_t *returnInfoNum);
void (*destroyInfo)(char **returnInfo);
} GroupImpl;

View File

@ -17,7 +17,7 @@
#define GROUP_OPERATION_COMMON_H
#include "string_util.h"
#include "database.h"
#include "data_manager.h"
#include "json_utils.h"
#ifdef __cplusplus
@ -25,8 +25,8 @@ extern "C" {
#endif
bool IsAccountRelatedGroup(int groupType);
int32_t GenerateReturnGroupInfo(const GroupInfo *groupInfo, CJson *returnJson);
int32_t GenerateReturnDevInfo(const DeviceInfo *devInfo, CJson *returnJson);
int32_t GenerateReturnGroupInfo(const TrustedGroupEntry *groupInfo, CJson *returnJson);
int32_t GenerateReturnDevInfo(const TrustedDeviceEntry *devInfo, CJson *returnJson);
bool IsUserTypeValid(int userType);
bool IsExpireTimeValid(int expireTime);
@ -36,46 +36,64 @@ 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 AssertUserIdHashExist(const CJson *jsonParams);
int32_t CheckGroupExist(const char *groupId);
int32_t CheckGroupNumLimit(int32_t groupType, const char *appId);
int32_t CheckDeviceNumLimit(const char *groupId, 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);
int32_t CheckUserTypeIfExist(const CJson *jsonParams);
int32_t CheckGroupVisibilityIfExist(const CJson *jsonParams);
int32_t CheckExpireTimeIfExist(const CJson *jsonParams);
int32_t CheckPermForGroup(int actionType, const char *callerPkgName, const char *groupId);
int32_t CheckPermForGroup(int32_t osAccountId, int actionType, const char *callerPkgName, const char *groupId);
int32_t AddGroupNameToParams(const char *groupName, GroupInfo *groupParams);
int32_t AddGroupIdToParams(const char *groupId, GroupInfo *groupParams);
int32_t AddGroupOwnerToParams(const char *owner, GroupInfo *groupParams);
int32_t AddGroupTypeToParams(int groupType, GroupInfo *groupParams);
int32_t AddGroupVisibilityOrDefault(const CJson *jsonParams, GroupInfo *groupParams);
int32_t AddExpireTimeOrDefault(const CJson *jsonParams, GroupInfo *groupParams);
int32_t AddUserIdHashToGroupParams(const CJson *jsonParams, GroupInfo *groupParams);
int32_t AddGroupNameToParams(const char *groupName, TrustedGroupEntry *groupParams);
int32_t AddGroupIdToParams(const char *groupId, TrustedGroupEntry *groupParams);
int32_t AddGroupOwnerToParams(const char *owner, TrustedGroupEntry *groupParams);
int32_t AddGroupTypeToParams(int groupType, TrustedGroupEntry *groupParams);
int32_t AddGroupVisibilityOrDefault(const CJson *jsonParams, TrustedGroupEntry *groupParams);
int32_t AddExpireTimeOrDefault(const CJson *jsonParams, TrustedGroupEntry *groupParams);
int32_t AddUserIdHashToGroupParams(const CJson *jsonParams, TrustedGroupEntry *groupParams);
int32_t AddUdidToParams(DeviceInfo *devParams);
int32_t AddAuthIdToParamsOrDefault(const CJson *jsonParams, DeviceInfo *devParams);
int32_t AddUserTypeToParamsOrDefault(const CJson *jsonParams, DeviceInfo *devParams);
int32_t AddServiceTypeToParams(const char *groupId, DeviceInfo *devParams);
int32_t AddGroupIdToDevParams(const char *groupId, DeviceInfo *devParams);
int32_t AddUserIdHashToDevParams(const CJson *jsonParams, DeviceInfo *devParams);
int32_t AddUdidToParams(TrustedDeviceEntry *devParams);
int32_t AddAuthIdToParamsOrDefault(const CJson *jsonParams, TrustedDeviceEntry *devParams);
int32_t AddUserTypeToParamsOrDefault(const CJson *jsonParams, TrustedDeviceEntry *devParams);
int32_t AddServiceTypeToParams(const char *groupId, TrustedDeviceEntry *devParams);
int32_t AddGroupIdToDevParams(const char *groupId, TrustedDeviceEntry *devParams);
int32_t AddUserIdHashToDevParams(const CJson *jsonParams, TrustedDeviceEntry *devParams);
int32_t AddGroupToDatabaseByJson(int32_t (*generateGroupParams)(const CJson*, const char *, GroupInfo*),
const CJson *jsonParams, const char *groupId);
int32_t AddDeviceToDatabaseByJson(int32_t (*generateDevParams)(const CJson*, const char*, DeviceInfo*),
const CJson *jsonParams, const char *groupId);
int32_t DelGroupFromDatabase(const char *groupId);
int32_t AddGroupToDatabaseByJson(int32_t osAccountId, int32_t (*generateGroupParams)(const CJson*,
const char *, TrustedGroupEntry*), const CJson *jsonParams, const char *groupId);
int32_t AddDeviceToDatabaseByJson(int32_t osAccountId, int32_t (*generateDevParams)(const CJson*, const char*,
TrustedDeviceEntry*), const CJson *jsonParams, const char *groupId);
int32_t DelGroupFromDb(int32_t osAccountId, const char *groupId);
int32_t ConvertGroupIdToJsonStr(const char *groupId, char **returnJsonStr);
int32_t GenerateBindSuccessData(const char *peerAuthId, const char *groupId, char **returnDataStr);
int32_t GenerateUnbindSuccessData(const char *peerAuthId, const char *groupId, char **returnDataStr);
int32_t GetGroupTypeFromDb(const char *groupId, int32_t *returnGroupType);
int32_t GetGroupTypeFromDb(int32_t osAccountId, const char *groupId, int32_t *returnGroupType);
int32_t GetUserIdHashFromJson(const CJson *jsonParams, char **userIdHash);
int32_t GetGroupIdFromJson(const CJson *jsonParams, const char **groupId);
int32_t GetAppIdFromJson(const CJson *jsonParams, const char **appId);
int32_t GetHashResult(const uint8_t *info, uint32_t infoLen, char *hash, uint32_t hashLen);
bool IsTrustedDeviceInGroup(int32_t osAccountId, const char *groupId, const char *deviceId, bool isUdid);
int32_t GetGroupInfoById(int32_t osAccountId, const char *groupId, TrustedGroupEntry *returnGroupEntry);
bool IsGroupOwner(int32_t osAccountId, const char *groupId, const char *appId);
bool IsGroupAccessible(int32_t osAccountId, const char *groupId, const char *appId);
bool IsGroupExistByGroupId(int32_t osAccountId, const char *groupId);
bool IsGroupEditAllowed(int32_t osAccountId, const char *groupId, const char *appId);
int32_t GetGroupInfo(int32_t osAccountId, int groupType, const char *groupId, const char *groupName,
const char *groupOwner, GroupEntryVec *groupEntryVec);
int32_t GetJoinedGroups(int32_t osAccountId, int groupType, GroupEntryVec *groupEntryVec);
int32_t GetTrustedDevInfoById(int32_t osAccountId, const char *deviceId, bool isUdid, const char *groupId,
TrustedDeviceEntry *deviceEntry);
int32_t GetTrustedDevices(int32_t osAccountId, const char *groupId, DeviceEntryVec *deviceEntryVec);
int32_t GetRelatedGroups(int32_t osAccountId, const char *peerDeviceId, bool isUdid, GroupEntryVec *groupEntryVec);
TrustedGroupEntry *GetGroupEntryById(int32_t osAccountId, const char *groupId);
TrustedDeviceEntry *GetTrustedDeviceEntryById(int32_t osAccountId, const char *deviceId, bool isUdid,
const char *groupId);
#ifdef __cplusplus
}
#endif

View File

@ -24,13 +24,18 @@ extern "C" {
typedef struct {
BaseGroup base;
int32_t (*addMember)(int64_t requestId, CJson *jsonParams, const DeviceAuthCallback *callback);
int32_t (*deleteMember)(int64_t requestId, CJson *jsonParams, const DeviceAuthCallback *callback);
int32_t (*processData)(int64_t requestId, CJson *jsonParams, const DeviceAuthCallback *callback);
int32_t (*addGroupRole)(bool isManager, const char *appId, const char *groupId, const char *roleAppId);
int32_t (*deleteGroupRole)(bool isManager, const char *appId, const char *groupId, const char *roleAppId);
int32_t (*getGroupRoles)(bool isManager, const char *appId, const char *groupId, char **returnJsonStr,
uint32_t *returnSize);
int32_t (*addMember)(int32_t osAccountId, int64_t requestId, CJson *jsonParams,
const DeviceAuthCallback *callback);
int32_t (*deleteMember)(int32_t osAccountId, int64_t requestId, CJson *jsonParams,
const DeviceAuthCallback *callback);
int32_t (*processData)(int64_t requestId, CJson *jsonParams,
const DeviceAuthCallback *callback);
int32_t (*addGroupRole)(int32_t osAccountId, bool isManager, const char *appId, const char *groupId,
const char *roleAppId);
int32_t (*deleteGroupRole)(int32_t osAccountId, bool isManager, const char *appId, const char *groupId,
const char *roleAppId);
int32_t (*getGroupRoles)(int32_t osAccountId, bool isManager, const char *appId, const char *groupId,
char **returnJsonStr, uint32_t *returnSize);
} PeerToPeerGroup;
BaseGroup *GetPeerToPeerGroupInstance(void);

View File

@ -20,7 +20,7 @@
int32_t AddInfoToSendData(bool isNeedCompatibleInfo, const BindSession *session, CJson *data);
int32_t GenerateBasicModuleParams(bool isClient, BindSession *session, CJson *moduleParams);
int32_t GenerateBindParams(int isClient, const CJson *jsonParams, BindSession *session);
int32_t GenerateBindParams(int32_t osAccountId, int isClient, const CJson *jsonParams, BindSession *session);
bool NeedCreateGroup(int isClient, int operationCode);
bool NeedForceDelete(const BindSession *session);
int32_t ForceUnbindDevice(const BindSession *session);

View File

@ -33,6 +33,7 @@ typedef struct {
int32_t opCode;
int32_t channelType;
int32_t moduleType;
int32_t osAccountId;
int64_t reqId;
int64_t channelId;
} BindSession;

View File

@ -28,19 +28,19 @@ typedef struct {
DataChangeListener *listener;
} ListenerEntry;
DECLARE_HC_VECTOR(ListenerEntryVec, ListenerEntry)
IMPLEMENT_HC_VECTOR(ListenerEntryVec, ListenerEntry, 1)
DECLARE_HC_VECTOR(ListenerEntryVec, ListenerEntry);
IMPLEMENT_HC_VECTOR(ListenerEntryVec, ListenerEntry, 1);
static ListenerEntryVec g_listenerEntryVec;
static HcMutex *g_broadcastMutex = NULL;
static int32_t GenerateMessage(const GroupInfo *groupInfo, char **returnGroupInfo)
static int32_t GenerateMessage(const TrustedGroupEntry *groupEntry, char **returnGroupInfo)
{
CJson *message = CreateJson();
if (message == NULL) {
LOGE("Failed to allocate message memory!");
return HC_ERR_ALLOC_MEMORY;
}
int32_t result = GenerateReturnGroupInfo(groupInfo, message);
int32_t result = GenerateReturnGroupInfo(groupEntry, message);
if (result != HC_SUCCESS) {
FreeJson(message);
return result;
@ -55,14 +55,14 @@ static int32_t GenerateMessage(const GroupInfo *groupInfo, char **returnGroupInf
return HC_SUCCESS;
}
static void PostOnGroupCreated(const GroupInfo *groupInfo)
static void PostOnGroupCreated(const TrustedGroupEntry *groupEntry)
{
if (groupInfo == NULL) {
if (groupEntry == NULL) {
LOGE("The groupEntry is NULL!");
return;
}
char *messageStr = NULL;
if (GenerateMessage(groupInfo, &messageStr) != HC_SUCCESS) {
if (GenerateMessage(groupEntry, &messageStr) != HC_SUCCESS) {
return;
}
uint32_t index;
@ -78,14 +78,14 @@ static void PostOnGroupCreated(const GroupInfo *groupInfo)
g_broadcastMutex->unlock(g_broadcastMutex);
}
static void PostOnGroupDeleted(const GroupInfo *groupInfo)
static void PostOnGroupDeleted(const TrustedGroupEntry *groupEntry)
{
if (groupInfo == NULL) {
if (groupEntry == NULL) {
LOGE("The groupEntry is NULL!");
return;
}
char *messageStr = NULL;
if (GenerateMessage(groupInfo, &messageStr) != HC_SUCCESS) {
if (GenerateMessage(groupEntry, &messageStr) != HC_SUCCESS) {
return;
}
uint32_t index;
@ -101,14 +101,14 @@ static void PostOnGroupDeleted(const GroupInfo *groupInfo)
g_broadcastMutex->unlock(g_broadcastMutex);
}
static void PostOnDeviceBound(const char *peerUdid, const GroupInfo *groupInfo)
static void PostOnDeviceBound(const char *peerUdid, const TrustedGroupEntry *groupEntry)
{
if ((peerUdid == NULL) || (groupInfo == NULL)) {
if ((peerUdid == NULL) || (groupEntry == NULL)) {
LOGE("The peerUdid or groupEntry is NULL!");
return;
}
char *messageStr = NULL;
if (GenerateMessage(groupInfo, &messageStr) != HC_SUCCESS) {
if (GenerateMessage(groupEntry, &messageStr) != HC_SUCCESS) {
return;
}
uint32_t index;
@ -124,14 +124,14 @@ static void PostOnDeviceBound(const char *peerUdid, const GroupInfo *groupInfo)
g_broadcastMutex->unlock(g_broadcastMutex);
}
static void PostOnDeviceUnBound(const char *peerUdid, const GroupInfo *groupInfo)
static void PostOnDeviceUnBound(const char *peerUdid, const TrustedGroupEntry *groupEntry)
{
if ((peerUdid == NULL) || (groupInfo == NULL)) {
if ((peerUdid == NULL) || (groupEntry == NULL)) {
LOGE("The peerUdid or groupEntry is NULL!");
return;
}
char *messageStr = NULL;
if (GenerateMessage(groupInfo, &messageStr) != HC_SUCCESS) {
if (GenerateMessage(groupEntry, &messageStr) != HC_SUCCESS) {
return;
}
uint32_t index;
@ -284,7 +284,7 @@ int32_t InitBroadcastManager(void)
return HC_ERROR;
}
}
g_listenerEntryVec = CREATE_HC_VECTOR(ListenerEntryVec)
g_listenerEntryVec = CREATE_HC_VECTOR(ListenerEntryVec);
LOGI("[Broadcaster]: Init broadcast manager module successfully!");
return HC_SUCCESS;
}
@ -300,7 +300,7 @@ void DestroyBroadcastManager(void)
HcFree(entry->listener);
}
}
DESTROY_HC_VECTOR(ListenerEntryVec, &g_listenerEntryVec)
DESTROY_HC_VECTOR(ListenerEntryVec, &g_listenerEntryVec);
g_broadcastMutex->unlock(g_broadcastMutex);
if (g_broadcastMutex != NULL) {
DestroyHcMutex(g_broadcastMutex);

View File

@ -27,7 +27,7 @@ typedef struct {
DeviceAuthCallback *callback;
} CallbackEntry;
DECLARE_HC_VECTOR(GMCallbackEntryVec, CallbackEntry)
DECLARE_HC_VECTOR(GMCallbackEntryVec, CallbackEntry);
IMPLEMENT_HC_VECTOR(GMCallbackEntryVec, CallbackEntry, 1)
static GMCallbackEntryVec g_callbackVec;
static HcMutex *g_callbackMutex = NULL;

View File

@ -37,7 +37,7 @@ typedef struct {
int64_t channelId;
} ChannelEntry;
DECLARE_HC_VECTOR(ChannelEntryVec, ChannelEntry)
DECLARE_HC_VECTOR(ChannelEntryVec, ChannelEntry);
IMPLEMENT_HC_VECTOR(ChannelEntryVec, ChannelEntry, 1)
static ChannelEntryVec g_channelVec;
static HcMutex *g_channelMutex = NULL;
@ -284,7 +284,7 @@ int32_t InitSoftBusChannelModule(void)
return HC_ERR_INIT_FAILED;
}
}
g_channelVec = CREATE_HC_VECTOR(ChannelEntryVec)
g_channelVec = CREATE_HC_VECTOR(ChannelEntryVec);
ISessionListener softBusListener = {
.OnSessionOpened = OnChannelOpenedCb,
.OnSessionClosed = OnChannelClosedCb,
@ -300,7 +300,7 @@ int32_t InitSoftBusChannelModule(void)
void DestroySoftBusChannelModule(void)
{
g_channelMutex->lock(g_channelMutex);
DESTROY_HC_VECTOR(ChannelEntryVec, &g_channelVec)
DESTROY_HC_VECTOR(ChannelEntryVec, &g_channelVec);
g_channelMutex->unlock(g_channelMutex);
if (g_channelMutex != NULL) {
DestroyHcMutex(g_channelMutex);

View File

@ -17,28 +17,32 @@
#include "bind_peer.h"
#include "common_defs.h"
#include "database_manager.h"
#include "data_manager.h"
#include "group_operation.h"
#include "key_agree.h"
int32_t CreateGroupImpl(int64_t requestId, const char *appId, const char *createParams)
int32_t CreateGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams)
{
return IsGroupSupport() ? GetGroupImplInstance()->createGroup(requestId, appId, createParams) : HC_ERR_NOT_SUPPORT;
return IsGroupSupport() ? GetGroupImplInstance()->createGroup(osAccountId, requestId, appId, createParams)
: HC_ERR_NOT_SUPPORT;
}
int32_t DeleteGroupImpl(int64_t requestId, const char *appId, const char *disbandParams)
int32_t DeleteGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *disbandParams)
{
return IsGroupSupport() ? GetGroupImplInstance()->deleteGroup(requestId, appId, disbandParams) : HC_ERR_NOT_SUPPORT;
return IsGroupSupport() ? GetGroupImplInstance()->deleteGroup(osAccountId, requestId, appId, disbandParams)
: HC_ERR_NOT_SUPPORT;
}
int32_t AddMemberToGroupImpl(int64_t requestId, const char *appId, const char *addParams)
int32_t AddMemberToGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams)
{
return IsGroupSupport() ? GetGroupImplInstance()->addMember(requestId, appId, addParams) : HC_ERR_NOT_SUPPORT;
return IsGroupSupport() ? GetGroupImplInstance()->addMember(osAccountId, requestId, appId, addParams)
: HC_ERR_NOT_SUPPORT;
}
int32_t DeleteMemberFromGroupImpl(int64_t requestId, const char *appId, const char *deleteParams)
int32_t DeleteMemberFromGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *deleteParams)
{
return IsGroupSupport() ? GetGroupImplInstance()->deleteMember(requestId, appId, deleteParams) : HC_ERR_NOT_SUPPORT;
return IsGroupSupport() ? GetGroupImplInstance()->deleteMember(osAccountId, requestId, appId, deleteParams)
: HC_ERR_NOT_SUPPORT;
}
int32_t ProcessBindDataImpl(int64_t requestId, const uint8_t *data, uint32_t dataLen)
@ -46,9 +50,9 @@ int32_t ProcessBindDataImpl(int64_t requestId, const uint8_t *data, uint32_t dat
return IsGroupSupport() ? GetGroupImplInstance()->processBindData(requestId, data, dataLen) : HC_ERR_NOT_SUPPORT;
}
int32_t ConfirmRequestImpl(int64_t requestId, const char *appId, const char *confirmParams)
int32_t ConfirmRequestImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *confirmParams)
{
return IsGroupSupport() ? GetGroupImplInstance()->confirmRequest(requestId, appId,
return IsGroupSupport() ? GetGroupImplInstance()->confirmRequest(osAccountId, requestId, appId,
confirmParams) : HC_ERR_NOT_SUPPORT;
}
@ -66,39 +70,41 @@ int32_t SyncAcrossAccountGroupImpl(const char *appId, const char *userIdHash, co
sharedUserIdHashList) : HC_ERR_NOT_SUPPORT;
}
int32_t AddGroupManagerImpl(const char *appId, const char *groupId, const char *managerAppId)
int32_t AddGroupManagerImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *managerAppId)
{
return IsGroupSupport() ? GetGroupImplInstance()->addGroupRole(true, appId, groupId,
return IsGroupSupport() ? GetGroupImplInstance()->addGroupRole(osAccountId, true, appId, groupId,
managerAppId) : HC_ERR_NOT_SUPPORT;
}
int32_t AddGroupFriendImpl(const char *appId, const char *groupId, const char *friendAppId)
int32_t AddGroupFriendImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *friendAppId)
{
return IsGroupSupport() ? GetGroupImplInstance()->addGroupRole(false, appId, groupId,
return IsGroupSupport() ? GetGroupImplInstance()->addGroupRole(osAccountId, false, appId, groupId,
friendAppId) : HC_ERR_NOT_SUPPORT;
}
int32_t DeleteGroupManagerImpl(const char *appId, const char *groupId, const char *managerAppId)
int32_t DeleteGroupManagerImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *managerAppId)
{
return IsGroupSupport() ? GetGroupImplInstance()->deleteGroupRole(true, appId, groupId,
return IsGroupSupport() ? GetGroupImplInstance()->deleteGroupRole(osAccountId, true, appId, groupId,
managerAppId) : HC_ERR_NOT_SUPPORT;
}
int32_t DeleteGroupFriendImpl(const char *appId, const char *groupId, const char *friendAppId)
int32_t DeleteGroupFriendImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *friendAppId)
{
return IsGroupSupport() ? GetGroupImplInstance()->deleteGroupRole(false, appId, groupId,
return IsGroupSupport() ? GetGroupImplInstance()->deleteGroupRole(osAccountId, false, appId, groupId,
friendAppId) : HC_ERR_NOT_SUPPORT;
}
int32_t GetGroupManagersImpl(const char *appId, const char *groupId, char **returnManagers, uint32_t *returnSize)
int32_t GetGroupManagersImpl(int32_t osAccuntId, const char *appId, const char *groupId,
char **returnManagers, uint32_t *returnSize)
{
return IsGroupSupport() ? GetGroupImplInstance()->getGroupRoles(true, appId, groupId,
return IsGroupSupport() ? GetGroupImplInstance()->getGroupRoles(osAccuntId, true, appId, groupId,
returnManagers, returnSize) : HC_ERR_NOT_SUPPORT;
}
int32_t GetGroupFriendsImpl(const char *appId, const char *groupId, char **returnFriends, uint32_t *returnSize)
int32_t GetGroupFriendsImpl(int32_t osAccuntId, const char *appId, const char *groupId,
char **returnFriends, uint32_t *returnSize)
{
return IsGroupSupport() ? GetGroupImplInstance()->getGroupRoles(false, appId, groupId,
return IsGroupSupport() ? GetGroupImplInstance()->getGroupRoles(osAccuntId, false, appId, groupId,
returnFriends, returnSize) : HC_ERR_NOT_SUPPORT;
}
@ -112,53 +118,66 @@ int32_t UnRegListenerImpl(const char *appId)
return IsGroupSupport() ? GetGroupImplInstance()->unRegListener(appId) : HC_ERR_NOT_SUPPORT;
}
int32_t CheckAccessToGroupImpl(const char *appId, const char *groupId)
int32_t CheckAccessToGroupImpl(int32_t osAccountId, const char *appId, const char *groupId)
{
return IsGroupSupport() ? GetGroupImplInstance()->checkAccessToGroup(appId, groupId) : HC_ERR_NOT_SUPPORT;
return IsGroupSupport() ? GetGroupImplInstance()->checkAccessToGroup(osAccountId, appId, groupId)
: HC_ERR_NOT_SUPPORT;
}
int32_t GetGroupInfoByIdImpl(const char *appId, const char *groupId, char **returnGroupInfo)
int32_t GetGroupInfoByIdImpl(int32_t osAccountId, const char *appId, const char *groupId, char **returnGroupInfo)
{
return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleGroupInfoById(appId, groupId,
return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleGroupInfoById(osAccountId, appId, groupId,
returnGroupInfo) : HC_ERR_NOT_SUPPORT;
}
int32_t GetGroupInfoImpl(const char *appId, const char *queryParams, char **returnGroupVec, uint32_t *groupNum)
int32_t GetGroupInfoImpl(int32_t osAccountId, const char *appId, const char *queryParams,
char **returnGroupVec, uint32_t *groupNum)
{
return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleGroupInfo(appId, queryParams, returnGroupVec,
groupNum) : HC_ERR_NOT_SUPPORT;
}
int32_t GetJoinedGroupsImpl(const char *appId, int groupType, char **returnGroupVec, uint32_t *groupNum)
{
return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleJoinedGroups(appId, groupType, returnGroupVec,
groupNum) : HC_ERR_NOT_SUPPORT;
}
int32_t GetRelatedGroupsImpl(const char *appId, const char *peerDeviceId, char **returnGroupVec, uint32_t *groupNum)
{
return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleRelatedGroups(appId, peerDeviceId, false,
return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleGroupInfo(osAccountId, appId, queryParams,
returnGroupVec, groupNum) : HC_ERR_NOT_SUPPORT;
}
int32_t GetDeviceInfoByIdImpl(const char *appId, const char *deviceId, const char *groupId, char **returnDeviceInfo)
int32_t GetJoinedGroupsImpl(int32_t osAccountId, const char *appId, int groupType,
char **returnGroupVec, uint32_t *groupNum)
{
return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleDeviceInfoById(appId, deviceId, false, groupId,
returnDeviceInfo) : HC_ERR_NOT_SUPPORT;
return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleJoinedGroups(osAccountId, appId, groupType,
returnGroupVec, groupNum) : HC_ERR_NOT_SUPPORT;
}
int32_t GetTrustedDevicesImpl(const char *appId, const char *groupId, char **returnDevInfoVec, uint32_t *deviceNum)
int32_t GetRelatedGroupsImpl(int32_t osAccountId, const char *appId, const char *peerDeviceId,
char **returnGroupVec, uint32_t *groupNum)
{
return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleTrustedDevices(appId, groupId, returnDevInfoVec,
deviceNum) : HC_ERR_NOT_SUPPORT;
return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleRelatedGroups(osAccountId, appId, peerDeviceId,
false, returnGroupVec, groupNum) : HC_ERR_NOT_SUPPORT;
}
bool IsDeviceInGroupImpl(const char *appId, const char *groupId, const char *deviceId)
int32_t GetDeviceInfoByIdImpl(int32_t osAccountId, const char *appId, const char *deviceId, const char *groupId,
char **returnDeviceInfo)
{
return IsGroupSupport() ? GetGroupImplInstance()->isDeviceInAccessibleGroup(appId, groupId,
return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleDeviceInfoById(osAccountId, appId, deviceId,
false, groupId, returnDeviceInfo) : HC_ERR_NOT_SUPPORT;
}
int32_t GetTrustedDevicesImpl(int32_t osAccountId, const char *appId, const char *groupId,
char **returnDevInfoVec, uint32_t *deviceNum)
{
return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleTrustedDevices(osAccountId, appId, groupId,
returnDevInfoVec, deviceNum) : HC_ERR_NOT_SUPPORT;
}
bool IsDeviceInGroupImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *deviceId)
{
return IsGroupSupport() ? GetGroupImplInstance()->isDeviceInAccessibleGroup(osAccountId, appId, groupId,
deviceId, false) : false;
}
int32_t GetPkInfoListImpl(int32_t osAccountId, const char *appId, const char *queryParams,
char **returnInfoList, uint32_t *returnInfoNum)
{
return IsGroupSupport() ? GetGroupImplInstance()->getPkInfoList(osAccountId, appId, queryParams,
returnInfoList, returnInfoNum) : HC_ERR_NOT_SUPPORT;
}
void DestroyInfoImpl(char **returnInfo)
{
if (IsGroupSupport()) {

View File

@ -20,14 +20,15 @@
#include "callback_manager.h"
#include "task_manager.h"
static int32_t InitGroupManagerTask(GroupManagerTask *task, int32_t opCode, int64_t reqId, CJson *params, TaskFunc func)
static int32_t InitGroupManagerTask(GroupManagerTask *task, GMTaskParams *taskParams, TaskFunc func)
{
task->base.doAction = func;
task->base.destroy = DestroyGroupManagerTask;
task->opCode = opCode;
task->reqId = reqId;
task->params = params;
return BindCallbackToTask(task, params);
task->osAccountId = taskParams->osAccountId;
task->opCode = taskParams->opCode;
task->reqId = taskParams->reqId;
task->params = taskParams->params;
return BindCallbackToTask(task, taskParams->params);
}
int32_t AddReqInfoToJson(int64_t requestId, const char *appId, CJson *jsonParams)
@ -76,14 +77,19 @@ int32_t AddBindParamsToJson(int operationCode, int64_t requestId, const char *ap
return AddReqInfoToJson(requestId, appId, jsonParams);
}
int32_t InitAndPushGMTask(int32_t opCode, int64_t reqId, CJson *params, TaskFunc func)
int32_t InitAndPushGMTask(int32_t osAccountId, int32_t opCode, int64_t reqId, CJson *params, TaskFunc func)
{
GroupManagerTask *task = (GroupManagerTask *)HcMalloc(sizeof(GroupManagerTask), 0);
if (task == NULL) {
LOGE("Failed to allocate task memory!");
return HC_ERR_ALLOC_MEMORY;
}
if (InitGroupManagerTask(task, opCode, reqId, params, func) != HC_SUCCESS) {
GMTaskParams taskParams;
taskParams.osAccountId = osAccountId;
taskParams.opCode = opCode;
taskParams.reqId = reqId;
taskParams.params = params;
if (InitGroupManagerTask(task, &taskParams, func) != HC_SUCCESS) {
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}

View File

@ -18,11 +18,15 @@
#include "alg_defs.h"
#include "broadcast_manager.h"
#include "callback_manager.h"
#include "database_manager.h"
#include "common_defs.h"
#include "data_manager.h"
#include "dev_auth_module_manager.h"
#include "device_auth_defines.h"
#include "group_manager_common.h"
#include "group_operation_common.h"
#include "hc_dev_info.h"
#include "hc_log.h"
#include "os_account_adapter.h"
#include "session_manager.h"
#include "task_manager.h"
@ -30,6 +34,7 @@
#include "identical_account_group.h"
#include "peer_to_peer_group.h"
static bool IsGroupTypeSupported(int groupType)
{
if (((groupType == PEER_TO_PEER_GROUP) && (IsPeerToPeerGroupSupported())) ||
@ -41,23 +46,24 @@ static bool IsGroupTypeSupported(int groupType)
return false;
}
static void RemoveNoPermissionGroup(GroupInfoVec *groupInfoVec, const char *appId)
static void RemoveNoPermissionGroup(int32_t osAccountId, GroupEntryVec *groupEntryVec, const char *appId)
{
uint32_t index = 0;
void **groupInfoPtr = NULL;
while (index < groupInfoVec->size(groupInfoVec)) {
groupInfoPtr = groupInfoVec->getp(groupInfoVec, index);
if ((groupInfoPtr == NULL) || (*groupInfoPtr == NULL)) {
TrustedGroupEntry **groupEntryPtr = NULL;
while (index < groupEntryVec->size(groupEntryVec)) {
groupEntryPtr = groupEntryVec->getp(groupEntryVec, index);
if ((groupEntryPtr == NULL) || (*groupEntryPtr == NULL)) {
index++;
continue;
}
GroupInfo *groupInfo = (GroupInfo *)(*groupInfoPtr);
if (IsGroupAccessible(StringGet(&groupInfo->id), appId)) {
if (IsGroupAccessible(osAccountId, StringGet(&(*groupEntryPtr)->id), appId)) {
index++;
continue;
}
void *tempEntry = NULL;
HC_VECTOR_POPELEMENT(groupInfoVec, &tempEntry, index);
LOGI("Remove a group without permission!");
TrustedGroupEntry *tempEntry = NULL;
HC_VECTOR_POPELEMENT(groupEntryVec, &tempEntry, index);
DestroyGroupEntry(tempEntry);
}
}
@ -77,7 +83,7 @@ static int32_t GenerateReturnEmptyArrayStr(char **returnVec)
return HC_SUCCESS;
}
static int32_t GenerateReturnGroupVec(GroupInfoVec *groupInfoVec, char **returnGroupVec, uint32_t *groupNum)
static int32_t GenerateReturnGroupVec(GroupEntryVec *groupInfoVec, char **returnGroupVec, uint32_t *groupNum)
{
if (HC_VECTOR_SIZE(groupInfoVec) == 0) {
LOGI("No group is found based on the query parameters!");
@ -92,10 +98,10 @@ static int32_t GenerateReturnGroupVec(GroupInfoVec *groupInfoVec, char **returnG
}
uint32_t groupCount = 0;
uint32_t index;
void **groupInfoPtr = NULL;
TrustedGroupEntry **groupInfoPtr = NULL;
FOR_EACH_HC_VECTOR(*groupInfoVec, index, groupInfoPtr) {
if ((groupInfoPtr != NULL) && ((*groupInfoPtr) != NULL)) {
GroupInfo *groupInfo = (GroupInfo*)(*groupInfoPtr);
if (groupInfoPtr != NULL) {
TrustedGroupEntry *groupInfo = *groupInfoPtr;
CJson *groupInfoJson = CreateJson();
if (groupInfoJson == NULL) {
LOGE("Failed to allocate groupInfoJson memory!");
@ -127,7 +133,7 @@ static int32_t GenerateReturnGroupVec(GroupInfoVec *groupInfoVec, char **returnG
return HC_SUCCESS;
}
static int32_t GenerateReturnDeviceVec(DeviceInfoVec *devInfoVec, char **returnDevInfoVec, uint32_t *deviceNum)
static int32_t GenerateReturnDeviceVec(DeviceEntryVec *devInfoVec, char **returnDevInfoVec, uint32_t *deviceNum)
{
if (HC_VECTOR_SIZE(devInfoVec) == 0) {
LOGI("No device is found based on the query parameters!");
@ -142,10 +148,10 @@ static int32_t GenerateReturnDeviceVec(DeviceInfoVec *devInfoVec, char **returnD
}
uint32_t devCount = 0;
uint32_t index;
void **devInfoPtr = NULL;
TrustedDeviceEntry **devInfoPtr = NULL;
FOR_EACH_HC_VECTOR(*devInfoVec, index, devInfoPtr) {
if ((devInfoPtr != NULL) && ((*devInfoPtr) != NULL)) {
DeviceInfo *devInfo = (DeviceInfo*)(*devInfoPtr);
TrustedDeviceEntry *devInfo = (TrustedDeviceEntry*)(*devInfoPtr);
CJson *devInfoJson = CreateJson();
if (devInfoJson == NULL) {
LOGE("Failed to allocate devInfoJson memory!");
@ -186,6 +192,182 @@ static bool IsQueryParamsValid(int groupType, const char *groupId, const char *g
}
}
static int32_t QueryRelatedGroupsForGetPk(int32_t osAccountId, const char *udid, GroupEntryVec *returnGroupEntryVec)
{
DeviceEntryVec deviceEntryVec = CreateDeviceEntryVec();
QueryDeviceParams params = InitQueryDeviceParams();
params.udid = udid;
int32_t result = QueryDevices(osAccountId, &params, &deviceEntryVec);
if (result != HC_SUCCESS) {
LOGE("Failed to query trusted devices!");
ClearDeviceEntryVec(&deviceEntryVec);
return result;
}
uint32_t index;
TrustedDeviceEntry **entry = NULL;
FOR_EACH_HC_VECTOR(deviceEntryVec, index, entry) {
if ((entry == NULL) || (*entry == NULL)) {
continue;
}
TrustedGroupEntry *groupEntry = GetGroupEntryById(osAccountId, StringGet(&(*entry)->groupId));
if (groupEntry == NULL) {
LOGE("Failed to get group entry by id!");
ClearDeviceEntryVec(&deviceEntryVec);
return HC_ERR_GROUP_NOT_EXIST;
}
if ((groupEntry->type != PEER_TO_PEER_GROUP) || (groupEntry->visibility != GROUP_VISIBILITY_PUBLIC)) {
DestroyGroupEntry(groupEntry);
continue;
}
if (returnGroupEntryVec->pushBackT(returnGroupEntryVec, groupEntry) == NULL) {
LOGE("Failed to push groupEntry to returnGroupEntryVec!");
DestroyGroupEntry(groupEntry);
ClearDeviceEntryVec(&deviceEntryVec);
return HC_ERR_MEMORY_COPY;
}
}
ClearDeviceEntryVec(&deviceEntryVec);
return HC_SUCCESS;
}
static int32_t GetPkByParams(const char *groupId, const TrustedDeviceEntry *deviceEntry,
char *returnPkHexStr, int32_t returnPkHexStrLen)
{
/* Use the DeviceGroupManager package name. */
const char *appId = GROUP_MANAGER_PACKAGE_NAME;
int userType = deviceEntry->devType;
const char *authId = StringGet(&deviceEntry->authId);
if (authId == NULL) {
LOGE("Failed to get authId from deviceEntry!");
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;
AuthModuleParams authParams = {
.pkgName = appId,
.serviceType = groupId,
.authId = &authIdBuff,
.userType = userType
};
int32_t res = GetPublicKey(DAS_MODULE, &authParams, &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(int32_t osAccountId, const char *queryUdid, const char *groupId, CJson *pkInfo)
{
TrustedDeviceEntry *deviceEntry = GetTrustedDeviceEntryById(osAccountId, queryUdid, true, groupId);
if (deviceEntry == NULL) {
LOGE("The trusted device is not found!");
return HC_ERR_DEVICE_NOT_EXIST;
}
char returnPkHexStr[SHA256_LEN * BYTE_TO_HEX_OPER_LENGTH + 1] = { 0 };
int32_t result = GetPkByParams(groupId, deviceEntry, returnPkHexStr, sizeof(returnPkHexStr));
DestroyDeviceEntry(deviceEntry);
if (result != HC_SUCCESS) {
return result;
}
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(int32_t osAccountId, const char *queryUdid, const GroupEntryVec *groupEntryVec,
CJson *pkInfoList)
{
uint32_t index;
TrustedGroupEntry **entry = NULL;
FOR_EACH_HC_VECTOR(*groupEntryVec, index, entry) {
if ((entry == NULL) || (*entry == NULL)) {
continue;
}
const char *groupId = StringGet(&((*entry)->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(osAccountId, 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(int32_t osAccountId, 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;
}
GroupEntryVec groupEntryVec = CreateGroupEntryVec();
int32_t res = QueryRelatedGroupsForGetPk(osAccountId, udid, &groupEntryVec);
if (res != HC_SUCCESS) {
ClearGroupEntryVec(&groupEntryVec);
return res;
}
RemoveNoPermissionGroup(osAccountId, &groupEntryVec, appId);
const char *queryUdid = NULL;
char selfUdid[INPUT_UDID_LEN] = { 0 };
if (isSelfPk) {
res = HcGetUdid((uint8_t *)selfUdid, INPUT_UDID_LEN);
if (res != HC_SUCCESS) {
LOGE("Failed to get local udid! res: %d", res);
ClearGroupEntryVec(&groupEntryVec);
return HC_ERR_DB;
}
queryUdid = selfUdid;
} else {
queryUdid = udid;
}
AddAllPkInfoToList(osAccountId, queryUdid, &groupEntryVec, pkInfoList);
ClearGroupEntryVec(&groupEntryVec);
return HC_SUCCESS;
}
static BaseGroup *GetGroupInstance(int32_t groupType)
{
if (!IsGroupTypeSupported(groupType)) {
@ -202,7 +384,7 @@ static BaseGroup *GetGroupInstance(int32_t groupType)
return instance;
}
static int32_t CreateGroup(CJson *jsonParams, char **returnJsonStr)
static int32_t CreateGroup(int32_t osAccountId, CJson *jsonParams, char **returnJsonStr)
{
if ((jsonParams == NULL) || (returnJsonStr == NULL)) {
LOGE("The input parameters contains NULL value!");
@ -218,10 +400,10 @@ static int32_t CreateGroup(CJson *jsonParams, char **returnJsonStr)
LOGE("The group instance is NULL or its function ptr is NULL!");
return HC_ERR_NULL_PTR;
}
return instance->createGroup(jsonParams, returnJsonStr);
return instance->createGroup(osAccountId, jsonParams, returnJsonStr);
}
static int32_t DeleteGroup(CJson *jsonParams, char **returnJsonStr)
static int32_t DeleteGroup(int32_t osAccountId, CJson *jsonParams, char **returnJsonStr)
{
if ((jsonParams == NULL) || (returnJsonStr == NULL)) {
LOGE("The input parameters contains NULL value!");
@ -233,9 +415,9 @@ static int32_t DeleteGroup(CJson *jsonParams, char **returnJsonStr)
int32_t groupType = PEER_TO_PEER_GROUP;
if (((result = GetGroupIdFromJson(jsonParams, &groupId)) != HC_SUCCESS) ||
((result = GetAppIdFromJson(jsonParams, &appId)) != HC_SUCCESS) ||
((result = CheckGroupExist(groupId)) != HC_SUCCESS) ||
((result = GetGroupTypeFromDb(groupId, &groupType)) != HC_SUCCESS) ||
((result = CheckPermForGroup(GROUP_DISBAND, appId, groupId)) != HC_SUCCESS)) {
((result = CheckGroupExist(osAccountId, groupId)) != HC_SUCCESS) ||
((result = GetGroupTypeFromDb(osAccountId, groupId, &groupType)) != HC_SUCCESS) ||
((result = CheckPermForGroup(osAccountId, GROUP_DISBAND, appId, groupId)) != HC_SUCCESS)) {
return result;
}
BaseGroup *instance = GetGroupInstance(groupType);
@ -243,10 +425,11 @@ static int32_t DeleteGroup(CJson *jsonParams, char **returnJsonStr)
LOGE("The group instance is NULL or its function ptr is NULL!");
return HC_ERR_NULL_PTR;
}
return instance->deleteGroup(jsonParams, returnJsonStr);
return instance->deleteGroup(osAccountId, jsonParams, returnJsonStr);
}
static int32_t AddMemberToPeerToPeerGroup(int64_t requestId, CJson *jsonParams, const DeviceAuthCallback *callback)
static int32_t AddMemberToPeerToPeerGroup(int32_t osAccountId, int64_t requestId, CJson *jsonParams,
const DeviceAuthCallback *callback)
{
if ((jsonParams == NULL) || (callback == NULL)) {
LOGE("The input parameters contains NULL value!");
@ -261,10 +444,11 @@ static int32_t AddMemberToPeerToPeerGroup(int64_t requestId, CJson *jsonParams,
LOGE("The group instance is NULL or its function ptr is NULL!");
return HC_ERR_NULL_PTR;
}
return instance->addMember(requestId, jsonParams, callback);
return instance->addMember(osAccountId, requestId, jsonParams, callback);
}
static int32_t DeleteMemberFromPeerToPeerGroup(int64_t requestId, CJson *jsonParams, const DeviceAuthCallback *callback)
static int32_t DeleteMemberFromPeerToPeerGroup(int32_t osAccountId, int64_t requestId, CJson *jsonParams,
const DeviceAuthCallback *callback)
{
if ((jsonParams == NULL) || (callback == NULL)) {
LOGE("The input parameters contains NULL value!");
@ -279,7 +463,7 @@ static int32_t DeleteMemberFromPeerToPeerGroup(int64_t requestId, CJson *jsonPar
LOGE("The group instance is NULL or its function ptr is NULL!");
return HC_ERR_NULL_PTR;
}
return instance->deleteMember(requestId, jsonParams, callback);
return instance->deleteMember(osAccountId, requestId, jsonParams, callback);
}
static int32_t ProcessBindData(int64_t requestId, CJson *jsonParams, const DeviceAuthCallback *callback)
@ -342,7 +526,8 @@ static int32_t SyncAcrossAccountGroup(const char *appId, const char *userIdHash,
return instance->syncGroup(appId, userIdHash, deviceId, sharedUserIdHashList);
}
static int32_t AddGroupRoleWithCheck(bool isManager, const char *appId, const char *groupId, const char *roleAppId)
static int32_t AddGroupRoleWithCheck(int32_t osAccuntId, bool isManager, const char *appId, const char *groupId,
const char *roleAppId)
{
if ((appId == NULL) || (groupId == NULL) || (roleAppId == NULL)) {
LOGE("The input parameters contains NULL value!");
@ -357,10 +542,11 @@ static int32_t AddGroupRoleWithCheck(bool isManager, const char *appId, const ch
LOGE("The group instance is NULL or its function ptr is NULL!");
return HC_ERR_NULL_PTR;
}
return instance->addGroupRole(isManager, appId, groupId, roleAppId);
return instance->addGroupRole(osAccuntId, isManager, appId, groupId, roleAppId);
}
static int32_t DeleteGroupRoleWithCheck(bool isManager, const char *appId, const char *groupId, const char *roleAppId)
static int32_t DeleteGroupRoleWithCheck(int32_t osAccuntId, bool isManager, const char *appId, const char *groupId,
const char *roleAppId)
{
if ((appId == NULL) || (groupId == NULL) || (roleAppId == NULL)) {
LOGE("The input parameters contains NULL value!");
@ -375,11 +561,11 @@ static int32_t DeleteGroupRoleWithCheck(bool isManager, const char *appId, const
LOGE("The group instance is NULL or its function ptr is NULL!");
return HC_ERR_NULL_PTR;
}
return instance->deleteGroupRole(isManager, appId, groupId, roleAppId);
return instance->deleteGroupRole(osAccuntId, isManager, appId, groupId, roleAppId);
}
static int32_t GetGroupRolesWithCheck(bool isManager, const char *appId, const char *groupId, char **returnJsonStr,
uint32_t *returnSize)
static int32_t GetGroupRolesWithCheck(int32_t osAccuntId, bool isManager, const char *appId, const char *groupId,
char **returnJsonStr, uint32_t *returnSize)
{
if ((appId == NULL) || (groupId == NULL) || (returnJsonStr == NULL) || (returnSize == NULL)) {
LOGE("The input parameters contains NULL value!");
@ -394,7 +580,7 @@ static int32_t GetGroupRolesWithCheck(bool isManager, const char *appId, const c
LOGE("The group instance is NULL or its function ptr is NULL!");
return HC_ERR_NULL_PTR;
}
return instance->getGroupRoles(isManager, appId, groupId, returnJsonStr, returnSize);
return instance->getGroupRoles(osAccuntId, isManager, appId, groupId, returnJsonStr, returnSize);
}
static int32_t GetOpCodeWhenAdd(const CJson *jsonParams)
@ -414,7 +600,7 @@ static void DoCreateGroup(HcTaskBase *baseTask)
GroupManagerTask *task = (GroupManagerTask *)baseTask;
LOGI("[Start]: DoCreateGroup! [ReqId]: %" PRId64, task->reqId);
char *returnJsonStr = NULL;
int32_t result = CreateGroup(task->params, &returnJsonStr);
int32_t result = CreateGroup(task->osAccountId, task->params, &returnJsonStr);
if (result != HC_SUCCESS) {
ProcessErrorCallback(task->reqId, GROUP_CREATE, result, NULL, task->cb);
} else {
@ -432,7 +618,7 @@ static void DoDeleteGroup(HcTaskBase *baseTask)
GroupManagerTask *task = (GroupManagerTask *)baseTask;
LOGI("[Start]: DoDeleteGroup! [ReqId]: %" PRId64, task->reqId);
char *returnJsonStr = NULL;
int32_t result = DeleteGroup(task->params, &returnJsonStr);
int32_t result = DeleteGroup(task->osAccountId, task->params, &returnJsonStr);
if (result != HC_SUCCESS) {
ProcessErrorCallback(task->reqId, GROUP_DISBAND, result, NULL, task->cb);
} else {
@ -449,7 +635,7 @@ static void DoAddMember(HcTaskBase *baseTask)
}
GroupManagerTask *task = (GroupManagerTask *)baseTask;
LOGI("[Start]: DoAddMember! [ReqId]: %" PRId64, task->reqId);
(void)AddMemberToPeerToPeerGroup(task->reqId, task->params, task->cb);
(void)AddMemberToPeerToPeerGroup(task->osAccountId, task->reqId, task->params, task->cb);
}
static void DoDeleteMember(HcTaskBase *baseTask)
@ -460,7 +646,7 @@ static void DoDeleteMember(HcTaskBase *baseTask)
}
GroupManagerTask *task = (GroupManagerTask *)baseTask;
LOGI("[Start]: DoDeleteMember! [ReqId]: %" PRId64, task->reqId);
(void)DeleteMemberFromPeerToPeerGroup(task->reqId, task->params, task->cb);
(void)DeleteMemberFromPeerToPeerGroup(task->osAccountId, task->reqId, task->params, task->cb);
}
static void DoProcessBindData(HcTaskBase *baseTask)
@ -496,10 +682,11 @@ static void DoConfirmRequest(HcTaskBase *baseTask)
OnConfirmed(task->reqId, task->params);
}
static int32_t RequestCreateGroup(int64_t requestId, const char *appId, const char *createParams)
static int32_t RequestCreateGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams)
{
if ((appId == NULL) || (createParams == NULL)) {
LOGE("The input parameters contains NULL value!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (createParams == NULL) || (osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: RequestCreateGroup! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
@ -513,7 +700,7 @@ static int32_t RequestCreateGroup(int64_t requestId, const char *appId, const ch
FreeJson(params);
return result;
}
if (InitAndPushGMTask(GROUP_CREATE, requestId, params, DoCreateGroup) != HC_SUCCESS) {
if (InitAndPushGMTask(osAccountId, GROUP_CREATE, requestId, params, DoCreateGroup) != HC_SUCCESS) {
FreeJson(params);
return HC_ERR_INIT_TASK_FAIL;
}
@ -521,10 +708,11 @@ static int32_t RequestCreateGroup(int64_t requestId, const char *appId, const ch
return HC_SUCCESS;
}
static int32_t RequestDeleteGroup(int64_t requestId, const char *appId, const char *disbandParams)
static int32_t RequestDeleteGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *disbandParams)
{
if ((appId == NULL) || (disbandParams == NULL)) {
LOGE("The input parameters contains NULL value!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (disbandParams == NULL) || (osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: RequestDeleteGroup! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
@ -538,7 +726,7 @@ static int32_t RequestDeleteGroup(int64_t requestId, const char *appId, const ch
FreeJson(params);
return result;
}
if (InitAndPushGMTask(GROUP_DISBAND, requestId, params, DoDeleteGroup) != HC_SUCCESS) {
if (InitAndPushGMTask(osAccountId, GROUP_DISBAND, requestId, params, DoDeleteGroup) != HC_SUCCESS) {
FreeJson(params);
return HC_ERR_INIT_TASK_FAIL;
}
@ -546,10 +734,11 @@ static int32_t RequestDeleteGroup(int64_t requestId, const char *appId, const ch
return HC_SUCCESS;
}
static int32_t RequestAddMemberToGroup(int64_t requestId, const char *appId, const char *addParams)
static int32_t RequestAddMemberToGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams)
{
if ((appId == NULL) || (addParams == NULL)) {
LOGE("The input parameters contains NULL value!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (addParams == NULL) || (osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: RequestAddMemberToGroup! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
@ -564,7 +753,7 @@ static int32_t RequestAddMemberToGroup(int64_t requestId, const char *appId, con
FreeJson(params);
return result;
}
if (InitAndPushGMTask(opCode, requestId, params, DoAddMember) != HC_SUCCESS) {
if (InitAndPushGMTask(osAccountId, opCode, requestId, params, DoAddMember) != HC_SUCCESS) {
FreeJson(params);
return HC_ERR_INIT_TASK_FAIL;
}
@ -572,10 +761,12 @@ static int32_t RequestAddMemberToGroup(int64_t requestId, const char *appId, con
return HC_SUCCESS;
}
static int32_t RequestDeleteMemberFromGroup(int64_t requestId, const char *appId, const char *deleteParams)
static int32_t RequestDeleteMemberFromGroup(int32_t osAccountId, int64_t requestId, const char *appId,
const char *deleteParams)
{
if ((appId == NULL) || (deleteParams == NULL)) {
LOGE("The input parameters contains NULL value!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (deleteParams == NULL) || (osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: RequestDeleteMemberFromGroup! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
@ -589,7 +780,7 @@ static int32_t RequestDeleteMemberFromGroup(int64_t requestId, const char *appId
FreeJson(params);
return result;
}
if (InitAndPushGMTask(MEMBER_DELETE, requestId, params, DoDeleteMember) != HC_SUCCESS) {
if (InitAndPushGMTask(osAccountId, MEMBER_DELETE, requestId, params, DoDeleteMember) != HC_SUCCESS) {
FreeJson(params);
return HC_ERR_INIT_TASK_FAIL;
}
@ -620,7 +811,7 @@ static int32_t RequestProcessBindData(int64_t requestId, const uint8_t *data, ui
FreeJson(params);
return HC_ERR_INVALID_PARAMS;
}
if (InitAndPushGMTask(CODE_NULL, requestId, params, DoProcessBindData) != HC_SUCCESS) {
if (InitAndPushGMTask(INVALID_OS_ACCOUNT, CODE_NULL, requestId, params, DoProcessBindData) != HC_SUCCESS) {
FreeJson(params);
return HC_ERR_INIT_TASK_FAIL;
}
@ -628,10 +819,12 @@ static int32_t RequestProcessBindData(int64_t requestId, const uint8_t *data, ui
return HC_SUCCESS;
}
static int32_t RequestConfirmRequest(int64_t requestId, const char *appId, const char *confirmParams)
static int32_t RequestConfirmRequest(int32_t osAccountId, int64_t requestId, const char *appId,
const char *confirmParams)
{
if ((appId == NULL) || (confirmParams == NULL)) {
LOGE("The input parameters contains NULL value!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (confirmParams == NULL) || (osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: RequestConfirmRequest! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
@ -645,7 +838,7 @@ static int32_t RequestConfirmRequest(int64_t requestId, const char *appId, const
FreeJson(params);
return HC_ERR_JSON_FAIL;
}
if (InitAndPushGMTask(CODE_NULL, requestId, params, DoConfirmRequest) != HC_SUCCESS) {
if (InitAndPushGMTask(osAccountId, CODE_NULL, requestId, params, DoConfirmRequest) != HC_SUCCESS) {
FreeJson(params);
return HC_ERR_INIT_TASK_FAIL;
}
@ -679,51 +872,54 @@ static int32_t UnRegListener(const char *appId)
return RemoveListener(appId);
}
static int32_t CheckAccessToGroup(const char *appId, const char *groupId)
static int32_t CheckAccessToGroup(int32_t osAccountId, const char *appId, const char *groupId)
{
if ((appId == NULL) || (groupId == NULL)) {
LOGE("The input parameters contains NULL value!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (groupId == NULL) || (osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
return HC_ERR_INVALID_PARAMS;
}
if (!IsGroupAccessible(groupId, appId)) {
if (!IsGroupAccessible(osAccountId, groupId, appId)) {
LOGE("You do not have the permission to query the group information!");
return HC_ERR_ACCESS_DENIED;
}
return HC_SUCCESS;
}
static int32_t GetAccessibleGroupInfoById(const char *appId, const char *groupId, char **returnGroupInfo)
static int32_t GetAccessibleGroupInfoById(int32_t osAccountId, const char *appId, const char *groupId,
char **returnGroupInfo)
{
if ((appId == NULL) || (groupId == NULL) || (returnGroupInfo == NULL)) {
LOGE("The input parameters contains NULL value!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (groupId == NULL) || (returnGroupInfo == NULL) || (osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
return HC_ERR_INVALID_PARAMS;
}
if (!IsGroupExistByGroupId(groupId)) {
if (!IsGroupExistByGroupId(osAccountId, groupId)) {
LOGE("No group is found based on the query parameters!");
return HC_ERR_GROUP_NOT_EXIST;
}
if (!IsGroupAccessible(groupId, appId)) {
if (!IsGroupAccessible(osAccountId, groupId, appId)) {
LOGE("You do not have the permission to query the group information!");
return HC_ERR_ACCESS_DENIED;
}
GroupInfo *groupInfo = CreateGroupInfoStruct();
TrustedGroupEntry *groupInfo = CreateGroupEntry();
if (groupInfo == NULL) {
LOGE("Failed to allocate groupInfo memory!");
return HC_ERR_ALLOC_MEMORY;
}
if (GetGroupInfoById(groupId, groupInfo) != HC_SUCCESS) {
if (GetGroupInfoById(osAccountId, groupId, groupInfo) != HC_SUCCESS) {
LOGE("Failed to obtain the group information from the database!");
DestroyGroupInfoStruct(groupInfo);
DestroyGroupEntry(groupInfo);
return HC_ERR_DB;
}
CJson *groupInfoJson = CreateJson();
if (groupInfoJson == NULL) {
LOGE("Failed to allocate groupInfoJson memory!");
DestroyGroupInfoStruct(groupInfo);
DestroyGroupEntry(groupInfo);
return HC_ERR_JSON_FAIL;
}
int32_t result = GenerateReturnGroupInfo(groupInfo, groupInfoJson);
DestroyGroupInfoStruct(groupInfo);
DestroyGroupEntry(groupInfo);
if (result != HC_SUCCESS) {
FreeJson(groupInfoJson);
return result;
@ -737,11 +933,13 @@ static int32_t GetAccessibleGroupInfoById(const char *appId, const char *groupId
return HC_SUCCESS;
}
static int32_t GetAccessibleGroupInfo(const char *appId, const char *queryParams, char **returnGroupVec,
uint32_t *groupNum)
static int32_t GetAccessibleGroupInfo(int32_t osAccountId, const char *appId, const char *queryParams,
char **returnGroupVec, uint32_t *groupNum)
{
if ((appId == NULL) || (queryParams == NULL) || (returnGroupVec == NULL) || (groupNum == NULL)) {
LOGE("The input parameters contains NULL value!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (queryParams == NULL) || (returnGroupVec == NULL) || (groupNum == NULL) ||
(osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
return HC_ERR_INVALID_PARAMS;
}
CJson *queryParamsJson = CreateJsonFromString(queryParams);
@ -764,97 +962,100 @@ static int32_t GetAccessibleGroupInfo(const char *appId, const char *queryParams
FreeJson(queryParamsJson);
return HC_ERR_INVALID_PARAMS;
}
GroupInfoVec groupInfoVec;
CreateGroupInfoVecStruct(&groupInfoVec);
int32_t result = GetGroupInfo(groupType, groupId, groupName, groupOwner, &groupInfoVec);
GroupEntryVec groupEntryVec = CreateGroupEntryVec();
int32_t result = GetGroupInfo(osAccountId, groupType, groupId, groupName, groupOwner, &groupEntryVec);
FreeJson(queryParamsJson);
if (result != HC_SUCCESS) {
DestroyGroupInfoVecStruct(&groupInfoVec);
ClearGroupEntryVec(&groupEntryVec);
return result;
}
RemoveNoPermissionGroup(&groupInfoVec, appId);
result = GenerateReturnGroupVec(&groupInfoVec, returnGroupVec, groupNum);
DestroyGroupInfoVecStruct(&groupInfoVec);
RemoveNoPermissionGroup(osAccountId, &groupEntryVec, appId);
result = GenerateReturnGroupVec(&groupEntryVec, returnGroupVec, groupNum);
ClearGroupEntryVec(&groupEntryVec);
return result;
}
static int32_t GetAccessibleJoinedGroups(const char *appId, int groupType, char **returnGroupVec, uint32_t *groupNum)
static int32_t GetAccessibleJoinedGroups(int32_t osAccountId, const char *appId, int groupType,
char **returnGroupVec, uint32_t *groupNum)
{
if ((appId == NULL) || (returnGroupVec == NULL) || (groupNum == NULL)) {
LOGE("The input parameters contains NULL value!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (returnGroupVec == NULL) || (groupNum == NULL) || (osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
return HC_ERR_INVALID_PARAMS;
}
if (!IsGroupTypeSupported(groupType)) {
LOGE("Invalid group type!");
return HC_ERR_INVALID_PARAMS;
}
GroupInfoVec groupInfoVec;
CreateGroupInfoVecStruct(&groupInfoVec);
int32_t result = GetJoinedGroups(groupType, &groupInfoVec);
GroupEntryVec groupEntryVec = CreateGroupEntryVec();
int32_t result = GetJoinedGroups(osAccountId, groupType, &groupEntryVec);
if (result != HC_SUCCESS) {
DestroyGroupInfoVecStruct(&groupInfoVec);
ClearGroupEntryVec(&groupEntryVec);
return result;
}
RemoveNoPermissionGroup(&groupInfoVec, appId);
result = GenerateReturnGroupVec(&groupInfoVec, returnGroupVec, groupNum);
DestroyGroupInfoVecStruct(&groupInfoVec);
RemoveNoPermissionGroup(osAccountId, &groupEntryVec, appId);
result = GenerateReturnGroupVec(&groupEntryVec, returnGroupVec, groupNum);
ClearGroupEntryVec(&groupEntryVec);
return result;
}
static int32_t GetAccessibleRelatedGroups(const char *appId, const char *peerDeviceId, bool isUdid,
static int32_t GetAccessibleRelatedGroups(int32_t osAccountId, const char *appId, const char *peerDeviceId, bool isUdid,
char **returnGroupVec, uint32_t *groupNum)
{
if ((appId == NULL) || (peerDeviceId == NULL) || (returnGroupVec == NULL) || (groupNum == NULL)) {
LOGE("The input parameters contains NULL value!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (peerDeviceId == NULL) || (returnGroupVec == NULL) || (groupNum == NULL) ||
(osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("Start to get related groups! [AppId]: %s", appId);
GroupInfoVec groupInfoVec;
CreateGroupInfoVecStruct(&groupInfoVec);
int32_t result = GetRelatedGroups(peerDeviceId, isUdid, &groupInfoVec);
GroupEntryVec groupEntryVec = CreateGroupEntryVec();
int32_t result = GetRelatedGroups(osAccountId, peerDeviceId, isUdid, &groupEntryVec);
if (result != HC_SUCCESS) {
DestroyGroupInfoVecStruct(&groupInfoVec);
ClearGroupEntryVec(&groupEntryVec);
return result;
}
RemoveNoPermissionGroup(&groupInfoVec, appId);
result = GenerateReturnGroupVec(&groupInfoVec, returnGroupVec, groupNum);
DestroyGroupInfoVecStruct(&groupInfoVec);
RemoveNoPermissionGroup(osAccountId, &groupEntryVec, appId);
result = GenerateReturnGroupVec(&groupEntryVec, returnGroupVec, groupNum);
ClearGroupEntryVec(&groupEntryVec);
return result;
}
static int32_t GetAccessibleDeviceInfoById(const char *appId, const char *deviceId, bool isUdid,
static int32_t GetAccessibleDeviceInfoById(int32_t osAccountId, const char *appId, const char *deviceId, bool isUdid,
const char *groupId, char **returnDeviceInfo)
{
if ((appId == NULL) || (deviceId == NULL) || (groupId == NULL) || (returnDeviceInfo == NULL)) {
LOGE("The input parameters contains NULL value!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (deviceId == NULL) || (groupId == NULL) || (returnDeviceInfo == NULL) ||
(osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
return HC_ERR_INVALID_PARAMS;
}
if (!IsGroupExistByGroupId(groupId)) {
if (!IsGroupExistByGroupId(osAccountId, groupId)) {
LOGE("No group is found based on the query parameters!");
return HC_ERR_GROUP_NOT_EXIST;
}
if (!IsGroupAccessible(groupId, appId)) {
if (!IsGroupAccessible(osAccountId, groupId, appId)) {
LOGE("You do not have the permission to query the group information!");
return HC_ERR_ACCESS_DENIED;
}
DeviceInfo *devInfo = CreateDeviceInfoStruct();
if (devInfo == NULL) {
LOGE("Failed to allocate devInfo memory!");
TrustedDeviceEntry *deviceEntry = CreateDeviceEntry();
if (deviceEntry == NULL) {
LOGE("Failed to allocate deviceEntry memory!");
return HC_ERR_ALLOC_MEMORY;
}
if (GetTrustedDevInfoById(deviceId, isUdid, groupId, devInfo) != HC_SUCCESS) {
if (GetTrustedDevInfoById(osAccountId, deviceId, isUdid, groupId, deviceEntry) != HC_SUCCESS) {
LOGE("No device is found based on the query parameters!");
DestroyDeviceInfoStruct(devInfo);
DestroyDeviceEntry(deviceEntry);
return HC_ERR_DEVICE_NOT_EXIST;
}
CJson *devInfoJson = CreateJson();
if (devInfoJson == NULL) {
LOGE("Failed to allocate devInfoJson memory!");
DestroyDeviceInfoStruct(devInfo);
DestroyDeviceEntry(deviceEntry);
return HC_ERR_JSON_FAIL;
}
int32_t result = GenerateReturnDevInfo(devInfo, devInfoJson);
DestroyDeviceInfoStruct(devInfo);
int32_t result = GenerateReturnDevInfo(deviceEntry, devInfoJson);
DestroyDeviceEntry(deviceEntry);
if (result != HC_SUCCESS) {
FreeJson(devInfoJson);
return result;
@ -868,48 +1069,91 @@ static int32_t GetAccessibleDeviceInfoById(const char *appId, const char *device
return HC_SUCCESS;
}
static int32_t GetAccessibleTrustedDevices(const char *appId, const char *groupId,
static int32_t GetAccessibleTrustedDevices(int32_t osAccountId, const char *appId, const char *groupId,
char **returnDevInfoVec, uint32_t *deviceNum)
{
if ((appId == NULL) || (groupId == NULL) || (returnDevInfoVec == NULL) || (deviceNum == NULL)) {
LOGE("The input parameters contains NULL value!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (groupId == NULL) || (returnDevInfoVec == NULL) || (deviceNum == NULL) ||
(osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
return HC_ERR_INVALID_PARAMS;
}
if (!IsGroupExistByGroupId(groupId)) {
if (!IsGroupExistByGroupId(osAccountId, groupId)) {
LOGE("No group is found based on the query parameters!");
return HC_ERR_GROUP_NOT_EXIST;
}
if (!IsGroupAccessible(groupId, appId)) {
if (!IsGroupAccessible(osAccountId, groupId, appId)) {
LOGE("You do not have the permission to query the group information!");
return HC_ERR_ACCESS_DENIED;
}
DeviceInfoVec deviceInfoVec;
CreateDeviceInfoVecStruct(&deviceInfoVec);
int32_t result = GetTrustedDevices(groupId, &deviceInfoVec);
DeviceEntryVec deviceEntryVec = CreateDeviceEntryVec();
int32_t result = GetTrustedDevices(osAccountId, groupId, &deviceEntryVec);
if (result != HC_SUCCESS) {
DestroyDeviceInfoVecStruct(&deviceInfoVec);
ClearDeviceEntryVec(&deviceEntryVec);
return result;
}
result = GenerateReturnDeviceVec(&deviceInfoVec, returnDevInfoVec, deviceNum);
DestroyDeviceInfoVecStruct(&deviceInfoVec);
result = GenerateReturnDeviceVec(&deviceEntryVec, returnDevInfoVec, deviceNum);
ClearDeviceEntryVec(&deviceEntryVec);
return result;
}
static bool IsDeviceInAccessibleGroup(const char *appId, const char *groupId, const char *deviceId, bool isUdid)
static bool IsDeviceInAccessibleGroup(int32_t osAccountId, const char *appId, const char *groupId,
const char *deviceId, bool isUdid)
{
if ((appId == NULL) || (groupId == NULL) || (deviceId == NULL)) {
LOGE("The input parameters contains NULL value!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (groupId == NULL) || (deviceId == NULL) || (osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
return false;
}
if (!IsGroupExistByGroupId(groupId)) {
if (!IsGroupExistByGroupId(osAccountId, groupId)) {
LOGE("No group is found based on the query parameters!");
return false;
}
if (!IsGroupAccessible(groupId, appId)) {
if (!IsGroupAccessible(osAccountId, groupId, appId)) {
LOGE("You do not have the permission to query the group information!");
return false;
}
return IsTrustedDeviceInGroup(groupId, deviceId, isUdid);
return IsTrustedDeviceInGroup(osAccountId, groupId, deviceId, isUdid);
}
static int32_t GetPkInfoList(int32_t osAccountId, const char *appId, const char *queryParams,
char **returnInfoList, uint32_t *returnInfoNum)
{
LOGI("[Start]: start to get pk list!");
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if ((appId == NULL) || (queryParams == NULL) || (returnInfoList == NULL) ||
(returnInfoNum == NULL) || (osAccountId == INVALID_OS_ACCOUNT)) {
LOGE("Invalid input parameters!");
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(osAccountId, 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 void DestroyInfo(char **returnInfo)
@ -943,6 +1187,7 @@ static const GroupImpl g_groupImplInstance = {
.getAccessibleDeviceInfoById = GetAccessibleDeviceInfoById,
.getAccessibleTrustedDevices = GetAccessibleTrustedDevices,
.isDeviceInAccessibleGroup = IsDeviceInAccessibleGroup,
.getPkInfoList = GetPkInfoList,
.destroyInfo = DestroyInfo
};
@ -954,15 +1199,11 @@ int32_t InitGroupRelatedModule(void)
return HC_ERR_SERVICE_NEED_RESTART;
}
}
if (IsAcrossAccountGroupSupported()) {
RegGenerateGroupIdFunc(((AcrossAccountGroup *)GetAcrossAccountGroupInstance())->generateGroupId);
}
return HC_SUCCESS;
}
void DestroyGroupRelatedModule(void)
{
DeregGenerateGroupIdFunc();
DestroyBroadcastManager();
}

View File

@ -17,14 +17,339 @@
#include "alg_loader.h"
#include "string_util.h"
#include "database_manager.h"
#include "common_defs.h"
#include "data_manager.h"
#include "dev_auth_module_manager.h"
#include "device_auth_defines.h"
#include "group_operation.h"
#include "hal_error.h"
#include "hc_dev_info.h"
#include "hc_log.h"
static int32_t AddGroupNameToReturn(const GroupInfo *groupInfo, CJson *json)
static bool IsGroupManager(const char *appId, const TrustedGroupEntry *entry)
{
uint32_t index;
HcString *manager = NULL;
FOR_EACH_HC_VECTOR(entry->managers, index, manager) {
if (strcmp(StringGet(manager), appId) == 0) {
return true;
}
}
return false;
}
static bool IsGroupFriend(const char *appId, const TrustedGroupEntry *entry)
{
uint32_t index;
HcString *trustedFriend = NULL;
FOR_EACH_HC_VECTOR(entry->friends, index, trustedFriend) {
if (strcmp(StringGet(trustedFriend), appId) == 0) {
return true;
}
}
return false;
}
static int32_t GetGroupNumByOwner(int32_t osAccountId, const char *ownerName)
{
if (ownerName == NULL) {
LOGE("The input ownerName is NULL!");
return 0;
}
int count = 0;
QueryGroupParams queryParams = InitQueryGroupParams();
queryParams.ownerName = ownerName;
GroupEntryVec groupEntryVec = CreateGroupEntryVec();
int32_t result = QueryGroups(osAccountId, &queryParams, &groupEntryVec);
if (result != HC_SUCCESS) {
LOGE("Failed to query groups!");
ClearGroupEntryVec(&groupEntryVec);
return count;
}
count = HC_VECTOR_SIZE(&groupEntryVec);
ClearGroupEntryVec(&groupEntryVec);
return count;
}
TrustedDeviceEntry *GetTrustedDeviceEntryById(int32_t osAccountId, const char *deviceId, bool isUdid,
const char *groupId)
{
uint32_t index;
TrustedDeviceEntry **deviceEntry = NULL;
DeviceEntryVec deviceEntryVec = CreateDeviceEntryVec();
QueryDeviceParams params = InitQueryDeviceParams();
params.groupId = groupId;
if (isUdid) {
params.udid = deviceId;
} else {
params.authId = deviceId;
}
if (QueryDevices(osAccountId, &params, &deviceEntryVec) != HC_SUCCESS) {
LOGE("Failed to query trusted devices!");
ClearDeviceEntryVec(&deviceEntryVec);
return NULL;
}
FOR_EACH_HC_VECTOR(deviceEntryVec, index, deviceEntry) {
if ((deviceEntry != NULL) && (*deviceEntry != NULL)) {
TrustedDeviceEntry *returnEntry = DeepCopyDeviceEntry(*deviceEntry);
ClearDeviceEntryVec(&deviceEntryVec);
return returnEntry;
}
}
ClearDeviceEntryVec(&deviceEntryVec);
return NULL;
}
TrustedGroupEntry *GetGroupEntryById(int32_t osAccountId, const char *groupId)
{
if (groupId == NULL) {
LOGE("The input groupId is NULL!");
return NULL;
}
uint32_t index;
TrustedGroupEntry **entry = NULL;
GroupEntryVec groupEntryVec = CreateGroupEntryVec();
QueryGroupParams params = InitQueryGroupParams();
params.groupId = groupId;
if (QueryGroups(osAccountId, &params, &groupEntryVec) != HC_SUCCESS) {
LOGE("Failed to query groups!");
ClearGroupEntryVec(&groupEntryVec);
return NULL;
}
FOR_EACH_HC_VECTOR(groupEntryVec, index, entry) {
if ((entry != NULL) && (*entry != NULL)) {
TrustedGroupEntry *returnEntry = DeepCopyGroupEntry(*entry);
ClearGroupEntryVec(&groupEntryVec);
return returnEntry;
}
}
ClearGroupEntryVec(&groupEntryVec);
return NULL;
}
bool IsTrustedDeviceInGroup(int32_t osAccountId, const char *groupId, const char *deviceId, bool isUdid)
{
if ((groupId == NULL) || (deviceId == NULL)) {
LOGE("The input groupId or deviceId is NULL!");
return false;
}
TrustedDeviceEntry *entry = GetTrustedDeviceEntryById(osAccountId, deviceId, isUdid, groupId);
if (entry == NULL) {
return false;
}
DestroyDeviceEntry(entry);
return true;
}
int32_t GetGroupInfoById(int32_t osAccountId, const char *groupId, TrustedGroupEntry *returnGroupEntry)
{
if ((groupId == NULL) || (returnGroupEntry == NULL)) {
LOGE("The input groupId or returnGroupEntry is NULL!");
return HC_ERR_INVALID_PARAMS;
}
int32_t result;
uint32_t index;
TrustedGroupEntry **entry = NULL;
GroupEntryVec groupEntryVec = CreateGroupEntryVec();
QueryGroupParams params = InitQueryGroupParams();
params.groupId = groupId;
result = QueryGroups(osAccountId, &params, &groupEntryVec);
if (result != HC_SUCCESS) {
LOGE("Failed to query groups!");
ClearGroupEntryVec(&groupEntryVec);
return result;
}
FOR_EACH_HC_VECTOR(groupEntryVec, index, entry) {
if ((entry == NULL) || (*entry == NULL)) {
continue;
}
result = GenerateGroupEntryFromEntry(*entry, returnGroupEntry) ? HC_SUCCESS : HC_ERR_MEMORY_COPY;
ClearGroupEntryVec(&groupEntryVec);
return result;
}
ClearGroupEntryVec(&groupEntryVec);
return HC_ERR_GROUP_NOT_EXIST;
}
bool IsGroupAccessible(int32_t osAccountId, const char *groupId, const char *appId)
{
if ((groupId == NULL) || (appId == NULL)) {
LOGE("The input groupId or appId is NULL!");
return false;
}
TrustedGroupEntry *entry = GetGroupEntryById(osAccountId, groupId);
if (entry == NULL) {
LOGE("The group cannot be found!");
return false;
}
if ((entry->visibility == GROUP_VISIBILITY_PUBLIC) ||
(IsGroupManager(appId, entry)) ||
(IsGroupFriend(appId, entry))) {
DestroyGroupEntry(entry);
return true;
}
DestroyGroupEntry(entry);
return false;
}
int32_t CheckGroupNumLimit(int32_t osAccountId, int32_t groupType, const char *appId)
{
/* Currently, only peer to peer group is supported. */
(void)groupType;
if (GetGroupNumByOwner(osAccountId, appId) >= HC_TRUST_GROUP_ENTRY_MAX_NUM) {
LOGE("The number of groups created by the service exceeds the maximum!");
return HC_ERR_BEYOND_LIMIT;
}
return HC_SUCCESS;
}
bool IsGroupOwner(int32_t osAccountId, const char *groupId, const char *appId)
{
if ((groupId == NULL) || (appId == NULL)) {
LOGE("The input groupId or appId is NULL!");
return false;
}
TrustedGroupEntry *entry = GetGroupEntryById(osAccountId, groupId);
if (entry == NULL) {
LOGE("The group cannot be found!");
return false;
}
if (HC_VECTOR_SIZE(&entry->managers) <= 0) {
LOGE("The group does not have manager and owner!");
DestroyGroupEntry(entry);
return false;
}
HcString entryManager = HC_VECTOR_GET(&entry->managers, 0);
const char *groupOwner = StringGet(&entryManager);
if ((groupOwner != NULL) && strcmp(groupOwner, appId) == 0) {
DestroyGroupEntry(entry);
return true;
}
DestroyGroupEntry(entry);
return false;
}
bool IsGroupExistByGroupId(int32_t osAccountId, const char *groupId)
{
if (groupId == NULL) {
LOGE("The input groupId is NULL!");
return false;
}
TrustedGroupEntry *entry = GetGroupEntryById(osAccountId, groupId);
if (entry == NULL) {
LOGE("The group cannot be found!");
return false;
}
DestroyGroupEntry(entry);
return true;
}
bool IsGroupEditAllowed(int32_t osAccountId, const char *groupId, const char *appId)
{
if ((groupId == NULL) || (appId == NULL)) {
LOGE("The input groupId or appId is NULL!");
return false;
}
TrustedGroupEntry *entry = GetGroupEntryById(osAccountId, groupId);
if (entry == NULL) {
LOGE("The group cannot be found!");
return false;
}
if (IsGroupManager(appId, entry)) {
DestroyGroupEntry(entry);
return true;
}
DestroyGroupEntry(entry);
return false;
}
int32_t GetGroupInfo(int32_t osAccountId, int groupType, const char *groupId, const char *groupName,
const char *groupOwner, GroupEntryVec *returnGroupEntryVec)
{
/* Fuzzy query interfaces, so some parameters can be NULL. */
if (returnGroupEntryVec == NULL) {
LOGE("The input returnGroupEntryVec is NULL!");
return HC_ERR_INVALID_PARAMS;
}
QueryGroupParams params = InitQueryGroupParams();
params.groupId = groupId;
params.groupName = groupName;
params.ownerName = groupOwner;
params.groupType = groupType;
return QueryGroups(osAccountId, &params, returnGroupEntryVec);
}
int32_t GetJoinedGroups(int32_t osAccountId, int groupType, GroupEntryVec *returnGroupEntryVec)
{
QueryGroupParams params = InitQueryGroupParams();
params.groupType = groupType;
return QueryGroups(osAccountId, &params, returnGroupEntryVec);
}
int32_t GetRelatedGroups(int32_t osAccountId, const char *peerDeviceId, bool isUdid, GroupEntryVec *returnGroupEntryVec)
{
uint32_t index;
TrustedDeviceEntry **entry = NULL;
DeviceEntryVec deviceEntryVec = CreateDeviceEntryVec();
QueryDeviceParams params = InitQueryDeviceParams();
params.groupId = NULL;
if (isUdid) {
params.udid = peerDeviceId;
} else {
params.authId = peerDeviceId;
}
int32_t result = QueryDevices(osAccountId, &params, &deviceEntryVec);
if (result != HC_SUCCESS) {
LOGE("Failed to query trusted devices!");
ClearDeviceEntryVec(&deviceEntryVec);
return result;
}
FOR_EACH_HC_VECTOR(deviceEntryVec, index, entry) {
if ((entry == NULL) || (*entry == NULL)) {
continue;
}
TrustedGroupEntry *groupEntry = GetGroupEntryById(osAccountId, StringGet(&(*entry)->groupId));
if (groupEntry == NULL) {
LOGE("Failed to get group entry by id!");
ClearDeviceEntryVec(&deviceEntryVec);
return HC_ERR_GROUP_NOT_EXIST;
}
if (returnGroupEntryVec->pushBackT(returnGroupEntryVec, groupEntry) == NULL) {
DestroyGroupEntry(groupEntry);
ClearDeviceEntryVec(&deviceEntryVec);
return HC_ERR_MEMORY_COPY;
}
}
ClearDeviceEntryVec(&deviceEntryVec);
return HC_SUCCESS;
}
int32_t GetTrustedDevInfoById(int32_t osAccountId, const char *deviceId, bool isUdid, const char *groupId,
TrustedDeviceEntry *returnDeviceEntry)
{
if ((deviceId == NULL) || (groupId == NULL) || (returnDeviceEntry == NULL)) {
LOGE("The input parameters contain NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("Start to get device information of a specified group!");
TrustedDeviceEntry *deviceEntry = GetTrustedDeviceEntryById(osAccountId, deviceId, isUdid, groupId);
if (deviceEntry == NULL) {
LOGE("The trusted device is not found!");
return HC_ERR_DEVICE_NOT_EXIST;
}
int32_t result = GenerateDeviceEntryFromEntry(deviceEntry, returnDeviceEntry) ? HC_SUCCESS : HC_ERR_MEMORY_COPY;
DestroyDeviceEntry(deviceEntry);
return result;
}
int32_t GetTrustedDevices(int32_t osAccountId, const char *groupId, DeviceEntryVec *returnDeviceEntryVec)
{
QueryDeviceParams params = InitQueryDeviceParams();
params.groupId = groupId;
return QueryDevices(osAccountId, &params, returnDeviceEntryVec);
}
static int32_t AddGroupNameToReturn(const TrustedGroupEntry *groupInfo, CJson *json)
{
const char *groupName = StringGet(&groupInfo->name);
if (groupName == NULL) {
@ -38,7 +363,7 @@ static int32_t AddGroupNameToReturn(const GroupInfo *groupInfo, CJson *json)
return HC_SUCCESS;
}
static int32_t AddGroupIdToReturn(const GroupInfo *groupInfo, CJson *json)
static int32_t AddGroupIdToReturn(const TrustedGroupEntry *groupInfo, CJson *json)
{
const char *groupId = StringGet(&groupInfo->id);
if (groupId == NULL) {
@ -52,9 +377,10 @@ static int32_t AddGroupIdToReturn(const GroupInfo *groupInfo, CJson *json)
return HC_SUCCESS;
}
static int32_t AddGroupOwnerToReturn(const GroupInfo *groupInfo, CJson *json)
static int32_t AddGroupOwnerToReturn(const TrustedGroupEntry *groupInfo, CJson *json)
{
const char *groupOwner = StringGet(&groupInfo->ownerName);
HcString entryManager = HC_VECTOR_GET(&groupInfo->managers, 0);
const char *groupOwner = StringGet(&entryManager);
if (groupOwner == NULL) {
LOGE("Failed to get groupOwner from groupInfo!");
return HC_ERR_NULL_PTR;
@ -66,7 +392,7 @@ static int32_t AddGroupOwnerToReturn(const GroupInfo *groupInfo, CJson *json)
return HC_SUCCESS;
}
static int32_t AddGroupTypeToReturn(const GroupInfo *groupInfo, CJson *json)
static int32_t AddGroupTypeToReturn(const TrustedGroupEntry *groupInfo, CJson *json)
{
int32_t groupType = groupInfo->type;
if (AddIntToJson(json, FIELD_GROUP_TYPE, groupType) != HC_SUCCESS) {
@ -76,7 +402,7 @@ static int32_t AddGroupTypeToReturn(const GroupInfo *groupInfo, CJson *json)
return HC_SUCCESS;
}
static int32_t AddGroupVisibilityToReturn(const GroupInfo *groupInfo, CJson *json)
static int32_t AddGroupVisibilityToReturn(const TrustedGroupEntry *groupInfo, CJson *json)
{
int groupVisibility = groupInfo->visibility;
if (AddIntToJson(json, FIELD_GROUP_VISIBILITY, groupVisibility) != HC_SUCCESS) {
@ -86,41 +412,7 @@ static int32_t AddGroupVisibilityToReturn(const GroupInfo *groupInfo, CJson *jso
return HC_SUCCESS;
}
static int32_t AddGroupUserIdHashToReturnIfNeed(const GroupInfo *groupInfo, CJson *json)
{
if (!IsAccountRelatedGroup(groupInfo->type)) {
return HC_SUCCESS;
}
const char *userIdHash = StringGet(&groupInfo->userIdHash);
if (userIdHash == NULL) {
LOGE("Failed to get userIdHash from groupInfo!");
return HC_ERR_NULL_PTR;
}
if (AddStringToJson(json, FIELD_USER_ID, userIdHash) != HC_SUCCESS) {
LOGE("Failed to add userIdHash to json!");
return HC_ERR_JSON_FAIL;
}
return HC_SUCCESS;
}
static int32_t AddGroupSharedUserIdHashToReturnIfNeed(const GroupInfo *groupInfo, CJson *json)
{
if (groupInfo->type != ACROSS_ACCOUNT_AUTHORIZE_GROUP) {
return HC_SUCCESS;
}
const char *sharedUserIdHash = StringGet(&groupInfo->sharedUserIdHash);
if (sharedUserIdHash == NULL) {
LOGE("Failed to get sharedUserIdHash from groupInfo!");
return HC_ERR_NULL_PTR;
}
if (AddStringToJson(json, FIELD_SHARED_USER_ID, sharedUserIdHash) != HC_SUCCESS) {
LOGE("Failed to add sharedUserIdHash to json!");
return HC_ERR_JSON_FAIL;
}
return HC_SUCCESS;
}
static int32_t AddAuthIdToReturn(const DeviceInfo *deviceInfo, CJson *json)
static int32_t AddAuthIdToReturn(const TrustedDeviceEntry *deviceInfo, CJson *json)
{
const char *authId = StringGet(&deviceInfo->authId);
if (authId == NULL) {
@ -134,21 +426,7 @@ static int32_t AddAuthIdToReturn(const DeviceInfo *deviceInfo, CJson *json)
return HC_SUCCESS;
}
static int32_t AddUserIdHashToReturn(const DeviceInfo *deviceInfo, CJson *json)
{
const char *userIdHash = StringGet(&deviceInfo->userIdHash);
if (userIdHash == NULL) {
LOGE("Failed to get userIdHash from deviceInfo!");
return HC_ERR_NULL_PTR;
}
if (AddStringToJson(json, FIELD_USER_ID, userIdHash) != HC_SUCCESS) {
LOGE("Failed to add userIdHash to json!");
return HC_ERR_JSON_FAIL;
}
return HC_SUCCESS;
}
static int32_t AddCredentialTypeToReturn(const DeviceInfo *deviceInfo, CJson *json)
static int32_t AddCredentialTypeToReturn(const TrustedDeviceEntry *deviceInfo, CJson *json)
{
int credentialType = deviceInfo->credential;
if (AddIntToJson(json, FIELD_CREDENTIAL_TYPE, credentialType) != HC_SUCCESS) {
@ -158,7 +436,7 @@ static int32_t AddCredentialTypeToReturn(const DeviceInfo *deviceInfo, CJson *js
return HC_SUCCESS;
}
static int32_t AddUserTypeToReturn(const DeviceInfo *deviceInfo, CJson *json)
static int32_t AddUserTypeToReturn(const TrustedDeviceEntry *deviceInfo, CJson *json)
{
int userType = deviceInfo->devType;
if (AddIntToJson(json, FIELD_USER_TYPE, userType) != HC_SUCCESS) {
@ -173,26 +451,23 @@ bool IsAccountRelatedGroup(int groupType)
return ((groupType == IDENTICAL_ACCOUNT_GROUP) || (groupType == ACROSS_ACCOUNT_AUTHORIZE_GROUP));
}
int32_t GenerateReturnGroupInfo(const GroupInfo *groupInfo, CJson *returnJson)
int32_t GenerateReturnGroupInfo(const TrustedGroupEntry *groupInfo, CJson *returnJson)
{
int32_t result;
if (((result = AddGroupNameToReturn(groupInfo, returnJson)) != HC_SUCCESS) ||
((result = AddGroupIdToReturn(groupInfo, returnJson)) != HC_SUCCESS) ||
((result = AddGroupOwnerToReturn(groupInfo, returnJson)) != HC_SUCCESS) ||
((result = AddGroupTypeToReturn(groupInfo, returnJson)) != HC_SUCCESS) ||
((result = AddGroupVisibilityToReturn(groupInfo, returnJson)) != HC_SUCCESS) ||
((result = AddGroupUserIdHashToReturnIfNeed(groupInfo, returnJson)) != HC_SUCCESS) ||
((result = AddGroupSharedUserIdHashToReturnIfNeed(groupInfo, returnJson)) != HC_SUCCESS)) {
((result = AddGroupVisibilityToReturn(groupInfo, returnJson)) != HC_SUCCESS)) {
return result;
}
return HC_SUCCESS;
}
int32_t GenerateReturnDevInfo(const DeviceInfo *devInfo, CJson *returnJson)
int32_t GenerateReturnDevInfo(const TrustedDeviceEntry *devInfo, CJson *returnJson)
{
int32_t result;
if (((result = AddAuthIdToReturn(devInfo, returnJson)) != HC_SUCCESS) ||
((result = AddUserIdHashToReturn(devInfo, returnJson)) != HC_SUCCESS) ||
((result = AddCredentialTypeToReturn(devInfo, returnJson)) != HC_SUCCESS) ||
((result = AddUserTypeToReturn(devInfo, returnJson)) != HC_SUCCESS)) {
return result;
@ -242,29 +517,38 @@ int32_t GetHashMessage(const Uint8Buff *first, const Uint8Buff *second, uint8_t
return HC_SUCCESS;
}
int32_t CheckGroupNumLimit(int32_t groupType, const char *appId)
int32_t GetCurDeviceNumByGroupId(int32_t osAccountId, const char *groupId)
{
if ((groupType == IDENTICAL_ACCOUNT_GROUP) && (IsIdenticalGroupExist())) {
LOGE("The identical account group already exists!");
return HC_ERR_BEYOND_LIMIT;
if (groupId == NULL) {
LOGE("The input groupId is NULL!");
return 0;
}
if (GetGroupNumByOwner(appId) >= HC_TRUST_GROUP_ENTRY_MAX_NUM) {
LOGE("The number of groups created by the service exceeds the maximum!");
return HC_ERR_BEYOND_LIMIT;
int count = 0;
QueryDeviceParams queryDeviceParams = InitQueryDeviceParams();
queryDeviceParams.groupId = groupId;
DeviceEntryVec deviceEntryVec = CreateDeviceEntryVec();
int32_t result = QueryDevices(osAccountId, &queryDeviceParams, &deviceEntryVec);
if (result != HC_SUCCESS) {
LOGE("Failed to query trusted devices!");
ClearDeviceEntryVec(&deviceEntryVec);
return result;
}
return HC_SUCCESS;
count = HC_VECTOR_SIZE(&deviceEntryVec);
ClearDeviceEntryVec(&deviceEntryVec);
return count;
}
int32_t CheckDeviceNumLimit(const char *groupId, const char *peerUdid)
int32_t CheckDeviceNumLimit(int32_t osAccountId, const char *groupId, const char *peerUdid)
{
/*
* If the peer device does not exist in the group and needs to be added,
* check whether the number of trusted devices exceeds the upper limit.
*/
if ((peerUdid != NULL) && (IsTrustedDeviceInGroup(groupId, peerUdid, true))) {
if ((peerUdid != NULL) && (IsTrustedDeviceInGroup(osAccountId, groupId, peerUdid, true))) {
return HC_SUCCESS;
}
if (GetCurDeviceNumByGroupId(groupId) >= HC_TRUST_DEV_ENTRY_MAX_NUM) {
if (GetCurDeviceNumByGroupId(osAccountId, groupId) >= HC_TRUST_DEV_ENTRY_MAX_NUM) {
LOGE("The number of devices in the group has reached the upper limit!");
return HC_ERR_BEYOND_LIMIT;
}
@ -332,7 +616,7 @@ int32_t CheckExpireTimeIfExist(const CJson *jsonParams)
return HC_SUCCESS;
}
int32_t AddGroupNameToParams(const char *groupName, GroupInfo *groupParams)
int32_t AddGroupNameToParams(const char *groupName, TrustedGroupEntry *groupParams)
{
if (!StringSetPointer(&groupParams->name, groupName)) {
LOGE("Failed to copy groupName!");
@ -341,7 +625,7 @@ int32_t AddGroupNameToParams(const char *groupName, GroupInfo *groupParams)
return HC_SUCCESS;
}
int32_t AddGroupIdToParams(const char *groupId, GroupInfo *groupParams)
int32_t AddGroupIdToParams(const char *groupId, TrustedGroupEntry *groupParams)
{
if (!StringSetPointer(&groupParams->id, groupId)) {
LOGE("Failed to copy groupId!");
@ -350,22 +634,27 @@ int32_t AddGroupIdToParams(const char *groupId, GroupInfo *groupParams)
return HC_SUCCESS;
}
int32_t AddGroupOwnerToParams(const char *owner, GroupInfo *groupParams)
int32_t AddGroupOwnerToParams(const char *owner, TrustedGroupEntry *groupParams)
{
if (!StringSetPointer(&groupParams->ownerName, owner)) {
HcString ownerName = CreateString();
if (!StringSetPointer(&ownerName, owner)) {
LOGE("Failed to copy groupOwner!");
return HC_ERR_MEMORY_COPY;
}
if (groupParams->managers.pushBackT(&groupParams->managers, ownerName) == NULL) {
LOGE("Failed to push owner to vec!");
return HC_ERR_MEMORY_COPY;
}
return HC_SUCCESS;
}
int32_t AddGroupTypeToParams(int groupType, GroupInfo *groupParams)
int32_t AddGroupTypeToParams(int groupType, TrustedGroupEntry *groupParams)
{
groupParams->type = groupType;
return HC_SUCCESS;
}
int32_t AddGroupVisibilityOrDefault(const CJson *jsonParams, GroupInfo *groupParams)
int32_t AddGroupVisibilityOrDefault(const CJson *jsonParams, TrustedGroupEntry *groupParams)
{
/* Currently, only the public group and private group can be created. */
int32_t groupVisibility = GROUP_VISIBILITY_PUBLIC;
@ -374,7 +663,7 @@ int32_t AddGroupVisibilityOrDefault(const CJson *jsonParams, GroupInfo *groupPar
return HC_SUCCESS;
}
int32_t AddExpireTimeOrDefault(const CJson *jsonParams, GroupInfo *groupParams)
int32_t AddExpireTimeOrDefault(const CJson *jsonParams, TrustedGroupEntry *groupParams)
{
int32_t expireTime = DEFAULT_EXPIRE_TIME;
(void)GetIntFromJson(jsonParams, FIELD_EXPIRE_TIME, &expireTime);
@ -382,7 +671,7 @@ int32_t AddExpireTimeOrDefault(const CJson *jsonParams, GroupInfo *groupParams)
return HC_SUCCESS;
}
int32_t AddUserIdHashToGroupParams(const CJson *jsonParams, GroupInfo *groupParams)
int32_t AddUserIdHashToGroupParams(const CJson *jsonParams, TrustedGroupEntry *groupParams)
{
char *userIdHash = NULL;
int32_t result = GetUserIdHashFromJson(jsonParams, &userIdHash);
@ -398,11 +687,12 @@ int32_t AddUserIdHashToGroupParams(const CJson *jsonParams, GroupInfo *groupPara
return HC_SUCCESS;
}
int32_t AddUdidToParams(DeviceInfo *devParams)
int32_t AddUdidToParams(TrustedDeviceEntry *devParams)
{
const char *udid = GetLocalDevUdid();
if (udid == NULL) {
LOGE("Failed to get local udid!");
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 (!StringSetPointer(&devParams->udid, udid)) {
@ -412,14 +702,15 @@ int32_t AddUdidToParams(DeviceInfo *devParams)
return HC_SUCCESS;
}
int32_t AddAuthIdToParamsOrDefault(const CJson *jsonParams, DeviceInfo *devParams)
int32_t AddAuthIdToParamsOrDefault(const CJson *jsonParams, TrustedDeviceEntry *devParams)
{
const char *authId = GetStringFromJson(jsonParams, FIELD_DEVICE_ID);
if (authId == NULL) {
LOGD("No authId is found. The default value is udid!");
const char *udid = GetLocalDevUdid();
if (udid == NULL) {
LOGE("Failed to get local udid!");
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;
}
authId = udid;
@ -431,7 +722,7 @@ int32_t AddAuthIdToParamsOrDefault(const CJson *jsonParams, DeviceInfo *devParam
return HC_SUCCESS;
}
int32_t AddUserTypeToParamsOrDefault(const CJson *jsonParams, DeviceInfo *devParams)
int32_t AddUserTypeToParamsOrDefault(const CJson *jsonParams, TrustedDeviceEntry *devParams)
{
int32_t userType = DEVICE_TYPE_ACCESSORY;
(void)GetIntFromJson(jsonParams, FIELD_USER_TYPE, &userType);
@ -439,7 +730,7 @@ int32_t AddUserTypeToParamsOrDefault(const CJson *jsonParams, DeviceInfo *devPar
return HC_SUCCESS;
}
int32_t AddServiceTypeToParams(const char *groupId, DeviceInfo *devParams)
int32_t AddServiceTypeToParams(const char *groupId, TrustedDeviceEntry *devParams)
{
if (!StringSetPointer(&devParams->serviceType, groupId)) {
LOGE("Failed to copy serviceType!");
@ -448,7 +739,7 @@ int32_t AddServiceTypeToParams(const char *groupId, DeviceInfo *devParams)
return HC_SUCCESS;
}
int32_t AddGroupIdToDevParams(const char *groupId, DeviceInfo *devParams)
int32_t AddGroupIdToDevParams(const char *groupId, TrustedDeviceEntry *devParams)
{
if (!StringSetPointer(&devParams->groupId, groupId)) {
LOGE("Failed to copy groupId!");
@ -457,7 +748,7 @@ int32_t AddGroupIdToDevParams(const char *groupId, DeviceInfo *devParams)
return HC_SUCCESS;
}
int32_t AddUserIdHashToDevParams(const CJson *jsonParams, DeviceInfo *devParams)
int32_t AddUserIdHashToDevParams(const CJson *jsonParams, TrustedDeviceEntry *devParams)
{
char *userIdHash = NULL;
int32_t result = GetUserIdHashFromJson(jsonParams, &userIdHash);
@ -483,27 +774,27 @@ int32_t AssertUserIdHashExist(const CJson *jsonParams)
return HC_SUCCESS;
}
int32_t CheckGroupExist(const char *groupId)
int32_t CheckGroupExist(int32_t osAccountId, const char *groupId)
{
if (groupId == NULL) {
LOGE("The input groupId is NULL!");
return HC_ERR_NULL_PTR;
}
if (!IsGroupExistByGroupId(groupId)) {
if (!IsGroupExistByGroupId(osAccountId, groupId)) {
LOGE("The group does not exist!");
return HC_ERR_GROUP_NOT_EXIST;
}
return HC_SUCCESS;
}
int32_t AddGroupToDatabaseByJson(int32_t (*generateGroupParams)(const CJson*, const char *, GroupInfo*),
const CJson *jsonParams, const char *groupId)
int32_t AddGroupToDatabaseByJson(int32_t osAccountId, int32_t (*generateGroupParams)(const CJson*, const char *,
TrustedGroupEntry*), const CJson *jsonParams, const char *groupId)
{
if ((generateGroupParams == NULL) || (jsonParams == NULL) || (groupId == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
GroupInfo *groupParams = CreateGroupInfoStruct();
TrustedGroupEntry *groupParams = CreateGroupEntry();
if (groupParams == NULL) {
LOGE("Failed to allocate groupParams memory!");
return HC_ERR_ALLOC_MEMORY;
@ -511,26 +802,26 @@ int32_t AddGroupToDatabaseByJson(int32_t (*generateGroupParams)(const CJson*, co
int32_t result = (*generateGroupParams)(jsonParams, groupId, groupParams);
if (result != HC_SUCCESS) {
DestroyGroupInfoStruct(groupParams);
DestroyGroupEntry(groupParams);
return result;
}
result = AddGroup(groupParams);
DestroyGroupInfoStruct(groupParams);
result = AddGroup(osAccountId, groupParams);
DestroyGroupEntry(groupParams);
if (result != HC_SUCCESS) {
LOGE("Failed to add the group to the database!");
}
return result;
}
int32_t AddDeviceToDatabaseByJson(int32_t (*generateDevParams)(const CJson*, const char*, DeviceInfo*),
const CJson *jsonParams, const char *groupId)
int32_t AddDeviceToDatabaseByJson(int32_t osAccountId, int32_t (*generateDevParams)(const CJson*, const char*,
TrustedDeviceEntry*), const CJson *jsonParams, const char *groupId)
{
if ((generateDevParams == NULL) || (jsonParams == NULL) || (groupId == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
DeviceInfo *devParams = CreateDeviceInfoStruct();
TrustedDeviceEntry *devParams = CreateDeviceEntry();
if (devParams == NULL) {
LOGE("Failed to allocate devParams memory!");
return HC_ERR_ALLOC_MEMORY;
@ -538,26 +829,32 @@ int32_t AddDeviceToDatabaseByJson(int32_t (*generateDevParams)(const CJson*, con
int32_t result = (*generateDevParams)(jsonParams, groupId, devParams);
if (result != HC_SUCCESS) {
DestroyDeviceInfoStruct(devParams);
DestroyDeviceEntry(devParams);
return result;
}
result = AddTrustedDevice(devParams, NULL);
DestroyDeviceInfoStruct(devParams);
result = AddTrustedDevice(osAccountId, devParams);
DestroyDeviceEntry(devParams);
if (result != HC_SUCCESS) {
LOGE("Failed to add the trust device to the database!");
}
return result;
}
int32_t DelGroupFromDatabase(const char *groupId)
int32_t DelGroupFromDb(int32_t osAccountId, const char *groupId)
{
if (groupId == NULL) {
LOGE("The input groupId is NULL!");
return HC_ERR_NULL_PTR;
}
int32_t result = DelGroupByGroupId(groupId);
if (result != HC_SUCCESS) {
int32_t result;
QueryGroupParams queryGroupParams = InitQueryGroupParams();
queryGroupParams.groupId = groupId;
QueryDeviceParams queryDeviceParams = InitQueryDeviceParams();
queryDeviceParams.groupId = groupId;
if (((result = DelTrustedDevice(osAccountId, &queryDeviceParams)) != HC_SUCCESS) ||
((result = DelGroup(osAccountId, &queryGroupParams)) != HC_SUCCESS) ||
((result = SaveOsAccountDb(osAccountId)) != HC_SUCCESS)) {
LOGE("Failed to delete group from database!");
return result;
}
@ -678,14 +975,15 @@ int32_t ProcessKeyPair(int action, const CJson *jsonParams, const char *groupId)
/* Use the DeviceGroupManager package name. */
const char *appId = GROUP_MANAGER_PACKAGE_NAME;
const char *authId = GetStringFromJson(jsonParams, FIELD_DEVICE_ID);
char udid[INPUT_UDID_LEN] = { 0 };
if (authId == NULL) {
LOGD("No authId is found. The default value is udid!");
const char *udid = GetLocalDevUdid();
if (udid == NULL) {
LOGE("Failed to get local udid!");
return HC_ERROR;
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;
}
authId = udid;
authId = (char *)udid;
}
int32_t userType = DEVICE_TYPE_ACCESSORY;
(void)GetIntFromJson(jsonParams, FIELD_USER_TYPE, &userType);
@ -715,24 +1013,24 @@ int32_t ProcessKeyPair(int action, const CJson *jsonParams, const char *groupId)
return result;
}
int32_t GetGroupTypeFromDb(const char *groupId, int32_t *returnGroupType)
int32_t GetGroupTypeFromDb(int32_t osAccountId, const char *groupId, int32_t *returnGroupType)
{
if ((groupId == NULL) || (returnGroupType == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
GroupInfo *groupInfo = CreateGroupInfoStruct();
if (groupInfo == NULL) {
LOGE("Failed to allocate groupInfo memory!");
TrustedGroupEntry *groupEntry = CreateGroupEntry();
if (groupEntry == NULL) {
LOGE("Failed to allocate groupEntry memory!");
return HC_ERR_ALLOC_MEMORY;
}
if (GetGroupInfoById(groupId, groupInfo) != HC_SUCCESS) {
LOGE("Failed to get groupInfo from database!");
DestroyGroupInfoStruct(groupInfo);
if (GetGroupInfoById(osAccountId, groupId, groupEntry) != HC_SUCCESS) {
LOGE("Failed to get groupEntry from database!");
DestroyGroupEntry(groupEntry);
return HC_ERR_DB;
}
*returnGroupType = groupInfo->type;
DestroyGroupInfoStruct(groupInfo);
*returnGroupType = groupEntry->type;
DestroyGroupEntry(groupEntry);
return HC_SUCCESS;
}
@ -778,11 +1076,11 @@ int32_t GetAppIdFromJson(const CJson *jsonParams, const char **appId)
return HC_SUCCESS;
}
int32_t CheckPermForGroup(int actionType, const char *callerPkgName, const char *groupId)
int32_t CheckPermForGroup(int32_t osAccountId, int actionType, const char *callerPkgName, const char *groupId)
{
if (((actionType == GROUP_DISBAND) && (IsGroupOwner(groupId, callerPkgName))) ||
((actionType == MEMBER_INVITE) && (IsGroupEditAllowed(groupId, callerPkgName))) ||
((actionType == MEMBER_DELETE) && (IsGroupEditAllowed(groupId, callerPkgName)))) {
if (((actionType == GROUP_DISBAND) && (IsGroupOwner(osAccountId, groupId, callerPkgName))) ||
((actionType == MEMBER_INVITE) && (IsGroupEditAllowed(osAccountId, groupId, callerPkgName))) ||
((actionType == MEMBER_DELETE) && (IsGroupEditAllowed(osAccountId, groupId, callerPkgName)))) {
return HC_SUCCESS;
}
LOGE("You do not have the right to execute the command!");
@ -824,4 +1122,4 @@ int32_t GetHashResult(const uint8_t *info, uint32_t infoLen, char *hash, uint32_
HcFree(infoHash.val);
HcFree(message.val);
return result;
}
}

View File

@ -18,7 +18,7 @@
#include "alg_defs.h"
#include "callback_manager.h"
#include "channel_manager.h"
#include "database_manager.h"
#include "data_manager.h"
#include "dev_auth_module_manager.h"
#include "group_operation_common.h"
#include "hc_dev_info.h"
@ -26,7 +26,30 @@
#include "session_manager.h"
#include "string_util.h"
static int32_t CheckGroupName(const char *appId, const CJson *jsonParams)
static bool IsSameNameGroupExist(int32_t osAccountId, const char *ownerName, const char *groupName)
{
if ((ownerName == NULL) || (groupName == NULL)) {
LOGE("The input ownerName or groupName is NULL!");
return false;
}
QueryGroupParams queryParams = InitQueryGroupParams();
queryParams.ownerName = ownerName;
queryParams.groupName = groupName;
GroupEntryVec groupEntryVec = CreateGroupEntryVec();
int32_t result = QueryGroups(osAccountId, &queryParams, &groupEntryVec);
if (result != HC_SUCCESS) {
ClearGroupEntryVec(&groupEntryVec);
return result;
}
if (HC_VECTOR_SIZE(&groupEntryVec) > 0) {
ClearGroupEntryVec(&groupEntryVec);
return true;
}
ClearGroupEntryVec(&groupEntryVec);
return false;
}
static int32_t CheckGroupName(int32_t osAccountId, const char *appId, const CJson *jsonParams)
{
const char *groupName = GetStringFromJson(jsonParams, FIELD_GROUP_NAME);
if (groupName == NULL) {
@ -34,7 +57,7 @@ static int32_t CheckGroupName(const char *appId, const CJson *jsonParams)
return HC_ERR_JSON_GET;
}
if (IsSameNameGroupExist(appId, groupName)) {
if (IsSameNameGroupExist(osAccountId, appId, groupName)) {
LOGE("A group with the same group name has been created! [AppId]: %s, [GroupName]: %s", appId, groupName);
return HC_ERR_INVALID_PARAMS;
}
@ -90,7 +113,7 @@ static int32_t GeneratePeerToPeerGroupId(const CJson *jsonParams, char **returnG
return HC_SUCCESS;
}
static int32_t CheckCreateParams(const CJson *jsonParams)
static int32_t CheckCreateParams(int32_t osAccountId, const CJson *jsonParams)
{
const char *appId = GetStringFromJson(jsonParams, FIELD_APP_ID);
if (appId == NULL) {
@ -98,17 +121,17 @@ static int32_t CheckCreateParams(const CJson *jsonParams)
return HC_ERR_JSON_GET;
}
int32_t result;
if (((result = CheckGroupName(appId, jsonParams)) != HC_SUCCESS) ||
if (((result = CheckGroupName(osAccountId, appId, jsonParams)) != HC_SUCCESS) ||
((result = CheckUserTypeIfExist(jsonParams)) != HC_SUCCESS) ||
((result = CheckGroupVisibilityIfExist(jsonParams)) != HC_SUCCESS) ||
((result = CheckExpireTimeIfExist(jsonParams)) != HC_SUCCESS) ||
((result = CheckGroupNumLimit(PEER_TO_PEER_GROUP, appId)) != HC_SUCCESS)) {
((result = CheckGroupNumLimit(osAccountId, PEER_TO_PEER_GROUP, appId)) != HC_SUCCESS)) {
return result;
}
return HC_SUCCESS;
}
static int32_t GenerateGroupParams(const CJson *jsonParams, const char *groupId, GroupInfo *groupParams)
static int32_t GenerateGroupParams(const CJson *jsonParams, const char *groupId, TrustedGroupEntry *groupParams)
{
const char *groupName = GetStringFromJson(jsonParams, FIELD_GROUP_NAME);
if (groupName == NULL) {
@ -132,7 +155,7 @@ static int32_t GenerateGroupParams(const CJson *jsonParams, const char *groupId,
return HC_SUCCESS;
}
static int32_t GenerateDevParams(const CJson *jsonParams, const char *groupId, DeviceInfo *devParams)
static int32_t GenerateDevParams(const CJson *jsonParams, const char *groupId, TrustedDeviceEntry *devParams)
{
int32_t result;
if (((result = AddUdidToParams(devParams)) != HC_SUCCESS) ||
@ -145,15 +168,16 @@ static int32_t GenerateDevParams(const CJson *jsonParams, const char *groupId, D
return HC_SUCCESS;
}
static int32_t CreateGroupInner(const CJson *jsonParams, char **returnGroupId)
static int32_t CreateGroupInner(int32_t osAccountId, const CJson *jsonParams, char **returnGroupId)
{
char *groupId = NULL;
int32_t result;
if (((result = CheckCreateParams(jsonParams)) != HC_SUCCESS) ||
if (((result = CheckCreateParams(osAccountId, jsonParams)) != HC_SUCCESS) ||
((result = GeneratePeerToPeerGroupId(jsonParams, &groupId)) != HC_SUCCESS) ||
((result = ProcessKeyPair(CREATE_KEY_PAIR, jsonParams, groupId)) != HC_SUCCESS) ||
((result = AddGroupToDatabaseByJson(GenerateGroupParams, jsonParams, groupId)) != HC_SUCCESS) ||
((result = AddDeviceToDatabaseByJson(GenerateDevParams, jsonParams, groupId)) != HC_SUCCESS)) {
((result = AddGroupToDatabaseByJson(osAccountId, GenerateGroupParams, jsonParams, groupId)) != HC_SUCCESS) ||
((result = AddDeviceToDatabaseByJson(osAccountId, GenerateDevParams, jsonParams, groupId)) != HC_SUCCESS) ||
((result = SaveOsAccountDb(osAccountId)) != HC_SUCCESS)) {
HcFree(groupId);
return result;
}
@ -161,28 +185,31 @@ static int32_t CreateGroupInner(const CJson *jsonParams, char **returnGroupId)
return HC_SUCCESS;
}
static int32_t GetPeerDevUserTypeFromDb(const char *groupId, const char *peerAuthId)
static int32_t GetPeerDevUserTypeFromDb(int32_t osAccountId, const char *groupId, const char *peerAuthId)
{
int peerUserType = DEVICE_TYPE_ACCESSORY;
DeviceInfo *devAuthParams = CreateDeviceInfoStruct();
TrustedDeviceEntry *devAuthParams = CreateDeviceEntry();
if (devAuthParams == NULL) {
LOGE("Failed to allocate devEntry memory!");
return peerUserType;
}
if (GetTrustedDevInfoById(peerAuthId, false, groupId, devAuthParams) != HC_SUCCESS) {
if (GetTrustedDevInfoById(osAccountId, peerAuthId, false, groupId, devAuthParams) != HC_SUCCESS) {
LOGE("Failed to obtain the device information from the database!");
DestroyDeviceInfoStruct(devAuthParams);
DestroyDeviceEntry(devAuthParams);
return peerUserType;
}
peerUserType = devAuthParams->devType;
DestroyDeviceInfoStruct(devAuthParams);
DestroyDeviceEntry(devAuthParams);
return peerUserType;
}
static int32_t DelPeerDevAndKeyInfo(const char *groupId, const char *peerAuthId)
static int32_t DelPeerDevAndKeyInfo(int32_t osAccountId, const char *groupId, const char *peerAuthId)
{
int32_t peerUserType = GetPeerDevUserTypeFromDb(groupId, peerAuthId);
int32_t result = DelTrustedDevice(peerAuthId, false, groupId);
int32_t peerUserType = GetPeerDevUserTypeFromDb(osAccountId, groupId, peerAuthId);
QueryDeviceParams queryDeviceParams = InitQueryDeviceParams();
queryDeviceParams.groupId = groupId;
queryDeviceParams.authId = peerAuthId;
int32_t result = DelTrustedDevice(osAccountId, &queryDeviceParams);
if (result != HC_SUCCESS) {
LOGE("Failed to delete peer device from database!");
return result;
@ -208,77 +235,87 @@ static int32_t DelPeerDevAndKeyInfo(const char *groupId, const char *peerAuthId)
static bool IsLocalDevice(const char *udid)
{
return (strcmp(GetLocalDevUdid(), udid) == 0);
char localUdid[INPUT_UDID_LEN] = { 0 };
int32_t res = HcGetUdid((uint8_t *)localUdid, INPUT_UDID_LEN);
if (res != HC_SUCCESS) {
LOGE("Failed to get local udid! res: %d", res);
return HC_ERR_DB;
}
return (strcmp(localUdid, udid) == 0);
}
static int32_t DelAllPeerDevAndKeyInfo(const char *groupId)
static int32_t DelAllPeerDevAndKeyInfo(int32_t osAccountId, const char *groupId)
{
DeviceInfoVec deviceInfoVec;
CreateDeviceInfoVecStruct(&deviceInfoVec);
int32_t result = GetTrustedDevices(groupId, &deviceInfoVec);
QueryDeviceParams queryParams = InitQueryDeviceParams();
queryParams.groupId = groupId;
DeviceEntryVec deviceEntryVec = CreateDeviceEntryVec();
int32_t result = QueryDevices(osAccountId, &queryParams, &deviceEntryVec);
if (result != HC_SUCCESS) {
DestroyDeviceInfoVecStruct(&deviceInfoVec);
ClearDeviceEntryVec(&deviceEntryVec);
return result;
}
uint32_t index;
void **devInfoPtr = NULL;
FOR_EACH_HC_VECTOR(deviceInfoVec, index, devInfoPtr) {
if ((devInfoPtr == NULL) || ((*devInfoPtr) == NULL)) {
TrustedDeviceEntry **entryPtr = NULL;
FOR_EACH_HC_VECTOR(deviceEntryVec, index, entryPtr) {
if ((entryPtr == NULL) || (*entryPtr == NULL)) {
continue;
}
DeviceInfo *devInfo = (DeviceInfo*)(*devInfoPtr);
if (IsLocalDevice(StringGet(&devInfo->udid))) {
TrustedDeviceEntry *entry = (TrustedDeviceEntry *)(*entryPtr);
if (IsLocalDevice(StringGet(&entry->udid))) {
continue;
}
result = DelPeerDevAndKeyInfo(groupId, StringGet(&devInfo->authId));
result = DelPeerDevAndKeyInfo(osAccountId, groupId, StringGet(&entry->authId));
if (result != HC_SUCCESS) {
DestroyDeviceInfoVecStruct(&deviceInfoVec);
ClearDeviceEntryVec(&deviceEntryVec);
return result;
}
}
DestroyDeviceInfoVecStruct(&deviceInfoVec);
ClearDeviceEntryVec(&deviceEntryVec);
return HC_SUCCESS;
}
static int32_t AddAuthIdAndUserTypeToParams(const char *groupId, CJson *jsonParams)
static int32_t AddAuthIdAndUserTypeToParams(int32_t osAccountId, const char *groupId, CJson *jsonParams)
{
DeviceInfo *deviceInfo = CreateDeviceInfoStruct();
TrustedDeviceEntry *deviceInfo = CreateDeviceEntry();
if (deviceInfo == NULL) {
LOGE("Failed to allocate deviceInfo memory!");
return HC_ERR_ALLOC_MEMORY;
}
const char *udid = GetLocalDevUdid();
if (udid == NULL) {
LOGE("Failed to get local udid!");
DestroyDeviceInfoStruct(deviceInfo);
return HC_ERROR;
}
if (GetTrustedDevInfoById(udid, true, groupId, deviceInfo) != HC_SUCCESS) {
LOGE("Failed to obtain the device information from the database!");
DestroyDeviceInfoStruct(deviceInfo);
char localUdid[INPUT_UDID_LEN] = { 0 };
int32_t res = HcGetUdid((uint8_t *)localUdid, INPUT_UDID_LEN);
if (res != HC_SUCCESS) {
LOGE("Failed to get local udid! res: %d", res);
return HC_ERR_DB;
}
if (GetTrustedDevInfoById(osAccountId, localUdid, true, groupId, deviceInfo) != HC_SUCCESS) {
LOGE("Failed to obtain the device information from the database!");
DestroyDeviceEntry(deviceInfo);
return HC_ERR_DB;
}
if (AddStringToJson(jsonParams, FIELD_DEVICE_ID, StringGet(&deviceInfo->authId)) != HC_SUCCESS) {
LOGE("Failed to add authId to params!");
DestroyDeviceInfoStruct(deviceInfo);
DestroyDeviceEntry(deviceInfo);
return HC_ERR_JSON_FAIL;
}
if (AddIntToJson(jsonParams, FIELD_USER_TYPE, deviceInfo->devType) != HC_SUCCESS) {
LOGE("Failed to add userType to params!");
DestroyDeviceInfoStruct(deviceInfo);
DestroyDeviceEntry(deviceInfo);
return HC_ERR_JSON_FAIL;
}
DestroyDeviceInfoStruct(deviceInfo);
DestroyDeviceEntry(deviceInfo);
return HC_SUCCESS;
}
static int32_t DelGroupAndSelfKeyInfo(const char *groupId, CJson *jsonParams)
static int32_t DelGroupAndSelfKeyInfo(int32_t osAccountId, const char *groupId, CJson *jsonParams)
{
int32_t result = AddAuthIdAndUserTypeToParams(groupId, jsonParams);
int32_t result = AddAuthIdAndUserTypeToParams(osAccountId, groupId, jsonParams);
if (result != HC_SUCCESS) {
return result;
}
result = DelGroupFromDatabase(groupId);
result = DelGroupFromDb(osAccountId, groupId);
if (result != HC_SUCCESS) {
return result;
}
@ -295,7 +332,8 @@ static int32_t DelGroupAndSelfKeyInfo(const char *groupId, CJson *jsonParams)
return HC_SUCCESS;
}
static int32_t HandleLocalUnbind(int64_t requestId, const CJson *jsonParams, const DeviceAuthCallback *callback)
static int32_t HandleLocalUnbind(int64_t requestId, const CJson *jsonParams,
const DeviceAuthCallback *callback)
{
const char *peerAuthId = GetStringFromJson(jsonParams, FIELD_DELETE_ID);
if (peerAuthId == NULL) {
@ -307,10 +345,20 @@ static int32_t HandleLocalUnbind(int64_t requestId, const CJson *jsonParams, con
LOGE("Failed to get groupId from jsonParams!");
return HC_ERR_JSON_GET;
}
int32_t result = DelPeerDevAndKeyInfo(groupId, peerAuthId);
int32_t osAccountId;
if (GetIntFromJson(jsonParams, FIELD_OS_ACCOUNT_ID, &osAccountId) != HC_SUCCESS) {
LOGE("Failed to get osAccountId from jsonParams!");
return HC_ERR_JSON_GET;
}
int result = DelPeerDevAndKeyInfo(osAccountId, groupId, peerAuthId);
if (result != HC_SUCCESS) {
return result;
}
result = SaveOsAccountDb(osAccountId);
if (result != HC_SUCCESS) {
LOGE("Failed to save osAccountDb!");
return result;
}
char *returnDataStr = NULL;
result = GenerateUnbindSuccessData(peerAuthId, groupId, &returnDataStr);
if (result != HC_SUCCESS) {
@ -346,10 +394,11 @@ static int32_t IsPeerDeviceNotSelf(const char *peerUdid)
LOGE("The input peerUdid is NULL!");
return HC_ERR_NULL_PTR;
}
const char *udid = GetLocalDevUdid();
if (udid == NULL) {
LOGE("Failed to get local udid!");
return HC_ERROR;
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!");
@ -358,26 +407,26 @@ static int32_t IsPeerDeviceNotSelf(const char *peerUdid)
return HC_SUCCESS;
}
static int32_t CheckPeerDeviceStatus(const char *groupId, const CJson *jsonParams)
static int32_t CheckPeerDeviceStatus(int32_t osAccountId, const char *groupId, const CJson *jsonParams)
{
const char *peerAuthId = GetStringFromJson(jsonParams, FIELD_DELETE_ID);
if (peerAuthId == NULL) {
LOGE("Failed to get peerUdid from jsonParams!");
return HC_ERR_JSON_GET;
}
DeviceInfo *deviceInfo = CreateDeviceInfoStruct();
TrustedDeviceEntry *deviceInfo = CreateDeviceEntry();
if (deviceInfo == NULL) {
LOGE("Failed to allocate deviceInfo memory!");
return HC_ERR_ALLOC_MEMORY;
}
int32_t result = GetTrustedDevInfoById(peerAuthId, false, groupId, deviceInfo);
int32_t result = GetTrustedDevInfoById(osAccountId, peerAuthId, false, groupId, deviceInfo);
if (result != HC_SUCCESS) {
LOGE("Failed to obtain the peer device information from the database!");
DestroyDeviceInfoStruct(deviceInfo);
DestroyDeviceEntry(deviceInfo);
return result;
}
result = IsPeerDeviceNotSelf(StringGet(&deviceInfo->udid));
DestroyDeviceInfoStruct(deviceInfo);
DestroyDeviceEntry(deviceInfo);
return result;
}
@ -393,14 +442,19 @@ static int32_t CheckInvitePeer(const CJson *jsonParams)
LOGE("Failed to get appId from jsonParams!");
return HC_ERR_JSON_GET;
}
int32_t osAccountId;
if (GetIntFromJson(jsonParams, FIELD_OS_ACCOUNT_ID, &osAccountId) != HC_SUCCESS) {
LOGE("Failed to get osAccountId from jsonParams!");
return HC_ERR_JSON_GET;
}
int32_t groupType = PEER_TO_PEER_GROUP;
int32_t result;
if (((result = CheckGroupExist(groupId)) != HC_SUCCESS) ||
((result = GetGroupTypeFromDb(groupId, &groupType)) != HC_SUCCESS) ||
if (((result = CheckGroupExist(osAccountId, groupId)) != HC_SUCCESS) ||
((result = GetGroupTypeFromDb(osAccountId, groupId, &groupType)) != HC_SUCCESS) ||
((result = AssertPeerToPeerGroupType(groupType)) != HC_SUCCESS) ||
((result = CheckPermForGroup(MEMBER_INVITE, appId, groupId)) != HC_SUCCESS) ||
((result = CheckDeviceNumLimit(groupId, NULL)) != HC_SUCCESS)) {
((result = CheckPermForGroup(osAccountId, MEMBER_INVITE, appId, groupId)) != HC_SUCCESS) ||
((result = CheckDeviceNumLimit(osAccountId, groupId, NULL)) != HC_SUCCESS)) {
return result;
}
return HC_SUCCESS;
@ -423,14 +477,19 @@ static int32_t CheckDeletePeer(const CJson *jsonParams)
LOGE("Failed to get appId from jsonParams!");
return HC_ERR_JSON_GET;
}
int32_t osAccountId;
if (GetIntFromJson(jsonParams, FIELD_OS_ACCOUNT_ID, &osAccountId) != HC_SUCCESS) {
LOGE("Failed to get osAccountId from jsonParams!");
return HC_ERR_JSON_GET;
}
int32_t groupType = PEER_TO_PEER_GROUP;
int32_t result;
if (((result = CheckGroupExist(groupId)) != HC_SUCCESS) ||
((result = GetGroupTypeFromDb(groupId, &groupType)) != HC_SUCCESS) ||
if (((result = CheckGroupExist(osAccountId, groupId)) != HC_SUCCESS) ||
((result = GetGroupTypeFromDb(osAccountId, groupId, &groupType)) != HC_SUCCESS) ||
((result = AssertPeerToPeerGroupType(groupType)) != HC_SUCCESS) ||
((result = CheckPermForGroup(MEMBER_DELETE, appId, groupId)) != HC_SUCCESS) ||
((result = CheckPeerDeviceStatus(groupId, jsonParams)) != HC_SUCCESS)) {
((result = CheckPermForGroup(osAccountId, MEMBER_DELETE, appId, groupId)) != HC_SUCCESS) ||
((result = CheckPeerDeviceStatus(osAccountId, groupId, jsonParams)) != HC_SUCCESS)) {
return result;
}
return HC_SUCCESS;
@ -503,49 +562,6 @@ static void InformPeerProcessError(int64_t requestId, const CJson *jsonParams, c
FreeJsonString(errorDataStr);
}
static int32_t CheckServerStatusIfNotInvite(int operationCode, const CJson *jsonParams)
{
if (operationCode == MEMBER_INVITE) {
return HC_SUCCESS;
}
const char *groupId = GetStringFromJson(jsonParams, FIELD_GROUP_ID);
if (groupId == NULL) {
LOGE("Failed to get groupId from jsonParams!");
return HC_ERR_JSON_GET;
}
const char *appId = GetStringFromJson(jsonParams, FIELD_APP_ID);
if (appId == NULL) {
LOGE("Failed to get appId from jsonParams!");
return HC_ERR_JSON_GET;
}
const char *peerUdid = GetStringFromJson(jsonParams, FIELD_CONN_DEVICE_ID);
if (peerUdid == NULL) {
LOGE("Failed to get peerUdid from jsonParams!");
return HC_ERR_JSON_GET;
}
int32_t result = CheckGroupExist(groupId);
if (result != HC_SUCCESS) {
return result;
}
if (operationCode == MEMBER_JOIN) {
/* The client sends a join request, which is equivalent to the server performing an invitation operation. */
result = CheckPermForGroup(MEMBER_INVITE, appId, groupId);
if (result != HC_SUCCESS) {
return result;
}
result = CheckDeviceNumLimit(groupId, peerUdid);
} else if (operationCode == MEMBER_DELETE) {
result = CheckPermForGroup(MEMBER_DELETE, appId, groupId);
if (result != HC_SUCCESS) {
return result;
}
if (!IsTrustedDeviceInGroup(groupId, peerUdid, true)) {
result = HC_ERR_DEVICE_NOT_EXIST;
}
}
return result;
}
static int32_t ShouldForceUnbind(bool isForceDelete, const CJson *jsonParams)
{
bool isIgnoreChannel = false;
@ -589,7 +605,7 @@ static int32_t CreateServerSession(int64_t requestId, int32_t operationCode, CJs
return HC_SUCCESS;
}
static int32_t CreateGroup(CJson *jsonParams, char **returnJsonStr)
static int32_t CreateGroup(int32_t osAccountId, CJson *jsonParams, char **returnJsonStr)
{
LOGI("[Start]: Start to create a peer to peer group!");
if ((jsonParams == NULL) || (returnJsonStr == NULL)) {
@ -597,7 +613,7 @@ static int32_t CreateGroup(CJson *jsonParams, char **returnJsonStr)
return HC_ERR_INVALID_PARAMS;
}
char *groupId = NULL;
int32_t result = CreateGroupInner(jsonParams, &groupId);
int32_t result = CreateGroupInner(osAccountId, jsonParams, &groupId);
if (result != HC_SUCCESS) {
return result;
}
@ -610,7 +626,7 @@ static int32_t CreateGroup(CJson *jsonParams, char **returnJsonStr)
return HC_SUCCESS;
}
static int32_t DeleteGroup(CJson *jsonParams, char **returnJsonStr)
static int32_t DeleteGroup(int32_t osAccountId, CJson *jsonParams, char **returnJsonStr)
{
LOGI("[Start]: Start to delete a peer to peer group!");
if ((jsonParams == NULL) || (returnJsonStr == NULL)) {
@ -620,8 +636,8 @@ static int32_t DeleteGroup(CJson *jsonParams, char **returnJsonStr)
int32_t result;
const char *groupId = NULL;
if (((result = GetGroupIdFromJson(jsonParams, &groupId)) != HC_SUCCESS) ||
((result = DelAllPeerDevAndKeyInfo(groupId)) != HC_SUCCESS) ||
((result = DelGroupAndSelfKeyInfo(groupId, jsonParams)) != HC_SUCCESS) ||
((result = DelAllPeerDevAndKeyInfo(osAccountId, groupId)) != HC_SUCCESS) ||
((result = DelGroupAndSelfKeyInfo(osAccountId, groupId, jsonParams)) != HC_SUCCESS) ||
((result = ConvertGroupIdToJsonStr(groupId, returnJsonStr)) != HC_SUCCESS)) {
return result;
}
@ -629,7 +645,8 @@ static int32_t DeleteGroup(CJson *jsonParams, char **returnJsonStr)
return HC_SUCCESS;
}
static int32_t AddMemberToGroup(int64_t requestId, CJson *jsonParams, const DeviceAuthCallback *callback)
static int32_t AddMemberToGroup(int32_t osAccountId, int64_t requestId, CJson *jsonParams,
const DeviceAuthCallback *callback)
{
LOGI("[Start]: Start to add member to a peer to peer group!");
if ((jsonParams == NULL) || (callback == NULL)) {
@ -638,6 +655,7 @@ static int32_t AddMemberToGroup(int64_t requestId, CJson *jsonParams, const Devi
}
int32_t result;
int32_t operationCode = MEMBER_INVITE;
AddIntToJson(jsonParams, FIELD_OS_ACCOUNT_ID, osAccountId);
(void)GetIntFromJson(jsonParams, FIELD_OPERATION_CODE, &operationCode);
result = CheckClientStatus(operationCode, jsonParams);
if (result != HC_SUCCESS) {
@ -647,13 +665,15 @@ static int32_t AddMemberToGroup(int64_t requestId, CJson *jsonParams, const Devi
return CreateClientSession(requestId, operationCode, GetChannelType(callback, jsonParams), jsonParams, callback);
}
static int32_t DeleteMemberFromGroup(int64_t requestId, CJson *jsonParams, const DeviceAuthCallback *callback)
static int32_t DeleteMemberFromGroup(int32_t osAccountId, int64_t requestId, CJson *jsonParams,
const DeviceAuthCallback *callback)
{
LOGI("[Start]: Start to delete member from a peer to peer group!");
if ((jsonParams == NULL) || (callback == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
AddIntToJson(jsonParams, FIELD_OS_ACCOUNT_ID, osAccountId);
int32_t result = CheckClientStatus(MEMBER_DELETE, jsonParams);
if (result != HC_SUCCESS) {
ProcessErrorCallback(requestId, MEMBER_DELETE, result, NULL, callback);
@ -680,118 +700,95 @@ static int32_t ProcessData(int64_t requestId, CJson *jsonParams, const DeviceAut
}
int32_t operationCode = MEMBER_INVITE;
(void)(GetIntFromJson(jsonParams, FIELD_GROUP_OP, &operationCode));
int32_t result = CheckServerStatusIfNotInvite(operationCode, jsonParams);
if (result != HC_SUCCESS) {
InformPeerProcessError(requestId, jsonParams, callback, result);
ProcessErrorCallback(requestId, operationCode, result, NULL, callback);
return result;
}
return CreateServerSession(requestId, operationCode, jsonParams, callback);
}
static int32_t AddManagerWithCheck(const char *appId, const char *groupId, const char *managerAppId)
static int32_t AddManagerWithCheck(int32_t osAccountId, const char *appId, const char *groupId, const char *managerAppId)
{
int32_t groupType = PEER_TO_PEER_GROUP;
if (GetGroupTypeFromDb(groupId, &groupType) != HC_SUCCESS) {
if (GetGroupTypeFromDb(osAccountId, groupId, &groupType) != HC_SUCCESS) {
LOGE("No group is found based on the query parameters!");
return HC_ERR_GROUP_NOT_EXIST;
}
if (AssertPeerToPeerGroupType(groupType) != HC_SUCCESS) {
return HC_ERR_NOT_SUPPORT;
}
if (!IsGroupOwner(groupId, appId)) {
if (!IsGroupOwner(osAccountId, groupId, appId)) {
LOGE("You do not have the permission to add a manager to the group!");
return HC_ERR_ACCESS_DENIED;
}
if (AddGroupRole(groupId, GROUP_MANAGER, managerAppId) != HC_SUCCESS) {
LOGE("Failed to add manager!");
return HC_ERR_DB;
}
(void)managerAppId;
return HC_SUCCESS;
}
static int32_t AddFriendWithCheck(const char *appId, const char *groupId, const char *friendAppId)
static int32_t AddFriendWithCheck(int32_t osAccountId, const char *appId, const char *groupId, const char *friendAppId)
{
int32_t groupType = PEER_TO_PEER_GROUP;
if (GetGroupTypeFromDb(groupId, &groupType) != HC_SUCCESS) {
if (GetGroupTypeFromDb(osAccountId, groupId, &groupType) != HC_SUCCESS) {
LOGE("No group is found based on the query parameters!");
return HC_ERR_GROUP_NOT_EXIST;
}
if (AssertPeerToPeerGroupType(groupType) != HC_SUCCESS) {
return HC_ERR_NOT_SUPPORT;
}
if (!IsGroupEditAllowed(groupId, appId)) {
if (!IsGroupEditAllowed(osAccountId, groupId, appId)) {
LOGE("You do not have the permission to add a friend to the group!");
return HC_ERR_ACCESS_DENIED;
}
if (CompareVisibility(groupId, GROUP_VISIBILITY_ALLOW_LIST) != HC_SUCCESS) {
LOGE("The group dose not support the allow list protection!");
return HC_ERR_NOT_SUPPORT;
}
if (AddGroupRole(groupId, GROUP_FRIEND, friendAppId) != HC_SUCCESS) {
LOGE("Failed to add friend!");
return HC_ERR_DB;
}
(void)friendAppId;
return HC_SUCCESS;
}
static int32_t DeleteManagerWithCheck(const char *appId, const char *groupId, const char *managerAppId)
static int32_t DeleteManagerWithCheck(int32_t osAccountId, const char *appId, const char *groupId,
const char *managerAppId)
{
int32_t groupType = PEER_TO_PEER_GROUP;
if (GetGroupTypeFromDb(groupId, &groupType) != HC_SUCCESS) {
if (GetGroupTypeFromDb(osAccountId, groupId, &groupType) != HC_SUCCESS) {
LOGE("No group is found based on the query parameters!");
return HC_ERR_GROUP_NOT_EXIST;
}
if (AssertPeerToPeerGroupType(groupType) != HC_SUCCESS) {
return HC_ERR_NOT_SUPPORT;
}
if (!IsGroupOwner(groupId, appId)) {
if (!IsGroupOwner(osAccountId, groupId, appId)) {
LOGE("You do not have the permission to delete a manager from the group!");
return HC_ERR_ACCESS_DENIED;
}
if (RemoveGroupRole(groupId, GROUP_MANAGER, managerAppId) != HC_SUCCESS) {
LOGE("Failed to delete manager!");
return HC_ERR_DB;
}
(void)managerAppId;
return HC_SUCCESS;
}
static int32_t DeleteFriendWithCheck(const char *appId, const char *groupId, const char *friendAppId)
static int32_t DeleteFriendWithCheck(int32_t osAccountId, const char *appId, const char *groupId,
const char *friendAppId)
{
int32_t groupType = PEER_TO_PEER_GROUP;
if (GetGroupTypeFromDb(groupId, &groupType) != HC_SUCCESS) {
if (GetGroupTypeFromDb(osAccountId, groupId, &groupType) != HC_SUCCESS) {
LOGE("No group is found based on the query parameters!");
return HC_ERR_GROUP_NOT_EXIST;
}
if (AssertPeerToPeerGroupType(groupType) != HC_SUCCESS) {
return HC_ERR_NOT_SUPPORT;
}
if (!IsGroupEditAllowed(groupId, appId)) {
if (!IsGroupEditAllowed(osAccountId, groupId, appId)) {
LOGE("You do not have the permission to add a friend to the group!");
return HC_ERR_ACCESS_DENIED;
}
if (CompareVisibility(groupId, GROUP_VISIBILITY_ALLOW_LIST) != HC_SUCCESS) {
LOGE("The group dose not support the allow list protection!");
return HC_ERR_NOT_SUPPORT;
}
if (RemoveGroupRole(groupId, GROUP_FRIEND, friendAppId) != HC_SUCCESS) {
LOGE("Failed to delete friend!");
return HC_ERR_DB;
}
(void)friendAppId;
return HC_SUCCESS;
}
static int32_t GetManagersWithCheck(const char *appId, const char *groupId, char **returnManagers, uint32_t *returnSize)
static int32_t GetManagersWithCheck(int32_t osAccountId, const char *appId, const char *groupId, char **returnManagers,
uint32_t *returnSize)
{
int32_t groupType = PEER_TO_PEER_GROUP;
if (GetGroupTypeFromDb(groupId, &groupType) != HC_SUCCESS) {
if (GetGroupTypeFromDb(osAccountId, groupId, &groupType) != HC_SUCCESS) {
LOGE("No group is found based on the query parameters!");
return HC_ERR_GROUP_NOT_EXIST;
}
if (AssertPeerToPeerGroupType(groupType) != HC_SUCCESS) {
return HC_ERR_NOT_SUPPORT;
}
if (!IsGroupOwner(groupId, appId)) {
if (!IsGroupOwner(osAccountId, groupId, appId)) {
LOGE("You do not have the permission to query the group managers information!");
return HC_ERR_ACCESS_DENIED;
}
@ -800,82 +797,56 @@ static int32_t GetManagersWithCheck(const char *appId, const char *groupId, char
LOGE("Failed to allocate managers memory!");
return HC_ERR_JSON_FAIL;
}
int32_t result = GetGroupRoles(groupId, GROUP_MANAGER, managers);
if (result != HC_SUCCESS) {
LOGE("Failed to get managers!");
FreeJson(managers);
return result;
}
*returnManagers = PackJsonToString(managers);
if (*returnManagers == NULL) {
LOGE("Failed to convert json to string!");
FreeJson(managers);
return HC_ERR_JSON_FAIL;
}
*returnSize = GetItemNum(managers);
FreeJson(managers);
(void)returnManagers;
(void)returnSize;
return HC_SUCCESS;
}
static int32_t GetFriendsWithCheck(const char *appId, const char *groupId, char **returnFriends, uint32_t *returnSize)
static int32_t GetFriendsWithCheck(int32_t osAccountId, const char *appId, const char *groupId, char **returnFriends,
uint32_t *returnSize)
{
int32_t groupType = PEER_TO_PEER_GROUP;
if (GetGroupTypeFromDb(groupId, &groupType) != HC_SUCCESS) {
if (GetGroupTypeFromDb(osAccountId, groupId, &groupType) != HC_SUCCESS) {
LOGE("No group is found based on the query parameters!");
return HC_ERR_GROUP_NOT_EXIST;
}
if (AssertPeerToPeerGroupType(groupType) != HC_SUCCESS) {
return HC_ERR_NOT_SUPPORT;
}
if (!IsGroupEditAllowed(groupId, appId)) {
if (!IsGroupEditAllowed(osAccountId, groupId, appId)) {
LOGE("You do not have the permission to query the group friends information!");
return HC_ERR_ACCESS_DENIED;
}
CJson *friends = CreateJsonArray();
if (friends == NULL) {
LOGE("Failed to allocate friends memory!");
return HC_ERR_JSON_FAIL;
}
int32_t result = GetGroupRoles(groupId, GROUP_FRIEND, friends);
if (result != HC_SUCCESS) {
LOGE("Failed to get friends!");
FreeJson(friends);
return result;
}
*returnFriends = PackJsonToString(friends);
if (*returnFriends == NULL) {
LOGE("Failed to convert json to string!");
FreeJson(friends);
return HC_ERR_JSON_FAIL;
}
*returnSize = GetItemNum(friends);
FreeJson(friends);
(void)returnFriends;
(void)returnSize;
return HC_SUCCESS;
}
static int32_t AddGroupRoleWithCheck(bool isManager, const char *appId, const char *groupId, const char *roleAppId)
static int32_t AddGroupRoleWithCheck(int32_t osAccountId, bool isManager, const char *appId, const char *groupId,
const char *roleAppId)
{
if (isManager) {
return AddManagerWithCheck(appId, groupId, roleAppId);
return AddManagerWithCheck(osAccountId, appId, groupId, roleAppId);
}
return AddFriendWithCheck(appId, groupId, roleAppId);
return AddFriendWithCheck(osAccountId, appId, groupId, roleAppId);
}
static int32_t DeleteGroupRoleWithCheck(bool isManager, const char *appId, const char *groupId, const char *roleAppId)
static int32_t DeleteGroupRoleWithCheck(int32_t osAccountId, bool isManager, const char *appId, const char *groupId,
const char *roleAppId)
{
if (isManager) {
return DeleteManagerWithCheck(appId, groupId, roleAppId);
return DeleteManagerWithCheck(osAccountId, appId, groupId, roleAppId);
}
return DeleteFriendWithCheck(appId, groupId, roleAppId);
return DeleteFriendWithCheck(osAccountId, appId, groupId, roleAppId);
}
static int32_t GetGroupRolesWithCheck(bool isManager, const char *appId, const char *groupId, char **returnJsonStr,
uint32_t *returnSize)
static int32_t GetGroupRolesWithCheck(int32_t osAccountId, bool isManager, const char *appId, const char *groupId,
char **returnJsonStr, uint32_t *returnSize)
{
if (isManager) {
return GetManagersWithCheck(appId, groupId, returnJsonStr, returnSize);
return GetManagersWithCheck(osAccountId, appId, groupId, returnJsonStr, returnSize);
}
return GetFriendsWithCheck(appId, groupId, returnJsonStr, returnSize);
return GetFriendsWithCheck(osAccountId, appId, groupId, returnJsonStr, returnSize);
}
static PeerToPeerGroup g_peerToPeerGroup = {

View File

@ -24,5 +24,5 @@ BaseGroup *GetPeerToPeerGroupInstance(void)
bool IsPeerToPeerGroupSupported(void)
{
return false;
return true;
}

View File

@ -136,7 +136,7 @@ static void OnBindChannelOpened(Session *session, int64_t channelId, int64_t req
static int32_t PrepareClient(const CJson *jsonParams, BindSession *session)
{
int32_t result = GenerateBindParams(CLIENT, jsonParams, session);
int32_t result = GenerateBindParams(session->osAccountId, CLIENT, jsonParams, session);
if (result != HC_SUCCESS) {
return result;
}

View File

@ -17,7 +17,7 @@
#include "bind_session_common_util.h"
#include "callback_manager.h"
#include "channel_manager.h"
#include "database_manager.h"
#include "data_manager.h"
#include "dev_auth_module_manager.h"
#include "group_operation_common.h"
#include "hc_dev_info.h"
@ -98,8 +98,10 @@ static int32_t AddRequestInfoToSendData(const BindSession *session, CJson *data)
static int32_t GenerateCompatibleInfo(CJson *groupInfo)
{
const char *udid = GetLocalDevUdid();
if (udid == NULL) {
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 (AddStringToJson(groupInfo, FIELD_DEVICE_ID, udid) != HC_SUCCESS) {
@ -279,7 +281,7 @@ static int32_t TryAddPeerUserTypeToParams(const CJson *jsonParams, BindSession *
return HC_SUCCESS;
}
static int32_t AddGroupInfoToParams(const GroupInfo *entry, CJson *params)
static int32_t AddGroupInfoToParams(const TrustedGroupEntry *entry, CJson *params)
{
if (AddStringToJson(params, FIELD_GROUP_ID, StringGet(&entry->id)) != HC_SUCCESS) {
LOGE("Failed to add groupId to json!");
@ -296,7 +298,7 @@ static int32_t AddGroupInfoToParams(const GroupInfo *entry, CJson *params)
return HC_SUCCESS;
}
static int32_t AddDevInfoToParams(const DeviceInfo *devAuthParams, CJson *params)
static int32_t AddDevInfoToParams(const TrustedDeviceEntry *devAuthParams, CJson *params)
{
if (AddStringToJson(params, FIELD_AUTH_ID, StringGet(&devAuthParams->authId)) != HC_SUCCESS) {
LOGE("Failed to add authId to params!");
@ -313,47 +315,49 @@ static int32_t AddDevInfoToParams(const DeviceInfo *devAuthParams, CJson *params
return HC_SUCCESS;
}
static int32_t AddGroupInfoByDatabase(const char *groupId, CJson *params)
static int32_t AddGroupInfoByDatabase(int32_t osAccountId, const char *groupId, CJson *params)
{
GroupInfo *entry = CreateGroupInfoStruct();
TrustedGroupEntry *entry = CreateGroupEntry();
if (entry == NULL) {
LOGE("Failed to allocate groupEntry memory!");
return HC_ERR_ALLOC_MEMORY;
}
if (GetGroupInfoById(groupId, entry) != HC_SUCCESS) {
if (GetGroupInfoById(osAccountId, groupId, entry) != HC_SUCCESS) {
LOGE("Failed to obtain the group information from the database!");
DestroyGroupInfoStruct(entry);
DestroyGroupEntry(entry);
return HC_ERR_DB;
}
if (AddGroupInfoToParams(entry, params) != HC_SUCCESS) {
DestroyGroupInfoStruct(entry);
DestroyGroupEntry(entry);
return HC_ERR_JSON_FAIL;
}
DestroyGroupInfoStruct(entry);
DestroyGroupEntry(entry);
return HC_SUCCESS;
}
static int32_t AddDevInfoByDatabase(const char *groupId, CJson *params)
static int32_t AddDevInfoByDatabase(int32_t osAccountId, const char *groupId, CJson *params)
{
const char *udid = GetLocalDevUdid();
if (udid == NULL) {
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;
}
DeviceInfo *devAuthParams = CreateDeviceInfoStruct();
TrustedDeviceEntry *devAuthParams = CreateDeviceEntry();
if (devAuthParams == NULL) {
LOGE("Failed to allocate devEntry memory!");
return HC_ERR_ALLOC_MEMORY;
}
if (GetTrustedDevInfoById(udid, true, groupId, devAuthParams) != HC_SUCCESS) {
if (GetTrustedDevInfoById(osAccountId, udid, true, groupId, devAuthParams) != HC_SUCCESS) {
LOGE("Failed to obtain the device information from the database!");
DestroyDeviceInfoStruct(devAuthParams);
DestroyDeviceEntry(devAuthParams);
return HC_ERR_DB;
}
if (AddDevInfoToParams(devAuthParams, params) != HC_SUCCESS) {
DestroyDeviceInfoStruct(devAuthParams);
DestroyDeviceEntry(devAuthParams);
return HC_ERR_JSON_FAIL;
}
DestroyDeviceInfoStruct(devAuthParams);
DestroyDeviceEntry(devAuthParams);
return HC_SUCCESS;
}
@ -440,37 +444,40 @@ static int32_t AddExpireTimeIfValidOrDefault(const CJson *jsonParams, CJson *par
return HC_SUCCESS;
}
static int32_t CheckAuthIdAndUserTypeValid(int userType, const char *groupId, const char *authId)
static int32_t CheckAuthIdAndUserTypeValid(int32_t osAccountId, int userType, const char *groupId, const char *authId)
{
if (!IsGroupExistByGroupId(groupId)) {
if (!IsGroupExistByGroupId(osAccountId, groupId)) {
return HC_SUCCESS;
}
const char *udid = GetLocalDevUdid();
if (udid == NULL) {
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;
}
DeviceInfo *deviceInfo = CreateDeviceInfoStruct();
TrustedDeviceEntry *deviceInfo = CreateDeviceEntry();
if (deviceInfo == NULL) {
LOGE("Failed to allocate deviceInfo memory!");
return HC_ERR_ALLOC_MEMORY;
}
int32_t result = GetTrustedDevInfoById(udid, true, groupId, deviceInfo);
int32_t result = GetTrustedDevInfoById(osAccountId, udid, true, groupId, deviceInfo);
if (result != HC_SUCCESS) {
LOGE("Failed to obtain the local device information from the database!");
DestroyDeviceInfoStruct(deviceInfo);
DestroyDeviceEntry(deviceInfo);
return result;
}
const char *oriAuthId = StringGet(&deviceInfo->authId);
if ((deviceInfo->devType != userType) || ((oriAuthId != NULL) && (strcmp(oriAuthId, authId) != 0))) {
LOGE("Once a group is created, the service cannot change the local authId and userType used in the group!");
DestroyDeviceInfoStruct(deviceInfo);
DestroyDeviceEntry(deviceInfo);
return HC_ERR_INVALID_PARAMS;
}
DestroyDeviceInfoStruct(deviceInfo);
DestroyDeviceEntry(deviceInfo);
return HC_SUCCESS;
}
static int32_t AddAuthIdAndUserTypeIfValidOrDefault(const char *groupId, const CJson *jsonParams, CJson *params)
static int32_t AddAuthIdAndUserTypeIfValidOrDefault(int32_t osAccountId, const char *groupId, const CJson *jsonParams,
CJson *params)
{
int32_t userType = DEVICE_TYPE_ACCESSORY;
(void)GetIntFromJson(jsonParams, FIELD_USER_TYPE, &userType);
@ -481,12 +488,18 @@ static int32_t AddAuthIdAndUserTypeIfValidOrDefault(const char *groupId, const C
const char *authId = GetStringFromJson(jsonParams, FIELD_DEVICE_ID);
if (authId == NULL) {
LOGD("No authId is found. The default value is udid!");
authId = GetLocalDevUdid();
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;
}
authId = udid;
if (authId == NULL) {
return HC_ERR_DB;
}
}
int32_t result = CheckAuthIdAndUserTypeValid(userType, groupId, authId);
int32_t result = CheckAuthIdAndUserTypeValid(osAccountId, userType, groupId, authId);
if (result != HC_SUCCESS) {
return result;
}
@ -503,8 +516,10 @@ static int32_t AddAuthIdAndUserTypeIfValidOrDefault(const char *groupId, const C
static int32_t AddUdid(CJson *params)
{
const char *udid = GetLocalDevUdid();
if (udid == NULL) {
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 (AddStringToJson(params, FIELD_CONN_DEVICE_ID, udid) != HC_SUCCESS) {
@ -543,10 +558,11 @@ static int32_t AddGroupInfoToSessionParams(const char *groupId, const CJson *jso
return HC_SUCCESS;
}
static int32_t AddDevInfoToSessionParams(const char *groupId, const CJson *jsonParams, CJson *params)
static int32_t AddDevInfoToSessionParams(int32_t osAccountId, const char *groupId, const CJson *jsonParams,
CJson *params)
{
int32_t result;
if (((result = AddAuthIdAndUserTypeIfValidOrDefault(groupId, jsonParams, params)) != HC_SUCCESS) ||
if (((result = AddAuthIdAndUserTypeIfValidOrDefault(osAccountId, groupId, jsonParams, params)) != HC_SUCCESS) ||
((result = AddUdid(params)) != HC_SUCCESS) ||
((result = AddUserTypeIfValidOrDefault(jsonParams, params)) != HC_SUCCESS)) {
return result;
@ -554,22 +570,22 @@ static int32_t AddDevInfoToSessionParams(const char *groupId, const CJson *jsonP
return HC_SUCCESS;
}
static int32_t GenerateParamsByInput(const char *groupId, const CJson *jsonParams, CJson *params)
static int32_t GenerateParamsByInput(int32_t osAccountId, const char *groupId, const CJson *jsonParams, CJson *params)
{
int32_t result = AddGroupInfoToSessionParams(groupId, jsonParams, params);
if (result != HC_SUCCESS) {
return result;
}
return AddDevInfoToSessionParams(groupId, jsonParams, params);
return AddDevInfoToSessionParams(osAccountId, groupId, jsonParams, params);
}
static int32_t GenerateParamsByDatabase(const char *groupId, CJson *params)
static int32_t GenerateParamsByDatabase(int32_t osAccountId, const char *groupId, CJson *params)
{
int32_t result = AddGroupInfoByDatabase(groupId, params);
int32_t result = AddGroupInfoByDatabase(osAccountId, groupId, params);
if (result != HC_SUCCESS) {
return result;
}
return AddDevInfoByDatabase(groupId, params);
return AddDevInfoByDatabase(osAccountId, groupId, params);
}
static int32_t AddIsForceDeleteIfNeed(int isClient, const CJson *jsonParams, BindSession *session)
@ -664,21 +680,21 @@ static int32_t AddPeerUserTypeIfDelete(BindSession *session)
LOGE("Failed to get groupId from params!");
return HC_ERR_JSON_GET;
}
DeviceInfo *devAuthParams = CreateDeviceInfoStruct();
TrustedDeviceEntry *devAuthParams = CreateDeviceEntry();
if (devAuthParams == NULL) {
LOGE("Failed to allocate devEntry memory!");
return HC_ERR_ALLOC_MEMORY;
}
if (GetTrustedDevInfoById(peerAuthId, false, groupId, devAuthParams) != HC_SUCCESS) {
if (GetTrustedDevInfoById(session->osAccountId, peerAuthId, false, groupId, devAuthParams) != HC_SUCCESS) {
LOGE("Failed to obtain the device information from the database!");
DestroyDeviceInfoStruct(devAuthParams);
DestroyDeviceEntry(devAuthParams);
return HC_ERR_DB;
}
if (AddIntToJson(session->params, FIELD_PEER_USER_TYPE, devAuthParams->devType) != HC_SUCCESS) {
DestroyDeviceInfoStruct(devAuthParams);
DestroyDeviceEntry(devAuthParams);
return HC_ERR_JSON_FAIL;
}
DestroyDeviceInfoStruct(devAuthParams);
DestroyDeviceEntry(devAuthParams);
return HC_SUCCESS;
}
@ -694,7 +710,7 @@ static int32_t AddPeerDevInfoIfNeed(bool isClient, const CJson *jsonParams, Bind
return AddPeerAuthIdAndUdidIfExist(jsonParams, session);
}
static int32_t AddGroupAndDevInfo(int isClient, const CJson *jsonParams, BindSession *session)
static int32_t AddGroupAndDevInfo(int32_t osAccountId, int isClient, const CJson *jsonParams, BindSession *session)
{
const char *groupId = GetStringFromJson(jsonParams, FIELD_GROUP_ID);
if (groupId == NULL) {
@ -702,9 +718,9 @@ static int32_t AddGroupAndDevInfo(int isClient, const CJson *jsonParams, BindSes
return HC_ERR_JSON_GET;
}
if (NeedCreateGroup(isClient, session->opCode)) {
return GenerateParamsByInput(groupId, jsonParams, session->params);
return GenerateParamsByInput(osAccountId, groupId, jsonParams, session->params);
} else {
return GenerateParamsByDatabase(groupId, session->params);
return GenerateParamsByDatabase(session->osAccountId, groupId, session->params);
}
}
@ -752,7 +768,7 @@ static int32_t InformSelfUnbindSuccess(const char *peerAuthId, const char *group
return HC_SUCCESS;
}
static int32_t SetGroupId(const CJson *params, GroupInfo *groupParams)
static int32_t SetGroupId(const CJson *params, TrustedGroupEntry *groupParams)
{
const char *groupId = GetStringFromJson(params, FIELD_GROUP_ID);
if (groupId == NULL) {
@ -766,7 +782,7 @@ static int32_t SetGroupId(const CJson *params, GroupInfo *groupParams)
return HC_SUCCESS;
}
static int32_t SetGroupName(const CJson *params, GroupInfo *groupParams)
static int32_t SetGroupName(const CJson *params, TrustedGroupEntry *groupParams)
{
const char *groupName = GetStringFromJson(params, FIELD_GROUP_NAME);
if (groupName == NULL) {
@ -780,27 +796,29 @@ static int32_t SetGroupName(const CJson *params, GroupInfo *groupParams)
return HC_SUCCESS;
}
static int32_t SetGroupOwner(const char *ownerAppId, GroupInfo *groupParams)
static int32_t SetGroupOwner(const char *ownerAppId, TrustedGroupEntry *groupParams)
{
if (!StringSetPointer(&groupParams->ownerName, ownerAppId)) {
HcString ownerName = CreateString();
if (!StringSetPointer(&ownerName, ownerAppId)) {
LOGE("Failed to copy groupOwner!");
return HC_ERR_MEMORY_COPY;
}
if (groupParams->managers.pushBackT(&groupParams->managers, ownerName) == NULL) {
LOGE("Failed to push owner to vec!");
return HC_ERR_MEMORY_COPY;
}
return HC_SUCCESS;
}
static int32_t SetGroupType(const CJson *params, GroupInfo *groupParams)
static int32_t SetGroupType(const CJson *params, TrustedGroupEntry *groupParams)
{
int32_t groupType = PEER_TO_PEER_GROUP;
if (GetIntFromJson(params, FIELD_GROUP_TYPE, &groupType) != HC_SUCCESS) {
LOGE("Failed to get groupType from params!");
return HC_ERR_JSON_GET;
}
groupParams->type = groupType;
/* Currently, only peer to peer group is supported. */
(void)params;
groupParams->type = PEER_TO_PEER_GROUP;
return HC_SUCCESS;
}
static int32_t SetGroupVisibility(const CJson *params, GroupInfo *groupParams)
static int32_t SetGroupVisibility(const CJson *params, TrustedGroupEntry *groupParams)
{
int32_t groupVisibility = GROUP_VISIBILITY_PUBLIC;
(void)GetIntFromJson(params, FIELD_GROUP_VISIBILITY, &groupVisibility);
@ -808,7 +826,7 @@ static int32_t SetGroupVisibility(const CJson *params, GroupInfo *groupParams)
return HC_SUCCESS;
}
static int32_t SetGroupExpireTime(const CJson *params, GroupInfo *groupParams)
static int32_t SetGroupExpireTime(const CJson *params, TrustedGroupEntry *groupParams)
{
int32_t expireTime = DEFAULT_EXPIRE_TIME;
(void)GetIntFromJson(params, FIELD_EXPIRE_TIME, &expireTime);
@ -839,7 +857,7 @@ static int32_t ForceDeletePeerKey(CJson *params)
return DeletePeerAuthInfo(appId, groupId, &peerAuthIdBuff, peerUserType, DAS_MODULE);
}
static int32_t GenerateGroupParams(const BindSession *session, GroupInfo *groupParams)
static int32_t GenerateGroupParams(const BindSession *session, TrustedGroupEntry *groupParams)
{
int32_t result;
if (((result = SetGroupId(session->params, groupParams)) != HC_SUCCESS) ||
@ -855,7 +873,7 @@ static int32_t GenerateGroupParams(const BindSession *session, GroupInfo *groupP
static int32_t AddGroupToDatabase(const BindSession *session)
{
GroupInfo *groupParams = CreateGroupInfoStruct();
TrustedGroupEntry *groupParams = CreateGroupEntry();
if (groupParams == NULL) {
LOGE("Failed to allocate groupParams memory!");
return HC_ERR_ALLOC_MEMORY;
@ -863,11 +881,11 @@ static int32_t AddGroupToDatabase(const BindSession *session)
int32_t result = GenerateGroupParams(session, groupParams);
if (result != HC_SUCCESS) {
LOGE("Failed to generate groupParams!");
DestroyGroupInfoStruct(groupParams);
DestroyGroupEntry(groupParams);
return HC_ERR_DB;
}
result = AddGroup(groupParams);
DestroyGroupInfoStruct(groupParams);
result = AddGroup(session->osAccountId, groupParams);
DestroyGroupEntry(groupParams);
if (result != HC_SUCCESS) {
LOGE("Failed to add the group to the database!");
return HC_ERR_DB;
@ -876,7 +894,7 @@ static int32_t AddGroupToDatabase(const BindSession *session)
}
static int32_t GenerateDevAuthParams(const char *authId, const char *udid, const char *groupId,
int userType, DeviceInfo *devAuthParams)
int userType, TrustedDeviceEntry *devAuthParams)
{
devAuthParams->devType = userType;
StringSetPointer(&(devAuthParams->authId), authId);
@ -886,9 +904,10 @@ static int32_t GenerateDevAuthParams(const char *authId, const char *udid, const
return HC_SUCCESS;
}
static int32_t AddTrustDevToDatabase(const char *authId, const char *udid, const char *groupId, int userType)
static int32_t AddTrustDevToDatabase(int32_t osAccountId, const char *authId, const char *udid, const char *groupId,
int userType)
{
DeviceInfo *devAuthParams = CreateDeviceInfoStruct();
TrustedDeviceEntry *devAuthParams = CreateDeviceEntry();
if (devAuthParams == NULL) {
LOGE("Failed to allocate devAuthParams memory!");
return HC_ERR_ALLOC_MEMORY;
@ -896,11 +915,11 @@ static int32_t AddTrustDevToDatabase(const char *authId, const char *udid, const
int32_t result = GenerateDevAuthParams(authId, udid, groupId, userType, devAuthParams);
if (result != HC_SUCCESS) {
LOGE("Failed to generate devAuthParams!");
DestroyDeviceInfoStruct(devAuthParams);
DestroyDeviceEntry(devAuthParams);
return result;
}
result = AddTrustedDevice(devAuthParams, NULL);
DestroyDeviceInfoStruct(devAuthParams);
result = AddTrustedDevice(osAccountId, devAuthParams);
DestroyDeviceEntry(devAuthParams);
if (result != HC_SUCCESS) {
LOGE("Failed to add the trusted devices to the database!");
return HC_ERR_DB;
@ -910,34 +929,39 @@ static int32_t AddTrustDevToDatabase(const char *authId, const char *udid, const
static int32_t AddGroupAndLocalDevIfNotExist(const char *groupId, const BindSession *session)
{
int32_t result = HC_SUCCESS;
if (!IsGroupExistByGroupId(groupId)) {
const char *udid = GetLocalDevUdid();
if (udid == NULL) {
return HC_ERR_DB;
}
result = AddGroupToDatabase(session);
if (result != HC_SUCCESS) {
return result;
}
const char *authId = GetStringFromJson(session->params, FIELD_AUTH_ID);
if (authId == NULL) {
LOGI("No authId is found. The default value is udid!");
authId = udid;
}
int32_t userType = DEVICE_TYPE_ACCESSORY;
(void)GetIntFromJson(session->params, FIELD_USER_TYPE, &userType);
return AddTrustDevToDatabase(authId, udid, groupId, userType);
if (IsGroupExistByGroupId(session->osAccountId, groupId)) {
return HC_SUCCESS;
}
return result;
int32_t result = HC_SUCCESS;
char udid[INPUT_UDID_LEN] = { 0 };
result = HcGetUdid((uint8_t *)udid, INPUT_UDID_LEN);
if (result != HC_SUCCESS) {
LOGE("Failed to get local udid! res: %d", result);
return HC_ERR_DB;
}
result = AddGroupToDatabase(session);
if (result != HC_SUCCESS) {
return result;
}
const char *authId = GetStringFromJson(session->params, FIELD_AUTH_ID);
if (authId == NULL) {
LOGI("No authId is found. The default value is udid!");
authId = udid;
}
int32_t userType = DEVICE_TYPE_ACCESSORY;
(void)GetIntFromJson(session->params, FIELD_USER_TYPE, &userType);
return AddTrustDevToDatabase(session->osAccountId, authId, udid, groupId, userType);
}
static int32_t AddPeerDevToGroup(const char *peerAuthId, const char *peerUdid,
const char *groupId, const BindSession *session)
{
if (IsTrustedDeviceInGroup(groupId, peerAuthId, false)) {
if (IsTrustedDeviceInGroup(session->osAccountId, groupId, peerUdid, true)) {
LOGI("The peer device already exists in the group! RequestId: %" PRId64, session->reqId);
if (DelTrustedDevice(peerAuthId, false, groupId) != HC_SUCCESS) {
QueryDeviceParams params = InitQueryDeviceParams();
params.groupId = groupId;
params.udid = peerUdid;
if (DelTrustedDevice(session->osAccountId, &params) != HC_SUCCESS) {
LOGE("Failed to delete the original data! RequestId: %" PRId64, session->reqId);
return HC_ERR_DB;
}
@ -945,7 +969,7 @@ static int32_t AddPeerDevToGroup(const char *peerAuthId, const char *peerUdid,
}
int32_t peerUserType = DEVICE_TYPE_ACCESSORY;
(void)GetIntFromJson(session->params, FIELD_PEER_USER_TYPE, &peerUserType);
int32_t result = AddTrustDevToDatabase(peerAuthId, peerUdid, groupId, peerUserType);
int32_t result = AddTrustDevToDatabase(session->osAccountId, peerAuthId, peerUdid, groupId, peerUserType);
if (result != HC_SUCCESS) {
LOGE("Failed to update the peer trusted device information! RequestId: %" PRId64, session->reqId);
return result;
@ -961,7 +985,11 @@ static int32_t AddGroupAndDev(const char *peerAuthId, const char *peerUdid,
if (result != HC_SUCCESS) {
return result;
}
return AddPeerDevToGroup(peerAuthId, peerUdid, groupId, session);
result = AddPeerDevToGroup(peerAuthId, peerUdid, groupId, session);
if (result != HC_SUCCESS) {
return result;
}
return SaveOsAccountDb(session->osAccountId);
}
static int32_t HandleBindSuccess(const char *peerAuthId, const char *peerUdid,
@ -976,8 +1004,12 @@ static int32_t HandleBindSuccess(const char *peerAuthId, const char *peerUdid,
static int32_t HandleUnbindSuccess(const char *peerAuthId, const char *groupId, const BindSession *session)
{
if (IsGroupExistByGroupId(groupId)) {
if (DelTrustedDevice(peerAuthId, false, groupId) != HC_SUCCESS) {
if (IsGroupExistByGroupId(session->osAccountId, groupId)) {
QueryDeviceParams params = InitQueryDeviceParams();
params.groupId = groupId;
params.authId = peerAuthId;
if (DelTrustedDevice(session->osAccountId, &params) != HC_SUCCESS ||
SaveOsAccountDb(session->osAccountId) != HC_SUCCESS) {
LOGE("Failed to unbind device from database!");
return HC_ERR_DB;
}
@ -1136,16 +1168,19 @@ int32_t ForceUnbindDevice(const BindSession *session)
LOGE("Failed to get groupId from jsonParams!");
return HC_ERR_JSON_GET;
}
int32_t result = DelTrustedDevice(peerAuthId, false, groupId);
if (result != HC_SUCCESS) {
QueryDeviceParams queryDeviceParams = InitQueryDeviceParams();
queryDeviceParams.groupId = groupId;
queryDeviceParams.authId = peerAuthId;
if (DelTrustedDevice(session->osAccountId, &queryDeviceParams) != HC_SUCCESS ||
SaveOsAccountDb(session->osAccountId) != HC_SUCCESS) {
LOGE("Failed to delete trust device from database!");
return result;
return HC_ERR_DB;
}
/*
* If the trusted device has been deleted from the database but the peer key fails to be deleted,
* the forcible unbinding is still considered successful. Only logs need to be printed.
*/
result = ForceDeletePeerKey(session->params);
int32_t result = ForceDeletePeerKey(session->params);
if (result != HC_SUCCESS) {
LOGE("Failed to delete peer key!");
}
@ -1160,7 +1195,7 @@ int32_t ForceUnbindDevice(const BindSession *session)
return HC_SUCCESS;
}
int32_t GenerateBindParams(int isClient, const CJson *jsonParams, BindSession *session)
int32_t GenerateBindParams(int32_t osAccountId, int isClient, const CJson *jsonParams, BindSession *session)
{
if (session->params == NULL) {
session->params = CreateJson();
@ -1174,7 +1209,7 @@ int32_t GenerateBindParams(int isClient, const CJson *jsonParams, BindSession *s
if (((result = AddIsForceDeleteIfNeed(isClient, jsonParams, session)) != HC_SUCCESS) ||
((result = AddChannelIdIfNeed(isClient, jsonParams, session)) != HC_SUCCESS) ||
((result = AddPinCodeIfNeed(jsonParams, session)) != HC_SUCCESS) ||
((result = AddGroupAndDevInfo(isClient, jsonParams, session)) != HC_SUCCESS) ||
((result = AddGroupAndDevInfo(osAccountId, isClient, jsonParams, session)) != HC_SUCCESS) ||
((result = AddPeerDevInfoIfNeed(isClient, jsonParams, session)) != HC_SUCCESS)) {
return result;
}

View File

@ -20,6 +20,7 @@
#include "das_module_defines.h"
#include "group_operation_common.h"
#include "hc_log.h"
#include "os_account_adapter.h"
#include "session_manager.h"
static int32_t AddRecvModuleDataToParams(CJson *jsonParams, CJson *moduleParams)
@ -311,6 +312,49 @@ static int32_t CombineInputData(int operationCode, const CJson *returnData, CJso
}
}
static int32_t CheckServerStatusIfNotInvite(int32_t osAccountId, int operationCode, const CJson *jsonParams)
{
if (operationCode == MEMBER_INVITE) {
return HC_SUCCESS;
}
const char *groupId = GetStringFromJson(jsonParams, FIELD_GROUP_ID);
if (groupId == NULL) {
LOGE("Failed to get groupId from jsonParams!");
return HC_ERR_JSON_GET;
}
const char *appId = GetStringFromJson(jsonParams, FIELD_APP_ID);
if (appId == NULL) {
LOGE("Failed to get appId from jsonParams!");
return HC_ERR_JSON_GET;
}
const char *peerUdid = GetStringFromJson(jsonParams, FIELD_CONN_DEVICE_ID);
if (peerUdid == NULL) {
LOGE("Failed to get peerUdid from jsonParams!");
return HC_ERR_JSON_GET;
}
int32_t result = CheckGroupExist(osAccountId, groupId);
if (result != HC_SUCCESS) {
return result;
}
if (operationCode == MEMBER_JOIN) {
/* The client sends a join request, which is equivalent to the server performing an invitation operation. */
result = CheckPermForGroup(osAccountId, MEMBER_INVITE, appId, groupId);
if (result != HC_SUCCESS) {
return result;
}
result = CheckDeviceNumLimit(osAccountId, groupId, peerUdid);
} else if (operationCode == MEMBER_DELETE) {
result = CheckPermForGroup(osAccountId, MEMBER_DELETE, appId, groupId);
if (result != HC_SUCCESS) {
return result;
}
if (!IsTrustedDeviceInGroup(osAccountId, groupId, peerUdid, true)) {
result = HC_ERR_DEVICE_NOT_EXIST;
}
}
return result;
}
static int32_t PrepareServer(BindSession *session, CJson *returnData, bool *isNeedInform)
{
if ((session->isWaiting) && (!IsAcceptRequest(returnData))) {
@ -322,7 +366,20 @@ static int32_t PrepareServer(BindSession *session, CJson *returnData, bool *isNe
LOGE("Received data before request confirmation are lost!");
return HC_ERR_LOST_DATA;
}
int32_t result = CombineInputData(session->opCode, returnData, jsonParams);
int32_t osAccountId = ANY_OS_ACCOUNT;
(void)GetIntFromJson(returnData, FIELD_OS_ACCOUNT_ID, &osAccountId);
osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId);
if (osAccountId == INVALID_OS_ACCOUNT) {
FreeJson(jsonParams);
return HC_ERR_INVALID_PARAMS;
}
int32_t result = CheckServerStatusIfNotInvite(osAccountId, session->opCode, jsonParams);
if (result != HC_SUCCESS) {
FreeJson(jsonParams);
return result;
}
session->osAccountId = osAccountId;
result = CombineInputData(session->opCode, returnData, jsonParams);
/* Release the memory in advance to reduce the memory usage. */
DeleteAllItem(returnData);
session->isWaiting = false;
@ -330,7 +387,7 @@ static int32_t PrepareServer(BindSession *session, CJson *returnData, bool *isNe
FreeJson(jsonParams);
return result;
}
result = GenerateBindParams(SERVER, jsonParams, session);
result = GenerateBindParams(osAccountId, SERVER, jsonParams, session);
if (result != HC_SUCCESS) {
FreeJson(jsonParams);
return result;

View File

@ -82,10 +82,13 @@ BindSession *CreateBaseBindSession(int32_t sessionType, int32_t opCode, const CJ
HcFree(session);
return NULL;
}
int32_t osAccountId = 0;
(void)GetIntFromJson(params, FIELD_OS_ACCOUNT_ID, &osAccountId);
session->base.type = sessionType;
session->base.process = func;
session->base.destroy = DestroyBindSession;
session->base.callback = callback;
session->osAccountId = osAccountId;
session->curTaskId = 0;
session->opCode = opCode;
session->moduleType = DAS_MODULE;

View File

@ -19,21 +19,25 @@ module_output_path = "deviceauth_standard/deviceauth_test"
ohos_unittest("deviceauth_llt") {
module_out_path = module_output_path
include_dirs = [
include_dirs = inc_path
include_dirs += hals_inc_path
include_dirs += [
"./include",
"//third_party/json/include",
"//utils/native/base/include",
"//foundation/communication/dsoftbus/interfaces/kits/common",
"//foundation/communication/dsoftbus/interfaces/kits/transport",
"//foundation/communication/dsoftbus/interfaces/inner_kits/transport",
"//base/account/os_account/interfaces/innerkits/osaccount/native/include",
]
include_dirs += inc_path
include_dirs += hals_inc_path
sources = [
"${common_lib_path}/impl/src/clib_types.c",
"${common_lib_path}/impl/src/hc_parcel.c",
"${common_lib_path}/impl/src/hc_string.c",
"${common_lib_path}/impl/src/hc_string_vector.c",
"${common_lib_path}/impl/src/hc_tlv_parser.c",
"${common_lib_path}/impl/src/json_utils.c",
"${common_lib_path}/impl/src/string_util.c",
@ -67,5 +71,6 @@ ohos_unittest("deviceauth_llt") {
external_deps = [
"dsoftbus_standard:softbus_client",
"hiviewdfx_hilog_native:libhilog",
"os_account_standard:os_account_innerkits",
]
}

View File

@ -16,93 +16,5 @@
#ifndef DEVICEAUTH_STANDARD_TEST_H
#define DEVICEAUTH_STANDARD_TEST_H
#include <cstdint>
#include "gtest/gtest.h"
#include "gmock/gmock.h"
extern "C" {
#include "device_auth.h"
}
namespace {
const char *TEST_APP_NAME = "TestApp";
const int32_t TEMP_REQUEST_ID = 123;
const int32_t BUFFER_SIZE = 2048;
const char *CLIENT_AUTH_ID = "3C58C27533D8";
const char *SERVER_AUTH_ID = "CAF34E13190CBA510AA8DABB70CDFF8E9F623656DED400EF0D4CFD9E88FD6202";
const char *PIN_CODE = "123456";
const int32_t CLIENT_REQUEST_ID = 123;
const int32_t SERVER_REQUEST_ID = 345;
const int32_t STR_BUFF_SZ_MIN = 32;
const int32_t STR_BUFF_SZ_NORMAL = 128;
const int32_t MAX_GROUP_NUMBER = 101;
}
typedef enum {
ON_REQUEST = 1,
ON_ERROR = 2,
ON_FINISH = 3,
ON_SESSION_KEY_RETURNED = 4,
ON_TRANSMIT = 5
} CallbackType;
class GET_INSTANCE : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override {}
void TearDown() override {}
};
class REGISTER_CALLBACK : public testing::Test {
public:
static void SetUpTestCase() {}
static void TearDownTestCase() {}
virtual void SetUp() override;
virtual void TearDown() override;
const DeviceGroupManager *gm = nullptr;
const GroupAuthManager *ga = nullptr;
};
class CREATE_GROUP_P2P : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
};
class AUTHENTICATE_GA : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override {}
void TearDown() override {}
};
class ADD_MEMBER_TO_GROUP : public testing::Test {
public:
static void SetUpTestCase() {};
static void TearDownTestCase() {};
void SetUp() override;
void TearDown() override;
};
class REGISTER_LISTENER : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
};
class QUERY_INTERFACE : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
};
#endif

View File

@ -23,4 +23,6 @@
void SetClient(bool tag);
bool GetClient();
const char *GetStorageDirPath(void);
#endif

View File

@ -14,431 +14,44 @@
*/
#include "deviceauth_standard_test.h"
#include "deviceauth_test_mock.h"
#include <ctime>
extern "C" {
#include <cstdint>
#include "common_defs.h"
#include "json_utils.h"
#include "deviceauth_test_mock.h"
#include "device_auth.h"
#include "device_auth_defines.h"
#include "database_manager.h"
#include "hc_condition.h"
#include "hc_mutex.h"
#include "hc_types.h"
}
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "json_utils.h"
using namespace std;
using namespace testing::ext;
static bool g_isNeedContinue = false;
static int64_t g_requestId = 0L;
static int g_operationCode = -1;
static int g_errorCode = 1;
static char *g_tempStr = nullptr;
static int g_messageCode = -1;
static char g_dataBuffer[BUFFER_SIZE] = { 0 };
static HcCondition g_testCondition;
static const DeviceGroupManager *g_testGm = nullptr;
static const GroupAuthManager *g_testGa = nullptr;
static DeviceAuthCallback g_gaCallback;
static void DelayWithMSec(int32_t mSecs)
{
struct timeval out;
out.tv_sec = 0;
out.tv_usec = mSecs * 1000;
(void)select(1, NULL, NULL, NULL, &out);
return;
}
void ClearTempValue()
{
g_isNeedContinue = false;
g_requestId = 0L;
g_operationCode = -1;
g_errorCode = 1;
g_tempStr = nullptr;
g_messageCode = -1;
}
/* delete file path success */
static int32_t RemoveDir(const char *path)
{
char strBuf[BUFFER_SIZE] = {0};
if (path == nullptr) {
return -1;
/* test suit - GET_INSTANCE */
class GET_INSTANCE : public testing::Test {
public:
static void SetUpTestCase() {};
static void TearDownTestCase() {};
virtual void SetUp()
{
int32_t ret = InitDeviceAuthService();
EXPECT_EQ(ret == HC_SUCCESS, true);
}
sprintf_s(strBuf, sizeof(strBuf) - 1, "rm -rf %s", path);
cout << strBuf << endl;
system(strBuf);
return 0;
}
static void RemoveHuks(void)
{
int ret;
ret = RemoveDir("/data/data/maindata");
cout << "[Clear] clear huks:maindata done: " << ret << endl;
ret = RemoveDir("/data/data/bakdata");
cout << "[Clear] clear huks:bakdata done: " << ret << endl;
}
static int DeleteDatabase()
{
const char *groupPath = "/data/data/deviceauth/hcgroup.dat";
int ret;
ret = RemoveDir(groupPath);
cout << "[Clear] clear db: done: " << ret << endl;
RemoveHuks();
/* wait for delete data */
DelayWithMSec(500);
return 0;
}
#define CHECK_GROUP_ID(groupInfo) const char *groupId = GetStringFromJson(groupInfo, FIELD_GROUP_ID); \
ret = strcmp(groupId, "BC680ED1137A5731F4A5A90B1AACC4A0A3663F6FC2387B7273EFBCC66A54DC0B"); \
EXPECT_EQ(ret == HC_SUCCESS, true);
#define PRINT_COST_TIME(costTime) cout << "[ TIME ] used time: " << costTime << "(ms)" << endl;
#define CHECK_EXPIRE_TIME(groupInfo, tmpExpireTime) int expireTime = 0; \
GetIntFromJson(groupInfo, FIELD_EXPIRE_TIME, &expireTime); \
EXPECT_EQ(expireTime, tmpExpireTime);
static char *OnRequestNormal(int64_t requestId, int operationCode, const char *reqParams)
{
g_messageCode = ON_REQUEST;
g_requestId = requestId;
g_operationCode = operationCode;
CJson *json = CreateJson();
AddIntToJson(json, FIELD_CONFIRMATION, REQUEST_ACCEPTED);
AddStringToJson(json, FIELD_PIN_CODE, "123456");
AddStringToJson(json, FIELD_DEVICE_ID, SERVER_AUTH_ID);
AddIntToJson(json, FIELD_USER_TYPE, DEVICE_TYPE_ACCESSORY);
AddIntToJson(json, FIELD_GROUP_VISIBILITY, GROUP_VISIBILITY_PUBLIC);
AddIntToJson(json, FIELD_EXPIRE_TIME, 90);
char *returnDataStr = PackJsonToString(json);
FreeJson(json);
return returnDataStr;
}
static void OnError(int64_t requestId, int operationCode, int errorCode, const char *errorReturn)
{
(void)errorReturn;
g_messageCode = ON_ERROR;
g_requestId = requestId;
g_operationCode = operationCode;
g_errorCode = errorCode;
g_testCondition.notify(&g_testCondition);
}
static void OnError2(int64_t requestId, int operationCode, int errorCode, const char *errorReturn)
{
(void)errorReturn;
g_messageCode = ON_ERROR;
g_requestId = requestId;
g_operationCode = operationCode;
g_errorCode = errorCode;
}
static void OnFinish(int64_t requestId, int operationCode, const char *returnData)
{
g_messageCode = ON_FINISH;
g_requestId = requestId;
g_operationCode = operationCode;
if (operationCode == GROUP_CREATE) {
CJson *json = CreateJsonFromString(returnData);
const char *groupId = GetStringFromJson(json, FIELD_GROUP_ID);
(void)memcpy_s(g_dataBuffer, BUFFER_SIZE, groupId, strlen(groupId));
FreeJson(json);
virtual void TearDown()
{
DestroyDeviceAuthService();
}
g_testCondition.notify(&g_testCondition);
}
static void OnFinish2(int64_t requestId, int operationCode, const char *returnData)
{
g_messageCode = ON_FINISH;
g_requestId = requestId;
g_operationCode = operationCode;
}
static void OnSessionKeyReturned(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen)
{
g_messageCode = ON_SESSION_KEY_RETURNED;
g_requestId = requestId;
}
static bool OnTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen)
{
g_messageCode = ON_TRANSMIT;
g_requestId = requestId;
g_isNeedContinue = true;
memset_s(g_dataBuffer, BUFFER_SIZE, 0, BUFFER_SIZE);
memcpy_s(g_dataBuffer, BUFFER_SIZE, data, dataLen);
return true;
}
static char *GaOnRequest(int64_t requestId, int operationCode, const char *reqParams)
{
g_messageCode = ON_REQUEST;
g_requestId = requestId;
g_operationCode = operationCode;
CJson *json = CreateJson();
AddIntToJson(json, FIELD_CONFIRMATION, REQUEST_ACCEPTED);
AddStringToJson(json, FIELD_SERVICE_PKG_NAME, TEST_APP_NAME);
AddStringToJson(json, FIELD_PEER_CONN_DEVICE_ID, "udid1");
char *returnDataStr = PackJsonToString(json);
FreeJson(json);
return returnDataStr;
}
enum {
GROUP_CREATED = 0,
GROUP_DELETED,
DEVICE_BOUND,
DEVICE_UNBOUND,
DEVICE_NOT_TRUSTED,
LAST_GROUP_DELETED,
TRUSTED_DEVICE_NUM_CHANGED
};
static int g_receivedMessageNum[7] = {0};
void OnGroupCreated(const char *groupInfo)
{
g_receivedMessageNum[GROUP_CREATED]++;
}
void OnGroupDeleted(const char *groupInfo)
{
g_receivedMessageNum[GROUP_DELETED]++;
}
void OnDeviceBound(const char *peerUdid, const char *groupInfo)
{
g_receivedMessageNum[DEVICE_BOUND]++;
}
void OnDeviceUnBound(const char *peerUdid, const char *groupInfo)
{
g_receivedMessageNum[DEVICE_UNBOUND]++;
}
void OnDeviceNotTrusted(const char *peerUdid)
{
g_receivedMessageNum[DEVICE_NOT_TRUSTED]++;
}
void OnLastGroupDeleted(const char *peerUdid, int groupType)
{
g_receivedMessageNum[LAST_GROUP_DELETED]++;
}
void OnTrustedDeviceNumChanged(int curTrustedDeviceNum)
{
g_receivedMessageNum[TRUSTED_DEVICE_NUM_CHANGED]++;
}
static void InitCaseResource(void)
{
int32_t ret;
const DeviceGroupManager *gmTmp = nullptr;
ret = InitDeviceAuthService();
EXPECT_EQ(ret == HC_SUCCESS, true);
gmTmp = GetGmInstance();
EXPECT_NE(gmTmp, nullptr);
g_testGm = gmTmp;
g_gaCallback.onRequest = OnRequestNormal;
g_gaCallback.onTransmit = OnTransmit;
g_gaCallback.onFinish = OnFinish;
g_gaCallback.onError = OnError;
g_gaCallback.onSessionKeyReturned = OnSessionKeyReturned;
g_testGm->regCallback(TEST_APP_NAME, &g_gaCallback);
DelayWithMSec(500);
}
static void DeInitCaseResource(void)
{
DestroyDeviceAuthService();
ClearTempValue();
g_testGm = nullptr;
}
/* test suit - GET_INSTANCE */
void GET_INSTANCE::SetUpTestCase()
{
int32_t ret;
ret = InitDeviceAuthService();
EXPECT_EQ(ret == HC_SUCCESS, true);
}
void GET_INSTANCE::TearDownTestCase()
{
DestroyDeviceAuthService();
ClearTempValue();
}
/* test suit - REGISTER_CALLBACK */
void REGISTER_CALLBACK::SetUp()
{
int32_t ret;
ret = InitDeviceAuthService();
EXPECT_EQ(ret == HC_SUCCESS, true);
gm = GetGmInstance();
EXPECT_NE(gm, nullptr);
}
void REGISTER_CALLBACK::TearDown()
{
DestroyDeviceAuthService();
ClearTempValue();
gm = nullptr;
}
/* test suit - CREATE_GROUP_P2P */
void CREATE_GROUP_P2P::SetUpTestCase()
{
InitHcCond(&g_testCondition, nullptr);
}
void CREATE_GROUP_P2P::TearDownTestCase()
{
DestroyHcCond(&g_testCondition);
}
void CREATE_GROUP_P2P::SetUp()
{
SetClient(false);
DeleteDatabase();
InitCaseResource();
}
void CREATE_GROUP_P2P::TearDown()
{
DeInitCaseResource();
}
/* test suit - AUTHENTICATE_GA */
void AUTHENTICATE_GA::SetUpTestCase()
{
int32_t ret;
ret = InitDeviceAuthService();
EXPECT_EQ(ret == HC_SUCCESS, true);
g_gaCallback = {
OnTransmit,
OnSessionKeyReturned,
OnFinish,
OnError,
GaOnRequest
};
g_testGa = GetGaInstance();
EXPECT_NE(g_testGa, nullptr);
SetClient(false);
}
void AUTHENTICATE_GA::TearDownTestCase()
{
DestroyDeviceAuthService();
DeleteDatabase();
ClearTempValue();
g_testGa = nullptr;
}
/* test suit - ADD_MEMBER_TO_GROUP */
void ADD_MEMBER_TO_GROUP::SetUp()
{
int32_t ret;
const DeviceGroupManager *gmTmp = nullptr;
DeleteDatabase();
ret = InitDeviceAuthService();
EXPECT_EQ(ret == HC_SUCCESS, true);
g_gaCallback = {
OnTransmit,
OnSessionKeyReturned,
OnFinish2,
OnError2,
OnRequestNormal
};
gmTmp = GetGmInstance();
EXPECT_NE(gmTmp, nullptr);
g_testGm = gmTmp;
ret = g_testGm->regCallback(TEST_APP_NAME, &g_gaCallback);
EXPECT_EQ(ret == HC_SUCCESS, true);
SetClient(false);
}
void ADD_MEMBER_TO_GROUP::TearDown()
{
DestroyDeviceAuthService();
DeleteDatabase();
ClearTempValue();
g_testGm = nullptr;
}
/* test suit - REGISTER_LISTENER */
void REGISTER_LISTENER::SetUpTestCase()
{
DeleteDatabase();
InitHcCond(&g_testCondition, nullptr);
}
void REGISTER_LISTENER::TearDownTestCase()
{
DestroyHcCond(&g_testCondition);
}
void REGISTER_LISTENER::SetUp()
{
InitDeviceAuthService();
g_gaCallback = {
OnTransmit,
OnSessionKeyReturned,
OnFinish,
OnError,
OnRequestNormal
};
g_testGm = GetGmInstance();
g_testGm->regCallback(TEST_APP_NAME, &g_gaCallback);
DelayWithMSec(500);
}
void REGISTER_LISTENER::TearDown()
{
DestroyDeviceAuthService();
DeleteDatabase();
ClearTempValue();
}
void QUERY_INTERFACE::SetUpTestCase()
{
DeleteDatabase();
}
void QUERY_INTERFACE::TearDownTestCase() {}
void QUERY_INTERFACE::SetUp()
{
InitDeviceAuthService();
g_gaCallback = {
OnTransmit,
OnSessionKeyReturned,
OnFinish2,
OnError2,
OnRequestNormal
};
g_testGm = GetGmInstance();
g_testGm->regCallback(TEST_APP_NAME, &g_gaCallback);
}
void QUERY_INTERFACE::TearDown()
{
DestroyDeviceAuthService();
DeleteDatabase();
ClearTempValue();
}
/* start cases */
HWTEST_F(GET_INSTANCE, TC_GET_GM_INSTANCE, TestSize.Level0)
TEST_F(GET_INSTANCE, TC_GET_GM_INSTANCE)
{
const DeviceGroupManager *gm = GetGmInstance();
EXPECT_NE(gm, nullptr);
}
TEST_F(GET_INSTANCE, TC_GET_GA_INSTANCE)
{
const GroupAuthManager *ga = GetGaInstance();
EXPECT_NE(ga, nullptr);
}

View File

@ -14,9 +14,12 @@
*/
#include "deviceauth_test_mock.h"
#include "iostream"
#include <cstring>
#include "securec.h"
using namespace std;
static bool g_testForClient = false;
void SetClient(bool tag)
@ -41,7 +44,17 @@ int32_t HcGetUdid(uint8_t *udid, int32_t udidLen)
return 0;
}
const char *GetStoragePath()
const char *GetStoragePath(void)
{
return "/data/data/deviceauth/hcgroup.dat";
}
const char *GetStorageDirPath(void)
{
#ifndef LITE_DEVICE
const char *storageFile = "/data/data/deviceauth";
#else
const char *storageFile = "/storage/deviceauth";
#endif
return storageFile;
}