mssim

package
v1.16.2 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: LGPL-3.0 Imports: 11 Imported by: 3

Documentation

Overview

Package mssim provides an interface for communicating with a TPM simulator

Index

Constants

View Source
const (
	// DefaultPort is the default IP port that the TPM channel of
	// the simulator runs on. The platform port is normally this + 1,
	// but can be customized by WithPlatformPort.
	DefaultPort uint16 = 2321
)

Variables

View Source
var ErrUnsupportedOperation = errors.New("the simulator does not support this operation")

ErrUnsupportedOperation is returned from a method of Transport if the operation isn't supported by the attached simulator.

Functions

This section is empty.

Types

type Device added in v1.1.0

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

Device describes a TPM simulator device.

var (
	// DefaultDevice is configured for the simulator, running locally
	// with the default port of 2321 for the TPM channel and 2322 for
	// the platform channel.
	DefaultDevice *Device = NewDevice()
)

func NewDevice added in v1.1.0

func NewDevice(opts ...DeviceOption) *Device

NewDevice returns a new device structure. By default, the host is localhost, the TPM channel port set to DefaultPort, and it assumes that the platform channel port is DefaultPort + 1. The default retry parameters have MaxRetries set to 4, InitialBackoff set to 20ms and the BackoffRate set to 2.

It can be customized by any of the [DeviceOption]s.

The returned device is safe to use from multiple goroutines simultaneously.

func (*Device) Host deprecated added in v1.1.0

func (d *Device) Host() string

Host is the host that the TPM simulator is running on.

Deprecated: Use Device.TPMAddr or Device.PlatformAddr instead.

func (*Device) Open added in v1.1.0

func (d *Device) Open() (tpm2.Transport, error)

Open implements tpm2.TPMDevice.Open.

The returned transport will automatically retry commands that fail with TPM_RC_RETRY or TPM_RC_YIELDED. It will also retry commands that fail with TPM_RC_TESTING if the command wasn't TPM_CC_SELF_TEST.

The returned transport should not be used from more than one goroutine simultaneously.

Before returning an open transport, this package will send some platform commands to make sure that the simulator TPM device is on and NV storage is available. If this is already the case, then these commands are no-ops. It does not call TPM2_Startup.

func (*Device) PlatformAddr added in v1.8.0

func (d *Device) PlatformAddr() net.Addr

PlatformAddr returns the address of the platform channel for this device.

func (*Device) Port deprecated added in v1.1.0

func (d *Device) Port() uint

Port is the port number of the TPM simulator's command channel. Its platform channel runs on the next port number.

Deprecated: Use Device.TPMAddr or Device.PlatformAddr instead.

func (*Device) RetryParams added in v1.12.0

func (d *Device) RetryParams() transportutil.RetryParams

RetryParams returns the command retry parameters for this device.

func (*Device) String added in v1.1.0

func (d *Device) String() string

String implements fmt.Stringer.

func (*Device) TPMAddr added in v1.8.0

func (d *Device) TPMAddr() net.Addr

TPMAddr returns the address of the TPM channel for this device.

type DeviceOption added in v1.12.0

type DeviceOption func(*Device)

DeviceOption is an option passed to any function that creates a new Device instance.

func WithHost added in v1.12.0

func WithHost(host string) DeviceOption

WithHost is used to customize the host address on which the simulator's TCP ports can be accessed. The default is localhost.

func WithPlatformPort added in v1.12.0

func WithPlatformPort(port uint16) DeviceOption

WithPlatformPort is used to customize the TCP port on which the platform chanel for the simulator is accessed. It doesn't modify the port for the TPM channel

func WithPort added in v1.12.0

func WithPort(port uint16) DeviceOption

WithPort is used to customize the TCP ports on which the TPM and platform channels for the simulator are accessed. It sets the platform channel port to the TPM channel port + 1.

func WithRetryParams added in v1.12.0

func WithRetryParams(maxRetries uint, initialBackoff time.Duration, backoffRate uint) DeviceOption

