mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 12:46:44 +00:00
Update main.go
This commit is contained in:
parent
3bbf5f5b6a
commit
c4fbac7032
1 changed files with 26 additions and 10 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue