You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
872 B
37 lines
872 B
3 years ago
|
//go:build windows
|
||
|
|
||
3 years ago
|
package chromium
|
||
|
|
||
|
import (
|
||
|
"encoding/base64"
|
||
|
"errors"
|
||
3 years ago
|
"os"
|
||
3 years ago
|
|
||
|
"github.com/tidwall/gjson"
|
||
3 years ago
|
|
||
2 years ago
|
"github.com/moond4rk/HackBrowserData/item"
|
||
|
"github.com/moond4rk/HackBrowserData/log"
|
||
|
"github.com/moond4rk/HackBrowserData/utils/fileutil"
|
||
3 years ago
|
)
|
||
|
|
||
3 years ago
|
var errDecodeMasterKeyFailed = errors.New("decode master key failed")
|
||
3 years ago
|
|
||
2 years ago
|
func (c *Chromium) GetMasterKey() ([]byte, error) {
|
||
3 years ago
|
keyFile, err := fileutil.ReadFile(item.TempChromiumKey)
|
||
3 years ago
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
3 years ago
|
defer os.Remove(keyFile)
|
||
3 years ago
|
encryptedKey := gjson.Get(keyFile, "os_crypt.encrypted_key")
|
||
2 years ago
|
if !encryptedKey.Exists() {
|
||
|
return nil, nil
|
||
3 years ago
|
}
|
||
2 years ago
|
pureKey, err := base64.StdEncoding.DecodeString(encryptedKey.String())
|
||
|
if err != nil {
|
||
|
return nil, errDecodeMasterKeyFailed
|
||
|
}
|
||
2 years ago
|
c.masterKey, err = crypto.DPAPI(pureKey[5:])
|
||
2 years ago
|
log.Infof("%s initialized master key success", c.name)
|
||
|
return c.masterKey, err
|
||
3 years ago
|
}
|