tpm

package
v2.7.1-0...-5f38440 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// currently we support only PCR0 and PCR1
	//
	// TODO: move this value into TPM settings
	PCRRegistersAmount = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Algorithm

type Algorithm = pcr.Algorithm

Algorithm is just a type-alias.

func SupportedHashAlgos

func SupportedHashAlgos() []Algorithm

SupportedHashAlgos the list of currently supported hashing algorithms.

type CauseAction

type CauseAction = types.Action

CauseAction defines the Action which caused the Command.

type CauseCoordinates

type CauseCoordinates = types.ActionCoordinates

CauseCoordinates defines the coordinates of the Action in a Flow which caused the Command.

type Command

type Command interface {
	// Apply applies the changes themselves to the given *TPM (not including appending CommandLog).
	//
	// Do not use this method directly unless you know what are you doing,
	// use (*TPM).TPMExecute instead.
	Apply(context.Context, *TPM) error

	// LogString formats the entry for CommandLog.
	LogString() string
}

Command is a serializable command that could be "sent" (applied) to TPM.

type CommandEventLogAdd

type CommandEventLogAdd struct {
	CommandExtend
	Type tpmeventlog.EventType
	Data []byte
}

CommandEventLogAdd is a Command which adds an entry to TPM Event Log.

func NewCommandEventLogAdd

func NewCommandEventLogAdd(
	cmdExtend CommandExtend,
	evType tpmeventlog.EventType,
	data []byte,
) *CommandEventLogAdd

NewCommandEventLogAdd returns a new instance of CommandEventLogAdd

func (*CommandEventLogAdd) Apply

func (cmd *CommandEventLogAdd) Apply(_ context.Context, tpm *TPM) error

apply implements Command.

func (*CommandEventLogAdd) LogString

func (cmd *CommandEventLogAdd) LogString() string

LogString formats the entry for CommandLog.

func (*CommandEventLogAdd) String

func (cmd *CommandEventLogAdd) String() string

String implements fmt.Stringer.

type CommandExtend

type CommandExtend struct {
	PCRIndex PCRID
	HashAlgo Algorithm
	Digest   Digest
}

CommandExtend implements Command to represent TPM2_PCR_Extend

Is also used (together with CommandEventLogAdd) to implement a TPM2_PCR_Event Action.

func NewCommandExtend

func NewCommandExtend(
	pcrIdx PCRID,
	hashAlgo Algorithm,
	digest Digest,
) *CommandExtend

NewCommandExtend returns a new instance of CommandExtend.

func (*CommandExtend) Apply

func (cmd *CommandExtend) Apply(_ context.Context, tpm *TPM) error

apply implements Command.

func (CommandExtend) LogString

func (cmd CommandExtend) LogString() string

LogString implements Command.

func (CommandExtend) String

func (cmd CommandExtend) String() string

String implements fmt.Stringer.

type CommandInit

type CommandInit struct {
	Locality uint8
}

CommandInit represents _TPM_init + TPM2_Startup(CLEAR).

func NewCommandInit

func NewCommandInit(locality uint8) *CommandInit

NewCommandInit returns a new instance of CommandInit.

func (*CommandInit) Apply

func (cmd *CommandInit) Apply(_ context.Context, tpm *TPM) error

apply implements Command.

func (*CommandInit) LogString

func (cmd *CommandInit) LogString() string

LogString implements Command.

func (*CommandInit) String

func (cmd *CommandInit) String() string

String implements fmt.Stringer.

type CommandLog

type CommandLog []CommandLogEntry

CommandLog is a log of Command-s executed by the TPM.

func (CommandLog) Commands

func (s CommandLog) Commands() Commands

Commands returns the list of raw Command-s.

func (CommandLog) String

func (s CommandLog) String() string

String implements fmt.Stringer

type CommandLogEntry

type CommandLogEntry struct {
	Command
	CauseCoordinates
	CauseAction
}

CommandLogEntry is a log entry of a Command.

func (CommandLogEntry) String

func (entry CommandLogEntry) String() string

String implements fmt.Stringer.

type CommandLogInfoProvider

type CommandLogInfoProvider interface {
	CauseCoordinates() types.ActionCoordinates
	CauseAction() types.Action
}

