keymanager

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package keymanager provides KeyManager implementations.

The file-based adapter stores ECDSA P-256 keys on the local filesystem for zero-config development use. Each key is two PEM files:

<path>/<keyID>.key  — PKCS#8 private key (mode 0600)
<path>/<keyID>.pub  — PKIX public key

Production deployments should use cloud KMS adapters (AWS KMS, GCP KMS, Vault Transit). Those will be contributed by the community; the port interface is stable.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound          = errors.New("keymanager: key not found")
	ErrUnsupportedAlgorithm = errors.New("keymanager: unsupported algorithm")
	ErrKeyExists            = errors.New("keymanager: key already exists")
)

Errors returned by the file key manager.

Functions

func KeyFingerprint

func KeyFingerprint(pub crypto.PublicKey) string

KeyFingerprint returns a short identifier (first 8 bytes hex) of the given public key's PKIX SHA-256. Useful for log lines.

func PublicKeyToPEM

func PublicKeyToPEM(pub crypto.PublicKey) ([]byte, error)

PublicKeyToPEM returns the PKIX DER of pub wrapped in a PEM block with type "PUBLIC KEY". Safe for inclusion in text/plain responses (e.g. the TL /root-keys endpoint) and for pasting into config files.

Types

type FileKeyManager

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

FileKeyManager implements port.KeyManager with on-disk ECDSA/RSA keys.

func NewFileKeyManager

func NewFileKeyManager(dir string) (*FileKeyManager, error)

NewFileKeyManager opens (or creates) a filesystem key directory. The directory is created with 0700 permissions if it does not exist.

func (*FileKeyManager) CreateKey

func (f *FileKeyManager) CreateKey(ctx context.Context, algorithm string) (string, error)

CreateKey generates a new key pair with a random ID.

func (*FileKeyManager) EnsureKey

func (f *FileKeyManager) EnsureKey(ctx context.Context, keyID, algorithm string) (string, error)

EnsureKey is a convenience helper: if a key with the given ID already exists, it is returned; otherwise a new key is generated. Used at startup by ans-tl to auto-provision a signing key on first run.

func (*FileKeyManager) GetPublicKey

func (f *FileKeyManager) GetPublicKey(ctx context.Context, keyID string) (crypto.PublicKey, error)

GetPublicKey returns the public key for the given keyID.

func (*FileKeyManager) ListKeys

func (f *FileKeyManager) ListKeys(ctx context.Context) ([]string, error)

ListKeys returns the IDs of all keys in the directory.

func (*FileKeyManager) Sign

func (f *FileKeyManager) Sign(ctx context.Context, keyID string, data []byte) ([]byte, error)

Sign produces a signature over data using the key identified by keyID. ECDSA signatures are ASN.1-DER encoded; RSA uses PKCS#1 v1.5 with SHA-256.

func (*FileKeyManager) Verify

func (f *FileKeyManager) Verify(ctx context.Context, keyID string, data, signature []byte) (bool, error)

Verify validates the signature against data using the public key for keyID.

Jump to

Keyboard shortcuts

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