• Home
Name Date Size #Lines LOC

..--

docs/opentrustee-guidelines/22-Oct-2025-3,6423,058

sdk/22-Oct-2025-7,2665,570

thirdparty/open_source/22-Oct-2025-161124

CHANGELOG.mdD22-Oct-202586 65

LICENSED22-Oct-20258.2 KiB12870

OAT.xmlD22-Oct-20254.3 KiB6619

README.mdD22-Oct-20258.4 KiB183126

README_zh.mdD22-Oct-20258.3 KiB184126

VERSIOND22-Oct-20256 21

bundle.jsonD22-Oct-2025670 3231

README.md

1
2# tee_tee_dev_kit #
3
4## Introduction ##
5
6The TEE SDK development kit supports independent development of TA, including TA dependent header files, compilation frameworks, signature scripts, etc.
7
8| Abbreviations | English | Chinese|
9| ------ | ----------------------------- | ------------ |
10| TEE | Trusted Execution Environment | Trusted Execution Environment|
11| TA | Trusted Application | Trusted Application|
12| SDK | Software Development Kit | Software Development Kit|
13
14## Table of Contents<a name="section161941989596"></a>
15
16The directory structure of TEE SDK is as follows:
17
18```
19├── sdk/build
20│   ├── ld
21│   ├── mk
22│   ├── signkey
23│   └── tools
24├── sysroot
25│   └── usr
26|       └── include
27├── sdk/src
28│   └── TA
29|      └── sample
30├── thirdparty
31│   └── open_source
32│       └── import_open_source_header.sh
33└── CHANGELOG
34```
35
36## Instructions for use<a name="section161941989597"></a>
37
38Developers need to do some preparation work before using the TEE SDK development kit to develop TA.
39
40### Configure the compilation toolchain
41
42The compilation toolchain used by TEE is LLVM, which is consistent with OpenHarmony. Developers need to download the OpenHarmony compilation toolchain first.
43
44First choice to download OpenHarmony [build code repository]( https://gitee.com/openharmony/build )
45
46```
47git clone  git@gitee.com : openharmony/build.git
48```
49
50Then execute the download script in the repository
51
52```
53./build/prebuilts_download.sh
54```
55
56After downloading, it is necessary to declare the path of the LLVM compilation toolchain in the current compilation environment. The compilation toolchain path can be declared using the following command:
57
58```
59export PATH=openharmony/prebuilts/clang/ohos/linux-x86_64/15.0.4/llvm/bin:$PATH
60```
61
62This command is only an example, developers need to specify the correct compilation toolchain path.
63
64### Import third-party header files
65
66TEE integrates the Musl library and security function library, which TA can use. The TEE SDK does not include header files for the musl library and security function library by default, but provides import scripts. Developers need to download the [musl library] first( https://gitee.com/openharmony/third_party_musl )And [Security Function Library]( https://gitee.com/openharmony/third_party_bounds_checking_function )Source code repository:
67
68```
69git clone  git@gitee.com : openharmony/third_party_musl.git
70git clone  git@gitee.com : openharmony/third_party_bounds_checking_function.git
71```
72
73Then execute
74
75```
76./tee_dev_kit/sdk/thirdparty/open_source/import_open_source_header.sh
77```
78
79Import the musl header file and security function library header file from the source code repository into the TEE SDK.
80
81### Replace TA signature and verification key
82
83The TEE SDK has a preset private key for signing TA files, which can only be used for debugging. In the commercial version, developers need to replace this private key themselves. The private key path: tee_dev_kit/sdk/build/signkey/ta_sign_priv_key.pem。 At the same time, it provides the scripts tee_dev-kit/sdk/build/signkey/ta-sign_algonfig.ini, which can be used to configure the signature algorithm. The default signature algorithm is RSA, with a key length of 4096 bits.
84
85If the developer replaces the signature private key in the TEE SDK, they need to correspondingly replace the signature verification public key in the OpenTrustee operating system. The path of the signature verification public key is:/ base/tee/tee_os_framework/lib/syslib/libelf_verify_key/src/common/ta_verify_key.c86
87## Tool Dependency<a name="section11914418405"></a>
88
89The TEE SDK uses Python scripts to parse TA's property configuration files, sign TA files, and perform other operations, so Python tools need to be installed in the development environment.
90
911. Install Python 3 and above versions
92
932. Install Python related libraries, such as:
94
95```
96pip install pycryptodome
97
98pip install defusedxml
99```
100
101If there is a prompt during the compilation process that other Python libraries are missing, they need to be installed together.
102
103## Use constraint<a name="section1371113476307"></a>
104
105-Supported development language: C language
106-SDK runtime environment: Linux operating system
107-No code editor provided
108
109## TA development steps
110
111When developing a new TA, it is necessary to create a new TA source code directory in the tee_dev-kit/sdk/src/TA directory. The directory structure can refer to the demo example code in this directory. Taking helloworld_demo as an example, the directory structure is as follows:
112
113```
114├── helloworld_demo
115▽-- ta_demo. c # TA source code file
116∝ - configs.xml # TA attribute configuration file
117∝ - Makefile # TA Compile Makefile
118∝ - build_ta. sh # TA One Click Script Generation
119```
120
121### TA code writing
122
123The TA code must implement the following entry functions specified in the GP TEE standard:
124
125|TA Entry Function Name | Function Description|
126| -------------------------- | ----------------------------------------------------- |
127|TA_Create Entry Point | Constructor of TA instance, called only once in the lifecycle of each TA instance|
128|TA_SpenSessionExitPoint | Client requests to create a session with TA|
129|TA_invokeCommandEntry Point | After successfully creating a session, the client sends instructions to the TA|
130|TA_CloseSessionExitPoint | Client requests to close session with TA|
131|TA_SestroyInterpoint | The destructor of the TA instance, which OpenTrustee calls when destroying the TA instance|
132
133### TA Makefile Writing
134
135TA needs to write their own Makefile file, please refer to the example code in the SDK. There are the following key points:
136
137-The target file name generated by TA compilation is fixed as libcombine.so.
138-For 64 bit TAs, it is necessary to add the "TARGET_S_SARM64=y" tag in the Makefile header; For 32-bit TA, this tag should not be included in the Makefile.
139
140### TA attribute configuration
141
142Each TA source code directory needs to contain configs.xml, which defines the attribute information of that TA.
143
144|Attribute Name | Data Type | Attribute Description | System Default Value|
145| ------------------- | -------- | ------------------------------------------------------------ | ---------- |
146|Service_name | String | TA name, string length not exceeding 64 characters, only supports numbers and letters, '_' and '-' | None|
147|UUID | UUID | TA unique identifier | None|
148|Instance_ceep_alive | Bool | If true, it means that even if all TA sessions are closed, the TA instance will not be destroyed and the global data will still exist until the TEE runs. If false, it means that if all TA sessions are closed, the TA instance will be destroyed| false      |
149|Stack_Size | Integer | The stack space size for each session of TA needs to be evaluated based on their actual situation | 8192|
150|Heapsosize | Integer | The heap space occupied by the TA instance needs to be evaluated based on its actual situation | 0|
151|Does multi-session | Bool | TA support establishing multiple sessions simultaneously | false|
152|Single_instance | Bool | Whether multiple sessions of TA belong to the same instance (currently only singleInstance is supported as true) | true|
153
154The example is as follows:
155
156```
157<ConfigInfo>
158  <TA_Basic_Info>
159    <service_name>demo-ta</service_name>
160    <uuid>e3d37f4a-f24c-48d0-8884-3bdd6c44e988</uuid>
161  </TA_Basic_Info>
162  <TA_Manifest_Info>
163    <instance_keep_alive>false</instance_keep_alive>
164    <stack_size>8192</stack_size>
165    <heap_size>81920</heap_size>
166    <multi_session>false</multi_session>
167    <single_instance>true</single_instance>
168  </TA_Manifest_Info>
169</ConfigInfo>
170```
171
172### TA compilation and signature
173
174The OpenTrustee SDK provides a one click script for TA generation, which copies tee_dev_kit/sdk/build/build_ta.sh to the TA source code directory for execution. This completes TA compilation, property configuration file parsing, signing, and other operations, and generates a TA installation package file named uuid.sec in the current directory.
175
176## Related Dependency Warehouse<a name="section1371113476308"></a>
177
178[OpenHarmony/build]( https://gitee.com/openharmony/build )
179
180[OpenHarmony/third_party/musl]( https://gitee.com/openharmony/third_party_musl )
181
182[OpenHarmony/third_party/bounds_checking_function]( https://gitee.com/openharmony/third_party_bounds_checking_function )
183

README_zh.md

1
2# tee_tee_dev_kit仓库说明 <a name="ZH-CN_TOPIC_0000001078026808"></a>
3
4## 简介<a name="section11660541593"></a>
5
6tee_tee_dev_kit仓库主要包含TEE SDK开发套件,支持独立开发TA,包含了TA依赖的头文件、编译框架、签名脚本等。
7
8| 缩略语 | 英文                          | 中文         |
9| ------ | ----------------------------- | ------------ |
10| TEE    | Trusted Execution Environment | 可信执行环境 |
11| TA     | Trusted Application           | 可信应用     |
12| SDK    | Software Development Kit      | 软件开发包   |
13
14## 目录<a name="section161941989596"></a>
15
16TEE SDK目录结构如下:
17
18```
19├── sdk/build
20│   ├── ld                                # 生成TA ELF文件的链接脚本
21│   ├── mk                                # TA make编译框架
22│   ├── signkey                           # TA签名用的私钥
23│   └── tools                             # 生成TA安装包并对TA签名的脚本
24├── sysroot
25│   └── usr
26|       └── include                       # 给TA提供的TEE头文件
27├── sdk/src
28│   └── TA                                # 放置TA源码
29|      └── sample                         # TA示例代码
30├── thirdparty
31│   └── open_source
32│       └── import_open_source_header.sh  # 导入TA编译依赖的musl头文件和安全函数库头文件
33└── CHANGELOG                             # SDK包版本发布记录
34```
35
36## 使用说明<a name="section161941989597"></a>
37
38开发者在使用TEE SDK开发套件开发TA之前,需要进行一些准备工作。
39
40###  配置编译工具链
41
42TEE使用的编译工具链为llvm,与OpenHarmony一致,开发者需要先下载OpenHarmony编译工具链。
43
44首选下载OpenHarmony [build代码仓](https://gitee.com/openharmony/build)
45
46```
47git clone git@gitee.com:openharmony/build.git
48```
49
50然后执行该仓中的下载脚本
51
52```
53./build/prebuilts_download.sh
54```
55
56下载完成后,需要在当前编译环境中声明llvm编译工具链的路径。可通过如下命令声明编译工具链路径:
57
58```
59export PATH=openharmony/prebuilts/clang/ohos/linux-x86_64/15.0.4/llvm/bin:$PATH
60```
61
62该命令仅是示例,开发者需要指定正确的编译工具链路径。
63
64###  导入第三方头文件
65
66TEE集成了musl库和安全函数库,TA可以使用这些库。TEE SDK并没有默认包含musl库和安全函数库的头文件,但是提供了导入的脚本。 开发者需要先下载[musl库](https://gitee.com/openharmony/third_party_musl)和[安全函数库](https://gitee.com/openharmony/third_party_bounds_checking_function)源码仓:
67
68```
69git clone git@gitee.com:openharmony/third_party_musl.git
70git clone git@gitee.com:openharmony/third_party_bounds_checking_function.git
71```
72
73然后执行
74
75```
76./tee_dev_kit/sdk/thirdparty/open_source/import_open_source_header.sh
77```
78
79将musl头文件和安全函数库头文件从源码仓导入到TEE SDK中。
80
81### 替换TA签名和验签密钥
82
83TEE SDK中预置了对TA文件进行签名的私钥,该预置私钥只能用来调试,在商用版本中,开发者需要自行替换该私钥。该私钥路径:tee_dev_kit/sdk/build/signkey/ta_sign_priv_key.pem。同时提供了tee_dev_kit/sdk/build/signkey/ta_sign_algo_config.ini脚本,可以用来对签名算法进行配置。默认的签名算法是RSA,密钥长度4096bit。
84
85如果开发者替换了TEE SDK中的签名私钥,需要对应替换OpenTrustee操作系统中的验签公钥,验签公钥的路径:base/tee/tee_os_framework/lib/syslib/libelf_verify_key/src/common/ta_verify_key.c86
87## 工具依赖<a name="section11914418405"></a>
88
89TEE SDK中用到了python脚本来完成TA的属性配置文件解析、对TA文件进行签名等操作,因此需要在开发环境上安装python工具。
90
911、安装python3及以上版本
92
932、安装python相关的库,如:
94
95```
96pip install pycryptodome
97
98pip install defusedxml
99```
100
101如果在编译过程中提示缺少其他python库,需要一并安装。
102
103## 使用约束<a name="section1371113476307"></a>
104
105- 支持开发语言:C语言
106- SDK运行环境:linux操作系统
107- 未提供代码编辑器
108
109## TA开发步骤
110
111开发一个新的TA时,需要在tee_dev_kit/sdk/src/TA目录下创建新的TA源码目录,目录结构可以参考该目录下demo示例代码。以helloworld_demo为例,目录结构如下:
112
113```
114├── helloworld_demo
115    ├── ta_demo.c                  # TA源码文件
116    ├── configs.xml                # TA属性配置文件
117    ├── Makefile                   # TA编译Makefile
118    ├── build_ta.sh                # TA一键生成脚本
119```
120
121### TA代码编写
122
123TA代码必须实现如下GP TEE标准规定的入口函数,详细说明可以参考《[TEE Client API Specification v1.0 (GPD_SPE_007)](https://globalplatform.org/specs-library/?filter-committee=tee)124
125| TA入口函数名称             | 函数描述                                              |
126| -------------------------- | ----------------------------------------------------- |
127| TA_CreateEntryPoint        | TA实例的构造函数,每个TA实例的生命周期中只被调用一次  |
128| TA_OpenSessionEntryPoint   | 客户端请求创建一个与TA的会话                          |
129| TA_InvokeCommandEntryPoint | 客户端在创建会话成功后向TA发送指令                    |
130| TA_CloseSessionEntryPoint  | 客户端请求关闭与TA的会话                              |
131| TA_DestroyEntryPoint       | TA示例的析构函数,OpenTrustee在销毁TA实例时调用此函数 |
132
133### TA Makefile编写
134
135TA需要自行编写Makefile文件,可参考SDK中示例代码。有如下要点:
136
137- TA编译生成的目标文件名固定为libcombine.so138- 对于64位的TA,需要在Makefile头部增加“TARGET_IS_ARM64 = y”标记;对于32位TA,Makefile中不应包含此标记。
139
140### TA属性配置
141
142每个TA源码目录下需要包含configs.xml,定义该TA的属性信息。
143
144| 属性名              | 数据类型 | 属性描述                                                     | 系统默认值 |
145| ------------------- | -------- | ------------------------------------------------------------ | ---------- |
146| service_name        | String   | TA名称,字符串长度不超过64字符,仅支持数字、字母,'_'和'-'   | 无         |
147| uuid                | UUID     | TA唯一标识                                                   | 无         |
148| instance_keep_alive | Bool     | 如果为true,表示即使TA所有会话被关闭,TA实例也不会被销毁,全局数据仍然存在,直到TEE运行结束。如果为false,表示若TA所有会话关闭,TA实例会被销毁。 | false      |
149| stack_size          | Integer  | TA每个会话的栈空间大小,需要根据TA实际情况评估               | 8192       |
150| heap_size           | Integer  | TA实例占用的堆空间大小,需要根据TA实际情况评估               | 0          |
151| multi_session       | Bool     | TA是否支持同时建立多个会话                                   | false      |
152| single_instance     | Bool     | TA的多个会话是否归属同一个实例(当前只支持singleInstance为true) | true       |
153
154示例如下:
155
156```
157<ConfigInfo>
158  <TA_Basic_Info>
159    <service_name>demo-ta</service_name>
160    <uuid>e3d37f4a-f24c-48d0-8884-3bdd6c44e988</uuid>
161  </TA_Basic_Info>
162  <TA_Manifest_Info>
163    <instance_keep_alive>false</instance_keep_alive>
164    <stack_size>8192</stack_size>
165    <heap_size>81920</heap_size>
166    <multi_session>false</multi_session>
167    <single_instance>true</single_instance>
168  </TA_Manifest_Info>
169</ConfigInfo>
170```
171
172### TA编译和签名
173
174OpenTrustee SDK中提供了TA一键生成脚本,将tee_dev_kit/sdk/build/build_ta.sh拷贝到TA源码目录执行,即完成TA编译、属性配置文件解析、签名等操作,在当前目录生成uuid.sec命名的TA安装包文件。
175
176
177## 相关依赖仓<a name="section1371113476308"></a>
178
179 [OpenHarmony/build](https://gitee.com/openharmony/build)
180
181[OpenHarmony/third_party/musl](https://gitee.com/openharmony/third_party_musl)
182
183[OpenHarmony/third_party/bounds_checking_function](https://gitee.com/openharmony/third_party_bounds_checking_function)
184