refactor: rename keys package to masterkey

"keys" was too generic — it collided with the keys local var, the keys.MasterKeys field, and the CLI keys subcommand. Folds in PickOptions→DiscoverOptions and browser/ comment cleanup.
This commit is contained in:
moonD4rk
2026-06-01 15:41:40 +08:00
parent c951d7ac16
commit 75b15c6fc4
44 changed files with 210 additions and 262 deletions
+10 -10
View File
@@ -7,8 +7,8 @@ import (
"time"
"github.com/moond4rk/hackbrowserdata/filemanager"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/log"
"github.com/moond4rk/hackbrowserdata/masterkey"
"github.com/moond4rk/hackbrowserdata/types"
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
)
@@ -17,11 +17,11 @@ import (
// that share a master key. The key is derived once and reused across profiles.
type Browser struct {
cfg types.BrowserConfig
retrievers keys.Retrievers
retrievers masterkey.Retrievers
profiles []*profile
keysOnce sync.Once
keys keys.MasterKeys
keys masterkey.MasterKeys
}
// NewBrowser discovers the profiles under cfg.UserDataDir, or returns nil if none resolve.
@@ -52,7 +52,7 @@ func NewBrowser(cfg types.BrowserConfig) (*Browser, error) {
// SetRetrievers wires the per-tier master-key retrievers (V10/V11/V20) used by
// Extract; unused tiers stay nil.
func (b *Browser) SetRetrievers(r keys.Retrievers) { b.retrievers = r }
func (b *Browser) SetRetrievers(r masterkey.Retrievers) { b.retrievers = r }
func (b *Browser) BrowserName() string { return b.cfg.Name }
func (b *Browser) UserDataDir() string { return b.cfg.UserDataDir }
@@ -93,19 +93,19 @@ func (b *Browser) CountEntries(categories []types.Category) ([]types.CountResult
// ExportKeys derives the master keys without extracting. Returns the tiers that succeeded plus a
// joined error for those that failed — partial results matter (a v20-only failure keeps the v10 key).
func (b *Browser) ExportKeys() (keys.MasterKeys, error) {
func (b *Browser) ExportKeys() (masterkey.MasterKeys, error) {
session, err := filemanager.NewSession()
if err != nil {
return keys.MasterKeys{}, err
return masterkey.MasterKeys{}, err
}
defer session.Cleanup()
return keys.NewMasterKeys(b.retrievers, b.buildHints(session))
return masterkey.NewMasterKeys(b.retrievers, b.buildHints(session))
}
// masterKeys derives and caches the installation's keys exactly once (sync.Once), so a failure is
// warned once — no cross-profile dedup state needed.
func (b *Browser) masterKeys() keys.MasterKeys {
func (b *Browser) masterKeys() masterkey.MasterKeys {
b.keysOnce.Do(func() {
masterKeys, err := b.ExportKeys()
if err != nil {
@@ -118,7 +118,7 @@ func (b *Browser) masterKeys() keys.MasterKeys {
// buildHints copies Local State into the session temp dir (so Windows DPAPI/ABE retrievers read it
// from a process-owned path) and assembles the Hints. Local State sits at the installation root.
func (b *Browser) buildHints(session *filemanager.Session) keys.Hints {
func (b *Browser) buildHints(session *filemanager.Session) masterkey.Hints {
var localStateDst string
candidate := filepath.Join(b.cfg.UserDataDir, "Local State")
if fileutil.FileExists(candidate) {
@@ -134,7 +134,7 @@ func (b *Browser) buildHints(session *filemanager.Session) keys.Hints {
if b.cfg.WindowsABE {
abeKey = b.cfg.Key
}
return keys.Hints{
return masterkey.Hints{
KeychainLabel: b.cfg.KeychainLabel,
WindowsABEKey: abeKey,
LocalStatePath: localStateDst,
+14 -14
View File
@@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/masterkey"
"github.com/moond4rk/hackbrowserdata/types"
)
@@ -380,20 +380,20 @@ func TestLocalStatePath(t *testing.T) {
// mockRetriever records the arguments passed to RetrieveKey.
type mockRetriever struct {
hints keys.Hints
hints masterkey.Hints
key []byte
err error
called bool
}
func (m *mockRetriever) RetrieveKey(hints keys.Hints) ([]byte, error) {
func (m *mockRetriever) RetrieveKey(hints masterkey.Hints) ([]byte, error) {
m.called = true
m.hints = hints
return m.key, m.err
}
func TestGetMasterKeys(t *testing.T) {
// getMasterKeys routes through keys.NewMasterKeys on every platform — the V10 mock
// getMasterKeys routes through masterkey.NewMasterKeys on every platform — the V10 mock
// wired via SetRetrievers(Retrievers{V10: mock}) is consulted cross-platform.
// Profile directory without Local State file.
@@ -405,7 +405,7 @@ func TestGetMasterKeys(t *testing.T) {
name string
dir string
keychainLabel string
retriever keys.Retriever // nil → don't call SetRetrievers
retriever masterkey.Retriever // nil → don't call SetRetrievers
wantV10 []byte
wantKeychainLabel string
wantLocalState bool // whether localStatePath passed to retriever is non-empty
@@ -442,7 +442,7 @@ func TestGetMasterKeys(t *testing.T) {
require.NotNil(t, b)
if tt.retriever != nil {
b.SetRetrievers(keys.Retrievers{V10: tt.retriever})
b.SetRetrievers(masterkey.Retrievers{V10: tt.retriever})
}
mk := b.masterKeys()
@@ -470,7 +470,7 @@ func TestGetMasterKeys(t *testing.T) {
// Before the refactor a Windows-only bypass meant only one tier's retriever was consulted, so a
// profile mixing prefixes silently lost the un-retrieved tier. After the refactor every
// configured tier must be called exactly once and its key must land in the matching MasterKeys
// slot. This catches any future "bypass the keys package for a faster path" regression and covers the
// slot. This catches any future "bypass the masterkey package for a faster path" regression and covers the
// analogous Linux v10/v11 case — no platform silently drops a tier any more.
func TestGetMasterKeys_AllTiersInvoked(t *testing.T) {
v10mock := &mockRetriever{key: []byte("fake-v10-key")}
@@ -483,7 +483,7 @@ func TestGetMasterKeys_AllTiersInvoked(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, b)
b.SetRetrievers(keys.Retrievers{V10: v10mock, V11: v11mock, V20: v20mock})
b.SetRetrievers(masterkey.Retrievers{V10: v10mock, V11: v11mock, V20: v20mock})
mk := b.masterKeys()
assert.Equal(t, []byte("fake-v10-key"), mk.V10, "V10 slot must be populated")
@@ -521,7 +521,7 @@ func TestGetMasterKeys_WindowsABEThreading(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, b)
b.SetRetrievers(keys.Retrievers{V20: mock})
b.SetRetrievers(masterkey.Retrievers{V20: mock})
b.masterKeys()
assert.Equal(t, tt.wantABEKey, mock.hints.WindowsABEKey)
@@ -540,8 +540,8 @@ func TestExtract(t *testing.T) {
tests := []struct {
name string
retriever keys.Retriever // nil → don't call SetRetriever
wantRetriever bool // whether retriever should be called
retriever masterkey.Retriever // nil → don't call SetRetriever
wantRetriever bool // whether retriever should be called
}{
{
name: "without retriever extracts unencrypted data",
@@ -562,7 +562,7 @@ func TestExtract(t *testing.T) {
require.NotNil(t, b)
if tt.retriever != nil {
b.SetRetrievers(keys.Retrievers{V10: tt.retriever})
b.SetRetrievers(masterkey.Retrievers{V10: tt.retriever})
}
results, err := b.Extract([]types.Category{types.History})
@@ -630,12 +630,12 @@ func TestCountEntries_NoRetrieverNeeded(t *testing.T) {
// ---------------------------------------------------------------------------
// SetRetrievers: verify *Browser satisfies the interface used by
// browser.pickFromConfigs for post-construction retriever injection.
// browser.discoverFromConfigs for post-construction retriever injection.
// ---------------------------------------------------------------------------
func TestSetRetrievers_SatisfiesInterface(t *testing.T) {
var _ interface {
SetRetrievers(keys.Retrievers)
SetRetrievers(masterkey.Retrievers)
} = (*Browser)(nil)
}
+2 -2
View File
@@ -4,7 +4,7 @@ import (
"fmt"
"github.com/moond4rk/hackbrowserdata/crypto"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/masterkey"
)
// decryptValue decrypts a Chromium-encrypted value by dispatching on the ciphertext's version
@@ -18,7 +18,7 @@ import (
// changes), so every applicable key must be populated upstream for lossless extraction. Missing
// tier keys surface as decrypt errors at the ciphertext level; the extract layer treats those as
// empty plaintexts rather than fatal errors.
func decryptValue(masterKeys keys.MasterKeys, ciphertext []byte) ([]byte, error) {
func decryptValue(masterKeys masterkey.MasterKeys, ciphertext []byte) ([]byte, error) {
if len(ciphertext) == 0 {
return nil, nil
}
+5 -5
View File
@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/moond4rk/hackbrowserdata/crypto"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/masterkey"
)
// TestDecryptValue_MixedTier is the regression test for mixed-cipher profiles (issue #578 on
@@ -33,7 +33,7 @@ func TestDecryptValue_MixedTier(t *testing.T) {
v20Ciphertext := append([]byte("v20"), append(nonce, gcmEnc...)...)
t.Run("all tiers populated: v20 picks V20, decrypts", func(t *testing.T) {
got, err := decryptValue(keys.MasterKeys{V10: k10, V11: k11, V20: k20}, v20Ciphertext)
got, err := decryptValue(masterkey.MasterKeys{V10: k10, V11: k11, V20: k20}, v20Ciphertext)
require.NoError(t, err)
assert.Equal(t, plaintext, got)
})
@@ -41,20 +41,20 @@ func TestDecryptValue_MixedTier(t *testing.T) {
t.Run("V20 holds wrong key: v20 still picks V20 slot (not V10/V11), errors", func(t *testing.T) {
// If the dispatcher incorrectly fell back to V10 or V11 when V20 had a wrong key, this
// would succeed. Proves the router uses prefix-based selection, not first-usable-key.
_, err := decryptValue(keys.MasterKeys{V10: k20, V11: k20, V20: k10}, v20Ciphertext)
_, err := decryptValue(masterkey.MasterKeys{V10: k20, V11: k20, V20: k10}, v20Ciphertext)
require.Error(t, err)
})
t.Run("only V20 populated: v20 still decrypts", func(t *testing.T) {
// The pre-#578 symmetric regression: when DPAPI/keyring failed and only V20 was retrieved,
// v20 cookies had to still decrypt. This asserts V10 and V11 being nil doesn't block v20.
got, err := decryptValue(keys.MasterKeys{V20: k20}, v20Ciphertext)
got, err := decryptValue(masterkey.MasterKeys{V20: k20}, v20Ciphertext)
require.NoError(t, err)
assert.Equal(t, plaintext, got)
})
t.Run("V20 slot unpopulated: v20 errors (no key to use)", func(t *testing.T) {
_, err := decryptValue(keys.MasterKeys{V10: k10, V11: k11}, v20Ciphertext)
_, err := decryptValue(masterkey.MasterKeys{V10: k10, V11: k11}, v20Ciphertext)
require.Error(t, err)
})
}
+5 -5
View File
@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/moond4rk/hackbrowserdata/crypto"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/masterkey"
)
func TestDecryptValue_V10(t *testing.T) {
@@ -40,7 +40,7 @@ func TestDecryptValue_V10(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := decryptValue(keys.MasterKeys{V10: tt.key}, v10Ciphertext)
got, err := decryptValue(masterkey.MasterKeys{V10: tt.key}, v10Ciphertext)
if tt.wantErrMsg != "" {
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErrMsg)
@@ -61,7 +61,7 @@ func TestDecryptValue_V11(t *testing.T) {
v11Ciphertext := append([]byte("v11"), cbcEncrypted...)
// v11 ciphertexts route to the V11 slot (Linux's keyring-derived kV11Key) — not V10 (peanuts).
got, err := decryptValue(keys.MasterKeys{V11: testAESKey}, v11Ciphertext)
got, err := decryptValue(masterkey.MasterKeys{V11: testAESKey}, v11Ciphertext)
require.NoError(t, err)
assert.Equal(t, plaintext, got)
}
@@ -87,7 +87,7 @@ func TestDecryptValue_V10_V11_SlotSeparation(t *testing.T) {
require.NoError(t, err)
v11Ciphertext := append([]byte("v11"), v11Enc...)
mk := keys.MasterKeys{V10: k10, V11: k11}
mk := masterkey.MasterKeys{V10: k10, V11: k11}
t.Run("v10 ciphertext decrypts via V10 slot", func(t *testing.T) {
got, err := decryptValue(mk, v10Ciphertext)
@@ -102,7 +102,7 @@ func TestDecryptValue_V10_V11_SlotSeparation(t *testing.T) {
})
t.Run("swapped keys fail both directions", func(t *testing.T) {
swapped := keys.MasterKeys{V10: k11, V11: k10}
swapped := masterkey.MasterKeys{V10: k11, V11: k10}
_, err := decryptValue(swapped, v10Ciphertext)
require.Error(t, err, "v10 with V11's key must fail")
_, err = decryptValue(swapped, v11Ciphertext)
+3 -3
View File
@@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/moond4rk/hackbrowserdata/crypto"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/masterkey"
)
// TestDecryptValue_V20 is cross-platform because v20's ciphertext format
@@ -24,13 +24,13 @@ func TestDecryptValue_V20(t *testing.T) {
// v20 layout: "v20" (3B) + nonce (12B) + ciphertext+tag
ciphertext := append([]byte("v20"), append(nonce, gcm...)...)
got, err := decryptValue(keys.MasterKeys{V20: testAESKey}, ciphertext)
got, err := decryptValue(masterkey.MasterKeys{V20: testAESKey}, ciphertext)
require.NoError(t, err)
assert.Equal(t, plaintext, got)
}
func TestDecryptValue_V20_ShortCiphertext(t *testing.T) {
// Missing nonce (prefix only) must error, not panic.
_, err := decryptValue(keys.MasterKeys{V20: testAESKey}, []byte("v20"))
_, err := decryptValue(masterkey.MasterKeys{V20: testAESKey}, []byte("v20"))
require.Error(t, err)
}
+3 -3
View File
@@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/moond4rk/hackbrowserdata/crypto"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/masterkey"
)
// encryptWithDPAPI encrypts data using Windows DPAPI (CryptProtectData).
@@ -64,7 +64,7 @@ func TestDecryptValue_V10_Windows(t *testing.T) {
// v10 format on Windows: "v10" + nonce(12) + encrypted
ciphertext := append([]byte("v10"), append(nonce, gcmEncrypted...)...)
got, err := decryptValue(keys.MasterKeys{V10: testAESKey}, ciphertext)
got, err := decryptValue(masterkey.MasterKeys{V10: testAESKey}, ciphertext)
require.NoError(t, err)
assert.Equal(t, plaintext, got)
}
@@ -78,7 +78,7 @@ func TestDecryptValue_DPAPI_Windows(t *testing.T) {
require.NotEmpty(t, encrypted)
// No v10/v20 prefix → decryptValue routes to DPAPI path; no per-tier key needed.
got, err := decryptValue(keys.MasterKeys{}, encrypted)
got, err := decryptValue(masterkey.MasterKeys{}, encrypted)
require.NoError(t, err)
assert.Equal(t, plaintext, got)
}
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"database/sql"
"sort"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/masterkey"
"github.com/moond4rk/hackbrowserdata/types"
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
)
@@ -18,7 +18,7 @@ const (
countCookieQuery = `SELECT COUNT(*) FROM cookies`
)
func extractCookies(masterKeys keys.MasterKeys, path string) ([]types.CookieEntry, error) {
func extractCookies(masterKeys masterkey.MasterKeys, path string) ([]types.CookieEntry, error) {
cookies, err := sqliteutil.QueryRows(path, false, defaultCookieQuery,
func(rows *sql.Rows) (types.CookieEntry, error) {
var (
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/masterkey"
)
func setupCookieDB(t *testing.T) string {
@@ -21,7 +21,7 @@ func setupCookieDB(t *testing.T) string {
func TestExtractCookies(t *testing.T) {
path := setupCookieDB(t)
got, err := extractCookies(keys.MasterKeys{}, path)
got, err := extractCookies(masterkey.MasterKeys{}, path)
require.NoError(t, err)
require.Len(t, got, 2)
+3 -3
View File
@@ -6,8 +6,8 @@ import (
"errors"
"github.com/moond4rk/hackbrowserdata/crypto"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/log"
"github.com/moond4rk/hackbrowserdata/masterkey"
"github.com/moond4rk/hackbrowserdata/types"
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
)
@@ -36,7 +36,7 @@ type yandexPrivateData struct {
SecretComment string `json:"secret_comment"`
}
func extractCreditCards(masterKeys keys.MasterKeys, path string) ([]types.CreditCardEntry, error) {
func extractCreditCards(masterKeys masterkey.MasterKeys, path string) ([]types.CreditCardEntry, error) {
cards, err := sqliteutil.QueryRows(path, false, defaultCreditCardQuery,
func(rows *sql.Rows) (types.CreditCardEntry, error) {
var guid, name, month, year, nickname, address string
@@ -62,7 +62,7 @@ func extractCreditCards(masterKeys keys.MasterKeys, path string) ([]types.Credit
}
// extractYandexCreditCards reads the records table (not Chromium's credit_cards). AAD = guid. See RFC-012 §4.
func extractYandexCreditCards(masterKeys keys.MasterKeys, path string) ([]types.CreditCardEntry, error) {
func extractYandexCreditCards(masterKeys masterkey.MasterKeys, path string) ([]types.CreditCardEntry, error) {
dataKey, err := loadYandexDataKey(path, masterKeys.V10)
if err != nil {
if errors.Is(err, errYandexMasterPasswordSet) {
+4 -4
View File
@@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/masterkey"
)
func setupCreditCardDB(t *testing.T) string {
@@ -21,7 +21,7 @@ func setupCreditCardDB(t *testing.T) string {
func TestExtractCreditCards(t *testing.T) {
path := setupCreditCardDB(t)
got, err := extractCreditCards(keys.MasterKeys{}, path)
got, err := extractCreditCards(masterkey.MasterKeys{}, path)
require.NoError(t, err)
require.Len(t, got, 2)
@@ -80,7 +80,7 @@ func TestExtractYandexCreditCards(t *testing.T) {
},
)
got, err := extractYandexCreditCards(keys.MasterKeys{V10: masterKey}, path)
got, err := extractYandexCreditCards(masterkey.MasterKeys{V10: masterKey}, path)
require.NoError(t, err)
require.Len(t, got, 2)
@@ -128,7 +128,7 @@ func TestExtractYandexCreditCards_WrongMasterKey(t *testing.T) {
yandexCreditCard{GUID: "g1", FullCardNumber: "4111"},
)
_, err := extractYandexCreditCards(keys.MasterKeys{V10: wrongKey}, path)
_, err := extractYandexCreditCards(masterkey.MasterKeys{V10: wrongKey}, path)
require.Error(t, err)
}
+4 -4
View File
@@ -6,8 +6,8 @@ import (
"sort"
"github.com/moond4rk/hackbrowserdata/crypto"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/log"
"github.com/moond4rk/hackbrowserdata/masterkey"
"github.com/moond4rk/hackbrowserdata/types"
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
)
@@ -20,11 +20,11 @@ const (
password_element, password_value, signon_realm, date_created FROM logins`
)
func extractPasswords(masterKeys keys.MasterKeys, path string) ([]types.LoginEntry, error) {
func extractPasswords(masterKeys masterkey.MasterKeys, path string) ([]types.LoginEntry, error) {
return extractPasswordsWithQuery(masterKeys, path, defaultLoginQuery)
}
func extractPasswordsWithQuery(masterKeys keys.MasterKeys, path, query string) ([]types.LoginEntry, error) {
func extractPasswordsWithQuery(masterKeys masterkey.MasterKeys, path, query string) ([]types.LoginEntry, error) {
logins, err := sqliteutil.QueryRows(path, false, query,
func(rows *sql.Rows) (types.LoginEntry, error) {
var url, username string
@@ -53,7 +53,7 @@ func extractPasswordsWithQuery(masterKeys keys.MasterKeys, path, query string) (
// extractYandexPasswords walks Ya Passman Data; protocol in RFC-012 §4.
// Note: URL column is origin_url — it's what the per-row AAD is computed over (not action_url).
func extractYandexPasswords(masterKeys keys.MasterKeys, path string) ([]types.LoginEntry, error) {
func extractYandexPasswords(masterKeys masterkey.MasterKeys, path string) ([]types.LoginEntry, error) {
dataKey, err := loadYandexDataKey(path, masterKeys.V10)
if err != nil {
if errors.Is(err, errYandexMasterPasswordSet) {
+5 -5
View File
@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/masterkey"
)
func setupLoginDB(t *testing.T) string {
@@ -22,7 +22,7 @@ func setupLoginDB(t *testing.T) string {
func TestExtractPasswords(t *testing.T) {
path := setupLoginDB(t)
got, err := extractPasswords(keys.MasterKeys{}, path)
got, err := extractPasswords(masterkey.MasterKeys{}, path)
require.NoError(t, err)
require.Len(t, got, 2)
@@ -70,7 +70,7 @@ func TestExtractYandexPasswords(t *testing.T) {
},
)
got, err := extractYandexPasswords(keys.MasterKeys{V10: masterKey}, path)
got, err := extractYandexPasswords(masterkey.MasterKeys{V10: masterKey}, path)
require.NoError(t, err)
require.Len(t, got, 2)
@@ -93,7 +93,7 @@ func TestExtractYandexPasswords_MasterPasswordSkipped(t *testing.T) {
},
)
got, err := extractYandexPasswords(keys.MasterKeys{V10: masterKey}, path)
got, err := extractYandexPasswords(masterkey.MasterKeys{V10: masterKey}, path)
require.NoError(t, err)
assert.Empty(t, got, "master-password profiles should be skipped in v1")
}
@@ -112,7 +112,7 @@ func TestExtractYandexPasswords_WrongMasterKey(t *testing.T) {
// A wrong master key fails at the intermediate step, surfacing as an error
// from the extractor.
_, err := extractYandexPasswords(keys.MasterKeys{V10: wrongKey}, path)
_, err := extractYandexPasswords(masterkey.MasterKeys{V10: wrongKey}, path)
require.Error(t, err)
}
+3 -3
View File
@@ -4,8 +4,8 @@ import (
"path/filepath"
"github.com/moond4rk/hackbrowserdata/filemanager"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/log"
"github.com/moond4rk/hackbrowserdata/masterkey"
"github.com/moond4rk/hackbrowserdata/types"
)
@@ -30,7 +30,7 @@ func (p *profile) label() string { return p.browserName + "/" + p.name() }
// extract copies the profile's source files to a temp directory and extracts the
// requested categories, decrypting with the installation's master keys.
func (p *profile) extract(masterKeys keys.MasterKeys, categories []types.Category) *types.BrowserData {
func (p *profile) extract(masterKeys masterkey.MasterKeys, categories []types.Category) *types.BrowserData {
session, err := filemanager.NewSession()
if err != nil {
log.Debugf("new session for %s: %v", p.label(), err)
@@ -91,7 +91,7 @@ func (p *profile) acquireFiles(session *filemanager.Session, categories []types.
// extractCategory calls the appropriate extract function for a category. A custom
// extractor (registered via extractorsForKind) takes precedence over the switch.
func (p *profile) extractCategory(data *types.BrowserData, cat types.Category, masterKeys keys.MasterKeys, path string) {
func (p *profile) extractCategory(data *types.BrowserData, cat types.Category, masterKeys masterkey.MasterKeys, path string) {
if ext, ok := p.extractors[cat]; ok {
if err := ext.extract(masterKeys, path, data); err != nil {
log.Debugf("extract %s for %s: %v", cat, p.label(), err)
+3 -3
View File
@@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/moond4rk/hackbrowserdata/filemanager"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/masterkey"
"github.com/moond4rk/hackbrowserdata/types"
)
@@ -32,7 +32,7 @@ func TestExtractCategory_CustomExtractor(t *testing.T) {
}
data := &types.BrowserData{}
p.extractCategory(data, types.Extension, keys.MasterKeys{}, "unused-path")
p.extractCategory(data, types.Extension, masterkey.MasterKeys{}, "unused-path")
assert.True(t, called, "custom extractor should be called")
require.Len(t, data.Extensions, 1)
@@ -51,7 +51,7 @@ func TestExtractCategory_DefaultFallback(t *testing.T) {
}
data := &types.BrowserData{}
p.extractCategory(data, types.History, keys.MasterKeys{}, path)
p.extractCategory(data, types.History, masterkey.MasterKeys{}, path)
require.Len(t, data.Histories, 1)
assert.Equal(t, "Example", data.Histories[0].Title)
+7 -7
View File
@@ -3,7 +3,7 @@ package chromium
import (
"path/filepath"
"github.com/moond4rk/hackbrowserdata/keys"
"github.com/moond4rk/hackbrowserdata/masterkey"
"github.com/moond4rk/hackbrowserdata/types"
)
@@ -51,15 +51,15 @@ func sourcesForKind(kind types.BrowserKind) map[types.Category][]sourcePath {
// switch logic, enabling browser-specific parsing (e.g. Opera's opsettings
// for extensions, Yandex's credit card table, QBCI-encrypted bookmarks).
type categoryExtractor interface {
extract(masterKeys keys.MasterKeys, path string, data *types.BrowserData) error
extract(masterKeys masterkey.MasterKeys, path string, data *types.BrowserData) error
}
// passwordExtractor wraps a custom password extract function.
type passwordExtractor struct {
fn func(masterKeys keys.MasterKeys, path string) ([]types.LoginEntry, error)
fn func(masterKeys masterkey.MasterKeys, path string) ([]types.LoginEntry, error)
}
func (e passwordExtractor) extract(masterKeys keys.MasterKeys, path string, data *types.BrowserData) error {
func (e passwordExtractor) extract(masterKeys masterkey.MasterKeys, path string, data *types.BrowserData) error {
var err error
data.Passwords, err = e.fn(masterKeys, path)
return err
@@ -70,7 +70,7 @@ type extensionExtractor struct {
fn func(path string) ([]types.ExtensionEntry, error)
}
func (e extensionExtractor) extract(_ keys.MasterKeys, path string, data *types.BrowserData) error {
func (e extensionExtractor) extract(_ masterkey.MasterKeys, path string, data *types.BrowserData) error {
var err error
data.Extensions, err = e.fn(path)
return err
@@ -79,10 +79,10 @@ func (e extensionExtractor) extract(_ keys.MasterKeys, path string, data *types.
// creditCardExtractor wraps a custom credit-card extract function, used by Yandex whose Ya Credit Cards DB stores
// rows as records(guid, public_data, private_data) with JSON blobs rather than Chromium's flat credit_cards table.
type creditCardExtractor struct {
fn func(masterKeys keys.MasterKeys, path string) ([]types.CreditCardEntry, error)
fn func(masterKeys masterkey.MasterKeys, path string) ([]types.CreditCardEntry, error)
}
func (e creditCardExtractor) extract(masterKeys keys.MasterKeys, path string, data *types.BrowserData) error {
func (e creditCardExtractor) extract(masterKeys masterkey.MasterKeys, path string, data *types.BrowserData) error {
var err error
data.CreditCards, err = e.fn(masterKeys, path)
return err