Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmsdk/python: update cli for event log #31

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading