TPM Emulator 安装与使用教程
项目概述
TPM Emulator 是一个软件实现的 Trusted Platform Module (TPM) 和 Mobile Trusted Module (MTM) 模拟器,支持 TPM 1.2 标准。该项目由 Mario Strasser 开发,采用 C 语言编写,使用 CMake 构建系统进行编译和安装。
项目结构
TPM Emulator 项目包含以下几个核心组件:
- tpmd - 用户空间应用程序,实现实际的 TPM 模拟器功能
- tpmd_dev - 内核模块,提供
/dev/tpm设备用于向后兼容 - tddl - TSS 兼容设备驱动库
- tpm - TPM 模拟器核心实现
- crypto - 加密算法实现模块
- mtm - MTM 模拟器支持模块
安装要求
在安装 TPM Emulator 之前,需要确保系统满足以下要求:
- CMake 构建环境(版本 2.6 或更高)
- GNU MP 库(版本 4.0 或更高)
- 对于 Windows 系统,需要 MinGW 编译器套件
编译和安装步骤
步骤 1:获取源代码
git clone https://gitcode.com/gh_mirrors/tp/tpm-emulator
cd tpm-emulator
步骤 2:创建构建目录并配置
mkdir build
cd build
cmake ../
如果要启用 MTM 支持,使用以下命令:
cmake ../ -DMTM_EMULATOR=ON
步骤 3:编译项目
make
步骤 4:安装
make install
启动和使用 TPM Emulator
Linux 系统启动
在 Linux 系统上启动 TPM Emulator 需要执行以下步骤:
# 加载 TPM 设备转发模块
modprobe tpmd_dev
# 启动 TPM 模拟器守护进程
tpmd
启动参数说明
TPM Emulator 支持多种启动参数:
usage: tpmd [-d] [-f] [-s storage file] [-u unix socket name]
[-o user name] [-g group name] [-h] [startup mode]
d : enable debug mode
f : forces the application to run in the foreground
s : storage file to use (default: /var/lib/tpm/tpm_emulator-1_2_0_7)
u : unix socket name to use (default: /var/run/tpm/tpmd_socket:0)
o : effective user the application should run as
g : effective group the application should run as
h : print this help message
startup mode : must be 'clear', 'save' (default) or 'deactivated'
启动模式说明
- clear - 清除模式:清除所有 TPM 状态并重新初始化
- save - 保存模式:尝试加载之前保存的 TPM 状态(默认模式)
- deactivated - 停用模式:停用 TPM 功能
故障排除
首次启动问题
如果是第一次启动 TPM Emulator,必须使用 clear 模式:
tpmd clear
恢复失败停止状态
如果模拟器进入失败停止状态,可以按照以下步骤恢复:
# 停用 TPM
tpmd deactivated
# 终止所有 tpmd 进程
killall tpmd
# 以清除模式重新启动
tpmd clear
使用示例
与 TPM/J 配合使用
在 Linux 系统上使用 TPM/J 的示例:
# 启动 TPM 模拟器
modprobe tpmd_dev
tpmd -d
# 设置 TPM/J 环境
cd <path to tpmj>/lib
export CLASSPATH=tpmj.jar:bcprov-jdk15-131.jar:$CLASSPATH
# 运行 TPM 信息工具
java edu.mit.csail.tpmj.tools.TPMInfo
配置说明
TPM Emulator 主要通过命令行参数进行配置,但涉及以下系统路径:
- Unix Socket 路径:
/var/run/tpm/tpmd_socket:0 - 存储文件路径:
/var/lib/tpm/tpm_emulator-1_2_0_7 - 日志文件路径:
/var/log/tpmd.log
这些路径可以在编译时通过 CMake 配置进行修改。
注意事项
- TPM Emulator 仅支持 TPM 1.2 标准
- 不同版本之间的持久存储文件格式可能不兼容
- 在 Windows 系统上需要额外注册系统服务
- 建议首次使用时使用
clear模式启动 - 生产环境中建议使用
save模式以确保状态持久化
通过本教程,您应该能够成功安装、配置和使用 TPM Emulator 来模拟 TPM 1.2 功能,为可信计算应用开发和测试提供支持。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考



