Skip to content

Commit

Permalink
Merge pull request #31 from Ruoyu-y/update-python-el
Browse files Browse the repository at this point in the history
  • Loading branch information
wenhuizhang authored Apr 2, 2024
2 parents 00e1345 + 221893f commit 5953348
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 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,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__":
Expand Down

0 comments on commit 5953348

Please sign in to comment.