From 5936e17e26c0c2f0be24aaded1db9750cf48bd1b 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, 31 Jul 2020 15:29:07 +0800 Subject: [PATCH] refactor: format code with interface --- core/browser.go | 13 +++++++------ core/browser_darwin.go | 2 +- core/browser_linux.go | 6 +++--- core/common/parse.go | 1 + core/decrypt/decrypt.go | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/core/browser.go b/core/browser.go index 5db693d..4751134 100644 --- a/core/browser.go +++ b/core/browser.go @@ -57,9 +57,10 @@ const ( ) var ( - ErrDataNotSupported = errors.New(`not supported, default is "all", choose from history|password|bookmark|cookie`) - ErrBrowserNotSupported = errors.New("browser not supported") - ErrChromeSecretIsEmpty = errors.New("chrome secret is empty") + errDataNotSupported = errors.New(`not supported, default is "all", choose from history|password|bookmark|cookie`) + errBrowserNotSupported = errors.New("browser not supported") + errChromeSecretIsEmpty = errors.New("chrome secret is empty") + errDbusSecretIsEmpty = errors.New("dbus secret key is empty") chromiumParseList = map[string]FileList{ cookie: { name: cookie, @@ -129,7 +130,7 @@ func (c *chromium) GetProfilePath(filename string) (err error) { c.FileLists = append(c.FileLists, v) } } else { - return ErrDataNotSupported + return errDataNotSupported } return nil } @@ -315,7 +316,7 @@ func (f *firefox) GetProfilePath(filename string) (err error) { f.FileLists = append(f.FileLists, v) } } else { - return ErrDataNotSupported + return errDataNotSupported } return nil } @@ -393,7 +394,7 @@ func PickBrowsers(name string) ([]Browser, error) { browsers = append(browsers, b) return browsers, err } - return nil, ErrBrowserNotSupported + return nil, errBrowserNotSupported } func chromeParse(key []byte, f common.Formatter) error { diff --git a/core/browser_darwin.go b/core/browser_darwin.go index 6273eef..e61380d 100644 --- a/core/browser_darwin.go +++ b/core/browser_darwin.go @@ -62,7 +62,7 @@ func (c *chromium) InitSecretKey() error { temp := stdout.Bytes() chromeSecret := temp[:len(temp)-1] if chromeSecret == nil { - return ErrChromeSecretIsEmpty + return errChromeSecretIsEmpty } var chromeSalt = []byte("saltysalt") // @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157 diff --git a/core/browser_linux.go b/core/browser_linux.go index 38990a1..45393f4 100644 --- a/core/browser_linux.go +++ b/core/browser_linux.go @@ -2,10 +2,10 @@ package core import ( "crypto/sha1" - "github.com/godbus/dbus/v5" - keyring "github.com/ppacher/go-dbus-keyring" "hack-browser-data/log" + "github.com/godbus/dbus/v5" + keyring "github.com/ppacher/go-dbus-keyring" "golang.org/x/crypto/pbkdf2" ) @@ -80,7 +80,7 @@ func (c *chromium) InitSecretKey() error { } var chromeSalt = []byte("saltysalt") if chromeSecret == nil { - return ErrChromeSecretIsEmpty + return errDbusSecretIsEmpty } // @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_linux.cc key := pbkdf2.Key(chromeSecret, chromeSalt, 1, 16, sha1.New) diff --git a/core/common/parse.go b/core/common/parse.go index ea8e266..57d1a41 100644 --- a/core/common/parse.go +++ b/core/common/parse.go @@ -380,6 +380,7 @@ func (b *Bookmarks) FirefoxParse() error { func (b *Bookmarks) Release(filename string) error { return os.Remove(filename) } + func (c *Cookies) Release(filename string) error { return os.Remove(filename) } diff --git a/core/decrypt/decrypt.go b/core/decrypt/decrypt.go index b322ff4..5ca5438 100644 --- a/core/decrypt/decrypt.go +++ b/core/decrypt/decrypt.go @@ -13,7 +13,6 @@ var ( errSecurityKeyIsEmpty = errors.New("input [security find-generic-password -wa 'Chrome'] in terminal") errPasswordIsEmpty = errors.New("password is empty") errDecryptFailed = errors.New("decrypt failed, password is empty") - errDbusSecretIsEmpty = errors.New("dbus secret key is empty") ) func aes128CBCDecrypt(key, iv, encryptPass []byte) ([]byte, error) { @@ -33,6 +32,7 @@ func PKCS5UnPadding(src []byte) []byte { unpad := int(src[length-1]) return src[:(length - unpad)] } + func Des3Decrypt(key, iv []byte, src []byte) ([]byte, error) { block, err := des.NewTripleDESCipher(key) if err != nil {