From 4cc3f7d334bcd0854e72c82c1c44b4d35b471325 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: Thu, 22 Oct 2020 13:02:06 +0800 Subject: [PATCH] feat: support edge-dev for linux --- core/browser.go | 11 ++++++----- core/browser_darwin.go | 13 +++++++------ core/browser_linux.go | 23 +++++++++++++++++++---- core/browser_windows.go | 3 ++- core/decrypt/decrypt_windows.go | 14 -------------- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/core/browser.go b/core/browser.go index 712df70..29713f9 100644 --- a/core/browser.go +++ b/core/browser.go @@ -99,11 +99,12 @@ type Chromium struct { name string profilePath string keyPath string + storage string // use for linux browser secretKey []byte } -func NewChromium(profile, key, name string) (Browser, error) { - return &Chromium{profilePath: profile, keyPath: key, name: name}, nil +func NewChromium(profile, key, name, storage string) (Browser, error) { + return &Chromium{profilePath: profile, keyPath: key, name: name, storage: storage}, nil } func (c *Chromium) GetName() string { @@ -149,7 +150,7 @@ type Firefox struct { keyPath string } -func NewFirefox(profile, key, name string) (Browser, error) { +func NewFirefox(profile, key, name, storage string) (Browser, error) { return &Firefox{profilePath: profile, keyPath: key, name: name}, nil } @@ -221,7 +222,7 @@ func PickBrowser(name string) ([]Browser, error) { name = strings.ToLower(name) if name == "all" { for _, v := range browserList { - b, err := v.New(v.ProfilePath, v.KeyPath, v.Name) + b, err := v.New(v.ProfilePath, v.KeyPath, v.Name, v.Storage) if err != nil { log.Error(err) } @@ -229,7 +230,7 @@ func PickBrowser(name string) ([]Browser, error) { } return browsers, nil } else if choice, ok := browserList[name]; ok { - b, err := choice.New(choice.ProfilePath, choice.KeyPath, choice.Name) + b, err := choice.New(choice.ProfilePath, choice.KeyPath, choice.Name, choice.Storage) browsers = append(browsers, b) return browsers, err } diff --git a/core/browser_darwin.go b/core/browser_darwin.go index e08d8b7..90a285d 100644 --- a/core/browser_darwin.go +++ b/core/browser_darwin.go @@ -20,8 +20,14 @@ var ( ProfilePath string Name string KeyPath string - New func(profile, key, name string) (Browser, error) + Storage string + New func(profile, key, name, storage string) (Browser, error) }{ + "firefox": { + ProfilePath: fireFoxProfilePath, + Name: firefoxName, + New: NewFirefox, + }, "chrome": { ProfilePath: chromeProfilePath, Name: chromeName, @@ -32,11 +38,6 @@ var ( Name: edgeName, New: NewChromium, }, - "firefox": { - ProfilePath: fireFoxProfilePath, - Name: firefoxName, - New: NewFirefox, - }, } ) diff --git a/core/browser_linux.go b/core/browser_linux.go index bd11716..07a05fe 100644 --- a/core/browser_linux.go +++ b/core/browser_linux.go @@ -12,6 +12,12 @@ import ( const ( fireFoxProfilePath = "/home/*/.mozilla/firefox/*.default-release/" chromeProfilePath = "/home/*/.config/google-chrome/*/" + edgeProfilePath = "/home/*/.config/microsoft-edge*/*/" +) + +const ( + chromeStorageName = "Chrome Safe Storage" + edgeStorageName = "Chromium Safe Storage" ) var ( @@ -19,7 +25,8 @@ var ( ProfilePath string Name string KeyPath string - New func(profile, key, name string) (Browser, error) + Storage string + New func(profile, key, name, storage string) (Browser, error) }{ "firefox": { ProfilePath: fireFoxProfilePath, @@ -29,6 +36,13 @@ var ( "chrome": { ProfilePath: chromeProfilePath, Name: chromeName, + Storage: chromeStorageName, + New: NewChromium, + }, + "edge": { + ProfilePath: edgeProfilePath, + Name: edgeName, + Storage: edgeStorageName, New: NewChromium, }, } @@ -62,24 +76,25 @@ func (c *Chromium) InitSecretKey() error { return err } for _, item := range items { - i, err := item.GetLabel() + label, err := item.GetLabel() if err != nil { log.Error(err) continue } - if i == "Chrome Safe Storage" { + if label == c.storage { se, err := item.GetSecret(session.Path()) if err != nil { + log.Error(err) return err } chromeSecret = se.Value } } } - var chromeSalt = []byte("saltysalt") if chromeSecret == nil { return errDbusSecretIsEmpty } + 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.secretKey = key diff --git a/core/browser_windows.go b/core/browser_windows.go index 5cc756c..eb000b9 100644 --- a/core/browser_windows.go +++ b/core/browser_windows.go @@ -28,7 +28,8 @@ var ( ProfilePath string Name string KeyPath string - New func(profile, key, name string) (Browser, error) + Storage string + New func(profile, key, name, storage string) (Browser, error) }{ "chrome": { ProfilePath: os.Getenv("USERPROFILE") + chromeProfilePath, diff --git a/core/decrypt/decrypt_windows.go b/core/decrypt/decrypt_windows.go index bbf0a89..2db5b5b 100644 --- a/core/decrypt/decrypt_windows.go +++ b/core/decrypt/decrypt_windows.go @@ -62,20 +62,6 @@ func (b *dataBlob) ToByteArray() []byte { } // chrome < 80 https://chromium.googlesource.com/chromium/src/+/76f496a7235c3432983421402951d73905c8be96/components/os_crypt/os_crypt_win.cc#82 -func decryptStringWithDPAPI(data []byte) ([]byte, error) { - dllCrypt := syscall.NewLazyDLL("Crypt32.dll") - dllKernel := syscall.NewLazyDLL("Kernel32.dll") - procDecryptData := dllCrypt.NewProc("CryptUnprotectData") - procLocalFree := dllKernel.NewProc("LocalFree") - var outBlob dataBlob - r, _, err := procDecryptData.Call(uintptr(unsafe.Pointer(NewBlob(data))), 0, 0, 0, 0, 0, uintptr(unsafe.Pointer(&outBlob))) - if r == 0 { - return nil, err - } - defer procLocalFree.Call(uintptr(unsafe.Pointer(outBlob.pbData))) - return outBlob.ToByteArray(), nil -} - func DPApi(data []byte) ([]byte, error) { dllCrypt := syscall.NewLazyDLL("Crypt32.dll") dllKernel := syscall.NewLazyDLL("Kernel32.dll")