1e656c62eSopenharmony_ci# TEE Client 2e656c62eSopenharmony_ci 3e656c62eSopenharmony_ci## Introduction 4e656c62eSopenharmony_ci 5e656c62eSopenharmony_ciTEE Client provides an API interface for accessing TEE to the OpenHarmony side CA (Client Application), and also includes TEE's proxy services to work with TEE to achieve secure storage, log printing, and other functions. 6e656c62eSopenharmony_ci 7e656c62eSopenharmony_ciTEE Client includes the following modules: 8e656c62eSopenharmony_ci 9e656c62eSopenharmony_ci- libteec.so: Provide the TEE Client API for native applications of HAP applications or system components. 10e656c62eSopenharmony_ci- libteec_vendor.so: Provide TEE Client API for Native applications of chip components. 11e656c62eSopenharmony_ci- cadaemon: Forward CA requests and authenticate the CA. 12e656c62eSopenharmony_ci- teecd: As a proxy service for TEE, it supports TEE's implementation of secure storage and other functions. Simultaneously teecd supports identity recognition for CA. 13e656c62eSopenharmony_ci- tlogcat: Support printing TEE logs. 14e656c62eSopenharmony_ci 15e656c62eSopenharmony_ciFigure 1: Architecture diagram of TEE Client 16e656c62eSopenharmony_ci 17e656c62eSopenharmony_ci 18e656c62eSopenharmony_ci 19e656c62eSopenharmony_ci## Directory 20e656c62eSopenharmony_ci 21e656c62eSopenharmony_ci``` 22e656c62eSopenharmony_cibase/tee/tee_client 23e656c62eSopenharmony_ci├── frameworks 24e656c62eSopenharmony_ci│ └── libteec_vendor # libteec_vendor.so library, providing TEE Client API. 25e656c62eSopenharmony_ci├── interfaces 26e656c62eSopenharmony_ci│ ├── inner_api # Internal interfaces of this component 27e656c62eSopenharmony_ci| └── kits # The libteec.so library and corresponding TEE Client API published to SDK 28e656c62eSopenharmony_ci└── services 29e656c62eSopenharmony_ci ├── authentication # CA identity recognition(Reserved function, not yet enabled) 30e656c62eSopenharmony_ci ├── cadaemon # Forward CA request 31e656c62eSopenharmony_ci ├── teecd # TEE proxy services 32e656c62eSopenharmony_ci └── tlogcat # TEE log service 33e656c62eSopenharmony_ci``` 34e656c62eSopenharmony_ci 35e656c62eSopenharmony_ci## Interface Description 36e656c62eSopenharmony_ci 37e656c62eSopenharmony_ciThe list of APIs provided by the TEE Client to CA is as follows: 38e656c62eSopenharmony_ci 39e656c62eSopenharmony_ci| Name | Description | 40e656c62eSopenharmony_ci| ------------------------------------------------------------ | -------------------- | 41e656c62eSopenharmony_ci| TEEC_InitializeContext (const char *name, TEEC_Context *context) | Initialize TEE context. | 42e656c62eSopenharmony_ci| TEEC_FinalizeContext (TEEC_Context *context) | End TEE context. | 43e656c62eSopenharmony_ci| TEEC_OpenSession (TEEC_Context *context, TEEC_Session *session, const TEEC_UUID *destination, uint32_t connectionMethod, const void *connectionData, TEEC_Operation *operation, uint32_t *returnOrigin) | Establish a conversation with TEE. | 44e656c62eSopenharmony_ci| TEEC_CloseSession (TEEC_Session *session) | Close the session with TEE. | 45e656c62eSopenharmony_ci| TEEC_InvokeCommand (TEEC_Session *session, uint32_t commandID, TEEC_Operation *operation, uint32_t *returnOrigin) | Send commands to TEE. | 46e656c62eSopenharmony_ci| TEEC_RegisterSharedMemory (TEEC_Context *context, TEEC_SharedMemory *sharedMem) | Register for shared memory. | 47e656c62eSopenharmony_ci| TEEC_AllocateSharedMemory (TEEC_Context *context, TEEC_SharedMemory *sharedMem) | Apply for shared memory. | 48e656c62eSopenharmony_ci| TEEC_ReleaseSharedMemory (TEEC_SharedMemory *sharedMem) | Release shared memory. | 49e656c62eSopenharmony_ci| TEEC_RequestCancellation (TEEC_Operation *operation) | Cancel the running operation. | 50e656c62eSopenharmony_ci 51e656c62eSopenharmony_ciThe above APIs are all specified by the GlobalPlatform TEE standard, which can be referred to in the "[TEE Client API Specification v1.0 (GPD_SPE_007)](https://globalplatform.org/specs-library/?filter-committee=tee)". There are differences between a small number of implementations and the GlobalPlatform TEE specification, and the differences are as follows: 52e656c62eSopenharmony_ci 53e656c62eSopenharmony_ci1. The TEEC_Context structure member ta_path of the TEEC_OpenSession interface supports specifying the file path of TA (limited to the /data directory). 54e656c62eSopenharmony_ci 55e656c62eSopenharmony_ci Give an example: 56e656c62eSopenharmony_ci 57e656c62eSopenharmony_ci ``` 58e656c62eSopenharmony_ci TEEC_Context context; 59e656c62eSopenharmony_ci context.ta_path = (uint8_t *)"/data/58dbb3b9-4a0c-42d2-a84d-7c7ab17539fc.sec" 60e656c62eSopenharmony_ci ``` 61e656c62eSopenharmony_ci 62e656c62eSopenharmony_ci If CA doesn't use ta_path to specify the file path of TA, TEE Client will read the TA file named uuid.sec (uuid needs to be replaced with TA's real uuid) from the default path. There are two default paths: "/system/bin" and "/vendor/bin". 63e656c62eSopenharmony_ci 64e656c62eSopenharmony_ci2. The input parameter connectionMethod of the TEEC_OpenSession interface only supports TEEC_LOGIN_IDENTIFY. 65e656c62eSopenharmony_ci 66e656c62eSopenharmony_ci For the fourth input parameter connectionMethod in the TEEC-OpenSession function, the GP specification defines six Login Methods, and TEE Client extends the type of TEEC_LOGIN_IDENTIFY and only supports this type of connectionMethod. 67e656c62eSopenharmony_ci 68e656c62eSopenharmony_ci3. When calling TEEC_OpenSession, its parameters are limited. 69e656c62eSopenharmony_ci 70e656c62eSopenharmony_ci When calling the TEEC_OpenSession interface, the params[2] and params[3] in TEEC_Operation are reserved for the system and are not allowed for use by CA. CA can only use params[0] and [1]. 71e656c62eSopenharmony_ci 72e656c62eSopenharmony_ci## Guidelines for Compilation 73e656c62eSopenharmony_ci 74e656c62eSopenharmony_ciThe TEE Client component supports separate compilation and debugging. Taking the RK3568 chip as an example, run the following command to compile the TEE Client component: 75e656c62eSopenharmony_ci 76e656c62eSopenharmony_ci``` 77e656c62eSopenharmony_ci./build.sh --product-name rk3568 --ccache --build-target tee_client 78e656c62eSopenharmony_ci``` 79e656c62eSopenharmony_ci 80e656c62eSopenharmony_ciThe path to the compiled product:out/rk3568/tee/tee_client 81e656c62eSopenharmony_ci 82e656c62eSopenharmony_ciCompilation products can be pushed into the device for debugging: 83e656c62eSopenharmony_ci 84e656c62eSopenharmony_ci``` 85e656c62eSopenharmony_cihdc file send cadaemon.json /system/profile/ 86e656c62eSopenharmony_cihdc file send cadaemon.cfg /system/etc/init/ 87e656c62eSopenharmony_cihdc file send libteec.so /system/lib/ 88e656c62eSopenharmony_cihdc file send libcadaemon.so /system/lib/ 89e656c62eSopenharmony_cihdc file send tlogcat /system/bin/ 90e656c62eSopenharmony_cihdc file send libteec_vendor.so /vendor/lib/ 91e656c62eSopenharmony_cihdc file send teecd /vendor/bin/ 92e656c62eSopenharmony_ci``` 93e656c62eSopenharmony_ci 94e656c62eSopenharmony_ci## Related code repository 95e656c62eSopenharmony_ci 96e656c62eSopenharmony_ci[tee_tzdriver](https://gitee.com/openharmony-sig/tee_tee_tzdriver) 97