Moved from yet's internal/trust without changing behavior or file formats: KeyPair, GenerateKey, SaveKeyPair, LoadPrivateKey, ParsePrivateKey, LoadPublicKey, MarshalPublicKey, SignEd25519, VerifyEd25519, ExportPEM, ImportPEM, and the package signature as SignDigest. New: Sign and VerifyMessage, a detached minisign signature over any bytes and its check (returns the trusted comment; another key with a colliding ID fails), and KeyFromRef, a key pair from a core/secretref reference with error messages that never carry the secret. A golden vector (testdata/sign-vector.*) pins the output, and VerifySignature is tested against what SignDigest makes. For yabar's evidence signing (ADR-0037 there, owner decision Q-5 option A); yet keeps registry signing and its auto-sign key store. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
78 lines
3.6 KiB
Markdown
78 lines
3.6 KiB
Markdown
# yetano.dev/yetano/core/trust
|
|
|
|
The family's minisign (Ed25519) signatures: verifying, shared by every
|
|
program that pulls signed content -- yet (packages) and yacota (images)
|
|
check against the same files, so a host makes one trust decision -- and
|
|
signing, shared by every program that signs: yet (packages,
|
|
attestations) and yabar (evidence records, ADR-0037 there).
|
|
|
|
```text
|
|
module yetano.dev/yetano/core/trust tags: trust/v0.1.0, trust/v0.2.0, ... go 1.25
|
|
```
|
|
|
|
A nested module of the core repository, like `core/tui`, so the main core
|
|
module stays free of minisign. Depends on `aead.dev/minisign` (MIT) and
|
|
core (`core/paths`, for `Home`; `core/secretref`, for `KeyFromRef`).
|
|
Moved from `yet/internal/trust` without changing behavior or file
|
|
formats: the verifying half on 2026-11-12 (trust/v0.1.0), the signing
|
|
half on 2026-11-27 (trust/v0.2.0). Pushing signatures to a registry and
|
|
where auto-sign keeps its keys stay in yet.
|
|
|
|
## What it is
|
|
|
|
- **Signatures:** minisign (Ed25519) over the resolved OCI manifest
|
|
digest, as the JSON payload (`Signature`, media and artifact type
|
|
`application/vnd.yetano.signature.v1+json`) of an OCI 1.1 referrer
|
|
on that digest. `Verify(subjectDigest, payloads)` checks fetched
|
|
referrers (the caller fetches them with its own registry client);
|
|
valid signatures whose key IDs collide are made invalid.
|
|
- **Known keys** (`known-keys.json`, TOFU like SSH's known_hosts):
|
|
`Reconcile` pins a repository's first valid signer and refuses later
|
|
content signed only by other keys (an error that `errors.Is`
|
|
`ErrRefused`). A key is compared as the key (`SameKey`), never by its
|
|
ID alone.
|
|
- **Trust policy** (`trust-policy.json`, edited with `yet trust
|
|
policy`): rules per namespace pattern naming allowed keys,
|
|
`require_signatures`; `Evaluate`, `AllowsCapability`, `Curated`.
|
|
- **Where:** `Home(scope)` is yet's data directory (core/paths' DataDir
|
|
for "yet"), `DefaultPolicyPath(home)`, `DefaultKnownKeysPath(home)`.
|
|
|
|
- **Keys:** `KeyPair`, `GenerateKey`, `SaveKeyPair(path, kp, password)`
|
|
(private key owner-only, `<path>.pub` beside it; the minisign CLI's
|
|
formats, scrypt-encrypted with a password), `LoadPrivateKey`,
|
|
`ParsePrivateKey`, `LoadPublicKey`, `MarshalPublicKey`, and
|
|
`KeyFromRef(ctx, resolver, keyRef, passwordRef)` for a key held as a
|
|
secret reference (`secret://...` in yaseva, `env:`, `file:`).
|
|
- **Signing:** `SignDigest(kp, digest)` makes the package signature
|
|
`VerifySignature` checks; `Sign(kp, message, trustedComment,
|
|
untrustedComment)` makes a detached `.minisig` over any bytes, and
|
|
`VerifyMessage(pub, message, sig)` checks it and returns the trusted
|
|
comment (`minisign -Vm` checks it too); `SignEd25519`/`VerifyEd25519`
|
|
are plain Ed25519 for DSSE envelopes; `ExportPEM`/`ImportPEM` for
|
|
cosign and openssl.
|
|
- **Vector:** `testdata/sign-vector.*` -- a published test key, a
|
|
message and its signature; every version must produce and accept it.
|
|
|
|
## Use
|
|
|
|
```go
|
|
home, _ := trust.Home(core.UserScope)
|
|
verified := trust.Verify(manifestDigest, payloads) // fetched referrers
|
|
if err := trust.Reconcile(trust.DefaultKnownKeysPath(home), "registry/repo", verified); err != nil {
|
|
return err // errors.Is(err, trust.ErrRefused): the pinned key changed
|
|
}
|
|
policy, _ := trust.LoadPolicy(trust.DefaultPolicyPath(home))
|
|
if d := policy.Evaluate(name, kind, verified); !d.Trusted { ... }
|
|
```
|
|
|
|
Signing:
|
|
|
|
```go
|
|
kp, err := trust.KeyFromRef(ctx, secretref.New(""), "secret://yabar/evidence/minisign", "")
|
|
sig, err := trust.Sign(kp, recordBytes, "yabar evidence <test_id> <repository_id>", "")
|
|
comment, err := trust.VerifyMessage(pub, recordBytes, sig)
|
|
```
|
|
|
|
`Warn` (a variable) reports warnings that are not errors, on standard
|
|
error by default.
|