1 trusted computing tss - tcg software stack tcg software stack 2010-04-28

67
1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

Post on 19-Dec-2015

257 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

1

Trusted Computing

TSS - TCG SoftwareStack

TCG Software Stack

2010-04-28

Page 2: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

2

• Introduction

• TPM Internals

• TPM Device Driver (TDD)

• TCG Device Driver Library (TDDL)

• TCG Core Services (TCS)

• TCG Service Provider (TSP)

TCG Software Stack

Overview

Page 3: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

3

• Introduction– TSS Overview– TSS Architecture

• TPM Internals

• TPM Device Driver (TDD)

• TCG Device Driver Library (TDDL)

• TCG Core Services (TCS)

• TCG Service Provider (TSP)

TCG Software Stack

Overview

Page 4: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

4

Introduction

• TSS 是与 TPM 进行交互的核心软件部件• TSS 的设计规范由 TCG 颁布

– TSS 1.2 规范已有 750 余页– 厂商自行设计的 TSS 必须符合 TSS 1.2 标准

• TSS 的设计目的– 1. 为应用程序提供到 TPM 功能的单入口点– 2. 提供对 TPM 的同步访问– 3. 按标准构建字节流隐藏应用程序所构建的命令流– 4. TPM 的资源管理

TCG Software Stack

Page 5: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

5

Introduction

• TSS 体系结构– TCG 服务提供者 (TSP)

• 顶层模块• 提供标准的 API 接口

– TSS 核心服务 (TCS)• 管理服务

– TCG 设备驱动库 (TDDL)

• 提供标准的驱动接口

TCG Software Stack

Page 6: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

6

• Introduction

• TPM Internals– I/O 、 Execution Engine 、 RNG 、……

• TPM Device Driver (TDD)

• TCG Device Driver Library (TDDL)

• TCG Core Services (TCS)

• TCG Service Provider (TSP)

TCG Software Stack

Overview

Page 7: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

7

TPM Internals

• I/O– 管理流经通信总线的信号流– 典型的 LPC 总线 (Low PinCount Bus)

• Execution Engine– 命令的校验及解析– 命令码的执行– 控制内部执行流– 微控制器

TCG Software Stack

RSA Engine

RSA key-generator

SHA1 Engine

RNG

Opt-in

I/O(LPC Bus)

Execution Engine

Non-volatile storage(special keys, owner secret, …)

Volatile storage(keyslots, PCR registers, …)

TPM

Page 8: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

8

• SHA-1 Engine (160 bits)– 主要被 TPM 使用,作为其可信的哈希算法– 在平台启动过程中,其接口暴露在 TPM 外以进行度量工作– 未来的 TPM 版本会加入更多的哈希算法

• RNG– TPM 内部的随机源– Nonce , 密钥的生成 , ...

TCG Software Stack

RSA Engine

RSA key-generator

SHA1 Engine

RNG

Opt-in

I/O(LPC Bus)

Execution Engine

Non-volatile storage(special keys, owner secret, …)

Volatile storage(keyslots, PCR registers, …)

TPM

TPM Internals

Page 9: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

9

• RSA Engine and Key Generator– 非对称密钥的生成 (RSA ;存储 SK 及 AIK 密钥大

小 >= 2048)– 必须支持 512, 1024, 2048 bit 的密钥– 建议使用 2048 位的密钥– RSA 密钥生成遵循 PKCS #1 标准– RSA 密钥在使用的时候要加载到 TPM 内部

TCG Software Stack

RSA Engine

RSA key-generator

SHA1 Engine

RNG

Opt-in

I/O(LPC Bus)

Execution Engine

Non-volatile storage(special keys, owner secret, …)

Volatile storage(keyslots, PCR registers, …)

TPM

TPM Internals

Page 10: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

10

• Volatile Memory– 密钥槽 (10 个 ) 、 PCR 值 (24 个 )– 密钥句柄、授权会话句柄等

• Non-Volatile Memory– EK(2048bit) 、 EK 证书– SRK(2048bit) 及属主 (Owner) 授权数据 (160bit) 等

• Opt-In: 平台属主决定是否使用 TPM

TCG Software Stack

RSA Engine

RSA key-generator

SHA1 Engine

RNG

Opt-in

I/O(LPC Bus)

Execution Engine

Non-volatile storage(special keys, owner secret, …)

