From 328e49d9541f1ae17db360291b287f5d6774a811 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: Fri, 15 Apr 2022 00:46:14 +0800 Subject: [PATCH] fix: find chromium master key from linux dbus failed --- internal/browser/chromium/chromium_linux.go | 23 ++++++++++++--------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/internal/browser/chromium/chromium_linux.go b/internal/browser/chromium/chromium_linux.go index a36c175..f345b4e 100644 --- a/internal/browser/chromium/chromium_linux.go +++ b/internal/browser/chromium/chromium_linux.go @@ -2,21 +2,24 @@ package chromium import ( "crypto/sha1" + "os" "github.com/godbus/dbus/v5" keyring "github.com/ppacher/go-dbus-keyring" "golang.org/x/crypto/pbkdf2" + "hack-browser-data/internal/item" "hack-browser-data/internal/log" ) func (c *chromium) GetMasterKey() ([]byte, error) { // what is d-bus @https://dbus.freedesktop.org/ - var chromeSecret []byte + var chromiumSecret []byte conn, err := dbus.SessionBus() if err != nil { return nil, err } + defer os.Remove(item.TempChromiumKey) svc, err := keyring.GetSecretService(conn) if err != nil { return nil, err @@ -37,29 +40,29 @@ func (c *chromium) GetMasterKey() ([]byte, error) { if err != nil { return nil, err } - for _, item := range items { - label, err := item.GetLabel() + for _, i := range items { + label, err := i.GetLabel() if err != nil { log.Error(err) continue } if label == c.storage { - se, err := item.GetSecret(session.Path()) + se, err := i.GetSecret(session.Path()) if err != nil { log.Error(err) return nil, err } - chromeSecret = se.Value + chromiumSecret = se.Value } } } - // TODO: handle error if no secret found - if chromeSecret == nil { - return nil, err + if chromiumSecret == nil { + // @https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=100 + chromiumSecret = []byte("peanuts") } - var chromeSalt = []byte("saltysalt") + var chromiumSalt = []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) + key := pbkdf2.Key(chromiumSecret, chromiumSalt, 1, 16, sha1.New) c.masterKey = key return key, nil }