HackBrowserData/internal/browser/chromium/chromium_windows.go

38 lines
893 B
Go
Raw Normal View History

//go:build windows
package chromium
import (
"encoding/base64"
"errors"
2022-04-13 07:30:30 +00:00
"os"
"github.com/tidwall/gjson"
2022-04-11 07:53:19 +00:00
"hack-browser-data/internal/decrypter"
"hack-browser-data/internal/item"
2022-04-15 19:57:19 +00:00
"hack-browser-data/internal/log"
2022-04-11 07:53:19 +00:00
"hack-browser-data/internal/utils/fileutil"
)
var errDecodeMasterKeyFailed = errors.New("decode master key failed")
func (c *chromium) GetMasterKey() ([]byte, error) {
2022-04-11 07:53:19 +00:00
keyFile, err := fileutil.ReadFile(item.TempChromiumKey)
if err != nil {
return nil, err
}
2022-04-13 07:30:30 +00:00
defer os.Remove(keyFile)
encryptedKey := gjson.Get(keyFile, "os_crypt.encrypted_key")
if encryptedKey.Exists() {
pureKey, err := base64.StdEncoding.DecodeString(encryptedKey.String())
if err != nil {
return nil, errDecodeMasterKeyFailed
}
2022-04-11 07:53:19 +00:00
c.masterKey, err = decrypter.DPApi(pureKey[5:])
2022-04-15 19:57:19 +00:00
log.Infof("%s initialized master key success", c.name)
2022-04-11 07:53:19 +00:00
return c.masterKey, err
}
return nil, nil
}