forked from cc-api/cc-trusted-vmsdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cc_imr_cli.py
39 lines (31 loc) · 1.26 KB
/
cc_imr_cli.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
"""
Command line to dump the integrated measurement register
"""
import logging
import os
from evidence_api.api import EvidenceApi
from cctrusted_vm.cvm import ConfidentialVM
from cctrusted_vm.sdk import CCTrustedVmSdk
LOG = logging.getLogger(__name__)
logging.basicConfig(level=logging.NOTSET, format='%(name)s %(levelname)-8s %(message)s')
def main():
"""Example to call get_cc_measurement and dump the result to stdout."""
if ConfidentialVM.detect_cc_type() == EvidenceApi.TYPE_CC_NONE:
LOG.error("This is not a confidential VM!")
return
if os.geteuid() != 0:
LOG.error("Please run as root which is required for this example!")
return
count = CCTrustedVmSdk.inst().get_measurement_count()
LOG.info("Measurement Count: %d", count)
for index in range(CCTrustedVmSdk.inst().get_measurement_count()):
alg = CCTrustedVmSdk.inst().get_default_algorithms()
imr = CCTrustedVmSdk.inst().get_cc_measurement([index, alg.alg_id])
digest_obj = imr.digest(alg.alg_id)
hash_str = ""
for hash_item in digest_obj.hash:
hash_str += "".join([f"{hash_item:02x}", " "])
LOG.info("Algorithms: %s", str(alg))
LOG.info("HASH: %s", hash_str)
if __name__ == "__main__":
main()