storage

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExists = errors.New("already exists")

ErrExists is returned when a Key or AK already exists in storage

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a Key or AK cannot be found in storage

Functions

func BlackHoleContext

func BlackHoleContext(ctx context.Context) context.Context

BlackholeContext adds a new BlackHole storage to the context.

func NewContext

func NewContext(ctx context.Context, t TPMStore) context.Context

NewContext adds TPMStore `t` to the context.

Types

type AK

type AK struct {
	Name      string
	Data      []byte
	Chain     []*x509.Certificate
	CreatedAt time.Time
}

AK is the type used to store AKs.

func (*AK) MarshalJSON

func (ak *AK) MarshalJSON() ([]byte, error)

MarshalJSON marshals the AK into JSON.

func (*AK) UnmarshalJSON

func (ak *AK) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals `data` into an AK.

type Dirstore

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

Dirstore is a concrete implementation of the TPMStore interface that stores TPM objects in a directory. Each object will be stored in a separate file. The name of the file is constructed by prefixing the name of the object with its type.

func NewDirstore

func NewDirstore(directory string) *Dirstore

NewDirstore creates a new instance of a Direstore.

func (*Dirstore) AddAK

func (s *Dirstore) AddAK(ak *AK) error

func (*Dirstore) AddKey

func (s *Dirstore) AddKey(key *Key) error

func (*Dirstore) DeleteAK

func (s *Dirstore) DeleteAK(name string) error

func (*Dirstore) DeleteKey

func (s *Dirstore) DeleteKey(name string) error

func (*Dirstore) GetAK

func (s *Dirstore) GetAK(name string) (*AK, error)

func (*Dirstore) GetKey

func (s *Dirstore) GetKey(name string) (*Key, error)

func (*Dirstore) ListAKNames

func (s *Dirstore) ListAKNames() []string

func (*Dirstore) ListAKs

func (s *Dirstore) ListAKs() ([]*AK, error)

func (*Dirstore) ListKeyNames

func (s *Dirstore) ListKeyNames() []string

func (*Dirstore) ListKeys

func (s *Dirstore) ListKeys() ([]*Key, error)

func (*Dirstore) Load

func (s *Dirstore) Load() error

func (*Dirstore) Persist

func (s *Dirstore) Persist() error

func (*Dirstore) UpdateAK

func (s *Dirstore) UpdateAK(ak *AK) error

func (*Dirstore) UpdateKey

func (s *Dirstore) UpdateKey(key *Key) error

type FeedthroughStore

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

FeedthroughStore is a TPMStore that feeds through storage operations to the underlying TPMStore. If no backing TPMStore is set, the operations effectively become NOOPs.

func NewFeedthroughStore

func NewFeedthroughStore(store TPMStore) *FeedthroughStore

func (*FeedthroughStore) AddAK

func (f *FeedthroughStore) AddAK(ak *AK) error

func (*FeedthroughStore) AddKey

func (f *FeedthroughStore) AddKey(key *Key) error

func (*FeedthroughStore) DeleteAK

func (f *FeedthroughStore) DeleteAK(name string) error

func (*FeedthroughStore) DeleteKey

func (f *FeedthroughStore) DeleteKey(name string) error

func (*FeedthroughStore) GetAK

func (f *FeedthroughStore) GetAK(name string) (*AK, error)

func (*FeedthroughStore) GetKey

func (f *FeedthroughStore) GetKey(name string) (*Key, error)

func (*FeedthroughStore) ListAKNames

func (f *FeedthroughStore) ListAKNames() []string

func (*FeedthroughStore) ListAKs

func (f *FeedthroughStore) ListAKs() ([]*AK, error)

func (*FeedthroughStore) ListKeyNames

func (f *FeedthroughStore) ListKeyNames() []string

func (*FeedthroughStore) ListKeys

func (f *FeedthroughStore) ListKeys() ([]*Key, error)

func (*FeedthroughStore) Load

func (f *FeedthroughStore) Load() error

func (*FeedthroughStore) Persist

func (f *FeedthroughStore) Persist() error

func (*FeedthroughStore) UpdateAK

func (f *FeedthroughStore) UpdateAK(ak *AK) error

func (*FeedthroughStore) UpdateKey

func (f *FeedthroughStore) UpdateKey(key *Key) error

type Filestore

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

Filestore is a concrete implementation of the TPMStore interface that keeps an in-memory map of AKs and TPM Keys. The current state of the in-memory storage can be persisted to a file.

func NewFilestore

func NewFilestore(filepath string) *Filestore

NewFilestore creates a new instance of a Filestore

TODO: provide options for filepath (with default), gzip, persistence en-/disabled, ... ?

func (*Filestore) AddAK

func (s *Filestore) AddAK(ak *AK) error

func (*Filestore) AddKey

func (s *Filestore) AddKey(k *Key) error

func (*Filestore) DeleteAK

func (s *Filestore) DeleteAK(name string) error

func (*Filestore) DeleteKey

func (s *Filestore) DeleteKey(name string) error

func (*Filestore) GetAK

func (s *Filestore) GetAK(name string) (*AK, error)

func (*Filestore) GetKey

func (s *Filestore) GetKey(name string) (*Key, error)

func (*Filestore) ListAKNames

func (s *Filestore) ListAKNames() []string

func (*Filestore) ListAKs

func (s *Filestore) ListAKs() ([]*AK, error)

func (*Filestore) ListKeyNames

func (s *Filestore) ListKeyNames() []string

func (*Filestore) ListKeys

func (s *Filestore) ListKeys() ([]*Key, error)

func (*Filestore) Load

func (s *Filestore) Load() error

func (*Filestore) Persist

func (s *Filestore) Persist() error

func (*Filestore) UpdateAK

func (s *Filestore) UpdateAK(ak *AK) error

func (*Filestore) UpdateKey

func (s *Filestore) UpdateKey(k *Key) error

type Key

type Key struct {
	Name       string
	Data       []byte
	AttestedBy string
	Chain      []*x509.Certificate
	CreatedAt  time.Time
}

Key is the type used to store Keys.

func (*Key) MarshalJSON

func (key *Key) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Key into JSON.

func (*Key) UnmarshalJSON

func (key *Key) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals `data` into a Key.

type TPMStore

type TPMStore interface {
	ListKeys() ([]*Key, error)
	ListKeyNames() []string
	GetKey(name string) (*Key, error)
	AddKey(key *Key) error
	UpdateKey(key *Key) error
	DeleteKey(name string) error

	ListAKs() ([]*AK, error)
	ListAKNames() []string
	GetAK(name string) (*AK, error)
	AddAK(ak *AK) error
	UpdateAK(ak *AK) error
	DeleteAK(name string) error

	Persist() error
	Load() error
}

TPMStore is the interface that TPM storage implementations need to implement.

func BlackHole

func BlackHole() TPMStore

BlackHole returns a FeedthroughStore without a backing storage, effectively resulting in no persistence.

func FromContext

func FromContext(ctx context.Context) TPMStore

FromContext retrieves a TPMStore from the context.

It panics when there's no TPMStore present.

Jump to

Keyboard shortcuts

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