diff --git a/src/python/cc_event_log_cli.py b/src/python/cc_event_log_cli.py index ec9410e..3de2911 100644 --- a/src/python/cc_event_log_cli.py +++ b/src/python/cc_event_log_cli.py @@ -5,6 +5,8 @@ import argparse import os from cctrusted_base.api import CCTrustedApi +from cctrusted_base.eventlog import TcgEventLog +from cctrusted_base.tcgcel import TcgTpmsCelEvent from cctrusted_vm.cvm import ConfidentialVM from cctrusted_vm.sdk import CCTrustedVmSdk @@ -28,12 +30,31 @@ def main(): help='index of first event log to fetch', dest='start') parser.add_argument("-c", type=int, help="number of event logs to fetch", dest="count") + parser.add_argument("-f", type=bool, help="enable canonical tlv format", default=False, + dest="cel_format") args = parser.parse_args() event_logs = CCTrustedVmSdk.inst().get_cc_eventlog(args.start, args.count) - if event_logs is not None: - LOG.info("Total %d of event logs fetched.", len(event_logs)) - for event in event_logs: + if event_logs is None: + LOG.error("No event log fetched. Check debug log for issues.") + return + LOG.info("Total %d of event logs fetched.", len(event_logs)) + + res = CCTrustedApi.replay_cc_eventlog(event_logs) + LOG.info("Replayed result of collected event logs:") + # pylint: disable-next=C0201 + for key in res.keys(): + LOG.info("RTMR[%d]: ", key) + LOG.info(" %s", res.get(key).get(12).hex()) + + LOG.info("Dump collected event logs:") + for event in event_logs: + if isinstance(event, TcgTpmsCelEvent): + if args.cel_format: + TcgTpmsCelEvent.encode(event, TcgEventLog.TCG_FORMAT_CEL_TLV).dump() + else: + event.to_pcclient_format().dump() + else: event.dump() if __name__ == "__main__":