refactor: Refactor encryption modules for Chromium browsers.

This commit is contained in:
moonD4rk 2024-04-15 16:11:25 +08:00 committed by ᴍᴏᴏɴD4ʀᴋ
parent 6237658fe7
commit fc8a3515d8
4 changed files with 6 additions and 8 deletions

View File

@ -12,8 +12,8 @@ import (
"os/exec" "os/exec"
"strings" "strings"
"github.com/moond4rk/hackbrowserdata/crypto"
"github.com/moond4rk/hackbrowserdata/types" "github.com/moond4rk/hackbrowserdata/types"
"github.com/moond4rk/hackbrowserdata/utils/cryptoutil"
) )
var ( var (
@ -49,7 +49,7 @@ func (c *Chromium) GetMasterKey() ([]byte, error) {
} }
salt := []byte("saltysalt") salt := []byte("saltysalt")
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157 // @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157
key := cryptoutil.PBKDF2Key(secret, salt, 1003, 16, sha1.New) key := crypto.PBKDF2Key(secret, salt, 1003, 16, sha1.New)
if key == nil { if key == nil {
return nil, errWrongSecurityCommand return nil, errWrongSecurityCommand
} }

View File

@ -11,8 +11,8 @@ import (
"github.com/godbus/dbus/v5" "github.com/godbus/dbus/v5"
keyring "github.com/ppacher/go-dbus-keyring" keyring "github.com/ppacher/go-dbus-keyring"
"github.com/moond4rk/hackbrowserdata/crypto"
"github.com/moond4rk/hackbrowserdata/types" "github.com/moond4rk/hackbrowserdata/types"
"github.com/moond4rk/hackbrowserdata/utils/cryptoutil"
) )
func (c *Chromium) GetMasterKey() ([]byte, error) { func (c *Chromium) GetMasterKey() ([]byte, error) {
@ -69,7 +69,7 @@ func (c *Chromium) GetMasterKey() ([]byte, error) {
} }
salt := []byte("saltysalt") salt := []byte("saltysalt")
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_linux.cc // @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_linux.cc
key := cryptoutil.PBKDF2Key(secret, salt, 1, 16, sha1.New) key := crypto.PBKDF2Key(secret, salt, 1, 16, sha1.New)
c.masterKey = key c.masterKey = key
slog.Info("get master key success", "browser", c.name) slog.Info("get master key success", "browser", c.name)
return key, nil return key, nil

View File

@ -6,8 +6,6 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/asn1" "encoding/asn1"
"errors" "errors"
"github.com/moond4rk/hackbrowserdata/utils/cryptoutil"
) )
type ASN1PBE interface { type ASN1PBE interface {
@ -158,7 +156,7 @@ func (m metaPBE) deriveKeyAndIV(globalSalt []byte) ([]byte, []byte) {
iter := m.AlgoAttr.Data.Data.SlatAttr.IterationCount iter := m.AlgoAttr.Data.Data.SlatAttr.IterationCount
keyLen := m.AlgoAttr.Data.Data.SlatAttr.KeySize keyLen := m.AlgoAttr.Data.Data.SlatAttr.KeySize
key := cryptoutil.PBKDF2Key(password[:], salt, iter, keyLen, sha256.New) key := PBKDF2Key(password[:], salt, iter, keyLen, sha256.New)
iv := append([]byte{4, 14}, m.AlgoAttr.Data.IVData.IV...) iv := append([]byte{4, 14}, m.AlgoAttr.Data.IVData.IV...)
return key, iv return key, iv
} }

View File

@ -1,4 +1,4 @@
package cryptoutil package crypto
import ( import (
"crypto/hmac" "crypto/hmac"