diff --git a/services/common/inc/device_auth_common.h b/services/common/inc/device_auth_common.h new file mode 100644 index 0000000000000000000000000000000000000000..0e11ac6df8ee8090e15d6eea4cae41fd78fd5e8d --- /dev/null +++ b/services/common/inc/device_auth_common.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022-2023 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 DEVICE_AUTH_COMMON_H +#define DEVICE_AUTH_COMMON_H + +#include "common_defs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t AddOsAccountIdToContextIfValid(CJson *context); +int32_t CheckConfirmationExist(const CJson *context); +int32_t AddChannelInfoToContext(int32_t channelType, int64_t channelId, CJson *context); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/services/common/inc/hisysevent_common.h b/services/common/inc/hisysevent_common.h new file mode 100644 index 0000000000000000000000000000000000000000..35437083b53acd24fb966161f2efc99a08def528 --- /dev/null +++ b/services/common/inc/hisysevent_common.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022-2023 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 HISYSEVENT_COMMON_H +#define HISYSEVENT_COMMON_H + +#include +#include +#include "hisysevent_adapter.h" + +#ifdef __cplusplus +extern "C" { +#endif + +const char *GetAddMemberCallEventFuncName(const char *addParams); +DevAuthBizScene GetBizScene(bool isBind, bool isClient); + +void ReportBehaviorBeginEvent(bool isBind, bool isClient, int64_t reqId); +void ReportBehaviorBeginResultEvent(bool isBind, bool isClient, int64_t reqId, const char *peerUdid, int32_t res); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/services/common/src/device_auth_common.c b/services/common/src/device_auth_common.c new file mode 100644 index 0000000000000000000000000000000000000000..a554b857b0aa7112c11c1571ad10e1081543fe8a --- /dev/null +++ b/services/common/src/device_auth_common.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2025 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_common.h" +#include "hc_log.h" + +int32_t AddOsAccountIdToContextIfValid(CJson *context) +{ + int32_t osAccountId = ANY_OS_ACCOUNT; + (void)GetIntFromJson(context, FIELD_OS_ACCOUNT_ID, &osAccountId); + osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId); + LOGI("[OsAccountId]: %" LOG_PUB "d", osAccountId); + if (osAccountId == INVALID_OS_ACCOUNT) { + return HC_ERR_INVALID_PARAMS; + } + if (!CheckIsForegroundOsAccountId(osAccountId)) { + LOGE("This access is not from the foreground user, rejected it."); + return HC_ERR_CROSS_USER_ACCESS; + } + if (!IsOsAccountUnlocked(osAccountId)) { + LOGE("Os account is not unlocked!"); + return HC_ERR_OS_ACCOUNT_NOT_UNLOCKED; + } + if (AddIntToJson(context, FIELD_OS_ACCOUNT_ID, osAccountId) != HC_SUCCESS) { + LOGE("add operationCode to context fail."); + return HC_ERR_JSON_ADD; + } + return HC_SUCCESS; +} + +int32_t CheckConfirmationExist(const CJson *context) +{ + uint32_t confirmation = REQUEST_REJECTED; + if (GetUnsignedIntFromJson(context, FIELD_CONFIRMATION, &confirmation) != HC_SUCCESS) { + LOGE("Failed to get confimation from json!"); + return HC_ERR_JSON_GET; + } + if (confirmation == REQUEST_ACCEPTED) { + LOGI("The service accepts this request!"); + } else { + LOGW("The service rejects this request!"); + } + return HC_SUCCESS; +} + +int32_t AddChannelInfoToContext(int32_t channelType, int64_t channelId, CJson *context) +{ + if (AddIntToJson(context, FIELD_CHANNEL_TYPE, channelType) != HC_SUCCESS) { + LOGE("add channelType to context fail."); + return HC_ERR_JSON_ADD; + } + if (AddByteToJson(context, FIELD_CHANNEL_ID, (uint8_t *)&channelId, sizeof(int64_t)) != HC_SUCCESS) { + LOGE("add channelId to context fail."); + return HC_ERR_JSON_ADD; + } + return HC_SUCCESS; +} \ No newline at end of file diff --git a/services/common/src/hisysevent_common.c b/services/common/src/hisysevent_common.c new file mode 100644 index 0000000000000000000000000000000000000000..062fff836e89c55c5c7d630298997153ecf28cf2 --- /dev/null +++ b/services/common/src/hisysevent_common.c @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2025 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 "hisysevent_common.h" +#include "common_defs.h" +#include "hisysevent.h" +#include "hc_log.h" +#include "hc_dev_info.h" +#include "string_util.h" + +#ifdef DEV_AUTH_HIVIEW_ENABLE +const char *GetAddMemberCallEventFuncName(const char *addParams) +{ + if (addParams == NULL) { + LOGE("add params is null!"); + return ADD_MEMBER_EVENT; + } + CJson *in = CreateJsonFromString(addParams); + if (in == NULL) { + LOGE("Failed to create json param!"); + return ADD_MEMBER_EVENT; + } + int32_t protocolExpandVal = INVALID_PROTOCOL_EXPAND_VALUE; + (void)GetIntFromJson(in, FIELD_PROTOCOL_EXPAND, &protocolExpandVal); + FreeJson(in); + if (protocolExpandVal == LITE_PROTOCOL_STANDARD_MODE) { + return ADD_MEMBER_WITH_LITE_STANDARD; + } else if (protocolExpandVal == LITE_PROTOCOL_COMPATIBILITY_MODE) { + return ADD_MEMBER_WITH_LITE_COMPATIBILITY; + } else { + return ADD_MEMBER_EVENT; + } +} + +DevAuthBizScene GetBizScene(bool isBind, bool isClient) +{ + if (isBind) { + if (isClient) { + return BIZ_SCENE_ADD_MEMBER_CLIENT; + } else { + return BIZ_SCENE_ADD_MEMBER_SERVER; + } + } else { + if (isClient) { + return BIZ_SCENE_AUTH_DEVICE_CLIENT; + } else { + return BIZ_SCENE_AUTH_DEVICE_SERVER; + } + } +} +#endif + +void ReportBehaviorBeginEvent(bool isBind, bool isClient, int64_t reqId) +{ +#ifdef DEV_AUTH_HIVIEW_ENABLE + char *funcName = isBind ? ADD_MEMBER_EVENT : AUTH_DEV_EVENT; + DevAuthBizScene scene = GetBizScene(isBind, isClient); + DevAuthBehaviorEvent eventData = { 0 }; + BuildBehaviorEventData(&eventData, funcName, scene, BIZ_STATE_BEGIN, BIZ_STAGE_BEGIN); + char anonymousLocalUdid[ANONYMOUS_UDID_LEN + 1] = { 0 }; + if (isBind) { + eventData.hostPkg = ADD_MEMBER_HOST_PKG_NAME; + eventData.toCallPkg = ADD_MEMBER_TO_CALL_PKG_NAME; + } else { + eventData.hostPkg = AUTH_DEVICE_HOST_PKG_NAME; + char selfUdid[INPUT_UDID_LEN] = { 0 }; + (void)HcGetUdid((uint8_t *)selfUdid, INPUT_UDID_LEN); + if (GetAnonymousString(selfUdid, anonymousLocalUdid, ANONYMOUS_UDID_LEN) == HC_SUCCESS) { + eventData.localUdid = anonymousLocalUdid; + } + } + char concurrentId[MAX_REQUEST_ID_LEN] = { 0 }; + (void)sprintf_s(concurrentId, sizeof(concurrentId), "%" PRId64, reqId); + eventData.concurrentId = concurrentId; + DevAuthReportBehaviorEvent(&eventData); +#else + (void)isBind; + (void)isClient; + (void)reqId; +#endif +} + +void ReportBehaviorBeginResultEvent(bool isBind, bool isClient, int64_t reqId, const char *peerUdid, int32_t res) +{ +#ifdef DEV_AUTH_HIVIEW_ENABLE + char *funcName = isBind ? ADD_MEMBER_EVENT : AUTH_DEV_EVENT; + DevAuthBizScene scene = GetBizScene(isBind, isClient); + DevAuthBehaviorEvent eventData = { 0 }; + BuildBehaviorEventData(&eventData, funcName, scene, BIZ_STATE_PROCESS, BIZ_STAGE_BEGIN); + char anonymousLocalUdid[ANONYMOUS_UDID_LEN + 1] = { 0 }; + char anonymousPeerUdid[ANONYMOUS_UDID_LEN + 1] = { 0 }; + if (isBind) { + eventData.hostPkg = ADD_MEMBER_HOST_PKG_NAME; + eventData.toCallPkg = ADD_MEMBER_TO_CALL_PKG_NAME; + } else { + eventData.hostPkg = AUTH_DEVICE_HOST_PKG_NAME; + char selfUdid[INPUT_UDID_LEN] = { 0 }; + (void)HcGetUdid((uint8_t *)selfUdid, INPUT_UDID_LEN); + if (GetAnonymousString(selfUdid, anonymousLocalUdid, ANONYMOUS_UDID_LEN) == HC_SUCCESS) { + eventData.localUdid = anonymousLocalUdid; + } + if (GetAnonymousString(peerUdid, anonymousPeerUdid, ANONYMOUS_UDID_LEN) == HC_SUCCESS) { + eventData.peerUdid = anonymousPeerUdid; + } + } + char concurrentId[MAX_REQUEST_ID_LEN] = { 0 }; + (void)sprintf_s(concurrentId, sizeof(concurrentId), "%" PRId64, reqId); + eventData.concurrentId = concurrentId; + if (res == HC_SUCCESS) { + eventData.stageRes = STAGE_RES_SUCCESS; + } else { + eventData.stageRes = STAGE_RES_FAILED; + eventData.errorCode = res; + } + DevAuthReportBehaviorEvent(&eventData); +#else + (void)isBind; + (void)isClient; + (void)reqId; + (void)peerUdid; + (void)res; +#endif +} diff --git a/services/device_auth.c b/services/device_auth.c index 65f1e37c7fbbf03d04f43c8260684d3f4daaf643..05f7cd05a393e8ee32a7bb7474a14358dc47d3e6 100644 --- a/services/device_auth.c +++ b/services/device_auth.c @@ -29,7 +29,7 @@ #include "hc_init_protection.h" #include "hc_log.h" #include "hc_time.h" -#include "hisysevent_adapter.h" +#include "hisysevent_common.h" #include "hitrace_adapter.h" #include "json_utils.h" #include "key_manager.h" @@ -41,6 +41,7 @@ #include "identity_manager.h" #include "group_auth_manager.h" #include "account_task_manager.h" +#include "device_auth_common.h" #include "identity_service.h" #include "cred_session_util.h" @@ -61,291 +62,6 @@ static CredAuthManager *g_credAuthManager = NULL; #define CLEAN_IDENTITY_SERVICE 5 #define CLEAN_ALL 6 -typedef struct { - HcTaskBase base; - int64_t sessionId; -} StartSessionTask; - -typedef struct { - HcTaskBase base; - int64_t sessionId; - CJson *receivedMsg; -} ProcSessionTask; - -typedef struct { - HcTaskBase base; - int64_t requestId; -} SoftBusTask; - -static int32_t IsDeviceIdHashMatch(const char *udid, const char *subUdidHash) -{ - Uint8Buff udidBuf = { (uint8_t *)udid, (uint32_t)HcStrlen(udid) }; - uint8_t udidHashByte[SHA256_LEN] = { 0 }; - Uint8Buff udidHashBuf = { udidHashByte, sizeof(udidHashByte) }; - int32_t ret = GetLoaderInstance()->sha256(&udidBuf, &udidHashBuf); - if (ret != HC_SUCCESS) { - LOGE("sha256 failed, ret:%" LOG_PUB "d", ret); - return ret; - } - uint32_t udidHashLen = SHA256_LEN * BYTE_TO_HEX_OPER_LENGTH + 1; - char *udidHash = (char *)HcMalloc(udidHashLen, 0); - if (udidHash == NULL) { - LOGE("malloc udidHash string failed"); - return HC_ERR_ALLOC_MEMORY; - } - ret = ByteToHexString(udidHashByte, SHA256_LEN, udidHash, udidHashLen); - if (ret != HC_SUCCESS) { - LOGE("Byte to hexString failed, ret:%" LOG_PUB "d", ret); - HcFree(udidHash); - return ret; - } - char *subUdidHashUpper = NULL; - ret = ToUpperCase(subUdidHash, &subUdidHashUpper); - if (ret != HC_SUCCESS) { - LOGE("Failed to convert the input sub udid hash to upper case!"); - HcFree(udidHash); - return ret; - } - if (strstr((const char *)udidHash, subUdidHashUpper) != NULL) { - LOGI("udid hash is match!"); - HcFree(udidHash); - HcFree(subUdidHashUpper); - return HC_SUCCESS; - } - HcFree(udidHash); - HcFree(subUdidHashUpper); - return HC_ERROR; -} - -static const char *GetUdidByGroup(int32_t osAccountId, const char *groupId, const char *deviceIdHash) -{ - uint32_t index; - TrustedDeviceEntry **deviceEntry = NULL; - DeviceEntryVec deviceEntryVec = CREATE_HC_VECTOR(DeviceEntryVec); - QueryDeviceParams params = InitQueryDeviceParams(); - params.groupId = groupId; - if (QueryDevices(osAccountId, ¶ms, &deviceEntryVec) != HC_SUCCESS) { - LOGE("query trusted devices failed!"); - ClearDeviceEntryVec(&deviceEntryVec); - return NULL; - } - FOR_EACH_HC_VECTOR(deviceEntryVec, index, deviceEntry) { - const char *udid = StringGet(&(*deviceEntry)->udid); - if (IsDeviceIdHashMatch(udid, deviceIdHash) == HC_SUCCESS) { - ClearDeviceEntryVec(&deviceEntryVec); - return udid; - } - continue; - } - ClearDeviceEntryVec(&deviceEntryVec); - return NULL; -} - -static const char *GetDeviceIdByUdidHash(int32_t osAccountId, const char *deviceIdHash) -{ - if (deviceIdHash == NULL) { - LOGE("deviceIdHash is null"); - return NULL; - } - QueryGroupParams queryParams = InitQueryGroupParams(); - GroupEntryVec groupEntryVec = CreateGroupEntryVec(); - int32_t ret = QueryGroups(osAccountId, &queryParams, &groupEntryVec); - if (ret != HC_SUCCESS) { - LOGE("Failed to query groups!"); - ClearGroupEntryVec(&groupEntryVec); - return NULL; - } - uint32_t index; - TrustedGroupEntry **ptr = NULL; - FOR_EACH_HC_VECTOR(groupEntryVec, index, ptr) { - const TrustedGroupEntry *groupEntry = (const TrustedGroupEntry *)(*ptr); - const char *groupId = StringGet(&(groupEntry->id)); - if (groupId == NULL) { - continue; - } - const char *udid = GetUdidByGroup(osAccountId, groupId, deviceIdHash); - if (udid != NULL) { - ClearGroupEntryVec(&groupEntryVec); - return udid; - } - } - ClearGroupEntryVec(&groupEntryVec); - return NULL; -} - -static const char *GetPeerUdidFromJson(int32_t osAccountId, const CJson *in) -{ - const char *peerConnDeviceId = GetStringFromJson(in, FIELD_PEER_CONN_DEVICE_ID); - if (peerConnDeviceId == NULL) { - LOGI("get peerConnDeviceId from json fail."); - return NULL; - } - bool isUdidHash = false; - (void)GetBoolFromJson(in, FIELD_IS_UDID_HASH, &isUdidHash); - if (isUdidHash) { - const char *deviceId = GetDeviceIdByUdidHash(osAccountId, peerConnDeviceId); - return (deviceId == NULL ? peerConnDeviceId : deviceId); - } - return peerConnDeviceId; -} - -static int32_t GetOpCodeFromContext(const CJson *context) -{ - bool isAdmin = true; - (void)GetBoolFromJson(context, FIELD_IS_ADMIN, &isAdmin); - return isAdmin ? MEMBER_INVITE : MEMBER_JOIN; -} - -static int32_t AddClientReqInfoToContext(int32_t osAccountId, int64_t requestId, const char *appId, CJson *context) -{ - const char *groupId = GetStringFromJson(context, FIELD_GROUP_ID); - if (groupId == NULL) { - LOGE("get groupId from json fail."); - return HC_ERR_JSON_GET; - } - if (AddBoolToJson(context, FIELD_IS_BIND, true) != HC_SUCCESS) { - LOGE("add isBind to context fail."); - return HC_ERR_JSON_ADD; - } - if (AddBoolToJson(context, FIELD_IS_CLIENT, true) != HC_SUCCESS) { - LOGE("add isClient to context fail."); - return HC_ERR_JSON_ADD; - } - if (AddIntToJson(context, FIELD_OS_ACCOUNT_ID, osAccountId) != HC_SUCCESS) { - LOGE("add osAccountId to context fail."); - return HC_ERR_JSON_ADD; - } - if (AddInt64StringToJson(context, FIELD_REQUEST_ID, requestId) != HC_SUCCESS) { - LOGE("add requestId to context fail."); - return HC_ERR_JSON_ADD; - } - if (AddStringToJson(context, FIELD_APP_ID, appId) != HC_SUCCESS) { - LOGE("add appId to context fail."); - return HC_ERR_JSON_ADD; - } - int32_t opCode = GetOpCodeFromContext(context); - if (AddIntToJson(context, FIELD_OPERATION_CODE, opCode) != HC_SUCCESS) { - LOGE("add operationCode to context fail."); - return HC_ERR_JSON_ADD; - } - if (opCode == MEMBER_JOIN) { - return AddDevInfoToContextByInput(context); - } - int32_t res = AddDevInfoToContextByDb(groupId, context); - if (res != HC_SUCCESS) { - return res; - } - return AddGroupInfoToContextByDb(groupId, context); -} - -static int32_t AddChannelInfoToContext(int32_t channelType, int64_t channelId, CJson *context) -{ - if (AddIntToJson(context, FIELD_CHANNEL_TYPE, channelType) != HC_SUCCESS) { - LOGE("add channelType to context fail."); - return HC_ERR_JSON_ADD; - } - if (AddByteToJson(context, FIELD_CHANNEL_ID, (uint8_t *)&channelId, sizeof(int64_t)) != HC_SUCCESS) { - LOGE("add channelId to context fail."); - return HC_ERR_JSON_ADD; - } - return HC_SUCCESS; -} - -static int32_t BuildClientBindContext(int32_t osAccountId, int64_t requestId, const char *appId, - const DeviceAuthCallback *callback, CJson *context) -{ - int32_t res = AddClientReqInfoToContext(osAccountId, requestId, appId, context); - if (res != HC_SUCCESS) { - return res; - } - ChannelType channelType = GetChannelType(callback, context); - int64_t channelId; - res = OpenChannel(channelType, context, requestId, &channelId); - if (res != HC_SUCCESS) { - LOGE("open channel fail."); - return res; - } - return AddChannelInfoToContext(channelType, channelId, context); -} - -static void DoStartSession(HcTaskBase *task) -{ - LOGI("start session task begin."); - if (task == NULL) { - LOGE("The input task is NULL, can't start session!"); - return; - } - StartSessionTask *realTask = (StartSessionTask *)task; - SET_LOG_MODE(TRACE_MODE); - SET_TRACE_ID(realTask->sessionId); - int32_t res = StartDevSession(realTask->sessionId); - if (res != HC_SUCCESS) { - LOGE("start session fail.[Res]: %" LOG_PUB "d", res); - CloseDevSession(realTask->sessionId); - } -} - -static void DoProcSession(HcTaskBase *task) -{ - LOGI("proc session task begin."); - if (task == NULL) { - LOGE("The input task is NULL, can't start session!"); - return; - } - ProcSessionTask *realTask = (ProcSessionTask *)task; - SET_LOG_MODE(TRACE_MODE); - SET_TRACE_ID(realTask->sessionId); - bool isFinish = false; - int32_t res = ProcessDevSession(realTask->sessionId, realTask->receivedMsg, &isFinish); - if (res != HC_SUCCESS) { - LOGE("ProcessDevSession fail. [Res]: %" LOG_PUB "d", res); - CloseDevSession(realTask->sessionId); - return; - } - LOGI("ProcessDevSession success. [State]: %" LOG_PUB "s", isFinish ? "FINISH" : "CONTINUE"); - if (isFinish) { - CloseDevSession(realTask->sessionId); - } -} - -static void InitStartSessionTask(StartSessionTask *task, int64_t sessionId) -{ - task->base.doAction = DoStartSession; - task->base.destroy = NULL; - task->sessionId = sessionId; -} - -static void DestroyProcSessionTask(HcTaskBase *task) -{ - ProcSessionTask *realTask = (ProcSessionTask *)task; - FreeJson(realTask->receivedMsg); -} - -static void InitProcSessionTask(ProcSessionTask *task, int64_t sessionId, CJson *receivedMsg) -{ - task->base.doAction = DoProcSession; - task->base.destroy = DestroyProcSessionTask; - task->sessionId = sessionId; - task->receivedMsg = receivedMsg; -} - -static int32_t PushStartSessionTask(int64_t sessionId) -{ - StartSessionTask *task = (StartSessionTask *)HcMalloc(sizeof(StartSessionTask), 0); - if (task == NULL) { - LOGE("Failed to allocate memory for task!"); - return HC_ERR_ALLOC_MEMORY; - } - InitStartSessionTask(task, sessionId); - if (PushTask((HcTaskBase*)task) != HC_SUCCESS) { - LOGE("push start session task fail."); - HcFree(task); - return HC_ERR_INIT_TASK_FAIL; - } - LOGI("push start session task success."); - return HC_SUCCESS; -} - static int32_t AddOriginDataForPlugin(CJson *receivedMsg, const uint8_t *data) { if ((receivedMsg == NULL) || (data == NULL)) { @@ -355,516 +71,6 @@ static int32_t AddOriginDataForPlugin(CJson *receivedMsg, const uint8_t *data) return AddStringToJson(receivedMsg, FIELD_PLUGIN_EXT_DATA, (const char *)data); } -static int32_t PushProcSessionTask(int64_t sessionId, CJson *receivedMsg) -{ - ProcSessionTask *task = (ProcSessionTask *)HcMalloc(sizeof(ProcSessionTask), 0); - if (task == NULL) { - LOGE("Failed to allocate memory for task!"); - return HC_ERR_ALLOC_MEMORY; - } - InitProcSessionTask(task, sessionId, receivedMsg); - if (PushTask((HcTaskBase*)task) != HC_SUCCESS) { - LOGE("push start session task fail."); - HcFree(task); - return HC_ERR_INIT_TASK_FAIL; - } - LOGI("push start session task success."); - return HC_SUCCESS; -} - -#ifdef ENABLE_P2P_BIND_LITE_PROTOCOL_CHECK -// If bind with iso short pin, groupVisibility must be private -static int32_t CheckGroupVisibility(const CJson *context) -{ - int32_t osAccountId = INVALID_OS_ACCOUNT; - if (GetIntFromJson(context, FIELD_OS_ACCOUNT_ID, &osAccountId) != HC_SUCCESS) { - LOGE("Failed to get osAccountId!"); - return HC_ERR_JSON_GET; - } - const char *groupId = GetStringFromJson(context, FIELD_GROUP_ID); - if (groupId == NULL) { - LOGE("Failed to get groupId!"); - return HC_ERR_JSON_GET; - } - const char *appId = GetStringFromJson(context, FIELD_APP_ID); - if (appId == NULL) { - LOGE("Failed to get appId!"); - return HC_ERR_JSON_GET; - } - TrustedGroupEntry *entry = GetGroupEntryById(osAccountId, groupId); - if (entry == NULL) { - LOGE("Failed to get group entry!"); - return HC_ERR_GROUP_NOT_EXIST; - } - int32_t res = CheckUpgradeIdentity(entry->upgradeFlag, appId, NULL); - if (res == HC_SUCCESS) { - LOGI("Group is from upgrade, no need to check visibility."); - DestroyGroupEntry(entry); - return HC_SUCCESS; - } - if (entry->visibility != GROUP_VISIBILITY_PRIVATE) { - LOGE("Group is not private, can not bind old version wearable device!"); - DestroyGroupEntry(entry); - return HC_ERR_INVALID_PARAMS; - } - DestroyGroupEntry(entry); - return HC_SUCCESS; -} -#endif - -#ifdef ENABLE_P2P_BIND_LITE_PROTOCOL_CHECK -static int32_t CheckBindParams(const CJson *context, bool isClient) -{ - int32_t opCode; - if (GetIntFromJson(context, FIELD_OPERATION_CODE, &opCode) != HC_SUCCESS) { - LOGE("Failed to get operation code!"); - return HC_ERR_JSON_GET; - } - if ((isClient && opCode == MEMBER_INVITE) || (!isClient && opCode == MEMBER_JOIN)) { - int32_t protocolExpandVal = INVALID_PROTOCOL_EXPAND_VALUE; - (void)GetIntFromJson(context, FIELD_PROTOCOL_EXPAND, &protocolExpandVal); - if (protocolExpandVal == LITE_PROTOCOL_COMPATIBILITY_MODE) { - return CheckGroupVisibility(context); - } - } - return HC_SUCCESS; -} -#endif - -static int32_t StartClientBindSession(int32_t osAccountId, int64_t requestId, const char *appId, - const char *contextParams, const DeviceAuthCallback *callback) -{ - CJson *context = CreateJsonFromString(contextParams); - if (context == NULL) { - LOGE("Failed to create json from string!"); - return HC_ERR_JSON_FAIL; - } - int32_t res = BuildClientBindContext(osAccountId, requestId, appId, callback, context); - if (res != HC_SUCCESS) { - FreeJson(context); - return res; - } -#ifdef ENABLE_P2P_BIND_LITE_PROTOCOL_CHECK - res = CheckBindParams(context, true); - if (res != HC_SUCCESS) { - FreeJson(context); - return res; - } -#endif - ChannelType channelType = GetChannelType(callback, context); - SessionInitParams params = { context, *callback }; - res = OpenDevSession(requestId, appId, ¶ms); - FreeJson(context); - if (res != HC_SUCCESS) { - LOGE("OpenDevSession fail. [Res]: %" LOG_PUB "d", res); - return res; - } - if (channelType == SERVICE_CHANNEL) { - res = PushStartSessionTask(requestId); - if (res != HC_SUCCESS) { - return res; - } - } - return HC_SUCCESS; -} - -#ifdef DEV_AUTH_HIVIEW_ENABLE -static const char *GetAddMemberCallEventFuncName(const char *addParams) -{ - if (addParams == NULL) { - LOGE("add params is null!"); - return ADD_MEMBER_EVENT; - } - CJson *in = CreateJsonFromString(addParams); - if (in == NULL) { - LOGE("Failed to create json param!"); - return ADD_MEMBER_EVENT; - } - int32_t protocolExpandVal = INVALID_PROTOCOL_EXPAND_VALUE; - (void)GetIntFromJson(in, FIELD_PROTOCOL_EXPAND, &protocolExpandVal); - FreeJson(in); - if (protocolExpandVal == LITE_PROTOCOL_STANDARD_MODE) { - return ADD_MEMBER_WITH_LITE_STANDARD; - } else if (protocolExpandVal == LITE_PROTOCOL_COMPATIBILITY_MODE) { - return ADD_MEMBER_WITH_LITE_COMPATIBILITY; - } else { - return ADD_MEMBER_EVENT; - } -} -#endif - -static int32_t AddMemberToGroupInner(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams) -{ - SET_LOG_MODE(TRACE_MODE); - SET_TRACE_ID(requestId); - ADD_PERFORM_DATA(requestId, true, true, HcGetCurTimeInMillis()); - osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId); - if ((appId == NULL) || (addParams == NULL) || (osAccountId == INVALID_OS_ACCOUNT)) { - LOGE("Invalid input parameters!"); - return HC_ERR_INVALID_PARAMS; - } - if (!CheckIsForegroundOsAccountId(osAccountId)) { - LOGE("This access is not from the foreground user, rejected it."); - return HC_ERR_CROSS_USER_ACCESS; - } - if (!IsOsAccountUnlocked(osAccountId)) { - LOGE("Os account is not unlocked!"); - return HC_ERR_OS_ACCOUNT_NOT_UNLOCKED; - } - LOGI("Start to add member to group. [ReqId]: %" LOG_PUB PRId64 ", [OsAccountId]: %" LOG_PUB "d, [AppId]: %" - LOG_PUB "s", requestId, osAccountId, appId); - const DeviceAuthCallback *callback = GetGMCallbackByAppId(appId); - if (callback == NULL) { - LOGE("Failed to find callback by appId! [AppId]: %" LOG_PUB "s", appId); - return HC_ERR_CALLBACK_NOT_FOUND; - } - return StartClientBindSession(osAccountId, requestId, appId, addParams, callback); -} - -#ifdef DEV_AUTH_HIVIEW_ENABLE -static DevAuthBizScene GetBizScene(bool isBind, bool isClient) -{ - if (isBind) { - if (isClient) { - return BIZ_SCENE_ADD_MEMBER_CLIENT; - } else { - return BIZ_SCENE_ADD_MEMBER_SERVER; - } - } else { - if (isClient) { - return BIZ_SCENE_AUTH_DEVICE_CLIENT; - } else { - return BIZ_SCENE_AUTH_DEVICE_SERVER; - } - } -} -#endif - -static void ReportBehaviorBeginEvent(bool isBind, bool isClient, int64_t reqId) -{ -#ifdef DEV_AUTH_HIVIEW_ENABLE - char *funcName = isBind ? ADD_MEMBER_EVENT : AUTH_DEV_EVENT; - DevAuthBizScene scene = GetBizScene(isBind, isClient); - DevAuthBehaviorEvent eventData = { 0 }; - BuildBehaviorEventData(&eventData, funcName, scene, BIZ_STATE_BEGIN, BIZ_STAGE_BEGIN); - char anonymousLocalUdid[ANONYMOUS_UDID_LEN + 1] = { 0 }; - if (isBind) { - eventData.hostPkg = ADD_MEMBER_HOST_PKG_NAME; - eventData.toCallPkg = ADD_MEMBER_TO_CALL_PKG_NAME; - } else { - eventData.hostPkg = AUTH_DEVICE_HOST_PKG_NAME; - char selfUdid[INPUT_UDID_LEN] = { 0 }; - (void)HcGetUdid((uint8_t *)selfUdid, INPUT_UDID_LEN); - if (GetAnonymousString(selfUdid, anonymousLocalUdid, ANONYMOUS_UDID_LEN) == HC_SUCCESS) { - eventData.localUdid = anonymousLocalUdid; - } - } - char concurrentId[MAX_REQUEST_ID_LEN] = { 0 }; - (void)sprintf_s(concurrentId, sizeof(concurrentId), "%" PRId64, reqId); - eventData.concurrentId = concurrentId; - DevAuthReportBehaviorEvent(&eventData); -#else - (void)isBind; - (void)isClient; - (void)reqId; -#endif -} - -static void ReportBehaviorBeginResultEvent(bool isBind, bool isClient, int64_t reqId, const char *peerUdid, int32_t res) -{ -#ifdef DEV_AUTH_HIVIEW_ENABLE - char *funcName = isBind ? ADD_MEMBER_EVENT : AUTH_DEV_EVENT; - DevAuthBizScene scene = GetBizScene(isBind, isClient); - DevAuthBehaviorEvent eventData = { 0 }; - BuildBehaviorEventData(&eventData, funcName, scene, BIZ_STATE_PROCESS, BIZ_STAGE_BEGIN); - char anonymousLocalUdid[ANONYMOUS_UDID_LEN + 1] = { 0 }; - char anonymousPeerUdid[ANONYMOUS_UDID_LEN + 1] = { 0 }; - if (isBind) { - eventData.hostPkg = ADD_MEMBER_HOST_PKG_NAME; - eventData.toCallPkg = ADD_MEMBER_TO_CALL_PKG_NAME; - } else { - eventData.hostPkg = AUTH_DEVICE_HOST_PKG_NAME; - char selfUdid[INPUT_UDID_LEN] = { 0 }; - (void)HcGetUdid((uint8_t *)selfUdid, INPUT_UDID_LEN); - if (GetAnonymousString(selfUdid, anonymousLocalUdid, ANONYMOUS_UDID_LEN) == HC_SUCCESS) { - eventData.localUdid = anonymousLocalUdid; - } - if (GetAnonymousString(peerUdid, anonymousPeerUdid, ANONYMOUS_UDID_LEN) == HC_SUCCESS) { - eventData.peerUdid = anonymousPeerUdid; - } - } - char concurrentId[MAX_REQUEST_ID_LEN] = { 0 }; - (void)sprintf_s(concurrentId, sizeof(concurrentId), "%" PRId64, reqId); - eventData.concurrentId = concurrentId; - if (res == HC_SUCCESS) { - eventData.stageRes = STAGE_RES_SUCCESS; - } else { - eventData.stageRes = STAGE_RES_FAILED; - eventData.errorCode = res; - } - DevAuthReportBehaviorEvent(&eventData); -#else - (void)isBind; - (void)isClient; - (void)reqId; - (void)peerUdid; - (void)res; -#endif -} - -static int32_t AddMemberToGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams) -{ - ReportBehaviorBeginEvent(true, true, requestId); - int32_t res = AddMemberToGroupInner(osAccountId, requestId, appId, addParams); - ReportBehaviorBeginResultEvent(true, true, requestId, NULL, res); -#ifdef DEV_AUTH_HIVIEW_ENABLE - const char *callEventFuncName = GetAddMemberCallEventFuncName(addParams); - DEV_AUTH_REPORT_UE_CALL_EVENT_BY_PARAMS(osAccountId, addParams, appId, callEventFuncName); -#endif - return res; -} - -static int32_t AddServerReqInfoToContext(int64_t requestId, const char *appId, int32_t opCode, - const CJson *receivedMsg, CJson *context) -{ - const char *groupId = GetStringFromJson(receivedMsg, FIELD_GROUP_ID); - if (groupId == NULL) { - LOGE("get groupId from json fail."); - return HC_ERR_JSON_GET; - } - if (AddBoolToJson(context, FIELD_IS_SINGLE_CRED, true) != HC_SUCCESS) { - LOGE("add isSingleCred to context fail."); - return HC_ERR_JSON_ADD; - } - if (AddBoolToJson(context, FIELD_IS_BIND, true) != HC_SUCCESS) { - LOGE("add isBind to context fail."); - return HC_ERR_JSON_ADD; - } - if (AddBoolToJson(context, FIELD_IS_CLIENT, false) != HC_SUCCESS) { - LOGE("add isClient to context fail."); - return HC_ERR_JSON_ADD; - } - if (AddInt64StringToJson(context, FIELD_REQUEST_ID, requestId) != HC_SUCCESS) { - LOGE("add requestId to context fail."); - return HC_ERR_JSON_ADD; - } - if (AddStringToJson(context, FIELD_APP_ID, appId) != HC_SUCCESS) { - LOGE("add appId to context fail."); - return HC_ERR_JSON_ADD; - } - if (AddIntToJson(context, FIELD_OPERATION_CODE, opCode) != HC_SUCCESS) { - LOGE("add opCode to context fail."); - return HC_ERR_JSON_ADD; - } - int32_t res; - if (opCode == MEMBER_INVITE) { - res = AddGroupInfoToContextByInput(receivedMsg, context); - if (res != HC_SUCCESS) { - return res; - } - return AddDevInfoToContextByInput(context); - } - res = AddGroupInfoToContextByDb(groupId, context); - if (res != HC_SUCCESS) { - return res; - } - return AddDevInfoToContextByDb(groupId, context); -} - -static int32_t CheckConfirmationExist(const CJson *context) -{ - uint32_t confirmation = REQUEST_REJECTED; - if (GetUnsignedIntFromJson(context, FIELD_CONFIRMATION, &confirmation) != HC_SUCCESS) { - LOGE("Failed to get confimation from json!"); - return HC_ERR_JSON_GET; - } - if (confirmation == REQUEST_ACCEPTED) { - LOGI("The service accepts this request!"); - } else { - LOGW("The service rejects this request!"); - } - return HC_SUCCESS; -} - -static int32_t AddOsAccountIdToContextIfValid(CJson *context) -{ - int32_t osAccountId = ANY_OS_ACCOUNT; - (void)GetIntFromJson(context, FIELD_OS_ACCOUNT_ID, &osAccountId); - osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId); - LOGI("[OsAccountId]: %" LOG_PUB "d", osAccountId); - if (osAccountId == INVALID_OS_ACCOUNT) { - return HC_ERR_INVALID_PARAMS; - } - if (!CheckIsForegroundOsAccountId(osAccountId)) { - LOGE("This access is not from the foreground user, rejected it."); - return HC_ERR_CROSS_USER_ACCESS; - } - if (!IsOsAccountUnlocked(osAccountId)) { - LOGE("Os account is not unlocked!"); - return HC_ERR_OS_ACCOUNT_NOT_UNLOCKED; - } - if (AddIntToJson(context, FIELD_OS_ACCOUNT_ID, osAccountId) != HC_SUCCESS) { - LOGE("add operationCode to context fail."); - return HC_ERR_JSON_ADD; - } - return HC_SUCCESS; -} - -static int32_t BuildServerBindContext(int64_t requestId, const char *appId, int32_t opCode, - const CJson *receivedMsg, CJson *context) -{ - int32_t res = CheckConfirmationExist(context); - if (res != HC_SUCCESS) { - return res; - } - res = AddOsAccountIdToContextIfValid(context); - if (res != HC_SUCCESS) { - return res; - } - res = AddServerReqInfoToContext(requestId, appId, opCode, receivedMsg, context); - if (res != HC_SUCCESS) { - return res; - } - int32_t channelType; - int64_t channelId = DEFAULT_CHANNEL_ID; - if (GetByteFromJson(receivedMsg, FIELD_CHANNEL_ID, (uint8_t *)&channelId, sizeof(int64_t)) == HC_SUCCESS) { - channelType = SOFT_BUS; - } else { - channelType = SERVICE_CHANNEL; - } - return AddChannelInfoToContext(channelType, channelId, context); -} - -static const char *GetAppIdFromReceivedMsg(const CJson *receivedMsg) -{ - const char *appId = GetStringFromJson(receivedMsg, FIELD_APP_ID); - if (appId == NULL) { - LOGW("use default device manager appId."); - appId = DM_APP_ID; - } - return appId; -} - -static int32_t CreateAppIdJsonString(const char *appId, char **reqParames) -{ - CJson *reqJson = CreateJson(); - if ((reqJson == NULL) || (reqParames == NULL)) { - LOGE("Failed to create json!"); - return HC_ERR_JSON_CREATE; - } - if (AddStringToJson(reqJson, FIELD_APP_ID, appId) != HC_SUCCESS) { - LOGE("Failed to add appId!"); - FreeJson(reqJson); - return HC_ERR_JSON_ADD; - } - *reqParames = PackJsonToString(reqJson); - FreeJson(reqJson); - if ((*reqParames) == NULL) { - LOGE("Failed to create reqParames string!"); - return HC_ERR_PACKAGE_JSON_TO_STRING_FAIL; - } - return HC_SUCCESS; -} - -static int32_t OpenServerBindSession(int64_t requestId, const CJson *receivedMsg) -{ - const char *appId = GetAppIdFromReceivedMsg(receivedMsg); - const DeviceAuthCallback *callback = GetGMCallbackByAppId(appId); - if (callback == NULL) { - LOGE("Failed to find callback by appId! [AppId]: %" LOG_PUB "s", appId); - return HC_ERR_CALLBACK_NOT_FOUND; - } - int32_t opCode; - if (GetIntFromJson(receivedMsg, FIELD_GROUP_OP, &opCode) != HC_SUCCESS) { - if (GetIntFromJson(receivedMsg, FIELD_OP_CODE, &opCode) != HC_SUCCESS) { - opCode = MEMBER_JOIN; - LOGW("use default opCode."); - } - } - char *reqParames = NULL; - int32_t res = CreateAppIdJsonString(appId, &reqParames); - if (res != HC_SUCCESS) { - LOGE("Create reqParames from appid failed!"); - return res; - } - char *returnDataStr = ProcessRequestCallback(requestId, opCode, reqParames, callback); - FreeJsonString(reqParames); - if (returnDataStr == NULL) { - LOGE("The OnRequest callback is fail!"); - return HC_ERR_REQ_REJECTED; - } - CJson *context = CreateJsonFromString(returnDataStr); - FreeJsonString(returnDataStr); - if (context == NULL) { - LOGE("Failed to create context from string!"); - return HC_ERR_JSON_FAIL; - } - res = BuildServerBindContext(requestId, appId, opCode, receivedMsg, context); - if (res != HC_SUCCESS) { - FreeJson(context); - return res; - } -#ifdef ENABLE_P2P_BIND_LITE_PROTOCOL_CHECK - res = CheckBindParams(context, false); - if (res != HC_SUCCESS) { - FreeJson(context); - return res; - } -#endif - SessionInitParams params = { context, *callback }; - res = OpenDevSession(requestId, appId, ¶ms); - FreeJson(context); - return res; -} - -static int32_t ProcessBindDataInner(int64_t requestId, const uint8_t *data, uint32_t dataLen) -{ - SET_LOG_MODE(TRACE_MODE); - SET_TRACE_ID(requestId); - if (!IsSessionExist(requestId)) { - ADD_PERFORM_DATA(requestId, true, false, HcGetCurTimeInMillis()); - } else { - UPDATE_PERFORM_DATA_BY_SELF_INDEX(requestId, HcGetCurTimeInMillis()); - } - if ((data == NULL) || (dataLen == 0) || (dataLen > MAX_DATA_BUFFER_SIZE)) { - LOGE("The input data is invalid!"); - return HC_ERR_INVALID_PARAMS; - } - LOGI("[Start]: RequestProcessBindData! [ReqId]: %" LOG_PUB PRId64, requestId); - CJson *receivedMsg = CreateJsonFromString((const char *)data); - if (receivedMsg == NULL) { - LOGE("Failed to create json from string!"); - return HC_ERR_JSON_FAIL; - } - int32_t res; - if (!IsSessionExist(requestId)) { - res = OpenServerBindSession(requestId, receivedMsg); - if (res != HC_SUCCESS) { - FreeJson(receivedMsg); - return res; - } - } - res = PushProcSessionTask(requestId, receivedMsg); - if (res != HC_SUCCESS) { - FreeJson(receivedMsg); - return res; - } - return HC_SUCCESS; -} - -static int32_t ProcessBindData(int64_t requestId, const uint8_t *data, uint32_t dataLen) -{ - bool isSessionExist = IsSessionExist(requestId); - if (!isSessionExist) { - ReportBehaviorBeginEvent(true, false, requestId); - } - int32_t res = ProcessBindDataInner(requestId, data, dataLen); - if (!isSessionExist) { - ReportBehaviorBeginResultEvent(true, false, requestId, NULL, res); - } - return res; -} - static int32_t BuildClientAuthContext(int32_t osAccountId, int64_t requestId, const char *appId, CJson *context, char **returnPeerUdid) { @@ -1764,88 +970,6 @@ static void InitPseudonymModule(void) manager->loadPseudonymData(); } -static void DoOnChannelOpened(HcTaskBase *baseTask) -{ - if (baseTask == NULL) { - LOGE("The input task is NULL!"); - return; - } - SoftBusTask *task = (SoftBusTask *)baseTask; - SET_LOG_MODE(TRACE_MODE); - SET_TRACE_ID(task->requestId); - LOGI("[Start]: DoOnChannelOpened!"); - int32_t res = StartDevSession(task->requestId); - if (res != HC_SUCCESS) { - LOGE("start session fail.[Res]: %" LOG_PUB "d", res); - CloseDevSession(task->requestId); - } -} - -static void InitSoftBusTask(SoftBusTask *task, int64_t requestId) -{ - task->base.doAction = DoOnChannelOpened; - task->base.destroy = NULL; - task->requestId = requestId; -} - -static int OnChannelOpenedCb(int64_t requestId, int result) -{ - if (result != HC_SUCCESS) { - LOGE("[SoftBus][Out]: Failed to open channel! res: %" LOG_PUB "d", result); - CloseDevSession(requestId); - return HC_ERR_SOFT_BUS; - } - LOGI("[Start]: OnChannelOpened! [ReqId]: %" LOG_PUB PRId64, requestId); - SoftBusTask *task = (SoftBusTask *)HcMalloc(sizeof(SoftBusTask), 0); - if (task == NULL) { - LOGE("Failed to allocate task memory!"); - CloseDevSession(requestId); - return HC_ERR_ALLOC_MEMORY; - } - InitSoftBusTask(task, requestId); - if (PushTask((HcTaskBase *)task) != HC_SUCCESS) { - HcFree(task); - CloseDevSession(requestId); - return HC_ERR_INIT_TASK_FAIL; - } - LOGI("[End]: OnChannelOpened!"); - return HC_SUCCESS; -} - -static void OnChannelClosedCb(void) -{ - return; -} - -static void OnBytesReceivedCb(int64_t requestId, uint8_t *data, uint32_t dataLen) -{ - if ((data == NULL) || (dataLen == 0) || (dataLen > MAX_DATA_BUFFER_SIZE)) { - LOGE("Invalid input params!"); - return; - } - (void)ProcessBindData(requestId, data, dataLen); -} - -static int32_t RegCallback(const char *appId, const DeviceAuthCallback *callback) -{ - SET_LOG_MODE(NORMAL_MODE); - if ((appId == NULL) || (callback == NULL)) { - LOGE("The input parameters contains NULL value!"); - return HC_ERR_INVALID_PARAMS; - } - ChannelProxy proxy = { - .onChannelOpened = OnChannelOpenedCb, - .onChannelClosed = OnChannelClosedCb, - .onBytesReceived = OnBytesReceivedCb - }; - int32_t res = InitChannelManager(&proxy); - if (res != HC_SUCCESS) { - LOGE("[End]: [Service]: Failed to init channel manage module!"); - return res; - } - return RegGroupManagerCallback(appId, callback); -} - DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void) { LOGI("[Service]: Start to init device auth service!"); @@ -1917,17 +1041,17 @@ DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance(void) return NULL; } - g_groupManagerInstance->regCallback = RegCallback; - g_groupManagerInstance->unRegCallback = UnRegGroupManagerCallback; + g_groupManagerInstance->regCallback = RegCallbackImpl; + g_groupManagerInstance->unRegCallback = UnRegCallbackImpl; g_groupManagerInstance->regDataChangeListener = RegListenerImpl; g_groupManagerInstance->unRegDataChangeListener = UnRegListenerImpl; g_groupManagerInstance->createGroup = CreateGroupImpl; g_groupManagerInstance->deleteGroup = DeleteGroupImpl; - g_groupManagerInstance->addMemberToGroup = AddMemberToGroup; + g_groupManagerInstance->addMemberToGroup = AddMemberToGroupImpl; g_groupManagerInstance->deleteMemberFromGroup = DeleteMemberFromGroupImpl; g_groupManagerInstance->addMultiMembersToGroup = AddMultiMembersToGroupImpl; g_groupManagerInstance->delMultiMembersFromGroup = DelMultiMembersFromGroupImpl; - g_groupManagerInstance->processData = ProcessBindData; + g_groupManagerInstance->processData = ProcessBindDataImpl; g_groupManagerInstance->getRegisterInfo = GetRegisterInfoImpl; g_groupManagerInstance->checkAccessToGroup = CheckAccessToGroupImpl; g_groupManagerInstance->getPkInfoList = GetPkInfoListImpl; diff --git a/services/deviceauth.gni b/services/deviceauth.gni index 9e62d06a5805a1ee127b0d60d579c1ed7703f410..79b6beba613359e1281284a9aac33bf114dadb14 100644 --- a/services/deviceauth.gni +++ b/services/deviceauth.gni @@ -29,6 +29,8 @@ creds_manager_path = "${services_path}/legacy/creds_manager" mk_agree_path = "${services_path}/mk_agree" identity_manager_path = "${services_path}/legacy/identity_manager" identity_service_path = "${services_path}/identity_service" +device_auth_common = "${services_path}/common" + enable_broadcast = true deviceauth_defines = [] @@ -57,6 +59,7 @@ identity_service_mock_files = [ inc_path = [ "${inner_api_path}", + "${device_auth_common}/inc", "${frameworks_path}/inc", "${ext_plugin_manager_path}/inc", "${ext_plugin_manager_path}/inc/account_related", @@ -115,6 +118,8 @@ inc_path += identity_service_inc deviceauth_common_files = [ "${services_path}/device_auth.c", + "${device_auth_common}/src/hisysevent_common.c", + "${device_auth_common}/src/device_auth_common.c", "${group_manager_path}/src/group_manager.c", "${group_manager_path}/src/channel_manager/channel_manager.c", "${group_manager_path}/src/callback_manager/callback_manager.c", diff --git a/services/identity_service/session/src/cred_session_util.c b/services/identity_service/session/src/cred_session_util.c index dd99130daf8168227c26a55ea1e42e8d06bc5450..aed4d3616592a6d00c634efad1003dd96f577228 100644 --- a/services/identity_service/session/src/cred_session_util.c +++ b/services/identity_service/session/src/cred_session_util.c @@ -19,7 +19,7 @@ #include "identity_service.h" #include "device_auth.h" #include "common_defs.h" -#include "device_auth_defines.h" +#include "device_auth_common.h" #include "hc_types.h" #include "hc_dev_info.h" #include "json_utils.h" @@ -29,19 +29,6 @@ #include "os_account_adapter.h" #include "identity_service_defines.h" -static int32_t AddChannelInfoToContext(int32_t channelType, int64_t channelId, CJson *context) -{ - if (AddIntToJson(context, FIELD_CHANNEL_TYPE, channelType) != HC_SUCCESS) { - LOGE("add channelType to context fail."); - return HC_ERR_JSON_ADD; - } - if (AddByteToJson(context, FIELD_CHANNEL_ID, (uint8_t *)&channelId, sizeof(int64_t)) != HC_SUCCESS) { - LOGE("add channelId to context fail."); - return HC_ERR_JSON_ADD; - } - return HC_SUCCESS; -} - static int32_t AddCredIdToContextIfNeeded(CJson *context) { CJson *credJson = GetObjFromJson(context, FIELD_CREDENTIAL_OBJ); @@ -66,21 +53,6 @@ static int32_t AddCredIdToContextIfNeeded(CJson *context) return HC_SUCCESS; } -static int32_t CheckConfirmationExist(const CJson *context) -{ - uint32_t confirmation = REQUEST_REJECTED; - if (GetUnsignedIntFromJson(context, FIELD_CONFIRMATION, &confirmation) != HC_SUCCESS) { - LOGE("Failed to get confimation from json!"); - return HC_ERR_JSON_GET; - } - if (confirmation == REQUEST_ACCEPTED) { - LOGI("The service accepts this request!"); - } else { - LOGW("The service rejects this request!"); - } - return HC_SUCCESS; -} - static const char *GetAppIdByContext(const CJson *context) { const char *pinCode = GetStringFromJson(context, FIELD_PIN_CODE); @@ -347,30 +319,6 @@ int32_t BuildClientCredContext(int32_t osAccountId, int64_t requestId, CJson *co return BuildClientCredAuthContext(osAccountId, requestId, context, returnAppId); } -static int32_t AddOsAccountIdToContextIfValid(CJson *context) -{ - int32_t osAccountId = ANY_OS_ACCOUNT; - (void)GetIntFromJson(context, FIELD_OS_ACCOUNT_ID, &osAccountId); - osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId); - LOGI("[OsAccountId]: %" LOG_PUB "d", osAccountId); - if (osAccountId == INVALID_OS_ACCOUNT) { - return HC_ERR_INVALID_PARAMS; - } - if (!CheckIsForegroundOsAccountId(osAccountId)) { - LOGE("This access is not from the foreground user, rejected it."); - return HC_ERR_CROSS_USER_ACCESS; - } - if (!IsOsAccountUnlocked(osAccountId)) { - LOGE("Os account is not unlocked!"); - return HC_ERR_OS_ACCOUNT_NOT_UNLOCKED; - } - if (AddIntToJson(context, FIELD_OS_ACCOUNT_ID, osAccountId) != HC_SUCCESS) { - LOGE("add operationCode to context fail."); - return HC_ERR_JSON_ADD; - } - return HC_SUCCESS; -} - static int32_t BuildServerCredBindContext(int64_t requestId, CJson *context, char **returnPeerUdid, const char **returnAppId) { diff --git a/services/legacy/group_manager/inc/group_manager.h b/services/legacy/group_manager/inc/group_manager.h index b536dd74b0140a5dc9069d56fbd523dcad16f522..8d37024f3875287b04e5bd40efcc492e89c375f6 100644 --- a/services/legacy/group_manager/inc/group_manager.h +++ b/services/legacy/group_manager/inc/group_manager.h @@ -28,10 +28,16 @@ void DestroyGroupManager(void); 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 ProcessBindDataImpl(int64_t requestId, const uint8_t *data, uint32_t dataLen); + int32_t DeleteMemberFromGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *deleteParams); int32_t AddMultiMembersToGroupImpl(int32_t osAccountId, const char *appId, const char *addParams); int32_t DelMultiMembersFromGroupImpl(int32_t osAccountId, const char *appId, const char *deleteParams); +int32_t RegCallbackImpl(const char *appId, const DeviceAuthCallback *callback); +int32_t UnRegCallbackImpl(const char *appId); + int32_t RegListenerImpl(const char *appId, const DataChangeListener *listener); int32_t UnRegListenerImpl(const char *appId); diff --git a/services/legacy/group_manager/inc/group_operation.h b/services/legacy/group_manager/inc/group_operation.h index caa6760d38dee814b011fb672c8a9867fc30c297..269968e80dd82ec0d6ebe07cc5eac0011eb14465 100644 --- a/services/legacy/group_manager/inc/group_operation.h +++ b/services/legacy/group_manager/inc/group_operation.h @@ -31,9 +31,13 @@ typedef struct { typedef struct { 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 (*processBindData)(int64_t requestId, const uint8_t *data, uint32_t dataLen); int32_t (*deleteMember)(int32_t osAccountId, int64_t requestId, const char *appId, const char *deleteParams); int32_t (*addMultiMembers)(int32_t osAccountId, const char *appId, const char *addParams); int32_t (*delMultiMembers)(int32_t osAccountId, const char *appId, const char *deleteParams); + int32_t (*regCallback)(const char *appId, const DeviceAuthCallback *callback); + int32_t (*unRegCallback)(const char *appId); int32_t (*regListener)(const char *appId, const DataChangeListener *listener); int32_t (*unRegListener)(const char *appId); int32_t (*getRegisterInfo)(const char *reqJsonStr, char **returnRegisterInfo); diff --git a/services/legacy/group_manager/inc/group_operation_common.h b/services/legacy/group_manager/inc/group_operation_common.h index 69142f8c1d682cef80ec7fab7f4b51266e0ad00a..b64e2e02b592213fe64ee01086d3c74f39056553 100644 --- a/services/legacy/group_manager/inc/group_operation_common.h +++ b/services/legacy/group_manager/inc/group_operation_common.h @@ -110,6 +110,7 @@ int32_t AddDevInfoToContextByDb(const char *groupId, CJson *context); int32_t AddGroupInfoToContextByInput(const CJson *receivedMsg, CJson *context); int32_t AddDevInfoToContextByInput(CJson *context); +const char *GetPeerUdidFromJson(int32_t osAccountId, const CJson *in); #ifdef __cplusplus } diff --git a/services/legacy/group_manager/src/group_manager.c b/services/legacy/group_manager/src/group_manager.c index 1717c79fe5413cfd57b5f7bf39c0722807f8a20c..02ba92c8e5a7c1f9960df114e32268b1db957133 100644 --- a/services/legacy/group_manager/src/group_manager.c +++ b/services/legacy/group_manager/src/group_manager.c @@ -37,6 +37,22 @@ int32_t DeleteGroupImpl(int32_t osAccountId, int64_t requestId, const char *appI : HC_ERR_NOT_SUPPORT; } +int32_t AddMemberToGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams) +{ + SET_LOG_MODE(NORMAL_MODE); + SET_TRACE_ID(requestId); + return IsGroupSupport() ? GetGroupImplInstance()->addMemberToGroup(osAccountId, requestId, appId, addParams) + : HC_ERR_NOT_SUPPORT; +} + +int32_t ProcessBindDataImpl(int64_t requestId, const uint8_t *data, uint32_t dataLen) +{ + SET_LOG_MODE(NORMAL_MODE); + SET_TRACE_ID(requestId); + return IsGroupSupport() ? GetGroupImplInstance()->processBindData(requestId, data, dataLen) + : HC_ERR_NOT_SUPPORT; +} + int32_t DeleteMemberFromGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *deleteParams) { SET_LOG_MODE(TRACE_MODE); @@ -59,6 +75,18 @@ int32_t DelMultiMembersFromGroupImpl(int32_t osAccountId, const char *appId, con : HC_ERR_NOT_SUPPORT; } +int32_t RegCallbackImpl(const char *appId, const DeviceAuthCallback *callback) +{ + SET_LOG_MODE(NORMAL_MODE); + return IsGroupSupport() ? GetGroupImplInstance()->regCallback(appId, callback) : HC_ERR_NOT_SUPPORT; +} + +int32_t UnRegCallbackImpl(const char *appId, const DeviceAuthCallback *callback) +{ + SET_LOG_MODE(NORMAL_MODE); + return IsGroupSupport() ? GetGroupImplInstance()->unRegCallback(appId) : HC_ERR_NOT_SUPPORT; +} + int32_t RegListenerImpl(const char *appId, const DataChangeListener *listener) { SET_LOG_MODE(NORMAL_MODE); diff --git a/services/legacy/group_manager/src/group_operation/group_operation.c b/services/legacy/group_manager/src/group_operation/group_operation.c index 5d5af6e6ba36d6c937143dfa8bc472c1af02b0f7..307302136b2015a664d62eb972f2b429734b5be9 100644 --- a/services/legacy/group_manager/src/group_operation/group_operation.c +++ b/services/legacy/group_manager/src/group_operation/group_operation.c @@ -20,13 +20,10 @@ #include "callback_manager.h" #include "common_defs.h" #include "ext_plugin_manager.h" -#include "group_data_manager.h" #include "dev_auth_module_manager.h" -#include "device_auth_defines.h" #include "group_operation_common.h" #include "hc_dev_info.h" #include "hc_log.h" -#include "hisysevent_adapter.h" #include "hitrace_adapter.h" #include "os_account_adapter.h" #include "task_manager.h" @@ -36,9 +33,19 @@ #include "peer_to_peer_group.h" #include "hc_time.h" #include "account_task_manager.h" +#include "dev_session_mgr.h" +#include "hisysevent_common.h" +#include "device_auth_common.h" +#include "performance_dumper.h" +#include "channel_manager.h" #define EXT_PART_APP_ID "ext_part" +typedef struct { + HcTaskBase base; + int64_t requestId; +} SoftBusTask; + static bool IsGroupTypeSupported(int groupType) { if (((groupType == PEER_TO_PEER_GROUP) && (IsPeerToPeerGroupSupported())) || @@ -640,6 +647,406 @@ static int32_t DeleteMemberFromGroupInner(int32_t osAccountId, int64_t requestId return HC_SUCCESS; } +static int32_t GetOpCodeFromContext(const CJson *context) +{ + bool isAdmin = true; + (void)GetBoolFromJson(context, FIELD_IS_ADMIN, &isAdmin); + return isAdmin ? MEMBER_INVITE : MEMBER_JOIN; +} + +static int32_t AddClientReqInfoToContext(int32_t osAccountId, int64_t requestId, const char *appId, CJson *context) +{ + const char *groupId = GetStringFromJson(context, FIELD_GROUP_ID); + if (groupId == NULL) { + LOGE("get groupId from json fail."); + return HC_ERR_JSON_GET; + } + if (AddBoolToJson(context, FIELD_IS_BIND, true) != HC_SUCCESS) { + LOGE("add isBind to context fail."); + return HC_ERR_JSON_ADD; + } + if (AddBoolToJson(context, FIELD_IS_CLIENT, true) != HC_SUCCESS) { + LOGE("add isClient to context fail."); + return HC_ERR_JSON_ADD; + } + if (AddIntToJson(context, FIELD_OS_ACCOUNT_ID, osAccountId) != HC_SUCCESS) { + LOGE("add osAccountId to context fail."); + return HC_ERR_JSON_ADD; + } + if (AddInt64StringToJson(context, FIELD_REQUEST_ID, requestId) != HC_SUCCESS) { + LOGE("add requestId to context fail."); + return HC_ERR_JSON_ADD; + } + if (AddStringToJson(context, FIELD_APP_ID, appId) != HC_SUCCESS) { + LOGE("add appId to context fail."); + return HC_ERR_JSON_ADD; + } + int32_t opCode = GetOpCodeFromContext(context); + if (AddIntToJson(context, FIELD_OPERATION_CODE, opCode) != HC_SUCCESS) { + LOGE("add operationCode to context fail."); + return HC_ERR_JSON_ADD; + } + if (opCode == MEMBER_JOIN) { + return AddDevInfoToContextByInput(context); + } + int32_t res = AddDevInfoToContextByDb(groupId, context); + if (res != HC_SUCCESS) { + return res; + } + return AddGroupInfoToContextByDb(groupId, context); +} + +#ifdef ENABLE_P2P_BIND_LITE_PROTOCOL_CHECK +// If bind with iso short pin, groupVisibility must be private +static int32_t CheckGroupVisibility(const CJson *context) +{ + int32_t osAccountId = INVALID_OS_ACCOUNT; + if (GetIntFromJson(context, FIELD_OS_ACCOUNT_ID, &osAccountId) != HC_SUCCESS) { + LOGE("Failed to get osAccountId!"); + return HC_ERR_JSON_GET; + } + const char *groupId = GetStringFromJson(context, FIELD_GROUP_ID); + if (groupId == NULL) { + LOGE("Failed to get groupId!"); + return HC_ERR_JSON_GET; + } + const char *appId = GetStringFromJson(context, FIELD_APP_ID); + if (appId == NULL) { + LOGE("Failed to get appId!"); + return HC_ERR_JSON_GET; + } + TrustedGroupEntry *entry = GetGroupEntryById(osAccountId, groupId); + if (entry == NULL) { + LOGE("Failed to get group entry!"); + return HC_ERR_GROUP_NOT_EXIST; + } + int32_t res = CheckUpgradeIdentity(entry->upgradeFlag, appId, NULL); + if (res == HC_SUCCESS) { + LOGI("Group is from upgrade, no need to check visibility."); + DestroyGroupEntry(entry); + return HC_SUCCESS; + } + if (entry->visibility != GROUP_VISIBILITY_PRIVATE) { + LOGE("Group is not private, can not bind old version wearable device!"); + DestroyGroupEntry(entry); + return HC_ERR_INVALID_PARAMS; + } + DestroyGroupEntry(entry); + return HC_SUCCESS; +} +#endif + +#ifdef ENABLE_P2P_BIND_LITE_PROTOCOL_CHECK +static int32_t CheckBindParams(const CJson *context, bool isClient) +{ + int32_t opCode; + if (GetIntFromJson(context, FIELD_OPERATION_CODE, &opCode) != HC_SUCCESS) { + LOGE("Failed to get operation code!"); + return HC_ERR_JSON_GET; + } + if ((isClient && opCode == MEMBER_INVITE) || (!isClient && opCode == MEMBER_JOIN)) { + int32_t protocolExpandVal = INVALID_PROTOCOL_EXPAND_VALUE; + (void)GetIntFromJson(context, FIELD_PROTOCOL_EXPAND, &protocolExpandVal); + if (protocolExpandVal == LITE_PROTOCOL_COMPATIBILITY_MODE) { + return CheckGroupVisibility(context); + } + } + return HC_SUCCESS; +} +#endif + +static int32_t BuildClientBindContext(int32_t osAccountId, int64_t requestId, const char *appId, + const DeviceAuthCallback *callback, CJson *context) +{ + int32_t res = AddClientReqInfoToContext(osAccountId, requestId, appId, context); + if (res != HC_SUCCESS) { + return res; + } + ChannelType channelType = GetChannelType(callback, context); + int64_t channelId; + res = OpenChannel(channelType, context, requestId, &channelId); + if (res != HC_SUCCESS) { + LOGE("open channel fail."); + return res; + } + return AddChannelInfoToContext(channelType, channelId, context); +} + +static int32_t StartClientBindSession(int32_t osAccountId, int64_t requestId, const char *appId, + const char *contextParams, const DeviceAuthCallback *callback) +{ + CJson *context = CreateJsonFromString(contextParams); + if (context == NULL) { + LOGE("Failed to create json from string!"); + return HC_ERR_JSON_FAIL; + } + int32_t res = BuildClientBindContext(osAccountId, requestId, appId, callback, context); + if (res != HC_SUCCESS) { + FreeJson(context); + return res; + } +#ifdef ENABLE_P2P_BIND_LITE_PROTOCOL_CHECK + res = CheckBindParams(context, true); + if (res != HC_SUCCESS) { + FreeJson(context); + return res; + } +#endif + ChannelType channelType = GetChannelType(callback, context); + SessionInitParams params = { context, *callback }; + res = OpenDevSession(requestId, appId, ¶ms); + FreeJson(context); + if (res != HC_SUCCESS) { + LOGE("OpenDevSession fail. [Res]: %" LOG_PUB "d", res); + return res; + } + if (channelType == SERVICE_CHANNEL) { + res = PushStartSessionTask(requestId); + if (res != HC_SUCCESS) { + return res; + } + } + return HC_SUCCESS; +} + +static int32_t RequestAddMemberToGroupInner(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams) +{ + ADD_PERFORM_DATA(requestId, true, true, HcGetCurTimeInMillis()); + osAccountId = DevAuthGetRealOsAccountLocalId(osAccountId); + if ((appId == NULL) || (addParams == NULL) || (osAccountId == INVALID_OS_ACCOUNT)) { + LOGE("Invalid input parameters!"); + return HC_ERR_INVALID_PARAMS; + } + if (!CheckIsForegroundOsAccountId(osAccountId)) { + LOGE("This access is not from the foreground user, rejected it."); + return HC_ERR_CROSS_USER_ACCESS; + } + if (!IsOsAccountUnlocked(osAccountId)) { + LOGE("Os account is not unlocked!"); + return HC_ERR_OS_ACCOUNT_NOT_UNLOCKED; + } + LOGI("Start to add member to group. [ReqId]: %" LOG_PUB PRId64 ", [OsAccountId]: %" LOG_PUB "d, [AppId]: %" + LOG_PUB "s", requestId, osAccountId, appId); + const DeviceAuthCallback *callback = GetGMCallbackByAppId(appId); + if (callback == NULL) { + LOGE("Failed to find callback by appId! [AppId]: %" LOG_PUB "s", appId); + return HC_ERR_CALLBACK_NOT_FOUND; + } + return StartClientBindSession(osAccountId, requestId, appId, addParams, callback); +} + +static int32_t RequestAddMemberToGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams) +{ + ReportBehaviorBeginEvent(true, true, requestId); + int32_t res = RequestAddMemberToGroupInner(osAccountId, requestId, appId, addParams); + ReportBehaviorBeginResultEvent(true, true, requestId, NULL, res); +#ifdef DEV_AUTH_HIVIEW_ENABLE + const char *callEventFuncName = GetAddMemberCallEventFuncName(addParams); + DEV_AUTH_REPORT_UE_CALL_EVENT_BY_PARAMS(osAccountId, addParams, appId, callEventFuncName); +#endif + return res; +} + +static int32_t CreateAppIdJsonString(const char *appId, char **reqParames) +{ + CJson *reqJson = CreateJson(); + if ((reqJson == NULL) || (reqParames == NULL)) { + LOGE("Failed to create json!"); + return HC_ERR_JSON_CREATE; + } + if (AddStringToJson(reqJson, FIELD_APP_ID, appId) != HC_SUCCESS) { + LOGE("Failed to add appId!"); + FreeJson(reqJson); + return HC_ERR_JSON_ADD; + } + *reqParames = PackJsonToString(reqJson); + FreeJson(reqJson); + if ((*reqParames) == NULL) { + LOGE("Failed to create reqParames string!"); + return HC_ERR_PACKAGE_JSON_TO_STRING_FAIL; + } + return HC_SUCCESS; +} + +static const char *GetAppIdFromReceivedMsg(const CJson *receivedMsg) +{ + const char *appId = GetStringFromJson(receivedMsg, FIELD_APP_ID); + if (appId == NULL) { + LOGW("use default device manager appId."); + appId = DM_APP_ID; + } + return appId; +} + +static int32_t AddServerReqInfoToContext(int64_t requestId, const char *appId, int32_t opCode, + const CJson *receivedMsg, CJson *context) +{ + const char *groupId = GetStringFromJson(receivedMsg, FIELD_GROUP_ID); + if (groupId == NULL) { + LOGE("get groupId from json fail."); + return HC_ERR_JSON_GET; + } + if (AddBoolToJson(context, FIELD_IS_SINGLE_CRED, true) != HC_SUCCESS) { + LOGE("add isSingleCred to context fail."); + return HC_ERR_JSON_ADD; + } + if (AddBoolToJson(context, FIELD_IS_BIND, true) != HC_SUCCESS) { + LOGE("add isBind to context fail."); + return HC_ERR_JSON_ADD; + } + if (AddBoolToJson(context, FIELD_IS_CLIENT, false) != HC_SUCCESS) { + LOGE("add isClient to context fail."); + return HC_ERR_JSON_ADD; + } + if (AddInt64StringToJson(context, FIELD_REQUEST_ID, requestId) != HC_SUCCESS) { + LOGE("add requestId to context fail."); + return HC_ERR_JSON_ADD; + } + if (AddStringToJson(context, FIELD_APP_ID, appId) != HC_SUCCESS) { + LOGE("add appId to context fail."); + return HC_ERR_JSON_ADD; + } + if (AddIntToJson(context, FIELD_OPERATION_CODE, opCode) != HC_SUCCESS) { + LOGE("add opCode to context fail."); + return HC_ERR_JSON_ADD; + } + int32_t res; + if (opCode == MEMBER_INVITE) { + res = AddGroupInfoToContextByInput(receivedMsg, context); + if (res != HC_SUCCESS) { + return res; + } + return AddDevInfoToContextByInput(context); + } + res = AddGroupInfoToContextByDb(groupId, context); + if (res != HC_SUCCESS) { + return res; + } + return AddDevInfoToContextByDb(groupId, context); +} + +static int32_t BuildServerBindContext(int64_t requestId, const char *appId, int32_t opCode, + const CJson *receivedMsg, CJson *context) +{ + int32_t res = CheckConfirmationExist(context); + if (res != HC_SUCCESS) { + return res; + } + res = AddOsAccountIdToContextIfValid(context); + if (res != HC_SUCCESS) { + return res; + } + res = AddServerReqInfoToContext(requestId, appId, opCode, receivedMsg, context); + if (res != HC_SUCCESS) { + return res; + } + int32_t channelType; + int64_t channelId = DEFAULT_CHANNEL_ID; + if (GetByteFromJson(receivedMsg, FIELD_CHANNEL_ID, (uint8_t *)&channelId, sizeof(int64_t)) == HC_SUCCESS) { + channelType = SOFT_BUS; + } else { + channelType = SERVICE_CHANNEL; + } + return AddChannelInfoToContext(channelType, channelId, context); +} + +static int32_t OpenServerBindSession(int64_t requestId, const CJson *receivedMsg) +{ + const char *appId = GetAppIdFromReceivedMsg(receivedMsg); + const DeviceAuthCallback *callback = GetGMCallbackByAppId(appId); + if (callback == NULL) { + LOGE("Failed to find callback by appId! [AppId]: %" LOG_PUB "s", appId); + return HC_ERR_CALLBACK_NOT_FOUND; + } + int32_t opCode; + if (GetIntFromJson(receivedMsg, FIELD_GROUP_OP, &opCode) != HC_SUCCESS) { + if (GetIntFromJson(receivedMsg, FIELD_OP_CODE, &opCode) != HC_SUCCESS) { + opCode = MEMBER_JOIN; + LOGW("use default opCode."); + } + } + char *reqParames = NULL; + int32_t res = CreateAppIdJsonString(appId, &reqParames); + if (res != HC_SUCCESS) { + LOGE("Create reqParames from appid failed!"); + return res; + } + char *returnDataStr = ProcessRequestCallback(requestId, opCode, reqParames, callback); + FreeJsonString(reqParames); + if (returnDataStr == NULL) { + LOGE("The OnRequest callback is fail!"); + return HC_ERR_REQ_REJECTED; + } + CJson *context = CreateJsonFromString(returnDataStr); + FreeJsonString(returnDataStr); + if (context == NULL) { + LOGE("Failed to create context from string!"); + return HC_ERR_JSON_FAIL; + } + res = BuildServerBindContext(requestId, appId, opCode, receivedMsg, context); + if (res != HC_SUCCESS) { + FreeJson(context); + return res; + } +#ifdef ENABLE_P2P_BIND_LITE_PROTOCOL_CHECK + res = CheckBindParams(context, false); + if (res != HC_SUCCESS) { + FreeJson(context); + return res; + } +#endif + SessionInitParams params = { context, *callback }; + res = OpenDevSession(requestId, appId, ¶ms); + FreeJson(context); + return res; +} + +static int32_t RequestProcessBindDataInner(int64_t requestId, const uint8_t *data, uint32_t dataLen) +{ + if (!IsSessionExist(requestId)) { + ADD_PERFORM_DATA(requestId, true, false, HcGetCurTimeInMillis()); + } else { + UPDATE_PERFORM_DATA_BY_SELF_INDEX(requestId, HcGetCurTimeInMillis()); + } + if ((data == NULL) || (dataLen == 0) || (dataLen > MAX_DATA_BUFFER_SIZE)) { + LOGE("The input data is invalid!"); + return HC_ERR_INVALID_PARAMS; + } + LOGI("[Start]: RequestProcessBindData! [ReqId]: %" LOG_PUB PRId64, requestId); + CJson *receivedMsg = CreateJsonFromString((const char *)data); + if (receivedMsg == NULL) { + LOGE("Failed to create json from string!"); + return HC_ERR_JSON_FAIL; + } + int32_t res; + if (!IsSessionExist(requestId)) { + res = OpenServerBindSession(requestId, receivedMsg); + if (res != HC_SUCCESS) { + FreeJson(receivedMsg); + return res; + } + } + res = PushProcSessionTask(requestId, receivedMsg); + if (res != HC_SUCCESS) { + FreeJson(receivedMsg); + return res; + } + return HC_SUCCESS; +} + +static int32_t RequestProcessBindData(int64_t requestId, const uint8_t *data, uint32_t dataLen) +{ + bool isSessionExist = IsSessionExist(requestId); + if (!isSessionExist) { + ReportBehaviorBeginEvent(true, false, requestId); + } + int32_t res = RequestProcessBindDataInner(requestId, data, dataLen); + if (!isSessionExist) { + ReportBehaviorBeginResultEvent(true, false, requestId, NULL, res); + } + return res; +} + static int32_t RequestDeleteMemberFromGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *deleteParams) { @@ -800,6 +1207,96 @@ static int32_t RegListener(const char *appId, const DataChangeListener *listener return AddListener(appId, listener); } +static void DoOnChannelOpened(HcTaskBase *baseTask) +{ + if (baseTask == NULL) { + LOGE("The input task is NULL!"); + return; + } + SoftBusTask *task = (SoftBusTask *)baseTask; + SET_LOG_MODE(TRACE_MODE); + SET_TRACE_ID(task->requestId); + LOGI("[Start]: DoOnChannelOpened!"); + int32_t res = StartDevSession(task->requestId); + if (res != HC_SUCCESS) { + LOGE("start session fail.[Res]: %" LOG_PUB "d", res); + CloseDevSession(task->requestId); + } +} + +static void InitSoftBusTask(SoftBusTask *task, int64_t requestId) +{ + task->base.doAction = DoOnChannelOpened; + task->base.destroy = NULL; + task->requestId = requestId; +} + +static int OnChannelOpenedCb(int64_t requestId, int result) +{ + if (result != HC_SUCCESS) { + LOGE("[SoftBus][Out]: Failed to open channel! res: %" LOG_PUB "d", result); + CloseDevSession(requestId); + return HC_ERR_SOFT_BUS; + } + LOGI("[Start]: OnChannelOpened! [ReqId]: %" LOG_PUB PRId64, requestId); + SoftBusTask *task = (SoftBusTask *)HcMalloc(sizeof(SoftBusTask), 0); + if (task == NULL) { + LOGE("Failed to allocate task memory!"); + CloseDevSession(requestId); + return HC_ERR_ALLOC_MEMORY; + } + InitSoftBusTask(task, requestId); + if (PushTask((HcTaskBase *)task) != HC_SUCCESS) { + HcFree(task); + CloseDevSession(requestId); + return HC_ERR_INIT_TASK_FAIL; + } + LOGI("[End]: OnChannelOpened!"); + return HC_SUCCESS; +} + +static void OnChannelClosedCb(void) +{ + return; +} + +static void OnBytesReceivedCb(int64_t requestId, uint8_t *data, uint32_t dataLen) +{ + if ((data == NULL) || (dataLen == 0) || (dataLen > MAX_DATA_BUFFER_SIZE)) { + LOGE("Invalid input params!"); + return; + } + (void)RequestProcessBindData(requestId, data, dataLen); +} + +static int32_t RegCallback(const char *appId, const DeviceAuthCallback *callback) +{ + if ((appId == NULL) || (callback == NULL)) { + LOGE("The input parameters contains NULL value!"); + return HC_ERR_INVALID_PARAMS; + } + ChannelProxy proxy = { + .onChannelOpened = OnChannelOpenedCb, + .onChannelClosed = OnChannelClosedCb, + .onBytesReceived = OnBytesReceivedCb + }; + int32_t res = InitChannelManager(&proxy); + if (res != HC_SUCCESS) { + LOGE("[End]: [Service]: Failed to init channel manage module!"); + return res; + } + return RegGroupManagerCallback(appId, callback); +} + +static int32_t UnRegCallback(const char *appId) +{ + if ((appId == NULL)) { + LOGE("The input parameters contains NULL value!"); + return HC_ERR_INVALID_PARAMS; + } + return UnRegGroupManagerCallback(appId); +} + static int32_t UnRegListener(const char *appId) { if (appId == NULL) { @@ -1210,9 +1707,13 @@ static void DestroyInfo(char **returnInfo) static const GroupImpl GROUP_IMPL_INSTANCE = { .createGroup = RequestCreateGroup, .deleteGroup = RequestDeleteGroup, + .addMemberToGroup = RequestAddMemberToGroup, + .processBindData = RequestProcessBindData, .deleteMember = RequestDeleteMemberFromGroup, .addMultiMembers = RequestAddMultiMembersToGroup, .delMultiMembers = RequestDelMultiMembersFromGroup, + .regCallback = RegCallback, + .unRegCallback = UnRegCallback, .regListener = RegListener, .unRegListener = UnRegListener, .getRegisterInfo = GetRegisterInfo, diff --git a/services/legacy/group_manager/src/group_operation/group_operation_common/group_operation_common.c b/services/legacy/group_manager/src/group_operation/group_operation_common/group_operation_common.c index 6098296b7a1f2e98ec03fea3ff7e4f59d17a37bc..f4d942296f7c45aff25cf2817469d5b2938ca104 100644 --- a/services/legacy/group_manager/src/group_operation/group_operation_common/group_operation_common.c +++ b/services/legacy/group_manager/src/group_operation/group_operation_common/group_operation_common.c @@ -1250,4 +1250,116 @@ int32_t AddDevInfoToContextByInput(CJson *context) return HC_ERR_JSON_FAIL; } return HC_SUCCESS; -} \ No newline at end of file +} + +static int32_t IsDeviceIdHashMatch(const char *udid, const char *subUdidHash) +{ + Uint8Buff udidBuf = { (uint8_t *)udid, (uint32_t)HcStrlen(udid) }; + uint8_t udidHashByte[SHA256_LEN] = { 0 }; + Uint8Buff udidHashBuf = { udidHashByte, sizeof(udidHashByte) }; + int32_t ret = GetLoaderInstance()->sha256(&udidBuf, &udidHashBuf); + if (ret != HC_SUCCESS) { + LOGE("sha256 failed, ret:%" LOG_PUB "d", ret); + return ret; + } + uint32_t udidHashLen = SHA256_LEN * BYTE_TO_HEX_OPER_LENGTH + 1; + char *udidHash = (char *)HcMalloc(udidHashLen, 0); + if (udidHash == NULL) { + LOGE("malloc udidHash string failed"); + return HC_ERR_ALLOC_MEMORY; + } + ret = ByteToHexString(udidHashByte, SHA256_LEN, udidHash, udidHashLen); + if (ret != HC_SUCCESS) { + LOGE("Byte to hexString failed, ret:%" LOG_PUB "d", ret); + HcFree(udidHash); + return ret; + } + char *subUdidHashUpper = NULL; + ret = ToUpperCase(subUdidHash, &subUdidHashUpper); + if (ret != HC_SUCCESS) { + LOGE("Failed to convert the input sub udid hash to upper case!"); + HcFree(udidHash); + return ret; + } + if (strstr((const char *)udidHash, subUdidHashUpper) != NULL) { + LOGI("udid hash is match!"); + HcFree(udidHash); + HcFree(subUdidHashUpper); + return HC_SUCCESS; + } + HcFree(udidHash); + HcFree(subUdidHashUpper); + return HC_ERROR; +} + +static const char *GetUdidByGroup(int32_t osAccountId, const char *groupId, const char *deviceIdHash) +{ + uint32_t index; + TrustedDeviceEntry **deviceEntry = NULL; + DeviceEntryVec deviceEntryVec = CREATE_HC_VECTOR(DeviceEntryVec); + QueryDeviceParams params = InitQueryDeviceParams(); + params.groupId = groupId; + if (QueryDevices(osAccountId, ¶ms, &deviceEntryVec) != HC_SUCCESS) { + LOGE("query trusted devices failed!"); + ClearDeviceEntryVec(&deviceEntryVec); + return NULL; + } + FOR_EACH_HC_VECTOR(deviceEntryVec, index, deviceEntry) { + const char *udid = StringGet(&(*deviceEntry)->udid); + if (IsDeviceIdHashMatch(udid, deviceIdHash) == HC_SUCCESS) { + ClearDeviceEntryVec(&deviceEntryVec); + return udid; + } + continue; + } + ClearDeviceEntryVec(&deviceEntryVec); + return NULL; +} + +static const char *GetDeviceIdByUdidHash(int32_t osAccountId, const char *deviceIdHash) +{ + if (deviceIdHash == NULL) { + LOGE("deviceIdHash is null"); + return NULL; + } + QueryGroupParams queryParams = InitQueryGroupParams(); + GroupEntryVec groupEntryVec = CreateGroupEntryVec(); + int32_t ret = QueryGroups(osAccountId, &queryParams, &groupEntryVec); + if (ret != HC_SUCCESS) { + LOGE("Failed to query groups!"); + ClearGroupEntryVec(&groupEntryVec); + return NULL; + } + uint32_t index; + TrustedGroupEntry **ptr = NULL; + FOR_EACH_HC_VECTOR(groupEntryVec, index, ptr) { + const TrustedGroupEntry *groupEntry = (const TrustedGroupEntry *)(*ptr); + const char *groupId = StringGet(&(groupEntry->id)); + if (groupId == NULL) { + continue; + } + const char *udid = GetUdidByGroup(osAccountId, groupId, deviceIdHash); + if (udid != NULL) { + ClearGroupEntryVec(&groupEntryVec); + return udid; + } + } + ClearGroupEntryVec(&groupEntryVec); + return NULL; +} + +const char *GetPeerUdidFromJson(int32_t osAccountId, const CJson *in) +{ + const char *peerConnDeviceId = GetStringFromJson(in, FIELD_PEER_CONN_DEVICE_ID); + if (peerConnDeviceId == NULL) { + LOGI("get peerConnDeviceId from json fail."); + return NULL; + } + bool isUdidHash = false; + (void)GetBoolFromJson(in, FIELD_IS_UDID_HASH, &isUdidHash); + if (isUdidHash) { + const char *deviceId = GetDeviceIdByUdidHash(osAccountId, peerConnDeviceId); + return (deviceId == NULL ? peerConnDeviceId : deviceId); + } + return peerConnDeviceId; +} diff --git a/services/session_manager/inc/dev_session_mgr.h b/services/session_manager/inc/dev_session_mgr.h index 42d545dd466a59cde575b02fc048820e342c29e8..f31d0662912e96b06767821a4239a76b5b15ad88 100644 --- a/services/session_manager/inc/dev_session_mgr.h +++ b/services/session_manager/inc/dev_session_mgr.h @@ -34,6 +34,9 @@ void CloseDevSession(int64_t sessionId); bool IsSessionExist(int64_t sessionId); void CancelDevSession(int64_t sessionId, const char *appId); +int32_t PushStartSessionTask(int64_t sessionId); +int32_t PushProcSessionTask(int64_t sessionId, CJson *receivedMsg); + #ifdef __cplusplus } #endif diff --git a/services/session_manager/src/dev_session_mgr.c b/services/session_manager/src/dev_session_mgr.c index cb2ed967e771d49ab9eb069cac3ab25e129868e8..84f80bb129c6186471270318fcc6c2ac992d055f 100644 --- a/services/session_manager/src/dev_session_mgr.c +++ b/services/session_manager/src/dev_session_mgr.c @@ -23,12 +23,24 @@ #include "hc_mutex.h" #include "hc_time.h" #include "hc_vector.h" +#include "task_manager.h" typedef struct { DevSession *session; int64_t createTime; } SessionInfo; +typedef struct { + HcTaskBase base; + int64_t sessionId; +} StartSessionTask; + +typedef struct { + HcTaskBase base; + int64_t sessionId; + CJson *receivedMsg; +} ProcSessionTask; + DECLARE_HC_VECTOR(SessionInfoList, SessionInfo) IMPLEMENT_HC_VECTOR(SessionInfoList, SessionInfo, 1) @@ -246,3 +258,98 @@ void CancelDevSession(int64_t sessionId, const char *appId) LOGI("session not exist. [Id]: %" LOG_PUB PRId64, sessionId); UnlockHcMutex(&g_sessionMutex); } + +static void DoStartSession(HcTaskBase *task) +{ + LOGI("start session task begin."); + if (task == NULL) { + LOGE("The input task is NULL, can't start session!"); + return; + } + StartSessionTask *realTask = (StartSessionTask *)task; + SET_LOG_MODE(TRACE_MODE); + SET_TRACE_ID(realTask->sessionId); + int32_t res = StartDevSession(realTask->sessionId); + if (res != HC_SUCCESS) { + LOGE("start session fail.[Res]: %" LOG_PUB "d", res); + CloseDevSession(realTask->sessionId); + } +} + +static void DoProcSession(HcTaskBase *task) +{ + LOGI("proc session task begin."); + if (task == NULL) { + LOGE("The input task is NULL, can't start session!"); + return; + } + ProcSessionTask *realTask = (ProcSessionTask *)task; + SET_LOG_MODE(TRACE_MODE); + SET_TRACE_ID(realTask->sessionId); + bool isFinish = false; + int32_t res = ProcessDevSession(realTask->sessionId, realTask->receivedMsg, &isFinish); + if (res != HC_SUCCESS) { + LOGE("ProcessDevSession fail. [Res]: %" LOG_PUB "d", res); + CloseDevSession(realTask->sessionId); + return; + } + LOGI("ProcessDevSession success. [State]: %" LOG_PUB "s", isFinish ? "FINISH" : "CONTINUE"); + if (isFinish) { + CloseDevSession(realTask->sessionId); + } +} + +static void InitStartSessionTask(StartSessionTask *task, int64_t sessionId) +{ + task->base.doAction = DoStartSession; + task->base.destroy = NULL; + task->sessionId = sessionId; +} + +static void DestroyProcSessionTask(HcTaskBase *task) +{ + ProcSessionTask *realTask = (ProcSessionTask *)task; + FreeJson(realTask->receivedMsg); +} + +static void InitProcSessionTask(ProcSessionTask *task, int64_t sessionId, CJson *receivedMsg) +{ + task->base.doAction = DoProcSession; + task->base.destroy = DestroyProcSessionTask; + task->sessionId = sessionId; + task->receivedMsg = receivedMsg; +} + +int32_t PushStartSessionTask(int64_t sessionId) +{ + StartSessionTask *task = (StartSessionTask *)HcMalloc(sizeof(StartSessionTask), 0); + if (task == NULL) { + LOGE("Failed to allocate memory for task!"); + return HC_ERR_ALLOC_MEMORY; + } + InitStartSessionTask(task, sessionId); + if (PushTask((HcTaskBase*)task) != HC_SUCCESS) { + LOGE("push start session task fail."); + HcFree(task); + return HC_ERR_INIT_TASK_FAIL; + } + LOGI("push start session task success."); + return HC_SUCCESS; +} + +int32_t PushProcSessionTask(int64_t sessionId, CJson *receivedMsg) +{ + ProcSessionTask *task = (ProcSessionTask *)HcMalloc(sizeof(ProcSessionTask), 0); + if (task == NULL) { + LOGE("Failed to allocate memory for task!"); + return HC_ERR_ALLOC_MEMORY; + } + InitProcSessionTask(task, sessionId, receivedMsg); + if (PushTask((HcTaskBase*)task) != HC_SUCCESS) { + LOGE("push start session task fail."); + HcFree(task); + return HC_ERR_INIT_TASK_FAIL; + } + LOGI("push start session task success."); + return HC_SUCCESS; +} \ No newline at end of file diff --git a/services/session_manager/src/session/dev_session_fwk.c b/services/session_manager/src/session/dev_session_fwk.c index a5435ec5d0cd6593e120ee36bbdfea649614f464..49de88addb25d84e4b2df0edff5de3bee2a151ee 100644 --- a/services/session_manager/src/session/dev_session_fwk.c +++ b/services/session_manager/src/session/dev_session_fwk.c @@ -32,7 +32,7 @@ #include "hc_time.h" #include "hc_types.h" #include "performance_dumper.h" -#include "hisysevent_adapter.h" +#include "hisysevent_common.h" static int32_t StartV1Session(SessionImpl *impl, CJson **sendMsg) { @@ -228,25 +228,6 @@ static bool IsMetaNode(const CJson *context) return GetStringFromJson(context, FIELD_META_NODE_TYPE) != NULL; } -#ifdef DEV_AUTH_HIVIEW_ENABLE -static DevAuthBizScene GetBizScene(bool isBind, bool isClient) -{ - if (isBind) { - if (isClient) { - return BIZ_SCENE_ADD_MEMBER_CLIENT; - } else { - return BIZ_SCENE_ADD_MEMBER_SERVER; - } - } else { - if (isClient) { - return BIZ_SCENE_AUTH_DEVICE_CLIENT; - } else { - return BIZ_SCENE_AUTH_DEVICE_SERVER; - } - } -} -#endif - static void ReportBehaviorEvent(const SessionImpl *impl, bool isProcessEnd, bool isBehaviorEnd, int32_t res) { #ifdef DEV_AUTH_HIVIEW_ENABLE diff --git a/test/fuzztest/session_manager/session/v2/auth_sub_session/authsubsession_fuzzer/BUILD.gn b/test/fuzztest/session_manager/session/v2/auth_sub_session/authsubsession_fuzzer/BUILD.gn index d0e267b6db852f0c56a34d4fcaef525f5eeac6fa..ea29c659924b0e390c26b8afd3cc016259f04dc0 100644 --- a/test/fuzztest/session_manager/session/v2/auth_sub_session/authsubsession_fuzzer/BUILD.gn +++ b/test/fuzztest/session_manager/session/v2/auth_sub_session/authsubsession_fuzzer/BUILD.gn @@ -74,6 +74,7 @@ ohos_fuzztest("AuthSubSessionFuzzTest") { "${services_path}/ext_plugin_manager/inc/account_related", "${services_path}/ext_plugin_manager/inc", "${protocol_path}/inc", + "${device_auth_common}/inc", "${session_manager_path}/inc/session/v2/auth_sub_session/protocol_lib", ] sources += identity_manager_files diff --git a/test/fuzztest/session_manager/session/v2/expand_sub_session/expand_process_lib/authcodeimport_fuzzer/BUILD.gn b/test/fuzztest/session_manager/session/v2/expand_sub_session/expand_process_lib/authcodeimport_fuzzer/BUILD.gn index 59b19d3d50e9e4c139e757874768263f591f322e..a8411de2e935eedb5c83a9bd5d41224df7f66dee 100644 --- a/test/fuzztest/session_manager/session/v2/expand_sub_session/expand_process_lib/authcodeimport_fuzzer/BUILD.gn +++ b/test/fuzztest/session_manager/session/v2/expand_sub_session/expand_process_lib/authcodeimport_fuzzer/BUILD.gn @@ -69,6 +69,7 @@ ohos_fuzztest("AuthCodeImportFuzzTest") { "${mk_agree_path}/inc", "${services_path}/ext_plugin_manager/inc/account_related", "${services_path}/ext_plugin_manager/inc", + "${device_auth_common}/inc", "${protocol_path}/inc", ] sources += identity_manager_files diff --git a/test/fuzztest/session_manager/session/v2/expand_sub_session/expand_process_lib/pubkeyexchange_fuzzer/BUILD.gn b/test/fuzztest/session_manager/session/v2/expand_sub_session/expand_process_lib/pubkeyexchange_fuzzer/BUILD.gn index 60f4c78d94f2f8e5bf7028a6a93efdc85b090720..4d649e0911b46aada83399d38fabc1db16777400 100644 --- a/test/fuzztest/session_manager/session/v2/expand_sub_session/expand_process_lib/pubkeyexchange_fuzzer/BUILD.gn +++ b/test/fuzztest/session_manager/session/v2/expand_sub_session/expand_process_lib/pubkeyexchange_fuzzer/BUILD.gn @@ -72,6 +72,7 @@ ohos_fuzztest("PubkeyExchangeFuzzTest") { "${mk_agree_path}/inc", "${services_path}/ext_plugin_manager/inc/account_related", "${services_path}/ext_plugin_manager/inc", + "${device_auth_common}/inc", "${protocol_path}/inc", ] sources += identity_manager_files diff --git a/test/fuzztest/session_manager/session/v2/expand_sub_session/expand_process_lib/savetrustedinfo_fuzzer/BUILD.gn b/test/fuzztest/session_manager/session/v2/expand_sub_session/expand_process_lib/savetrustedinfo_fuzzer/BUILD.gn index c660696999470f468bf072ba93cad9c92fc241c5..385feee8f809035be1622fc06f88554adb511bb0 100644 --- a/test/fuzztest/session_manager/session/v2/expand_sub_session/expand_process_lib/savetrustedinfo_fuzzer/BUILD.gn +++ b/test/fuzztest/session_manager/session/v2/expand_sub_session/expand_process_lib/savetrustedinfo_fuzzer/BUILD.gn @@ -70,6 +70,7 @@ ohos_fuzztest("SaveTrustedInfoFuzzTest") { "${mk_agree_path}/inc", "${services_path}/ext_plugin_manager/inc/account_related", "${services_path}/ext_plugin_manager/inc", + "${device_auth_common}/inc", "${protocol_path}/inc", ] sources += identity_manager_files diff --git a/test/fuzztest/session_manager/session/v2/expand_sub_session/expandsubsession_fuzzer/BUILD.gn b/test/fuzztest/session_manager/session/v2/expand_sub_session/expandsubsession_fuzzer/BUILD.gn index 0c081bc565deec7d746b9b461713a64706af8a83..88303c71f51eb19676a2dcec5a379b7a385a9be0 100644 --- a/test/fuzztest/session_manager/session/v2/expand_sub_session/expandsubsession_fuzzer/BUILD.gn +++ b/test/fuzztest/session_manager/session/v2/expand_sub_session/expandsubsession_fuzzer/BUILD.gn @@ -76,6 +76,7 @@ ohos_fuzztest("ExpandSubSessionFuzzTest") { "${mk_agree_path}/inc", "${services_path}/ext_plugin_manager/inc/account_related", "${services_path}/ext_plugin_manager/inc", + "${device_auth_common}/inc", "${protocol_path}/inc", ] sources += identity_manager_files diff --git a/test/unittest/deviceauth/unit_test/source/account_related_group_auth_dir_test.cpp b/test/unittest/deviceauth/unit_test/source/account_related_group_auth_dir_test.cpp index 09347b6b220cd68064d32b76e339eac3baf75d7c..ad88da5478c89c76d332f7bd55dd31b83de120ee 100644 --- a/test/unittest/deviceauth/unit_test/source/account_related_group_auth_dir_test.cpp +++ b/test/unittest/deviceauth/unit_test/source/account_related_group_auth_dir_test.cpp @@ -159,10 +159,10 @@ HWTEST_F(AccountRelatedGroupAuthTest, AccountRelatedGroupAuthTest002, TestSize.L (void)GetAccountRelatedGroupAuth()->onFinish(0, authParam, out, &g_deviceAuthCallBack); // For unit test. ret = AddObjToJson(out, FIELD_SEND_TO_PEER, sendToPeer); - EXPECT_EQ(ret, HC_SUCCESS); FreeJson(sendToPeer); FreeJson(out); FreeJson(authParam); + EXPECT_EQ(ret, HC_SUCCESS); } HWTEST_F(AccountRelatedGroupAuthTest, AccountRelatedGroupAuthTest0021, TestSize.Level0) @@ -279,7 +279,7 @@ HWTEST_F(AccountRelatedGroupAuthTest, AccountRelatedGroupAuthTest0023, TestSize. (void)AddStringToJson(sendToSelf, FIELD_USER_ID, "USER_ID"); // For unit test. (void)AddObjToJson(out, FIELD_SEND_TO_SELF, sendToSelf); (void)GetAccountRelatedGroupAuth()->onFinish(0, authParam, out, &g_deviceAuthCallBack); // For unit test. - ret = AddObjToJson(out, FIELD_SEND_TO_PEER, sendToPeer); + ret = AddObjToJson(out, FIELD_SEND_TO_SELF, sendToSelf); EXPECT_EQ(ret, HC_SUCCESS); FreeJson(sendToSelf); FreeJson(out); diff --git a/test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/expand_sub_session/BUILD.gn b/test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/expand_sub_session/BUILD.gn index 949313395ee62925ef47fd1a136bb6c7e3543157..7287ed19b5a9878e86b4cd73bf7dce37a45b486c 100644 --- a/test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/expand_sub_session/BUILD.gn +++ b/test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/expand_sub_session/BUILD.gn @@ -34,6 +34,7 @@ ohos_unittest("expand_sub_session_test") { "${mk_agree_path}/inc", "${services_path}/ext_plugin_manager/inc/account_related", "${services_path}/ext_plugin_manager/inc", + "${device_auth_common}/inc", "${protocol_path}/inc", ] include_dirs += identity_service_inc diff --git a/test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/expand_sub_session/expand_process_lib/BUILD.gn b/test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/expand_sub_session/expand_process_lib/BUILD.gn index 8c0f8315299dcbc0bb1782cbaa4c6cf475ba9f05..b19becfe6c9aa8065725a29711a85616897cc7c1 100644 --- a/test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/expand_sub_session/expand_process_lib/BUILD.gn +++ b/test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/expand_sub_session/expand_process_lib/BUILD.gn @@ -60,6 +60,7 @@ ohos_unittest("auth_code_import_test") { "${mk_agree_path}/inc", "${services_path}/ext_plugin_manager/inc/account_related", "${services_path}/ext_plugin_manager/inc", + "${device_auth_common}/inc", "${protocol_path}/inc", ] sources += identity_manager_files @@ -123,6 +124,7 @@ ohos_unittest("pub_key_exchange_test") { "${mk_agree_path}/inc", "${services_path}/ext_plugin_manager/inc/account_related", "${services_path}/ext_plugin_manager/inc", + "${device_auth_common}/inc", "${protocol_path}/inc", ]