Skip to content

Commit 7526f82

Browse files
committed
tpm2_getcap: Add capability to print PCR handles in the authorization set
Signed-off-by: Imran Desai <imran.desai@intel.com>
1 parent b7e1d2f commit 7526f82

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

lib/pcr.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,25 @@ bool pcr_print_pcr_struct(TPML_PCR_SELECTION *pcr_select, tpm2_pcrs *pcrs) {
426426
return pcr_print_values(pcr_select, pcrs);
427427
}
428428

429+
void pcr_print_taggedpcr_selections(TPML_TAGGED_PCR_PROPERTY *pcrProperties) {
430+
431+
tpm2_tool_output(" - PCR-Handles: [");
432+
/* Iterate through the PCRs of the bank */
433+
bool first = true;
434+
unsigned j;
435+
for (j = 0; j < pcrProperties->pcrProperty->sizeofSelect * 8; j++) {
436+
if ((pcrProperties->pcrProperty->pcrSelect[j / 8] & 1 << (j % 8)) != 0) {
437+
if (first) {
438+
tpm2_tool_output(" %i", j);
439+
first = false;
440+
} else {
441+
tpm2_tool_output(", %i", j);
442+
}
443+
}
444+
}
445+
tpm2_tool_output(" ]\n");
446+
}
447+
429448
bool pcr_print_pcr_selections(TPML_PCR_SELECTION *pcr_selections) {
430449
tpm2_tool_output("selected-pcrs:\n");
431450

lib/pcr.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ typedef struct tpm2_forwards {
4444
*/
4545
bool pcr_print_pcr_struct(TPML_PCR_SELECTION *pcrSelect, tpm2_pcrs *pcrs);
4646

47+
/**
48+
* Echo out all the PCR indices that satisy a PCR property
49+
* @param pcrProperties
50+
* Description of the selected pcr properties
51+
* @return
52+
* None
53+
*/
54+
void pcr_print_taggedpcr_selections(TPML_TAGGED_PCR_PROPERTY *pcrProperties);
55+
4756
/**
4857
* Echo out all PCR banks according to g_pcrSelection & g_pcrs->.
4958
* Assume that data structures are all little endian.

man/tpm2_getcap.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ argument to the tool. Currently supported capability groups are:
5353
- **handles-saved-session**:
5454
Display handles about saved sessions.
5555

56+
- **pcrhandles-with-auth**:
57+
Display PCR handles that are in the authorization set.
58+
5659
- **vendor[:num]**:
5760
Displays the vendor properties as a hex buffer output. The string "vendor"
5861
can be suffixed with a colon followed by a number as understood by strtoul(3)

tools/tpm2_getcap.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ capability_map_entry_t capability_map[] = {
123123
.property = TPM2_ACTIVE_SESSION_FIRST,
124124
.count = TPM2_MAX_CAP_HANDLES,
125125
},
126+
{
127+
.capability_string = "pcrhandles-with-auth",
128+
.capability = TPM2_CAP_PCR_PROPERTIES,
129+
.property = TPM2_PT_PCR_AUTH,
130+
.count = TPM2_MAX_PCR_PROPERTIES,
131+
},
126132
#if defined(ESYS_4_0)
127133
{
128134
.capability_string = "vendor",
@@ -812,6 +818,12 @@ static bool dump_tpm_capability(TPMU_CAPABILITIES *capabilities) {
812818
case TPM2_CAP_PCRS:
813819
pcr_print_pcr_selections(&capabilities->assignedPCR);
814820
break;
821+
case TPM2_CAP_PCR_PROPERTIES:
822+
if(options.property == TPM2_PT_PCR_AUTH) {
823+
tpm2_tool_output("TPM2_PT_PCR_AUTH:\n");
824+
pcr_print_taggedpcr_selections(&capabilities->pcrProperties);
825+
}
826+
break;
815827
#if defined(ESYS_4_0)
816828
case TPM2_CAP_VENDOR_PROPERTY: {
817829

0 commit comments

Comments
 (0)