README.md
1# Device Security Level Management
2
3
4
5## Introduction
6
7The OpenHarmony distributed technology can converge resources from different devices to form a Super Device. Poor security capabilities of any device may threaten the security of the Super Device. The Device Security Level Management (DSLM) module is introduced to manage the security levels of OpenHarmony devices.
8
9The security level of an OpenHarmony device depends on the system security capabilities of the device. The OpenHarmony system security capabilities are based on the root of trust (RoT) for boot, RoT for storage, and RoT for compute on the hardware. Security technologies and capabilities focus on device integrity protection, data confidentiality protection, and vulnerability defense.
10
11The figure below shows the OpenHarmony security architecture.
12
13![OpenHarmony system security architecture](figures/ohos_system_security_architecture_en.png)
14
15The above figure shows the typical security architecture for a single device. The architecture may vary depending on the risk level as well as the software and hardware resources of the device. The security capabilities of OpenHarmony devices are classified into five levels from SL1 to SL5, based on the industry standard security classification model and actual OpenHarmony service scenarios and device types. In the OpenHarmony ecosystem, higher security levels include all the capabilities of lower security levels by default. The figure below shows the security levels of OpenHarmony devices.
16
17![OpenHarmony device security levels](figures/ohos_device_security_level_en.png)
18
19- SL1: SL1 is the lowest security level of OpenHarmony devices. Usually equipped with a lightweight operating system and low-end microprocessors, such devices implement simple services and do not need to process sensitive data. SL1 devices are required to support software integrity protection and eliminate common errors. Devices that cannot meet the requirements of SL1 can only be controlled by OpenHarmony devices. They cannot control OpenHarmony devices for more complex service collaboration.
20
21- SL2: OpenHarmony devices of SL2 can label their own data and define access control rules to implement discretionary access control (DAC). These devices must have basic anti-penetration capabilities. Devices of this level support a lightweight, secure, and isolated environment for deploying a small number of necessary security services.
22
23- OpenHarmony devices of SL3 have comprehensive security protection capabilities, and their operating systems have relatively complete security semantics and support mandatory access control (MAC). The system data can be structured as critical elements and non-critical elements. The critical elements are protected by a well-defined security policy model. Devices of this level must have certain anti-penetration capabilities to defend against common vulnerability exploits.
24
25- SL4: OpenHarmony devices of SL4 must have simplified trusted computing base (TCB) and come with anti-tampering capabilities. The implementation of SL4 should be concise and secure enough. Adequate authentication and arbitration are required for any access to critical elements. Devices of this level have considerable anti-penetration capabilities and can defend against most software attacks.
26
27- SL5: SL5 indicates the highest security protection capabilities for OpenHarmony devices. The system core software modules must have passed formal verification. Key hardware modules, such as the RoT and cryptographic computing engine, must be able to defend against physical attacks and attacks simulated in labs. Devices at this level must have high-security units, such as dedicated security chips, to enhance the boot, storage, and running of the root of trust (RoT).
28
29The security level of each device in a Super Device provides the decision-making criteria for processing or hopping various user data.
30
31For details about the relationship between data risk levels and device security levels, see [Data Transfer Management](https://gitee.com/openharmony/security_dataclassification).
32
33## Directory Structure
34
35The directory structure of the DSLM module is as follows:
36
37```undefined
38base/security/device_security_level
39├── baselib # Base library
40├── common # Common header files
41├── interfaces # Inner APIs
42├── oem_property # OEM adaptation
43├── profile # Component profiles
44├── services # Service framework code
45└── test # Test code
46```
47
48## Constraints
49
50- Only C and C++ are supported.
51- The default security level of OpenHarmony devices is SL1. Device vendors can [customize](https://gitee.com/openharmony/docs/blob/master/en/device-dev/subsystems/subsys-security-devicesecuritylevel.md#customizing-device-security-levels) a higher security level as required.
52
53## Description
54
55### Available APIs
56
57When different types of user data are hopped or processed in OpenHarmony distributed devices, the DSLM APIs can be called to obtain the security levels of related devices for subsequent processing.
58
59| API | Description |
60| ----------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- |
61| int32_t RequestDeviceSecurityInfo(const DeviceIdentify \*identify, const RequestOption \*option, DeviceSecurityInfo **info); | Requests the security level information of a device synchronously.|
62| int32_t RequestDeviceSecurityInfoAsync(const DeviceIdentify \*identify, const RequestOption \*option, DeviceSecurityInfoCallback callback); | Requests the security level information of a device asynchronously.|
63| void FreeDeviceSecurityInfo(DeviceSecurityInfo \*info); | Releases the device security level information. |
64| int32_t GetDeviceSecurityLevelValue(const DeviceSecurityInfo \*info, int32_t \*level); | Obtains the device security level from the security level information. |
65
66### Usage
67
68All the APIs are native C interfaces for implementing underlying capabilities and are not open to apps.
69
70- Adding Dependencies
71
721. Add the dependencies for compilation.
73
74 ```undefined
75 external_deps += [ "device_security_level:dslm_sdk" ]
76 ```
77
782. Add the header files of dependencies.
79
80 ```cpp
81 #include "device_security_defines.h" // Header file for defining critical data structures.
82 #include "device_security_info.h" // Header file for defining APIs.
83 ```
84
85- Example
86
87The following is an example of synchronously obtaining the device security level:
88
89```cpp
90void CheckDestDeviceSecurityLevel(const DeviceIdentify *device, RequestOption *option)
91{
92 // Pointer to the device security level information.
93 DeviceSecurityInfo *info = NULL;
94
95 // Obtain the security level information of the device.
96 int32_t ret = RequestDeviceSecurityInfo(device, option, &info);
97 if (ret != SUCCESS) {
98 // Failed to obtain the information. You can develop a retry process as required.
99 return;
100 }
101 int32_t level = 0;
102 // Obtain the device security level from the security level information.
103 ret = GetDeviceSecurityLevelValue(info, &level);
104 if (ret != SUCCESS) {
105 // Failed to obtain the device security level. You can develop a retry process as required.
106 FreeDeviceSecurityInfo(info);
107 return;
108 }
109
110 // After the device security level is successfully obtained, check the lowest security level required for the current operation.
111 // The lowest device security level required for the current operation is 3.
112 if (level >= 3) {
113 // The security level of the target device meets the requirements. Services are processed properly.
114 } else {
115 // The security level of the target device does not meet the requirements. A toast or dialog box is displayed as required.
116 }
117
118 // Release the memory before the processing is complete.
119 FreeDeviceSecurityInfo(info);
120}
121```
122
123The following is an example of asynchronously obtaining the device security level:
124
125```cpp
126// Callback
127void DeviceSecurityInfoCallback(const DeviceIdentify *identify, struct DeviceSecurityInfo *info)
128{
129 int32_t level = 0;
130 // Obtain the device security level from the security level information.
131 int32_t ret = GetDeviceSecurityLevelValue(info, &level);
132 if (ret != SUCCESS) {
133 // Failed to obtain the information. You can develop a retry process as required.
134 FreeDeviceSecurityInfo(info);
135 return;
136 }
137
138 // After the device security level is successfully obtained, check the lowest security level required for the current operation.
139 // The lowest device security level required for the current operation is 3.
140 if (level >= 3) {
141 // The security level of the target device meets the requirements. Services are processed properly.
142 } else {
143 // The security level of the target device does not meet the requirements. A toast or dialog box is displayed as required.
144 }
145
146 // Release the memory before the processing is complete.
147 FreeDeviceSecurityInfo(info);
148}
149
150void CheckDestDeviceSecurityLevelAsync(const DeviceIdentify *device, RequestOption *option)
151{
152 // Invoke the asynchronous callback to return the device security level obtained.
153 int ret = RequestDeviceSecurityInfoAsync(device, option, DeviceSecurityInfoCallback);
154 if (ret != SUCCESS) {
155 // Failed to obtain the device security level. You can develop a retry process as required.
156 // In this case, the callback will not be invoked.
157 return;
158 }
159 // The callback is invoked. Wait for the callback to return the device security level.
160}
161```
162
163## Change Log
164
165- V 1.0
166
167## Repositories Involved
168
169[Data Transfer Management](https://gitee.com/openharmony/security_dataclassification)
170
171[**Device Security Level Management**](https://gitee.com/openharmony/security_device_security_level)
172
173[HUKS](https://gitee.com/openharmony/security_huks)
174
175[Application Permission Management](https://gitee.com/openharmony/security_permission)
176
177[Device Authentication](https://gitee.com/openharmony/security_device_auth)
178
179[SELinux](https://gitee.com/openharmony/security_selinux)
180
README_ZH.md
1# 设备安全等级管理
2
3- [设备安全等级管理](#设备安全等级管理)
4 - [简介](#简介)
5 - [目录](#目录)
6 - [约束](#约束)
7 - [说明](#说明)
8 - [接口说明](#接口说明)
9 - [使用说明](#使用说明)
10 - [Changelog](#changelog)
11 - [相关仓](#相关仓)
12
13## 简介
14
15OpenHarmony的分布式技术可以实现不同设备的资源融合,将多个设备虚拟成一个“超级虚拟终端”。在这个“超级虚拟终端”的内部,处理、流转各类用户数据时,需要确保各个节点不因安全能力薄弱,成为整个“超级虚拟终端”的薄弱点,因此引入设备安全等级管理模块来解决这类问题。
16
17OpenHarmony设备的安全等级取决于设备的系统安全能力。OpenHarmony系统安全能力,根植于硬件实现的三个可信根:启动、存储、计算。基于基础安全工程能力,重点围绕以下三点构建相关的安全技术和能力:设备完整性保护、数据机密性保护、漏洞攻防对抗。
18
19OpenHarmony系统安全架构如下图所示:
20
21![OpenHarmony系统安全架构](figures/ohos_system_security_architecture.png)
22
23上图为典型的OpenHarmony单设备系统安全架构,在不同种类OpenHarmony设备上的实现可以存在差异,取决于设备的威胁分析(风险高低)和设备的软硬件资源。OpenHarmony在参考业界权威的安全分级模型基础上,结合OpenHarmony实际的业务场景和设备分类,将OpenHarmony设备的安全能力划分为 5 个安全等级:SL1 ~ SL5。OpenHarmony操作系统生态体系中,要求高一级的设备安全能力默认包含低一级的设备安全能力。分级概要可参考下图:
24
25![OpenHarmony设备安全等级](figures/ohos_device_security_level.png)
26
27- SL1为OpenHarmony设备中最低的安全等级。这类设备通常搭载轻量级系统和使用低端微处理器,业务形态较为单一,不涉及敏感数据的处理。本安全等级要求消除常见的错误,支持软件的完整性保护。若无法满足本等级的要求,则只能作为配件受OpenHarmony设备操控,无法反向操控OpenHarmony设备并进行更复杂的业务协同。
28
29- SL2安全等级的OpenHarmony设备,可对自身数据进行标记并定义访问控制规则,实现自主的访问控制,需要具备基础的抗渗透能力。此级别设备可支持轻量化的可安全隔离环境,用于部署少量必需的安全业务。
30
31- SL3安全等级的OpenHarmony设备,具备较为完善的安全保护能力。其操作系统具有较为完善的安全语义,可支持强制访问控制。系统可结构化为关键保护元素和非关键保护元素,其关键保护元素被明确定义的安全策略模型保护。此级别设备应具备一定的抗渗透能力,可对抗常见的漏洞利用方法。
32
33- SL4安全等级的OpenHarmony设备,可信基应保持足够的精简,具备防篡改的能力。SL4的实现应足够精简和安全,可对关键保护元素的访问控制进行充分的鉴定和仲裁。此级别设备具备相当的抗渗透能力,可抑制绝大多数软件攻击。
34
35- SL5安全等级的OpenHarmony设备,为OpenHarmony设备中具备最高等级安全防护能力的设备。系统核心软件模块应进行形式化验证。关键硬件模块如可信根、密码计算引擎等应具备防物理攻击能力,可应对实验室级别的攻击。此级别设备应具备高安全单元,如专用的安全芯片,用于强化设备的启动可信根、存储可信根、运行可信根。
36
37当“超级虚拟终端”内的各个设备有了自己的“设备安全等级”,这个“超级虚拟终端”的内部,各类用户数据的处理或流转便有了决策依据。
38
39关于数据风险等级和设备安全等级之间的关系,可参考[数据分级保护](https://gitee.com/openharmony/security_dataclassification)。
40
41## 目录
42
43设备安全等级管理模块的代码目录结构如下:
44
45```undefined
46base/security/device_security_level
47├── baselib # 基础库
48├── common # 公共头文件
49├── interfaces # inner api接口
50├── oem_property # OEM厂家适配层
51├── profile # 组件配置文件
52├── services # 服务框架代码
53└── test # 测试代码
54```
55
56## 约束
57
58- 开发语言:C/C++
59- OpenHarmony设备的默认安全等级为SL1,设备制造商可以根据设备实际情况[定制](https://gitee.com/openharmony/docs/tree/master/zh-cn/device-dev/subsystems/subsys-security-devicesecuritylevel.md#%E8%AE%BE%E5%A4%87%E5%AE%89%E5%85%A8%E7%AD%89%E7%BA%A7%E5%AE%9A%E5%88%B6)更高的安全等级。
60
61## 说明
62
63### 接口说明
64
65各子系统在处理、流转各类用户数据时,可以调用“设备安全等级管理”模块提供的下列接口,获取相关设备的安全等级信息。
66
67| 接口名 | 说明 |
68| ----------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- |
69| int32_t RequestDeviceSecurityInfo(const DeviceIdentify \*identify, const RequestOption \*option, DeviceSecurityInfo **info); | 请求获取某设备的设备安全等级信息(同步接口) |
70| int32_t RequestDeviceSecurityInfoAsync(const DeviceIdentify \*identify, const RequestOption \*option, DeviceSecurityInfoCallback callback); | 请求获取某设备的设备安全等级信息(异步接口) |
71| void FreeDeviceSecurityInfo(DeviceSecurityInfo \*info); | 释放设备安全等级信息 |
72| int32_t GetDeviceSecurityLevelValue(const DeviceSecurityInfo \*info, int32_t \*level); | 从设备安全等级信息中提取对应的设备安全等级 |
73
74### 使用说明
75
76所有接口均为native C内部接口,仅提供底层能力,不对App开放。
77
78- 依赖添加
79
801. 编译依赖添加
81
82 ```undefined
83 external_deps += [ "device_security_level:dslm_sdk" ]
84 ```
85
862. 头文件依赖添加
87
88 ```cpp
89 #include "device_security_defines.h" // 关键数据结构定义头文件
90 #include "device_security_info.h" // 接口函数定义头文件
91 ```
92
93- 接口使用示例
94
951. 同步接口使用示例如下:
96
97 ```cpp
98 void CheckDestDeviceSecurityLevel(const DeviceIdentify *device, RequestOption *option)
99 {
100 // 设备安全等级信息指针
101 DeviceSecurityInfo *info = NULL;
102
103 // 调用同步接口获取设备的安全等级等级信息
104 int32_t ret = RequestDeviceSecurityInfo(device, option, &info);
105 if (ret != SUCCESS) {
106 // 获取信息失败。此场景建议开发者根据实际情况进行重试
107 return;
108 }
109 int32_t level = 0;
110 // 从设备安全等级信息中提取设备安全等级字段
111 ret = GetDeviceSecurityLevelValue(info, &level);
112 if (ret != SUCCESS) {
113 // 提取信息失败, 此场景建议开发者根据实际情况进行重试
114 FreeDeviceSecurityInfo(info);
115 return;
116 }
117
118 // 成功获取到设备安全等级,确认当前操作允许的最低安全等级
119 // 假设当前操作允许的最低设备安全等级为3
120 if (level >= 3) {
121 // 目标设备的设备安全等级满足要求, 相关业务正常处理
122 } else {
123 // 目标设备的设备安全等级不满足要求, 建议开发者结合实际业务场景进行相应处理,例如告警、弹窗提示用户等
124 }
125
126 // 结束处理前,需要释放内存
127 FreeDeviceSecurityInfo(info);
128 }
129 ```
130
1312. 异步接口使用示例如下:
132
133 ```cpp
134 // 回调函数
135 void DeviceSecurityInfoCallback(const DeviceIdentify *identify, struct DeviceSecurityInfo *info)
136 {
137 int32_t level = 0;
138 // 从设备安全等级信息中提取设备安全等级字段
139 int32_t ret = GetDeviceSecurityLevelValue(info, &level);
140 if (ret != SUCCESS) {
141 // 获取信息失败。此场景建议开发者根据实际情况进行重试
142 FreeDeviceSecurityInfo(info);
143 return;
144 }
145
146 // 成功获取到设备安全等级,确认当前操作允许的最低安全等级
147 // 假设当前操作允许的最低设备安全等级为3
148 if (level >= 3) {
149 // 目标设备的设备安全等级满足要求, 相关业务正常处理
150 } else {
151 // 目标设备的设备安全等级不满足要求, 建议开发者结合实际业务场景进行相应处理,例如告警、弹窗提示用户等
152 }
153
154 // 结束处理前,需要释放内存
155 FreeDeviceSecurityInfo(info);
156 }
157
158 void CheckDestDeviceSecurityLevelAsync(const DeviceIdentify *device, RequestOption *option)
159 {
160 // 调用异步接口获取设备设备的安全等级等级信息
161 int ret = RequestDeviceSecurityInfoAsync(device, option, DeviceSecurityInfoCallback);
162 if (ret != SUCCESS) {
163 // 获取信息失败,此场景建议开发者根据实际情况进行重试
164 // 此场景下callback不会回调。
165 return;
166 }
167 // 调用成功,等待callback回调。
168 }
169 ```
170
171## Changelog
172
173- V1.0 首次提交
174
175## 相关仓
176
177[数据分级保护](https://gitee.com/openharmony/security_dataclassification)
178
179[**设备安全等级管理**](https://gitee.com/openharmony/security_device_security_level/)
180
181[HUKS](https://gitee.com/openharmony/security_huks)
182
183[应用权限管理](https://gitee.com/openharmony/security_permission)
184
185[设备认证](https://gitee.com/openharmony/security_device_auth)
186
187[SELinux](https://gitee.com/openharmony/security_selinux)
188