WithRetryParams is used to customize the retry parameters for a device.

func WithTPMPort added in v1.12.0

func WithTPMPort(port uint16) DeviceOption

WithTPMPort is used to customize the TCP port on which the TPM channel for the simulator is accessed. It doesn't modify the port for the platform channel.

type HashSequence added in v1.8.0

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

HashSequence corresponds to a H-CRTM or DRTM sequence.

func (*HashSequence) End added in v1.8.0

func (s *HashSequence) End() error

End terminates this hash sequence with _TPM_Hash_End. On success, it will no longer be possible to use this sequence.

func (*HashSequence) Write added in v1.8.0

func (s *HashSequence) Write(data []byte) error

Write writes the supplied bytes to this hash sequence with the _TPM_Hash_Data command.

type PlatformCommandError deprecated

type PlatformCommandError struct {
	Code uint32
	// contains filtered or unexported fields
}

PlatformCommandError corresponds to an error code in response to a platform command executed on a TPM simulator.

Deprecated: This never returned.

func (*PlatformCommandError) Error

func (e *PlatformCommandError) Error() string

type SimulatorFlags added in v1.8.0

type SimulatorFlags uint32

SimulatorFlags provides information about TPM simulator features.

const (
	// SimulatorFlagPlatformAvailable indicates that the platform hierarchy
	// is available, and hardware platform functionality (eg, _TPM_Hash_Start)
	// is also available.
	SimulatorFlagPlatformAvailable SimulatorFlags = 1 << iota

	// SimulatorFlagUsesTbs indicates that a resource manager is used. In
	// this case, handles for transient objects and sessions returned to the
	// caller are virtualized.
	SimulatorFlagUsesTbs

	// SimulatorFlagInRawMode indicates that no resource virtualization is
	// performed.
	SimulatorFlagInRawMode

	// SimulatorFlagSupportsPP indicates that the simulator supports asserting
	// physical presence.
	SimulatorFlagSupportsPP

	// SimulatorFlagsNoPowerCtl indicates that the simulator does not support
	// power control commands.
	SimulatorFlagsNoPowertCtl

	// SimulatorFlagsNoLocalityCtl indicates that the simulator does not support
	// controlling the command locality.
	SimulatorFlagsNoLocalityCtl

	// SimulatorFlagsNoNvCtl indicates that the simulator does not support any
	// NV control commands.
	SimulatorFlagsNoNvCtl
)

type Tcti deprecated

type Tcti = Transport

Tcti represents a connection to a TPM simulator that implements the Microsoft TPM2 simulator interface.

Deprecated: Use Transport.

type Transport added in v1.4.0

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

Transport represents a connection to a TPM simulator that implements the Microsoft TPM2 simulator interface. It should not be used from multiple goroutines simultaneously.

func OpenConnection deprecated

func OpenConnection(host string, port uint) (*Transport, error)

OpenConnection attempts to open a connection to a TPM simulator on the specified host and port. The port argument corresponds to the TPM command server. The simulator will also provide a platform server on port+1. If host is an empty string, it defaults to "localhost".

If successful, it returns a new Transport instance which can be passed to tpm2.NewTPMContext.

Deprecated: Use NewDevice, [NewLocalDevice] or DefaultDevice.

func (*Transport) CancelOff added in v1.12.0

func (t *Transport) CancelOff() error

CancelOff disables the cancellation of the limited number of commands that can be canceled.

func (*Transport) CancelOn added in v1.12.0

func (t *Transport) CancelOn() error

CancelOn enables the cancellation of the limited number of commands that can be canceled.

func (*Transport) Close added in v1.4.0

func (t *Transport) Close() (err error)

Close implements tpm2.Transport.Close. Close can be called from any goroutine and will unblock a goroutine that is currently waiting in [Read] or [Write].

func (*Transport) HashStart added in v1.8.0

func (t *Transport) HashStart() (*HashSequence, error)

