mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
Crypto stays free of OS calls, so every secret-store read sits behind one masterkey contract. The macOS v10 retriever reads one run-scoped login keychain handle that Safari will share.
88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
//go:build linux
|
|
|
|
package masterkey
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha1"
|
|
"fmt"
|
|
|
|
"github.com/godbus/dbus/v5"
|
|
keyring "github.com/ppacher/go-dbus-keyring"
|
|
)
|
|
|
|
// https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc
|
|
var linuxParams = pbkdf2Params{
|
|
salt: []byte("saltysalt"),
|
|
iterations: 1,
|
|
keySize: 16,
|
|
hashFunc: sha1.New,
|
|
}
|
|
|
|
// One per prefix Chromium emits: v10 = PBKDF2("peanuts") when no keyring exists, v11 = PBKDF2(keyring secret).
|
|
// A profile carries both if the host moved between headless and keyring sessions.
|
|
var platformRetrievers = []Retriever{posixRetriever{}, dbusRetriever{}}
|
|
|
|
// dbusRetriever queries GNOME Keyring / KDE Wallet via D-Bus Secret Service.
|
|
type dbusRetriever struct{}
|
|
|
|
func (dbusRetriever) Version() Version { return V11 }
|
|
|
|
func (dbusRetriever) Retrieve(_ context.Context, loc Locator) ([]byte, error) {
|
|
storage := loc.KeychainLabel
|
|
conn, err := dbus.SessionBus()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("dbus session: %w", err)
|
|
}
|
|
|
|
svc, err := keyring.GetSecretService(conn)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("secret service: %w", err)
|
|
}
|
|
|
|
session, err := svc.OpenSession()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("open session: %w", err)
|
|
}
|
|
defer session.Close()
|
|
|
|
collections, err := svc.GetAllCollections()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("get collections: %w", err)
|
|
}
|
|
|
|
for _, col := range collections {
|
|
items, err := col.GetAllItems()
|
|
if err != nil {
|
|
continue
|
|
}
|
|
for _, item := range items {
|
|
label, err := item.GetLabel()
|
|
if err != nil {
|
|
continue
|
|
}
|
|
if label == storage {
|
|
secret, err := item.GetSecret(session.Path())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("get secret for %s: %w", storage, err)
|
|
}
|
|
if len(secret.Value) > 0 {
|
|
return linuxParams.deriveKey(secret.Value), nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil, fmt.Errorf("%q: %w", storage, errStorageNotFound)
|
|
}
|
|
|
|
// posixRetriever derives Chromium's kV10Key via PBKDF2 over the hardcoded "peanuts" password — the
|
|
// deterministic v10 key used when no keyring exists (headless/Docker/CI). Mirrors PosixKeyProvider.
|
|
type posixRetriever struct{}
|
|
|
|
func (posixRetriever) Version() Version { return V10 }
|
|
|
|
func (posixRetriever) Retrieve(context.Context, Locator) ([]byte, error) {
|
|
return linuxParams.deriveKey([]byte("peanuts")), nil
|
|
}
|