Skip to content

Commit

Permalink
vmsdk: add exception handling in get_cc_report
Browse files Browse the repository at this point in the history
* add exception handling for python impl of get_cc_report

Signed-off-by: Ruoyu Ying <[email protected]>
  • Loading branch information
Ruoyu-y committed Apr 22, 2024
1 parent bcc11dc commit 4450187
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/python/cctrusted_vm/cvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def process_eventlog(self) -> bool:
raise NotImplementedError("Should be implemented by inherited class")

@abstractmethod
# pylint: disable-next=R0911
def get_cc_report(self, nonce: bytearray, data: bytearray, extraArgs) -> CcReport:
"""Get the CcReport (i.e. quote) for given nonce and data.
Expand Down Expand Up @@ -180,9 +181,16 @@ def get_cc_report(self, nonce: bytearray, data: bytearray, extraArgs) -> CcRepor
with open(os.path.join(tempdir, "inblob"), 'wb') as inblob_file:
inblob_file.write(input_data)

# Read the output of report
with open(os.path.join(tempdir, "outblob"), 'rb') as outblob_file:
td_report = outblob_file.read()
# Read the output of report and prevent case of resource busy
try:
with open(os.path.join(tempdir, "outblob"), 'rb') as outblob_file:
td_report = outblob_file.read()
except OSError:
LOG.error("Read outblob failed with OSError")
return None
except:
LOG.error("Error in opening outblob file.")
return None

# Read provider info
with open(os.path.join(tempdir, "provider"), 'r', encoding='utf-8') as provider_file:
Expand All @@ -192,6 +200,10 @@ def get_cc_report(self, nonce: bytearray, data: bytearray, extraArgs) -> CcRepor
with open(os.path.join(tempdir, "generation"), 'r', encoding='utf-8') \
as generation_file:
generation = generation_file.read()
# Check if the outblob has been corrupted during file open
if int(generation) > 1:
LOG.error("Found corrupted generation. Skipping attestation report fetching...")
return None

if os.path.exists(os.path.join(tempdir, "auxblob")):
with open(os.path.join(tempdir, "auxblob"), 'rb') as auxblob_file:
Expand Down

0 comments on commit 4450187

Please sign in to comment.