rust-libteec 0.4.1

Rust implementation of TEE Client API for secure communication with Trusted Applications.
Documentation
# rust-libteec

[![Crates.io](https://img.shields.io/crates/v/rust-libteec.svg)](https://crates.io/crates/rust-libteec)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)

## 介绍

基于 GlobalPlatform TEE Client API 规范的 TEE (Trusted Execution Environment) 客户端库的 Rust 实现。该库提供与可信执行环境中的可信应用 (TA) 通信的接口,支持通过机密通信通道(TLS + VSOCK)进行安全数据传输。

## 主要特性

- **完整的 TEEC API 实现**: 支持上下文管理、会话管理、命令调用等所有标准 API
-**机密通信**: 基于 TLS + VSOCK 的加密通信通道,CA 与 TA 之间的所有数据都通过此通道传输
-**共享内存管理**: 管理 MEMREF 类型参数的本地缓冲区(数据通过网络序列化传输)
-**CA 认证**: 自动验证客户端应用的签名和证书链,为 TA 提供 ACL 访问控制信息
-**多参数类型支持**: VALUE、MEMREF(INPUT/OUTPUT/INOUT)、PARTIAL MEMREF 等
-**线程安全**: 使用 DashMap 实现并发安全的缓存和上下文管理

## 软件架构

```
rust-libteec/
├── src/
│   ├── cc_client/          # 机密通信客户端模块
│   │   ├── client.rs       # TLS + VSOCK 客户端实现
│   │   ├── protocol.rs     # 通信协议定义
│   │   ├── psk.rs          # PSK 密钥生成
│   │   └── vsock_define.rs # VSOCK 配置
│   ├── teec/               # TEEC API 实现模块
│   │   ├── ca_auth.rs      # CA 认证和缓存管理
│   │   ├── context.rs      # TEE 上下文管理
│   │   ├── mod.rs          # 主模块和公共 API
│   │   ├── operation.rs    # 操作参数处理
│   │   ├── safe_ptr.rs     # 安全指针封装
│   │   └── shared_memory.rs# 共享内存管理
│   ├── error.rs            # 错误类型定义
│   ├── lib.rs              # 库入口
│   └── teec_trace.rs       # 日志跟踪
├── teec-api-types/         # TEE API 类型定义(子 crate)
├── examples/               # Rust 示例程序
├── c-examples/             # C 语言示例程序
└── tests/                  # 集成测试
```

## 安装教程

### 系统要求

- **Rust 1.80 或更高版本**
- Linux 操作系统(支持 VSOCK)
- GCC(用于编译 C 示例)
- clang
- cmake

### 安装步骤

1. **克隆仓库**   ```bash
   git clone https://gitee.com/openkylin/rust-libteec.git
   cd rust-libteec
   ```

2. **构建库**   ```bash
   # 构建发布版本
   cargo build --release

   # 或使用 Makefile
   make build
   ```

3. **安装到系统**(可选):
   ```bash
   sudo make install
   ```

## 使用说明

### Rust 项目中使用

在 `Cargo.toml` 中添加依赖:

```toml
[dependencies]
rust-libteec = "0.2.0"
```

基本使用示例请参考 [examples/cc-teec.rs](examples/cc-teec.rs)。

### 运行示例

```bash
# 运行 Rust 示例
cargo run --release --example cc-teec

# 编译并运行 C 示例
make test-c-examples
```

### 运行测试

```bash
# 运行单元测试
make test

# 运行覆盖率测试
make coverage
```

## 特性标志

- `ca-sign-verify`: 启用 CA 认证功能(默认启用)
- `debug_level_0` ~ `debug_level_4`: 控制日志详细程度(默认 level_2)

## 参与贡献

1. Fork 本仓库
2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
4. 推送到分支 (`git push origin feature/AmazingFeature`)
5. 开启 Pull Request

## 许可证

本项目采用 Apache License 2.0 许可证 - 详见 [LICENSE](LICENSE) 文件

## 联系方式

- 项目主页: https://gitee.com/openkylin/rust-libteec
- 问题反馈: https://gitee.com/openkylin/rust-libteec/issues