Update main.go

This commit is contained in:
0xLogicalx 2025-11-26 19:33:05 +01:00 committed by GitHub
parent 3bbf5f5b6a
commit c4fbac7032
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -374,6 +374,22 @@ You should treat 'masterseed.json' with utmost secrecy and make a backup of it!
return nil return nil
} }
const (
vaultDomain = "vault"
configDomain = "config"
credentialsDomain = "credentials"
jsStorageDomain = "jsstorage"
)
func deriveStorageKey(domain string, stretchedKey []byte) []byte {
return crypto.Keccak256([]byte(domain), stretchedKey)
}
func deriveVaultLocation(configDir string, stretchedKey []byte) string {
vaultHash := deriveStorageKey(vaultDomain, stretchedKey)
return filepath.Join(configDir, common.Bytes2Hex(vaultHash[:10]))
}
func attestFile(ctx *cli.Context) error { func attestFile(ctx *cli.Context) error {
if ctx.NArg() < 1 { if ctx.NArg() < 1 {
utils.Fatalf("This command requires an argument.") utils.Fatalf("This command requires an argument.")
@ -387,8 +403,8 @@ func attestFile(ctx *cli.Context) error {
utils.Fatalf(err.Error()) utils.Fatalf(err.Error())
} }
configDir := ctx.String(configdirFlag.Name) configDir := ctx.String(configdirFlag.Name)
vaultLocation := filepath.Join(configDir, common.Bytes2Hex(crypto.Keccak256([]byte("vault"), stretchedKey)[:10])) vaultLocation := deriveVaultLocation(configDir, stretchedKey)
confKey := crypto.Keccak256([]byte("config"), stretchedKey) confKey := deriveStorageKey(configDomain, stretchedKey)
// Initialize the encrypted storages // Initialize the encrypted storages
configStorage := storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "config.json"), confKey) configStorage := storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "config.json"), confKey)
@ -434,8 +450,8 @@ func setCredential(ctx *cli.Context) error {
utils.Fatalf(err.Error()) utils.Fatalf(err.Error())
} }
configDir := ctx.String(configdirFlag.Name) configDir := ctx.String(configdirFlag.Name)
vaultLocation := filepath.Join(configDir, common.Bytes2Hex(crypto.Keccak256([]byte("vault"), stretchedKey)[:10])) vaultLocation := deriveVaultLocation(configDir, stretchedKey)
pwkey := crypto.Keccak256([]byte("credentials"), stretchedKey) pwkey := deriveStorageKey(credentialsDomain, stretchedKey)
pwStorage := storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "credentials.json"), pwkey) pwStorage := storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "credentials.json"), pwkey)
pwStorage.Put(address.Hex(), password) pwStorage.Put(address.Hex(), password)
@ -462,8 +478,8 @@ func removeCredential(ctx *cli.Context) error {
utils.Fatalf(err.Error()) utils.Fatalf(err.Error())
} }
configDir := ctx.String(configdirFlag.Name) configDir := ctx.String(configdirFlag.Name)
vaultLocation := filepath.Join(configDir, common.Bytes2Hex(crypto.Keccak256([]byte("vault"), stretchedKey)[:10])) vaultLocation := deriveVaultLocation(configDir, stretchedKey)
pwkey := crypto.Keccak256([]byte("credentials"), stretchedKey) pwkey := deriveStorageKey(credentialsDomain, stretchedKey)
pwStorage := storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "credentials.json"), pwkey) pwStorage := storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "credentials.json"), pwkey)
pwStorage.Del(address.Hex()) pwStorage.Del(address.Hex())
@ -657,12 +673,12 @@ func signer(c *cli.Context) error {
if stretchedKey, err := readMasterKey(c, ui); err != nil { if stretchedKey, err := readMasterKey(c, ui); err != nil {
log.Warn("Failed to open master, rules disabled", "err", err) log.Warn("Failed to open master, rules disabled", "err", err)
} else { } else {
vaultLocation := filepath.Join(configDir, common.Bytes2Hex(crypto.Keccak256([]byte("vault"), stretchedKey)[:10])) vaultLocation := deriveVaultLocation(configDir, stretchedKey)
// Generate domain specific keys // Generate domain specific keys
pwkey := crypto.Keccak256([]byte("credentials"), stretchedKey) pwkey := deriveStorageKey(credentialsDomain, stretchedKey)
jskey := crypto.Keccak256([]byte("jsstorage"), stretchedKey) jskey := deriveStorageKey(jsStorageDomain, stretchedKey)
confkey := crypto.Keccak256([]byte("config"), stretchedKey) confkey := deriveStorageKey(configDomain, stretchedKey)
// Initialize the encrypted storages // Initialize the encrypted storages
pwStorage = storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "credentials.json"), pwkey) pwStorage = storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "credentials.json"), pwkey)