Skip to content

Commit

Permalink
vmsdk/python: update cli for event log
Browse files Browse the repository at this point in the history
* provide extra format option for user to determine the output format
of event logs. Using TCG PCClient by default.

Signed-off-by: Ruoyu Ying <[email protected]>
  • Loading branch information
Ruoyu-y committed Apr 2, 2024
1 parent 95dc2c7 commit 40fb0cc
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/python/cc_event_log_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -28,12 +30,30 @@ 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:")
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__":
Expand Down

0 comments on commit 40fb0cc

Please sign in to comment.