Files
HackBrowserData/cmd/hack-browser-data/dumpkeys.go
T
Roger c0a03769f1 fix: stop cleanly on Ctrl-C, SIGTERM, and SIGHUP (#668)
A signal killed the process mid-run and left the snapshot's copies of browser files in the temp dir.
The run now stops at its next step, removes them, and ends by the same signal, so the exit status and
calling scripts see what they did before. RFC-012 also keeps the list goldens in cmd.
2026-10-29 15:12:30 +08:00

53 lines
1.3 KiB
Go

package main
import (
"errors"
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/moond4rk/hackbrowserdata/internal/app"
"github.com/moond4rk/hackbrowserdata/internal/log"
)
func dumpKeysCmd() *cobra.Command {
var (
f app.Flags
outputPath string
)
cmd := &cobra.Command{
Use: "dumpkeys",
Short: "Export Chromium master keys as JSON for cross-host decryption",
Example: ` hack-browser-data dumpkeys -o keys.json
hack-browser-data dumpkeys -b chrome`,
RunE: func(cmd *cobra.Command, args []string) error {
req, err := app.ValidateKeys(f)
if err != nil {
return err
}
dump, err := app.DumpKeys(cmd.Context(), app.Discover(req), req)
if err != nil {
return err
}
log.Infof("Exported keys for %d vault(s)", len(dump.Vaults))
if outputPath == "" {
return dump.WriteJSON(os.Stdout)
}
file, err := os.OpenFile(outputPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)
if err != nil {
return fmt.Errorf("create %s: %w", outputPath, err)
}
return errors.Join(dump.WriteJSON(file), file.Close())
},
}
cmd.Flags().StringVarP(&f.Browser, "browser", "b", "all", "target browser: all|"+browserNames())
cmd.Flags().StringVarP(&outputPath, "output", "o", "", "output file (default: stdout)")
keychainPasswordFlags(cmd, &f)
return cmd
}