From patchwork Thu Sep 10 09:36:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1361371 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BnDKV38F2z9sTM for ; Thu, 10 Sep 2020 19:36:13 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1kGIzy-0004uT-Jx; Thu, 10 Sep 2020 09:36:10 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kGIzw-0004uN-80 for fwts-devel@lists.ubuntu.com; Thu, 10 Sep 2020 09:36:08 +0000 Received: from 61-220-137-37.hinet-ip.hinet.net ([61.220.137.37] helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kGIzv-0003QX-I7 for fwts-devel@lists.ubuntu.com; Thu, 10 Sep 2020 09:36:08 +0000 From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH][V2] tpmevlogdump: add dumping sha1 log format event log Date: Thu, 10 Sep 2020 17:36:04 +0800 Message-Id: <1599730564-18304-1-git-send-email-ivan.hu@canonical.com> X-Mailer: git-send-email 2.7.4 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" Signed-off-by: Ivan Hu Acked-by: Alex Hung Acked-by: Colin Ian King --- src/tpm/tpmevlogdump/tpmevlogdump.c | 42 ++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/tpm/tpmevlogdump/tpmevlogdump.c b/src/tpm/tpmevlogdump/tpmevlogdump.c index dd5e3a5..94bb5cc 100644 --- a/src/tpm/tpmevlogdump/tpmevlogdump.c +++ b/src/tpm/tpmevlogdump/tpmevlogdump.c @@ -411,6 +411,42 @@ static void tpmevlogdump_parser(fwts_framework *fw, uint8_t *data, size_t len) return; } +static void tpmevlogdump_event_dump(fwts_framework *fw, uint8_t *data, size_t len) +{ + + uint8_t *pdata = data; + char *str_info; + fwts_pc_client_pcr_event *pc_event = NULL; + + while (len > 0) { + /* check the data length for dumping */ + if (len < sizeof(fwts_pc_client_pcr_event)) { + fwts_log_info(fw, + "Log event data is too small (%zd bytes) " + "than a TCG PC Client PCR event structure " + "(%zd bytes).", + len, sizeof(fwts_pc_client_pcr_event)); + return; + } + + pc_event = (fwts_pc_client_pcr_event *)pdata; + + str_info = tpmevlogdump_pcrindex_to_string(pc_event->pcr_index); + fwts_log_info_verbatim(fw, "PCRIndex: 0x%8.8" PRIx32 "(%s)", pc_event->pcr_index, str_info); + str_info = tpmevlogdump_evtype_to_string(pc_event->event_type); + fwts_log_info_verbatim(fw, "EventType: 0x%8.8" PRIx32 "(%s)", pc_event->event_type, str_info); + tpmevlogdump_data_hexdump(fw, pc_event->digest, sizeof(pc_event->digest), "Digest"); + fwts_log_info_verbatim(fw, "EventSize: 0x%8.8" PRIx32, pc_event->event_data_size); + if (pc_event->event_data_size > 0) + tpmevlogdump_data_hexdump(fw, pc_event->event, pc_event->event_data_size, "Event"); + pdata += (sizeof(fwts_pc_client_pcr_event) + pc_event->event_data_size); + len -= (sizeof(fwts_pc_client_pcr_event) + pc_event->event_data_size); + } + return; + +} + + static uint8_t *tpmevlogdump_load_file(const int fd, size_t *length) { uint8_t *ptr = NULL, *tmp; @@ -495,11 +531,7 @@ static int tpmevlogdump_test1(fwts_framework *fw) if (strstr((char *)(data + sizeof(fwts_pc_client_pcr_event)), FWTS_TPM_EVENTLOG_V2_SIGNATURE)) tpmevlogdump_parser(fw, data, length); else { - fwts_log_info(fw, "Cannot find the tpm2 event log. Aborted."); - free(data); - (void)closedir(dir); - (void)close(fd); - return FWTS_ABORTED; + (void)tpmevlogdump_event_dump(fw, data, length); } free(data); }