keyring

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package keyring holds a keyring and the load checks of SPEC.md section 10.2, step 0 (CONFIGURATION), which every keyring the verifier loads passes before any key in it can bind (sections 8.3 (External verifiers) and 9 (What a verifier pins)). It is the one loader for every keyring a run loads: the compiled pin, a keyring file, a configured keyring, and, online, a keyring read from www.truestamp.com or from the origin an explicit --base-url names; a test holds the compiled pin to it too.

Load reads a keyring's bytes under the parsing rules of section 10.1 (J1 to J6, with internal/strictjson), then makes exactly the checks of section 10.2, step 0, and no others (no [L]A check):

  1. the keyring is an object with exactly two members, keys, an array, and version, the string "1.0";
  2. each element of keys is an object with exactly active (a boolean), key_id (KID), public_key (B64U32) and sequence (INT);
  3. each key_id is the key id of its public_key (section 3.3);
  4. no two keys share a public_key or a key_id;
  5. each public_key passes the checks of a key's bytes (section 6.2): its y is below 2^255 - 19, and it is not one of SMALL_ORDER_KEYS;
  6. no key is VECTOR_KEY unless E_v is test;
  7. in a production keyring, no key is in spec/keys.nonproduction.json.

A production keyring is any keyring loaded in a run whose E_v is prod, whatever its source, a keyring file included (section 6.4 (The environment marker)), so check 7 applies exactly when the environment Load is given is prod.

Each check is made over every key before the next check, so a keyring with two defects is named by the earlier check of the list above. An order that names the first key that fails and the first check it fails refuses exactly the same keyrings, and SPEC.md fixes no order. A key's public key is a [32]byte, and a failure also names the index of the key that fails. A keyring Load loads holds its digest d (section 8.3), made by Digest from the bytes as read (digest.go). LoadValue makes the same checks over a value already read, which has no bytes and so no digest: the keyring a conformance case's replay file answers a keyring read with (section 13.2 (The vectors)).

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownEnvironment = errors.New("keyring: not an environment a verifier knows")

ErrUnknownEnvironment marks a call of Load with an environment that is not an E_v (SPEC.md section 6.4), a defect in the caller.

Functions

func CompiledPin

func CompiledPin() []byte

CompiledPin returns the bytes of the compiled pin, spec/keyring.production.json as built in (SPEC.md section 8.3). A run loads it through Load under prod, as it loads every keyring.

func Digest

func Digest(data []byte) string

Digest returns d, the lowercase hex SHA-256 of data, a keyring's bytes as read.

func NonproductionKeys

func NonproductionKeys() [][32]byte

NonproductionKeys returns the 32-octet keys of spec/keys.nonproduction.json, in the file's order.

func VectorKey

func VectorKey() [32]byte

VectorKey returns VECTOR_KEY (SPEC.md section 9) as its 32 octets.

Types

type Check

type Check int

Check names a load check, by the order of the package's list.

const (
	// CheckJSON: the bytes break a parsing rule of SPEC.md section 10.1.
	CheckJSON Check = iota + 1
	// CheckKeyringMembers is check 1.
	CheckKeyringMembers
	// CheckKeyMembers is check 2.
	CheckKeyMembers
	// CheckKeyID is check 3.
	CheckKeyID
	// CheckRepeatedPublicKey and CheckRepeatedKeyID are check 4.
	CheckRepeatedPublicKey
	CheckRepeatedKeyID
	// CheckYNotBelowP and CheckSmallOrderKey are check 5.
	CheckYNotBelowP
	CheckSmallOrderKey
	// CheckVectorKey is check 6.
	CheckVectorKey
	// CheckNonproductionKey is check 7.
	CheckNonproductionKey
)

The load checks a keyring can fail.

type Failure

type Failure struct {
	Check Check
	// Key is the index in keys of the key that fails, or -1 for a check of
	// the keyring as a whole (CheckJSON, CheckKeyringMembers). For a
	// repeat, it is the later of the two keys.
	Key int
	// Rejection is the parsing rule the bytes break, for CheckJSON.
	Rejection *strictjson.Rejection
}

Failure is the load check a keyring fails.

func (*Failure) Describe

func (f *Failure) Describe() string

Describe is a plain sentence saying which load check f names, for the message of configuration_error, which carries no sub_reason.

func (*Failure) Error

func (f *Failure) Error() string

Error describes the failure, as Failure.Describe does.

type Key

type Key struct {
	Active bool
	// KeyID is the key id of PublicKey, 8 lowercase hex characters (KID).
	KeyID string
	// PublicKey is the key's 32 octets.
	PublicKey [32]byte
	// Sequence is an INT: an integer from 0 to MAX_INTEGER.
	Sequence int64
}

Key is one key of a loaded keyring.

type Keyring

type Keyring struct {
	Keys     []Key
	Digest   string
	Location string
}

Keyring is a keyring that passed the load checks: its keys in the file's order; Digest, d, the lowercase hex SHA-256 of the bytes it was loaded from as read (SPEC.md section 8.3); and Location, the file or URL it came from, or "" when it came from neither.

func Load

func Load(data []byte, environment string, location string) (*Keyring, error)

Load loads the keyring whose bytes are data in a run whose E_v is environment, with the checks of the package's list: the keyring, or a *Failure naming the first check that fails. location names where the bytes came from, for trust_root (SPEC.md section 10.5), or is "". The keyring's Digest is d of data.

func LoadValue

func LoadValue(value any, environment string, location string) (*Keyring, error)

LoadValue makes checks 1 to 7 over value, a keyring already read under SPEC.md section 10.1 into the strict reader's values, in a run whose E_v is environment: the keyring, or a *Failure naming the first check that fails. Such a value has no bytes of its own, so the keyring's Digest is "", which trust_root writes as null (section 10.5). It loads the keyring a conformance case's replay file answers a keyring read with (SPEC.md section 13.2 (The vectors): a value the load checks then judge).

func (*Keyring) Find

func (k *Keyring) Find(publicKey [32]byte) (Key, bool)

Find returns the key of k whose 32 octets equal publicKey, and whether there is one. Only the full comparison binds (SPEC.md section 6.1): no key id is read.

Jump to

Keyboard shortcuts

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