tdx_guest

package module
v0.0.0-...-110d291 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 24 Imported by: 0

README

TDX Guest

It's a golang library to generate and verify Intel TDX Quote V5.

Similar Go libraries are go-tdx-qpl and go-tdx-guest, which only support quote V4. But their code and documentation also provided me with some reference and assistance.

GetQuote(data [64]byte) ([]byte, error)

The func uses "/dev/tdx_guest" device to get a TDX Quote V5. It's based on SGXDataCenterAttestationPrimitives DCAP_1.22.

VerifyQuote(quoteRaw []byte, options VerifyOptions) (*SgxQuote, error)

It verifies the TDX Quote V4 or V5. It's based on QVL v1.1.8886

VerifyOptions
  • GetCollateral: download the collateral from intel pcs and check.
  • CheckCrl: download the crl (certificate revocation list) and check if quote pck cert is revoked.

GetCollateral and CheckCrl are false by default DefaultVerifyOptions().

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetQuote

func GetQuote(data [reportDataSize]byte) ([]byte, error)

GetQuote generates a TDX quote for the given user data. Supported quote formats - QuoteV5.

Types

type EnclaveIdentity

type EnclaveIdentity struct {
	ID                      string     `json:"id"`
	Version                 int        `json:"version"`
	IssueDate               time.Time  `json:"issueDate"`
	NextUpdate              time.Time  `json:"nextUpdate"`
	TcbEvaluationDataNumber int        `json:"tcbEvaluationDataNumber"`
	MiscSelect              HexUint32  `json:"miscselect"`
	MiscSelectMask          HexUint32  `json:"miscSelectMask"`
	Attributes              HexBytes   `json:"attributes"`
	AttributesMask          HexBytes   `json:"attributesMask"`
	MrSigner                HexBytes   `json:"mrsigner"`
	IsvProdID               uint16     `json:"isvprodid"`
	TcbLevels               []TcbLevel `json:"tcbLevels"`
}

EnclaveIdentity https://api.portal.trustedservices.intel.com/content/documentation.html#pcs-enclave-identity-model-v2

type EnclaveReport

type EnclaveReport struct {
	CpuSvn     [16]byte
	MiscSelect uint32
	Reserved1  [28]byte
	Attributes [16]byte
	MrEnclave  [32]byte
	Reserved2  [32]byte
	MrSigner   [32]byte
	Reserved3  [96]byte
	IsvProdID  uint16
	IsvSvn     uint16
	Reserved4  [60]byte
	ReportData [64]byte
}

type HexBytes

type HexBytes []byte

func (*HexBytes) UnmarshalJSON

func (p *HexBytes) UnmarshalJSON(s []byte) error

UnmarshalJSON for hex bytes converts hex encoded string to bytes

type HexUint32

type HexUint32 uint32

func (*HexUint32) UnmarshalJSON

func (p *HexUint32) UnmarshalJSON(s []byte) error

type PckConfiguration

type PckConfiguration struct {
	DynamicPlatform bool
	CachedKeys      bool
	SmtEnabled      bool
}

type PckExtension

type PckExtension struct {
	Ppid               [16]byte
	Tcb                PckTcb
	PceID              [2]byte
	Fmspc              [6]byte
	SgxType            int
	PlatformInstanceID [16]byte
	Configuration      PckConfiguration
}

type PckTcb

type PckTcb struct {
	Components [16]byte // SGX TCB Comp01 SVN ... SGX TCB Comp16 SVN
	PceSvn     int
	CpuSvn     [16]byte
}

type PcsClient

type PcsClient struct {
	// contains filtered or unexported fields
}

PcsClient is client for Intel® SGX and Intel® TDX Provisioning Certification Service https://api.portal.trustedservices.intel.com/content/documentation.html#pcs

func NewPcsClient

func NewPcsClient(baseUrl string, now time.Time, request Request) PcsClient

func (*PcsClient) GetPckCrl

func (client *PcsClient) GetPckCrl(commonName string) (*x509.RevocationList, error)

GetPckCrl is Get Revocation List V4. Retrieve X.509 Certificate Revocation List with revoked SGX PCK Certificates. CRL is issued by Intel SGX Processor CA or Platform CA. https://api.portal.trustedservices.intel.com/content/documentation.html#pcs-revocation-v4

func (*PcsClient) GetQeIdentity

func (client *PcsClient) GetQeIdentity() (*EnclaveIdentity, error)

