accounts: add ErrDecrypt

pull/2284/head
Felix Lange 9 years ago
parent a9f26dcd0d
commit 6f1ca0bc91
  1. 1
      accounts/account_manager.go
  2. 5
      accounts/key_store_passphrase.go
  3. 4
      accounts/key_store_test.go
  4. 3
      accounts/presale.go
  5. 2
      cmd/geth/accountcmd.go
  6. 2
      cmd/geth/accountcmd_test.go

@ -38,6 +38,7 @@ import (
var ( var (
ErrLocked = errors.New("account is locked") ErrLocked = errors.New("account is locked")
ErrNoMatch = errors.New("no key for given address or file") ErrNoMatch = errors.New("no key for given address or file")
ErrDecrypt = errors.New("could not decrypt key with given passphrase")
) )
type Account struct { type Account struct {

@ -31,7 +31,6 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"path/filepath" "path/filepath"
@ -214,7 +213,7 @@ func decryptKeyV3(keyProtected *encryptedKeyJSONV3, auth string) (keyBytes []byt
calculatedMAC := crypto.Keccak256(derivedKey[16:32], cipherText) calculatedMAC := crypto.Keccak256(derivedKey[16:32], cipherText)
if !bytes.Equal(calculatedMAC, mac) { if !bytes.Equal(calculatedMAC, mac) {
return nil, nil, errors.New("Decryption failed: MAC mismatch") return nil, nil, ErrDecrypt
} }
plainText, err := aesCTRXOR(derivedKey[:16], cipherText, iv) plainText, err := aesCTRXOR(derivedKey[:16], cipherText, iv)
@ -248,7 +247,7 @@ func decryptKeyV1(keyProtected *encryptedKeyJSONV1, auth string) (keyBytes []byt
calculatedMAC := crypto.Keccak256(derivedKey[16:32], cipherText) calculatedMAC := crypto.Keccak256(derivedKey[16:32], cipherText)
if !bytes.Equal(calculatedMAC, mac) { if !bytes.Equal(calculatedMAC, mac) {
return nil, nil, errors.New("Decryption failed: MAC mismatch") return nil, nil, ErrDecrypt
} }
plainText, err := aesCBCDecrypt(crypto.Keccak256(derivedKey[:16])[:16], cipherText, iv) plainText, err := aesCBCDecrypt(crypto.Keccak256(derivedKey[:16])[:16], cipherText, iv)

@ -94,8 +94,8 @@ func TestKeyStorePassphraseDecryptionFail(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if _, err = ks.GetKey(k1.Address, account.File, "bar"); err == nil { if _, err = ks.GetKey(k1.Address, account.File, "bar"); err != ErrDecrypt {
t.Fatal("no error for invalid passphrase") t.Fatalf("wrong error for invalid passphrase\ngot %q\nwant %q", err, ErrDecrypt)
} }
} }

@ -22,7 +22,6 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
@ -106,7 +105,7 @@ func aesCBCDecrypt(key, cipherText, iv []byte) ([]byte, error) {
decrypter.CryptBlocks(paddedPlaintext, cipherText) decrypter.CryptBlocks(paddedPlaintext, cipherText)
plaintext := pkcs7Unpad(paddedPlaintext) plaintext := pkcs7Unpad(paddedPlaintext)
if plaintext == nil { if plaintext == nil {
err = errors.New("Decryption failed: PKCS7Unpad failed after AES decryption") return nil, ErrDecrypt
} }
return plaintext, err return plaintext, err
} }

@ -263,7 +263,7 @@ func importWallet(ctx *cli.Context) {
acct, err := accman.ImportPreSaleKey(keyJson, passphrase) acct, err := accman.ImportPreSaleKey(keyJson, passphrase)
if err != nil { if err != nil {
utils.Fatalf("Could not create the account: %v", err) utils.Fatalf("%v", err)
} }
fmt.Printf("Address: {%x}\n", acct.Address) fmt.Printf("Address: {%x}\n", acct.Address)
} }

@ -127,7 +127,7 @@ func TestWalletImportBadPassword(t *testing.T) {
geth.expect(` geth.expect(`
!! Unsupported terminal, password will be echoed. !! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "wrong"}} Passphrase: {{.InputLine "wrong"}}
Fatal: Could not create the account: Decryption failed: PKCS7Unpad failed after AES decryption Fatal: could not decrypt key with given passphrase
`) `)
} }

Loading…
Cancel
Save