cel

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: Apache-2.0 Imports: 7 Imported by: 2

README

Canonical Event Log Format (CEL)

See https://trustedcomputinggroup.org/resource/canonical-event-log-format/.

Not to be confused with Confidential Computing Event Log (CCEL).

Documentation

Overview

Package cel contains some basic operations of Canonical Eventlog. Based on Canonical EventLog Spec (Draft) Version: TCG_IWG_CEL_v1_r0p37.

Index

Constants

View Source
const (
	// FakeEventType indicates the CELR event is a Fake content type.
	FakeEventType uint8 = 222
	// FakeEventMR is the PCR which should be used for FakeEventType events.
	FakeEventMR = 23
)

Variables

This section is empty.

Functions

func VerifyDigests

func VerifyDigests(c Content, digestMap map[crypto.Hash][]byte) error

VerifyDigests checks the digest generated by the given record's content to make sure they are equal to the digests in the digestMap.

Types

type CEL

type CEL interface {
	// Records returns all the records in the CEL.
	Records() []Record
	// AppendEvent appends a new record to the CEL.
	AppendEvent(Content, []crypto.Hash, int, MRExtender) error
	// EncodeCEL returns the TLV encoding of the CEL.
	EncodeCEL(*bytes.Buffer) error
	// Replay verifies the contents of the event log with the given MR bank.
	Replay(register.MRBank) error
	// MRType returns the measurement register type used in the CEL.
	MRType() MRType
}

CEL represents a Canonical Event Log, which contains a list of Records.

func DecodeToCEL

func DecodeToCEL(buf *bytes.Buffer) (CEL, error)

DecodeToCEL will read the buf for CEL, will return err if the buffer is not complete.

func NewConfComputeMR

func NewConfComputeMR() CEL

NewConfComputeMR returns a CEL with events measured in confidential computing measurement registers.

func NewPCR

func NewPCR() CEL

NewPCR returns a CEL with events measured in TPM PCRs.

type Content

type Content interface {
	GenerateDigest(crypto.Hash) ([]byte, error)
	TLV() (TLV, error)
}

Content is a interface for the content in CELR.

type FakeTlv

type FakeTlv struct {
	EventType    FakeType
	EventContent []byte
}

FakeTlv is a specific TLV created for testing.

func (FakeTlv) GenerateDigest

func (f FakeTlv) GenerateDigest(hashAlgo crypto.Hash) ([]byte, error)

GenerateDigest generates the digest for the given fake TLV. The whole TLV struct will be marshaled to bytes and feed into the hash algo.

func (FakeTlv) TLV

func (f FakeTlv) TLV() (TLV, error)

TLV returns the TLV representation of the fake TLV.

type FakeType

type FakeType uint8

FakeType represent a Fake content type in a CEL record content.

const (
	FakeEvent1 FakeType = iota
	FakeEvent2
)

Type for Fake nested events

type MRExtender

type MRExtender func(crypto.Hash, int, []byte) error

MRExtender extends an implementation-specific measurement register at the specified bank and index with the supplied digest.

type MRType

type MRType TopLevelEventType

MRType represents the type of measurement register used in the CEL for field CEL_PCR_NVindex TLV.

const (

	// PCRType indicates a PCR event index
	PCRType MRType = 1

	// CCMRType indicates a RTMR event index
	CCMRType MRType = 108
)

type Record

type Record struct {
	RecNum uint64
	// Generic Measurement Register index number, register type
	// is determined by IndexType
	Index     uint8
	IndexType uint8
	Digests   map[crypto.Hash][]byte
	Content   TLV
}

Record represents a Canonical Eventlog Record.

func (*Record) EncodeCELR

func (r *Record) EncodeCELR(buf *bytes.Buffer) error

EncodeCELR encodes the CELR to bytes according to the CEL spec and write them to the bytes byffer.

type TLV

type TLV struct {
	Type  uint8
	Value []byte
}

TLV definition according to CEL spec TCG_IWG_CEL_v1_r0p37, page 16. Length is implicitly defined by len(Value), using uint32 big-endian when encoding.

func (TLV) IsFakeTLV

func (t TLV) IsFakeTLV() bool

IsFakeTLV check whether a TLV is a Fake TLV by its Type value.

func (TLV) MarshalBinary

func (t TLV) MarshalBinary() (data []byte, err error)

MarshalBinary marshals a TLV to a byte slice.

func (TLV) ParseToFakeTlv

func (t TLV) ParseToFakeTlv() (FakeTlv, error)

ParseToFakeTlv constructs a FakeTlv from a TLV. It will check for the correct fake event type, and unmarshal the nested event.

func (*TLV) UnmarshalBinary

func (t *TLV) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshal a byte slice to a TLV.

type TopLevelEventType

type TopLevelEventType uint8

TopLevelEventType represents the CEL spec's known CELR data types for TPMS_CEL_EVENT.

Jump to

Keyboard shortcuts

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