Add key header to unencrypted key file

This commit is contained in:
Gustav Simonsson 2015-04-15 15:47:00 +02:00
parent 29a5a92d13
commit cd88295f5a
2 changed files with 16 additions and 8 deletions

View File

@ -45,12 +45,14 @@ type Key struct {
type plainKeyJSON struct {
Id []byte
Address []byte
KeyHeader keyHeaderJSON
PrivateKey []byte
}
type encryptedKeyJSON struct {
Id []byte
Address []byte
KeyHeader keyHeaderJSON
Crypto cipherJSON
}
@ -58,14 +60,13 @@ type cipherJSON struct {
MAC []byte
Salt []byte
IV []byte
KeyHeader keyHeaderJSON
CipherText []byte
}
type keyHeaderJSON struct {
Version string
Kdf string
KdfParams scryptParamsJSON // TODO: make more generic?
KdfParams *scryptParamsJSON // TODO: make more generic?
}
type scryptParamsJSON struct {
@ -77,9 +78,15 @@ type scryptParamsJSON struct {
}
func (k *Key) MarshalJSON() (j []byte, err error) {
keyHeader := keyHeaderJSON{
Version: "1",
Kdf: "",
KdfParams: nil,
}
jStruct := plainKeyJSON{
k.Id,
k.Address.Bytes(),
keyHeader,
FromECDSA(k.PrivateKey),
}
j, err = json.Marshal(jStruct)

View File

@ -153,7 +153,7 @@ func (ks keyStorePassphrase) StoreKey(key *Key, auth string) (err error) {
keyHeaderJSON := keyHeaderJSON{
Version: keyHeaderVersion,
Kdf: keyHeaderKDF,
KdfParams: paramsJSON,
KdfParams: &paramsJSON,
}
keyHeaderJSONStr, err := json.Marshal(keyHeaderJSON)
@ -167,12 +167,12 @@ func (ks keyStorePassphrase) StoreKey(key *Key, auth string) (err error) {
mac,
salt,
iv,
keyHeaderJSON,
cipherText,
}
keyStruct := encryptedKeyJSON{
key.Id,
key.Address.Bytes(),
keyHeaderJSON,
cipherStruct,
}
keyJSON, err := json.Marshal(keyStruct)
@ -204,10 +204,11 @@ func DecryptKey(ks keyStorePassphrase, keyAddr common.Address, auth string) (key
err = json.Unmarshal(fileContent, keyProtected)
keyId = keyProtected.Id
keyHeader := keyProtected.KeyHeader
mac := keyProtected.Crypto.MAC
salt := keyProtected.Crypto.Salt
iv := keyProtected.Crypto.IV
keyHeader := keyProtected.Crypto.KeyHeader
cipherText := keyProtected.Crypto.CipherText
// used in MAC