GetQeIdentity is Enclave Identity V4. https://api.portal.trustedservices.intel.com/content/documentation.html#pcs-enclave-identity-v4

func (*PcsClient) GetRootCrl

func (client *PcsClient) GetRootCrl() (*x509.RevocationList, error)

func (*PcsClient) GetTcbInfo

func (client *PcsClient) GetTcbInfo(fmspc [6]byte) (*TcbInfo, error)

GetTcbInfo is Get TDX TCB Info V4. Retrieve TDX TCB information for given FMSPC. https://api.portal.trustedservices.intel.com/content/documentation.html#pcs-tcb-info-tdx-v4

type QeAuthData

type QeAuthData struct {
	ParsedDataSize uint16
	Data           []byte
}

type QeReportCertificationData

type QeReportCertificationData struct {
	QeReport EnclaveReport

	QeReportSignature [64]byte
	QeAuthData        QeAuthData
	Type              uint16
	ParsedDataSize    uint32
	Data              []byte
	// contains filtered or unexported fields
}

type QgsMsgGetQuoteReq

type QgsMsgGetQuoteReq struct {
	Header       QgsMsgHeader     // header.type = GET_QUOTE_REQ (0)
	ReportSize   uint32           // cannot be 0
	IdListSize   uint32           // length of id_list, in byte, can be 0
	ReportIdList [reportSize]byte // report followed by id list
}

QgsMsgGetQuoteReq is qgs_msg_get_quote_req_t, https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/DCAP_1.22/QuoteGeneration/quote_wrapper/qgs_msg_lib/inc/qgs_msg_lib.h#L81-L86

type QgsMsgGetQuoteResp

type QgsMsgGetQuoteResp struct {
	Header         QgsMsgHeader // header.type = GET_QUOTE_RESP
	SelectedIdSize uint32       // can be 0 in case only one id is sent in request
	QuoteSize      uint32       // length of quote_data, in byte

}

QgsMsgGetQuoteResp is qgs_msg_get_quote_resp_t, https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/DCAP_1.22/QuoteGeneration/quote_wrapper/qgs_msg_lib/inc/qgs_msg_lib.h#L88-L93

type QgsMsgHeader

type QgsMsgHeader struct {
	MajorVersion uint16
	MinorVersion uint16
	Type         uint32
	Size         uint32 // size of the whole message, include this header, in byte
	ErrorCode    uint32 // used in response only
}

QgsMsgHeader is qgs_msg_header_t, https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/DCAP_1.22/QuoteGeneration/quote_wrapper/qgs_msg_lib/inc/qgs_msg_lib.h#L73-L79

type ReportBodyType

type ReportBodyType uint16
const (
	ReportBodyTypeSgxEnclave ReportBodyType = 1
	ReportBodyTypeTdx10      ReportBodyType = 2
	ReportBodyTypeTdx15      ReportBodyType = 3
)

type Request

type Request func(url string) ([]byte, http.Header, error)

type SgxQuote

type SgxQuote struct {
	Header     SgxQuoteHeader
	Type       ReportBodyType
	Size       uint32
	ReportBody SgxReport2BodyV15

	SignatureDataLen uint32
	SignatureData    Ecdsa256BitQuoteV4AuthData
	// contains filtered or unexported fields
}

SgxQuote is mixed struct of sgx_quote4_t and sgx_quote5_t.

sgx_quote4_t: https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/DCAP_1.22/QuoteGeneration/quote_wrapper/common/inc/sgx_quote_4.h#L141-L154

type SgxQuoteV4 struct {
	Header           SgxQuoteHeader             // < 0:   The quote header.
	ReportBody       SgxReport2Body             // < 48:  The REPORT of the TD that is attesting remotely.
	SignatureDataLen uint32                     // < 632: The length of the signature_data.  Varies depending on the type of sign_type.
	SignatureData    Ecdsa256BitQuoteV4AuthData // < 636: Contains the variable length containing the quote signature and support data for the signature.
}

sgx_quote5_t: https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/DCAP_1.22/QuoteGeneration/quote_wrapper/common/inc/sgx_quote_5.h#L106-L128

