mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
refactor: pass secrets as values, fetched once per scope (#713)
* refactor: pass secrets as values, fetched once per scope A master key travelled through five layers of function values and three sync.Once guarded reuse; holding each secret where its scope lives shows where it comes from. Only the keychain prompt still waits for first use. * docs(rfcs): fetch secrets per extraction, not per record
This commit is contained in:
1 parent
a734e777a8
commit
f36790d4dd
41 files changed
+285
-388
No files matched your search
@@ -42,10 +42,13 @@ func newDumpCommand() *cobra.Command {
|
||||
}
|
||||
|
||||
func runDump(ctx context.Context, stderr io.Writer, flags app.DumpFlags, keychain, firefox passwordFlags) error {
|
||||
options, err := app.ValidateDump(flags, keychainPasswordFunc(keychain, os.Stdin), firefoxPasswordFunc(firefox, os.Stdin))
|
||||
options, err := app.ValidateDump(flags, keychainPasswordFunc(keychain, os.Stdin))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if options.FirefoxPrimaryPassword, err = readFirefoxPassword(ctx, firefox, os.Stdin); err != nil {
|
||||
return err
|
||||
}
|
||||
discovery, summary, err := app.Dump(ctx, options)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/term"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/keychain"
|
||||
)
|
||||
|
||||
// passwordFlags say where one password comes from: its flag, or the first line of stdin. Neither leaves it to the
|
||||
@@ -27,25 +29,18 @@ func addPasswordFlags(command *cobra.Command, flags *passwordFlags, name, what s
|
||||
command.MarkFlagsMutuallyExclusive(name, name+"-stdin")
|
||||
}
|
||||
|
||||
// firefoxPasswordFunc reads a flag, else the first line of stdin; nil means the empty password, and it never prompts.
|
||||
func firefoxPasswordFunc(flags passwordFlags, stdin *os.File) func(context.Context) (string, error) {
|
||||
switch {
|
||||
case flags.value != "":
|
||||
password := flags.value
|
||||
return func(context.Context) (string, error) { return password, nil }
|
||||
case flags.fromStdin:
|
||||
return func(ctx context.Context) (string, error) {
|
||||
return untilDone(ctx, func() (string, error) { return firstLine(stdin) })
|
||||
}
|
||||
default:
|
||||
return nil
|
||||
// readFirefoxPassword takes the flag, else the first line of stdin; "" is the empty password, and it never prompts.
|
||||
func readFirefoxPassword(ctx context.Context, flags passwordFlags, stdin io.Reader) (string, error) {
|
||||
if flags.fromStdin {
|
||||
return untilDone(ctx, func() (string, error) { return firstLine(stdin) })
|
||||
}
|
||||
return flags.value, nil
|
||||
}
|
||||
|
||||
var errNoPassword = errors.New("macOS login password not given and stdin is not a terminal")
|
||||
|
||||
// keychainPasswordFunc is read lazily: a flag, else a no-echo prompt on a terminal, else none (metadata only).
|
||||
func keychainPasswordFunc(flags passwordFlags, stdin *os.File) func(context.Context) (string, error) {
|
||||
func keychainPasswordFunc(flags passwordFlags, stdin *os.File) keychain.PasswordFunc {
|
||||
switch {
|
||||
case flags.value != "":
|
||||
password := flags.value
|
||||
|
||||
Reference in new issue
Block a user