Volatile storage(keyslots, PCR registers, …)

TPM

TPM Internals

Page 11: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

11

• Introduction

• TPM Internals

• TPM Device Driver (TDD)

• TCG Device Driver Library (TDDL)

• TCG Core Services (TCS)

• TCG Service Provider (TSP)

TCG Software Stack

Overview

Page 12: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

12

TPM Device Driver

• TPM 的驱动程序由厂商提供,并运行在内核模式下;

• 驱动程序所提供的功能接口仅由 TDDL 调用使用,而不允许其他的组件调用;

• 驱动是除了 TSS 外,是不提供对其他应用程序的连接 TPM 服务;

• 提供除基本驱动以外的额外服务 例如,电源管理等;

• TDD 接口设计必须参考 TIS 标准。

TCG Software Stack

Page 13: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

13

• Introduction

• TPM Internals

• TPM Device Driver (TDD)

• TCG Device Driver Library (TDDL)– Introduction– TPM Commands– TPM Authorization Protocols

• TCG Core Services (TCS)

• TCG Service Provider (TSP)

TCG Software Stack

Overview

Page 14: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

14

TCG Device Driver Library

• Introduction– TSS 用于和 TPM 通信的组件。– 运行于用户空间的第一个 TSS 组件,提供了内核模

式到用户模式的转换。处于 TCS 和 TDD 之间,为TCS 提供接口 TDDLi 。

– TDDLi 是一个单线程同步接口,发送到 TDDLi 的 TPM 命令都已经被串行化。

– 对于直接访问 TPM 设备的程序, TDDLi 提供了 7个功能函数,用于和 TDD 进行通信。

• Tddli_Open() 、 Tddli_Close() 、 Tddli_TransmitData(…) 、…

– TDDL 必须仅提供对 TCS 的链接TCG Software Stack

Page 15: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

15

TCG Device Driver Library

• TPM Command– 规范中 TPM 有 122 个命令– 所有 TPM 命令格式都有相同的头

PARAM HMACType Name Description

# SZ # SZ

1 2 TPM_TAG tag TPM命令标签

2 4 UINT32 paramSize 整个命令的大小

3 4 TPM_COMMAND_CODE ordinal 命令索引,唯一标示一个命令,格式: TPM_ORD_XX

TCG Software Stack

Command

Result

Tag Name

0x00C1 TPM_TAG_RQU_COMMAND

0x00C2 TPM_TAG_RQU_AUTH1_COMMAND

0x00C3 TPM_TAG_RQU_AUTH2_COMMAND

0x00C4 TPM_TAG_RSP_COMMAND

0x00C5 TPM_TAG_RSP_AUTH1_COMMAND

0x00C6 TPM_TAG_RSP_AUTH2_COMMAND

TPM_ORD_OIAP 10 0x0000000A X

TPM_ORD_OSAP 11 0x0000000B X

TPM_ORD_OwnerClear 91 0x0000005B X

TPM_ORD_OwnerReadInternalPub 129 0x00000081 X

TPM_ORD_OwnerReadPubek 125 0x0000007D X

TPM_ORD_OwnerSetDisable 110 0x0000006E X

Page 16: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

16

TCG Device Driver Library

• Example A:

PARAM HMACType Name Description

# SZ # SZ

1 2 TPM_TAG tag TPM_TAG_RQU_COMMAND

2 4 UINT32 paramSize Total number of input bytes including paramSize and tag

3 4 TPM_COMMAND_CODE ordinal Command ordinal: TPM_ORD_GetCapability

4 4 TPM_CAPABILITY_AREA capArea Partition of capabilities to be interrogated

5 4 UINT32 subCapSize Size of subCap parameter

6 <> BYTE[] subCap Further definition of information

TCG Software Stack

Command

How many PCRs do you have?

TPM_GetCapability Command

命令标识 0x00 C1

包大小 0x00 00 00 16

命令索引 0x00 00 00 65

功能域 0x00 00 00 05

功能子域大小 0c00 00 00 04

功能子域 0x00 00 01 01

… TPM_TAG_RQU_COMMAND… Command size: 22 bytes (0x16)… TPM_ORD_GetCapability… TPM_CAP_PROPERTY… Sub capability size: 4 bytes… TPM_CAP_PROP_PCR

Page 17: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

17

TCG Device Driver Library

• Example A:

TCG Software Stack

Result

Ok, listen: 24.

PARAM HMACType Name Description

# SZ # SZ

1 2 TPM_TAG tag TPM_TAG_RSP_COMMAND

2 4 UINT32 paramSize Total number of output bytes including paramSize and tag

3 4 TPM_RESULT returnCode The return code of the operation.

4 4 UINT32 respSize The length of the returned capability response

5 <> BYTE[ ] resp The capability response

TPM_GetCapability Response

命令标识 0x00 C4

包大小 0x00 00 00 12

返回码 0x00 00 00 00

响应净荷大小 0x00 00 00 04

响应数据大小 0c00 00 00 18

… TPM_TAG_RSP_COMMAND… Response size: 18 bytes (0x12)… TPM_SUCCESS… Response payload size: 4 bytes… Response data: 0x18 … 24 PCRs

Page 18: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

18

TCG Device Driver Library

• Programme 1.

TCG Software Stack

// 获取 8 个字节随机数;

// 使能 SHA-1 ;

// 需加密的数据, 64 个字节;

Page 19: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

19

TCG Device Driver Library

• TPM Authorization Protocols– Authorization

• 能够证明请求者拥有执行某个 TPM 功能和使用 某些对象的许可。

• 用双方共享秘密 ( 授权数据 ) 进行证明,无其他 方式。

– Authorization Data• 是一个在用户和 TPM 之间共享的 160bit 秘密值• 由用户创建,可以看做是 password

• SRK 及 TPM Owner 的授权数据要保存在 TPM 内部非易失性存储区内,而其他对象的授权数据则要与其自身进行绑定。

TCG Software Stack

Page 20: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

20

TCG Device Driver Library

• TPM Authorization Protocols– Object Independent Authorization Protocol (OIAP)

• 为提高效率而设计,在一个授权会话中可以验证一个或多个不同的对象

• 验证的过程使用双方共享的秘密值 ( 授权数据 )

– Object Specific Authorization Protocol (OSAP)• 在一个授权会话中仅对一个对象进行操作• 验证的过程使用双方共享的秘密值 ( 授权数据 )• 设置或重新设置授权数据的时候必须使用该协议

TCG Software Stack

Page 21: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

21

TPM Device Driver Library

• Example B: ( 创建并使用密钥—创建密钥 )

TCG Software Stack

TPM_OSAP(parentKeyHandle, NonceOdd)

ShareSecret = HMAC(parenthKeyAuth; NonceEven, NonceOdd)

authHandle, authLastNonceEven, NonceEven

TPM_CreateWrapKey(parentKeyHandle, encAuth, keyInfo, authHandle, NonceOdd)HMAC(ShareSecret; encAuth, keyInfo, authLastNonceEven, NonceOdd)

NonceEven’, keyBlob, HMAC(ShareSecret; NonceEven’, NonceOdd)

Page 22: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

22

TPM Device Driver Library

• Example B: ( 创建并使用密钥—加载密钥 )

TCG Software Stack

TPM_OIAP()

authHandle, NonceEven

TPM_LoadKey2(parentKeyHandle, Warppedkey, authHandle, NonceOdd)HMAC(parentKeyauth; Warppedkey, NonceEven, NonceOdd)

NonceEven’, keyBlob, HMAC(parentKeyauth; NonceEven’, NonceOdd)

Page 23: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

23

TPM Device Driver Library

• Example B: ( 创建并使用密钥—使用密钥 )

TCG Software Stack

TPM OSAP(keyHandle, NonceOdd)

ShareSecret = HMAC(KeyAuth; NonceEven, NonceOdd)

authHandle, authLastNonceEven, NonceEven

TPM_Seal(keyHandle, encAuth, PCRInfo, data, authHandle, NonceOdd)HMAC(ShareSecret; encAuth, PCRInfo, data, authLastNonceEven, NonceOdd)

NonceEven’, SealedBlob, HMAC(ShareSecret; NonceEven’, NonceOdd)

Page 24: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

24

• Introduction

• TPM Internals

• TPM Device Driver (TDD)

• TCG Device Driver Library (TDDL)

• TCG Core Services (TCS)– Introduction– Management Services

• TCG Service Provider (TSP)

TCG Software Stack

Overview

Page 25: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

25

TCG Core Service

• Introduction– TPM 的缺陷

