Skip to content

Commit

Permalink
tpm2: Display RuntimeAttributes as part of TPMLIB_GetInfo
Browse files Browse the repository at this point in the history
Display RuntimeAttributes as part of TPMLIB_GetInfo when the flag
'128' (0x80) is set.

Signed-off-by: Stefan Berger <[email protected]>
  • Loading branch information
stefanberger committed Sep 3, 2024
1 parent 38a2ad9 commit e983cdf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/libtpms/tpm_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ enum TPMLIB_InfoFlags {
TPMLIB_INFO_RUNTIME_COMMANDS = 16,
TPMLIB_INFO_ACTIVE_PROFILE = 32,
TPMLIB_INFO_AVAILABLE_PROFILES = 64,
TPMLIB_INFO_RUNTIME_ATTRIBUTES = 128,
};

char *TPMLIB_GetInfo(enum TPMLIB_InfoFlags flags);
Expand Down
1 change: 1 addition & 0 deletions include/libtpms/tpm_library.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ enum TPMLIB_InfoFlags {
TPMLIB_INFO_RUNTIME_COMMANDS = 16,
TPMLIB_INFO_ACTIVE_PROFILE = 32,
TPMLIB_INFO_AVAILABLE_PROFILES = 64,
TPMLIB_INFO_RUNTIME_ATTRIBUTES = 128,
};

char *TPMLIB_GetInfo(enum TPMLIB_InfoFlags flags);
Expand Down
34 changes: 34 additions & 0 deletions src/tpm_tpm2_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,13 @@ static char *TPM2_GetInfo(enum TPMLIB_InfoFlags flags)
"\"Enabled\":%s,"
"\"Disabled\":%s"
"}";
const char *runtimeAttributes_temp =
"\"RuntimeAttributes\":{"
"\"Implemented\":%s,"
"\"CanBeDisabled\":%s,"
"\"Enabled\":%s,"
"\"Disabled\":%s"
"}";
const char *tpmProfile_temp = "\"ActiveProfile\":%s";
const char *availableProfiles_temp =
"\"AvailableProfiles\":["
Expand All @@ -410,10 +417,13 @@ static char *TPM2_GetInfo(enum TPMLIB_InfoFlags flags)
char camelliakeys[16];
char *runtimeAlgos[RUNTIME_ALGO_NUM] = { NULL, };
char *runtimeCmds[RUNTIME_CMD_NUM] = { NULL, };
char *runtimeAttrs[RUNTIME_ATTR_NUM] = { NULL, };
enum RuntimeAlgorithmType rat;
enum RuntimeCommandType rct;
enum RuntimeAttributeType rabt;
char *runtimeAlgorithms = NULL;
char *runtimeCommands = NULL;
char *runtimeAttributes = NULL;
char *profile = NULL;
const char *profileJSON;
char *availableProfiles = NULL;
Expand Down Expand Up @@ -513,6 +523,27 @@ static char *TPM2_GetInfo(enum TPMLIB_InfoFlags flags)
printed = true;
}

if ((flags & TPMLIB_INFO_RUNTIME_ATTRIBUTES)) {
fmt = buffer;
buffer = NULL;
for (rabt = RUNTIME_ATTR_IMPLEMENTED; rabt < RUNTIME_ATTR_NUM; rabt++) {
runtimeAttrs[rabt] = RuntimeAttributesGet(&g_RuntimeProfile.RuntimeAttributes, rabt);
if (!runtimeAttrs[rabt])
goto error;
}
if (asprintf(&runtimeAttributes, runtimeAttributes_temp,
runtimeAttrs[RUNTIME_ATTR_IMPLEMENTED],
runtimeAttrs[RUNTIME_ATTR_CAN_BE_DISABLED],
runtimeAttrs[RUNTIME_ATTR_ENABLED],
runtimeAttrs[RUNTIME_ATTR_DISABLED]) < 0)
goto error;
if (asprintf(&buffer, fmt, printed ? "," : "",
runtimeAttributes, "%s%s%s") < 0)
goto error;
free(fmt);
printed = true;
}

if ((flags & TPMLIB_INFO_ACTIVE_PROFILE) &&
(profileJSON = RuntimeProfileGetJSON(&g_RuntimeProfile))) {
fmt = buffer;
Expand Down Expand Up @@ -576,8 +607,11 @@ static char *TPM2_GetInfo(enum TPMLIB_InfoFlags flags)
free(runtimeAlgos[rat]);
for (rct = RUNTIME_CMD_IMPLEMENTED; rct < RUNTIME_CMD_NUM; rct++)
free(runtimeCmds[rct]);
for (rabt = RUNTIME_ATTR_IMPLEMENTED; rabt < RUNTIME_ATTR_NUM; rabt++)
free(runtimeAttrs[rabt]);
free(runtimeAlgorithms);
free(runtimeCommands);
free(runtimeAttributes);
free(availableProfiles);
free(tmp);

Expand Down

0 comments on commit e983cdf

Please sign in to comment.