storekey

package
v1.66.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package storekey implements the client-held store key: its key file, deterministic sealing of blobs, name tokens and inline content, the digest blobs are named by, and passphrase escrow. The server never sees the key. It carries none of the object format, so a WebAssembly build can take it without the rest of goback.

Index

Constants

View Source
const IDSize = 8

IDSize is the width of a key id.

View Source
const MinPassphrase = 12

MinPassphrase is the fewest characters Escrow takes: anyone holding an agent key of the store can fetch the escrowed copy and guess at it offline.

Variables

View Source
var (
	// ErrWrongKey is returned when a token or sealed blob does not open
	// under the given key.
	ErrWrongKey = errors.New("wrong store key or corrupt ciphertext")
	// ErrNoKey is returned when an encrypted object is met without a key.
	ErrNoKey = errors.New("object is encrypted and no store key is loaded")
)

Functions

func ReadKeyset

func ReadKeyset(data json.RawMessage) (*keyset.Handle, error)

ReadKeyset reads a keyset as a key file holds it.

func WriteKeyset

func WriteKeyset(h *keyset.Handle) (json.RawMessage, error)

WriteKeyset writes a keyset as a key file holds it.

Types

type Field

type Field string

Field names the FileInfo fields that are sealed.

const (
	// FieldName is the entry name.
	FieldName Field = "name"
	// FieldUser is the owning user.
	FieldUser Field = "user"
	// FieldGroup is the owning group.
	FieldGroup Field = "group"
	// FieldTarget is a symlink's target.
	FieldTarget Field = "link_target"
)

type Key

type Key struct {
	Name   string
	Policy Policy
	// contains filtered or unexported fields
}

Key is a store key, named after its store, with the policy the agent writes under. It is a pair of Tink keysets: deterministic AEAD seals, a PRF names blobs.

func Generate

func Generate(name string) (*Key, error)

Generate makes a fresh key named after its store.

func Load

func Load(path string) (*Key, error)

Load reads a key file written by Save.

func New

func New(name string, policy Policy, seal, ref *keyset.Handle) (*Key, error)

New makes a key from its keysets: deterministic AEAD to seal with and a PRF to name blobs with.

func Parse

func Parse(data []byte) (*Key, error)

Parse reads a key file's contents.

func Recover

func Recover(escrowed []byte, passphrase string) (*Key, error)

Recover opens an escrowed key with its passphrase.

func (*Key) Digest

func (k *Key) Digest(plaintext []byte) []byte

Digest is the PRF of a blob's plaintext, which its ref is made from: equal under one key, unrelated under another.

func (*Key) Escrow

func (k *Key) Escrow(passphrase string) ([]byte, error)

Escrow wraps the key file under a passphrase of at least MinPassphrase characters with age, so the key's owner can keep it where the server cannot open it. The result is an armored age file; `age -d` opens it too.

func (*Key) ID

func (k *Key) ID() []byte

ID identifies the key in object headers.

func (*Key) IDString

func (k *Key) IDString() string

IDString is the hex form of ID.

func (*Key) Marshal

func (k *Key) Marshal() ([]byte, error)

Marshal returns the key file's contents.

func (*Key) OpenBlob

func (k *Key) OpenBlob(sealed, ref []byte) ([]byte, error)

OpenBlob reverses SealBlob.

func (*Key) OpenField

func (k *Key) OpenField(parent []byte, field Field, token []byte) ([]byte, error)

OpenField reverses SealField.

func (*Key) OpenInline

func (k *Key) OpenInline(ciphertext []byte) ([]byte, error)

OpenInline reverses SealInline.

func (*Key) Save

func (k *Key) Save(path string) error

Save writes the key file, readable by its owner only. It refuses a path that exists, with an error matching fs.ErrExist, so no key is ever written over another.

func (*Key) SealBlob

func (k *Key) SealBlob(stored, ref []byte) []byte

SealBlob seals a blob's stored bytes, bound to the blob's ref. Sealing is deterministic, so a blob stored twice is stored once.

func (*Key) SealField

func (k *Key) SealField(parent []byte, field Field, plaintext []byte) []byte

SealField makes the deterministic token of a name-like field within its parent directory. Equal names in one directory give equal tokens; the same name elsewhere gives a different one. An empty value stays empty.

func (*Key) SealInline

func (k *Key) SealInline(plaintext []byte) []byte

SealInline seals a small file's whole content.

type Mode

type Mode string

Mode is the store policy's encryption requirement for new writes. An agent holding a store key seals whatever the mode.

const (
	// ModeSealed refuses agents without a store key.
	ModeSealed Mode = "sealed"
	// ModeNone also admits agents without a store key, which write in the
	// clear.
	ModeNone Mode = "none"
)

type Policy

type Policy struct {
	Version       uint32 `json:"version"`
	Mode          Mode   `json:"mode"`
	PresenceScope string `json:"presence_scope"`
}

Policy is the store's write policy, as the agent holds it.

func DefaultPolicy

func DefaultPolicy() Policy

DefaultPolicy seals everything and scopes presence to the store.

Jump to

Keyboard shortcuts

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