• 一次只有一个操作可以进行• 处理速度很慢• 有限的资源,包括密钥槽、授权槽等• 只能通过一个驱动程序与其进行串行通信• 本地软件与之通信是有限制的

– TCS 的优点• 可以对多个 TPM待处理的操作进行排队• 对于不需要 TPM 处理的操作, TCS 可以自行作出响应• 对 TPM 有限资源进行管理,可看作是无限的资源• 将输入输出的数据进行相应的转换• 可以对资源提供本地的或者远程的调用方式

TCG Software Stack

Page 26: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

26

TCG Core Service

• Introduction– TCS 的特点

• TCS 是一个后台服务 (daemon or system service)• 为 TSP 提供标准的接口• TCG 标准中, TCS 对 TPM 的访问是唯一的

• 每个 TPM 仅对应一个 TCS– TCS 并不提供加解密功能

• 对 TPM 有限的资源进行管理– 密钥、证书管理– 上下文管理

• TCS负责调度要执行的 TPM 命令– 每个操作都是原子操作– 允许多线程访问 TCS

• TCS 对 TPM 命令格式进行转换

TCG Software Stack

“软件TPM”

Page 27: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

27

TCG Core Service

• Introduction– TCS Interface (TCSi)

• 类 C语言接口• 允许多个线程访问 TCS

• 每个操作都是原子操作• 作为系统进程而存在, TSP 与 TCS 之间的通信有可能是

RPC 。• 真正的接口定义在 TSS 发布的 .wsdl文件中。

TCG Software Stack

PPRomate PRomate P

TSPTSP

TSPTSP

RPCRPCTCGTCG

Page 28: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

28

TCG Core Service

• Management Services– 上下文的管理

TCG Software Stack

TSS Core Services Interfaces (TCSi)

TCS Context Manager

AllocatedMemory blocks

Handles

• 在发送命令到 TCS 之前,上层 (TSP, 应用程序 ) 需要打开一个 TCS上下文对象

• TCS上下文管理器管理多个 TCS上下文• 为每一个上下文分配所需内存并设置其

中每一类型对象的句柄,同时包括该上下文的句柄

• 对每一个上下文进行内存管理

Context

Page 29: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

29

TCG Core Service

• Management Services– 密钥、证书的管理

TCG Software Stack

TSS Core Services Interfaces (TCSi)

Key & CredentialManager

Key Cache Manager

• 证书管理– 只负责对 EK 证书、平台证

书及一致性证书进行管理,只有 Owner 有对证书的访问权

PersistentStorage (S)

Page 30: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

30

TCG Core Service

• 密钥存储管理– 定义了一个密钥永久存储层次结构,在其内部对其进行管理

– 所有密钥在其中进行注册,并为每个密钥分配唯一标识的 UUID ,通过它来加载密钥

– 子密钥的加载依赖于父密钥

TCG Software Stack

Key Manager

EK

SRKRSAAuthdata

TPM

Key Slots

MassStorage

……

……

……

……

……

……

Page 31: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

31

TCG Core Service

• 密钥缓存管理– 在密钥加载之后,

为其分配一个唯一的 TCS 密钥句柄

– 当 KeySlot没有空间时,将其中某一个密钥换出,然后新密钥加入

– 需要建立一张 TCS与 TPM 密钥句柄的映射表

TCG Software Stack

Key Manager

EK

SRKRSAAuthdata

TPM

Key Slots

MassStorage

……

……

……

……

……

……

Page 32: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

32

TCG Core Service

• Example C.

• 创建TPM密钥– RSA引擎创建一个新的 RSA 密钥对

– 一个父密钥 ( 存储密钥 ) 需要被指定,用于封装 (Wrap) 使用后的新密钥

– 为新密钥设置授权信息

TCG Software Stack

Key Manager

EK

SRKRSAAuthdata

TPM

Key Slots

MassStorage

……

……

……

……

……

……

Page 33: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

33

TCG Core Service

• Example C.

• 存放 TPM 密钥– 在使用完 RSA 密钥

对后,将其存放在密钥结构中,用 UUID唯一标识

– 用父密钥对其加密 :

– Enc(Ppk; PK, Enc(Authdata; SK))

TCG Software Stack

Key Manager

EK

SRKRSAAuthdata

TPM

Key Slots

MassStorage

……

……

……

……

……

Enc

Page 34: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

34

