From 4f80bd0ca7a4950f4d649bf113bfd8ebbf27f9dc 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, 10 Jul 2020 10:46:33 +0800 Subject: [PATCH] fix: firefox for windows decrypt failure --- utils/utils.go | 8 +++----- utils/utils_darwin.go | 5 ++++- utils/utils_windows.go | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 4cd524e..dc995c6 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -17,9 +17,9 @@ import ( ) var ( - passwordIsEmpty = errors.New("decrypt fail, password is empty") - + errPasswordIsEmpty = errors.New("decrypt failed, password is empty") errBrowserNotSupported = errors.New("browser not supported") + errKeyIsEmpty = errors.New("input [security find-generic-password -wa 'Chrome'] in terminal") VersionUnder80 bool ) @@ -227,9 +227,7 @@ func DecodeLogin(decodeItem []byte) (pbe LoginPBE, err error) { } func aes128CBCDecrypt(key, iv, encryptPass []byte) ([]byte, error) { - if len(chromeKey) == 0 { - return []byte{}, nil - } + block, err := aes.NewCipher(key) if err != nil { return []byte{}, err diff --git a/utils/utils_darwin.go b/utils/utils_darwin.go index 45883f0..daf00ee 100644 --- a/utils/utils_darwin.go +++ b/utils/utils_darwin.go @@ -88,11 +88,14 @@ func decryptChromeKey(chromePass []byte) { func DecryptChromePass(encryptPass []byte) (string, error) { if len(encryptPass) > 3 { + if len(chromeKey) == 0 { + return "", errKeyIsEmpty + } m, err := aes128CBCDecrypt(chromeKey, iv, encryptPass[3:]) return string(m), err } else { return "", &DecryptError{ - err: passwordIsEmpty, + err: errPasswordIsEmpty, } } } diff --git a/utils/utils_windows.go b/utils/utils_windows.go index 55720c6..ee0431d 100644 --- a/utils/utils_windows.go +++ b/utils/utils_windows.go @@ -106,7 +106,7 @@ func DecryptChromePass(encryptPass []byte) (string, error) { // remove prefix 'v10' return aesGCMDecrypt(encryptPass[15:], chromeKey, encryptPass[3:15]) } else { - return "", passwordIsEmpty + return "", errPasswordIsEmpty } }