Skip to content

Add tamper-evident audit log (audit package, logx verify/keygen) - #1

Merged
AyoubTadlaoui merged 2 commits into
mainfrom
feat/audit-tamper-evident
Jun 7, 2026
Merged

Add tamper-evident audit log (audit package, logx verify/keygen)#1
AyoubTadlaoui merged 2 commits into
mainfrom
feat/audit-tamper-evident

Conversation

@AyoubTadlaoui

Copy link
Copy Markdown
Owner

Adds an audit subpackage: an append-only, hash-chained, optionally Ed25519-signed slog.Handler for tamper-evident logging, plus logx verify and logx keygen to check and key it.

What

  • audit.NewHandler writes each record as a hash-chained entry. hash = SHA-256(seq, prev, time, data), with each field length-prefixed so crafted input cannot shift the boundaries. Editing, deleting, reordering, or inserting a line breaks the chain at that entry.
  • With an Ed25519 signer, every entry is also signed, so entries cannot be re-forged into a clean chain without the private key.
  • audit.Verify / VerifyFile walk a log offline and report the first broken entry. audit.OpenFile resumes an existing chain across restarts.
  • logx verify [-pubkey k] file... checks integrity (exit 0 intact, 1 tampered, 2 unreadable). logx keygen writes an Ed25519 keypair. Existing logx pretty-print behavior is unchanged; the verbs dispatch only when they are the first argument.

Threat model

Detected: edits, deletes, reorders, insertions; with -pubkey, forgery or re-signing without the key.

Not detected on its own (documented in the package and README): dropping entries from the very end of the file, and a full rewrite of an unsigned log. Sign the log and keep the private key off the writing host; anchor the head hash externally if end-truncation is in scope.

Notes

  • Zero external dependencies. Standard library only (crypto/sha256, crypto/ed25519, crypto/rand, encoding/pem). No crypto/x509.
  • 106 test functions across the module pass under -race. gofmt -s, go vet, and golangci-lint are clean. Runnable example in examples/audit.

@AyoubTadlaoui
AyoubTadlaoui merged commit 24657fa into main Jun 7, 2026
3 checks passed
@AyoubTadlaoui
AyoubTadlaoui deleted the feat/audit-tamper-evident branch June 8, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant