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): refine get_quote output format #22

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
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
98 changes: 24 additions & 74 deletions common/python/cctrusted_base/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,101 +2,51 @@
Quote data structures
"""

from abc import ABC, abstractmethod
import logging
from abc import abstractmethod
from cctrusted_base.binaryblob import BinaryBlob

LOG = logging.getLogger(__name__)


class QuoteHeader(ABC):
class QuoteData(BinaryBlob):
"""
Quote Header abstract class (interface)
Quote Data
"""

@abstractmethod
def get_data(self) -> bytearray:
"""
Get raw data
"""
raise NotImplementedError("Should be implemented by inherited class")

class QuoteBody(ABC):
class QuoteSignature(BinaryBlob):
"""
Quote Body abstract class (interface)
Quote Signature
"""

@abstractmethod
def get_data(self) -> bytearray:
"""
Get raw data
"""
raise NotImplementedError("Should be implemented by inherited class")

QuoteSignature = bytearray

class Quote(ABC):
class Quote(BinaryBlob):
"""
Quote abstract class (interface)
"""

@abstractmethod
def get_header(self) -> QuoteHeader:
def get_quoted_data(self) -> QuoteData:
"""
Get quote header.
Get quoted data
"""
raise NotImplementedError("Should be implemented by inherited class")

@abstractmethod
def get_body(self) -> QuoteBody:
"""
Get quote body.
The body (excludes the header) correspongs to the data to be signed.
"""
raise NotImplementedError("Should be implemented by inherited class")

@abstractmethod
def get_sig(self) -> QuoteSignature:
"""
Get quote signature.
Get quote signature
"""
raise NotImplementedError("Should be implemented by inherited class")

class Tpm2Quote(Quote):
"""
TPM Quote
https://trustedcomputinggroup.org/wp-content/uploads/TCG_TPM2_r1p59_Part3_Commands_pub.pdf
Table 91 — TPM2_Quote Response
Type Name Description
TPM_ST tag see clause 6
UINT32 responseSize
TPM_RC responseCode
TPM2B_ATTEST quoted the quoted information
TPMT_SIGNATURE signature the signature over quoted
In our code, these info will be grouped into 3 properties according to the definition of Quote
header: includes tag, responseSize and responseCode
body: quoted
sig: signature
"""

def __init__(self, data: bytearray):
self._data = data
# TODO: parse raw data into header, body and sigature

def get_header(self) -> QuoteHeader:
"""
Get TPM2 quote header which includes tag, responseSize and responseCode
@abstractmethod
def dump(self, is_raw=True) -> None:
"""
# TODO: parse the raw data to get header
return None
Dump Quote Data.

def get_body(self) -> QuoteBody:
"""
Get TPM2 quote body
Args:
is_raw:
True: dump in hex strings
False: dump in human readable texts
Returns:
None
Raises:
None
"""
# TODO: parse the raw data to get body
return None

def get_sig(self) -> QuoteSignature:
"""
Get TPM2 quote signature
"""
# TODO: parse the raw data to get signature
return None
raise NotImplementedError("Should be implemented by inherited class")
3 changes: 3 additions & 0 deletions common/python/cctrusted_base/tdx/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
TDX_VERSION_1_0 = "1.0"
TDX_VERSION_1_5 = "1.5"

TDX_QUOTE_VERSION_4 = 4
TDX_QUOTE_VERSION_5 = 5

# The length of the reportdata
TDX_REPORTDATA_LEN = 64
# The length of the tdreport
Expand Down
Loading
Loading