Documentation
¶
Overview ¶
Package secret encrypts what the base keeps of the notes (AES-256-GCM): a stolen base, backup or disk is unreadable without the server's key NOTES_SECRET. Not a compromised server: it holds the key. Each account has its own random key, kept in users.data_key sealed by NOTES_SECRET: changing NOTES_SECRET only seals those again (Rewrap), not every note.
Index ¶
- Constants
- Variables
- func Blind(userID, text string) (string, error)
- func BlindGrams(userID string, grams []string) ([]int16, error)
- func Forget(userID string)
- func Load(ctx context.Context, db bun.IDB, userID string) error
- func Open(value string) (string, error)
- func OpenBytes(userID string, data []byte) ([]byte, error)
- func Rewrap(wrapped, oldSecret string) (string, error)
- func SealBytes(userID string, data []byte) ([]byte, error)
- type Text
Constants ¶
const Prefix = "enc1:"
Prefix starts every sealed value, followed by the id of its account.
Variables ¶
var ( ErrNoKey = errors.New("NOTES_SECRET must be set to 32 random bytes in base64: openssl rand -base64 32") ErrNotLoaded = errors.New("the key of the account is not loaded") ErrCorrupt = errors.New("a value of the base cannot be decrypted: is NOTES_SECRET the one it was written with?") )
Functions ¶
func Blind ¶
Blind gives what the base keeps to find or keep unique a sealed text whatever its case: an HMAC of the text lowered, with the key of the account, loaded. The same text always gives the same value, of that account only.
func BlindGrams ¶
BlindGrams gives the blind of each gram (a few letters, at most 15 bytes) on 16 bits, sorted, each once: an AES block of the gram, with a key derived from the account's, loaded. Many grams share a value, so a search on them gives a few notes more to check (its index tells less too); tens of ns each, not the µs of an HMAC.
func Forget ¶
func Forget(userID string)
Forget drops the key of an account from memory, as a restart of the server does: tests replay a login before Load.
func Load ¶
Load reads the key of an account into memory, made on its first use: Seal and Open need it.