---
title: 搭建步骤
description: "本文以iTrustee SDK中提供的helloworld用例介绍TA和CA编译环境搭建，操作系统版本为openEuler 20.03 LTS SP1。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengcctrustzone/trustzone/fg/kunpengtrustzone_20_0016.html
sourcePath: /source/zh/kunpengcctrustzone/trustzone/fg/kunpengtrustzone_20_0016.html
indexId: 10a905a8fa355c3f843d64fdd32dd7f531b6008a46a026f145057694a245211f72
---
# 搭建步骤

本文以iTrustee SDK中提供的helloworld用例介绍TA和CA编译环境搭建，操作系统版本为openEuler 20.03 LTS SP1。

#### 获取iTrustee SDK开发套件

1. 获取iTrustee SDK开发套件。
  1 git clone -b master https://gitcode.com/openeuler/itrustee_sdk.git

  获取的SDK文件目录结构如下图所示。

  SDK文件中主要涉及“build”
  、“include”
  、“test”
  、“thirdparty”
  四个目录。其中：
  - “build/”存放TA应用的签名工具。
  - “include/”存放当前iTrustee OS支持的函数接口说明，包含GP（Global Platform）标准接口和部分华为扩展接口。
  - “test/”主要存放一些TEE工具和演示demo的TA和CA应用源码。
  - “thirdparty/”存放TA和CA应用使用的第三方库。


2. 获取libboundscheck边界检查函数库。将下载的libboundscheck文件夹移动到“itrustee_sdk/thirdparty/open_source/”目录下，如下图所示。
  1 2 git clone https://gitcode.com/openeuler/libboundscheck.git mv libboundscheck itrustee_sdk/thirdparty/open_source/


#### 编译CA/TA应用

iTrustee SDK的test目录下提供了CA/TA演示用例helloworld，其实现了CA/TA之间的通信。客户可参考此用例完成自己的CA/TA开发。以下步骤以helloworld为例，演示CA/TA的编译。

1. 参考调测环境TA应用开发者证书申请获取TA配套编译材料。主要包括：TA资源配置configs.xml、私钥private_key.pem、华为签发的config二进制文件。
2. 编译CA应用。

  a. 根据configs.xml中TA的UUID修改CA源码中的g_demoTemplateUuid变量。
```
cd itrustee_sdk/test/CA/helloworld
vim ca_demo.c
```


    - 若ca_demo.c中未指定TA的加载路径，则TA文件需部署在默认查找路径“/var/itrustee/ta/”。
    - 若需要指定TA加载路径，可在TEEC_OpenSession调用前，设置TEEC_Context的ta_path字段。如下图表示TA查找目录为/data。
  b. 生成CA二进制。
    1 make

    编译后，会在Makefile文件同级目录产生CA二进制文件，如下图所示。

3. 编译TA应用，进入helloworld的TA目录。
```
cd itrustee_sdk/test/TA/helloworld
```


  a. 查看TA源代码，其中指定了TA可被哪些CA应用调用。
    1 vim ta_demo.c

    图中示例表示该CA需部署到“/vendor/bin”目录下，并由root用户以“/vendor/bin/demo_hello”的命令执行，才能通过CA鉴权。

  b. 根据configs.xml修改manifest.txt中各对应字段的值。
    1 vim manifest.txt

  c. 查看Makefile，确定TA签名打包的配置文件。
    1 vim Makefile

    TA编译会先将源文件编译为so文件，并调用signtool_v3.py脚本根据config_cloud.ini中的配置，对so文件进行签名打包。

  d. 查看config_cloud.ini文件，获取TA签名打包配套资源的存放路径。
```
vim ../../../build/signtools/config_cloud.ini
```


    - secSignKey：private_key.pem私钥路径，用于对TA应用签名。
    - configPath：config二进制路径，用于加载TA时验签。
若使用相对路径，上述两个路径应填写基于“itrustee_sdk/build/signtools/signtool_v3.py”的相对路径。客户可自定义路径。
  e. 根据配置文件中设置的路径放置私钥private_key.pem和config文件。按默认配置，需在“itrustee_sdk/build/signtools”目录下创建如下两个目录，并上传私钥和config到对应目录下。
    1 2 mkdir ../../../build/signtools/TA_cert mkdir ../../../build/signtools/signed_config

  f. 安装Python库，用于签名打包TA。
    1 pip3 install pycryptodomex pycryptodome defusedxml gmssl

  g. 编译TA应用。
    1 make

    编译后，会在Makefile文件同级目录产生TA应用.sec文件，文件名为每个TA应用独有的UUID。

- TEE OS从1.6.2版本开始支持对TA的加密采用SM4-CBC国密算法。可配置config_cloud.ini文件中的secEncryptContentAlg字段为1，TA编译过程将自动使用国密算法加密。默认配置为0（国际AES-CBC算法）。

- CA/TA更多开发资料请参见《iTrustee SDK 开发者手册》，该手册需向华为业务负责人申请获取。
