diff --git a/src/detection/tpm/tpm.h b/src/detection/tpm/tpm.h index d8bc72b54..2310a23bf 100644 --- a/src/detection/tpm/tpm.h +++ b/src/detection/tpm/tpm.h @@ -5,7 +5,7 @@ typedef struct FFTPMResult { FFstrbuf version; - FFstrbuf interfaceType; + FFstrbuf description; } FFTPMResult; const char* ffDetectTPM(FFTPMResult* result); diff --git a/src/detection/tpm/tpm_linux.c b/src/detection/tpm/tpm_linux.c index 14e8be369..2547339c6 100644 --- a/src/detection/tpm/tpm_linux.c +++ b/src/detection/tpm/tpm_linux.c @@ -1,22 +1,24 @@ #include "tpm.h" #include "common/io/io.h" -const char* ffDetectTPM(FF_MAYBE_UNUSED FFTPMResult* result) +const char* ffDetectTPM(FFTPMResult* result) { + if (!ffPathExists("/sys/class/tpm/tpm0", FF_PATHTYPE_DIRECTORY)) + { + if (!ffPathExists("/sys/class/tpm", FF_PATHTYPE_DIRECTORY)) + return "TPM is not supported by kernel"; + return "TPM device is not found"; + } + if (ffReadFileBuffer("/sys/class/tpm/tpm0/tpm_version_major", &result->version)) { ffStrbufTrimRightSpace(&result->version); if (ffStrbufEqualS(&result->version, "2")) ffStrbufSetStatic(&result->version, "2.0"); - - return NULL; } - if (ffPathExists("/sys/class/tpm/tpm0", FF_PATHTYPE_DIRECTORY)) - { - ffStrbufSetStatic(&result->version, "unknown"); - return NULL; - } + if (ffReadFileBuffer("/sys/class/tpm/tpm0/device/description", &result->description)) + ffStrbufTrimRightSpace(&result->description); - return "TPM device is not found"; + return NULL; } diff --git a/src/detection/tpm/tpm_windows.c b/src/detection/tpm/tpm_windows.c index 2837822d8..a63a93f5f 100644 --- a/src/detection/tpm/tpm_windows.c +++ b/src/detection/tpm/tpm_windows.c @@ -60,19 +60,19 @@ const char* ffDetectTPM(FFTPMResult* result) switch (deviceInfo.tpmInterfaceType) { case TPM_IFTYPE_1: - ffStrbufSetStatic(&result->interfaceType, "I/O-port or MMIO"); + ffStrbufSetF(&result->description, "I/O-port or MMIO TPM %s", result->version.chars); break; case TPM_IFTYPE_TRUSTZONE: - ffStrbufSetStatic(&result->interfaceType, "Trustzone"); + ffStrbufSetF(&result->description, "Trustzone TPM %s", result->version.chars); break; case TPM_IFTYPE_HW: - ffStrbufSetStatic(&result->interfaceType, "HW TPM"); + ffStrbufSetF(&result->description, "HW TPM %s", result->version.chars); break; case TPM_IFTYPE_EMULATOR: - ffStrbufSetStatic(&result->interfaceType, "SW-emulator"); + ffStrbufSetF(&result->description, "SW-emulator TPM %s", result->version.chars); break; case TPM_IFTYPE_SPB: - ffStrbufSetStatic(&result->interfaceType, "SPB attached"); + ffStrbufSetF(&result->description, "SPB attached TPM %s", result->version.chars); break; default: break; diff --git a/src/modules/tpm/tpm.c b/src/modules/tpm/tpm.c index f9b7a1e5d..3934fb4ce 100644 --- a/src/modules/tpm/tpm.c +++ b/src/modules/tpm/tpm.c @@ -10,7 +10,7 @@ void ffPrintTPM(FFTPMOptions* options) { FFTPMResult result = { .version = ffStrbufCreate(), - .interfaceType = ffStrbufCreate() + .description = ffStrbufCreate() }; const char* error = ffDetectTPM(&result); @@ -23,18 +23,21 @@ void ffPrintTPM(FFTPMOptions* options) if(options->moduleArgs.outputFormat.length == 0) { ffPrintLogoAndKey(FF_TPM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); - ffStrbufPutTo(&result.version, stdout); + if (result.description.length > 0) + ffStrbufPutTo(&result.description, stdout); + else + ffStrbufPutTo(&result.version, stdout); } else { FF_PRINT_FORMAT_CHECKED(FF_TPM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_TPM_NUM_FORMAT_ARGS, ((FFformatarg[]){ FF_FORMAT_ARG(result.version, "version"), - FF_FORMAT_ARG(result.interfaceType, "interface-type"), + FF_FORMAT_ARG(result.description, "description"), })); } ffStrbufDestroy(&result.version); - ffStrbufDestroy(&result.interfaceType); + ffStrbufDestroy(&result.description); } bool ffParseTPMCommandOptions(FFTPMOptions* options, const char* key, const char* value) @@ -76,7 +79,7 @@ void ffGenerateTPMJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_ { FFTPMResult result = { .version = ffStrbufCreate(), - .interfaceType = ffStrbufCreate() + .description = ffStrbufCreate() }; const char* error = ffDetectTPM(&result); @@ -88,17 +91,17 @@ void ffGenerateTPMJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_ yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); yyjson_mut_obj_add_strbuf(doc, obj, "version", &result.version); - yyjson_mut_obj_add_strbuf(doc, obj, "interfaceType", &result.interfaceType); + yyjson_mut_obj_add_strbuf(doc, obj, "description", &result.description); ffStrbufDestroy(&result.version); - ffStrbufDestroy(&result.interfaceType); + ffStrbufDestroy(&result.description); } void ffPrintTPMHelpFormat(void) { - FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_TPM_MODULE_NAME, "{1} [{2}]", FF_TPM_NUM_FORMAT_ARGS, ((const char* []) { + FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_TPM_MODULE_NAME, "{2}", FF_TPM_NUM_FORMAT_ARGS, ((const char* []) { "TPM device version - version", - "TPM interface type - interface-type", + "TPM general description - description", })); } @@ -115,7 +118,7 @@ void ffInitTPMOptions(FFTPMOptions* options) ffPrintTPMHelpFormat, ffGenerateTPMJsonConfig ); - ffOptionInitModuleArg(&options->moduleArgs, "󰔎"); + ffOptionInitModuleArg(&options->moduleArgs, ""); } void ffDestroyTPMOptions(FFTPMOptions* options)