tpm

package
v0.10.0-main Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinNonceLength = 8
)

Variables

View Source
var (
	LDevIDTemplate = tpm2.TPMTPublic{
		Type:    tpm2.TPMAlgECC,
		NameAlg: tpm2.TPMAlgSHA256,
		ObjectAttributes: tpm2.TPMAObject{
			FixedTPM:             true,
			STClear:              false,
			FixedParent:          true,
			SensitiveDataOrigin:  true,
			UserWithAuth:         true,
			AdminWithPolicy:      true,
			NoDA:                 false,
			EncryptedDuplication: false,
			Restricted:           false,
			Decrypt:              false,
			SignEncrypt:          true,
		},
		Parameters: tpm2.NewTPMUPublicParms(
			tpm2.TPMAlgECC,
			&tpm2.TPMSECCParms{
				Scheme: tpm2.TPMTECCScheme{
					Scheme: tpm2.TPMAlgECDSA,
					Details: tpm2.NewTPMUAsymScheme(
						tpm2.TPMAlgECDSA,
						&tpm2.TPMSSigSchemeECDSA{
							HashAlg: tpm2.TPMAlgSHA256,
						},
					),
				},
				CurveID: tpm2.TPMECCNistP256,
			},
		),
		Unique: tpm2.NewTPMUPublicID(
			tpm2.TPMAlgECC,
			&tpm2.TPMSECCPoint{
				X: tpm2.TPM2BECCParameter{Buffer: make([]byte, 32)},
				Y: tpm2.TPM2BECCParameter{Buffer: make([]byte, 32)},
			},
		),
	}

	// AttestationKeyTemplate defines a standard attestation key template based on go-tpm-tools AKTemplateECC.
	// This creates an ECC restricted signing key suitable for TPM attestation operations.
	AttestationKeyTemplate = tpm2.TPMTPublic{
		Type:    tpm2.TPMAlgECC,
		NameAlg: tpm2.TPMAlgSHA256,
		ObjectAttributes: tpm2.TPMAObject{
			SignEncrypt:         true,
			Restricted:          true,
			FixedTPM:            true,
			FixedParent:         true,
			SensitiveDataOrigin: true,
			UserWithAuth:        true,
		},
		Parameters: tpm2.NewTPMUPublicParms(
			tpm2.TPMAlgECC,
			&tpm2.TPMSECCParms{
				Scheme: tpm2.TPMTECCScheme{
					Scheme: tpm2.TPMAlgECDSA,
					Details: tpm2.NewTPMUAsymScheme(
						tpm2.TPMAlgECDSA,
						&tpm2.TPMSSigSchemeECDSA{
							HashAlg: tpm2.TPMAlgSHA256,
						},
					),
				},
				CurveID: tpm2.TPMECCNistP256,
			},
		),
		Unique: tpm2.NewTPMUPublicID(
			tpm2.TPMAlgECC,
			&tpm2.TPMSECCPoint{
				X: tpm2.TPM2BECCParameter{Buffer: make([]byte, 32)},
				Y: tpm2.TPM2BECCParameter{Buffer: make([]byte, 32)},
			},
		),
	}
)

This key template uses the Storage Root Key as the parent key. Other key attributes are aligned with definitions from https://trustedcomputinggroup.org/wp-content/uploads/TCG_TPM-2p0-DevID_v1p00_r10_12july2021.pdf. Specifically, for key attribute and parameter recommendations, see Sections 7.3.4.1 and 7.3.4.3.

Functions

This section is empty.

Types

type Client added in v0.9.0

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

Client represents a connection to a TPM device and manages TPM operations.

func NewClient added in v0.9.0

func NewClient(log *log.PrefixLogger, rw fileio.ReadWriter, config *agent_config.Config) (*Client, error)

NewClient creates a new TPM client with the given configuration.

func (*Client) AttestationCollector added in v0.9.0

func (t *Client) AttestationCollector(ctx context.Context) string

AttestationCollector returns TPM attestation as a string for system info collection.

func (*Client) Clear added in v0.9.0

func (t *Client) Clear() error

func (*Client) Close added in v0.9.0

func (t *Client) Close(ctx context.Context) error

Close closes the TPM connection and flushes any transient handles. It should be called when the TPM is no longer needed to free resources.

func (*Client) EndorsementKeyCert

func (t *Client) EndorsementKeyCert() ([]byte, error)

func (*Client) EndorsementKeyPublic

func (t *Client) EndorsementKeyPublic() ([]byte, error)

func (*Client) GetAttestation

func (t *Client) GetAttestation(nonce []byte, ak *tpm2.NamedHandle) (*pbattest.Attestation, error)

GetAttestation generates a TPM attestation using the provided nonce and attestation key. The nonce must be at least MinNonceLength bytes long for security.

func (*Client) GetLocalAttestationPubKey

func (t *Client) GetLocalAttestationPubKey() (crypto.PublicKey, error)

GetLocalAttestationPubKey returns the public key of the Local Attestation Key.

func (*Client) GetPath

func (t *Client) GetPath() string

GetPath returns the TPM device path.

func (*Client) GetQuote

func (t *Client) GetQuote(nonce []byte, ak *tpm2.NamedHandle, pcrSelection *tpm2.TPMLPCRSelection) (*pbtpm.Quote, error)

GetQuote generates a TPM quote using the provided nonce, attestation key, and PCR selection. The quote provides cryptographic evidence of the current PCR values.

func (*Client) GetSigner added in v0.9.0

func (t *Client) GetSigner() crypto.Signer

func (*Client) Public added in v0.9.0

func (t *Client) Public() crypto.PublicKey

func (*Client) ReadPCRValues

func (t *Client) ReadPCRValues(measurements map[string]string) error

ReadPCRValues reads PCR values from the TPM and populates the provided map. The map keys are formatted as "pcr01", "pcr02", etc., and values are hex-encoded.

func (*Client) Sign added in v0.9.0

func (t *Client) Sign(rand io.Reader, data []byte, opts crypto.SignerOpts) ([]byte, error)

Sign signs the given data using the TPM's LDevID key. The rand parameter is ignored as the TPM generates its own randomness internally. Opts is ignored as the only hash type supported is SHA256 (as defined by the creation of the key)

func (*Client) UpdateNonce added in v0.9.0

func (t *Client) UpdateNonce(nonce []byte) error

UpdateNonce updates the current nonce for attestation operations.

func (*Client) VendorInfo

func (t *Client) VendorInfo() ([]byte, error)

VendorInfo returns the TPM manufacturer information. This can be used to identify the TPM vendor and model.

func (*Client) VendorInfoCollector added in v0.9.0

func (t *Client) VendorInfoCollector(ctx context.Context) string

VendorInfoCollector returns TPM vendor information as a string for system info collection.

type ClientConfig

type ClientConfig struct {
	Log             *log.PrefixLogger
	DeviceWriter    fileio.ReadWriter
	PersistencePath string
	DevicePath      string
}

ClientConfig contains configuration options for creating a TPM client.

type TPM

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

TPM represents a TPM device and its associated file paths.

func (*TPM) Close

func (t *TPM) Close(ctx context.Context) error

func (*TPM) Exists

func (t *TPM) Exists() bool

func (*TPM) ValidateVersion2

func (t *TPM) ValidateVersion2() error

Jump to

Keyboard shortcuts

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