From b655afd054cd6028ce0fafbaa4bd502b6ef87010 Mon Sep 17 00:00:00 2001 From: Roger Date: Tue, 27 Oct 2026 16:06:57 +0800 Subject: [PATCH] refactor: merge the browser tables into internal/browser (#654) One Def per browser carries every OS's user data dirs, keychain label, and Windows ABE target, so the per-OS lists and the abeTargets join go away and today's configs derive from it; a test parsing com_iid.c keeps the payload's table in step with the ABE rows. --- browser/abe_windows.go | 60 ----------- browser/browser_darwin.go | 95 ----------------- browser/browser_linux.go | 64 ------------ browser/browser_windows.go | 134 ++---------------------- browser/browser_windows_test.go | 40 ++----- browser/consts.go | 31 ------ browser/defs.go | 46 ++++++++ browser/keydump_test.go | 26 ++--- internal/browser/browser.go | 54 ++++++++++ internal/browser/browser_test.go | 131 +++++++++++++++++++++++ internal/browser/platform_darwin.go | 6 ++ internal/browser/platform_linux.go | 6 ++ internal/browser/platform_windows.go | 6 ++ internal/browser/table.go | 151 +++++++++++++++++++++++++++ rfcs/005-browser-definitions.md | 2 +- rfcs/011-testing-and-quality.md | 2 +- types/browser.go | 2 +- 17 files changed, 432 insertions(+), 424 deletions(-) delete mode 100644 browser/abe_windows.go delete mode 100644 browser/consts.go create mode 100644 browser/defs.go create mode 100644 internal/browser/browser.go create mode 100644 internal/browser/browser_test.go create mode 100644 internal/browser/platform_darwin.go create mode 100644 internal/browser/platform_linux.go create mode 100644 internal/browser/platform_windows.go create mode 100644 internal/browser/table.go diff --git a/browser/abe_windows.go b/browser/abe_windows.go deleted file mode 100644 index ae57c45..0000000 --- a/browser/abe_windows.go +++ /dev/null @@ -1,60 +0,0 @@ -//go:build windows - -package browser - -import "github.com/moond4rk/hackbrowserdata/internal/masterkey" - -// abeTarget is a Windows ABE browser's executable and elevation-service dialect, keyed by BrowserConfig.Key. -// It stays beside the browser table until browser.Def.Platform absorbs it. -type abeTarget struct { - exe string - fallbacks []string - kind masterkey.ABEKind -} - -var abeTargets = map[string]abeTarget{ - "chrome": { - exe: "chrome.exe", - fallbacks: []string{ - `%ProgramFiles%\Google\Chrome\Application\chrome.exe`, - `%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe`, - `%LocalAppData%\Google\Chrome\Application\chrome.exe`, - }, - kind: masterkey.ABEChromeBase, - }, - "chrome-beta": { - exe: "chrome.exe", - fallbacks: []string{ - `%ProgramFiles%\Google\Chrome Beta\Application\chrome.exe`, - `%ProgramFiles(x86)%\Google\Chrome Beta\Application\chrome.exe`, - `%LocalAppData%\Google\Chrome Beta\Application\chrome.exe`, - }, - kind: masterkey.ABEChromeBase, - }, - "edge": { - exe: "msedge.exe", - fallbacks: []string{ - `%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe`, - `%ProgramFiles%\Microsoft\Edge\Application\msedge.exe`, - }, - kind: masterkey.ABEEdge, - }, - "brave": { - exe: "brave.exe", - fallbacks: []string{ - `%ProgramFiles%\BraveSoftware\Brave-Browser\Application\brave.exe`, - `%ProgramFiles(x86)%\BraveSoftware\Brave-Browser\Application\brave.exe`, - `%LocalAppData%\BraveSoftware\Brave-Browser\Application\brave.exe`, - }, - kind: masterkey.ABEChromeBase, - }, - "coccoc": { - exe: "browser.exe", - fallbacks: []string{ - `%ProgramFiles%\CocCoc\Browser\Application\browser.exe`, - `%ProgramFiles(x86)%\CocCoc\Browser\Application\browser.exe`, - `%LocalAppData%\CocCoc\Browser\Application\browser.exe`, - }, - kind: masterkey.ABEChromeBase, - }, -} diff --git a/browser/browser_darwin.go b/browser/browser_darwin.go index 6dd72c9..fb58f79 100644 --- a/browser/browser_darwin.go +++ b/browser/browser_darwin.go @@ -14,103 +14,8 @@ import ( "github.com/moond4rk/hackbrowserdata/internal/keychain" "github.com/moond4rk/hackbrowserdata/internal/log" "github.com/moond4rk/hackbrowserdata/internal/masterkey" - "github.com/moond4rk/hackbrowserdata/types" ) -func platformBrowsers() []types.BrowserConfig { - return []types.BrowserConfig{ - { - Key: "chrome", - Name: chromeName, - Kind: types.Chromium, - KeychainLabel: "Chrome", - UserDataDir: homeDir + "/Library/Application Support/Google/Chrome", - }, - { - Key: "edge", - Name: edgeName, - Kind: types.Chromium, - KeychainLabel: "Microsoft Edge", - UserDataDir: homeDir + "/Library/Application Support/Microsoft Edge", - }, - { - Key: "chromium", - Name: chromiumName, - Kind: types.Chromium, - KeychainLabel: "Chromium", - UserDataDir: homeDir + "/Library/Application Support/Chromium", - }, - { - Key: "chrome-beta", - Name: chromeBetaName, - Kind: types.Chromium, - KeychainLabel: "Chrome", - UserDataDir: homeDir + "/Library/Application Support/Google/Chrome Beta", - }, - { - Key: "opera", - Name: operaName, - Kind: types.ChromiumOpera, - KeychainLabel: "Opera", - UserDataDir: homeDir + "/Library/Application Support/com.operasoftware.Opera", - }, - { - Key: "opera-gx", - Name: operaGXName, - Kind: types.ChromiumOpera, - KeychainLabel: "Opera", - UserDataDir: homeDir + "/Library/Application Support/com.operasoftware.OperaGX", - }, - { - Key: "vivaldi", - Name: vivaldiName, - Kind: types.Chromium, - KeychainLabel: "Vivaldi", - UserDataDir: homeDir + "/Library/Application Support/Vivaldi", - }, - { - Key: "coccoc", - Name: coccocName, - Kind: types.Chromium, - KeychainLabel: "CocCoc", - UserDataDir: homeDir + "/Library/Application Support/Coccoc", - }, - { - Key: "brave", - Name: braveName, - Kind: types.Chromium, - KeychainLabel: "Brave", - UserDataDir: homeDir + "/Library/Application Support/BraveSoftware/Brave-Browser", - }, - { - Key: "yandex", - Name: yandexName, - Kind: types.ChromiumYandex, - KeychainLabel: "Yandex", - UserDataDir: homeDir + "/Library/Application Support/Yandex/YandexBrowser", - }, - { - Key: "arc", - Name: arcName, - Kind: types.Chromium, - KeychainLabel: "Arc", - UserDataDir: homeDir + "/Library/Application Support/Arc/User Data", - }, - { - Key: "firefox", - Name: firefoxName, - Kind: types.Firefox, - UserDataDir: homeDir + "/Library/Application Support/Firefox/Profiles", - }, - { - Key: "safari", - Name: safariName, - Kind: types.Safari, - UserDataDir: homeDir + "/Library/Safari", - }, - } -} - // loginKeychainPath is the per-user login keychain the run reads Chromium v10 secrets from. func loginKeychainPath() string { home, err := os.UserHomeDir() diff --git a/browser/browser_linux.go b/browser/browser_linux.go index 8912ff5..df187d7 100644 --- a/browser/browser_linux.go +++ b/browser/browser_linux.go @@ -2,70 +2,6 @@ package browser -import ( - "github.com/moond4rk/hackbrowserdata/types" -) - -func platformBrowsers() []types.BrowserConfig { - return []types.BrowserConfig{ - { - Key: "chrome", - Name: chromeName, - Kind: types.Chromium, - KeychainLabel: "Chrome Safe Storage", - UserDataDir: homeDir + "/.config/google-chrome", - }, - { - Key: "edge", - Name: edgeName, - Kind: types.Chromium, - KeychainLabel: "Chromium Safe Storage", - UserDataDir: homeDir + "/.config/microsoft-edge", - }, - { - Key: "chromium", - Name: chromiumName, - Kind: types.Chromium, - KeychainLabel: "Chromium Safe Storage", - UserDataDir: homeDir + "/.config/chromium", - }, - { - Key: "chrome-beta", - Name: chromeBetaName, - Kind: types.Chromium, - KeychainLabel: "Chrome Safe Storage", - UserDataDir: homeDir + "/.config/google-chrome-beta", - }, - { - Key: "opera", - Name: operaName, - Kind: types.ChromiumOpera, - KeychainLabel: "Chromium Safe Storage", - UserDataDir: homeDir + "/.config/opera", - }, - { - Key: "vivaldi", - Name: vivaldiName, - Kind: types.Chromium, - KeychainLabel: "Chrome Safe Storage", - UserDataDir: homeDir + "/.config/vivaldi", - }, - { - Key: "brave", - Name: braveName, - Kind: types.Chromium, - KeychainLabel: "Brave Safe Storage", - UserDataDir: homeDir + "/.config/BraveSoftware/Brave-Browser", - }, - { - Key: "firefox", - Name: firefoxName, - Kind: types.Firefox, - UserDataDir: homeDir + "/.mozilla/firefox", - }, - } -} - // newCredentialInjector is a no-op on Linux: RetrieveAll runs the peanuts (v10) and D-Bus keyring (v11) // retrievers itself, and a Chromium browser builds the rest of its Locator from its own config. func newCredentialInjector(_ DiscoverOptions) browserInjector { diff --git a/browser/browser_windows.go b/browser/browser_windows.go index 8a84968..ad55750 100644 --- a/browser/browser_windows.go +++ b/browser/browser_windows.go @@ -3,134 +3,10 @@ package browser import ( + ibrowser "github.com/moond4rk/hackbrowserdata/internal/browser" "github.com/moond4rk/hackbrowserdata/internal/masterkey" - "github.com/moond4rk/hackbrowserdata/types" ) -func platformBrowsers() []types.BrowserConfig { - return []types.BrowserConfig{ - { - Key: "chrome", - Name: chromeName, - Kind: types.Chromium, - WindowsABE: true, - UserDataDir: homeDir + "/AppData/Local/Google/Chrome/User Data", - }, - { - Key: "edge", - Name: edgeName, - Kind: types.Chromium, - WindowsABE: true, - UserDataDir: homeDir + "/AppData/Local/Microsoft/Edge/User Data", - }, - { - Key: "chromium", - Name: chromiumName, - Kind: types.Chromium, - UserDataDir: homeDir + "/AppData/Local/Chromium/User Data", - }, - { - Key: "chrome-beta", - Name: chromeBetaName, - Kind: types.Chromium, - WindowsABE: true, - UserDataDir: homeDir + "/AppData/Local/Google/Chrome Beta/User Data", - }, - { - Key: "opera", - Name: operaName, - Kind: types.ChromiumOpera, - UserDataDir: homeDir + "/AppData/Roaming/Opera Software/Opera Stable", - }, - { - Key: "opera-gx", - Name: operaGXName, - Kind: types.ChromiumOpera, - UserDataDir: homeDir + "/AppData/Roaming/Opera Software/Opera GX Stable", - }, - { - Key: "vought", - Name: voughtName, - Kind: types.ChromiumOpera, - UserDataDir: homeDir + "/AppData/Roaming/Browser from Vought", - }, - { - Key: "vivaldi", - Name: vivaldiName, - Kind: types.Chromium, - UserDataDir: homeDir + "/AppData/Local/Vivaldi/User Data", - }, - { - Key: "coccoc", - Name: coccocName, - Kind: types.Chromium, - WindowsABE: true, - UserDataDir: homeDir + "/AppData/Local/CocCoc/Browser/User Data", - }, - { - Key: "brave", - Name: braveName, - Kind: types.Chromium, - WindowsABE: true, - UserDataDir: homeDir + "/AppData/Local/BraveSoftware/Brave-Browser/User Data", - }, - { - Key: "yandex", - Name: yandexName, - Kind: types.ChromiumYandex, - UserDataDir: homeDir + "/AppData/Local/Yandex/YandexBrowser/User Data", - }, - { - Key: "360x", - Name: speed360XName, - Kind: types.Chromium, - UserDataDir: homeDir + "/AppData/Local/360ChromeX/Chrome/User Data", - }, - { - Key: "360", - Name: speed360Name, - Kind: types.Chromium, - UserDataDir: homeDir + "/AppData/Local/360chrome/Chrome/User Data", - }, - { - Key: "qq", - Name: qqName, - Kind: types.Chromium, - UserDataDir: homeDir + "/AppData/Local/Tencent/QQBrowser/User Data", - }, - { - Key: "dc", - Name: dcName, - Kind: types.Chromium, - UserDataDir: homeDir + "/AppData/Local/DCBrowser/User Data", - }, - { - Key: "sogou", - Name: sogouName, - Kind: types.Chromium, - UserDataDir: homeDir + "/AppData/Local/Sogou/SogouExplorer/User Data", - }, - { - Key: "arc", - Name: arcName, - Kind: types.Chromium, - UserDataDir: homeDir + "/AppData/Local/Packages/TheBrowserCompany.Arc_*/LocalCache/Local/Arc/User Data", - }, - { - Key: "duckduckgo", - Name: duckduckgoName, - Kind: types.Chromium, - UserDataDir: homeDir + "/AppData/Local/Packages/DuckDuckGo.DesktopBrowser_*/LocalState/EBWebView", - }, - { - Key: "firefox", - Name: firefoxName, - Kind: types.Firefox, - UserDataDir: homeDir + "/AppData/Roaming/Mozilla/Firefox/Profiles", - }, - } -} - // newCredentialInjector hands each ABE browser its executable and dialect; RetrieveAll runs v10 (DPAPI) and, // when the Locator carries an ABE kind, v20 (reflective injection) — both, since an upgraded profile mixes them. func newCredentialInjector(_ DiscoverOptions) browserInjector { @@ -139,8 +15,12 @@ func newCredentialInjector(_ DiscoverOptions) browserInjector { if !ok { return } - if target, ok := abeTargets[km.BrowserKey()]; ok { - km.SetLocator(masterkey.Locator{Exe: target.exe, ExeFallbacks: target.fallbacks, ABE: target.kind}) + def, ok := ibrowser.Lookup(km.BrowserKey()) + if !ok { + return + } + if p := def.Platform(); p.ABE != masterkey.ABENone { + km.SetLocator(masterkey.Locator{Exe: p.Exe, ExeFallbacks: p.ExeFallbacks, ABE: p.ABE}) } } } diff --git a/browser/browser_windows_test.go b/browser/browser_windows_test.go index c3ec983..4f09c90 100644 --- a/browser/browser_windows_test.go +++ b/browser/browser_windows_test.go @@ -5,38 +5,10 @@ package browser import ( "testing" + ibrowser "github.com/moond4rk/hackbrowserdata/internal/browser" "github.com/moond4rk/hackbrowserdata/internal/masterkey" ) -// TestABETargetsCoverABEBrowsers verifies that the browsers with WindowsABE: true in platformBrowsers() -// are exactly the keys in abeTargets. A mismatch means adding a Chromium fork was incomplete: either a -// BrowserConfig row is missing WindowsABE: true, or abeTargets has a stale or missing entry. -func TestABETargetsCoverABEBrowsers(t *testing.T) { - abeConfigs := make(map[string]struct{}) - for _, b := range platformBrowsers() { - if b.WindowsABE { - abeConfigs[b.Key] = struct{}{} - } - } - - for key, target := range abeTargets { - if target.exe == "" { - t.Errorf("abeTargets[%q] has no executable name", key) - } - if target.kind == masterkey.ABENone { - t.Errorf("abeTargets[%q] declares no ABE kind", key) - } - if _, ok := abeConfigs[key]; !ok { - t.Errorf("abeTargets[%q] has an entry but no BrowserConfig with Key %q sets WindowsABE: true", key, key) - } - } - for key := range abeConfigs { - if _, ok := abeTargets[key]; !ok { - t.Errorf("BrowserConfig with Key %q sets WindowsABE: true but abeTargets[%q] is missing", key, key) - } - } -} - type locatorRecorder struct { mockChromiumBrowser got *masterkey.Locator @@ -53,9 +25,13 @@ func TestCredentialInjector_HandsABEBrowsersTheirTarget(t *testing.T) { if chrome.got == nil { t.Fatal("chrome got no Locator") } - want := abeTargets["chrome"] - if chrome.got.Exe != want.exe || chrome.got.ABE != want.kind || len(chrome.got.ExeFallbacks) != len(want.fallbacks) { - t.Errorf("chrome Locator = %+v, want exe %q, kind %v, %d fallbacks", *chrome.got, want.exe, want.kind, len(want.fallbacks)) + def, ok := ibrowser.Lookup("chrome") + if !ok { + t.Fatal("chrome is not in the browser table") + } + want := def.Platform() + if chrome.got.Exe != want.Exe || chrome.got.ABE != want.ABE || len(chrome.got.ExeFallbacks) != len(want.ExeFallbacks) { + t.Errorf("chrome Locator = %+v, want exe %q, kind %v, %d fallbacks", *chrome.got, want.Exe, want.ABE, len(want.ExeFallbacks)) } opera := &locatorRecorder{mockChromiumBrowser: mockChromiumBrowser{key: "opera"}} diff --git a/browser/consts.go b/browser/consts.go deleted file mode 100644 index 8bf826a..0000000 --- a/browser/consts.go +++ /dev/null @@ -1,31 +0,0 @@ -package browser - -import ( - "os" -) - -// home dir path for all platforms -var homeDir, _ = os.UserHomeDir() - -const ( - chromeName = "Chrome" - chromeBetaName = "Chrome Beta" - chromiumName = "Chromium" - edgeName = "Microsoft Edge" - braveName = "Brave" - operaName = "Opera" - operaGXName = "OperaGX" - voughtName = "Browser from Vought" - vivaldiName = "Vivaldi" - coccocName = "CocCoc" - yandexName = "Yandex" - firefoxName = "Firefox" - speed360Name = "360 Speed" - speed360XName = "360 Speed X" - qqName = "QQ" - dcName = "DC" - sogouName = "Sogou" - arcName = "Arc" - duckduckgoName = "DuckDuckGo" - safariName = "Safari" -) diff --git a/browser/defs.go b/browser/defs.go new file mode 100644 index 0000000..846f3d8 --- /dev/null +++ b/browser/defs.go @@ -0,0 +1,46 @@ +package browser + +import ( + "os" + + ibrowser "github.com/moond4rk/hackbrowserdata/internal/browser" + "github.com/moond4rk/hackbrowserdata/internal/masterkey" + "github.com/moond4rk/hackbrowserdata/types" +) + +var homeDir, _ = os.UserHomeDir() + +// platformBrowsers adapts this OS's rows of the browser table; joining with "/" keeps today's user data dir strings. +func platformBrowsers() []types.BrowserConfig { + var configs []types.BrowserConfig + for _, d := range ibrowser.Supported() { + p := d.Platform() + for _, dir := range p.UserDataDirs { + configs = append(configs, types.BrowserConfig{ + Key: d.ID, + Name: d.Name, + Kind: kindOf(d), + KeychainLabel: p.KeychainLabel, + WindowsABE: p.ABE != masterkey.ABENone, + UserDataDir: homeDir + "/" + dir, + }) + } + } + return configs +} + +// kindOf derives today's engine kind; Yandex and the Opera family are the forks with their own on-disk format. +func kindOf(d ibrowser.Def) types.BrowserKind { + switch { + case d.Base == ibrowser.Firefox: + return types.Firefox + case d.Base == ibrowser.Safari: + return types.Safari + case d.ID == "yandex": + return types.ChromiumYandex + case d.ID == "opera", d.ID == "opera-gx", d.ID == "vought": + return types.ChromiumOpera + default: + return types.Chromium + } +} diff --git a/browser/keydump_test.go b/browser/keydump_test.go index 6ef3830..c803300 100644 --- a/browser/keydump_test.go +++ b/browser/keydump_test.go @@ -19,6 +19,8 @@ const ( testProfile1 = "Profile 1" testUDD = "/p" testEdgeName = "Edge" + testChromeName = "Chrome" + testFirefoxName = "Firefox" ) // mockBrowser is one installation holding zero or more profile names. @@ -89,7 +91,7 @@ func TestBuildDump_Empty(t *testing.T) { func TestBuildDump_SingleChromium(t *testing.T) { b := &mockChromiumBrowser{ - mockBrowser: mockBrowser{name: chromeName, userDataDir: testUDD, profiles: []string{testProfileDefault}}, + mockBrowser: mockBrowser{name: testChromeName, userDataDir: testUDD, profiles: []string{testProfileDefault}}, keys: masterkey.Set{masterkey.V10: []byte("v10-key")}, } @@ -99,7 +101,7 @@ func TestBuildDump_SingleChromium(t *testing.T) { t.Fatalf("Vaults len = %d, want 1", len(dump.Vaults)) } inst := dump.Vaults[0] - if !strings.EqualFold(inst.Browser, chromeName) || inst.UserDataDir != testUDD { + if !strings.EqualFold(inst.Browser, testChromeName) || inst.UserDataDir != testUDD { t.Errorf("inst metadata = %+v", inst) } if inst.Kind != "chromium" { @@ -118,7 +120,7 @@ func TestBuildDump_SingleChromium(t *testing.T) { // key exactly once. func TestBuildDump_MultipleProfilesOneVault(t *testing.T) { b := &mockChromiumBrowser{ - mockBrowser: mockBrowser{name: chromeName, userDataDir: testUDD, profiles: []string{testProfileDefault, testProfile1}}, + mockBrowser: mockBrowser{name: testChromeName, userDataDir: testUDD, profiles: []string{testProfileDefault, testProfile1}}, keys: masterkey.Set{masterkey.V10: []byte("v10")}, } @@ -137,24 +139,24 @@ func TestBuildDump_MultipleProfilesOneVault(t *testing.T) { func TestBuildDump_SkipsNonKeyManager(t *testing.T) { chrome := &mockChromiumBrowser{ - mockBrowser: mockBrowser{name: chromeName, userDataDir: "/chrome", profiles: []string{testProfileDefault}}, + mockBrowser: mockBrowser{name: testChromeName, userDataDir: "/chrome", profiles: []string{testProfileDefault}}, keys: masterkey.Set{masterkey.V10: []byte("v10")}, } - firefox := &mockBrowser{name: firefoxName, userDataDir: "/ff", profiles: []string{"default-release"}} + firefox := &mockBrowser{name: testFirefoxName, userDataDir: "/ff", profiles: []string{"default-release"}} dump := BuildDump([]Browser{chrome, firefox}) if len(dump.Vaults) != 1 { t.Fatalf("Vaults len = %d, want 1 (firefox skipped)", len(dump.Vaults)) } - if !strings.EqualFold(dump.Vaults[0].Browser, chromeName) { - t.Errorf("Browser = %q, want %q", dump.Vaults[0].Browser, strings.ToLower(chromeName)) + if !strings.EqualFold(dump.Vaults[0].Browser, testChromeName) { + t.Errorf("Browser = %q, want %q", dump.Vaults[0].Browser, strings.ToLower(testChromeName)) } } func TestBuildDump_SkipsExportError(t *testing.T) { good := &mockChromiumBrowser{ - mockBrowser: mockBrowser{name: chromeName, userDataDir: "/chrome", profiles: []string{testProfileDefault}}, + mockBrowser: mockBrowser{name: testChromeName, userDataDir: "/chrome", profiles: []string{testProfileDefault}}, keys: masterkey.Set{masterkey.V10: []byte("v10")}, } failing := &mockChromiumBrowser{ @@ -167,14 +169,14 @@ func TestBuildDump_SkipsExportError(t *testing.T) { if len(dump.Vaults) != 1 { t.Fatalf("Vaults len = %d, want 1 (failing browser skipped)", len(dump.Vaults)) } - if !strings.EqualFold(dump.Vaults[0].Browser, chromeName) { - t.Errorf("Browser = %q, want %q", dump.Vaults[0].Browser, strings.ToLower(chromeName)) + if !strings.EqualFold(dump.Vaults[0].Browser, testChromeName) { + t.Errorf("Browser = %q, want %q", dump.Vaults[0].Browser, strings.ToLower(testChromeName)) } } func TestBuildDump_JSONRoundTrip(t *testing.T) { b := &mockChromiumBrowser{ - mockBrowser: mockBrowser{name: chromeName, userDataDir: testUDD, profiles: []string{testProfileDefault}}, + mockBrowser: mockBrowser{name: testChromeName, userDataDir: testUDD, profiles: []string{testProfileDefault}}, keys: masterkey.Set{masterkey.V10: []byte{0x01, 0x02, 0x03}, masterkey.V20: []byte{0xff, 0xee}}, } @@ -212,7 +214,7 @@ func TestBuildDump_JSONRoundTrip(t *testing.T) { func TestBuildDump_PartialKeys(t *testing.T) { b := &mockChromiumBrowser{ - mockBrowser: mockBrowser{name: chromeName, userDataDir: testUDD, profiles: []string{testProfileDefault}}, + mockBrowser: mockBrowser{name: testChromeName, userDataDir: testUDD, profiles: []string{testProfileDefault}}, keys: masterkey.Set{masterkey.V10: []byte("v10")}, exportErr: errors.New("v20: ABE failed"), } diff --git a/internal/browser/browser.go b/internal/browser/browser.go new file mode 100644 index 0000000..8cb20bc --- /dev/null +++ b/internal/browser/browser.go @@ -0,0 +1,54 @@ +// Package browser describes the browsers HBD knows: one Def per browser, with how it appears on each OS. +package browser + +import "github.com/moond4rk/hackbrowserdata/internal/masterkey" + +// Def is one browser HBD knows. ID is the -b value and the keys.json vault key; Name is stamped on every record. +type Def struct { + ID string + Name string + Base Base + + Darwin Platform + Linux Platform + Windows Platform +} + +// Base is what a browser is built on; it selects the base package and the key path. +type Base int + +const ( + Chromium Base = iota + 1 + Firefox + Safari +) + +// Platform is how one browser appears on one OS; a Platform without UserDataDirs means the OS is not supported. +type Platform struct { + UserDataDirs []string // slash-separated, relative to the home directory; globs allowed + KeychainLabel string // macOS Keychain account / Linux Secret Service label; "" = none + Exe string // Windows: the program the ABE payload is injected into + ExeFallbacks []string // Windows: program paths tried when the registry has no App Paths entry + ABE masterkey.ABEKind +} + +// Supported returns the browsers of the running OS, in table order. +func Supported() []Def { + var out []Def + for _, d := range defs { + if len(d.Platform().UserDataDirs) > 0 { + out = append(out, d) + } + } + return out +} + +// Lookup finds a browser by ID in the whole table, whatever the running OS, so restore resolves another host's vaults. +func Lookup(id string) (Def, bool) { + for _, d := range defs { + if d.ID == id { + return d, true + } + } + return Def{}, false +} diff --git a/internal/browser/browser_test.go b/internal/browser/browser_test.go new file mode 100644 index 0000000..0b559a1 --- /dev/null +++ b/internal/browser/browser_test.go @@ -0,0 +1,131 @@ +package browser + +import ( + "os" + "path" + "regexp" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/moond4rk/hackbrowserdata/internal/masterkey" +) + +var platformOf = map[string]func(Def) Platform{ + "darwin": func(d Def) Platform { return d.Darwin }, + "linux": func(d Def) Platform { return d.Linux }, + "windows": func(d Def) Platform { return d.Windows }, +} + +func idsOn(platform func(Def) Platform) []string { + var ids []string + for _, d := range defs { + if len(platform(d).UserDataDirs) > 0 { + ids = append(ids, d.ID) + } + } + return ids +} + +// Discovery order is output order: reordering the table reorders the records in every output file. +func TestTableOrderPerOS(t *testing.T) { + want := map[string][]string{ + "darwin": { + "chrome", "edge", "chromium", "chrome-beta", "opera", "opera-gx", "vivaldi", "coccoc", "brave", "yandex", "arc", + "firefox", "safari", + }, + "linux": {"chrome", "edge", "chromium", "chrome-beta", "opera", "vivaldi", "brave", "firefox"}, + "windows": { + "chrome", "edge", "chromium", "chrome-beta", "opera", "opera-gx", "vought", "vivaldi", "coccoc", "brave", "yandex", + "360x", "360", "qq", "dc", "sogou", "arc", "duckduckgo", "firefox", + }, + } + for goos, platform := range platformOf { + assert.Equal(t, want[goos], idsOn(platform), goos) + } +} + +func TestSupported_ListsThisOSRowsInTableOrder(t *testing.T) { + var ids []string + for _, d := range Supported() { + ids = append(ids, d.ID) + } + assert.Equal(t, idsOn(Def.Platform), ids) +} + +func TestLookup_FindsEveryRowWhateverTheOS(t *testing.T) { + for _, want := range defs { + got, ok := Lookup(want.ID) + require.True(t, ok, want.ID) + assert.Equal(t, want, got) + } + _, ok := Lookup("netscape") + assert.False(t, ok) +} + +func TestTableRows(t *testing.T) { + seen := make(map[string]bool) + for _, d := range defs { + assert.NotEmpty(t, d.ID) + assert.Falsef(t, seen[d.ID], "duplicate ID %q", d.ID) + seen[d.ID] = true + assert.NotEmpty(t, d.Name, d.ID) + assert.Contains(t, []Base{Chromium, Firefox, Safari}, d.Base, d.ID) + + for goos, platform := range platformOf { + for _, dir := range platform(d).UserDataDirs { + assert.Truef(t, dir != "" && !path.IsAbs(dir) && !strings.Contains(dir, `\`), + "%s %s: user data dir %q must be slash-separated and relative to the home dir", d.ID, goos, dir) + } + } + + w := d.Windows + if w.ABE == masterkey.ABENone { + assert.Emptyf(t, w.Exe, "%s: an executable is only used by ABE", d.ID) + assert.Emptyf(t, w.ExeFallbacks, "%s: executable fallbacks are only used by ABE", d.ID) + continue + } + assert.Equal(t, Chromium, d.Base, d.ID) + assert.NotEmpty(t, w.Exe, d.ID) + for _, fallback := range w.ExeFallbacks { + assert.Truef(t, strings.HasSuffix(strings.ToLower(fallback), `\`+strings.ToLower(w.Exe)), + "%s: fallback %q does not name %s", d.ID, fallback, w.Exe) + } + } +} + +// The payload looks a browser up by its executable inside the browser process, so its C table is the other half of each +// ABE row. It may list browsers the Go table does not. +func TestABERowsMatchPayloadTable(t *testing.T) { + src, err := os.ReadFile("../../crypto/windows/abe_native/com_iid.c") + require.NoError(t, err) + + kinds := map[string]masterkey.ABEKind{ + "BROWSER_CHROME_BASE": masterkey.ABEChromeBase, + "BROWSER_EDGE": masterkey.ABEEdge, + "BROWSER_AVAST": masterkey.ABEAvast, + } + payload := make(map[string]masterkey.ABEKind) + for _, m := range regexp.MustCompile(`"([^"]+\.exe)",\s*(BROWSER_\w+)`).FindAllStringSubmatch(string(src), -1) { + kind, ok := kinds[m[2]] + require.Truef(t, ok, "unknown payload browser kind %s", m[2]) + exe := strings.ToLower(m[1]) + if _, dup := payload[exe]; !dup { + payload[exe] = kind + } + } + require.NotEmpty(t, payload, "no rows parsed from com_iid.c") + + for _, d := range defs { + w := d.Windows + if w.ABE == masterkey.ABENone { + continue + } + kind, ok := payload[strings.ToLower(w.Exe)] + if assert.Truef(t, ok, "%s: com_iid.c has no row for %s", d.ID, w.Exe) { + assert.Equalf(t, w.ABE, kind, "%s: com_iid.c dispatches %s as another ABE kind", d.ID, w.Exe) + } + } +} diff --git a/internal/browser/platform_darwin.go b/internal/browser/platform_darwin.go new file mode 100644 index 0000000..eba17e7 --- /dev/null +++ b/internal/browser/platform_darwin.go @@ -0,0 +1,6 @@ +//go:build darwin + +package browser + +// Platform returns the running OS's entry. +func (d Def) Platform() Platform { return d.Darwin } diff --git a/internal/browser/platform_linux.go b/internal/browser/platform_linux.go new file mode 100644 index 0000000..2831ba1 --- /dev/null +++ b/internal/browser/platform_linux.go @@ -0,0 +1,6 @@ +//go:build linux + +package browser + +// Platform returns the running OS's entry. +func (d Def) Platform() Platform { return d.Linux } diff --git a/internal/browser/platform_windows.go b/internal/browser/platform_windows.go new file mode 100644 index 0000000..12f60fa --- /dev/null +++ b/internal/browser/platform_windows.go @@ -0,0 +1,6 @@ +//go:build windows + +package browser + +// Platform returns the running OS's entry. +func (d Def) Platform() Platform { return d.Windows } diff --git a/internal/browser/table.go b/internal/browser/table.go new file mode 100644 index 0000000..504e28aa --- /dev/null +++ b/internal/browser/table.go @@ -0,0 +1,151 @@ +package browser + +import "github.com/moond4rk/hackbrowserdata/internal/masterkey" + +// defs is in discovery order, which is also the order records reach the output files. +var defs = []Def{ + { + ID: "chrome", Name: "Chrome", Base: Chromium, + Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Google/Chrome"}, KeychainLabel: "Chrome"}, + Linux: Platform{UserDataDirs: []string{".config/google-chrome"}, KeychainLabel: "Chrome Safe Storage"}, + Windows: Platform{ + UserDataDirs: []string{"AppData/Local/Google/Chrome/User Data"}, + Exe: "chrome.exe", + ExeFallbacks: []string{ + `%ProgramFiles%\Google\Chrome\Application\chrome.exe`, + `%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe`, + `%LocalAppData%\Google\Chrome\Application\chrome.exe`, + }, + ABE: masterkey.ABEChromeBase, + }, + }, + { + ID: "edge", Name: "Microsoft Edge", Base: Chromium, + Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Microsoft Edge"}, KeychainLabel: "Microsoft Edge"}, + Linux: Platform{UserDataDirs: []string{".config/microsoft-edge"}, KeychainLabel: "Chromium Safe Storage"}, + Windows: Platform{ + UserDataDirs: []string{"AppData/Local/Microsoft/Edge/User Data"}, + Exe: "msedge.exe", + ExeFallbacks: []string{ + `%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe`, + `%ProgramFiles%\Microsoft\Edge\Application\msedge.exe`, + }, + ABE: masterkey.ABEEdge, + }, + }, + { + ID: "chromium", Name: "Chromium", Base: Chromium, + Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Chromium"}, KeychainLabel: "Chromium"}, + Linux: Platform{UserDataDirs: []string{".config/chromium"}, KeychainLabel: "Chromium Safe Storage"}, + Windows: Platform{UserDataDirs: []string{"AppData/Local/Chromium/User Data"}}, + }, + { + ID: "chrome-beta", Name: "Chrome Beta", Base: Chromium, + Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Google/Chrome Beta"}, KeychainLabel: "Chrome"}, + Linux: Platform{UserDataDirs: []string{".config/google-chrome-beta"}, KeychainLabel: "Chrome Safe Storage"}, + Windows: Platform{ + UserDataDirs: []string{"AppData/Local/Google/Chrome Beta/User Data"}, + Exe: "chrome.exe", + ExeFallbacks: []string{ + `%ProgramFiles%\Google\Chrome Beta\Application\chrome.exe`, + `%ProgramFiles(x86)%\Google\Chrome Beta\Application\chrome.exe`, + `%LocalAppData%\Google\Chrome Beta\Application\chrome.exe`, + }, + ABE: masterkey.ABEChromeBase, + }, + }, + { + ID: "opera", Name: "Opera", Base: Chromium, + Darwin: Platform{UserDataDirs: []string{"Library/Application Support/com.operasoftware.Opera"}, KeychainLabel: "Opera"}, + Linux: Platform{UserDataDirs: []string{".config/opera"}, KeychainLabel: "Chromium Safe Storage"}, + Windows: Platform{UserDataDirs: []string{"AppData/Roaming/Opera Software/Opera Stable"}}, + }, + { + ID: "opera-gx", Name: "OperaGX", Base: Chromium, + Darwin: Platform{UserDataDirs: []string{"Library/Application Support/com.operasoftware.OperaGX"}, KeychainLabel: "Opera"}, + Windows: Platform{UserDataDirs: []string{"AppData/Roaming/Opera Software/Opera GX Stable"}}, + }, + { + ID: "vought", Name: "Browser from Vought", Base: Chromium, + Windows: Platform{UserDataDirs: []string{"AppData/Roaming/Browser from Vought"}}, + }, + { + ID: "vivaldi", Name: "Vivaldi", Base: Chromium, + Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Vivaldi"}, KeychainLabel: "Vivaldi"}, + Linux: Platform{UserDataDirs: []string{".config/vivaldi"}, KeychainLabel: "Chrome Safe Storage"}, + Windows: Platform{UserDataDirs: []string{"AppData/Local/Vivaldi/User Data"}}, + }, + { + ID: "coccoc", Name: "CocCoc", Base: Chromium, + Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Coccoc"}, KeychainLabel: "CocCoc"}, + Windows: Platform{ + UserDataDirs: []string{"AppData/Local/CocCoc/Browser/User Data"}, + Exe: "browser.exe", + ExeFallbacks: []string{ + `%ProgramFiles%\CocCoc\Browser\Application\browser.exe`, + `%ProgramFiles(x86)%\CocCoc\Browser\Application\browser.exe`, + `%LocalAppData%\CocCoc\Browser\Application\browser.exe`, + }, + ABE: masterkey.ABEChromeBase, + }, + }, + { + ID: "brave", Name: "Brave", Base: Chromium, + Darwin: Platform{UserDataDirs: []string{"Library/Application Support/BraveSoftware/Brave-Browser"}, KeychainLabel: "Brave"}, + Linux: Platform{UserDataDirs: []string{".config/BraveSoftware/Brave-Browser"}, KeychainLabel: "Brave Safe Storage"}, + Windows: Platform{ + UserDataDirs: []string{"AppData/Local/BraveSoftware/Brave-Browser/User Data"}, + Exe: "brave.exe", + ExeFallbacks: []string{ + `%ProgramFiles%\BraveSoftware\Brave-Browser\Application\brave.exe`, + `%ProgramFiles(x86)%\BraveSoftware\Brave-Browser\Application\brave.exe`, + `%LocalAppData%\BraveSoftware\Brave-Browser\Application\brave.exe`, + }, + ABE: masterkey.ABEChromeBase, + }, + }, + { + ID: "yandex", Name: "Yandex", Base: Chromium, + Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Yandex/YandexBrowser"}, KeychainLabel: "Yandex"}, + Windows: Platform{UserDataDirs: []string{"AppData/Local/Yandex/YandexBrowser/User Data"}}, + }, + { + ID: "360x", Name: "360 Speed X", Base: Chromium, + Windows: Platform{UserDataDirs: []string{"AppData/Local/360ChromeX/Chrome/User Data"}}, + }, + { + ID: "360", Name: "360 Speed", Base: Chromium, + Windows: Platform{UserDataDirs: []string{"AppData/Local/360chrome/Chrome/User Data"}}, + }, + { + ID: "qq", Name: "QQ", Base: Chromium, + Windows: Platform{UserDataDirs: []string{"AppData/Local/Tencent/QQBrowser/User Data"}}, + }, + { + ID: "dc", Name: "DC", Base: Chromium, + Windows: Platform{UserDataDirs: []string{"AppData/Local/DCBrowser/User Data"}}, + }, + { + ID: "sogou", Name: "Sogou", Base: Chromium, + Windows: Platform{UserDataDirs: []string{"AppData/Local/Sogou/SogouExplorer/User Data"}}, + }, + { + ID: "arc", Name: "Arc", Base: Chromium, + Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Arc/User Data"}, KeychainLabel: "Arc"}, + Windows: Platform{UserDataDirs: []string{"AppData/Local/Packages/TheBrowserCompany.Arc_*/LocalCache/Local/Arc/User Data"}}, + }, + { + ID: "duckduckgo", Name: "DuckDuckGo", Base: Chromium, + Windows: Platform{UserDataDirs: []string{"AppData/Local/Packages/DuckDuckGo.DesktopBrowser_*/LocalState/EBWebView"}}, + }, + { + ID: "firefox", Name: "Firefox", Base: Firefox, + Darwin: Platform{UserDataDirs: []string{"Library/Application Support/Firefox/Profiles"}}, + Linux: Platform{UserDataDirs: []string{".mozilla/firefox"}}, + Windows: Platform{UserDataDirs: []string{"AppData/Roaming/Mozilla/Firefox/Profiles"}}, + }, + { + ID: "safari", Name: "Safari", Base: Safari, + Darwin: Platform{UserDataDirs: []string{"Library/Safari"}}, + }, +} diff --git a/rfcs/005-browser-definitions.md b/rfcs/005-browser-definitions.md index 6eccce6..5f7a716 100644 --- a/rfcs/005-browser-definitions.md +++ b/rfcs/005-browser-definitions.md @@ -135,7 +135,7 @@ For a genuinely new base (not Chromium/Firefox/Safari), you add a new `internal/ ## Consistency, enforced by tests -Folding `winutil.Table` into `Platform` removes the Go-side join, and with it the need for today's `TestWinUtilTableCoversABEBrowsers`: one struct cannot disagree with itself. What remains is the C side — the payload runs inside the browser process with no Go runtime, so its table stays in `com_iid.c`. A Go test inside `browser`, over the whole table, parses that file and fails when its set of executables and ABE kinds differs from the Windows entries whose `ABE` is not `ABENone` ([RFC-011](011-testing-and-quality.md)). A mismatch fails `go test`, not production. +Folding `winutil.Table` into `Platform` removes the Go-side join, and with it the need for today's `TestWinUtilTableCoversABEBrowsers`: one struct cannot disagree with itself. What remains is the C side — the payload runs inside the browser process with no Go runtime, so its table stays in `com_iid.c`. A Go test inside `browser`, over the whole table, parses that file and fails when a Windows entry whose `ABE` is not `ABENone` has no row there with the same executable and ABE kind; the C table may list browsers the Go table does not, such as Avast ([RFC-011](011-testing-and-quality.md)). A mismatch fails `go test`, not production. ## Why a table beats per-browser types diff --git a/rfcs/011-testing-and-quality.md b/rfcs/011-testing-and-quality.md index 5a81079..c9c8398 100644 --- a/rfcs/011-testing-and-quality.md +++ b/rfcs/011-testing-and-quality.md @@ -63,7 +63,7 @@ Each bug designed out by this rewrite gets a test that would have caught it, so ## Table and payload consistency - Every key in the Chromium override table resolves through `browser.Lookup` to a Chromium `Def`. -- The table's Windows rows with `ABE` other than `ABENone` and the rows of the payload's `com_iid.c` name the same executables and ABE kinds; the test parses the C table. It lives inside `browser` and reads the whole table, since `Supported()` lists only the running OS's rows. (The Go-side `winutil.Table` join, and the `TestWinUtilTableCoversABEBrowsers` that guarded it, disappear into `Platform`.) +- Every Windows row of the table with `ABE` other than `ABENone` has a row in the payload's `com_iid.c` with the same executable and ABE kind; the test parses the C table, which may list browsers the Go table does not, such as Avast. It lives inside `browser` and reads the whole table, since `Supported()` lists only the running OS's rows. (The Go-side `winutil.Table` join, and the `TestWinUtilTableCoversABEBrowsers` that guarded it, disappear into `Platform`.) ## Import direction diff --git a/types/browser.go b/types/browser.go index f85116a..1990e67 100644 --- a/types/browser.go +++ b/types/browser.go @@ -34,7 +34,7 @@ func (k BrowserKind) String() string { // BrowserConfig holds the declarative configuration for a browser installation. type BrowserConfig struct { - Key string // lookup key; doubles as the Windows ABE / abeTargets key when WindowsABE is true + Key string // Def.ID in internal/browser; the Windows injector looks the ABE target up by it Name string // display name Kind BrowserKind // engine type KeychainLabel string // macOS Keychain account / Linux D-Bus Secret Service label; "" = none