mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +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
|
||||
}
|
||||
|
||||
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 {
|
||||
if ctx.NArg() < 1 {
|
||||
utils.Fatalf("This command requires an argument.")
|
||||
|
|
@ -387,8 +403,8 @@ func attestFile(ctx *cli.Context) error {
|
|||
utils.Fatalf(err.Error())
|
||||
}
|
||||
configDir := ctx.String(configdirFlag.Name)
|
||||
vaultLocation := filepath.Join(configDir, common.Bytes2Hex(crypto.Keccak256([]byte("vault"), stretchedKey)[:10]))
|
||||
confKey := crypto.Keccak256([]byte("config"), stretchedKey)
|
||||
vaultLocation := deriveVaultLocation(configDir, stretchedKey)
|
||||
confKey := deriveStorageKey(configDomain, stretchedKey)
|
||||
|
||||
// Initialize the encrypted storages
|
||||
configStorage := storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "config.json"), confKey)
|
||||
|
|
@ -434,8 +450,8 @@ func setCredential(ctx *cli.Context) error {
|
|||
utils.Fatalf(err.Error())
|
||||
}
|
||||
configDir := ctx.String(configdirFlag.Name)
|
||||
vaultLocation := filepath.Join(configDir, common.Bytes2Hex(crypto.Keccak256([]byte("vault"), stretchedKey)[:10]))
|
||||
pwkey := crypto.Keccak256([]byte("credentials"), stretchedKey)
|
||||
vaultLocation := deriveVaultLocation(configDir, stretchedKey)
|
||||
pwkey := deriveStorageKey(credentialsDomain, stretchedKey)
|
||||
|
||||
pwStorage := storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "credentials.json"), pwkey)
|
||||
pwStorage.Put(address.Hex(), password)
|
||||
|
|
@ -462,8 +478,8 @@ func removeCredential(ctx *cli.Context) error {
|
|||
utils.Fatalf(err.Error())
|
||||
}
|
||||
configDir := ctx.String(configdirFlag.Name)
|
||||
vaultLocation := filepath.Join(configDir, common.Bytes2Hex(crypto.Keccak256([]byte("vault"), stretchedKey)[:10]))
|
||||
pwkey := crypto.Keccak256([]byte("credentials"), stretchedKey)
|
||||
vaultLocation := deriveVaultLocation(configDir, stretchedKey)
|
||||
pwkey := deriveStorageKey(credentialsDomain, stretchedKey)
|
||||
|
||||
pwStorage := storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "credentials.json"), pwkey)
|
||||
pwStorage.Del(address.Hex())
|
||||
|
|
@ -657,12 +673,12 @@ func signer(c *cli.Context) error {
|
|||
if stretchedKey, err := readMasterKey(c, ui); err != nil {
|
||||
log.Warn("Failed to open master, rules disabled", "err", err)
|
||||
} else {
|
||||
vaultLocation := filepath.Join(configDir, common.Bytes2Hex(crypto.Keccak256([]byte("vault"), stretchedKey)[:10]))
|
||||
vaultLocation := deriveVaultLocation(configDir, stretchedKey)
|
||||
|
||||
// Generate domain specific keys
|
||||
pwkey := crypto.Keccak256([]byte("credentials"), stretchedKey)
|
||||
jskey := crypto.Keccak256([]byte("jsstorage"), stretchedKey)
|
||||
confkey := crypto.Keccak256([]byte("config"), stretchedKey)
|
||||
pwkey := deriveStorageKey(credentialsDomain, stretchedKey)
|
||||
jskey := deriveStorageKey(jsStorageDomain, stretchedKey)
|
||||
confkey := deriveStorageKey(configDomain, stretchedKey)
|
||||
|
||||
// Initialize the encrypted storages
|
||||
pwStorage = storage.NewAESEncryptedStorage(filepath.Join(vaultLocation, "credentials.json"), pwkey)
|
||||
|
|
|
|||
Loading…
Reference in a new issue