TPM命令解析之tpm2_startauthsession
参考网址链接:tpm2-tools/tpm2_startauthsession.1.md at master · tpm2-software/tpm2-tools · GitHub
命令名称
tpm2_startauthsession
功能
启动一个TPM会话。
命令形式
tpm2_startauthsession [OPTIONS]
描述
启动一个TPM会话。默认是启动一个试验(trial)会话,除非-a选项被指定。保存策略绘画的数据到一个文件中。该文件可在随后的工具中被使用,此工具可以将策略文件用于授权或策略事件。
这并不适用于在tpm2-abrmd之外的资源管理器(RMs),因为绝大多数RMs当一个客户端从IPC通道断开断开时将会刷新会话句柄。然而,当使用一个没有会话间隔功能的RM时,可以使用TCTI命令以保持连接打开。
第一步是使用tpm2_send命令创建一个套接字监听器:
mknod "$HOME/backpipe" p
while [ 1 ]; do tpm2_send 0<"$HOME/backpipe" | nc -lU "$HOME/sock" 1>"$HOME/backpipe"; done;
下一步是使用TCTI命令和netcat(nc)命令来发送数据到套接字:
tpm2_startauthsession --tcti="cmd:nc -q 0 -U $HOME/sock" <options>
当完成时,确保杀掉监听器。对于针对侦听器的使用命令tcti执行的命令,将需要管理临时句柄。最简单的方法是在每个命令之后添加一个刷新:
tpm2_flushcontext --tcti="cmd:nc -q 0 -U $HOME/sock" -t
注意:此例使用UNIX套接字,因为套接字受控于Linux访问控制。不推荐使用端口因为它开放给系统中的任何用户(本地)或者绑定到网卡并暴露给网络。
对于直接TPM访问这将正常工作,但注意在内部其在会话句柄之上调用了ContextSave和ContextLoad,因此会话不能被再次保存/加载。
选项
-
--policy-session:
Start a policy session of type TPM_SE_POLICY. Default without this option is TPM_SE_TRIAL.
NOTE: A trial session is used when building a policy and a policy session is used when authenticating with a policy.
-
--audit-session:
Start an HMAC session to be used as an audit session. Default without this option is TPM2_SE_TRIAL.
-
--hmac-session:
Start an HMAC session of type TPM_SE_HMAC. Default without this option is TPM2_SE_TRIAL.
-
-g, --hash-algorithm=ALGORITHM:
The hash algorithm used in computation of the policy digest.
-
-G, --key-algorithm=ALGORITHM:
The symmetric algorithm used in parameter encryption/decryption.
-
-c, --key-context=OBJECT:
Set the tpmkey and bind objects to be the same. Session parameter encryption is turned on. Session parameter decryption is turned on. Parameter encryption/decryption symmetric-key set to AES-CFB.
-
-S, --session=FILE:
The name of the policy session file, required.
-
--bind-context=FILE:
Set the bind object. Session parameter encryption is off. Use tpm2_sessionconfig to turn on. Session parameter decryption is off. Use tpm2_sessionconfig to turn on. Parameter encryption/decryption symmetric-key set to AES-CFB.
-
--bind-auth=AUTH:
Set the authorization value for the bind object.
-
--tpmkey-context=FILE:
Set the tpmkey object. Session parameter encryption is off. Use tpm2_sessionconfig to turn on. Session parameter decryption is off. Use tpm2_sessionconfig to turn on. Parameter encryption/decryption symmetric-key set to AES-CFB.
-
-n, --name=FILE
A name file as output from a tool like tpm2_readpublic(1)
-n
option. The name file can be used to verify a persistent handle input for the--tpmkey-context
,-c
, and--key-context
options. Verification that the object referenced by a peristent handle, e.g 0x81000000, is the key expected prevents attackers from performing a man-in-the-middle attack on session traffic.
举例
- 启动一个试验会话并且保存会话数据到一个文件中
tpm2_startauthsession -S mysession.ctx
- 启动一个策略会话并且保存会话数据到一个文件中
tpm2_startauthsession --policy-session -S mysession.ctx
- 启动一个加密和绑定策略会话并且保存会话数据到一个文件中
tpm2_createprimary -c primary.ctx
tpm2_startauthsession --policy-session -c primary.ctx -S mysession.ctx
返回值
工具(不只是本命令)可以返回以下代码的任意一个:
- 0 - 成功;
- 1 - 一般非特定错误;
- 2 - 选项处理错误;
- 3 - 身份验证错误;
- 4 - TCTI相关错误;
- 5 - 不支持的方案。适用于tpm2_testparams。