-
Notifications
You must be signed in to change notification settings - Fork 10
/
py_sdk_example.py
50 lines (44 loc) · 1.68 KB
/
py_sdk_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
CIMA SDK Example
"""
import logging
import argparse
from cima import CimaSdk
LOG = logging.getLogger(__name__)
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[
logging.StreamHandler()
]
)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="The utility to show how to use CIMA SDK")
parser.add_argument('-r', action='store_true', help='get cc report', dest='report')
parser.add_argument('-e', action='store_true', help='get cc eventlog', dest='eventlog')
parser.add_argument('-m', action='store_true', help='get cc measurement', dest='measurement')
parser.add_argument('-v', action='store_true', help='verify eventlog', dest='verify')
args = parser.parse_args()
if args.report:
CimaSdk.inst().get_cc_report().dump()
elif args.eventlog:
evt = CimaSdk.inst().get_cc_eventlog()
for e in evt:
e.dump()
elif args.measurement:
for i in [0, 1, 3]:
m = CimaSdk.inst().get_cc_measurement([i, 12])
LOG.info("IMR index: %d, hash: %s", i, m.hash.hex())
elif args.verify:
evt = CimaSdk.inst().get_cc_eventlog()
replay = CimaSdk.inst().replay_cc_eventlog(evt)
for r in replay:
LOG.info("Replay IMR[%d]: %s", r, replay[r][12].hex())
m = CimaSdk.inst().get_cc_measurement([r, 12])
LOG.info("Read IMR[%d]: %s", r, m.hash.hex())
if m.hash != replay[r][12]:
LOG.error("Replay IMR value does not match real IMR.")
else:
LOG.info("Verify event log replay value successfully.")
else:
parser.print_help()