tpmutil

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2022 License: Apache-2.0 Imports: 10 Imported by: 135

Documentation

Overview

Package tpmutil provides common utility functions for both TPM 1.2 and TPM 2.0 devices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenTPM

func OpenTPM(path string) (io.ReadWriteCloser, error)

OpenTPM opens a channel to the TPM at the given path. If the file is a device, then it treats it like a normal TPM device, and if the file is a Unix domain socket, then it opens a connection to the socket.

func Pack

func Pack(elts ...interface{}) ([]byte, error)

Pack encodes a set of elements into a single byte array, using encoding/binary. This means that all the elements must be encodeable according to the rules of encoding/binary.

It has one difference from encoding/binary: it encodes byte slices with a prepended length, to match how the TPM encodes variable-length arrays. If you wish to add a byte slice without length prefix, use RawBytes.

func Unpack

func Unpack(b []byte, elts ...interface{}) (int, error)

Unpack is a convenience wrapper around UnpackBuf. Unpack returns the number of bytes read from b to fill elts and error, if any.

func UnpackBuf

func UnpackBuf(buf io.Reader, elts ...interface{}) error

UnpackBuf recursively unpacks types from a reader just as encoding/binary does under binary.BigEndian, but with one difference: it unpacks a byte slice by first reading an integer with lengthPrefixSize bytes, then reading that many bytes. It assumes that incoming values are pointers to values so that, e.g., underlying slices can be resized as needed.

Types

type Command

type Command uint32

Command is an identifier of a TPM command.

type EmulatorReadWriteCloser added in v0.2.0

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

EmulatorReadWriteCloser manages connections with a TPM emulator over a Unix domain socket. These emulators often operate in a write/read/disconnect sequence, so the Write method always connects, and the Read method always closes. EmulatorReadWriteCloser is not thread safe.

func NewEmulatorReadWriteCloser added in v0.2.0

func NewEmulatorReadWriteCloser(path string) *EmulatorReadWriteCloser

NewEmulatorReadWriteCloser stores information about a Unix domain socket to write to and read from.

func (*EmulatorReadWriteCloser) Close added in v0.2.0

func (erw *EmulatorReadWriteCloser) Close() error

Close implements io.Closer by closing the Unix domain socket if one is open.

func (*EmulatorReadWriteCloser) Read added in v0.2.0

func (erw *EmulatorReadWriteCloser) Read(p []byte) (int, error)

Read implements io.Reader by reading from the Unix domain socket and closing it.

func (*EmulatorReadWriteCloser) Write added in v0.2.0

func (erw *EmulatorReadWriteCloser) Write(p []byte) (int, error)

Write implements io.Writer by connecting to the Unix domain socket and writing.

type Handle

type Handle uint32

A Handle is a reference to a TPM object.

type RawBytes

type RawBytes []byte

RawBytes is for Pack and RunCommand arguments that are already encoded. Compared to []byte, RawBytes will not be prepended with slice length during encoding.

type ResponseCode

type ResponseCode uint32

ResponseCode is a response code returned by TPM.

const RCRetry ResponseCode = 0x922

RCRetry is response code for TPM is busy.

const RCSuccess ResponseCode = 0x000

RCSuccess is response code for successful command. Identical for TPM 1.2 and 2.0.

func RunCommand

func RunCommand(rw io.ReadWriter, tag Tag, cmd Command, in ...interface{}) ([]byte, ResponseCode, error)

RunCommand executes cmd with given tag and arguments. Returns TPM response body (without response header) and response code from the header. Returned error may be nil if response code is not RCSuccess; caller should check both.

type SelfMarshaler added in v0.2.0

type SelfMarshaler interface {
	TPMMarshal(out io.Writer) error
	TPMUnmarshal(in io.Reader) error
}

SelfMarshaler allows custom types to override default encoding/decoding behavior in Pack, Unpack and UnpackBuf.

type Tag

type Tag uint16

Tag is a command tag.

type U16Bytes added in v0.2.0

type U16Bytes []byte

U16Bytes is a byte slice with a 16-bit header

func (*U16Bytes) TPMMarshal added in v0.2.0

func (b *U16Bytes) TPMMarshal(out io.Writer) error

TPMMarshal packs U16Bytes

func (*U16Bytes) TPMUnmarshal added in v0.2.0

func (b *U16Bytes) TPMUnmarshal(in io.Reader) error

TPMUnmarshal unpacks a U16Bytes

type U32Bytes added in v0.2.0

type U32Bytes []byte

U32Bytes is a byte slice with a 32-bit header

func (*U32Bytes) TPMMarshal added in v0.2.0

func (b *U32Bytes) TPMMarshal(out io.Writer) error

TPMMarshal packs U32Bytes

func (*U32Bytes) TPMUnmarshal added in v0.2.0

func (b *U32Bytes) TPMUnmarshal(in io.Reader) error

TPMUnmarshal unpacks a U32Bytes

Directories

Path Synopsis
Package mssim implements the Microsoft simulator TPM2 Transmission Interface The Microsoft simulator TPM Command Transmission Interface (TCTI) is a remote procedure interface donated to the TPM2 Specification by Microsoft.
Package mssim implements the Microsoft simulator TPM2 Transmission Interface The Microsoft simulator TPM Command Transmission Interface (TCTI) is a remote procedure interface donated to the TPM2 Specification by Microsoft.
Package tbs provides an low-level interface directly mapping to Windows Tbs.dll system library commands: https://docs.microsoft.com/en-us/windows/desktop/TBS/tpm-base-services-portal Public field descriptions contain links to the high-level Windows documentation.
Package tbs provides an low-level interface directly mapping to Windows Tbs.dll system library commands: https://docs.microsoft.com/en-us/windows/desktop/TBS/tpm-base-services-portal Public field descriptions contain links to the high-level Windows documentation.

Jump to

Keyboard shortcuts

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