TCG Core Service

• Example C.

• 加载密钥– 加载一个密钥 (签名、存储、 AIK等 ) 以备使用

– 首先需要知道该密钥的 UUID ,然后对其父密钥进行授权解密操作

TCG Software Stack

Key Manager

EK

SRKRSAAuthdata

TPM

Key Slots

1

2Mass

Storage

……

……

……

……

……

……

Page 35: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

35

TCG Core Service

• Example C.

• 加载密钥– 第一步:将 # 1 密

钥部分用 SRK 的私钥进行解密,这时候需要 SRK 的授权数据

– 将 #1 存放在 KeySlot 中

TCG Software Stack

Key Manager

EK

SRKRSA

1Authdata

TPM

Key Slots

1

2Mass

Storage

……

……

……

……

……

……

Dec

Page 36: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

36

TCG Core Service

• Example C.

• 加载密钥– 第二步:用 #1 的私

钥对 #2 密钥进行解密,并将其放入 KeySlot 中

– #1 需要授权数据

TCG Software Stack

Key Manager

EK

SRKRSA

12Authdata

TPM

Key Slots

1

2Mass

Storage

……

……

……

……

……

……

Dec

Page 37: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

37

TCG Core Service

• Example C.

• 加载密钥– 第三步:用 #2 的私

钥对所要加载的密钥进行解密,并将其放入 KeySlot 中

– #2 需要授权数据– 这样一个密钥的加

载就完成了,在使用该密钥的时候会需要该密钥的授权数据

TCG Software Stack

Key Manager

EK

SRKRSA

12Authdata

TPM

Key Slots

1

2Mass

Storage

……

……

……

……

……

……

Dec

Page 38: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

38

TCG Core Service

• Management Services– 事件的管理

TCG Software Stack

TSS Core Services Interfaces (TCSi)

Event Manager (Event Log)

OS

TSS runtime

BIOS

• 生成、管理并输出相关的事件 (PCR)记录– 主要的事件记录由 TSS 来管理,例如运行时

的度量 (IMA)

– 其他并不受 TSS 管理的事件,例如 BIOS 度量由 CRTM完成, OS 内核模块的度量由 VMM(DRTM)完成。

– 为外部实体提供所需要事件记录• 事件记录存放于相应的数据库中

Page 39: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

39

TCG Core Service

• Example D.

TCG Software Stack

Page 40: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

40

TCG Core Service

• 参数块生成器

TCG Software Stack

TSS Core Services Interfaces (TCSi)

ParameterBlock Generartor

TCG Device Driver Library

• 所有的命令(如, C类型的数据结构)都要转变为TDD 能理解的字节流

• 对于 TPM响应的字节流要转变为响应的数据结构

• 该生成器与 TCS 内部的各个模块进行交互

Page 41: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

41

TCG Core Service

• TCS 体系结构

TCG Software Stack

TSS Core Services Interfaces (TCSi)

TCS Context ManagerKey & CredentialManager

Event Manager (Event Log)

OS

TSS runtime

BIOS

ParameterBlock Generator

Key Cache ManagerPersistent

Storage (S)

TCG Device Driver Library资源管理

事件管理

接口管理

Page 42: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

42

• Introduction• TPM Internals• TPM Device Driver (TDD)• TCG Device Driver Library (TDDL)• TCG Core Services (TCS)• TCG Service Provider (TSP)

– Introduction– Working Objects– Programme with TSPi– Some Applications

TCG Software Stack

Overview

Page 43: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

43

TCG Service Provider

• Introduction– 所提供的服务

• 完整性收集和报告服务• 保护存储服务• 加密、解密服务• 证书服务

– 不仅提供对 TPM 的访问 ( 经由 TCS) ,也包括额外的功能,比如签名校验、哈希等

– 可以访问远程的 TCS ,经由 RPC 或者用标准的 SOAP消息

– 永久的用户存储,与 TCS类似,但是它针对的是每个用户,提供了隔离机制

– 提供了标准的 C语言接口 (TSPi) 及公共的库函数TCG Software Stack

Page 44: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

44

TCG Service Provider

• Introduction– TCG Service Provider Interface

• 是一种面向对象的 API 接口,每一条 API 都与对象关联• TSPI 定义的类

– 上下文类– 策略类– TPM类– 密钥类– 加密数据类 ( 密封或绑定的数据 )

