Skip to content

Commit 0ae8cee

Browse files
committed
tpm2_pcrsetauthvalue: Add new tool to implement TPM2_CC_PCRSetAuthValue
Fixes #3333 Signed-off-by: Imran Desai <imran.desai@intel.com>
1 parent 7526f82 commit 0ae8cee

File tree

6 files changed

+402
-1
lines changed

6 files changed

+402
-1
lines changed

Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ tpm2_tools = \
203203
tools/tpm2_ecdhzgen.c \
204204
tools/tpm2_zgen2phase.c \
205205
tools/tpm2_sessionconfig.c \
206-
tools/tpm2_getpolicydigest.c
206+
tools/tpm2_getpolicydigest.c \
207+
tools/tpm2_pcrsetauthvalue.c
207208

208209
# Create the symlinks for each tool to the tpm2 and optional tss2 bundled executables
209210
install-exec-hook:

lib/tpm2.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5842,6 +5842,28 @@ tool_rc tpm2_zgen2phase(ESYS_CONTEXT *esys_context,
58425842
return tool_rc_success;
58435843
}
58445844

5845+
tool_rc tpm2_pcr_setauthvalue(ESYS_CONTEXT *esys_context,
5846+
tpm2_loaded_object *pcrindex_auth_obj, const TPM2B_AUTH *pcrindex_newauth) {
5847+
5848+
ESYS_TR shandle1 = ESYS_TR_NONE;
5849+
tool_rc rc = tpm2_auth_util_get_shandle(esys_context,
5850+
pcrindex_auth_obj->tr_handle, pcrindex_auth_obj->session, &shandle1);
5851+
if (rc != tool_rc_success) {
5852+
LOG_ERR("Failed to get shandle");
5853+
return rc;
5854+
}
5855+
5856+
TSS2_RC rval = Esys_PCR_SetAuthValue(esys_context,
5857+
pcrindex_auth_obj->tr_handle, shandle1, ESYS_TR_NONE, ESYS_TR_NONE,
5858+
pcrindex_newauth);
5859+
if (rval != TPM2_RC_SUCCESS) {
5860+
LOG_PERR(Esys_PCR_SetAuthValue, rval);
5861+
return tool_rc_from_tpm(rval);
5862+
}
5863+
5864+
return rc;
5865+
}
5866+
58455867
tool_rc tpm2_getsapicontext(ESYS_CONTEXT *esys_context,
58465868
TSS2_SYS_CONTEXT **sys_context) {
58475869

lib/tpm2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ tool_rc tpm2_zgen2phase(ESYS_CONTEXT *esys_context,
552552
TPM2B_ECC_POINT *Q2, TPM2B_ECC_POINT **Z1, TPM2B_ECC_POINT **Z2,
553553
TPMI_ECC_KEY_EXCHANGE keyexchange_scheme, UINT16 commit_counter);
554554

555+
tool_rc tpm2_pcr_setauthvalue(ESYS_CONTEXT *esys_context,
556+
tpm2_loaded_object *pcrindex_auth_obj, const TPM2B_AUTH *pcrindex_newauth);
557+
555558
tool_rc tpm2_getsapicontext(ESYS_CONTEXT *esys_context,
556559
TSS2_SYS_CONTEXT **sys_context);
557560

lib/tpm2_util.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,77 @@ ESYS_TR tpm2_tpmi_hierarchy_to_esys_tr(TPMI_RH_PROVISION inh) {
614614
return ESYS_TR_NONE;
615615
}
616616

617+
ESYS_TR tpm2_sys_pcrhandle_to_esys_tr(TPMI_DH_PCR sys_pcrhandle) {
618+
619+
switch (sys_pcrhandle) {
620+
case 0:
621+
return ESYS_TR_PCR0;
622+
case 1:
623+
return ESYS_TR_PCR1;
624+
case 2:
625+
return ESYS_TR_PCR2;
626+
case 3:
627+
return ESYS_TR_PCR3;
628+
case 4:
629+
return ESYS_TR_PCR4;
630+
case 5:
631+
return ESYS_TR_PCR5;
632+
case 6:
633+
return ESYS_TR_PCR6;
634+
case 7:
635+
return ESYS_TR_PCR7;
636+
case 8:
637+
return ESYS_TR_PCR8;
638+
case 9:
639+
return ESYS_TR_PCR9;
640+
case 10:
641+
return ESYS_TR_PCR10;
642+
case 11:
643+
return ESYS_TR_PCR11;
644+
case 12:
645+
return ESYS_TR_PCR12;
646+
case 13:
647+
return ESYS_TR_PCR13;
648+
case 14:
649+
return ESYS_TR_PCR14;
650+
case 15:
651+
return ESYS_TR_PCR15;
652+
case 16:
653+
return ESYS_TR_PCR16;
654+
case 17:
655+
return ESYS_TR_PCR17;
656+
case 18:
657+
return ESYS_TR_PCR18;
658+
case 19:
659+
return ESYS_TR_PCR19;
660+
case 20:
661+
return ESYS_TR_PCR20;
662+
case 21:
663+
return ESYS_TR_PCR21;
664+
case 22:
665+
return ESYS_TR_PCR22;
666+
case 23:
667+
return ESYS_TR_PCR23;
668+
case 24:
669+
return ESYS_TR_PCR24;
670+
case 25:
671+
return ESYS_TR_PCR25;
672+
case 26:
673+
return ESYS_TR_PCR26;
674+
case 27:
675+
return ESYS_TR_PCR27;
676+
case 28:
677+
return ESYS_TR_PCR28;
678+
case 29:
679+
return ESYS_TR_PCR29;
680+
case 30:
681+
return ESYS_TR_PCR30;
682+
case 31:
683+
return ESYS_TR_PCR31;
684+
}
685+
return ESYS_TR_NONE;
686+
}
687+
617688
tool_rc tpm2_util_sys_handle_to_esys_handle(ESYS_CONTEXT *context,
618689
TPM2_HANDLE sys_handle, ESYS_TR *esys_handle) {
619690

@@ -623,6 +694,12 @@ tool_rc tpm2_util_sys_handle_to_esys_handle(ESYS_CONTEXT *context,
623694
return tool_rc_success;
624695
}
625696

697+
h = tpm2_sys_pcrhandle_to_esys_tr(sys_handle);
698+
if (h != ESYS_TR_NONE) {
699+
*esys_handle = h;
700+
return tool_rc_success;
701+
}
702+
626703
return tpm2_from_tpm_public(context, sys_handle, ESYS_TR_NONE, ESYS_TR_NONE,
627704
ESYS_TR_NONE, esys_handle);
628705
}

man/tpm2_pcrsetauthvalue.1.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
% tpm2_pcrsetauthvalue(1) tpm2-tools | General Commands Manual
2+
3+
# NAME
4+
5+
**tpm2_pcrsetauthvalue**(1) - Add or change the authvalue of a PCR handle which
6+
is in the authorization set.
7+
8+
# SYNOPSIS
9+
10+
**tpm2_pcrsetauthvalue** [*OPTIONS*] [*ARGUMENT*]
11+
12+
# DESCRIPTION
13+
14+
**tpm2_pcrsetauthvalue**(1) - Add or change the authvalue of a PCR handle which
15+
is in the authorization set. Only those PCR handles which are in the
16+
authorization set can be specified. To retrieve which specific PCR handles in a
17+
given TPM implementation are in the authorization set, run **tpm2_getcap** with
18+
option **pcrhandles-with-auth**.
19+
20+
# OPTIONS
21+
22+
* **-P**, **\--auth**=_AUTH_:
23+
24+
Specifies the existing authorization value for the PCR handle.
25+
26+
* **-p**, **\--newauth**=_AUTH_:
27+
28+
Specifies the new authorization value to be set for the PCR handle.
29+
30+
* **ARGUMENT** the command line argument specifies the PCR handle.
31+
32+
## References
33+
34+
[context object format](common/ctxobj.md) details the methods for specifying
35+
_OBJECT_.
36+
37+
[authorization formatting](common/authorizations.md) details the methods for
38+
specifying _AUTH_.
39+
40+
[common options](common/options.md) collection of common options that provide
41+
information many users may expect.
42+
43+
[common tcti options](common/tcti.md) collection of options used to configure
44+
the various known TCTI modules.
45+
46+
# EXAMPLES
47+
48+
## Change authvalue of the PCR handle 20
49+
50+
```bash
51+
tpm2_pcrsetauthvalue -p newauthvalue 0x00000014
52+
```
53+
54+
[returns](common/returns.md)
55+
56+
[footer](common/footer.md)

0 commit comments

Comments
 (0)