Files
core/trust/secret.go
T

32 lines
1.1 KiB
Go
Raw Normal View History

package trust
import (
"context"
"fmt"
"yetano.dev/yetano/core/secretref"
)
// KeyFromRef loads a signing key pair from a secret reference
// (secret://, env:, file:, base64: -- core/secretref), for example
// "secret://yabar/evidence/minisign" in yaseva. The value is a minisign
// private key file's contents. passwordRef ("" for none) is the
// reference of the password of an encrypted key. Error messages never
// contain the secret.
func KeyFromRef(ctx context.Context, r *secretref.Resolver, keyRef, passwordRef string) (KeyPair, error) {
data, err := r.Resolve(ctx, keyRef)
if err != nil {
return KeyPair{}, fmt.Errorf("signing key %s: %s", keyRef, r.Redact(err.Error()))
}
var password string
if passwordRef != "" {
if password, err = r.ResolveString(ctx, passwordRef); err != nil {
return KeyPair{}, fmt.Errorf("signing key password %s: %s", passwordRef, r.Redact(err.Error()))
}
}
kp, err := ParsePrivateKey(data, password)
if err != nil {
return KeyPair{}, fmt.Errorf("signing key %s: %s", keyRef, r.Redact(err.Error()))
}
return kp, nil
}