– PCR类– NVRAM 类– HASH类

• 每一个 Tspi_XXX_(API) 都按此命名,以便程序员知道正在操作的是哪种类型的对象

TCG Software Stack

Page 45: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

45

TCG Service Provider

• Working Objects– 上下文对象

• 在概念上类似于进程上下文• 提供管理资源和释放内存的功能• 连接到本地或者远程的 TCS

• 创建工作对象• 为工作中的对象建立默认策略 ,比如

为代表 TPM 所有者的 TPM 对象建立策略对象

• 提供访问永久性存储器数据库的功能

TCG Software Stack

Page 46: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

46

TCG Service Provider

• Working Objects– 与上下文相关的 API

• Tspi_Context_Create( &hContext);

• // 生成了一个上下文对象,创建了一个默认策略• Tspi_Context_Connect( hContext, Destination)

• //上下文连接到 TCS ,并产生一个上下文句柄,若 Destination 为空则连接到本地 TCS ;并隐式地创建一个 TPM 对象,并与上下文关联

• Tspi_Context_CreateObject( hContext, TSS_Object_Type, Flags, hObject)

• // 在上下文中创建一个新的对象,除了 TPM 对象,其余的对象都由此函数创建

TCG Software Stack

Page 47: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

47

TCG Service Provider

• Working Objects– 策略对象

• 三种策略类型:– 使用策略– 迁移策略– 操作策略

• 保存命令所需要用到的授权数据– 装载密钥– 迁移密钥– 加密 / 解密数据– 获取 TPM 所有权– 获得和设置 TPM敏感属性时

TCG Software Stack

Page 48: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

48

TCG Service Provider

• Working Objects– 与策略对象相关的 API

• Tspi_Policy_Setsecret( hPolicy, TSS_Secret_Mode, secret)

• // 为该策略设置秘密模式及秘密值,对于每个需要唯一口令的对象,必须创建一个新的策略,然后关联给该对象

• Tspi_Policy_AssignToObject( hPolicy, hObject);

• //将该策略关联到一个对象或多个对象

TCG Software Stack

Page 49: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

49

TCG Service Provider

• Working Objects– TPM 对象

• 当 TSP上下文连接到 TCS 时会隐式地生成一个 TPM 对象,并为其分配一个既定的策略,该策略处理 TPM Owner 的授权数据

• 提供了对证书的访问• TPM 对象的 API 接口提供了几类操

作– 身份认证管理– 获取 \ 设置 TPM状态– TPM测试– 获取 TPM 功能– 获取随机数– PCR事件

TCG Software Stack

Page 50: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

50

TCG Service Provider

• Working Objects– Key 对象

• 用来表示 TPM 密钥 (RSA 密钥对 )

• 有 7种不同的密钥类型– SRK

– AIK 密钥– 存储 (Store) 密钥– 签名 (Sign) 密钥– 绑定 (Bind) 密钥– 密封 (Seal) 密钥– 派生 (Leavcy) 密钥

• 在用户永久存储区保存密钥

TCG Software Stack

Page 51: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

51

TCG Service Provider

• Working Objects– 与 Key 对象相关的 API

• Tspi_Key_Loadkey( hKey, hUnwrappingKey )• // 加载密钥 key 到 TPM 中,需用父密钥对其解密• Tspi_Key_CreateKey( hKey, hWrappingKey, hPcrComposite)• // 创建密钥 key ,并用父密钥对其私钥部分加密,若使用 PCR

值则需指明用到哪几个 PCR 合成对象• Tspi_Key_WrapKey( hKey, hWrappingKey, hPcrComposite)

• // 与 Tspi_Key_CreateKey 功能一样,但不创建密钥

TCG Software Stack

Page 52: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

52

TCG Service Provider

• Working Objects– PCR 合成对象

• 代表了一批散列值及其合成的摘要值

• 提供了对 PCR 值选择 (Select) 、读 (Get) 、写 (Set) 和扩展 (Extend) 等操作

TCG Software Stack

Page 53: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

53

TCG Service Provider

• Working Objects– 与 PCR 合成对象相关的 API

• Tspi_PcrComposite_GetPcrValue( hPcrComposite, PcrIndex, ulPcrValueLength, rgbPcrValue)

• //从 PCR 合成对象中获取相应索引的 PCR 值• Tspi_PcrComposite_SetPcrValue( hPcrComposite, PcrIndex, ulPc

