Showing with 96 additions and 1 deletion.
  1. +21 −0 man/tpm2_dump_capability.1.md
  2. +75 −1 tools/tpm2_dump_capability.c
21 changes: 21 additions & 0 deletions man/tpm2_dump_capability.1.md
Expand Up @@ -37,6 +37,27 @@ command.
* ecc-curves:
Display data about elliptic curves.

* handles-transient:
Display handles about transient objects.

* handles-persistent:
Display handles about persistent objects.

* handles-permanent:
Display handles about permanent objects.

* handles-pcr:
Display handles about PCRs.

* handles-nv-index:
Display handles about NV Indices.

* handles-hmac-session:
Display handles about HMAC sessions.

* handles-policy-session:
Display handles about policy sessions.

[common options](common/options.md)

[common tcti options](common/tcti.md)
Expand Down
76 changes: 75 additions & 1 deletion tools/tpm2_dump_capability.c
Expand Up @@ -59,7 +59,7 @@ capability_map_entry_t capability_map[] = {
.capability_string = "algorithms",
.capability = TPM_CAP_ALGS,
.property = TPM_ALG_FIRST,
.count = MAX_ALG_LIST_SIZE,
.count = MAX_CAP_ALGS,
},
{
.capability_string = "commands",
Expand All @@ -85,6 +85,48 @@ capability_map_entry_t capability_map[] = {
.property = TPM_ECC_NIST_P192,
.count = MAX_ECC_CURVES,
},
{
.capability_string = "handles-transient",
.capability = TPM_CAP_HANDLES,
.property = TRANSIENT_FIRST,
.count = MAX_CAP_HANDLES,
},
{
.capability_string = "handles-persistent",
.capability = TPM_CAP_HANDLES,
.property = PERSISTENT_FIRST,
.count = MAX_CAP_HANDLES,
},
{
.capability_string = "handles-permanent",
.capability = TPM_CAP_HANDLES,
.property = PERMANENT_FIRST,
.count = MAX_CAP_HANDLES,
},
{
.capability_string = "handles-pcr",
.capability = TPM_CAP_HANDLES,
.property = PCR_FIRST,
.count = MAX_CAP_HANDLES,
},
{
.capability_string = "handles-nv-index",
.capability = TPM_CAP_HANDLES,
.property = NV_INDEX_FIRST,
.count = MAX_CAP_HANDLES,
},
{
.capability_string = "handles-hmac-session",
.capability = TPM_CAP_HANDLES,
.property = HMAC_SESSION_FIRST,
.count = MAX_CAP_HANDLES,
},
{
.capability_string = "handles-policy-session",
.capability = TPM_CAP_HANDLES,
.property = POLICY_SESSION_FIRST,
.count = MAX_CAP_HANDLES,
},
};
/*
* Structure to hold options for this tool.
Expand Down Expand Up @@ -685,6 +727,19 @@ dump_command_attr_array (TPMA_CC command_attributes[],
for (i = 0; i < count; ++i)
dump_command_attrs (command_attributes [i]);
}
/*
* Iterate over an array of TPML_HANDLEs and dump out the handle
* values.
*/
void
dump_handles (TPM_HANDLE handles[],
UINT32 count)
{
UINT32 i;

for (i = 0; i < count; ++i)
tpm2_tool_output ("0x%08x\n", handles[i]);
}
/*
* Query the TPM for TPM capabilities.
*/
Expand All @@ -705,6 +760,9 @@ get_tpm_capability_all (TSS2_SYS_CONTEXT *sapi_ctx,
if (rc != TSS2_RC_SUCCESS) {
LOG_ERR("Failed to GetCapability: capability: 0x%x, property: 0x%x, "
"TSS2_RC: 0x%x\n", options.capability, options.property, rc);
} else if (more_data == YES) {
LOG_WARN("More data to be queried: capability: 0x%x, property: "
"0x%x\n", options.capability, options.property);
}

return rc;
Expand Down Expand Up @@ -747,6 +805,22 @@ static int dump_tpm_capability (TPMU_CAPABILITIES *capabilities) {
dump_ecc_curves (capabilities->eccCurves.eccCurves,
capabilities->eccCurves.count);
break;
case TPM_CAP_HANDLES:
switch (options.property & HR_RANGE_MASK) {
case HR_TRANSIENT:
case HR_PERSISTENT:
case HR_PERMANENT:
case HR_PCR:
case HR_NV_INDEX:
case HR_HMAC_SESSION:
case HR_POLICY_SESSION:
dump_handles (capabilities->handles.handle,
capabilities->handles.count);
break;
default:
return 1;
}
break;
default:
return 1;
}
Expand Down