diff options
author | zelig <viktor.tron@gmail.com> | 2015-07-03 11:56:20 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-07-03 14:52:37 +0800 |
commit | 1959346793bdee469f68841843dd383cf801aba1 (patch) | |
tree | 12d53e0974ae96fdc27f8ed0e217565c5530b143 /crypto/key_store_passphrase.go | |
parent | fc17a527bc2bd07fc30e16d161059a441042d5f1 (diff) | |
download | go-tangerine-1959346793bdee469f68841843dd383cf801aba1.tar go-tangerine-1959346793bdee469f68841843dd383cf801aba1.tar.gz go-tangerine-1959346793bdee469f68841843dd383cf801aba1.tar.bz2 go-tangerine-1959346793bdee469f68841843dd383cf801aba1.tar.lz go-tangerine-1959346793bdee469f68841843dd383cf801aba1.tar.xz go-tangerine-1959346793bdee469f68841843dd383cf801aba1.tar.zst go-tangerine-1959346793bdee469f68841843dd383cf801aba1.zip |
account update: migrate or change password
* account.Update
* KeyStore.Cleanup
* fix dir rm for old format deleteKey
Diffstat (limited to 'crypto/key_store_passphrase.go')
-rw-r--r-- | crypto/key_store_passphrase.go | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/crypto/key_store_passphrase.go b/crypto/key_store_passphrase.go index d26e3407f..47909bc76 100644 --- a/crypto/key_store_passphrase.go +++ b/crypto/key_store_passphrase.go @@ -72,16 +72,19 @@ func (ks keyStorePassphrase) GenerateNewKey(rand io.Reader, auth string) (key *K } func (ks keyStorePassphrase) GetKey(keyAddr common.Address, auth string) (key *Key, err error) { - keyBytes, keyId, err := decryptKeyFromFile(ks, keyAddr, auth) - if err != nil { - return nil, err - } - key = &Key{ - Id: uuid.UUID(keyId), - Address: keyAddr, - PrivateKey: ToECDSA(keyBytes), + keyBytes, keyId, err := decryptKeyFromFile(ks.keysDirPath, keyAddr, auth) + if err == nil { + key = &Key{ + Id: uuid.UUID(keyId), + Address: keyAddr, + PrivateKey: ToECDSA(keyBytes), + } } - return key, err + return +} + +func (ks keyStorePassphrase) Cleanup(keyAddr common.Address) (err error) { + return cleanup(ks.keysDirPath, keyAddr) } func (ks keyStorePassphrase) GetKeyAddresses() (addresses []common.Address, err error) { @@ -142,7 +145,7 @@ func (ks keyStorePassphrase) StoreKey(key *Key, auth string) (err error) { func (ks keyStorePassphrase) DeleteKey(keyAddr common.Address, auth string) (err error) { // only delete if correct passphrase is given - _, _, err = decryptKeyFromFile(ks, keyAddr, auth) + _, _, err = decryptKeyFromFile(ks.keysDirPath, keyAddr, auth) if err != nil { return err } @@ -150,25 +153,25 @@ func (ks keyStorePassphrase) DeleteKey(keyAddr common.Address, auth string) (err return deleteKey(ks.keysDirPath, keyAddr) } -func decryptKeyFromFile(ks keyStorePassphrase, keyAddr common.Address, auth string) (keyBytes []byte, keyId []byte, err error) { +func decryptKeyFromFile(keysDirPath string, keyAddr common.Address, auth string) (keyBytes []byte, keyId []byte, err error) { + fmt.Printf("%v\n", keyAddr.Hex()) m := make(map[string]interface{}) - err = getKey(ks.keysDirPath, keyAddr, &m) + err = getKey(keysDirPath, keyAddr, &m) if err != nil { - fmt.Printf("get key error: %v\n", err) return } v := reflect.ValueOf(m["version"]) if v.Kind() == reflect.String && v.String() == "1" { k := new(encryptedKeyJSONV1) - getKey(ks.keysDirPath, keyAddr, &k) + err = getKey(keysDirPath, keyAddr, &k) if err != nil { return } return decryptKeyV1(k, auth) } else { k := new(encryptedKeyJSONV3) - getKey(ks.keysDirPath, keyAddr, &k) + err = getKey(keysDirPath, keyAddr, &k) if err != nil { return } |