type SgxQuoteV5 struct {
	Header           SgxQuoteHeader             // < 0:   The quote header.
	Type             ReportBodyType             // < 48:  Determines type of Quote body (TEE report), Architecturally supported values:
	                                            //        1 (SGX Enclave Report)
	                                            //        2 (TD Report for TDX 1.0)
	                                            //        3 (TD Report for TDX 1.5)
	Size             uint32                     // < 50:  Size of Quote Body field.
	ReportBody       Union:                     // < 54:  Quote Body. Its content depends on the value of Quote Body Type:
	                     SgxReportBody          //        Type 1
	                     SgxReport2Body         //        Type 2
	                     SgxReport2BodyV15      //        Type 3
	SignatureDataLen uint32                     // < _:   The length of the signature data.
	SignatureData    Ecdsa256BitQuoteV4AuthData // < _:   The quote signature data.
}

func VerifyQuote

func VerifyQuote(quoteRaw []byte, options VerifyOptions) (*SgxQuote, error)

VerifyQuote verifies the TDX quote using the pck certificate, tcb info, and qe identity. Supported quote formats - QuoteV4, QuoteV5. https://github.com/intel/SGX-TDX-DCAP-QuoteVerificationLibrary/tree/v1.1.8886 (qvl)

type SgxQuoteHeader

type SgxQuoteHeader struct {
	Version    uint16   // < 0:  The version this quote structure.
	AttKeyType uint16   // < 2:  sgx_attestation_algorithm_id_t.  Describes the type of signature in the signature_data[] field.
	TeeType    TeeType  // < 4:  Type of Trusted Execution Environment for which the Quote has been generated. Supported values: 0 (SGX), 0x81(TDX)
	Reserved   uint32   // < 8:  Reserved field.
	VendorId   [16]byte // < 12: Unique identifier of QE Vendor.
	UserData   [20]byte // < 28: Custom attestation key owner data.
}

SgxQuoteHeader is the quote header. It is designed to compatible with earlier versions of the quote. sgx_quote4_header_t, https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/DCAP_1.22/QuoteGeneration/quote_wrapper/common/inc/sgx_quote_4.h#L112-L120 sgx_quote5_header_t, https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/DCAP_1.22/QuoteGeneration/quote_wrapper/common/inc/sgx_quote_5.h#L82

type SgxReport2Body

type SgxReport2Body struct {
	TeeTcbSvn      TeeTcbSvn         // <  0:  TEE_TCB_SVN Array
	MrSeam         TeeMeasurement    // < 16:  Measurement of the SEAM module
	MrSignerSeam   TeeMeasurement    // < 64:  Measurement of a 3rd party SEAM module’s signer (SHA384 hash). The value is 0’ed for Intel SEAM module
	SeamAttributes TeeAttributes     // < 112: MBZ: TDX 1.0
	TdAttributes   TeeAttributes     // < 120: TD's attributes
	XFam           TeeAttributes     // < 128: TD's XFAM
	MrTd           TeeMeasurement    // < 136: Measurement of the initial contents of the TD
	MrConfigId     TeeMeasurement    // < 184: Software defined ID for non-owner-defined configuration on the guest TD. e.g., runtime or OS configuration
	MrOwner        TeeMeasurement    // < 232: Software defined ID for the guest TD's owner
	MrOwnerConfig  TeeMeasurement    // < 280: Software defined ID for owner-defined configuration of the guest TD, e.g., specific to the workload rather than the runtime or OS
	RtMr           [4]TeeMeasurement // < 328: Array of 4(TDX1: NUM_RTMRS is 4) runtime extendable measurement registers
	ReportData     TeeReportData     // < 520: Additional report data
}

SgxReport2Body is SGX Report2 body. sgx_report2_body_t, https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/DCAP_1.22/QuoteGeneration/quote_wrapper/common/inc/sgx_quote_4.h#L123-L137 TDReport10, https://github.com/intel/SGX-TDX-DCAP-QuoteVerificationLibrary/blob/v1.1.7988/Src/AttestationLibrary/src/QuoteVerification/QuoteStructures.h#L82-L103

type SgxReport2BodyV15

type SgxReport2BodyV15 struct {
	SgxReport2Body
	TeeTcbSvn2  TeeTcbSvn      // < 584: Array of TEE TCB SVNs (for TD preserving).
	MrServiceTd TeeMeasurement // < 600: If is one or more bound or pre-bound service TDs, SERVTD_HASH is the SHA384 hash of the TDINFO_STRUCTs of those service TDs bound. Else, SERVTD_HASH is 0..
}

SgxReport2BodyV15 is SGX Report2 body for quote v5. sgx_report2_body_v1_5_t, https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/DCAP_1.22/QuoteGeneration/quote_wrapper/common/inc/sgx_quote_5.h#L85-L102 TDReport15, https://github.com/intel/SGX-TDX-DCAP-QuoteVerificationLibrary/blob/v1.1.7988/Src/AttestationLibrary/src/QuoteVerification/QuoteStructures.h#L105-L112