rValueLength, rgbPcrValue)

• // 设置指定的 PCR 值到 PCR 对象中• Tspi_PcrComposite_SelectPcrIndex(hPcrComposite,PcrIndex)

• //选择要使用哪一个 PCR 值,并记录在 PCR 合成对象中

TCG Software Stack

Page 54: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

54

TCG Service Provider

• Working Objects– 与 PCR 合成对象相关的 API

• Tspi_TPM_PcrRead( hTPM, PcrIndex, PcrValueLength, PcrValue)

• //读取 TPM 中的 PCR 值• Tspi_TPM_PcrExtend( hTPM, PcrIndex, DigestValue, PcrValueLe

ngth, PcrValue)

• // 对 PCR 值进行扩展, TCS记录下扩展事件,并返回扩展后的 PCR 值。 PCRnew = SHA-1( PCRold || Measure )

TCG Software Stack

Page 55: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

55

TCG Service Provider

• Working Objects– 散列对象

• TSS 仅支持 SHA-1 算法,若使用其他散列算法,则需一个支持所需算法的外部库

• 支持对 hash 值的签名及校验操作

TCG Software Stack

Page 56: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

56

TCG Service Provider

• Working Objects– 与散列对象相关的 API

• Tspi_Hash_UpdateHashValue( hHash,strlen(data),data);

• // 对 data 进行 SHA-1 操作• Tspi_Hash_GetHashValue( hHash, &digestlen,&digest)

• // 获取 HASH 对象的散列值

TCG Software Stack

Page 57: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

57

TCG Service Provider

• Working Objects– 对象之间的关系

TCG Software Stack

需授权对象

无授权对象

Page 58: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

58

TCG Service Provider

• Programme with TSPi– Example D.

• D-1. PCR 值的读取– (1) 创建上下文并连接到本地 TCS ;– Tspi_Context_Create(&hContext); Tspi_Conte

xt_Connect(hContext, 0); – (2) 获取 TPM 对象;– Tspi_Context_GetTpmObject(hContext,&hTPM);– (3)读取 TPM 对象的 PCR 值;– Tspi_TPM_PcrRead(hTPM,i,&pulPcrValueLength,&p

rgbPcrValue)

TCG Software Stack

Page 59: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

59

TCG Service Provider

• Programme with TSPi– Example D.

• D-2. PCR 值的扩展– (1) 创建上下文并连接到本地 TCS ;– Tspi_Context_Create(&hContext); Tspi_Conte

xt_Connect(hContext, 0); – (2) 获取 TPM 对象;– Tspi_Context_GetTpmObject(hContext,&hTPM);– (3)扩展 TPM 对象的 PCR 值,通过 TCS扩展到真正 TPM 的 PCR 值;– Tspi_TPM_PcrExtend(hTPM, i, ulPcrDataLength, pb

PcrData, pPcrEvent, &pulPcrValueLength,&prgbPcrValue)

TCG Software Stack

Page 60: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

60

TCG Service Provider

• Programme with TSPi– Example D.

• D-3. PCR 合成对象的设置– (1) 创建上下文并连接到本地 TCS ;– Tspi_Context_Create(&hContext); Tspi_Context_Co

nnect(hContext, 0); – (2) 创建 PCR 合成对象;– Tspi_Context_CreateObject(hContext,TSS_OBJECT_TYP

E_PCR , TSS_PCRS_STRUCT_INFO_LONG, &hPcrs)

– (3)选择所要设置的 PCR ;– Tspi_PcrComposite_SelectPcrIndex(hPcrs,ulPcrIndex)– (4) 对所选择的 PCR 进行设值;– Tspi_PcrComposite_SetPcrValue(hPcrs,ulPcrIndex,

sizeof(digestValues), digestValues)

TCG Software Stack

Page 61: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

61

TCG Service Provider

• Programme with TSPi– Example E.

• SHA-1散列函数的使用– (1) 创建上下文并连接到本地 TCS ;– Tspi_Context_Create(&hContext); Tspi_Con

text_Connect(hContext, 0);– (2) 创建 HASH 对象;– Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HA

SH, TSS_HASH_SHA1, &hHash)– (3)将数据进行 HASH– Tspi_Hash_UpdateHashValue(hHash,strlen(data),data);– (4) 取回 HASH 对象的散列值– Tspi_Hash_GetHashValue(hHash, &digestlen,&digest)

