linux

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: 20 Imported by: 6

Documentation

Overview

Package linux provides an interface for communicating with TPMs using a Linux TPM character device

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDefaultNotTPM2Device indicates that the default device is not a TPM device.
	ErrDefaultNotTPM2Device = errors.New("the default TPM device is not a TPM2 device")

	// ErrNoPhysicalPresenceInterface indicates that there is no physical presence interface
	// available for a TPM device.
	ErrNoPhysicalPresenceInterface = errors.New("no physical presence interface available")

	// ErrNoResourceManagedDevice indicates that a TPM device has no corresponding resource
	// managed device.
	ErrNoResourceManagedDevice = errors.New("no resource managed TPM device available")

	// ErrNoTPMDevices indicates that there are no TPM devices.
	ErrNoTPMDevices = errors.New("no TPM devices are available")
)

Functions

func ForcePPIType added in v1.13.0

func ForcePPIType(ppiType ppi.Type)

ForcePPIType can be used to force the PPI implementation that is returned from DirectDevice.PhysicalPresenceInterface on any device. This will panic if it is called after DirectDevice.PhysicalPresenceInterface has been called for any device. If the forced PPI implementation isn't available, then any calls to DirectDevice.PhysicalPresenceInterface will return an error rather than falling back to an available implementation.

Types

type Device added in v1.4.0

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

Device represents a Linux TPM character device.

func (*Device) MajorVersion added in v1.4.0

func (d *Device) MajorVersion() TPMMajorVersion

MajorVersion indicates the TPM version.

func (*Device) Open added in v1.4.0

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

Open implements tpm2.TPMDevice.Open. The returned transport cannot be used from multiple goroutines simultaneously.

func (*Device) PartialReadSupported added in v1.4.0

func (d *Device) PartialReadSupported() bool

PartialReadSupported indicates whether the TPM character device supports partial reads.

func (*Device) Path added in v1.4.0

func (d *Device) Path() string

Path returns the path of the character device.

func (*Device) String added in v1.4.0

func (d *Device) String() string

String implements fmt.Stringer.

func (*Device) SysfsPath added in v1.4.0

func (d *Device) SysfsPath() string

SysfsPath returns the path of the device in sysfs.

type DirectDevice added in v1.14.0

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

DirectDevice represents a direct Linux TPM character device. These devices don't use the kernel's resource manager. It is safe to use this from multiple goroutines simultaneously.

func DefaultTPM2Device added in v1.1.0

func DefaultTPM2Device() (*DirectDevice, error)

DefaultTPM2Device returns the default TPM2 device. If there are no devices available, then ErrNoTPMDevices is returned. If the default TPM device is not a TPM2 device, then ErrDefaultNotTPM2Device is returned. Calling this function always returns a pointer to the same device or the same error for the lifetime of a process. It is safe to call this function from multiple goroutines simultaneously.

func DefaultTPMDevice added in v1.1.0

func DefaultTPMDevice() (*DirectDevice, error)

DefaultTPMDevice returns the default TPM device. If there are no devices available, then ErrNoTPMDevices is returned. Calling this function always returns a pointer to the same device or the same error for the lifetime of a process. It is safe to call this function from multiple goroutines simultaneously.

func ListTPM2Devices added in v1.1.0

func ListTPM2Devices() (out []*DirectDevice, err error)

ListTPMDevices returns a list of all TPM2 devices. Calling this function always returns the same slice or the same error for the lifetime of a process. It is safe to call this function from multiple goroutines simultaneously.

func ListTPMDevices added in v1.1.0

func ListTPMDevices() (out []*DirectDevice, err error)

ListTPMDevices returns a list of all TPM devices. Note that this returns all devices, regardless of version. Calling this function always returns the same slice or the same error for the lifetime of a process. It is safe to call this function from multiple goroutines simultaneously.

func (*DirectDevice) PhysicalPresenceInterface added in v1.14.0

func (d *DirectDevice) PhysicalPresenceInterface() (ppi.PPI, error)

PhysicalPresenceInterface returns the physical presence interface associated with this device. This will return the EFI implementation if it's supported, else it will return the ACPI implementation that is exposed via sysfs if supported. If no implementation is supported, an ErrNoPhysicalPresenceInterface error will be returned. Calling this function will always return either a pointer to the same interface or the same error for the lifetime of a process.

func (*DirectDevice) ResourceManagedDevice added in v1.14.0

func (d *DirectDevice) ResourceManagedDevice() (*RMDevice, error)

ResourceManagedDevice returns the corresponding resource managed device if one is available. If there isn't one, a ErrNoResourceManagedDevice error is returned. Calling this function will always return either a pointer to the same interface or the same error for the lifetime of a process.

type RMDevice added in v1.4.0

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

RMDevice represents a Linux TPM character device that makes use of the kernel resource manager. It is safe to use this from multiple goroutines simultaneously.

func (*RMDevice) DirectDevice added in v1.14.0

func (d *RMDevice) DirectDevice() *DirectDevice

DirectDevice returns the corresponding direct device.

func (*RMDevice) RawDevice deprecated added in v1.4.0

func (d *RMDevice) RawDevice() *RawDevice

RawDevice returns the corresponding raw device.

Deprecated: use DirectDevice.

type RawDevice deprecated added in v1.4.0

type RawDevice = DirectDevice

RawDevice represents a raw Linux TPM character device.

Deprecated: use DirectDevice.

type TPMDevice deprecated added in v1.1.0

type TPMDevice = Device

TPMDevice represents a Linux TPM character device.

Deprecated: use Device.

type TPMDeviceRM deprecated added in v1.1.0

type TPMDeviceRM = RMDevice

TPMDeviceRM represents a Linux TPM character device that makes use of the kernel resource manager.

Deprecated: use RMDevice.

type TPMDeviceRaw deprecated added in v1.1.0

type TPMDeviceRaw = DirectDevice

TPMDeviceRaw represents a raw Linux TPM character device.

Deprecated: use DirectDevice.

type TPMMajorVersion added in v1.2.0

type TPMMajorVersion int

TPMMajorVersion describes the major version of a TPM device.

const (
	TPMVersion1 TPMMajorVersion = 1
	TPMVersion2 TPMMajorVersion = 2
)

type Tcti deprecated added in v1.1.0

type Tcti = Transport

Tcti represents a connection to a Linux TPM character device.

Deprecated: Use Transport.

type TctiDevice deprecated

type TctiDevice = Transport

TctiDevice represents a connection to a Linux TPM character device.

Deprecated: Use Transport

type Transport added in v1.4.0

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

Transport represents a connection to a Linux TPM character device. It is not intended to be used from multiple goroutines simultaneously.

func OpenDevice deprecated

func OpenDevice(path string) (*Transport, error)

OpenDevice attempts to open a connection to the Linux TPM character device at the specified path. If successful, it returns a new Transport instance which can be passed to tpm2.NewTPMContext. Failure to open the TPM character device will result in a *os.PathError being returned.

Deprecated: Use DirectDevice and RMDevice.

func (*Transport) Close added in v1.4.0

func (d *Transport) Close() error

Close implements tpm2.Transport.Close.

func (*Transport) Read added in v1.4.0

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

Read implmements tpm2.Transport.

func (*Transport) Write added in v1.4.0

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

Write implmements tpm2.Transport.

Jump to

Keyboard shortcuts

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