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.
38 lines
888 B
38 lines
888 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
|
|
||
|
"hack-browser-data/internal/decrypter"
|
||
|
"hack-browser-data/internal/item"
|
||
3 years ago
|
"hack-browser-data/internal/log"
|
||
3 years ago
|
"hack-browser-data/internal/utils/fileutil"
|
||
3 years ago
|
)
|
||
|
|
||
3 years ago
|
var errDecodeMasterKeyFailed = errors.New("decode master key failed")
|
||
3 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
|
||
|
}
|
||
|
c.masterKey, err = decrypter.DPAPI(pureKey[5:])
|
||
|
log.Infof("%s initialized master key success", c.name)
|
||
|
return c.masterKey, err
|
||
3 years ago
|
}
|