diff --git a/BUILD.gn b/BUILD.gn index f077ba5e76e9a3fe3b661b189095a30a442fe0e7..1664932afef197d3bb569655a085c42384eb9688 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -13,8 +13,5 @@ import("//build/ohos.gni") group("dataclassification_build_module") { - deps = [ - "//base/security/dataclassification/interfaces/innerkits/fbe_iudf_xattr:fbe_iudf_xattr", - "//base/security/dataclassification/interfaces/innerkits/hwdevsl:hwdsl", - ] + deps = [ "//base/security/dataclassification/interfaces/innerkits/datasecuritylevel:datasecuritylevel" ] } diff --git a/README_zh.md b/README_zh.md old mode 100755 new mode 100644 index 1303c5342664a8949a81ab167bca69f1144c30c5..6b64ecbd8193465a73af3b92f7ec4ea0592649ac --- a/README_zh.md +++ b/README_zh.md @@ -1,75 +1,143 @@ -# 数据分级保护 - -- [简介](#section11660541593) -- [系统架构](#section342962219551) -- [接口说明](#section92711824195113) -- [相关仓](#section155556361910) - -## 简介 - -在OpenHarmony中,数据分级保护模块负责提供数据分级的保护策略。数据分级保护模块提供了数据分级相关的接口定义。(OpenHarmony当前不提供实际的功能实现。依赖设备厂商实现接口对应的功能,对搭载OpenHarmony的设备上的数据提供安全保护)。 - -数据分级保护模块当前提供如下接口定义: - -- 数据分级标签设置和查询接口:对业务生成的文件数据提供设置和查询风险等级标签的接口,业务可使用该接口设定和查询落盘文件数据的风险等级,使该文件在系统中具有对应的数据风险分级标识。 -- 基于设备安全等级的数据跨设备访问控制接口:提供基于设备安全等级的数据跨设备访问控制的接口,分布式跨设备数据传输业务可使用该接口获得对端设备可支持的数据风险等级。 - -为实现上述接口定义,数据分级保护模块当前包含数据分级标签设置查询接口和基于设备安全等级的数据跨设备访问控制接口两个子模块,模块中仅包括接口定义,而不包含实际的功能实现,其部署逻辑如下图: - -## 系统架构 - -**图 1** 数据分级保护子系统架构图 - - -![](figures/dataclassification_zh.png) - -## 接口说明 - -**表 1** 数据分级保护提供的API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - -

接口名

-

描述

-

int SetLabel(int userId, const char *filePath, const char *labelName, const char *labelValue, int flag);

-

设置风险等级标签能力,当前返回成功,设备厂商需自行实现标签风险等级设置能力。建议设置在文件的扩展属性中,数据风险等级更详细的定义描述参考开发者文档。

-

int GetLabel(int userId, const char *filePath, const char *labelName, char *labelValue, const int valueLen);

-

查询风险等级标签能力,当前返回S3,设备厂商自行实现标签风险等级查询能力。数据风险等级更详细的定义描述参考开发者文档。

-

int GetFlag(int userId, const char *filePath, const char *labelName);

-

查询风险等级的辅助信息,当前返回FLAG_FILE_PROTECTION_COMPLETE_UNLESS_OPEN,设备厂商自行实现标风险等级的辅助信息查询能力。数据风险等级更详细的定义描述参考开发者文档。

-

int32_t DEVSL_GetHighestSecLevel(DEVSLQueryParams *queryParams, uint32_t *levelInfo);

-

获取对应设备可支持的数据风险等级,当前返回S3,设备厂商需自行实现该功能,数据风险等级更详细的定义描述参考开发者文档。

-

int32_t DEVSL_OnStart(int32_t maxDevNum);

-

设备数据安全等级模块初始化,设备厂商需自行实现该功能。

-

void DEVSL_ToFinish(void);

-

设备数据安全等级模块去初始化,设备厂商需自行实现该功能。

