Documentation
¶
Overview ¶
Package mssim provides an interface for communicating with a TPM simulator
Index ¶
- Constants
- Variables
- type Device
- type DeviceOption
- type HashSequence
- type PlatformCommandErrordeprecated
- type SimulatorFlags
- type Tctideprecated
- type Transport
- func (t *Transport) CancelOff() error
- func (t *Transport) CancelOn() error
- func (t *Transport) Close() (err error)
- func (t *Transport) HashStart() (*HashSequence, error)
- func (t *Transport) Locality() uint8
- func (t *Transport) NVOff() error
- func (t *Transport) NVOn() error
- func (t *Transport) PhysicalPresenceOff() error
- func (t *Transport) PhysicalPresenceOn() error
- func (t *Transport) PlatformLocalAddr() net.Addr
- func (t *Transport) PlatformRemoteAddr() net.Addr
- func (t *Transport) PowerOff() error
- func (t *Transport) PowerOn() error
- func (t *Transport) Read(data []byte) (int, error)
- func (t *Transport) Reset() error
- func (t *Transport) Restart() error
- func (t *Transport) SetLocality(locality uint8) error
- func (t *Transport) SimulatorFlags() SimulatorFlags
- func (t *Transport) SimulatorVersion() uint32
- func (t *Transport) Stop() (err error)
- func (t *Transport) TPMLocalAddr() net.Addr
- func (t *Transport) TPMRemoteAddr() net.Addr
- func (t *Transport) TestFailureMode() error
- func (t *Transport) Write(data []byte) (int, error)
Constants ¶
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 ¶
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.
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
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
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
PlatformAddr returns the address of the platform channel for this device.
func (*Device) Port
deprecated
added in
v1.1.0
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
String implements fmt.Stringer.
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 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
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
CancelOff disables the cancellation of the limited number of commands that can be canceled.
func (*Transport) CancelOn ¶ added in v1.12.0
CancelOn enables the cancellation of the limited number of commands that can be canceled.
func (*Transport) Close ¶ added in v1.4.0
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
Locality returns the current locality that commands sent on this transport will be executed at.
func (*Transport) PhysicalPresenceOff ¶ added in v1.12.0
PhysicalPresenceOfff disables the indication of physical presence.
func (*Transport) PhysicalPresenceOn ¶ added in v1.12.0
PhysicalPresenceOn enables the indication of physical presence.
func (*Transport) PlatformLocalAddr ¶ added in v1.9.0
PlatformLocalAddr returns the local address of the platform channel.
func (*Transport) PlatformRemoteAddr ¶ added in v1.9.0
PlatformRemoteAddr returns the remote address of the platform channel.
func (*Transport) PowerOff ¶ added in v1.8.0
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
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
Read implements tpm2.Transport.Read. It reads from the TPM channel.
func (*Transport) Reset ¶ added in v1.4.0
Reset initiates a reset of the TPM simulator and results in the execution of _TPM_Init().
func (*Transport) SetLocality ¶ added in v1.7.0
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
SimulatorVersion returns the version number reported by the simulator.
func (*Transport) Stop ¶ added in v1.4.0
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
TPMLocalAddr returns the local address of the TPM channel.
func (*Transport) TPMRemoteAddr ¶ added in v1.9.0
TPMRemoteAddr returns the remote address of the TPM channel.
func (*Transport) TestFailureMode ¶ added in v1.12.0
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.