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.
74 lines
1.7 KiB
74 lines
1.7 KiB
3 years ago
|
//go:build linux
|
||
|
|
||
3 years ago
|
package chromium
|
||
3 years ago
|
|
||
|
import (
|
||
|
"crypto/sha1"
|
||
3 years ago
|
"errors"
|
||
3 years ago
|
"os"
|
||
3 years ago
|
|
||
|
"github.com/godbus/dbus/v5"
|
||
|
keyring "github.com/ppacher/go-dbus-keyring"
|
||
|
"golang.org/x/crypto/pbkdf2"
|
||
|
|
||
3 years ago
|
"hack-browser-data/internal/item"
|
||
3 years ago
|
"hack-browser-data/internal/log"
|
||
|
)
|
||
|
|
||
|
func (c *chromium) GetMasterKey() ([]byte, error) {
|
||
|
// what is d-bus @https://dbus.freedesktop.org/
|
||
3 years ago
|
var chromiumSecret []byte
|
||
3 years ago
|
conn, err := dbus.SessionBus()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
3 years ago
|
defer os.Remove(item.TempChromiumKey)
|
||
3 years ago
|
svc, err := keyring.GetSecretService(conn)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
session, err := svc.OpenSession()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer func() {
|
||
2 years ago
|
if err := session.Close(); err != nil {
|
||
|
log.Errorf("close session failed: %v", err)
|
||
|
}
|
||
3 years ago
|
}()
|
||
|
collections, err := svc.GetAllCollections()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
for _, col := range collections {
|
||
|
items, err := col.GetAllItems()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
3 years ago
|
for _, i := range items {
|
||
|
label, err := i.GetLabel()
|
||
3 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
continue
|
||
|
}
|
||
|
if label == c.storage {
|
||
3 years ago
|
se, err := i.GetSecret(session.Path())
|
||
3 years ago
|
if err != nil {
|
||
3 years ago
|
return nil, errors.New("get storage from dbus error:" + err.Error())
|
||
3 years ago
|
}
|
||
3 years ago
|
chromiumSecret = se.Value
|
||
3 years ago
|
}
|
||
|
}
|
||
|
}
|
||
3 years ago
|
if chromiumSecret == nil {
|
||
|
// @https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=100
|
||
|
chromiumSecret = []byte("peanuts")
|
||
3 years ago
|
}
|
||
3 years ago
|
chromiumSalt := []byte("saltysalt")
|
||
3 years ago
|
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_linux.cc
|
||
3 years ago
|
key := pbkdf2.Key(chromiumSecret, chromiumSalt, 1, 16, sha1.New)
|
||
3 years ago
|
c.masterKey = key
|
||
3 years ago
|
log.Infof("%s initialized master key success", c.name)
|
||
3 years ago
|
return key, nil
|
||
|
}
|