tpm2-util,analyze: add helper for generating hwdb lookup key from TPM2 vendor data
Our goal is to find TPM2 metadata in hwdb, hence let's compile a "modalias"-style string from the TPM2 metadata, we can use as hwdb lookup key.
This commit is contained in:
@@ -1047,7 +1047,8 @@ default ignore - -</programlisting>
|
||||
Specification Date: Mon 2023-01-09
|
||||
Manufacturer: STM
|
||||
Vendor String: ST33KTPM2XSPI
|
||||
Firmware Version: 9.258</programlisting>
|
||||
Firmware Version: 9.258
|
||||
Modalias String: fi2.0:lv0:rv1.59:sy2023:sd9:mfSTM:vsST33KTPM2XSPI:ty0:fw9.258.0:</programlisting>
|
||||
</example>
|
||||
|
||||
<xi:include href="version-info.xml" xpointer="v260"/>
|
||||
|
||||
@@ -120,6 +120,17 @@ int verb_identify_tpm2(int argc, char **argv, void *userdata) {
|
||||
if (r < 0)
|
||||
return table_log_add_error(r);
|
||||
|
||||
_cleanup_free_ char *m = NULL;
|
||||
if (tpm2_vendor_info_to_modalias(&info, &m) < 0)
|
||||
return log_oom();
|
||||
|
||||
r = table_add_many(
|
||||
table,
|
||||
TABLE_FIELD, "Modalias String",
|
||||
TABLE_STRING, m);
|
||||
if (r < 0)
|
||||
return table_log_add_error(r);
|
||||
|
||||
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, /* show_header= */ false);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -349,6 +349,43 @@ static int tpm2_get_capability(
|
||||
return more == TPM2_YES;
|
||||
}
|
||||
|
||||
int tpm2_vendor_info_to_modalias(const Tpm2VendorInfo *info, char **ret) {
|
||||
_cleanup_free_ char *m = NULL;
|
||||
|
||||
assert(info);
|
||||
assert(ret);
|
||||
|
||||
/* Closely inspired by kernel modalias strings, this distills information from the TPM vendor data
|
||||
* into a string suitable for matching hwdb */
|
||||
|
||||
if (asprintf(&m,
|
||||
"fi%s:"
|
||||
"lv%" PRIu32 ":"
|
||||
"rv%" PRIu32 ".%" PRIu32 ":"
|
||||
"sy%" PRIu32 ":"
|
||||
"sd%" PRIu32 ":"
|
||||
"mf%s:"
|
||||
"vs%s:"
|
||||
"ty%" PRIx32 ":"
|
||||
"fw%" PRIu16 ".%" PRIu16 ".%" PRIu32 ":",
|
||||
info->family_indicator,
|
||||
info->level,
|
||||
info->revision_major,
|
||||
info->revision_minor,
|
||||
info->year,
|
||||
info->day_of_year,
|
||||
info->manufacturer,
|
||||
info->vendor_string,
|
||||
info->vendor_tpm_type,
|
||||
info->firmware_version_major,
|
||||
info->firmware_version_minor,
|
||||
info->firmware_version2) < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = TAKE_PTR(m);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *mangle_vendor_chars(char *c, size_t n) {
|
||||
char *end = c;
|
||||
assert(c || n == 0);
|
||||
|
||||
@@ -210,6 +210,7 @@ typedef struct Tpm2VendorInfo {
|
||||
char vendor_string[4*4+1];
|
||||
} Tpm2VendorInfo;
|
||||
|
||||
int tpm2_vendor_info_to_modalias(const Tpm2VendorInfo *info, char **ret);
|
||||
int tpm2_get_vendor_info(Tpm2Context *c, Tpm2VendorInfo *ret);
|
||||
|
||||
void tpm2_log_debug_tpml_pcr_selection(const TPML_PCR_SELECTION *l, const char *msg);
|
||||
|
||||
Reference in New Issue
Block a user