2022-06-05 06:51:37 +00:00
|
|
|
//go:build windows
|
|
|
|
|
2022-04-08 11:06:04 +00:00
|
|
|
package chromium
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"errors"
|
2022-04-13 07:30:30 +00:00
|
|
|
"os"
|
2022-04-08 11:06:04 +00:00
|
|
|
|
|
|
|
"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"
|
2022-04-08 11:06:04 +00:00
|
|
|
)
|
|
|
|
|
2022-06-05 06:51:37 +00:00
|
|
|
var errDecodeMasterKeyFailed = errors.New("decode master key failed")
|
2022-04-08 11:06:04 +00:00
|
|
|
|
|
|
|
func (c *chromium) GetMasterKey() ([]byte, error) {
|
2022-04-11 07:53:19 +00:00
|
|
|
keyFile, err := fileutil.ReadFile(item.TempChromiumKey)
|
2022-04-08 11:06:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-04-13 07:30:30 +00:00
|
|
|
defer os.Remove(keyFile)
|
2022-04-08 11:06:04 +00:00
|
|
|
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
|
2022-04-08 11:06:04 +00:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|