oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import "amadan.net/rastrillo/rastrillo/crypto"
4
5// Sealer encrypts what Base keeps for a member's Equipo device (its
6// private key, its secret and its bearer) at rest. The key is derived
7// from BASE_INSTANCE_KEY with HKDF-SHA256, separately for each member, and
8// the cipher is AES-256-GCM (rastrillo's crypto.SealSym): a sealed blob
9// opens only for the member it was sealed for, under the same instance
10// key. Changing BASE_INSTANCE_KEY disconnects everyone from Equipo.
11type Sealer struct{ key []byte }
12
13// NewSealer derives the sealing key from the instance key.
14func NewSealer(instanceKey string) Sealer {
15 return Sealer{key: crypto.Derive([]byte(instanceKey), "base/equipo-device/v1")}
16}
17
18func (s Sealer) member(id string) []byte { return crypto.Derive(s.key, "member/"+id) }
19
20// Seal encrypts plaintext for member id.
21func (s Sealer) Seal(id string, plaintext []byte) ([]byte, error) {
22 return crypto.SealSym(s.member(id), plaintext)
23}
24
25// Open decrypts a blob Seal made for member id.
26func (s Sealer) Open(id string, sealed []byte) ([]byte, error) {
27 return crypto.OpenSym(s.member(id), sealed)
28}
29