From 153868198b5fd2b1d934709db311fb72f172d0fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=8D=E1=B4=8F=E1=B4=8F=C9=B4D4=CA=80=E1=B4=8B?= Date: Wed, 13 Apr 2022 15:30:30 +0800 Subject: [PATCH] feat: add chromium for linux --- internal/browser/browser_linux.go | 89 +++++++++++++++++++ internal/browser/chromium/chromium_linux.go | 64 +++++++++++++ internal/browser/chromium/chromium_windows.go | 2 + 3 files changed, 155 insertions(+) diff --git a/internal/browser/browser_linux.go b/internal/browser/browser_linux.go index c8d3c13..f4722a4 100644 --- a/internal/browser/browser_linux.go +++ b/internal/browser/browser_linux.go @@ -1,3 +1,92 @@ //go:build linux package browser + +import ( + "hack-browser-data/internal/item" +) + +var ( + chromiumList = map[string]struct { + name string + storage string + profilePath string + items []item.Item + }{ + "chrome": { + name: chromeName, + storage: chromeStorageName, + profilePath: chromeProfilePath, + items: item.DefaultChromium, + }, + "edge": { + name: edgeName, + storage: edgeStorageName, + profilePath: edgeProfilePath, + items: item.DefaultChromium, + }, + "chromium": { + name: chromiumName, + storage: chromiumStorageName, + profilePath: chromiumProfilePath, + items: item.DefaultChromium, + }, + "chrome-beta": { + name: chromeBetaName, + storage: chromeBetaStorageName, + profilePath: chromeBetaProfilePath, + items: item.DefaultChromium, + }, + "opera": { + name: operaName, + profilePath: operaProfilePath, + storage: operaStorageName, + items: item.DefaultChromium, + }, + "vivaldi": { + name: vivaldiName, + storage: vivaldiStorageName, + profilePath: vivaldiProfilePath, + items: item.DefaultChromium, + }, + "brave": { + name: braveName, + profilePath: braveProfilePath, + storage: braveStorageName, + items: item.DefaultChromium, + }, + } + firefoxList = map[string]struct { + name string + storage string + profilePath string + items []item.Item + }{ + "firefox": { + name: firefoxName, + profilePath: firefoxProfilePath, + items: item.DefaultFirefox, + }, + } +) + +var ( + firefoxProfilePath = homeDir + "/.mozilla/firefox/*.default-release*/" + chromeProfilePath = homeDir + "/.config/google-chrome/*/" + chromiumProfilePath = homeDir + "/.config/chromium/*/" + edgeProfilePath = homeDir + "/.config/microsoft-edge*/*/" + braveProfilePath = homeDir + "/.config/BraveSoftware/Brave-Browser/*/" + chromeBetaProfilePath = homeDir + "/.config/google-chrome-beta/*/" + operaProfilePath = homeDir + "/.config/opera/" + vivaldiProfilePath = homeDir + "/.config/vivaldi/*/" +) + +const ( + chromeStorageName = "Chrome Safe Storage" + chromiumStorageName = "Chromium Safe Storage" + edgeStorageName = "Chromium Safe Storage" + braveStorageName = "Brave Safe Storage" + chromeBetaStorageName = "Chrome Safe Storage" + operaStorageName = "Chromium Safe Storage" + vivaldiStorageName = "Chrome Safe Storage" +) diff --git a/internal/browser/chromium/chromium_linux.go b/internal/browser/chromium/chromium_linux.go index 731c7bf..a36c175 100644 --- a/internal/browser/chromium/chromium_linux.go +++ b/internal/browser/chromium/chromium_linux.go @@ -1 +1,65 @@ package chromium + +import ( + "crypto/sha1" + + "github.com/godbus/dbus/v5" + keyring "github.com/ppacher/go-dbus-keyring" + "golang.org/x/crypto/pbkdf2" + + "hack-browser-data/internal/log" +) + +func (c *chromium) GetMasterKey() ([]byte, error) { + // what is d-bus @https://dbus.freedesktop.org/ + var chromeSecret []byte + conn, err := dbus.SessionBus() + if err != nil { + return nil, err + } + svc, err := keyring.GetSecretService(conn) + if err != nil { + return nil, err + } + session, err := svc.OpenSession() + if err != nil { + return nil, err + } + defer func() { + session.Close() + }() + collections, err := svc.GetAllCollections() + if err != nil { + return nil, err + } + for _, col := range collections { + items, err := col.GetAllItems() + if err != nil { + return nil, err + } + for _, item := range items { + label, err := item.GetLabel() + if err != nil { + log.Error(err) + continue + } + if label == c.storage { + se, err := item.GetSecret(session.Path()) + if err != nil { + log.Error(err) + return nil, err + } + chromeSecret = se.Value + } + } + } + // TODO: handle error if no secret found + if chromeSecret == nil { + return nil, err + } + var chromeSalt = []byte("saltysalt") + // @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_linux.cc + key := pbkdf2.Key(chromeSecret, chromeSalt, 1, 16, sha1.New) + c.masterKey = key + return key, nil +} diff --git a/internal/browser/chromium/chromium_windows.go b/internal/browser/chromium/chromium_windows.go index 02ad75d..dfd00fe 100644 --- a/internal/browser/chromium/chromium_windows.go +++ b/internal/browser/chromium/chromium_windows.go @@ -3,6 +3,7 @@ package chromium import ( "encoding/base64" "errors" + "os" "github.com/tidwall/gjson" @@ -20,6 +21,7 @@ func (c *chromium) GetMasterKey() ([]byte, error) { if err != nil { return nil, err } + defer os.Remove(keyFile) encryptedKey := gjson.Get(keyFile, "os_crypt.encrypted_key") if encryptedKey.Exists() { pureKey, err := base64.StdEncoding.DecodeString(encryptedKey.String())