type Tcb

type Tcb struct {
	IsvSvn           uint16           `json:"isvsvn"` // TDX SEAM module's ISV SVN, Wrong "isvnsvn" in document
	SgxTcbComponents [16]TcbComponent `json:"sgxtcbcomponents"`
	PceSvn           int              `json:"pcesvn"`
	TdxTcbComponents [16]TcbComponent `json:"tdxtcbcomponents"`
}

type TcbComponent

type TcbComponent struct {
	Svn      uint8  `json:"svn"`
	Category string `json:"category"`
	Type     string `json:"type"`
}

type TcbInfo

type TcbInfo struct {
	ID                      string              `json:"id"`
	Version                 int                 `json:"version"`
	IssueDate               time.Time           `json:"issueDate"`
	NextUpdate              time.Time           `json:"nextUpdate"`
	Fmspc                   HexBytes            `json:"fmspc"`
	PceID                   HexBytes            `json:"pceId"`
	TcbType                 int                 `json:"tcbType"`
	TcbEvaluationDataNumber int                 `json:"tcbEvaluationDataNumber"`
	TdxModule               TdxModule           `json:"tdxModule"`
	TdxModuleIdentities     []TdxModuleIdentity `json:"tdxModuleIdentities"`
	TcbLevels               []TcbLevel          `json:"tcbLevels"`
}

TcbInfo https://api.portal.trustedservices.intel.com/content/documentation.html#pcs-tcb-info-model-v3

type TcbLevel

type TcbLevel struct {
	Tcb         Tcb       `json:"tcb"`
	TcbDate     time.Time `json:"tcbDate"`
	TcbStatus   TcbStatus `json:"tcbStatus"`
	AdvisoryIDs []string  `json:"advisoryIDs"`
}

type TcbStatus

type TcbStatus string
const (
	TcbStatusUpToDate                          TcbStatus = "UpToDate"
	TcbStatusConfigurationNeeded               TcbStatus = "ConfigurationNeeded"
	TcbStatusOutOfDate                         TcbStatus = "OutOfDate"
	TcbStatusOutOfDateConfigurationNeeded      TcbStatus = "OutOfDateConfigurationNeeded"
	TcbStatusConfigurationAndSWHardeningNeeded TcbStatus = "ConfigurationAndSWHardeningNeeded"
	TcbStatusSWHardeningNeeded                 TcbStatus = "SWHardeningNeeded"
	TcbStatusRevoked                           TcbStatus = "Revoked"
)

type TdxModule

type TdxModule struct {
	MrSigner       HexBytes `json:"mrsigner"`
	Attributes     HexBytes `json:"attributes"`
	AttributesMask HexBytes `json:"attributesMask"`
}

type TdxModuleIdentity

type TdxModuleIdentity struct {
	TdxModule
	ID        string     `json:"id"`
	TcbLevels []TcbLevel `json:"tcbLevels"`
}

type TdxQuoteHdr

type TdxQuoteHdr struct {
	Version uint64           // Quote version, filled by TD
	Status  uint64           // Status code of Quote request, filled by VMM
	InLen   uint32           // Length of TDREPORT, filled by TD
	OutLen  uint32           // Length of Quote, filled by VMM
	Data    [reqBufSize]byte // Actual Quote data or TDREPORT on input
}

TdxQuoteHdr is tdx_quote_hdr, https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/DCAP_1.22/QuoteGeneration/quote_wrapper/tdx_attest/tdx_attest.c#L108-L119

type TdxReportReq

type TdxReportReq struct {
	ReportData [reportDataSize]byte
	TdReport   [reportSize]byte
}

TdxReportReq is tdx_report_req, https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/DCAP_1.22/QuoteGeneration/quote_wrapper/tdx_attest/tdx_attest.c#L98-L101

type TeeType

type TeeType uint32
const (
	TeeTypeSgx TeeType = 0x00000000
	TeeTypeTdx TeeType = 0x00000081
)

type VerifyOptions

type VerifyOptions struct {
	GetCollateral bool // download the collateral from intel pcs and check.
	CheckCrl      bool // download the crl (certificate revocation list) and check if quote pck cert is revoked.
	PcsClient     PcsClient
}

func DefaultVerifyOptions

func DefaultVerifyOptions() VerifyOptions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL