38 lines
893 B
Go
38 lines
893 B
Go
//go:build windows
|
|
|
|
package chromium
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"errors"
|
|
"os"
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
"hack-browser-data/internal/decrypter"
|
|
"hack-browser-data/internal/item"
|
|
"hack-browser-data/internal/log"
|
|
"hack-browser-data/internal/utils/fileutil"
|
|
)
|
|
|
|
var errDecodeMasterKeyFailed = errors.New("decode master key failed")
|
|
|
|
func (c *chromium) GetMasterKey() ([]byte, error) {
|
|
keyFile, err := fileutil.ReadFile(item.TempChromiumKey)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
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
|
|
}
|
|
c.masterKey, err = decrypter.DPApi(pureKey[5:])
|
|
log.Infof("%s initialized master key success", c.name)
|
|
return c.masterKey, err
|
|
}
|
|
return nil, nil
|
|
}
|