• SHA-1签名及校验 ( 在签名密钥生成并注册之后 )

TCG Software Stack

Page 62: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

62

TCG Service Provider

• Programme with TSPi– Example F.

• F-1(i). 密钥生成并注册– (1) 创建上下文并连接到本地 TCS ;– Tspi_Context_Create(&hContext); Tspi_Con

text_Connect(hContext, 0);– (2) 创建密钥对象,并设值相应的密钥属性– Tspi_Context_CreateObject(hContext,TSS_OBJECT_TYPE_RSA

KEY, FLAGS, &hKey);– (3) 创建策略对象,属性为使用策略– Tspi_Context_CreateObject(hContext,TSS_OBJECT_TYPE_POLI

CY,TSS_POLICY_USAGE, &hKeyPolicy);– (4) 为策略设置秘密值,也就是授权数据– Tspi_Policy_SetSecret(hKeyPolicy,TSS_SECRET_MODE_PLAIN,

strlen(secret), secret)

TCG Software Stack

Page 63: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

63

TCG Service Provider

• Programme with TSPi– Example F.

• F-1(ii). 密钥生成并注册– (5)将该策略关联到密钥对象– Tspi_Policy_AssignToObject(hKeyPolicy,hKey)– (6) 加载一个存储密钥,作为其父密钥,此时需要该密钥的授权数据– Tspi_Context_LoadKeyByUUID(hContext,TSS_PS_TYPE_SYSTE

M,SRK_UUID,&hSRK)– (7) 创建新的密钥– Tspi_Key_CreateKey(hKey,hSRK, 0)– (8)将新创建的密钥注册,并用 UUID唯一标识– Tspi_Context_RegisterKey(hContext, hKey, TSS_PS_TYPE_US

ER,user_storage_UUID, TSS_PS_TYPE_SYSTEM, SRK_UUID)

TCG Software Stack

Page 64: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

64

TCG Service Provider

• Programme with TSPi– Example F.

• F-2(i). 加载并使用密钥– (1) 创建上下文并连接到本地 TCS ;– Tspi_Context_Create(&hContext); Tspi_Conte

xt_Connect(hContext, 0);– (2) 创建策略对象– Tspi_Context_CreateObject(hContext,TSS_OBJECT_TYPE_POLIC

Y,TSS_POLICY_USAGE, &hKeyPolicy)– (3) 为策略对象设置要加载密钥的授权数据– Tspi_Policy_SetSecret(hKeyPolicy,TSS_SECRET_MODE_PLAIN, st

rlen(secret), secret)– (4) 加载该密钥的父密钥, Tspi_Context_GetRegisteredKeysByUUID– Tspi_Context_LoadKeyByUUID(hContext,TSS_PS_TYPE_SYSTEM,

SRK_UUID,&hSRK)

TCG Software Stack

Page 65: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

65

TCG Service Provider

• Programme with TSPi– Example F.

• F-2(ii). 加载并使用密钥– (5) 通过密钥的 UUID 获取该密钥对象– Tspi_Context_LoadKeyByUUID(hContext,TSS_PS_TYPE_USER,

user_storage_UUID,&hKey)– (6)将第 (2)&(3) 步创建的策略关联到该密钥对象– Tspi_Policy_AssignToObject(hKeyPolicy,hKey)– (7) 使用该密钥

TCG Software Stack

Page 66: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

66

TCG Service Provider

• Programme with TSPi– Example G.

• Seal 操作 (条件密码操作 )

• 将密钥操作和平台配置信息 (PCR) 进行绑定,将数据加密绑定到用户指定的 PCR 。

• KPUB-S{VPCR-x , K}, K 是用于加密消息的对称密钥,只有当当前的平台配置信息符合 VPCR-x 时,解密出 K ,对加密的密文进行解密。

TCG Software Stack

Page 67: 1 Trusted Computing TSS - TCG Software Stack TCG Software Stack 2010-04-28

TPM 模拟环境的搭建

• 准备工作:– 1. Linux 操作系统,内核版本在 2.6.30 以上– 2. Tpm_emulator 软件– 3. TSS 软件栈

• 以上软件安装完毕后,执行以下操作– 1.开启 Tpm_emulator– 2.开启 TSS 软件栈