accounts/keystore, crypto: enforce 256 bit keys on import

This commit is contained in:
Péter Szilágyi
2017-05-23 14:58:03 +03:00
parent 3556962053
commit aa73420207
10 changed files with 32 additions and 31 deletions

View File

@ -19,7 +19,6 @@ package ethapi
import (
"bytes"
"context"
"encoding/hex"
"errors"
"fmt"
"math/big"
@ -283,12 +282,11 @@ func fetchKeystore(am *accounts.Manager) *keystore.KeyStore {
// ImportRawKey stores the given hex encoded ECDSA key into the key directory,
// encrypting it with the passphrase.
func (s *PrivateAccountAPI) ImportRawKey(privkey string, password string) (common.Address, error) {
hexkey, err := hex.DecodeString(privkey)
key, err := crypto.HexToECDSA(privkey)
if err != nil {
return common.Address{}, err
}
acc, err := fetchKeystore(s.am).ImportECDSA(crypto.ToECDSA(hexkey), password)
acc, err := fetchKeystore(s.am).ImportECDSA(key, password)
return acc.Address, err
}