-
- -## 相关仓 - -安全子系统 - -base/security/dataclassification - +# 数据分级保护 + +- [数据分级保护](#数据分级保护) + - [简介](#简介) + - [系统架构](#系统架构) + - [目录](#目录) + - [约束](#约束) + - [说明](#说明) + - [接口说明](#接口说明) + - [使用说明](#使用说明) + - [相关仓](#相关仓) + +## 简介 + +在OpenHarmony中,数据分级保护模块负责提供数据分级的保护策略。数据分级保护模块提供了数据分级相关的接口定义。(OpenHarmony当前不提供实际的功能实现。依赖设备厂商实现接口对应的功能,对搭载OpenHarmony的设备上的数据提供安全保护)。 + +数据分级保护模块当前提供如下接口定义: + +- 基于设备安全等级的数据跨设备访问控制接口:提供基于设备安全等级的数据跨设备访问控制的接口,分布式跨设备数据传输业务可使用该接口获得对端设备可支持的数据风险等级。 + +## 系统架构 + + + +## 目录 + + + +``` +base/security/dataclassification +├── frameworks +│ └── datasecuritylevel # 代码实现 +├── interfaces # 接口API代码 +│ └── innerkits +│ └── datasecuritylevel +└── text #测试代码 + └── unittest + └── datasecuritylevel +``` + + + +## 约束 + +- 开发语言:C + +## 说明 + +### 接口说明 + +数据分级保护提供的API接口功能介绍 + +| 接口名 | 描述 | +| ------------------------------------------------------------ | :----------------------------------------------------- | +| int32_t DATASL_GetHighestSecLevel(DEVSLQueryParams *queryParams, uint32_t *levelInfo); | 请求获取对应设备允许传输的最高数据安全等级(同步接口) | +| int32_t DATASL_GetHighestSecLevelAsync(DEVSLQueryParams *queryParams, HigestSecInfoCallback *callback); | 请求获取对应设备允许传输的最高数据安全等级(异步接口) | +| int32_t DATASL_OnStart(void); | 初始化模块 | +| void DATASL_OnStop(void); | 模块退出 | + +### 使用说明 + +所有接口均为native C内部接口 + +#### 依赖添加 + +1、编译依赖添加 + +``` +external_deps += [ "dataclassification:datasecuritylevel" ] +``` + +2、头文件添加 + +``` +#include "dev_slinfo_mgr.h" +``` + +接口使用示例 + +1、同步接口使用示例如下: + +```c++ +void CheckDestHighestSecurityLevel(DEVSLQueryParams *queryParams) +{ + // 数据风险等级 + uint32_t levelInfo = 0; + + //初始化模块 + int32_t ret = DATASL_OnStart(); + if (ret != DEVSL_SUCCESS) { + // 初始化模块失败。此场景建议开发者根据实际情况进行重试 + return; + } + + // 调用同步接口获取设备允许的最高数据风险等级 + int32_t ret = DATASL_GetHighestSecLevel(queryParams, &levelInfo); + if (ret != DEVSL_SUCCESS) { + // 获取信息失败。此场景建议开发者根据实际情况进行重试 + return; + } + + // 模块退出 + DATASL_OnStop(); +} +``` + +2、异步接口使用示例如下: + +```c++ +// 回调函数,callback返回错误码以及设备允许的最高数据风险等级 +void HigestSecInfoCallback(DEVSLQueryParams *queryParams, int32_t result, uint32_t levelInfo) +{ + if (result != DEVSL_SUCCESS) { + // 异步获取信息失败。此场景建议开发者根据实际情况进行重试 + return; + } +} +void CheckDestHighestSecurityLevel(DEVSLQueryParams *queryParams) +{ + //初始化模块,重复初始化不影响功能,建议避免重复操作 + int32_t ret = DATASL_OnStart(); + + //调用异步接口获取设备允许的最高数据风险等级 + ret = DATASL_GetHighestSecLevelAsync(queryParams, HigestSecInfoCallback); + if (ret != DEVSL_SUCCESS) { + // 获取信息失败,此场景建议开发者根据实际情况进行重试 + // 此场景下callback不会回调。 + return; + } + // 调用成功,等待callback回调。 + + //关闭模块,注意在多线程的情况下慎重使用,当前线程关闭之后会对其他线程造成影响 + DATASL_OnStop(); +} +``` + + + +## 相关仓 + +安全子系统 + +base/security/dataclassification \ No newline at end of file diff --git a/bundle.json b/bundle.json index 0df9d005ffdd0996233bbe2da94eb865d67693ad..201fabc865f3c658cb1e4903e192014c28436449 100755 --- a/bundle.json +++ b/bundle.json @@ -17,12 +17,13 @@ "adapted_system_type": [ "standard" ], - "rom": "30KB", - "ram": "20KB", + "rom": "50KB", + "ram": "50KB", "deps": { "components": [ "utils_base", - "libhilog" + "libhilog", + "dslm_sdk" ], "third_party": [] }, @@ -32,28 +33,17 @@ ], "inner_kits": [ { - "name": "//base/security/dataclassification/interfaces/innerkits/fbe_iudf_xattr:fbe_iudf_xattr", + "name": "//base/security/dataclassification/interfaces/innerkits/datasecuritylevel:datasecuritylevel", "header": { "header_files": [ - "fbe_sdp_code_num.h", - "fbe_sdp_policy.h" + "dev_slinfo_mgr.h" ], - "header_base": "//base/security/dataclassification/interfaces/innerkits/fbe_iudf_xattr/include" - } - }, - { - "name": "//base/security/dataclassification/interfaces/innerkits/hwdevsl:hwdsl", - "header": { - "header_files": [ - "1.0/dev_slinfo_mgr.h" - ], - "header_base": "//base/security/dataclassification/interfaces/innerkits/hwdevsl/include" + "header_base": "//base/security/dataclassification/interfaces/innerkits/datasecuritylevel/include" } } ], "test": [ - "//base/security/dataclassification/test/unittest/fbe_iudf_xattr:fbe_iudf_xattr_test", - "//base/security/dataclassification/test/unittest/hwdevsl:hwdevsl_test" + "//base/security/dataclassification/test/unittest/datasecuritylevel:DevSLMgrTest" ] } } diff --git a/frameworks/datasecuritylevel/dev_slinfo_adpt.c b/frameworks/datasecuritylevel/dev_slinfo_adpt.c new file mode 100644 index 0000000000000000000000000000000000000000..fe6ff67f9fcbefda18e650f38cf40bd8251356e0 --- /dev/null +++ b/frameworks/datasecuritylevel/dev_slinfo_adpt.c @@ -0,0 +1,310 @@ +/* + * 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 "dev_slinfo_adpt.h" +#include +#include "securec.h" +#include "dev_slinfo_list.h" +#include "dev_slinfo_log.h" +#include "dev_slinfo_mgr.h" + +void *g_deviceSecDlhandle = NULL; +DeviceSecEnv g_deviceSecEnv; +static struct DATASLListParams *g_callback = NULL; + +static void DestroyDeviceSecEnv(void) +{ + if (g_deviceSecDlhandle != NULL) { + (void)memset_s(&g_deviceSecEnv, sizeof(g_deviceSecEnv), 0, sizeof(g_deviceSecEnv)); + dlclose(g_deviceSecDlhandle); + g_deviceSecDlhandle = NULL; + } + return; +} + +static int32_t DlopenSDK(void) +{ + g_deviceSecDlhandle = dlopen("libdslm_sdk.z.so", RTLD_LAZY | RTLD_NODELETE); + if (!g_deviceSecDlhandle) { + DATA_SEC_LOG_ERROR("failed to load libdevicesecmgrsdktmp: %s", dlerror()); + return DEVSL_ERROR; + } + + return SUCCESS; +} + +static int32_t InitDeviceSecEnv(void) +{ + if (g_deviceSecDlhandle != NULL) { + DATA_SEC_LOG_WARN("libdevicesecmgrsdk already loaded"); + return SUCCESS; + } + int32_t ret = DlopenSDK(); + if (ret != SUCCESS) { + return ret; + } + RequestDeviceSecurityInfoFunction requestDeviceSecurityInfo = (RequestDeviceSecurityInfoFunction)dlsym( + g_deviceSecDlhandle, "RequestDeviceSecurityInfo"); + if (!requestDeviceSecurityInfo) { + dlclose(g_deviceSecDlhandle); + g_deviceSecDlhandle = NULL; + DATA_SEC_LOG_ERROR("failed to find symbol: %s", dlerror()); + return DEVSL_ERROR; + } + FreeDeviceSecurityInfoFunction freeDeviceSecurityInfo = (FreeDeviceSecurityInfoFunction)dlsym(g_deviceSecDlhandle, + "FreeDeviceSecurityInfo"); + if (!freeDeviceSecurityInfo) { + dlclose(g_deviceSecDlhandle); + g_deviceSecDlhandle = NULL; + DATA_SEC_LOG_ERROR("failed to find symbol: %s", dlerror()); + return DEVSL_ERROR; + } + GetDeviceSecurityLevelValueFunction getDeviceSecurityLevelValue = (GetDeviceSecurityLevelValueFunction)dlsym( + g_deviceSecDlhandle, "GetDeviceSecurityLevelValue"); + if (!getDeviceSecurityLevelValue) { + dlclose(g_deviceSecDlhandle); + g_deviceSecDlhandle = NULL; + DATA_SEC_LOG_ERROR("failed to find symbol: %s", dlerror()); + return DEVSL_ERROR; + } + RequestDeviceSecurityInfoAsyncFunction requestDeviceSecurityInfoAsync = + (RequestDeviceSecurityInfoAsyncFunction)dlsym(g_deviceSecDlhandle, "RequestDeviceSecurityInfoAsync"); + if (!requestDeviceSecurityInfoAsync) { + dlclose(g_deviceSecDlhandle); + g_deviceSecDlhandle = NULL; + DATA_SEC_LOG_ERROR("failed to find symbol: %s", dlerror()); + return DEVSL_ERROR; + } + (void)memset_s(&g_deviceSecEnv, sizeof(g_deviceSecEnv), 0, sizeof(g_deviceSecEnv)); + g_deviceSecEnv.requestDeviceSecurityInfo = requestDeviceSecurityInfo; + g_deviceSecEnv.freeDeviceSecurityInfo = freeDeviceSecurityInfo; + g_deviceSecEnv.getDeviceSecurityLevelValue = getDeviceSecurityLevelValue; + g_deviceSecEnv.requestDeviceSecurityInfoAsync = requestDeviceSecurityInfoAsync; + return SUCCESS; +} + +int32_t StartDevslEnv() +{ + DATA_SEC_LOG_INFO("Enter InitDeviceSecEnv..."); + int32_t ret = InitDeviceSecEnv(); + DATA_SEC_LOG_INFO("InitDeviceSecEnv done"); + if (ret != SUCCESS) { + return DEVSL_ERR_DEVICE_SEC_SDK_INIT; + } + return SUCCESS; +} + +void FinishDevslEnv(void) +{ + DestroyDeviceSecEnv(); + return; +} + +int32_t GetDeviceSecLevelByUdid(uint8_t *udid, uint32_t udidLen, int32_t *devLevel) +{ + DATA_SEC_LOG_INFO("Enter GetDeviceSecLevelByUdid!"); + if (g_deviceSecEnv.requestDeviceSecurityInfo == NULL) { + DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdid: requestDeviceSecurityInfo is incalid"); + return DEVSL_ERROR; + } + + if (g_deviceSecEnv.freeDeviceSecurityInfo == NULL) { + DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdid: freeDeviceSecurityInfo is incalid"); + return DEVSL_ERROR; + } + + if (g_deviceSecEnv.getDeviceSecurityLevelValue == NULL) { + DATA_SEC_LOG_ERROR("GetDeviceSecByUdid: getDeviceSecurityLevelValue is incalid"); + return DEVSL_ERROR; + } + + int32_t ret; + struct DeviceSecurityInfo *info = NULL; + + struct DeviceIdentify devId; + (void)memset_s(&devId, sizeof(devId), 0, sizeof(devId)); + + if (memcpy_s(devId.identity, DEVICE_ID_MAX_LEN, udid, udidLen) != EOK) { + DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdid, udid memcpy failed"); + return DEVSL_ERR_MEM_CPY; + } + devId.length = udidLen; + + ret = g_deviceSecEnv.requestDeviceSecurityInfo(&devId, NULL, &info); + if (ret != SUCCESS) { + DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdid: request device Security info failed, %d", ret); + g_deviceSecEnv.freeDeviceSecurityInfo(info); + return ret; + } + + ret = g_deviceSecEnv.getDeviceSecurityLevelValue(info, devLevel); + if (ret != SUCCESS) { + DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdid, get device Security value failed, %d", ret); + g_deviceSecEnv.freeDeviceSecurityInfo(info); + return ret; + } + + g_deviceSecEnv.freeDeviceSecurityInfo(info); + DATA_SEC_LOG_INFO("GetDeviceSecLevelByUdid done!"); + return SUCCESS; +} + +// Async +void OnApiDeviceSecInfoCallback(const DeviceIdentify *identify, struct DeviceSecurityInfo *info) +{ + pthread_mutex_lock(&gMutex); + DATA_SEC_LOG_INFO("Enter OnApiDeviceSecInfoCallback!"); + int32_t ret; + + if (g_deviceSecEnv.getDeviceSecurityLevelValue == NULL) { + DATA_SEC_LOG_ERROR("OnApiDeviceSecInfoCallback: getDeviceSecValue is incalid"); + ret = DEVSL_ERROR; + } + + if (g_deviceSecEnv.freeDeviceSecurityInfo == NULL) { + DATA_SEC_LOG_ERROR("OnApiDeviceSecInfoCallback: freeDeviceSecurityInfo is incalid"); + ret = DEVSL_ERROR; + } + + int32_t devLevel = DEFAULT_DEV_SEC_LEVEL; + uint32_t levelInfo = DEFAULT_DEV_SEC_LEVEL; + ret = g_deviceSecEnv.getDeviceSecurityLevelValue(info, &devLevel); + if (ret != SUCCESS) { + DATA_SEC_LOG_ERROR("OnApiDeviceSecInfoCallback, get device security level value, %d", ret); + } else { + levelInfo = GetDataSecLevelByDevSecLevel(devLevel); + } + + g_deviceSecEnv.freeDeviceSecurityInfo(info); + DEVSLQueryParams queryParams; + (void)memset_s(&queryParams, sizeof(queryParams), 0, sizeof(queryParams)); + + if (memcpy_s(queryParams.udid, DEVICE_ID_MAX_LEN, identify->identity, identify->length) != EOK) { + DATA_SEC_LOG_ERROR("OnApiDeviceSecInfoCallback, udid memcpy failed"); + pthread_mutex_unlock(&gMutex); + return; + } + queryParams.udidLen = identify->length; + + if (g_callback != NULL) { + struct DATASLListParams *tmpCallback = g_callback->next; + while (tmpCallback != NULL && tmpCallback != g_callback) { + struct DATASLListParams *nextCallback = tmpCallback->next; + int32_t result = UdidCmp(tmpCallback->callbackParams->queryParams, &queryParams); + if (result == SUCCESS) { + tmpCallback->callbackParams->callback(&queryParams, ret, levelInfo); + ListPop(g_callback, tmpCallback->callbackParams); + } + tmpCallback = nextCallback; + } + } + + DATA_SEC_LOG_INFO("OnApiDeviceSecInfoCallback done, ret %d!", ret); + pthread_mutex_unlock(&gMutex); +} + +int32_t GetDeviceSecLevelByUdidAsync(uint8_t *udid, uint32_t udidLen) +{ + DATA_SEC_LOG_INFO("Enter GetDeviceSecLevelByUdidAsync!"); + if (g_deviceSecEnv.requestDeviceSecurityInfoAsync == NULL) { + DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdidAsync: requestDeviceSecurityInfoAsync is incalid"); + return DEVSL_ERROR; + } + + int32_t ret; + DeviceIdentify devId; + (void)memset_s(&devId, sizeof(devId), 0, sizeof(devId)); + + if (memcpy_s(devId.identity, DEVICE_ID_MAX_LEN, udid, udidLen) != EOK) { + DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdidAsync, udid memcpy failed"); + return DEVSL_ERR_MEM_CPY; + } + devId.length = udidLen; + ret = g_deviceSecEnv.requestDeviceSecurityInfoAsync(&devId, NULL, OnApiDeviceSecInfoCallback); + if (ret != SUCCESS) { + DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdidAsync, request device security Info for Async failed, %d", ret); + return ret; + } + + DATA_SEC_LOG_INFO("GetDeviceSecLevelByUdidAsync done, ret %d!", ret); + return ret; +} + +int32_t UdidCmp(DEVSLQueryParams *queryParamsL, DEVSLQueryParams *queryParamsR) +{ + uint32_t i; + if (queryParamsL->udidLen != queryParamsR->udidLen) { + return DEVSL_ERROR; + } + for (i = 0; i < queryParamsL->udidLen; i++) { + if (queryParamsL->udid[i] != queryParamsR->udid[i]) { + return DEVSL_ERROR; + } + } + return SUCCESS; +} + +int32_t GetDataSecLevelByDevSecLevel(int32_t devLevel) +{ + int32_t i; + int32_t n; + struct { + int32_t devSecLevel; + int32_t dataSecLevel; + } devTypeMap[] = { + { DEV_SEC_LEVEL1, DATA_SEC_LEVEL1 }, + { DEV_SEC_LEVEL2, DATA_SEC_LEVEL2 }, + { DEV_SEC_LEVEL3, DATA_SEC_LEVEL4 }, + { DEV_SEC_LEVEL4, DATA_SEC_LEVEL4 }, + { DEV_SEC_LEVEL5, DATA_SEC_LEVEL4 }, + }; + + n = (int32_t)(sizeof(devTypeMap) / sizeof(devTypeMap[0])); + for (i = 0; i < n; i++) { + if (devTypeMap[i].devSecLevel == devLevel) { + return devTypeMap[i].dataSecLevel; + } + } + if (i >= n) { + DATA_SEC_LOG_WARN("GetDataSecLevelBySecLevel, unknow device level tag: %d", devLevel); + } + return DATA_SEC_LEVEL0; +} + +int32_t UpdateCallback(DEVSLQueryParams *queryParams, HigestSecInfoCallback *callback) +{ + int32_t ret; + int32_t result = DEVSL_ERR_SERVICES_TOO_MANY; + int32_t levelInfo = DEFAULT_DEV_SEC_LEVEL; + if (g_callback == NULL) { + g_callback = ListInit(); + } + + struct DATASLCallbackParams newList; + newList.queryParams = queryParams; + newList.callback = callback; + + ret = ListLength(g_callback); + if (ret == MAX_LIST_SUM) { + g_callback->next->callbackParams->callback(queryParams, result, levelInfo); + ListPop(g_callback, g_callback->next->callbackParams); + } + + ret = ListFind(g_callback, &newList); + if (ret != SUCCESS) { + ListPush(g_callback, &newList); + } + return SUCCESS; +} \ No newline at end of file diff --git a/frameworks/datasecuritylevel/dev_slinfo_list.c b/frameworks/datasecuritylevel/dev_slinfo_list.c new file mode 100644 index 0000000000000000000000000000000000000000..e4fc7fa6f9ae600b84b78a7f00bc6af40979bf18 --- /dev/null +++ b/frameworks/datasecuritylevel/dev_slinfo_list.c @@ -0,0 +1,118 @@ +/* + * 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 "dev_slinfo_list.h" +#include "dev_slinfo_adpt.h" +#include "dev_slinfo_log.h" + +struct DATASLListParams* ListInit(void) +{ + pthread_mutex_lock(&gMutex); + struct DATASLListParams *list; + list = (struct DATASLListParams *)malloc(sizeof(struct DATASLListParams)); + list->next = list; + list->prev = list; + pthread_mutex_unlock(&gMutex); + return list; +} + +void Update(struct DATASLListParams *new, struct DATASLListParams *prev, struct DATASLListParams *next) +{ + next->prev = new; + new->next = next; + new->prev = prev; + prev->next = new; +} + +void ListPush(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams) +{ + DATA_SEC_LOG_INFO("ListPush, ret!"); + pthread_mutex_lock(&gMutex); + struct DATASLListParams *newList = (struct DATASLListParams*)malloc(sizeof(struct DATASLListParams)); + if (list->prev == NULL) { + list->prev = newList; + list->next = newList; + newList->prev = list; + newList->next = list; + } else { + Update(newList, list->prev, list); + } + newList->callbackParams = (struct DATASLCallbackParams*)callbackParams; + pthread_mutex_unlock(&gMutex); + DATA_SEC_LOG_INFO("ListPush done, ret!"); +} + +void ListPop(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams) +{ + DATA_SEC_LOG_INFO("ListPop, ret!"); + pthread_mutex_lock(&gMutex); + struct DATASLListParams *pList = list->next; + while (pList != NULL && pList != list) { + if (UdidCmp(pList->callbackParams->queryParams, + ((struct DATASLCallbackParams*)callbackParams)->queryParams) == SUCCESS) { + pList->prev->next = pList->next; + pList->next->prev = pList->prev; + free(pList); + break; + } + pList = pList->next; + } + pthread_mutex_unlock(&gMutex); + DATA_SEC_LOG_INFO("ListPop done, ret!"); +} + +void ListClear(struct DATASLListParams *list) +{ + pthread_mutex_lock(&gMutex); + struct DATASLListParams *pList = list->next; + while (pList == NULL || pList != list) { + struct DATASLListParams *delList = pList; + pList = pList->next; + free(delList); + } + pthread_mutex_unlock(&gMutex); +} + +int32_t ListLength(struct DATASLListParams *list) +{ + pthread_mutex_lock(&gMutex); + struct DATASLListParams *pList = list->next; + int32_t listLength = 0; + while (pList != NULL && pList != list) { + listLength++; + pList = pList->next; + } + pthread_mutex_unlock(&gMutex); + return listLength; +} + +int32_t ListFind(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams) +{ + pthread_mutex_lock(&gMutex); + DATA_SEC_LOG_INFO("ListFind, ret!"); + struct DATASLListParams *pList = list->next; + while (pList != NULL && pList != list) { + if (UdidCmp(pList->callbackParams->queryParams, + ((struct DATASLCallbackParams*)callbackParams)->queryParams) == SUCCESS) { + DATA_SEC_LOG_INFO("ListFind fine done, ret!"); + pthread_mutex_unlock(&gMutex); + return SUCCESS; + } + pList = pList->next; + } + DATA_SEC_LOG_INFO("ListFind not find, ret!"); + pthread_mutex_unlock(&gMutex); + return DEVSL_ERROR; +} \ No newline at end of file diff --git a/frameworks/datasecuritylevel/dev_slinfo_mgr.c b/frameworks/datasecuritylevel/dev_slinfo_mgr.c new file mode 100644 index 0000000000000000000000000000000000000000..bc38c7db5519017692b1240c3b2cb5d1283e23e3 --- /dev/null +++ b/frameworks/datasecuritylevel/dev_slinfo_mgr.c @@ -0,0 +1,120 @@ +/* + * 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 "dev_slinfo_list.h" +#include "dev_slinfo_adpt.h" +#include "dev_slinfo_log.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define DEVSL_API __attribute__ ((visibility ("default"))) + +static int32_t GetHigestSecLevelByUdid(DEVSLQueryParams *queryParams, uint32_t *dataLevel) +{ + int32_t ret = 0; + int32_t devLevel = DEFAULT_DEV_SEC_LEVEL; + + DATA_SEC_LOG_INFO("GetHighestSecLevelByUdid by udid!"); + if ((queryParams->udidLen < 0u) || (queryParams->udidLen > 64u)) { + return ERR_INVALID_PARA; + } + + ret = GetDeviceSecLevelByUdid(queryParams->udid, queryParams->udidLen, &devLevel); + if (ret != SUCCESS) { + *dataLevel = DATA_SEC_LEVEL0; + DATA_SEC_LOG_ERROR("GetHigestSecLevelByUdid, get device security level failed, error code: %d", ret); + return ret; + } + + *dataLevel = GetDataSecLevelByDevSecLevel(devLevel); + return ret; +} + +DEVSL_API int32_t DATASL_OnStart(void) +{ + int32_t ret = 0; + + DATA_SEC_LOG_INFO("Enter DATASL_Onstart"); + ret = StartDevslEnv(); + if (ret != SUCCESS) { + DATA_SEC_LOG_ERROR("StartDevslEnv - failed, error code is %d", ret); + FinishDevslEnv(); + return DEVSL_ERROR; + } + DATA_SEC_LOG_INFO("DATASL_Onstart - success"); + return SUCCESS; +} + +DEVSL_API void DATASL_OnStop(void) +{ + DATA_SEC_LOG_INFO("Enter DATASL_OnStop"); + FinishDevslEnv(); + DATA_SEC_LOG_INFO("DATASL_OnStop done"); + return; +} + +DEVSL_API int32_t DATASL_GetHighestSecLevel(DEVSLQueryParams *queryParams, uint32_t *levelInfo) +{ + int32_t ret = 0; + DATA_SEC_LOG_INFO("Enter DATASL_GetHighestSecLevel!"); + if ((queryParams == NULL) || (levelInfo == NULL)) { + return ERR_INVALID_PARA; + } + + ret = GetHigestSecLevelByUdid(queryParams, levelInfo); + + DATA_SEC_LOG_INFO("DATASL_GetHighestSecLevel done, ret %d!", ret); + return ret; +} + +// Async +static int32_t GetHighestSecLevelByUdidAsync(DEVSLQueryParams *queryParams) +{ + DATA_SEC_LOG_INFO("Enter GetHighestSecLevelByUdidAsync!"); + int32_t ret; + + if ((queryParams->udidLen < 0u) || (queryParams->udidLen > 64u)) { + return ERR_INVALID_PARA; + } + + ret = GetDeviceSecLevelByUdidAsync(queryParams->udid, queryParams->udidLen); + if (ret != SUCCESS) { + DATA_SEC_LOG_ERROR("GetHigestSecLevelByUdid, get device security level failed, error code: %d", ret); + return ret; + } + + DATA_SEC_LOG_INFO("GetHighestSecLevelByUdidAsync done, ret %d!", ret); + return ret; +} + +DEVSL_API int32_t DATASL_GetHighestSecLevelAsync(DEVSLQueryParams *queryParams, HigestSecInfoCallback *callback) +{ + DATA_SEC_LOG_INFO("Enter DATASL_GetHighestSecLevelAsync!"); + int32_t ret; + + if ((queryParams == NULL) || (callback == NULL)) { + return ERR_INVALID_PARA; + } + + ret = UpdateCallback(queryParams, callback); + ret = GetHighestSecLevelByUdidAsync(queryParams); + DATA_SEC_LOG_INFO("DATASL_GetHighestSecLevelAsync done, ret %d!", ret); + return ret; +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/frameworks/fbesdp/fbe_sdp_policy.cpp b/frameworks/fbesdp/fbe_sdp_policy.cpp deleted file mode 100644 index 68c520f6c89f037dddd440d246f42aca2e1778a7..0000000000000000000000000000000000000000 --- a/frameworks/fbesdp/fbe_sdp_policy.cpp +++ /dev/null @@ -1,72 +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 "fbe_sdp_policy.h" - -extern "C" __attribute (()) bool IsSupportIudf() -{ - return false; -} - -extern "C" __attribute (()) int SetLabel(int userId, const char* filePath, - const char* labelName, const char* labelValue, int flag) -{ - return RET_SDP_OK; -} - -extern "C" __attribute (()) int GetLabel(int userId, const char* filePath, - const char* labelName, char* labelValue, const int valueLen) -{ - return RET_SDP_OK; -} - -extern "C" __attribute (()) int GetFlag(int userId, const char* filePath, const char* labelName) -{ - return RET_SDP_OK; -} - -extern "C" __attribute (()) int SetEcePathPolicy(int userId, const char *path) -{ - return RET_SDP_OK; -} - -extern "C" __attribute (()) int SetSecePathPolicy(int userId, const char *path) -{ - return RET_SDP_OK; -} - -extern "C" __attribute (()) int GetPathPolicy(const char *path) -{ - if (!IsSupportIudf()) { - return RET_SDP_SUPPORT_IUDF_ERROR; - } - return FSCRYPT_NO_ECE_OR_SECE_CLASS; -} - -__attribute (()) int GetLockState(int userId, int flag) -{ - return RET_LOCK_IUDF_SERVICE_NO_SUPPORT; -} - -__attribute (()) int RegisterLockStateChangeCallback(int flag, - std::function &lockStateChangedListener) -{ - return RET_SDP_OK; -} -__attribute (()) int UnRegisterLockStateChangeCallback( - std::function &lockStateChangedListener) -{ - return RET_SDP_OK; -} diff --git a/interfaces/innerkits/hwdevsl/BUILD.gn b/interfaces/innerkits/datasecuritylevel/BUILD.gn similarity index 55% rename from interfaces/innerkits/hwdevsl/BUILD.gn rename to interfaces/innerkits/datasecuritylevel/BUILD.gn index fcc8a234f91c15463c0dbb5b65d9c2380fa9cc76..0d7bae742828b6dfe212b363839fee707a0ddf77 100644 --- a/interfaces/innerkits/hwdevsl/BUILD.gn +++ b/interfaces/innerkits/datasecuritylevel/BUILD.gn @@ -1,36 +1,49 @@ -# 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. - -import("//build/ohos.gni") - -################################################################ -# C++, Main source file here. -################################################################ -config("hwdsl_config") { - include_dirs = [ "include" ] -} - -ohos_shared_library("hwdsl") { - subsystem_name = "security" - part_name = "dataclassification" - - public_configs = [ ":hwdsl_config" ] - - include_dirs = [ "include/1.0" ] - - sources = [ - "//base/security/dataclassification/frameworks/hwdevsl/dev_slinfo_mgr.c" - ] - - deps = [ "//utils/native/base:utils" ] -} +# 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. + +import("//build/ohos.gni") + +################################################################ +# C, Main source file here. +################################################################ +config("datasecuritylevel_config") { + include_dirs = [ "include" ] +} + +ohos_shared_library("datasecuritylevel") { + subsystem_name = "security" + part_name = "dataclassification" + + public_configs = [ ":datasecuritylevel_config" ] + + include_dirs = [ + "include", + ] + + sources = [ + "//base/security/dataclassification/frameworks/datasecuritylevel/dev_slinfo_mgr.c", + "//base/security/dataclassification/frameworks/datasecuritylevel/dev_slinfo_list.c", + "//base/security/dataclassification/frameworks/datasecuritylevel/dev_slinfo_adpt.c", + ] + + deps = [ + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "device_security_level:dslm_sdk", + ] + + cflags = [ "-Wall" ] +} diff --git a/interfaces/innerkits/datasecuritylevel/include/dev_slinfo_adpt.h b/interfaces/innerkits/datasecuritylevel/include/dev_slinfo_adpt.h new file mode 100644 index 0000000000000000000000000000000000000000..9f0a68bdf7d7f94f84b74744c082b5773daa8f2f --- /dev/null +++ b/interfaces/innerkits/datasecuritylevel/include/dev_slinfo_adpt.h @@ -0,0 +1,70 @@ +/* + * 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 DEV_SLINFO_ADPT_H +#define DEV_SLINFO_ADPT_H + +#include "device_security_info.h" +#include "dev_slinfo_mgr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define DEFAULT_DEV_SEC_LEVEL 0 +#define DEV_SEC_LEVEL1 1 /* sl1 */ +#define DEV_SEC_LEVEL2 2 /* sl2 */ +#define DEV_SEC_LEVEL3 3 /* sl3 */ +#define DEV_SEC_LEVEL4 4 /* sl4 */ +#define DEV_SEC_LEVEL5 5 /* sl5 */ + +typedef int32_t (*RequestDeviceSecurityInfoFunction)(const DeviceIdentify *identify, + const RequestOption *option, + DeviceSecurityInfo **info); + +typedef int32_t (*RequestDeviceSecurityInfoAsyncFunction)(const DeviceIdentify *identify, + const RequestOption *option, + DeviceSecurityInfoCallback callback); + +typedef void (*FreeDeviceSecurityInfoFunction)(DeviceSecurityInfo *info); + +typedef uint32_t (*GetDeviceSecurityLevelValueFunction)(const DeviceSecurityInfo *info, int32_t *level); + +typedef struct { + RequestDeviceSecurityInfoFunction requestDeviceSecurityInfo; + RequestDeviceSecurityInfoAsyncFunction requestDeviceSecurityInfoAsync; + FreeDeviceSecurityInfoFunction freeDeviceSecurityInfo; + GetDeviceSecurityLevelValueFunction getDeviceSecurityLevelValue; + int32_t version; +} DeviceSecEnv; + +int32_t StartDevslEnv(void); + +void FinishDevslEnv(void); + +int32_t GetDeviceSecLevelByUdid(uint8_t *udid, uint32_t udidLen, int32_t *devLevel); + +int32_t UdidCmp(DEVSLQueryParams *queryParamsL, DEVSLQueryParams *queryParamsR); + +int32_t GetDeviceSecLevelByUdidAsync(uint8_t *udid, uint32_t udidLen); + +int32_t GetDataSecLevelByDevSecLevel(int32_t devLevel); + +int32_t UpdateCallback(DEVSLQueryParams *queryParams, HigestSecInfoCallback *callback); + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/test/unittest/hwdevsl/hwdevsl_test.cpp b/interfaces/innerkits/datasecuritylevel/include/dev_slinfo_list.h similarity index 38% rename from test/unittest/hwdevsl/hwdevsl_test.cpp rename to interfaces/innerkits/datasecuritylevel/include/dev_slinfo_list.h index dee67e26d42687024b77336d6f6e6735c6ba8c5c..64523f758c1eb20cb1e2f8b435108e7bb8308d5e 100644 --- a/test/unittest/hwdevsl/hwdevsl_test.cpp +++ b/interfaces/innerkits/datasecuritylevel/include/dev_slinfo_list.h @@ -1,55 +1,49 @@ - -/* - * 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 "gtest/gtest.h" - -#include "hwdevsl_test.h" -#include "dev_slinfo_mgr.h" - -using namespace testing::ext; - -class DeviceSecurityLevelTest : public testing::Test { -protected: - DeviceSecurityLevelTest(); - ~DeviceSecurityLevelTest(); - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - -private: -}; - -DeviceSecurityLevelTest::DeviceSecurityLevelTest() {} -DeviceSecurityLevelTest::~DeviceSecurityLevelTest() {} -void DeviceSecurityLevelTest::SetUpTestCase() {} -void DeviceSecurityLevelTest::TearDownTestCase() {} -void DeviceSecurityLevelTest::SetUp() {} -void DeviceSecurityLevelTest::TearDown() {} - -/** - * @tc.name: TestOnStart - * @tc.desc: Verify DEVSL_OnStart function - * @tc.type: FUN - */ -HWTEST_F(DeviceSecurityLevelTest, TestOnStart, TestSize.Level0) -{ - int32_t ret; - - ret = DEVSL_OnStart(1); - EXPECT_EQ(DEVSL_SUCCESS, ret); - DEVSL_ToFinish(); -} \ No newline at end of file +/* + * 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 DEV_SLINFO_LIST_H +#define DEV_SLINFO_LIST_H + +#include "dev_slinfo_mgr.h" + +#include +#include + +static pthread_mutex_t gMutex = PTHREAD_MUTEX_INITIALIZER; + +struct DATASLCallbackParams { + DEVSLQueryParams *queryParams; + HigestSecInfoCallback *callback; +}; + +struct DATASLListParams { + struct DATASLCallbackParams *callbackParams; + struct DATASLListParams *prev; + struct DATASLListParams *next; +}; + +struct DATASLListParams* ListInit(void); + +void ListPush(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams); + +void ListPop(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams); + +void ListClear(struct DATASLListParams *list); + +int ListLength(struct DATASLListParams *list); + +int32_t ListFind(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams); + +#endif \ No newline at end of file diff --git a/frameworks/hwdevsl/dev_slinfo_mgr.c b/interfaces/innerkits/datasecuritylevel/include/dev_slinfo_log.h similarity index 48% rename from frameworks/hwdevsl/dev_slinfo_mgr.c rename to interfaces/innerkits/datasecuritylevel/include/dev_slinfo_log.h index 42c1573474af242b1109fc97be553b5406c3e9fc..c5c0bea23576f2f2a36ee7c331035c612cb36387 100644 --- a/frameworks/hwdevsl/dev_slinfo_mgr.c +++ b/interfaces/innerkits/datasecuritylevel/include/dev_slinfo_log.h @@ -13,37 +13,21 @@ * limitations under the License. */ -#include "dev_slinfo_mgr.h" +#ifndef DEV_SLINFO_LOG_H +#define DEV_SLINFO_LOG_H -#ifdef __cplusplus -extern "C" { -#endif - -#define DEVSL_API __attribute__ ((visibility ("default"))) - -DEVSL_API int32_t DEVSL_OnStart(int32_t maxDevNum) -{ - return DEVSL_SUCCESS; -} +#include -DEVSL_API void DEVSL_ToFinish(void) -{ - return; -} +#include "hilog/log.h" -DEVSL_API int32_t DEVSL_GetHighestSecLevel(DEVSLQueryParams *queryParams, uint32_t *levelInfo) -{ - *levelInfo = DATA_SEC_LEVEL3; - return DEVSL_SUCCESS; -} - -DEVSL_API int32_t DEVSL_GetLocalCertData(uint8_t *buff, uint32_t bufSz, uint32_t *dataLen) -{ - buff[0] = 0; - *dataLen = 0; - return DEVSL_SUCCESS; -} -#ifdef __cplusplus -} +#ifdef LOG_TAG +#undef LOG_TAG #endif - +#define LOG_TAG "DATA_SEC_LEVEL: " + +#define DATA_SEC_LOG_DEBUG(fmt, ...) HILOG_DEBUG(LOG_CORE, fmt, ##__VA_ARGS__) +#define DATA_SEC_LOG_INFO(fmt, ...) HILOG_INFO(LOG_CORE, fmt, ##__VA_ARGS__) +#define DATA_SEC_LOG_WARN(fmt, ...) HILOG_WARN(LOG_CORE, fmt, ##__VA_ARGS__) +#define DATA_SEC_LOG_ERROR(fmt, ...) HILOG_ERROR(LOG_CORE, fmt, ##__VA_ARGS__) +#define DATA_SEC_LOG_FATAL(fmt, ...) HILOG_FATAL(LOG_CORE, fmt, ##__VA_ARGS__) +#endif \ No newline at end of file diff --git a/interfaces/innerkits/fbe_iudf_xattr/include/fbe_sdp_code_num.h b/interfaces/innerkits/datasecuritylevel/include/dev_slinfo_mgr.h similarity index 34% rename from interfaces/innerkits/fbe_iudf_xattr/include/fbe_sdp_code_num.h rename to interfaces/innerkits/datasecuritylevel/include/dev_slinfo_mgr.h index 0270b53d94735d74818792ab23b5607e3c8edd25..033b6a7607c8e0bb9c26adfdac991482fad18f5f 100644 --- a/interfaces/innerkits/fbe_iudf_xattr/include/fbe_sdp_code_num.h +++ b/interfaces/innerkits/datasecuritylevel/include/dev_slinfo_mgr.h @@ -13,50 +13,51 @@ * limitations under the License. */ -#ifndef FBE_SDP_CODE_NUM -#define FBE_SDP_CODE_NUM - -enum ErrorCode { - RET_SDP_NOT_SUPPORT_ATTR = -13, - RET_SDP_NOT_SET_ERROR = -12, - RET_SDP_CODE_FAILED_ERROR = -11, - RET_SDP_CONTEXT_ERROR = -10, - RET_SDP_LABEL_HAS_BEEN_SET = -9, - RET_SDP_GENERIC_ERROR = -8, - RET_SDP_FILE_OPEN_ERROR = -7, - RET_SDP_GET_DESC_ERROR = -6, - RET_SDP_SUPPORT_IUDF_ERROR = -5, - RET_SDP_IOCTL_ERROR = -4, - RET_SDP_OPEN_ERROR = -3, - RET_SDP_MEMORY_ERROR = -2, - RET_SDP_PARAM_ERROR = -1, - RET_SDP_OK = 0, -}; +#ifndef DEV_SLINFO_MGR_H +#define DEV_SLINFO_MGR_H -enum FsCryptType { - FSCRYPT_NO_ECE_OR_SECE_CLASS = 1, - FSCRYPT_SDP_ECE_CLASS = 2, - FSCRYPT_SDP_SECE_CLASS = 3, - FSCRYPT_SDP_GET_FEB_VER = 10, -}; +#include -enum FbeVesion { - FBE_VER_NO_2 = 2, - FBE_VER_NO_3 = 3, -}; +#ifdef __cplusplus +extern "C" { +#endif -enum FbeLockState { - FLAG_LOCAL_STATE = 0x01, -}; +#define MAX_LIST_SUM 128 +#define MAX_UDID_LENGTH 64 + +#define DATA_SEC_LEVEL0 0 /* s0 */ +#define DATA_SEC_LEVEL1 1 /* s1 */ +#define DATA_SEC_LEVEL2 2 /* s2 */ +#define DATA_SEC_LEVEL3 3 /* s3 */ +#define DATA_SEC_LEVEL4 4 /* s4 */ + +typedef struct { + uint8_t udid[MAX_UDID_LENGTH]; + uint32_t udidLen; +} DEVSLQueryParams; -enum FbeLockErrorCode { - RET_LOCK_IUDF_SERVICE_NO_SUPPORT = -7, - RET_LOCK_CALLBACK_NOT_REGIST = -6, - RET_LOCK_CALLBACK_HAS_BEEN_REGIST = -5, - RET_LOCK_REMOTE_EXCEPTION = -4, - RET_LOCK_INVALID_PARAM_ERROR = -3, - RET_LOCK_SERVICE_NOT_FOUND = -2, - RET_LOCK_PARAM_ERROR = -1, - RET_LOCK_OK = 0, +enum { + DEVSL_SUCCESS = 0, + DEVSL_ERROR = 100, + DEVSL_ERR_GET_DEV_SEC_NOT_ONLINE = 101, + DEVSL_ERR_SERVICES_TOO_MANY = 102, + DEVSL_ERR_REPEATED_SERVICES = 103, + DEVSL_ERR_MEM_CPY = 104, + DEVSL_ERR_DEVICE_SEC_SDK_INIT = 105, }; + +int32_t DATASL_GetHighestSecLevel(DEVSLQueryParams *queryParams, uint32_t *levelInfo); + +int32_t DATASL_OnStart(void); + +void DATASL_OnStop(void); + +// Async +typedef void HigestSecInfoCallback(DEVSLQueryParams *queryParams, int32_t result, uint32_t levelInfo); + +int32_t DATASL_GetHighestSecLevelAsync(DEVSLQueryParams *queryParams, HigestSecInfoCallback *callback); + +#ifdef __cplusplus +} +#endif #endif \ No newline at end of file diff --git a/interfaces/innerkits/fbe_iudf_xattr/BUILD.gn b/interfaces/innerkits/fbe_iudf_xattr/BUILD.gn deleted file mode 100644 index 46600d49fc1e0d6e6ea1139ad4d8e46eb943cf35..0000000000000000000000000000000000000000 --- a/interfaces/innerkits/fbe_iudf_xattr/BUILD.gn +++ /dev/null @@ -1,35 +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. - -import("//build/ohos.gni") - -################################################################ -# C++, Main source file here. -################################################################ -config("fbe_iudf_xattr_config") { - include_dirs = [ "include" ] -} - -ohos_shared_library("fbe_iudf_xattr") { - subsystem_name = "security" - part_name = "dataclassification" - - public_configs = [ ":fbe_iudf_xattr_config" ] - - include_dirs = [ "include" ] - sources = [ - "//base/security/dataclassification/frameworks/fbesdp/fbe_sdp_policy.cpp" - ] - - deps = [ "//utils/native/base:utils" ] -} diff --git a/interfaces/innerkits/fbe_iudf_xattr/include/fbe_sdp_policy.h b/interfaces/innerkits/fbe_iudf_xattr/include/fbe_sdp_policy.h deleted file mode 100644 index 15063910e24d2f9bda89295f7d47dc944d759236..0000000000000000000000000000000000000000 --- a/interfaces/innerkits/fbe_iudf_xattr/include/fbe_sdp_policy.h +++ /dev/null @@ -1,47 +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 FBE_IUDF_H -#define FBE_IUDF_H - -#include "fbe_sdp_code_num.h" -#include - -#define LABEL_VALUE_S0 "S0" -#define LABEL_VALUE_S1 "S1" -#define LABEL_VALUE_S2 "S2" -#define LABEL_VALUE_S3 "S3" -#define LABEL_VALUE_S4 "S4" -#define LABEL_NAME_SECURITY_LEVEL "SecurityLevel" -#define FLAG_FILE_PROTECTION_COMPLETE 0 -#define FLAG_FILE_PROTECTION_COMPLETE_UNLESS_OPEN 1 - -extern "C" __attribute (()) bool IsSupportIudf(); -extern "C" __attribute (()) int SetEcePathPolicy(int userId, const char *path); -extern "C" __attribute (()) int SetSecePathPolicy(int userId, const char *path); -extern "C" __attribute (()) int GetPathPolicy(const char *path); -extern "C" __attribute (()) int SetLabel(int userId, const char *filePath, - const char *labelName, const char *labelValue, int flag); -extern "C" __attribute (()) int GetLabel(int userId, const char *filePath, - const char *labelName, char *labelValue, const int valueLen); -extern "C" __attribute (()) int GetFlag(int userId, const char *filePath, const char *labelName); -__attribute (()) int GetLockState(int userId, int flag); - -__attribute (()) int RegisterLockStateChangeCallback(int flag, - std::function &lockStateChangedListener); - -__attribute (()) int UnRegisterLockStateChangeCallback( - std::function &lockStateChangedListener); -#endif diff --git a/interfaces/innerkits/hwdevsl/include/1.0/dev_slinfo_mgr.h b/interfaces/innerkits/hwdevsl/include/1.0/dev_slinfo_mgr.h deleted file mode 100644 index 997af14ccbca23e040aa7a2af3b64d43f2b355c3..0000000000000000000000000000000000000000 --- a/interfaces/innerkits/hwdevsl/include/1.0/dev_slinfo_mgr.h +++ /dev/null @@ -1,128 +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 DEV_SLINFO_MGR_H -#define DEV_SLINFO_MGR_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - uint8_t *val; - uint32_t len; - uint32_t mSize; -} DEVSLData; - -#define DEV_TYPE_PHONE 1 /* device type - PHONE */ -#define DEV_TYPE_PAD 2 /* device type - PAD */ -#define DEV_TYPE_TV 3 /* device type - TV */ -#define DEV_TYPE_WATCH 5 /* device type - WATCH */ - -/* caller queries data security level : - * 1 - if with udid, devType should be 0 - * 2 - if devType > 0, only queried data security level with policy configuriation - */ -typedef struct { - const uint8_t *udid; /* if devType is 0, it must */ - const uint8_t *sensitiveData; /* optional */ - uint32_t idLen; /* if udid is a string, the length should not with end tag 0 */ - uint32_t sensitiveDataLen; /* length of sensitiveData */ - uint32_t devType; /* only support PHONE, PAD, TV, WATCH */ -} DEVSLQueryParams; - -/* tmpParams is pointer */ -#define DEVSL_INIT_PARAMS(tmpParams) do { \ - (tmpParams)->udid = NULL; \ - (tmpParams)->sensitiveData = NULL; \ - (tmpParams)->idLen = 0; \ - (tmpParams)->sensitiveDataLen = 0; \ - (tmpParams)->devType = 0; \ -} while (0) - -enum { - DEVSL_SUCCESS = 0, - DEVSL_ERROR, - DEVSL_ERR_UNINITIALIZED, - DEVSL_ERR_INITIALIZED, - DEVSL_ERR_INVALID_PARAMS, - DEVSL_ERR_ALLOC_MEMORY, - DEVSL_ENTRY_NUMBER_ERROR, - DEVSL_INIT_MUTEX_FAILED, - DEVSL_ASYNC_PROCESSING, - DEVSL_RESOURCE_BUSY, - DEVSL_ERR_IN_LOCKING, - DEVSL_ERR_GET_LOCAL_SENSITIVE, - DEVSL_ERR_ENTRY_FULL, - DEVSL_ERR_MEM_CPY, - DEVSL_ERR_CREATE_THREAD, - DEVSL_ASYNC_QUERY, - DEVSL_UNKNOWN_SEC_LEVEL, - DEVSL_ERR_PARSE_CFG, - DEVSL_ERR_GET_TIME, - DEVSL_ERR_FORM_CERT, - DEVSL_ERR_HKS_BLOB_BUFFER, - DEVSL_ERR_HKS_ATTEST_KEY, - DEVSL_ERR_HKS_CERT_CHAIN, - DEVSL_ERR_CERT_CHAIN_BUFFER, - DEVSL_ERR_GET_CERT_CHAIN, - DEVSL_ERR_VALIDATE_ATTEST_CERT, - DEVSL_ERR_ENTRY_NULL, - DEVSL_ERR_QUERY_SEC_LEVEL, - DEVSL_ERR_PROFILE_CONN, - DEVSL_ERR_PROFILE_GET_DATA, - DEVSL_ERR_PROFILE_PUT_DATA, - DEVSL_ERR_PROFILE_PUT_SERVICE, - DEVSL_ERR_PROFILE_PUT_DEVICE, - DEVSL_ERR_PROFILE_PROC_HOST, - DEVSL_ERR_PROFILE_DEV_DATA, - DEVSL_ERR_PROFILE_UDID, - DEVSL_ERR_PROFILE_DATA_CTX, - DEVSL_ERR_CERT_DATA_LEN, - DEVSL_ERR_PROFILE_CONN_IN_QUERY, - DEVSL_LEVEL_ONLY_WITH_POLICY, - DEVSL_ERR_WITHOUT_PERMISSION, - DEVSL_ERR_UNKNOWN_DEV_TYPE, - DEVSL_ERR_PROFILE_INIT -}; - -#define DATA_SEC_LEVEL0 0 /* s0 */ -#define DATA_SEC_LEVEL1 1 /* s1 */ -#define DATA_SEC_LEVEL2 2 /* s2 */ -#define DATA_SEC_LEVEL3 3 /* s3 */ -#define DATA_SEC_LEVEL4 4 /* s4 */ - -/* - * note: 1 - if return error code, the out levelInfo is invalid - * 2 - if @param queryParams's devType > 0, only do the compatible processing - * @param queryParams - if caller set the devType valid, get data security level only with policy configuration - * @param levelInfo - store the queried data level - * if success, return DEVSL_SUCCESS, else return error code. - */ -int32_t DEVSL_GetHighestSecLevel(DEVSLQueryParams *queryParams, uint32_t *levelInfo); -/* cert buffer length must be more than 13k, suggest 14k */ -int32_t DEVSL_GetLocalCertData(uint8_t *buff, uint32_t bufSz, uint32_t *dataLen); -/* not support mutil-thread */ -int32_t DEVSL_OnStart(int32_t maxDevNum); -/* not support mutil-thread */ -void DEVSL_ToFinish(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/test/unittest/hwdevsl/BUILD.gn b/test/unittest/datasecuritylevel/BUILD.gn similarity index 57% rename from test/unittest/hwdevsl/BUILD.gn rename to test/unittest/datasecuritylevel/BUILD.gn index 821e7c54c9fe28ec02c3ca8eba4d33375e810e52..ca713717193c4c5bb83feb1515a4f345b768403b 100644 --- a/test/unittest/hwdevsl/BUILD.gn +++ b/test/unittest/datasecuritylevel/BUILD.gn @@ -1,49 +1,44 @@ -# 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. - -import("//build/test.gni") -module_output_path = "dataclassification/hwdevsl" - -config("hwdevsl_private_config") { - visibility = [ ":*" ] - include_dirs = [ - "//base/security/dataclassification/test/unittest/hwdevsl", - "//base/security/dataclassification/interfaces/innerkits/hwdevsl/include/1.0", - "//third_party/googletest/googletest/include", - "utils/native/base/include", - ] - - cflags = [ "-DHILOG_ENABLE" ] -} - -ohos_unittest("HwDslTest") { - part_name = "dataclassification" - subsystem_name = "security" - module_out_path = module_output_path - - sources = [ "hwdevsl_test.cpp" ] - - configs = [ ":hwdevsl_private_config" ] - - deps = [ - "//base/security/dataclassification/interfaces/innerkits/hwdevsl:hwdsl", - "//utils/native/base:utils", - ] - - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] -} - -group("hwdevsl_test") { - testonly = true - deps = [ ":HwDslTest" ] -} +# 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. + +import("//build/test.gni") +module_output_path = "dataclassification/datasecuritylevel" + +config("datasecuritylevel_test_config") { + visibility = [ ":*" ] + include_dirs = [ + "//base/security/dataclassification/test/unittest/datasecuritylevel", + "//base/security/dataclassification/interfaces/innerkits/datasecuritylevel/include", + "//third_party/googletest/googletest/include", + "//utils/native/base/include", + ] + cflags = [ "-DHILOG_ENABLE" ] +} + +ohos_unittest("DevSLMgrTest") { + part_name = "dataclassification" + subsystem_name = "security" + module_out_path = module_output_path + + sources = [ "DevSLMgrTest.cpp" ] + + deps = [ + "//base/security/dataclassification/interfaces/innerkits/datasecuritylevel:datasecuritylevel", + "//utils/native/base:utils", + ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "dsoftbus_standard:softbus_client", + "device_security_level:dslm_sdk", + ] +} \ No newline at end of file diff --git a/test/unittest/datasecuritylevel/DevSLMgrTest.cpp b/test/unittest/datasecuritylevel/DevSLMgrTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0ea7542b94ce5e6c1ee529bbaf0e6f2d71749525 --- /dev/null +++ b/test/unittest/datasecuritylevel/DevSLMgrTest.cpp @@ -0,0 +1,140 @@ + +/* + * 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 +#include "gtest/gtest.h" +#include "dev_slinfo_mgr.h" +#include "securec.h" +#include "softbus_bus_center.h" +#include "dev_slinfo_adpt.h" +#include "DevSLMgrTest.h" + +using namespace testing::ext; + +class DevSLMgrTest : public testing::Test { +protected: + DevSLMgrTest(); + ~DevSLMgrTest(); + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + +private: +}; + +DevSLMgrTest::DevSLMgrTest() {} +DevSLMgrTest::~DevSLMgrTest() {} +void DevSLMgrTest::SetUpTestCase() {} +void DevSLMgrTest::TearDownTestCase() {}; +void DevSLMgrTest::SetUp() {} +void DevSLMgrTest::TearDown() {} + +static void DATASL_GetUdidByOpp(DEVSLQueryParams *queryParams) +{ + char udid[65] = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; + (void)memcpy_s(queryParams->udid, MAX_UDID_LENGTH, udid, MAX_UDID_LENGTH); + queryParams->udidLen = MAX_UDID_LENGTH; +} + +static HWTEST_F(DevSLMgrTest, TestOnstart, TestSize.Level1) +{ + int32_t ret; + + ret = DATASL_OnStart(); + EXPECT_EQ(SUCCESS, ret); +} + +static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevel001, TestSize.Level1) +{ + int32_t ret; + uint32_t levelInfo = 0; + + ret = DATASL_OnStart(); + ret = DATASL_GetHighestSecLevel(nullptr, &levelInfo); + EXPECT_EQ(ERR_INVALID_PARA, ret); +} + +static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevel002, TestSize.Level1) +{ + int32_t ret; + + DEVSLQueryParams queryParams; + (void)memset_s(&queryParams, sizeof(queryParams), 0, sizeof(queryParams)); + DATASL_GetUdidByOpp(&queryParams); + + ret = DATASL_OnStart(); + ret = DATASL_GetHighestSecLevel(&queryParams, nullptr); + EXPECT_EQ(ERR_INVALID_PARA, ret); +} + +static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevel003, TestSize.Level1) +{ + int32_t ret; + uint32_t levelInfo = 0; + + DEVSLQueryParams queryParams; + (void)memset_s(&queryParams, sizeof(queryParams), 0, sizeof(queryParams)); + DATASL_GetUdidByOpp(&queryParams); + + ret = DATASL_OnStart(); + ret = DATASL_GetHighestSecLevel(&queryParams, &levelInfo); + EXPECT_EQ(DATA_SEC_LEVEL0, static_cast(levelInfo)); + EXPECT_EQ(ERR_NOEXIST_DEVICE, ret); +} + +// Aysnc +static void tmpCallback000(DEVSLQueryParams *queryParams, int32_t result, uint32_t levelInfo) +{ + EXPECT_EQ(ERR_INVALID_PARA, result); +} + +static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevelAsync001, TestSize.Level1) +{ + int32_t ret; + + ret = DATASL_OnStart(); + ret = DATASL_GetHighestSecLevelAsync(nullptr, &tmpCallback000); + EXPECT_EQ(ERR_INVALID_PARA, ret); +} + +static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevelAsync002, TestSize.Level1) +{ + int32_t ret; + DEVSLQueryParams queryParams; + (void)memset_s(&queryParams, sizeof(queryParams), 0, sizeof(queryParams)); + DATASL_GetUdidByOpp(&queryParams); + + ret = DATASL_GetHighestSecLevelAsync(&queryParams, nullptr); + EXPECT_EQ(ERR_INVALID_PARA, ret); +} + +static void tmpCallback(DEVSLQueryParams *queryParams, int32_t result, uint32_t levelInfo) +{ + printf("yes\n"); + EXPECT_EQ(ERR_NOEXIST_DEVICE, result); + EXPECT_EQ(DATA_SEC_LEVEL0, static_cast(levelInfo)); +} +static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevelAsync003, TestSize.Level1) +{ + int32_t ret; + DEVSLQueryParams queryParams; + (void)memset_s(&queryParams, sizeof(queryParams), 0, sizeof(queryParams)); + DATASL_GetUdidByOpp(&queryParams); + + ret = DATASL_GetHighestSecLevelAsync(&queryParams, &tmpCallback); + DATASL_OnStop(); +} \ No newline at end of file diff --git a/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.h b/test/unittest/datasecuritylevel/DevSLMgrTest.h similarity index 63% rename from test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.h rename to test/unittest/datasecuritylevel/DevSLMgrTest.h index c07f158014071a7b16c21b4f234311f8497e5923..18563723599978907c4c8902852743d23852ce3e 100644 --- a/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.h +++ b/test/unittest/datasecuritylevel/DevSLMgrTest.h @@ -1,21 +1,28 @@ -/* - * 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 FBE_IUDF_XATTR_TEST_H -#define FBE_IUDF_XATTR_TEST_H - -int TestIsSupportIudf(void); - +/* + * 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 DATASECURITYLEVEL_TEST_H +#define DATASECURITYLEVEL_TEST_H + +int TestOnstart(void); +int TestGetHighestSecLevel001(void); +int TestGetHighestSecLevel002(void); +int TestGetHighestSecLevel003(void); + +int TestGetHighestSecLevelAsync001(void); +int TestGetHighestSecLevelAsync002(void); +int TestGetHighestSecLevelAsync003(void); + #endif \ No newline at end of file diff --git a/test/unittest/fbe_iudf_xattr/BUILD.gn b/test/unittest/fbe_iudf_xattr/BUILD.gn deleted file mode 100644 index 4c9fe2f289d877ca4f0f0c135e152437efe51305..0000000000000000000000000000000000000000 --- a/test/unittest/fbe_iudf_xattr/BUILD.gn +++ /dev/null @@ -1,44 +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. - -import("//build/test.gni") -module_output_path = "dataclassification/fbe_iudf_xattr" - -config("fbe_iudf_xattr_test_config") { - visibility = [ ":*" ] - include_dirs = [ - "//base/security/dataclassification/test/unittest/fbe_iudf_xattr", - "//base/security/dataclassification/interfaces/innerkits/fbe_iudf_xattr/include", - "//third_party/googletest/googletest/include", - ] - cflags = [ "-DHILOG_ENABLE" ] -} - -ohos_unittest("IudfXattrTest") { - part_name = "dataclassification" - subsystem_name = "security" - module_out_path = module_output_path - - sources = [ "fbe_iudf_xattr_test.cpp" ] - - configs = [ ":fbe_iudf_xattr_test_config" ] - - deps = [ "//base/security/dataclassification/interfaces/innerkits/fbe_iudf_xattr:fbe_iudf_xattr" ] - - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] -} - -group("fbe_iudf_xattr_test") { - testonly = true - deps = [ ":IudfXattrTest" ] -} diff --git a/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.cpp b/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.cpp deleted file mode 100644 index b878b9f3e3f6049e18b1d013cc5360f912ec0c2f..0000000000000000000000000000000000000000 --- a/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.cpp +++ /dev/null @@ -1,54 +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 "gtest/gtest.h" - -#include "fbe_iudf_xattr_test.h" -#include "fbe_sdp_policy.h" - -using namespace testing::ext; - -class IudfXattrTest : public testing::Test { -protected: - IudfXattrTest(); - ~IudfXattrTest(); - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - -private: -}; - -IudfXattrTest::IudfXattrTest() {} -IudfXattrTest::~IudfXattrTest() {} -void IudfXattrTest::SetUpTestCase() {} -void IudfXattrTest::TearDownTestCase() {} -void IudfXattrTest::SetUp() {} -void IudfXattrTest::TearDown() {} - -/** - * @tc.name: TestIsSupportIudf - * @tc.desc: Verify IsSupportIudf function - * @tc.type: FUN - */ -HWTEST_F(IudfXattrTest, TestIsSupportIudf, TestSize.Level0) -{ - bool ret; - - ret = IsSupportIudf(); - EXPECT_EQ(false, ret); -} \ No newline at end of file diff --git a/test/unittest/hwdevsl/hwdevsl_test.h b/test/unittest/hwdevsl/hwdevsl_test.h deleted file mode 100644 index d4ec4baaede73d701eba60d1255c016465739d80..0000000000000000000000000000000000000000 --- a/test/unittest/hwdevsl/hwdevsl_test.h +++ /dev/null @@ -1,21 +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 Device_SEC_LEVEL_TEST_H -#define Device_SEC_LEVEL_TEST_H - -int TestOnStart(void); - -#endif \ No newline at end of file