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"
|
2024-01-16 06:06:13 +00:00
|
|
|
"log/slog"
|
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
|
|
|
|
2023-06-04 05:47:43 +00:00
|
|
|
"github.com/moond4rk/hackbrowserdata/crypto"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/item"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/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
|
|
|
|
2023-03-10 06:52:26 +00:00
|
|
|
func (c *Chromium) GetMasterKey() ([]byte, error) {
|
2024-01-13 07:58:53 +00:00
|
|
|
b, err := fileutil.ReadFile(item.ChromiumKey.TempFilename())
|
2022-04-08 11:06:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-01-13 07:58:53 +00:00
|
|
|
defer os.Remove(item.ChromiumKey.TempFilename())
|
2023-03-11 12:09:10 +00:00
|
|
|
|
|
|
|
encryptedKey := gjson.Get(b, "os_crypt.encrypted_key")
|
2022-08-14 13:22:34 +00:00
|
|
|
if !encryptedKey.Exists() {
|
|
|
|
return nil, nil
|
2022-04-08 11:06:04 +00:00
|
|
|
}
|
2023-03-11 12:09:10 +00:00
|
|
|
|
|
|
|
key, err := base64.StdEncoding.DecodeString(encryptedKey.String())
|
2022-08-14 13:22:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errDecodeMasterKeyFailed
|
|
|
|
}
|
2024-01-27 14:30:28 +00:00
|
|
|
c.masterKey, err = crypto.DecryptWithDPAPI(key[5:])
|
2024-01-04 10:54:15 +00:00
|
|
|
if err != nil {
|
2024-01-16 06:06:13 +00:00
|
|
|
slog.Error("decrypt master key failed", "err", err)
|
2024-01-04 10:54:15 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2024-01-16 06:06:13 +00:00
|
|
|
slog.Info("get master key success", "browser", c.name)
|
2024-01-04 10:54:15 +00:00
|
|
|
return c.masterKey, nil
|
2022-04-08 11:06:04 +00:00
|
|
|
}
|