fix(keycard): convert to keycard action removes keystore and doesn't change the pass properly fixed

This commit is contained in:
Sale Djenic 2022-09-26 08:50:42 +02:00 committed by saledjenic
parent 5668bbaa8e
commit d89c0c8d9e
2 changed files with 17 additions and 17 deletions

View File

@ -690,12 +690,13 @@ func TestConvertAccount(t *testing.T) {
KeycardPairing: "pairing",
}
_, keyStoreErrBefore := os.Stat(keyStoreDir)
err = backend.ConvertToKeycardAccount(keyStoreDir, keycardAccount, keycardSettings, password, keycardPassword)
require.NoError(t, err)
_, err = os.Stat(keyStoreDir)
require.Error(t, err)
require.True(t, os.IsNotExist(err))
_, keyStoreErrAfter := os.Stat(keyStoreDir)
require.True(t, keyStoreErrBefore == keyStoreErrAfter)
err = backend.ensureAppDBOpened(keycardAccount, keycardPassword)
require.NoError(t, err)

View File

@ -529,17 +529,22 @@ func (b *GethStatusBackend) ImportUnencryptedDatabase(acc multiaccounts.Account,
func (b *GethStatusBackend) ChangeDatabasePassword(keyUID string, password string, newPassword string) error {
dbPath := filepath.Join(b.rootDataDir, fmt.Sprintf("%s.db", keyUID))
config := b.StatusNode().Config()
keyDir := config.KeyStoreDir
err := b.accountManager.ReEncryptKeyStoreDir(keyDir, password, newPassword)
if err != nil {
return fmt.Errorf("ReEncryptKeyStoreDir error: %v", err)
if config != nil {
keyDir := config.KeyStoreDir
err := b.accountManager.ReEncryptKeyStoreDir(keyDir, password, newPassword)
if err != nil {
return fmt.Errorf("ReEncryptKeyStoreDir error: %v", err)
}
}
err = appdatabase.ChangeDatabasePassword(dbPath, password, newPassword)
err := appdatabase.ChangeDatabasePassword(dbPath, password, newPassword)
if err != nil {
// couldn't change db password so undo keystore changes to mainitain consistency
_ = b.accountManager.ReEncryptKeyStoreDir(keyDir, newPassword, password)
if config != nil {
keyDir := config.KeyStoreDir
// couldn't change db password so undo keystore changes to mainitain consistency
_ = b.accountManager.ReEncryptKeyStoreDir(keyDir, newPassword, password)
}
return err
}
return nil
@ -585,13 +590,7 @@ func (b *GethStatusBackend) ConvertToKeycardAccount(keyStoreDir string, account
return err
}
err = os.RemoveAll(keyStoreDir)
if err != nil {
return err
}
dbPath := filepath.Join(b.rootDataDir, fmt.Sprintf("%s.db", account.KeyUID))
return appdatabase.ChangeDatabasePassword(dbPath, password, newPassword)
return b.ChangeDatabasePassword(account.KeyUID, password, newPassword)
}
func (b *GethStatusBackend) VerifyDatabasePassword(keyUID string, password string) error {