refactor: naming cleanup and crypto package improvements (#551)

* refactor: naming cleanup across all packages
This commit is contained in:
Roger
2026-04-05 16:51:56 +08:00
committed by GitHub
parent 4af2ded428
commit 410bffe643
49 changed files with 716 additions and 510 deletions
+3 -3
View File
@@ -69,7 +69,7 @@ type addressRange struct {
// DecryptKeychain extracts the browser storage password from login.keychain-db
// by dumping securityd memory and scanning for the keychain master key.
// Requires root privileges.
func DecryptKeychain(storagename string) (string, error) {
func DecryptKeychain(storageName string) (string, error) {
if os.Geteuid() != 0 {
return "", errors.New("requires root privileges")
}
@@ -124,13 +124,13 @@ func DecryptKeychain(storagename string) (string, error) {
continue
}
for _, rec := range records {
if rec.Account == storagename {
if rec.Account == storageName {
return string(rec.Password), nil
}
}
}
return "", fmt.Errorf("tried %d candidates, none matched storage %q", len(candidates), storagename)
return "", fmt.Errorf("tried %d candidates, none matched storage %q", len(candidates), storageName)
}
// scanMasterKeyCandidates scans the core dump for 24-byte master key candidates.
+1 -1
View File
@@ -20,7 +20,7 @@ import (
var darwinParams = pbkdf2Params{
salt: []byte("saltysalt"),
iterations: 1003,
keyLen: 16,
keySize: 16,
hashFunc: sha1.New,
}
+1 -1
View File
@@ -14,7 +14,7 @@ import (
var linuxParams = pbkdf2Params{
salt: []byte("saltysalt"),
iterations: 1,
keyLen: 16,
keySize: 16,
hashFunc: sha1.New,
}
+1 -1
View File
@@ -41,7 +41,7 @@ func (r *DPAPIRetriever) RetrieveKey(_, localStatePath string) ([]byte, error) {
return nil, fmt.Errorf("encrypted_key unexpected prefix: got %q, want %q", keyBytes[:len(dpapiPrefix)], dpapiPrefix)
}
masterKey, err := crypto.DecryptWithDPAPI(keyBytes[len(dpapiPrefix):])
masterKey, err := crypto.DecryptDPAPI(keyBytes[len(dpapiPrefix):])
if err != nil {
return nil, fmt.Errorf("DPAPI decrypt: %w", err)
}
+2 -2
View File
@@ -13,11 +13,11 @@ import (
type pbkdf2Params struct {
salt []byte
iterations int
keyLen int
keySize int
hashFunc func() hash.Hash
}
// deriveKey derives an encryption key from a secret using PBKDF2.
func (p pbkdf2Params) deriveKey(secret []byte) []byte {
return crypto.PBKDF2Key(secret, p.salt, p.iterations, p.keyLen, p.hashFunc)
return crypto.PBKDF2Key(secret, p.salt, p.iterations, p.keySize, p.hashFunc)
}