CommandLogInfoProvider is an abstract provider of additional/optional information to be added to the CommandLog.

type Commands

type Commands []Command

Commands is a slice of Command-s

func (Commands) Apply

func (s Commands) Apply(ctx context.Context, tpm *TPM) error

apply implements Command.

func (Commands) LogString

func (s Commands) LogString() string

LogString implements Command.

type Digest

type Digest = pcr.Digest

Digest is a digest/hash value

type EventLog

type EventLog []EventLogEntry

EventLog represents TPM Event Log.

func EventLogFromParsed

func EventLogFromParsed(parsed *tpmeventlog.TPMEventLog) EventLog

func (*EventLog) Add

func (log *EventLog) Add(extend CommandExtend, evType tpmeventlog.EventType, data []byte)

Add appends an entry to the EventLog.

func (EventLog) Replay

func (log EventLog) Replay(pcrID PCRID, hashAlgo Algorithm, locality uint8) Digest

func (EventLog) RestoreCommands

func (log EventLog) RestoreCommands() []Command

RestoreCommands returns a list of command logged by the EventLog.

type EventLogEntry

type EventLogEntry struct {
	CommandExtend
	Type tpmeventlog.EventType
	Data []byte
}

EventLogEntry is a single entry of EventLog.

func EventLogEntryFromParsed

func EventLogEntryFromParsed(ev *tpmeventlog.Event) EventLogEntry

func (EventLogEntry) Apply

func (entry EventLogEntry) Apply()

Apply is just a placeholder which forbids to use this entry directly as a Command.

func (EventLogEntry) String

func (entry EventLogEntry) String() string

String implements fmt.Stringer.

type PCRID

type PCRID = pcr.ID

PCRID is a numeric identifier of a PCR register. For example PCR0 has ID == 0 and PCR8 has ID == 8.

type PCRValues

type PCRValues = pcr.Values

PCRValues is a complete set of initialized PCR values of a TPM.

type TPM

type TPM struct {
	SupportedAlgos []Algorithm
	PCRValues      PCRValues
	CommandLog     CommandLog
	EventLog       EventLog
}

TPM is a TrustChain implementation which represents measured boot backed by a Trusted Platform Module (TPM).

func GetFrom

func GetFrom(state *types.State) (*TPM, error)

GetFrom returns a TPM given a State.

func NewTPM

func NewTPM() *TPM

NewTPM returns a new instance of TPM.

func (*TPM) DoNotUse_ResetNoInit

func (tpm *TPM) DoNotUse_ResetNoInit()

DoNotUse_ResetNoInit cleans up the state of TPM as it never received any commands, but does not set the state to a correct one.

Do no use this function unless you know what are you doing.

TODO: try to get rid of this function (or at least make it private).

func (*TPM) IsInitialized

func (tpm *TPM) IsInitialized() bool

IsInitialized returns if CommandInit was ever executed.

func (*TPM) Reset

func (tpm *TPM) Reset()

Reset cleans up the state of TPM as it never received any commands.

func (*TPM) TPMEventLogAdd

func (tpm *TPM) TPMEventLogAdd(
	ctx context.Context,
	pcrIndex PCRID,
	hashAlgo Algorithm,
	digest Digest,
	evType tpmeventlog.EventType,
	data []byte,
	info CommandLogInfoProvider,
) error

TPMEventLogAdd is just a wrapper which creates CommandEventLogAdd and executes it.

func (*TPM) TPMExecute

func (tpm *TPM) TPMExecute(ctx context.Context, cmd Command, logInfo CommandLogInfoProvider) error

TPMExecute executes an abstract command.

func (*TPM) TPMExtend

func (tpm *TPM) TPMExtend(
	ctx context.Context,
	pcrIndex PCRID,
	hashAlgo Algorithm,
	digest []byte,
	info CommandLogInfoProvider,
) error

TPMExtend is just a wrapper which creates CommandExtend and executes it.

func (*TPM) TPMInit

func (tpm *TPM) TPMInit(ctx context.Context, locality uint8, info CommandLogInfoProvider) error

TPMInit is just a wrapper which creates a CommandInit and executes it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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