HackBrowserData/browser/chromium/chromium_windows.go

40 lines
913 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
"github.com/moond4rk/HackBrowserData/crypto"
2023-03-10 06:52:26 +00:00
"github.com/moond4rk/HackBrowserData/item"
"github.com/moond4rk/HackBrowserData/log"
"github.com/moond4rk/HackBrowserData/utils/fileutil"
)
var errDecodeMasterKeyFailed = errors.New("decode master key failed")
2023-03-10 06:52:26 +00:00
func (c *Chromium) GetMasterKey() ([]byte, error) {
b, err := fileutil.ReadFile(item.TempChromiumKey)
if err != nil {
return nil, err
}
defer os.Remove(item.TempChromiumKey)
encryptedKey := gjson.Get(b, "os_crypt.encrypted_key")
2022-08-14 13:22:34 +00:00
if !encryptedKey.Exists() {
return nil, nil
}
key, err := base64.StdEncoding.DecodeString(encryptedKey.String())
2022-08-14 13:22:34 +00:00
if err != nil {
return nil, errDecodeMasterKeyFailed
}
c.masterKey, err = crypto.DPAPI(key[5:])
2022-08-14 13:22:34 +00:00
log.Infof("%s initialized master key success", c.name)
return c.masterKey, err
}