secret

package
v0.0.0-...-4d14c86 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 17 Imported by: 0

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

View Source
const Prefix = "enc1:"

Prefix starts every sealed value, followed by the id of its account.

Variables

View Source
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

func Blind(userID, text string) (string, error)

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

func BlindGrams(userID string, grams []string) ([]int16, error)

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

func Load(ctx context.Context, db bun.IDB, userID string) error

Load reads the key of an account into memory, made on its first use: Seal and Open need it.

func Open

func Open(value string) (string, error)

Open decrypts what Seal gave, its account's key loaded.

func OpenBytes

func OpenBytes(userID string, data []byte) ([]byte, error)

OpenBytes decrypts what SealBytes gave.

func Rewrap

func Rewrap(wrapped, oldSecret string) (string, error)

Rewrap gives back the key of an account sealed by oldSecret, sealed by NOTES_SECRET instead; unchanged when NOTES_SECRET opens it already.

func SealBytes

func SealBytes(userID string, data []byte) ([]byte, error)

SealBytes encrypts the bytes of a file with the key of the account, loaded: nonce then ciphertext, no base64.

Types

type Text

type Text string

Text is a string the base keeps sealed: bun opens it on scan. To write one, Seal it: bun refuses it in clear.

func Seal

func Seal(userID, text string) (Text, error)

Seal encrypts text with the key of the account, loaded: the same text never gives the same value twice.

func (*Text) Scan

func (t *Text) Scan(src any) error

func (Text) Value

func (t Text) Value() (driver.Value, error)

Value writes "" as NULL.

Jump to

Keyboard shortcuts

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