Documentation ¶
Overview ¶
Package tpmutil provides common utility functions for both TPM 1.2 and TPM 2.0 devices.
Index ¶
- func OpenTPM(path string) (io.ReadWriteCloser, error)
- func Pack(elts ...interface{}) ([]byte, error)
- func RunCommandRaw(rw io.ReadWriter, inb []byte) ([]byte, error)
- func Unpack(b []byte, elts ...interface{}) (int, error)
- func UnpackBuf(buf io.Reader, elts ...interface{}) error
- type Command
- type EmulatorReadWriteCloser
- type Handle
- type RawBytes
- type ResponseCode
- type SelfMarshaler
- type Tag
- type U16Bytes
- type U32Bytes
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 ¶
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 RunCommandRaw ¶ added in v0.9.0
func RunCommandRaw(rw io.ReadWriter, inb []byte) ([]byte, error)
RunCommandRaw executes the given raw command and returns the raw response. Does not check the response code except to execute retry logic.
func Unpack ¶
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 ¶
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 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.
type Handle ¶
type Handle uint32
A Handle is a reference to a TPM object.
func (Handle) HandleValue ¶ added in v0.9.0
HandleValue returns the handle value. This behavior is intended to satisfy an interface that can be implemented by other, more complex types as well.
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
SelfMarshaler allows custom types to override default encoding/decoding behavior in Pack, Unpack and UnpackBuf.
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
TPMMarshal packs 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
TPMMarshal packs U32Bytes
Directories ¶
Path | Synopsis |
---|---|
Package mssim implements the Microsoft simulator TPM2 Transmission Interface
|
Package mssim implements the Microsoft simulator TPM2 Transmission Interface |
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. |