Repository navigation
feat: add Logger interface and --verbose CLI flag - #20
Conversation
Add a Logger interface to the library so callers can receive non-sensitive structural diagnostics during parsing and unlock. The CLI gains a -v/--verbose flag that prints table structure, DBBlob metadata, unlock progress, and per-type extraction summaries to stderr. Also fixes: - duplicate ErrWrongKey wrapping in error messages - empty password treated as "no unlock method" instead of a valid attempt - missing CSSM table names (SchemaIndexes, SchemaParsingModule, AppleSharePassword) - non-deterministic table log order (now sorted by ID) Closes #19
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #20 +/- ##
==========================================
+ Coverage 74.76% 75.81% +1.04%
==========================================
Files 5 6 +1
Lines 638 769 +131
==========================================
+ Hits 477 583 +106
- Misses 89 112 +23
- Partials 72 74 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds opt-in diagnostic logging to the keychainbreaker library and exposes it via a new -v/--verbose CLI flag to help troubleshoot unlock/parse failures without leaking sensitive material.
Changes:
- Introduces a
Loggerinterface with a default no-op implementation, plusWithLogger()to inject custom loggers. - Adds verbose CLI support (
-v/--verbose) that emits structural parse/unlock diagnostics to stderr. - Improves unlock behavior and diagnostics (empty password treated as set, deterministic table logging, additional CSSM table IDs, and removes duplicate
ErrWrongKeywrapping).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| unlock.go | Treats empty password as a valid attempt; adds unlock-stage logging. |
| parse.go | Adds missing CSSM table ID constants and clarifies comment. |
| logger.go | Adds Logger interface and default no-op logger. |
| keychainbreaker.go | Wires logger through Open/parse, logs parse/DBBlob/table info deterministically. |
| decrypt.go | Removes ErrWrongKey wrapping from padding errors to avoid duplicate wrapping upstream. |
| cmd/keychainbreaker/cmd/verbose.go | Implements CLI logger that prints structured log lines to stderr. |
| cmd/keychainbreaker/cmd/root.go | Adds -v/--verbose flag and wires it to WithLogger() during open. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // WithLogger sets a custom logger for diagnostic output. | ||
| // By default, the library is silent (no-op logger). | ||
| func WithLogger(l Logger) OpenOption { | ||
| return func(c *openConfig) { |
There was a problem hiding this comment.
WithLogger currently allows passing a nil Logger, which will propagate into parse()/Keychain and cause a panic when the code calls logger.Info/Debug/etc. Consider normalizing nil to a nop logger (either inside WithLogger, or in Open()/parse() by doing if logger == nil { logger = nopLogger{} }) so logging is always safe.
| return func(c *openConfig) { | |
| return func(c *openConfig) { | |
| // Treat a nil logger as "use the existing/default logger" (typically a no-op logger). | |
| if l == nil { | |
| return | |
| } |
| kc.logger.Info("master key derived", | ||
| "method", deriveMethod(&cfg), | ||
| "iterations", pbkdf2Iter, | ||
| "keyLen", len(masterKey), | ||
| ) |
There was a problem hiding this comment.
The unlock log always emits "iterations"=pbkdf2Iter even when the unlock method is a raw hex key (deriveMethod="hex-key"). This makes verbose diagnostics misleading. Consider only logging iterations when cfg.passwordSet is true (or omit/set it to 0 for non-PBKDF2 methods).
| kc.logger.Info("master key derived", | |
| "method", deriveMethod(&cfg), | |
| "iterations", pbkdf2Iter, | |
| "keyLen", len(masterKey), | |
| ) | |
| fields := []interface{}{ | |
| "method", deriveMethod(&cfg), | |
| "keyLen", len(masterKey), | |
| } | |
| if cfg.passwordSet { | |
| fields = append(fields, "iterations", pbkdf2Iter) | |
| } | |
| kc.logger.Info("master key derived", fields...) |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // WithLogger sets a custom logger for diagnostic output. | ||
| // By default, the library is silent (no-op logger). | ||
| func WithLogger(l Logger) OpenOption { | ||
| return func(c *openConfig) { | ||
| if l != nil { | ||
| c.logger = l | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
WithLogger only checks l != nil, but a typed-nil logger (e.g. var l *MyLogger = nil) will pass this check and overwrite the default nopLogger{} with a nil underlying value. That can lead to panics or lost logging when methods are invoked. Consider defensively treating typed-nil as nil (e.g. via reflection) or normalizing nil to nopLogger{} in Open/parse.
| b.WriteString(", ") | ||
| } | ||
| fmt.Fprintf(&b, "%v=%v", kv[i], kv[i+1]) | ||
| } |
There was a problem hiding this comment.
formatKV silently drops the last element when an odd number of key/value items is provided, which can hide diagnostics and make output confusing. Consider handling odd-length input explicitly (e.g. emit the dangling key with a placeholder value or append "").
| } | |
| } | |
| if len(kv)%2 == 1 { | |
| if len(kv) > 1 { | |
| b.WriteString(", ") | |
| } | |
| fmt.Fprintf(&b, "%v=%v", kv[len(kv)-1], "<missing>") | |
| } |
Summary
Loggerinterface to the library with Debug/Info/Warn/Error levels, defaulting to silent (no-op)WithLogger()OpenOption so callers can inject custom logger implementations-v/--verboseCLI flag that prints non-sensitive structural diagnostics to stderrErrWrongKeywrapping in error messagesCloses #19
Related: #18
Verbose output example
Test plan
golangci-lint run- 0 issuestypos- no typosgo test -v -race ./...- 34 tests passed-v-v-v