Documentation
¶
Overview ¶
Package pseudonym is the keyed-HMAC destination pseudonymizer behind the traffic-redaction posture (ADR-0044). A Pseudonymizer owns one node-local 32-byte key, its non-secret generation id, and a pool of key-bound HMACs. Tokens are "h_" + 12 lowercase hex characters of HMAC-SHA256 over the host-only normalized destination; they are a persisted, correlatable identifier, so the algorithm and output are byte-stable.
Fail-closed: with no key installed Pseudonymize returns Sentinel, never the plaintext. Package main owns the instance, the posture flag (decRedactHosts), persistence of the key/id in admin settings, and every call site; this package owns only the key state and the token derivation. It holds no package-level state, starts no goroutines and does no I/O or logging.
Index ¶
- Constants
- func ReplaceHostFold(s, host, tok string) string
- type Pseudonymizer
- func (p *Pseudonymizer) Ensure() error
- func (p *Pseudonymizer) Key() []byte
- func (p *Pseudonymizer) KeyID() string
- func (p *Pseudonymizer) MintPair() (key []byte, id string, err error)
- func (p *Pseudonymizer) Pseudonymize(host string) string
- func (p *Pseudonymizer) Rotate() error
- func (p *Pseudonymizer) Set(k []byte)
- func (p *Pseudonymizer) SetPair(k []byte, id string)
Constants ¶
const ( // Sentinel is the fail-closed value: key missing, never plaintext. Sentinel = "redacted" // Prefix is the keyed-HMAC destination token prefix. Prefix = "h_" // KeyLen is the required HMAC key length in bytes. KeyLen = 32 )
Variables ¶
This section is empty.
Functions ¶
func ReplaceHostFold ¶
ReplaceHostFold replaces every WHOLE-hostname (case-insensitive) occurrence of host in s with tok. "Whole" = not flanked by another host-label byte, so "ex.com" does not match inside "complex.com". The unmatched remainder keeps its original casing.
Types ¶
type Pseudonymizer ¶
type Pseudonymizer struct {
// contains filtered or unexported fields
}
Pseudonymizer is an instance-owned keyed pseudonymizer. The zero value is not usable; construct with New. Safe for concurrent use.
func New ¶
func New() *Pseudonymizer
New returns a Pseudonymizer with no key installed (fail-closed).
func (*Pseudonymizer) Ensure ¶
func (p *Pseudonymizer) Ensure() error
Ensure publishes a fresh key iff no full-length key exists.
func (*Pseudonymizer) Key ¶
func (p *Pseudonymizer) Key() []byte
Key returns the active key (nil if unset). Callers must treat it as read-only.
func (*Pseudonymizer) KeyID ¶
func (p *Pseudonymizer) KeyID() string
KeyID returns the non-secret generation id ("" when no key is installed).
func (*Pseudonymizer) MintPair ¶
func (p *Pseudonymizer) MintPair() (key []byte, id string, err error)
MintPair mints a fresh (key, id) pair WITHOUT publishing it, for persist-before-apply callers that publish via SetPair only after their write lands.
func (*Pseudonymizer) Pseudonymize ¶
func (p *Pseudonymizer) Pseudonymize(host string) string
Pseudonymize returns the keyed token for a host (port/case/trailing dot normalized away), or Sentinel when no key is installed. Empty input stays empty. It never returns the plaintext.
func (*Pseudonymizer) Rotate ¶
func (p *Pseudonymizer) Rotate() error
Rotate publishes a FRESH key unconditionally; correlation with pre-rotation records is intentionally broken.
func (*Pseudonymizer) Set ¶
func (p *Pseudonymizer) Set(k []byte)
Set publishes the key (copying the input) with a freshly minted id. An empty key clears it, so Pseudonymize fails closed.
func (*Pseudonymizer) SetPair ¶
func (p *Pseudonymizer) SetPair(k []byte, id string)
SetPair publishes a (key, id) pair with one pointer store, so a reader can never pair a new key with an old id. An empty key clears the state and burns a generation so pooled hashers for the old key are stale.