|
|
@ -68,6 +68,7 @@ import ( |
|
|
|
"bytes" |
|
|
|
"bytes" |
|
|
|
"crypto/aes" |
|
|
|
"crypto/aes" |
|
|
|
"crypto/cipher" |
|
|
|
"crypto/cipher" |
|
|
|
|
|
|
|
"encoding/hex" |
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
"io" |
|
|
|
"io" |
|
|
@ -164,15 +165,16 @@ func (ks keyStorePassphrase) StoreKey(key *Key, auth string) (err error) { |
|
|
|
mac := Sha3(keyHeaderJSONStr, derivedKey[16:32], cipherText) |
|
|
|
mac := Sha3(keyHeaderJSONStr, derivedKey[16:32], cipherText) |
|
|
|
|
|
|
|
|
|
|
|
cipherStruct := cipherJSON{ |
|
|
|
cipherStruct := cipherJSON{ |
|
|
|
mac, |
|
|
|
hex.EncodeToString(mac), |
|
|
|
salt, |
|
|
|
hex.EncodeToString(salt), |
|
|
|
iv, |
|
|
|
hex.EncodeToString(iv), |
|
|
|
keyHeaderJSON, |
|
|
|
keyHeaderJSON, |
|
|
|
cipherText, |
|
|
|
hex.EncodeToString(cipherText), |
|
|
|
} |
|
|
|
} |
|
|
|
keyStruct := encryptedKeyJSON{ |
|
|
|
keyStruct := encryptedKeyJSON{ |
|
|
|
key.Id, |
|
|
|
version, |
|
|
|
key.Address.Bytes(), |
|
|
|
key.Id.String(), |
|
|
|
|
|
|
|
hex.EncodeToString(key.Address[:]), |
|
|
|
cipherStruct, |
|
|
|
cipherStruct, |
|
|
|
} |
|
|
|
} |
|
|
|
keyJSON, err := json.Marshal(keyStruct) |
|
|
|
keyJSON, err := json.Marshal(keyStruct) |
|
|
@ -190,7 +192,7 @@ func (ks keyStorePassphrase) DeleteKey(keyAddr common.Address, auth string) (err |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
keyDirPath := filepath.Join(ks.keysDirPath, keyAddr.Hex()) |
|
|
|
keyDirPath := filepath.Join(ks.keysDirPath, hex.EncodeToString(keyAddr[:])) |
|
|
|
return os.RemoveAll(keyDirPath) |
|
|
|
return os.RemoveAll(keyDirPath) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -203,12 +205,28 @@ func DecryptKey(ks keyStorePassphrase, keyAddr common.Address, auth string) (key |
|
|
|
keyProtected := new(encryptedKeyJSON) |
|
|
|
keyProtected := new(encryptedKeyJSON) |
|
|
|
err = json.Unmarshal(fileContent, keyProtected) |
|
|
|
err = json.Unmarshal(fileContent, keyProtected) |
|
|
|
|
|
|
|
|
|
|
|
keyId = keyProtected.Id |
|
|
|
keyId = uuid.Parse(keyProtected.Id) |
|
|
|
mac := keyProtected.Crypto.MAC |
|
|
|
|
|
|
|
salt := keyProtected.Crypto.Salt |
|
|
|
mac, err := hex.DecodeString(keyProtected.Crypto.MAC) |
|
|
|
iv := keyProtected.Crypto.IV |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
salt, err := hex.DecodeString(keyProtected.Crypto.Salt) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
iv, err := hex.DecodeString(keyProtected.Crypto.IV) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
keyHeader := keyProtected.Crypto.KeyHeader |
|
|
|
keyHeader := keyProtected.Crypto.KeyHeader |
|
|
|
cipherText := keyProtected.Crypto.CipherText |
|
|
|
cipherText, err := hex.DecodeString(keyProtected.Crypto.CipherText) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// used in MAC
|
|
|
|
// used in MAC
|
|
|
|
keyHeaderJSONStr, err := json.Marshal(keyHeader) |
|
|
|
keyHeaderJSONStr, err := json.Marshal(keyHeader) |
|
|
|