diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-05-23 19:58:03 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-05-23 19:58:03 +0800 |
commit | aa73420207cba02a68befdbb8667f1e6ceed3f4d (patch) | |
tree | 76b4fb7ffc9440e7ff27b22dc367355d4fc84f5c /accounts | |
parent | 3556962053267def82f1a9f9e97a26f7b7c1450e (diff) | |
download | go-tangerine-aa73420207cba02a68befdbb8667f1e6ceed3f4d.tar go-tangerine-aa73420207cba02a68befdbb8667f1e6ceed3f4d.tar.gz go-tangerine-aa73420207cba02a68befdbb8667f1e6ceed3f4d.tar.bz2 go-tangerine-aa73420207cba02a68befdbb8667f1e6ceed3f4d.tar.lz go-tangerine-aa73420207cba02a68befdbb8667f1e6ceed3f4d.tar.xz go-tangerine-aa73420207cba02a68befdbb8667f1e6ceed3f4d.tar.zst go-tangerine-aa73420207cba02a68befdbb8667f1e6ceed3f4d.zip |
accounts/keystore, crypto: enforce 256 bit keys on import
Diffstat (limited to 'accounts')
-rw-r--r-- | accounts/keystore/key.go | 5 | ||||
-rw-r--r-- | accounts/keystore/keystore.go | 1 | ||||
-rw-r--r-- | accounts/keystore/keystore_passphrase.go | 5 | ||||
-rw-r--r-- | accounts/keystore/keystore_passphrase_test.go | 2 | ||||
-rw-r--r-- | accounts/keystore/presale.go | 5 |
5 files changed, 11 insertions, 7 deletions
diff --git a/accounts/keystore/key.go b/accounts/keystore/key.go index 292b47b44..ecc955d74 100644 --- a/accounts/keystore/key.go +++ b/accounts/keystore/key.go @@ -124,14 +124,13 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) { if err != nil { return err } - - privkey, err := hex.DecodeString(keyJSON.PrivateKey) + privkey, err := crypto.HexToECDSA(keyJSON.PrivateKey) if err != nil { return err } k.Address = common.BytesToAddress(addr) - k.PrivateKey = crypto.ToECDSA(privkey) + k.PrivateKey = privkey return nil } diff --git a/accounts/keystore/keystore.go b/accounts/keystore/keystore.go index a81098227..9df7f2dd9 100644 --- a/accounts/keystore/keystore.go +++ b/accounts/keystore/keystore.go @@ -450,7 +450,6 @@ func (ks *KeyStore) ImportECDSA(priv *ecdsa.PrivateKey, passphrase string) (acco if ks.cache.hasAddress(key.Address) { return accounts.Account{}, fmt.Errorf("account already exists") } - return ks.importKey(key, passphrase) } diff --git a/accounts/keystore/keystore_passphrase.go b/accounts/keystore/keystore_passphrase.go index 2eae25841..9a5c452c1 100644 --- a/accounts/keystore/keystore_passphrase.go +++ b/accounts/keystore/keystore_passphrase.go @@ -182,7 +182,10 @@ func DecryptKey(keyjson []byte, auth string) (*Key, error) { if err != nil { return nil, err } - key := crypto.ToECDSA(keyBytes) + key, err := crypto.ToECDSA(keyBytes) + if err != nil { + return nil, err + } return &Key{ Id: uuid.UUID(keyId), Address: crypto.PubkeyToAddress(key.PublicKey), diff --git a/accounts/keystore/keystore_passphrase_test.go b/accounts/keystore/keystore_passphrase_test.go index 086addbc1..630682ceb 100644 --- a/accounts/keystore/keystore_passphrase_test.go +++ b/accounts/keystore/keystore_passphrase_test.go @@ -46,7 +46,7 @@ func TestKeyEncryptDecrypt(t *testing.T) { // Decrypt with the correct password key, err := DecryptKey(keyjson, password) if err != nil { - t.Errorf("test %d: json key failed to decrypt: %v", i, err) + t.Fatalf("test %d: json key failed to decrypt: %v", i, err) } if key.Address != address { t.Errorf("test %d: key address mismatch: have %x, want %x", i, key.Address, address) diff --git a/accounts/keystore/presale.go b/accounts/keystore/presale.go index 5b883c45f..2f18a64db 100644 --- a/accounts/keystore/presale.go +++ b/accounts/keystore/presale.go @@ -74,7 +74,10 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error return nil, err } ethPriv := crypto.Keccak256(plainText) - ecKey := crypto.ToECDSA(ethPriv) + ecKey, err := crypto.ToECDSA(ethPriv) + if err != nil { + return nil, err + } key = &Key{ Id: nil, Address: crypto.PubkeyToAddress(ecKey.PublicKey), |