HashStart begins a hash sequence with the _TPM_Hash_Start command on the TPM connection. If a sequence is already in progress, a _TPM_Hash_End will be sent for that sequence first. Whether this happens before or after TPM2_Startup determines whether it is a H-CRTM sequence or a DRTM sequence.

func (*Transport) Locality added in v1.12.0

func (t *Transport) Locality() uint8

Locality returns the current locality that commands sent on this transport will be executed at.

func (*Transport) NVOff added in v1.12.0

func (t *Transport) NVOff() error

NVOff makes NV memory unavailable.

func (*Transport) NVOn added in v1.12.0

func (t *Transport) NVOn() error

NVOn makes NV memory available.

func (*Transport) PhysicalPresenceOff added in v1.12.0

func (t *Transport) PhysicalPresenceOff() error

PhysicalPresenceOfff disables the indication of physical presence.

func (*Transport) PhysicalPresenceOn added in v1.12.0

func (t *Transport) PhysicalPresenceOn() error

PhysicalPresenceOn enables the indication of physical presence.

func (*Transport) PlatformLocalAddr added in v1.9.0

func (t *Transport) PlatformLocalAddr() net.Addr

PlatformLocalAddr returns the local address of the platform channel.

func (*Transport) PlatformRemoteAddr added in v1.9.0

func (t *Transport) PlatformRemoteAddr() net.Addr

PlatformRemoteAddr returns the remote address of the platform channel.

func (*Transport) PowerOff added in v1.8.0

func (t *Transport) PowerOff() error

PowerOff puts the simulator into a power off state. It has no effect if the simulator is already in a power off state.

func (*Transport) PowerOn added in v1.8.0

func (t *Transport) PowerOn() error

PowerOn puts the simulator into a power on state. It has no effect if the simulator is already in a power off state. If the simulator was in a power off state, it results in the execution of _TPM_Init().

func (*Transport) Read added in v1.4.0

func (t *Transport) Read(data []byte) (int, error)

Read implements tpm2.Transport.Read. It reads from the TPM channel.

func (*Transport) Reset added in v1.4.0

func (t *Transport) Reset() error

Reset initiates a reset of the TPM simulator and results in the execution of _TPM_Init().

func (*Transport) Restart added in v1.12.0

func (t *Transport) Restart() error

func (*Transport) SetLocality added in v1.7.0

func (t *Transport) SetLocality(locality uint8) error

SetLocality sets the locality for subsequent commands. The supplied value is the numeric locality rather than the TPMA_LOCALITY representation. Localities between 5 and 31 are invalid and the behaviour of the simulator is not defined in this case.

func (*Transport) SimulatorFlags added in v1.12.0

func (t *Transport) SimulatorFlags() SimulatorFlags

SimulatorFlags indicates the flags reported by the simulator.

func (*Transport) SimulatorVersion added in v1.12.0

func (t *Transport) SimulatorVersion() uint32

SimulatorVersion returns the version number reported by the simulator.

func (*Transport) Stop added in v1.4.0

func (t *Transport) Stop() (err error)

Stop submits a stop command on both the TPM command and platform channels, which initiates a shutdown of the TPM simulator.

func (*Transport) TPMLocalAddr added in v1.9.0

func (t *Transport) TPMLocalAddr() net.Addr

TPMLocalAddr returns the local address of the TPM channel.

func (*Transport) TPMRemoteAddr added in v1.9.0

func (t *Transport) TPMRemoteAddr() net.Addr

TPMRemoteAddr returns the remote address of the TPM channel.

func (*Transport) TestFailureMode added in v1.12.0

func (t *Transport) TestFailureMode() error

TestFailureMode is used to force the TPM into failure mode during tests. This will be cleared again on the simulator side when a TPM2_SelfTest command is executed.

func (*Transport) Write added in v1.4.0

func (t *Transport) Write(data []byte) (int, error)

Write implements tpm2.Transport.Write. It writes to the TPM channel and only supports TPM commands.

Jump to

Keyboard shortcuts

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